From c43d90b9050bf7084aa7ae2678197919071bad9e Mon Sep 17 00:00:00 2001 From: Edu Garcia <28616+Arcnor@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:14:29 +0000 Subject: [PATCH] Enable debug information for Vulkan shaders (#3193) * Enable debug information for Vulkan shaders * Enable debug information for Metal shaders --- docs/tools.rst | 5 ++++- tools/shaderc/shaderc.cpp | 7 ++++++- tools/shaderc/shaderc_metal.cpp | 6 +++++- tools/shaderc/shaderc_spirv.cpp | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/tools.rst b/docs/tools.rst index 3a78c3a0cb9..ea2e0fceda9 100644 --- a/docs/tools.rst +++ b/docs/tools.rst @@ -199,9 +199,12 @@ Options: --varyingdef A varying.def.sc's file path. --verbose Be verbose. -(DX9 and DX11 only): +(Vulkan, DirectX and Metal): --debug Debug information. + +(DirectX only): + --disasm Disassemble a compiled shader. -O Set optimization level. Can be 0–3. diff --git a/tools/shaderc/shaderc.cpp b/tools/shaderc/shaderc.cpp index 694d9d883f5..62fdeb9293f 100644 --- a/tools/shaderc/shaderc.cpp +++ b/tools/shaderc/shaderc.cpp @@ -1054,10 +1054,15 @@ namespace bgfx " --verbose Be verbose.\n" "\n" - "(DX9 and DX11 only):\n" + "(Vulkan, DirectX and Metal):\n" "\n" " --debug Debug information.\n" + + "\n" + "(DirectX only):\n" + + "\n" " --disasm Disassemble compiled shader.\n" " -O Set optimization level. Can be 0 to 3.\n" " --Werror Treat warnings as errors.\n" diff --git a/tools/shaderc/shaderc_metal.cpp b/tools/shaderc/shaderc_metal.cpp index b9e70aceb0f..7139dbb4f42 100644 --- a/tools/shaderc/shaderc_metal.cpp +++ b/tools/shaderc/shaderc_metal.cpp @@ -286,6 +286,7 @@ namespace bgfx { namespace metal | EShMsgReadHlsl | EShMsgVulkanRules | EShMsgSpvRules + | EShMsgDebugInfo ); shader->setEntryPoint("main"); @@ -495,7 +496,10 @@ namespace bgfx { namespace metal std::vector spirv; glslang::SpvOptions options; - options.disableOptimizer = false; + options.disableOptimizer = _options.debugInformation; + options.generateDebugInfo = _options.debugInformation; + options.emitNonSemanticShaderDebugInfo = _options.debugInformation; + options.emitNonSemanticShaderDebugSource = _options.debugInformation; glslang::GlslangToSpv(*intermediate, spirv, &options); diff --git a/tools/shaderc/shaderc_spirv.cpp b/tools/shaderc/shaderc_spirv.cpp index 542d6e506b7..49d0811a703 100644 --- a/tools/shaderc/shaderc_spirv.cpp +++ b/tools/shaderc/shaderc_spirv.cpp @@ -461,6 +461,7 @@ namespace bgfx { namespace spirv | EShMsgReadHlsl | EShMsgVulkanRules | EShMsgSpvRules + | EShMsgDebugInfo ); shader->setEntryPoint("main"); @@ -705,7 +706,10 @@ namespace bgfx { namespace spirv std::vector spirv; glslang::SpvOptions options; - options.disableOptimizer = false; + options.disableOptimizer = _options.debugInformation; + options.generateDebugInfo = _options.debugInformation; + options.emitNonSemanticShaderDebugInfo = _options.debugInformation; + options.emitNonSemanticShaderDebugSource = _options.debugInformation; glslang::GlslangToSpv(*intermediate, spirv, &options);