Skip to content

Commit

Permalink
AtomicStore, Atomic* fixes
Browse files Browse the repository at this point in the history
Use the allocation size of the pointer argument not the allocation size of the memory backing variable (stack or global)

For Atomic* operations:
* use the pointer argument as the variable input instead of the memory backing variable (static or global)
* copy just the res value into the result variable instead of the whole res variable
* use the pointer argument variable as the source pointer argument instead of the memory backing variable
* record changes to the pointer argument variable as well as to the memory backing variable
  • Loading branch information
Zorro666 committed Dec 19, 2024
1 parent 2759ebf commit 2aaac27
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions renderdoc/driver/shaders/dxil/dxil_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4155,11 +4155,11 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
const MemoryTracking::AllocPointer &ptr = itPtr->second;
baseMemoryId = ptr.baseMemoryId;
baseMemoryBackingPtr = ptr.backingMemory;
allocSize = ptr.size;

auto itAlloc = m_Memory.m_Allocs.find(baseMemoryId);
RDCASSERT(itAlloc != m_Memory.m_Allocs.end());
const MemoryTracking::Alloc &alloc = itAlloc->second;
allocSize = alloc.size;
allocMemoryBackingPtr = alloc.backingMemory;

RDCASSERT(baseMemoryBackingPtr);
Expand Down Expand Up @@ -5124,20 +5124,20 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
const MemoryTracking::AllocPointer &ptr = itPtr->second;
baseMemoryId = ptr.baseMemoryId;
baseMemoryBackingPtr = ptr.backingMemory;
allocSize = ptr.size;

auto itAlloc = m_Memory.m_Allocs.find(baseMemoryId);
RDCASSERT(itAlloc != m_Memory.m_Allocs.end());
const MemoryTracking::Alloc &alloc = itAlloc->second;
allocSize = alloc.size;
allocMemoryBackingPtr = alloc.backingMemory;
}

RDCASSERT(baseMemoryBackingPtr);
RDCASSERTNOTEQUAL(baseMemoryId, DXILDebug::INVALID_ID);

RDCASSERTNOTEQUAL(resultId, DXILDebug::INVALID_ID);
RDCASSERT(IsVariableAssigned(baseMemoryId));
const ShaderVariable a = m_Variables[baseMemoryId];
RDCASSERT(IsVariableAssigned(ptrId));
const ShaderVariable a = m_Variables[ptrId];

size_t newValueArgIdx = (opCode == Operation::CompareExchange) ? 2 : 1;
ShaderVariable b;
Expand Down Expand Up @@ -5252,21 +5252,33 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
UpdateBackingMemoryFromVariable(baseMemoryBackingPtr, allocSize, res);

ShaderVariableChange change;
change.before = a;
if(m_State)
change.before = a;

UpdateMemoryVariableFromBackingMemory(baseMemoryId, allocMemoryBackingPtr);

// record the change to the base memory variable
change.after = m_Variables[baseMemoryId];
if(m_State)
{
change.after = m_Variables[baseMemoryId];
m_State->changes.push_back(change);
}

// record the change to the ptr variable value
RDCASSERT(IsVariableAssigned(ptrId));
if(m_State)
change.before = m_Variables[ptrId];
// Update the ptr variable value
// Set the result to be the ptr variable which will then be recorded as a change
m_Variables[ptrId].value = res.value;

if(m_State)
{
change.after = m_Variables[ptrId];
m_State->changes.push_back(change);
}

RDCASSERT(IsVariableAssigned(ptrId));
result = m_Variables[ptrId];
result.value = res.value;
resultId = ptrId;
break;
}
case Operation::AddrSpaceCast:
Expand Down Expand Up @@ -5626,6 +5638,7 @@ void ThreadState::UpdateMemoryVariableFromBackingMemory(Id memoryId, const void
{
for(uint32_t i = 0; i < baseMemory.members.size(); ++i)
{
RDCASSERT(elementSize < sizeof(ShaderValue), elementSize);
memcpy(&baseMemory.members[i].value.f32v[0], src, elementSize);
src += elementSize;
}
Expand Down

0 comments on commit 2aaac27

Please sign in to comment.