diff options
Diffstat (limited to 'runtime/test/vk_queue_test.cpp')
| -rw-r--r-- | runtime/test/vk_queue_test.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/runtime/test/vk_queue_test.cpp b/runtime/test/vk_queue_test.cpp index 744adfab8..8dad391b0 100644 --- a/runtime/test/vk_queue_test.cpp +++ b/runtime/test/vk_queue_test.cpp | |||
| @@ -64,6 +64,33 @@ VKAPI_ATTR VkResult VKAPI_CALL stalling_wait_semaphores(VkDevice device, const V | |||
| 64 | return real_wait_semaphores(device, info, timeout); | 64 | return real_wait_semaphores(device, info, timeout); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | // Each submission's command buffer starts with a full memory barrier (D3D12's ExecuteCommandLists boundary): counts | ||
| 68 | // the command buffers begun and those whose first barrier is that one. | ||
| 69 | PFN_vkBeginCommandBuffer real_begin = nullptr; | ||
| 70 | PFN_vkCmdPipelineBarrier real_barrier = nullptr; | ||
| 71 | std::uint32_t begun = 0, led_by_full_barrier = 0; | ||
| 72 | bool awaiting_first_barrier = false; | ||
| 73 | |||
| 74 | VKAPI_ATTR VkResult VKAPI_CALL counting_begin(VkCommandBuffer cb, const VkCommandBufferBeginInfo* info) { | ||
| 75 | ++begun; | ||
| 76 | awaiting_first_barrier = true; | ||
| 77 | return real_begin(cb, info); | ||
| 78 | } | ||
| 79 | |||
| 80 | VKAPI_ATTR void VKAPI_CALL watching_barrier(VkCommandBuffer cb, VkPipelineStageFlags src, VkPipelineStageFlags dst, | ||
| 81 | VkDependencyFlags flags, std::uint32_t memory_count, | ||
| 82 | const VkMemoryBarrier* memory, std::uint32_t buffer_count, | ||
| 83 | const VkBufferMemoryBarrier* buffers, std::uint32_t image_count, | ||
| 84 | const VkImageMemoryBarrier* images) { | ||
| 85 | if (awaiting_first_barrier) { | ||
| 86 | awaiting_first_barrier = false; | ||
| 87 | if (src == VK_PIPELINE_STAGE_ALL_COMMANDS_BIT && dst == VK_PIPELINE_STAGE_ALL_COMMANDS_BIT && | ||
| 88 | memory_count == 1 && (memory[0].srcAccessMask & VK_ACCESS_MEMORY_WRITE_BIT)) | ||
| 89 | ++led_by_full_barrier; | ||
| 90 | } | ||
| 91 | real_barrier(cb, src, dst, flags, memory_count, memory, buffer_count, buffers, image_count, images); | ||
| 92 | } | ||
| 93 | |||
| 67 | const char* flags_text(VkQueueFlags f) { | 94 | const char* flags_text(VkQueueFlags f) { |
| 68 | static char buf[32]; | 95 | static char buf[32]; |
| 69 | std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "", | 96 | std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "", |
| @@ -347,6 +374,38 @@ int main() { | |||
| 347 | EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported); | 374 | EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported); |
| 348 | std::printf("copy and compute queues refuse a render-target clear\n"); | 375 | std::printf("copy and compute queues refuse a render-target clear\n"); |
| 349 | 376 | ||
| 377 | // 4b. Two ExecuteCommandLists copying into the same buffer, with no barrier in either list: D3D12 orders them (each | ||
| 378 | // ends with its work done and visible), so each submission's command buffer must start with a full memory barrier. | ||
| 379 | // Before, none did, and synchronization validation reported WRITE_AFTER_WRITE between them (in 5 below). | ||
| 380 | { | ||
| 381 | void* map = nullptr; | ||
| 382 | VkBuffer twice_src = d.buffer(4096, usage, &map); | ||
| 383 | VkBuffer twice_dst = d.buffer(4096, usage, &map); | ||
| 384 | EXPECT(twice_src && twice_dst); | ||
| 385 | add_buffer(9, twice_src, 4096); | ||
| 386 | add_buffer(10, twice_dst, 4096); | ||
| 387 | CommandList twice; | ||
| 388 | EXPECT(twice.copy_buffer({10, 0, 9, 0, 4096})); | ||
| 389 | EXPECT(twice.close()); | ||
| 390 | const CommandList* twice_lists[] = {&twice}; | ||
| 391 | real_begin = context.vk.vkBeginCommandBuffer; | ||
| 392 | real_barrier = context.vk.vkCmdPipelineBarrier; | ||
| 393 | context.vk.vkBeginCommandBuffer = counting_begin; | ||
| 394 | context.vk.vkCmdPipelineBarrier = watching_barrier; | ||
| 395 | begun = led_by_full_barrier = 0; | ||
| 396 | for (Kind kind : {Kind::direct, Kind::copy}) { | ||
| 397 | VulkanQueue& q = kind == Kind::direct ? direct : copy; | ||
| 398 | EXPECT(q.execute(twice_lists) == ReplayResult::success); | ||
| 399 | EXPECT(q.execute(twice_lists) == ReplayResult::success); | ||
| 400 | EXPECT(q.idle()); | ||
| 401 | } | ||
| 402 | context.vk.vkBeginCommandBuffer = real_begin; | ||
| 403 | context.vk.vkCmdPipelineBarrier = real_barrier; | ||
| 404 | std::printf("ExecuteCommandLists boundary: %u of %u submissions start with a full memory barrier\n", | ||
| 405 | led_by_full_barrier, begun); | ||
| 406 | EXPECT(begun >= 4 && led_by_full_barrier == begun); | ||
| 407 | } | ||
| 408 | |||
| 350 | // 5. A caller that submits faster than the GPU finishes must not grow the queue's command buffers without bound: | 409 | // 5. A caller that submits faster than the GPU finishes must not grow the queue's command buffers without bound: |
| 351 | // at the cap it waits for the oldest one. Big host-visible copies keep the GPU behind the submitting loop. The first | 410 | // at the cap it waits for the oldest one. Big host-visible copies keep the GPU behind the submitting loop. The first |
| 352 | // waits time out (injected), as on a stalled GPU: the cap must hold through a timeout too. | 411 | // waits time out (injected), as on a stalled GPU: the cap must hold through a timeout too. |