diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs
index 273bf081..8272b543 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateGetDispatchIdMethod.Syntax.cs
@@ -19,9 +19,10 @@ public sealed partial class IShaderGenerator
///
/// Creates a instance for the GetDispatchId method.
///
- ///The names of all instance fields within the current shader type.
+ /// The names of all instance fields within the current shader type.\
+ /// Indicates whether or not dynamic shaders are supported.
/// The resulting instance for the GetDispatchId method.
- public static MethodDeclarationSyntax GetSyntax(ImmutableArray delegateFieldNames)
+ public static MethodDeclarationSyntax GetSyntax(ImmutableArray delegateFieldNames, bool supportsDynamicShaders)
{
// This code produces a method declaration as follows:
//
@@ -35,18 +36,19 @@ public sealed partial class IShaderGenerator
Identifier("GetDispatchId"))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.__Internals.{nameof(IShader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
- .WithBody(GetShaderHashCodeBody(delegateFieldNames));
+ .WithBody(GetShaderHashCodeBody(delegateFieldNames, supportsDynamicShaders));
}
///
/// Gets a instance with the logic to compute the hashcode of a given shader type.
///
/// The names of all instance fields within the current shader type.
+ /// Indicates whether or not dynamic shaders are supported.
/// The instance to hash the input shader.
[Pure]
- private static BlockSyntax GetShaderHashCodeBody(ImmutableArray delegateFieldNames)
+ private static BlockSyntax GetShaderHashCodeBody(ImmutableArray delegateFieldNames, bool supportsDynamicShaders)
{
- if (delegateFieldNames.Length == 0)
+ if (delegateFieldNames.Length == 0 || !supportsDynamicShaders)
{
// return 0;
return
diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
index 0e42e6af..ba891525 100644
--- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.cs
@@ -67,12 +67,12 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
.WithComparers(HierarchyInfo.Comparer.Default, DispatchIdInfo.Comparer.Default);
// Generate the GetDispatchId() methods
- context.RegisterSourceOutput(hierarchyAndDispatchIdInfo, static (context, item) =>
+ context.RegisterSourceOutput(hierarchyAndDispatchIdInfo.Combine(supportsDynamicShaders), static (context, item) =>
{
- MethodDeclarationSyntax getDispatchIdMethod = GetDispatchId.GetSyntax(item.Info.Delegates);
- CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, getDispatchIdMethod, false);
+ MethodDeclarationSyntax getDispatchIdMethod = GetDispatchId.GetSyntax(item.Left.Info.Delegates, item.Right);
+ CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, getDispatchIdMethod, false);
- context.AddSource($"{item.Hierarchy.FilenameHint}.{nameof(GetDispatchId)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8));
+ context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(GetDispatchId)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8));
});
// Get the dispatch data, HLSL source and embedded bytecode info. This info is computed on the