diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs
index a7189020..884a657d 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslStringMethod.cs
@@ -119,7 +119,7 @@ public sealed partial class IShaderGenerator
continue;
}
- AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
+ AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == typeof(GroupSharedAttribute).FullName);
// Group shared fields must be static
if (attribute is not null)
@@ -215,7 +215,7 @@ public sealed partial class IShaderGenerator
continue;
}
- AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
+ AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == typeof(GroupSharedAttribute).FullName);
if (attribute is not null)
{
@@ -276,7 +276,7 @@ public sealed partial class IShaderGenerator
continue;
}
- AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
+ AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == typeof(GroupSharedAttribute).FullName);
if (attribute is null)
{
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs
index 645108ca..44a5082b 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateTryGetBytecodeMethod.cs
@@ -30,20 +30,18 @@ public sealed partial class IShaderGenerator
///
/// Gets the thread ids values for a given shader type, if available.
///
- /// The instance for the attribute.
/// The input instance to process.
/// Indicates whether or not the shader is dynamic (ie. captures delegates).
/// The resulting diagnostics from the processing operation.
/// The thread ids for the precompiled shader, if available.
public static ThreadIdsInfo GetInfo(
- INamedTypeSymbol embeddedBytecodeAttribute,
INamedTypeSymbol structDeclarationSymbol,
bool isDynamicShader,
out ImmutableArray diagnostics)
{
AttributeData? attribute = structDeclarationSymbol
.GetAttributes()
- .FirstOrDefault(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, embeddedBytecodeAttribute));
+ .FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == typeof(EmbeddedBytecodeAttribute).FullName);
if (attribute is null)
{
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
index 04d0fdd7..e16984d4 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
@@ -38,21 +38,18 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
Symbol: (INamedTypeSymbol?)context.SemanticModel.GetDeclaredSymbol(context.Node, token)))
.Where(static pair => pair.Symbol is not null)!;
- // Get the symbol for the IComputeShader interface
- IncrementalValueProvider iComputeShaderSymbol =
+ // Get the symbol for the IComputeShader and IPixelShader interfaces
+ IncrementalValueProvider<(INamedTypeSymbol Compute, INamedTypeSymbol Pixel) > shaderInterfaces =
context.CompilationProvider
- .Select(static (compilation, token) => compilation.GetTypeByMetadataName(typeof(IComputeShader).FullName))!;
-
- // Get the symbol for the IPixelShader interface
- IncrementalValueProvider iPixelShaderSymbol =
- context.CompilationProvider
- .Select(static (compilation, token) => compilation.GetTypeByMetadataName(typeof(IPixelShader<>).FullName))!;
+ .Select(static (compilation, token) => (
+ Compute: compilation.GetTypeByMetadataName(typeof(IComputeShader).FullName)!,
+ Pixel: compilation.GetTypeByMetadataName(typeof(IPixelShader<>).FullName)!));
// Filter struct declarations that implement a shader interface, and also gather the hierarchy info and shader type
IncrementalValuesProvider<(StructDeclarationSyntax Syntax, INamedTypeSymbol Symbol, HierarchyInfo Hierarchy, Type Type)> shaderDeclarations =
structDeclarations
- .Combine(iComputeShaderSymbol.Combine(iPixelShaderSymbol))
- .Select(static (item, token) => (item.Left, Type: GetShaderType(item.Left.Symbol, item.Right.Left, item.Right.Right)))
+ .Combine(shaderInterfaces)
+ .Select(static (item, token) => (item.Left, Type: GetShaderType(item.Left.Symbol, item.Right.Compute, item.Right.Pixel)))
.Where(static item => item.Type is not null)
.Select(static (item, token) => (item.Left.Syntax, item.Left.Symbol, HierarchyInfo.From(item.Left.Symbol), item.Type!));
@@ -71,30 +68,24 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
context.AddSource($"{item.Hierarchy.FilenameHint}.GetDispatchId", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8));
});
- // Get the [EmbeddedBytecode] attribute
- IncrementalValueProvider embeddedBytecodeSymbol =
- context.CompilationProvider
- .Select(static (compilation, token) => compilation.GetTypeByMetadataName(typeof(EmbeddedBytecodeAttribute).FullName)!);
-
// Get the dispatch data, HLSL source and embedded bytecode info. This info is computed on the
// same step as parts are shared in following sub-branches in the incremental generator pipeline.
IncrementalValuesProvider<(Result Dispatch, Result Hlsl, Result ThreadIds)> shaderInfoWithErrors =
shaderDeclarations
.Combine(context.CompilationProvider)
- .Combine(embeddedBytecodeSymbol)
.Select(static (item, token) =>
{
// LoadDispatchData() info
ImmutableArray fieldInfos = LoadDispatchData.GetInfo(
- item.Left.Left.Symbol,
- item.Left.Left.Type,
+ item.Left.Symbol,
+ item.Left.Type,
out int resourceCount,
out int root32BitConstantCount,
out ImmutableArray dispatchDataDiagnostics);
Result dispatchDataInfo = new(new DispatchDataInfo(
- item.Left.Left.Hierarchy,
- item.Left.Left.Type,
+ item.Left.Hierarchy,
+ item.Left.Type,
fieldInfos,
resourceCount,
root32BitConstantCount),
@@ -102,15 +93,14 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
// BuildHlslString() info
HlslSourceInfo hlslSourceInfo = BuildHlslString.GetInfo(
- item.Left.Right,
- item.Left.Left.Syntax,
- item.Left.Left.Symbol,
+ item.Right,
+ item.Left.Syntax,
+ item.Left.Symbol,
out ImmutableArray hlslSourceDiagnostics);
// TryGetBytecode() info
ThreadIdsInfo threadIds = TryGetBytecode.GetInfo(
- item.Right,
- item.Left.Left.Symbol,
+ item.Left.Symbol,
!hlslSourceInfo.Delegates.IsEmpty,
out ImmutableArray threadIdsDiagnostics);