Enable StripReflectionData flag in D2D generator

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-07 12:01:19 +01:00
1 親 b01e59ea1d
コミット 7726ba445e
3ファイル変更
+38 -8

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

+2
ファイルの表示
@@ -1,5 +1,6 @@
D3DCompile
D3DSetBlobPart
D3DStripShader
D2D1_BUFFER_PRECISION
D2D1_CHANNEL_DEPTH
D2D1_FILTER
@@ -19,6 +20,7 @@ D3DCOMPILE_OPTIMIZATION_LEVEL1
D3DCOMPILE_OPTIMIZATION_LEVEL2
D3DCOMPILE_OPTIMIZATION_LEVEL3
D3DCOMPILE_WARNINGS_ARE_ERRORS
D3DCOMPILER_STRIP_FLAGS
IUnknown
S_OK
S_FALSE
+8 -4
ファイルの表示
@@ -65,11 +65,13 @@ public static class D2D1ShaderCompiler
D2D1ShaderProfile shaderProfile,
D2D1CompileOptions options)
{
// Check linking support
// Check the additional compile options (not provided by FXC directly)
bool enableLinking = (options & D2D1CompileOptions.EnableLinking) == D2D1CompileOptions.EnableLinking;
bool stripReflectionData = (options & D2D1CompileOptions.StripReflectionData) == D2D1CompileOptions.StripReflectionData;
// Remove the linking flag to make the options blittable to flags
// Remove the additional options to make them blittable to flags
options &= ~D2D1CompileOptions.EnableLinking;
options &= ~D2D1CompileOptions.StripReflectionData;
// Compile the standalone D2D1 full shader
using ComPtr<ID3DBlob> d3DBlobFullShader = D3DCompiler.Compile(
@@ -78,7 +80,8 @@ public static class D2D1ShaderCompiler
d2DEntry: entryPointAscii,
entryPoint: entryPointAscii,
target: ASCII.GetPixelShaderProfile(shaderProfile),
flags: (uint)options);
flags: (uint)options,
stripReflectionData: stripReflectionData);
if (!enableLinking)
{
@@ -95,7 +98,8 @@ public static class D2D1ShaderCompiler
d2DEntry: entryPointAscii,
entryPoint: default,
target: ASCII.GetLibraryProfile(shaderProfile),
flags: (uint)options);
flags: (uint)options,
stripReflectionData: stripReflectionData);
// Embed it as private data if requested
using ComPtr<ID3DBlob> d3DBlobLinked = D3DCompiler.SetD3DPrivateData(d3DBlobFullShader.Get(), d3DBlobFunction.Get());
+28 -4
ファイルの表示
@@ -50,6 +50,12 @@ internal static unsafe partial class D3DCompiler
writtenBytes = Encoding.ASCII.GetBytes(source, buffer);
#endif
bool enableLinking = (options & D2D1CompileOptions.EnableLinking) == D2D1CompileOptions.EnableLinking;
bool stripReflectionData = (options & D2D1CompileOptions.StripReflectionData) == D2D1CompileOptions.StripReflectionData;
options &= ~D2D1CompileOptions.EnableLinking;
options &= ~D2D1CompileOptions.StripReflectionData;
try
{
// Compile the standalone D2D1 full shader
@@ -59,9 +65,10 @@ internal static unsafe partial class D3DCompiler
d2DEntry: ASCII.Execute,
entryPoint: ASCII.Execute,
target: ASCII.GetPixelShaderProfile(shaderProfile),
flags: (uint)(options & ~D2D1CompileOptions.EnableLinking));
flags: (uint)options,
stripReflectionData: stripReflectionData);
if ((options & D2D1CompileOptions.EnableLinking) == 0)
if (!enableLinking)
{
return d3DBlobFullShader.Move();
}
@@ -73,7 +80,8 @@ internal static unsafe partial class D3DCompiler
d2DEntry: ASCII.Execute,
entryPoint: default,
target: ASCII.GetLibraryProfile(shaderProfile),
flags: (uint)(options & ~D2D1CompileOptions.EnableLinking));
flags: (uint)options,
stripReflectionData: stripReflectionData);
// Embed it as private data if requested
using ComPtr<ID3DBlob> d3DBlobLinked = SetD3DPrivateData(d3DBlobFullShader.Get(), d3DBlobFunction.Get());
@@ -95,6 +103,7 @@ internal static unsafe partial class D3DCompiler
/// <param name="entryPoint">The entry point for the shader.</param>
/// <param name="target">The shader target to use to compile the input source.</param>
/// <param name="flags">The compilationm flag to use.</param>
/// <param name="stripReflectionData">Whether to strip reflection data from the shader bytecode.</param>
/// <returns>The bytecode for the compiled shader.</returns>
/// <exception cref="FxcCompilationException">Thrown if the compilation fails.</exception>
public static ComPtr<ID3DBlob> Compile(
@@ -103,7 +112,8 @@ internal static unsafe partial class D3DCompiler
ReadOnlySpan<byte> d2DEntry,
ReadOnlySpan<byte> entryPoint,
ReadOnlySpan<byte> target,
uint flags)
uint flags,
bool stripReflectionData)
{
using ComPtr<ID3DBlob> d3DBlobBytecode = default;
using ComPtr<ID3DBlob> d3DBlobErrors = default;
@@ -181,6 +191,20 @@ internal static unsafe partial class D3DCompiler
// there would always be a message), but better safe than sorry.
hResult.Assert();
// If requested, strip the reflection data and return that bytecode blob
if (stripReflectionData)
{
using ComPtr<ID3DBlob> d3DBlobBytecodeNoReflection = default;
DirectX.D3DStripShader(
pShaderBytecode: d3DBlobBytecode.Get()->GetBufferPointer(),
BytecodeLength: d3DBlobBytecode.Get()->GetBufferSize(),
uStripFlags: (uint)D3DCOMPILER_STRIP_FLAGS.D3DCOMPILER_STRIP_REFLECTION_DATA,
ppStrippedBlob: d3DBlobBytecodeNoReflection.GetAddressOf()).Assert();
return d3DBlobBytecodeNoReflection.Move();
}
return d3DBlobBytecode.Move();
}