-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of a VK_TRACETOOLS_trace_helpers unit test
- Loading branch information
1 parent
f012f79
commit b3f66b0
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Test of VK_TRACETOOLS_trace_helpers support | ||
|
||
#include "tests/common.h" | ||
#include <inttypes.h> | ||
#include "util_auto.h" | ||
#include "external/tracetooltests/include/vulkan_ext.h" | ||
|
||
typedef void (VKAPI_PTR *PFN_vkSyncBufferTRACETOOLTEST)(VkDevice device, VkBuffer buffer); | ||
|
||
#define TEST_NAME "tracing_7" | ||
#define NUM_BUFFERS 3 | ||
|
||
static void trace_3() | ||
{ | ||
vulkan_setup_t vulkan = test_init(TEST_NAME); | ||
VkResult result; | ||
|
||
PFN_vkAssertBufferTRACETOOLTEST vkAssertBuffer = (PFN_vkAssertBufferTRACETOOLTEST)trace_vkGetDeviceProcAddr(vulkan.device, "vkAssertBufferTRACETOOLTEST"); | ||
assert(vkAssertBuffer != nullptr); | ||
PFN_vkSyncBufferTRACETOOLTEST vkSyncBuffer = (PFN_vkSyncBufferTRACETOOLTEST)trace_vkGetDeviceProcAddr(vulkan.device, "vkSyncBufferTRACETOOLTEST"); | ||
assert(vkSyncBuffer != nullptr); | ||
PFN_vkUpdateBufferTRACETOOLTEST vkUpdateBuffer = (PFN_vkUpdateBufferTRACETOOLTEST)trace_vkGetDeviceProcAddr(vulkan.device, "vkUpdateBufferTRACETOOLTEST"); | ||
assert(vkUpdateBuffer); | ||
PFN_vkUpdateImageTRACETOOLTEST vkUpdateImage = (PFN_vkUpdateImageTRACETOOLTEST)trace_vkGetDeviceProcAddr(vulkan.device, "vkUpdateImageTRACETOOLTEST"); | ||
assert(vkUpdateImage); | ||
PFN_vkThreadBarrierTRACETOOLTEST vkThreadBarrier = (PFN_vkThreadBarrierTRACETOOLTEST)trace_vkGetDeviceProcAddr(vulkan.device, "vkThreadBarrierTRACETOOLTEST"); | ||
assert(vkThreadBarrier); | ||
|
||
VkBuffer buffer[NUM_BUFFERS]; | ||
VkBufferCreateInfo bufferCreateInfo = {}; | ||
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; | ||
bufferCreateInfo.size = 99; | ||
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; | ||
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; | ||
for (unsigned i = 0; i < NUM_BUFFERS; i++) | ||
{ | ||
result = trace_vkCreateBuffer(vulkan.device, &bufferCreateInfo, nullptr, &buffer[i]); | ||
check(result); | ||
} | ||
|
||
VkMemoryRequirements req; | ||
trace_vkGetBufferMemoryRequirements(vulkan.device, buffer[0], &req); | ||
uint32_t memoryTypeIndex = get_device_memory_type(req.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); | ||
|
||
VkMemoryAllocateInfo pAllocateMemInfo = {}; | ||
pAllocateMemInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; | ||
pAllocateMemInfo.memoryTypeIndex = memoryTypeIndex; | ||
pAllocateMemInfo.allocationSize = req.size * NUM_BUFFERS; | ||
VkDeviceMemory memory = 0; | ||
result = trace_vkAllocateMemory(vulkan.device, &pAllocateMemInfo, nullptr, &memory); | ||
check(result); | ||
assert(memory != 0); | ||
|
||
uint32_t checksum = 0; | ||
char* ptr = (char*)malloc(pAllocateMemInfo.allocationSize); | ||
for (unsigned b = 0; b < NUM_BUFFERS; b++) | ||
{ | ||
for (unsigned ii = 0; ii < bufferCreateInfo.size; ii++) ptr[ii + b * req.size] = ii % 255; // just fill it with a pattern | ||
checksum = adler32((unsigned char*)&ptr[b * req.size], bufferCreateInfo.size); | ||
printf("Buffer %d checksum=%u\n", (int)b, (unsigned)checksum); | ||
} | ||
|
||
VkDeviceSize offset = 0; | ||
for (unsigned i = 0; i < NUM_BUFFERS; i++) | ||
{ | ||
trace_vkBindBufferMemory(vulkan.device, buffer[i], memory, offset); | ||
|
||
VkUpdateMemoryInfoTRACETOOLTEST updateInfo = { VK_STRUCTURE_TYPE_UPDATE_MEMORY_INFO_TRACETOOLTEST, nullptr }; | ||
updateInfo.dstOffset = 0; // relative to start of buffer | ||
updateInfo.dataSize = bufferCreateInfo.size; | ||
updateInfo.pData = ptr; | ||
trace_vkUpdateBufferTRACETOOLTEST(vulkan.device, buffer[i], &updateInfo); | ||
|
||
offset += req.size; | ||
} | ||
free(ptr); | ||
ptr = nullptr; | ||
|
||
vkThreadBarrier(0, nullptr); | ||
|
||
for (unsigned i = 0; i < NUM_BUFFERS; i++) | ||
{ | ||
trace_vkSyncBufferTRACETOOLTEST(vulkan.device, buffer[i]); | ||
uint32_t checksum2 = trace_vkAssertBufferTRACETOOLTEST(vulkan.device, buffer[i]); | ||
assert(checksum == checksum2); | ||
} | ||
|
||
// Cleanup... | ||
for (unsigned i = 0; i < NUM_BUFFERS; i++) | ||
{ | ||
trace_vkDestroyBuffer(vulkan.device, buffer[i], nullptr); | ||
} | ||
trace_vkFreeMemory(vulkan.device, memory, nullptr); | ||
test_done(vulkan); | ||
} | ||
|
||
static bool getnext(lava_file_reader& t) | ||
{ | ||
bool done = false; | ||
const uint8_t instrtype = t.read_uint8_t(); | ||
if (instrtype == PACKET_API_CALL) | ||
{ | ||
const uint16_t apicall = t.read_uint16_t(); | ||
(void)t.read_int32_t(); | ||
DLOG("[t%02d %06d] %s", t.thread_index(), (int)t.parent->thread_call_numbers->at(t.thread_index()).load(std::memory_order_relaxed) + 1, get_function_name(apicall)); | ||
lava_replay_func api = retrace_getcall(apicall); | ||
api(t); | ||
t.parent->thread_call_numbers->at(t.thread_index()).fetch_add(1, std::memory_order_relaxed); | ||
suballoc_internal_test(); | ||
t.pool.reset(); | ||
if (apicall == 1) done = true; // is vkDestroyInstance | ||
} | ||
else if (instrtype == PACKET_THREAD_BARRIER) | ||
{ | ||
t.read_barrier(); | ||
} | ||
else if (instrtype == PACKET_BUFFER_UPDATE) | ||
{ | ||
const uint32_t device_index = t.read_handle(); | ||
const uint32_t buffer_index = t.read_handle(); | ||
buffer_update(t, device_index, buffer_index); | ||
} | ||
else assert(false); | ||
suballoc_internal_test(); | ||
return !done; | ||
} | ||
|
||
static void retrace_3() | ||
{ | ||
lava_reader r(TEST_NAME ".vk"); | ||
lava_file_reader& t = r.file_reader(0); | ||
int remaining = suballoc_internal_test(); | ||
assert(remaining == 0); // there should be nothing now | ||
while (getnext(t)) {} | ||
remaining = suballoc_internal_test(); | ||
assert(remaining == 0); // everything should be destroyed now | ||
} | ||
|
||
int main() | ||
{ | ||
trace_3(); | ||
retrace_3(); | ||
return 0; | ||
} |