From 7b2754a97856e4db74099f79b5c97bff56dcbbaf Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Wed, 4 Sep 2024 10:44:28 +0100 Subject: [PATCH] Santisie the shader source filenames in DXIL BuildReflection Reset Files and m_CompileFlags to avoid accumulation with repeated calls to BuildReflection Set "preferSourceDebug" to "1" if the DXIL has source file data --- .../driver/shaders/dxil/dxil_reflect.cpp | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/shaders/dxil/dxil_reflect.cpp b/renderdoc/driver/shaders/dxil/dxil_reflect.cpp index 33ffe3453..e2803c753 100644 --- a/renderdoc/driver/shaders/dxil/dxil_reflect.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_reflect.cpp @@ -23,6 +23,7 @@ ******************************************************************************/ #include "common/formatting.h" +#include "strings/string_utils.h" #include "dxil_bytecode.h" #include "dxil_common.h" @@ -1466,6 +1467,8 @@ DXBC::Reflection *Program::BuildReflection() using namespace DXBC; Reflection *refl = new Reflection; + Files.clear(); + m_CompileFlags.flags.clear(); DXMeta dx(m_NamedMeta); @@ -1528,13 +1531,25 @@ DXBC::Reflection *Program::BuildReflection() { if(f->children.size() != 2) continue; - Files.push_back({f->children[0]->str, f->children[1]->str}); + bool found = false; + rdcstr shaderFilePath = standardise_directory_separator(f->children[0]->str); + for(const ShaderSourceFile &shaderSource : Files) + { + if(shaderSource.filename == shaderFilePath) + { + found = true; + break; + } + } + + if(!found) + Files.push_back({shaderFilePath, f->children[1]->str}); } // push the main filename to the front if(dx.source.mainFileName && !dx.source.mainFileName->children.empty()) { - rdcstr mainFile = dx.source.mainFileName->children[0]->str; + rdcstr mainFile = standardise_directory_separator(dx.source.mainFileName->children[0]->str); if(!mainFile.empty()) { @@ -1548,6 +1563,8 @@ DXBC::Reflection *Program::BuildReflection() } } } + if(!Files.empty()) + m_CompileFlags.flags.push_back({"preferSourceDebug", "1"}); } if(dx.source.args && dx.source.args->children.size() == 1)