Skip to content

Commit fa4efc7

Browse files
Now pass in remap candidates to the spirv-simulator
1 parent 559a70b commit fa4efc7

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

src/execute_commands.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@ static bool run_spirv(lava_file_reader& reader, const trackedpipeline& pipeline_
2525
const uint32_t buffer_index = access.buffer_data->index;
2626
suballoc_location loc = reader.parent->allocator.find_buffer_memory(buffer_index);
2727
std::byte* base = (std::byte*)loc.memory;
28-
set_bindings[binding_pair.first] = base + access.offset;
28+
std::byte* binding_ptr = base + access.offset;
29+
set_bindings[binding_pair.first] = binding_ptr;
30+
if (!access.buffer_data->candidates.empty() && access.size != 0)
31+
{
32+
const VkDeviceSize binding_start = access.offset;
33+
const VkDeviceSize binding_end = access.offset + access.size;
34+
std::vector<SPIRVSimulator::PhysicalAddressCandidate>* candidate_list = nullptr;
35+
for (const auto& candidate : access.buffer_data->candidates)
36+
{
37+
if (candidate.offset < binding_start || candidate.offset >= binding_end) continue;
38+
if (!candidate_list) candidate_list = &inputs.candidates[static_cast<const void*>(binding_ptr)];
39+
SPIRVSimulator::PhysicalAddressCandidate sim_candidate;
40+
sim_candidate.address = candidate.address;
41+
sim_candidate.offset = candidate.offset - binding_start;
42+
sim_candidate.payload = access.buffer_data;
43+
candidate_list->push_back(sim_candidate);
44+
}
45+
}
2946
}
3047
}
3148
shader_data.calls++;

src/hardcode_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ VKAPI_ATTR void retrace_vkUpdateBufferTRACETOOLTEST(lava_file_reader& reader)
16141614
memcpy(ptr, info.pData, info.dataSize);
16151615
if (reader.parent->remap_scan)
16161616
{
1617-
reader.parent->find_address_candidates(tbuf, info.dataSize, info.pData, reader.current);
1617+
reader.parent->find_address_candidates(tbuf, info.dataSize, info.pData, info.dstOffset, reader.current);
16181618
if (ar) assert(tbuf.candidates.size() >= ar->count);
16191619
}
16201620
mem_unmap(reader, device, loc, ar, ptr);

src/lavatube.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct trackedshadermodule : trackable
236236
struct remap_candidate
237237
{
238238
VkDeviceAddress address; // contained value
239-
VkDeviceSize offset; // the offset of the candidate
239+
VkDeviceSize offset; // byte offset from start of buffer
240240
change_source source; // last write to memory area from which we came
241241

242242
remap_candidate(VkDeviceAddress a, VkDeviceSize b, change_source c) { address = a; offset = b; source = c; }

src/read.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,21 @@ void lava_reader::dump_info()
282282
}
283283
}
284284

285-
uint32_t lava_reader::find_address_candidates(trackedbuffer& buffer_data, VkDeviceSize size, const void* ptr, change_source source) const
285+
uint32_t lava_reader::find_address_candidates(trackedbuffer& buffer_data, VkDeviceSize size, const void* ptr, VkDeviceSize base_offset, change_source source) const
286286
{
287287
buffer_data.self_test();
288+
const char* base_ptr = (const char*)ptr;
288289
// Search on a 4-byte aligned boundary
289290
if ((uintptr_t)ptr % sizeof(uint32_t) != 0)
290291
{
291292
ptr = (const void*)aligned_size((uintptr_t)ptr, sizeof(uint32_t));
292293
}
293294
const uint32_t* start = (const uint32_t*)ptr;
294-
const uint32_t* end = (const uint32_t*)((char*)ptr + size);
295+
const uint32_t* end = (const uint32_t*)(base_ptr + size);
295296
uint32_t found = 0;
296297
for (const uint32_t* p = start; p + 2 <= end; p++)
297298
{
298-
const VkDeviceSize offset = (VkDeviceSize)p;
299+
const VkDeviceSize offset = base_offset + (VkDeviceSize)((const char*)p - base_ptr);
299300
const VkDeviceAddress candidate = *((uintptr_t*)p); // read full 64bit word at current position
300301

301302
// Do we already have a candidate for this address?

src/read.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ class lava_reader
6565
std::vector<std::atomic_uint_fast32_t>* thread_call_numbers; // thread local call numbers
6666

6767
// Use the remapping lists below to find possible candidates for remapping in a buffer.
68-
// Return the number of candidates found. Will search from 'ptr', which is a mapped buffer,
69-
// a 'size' sized window. Caller must make sure access is thread safe.
70-
uint32_t find_address_candidates(trackedbuffer& buffer_data, VkDeviceSize size, const void* ptr, change_source source) const;
68+
// Return the number of candidates found. Will search from 'ptr' over a 'size' sized window.
69+
// base_offset is the byte offset from the start of the buffer to 'ptr'.
70+
// Caller must make sure access is thread safe.
71+
uint32_t find_address_candidates(trackedbuffer& buffer_data, VkDeviceSize size, const void* ptr, VkDeviceSize base_offset, change_source source) const;
7172

7273
// This is thread safe since we allocate it all before threading begins.
7374
address_remapper<trackedobject> device_address_remapping;
@@ -161,7 +162,8 @@ class lava_file_reader : public file_reader
161162
if (buf && size)
162163
{
163164
memcpy(ptr, uptr, size);
164-
parent->find_address_candidates(buffer_data, size, ptr, current);
165+
const VkDeviceSize base_offset = (VkDeviceSize)(ptr - buf);
166+
parent->find_address_candidates(buffer_data, size, ptr, base_offset, current);
165167
}
166168
read_position += size;
167169
ptr += size;

0 commit comments

Comments
 (0)