From 522295472367fa5f05906ad21006f07aac830448 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Tue, 16 Sep 2025 16:51:02 +0100 Subject: [PATCH] Add a lock when simulating Atomic Memory instructions --- renderdoc/driver/shaders/spirv/spirv_debug.cpp | 13 +++++++++++++ renderdoc/driver/shaders/spirv/spirv_debug.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.cpp b/renderdoc/driver/shaders/spirv/spirv_debug.cpp index 097e0169f..f0550de20 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.cpp +++ b/renderdoc/driver/shaders/spirv/spirv_debug.cpp @@ -27,6 +27,7 @@ #include #include #include "common/formatting.h" +#include "common/threading.h" #include "core/settings.h" #include "maths/half_convert.h" #include "os/os_specific.h" @@ -4259,6 +4260,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray } case Op::AtomicLoad: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicLoad load(it); // ignore for now @@ -4302,6 +4305,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray } case Op::AtomicStore: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicStore store(it); // ignore for now @@ -4333,6 +4338,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray } case Op::AtomicExchange: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicExchange excg(it); // ignore for now @@ -4392,6 +4399,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray } case Op::AtomicCompareExchange: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicCompareExchange cmpexcg(it); // ignore for now @@ -4475,6 +4484,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray case Op::AtomicIIncrement: case Op::AtomicIDecrement: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicIIncrement atomic(it); // ignore for now @@ -4560,6 +4571,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray case Op::AtomicOr: case Op::AtomicXor: { + SCOPED_LOCK(debugger.GetAtomicMemoryLock()); + OpAtomicIAdd atomic(it); // ignore for now diff --git a/renderdoc/driver/shaders/spirv/spirv_debug.h b/renderdoc/driver/shaders/spirv/spirv_debug.h index bb92da7f6..2de5430fd 100644 --- a/renderdoc/driver/shaders/spirv/spirv_debug.h +++ b/renderdoc/driver/shaders/spirv/spirv_debug.h @@ -665,6 +665,8 @@ public: DeviceOpResult WriteTexel(const ShaderBindIndex &imageBind, const ShaderVariable &coord, uint32_t sample, const ShaderVariable &input) const; DeviceOpResult GetBufferLength(const ShaderBindIndex &bind, uint64_t &bufferLen) const; + + Threading::CriticalSection &GetAtomicMemoryLock() const { return atomicMemoryLock; } private: virtual void PreParse(uint32_t maxId); virtual void PostParse(); @@ -799,6 +801,7 @@ private: void SyncPendingGpuOps(); void SyncPendingLanes(); + mutable Threading::CriticalSection atomicMemoryLock; mutable Threading::CriticalSection queuedDebugMessagesLock; mutable rdcarray queuedDebugMessages; rdcarray queuedGpuMathOps;