Add stripping DXIL debug data from the shader cache when not used
This commit is contained in:
@@ -76,16 +76,19 @@ ShaderCompilerDX::ShaderCompilerDX(ShaderProfile profile, PlatformType platform,
|
||||
{
|
||||
IDxcCompiler3* compiler = nullptr;
|
||||
IDxcLibrary* library = nullptr;
|
||||
IDxcContainerBuilder* builder = nullptr;
|
||||
IDxcContainerReflection* containerReflection = nullptr;
|
||||
DxcCreateInstanceProc createInstance = dxcCreateInstanceProc ? (DxcCreateInstanceProc)dxcCreateInstanceProc : &DxcCreateInstance;
|
||||
if (FAILED(createInstance(CLSID_DxcCompiler, __uuidof(compiler), reinterpret_cast<void**>(&compiler))) ||
|
||||
FAILED(createInstance(CLSID_DxcLibrary, __uuidof(library), reinterpret_cast<void**>(&library))) ||
|
||||
FAILED(createInstance(CLSID_DxcContainerBuilder, __uuidof(builder), reinterpret_cast<void**>(&builder))) ||
|
||||
FAILED(createInstance(CLSID_DxcContainerReflection, __uuidof(containerReflection), reinterpret_cast<void**>(&containerReflection))))
|
||||
{
|
||||
LOG(Error, "DxcCreateInstance failed");
|
||||
}
|
||||
_compiler = compiler;
|
||||
_library = library;
|
||||
_builder = builder;
|
||||
_containerReflection = containerReflection;
|
||||
static HashSet<void*> PrintVersions;
|
||||
if (PrintVersions.Add(createInstance))
|
||||
@@ -103,14 +106,13 @@ ShaderCompilerDX::ShaderCompilerDX(ShaderProfile profile, PlatformType platform,
|
||||
|
||||
ShaderCompilerDX::~ShaderCompilerDX()
|
||||
{
|
||||
auto compiler = (IDxcCompiler2*)_compiler;
|
||||
if (compiler)
|
||||
if (auto compiler = (IDxcCompiler2*)_compiler)
|
||||
compiler->Release();
|
||||
auto library = (IDxcLibrary*)_library;
|
||||
if (library)
|
||||
if (auto library = (IDxcLibrary*)_library)
|
||||
library->Release();
|
||||
auto containerReflection = (IDxcContainerReflection*)_containerReflection;
|
||||
if (containerReflection)
|
||||
if (auto builder = (IDxcContainerBuilder*)_builder)
|
||||
builder->Release();
|
||||
if (auto containerReflection = (IDxcContainerReflection*)_containerReflection)
|
||||
containerReflection->Release();
|
||||
}
|
||||
|
||||
@@ -254,7 +256,7 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
}
|
||||
|
||||
// Get the output
|
||||
ComPtr<IDxcBlob> shaderBuffer = nullptr;
|
||||
ComPtr<IDxcBlob> shaderBuffer;
|
||||
if (FAILED(results->GetResult(&shaderBuffer)))
|
||||
{
|
||||
LOG(Error, "IDxcOperationResult::GetResult failed.");
|
||||
@@ -460,6 +462,28 @@ bool ShaderCompilerDX::CompileShader(ShaderFunctionMeta& meta, WritePermutationD
|
||||
}
|
||||
}
|
||||
|
||||
// Strip reflection data
|
||||
if (!options->GenerateDebugData)
|
||||
{
|
||||
if (auto builder = (IDxcContainerBuilder*)_builder)
|
||||
{
|
||||
if (builder->Load(shaderBuffer) == S_OK)
|
||||
{
|
||||
builder->RemovePart(DXC_PART_PDB);
|
||||
builder->RemovePart(DXC_PART_REFLECTION_DATA);
|
||||
ComPtr<IDxcOperationResult> serializeResult;
|
||||
if (builder->SerializeContainer(&serializeResult) == S_OK)
|
||||
{
|
||||
ComPtr<IDxcBlob> optimizedShaderBuffer;
|
||||
if (SUCCEEDED(serializeResult->GetResult(&optimizedShaderBuffer)))
|
||||
{
|
||||
shaderBuffer = optimizedShaderBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteShaderFunctionPermutation(_context, meta, permutationIndex, bindings, &header, sizeof(header), shaderBuffer->GetBufferPointer(), (int32)shaderBuffer->GetBufferSize()))
|
||||
return true;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ private:
|
||||
Array<char> _funcNameDefineBuffer;
|
||||
void* _compiler;
|
||||
void* _library;
|
||||
void* _builder;
|
||||
void* _containerReflection;
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user