diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.Syntax.cs
index 242f61b5..2f65635c 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.Syntax.cs
@@ -21,7 +21,7 @@ partial class D2DPixelShaderDescriptorGenerator
{
writer.WriteLine("/// ");
writer.WriteGeneratedAttributes(GeneratorName);
- writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};");
+ writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.ShaderProfile};");
}
///
@@ -33,7 +33,7 @@ partial class D2DPixelShaderDescriptorGenerator
{
// Get a formatted representation of the compile options being used
string compileOptionsExpression =
- info.HlslInfoKey.EffectiveCompileOptions
+ info.HlslInfoKey.CompileOptions
.ToString()
.Split(',')
.Select(static name => $"global::ComputeSharp.D2D1.D2D1CompileOptions.{name.Trim()}")
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs
index 3784f2e2..7289f859 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.HlslBytecode.cs
@@ -87,9 +87,13 @@ partial class D2DPixelShaderDescriptorGenerator
/// Gets the effective shader profile to use.
///
/// The requested shader profile.
+ /// Whether compilation should be performed with the input profile.
/// The effective shader profile.
- public static D2D1ShaderProfile GetEffectiveShaderProfile(D2D1ShaderProfile? shaderProfile)
+ public static D2D1ShaderProfile GetEffectiveShaderProfile(D2D1ShaderProfile? shaderProfile, out bool isCompilationEnabled)
{
+ // Compilation is only enabled if the user explicitly selected a shader profile
+ isCompilationEnabled = shaderProfile is not null;
+
// The effective shader profile is either be the requested one, or the default value (which maps to PS5.0)
return shaderProfile ?? D2D1ShaderProfile.PixelShader50;
}
@@ -150,11 +154,10 @@ partial class D2DPixelShaderDescriptorGenerator
{
static unsafe HlslBytecodeInfo GetInfo(HlslBytecodeInfoKey key, CancellationToken token)
{
- // No embedded shader was requested, or there were some errors earlier in the pipeline.
+ // Check if the compilation is not enabled (eg. if there's been errors earlier in the pipeline).
// In this case, skip the compilation, as diagnostic will be emitted for those anyway.
// Compiling would just add overhead and result in more errors, as the HLSL would be invalid.
- // We also skip compilation if no shader profile has been requested (we never just assume one).
- if (key.HasErrors || key.RequestedShaderProfile is null)
+ if (!key.IsCompilationEnabled)
{
return HlslBytecodeInfo.Missing.Instance;
}
@@ -166,8 +169,8 @@ partial class D2DPixelShaderDescriptorGenerator
// Compile the shader bytecode using the effective parameters
using ComPtr dxcBlobBytecode = D3DCompiler.Compile(
key.HlslSource.AsSpan(),
- key.EffectiveShaderProfile,
- key.EffectiveCompileOptions);
+ key.ShaderProfile,
+ key.CompileOptions);
token.ThrowIfCancellationRequested();
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
index 9f83daa7..9342c22e 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.cs
@@ -140,9 +140,8 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
bool isLinkingSupported = HlslBytecode.IsSimpleInputShader(typeSymbol, inputCount);
D2D1ShaderProfile? requestedShaderProfile = HlslBytecode.GetRequestedShaderProfile(typeSymbol);
D2D1CompileOptions? requestedCompileOptions = HlslBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol);
- D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile);
+ D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile, out bool isCompilationEnabled);
D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported);
- bool hasErrors = diagnostics.Count > 0;
token.ThrowIfCancellationRequested();
@@ -150,11 +149,9 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
// This is done last so that it can be skipped if any errors happened before.
HlslBytecodeInfoKey hlslInfoKey = new(
hlslSource,
- requestedShaderProfile,
- requestedCompileOptions,
effectiveShaderProfile,
effectiveCompileOptions,
- hasErrors);
+ isCompilationEnabled);
// Get the existing compiled shader, or compile the processed HLSL code
HlslBytecodeInfo hlslInfo = HlslBytecode.GetInfo(ref hlslInfoKey, token);
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslBytecodeInfoKey.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslBytecodeInfoKey.cs
index 772e9aea..035f7144 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslBytecodeInfoKey.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/HlslBytecodeInfoKey.cs
@@ -4,15 +4,11 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// A model with info to be a unique key for instances.
///
/// The input HLSL source code.
-/// The requested shader profile, if available.
-/// The requested compile options, if available.
-/// The effective shader profile.
-/// The effective compile options.
-/// Whether any errors were produced when analyzing the shader.
+/// The shader profile.
+/// The compile options.
+/// Whether compilation should be attempted for the current info.
internal sealed record HlslBytecodeInfoKey(
string HlslSource,
- D2D1ShaderProfile? RequestedShaderProfile,
- D2D1CompileOptions? RequestedCompileOptions,
- D2D1ShaderProfile EffectiveShaderProfile,
- D2D1CompileOptions EffectiveCompileOptions,
- bool HasErrors);
\ No newline at end of file
+ D2D1ShaderProfile ShaderProfile,
+ D2D1CompileOptions CompileOptions,
+ bool IsCompilationEnabled);
\ No newline at end of file