Add a lock when simulating Atomic Memory instructions

This commit is contained in:
Jake Turner
2025-09-24 15:21:41 +01:00
parent 234a78ecf2
commit 5222954723
2 changed files with 16 additions and 0 deletions
@@ -27,6 +27,7 @@
#include <time.h>
#include <limits>
#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<ThreadState>
}
case Op::AtomicLoad:
{
SCOPED_LOCK(debugger.GetAtomicMemoryLock());
OpAtomicLoad load(it);
// ignore for now
@@ -4302,6 +4305,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray<ThreadState>
}
case Op::AtomicStore:
{
SCOPED_LOCK(debugger.GetAtomicMemoryLock());
OpAtomicStore store(it);
// ignore for now
@@ -4333,6 +4338,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray<ThreadState>
}
case Op::AtomicExchange:
{
SCOPED_LOCK(debugger.GetAtomicMemoryLock());
OpAtomicExchange excg(it);
// ignore for now
@@ -4392,6 +4399,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray<ThreadState>
}
case Op::AtomicCompareExchange:
{
SCOPED_LOCK(debugger.GetAtomicMemoryLock());
OpAtomicCompareExchange cmpexcg(it);
// ignore for now
@@ -4475,6 +4484,8 @@ void ThreadState::StepNext(ShaderDebugState *state, const rdcarray<ThreadState>
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<ThreadState>
case Op::AtomicOr:
case Op::AtomicXor:
{
SCOPED_LOCK(debugger.GetAtomicMemoryLock());
OpAtomicIAdd atomic(it);
// ignore for now
@@ -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<DebugMessage> queuedDebugMessages;
rdcarray<bool> queuedGpuMathOps;