Wire up [D2D1CompileOptions] to [D2D1EmbeddedBytecode]

このコミットが含まれているのは:
Sergio Pedri committed 2022-05-22 01:50:14 +02:00
1 親 0bfe836a4e
コミット b4b8b76d2f
6ファイル変更
+42 -13

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

+1
ファイルの表示
@@ -51,3 +51,4 @@ CMPSD2D0041 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0042 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0043 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0044 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0045 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -634,4 +634,20 @@ internal static class DiagnosticDescriptors
isEnabledByDefault: true,
description: "A D2D1 shader generated with ComputeSharp.D2D1 cannot use the PackMatrixColumnMajor option, as that is not compatible with the generated code used to load shader constant buffers.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for the EnableLinking option being used.
/// <para>
/// Format: <c>"The D2D1 shader of type {0} is using the EnableLinking option in its [D2DCompileOptions] attribute for a non-linkable shader"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidEnableLinkingOption = new DiagnosticDescriptor(
id: "CMPSD2D0045",
title: "Invalid EnableLinking compile option",
messageFormat: "The D2D1 shader of type {0} is using the EnableLinking option in its [D2DCompileOptions] attribute for a non-linkable shader",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A D2D1 shader generated with ComputeSharp.D2D1 cannot use the EnableLinking option if the shader is non-linkable (ie. if it has any complex inputs).",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
+17 -5
ファイルの表示
@@ -46,8 +46,12 @@ partial class ID2D1ShaderGenerator
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
/// <param name="isLinkingSupported">Whether or not linking is supported for the current shader.</param>
/// <returns>The compile options to use to compile the shader, if present.</returns>
public static D2D1CompileOptions? GetCompileOptions(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
public static D2D1CompileOptions? GetCompileOptions(
ImmutableArray<Diagnostic>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
bool isLinkingSupported)
{
if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData))
{
@@ -61,7 +65,16 @@ partial class ID2D1ShaderGenerator
structDeclarationSymbol);
}
return options;
if ((options & D2D1CompileOptions.EnableLinking) != 0 && !isLinkingSupported)
{
diagnostics.Add(
InvalidEnableLinkingOption,
structDeclarationSymbol,
structDeclarationSymbol);
}
// PackMatrixRowMajor is always automatically enabled
return options | D2D1CompileOptions.PackMatrixRowMajor;
}
return null;
@@ -105,8 +118,7 @@ partial class ID2D1ShaderGenerator
// No embedded shader was requested, or there were some 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.
if (sourceInfo.HasErrors ||
sourceInfo.ShaderProfile is null)
if (sourceInfo is { HasErrors: true } or { ShaderProfile: null })
{
diagnostic = null;
@@ -121,7 +133,7 @@ partial class ID2D1ShaderGenerator
using ComPtr<ID3DBlob> dxcBlobBytecode = D3DCompiler.Compile(
sourceInfo.HlslSource.AsSpan(),
sourceInfo.ShaderProfile.Value,
sourceInfo.IsLinkingSupported);
sourceInfo.CompileOptions ?? D2D1CompileOptions.Default);
token.ThrowIfCancellationRequested();
+2 -2
ファイルの表示
@@ -92,9 +92,9 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
token.ThrowIfCancellationRequested();
// Get the shader profile and linking info for LoadBytecode()
bool isLinkingSupported = LoadBytecode.IsSimpleInputShader(item.Left.Symbol, inputCount);
D2D1ShaderProfile? shaderProfile = LoadBytecode.GetShaderProfile(item.Left.Symbol);
D2D1CompileOptions? compileOptions = LoadBytecode.GetCompileOptions(diagnostics, item.Left.Symbol);
bool isLinkingSupported = diagnostics.Count == 0 && LoadBytecode.IsSimpleInputShader(item.Left.Symbol, inputCount);
D2D1CompileOptions? compileOptions = LoadBytecode.GetCompileOptions(diagnostics, item.Left.Symbol, isLinkingSupported);
HlslShaderSourceInfo sourceInfo = new(
hlslSource,
+5 -5
ファイルの表示
@@ -32,9 +32,9 @@ internal static unsafe partial class D3DCompiler
/// </summary>
/// <param name="source">The HLSL source code to compile.</param>
/// <param name="shaderProfile">The shader profile to use to compile the shader.</param>
/// <param name="enableLinking">Whether to enable linking for the shader.</param>
/// <param name="options">The options to use to compile the shader.</param>
/// <returns>The bytecode for the compiled shader.</returns>
public static ComPtr<ID3DBlob> Compile(ReadOnlySpan<char> source, D2D1ShaderProfile shaderProfile, bool enableLinking)
public static ComPtr<ID3DBlob> Compile(ReadOnlySpan<char> source, D2D1ShaderProfile shaderProfile, D2D1CompileOptions options)
{
int maxLength = Encoding.ASCII.GetMaxByteCount(source.Length);
byte[] buffer = ArrayPool<byte>.Shared.Rent(maxLength);
@@ -49,9 +49,9 @@ internal static unsafe partial class D3DCompiler
d2DEntry: ASCII.Execute,
entryPoint: ASCII.Execute,
target: ASCII.GetPixelShaderProfile(shaderProfile),
flags: D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR);
flags: (uint)(options & ~D2D1CompileOptions.EnableLinking));
if (!enableLinking)
if ((options & D2D1CompileOptions.EnableLinking) == 0)
{
return d3DBlobFullShader.Move();
}
@@ -63,7 +63,7 @@ internal static unsafe partial class D3DCompiler
d2DEntry: ASCII.Execute,
entryPoint: default,
target: ASCII.GetLibraryProfile(shaderProfile),
flags: D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR);
flags: (uint)(options & ~D2D1CompileOptions.EnableLinking));
// Embed it as private data if requested
using ComPtr<ID3DBlob> d3DBlobLinked = SetD3DPrivateData(d3DBlobFullShader.Get(), d3DBlobFunction.Get());
+1 -1
ファイルの表示
@@ -31,7 +31,7 @@ public static class D2D1ShaderCompiler
using ComPtr<ID3DBlob> d3DBlobBytecode = Shaders.Translation.D3DCompiler.Compile(
hlslSource.AsSpan(),
shaderProfile ?? D2D1ShaderProfile.PixelShader50,
enableLinkingSupport);
D2D1CompileOptions.Default | (enableLinkingSupport ? D2D1CompileOptions.EnableLinking : 0));
loader.LoadDynamicBytecode((IntPtr)d3DBlobBytecode.Get());
}