From b5e208976826f7da4383d8d785099e2ff9a069bd Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 4 Aug 2021 21:11:19 +0000 Subject: [PATCH] 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 Commit-Queue: Austin Eng --- src/dawn_native/ShaderModule.cpp | 4 +++- src/dawn_native/opengl/ShaderModuleGL.cpp | 26 ++++++++++++++++++++++- src/dawn_native/vulkan/ShaderModuleVk.cpp | 14 ++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 79a9514b29..54eff8dc2a 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -434,7 +434,9 @@ namespace dawn_native { if (!spirvTools.Validate(code, codeSize)) { std::string disassembly; if (spirvTools.Disassemble(std::vector(code, code + codeSize), - &disassembly)) { + &disassembly, + SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | + SPV_BINARY_TO_TEXT_OPTION_INDENT)) { errorStream << "disassembly:" << std::endl << disassembly; } diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index 6aac35de75..3b9bec6ad6 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -150,6 +150,21 @@ namespace dawn_native { namespace opengl { } else { 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)); compiler.set_common_options(options); 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 diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 0144eefeff..98df4411c8 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -226,6 +226,20 @@ namespace dawn_native { namespace vulkan { std::vector 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 VkShaderModuleCreateInfo createInfo; createInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;