From 53411903c1a13bdf0a63c9b8b6d59fe260c6c824 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 8 Aug 2022 23:56:09 +0200 Subject: [PATCH] Fix incorrect [D2DRequiresScenePosition] name in diagnostic --- .../Diagnostics/DiagnosticDescriptors.cs | 12 ++++---- ...erGenerator.CreateBuildHlslSourceMethod.cs | 28 +++++++++---------- .../Mappings/HlslKnownMethods.cs | 6 ++-- .../SyntaxRewriters/HlslSourceRewriter.cs | 4 +-- .../SyntaxRewriters/ShaderSourceRewriter.cs | 6 ++-- .../SyntaxRewriters/StaticFieldRewriter.cs | 4 +-- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 339711a0..e3b47f1e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -636,19 +636,19 @@ internal static class DiagnosticDescriptors helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// - /// Gets a for when the [D2DRequiresPosition] attribute is missing. + /// Gets a for when the [D2DRequiresScenePosition] attribute is missing. /// - /// Format: "The D2D1 shader of type {0} is using D2D1 APIs that require the [D2DRequiresPosition] attribute to be used (that is, D2D1.GetScenePosition() and D2D1.SampleInputAtPosition(int, float2)), but the shader type is not annotated accordingly". + /// Format: "The D2D1 shader of type {0} is using D2D1 APIs that require the [D2DRequiresScenePosition] attribute to be used (that is, D2D1.GetScenePosition() and D2D1.SampleInputAtPosition(int, float2)), but the shader type is not annotated accordingly". /// /// - public static readonly DiagnosticDescriptor MissingD2DRequiresPositionAttribute = new DiagnosticDescriptor( + public static readonly DiagnosticDescriptor MissingD2DRequiresScenePositionAttribute = new DiagnosticDescriptor( id: "CMPSD2D0045", - title: "Missing [D2DRequiresPosition] attribute", - messageFormat: "The D2D1 shader of type {0} is using D2D1 APIs that require the [D2DRequiresPosition] attribute to be used (that is, D2D.GetScenePosition() and D2D.SampleInputAtPosition(int, float2)), but the shader type is not annotated accordingly", + title: "Missing [D2DRequiresScenePosition] attribute", + messageFormat: "The D2D1 shader of type {0} is using D2D1 APIs that require the [D2DRequiresScenePosition] attribute to be used (that is, D2D.GetScenePosition() and D2D.SampleInputAtPosition(int, float2)), but the shader type is not annotated accordingly", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "A D2D1 shader using functionality that needs position info (ie. when [D2DRequiresPosition] is used, which is mandatory when calling either D2D.GetScenePosition() or D2D.SampleInputAtPosition(int, float2)) needs to be annotated accordingly.", + description: "A D2D1 shader using functionality that needs position info (ie. when [D2DRequiresScenePosition] is used, which is mandatory when calling either D2D.GetScenePosition() or D2D.SampleInputAtPosition(int, float2)) needs to be annotated accordingly.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index cc9e2d2b..49c433df 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -63,8 +63,8 @@ partial class ID2D1ShaderGenerator // Explore the syntax tree and extract the processed info var semanticModelProvider = new SemanticModelProvider(compilation); - var (entryPoint, processedMethods) = GetProcessedMethods(diagnostics, structDeclaration, structDeclarationSymbol, semanticModelProvider, discoveredTypes, staticMethods, constantDefinitions, out bool methodsNeedD2D1RequiresPosition); - var staticFields = GetStaticFields(diagnostics, semanticModelProvider, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions, out bool fieldsNeedD2D1RequiresPosition); + var (entryPoint, processedMethods) = GetProcessedMethods(diagnostics, structDeclaration, structDeclarationSymbol, semanticModelProvider, discoveredTypes, staticMethods, constantDefinitions, out bool methodsNeedD2D1RequiresScenePosition); + var staticFields = GetStaticFields(diagnostics, semanticModelProvider, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions, out bool fieldsNeedD2D1RequiresScenePosition); // Process the discovered types and constants var declaredTypes = GetDeclaredTypes(diagnostics, structDeclarationSymbol, discoveredTypes); @@ -74,7 +74,7 @@ partial class ID2D1ShaderGenerator bool requiresScenePosition = GetD2DRequiresScenePositionInfo(structDeclarationSymbol); // Emit diagnostics for incorrect scene position uses - ReportInvalidD2DRequiresPositionUse(diagnostics, structDeclarationSymbol, requiresScenePosition, methodsNeedD2D1RequiresPosition || fieldsNeedD2D1RequiresPosition); + ReportInvalidD2DRequiresScenePositionUse(diagnostics, structDeclarationSymbol, requiresScenePosition, methodsNeedD2D1RequiresScenePosition || fieldsNeedD2D1RequiresScenePosition); // Get the HLSL source return GetHlslSource( @@ -174,7 +174,7 @@ partial class ID2D1ShaderGenerator /// The type symbol for the shader type. /// The collection of currently discovered types. /// The collection of discovered constant definitions. - /// Whether or not the shader needs the [D2DRequiresPosition] annotation. + /// Whether or not the shader needs the [D2DRequiresScenePosition] annotation. /// A sequence of static constant fields in . private static ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> GetStaticFields( ImmutableArray.Builder diagnostics, @@ -183,11 +183,11 @@ partial class ID2D1ShaderGenerator INamedTypeSymbol structDeclarationSymbol, ICollection discoveredTypes, IDictionary constantDefinitions, - out bool needsD2D1RequiresPosition) + out bool needsD2D1RequiresScenePosition) { ImmutableArray<(string, string, string?)>.Builder builder = ImmutableArray.CreateBuilder<(string, string, string?)>(); - needsD2D1RequiresPosition = false; + needsD2D1RequiresScenePosition = false; foreach (var fieldDeclaration in structDeclaration.Members.OfType()) { @@ -225,7 +225,7 @@ partial class ID2D1ShaderGenerator string? assignment = staticFieldRewriter.Visit(variableDeclarator)?.NormalizeWhitespace(eol: "\n").ToFullString(); - needsD2D1RequiresPosition |= staticFieldRewriter.NeedsD2DRequiresPositionAttribute; + needsD2D1RequiresScenePosition |= staticFieldRewriter.NeedsD2DRequiresScenePositionAttribute; builder.Add((mapping ?? fieldSymbol.Name, typeDeclaration, assignment)); } @@ -244,7 +244,7 @@ partial class ID2D1ShaderGenerator /// The collection of currently discovered types. /// The set of discovered and processed static methods. /// The collection of discovered constant definitions. - /// Whether or not the shader needs the [D2DRequiresPosition] annotation. + /// Whether or not the shader needs the [D2DRequiresScenePosition] annotation. /// A sequence of processed methods in , and the entry point. private static (string EntryPoint, ImmutableArray<(string Signature, string Definition)> Methods) GetProcessedMethods( ImmutableArray.Builder diagnostics, @@ -254,7 +254,7 @@ partial class ID2D1ShaderGenerator ICollection discoveredTypes, IDictionary staticMethods, IDictionary constantDefinitions, - out bool needsD2D1RequiresPosition) + out bool needsD2D1RequiresScenePosition) { // Find all declared methods in the type ImmutableArray methodDeclarations = ( @@ -265,7 +265,7 @@ partial class ID2D1ShaderGenerator string? entryPoint = null; ImmutableArray<(string, string)>.Builder methods = ImmutableArray.CreateBuilder<(string, string)>(); - needsD2D1RequiresPosition = false; + needsD2D1RequiresScenePosition = false; foreach (MethodDeclarationSyntax methodDeclaration in methodDeclarations) { @@ -295,7 +295,7 @@ partial class ID2D1ShaderGenerator MethodDeclarationSyntax? processedMethod = shaderSourceRewriter.Visit(methodDeclaration)!.WithoutTrivia(); // Update the position requirement - needsD2D1RequiresPosition |= shaderSourceRewriter.NeedsD2DRequiresPositionAttribute; + needsD2D1RequiresScenePosition |= shaderSourceRewriter.NeedsD2DRequiresScenePositionAttribute; // Emit the extracted local functions first foreach (var localFunction in shaderSourceRewriter.LocalFunctions) @@ -440,13 +440,13 @@ partial class ID2D1ShaderGenerator } /// - /// Reports diagnostics for invalid uses of [D2DRequiresPosition] in a shader. + /// Reports diagnostics for invalid uses of [D2DRequiresScenePosition] in a shader. /// /// The collection of produced instances. /// The input instance to process. /// Whether the shader type is declaring the need for scene position. /// Whether the shader is using APIs that rely on scene position. - private static void ReportInvalidD2DRequiresPositionUse( + private static void ReportInvalidD2DRequiresScenePositionUse( ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol, bool requiresScenePosition, @@ -454,7 +454,7 @@ partial class ID2D1ShaderGenerator { if (!requiresScenePosition && usesPositionDependentMethods) { - diagnostics.Add(MissingD2DRequiresPositionAttribute, structDeclarationSymbol, structDeclarationSymbol); + diagnostics.Add(MissingD2DRequiresScenePositionAttribute, structDeclarationSymbol, structDeclarationSymbol); } } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs index 5c502afc..2968f79c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownMethods.cs @@ -12,11 +12,11 @@ partial class HlslKnownMethods { /// /// Checks whether or not a method name (previous matched with - /// needs the [D2DRequiresPosition] annotation on its containing shader in order to be used. + /// needs the [D2DRequiresScenePosition] annotation on its containing shader in order to be used. /// /// The fully qualified metadata name. - /// Whether the method needs the [D2DRequiresPosition] annotation. - public static bool NeedsD2DRequiresPositionAttribute(string name) + /// Whether the method needs the [D2DRequiresScenePosition] annotation. + public static bool NeedsD2DRequiresScenePositionAttribute(string name) { return name is "ComputeSharp.D2D1.D2D.GetScenePosition" or "ComputeSharp.D2D1.D2D.SampleInputAtPosition"; } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs index 26f9c756..8e1c3bc9 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/HlslSourceRewriter.cs @@ -66,9 +66,9 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter } /// - /// Gets whether or not the shader needs the [D2DRequiresPosition] attribute. + /// Gets whether or not the shader needs the [D2DRequiresScenePosition] attribute. /// - public bool NeedsD2DRequiresPositionAttribute { get; protected set; } + public bool NeedsD2DRequiresScenePositionAttribute { get; protected set; } /// public override SyntaxNode VisitCastExpression(CastExpressionSyntax node) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 31f325a4..b6e4504d 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -285,10 +285,10 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter // For instance: Math.Abs(expr) => abs(expr). if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping)) { - // Track whether the method needs [D2DRequiresPosition] - if (HlslKnownMethods.NeedsD2DRequiresPositionAttribute(metadataName)) + // Track whether the method needs [D2DRequiresScenePosition] + if (HlslKnownMethods.NeedsD2DRequiresScenePositionAttribute(metadataName)) { - NeedsD2DRequiresPositionAttribute = true; + NeedsD2DRequiresScenePositionAttribute = true; } return updatedNode.WithExpression(ParseExpression(mapping!)); diff --git a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs index f4ae8d82..91f5ea3c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs @@ -99,9 +99,9 @@ internal sealed class StaticFieldRewriter : HlslSourceRewriter // Rewrite HLSL intrinsic methods if (HlslKnownMethods.TryGetMappedName(metadataName, out string? mapping)) { - if (HlslKnownMethods.NeedsD2DRequiresPositionAttribute(metadataName)) + if (HlslKnownMethods.NeedsD2DRequiresScenePositionAttribute(metadataName)) { - NeedsD2DRequiresPositionAttribute = true; + NeedsD2DRequiresScenePositionAttribute = true; } return updatedNode.WithExpression(ParseExpression(mapping!));