From b832874e551c8403d3f471772899896419f61339 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 6 Dec 2023 01:01:03 +0100 Subject: [PATCH] Track [D2DRequiresScenePosition] from external static fields --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 12 ++++-------- .../SyntaxRewriters/ShaderSourceRewriter.cs | 10 ++++++++-- .../SyntaxRewriters/ShaderSourceRewriter.cs | 8 +------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 4ddd4301..9b505839 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -29,18 +29,14 @@ partial class ShaderSourceRewriter } /// - private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName) + partial void TrackKnownMethodInvocation(string metadataName) { - // No special tracking is needed for D2D1 shaders + NeedsD2DRequiresScenePositionAttribute |= HlslKnownMethods.NeedsD2DRequiresScenePositionAttribute(metadataName); } /// - private partial void TrackKnownMethodInvocation(string metadataName) + partial void TrackExternalStaticField(StaticFieldRewriter staticFieldRewriter) { - // Track whether the method needs [D2DRequiresScenePosition] - if (HlslKnownMethods.NeedsD2DRequiresScenePositionAttribute(metadataName)) - { - NeedsD2DRequiresScenePositionAttribute = true; - } + NeedsD2DRequiresScenePositionAttribute |= staticFieldRewriter.NeedsD2DRequiresScenePositionAttribute; } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index e71d9f25..30ccf728 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -817,11 +817,17 @@ internal sealed partial class ShaderSourceRewriter( /// The instance for the operation. /// The instance for the operation. /// The mapped name for the property access. - private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName); + partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName); /// /// Tracks a method invocation for a known HLSL method. /// /// The metadata name of the method being invoked. - private partial void TrackKnownMethodInvocation(string metadataName); + partial void TrackKnownMethodInvocation(string metadataName); + + /// + /// Tracks an access to an external static field. + /// + /// The instance used to rewrite the field expression. + partial void TrackExternalStaticField(StaticFieldRewriter staticFieldRewriter); } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 4d684730..9a7b0748 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -48,7 +48,7 @@ partial class ShaderSourceRewriter } /// - private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName) + partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName) { // Mark which dispatch properties have been used, to optimize the declaration afterwards if (operation.Member.IsStatic) @@ -88,10 +88,4 @@ partial class ShaderSourceRewriter } } } - - /// - private partial void TrackKnownMethodInvocation(string metadataName) - { - // No special tracking is needed for DX12 compute shaders - } } \ No newline at end of file