diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index aca1799c6..6034e25d9 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -327,7 +327,7 @@ void ThreadState::WritePointerValue(Id pointer, const ShaderVariable &val) pointers.push_back(ptrid); for(size_t i = 0; i < pointers.size(); i++) - lastWrite[pointers[i]] = nextInstruction; + lastWrite[pointers[i]] = m_State ? m_State->stepIndex : nextInstruction; } } @@ -344,7 +344,7 @@ void ThreadState::SetDst(Id id, const ShaderVariable &val) ids[id] = val; ids[id].name = debugger.GetRawName(id); - lastWrite[id] = nextInstruction; + lastWrite[id] = m_State ? m_State->stepIndex : nextInstruction; auto it = std::lower_bound(live.begin(), live.end(), id); live.insert(it - live.begin(), id); diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index a2b47954a..9d5bdf0fc 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -322,9 +322,10 @@ struct LocalMapping return true; } - size_t offset; + uint32_t stepIndex; Id sourceVar; Id debugVar; + bool isDeclare; rdcarray indexes; }; diff --git a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp index e588217ea..245677fe0 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp @@ -1268,7 +1268,7 @@ void Debugger::ApplyDebugSourceVars(size_t startOffs, ThreadState &thread, Shade if(it->first > endOffs) break; - const LocalMapping &mapping = it->second; + LocalMapping mapping = it->second; if(mapping.debugVar == Id()) { @@ -1318,6 +1318,8 @@ void Debugger::ApplyDebugSourceVars(size_t startOffs, ThreadState &thread, Shade i++; } + mapping.stepIndex = state.stepIndex; + // now add the new mapping in sorted order pos = std::lower_bound(m_DebugInfo.activeLocalMappings.begin(), m_DebugInfo.activeLocalMappings.end(), mapping); @@ -1339,7 +1341,19 @@ void Debugger::ApplyDebugSourceVars(size_t startOffs, ThreadState &thread, Shade rdcarray sorted = m_DebugInfo.activeLocalMappings; std::sort(sorted.begin(), sorted.end(), - [](const LocalMapping &a, const LocalMapping &b) { return a.offset < b.offset; }); + [this, &thread](const LocalMapping &a, const LocalMapping &b) { + size_t aStep = a.stepIndex; + size_t bStep = b.stepIndex; + + // declarations use the step index of the last write rather than the step index they + // were added + if(a.isDeclare && thread.lastWrite[a.debugVar] > 0) + aStep = thread.lastWrite[a.debugVar]; + if(b.isDeclare && thread.lastWrite[b.debugVar] > 0) + bStep = thread.lastWrite[b.debugVar]; + + return aStep < bStep; + }); for(const LocalMapping &mapping : sorted) { @@ -1621,8 +1635,8 @@ rdcarray Debugger::ContinueDebug() if(!thread.callstack.empty()) funcRet = thread.callstack.back()->funcCallInstruction; - thread.StepNext(&state, workgroup); state.stepIndex = steps; + thread.StepNext(&state, workgroup); if(thread.callstack.size() > prevStackSize) instOffs = @@ -3108,7 +3122,7 @@ void Debugger::RegisterOp(Iter it) LocalMapping &mapping = m_DebugInfo.localMappings[it.offs()]; - mapping = {it.offs(), dbg.arg(0), id}; + mapping = {0, dbg.arg(0), id, dbg.inst == ShaderDbg::Declare}; if(constants.find(id) != constants.end() && !m_DebugInfo.constants.contains(id)) m_DebugInfo.constants.push_back(id);