Fix incorrect [D2DRequiresScenePosition] name in diagnostic

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-09 00:22:05 +02:00
1 親 6bda02c86f
コミット 53411903c1
6ファイル変更
+30 -30

検索条件に一致するファイルはありません

+6 -6
ファイルの表示
@@ -636,19 +636,19 @@ internal static class DiagnosticDescriptors
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DRequiresPosition]</c> attribute is missing.
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DRequiresScenePosition]</c> attribute is missing.
/// <para>
/// Format: <c>"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"</c>.
/// Format: <c>"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"</c>.
/// </para>
/// </summary>
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");
/// <summary>
@@ -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
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <param name="needsD2D1RequiresPosition">Whether or not the shader needs the <c>[D2DRequiresPosition]</c> annotation.</param>
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
/// <returns>A sequence of static constant fields in <paramref name="structDeclarationSymbol"/>.</returns>
private static ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> GetStaticFields(
ImmutableArray<Diagnostic>.Builder diagnostics,
@@ -183,11 +183,11 @@ partial class ID2D1ShaderGenerator
INamedTypeSymbol structDeclarationSymbol,
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IFieldSymbol, string> 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<FieldDeclarationSyntax>())
{
@@ -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
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
/// <param name="staticMethods">The set of discovered and processed static methods.</param>
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
/// <param name="needsD2D1RequiresPosition">Whether or not the shader needs the <c>[D2DRequiresPosition]</c> annotation.</param>
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
/// <returns>A sequence of processed methods in <paramref name="structDeclaration"/>, and the entry point.</returns>
private static (string EntryPoint, ImmutableArray<(string Signature, string Definition)> Methods) GetProcessedMethods(
ImmutableArray<Diagnostic>.Builder diagnostics,
@@ -254,7 +254,7 @@ partial class ID2D1ShaderGenerator
ICollection<INamedTypeSymbol> discoveredTypes,
IDictionary<IMethodSymbol, MethodDeclarationSyntax> staticMethods,
IDictionary<IFieldSymbol, string> constantDefinitions,
out bool needsD2D1RequiresPosition)
out bool needsD2D1RequiresScenePosition)
{
// Find all declared methods in the type
ImmutableArray<MethodDeclarationSyntax> 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
}
/// <summary>
/// Reports diagnostics for invalid uses of <c>[D2DRequiresPosition]</c> in a shader.
/// Reports diagnostics for invalid uses of <c>[D2DRequiresScenePosition]</c> in a shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="requiresScenePosition">Whether the shader type is declaring the need for scene position.</param>
/// <param name="usesPositionDependentMethods">Whether the shader is using APIs that rely on scene position.</param>
private static void ReportInvalidD2DRequiresPositionUse(
private static void ReportInvalidD2DRequiresScenePositionUse(
ImmutableArray<Diagnostic>.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);
}
}
+3 -3
ファイルの表示
@@ -12,11 +12,11 @@ partial class HlslKnownMethods
{
/// <summary>
/// Checks whether or not a method name (previous matched with <see cref="TryGetMappedName(string, out string?)"/>
/// needs the <c>[D2DRequiresPosition]</c> annotation on its containing shader in order to be used.
/// needs the <c>[D2DRequiresScenePosition]</c> annotation on its containing shader in order to be used.
/// </summary>
/// <param name="name">The fully qualified metadata name.</param>
/// <returns>Whether the method needs the <c>[D2DRequiresPosition]</c> annotation.</returns>
public static bool NeedsD2DRequiresPositionAttribute(string name)
/// <returns>Whether the method needs the <c>[D2DRequiresScenePosition]</c> annotation.</returns>
public static bool NeedsD2DRequiresScenePositionAttribute(string name)
{
return name is "ComputeSharp.D2D1.D2D.GetScenePosition" or "ComputeSharp.D2D1.D2D.SampleInputAtPosition";
}
+2 -2
ファイルの表示
@@ -66,9 +66,9 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
}
/// <summary>
/// Gets whether or not the shader needs the <c>[D2DRequiresPosition]</c> attribute.
/// Gets whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> attribute.
/// </summary>
public bool NeedsD2DRequiresPositionAttribute { get; protected set; }
public bool NeedsD2DRequiresScenePositionAttribute { get; protected set; }
/// <inheritdoc/>
public override SyntaxNode VisitCastExpression(CastExpressionSyntax node)
+3 -3
ファイルの表示
@@ -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!));
+2 -2
ファイルの表示
@@ -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!));