From 4fbd1a08ac5b14023735b0446f01b1ef2665bd03 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 15 Sep 2022 11:20:49 +0100 Subject: [PATCH] Prefer DebugFunction name over function OpName when available --- .../driver/shaders/spirv/spirv_debug.cpp | 4 +-- renderdoc/driver/shaders/spirv/spirv_debug.h | 5 +++- .../shaders/spirv/spirv_debug_setup.cpp | 30 +++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 16c5d05cd..6023c5c66 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -100,10 +100,10 @@ bool ThreadState::Finished() const return killed || callstack.empty(); } -void ThreadState::FillCallstack(ShaderDebugState &state) +void ThreadState::FillCallstack(rdcarray &funcs) { for(const StackFrame *frame : callstack) - state.callstack.push_back(debugger.GetHumanName(frame->function)); + funcs.push_back(frame->function); } void ThreadState::EnterFunction(const rdcarray &arguments) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 4a6e3c11b..331d370c8 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -182,7 +182,7 @@ struct ThreadState ShaderVariable CalcDeriv(DerivDir dir, DerivType type, const rdcarray &workgroup, Id val); - void FillCallstack(ShaderDebugState &state); + void FillCallstack(rdcarray &funcs); bool Finished() const; @@ -392,6 +392,7 @@ private: void MakeSignatureNames(const rdcarray &sigList, rdcarray &sigNames); + void FillCallstack(ThreadState &thread, ShaderDebugState &state); void FillDebugSourceVars(rdcarray &instInfo); void FillDefaultSourceVars(rdcarray &instInfo); @@ -471,6 +472,8 @@ private: SparseIdMap sources; SparseIdMap filenames; + SparseIdMap funcToDebugFunc; + std::map lineScope; std::map lineInline; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index f3064b1b6..b5100820c 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -1422,6 +1422,27 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *api, const ShaderStage s return ret; } +void Debugger::FillCallstack(ThreadState &thread, ShaderDebugState &state) +{ + rdcarray funcs; + thread.FillCallstack(funcs); + + for(Id f : funcs) + { + if(m_DebugInfo.valid) + { + auto it = m_DebugInfo.funcToDebugFunc.find(f); + if(it != m_DebugInfo.funcToDebugFunc.end()) + { + state.callstack.push_back(m_DebugInfo.scopes[it->second].name); + continue; + } + } + + state.callstack.push_back(GetHumanName(f)); + } +} + void Debugger::FillDebugSourceVars(rdcarray &instInfo) { for(InstructionSourceInfo &i : instInfo) @@ -1804,7 +1825,7 @@ rdcarray Debugger::ContinueDebug() if(lane == activeLaneIndex) { thread.EnterEntryPoint(&initial); - thread.FillCallstack(initial); + FillCallstack(thread, initial); initial.nextInstruction = thread.nextInstruction; } else @@ -1902,7 +1923,7 @@ rdcarray Debugger::ContinueDebug() else if(thread.callstack.size() < prevStackSize && funcRet != ~0U) instOffs = instructionOffsets[funcRet]; - thread.FillCallstack(state); + FillCallstack(thread, state); if(m_DebugInfo.valid) { @@ -3133,6 +3154,11 @@ void Debugger::RegisterOp(Iter it) }; break; } + case ShaderDbg::FunctionDefinition: + { + m_DebugInfo.funcToDebugFunc[dbg.arg(1)] = dbg.arg(0); + break; + } case ShaderDbg::Function: { rdcstr name = strings[dbg.arg(0)];