From d75993107af3c8c91663ee2e23aef5249afd0e85 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 22 May 2022 15:50:28 +0200 Subject: [PATCH] Wire up [D2D1CompileOptions] to all generated code and public APIs Also removes the diagnostics for invalid linking setup --- .../AnalyzerReleases.Shipped.md | 1 - .../Diagnostics/DiagnosticDescriptors.cs | 16 ---- ...nerator.CreateLoadBytecodeMethod.Syntax.cs | 77 +++++++++++++++---- ...haderGenerator.CreateLoadBytecodeMethod.cs | 32 ++++---- .../ID2D1ShaderGenerator.cs | 18 +++-- .../Models/EmbeddedBytecodeInfo.cs | 8 +- .../Interfaces/__Internals/ID2D1Shader.cs | 3 +- .../Shaders/Interop/D2D1PixelShader.cs | 36 ++++++++- .../Shaders/Interop/D2D1ReflectionServices.cs | 2 +- .../__Internals/D2D1ShaderCompiler.cs | 8 +- 10 files changed, 133 insertions(+), 68 deletions(-) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md index 7bd22acc..72d09bf1 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md @@ -51,4 +51,3 @@ 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) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index ff19b8e0..0e8167b3 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -634,20 +634,4 @@ 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"); - - /// - /// Gets a for the EnableLinking option being used. - /// - /// Format: "The D2D1 shader of type {0} is using the EnableLinking option in its [D2DCompileOptions] attribute for a non-linkable shader". - /// - /// - 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"); } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs index fcb97fa9..391851ba 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Linq; using ComputeSharp.__Internals; using ComputeSharp.D2D1.__Internals; using ComputeSharp.D2D1.SourceGenerators.Models; @@ -39,7 +40,7 @@ partial class ID2D1ShaderGenerator // This code produces a method declaration as follows: // - // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadBytecode(ref TLoader loader, global::ComputeSharp.D2D1.D2D1ShaderProfile? shaderProfile) + // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadBytecode(ref TLoader loader, global::ComputeSharp.D2D1.D2D1ShaderProfile? shaderProfile, global::ComputeSharp.D2D1.D2D1CompileOptions? options) // { // // } @@ -50,7 +51,8 @@ partial class ID2D1ShaderGenerator .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters( Parameter(Identifier("loader")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(IdentifierName("TLoader")), - Parameter(Identifier("shaderProfile")).WithType(NullableType(IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile")))) + Parameter(Identifier("shaderProfile")).WithType(NullableType(IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"))), + Parameter(Identifier("options")).WithType(NullableType(IdentifierName("global::ComputeSharp.D2D1.D2D1CompileOptions")))) .WithBody(block); } @@ -62,9 +64,38 @@ partial class ID2D1ShaderGenerator /// The instance trying to retrieve the precompiled shader. private static unsafe BlockSyntax GetShaderBytecodeBody(EmbeddedBytecodeInfo bytecodeInfo, out string? bytecodeLiterals) { + // This method needs to handle several different scenarions, which are as follows: + // 1) If [EmbeddedBytecode] is used, then the shader is precompiled and stored as a ReadOnlySpan. In this case, + // this bytecode would have been generated with some specific D2D1ShaderProfile and D2D1CompileOptions values. So, + // a branch is generated to try to retrieve this precompiled bytecode, which can be returned if and only if the + // requested shader profile and compile options are either null, or either matches the values that have been used + // to generate that bytecode. If this is the case, then no further work is done and that binary data is returned. + // 2) If either the requested shader profile or options do not match the values used to create the shader bytecode, + // then a call to the internal D2D1ShaderCompiler.LoadDynamicBytecode API is used, to create the shader on the fly. + // 3) If [EmbeddedBytecode] is not used, then regardless of the requested profile and options, a new shader is compiled. + // 4) If this is the case and either the shader profile or the options are null, then this method will manually set the + // value being null to the default one to use. That is, D2D1ShaderProfile.PixelShader50 will be used as the target, + // and the options will be set to D2D1CompileOptions.Default (and optionally, D2D1CompileOptions.EnableLinking too). + + // Get a formatted representation of the compile options being used + ExpressionSyntax optionsExpression = + ParseExpression( + bytecodeInfo.CompileOptions + .GetValueOrDefault() + .ToString(CultureInfo.InvariantCulture) + .Split(',') + .Select(static name => $"global::ComputeSharp.D2D1.D2D1CompileOptions.{name.Trim()}") + .Aggregate("", static (left, right) => left.Length > 0 ? $"{left} | {right}" : right)); + + // Add parantheses if needed + if (optionsExpression is BinaryExpressionSyntax) + { + optionsExpression = ParenthesizedExpression(optionsExpression); + } + // This code produces a method declaration as follows: // - // ComputeSharp.D2D1.__Internals.D2D1ShaderCompiler.LoadDynamicBytecode(ref loader, in this, shaderProfile, ); + // ComputeSharp.D2D1.__Internals.D2D1ShaderCompiler.LoadDynamicBytecode(ref loader, in this, shaderProfile ?? , options ?? ); ExpressionStatementSyntax dynamicLoadingStatement = ExpressionStatement( InvocationExpression( @@ -75,8 +106,14 @@ partial class ID2D1ShaderGenerator .AddArgumentListArguments( Argument(IdentifierName("loader")).WithRefKindKeyword(Token(SyntaxKind.RefKeyword)), Argument(ThisExpression()).WithRefKindKeyword(Token(SyntaxKind.InKeyword)), - Argument(IdentifierName("shaderProfile")), - Argument(LiteralExpression(bytecodeInfo.IsLinkingSupported ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression)))); + Argument(BinaryExpression( + SyntaxKind.CoalesceExpression, + IdentifierName("shaderProfile"), + IdentifierName($"global::ComputeSharp.D2D1.D2D1ShaderProfile.{D2D1ShaderProfile.PixelShader50}"))), + Argument(BinaryExpression( + SyntaxKind.CoalesceExpression, + IdentifierName("options"), + optionsExpression)))); // If there is no precompiled bytecode, just return the dynamic path if (bytecodeInfo.Bytecode.IsDefaultOrEmpty) @@ -90,7 +127,7 @@ partial class ID2D1ShaderGenerator // This code produces a branch as follows: // - // if (shaderProfile is null or ) + // if (shaderProfile is null or && options is null or ) // { // global::System.ReadOnlySpan bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE }; // loader.LoadEmbeddedBytecode(bytecode); @@ -101,16 +138,24 @@ partial class ID2D1ShaderGenerator // having to create/parse tens of thousands of literal expression nodes for every shader. IfStatementSyntax embeddedBranch = IfStatement( - IsPatternExpression( - IdentifierName("shaderProfile"), - BinaryPattern( - SyntaxKind.OrPattern, - ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)), - ConstantPattern( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"), - IdentifierName(bytecodeInfo.ShaderProfile.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)))))), + BinaryExpression( + SyntaxKind.LogicalAndExpression, + IsPatternExpression( + IdentifierName("shaderProfile"), + BinaryPattern( + SyntaxKind.OrPattern, + ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)), + ConstantPattern( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"), + IdentifierName(bytecodeInfo.ShaderProfile.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)))))), + IsPatternExpression( + IdentifierName("options"), + BinaryPattern( + SyntaxKind.OrPattern, + ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)), + ConstantPattern(optionsExpression)))), Block( LocalDeclarationStatement( VariableDeclaration( diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs index 973418f7..7f29ba5d 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs @@ -46,12 +46,8 @@ partial class ID2D1ShaderGenerator /// /// The collection of produced instances. /// The input instance to process. - /// Whether or not linking is supported for the current shader. /// The compile options to use to compile the shader, if present. - public static D2D1CompileOptions? GetCompileOptions( - ImmutableArray.Builder diagnostics, - INamedTypeSymbol structDeclarationSymbol, - bool isLinkingSupported) + public static D2D1CompileOptions? GetCompileOptions(ImmutableArray.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol) { if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) { @@ -65,14 +61,6 @@ partial class ID2D1ShaderGenerator structDeclarationSymbol); } - if ((options & D2D1CompileOptions.EnableLinking) != 0 && !isLinkingSupported) - { - diagnostics.Add( - InvalidEnableLinkingOption, - structDeclarationSymbol, - structDeclarationSymbol); - } - // PackMatrixRowMajor is always automatically enabled return options | D2D1CompileOptions.PackMatrixRowMajor; } @@ -109,9 +97,14 @@ partial class ID2D1ShaderGenerator /// /// The source info for the shader to compile. /// The used to cancel the operation, if needed. + /// The effective compile options used to create the shader bytecode. /// The resulting diagnostic from the processing operation, if any. /// The instance with the compiled shader bytecode. - public static unsafe ImmutableArray GetBytecode(HlslShaderSourceInfo sourceInfo, CancellationToken token, out DiagnosticInfo? diagnostic) + public static unsafe ImmutableArray GetBytecode( + HlslShaderSourceInfo sourceInfo, + CancellationToken token, + out D2D1CompileOptions options, + out DiagnosticInfo? diagnostic) { ImmutableArray bytecode = ImmutableArray.Empty; @@ -120,6 +113,7 @@ partial class ID2D1ShaderGenerator // Compiling would just add overhead and result in more errors, as the HLSL would be invalid. if (sourceInfo is { HasErrors: true } or { ShaderProfile: null }) { + options = default; diagnostic = null; goto End; @@ -129,11 +123,15 @@ partial class ID2D1ShaderGenerator { token.ThrowIfCancellationRequested(); - // Compile the shader bytecode + // If an explicit set of compile options is provided, use that directly. Otherwise, use the default + // options plus the option to enable linking only if the shader can potentially support it. + options = sourceInfo.CompileOptions ?? (D2D1CompileOptions.Default | (sourceInfo.IsLinkingSupported ? D2D1CompileOptions.EnableLinking : 0)); + + // Compile the shader bytecode using the requested parameters using ComPtr dxcBlobBytecode = D3DCompiler.Compile( sourceInfo.HlslSource.AsSpan(), sourceInfo.ShaderProfile.Value, - sourceInfo.CompileOptions ?? D2D1CompileOptions.Default); + options); token.ThrowIfCancellationRequested(); @@ -147,10 +145,12 @@ partial class ID2D1ShaderGenerator } catch (Win32Exception e) { + options = default; diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message)); } catch (FxcCompilationException e) { + options = default; diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message)); } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 3599fac4..9005fb51 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -92,16 +92,16 @@ 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, isLinkingSupported); + D2D1CompileOptions? compileOptions = LoadBytecode.GetCompileOptions(diagnostics, item.Left.Symbol); + bool isLinkingSupported = LoadBytecode.IsSimpleInputShader(item.Left.Symbol, inputCount); HlslShaderSourceInfo sourceInfo = new( hlslSource, shaderProfile, compileOptions, isLinkingSupported, - diagnostics.Count > 0); + HasErrors: diagnostics.Count > 0); token.ThrowIfCancellationRequested(); @@ -202,11 +202,19 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator shaderBytecodeInfo .Select(static (item, token) => { - ImmutableArray bytecode = LoadBytecode.GetBytecode(item.Source, token, out DiagnosticInfo? diagnostic); + ImmutableArray bytecode = LoadBytecode.GetBytecode( + item.Source, + token, + out D2D1CompileOptions options, + out DiagnosticInfo? diagnostic); token.ThrowIfCancellationRequested(); - EmbeddedBytecodeInfo bytecodeInfo = new(item.Source.HlslSource, item.Source.ShaderProfile, item.Source.IsLinkingSupported, bytecode); + EmbeddedBytecodeInfo bytecodeInfo = new( + item.Source.HlslSource, + item.Source.ShaderProfile, + options, + bytecode); return (item.Hierarchy, bytecodeInfo, diagnostic); }); diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs index 385b0144..532a839e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/EmbeddedBytecodeInfo.cs @@ -11,9 +11,9 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// /// The HLSL source for the shader. /// The shader profile to use to compile the shader, if requested. -/// Whether linking is supported for the current shader. +/// The compile options to use to compile the shader. /// The compiled shader bytecode, if available. -internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, bool IsLinkingSupported, ImmutableArray Bytecode) +internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile? ShaderProfile, D2D1CompileOptions? CompileOptions, ImmutableArray Bytecode) { /// /// An implementation for . @@ -25,7 +25,7 @@ internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile { hashCode.Add(obj.HlslSource); hashCode.Add(obj.ShaderProfile); - hashCode.Add(obj.IsLinkingSupported); + hashCode.Add(obj.CompileOptions); hashCode.AddBytes(obj.Bytecode.AsSpan()); } @@ -35,7 +35,7 @@ internal sealed record EmbeddedBytecodeInfo(string HlslSource, D2D1ShaderProfile return x.HlslSource == y.HlslSource && x.ShaderProfile == y.ShaderProfile && - x.IsLinkingSupported == y.IsLinkingSupported && + x.CompileOptions == y.CompileOptions && x.Bytecode.SequenceEqual(y.Bytecode); } } diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs index 0c4fe02c..cfc6814f 100644 --- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs +++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs @@ -88,9 +88,10 @@ public interface ID2D1Shader /// The type of bytecode loader being used. /// The instance to use to load the bytecode. /// The shader profile to use to get the shader bytecode (if , the precompiled shader will be used). + /// The compile options to use to get the shader bytecode (if , the precompiled shader will be used). /// Thrown if a precompiled bytecode was requested ( is ), but it wasn't availablle. [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method is not intended to be used directly by user code")] - void LoadBytecode(ref TLoader loader, D2D1ShaderProfile? shaderProfile) + void LoadBytecode(ref TLoader loader, D2D1ShaderProfile? shaderProfile, D2D1CompileOptions? options) where TLoader : struct, ID2D1BytecodeLoader; } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index afcb0287..f4c58bb9 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -30,7 +30,7 @@ public static class D2D1PixelShader public static ReadOnlyMemory LoadBytecode() where T : unmanaged, ID2D1PixelShader { - return LoadOrCompileBytecode(null); + return LoadOrCompileBytecode(null, null); } /// @@ -40,13 +40,40 @@ public static class D2D1PixelShader /// The shader profile to use to get the shader bytecode. /// A instance with the resulting shader bytecode. /// + /// + /// If precompiled shader for the profile does not exist, the shader will be compiled with either the custom compile options specified on the shader + /// type (through ), or using otherwise. + /// + /// + /// Additionally, in case no custom compile options are specified and the the shader type + /// supports linking, will also be automatically added. + /// + /// /// If the input shader was precompiled, the returned instance will wrap a pinned memory buffer (from the PE section). /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. + /// /// public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile) where T : unmanaged, ID2D1PixelShader { - return LoadOrCompileBytecode(shaderProfile); + return LoadOrCompileBytecode(shaderProfile, null); + } + + /// + /// Loads the bytecode from an input D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to load the bytecode for. + /// The shader profile to use to get the shader bytecode. + /// The compile options to use to get the shader bytecode. + /// A instance with the resulting shader bytecode. + /// + /// If the input shader was precompiled, the returned instance will wrap a pinned memory buffer (from the PE section). + /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. + /// + public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile, D2D1CompileOptions options) + where T : unmanaged, ID2D1PixelShader + { + return LoadOrCompileBytecode(shaderProfile, options); } /// @@ -54,16 +81,17 @@ public static class D2D1PixelShader /// /// The type of D2D1 pixel shader to load the bytecode for. /// The shader profile to use to get the shader bytecode. + /// The compile options to use to get the shader bytecode. /// A instance with the resulting shader bytecode. /// Thrown if the input shader has not been precompiled. - private static unsafe ReadOnlyMemory LoadOrCompileBytecode(D2D1ShaderProfile? shaderProfile) + private static unsafe ReadOnlyMemory LoadOrCompileBytecode(D2D1ShaderProfile? shaderProfile, D2D1CompileOptions? options) where T : unmanaged, ID2D1PixelShader { D2D1ShaderBytecodeLoader bytecodeLoader = default; Unsafe.SkipInit(out T shader); - shader.LoadBytecode(ref bytecodeLoader, shaderProfile); + shader.LoadBytecode(ref bytecodeLoader, shaderProfile, options); using ComPtr dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan precompiledBytecode); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs index f82b577c..ed93b63e 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs @@ -29,7 +29,7 @@ public static class D2D1ReflectionServices D2D1ShaderBytecodeLoader bytecodeLoader = default; - shader.LoadBytecode(ref bytecodeLoader, D2D1ShaderProfile.PixelShader50); + shader.LoadBytecode(ref bytecodeLoader, D2D1ShaderProfile.PixelShader50, D2D1CompileOptions.Default); using ComPtr dynamicBytecode = bytecodeLoader.GetResultingShaderBytecode(out ReadOnlySpan precompiledBytecode); diff --git a/src/ComputeSharp.D2D1/Shaders/Translation/__Internals/D2D1ShaderCompiler.cs b/src/ComputeSharp.D2D1/Shaders/Translation/__Internals/D2D1ShaderCompiler.cs index 3d5cfbbd..0802f677 100644 --- a/src/ComputeSharp.D2D1/Shaders/Translation/__Internals/D2D1ShaderCompiler.cs +++ b/src/ComputeSharp.D2D1/Shaders/Translation/__Internals/D2D1ShaderCompiler.cs @@ -21,8 +21,8 @@ public static class D2D1ShaderCompiler /// The instance to use to load the bytecode. /// The input instance representing the D2D1 shader to run. /// The shader profile to use to compile the shader. - /// Whether to enable linking support for the shader. - public static unsafe void LoadDynamicBytecode(ref TLoader loader, in T shader, D2D1ShaderProfile? shaderProfile, bool enableLinkingSupport) + /// The compiler options to use to compile the shader. + public static unsafe void LoadDynamicBytecode(ref TLoader loader, in T shader, D2D1ShaderProfile shaderProfile, D2D1CompileOptions options) where TLoader : struct, ID2D1BytecodeLoader where T : struct, ID2D1Shader { @@ -30,8 +30,8 @@ public static class D2D1ShaderCompiler using ComPtr d3DBlobBytecode = Shaders.Translation.D3DCompiler.Compile( hlslSource.AsSpan(), - shaderProfile ?? D2D1ShaderProfile.PixelShader50, - D2D1CompileOptions.Default | (enableLinkingSupport ? D2D1CompileOptions.EnableLinking : 0)); + shaderProfile, + options); loader.LoadDynamicBytecode((IntPtr)d3DBlobBytecode.Get()); }