Skip to content

Commit ca99ba5

Browse files
dump: More alignment warning
* dump: Add more alignment * dump: Cleanup warning logic * dump: Warn about bad indirect buffers
1 parent ac8fb02 commit ca99ba5

5 files changed

Lines changed: 622 additions & 320 deletions

File tree

layers/gpu_dump/gpu_dump.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ std::vector<uint8_t> GpuDump::CopyDataFromMemory(VkDeviceAddress memory_addresss
3838
auto buffer_state = *buffer_list.begin();
3939
const vvl::DeviceMemory& memory_state = *buffer_state->MemoryState();
4040

41+
// Prevent copying OOB of a buffer
42+
if ((memory_addresss + copy_size) > buffer_state->DeviceAddressRange().end) {
43+
return result;
44+
}
45+
4146
VkDeviceSize offset = memory_addresss - buffer_state->DeviceAddressRange().begin;
4247
if (memory_state.mappable) {
4348
uint8_t* data_ptr = static_cast<uint8_t*>(memory_state.p_driver_data);
4449

4550
if (!memory_state.p_driver_data) {
46-
DispatchMapMemory(device, memory_state.VkHandle(), offset, copy_size, 0, (void**)&data_ptr);
51+
// Just use WHOLE_SIZE to avoid issues with partial mappings
52+
// Example:
53+
// The |memory_address| is 0x1001 and |copy_size| is 4, the driver (or at least TestICD) will return back something
54+
// aligned to a value like 64, so if the buffer is only 64 bytes, you will now be accessing data over it
55+
DispatchMapMemory(device, memory_state.VkHandle(), offset, VK_WHOLE_SIZE, 0, (void**)&data_ptr);
4756

4857
// Skip checking if coherent memory or not
4958
VkMappedMemoryRange memory_range = vku::InitStructHelper();
@@ -62,9 +71,44 @@ std::vector<uint8_t> GpuDump::CopyDataFromMemory(VkDeviceAddress memory_addresss
6271
}
6372
} else {
6473
// TODO - Handle non-host visible memory
74+
// When we add, we need to guard against if trying to read non-aligned data
75+
// (which should have a warning already)
6576
}
6677

6778
return result;
6879
}
6980

81+
// return for warning if no buffer found
82+
bool GpuDump::ListBuffers(std::ostringstream& ss, VkDeviceAddress address, uint32_t indents, bool new_line_start) {
83+
if (new_line_start) {
84+
ss << "\n";
85+
}
86+
87+
auto buffer_states = GetBuffersByAddress(address);
88+
for (uint32_t i = 0; i < indents; i++) {
89+
ss << " ";
90+
}
91+
92+
for (uint32_t i = 0; i < buffer_states.size(); i++) {
93+
if (i != 0) {
94+
ss << '\n';
95+
for (uint32_t j = 0; j < indents; j++) {
96+
ss << " ";
97+
}
98+
}
99+
auto& buffer_state = buffer_states[i];
100+
ss << "- " << buffer_state->Describe(*this);
101+
}
102+
103+
if (buffer_states.empty()) {
104+
ss << "- [WARNING] No VkBuffer found at 0x" << std::hex << address;
105+
}
106+
107+
if (!new_line_start) {
108+
ss << "\n";
109+
}
110+
111+
return buffer_states.empty();
112+
}
113+
70114
} // namespace gpudump

layers/gpu_dump/gpu_dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class GpuDump : public vvl::DeviceProxy {
3838
void Created(vvl::CommandBuffer& cb_state) override;
3939

4040
std::vector<uint8_t> CopyDataFromMemory(VkDeviceAddress memory_addresss, VkDeviceSize copy_size);
41+
42+
bool ListBuffers(std::ostringstream& ss, VkDeviceAddress address, uint32_t indents, bool new_line_start = false);
4143
};
4244

4345
} // namespace gpudump

layers/gpu_dump/gpu_dump_copy_memory_indirect.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,15 @@
2323
#include <cstdint>
2424
#include <iostream>
2525
#include <sstream>
26-
#include "state_tracker/buffer_state.h"
2726
#include "state_tracker/cmd_buffer_state.h"
2827

2928
namespace gpudump {
3029

31-
// return for warning if no buffer found
32-
static bool ListBuffers(std::ostringstream& ss, const GpuDump& dev_data, VkDeviceAddress address, uint32_t indents) {
33-
auto buffer_states = dev_data.GetBuffersByAddress(address);
34-
for (uint32_t i = 0; i < indents; i++) {
35-
ss << " ";
36-
}
37-
for (auto& buffer_state : buffer_states) {
38-
ss << "- " << buffer_state->Describe(dev_data) << "\n";
39-
}
40-
if (buffer_states.empty()) {
41-
ss << "- [WARNING] No VkBuffer found at 0x" << std::hex << address << "\n";
42-
return true;
43-
}
44-
return false;
45-
}
46-
4730
bool CommandBufferSubState::DumpCopyMemoryIndirectCommon(std::ostringstream& ss, uint32_t copy_count,
4831
VkStridedDeviceAddressRangeKHR copy_address_range) const {
4932
ss << "copyCount = " << copy_count << ", starting address = 0x" << std::hex << copy_address_range.address
5033
<< ", size = " << std::dec << copy_address_range.size << ", stride = " << copy_address_range.stride << "\n";
51-
return ListBuffers(ss, dev_data, copy_address_range.address, 1);
34+
return dev_data.ListBuffers(ss, copy_address_range.address, 1);
5235
}
5336

5437
void CommandBufferSubState::DumpCopyMemoryIndirect(const VkCopyMemoryIndirectInfoKHR& info, const Location& loc) const {
@@ -70,9 +53,9 @@ void CommandBufferSubState::DumpCopyMemoryIndirect(const VkCopyMemoryIndirectInf
7053
auto command = *(VkCopyMemoryIndirectCommandKHR*)(indirect_data.data() + stride_i);
7154
ss << " - size: " << std::dec << command.size << '\n';
7255
ss << " - srcAddress: 0x" << std::hex << command.srcAddress << '\n';
73-
found_warning |= ListBuffers(ss, dev_data, command.srcAddress, 2);
56+
found_warning |= dev_data.ListBuffers(ss, command.srcAddress, 2);
7457
ss << " - dstAddress: 0x" << std::hex << command.dstAddress << '\n';
75-
found_warning |= ListBuffers(ss, dev_data, command.dstAddress, 2);
58+
found_warning |= dev_data.ListBuffers(ss, command.dstAddress, 2);
7659
}
7760
}
7861

@@ -106,7 +89,7 @@ void CommandBufferSubState::DumpCopyMemoryToImageIndirect(const VkCopyMemoryToIm
10689
if (know_data) {
10790
auto command = *(VkCopyMemoryToImageIndirectCommandKHR*)(indirect_data.data() + stride_i);
10891
ss << " - srcAddress: 0x" << std::hex << command.srcAddress << '\n';
109-
found_warning |= ListBuffers(ss, dev_data, command.srcAddress, 2);
92+
found_warning |= dev_data.ListBuffers(ss, command.srcAddress, 2);
11093
ss << " - bufferRowLength: " << std::dec << command.bufferRowLength << '\n';
11194
ss << " - bufferImageHeight: " << command.bufferImageHeight << '\n';
11295
ss << " - imageSubresource: " << string_VkImageSubresourceLayers(command.imageSubresource) << '\n';

0 commit comments

Comments
 (0)