diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 3052e820..9ee52faf 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -315,6 +315,31 @@ namespace ComputeSharp.Tests Assert.AreEqual(info.TextureStoreInstructionCount, 1u); Assert.AreEqual(info.BoundResourceCount, 2u); + Assert.AreEqual(""" + #define __GroupSize__get_X 8 + #define __GroupSize__get_Y 8 + #define __GroupSize__get_Z 1 + + cbuffer _ : register(b0) + { + uint __x; + uint __y; + } + + RWTexture2D __outputTexture : register(u0); + + [NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)] + void Execute(uint3 ThreadIds : SV_DispatchThreadID) + { + if (ThreadIds.x < __x && ThreadIds.y < __y) + { + { + __outputTexture[ThreadIds.xy] = float4(1, 1, 1, 1); + return; + } + } + } + """, info.HlslSource); } [ThreadGroupSize(DefaultThreadGroupSizes.XY)] diff --git a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs index b2c55d23..6208a34d 100644 --- a/tests/ComputeSharp.Tests/ShaderRewriterTests.cs +++ b/tests/ComputeSharp.Tests/ShaderRewriterTests.cs @@ -1559,4 +1559,100 @@ public partial class ShaderRewriterTests buffer[3] = mask2x3_r_or.M11 ? 1 : 0; } } + + // See https://github.com/Sergio0694/ComputeSharp/issues/855 + [TestMethod] + public void CompileExplicitEntryPointMethodComputeShader() + { + ShaderInfo info = ReflectionServices.GetShaderInfo(); + + Assert.AreEqual( + """ + #define __GroupSize__get_X 64 + #define __GroupSize__get_Y 1 + #define __GroupSize__get_Z 1 + + cbuffer _ : register(b0) + { + uint __x; + uint __y; + uint __z; + } + + RWStructuredBuffer __reserved__buffer : register(u0); + + [NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)] + void Execute(uint3 ThreadIds : SV_DispatchThreadID) + { + if (ThreadIds.x < __x && ThreadIds.y < __y && ThreadIds.z < __z) + { + __reserved__buffer[0] = 42; + } + } + """, + info.HlslSource); + } + + [AutoConstructor] + [ThreadGroupSize(DefaultThreadGroupSizes.X)] + [GeneratedComputeShaderDescriptor] + public readonly partial struct ExplicitEntryPointMethodComputeShader : IComputeShader + { + public readonly ReadWriteBuffer buffer; + + void IComputeShader.Execute() + { + buffer[0] = 42; + } + } + + // See https://github.com/Sergio0694/ComputeSharp/issues/855 + [TestMethod] + public void CompileExplicitEntryPointMethodPixelShader() + { + ShaderInfo info = ReflectionServices.GetShaderInfo(); + + Assert.AreEqual( + """ + #define __GroupSize__get_X 64 + #define __GroupSize__get_Y 1 + #define __GroupSize__get_Z 1 + + cbuffer _ : register(b0) + { + uint __x; + uint __y; + } + + RWTexture2D __outputTexture : register(u0); + + RWStructuredBuffer __reserved__buffer : register(u1); + + [NumThreads(__GroupSize__get_X, __GroupSize__get_Y, __GroupSize__get_Z)] + void Execute(uint3 ThreadIds : SV_DispatchThreadID) + { + if (ThreadIds.x < __x && ThreadIds.y < __y) + { + { + __outputTexture[ThreadIds.xy] = __reserved__buffer[0]; + return; + } + } + } + """, + info.HlslSource); + } + + [AutoConstructor] + [ThreadGroupSize(DefaultThreadGroupSizes.X)] + [GeneratedComputeShaderDescriptor] + public readonly partial struct ExplicitEntryPointMethodPixelShader : IComputeShader + { + public readonly ReadWriteBuffer buffer; + + float4 IComputeShader.Execute() + { + return buffer[0]; + } + } } \ No newline at end of file