diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs index 9ef3b213..5ddf70ba 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs @@ -43,8 +43,6 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene return default; } - StructDeclarationSyntax typeDeclaration = (StructDeclarationSyntax)context.TargetNode; - // Check that the shader implements the ID2D1PixelShader interface if (!typeSymbol.HasInterfaceWithType(context.SemanticModel.Compilation.GetTypeByMetadataName("ComputeSharp.D2D1.ID2D1PixelShader")!)) { @@ -110,7 +108,7 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene string hlslSource = HlslSource.GetHlslSource( diagnostics, context.SemanticModel.Compilation, - typeDeclaration, + (StructDeclarationSyntax)context.TargetNode, typeSymbol, inputCount, inputSimpleIndices, diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs index 50d63776..f81d68b9 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs @@ -5,7 +5,6 @@ using ComputeSharp.SourceGeneration.Helpers; using ComputeSharp.SourceGeneration.Models; using ComputeSharp.SourceGenerators.Models; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace ComputeSharp.SourceGenerators; @@ -27,7 +26,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener // Discover all shader types and extract all the necessary info from each of them IncrementalValuesProvider shaderInfo = context.SyntaxProvider - .CreateSyntaxProvider( + .ForAttributeWithMetadataName( + "ComputeSharp.GeneratedComputeShaderDescriptorAttribute", static (node, _) => node.IsTypeDeclarationWithOrPotentiallyWithBaseTypes(), static (context, token) => { @@ -37,10 +37,8 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener 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; } @@ -78,7 +76,7 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener HlslSource.GetInfo( diagnostics, context.SemanticModel.Compilation, - typeDeclaration, + (StructDeclarationSyntax)context.TargetNode, typeSymbol, threadsX, threadsY,