Skip to content

Commit

Permalink
Implemented Math functions, automated headless graphics device testin…
Browse files Browse the repository at this point in the history
…g, numerous bug fixes and improvements (#77)

* Created branch and got list of full MathF functions.  Began OpenGL changes.

* Initial attempt at GLSL implementations for MathF support.

* Changed tools to error when called on unavailable and instead moved logic to skip tests automatically into attribute system on tests.  This will cause tests that require certain backends to be simply skipped (with a reason) on systems that don't support that backend, instead of showing as passed.

* WIP Checking in changes to create new ToolChain system, this massively reduces duplicate code, and will make move to full stack testing easier. (Not yet compiling)

* Test project compiles and works.  Better encapsulation has made it easy to vastly enhance output in case of errors, making it easier to trace issues.

Tests which require various tool sets are now auto-skipped.

* ShaderBuiltins now directly implements Math functions.

* Updated known identifiers to use nameof, and added 'E' and 'PI' to ShaderBuiltins.

* Chains to make tool execution more robust.

* Added more robust tool runner.

* Auto-captures compiled output.

* Refactored ShaderGenerator constructor to support specific compute shader generation,  remove duplicate code, and improve signatures.

* Fix for #69, ensuring Compute shaders require at least version 320..

* Fixes #70, although this version still uses recursion, it calculates alignments and sizes in one pass and it adds alignment info objects as it goes, preventing duplicate analysis.  It remains thread safe and should be considerably faster and safer.

It also correctly skips static fields now, and the code is no longer duplicated.

* Fixes #71, ensuring that constructors don't get confused with legitimate members.

* Begins support for #72 by allowing constructor bodies to be supplied.  Doesn't yet correctly rewrite method body.

* WIP #65, creating test compute shaders.

* Updated fix for #70, as boolean is not a blittable type we should probably not support it at all in shader code.  To that end I've added a check that will auto-detect the majority of non-blittable types and error cleanly.

* Almost working end to end test of compute shader!

* Added compute tests for each backend.

* Added comparison code to compare CPU & GPU output and compute shader tests work on Vulkan, but none of the other backends which throw strange errors.

* Added information to indicate which method failed in the compute shader.

* Fixes issues reported in veldrid/veldrid#80.  All tests now passing on all backends.

Added deep check on structs to make it much easier to see which fields have failed comparison checks (also prevents failures due to float.NaN).

* Added headless creation support to ToolChain as suggested in veldrid/veldrid#80.

* Changed test to use headless graphics device code from ToolChain.

* Shader test now has tests for all maths functions and runs tests multiple times to find statistical failure rate.

(Note only GLS330 is implemented, so shader will not yet build on other backends).

* Completed implementation in HLSL, which now fully compiles.

* Added GlslEs300 support for new maths functions, fully compiles.

* Full implemented Glsl450 (Vulkan) and shader now compiles.

* All builtins now supported on all backends (though can't test Metal).

* Fixed Lerp and SmoothStep CPU implementations.  Added more tolerance control for automated tests, to reduce number of failures due to floating point rounding failures.

* Implemented Mul.  Clamp now returns NaN for invalid min/max.  Fixed Frac and Lerp.  Added more control over input values for tests.  Auto-skipping tests for now as the trig functions are still not really accurate enough for comparisons.

* Added Mellinoe myget to Nuget.Config to allow CI server to get latest Veldrid builds.

Added new MaximumFailureRate setting to allow tests to run and report inconsistencies without failing.

* Increased default ToolChain timeout (and added constant).  Start timer for automated tests after toolchain completes.

* Added more robust checking to see if a headless device is available.  Also enhanced the Fact attributes to allow optional requirement of requiring a headless graphics device.

* Auto-detecting headless seems to fail on AppVeyor, changed to only attempt if the compile tools were found at least.

* Changed Headless detection to lazy initialisation, to see if it can resolve bizarre CI server build issue.

* Final attempt at preventing XUnit failure on CI server.

* Added last ditch check to prevent test failures onf CI when headless devices are not available.

* More minor changes to improve CI build?

* Removed headless checks in Fact attributes as it crashes CI server without warning.

* Major refactor to tool chain to support more extensibility and a new 'feature' system.

Changed Skip logic to use builtin SkippableFacts in hope it addresses CI server issues.

* WIP To support auto-generation of test cases. split ShaderBuiltins into Builtins.

Now ShaderBuiltins members all throw a ShaderBuiltinException on execution (with improved error message), and Builtins can be executed on the GPU and CPU safely.

* Rolled out split of ShaderBuiltins and Builtins.  Kept changes to ToolChain and TestUtil and nicer ShaderBuiltInsException.

* Fix issue when using fully qualified name for structured buffer and rwtexture2d types.

* Fixed bug with create headless and create windowed (for future expansion) function testing.

* Added lazy initialisation into test utils to improve test performance.

* Added Skip message for ShaderBuiltinsTest to prevent CI server issues (although there shouldn't be any CI server issues).

* Added code to disable graphics device creation on CI servers as it seems to crash them even with error trapping.

* Addresses simple changes for GH-77

* Removed skip on ShaderBuiltinsTests.

* Added R# settings to enforce brace style, and ran across solution to re-add any missing braces.

* Replaces random structure creation logic as per GH-77.

* Changed all Tuples to Value Tuples with proper names as per GH-77.

Moved DeepCompareObjectFields<T>() and FillRandomFloats<T>() into TestUtil.  Changed FillRandomFloats<T>() to use a 'better' float generator.  For now, limited floats to quite a small range, but ultimately would looks to evaluate all possible floats accurately.

* Added logic to prevent failures in reading the tool output from masking underlying errors as reported in GH-77.

* Fixed naming of dfdx and dfdy as per GH-77.

* Fixed ambiguous atan/pow function output when the second parameter requires a float (see GH-77)

* Check for compute shader support as per GH-77.

* Use two-stage compilation in the Metal toolchain.

* Ensure code is propogated to CompileResult in MetalCompile when passing through second step.

* Force float-type parameters in appopriate pow/atan overloads.
  • Loading branch information
thargy authored and mellinoe committed May 30, 2018
1 parent 2d61172 commit 9c934c2
Show file tree
Hide file tree
Showing 48 changed files with 4,638 additions and 1,851 deletions.
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<packageSources>
<add key="dotnet-myget dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="dotnet-myget dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
<add key="myget mellinoe" value="https://www.myget.org/F/mellinoe/api/v3/index.json" />
</packageSources>
</configuration>
59 changes: 54 additions & 5 deletions src/ShaderGen.Primitives/RWStructuredBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
namespace ShaderGen
using System;
using System.Collections.Generic;
using System.Linq;

namespace ShaderGen
{
/// <summary>
/// A writable structured buffer.
/// </summary>
/// <typeparam name="T"></typeparam>
public class RWStructuredBuffer<T> where T : struct
{
public ref T this[int index]
/// <summary>
/// The data.
/// </summary>
private readonly T[] _data;

/// <summary>
/// Initializes a new instance of the <see cref="RWStructuredBuffer{T}" /> class.
/// </summary>
/// <param name="data">The data.</param>
/// <remarks>
/// Note, use with caution as this sets the underlying data to the passed in array.
/// TODO Implement shader code to mimic behaviour of calling constructor.
/// </remarks>
public RWStructuredBuffer(ref T[] data)
{
get => throw new ShaderBuiltinException();
_data = data;
}

public ref T this[uint index]
/// <summary>
/// Initializes a new instance of the <see cref="RWStructuredBuffer{T}" /> class.
/// </summary>
/// <param name="capacity">The capacity.</param>
/// <remarks>
/// TODO Implement shader code to mimic behaviour of calling constructor.
/// </remarks>
public RWStructuredBuffer(int capacity) : this((uint)capacity) { }
public RWStructuredBuffer(uint capacity)
{
get => throw new ShaderBuiltinException();
_data = new T[capacity];
}

/// <summary>
/// Gets the <see cref="T" /> with the specified index.
/// </summary>
/// <value>
/// The <see cref="T" />.
/// </value>
/// <param name="index">The index.</param>
/// <returns></returns>
public ref T this[int index] => ref _data[index];

/// <summary>
/// Gets the <see cref="T" /> with the specified index.
/// </summary>
/// <value>
/// The <see cref="T" />.
/// </value>
/// <param name="index">The index.</param>
/// <returns></returns>
public ref T this[uint index] => ref _data[index];
}
}
13 changes: 13 additions & 0 deletions src/ShaderGen.Primitives/ShaderBuiltinException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Runtime.CompilerServices;

namespace ShaderGen
{
public class ShaderBuiltinException : Exception
{
internal ShaderBuiltinException([CallerMemberName] string memberName = null)
: base($"{nameof(ShaderBuiltins)}.{memberName} can only be executed on the GPU.")
{
}
}
}
335 changes: 258 additions & 77 deletions src/ShaderGen.Primitives/ShaderBuiltins.cs

Large diffs are not rendered by default.

99 changes: 0 additions & 99 deletions src/ShaderGen.Tests/FxcTool.cs

This file was deleted.

107 changes: 0 additions & 107 deletions src/ShaderGen.Tests/GlslangValidatorTool.cs

This file was deleted.

8 changes: 3 additions & 5 deletions src/ShaderGen.Tests/IShaderSetProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ public class IShaderSetProcessorTests
[Fact]
private void TestProcessor_UsersArgs()
{
Compilation compilation = TestUtil.GetTestProjectCompilation();
Compilation compilation = TestUtil.GetCompilation();
HlslBackend backend = new HlslBackend(compilation);
TestProcessor processor = new TestProcessor();
ShaderGenerator sg = new ShaderGenerator(
compilation,
"TestShaders.ProcessorTestShaders.VS",
"TestShaders.ProcessorTestShaders.FS",
new[] { backend },
new[] { processor });
backend,
"TestShaders.ProcessorTestShaders.VS", "TestShaders.ProcessorTestShaders.FS", null, processor);
sg.GenerateShaders();
Assert.Equal("This Sentence Should Be Printed By_Enumerating All Resources In Order", processor.Result);
}
Expand Down
Loading

0 comments on commit 9c934c2

Please sign in to comment.