Simplify HlslBytecodeInfoKey model

このコミットが含まれているのは:
Sergio Pedri committed 2023-10-03 01:15:04 +02:00
1 親 1029ad2622
コミット 610fc5808e
4ファイル変更
+19 -23

検索条件に一致するファイルはありません

@@ -21,7 +21,7 @@ partial class D2DPixelShaderDescriptorGenerator
{
writer.WriteLine("/// <inheritdoc/>");
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};");
}
/// <summary>
@@ -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()}")
@@ -87,9 +87,13 @@ partial class D2DPixelShaderDescriptorGenerator
/// Gets the effective shader profile to use.
/// </summary>
/// <param name="shaderProfile">The requested shader profile.</param>
/// <param name="isCompilationEnabled">Whether compilation should be performed with the input profile.</param>
/// <returns>The effective shader profile.</returns>
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<ID3DBlob> dxcBlobBytecode = D3DCompiler.Compile(
key.HlslSource.AsSpan(),
key.EffectiveShaderProfile,
key.EffectiveCompileOptions);
key.ShaderProfile,
key.CompileOptions);
token.ThrowIfCancellationRequested();
+2 -5
ファイルの表示
@@ -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);
+6 -10
ファイルの表示
@@ -4,15 +4,11 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
/// A model with info to be a unique key for <see cref="HlslBytecodeInfo"/> instances.
/// </summary>
/// <param name="HlslSource">The input HLSL source code.</param>
/// <param name="RequestedShaderProfile">The requested shader profile, if available.</param>
/// <param name="RequestedCompileOptions">The requested compile options, if available.</param>
/// <param name="EffectiveShaderProfile">The effective shader profile.</param>
/// <param name="EffectiveCompileOptions">The effective compile options.</param>
/// <param name="HasErrors">Whether any errors were produced when analyzing the shader.</param>
/// <param name="ShaderProfile">The shader profile.</param>
/// <param name="CompileOptions">The compile options.</param>
/// <param name="IsCompilationEnabled">Whether compilation should be attempted for the current info.</param>
internal sealed record HlslBytecodeInfoKey(
string HlslSource,
D2D1ShaderProfile? RequestedShaderProfile,
D2D1CompileOptions? RequestedCompileOptions,
D2D1ShaderProfile EffectiveShaderProfile,
D2D1CompileOptions EffectiveCompileOptions,
bool HasErrors);
D2D1ShaderProfile ShaderProfile,
D2D1CompileOptions CompileOptions,
bool IsCompilationEnabled);