From 86b39c28f54fc8fde6bdf95ca2ef45ba8b8c0711 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 17 Dec 2023 15:09:00 +0100 Subject: [PATCH] Refactor HlslBytecodeSyntaxProcessor partial constants --- .../HlslBytecodeSyntaxProcessor.D2D1.cs | 9 +++++---- .../HlslBytecodeSyntaxProcessor.cs | 14 ++++++++++---- .../HlslBytecodeSyntaxProcessor.D3D12.cs | 9 +++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D2D1.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D2D1.cs index dd4c9742..d87ed2a7 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D2D1.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D2D1.cs @@ -10,10 +10,11 @@ namespace ComputeSharp.SourceGeneration.SyntaxProcessors; /// partial class HlslBytecodeSyntaxProcessor { - /// - /// The name of the attribute to enable double precision support. - /// - private const string RequiresDoublePrecisionSupportAttributeName = "ComputeSharp.D2D1.D2DRequiresDoublePrecisionSupportAttribute"; + /// + private static partial string GetRequiresDoublePrecisionSupportAttributeName() + { + return "ComputeSharp.D2D1.D2DRequiresDoublePrecisionSupportAttribute"; + } /// private static partial ComPtr Compile(HlslBytecodeInfoKey key, CancellationToken token) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslBytecodeSyntaxProcessor.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslBytecodeSyntaxProcessor.cs index 8d72c7a7..f530496e 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslBytecodeSyntaxProcessor.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/HlslBytecodeSyntaxProcessor.cs @@ -142,21 +142,21 @@ internal static partial class HlslBytecodeSyntaxProcessor return; } - bool hasD2DRequiresDoublePrecisionSupportAttribute = structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName( - RequiresDoublePrecisionSupportAttributeName, + bool hasRequiresDoublePrecisionSupportAttribute = structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName( + GetRequiresDoublePrecisionSupportAttributeName(), out AttributeData? attributeData); // Check the two cases where diagnostics are necessary: // - The shader does not have [[D2D]RequiresDoublePrecisionSupport], but it needs it // - The shader has [[D2D]RequiresDoublePrecisionSupport], but it does not need it - if (!hasD2DRequiresDoublePrecisionSupportAttribute && success.RequiresDoublePrecisionSupport) + if (!hasRequiresDoublePrecisionSupportAttribute && success.RequiresDoublePrecisionSupport) { diagnostics.Add(DiagnosticInfo.Create( MissingRequiresDoublePrecisionSupportAttribute, structDeclarationSymbol, structDeclarationSymbol)); } - else if (hasD2DRequiresDoublePrecisionSupportAttribute && !success.RequiresDoublePrecisionSupport) + else if (hasRequiresDoublePrecisionSupportAttribute && !success.RequiresDoublePrecisionSupport) { diagnostics.Add(DiagnosticInfo.Create( UnnecessaryRequiresDoublePrecisionSupportAttribute, @@ -165,6 +165,12 @@ internal static partial class HlslBytecodeSyntaxProcessor } } + /// + /// Gets the type name for the attribute to indicate that double precision support is required. + /// + /// The type name for the attribute to indicate that double precision support is required. + private static partial string GetRequiresDoublePrecisionSupportAttributeName(); + /// /// Compiles the input HLSL source into bytecode. /// diff --git a/src/ComputeSharp.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D3D12.cs b/src/ComputeSharp.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D3D12.cs index 6d49101d..1246494c 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D3D12.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxProcessors/HlslBytecodeSyntaxProcessor.D3D12.cs @@ -10,10 +10,11 @@ namespace ComputeSharp.SourceGeneration.SyntaxProcessors; /// partial class HlslBytecodeSyntaxProcessor { - /// - /// The name of the attribute to enable double precision support. - /// - private const string RequiresDoublePrecisionSupportAttributeName = "ComputeSharp.RequiresDoublePrecisionSupportAttribute"; + /// + private static partial string GetRequiresDoublePrecisionSupportAttributeName() + { + return "ComputeSharp.RequiresDoublePrecisionSupportAttribute"; + } /// private static partial ComPtr Compile(HlslBytecodeInfoKey key, CancellationToken token)