From ffcfcb3471ad463b48fb6107f052568995afac49 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 May 2022 00:24:38 +0200 Subject: [PATCH] Ensure function exports for shaders don't specify a target --- .../Shaders/Translation/D3DCompiler.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs index 9a486caf..21307121 100644 --- a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs +++ b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs @@ -44,11 +44,12 @@ internal static unsafe partial class D3DCompiler { // Compile the standalone D2D1 full shader using ComPtr d3DBlobFullShader = CompileShader( - buffer.AsSpan(0, writtenBytes), - ASCII.D2D_FULL_SHADER, - ASCII.Execute, - ASCII.GetPixelShaderProfile(shaderProfile), - D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR); + source: buffer.AsSpan(0, writtenBytes), + macro: ASCII.D2D_FULL_SHADER, + 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); if (!enableLinkingSupport) { @@ -57,11 +58,12 @@ internal static unsafe partial class D3DCompiler // Compile the export function using ComPtr d3DBlobFunction = CompileShader( - buffer.AsSpan(0, writtenBytes), - ASCII.D2D_FUNCTION, - ASCII.Execute, - ASCII.GetLibraryProfile(shaderProfile), - D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE.D3DCOMPILE_PACK_MATRIX_ROW_MAJOR); + source: buffer.AsSpan(0, writtenBytes), + macro: ASCII.D2D_FUNCTION, + 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); // Embed it as private data if requested using ComPtr d3DBlobLinked = SetD3DPrivateData(d3DBlobFullShader.Get(), d3DBlobFunction.Get()); @@ -79,6 +81,7 @@ internal static unsafe partial class D3DCompiler /// /// The HLSL source code to compile (in ASCII). /// The target macro to define for the shader (either D2D_FULL_SHADER or D2D_FUNCTION). + /// The D2D entry to specify when compiling the shader. /// The entry point for the shader. /// The shader target to use to compile the input source. /// The compilationm flag to use. @@ -87,6 +90,7 @@ internal static unsafe partial class D3DCompiler public static ComPtr CompileShader( ReadOnlySpan source, ReadOnlySpan macro, + ReadOnlySpan d2DEntry, ReadOnlySpan entryPoint, ReadOnlySpan target, uint flags) @@ -98,13 +102,14 @@ internal static unsafe partial class D3DCompiler fixed (byte* sourcePtr = source) fixed (byte* macroPtr = macro) + fixed (byte* d2DEntryPtr = d2DEntry) fixed (byte* entryPointPtr = entryPoint) fixed (byte* targetPtr = target) { // Prepare the macros for full shader compilation: // // -D - // -D D2D_ENTRY= + // -D D2D_ENTRY= // D3D_SHADER_MACRO* macros = stackalloc D3D_SHADER_MACRO[] { @@ -116,7 +121,7 @@ internal static unsafe partial class D3DCompiler new() { Name = (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.D2D_ENTRY)), - Definition = (sbyte*)entryPointPtr + Definition = (sbyte*)d2DEntryPtr }, new() };