Hook up dump_shaders toggle to dump SPIRV and GLSL

Bug: none
Change-Id: I742067d70bac5b43afe38d8d39b5eb2dae647a74
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/60960
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-08-04 21:11:19 +00:00 committed by Dawn LUCI CQ
parent 5c19bf25e3
commit b5e2089768
3 changed files with 42 additions and 2 deletions

View File

@ -434,7 +434,9 @@ namespace dawn_native {
if (!spirvTools.Validate(code, codeSize)) { if (!spirvTools.Validate(code, codeSize)) {
std::string disassembly; std::string disassembly;
if (spirvTools.Disassemble(std::vector<uint32_t>(code, code + codeSize), if (spirvTools.Disassemble(std::vector<uint32_t>(code, code + codeSize),
&disassembly)) { &disassembly,
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES |
SPV_BINARY_TO_TEXT_OPTION_INDENT)) {
errorStream << "disassembly:" << std::endl << disassembly; errorStream << "disassembly:" << std::endl << disassembly;
} }

View File

@ -150,6 +150,21 @@ namespace dawn_native { namespace opengl {
} else { } else {
spirv = GetSpirv(); spirv = GetSpirv();
} }
if (GetDevice()->IsToggleEnabled(Toggle::DumpShaders)) {
spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1);
std::ostringstream dumpedMsg;
std::string disassembly;
if (spirvTools.Disassemble(
spirv, &disassembly,
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT)) {
dumpedMsg << "/* Dumped generated SPIRV disassembly */" << std::endl << disassembly;
} else {
dumpedMsg << "/* Failed to disassemble generated SPIRV */";
}
GetDevice()->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
}
spirv_cross::CompilerGLSL compiler(std::move(spirv)); spirv_cross::CompilerGLSL compiler(std::move(spirv));
compiler.set_common_options(options); compiler.set_common_options(options);
compiler.set_entry_point(entryPointName, ShaderStageToExecutionModel(stage)); compiler.set_entry_point(entryPointName, ShaderStageToExecutionModel(stage));
@ -234,7 +249,16 @@ namespace dawn_native { namespace opengl {
} }
} }
return compiler.compile(); std::string glsl = compiler.compile();
if (GetDevice()->IsToggleEnabled(Toggle::DumpShaders)) {
std::ostringstream dumpedMsg;
dumpedMsg << "/* Dumped generated GLSL */" << std::endl << glsl;
GetDevice()->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
}
return glsl;
} }
}} // namespace dawn_native::opengl }} // namespace dawn_native::opengl

View File

@ -226,6 +226,20 @@ namespace dawn_native { namespace vulkan {
std::vector<uint32_t> spirv = result.spirv; std::vector<uint32_t> spirv = result.spirv;
if (GetDevice()->IsToggleEnabled(Toggle::DumpShaders)) {
spvtools::SpirvTools spirvTools(SPV_ENV_VULKAN_1_1);
std::ostringstream dumpedMsg;
std::string disassembly;
if (spirvTools.Disassemble(
result.spirv, &disassembly,
SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT)) {
dumpedMsg << "/* Dumped generated SPIRV disassembly */" << std::endl << disassembly;
} else {
dumpedMsg << "/* Failed to disassemble generated SPIRV */";
}
GetDevice()->EmitLog(WGPULoggingType_Info, dumpedMsg.str().c_str());
}
// Don't save the transformedParseResult but just create a VkShaderModule // Don't save the transformedParseResult but just create a VkShaderModule
VkShaderModuleCreateInfo createInfo; VkShaderModuleCreateInfo createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;