@@ -5166,8 +5166,8 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
5166
5166
ShaderVariable originalValue (m_Variables[ptrId]);
5167
5167
5168
5168
const MemoryTracking::Pointer &ptr = itPtr->second ;
5169
- Id baseMemoryId = ptr.baseMemoryId ;
5170
- void *memory = ptr.memory ;
5169
+ const Id baseMemoryId = ptr.baseMemoryId ;
5170
+ void *const memory = ptr.memory ;
5171
5171
uint64_t allocSize = ptr.size ;
5172
5172
5173
5173
RDCASSERT (memory);
@@ -5196,22 +5196,8 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
5196
5196
5197
5197
// active lane : writes to a GSM variable, write to local and global backing memory
5198
5198
if (m_State)
5199
- {
5200
- if (m_GlobalState.groupSharedMemoryIds .contains (baseMemoryId))
5201
- {
5202
- // Compute the local pointer offset and apply it to the global base memory
5203
- ptrdiff_t offset = (uintptr_t )memory - (uintptr_t )allocation.backingMemory ;
5204
- auto globalMem = m_GlobalState.memory .m_Allocations .find (baseMemoryId);
5205
- if (globalMem == m_GlobalState.memory .m_Allocations .end ())
5206
- {
5207
- RDCERR (" Unknown global memory allocation Id %u" , baseMemoryId);
5208
- break ;
5209
- }
5210
- void *globalMemory = (void *)((uintptr_t )globalMem->second .backingMemory + offset);
5211
- allocSize = ptr.size ;
5212
- UpdateBackingMemoryFromVariable (globalMemory, allocSize, val);
5213
- }
5214
- }
5199
+ UpdateGlobalBackingMemory (ptrId, ptr, allocation, val);
5200
+
5215
5201
// record the change to the base memory variable if it is not the ptrId variable
5216
5202
if (recordBaseMemoryChange)
5217
5203
{
@@ -6185,11 +6171,11 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
6185
6171
}
6186
6172
6187
6173
const MemoryTracking::Pointer &ptr = itPtr->second ;
6188
- Id baseMemoryId = ptr.baseMemoryId ;
6174
+ const Id baseMemoryId = ptr.baseMemoryId ;
6189
6175
6190
6176
RDCASSERTNOTEQUAL (baseMemoryId, DXILDebug::INVALID_ID);
6191
6177
6192
- void *memory = ptr.memory ;
6178
+ void *const memory = ptr.memory ;
6193
6179
RDCASSERT (memory);
6194
6180
uint64_t allocSize = ptr.size ;
6195
6181
@@ -6336,22 +6322,7 @@ bool ThreadState::ExecuteInstruction(DebugAPIWrapper *apiWrapper,
6336
6322
6337
6323
// active lane : writes to a GSM variable, write to local and global backing memory
6338
6324
if (m_State)
6339
- {
6340
- if (m_GlobalState.groupSharedMemoryIds .contains (baseMemoryId))
6341
- {
6342
- // Compute the local pointer offset and apply it to the global base memory
6343
- ptrdiff_t offset = (uintptr_t )memory - (uintptr_t )allocation.backingMemory ;
6344
- auto globalMem = m_GlobalState.memory .m_Allocations .find (baseMemoryId);
6345
- if (globalMem == m_GlobalState.memory .m_Allocations .end ())
6346
- {
6347
- RDCERR (" Unknown global memory allocation Id %u" , baseMemoryId);
6348
- break ;
6349
- }
6350
- void *globalMemory = (void *)((uintptr_t )globalMem->second .backingMemory + offset);
6351
- allocSize = ptr.size ;
6352
- UpdateBackingMemoryFromVariable (globalMemory, allocSize, res);
6353
- }
6354
- }
6325
+ UpdateGlobalBackingMemory (ptrId, ptr, allocation, res);
6355
6326
6356
6327
// record the change to the base memory variable
6357
6328
if (recordBaseMemoryChange)
@@ -6738,6 +6709,35 @@ void ThreadState::UpdateMemoryVariableFromBackingMemory(Id memoryId, const void
6738
6709
UpdateShaderVariableFromBackingMemory (baseMemory, ptr);
6739
6710
}
6740
6711
6712
+ void ThreadState::UpdateGlobalBackingMemory (Id ptrId, const MemoryTracking::Pointer &ptr,
6713
+ const MemoryTracking::Allocation &allocation,
6714
+ const ShaderVariable &val)
6715
+ {
6716
+ Id baseMemoryId = ptr.baseMemoryId ;
6717
+ if (m_GlobalState.groupSharedMemoryIds .contains (baseMemoryId))
6718
+ {
6719
+ void *const memory = ptr.memory ;
6720
+
6721
+ // Compute the local pointer offset and apply it to the global base memory
6722
+ ptrdiff_t offset = (uintptr_t )memory - (uintptr_t )allocation.backingMemory ;
6723
+ if (offset < 0 )
6724
+ {
6725
+ RDCERR (" Invalid global memory allocation offset ptrId %u Id %u" , ptrId, baseMemoryId);
6726
+ return ;
6727
+ }
6728
+ auto globalMem = m_GlobalState.memory .m_Allocations .find (baseMemoryId);
6729
+ if (globalMem == m_GlobalState.memory .m_Allocations .end ())
6730
+ {
6731
+ RDCERR (" Unknown global memory allocation Id %u" , baseMemoryId);
6732
+ return ;
6733
+ ;
6734
+ }
6735
+ void *globalMemory = (void *)((uintptr_t )globalMem->second .backingMemory + offset);
6736
+ uint64_t allocSize = ptr.size ;
6737
+ UpdateBackingMemoryFromVariable (globalMemory, allocSize, val);
6738
+ }
6739
+ }
6740
+
6741
6741
void ThreadState::PerformGPUResourceOp (const rdcarray<ThreadState> &workgroup, Operation opCode,
6742
6742
DXOp dxOpCode, const ResourceReferenceInfo &resRefInfo,
6743
6743
DebugAPIWrapper *apiWrapper, const DXIL::Instruction &inst,
@@ -9528,14 +9528,58 @@ rdcarray<ShaderDebugState> Debugger::ContinueDebug(DebugAPIWrapper *apiWrapper)
9528
9528
// active lane : needs it own local backing memory, copied from global at the start
9529
9529
for (Id id : m_GlobalState.groupSharedMemoryIds )
9530
9530
{
9531
- MemoryTracking::Allocation &globalAlloc = active. m_Memory .m_Allocations [id];
9531
+ MemoryTracking::Allocation &globalAlloc = m_GlobalState. memory .m_Allocations [id];
9532
9532
RDCASSERT (globalAlloc.globalVarAlloc );
9533
9533
const size_t allocSize = (size_t )globalAlloc.size ;
9534
9534
void *localBackingMem = malloc (allocSize);
9535
9535
memcpy (localBackingMem, globalAlloc.backingMemory , allocSize);
9536
9536
active.m_Memory .m_Allocations [id] = {localBackingMem, globalAlloc.size , true , true };
9537
9537
active.m_Memory .m_Pointers [id] = {id, localBackingMem, globalAlloc.size };
9538
9538
}
9539
+ // active lane: update the backing memory pointer of any pointers to the new local allocations
9540
+ for (const auto &itGlobalPtr : m_GlobalState.memory .m_Pointers )
9541
+ {
9542
+ const MemoryTracking::Pointer &globalPtr = itGlobalPtr.second ;
9543
+ Id ptrId = itGlobalPtr.first ;
9544
+ Id baseMemoryId = globalPtr.baseMemoryId ;
9545
+ // pointers for backing allocations have already have been updated
9546
+ if (ptrId == baseMemoryId)
9547
+ continue ;
9548
+
9549
+ auto itAlloc = m_GlobalState.memory .m_Allocations .find (baseMemoryId);
9550
+ if (itAlloc == m_GlobalState.memory .m_Allocations .end ())
9551
+ {
9552
+ RDCERR (" Could not find global backing memory allocation for ptr %u BaseMemoryId %u" , ptrId,
9553
+ baseMemoryId);
9554
+ continue ;
9555
+ }
9556
+ const MemoryTracking::Allocation &globalAlloc = itAlloc->second ;
9557
+ ptrdiff_t offset = (uintptr_t )globalPtr.memory - (uintptr_t )globalAlloc.backingMemory ;
9558
+ if (offset < 0 )
9559
+ {
9560
+ RDCERR (" Invalid memory allocation offset ptrId %u BaseMemoryId %u" , ptrId, baseMemoryId);
9561
+ continue ;
9562
+ }
9563
+ itAlloc = active.m_Memory .m_Allocations .find (baseMemoryId);
9564
+ if (itAlloc == active.m_Memory .m_Allocations .end ())
9565
+ {
9566
+ RDCERR (" Could not find local backing memory allocation for ptr %u BaseMemoryId %u" , ptrId,
9567
+ baseMemoryId);
9568
+ continue ;
9569
+ }
9570
+ const MemoryTracking::Allocation &localAlloc = itAlloc->second ;
9571
+ void *localMemory = (void *)((uintptr_t )localAlloc.backingMemory + offset);
9572
+ auto itLocalPtr = active.m_Memory .m_Pointers .find (ptrId);
9573
+ if (itLocalPtr == active.m_Memory .m_Pointers .end ())
9574
+ {
9575
+ RDCERR (" Could not find local ptr %u" , ptrId);
9576
+ continue ;
9577
+ }
9578
+ MemoryTracking::Pointer &localPtr = itLocalPtr->second ;
9579
+ RDCASSERTEQUAL (localPtr.baseMemoryId , baseMemoryId);
9580
+ RDCASSERTEQUAL (localPtr.size , globalPtr.size );
9581
+ localPtr.memory = localMemory;
9582
+ }
9539
9583
9540
9584
// globals won't be filled out by entering the entry point, ensure their change is registered.
9541
9585
for (const GlobalVariable &gv : m_GlobalState.globals )
0 commit comments