diff --git a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs index 95413d0e..04f5e40b 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs @@ -76,15 +76,14 @@ namespace ComputeSharp.Shaders.Translation } // Try to compile the new compute shader + fixed (char* shaderName = "") fixed (char* entryPoint = "CSMain") fixed (char* shaderProfile = "cs_6_1") fixed (char* optimization = "-O3") { - char nullTerminator = '\0'; - DxcCompiler.Get()->Compile( dxcBlobEncoding.Upcast().Get(), - (ushort*)&nullTerminator, + (ushort*)shaderName, (ushort*)entryPoint, (ushort*)shaderProfile, (ushort**)&optimization, diff --git a/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs new file mode 100644 index 00000000..8e5f8fe0 --- /dev/null +++ b/tests/ComputeSharp.Tests.Internals/ShaderCompilerTests.cs @@ -0,0 +1,51 @@ +using ComputeSharp.Shaders.Translation; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TerraFX.Interop; + +namespace ComputeSharp.Tests.Internals +{ + [TestClass] + [TestCategory("ShaderCompiler")] + public class ShaderCompilerTests + { + private const string ShaderSource = @" + /* =============== + * AUTO GENERATED + * =============== + * This shader was created by ComputeSharp. + * For info or issues: https://github.com/Sergio0694/ComputeSharp */ + + // Scalar/vector variables + cbuffer _ : register(b0) + { + uint __x__; // Target X iterations + uint __y__; // Target Y iterations + uint __z__; // Target Z iterations + int width; + } + + // ReadWriteBuffer buffer ""buffer"" + RWStructuredBuffer buffer : register(u1); + + // Shader body + [Shader(""compute"")] + [NumThreads(32, 1, 1)] + void CSMain(uint3 ids : SV_DispatchThreadId) + { + if (ids.x < __x__ && + ids.y < __y__ && + ids.z < __z__) // Automatic bounds check + { + int i = ids.x + ids.y * width; + buffer[i] *= 2; + } + } + "; + + [TestMethod] + public void CompileTest() + { + using ComPtr dxcBlob = ShaderCompiler.CompileShader(ShaderSource); + } + } +}