From d453390c4843adf01176e102c619490b61fafb3e Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Wed, 4 Aug 2021 21:45:38 -0400 Subject: [PATCH] ShaderCompiler: Attach source text to SPIR-V for debuggers like RenderDoc --- .../DolphinQt/Config/Graphics/AdvancedWidget.cpp | 6 +++--- .../Core/VideoBackends/Vulkan/ShaderCompiler.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp index 79f9305e77..3a62620f1c 100644 --- a/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/AdvancedWidget.cpp @@ -203,9 +203,9 @@ void AdvancedWidget::AddDescriptions() "unchecked."); static const char TR_VALIDATION_LAYER_DESCRIPTION[] = QT_TR_NOOP("Enables validation of API calls made by the video backend, which may assist in " - "debugging graphical issues. On D3D backends, this also enables debug symbols " - "for the compiled shaders.

If unsure, leave this " - "unchecked."); + "debugging graphical issues. On the Vulkan and D3D backends, this also enables " + "debug symbols for the compiled shaders.

If unsure, " + "leave this unchecked."); static const char TR_DUMP_TEXTURE_DESCRIPTION[] = QT_TR_NOOP("Dumps decoded game textures based on the other flags to " "User/Dump/Textures/<game_id>/.

If unsure, leave " diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp index f54bf7e4d2..a06cab771e 100644 --- a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp +++ b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp @@ -196,7 +196,21 @@ static std::optional CompileShaderToSPV(EShLanguage stage, SPIRVCodeVector out_code; spv::SpvBuildLogger logger; - glslang::GlslangToSpv(*intermediate, out_code, &logger); + glslang::SpvOptions options; + + if (g_ActiveConfig.bEnableValidationLayer) + { + // Attach the source code to the SPIR-V for tools like RenderDoc. + intermediate->addSourceText(pass_source_code, pass_source_code_length); + + options.generateDebugInfo = true; + options.disableOptimizer = true; + options.optimizeSize = false; + options.disassemble = false; + options.validate = true; + } + + glslang::GlslangToSpv(*intermediate, out_code, &logger, &options); // Write out messages // Temporary: skip if it contains "Warning, version 450 is not yet complete; most version-specific