From 03c5585c74d3bab5c4263fe3a243ff911a1f9c68 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 Apr 2022 12:47:11 +0200 Subject: [PATCH 1/2] Fix remapping of keyword-named fields in this. expressions --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 2 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index b519066b..2e32afce 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -244,7 +244,7 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter // If the member access is a this. access, rewrite it to strip "this." if (node.Expression.IsKind(SyntaxKind.ThisExpression)) { - return node.Name; + return updatedNode.Name; } } diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 59e5e7fd..ff8329ff 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -276,7 +276,7 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter // If the member access is a this. access, rewrite it to strip "this." if (node.Expression.IsKind(SyntaxKind.ThisExpression)) { - return node.Name; + return updatedNode.Name; } } From fcb8d028b2d43ef8624b3441e14dbf06483bc75f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 Apr 2022 12:47:23 +0200 Subject: [PATCH 2/2] Add unit tests for fields with this. expressions --- .../ComputeSharp.Tests/ShaderCompilerTests.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index fbaca8b5..0c497090 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -32,6 +32,43 @@ namespace ComputeSharp.Tests } } + [TestMethod] + public void ReservedKeywordsPrecompiled() + { + _ = ReflectionServices.GetShaderInfo(); + } + + [AutoConstructor] + [EmbeddedBytecode(DispatchAxis.X)] + public readonly partial struct ReservedKeywordsPrecompiledShader : IComputeShader + { + public readonly ReadWriteBuffer row_major; + public readonly float dword; + public readonly float float2; + public readonly int int2x2; + private readonly float sin; + private readonly float cos; + private readonly float scale; + private readonly float intensity; + + public void Execute() + { + float exp = Hlsl.Exp(dword * row_major[ThreadIds.X]); + float log = Hlsl.Log(1 + exp); + + float s1 = this.cos * exp * this.sin * log; + float t1 = -this.sin * exp * this.cos * log; + + float s2 = s1 + this.intensity + Hlsl.Tan(s1 * this.scale); + float t2 = t1 + this.intensity + Hlsl.Tan(t1 * this.scale); + + float u2 = this.cos * s2 - this.sin * t2; + float v2 = this.sin * s2 - this.cos * t2; + + row_major[ThreadIds.X] = log / dword + float2 + int2x2 + u2 + v2; + } + } + [TestMethod] public void SpecialTypeAsReturnType() {