From b01c5d597a475aff53a145c5743ffd5249bdc4f6 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 3a78c3a0c..ea2e0fced 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 694d9d883..62fdeb929 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 978c9f0c5..1b7cc8480 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"); @@ -494,7 +495,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 a8d3d4e15..fc13a14c1 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"); @@ -704,7 +705,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);