mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-05 06:03:34 +00:00
Log HLSL for dump_shaders even if HLSL compilation fails
Fixed: dawn:1681 Change-Id: I56abb56c47d97105fac541a49c377cc0222feb10 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130460 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
a246d8d3c2
commit
94bc4cf046
@ -347,41 +347,52 @@ void DumpCompiledShader(Device* device,
|
||||
const CompiledShader& compiledShader,
|
||||
uint32_t compileFlags) {
|
||||
std::ostringstream dumpedMsg;
|
||||
dumpedMsg << "/* Dumped generated HLSL */" << std::endl
|
||||
<< compiledShader.hlslSource << std::endl;
|
||||
// The HLSL may be empty if compilation failed.
|
||||
if (!compiledShader.hlslSource.empty()) {
|
||||
dumpedMsg << "/* Dumped generated HLSL */" << std::endl
|
||||
<< compiledShader.hlslSource << std::endl;
|
||||
}
|
||||
|
||||
if (device->IsToggleEnabled(Toggle::UseDXC)) {
|
||||
dumpedMsg << "/* Dumped disassembled DXIL */" << std::endl;
|
||||
const Blob& shaderBlob = compiledShader.shaderBlob;
|
||||
ComPtr<IDxcBlobEncoding> dxcBlob;
|
||||
ComPtr<IDxcBlobEncoding> disassembly;
|
||||
if (FAILED(device->GetDxcLibrary()->CreateBlobWithEncodingFromPinned(
|
||||
shaderBlob.Data(), shaderBlob.Size(), 0, &dxcBlob)) ||
|
||||
FAILED(device->GetDxcCompiler()->Disassemble(dxcBlob.Get(), &disassembly))) {
|
||||
dumpedMsg << "DXC disassemble failed" << std::endl;
|
||||
// The blob may be empty if FXC/DXC compilation failed.
|
||||
const Blob& shaderBlob = compiledShader.shaderBlob;
|
||||
if (!shaderBlob.Empty()) {
|
||||
if (device->IsToggleEnabled(Toggle::UseDXC)) {
|
||||
dumpedMsg << "/* Dumped disassembled DXIL */" << std::endl;
|
||||
ComPtr<IDxcBlobEncoding> dxcBlob;
|
||||
ComPtr<IDxcBlobEncoding> disassembly;
|
||||
if (FAILED(device->GetDxcLibrary()->CreateBlobWithEncodingFromPinned(
|
||||
shaderBlob.Data(), shaderBlob.Size(), 0, &dxcBlob)) ||
|
||||
FAILED(device->GetDxcCompiler()->Disassemble(dxcBlob.Get(), &disassembly))) {
|
||||
dumpedMsg << "DXC disassemble failed" << std::endl;
|
||||
} else {
|
||||
dumpedMsg << std::string_view(
|
||||
static_cast<const char*>(disassembly->GetBufferPointer()),
|
||||
disassembly->GetBufferSize());
|
||||
}
|
||||
} else {
|
||||
dumpedMsg << std::string_view(static_cast<const char*>(disassembly->GetBufferPointer()),
|
||||
disassembly->GetBufferSize());
|
||||
}
|
||||
} else {
|
||||
dumpedMsg << "/* FXC compile flags */ " << std::endl
|
||||
<< CompileFlagsToStringFXC(compileFlags) << std::endl;
|
||||
dumpedMsg << "/* Dumped disassembled DXBC */" << std::endl;
|
||||
ComPtr<ID3DBlob> disassembly;
|
||||
const Blob& shaderBlob = compiledShader.shaderBlob;
|
||||
UINT flags =
|
||||
// Some literals are printed as floats with precision(6) which is not enough
|
||||
// precision for values very close to 0, so always print literals as hex values.
|
||||
D3D_DISASM_PRINT_HEX_LITERALS;
|
||||
if (FAILED(device->GetFunctions()->d3dDisassemble(shaderBlob.Data(), shaderBlob.Size(),
|
||||
flags, nullptr, &disassembly))) {
|
||||
dumpedMsg << "D3D disassemble failed" << std::endl;
|
||||
} else {
|
||||
dumpedMsg << std::string_view(static_cast<const char*>(disassembly->GetBufferPointer()),
|
||||
disassembly->GetBufferSize());
|
||||
dumpedMsg << "/* FXC compile flags */ " << std::endl
|
||||
<< CompileFlagsToStringFXC(compileFlags) << std::endl;
|
||||
dumpedMsg << "/* Dumped disassembled DXBC */" << std::endl;
|
||||
ComPtr<ID3DBlob> disassembly;
|
||||
UINT flags =
|
||||
// Some literals are printed as floats with precision(6) which is not enough
|
||||
// precision for values very close to 0, so always print literals as hex values.
|
||||
D3D_DISASM_PRINT_HEX_LITERALS;
|
||||
if (FAILED(device->GetFunctions()->d3dDisassemble(shaderBlob.Data(), shaderBlob.Size(),
|
||||
flags, nullptr, &disassembly))) {
|
||||
dumpedMsg << "D3D disassemble failed" << std::endl;
|
||||
} else {
|
||||
dumpedMsg << std::string_view(
|
||||
static_cast<const char*>(disassembly->GetBufferPointer()),
|
||||
disassembly->GetBufferSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
device->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
|
||||
|
||||
std::string logMessage = dumpedMsg.str();
|
||||
if (!logMessage.empty()) {
|
||||
device->EmitLog(WGPULoggingType_Info, logMessage.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dawn::native::d3d
|
||||
|
@ -158,13 +158,20 @@ ResultOrError<d3d::CompiledShader> ShaderModule::Compile(
|
||||
req.hlsl.limits = LimitsForCompilationRequest::Create(limits.v1);
|
||||
|
||||
CacheResult<d3d::CompiledShader> compiledShader;
|
||||
DAWN_TRY_LOAD_OR_RUN(compiledShader, device, std::move(req), d3d::CompiledShader::FromBlob,
|
||||
d3d::CompileShader);
|
||||
MaybeError compileError = [&]() -> MaybeError {
|
||||
DAWN_TRY_LOAD_OR_RUN(compiledShader, device, std::move(req), d3d::CompiledShader::FromBlob,
|
||||
d3d::CompileShader);
|
||||
return {};
|
||||
}();
|
||||
|
||||
if (req.hlsl.dumpShaders) {
|
||||
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||
d3d::DumpCompiledShader(device, *compiledShader, compileFlags);
|
||||
}
|
||||
|
||||
if (compileError.IsError()) {
|
||||
return {compileError.AcquireError()};
|
||||
}
|
||||
|
||||
device->GetBlobCache()->EnsureStored(compiledShader);
|
||||
|
||||
// Clear the hlslSource. It is only used for logging and should not be used
|
||||
|
@ -207,13 +207,20 @@ ResultOrError<d3d::CompiledShader> ShaderModule::Compile(
|
||||
req.hlsl.limits = LimitsForCompilationRequest::Create(limits.v1);
|
||||
|
||||
CacheResult<d3d::CompiledShader> compiledShader;
|
||||
DAWN_TRY_LOAD_OR_RUN(compiledShader, device, std::move(req), d3d::CompiledShader::FromBlob,
|
||||
d3d::CompileShader);
|
||||
MaybeError compileError = [&]() -> MaybeError {
|
||||
DAWN_TRY_LOAD_OR_RUN(compiledShader, device, std::move(req), d3d::CompiledShader::FromBlob,
|
||||
d3d::CompileShader);
|
||||
return {};
|
||||
}();
|
||||
|
||||
if (device->IsToggleEnabled(Toggle::DumpShaders)) {
|
||||
d3d::DumpCompiledShader(device, *compiledShader, compileFlags);
|
||||
}
|
||||
|
||||
if (compileError.IsError()) {
|
||||
return {compileError.AcquireError()};
|
||||
}
|
||||
|
||||
device->GetBlobCache()->EnsureStored(compiledShader);
|
||||
|
||||
// Clear the hlslSource. It is only used for logging and should not be used
|
||||
|
Loading…
x
Reference in New Issue
Block a user