diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 517a104a3..58cb086be 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -387,6 +387,10 @@ DeviceOpResult ThreadState::WritePointerValue(Id pointer, const ShaderVariable & if(opResult == DeviceOpResult::NeedsDevice) return DeviceOpResult::NeedsDevice; + // Mark the pointer as being live + bool wasLive = SetLive(pointer); + bool baseWasLive = (pointer == ptrid) ? wasLive : true; + rdcarray changes; rdcarray &pointers = pointersForId[ptrid]; @@ -451,8 +455,8 @@ DeviceOpResult ThreadState::WritePointerValue(Id pointer, const ShaderVariable & SPIRV_DEBUG_RDCASSERTEQUAL(opResult, DeviceOpResult::Succeeded); // if this is the first local write, mark this variable as becoming alive here, instead of at - // its declaration - if(firstLocalWrite) + // its declaration or if the variable wasn't live + if(firstLocalWrite || !baseWasLive) basechange.before = {}; pendingDebugState.changes.push_back(basechange); @@ -489,6 +493,19 @@ void ThreadState::DebugBreak() pendingDebugState.flags |= ShaderEvents::DebugBreak; } +bool ThreadState::SetLive(Id id) +{ + bool wasLive = false; + if(hasDebugState) + { + auto it = std::lower_bound(live.begin(), live.end(), id); + wasLive = (it != live.end() && *it == id); + if(!wasLive) + live.insert(it - live.begin(), id); + } + return wasLive; +} + void ThreadState::SetDst(Id id, const ShaderVariable &val) { // Waiting for result i.e. from the GPU or replay thread @@ -525,14 +542,7 @@ void ThreadState::SetDst(Id id, const ShaderVariable &val) lastWrite[id] = hasDebugState ? stepIndex : nextInstruction; - bool wasLive = false; - if(hasDebugState) - { - auto it = std::lower_bound(live.begin(), live.end(), id); - wasLive = (it != live.end() && *it == id); - if(!wasLive) - live.insert(it - live.begin(), id); - } + bool wasLive = SetLive(id); if(val.type == VarType::GPUPointer && !debugger.IsPhysicalPointer(val)) { diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index 4055fc9bf..833ae574e 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -433,6 +433,7 @@ struct ThreadState private: void EnterFunction(const rdcarray &arguments); void SetDst(Id id, const ShaderVariable &val); + bool SetLive(Id id); void ProcessScopeChange(const rdcarray &oldLive, const rdcarray &newLive); void JumpToLabel(Id target); bool ReferencePointer(Id id);