From 6b9895ed7442b4165e27adc8f14f51db0824f681 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 23 Sep 2023 18:52:55 +0200 Subject: [PATCH] Switch D2D1 generator to use ForAttributeWithMetadataName --- .../ID2D1ShaderGenerator.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 810264f2..3b10c6fc 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -5,7 +5,6 @@ using ComputeSharp.SourceGeneration.Extensions; using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ComputeSharp.D2D1.SourceGenerators; @@ -22,7 +21,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator // Discover all shader types and extract all the necessary info from each of them IncrementalValuesProvider shaderInfo = context.SyntaxProvider - .CreateSyntaxProvider( + .ForAttributeWithMetadataName( + "ComputeSharp.D2D1.D2DGeneratedShaderMarshallerAttribute", static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes(), static (context, token) => { @@ -32,14 +32,14 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator return default; } - StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.Node; - // If the type symbol doesn't have at least one interface, it can't possibly be a shader type - if (context.SemanticModel.GetDeclaredSymbol(typeDeclaration, token) is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol) + if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol) { return default; } + StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.TargetNode; + // Check that the shader implements the ID2D1PixelShader interface if (!IsD2D1PixelShaderType(typeSymbol, context.SemanticModel.Compilation)) {