diff options
Diffstat (limited to 'runtime/test/vk_queue_query_sync_test.cpp')
| -rw-r--r-- | runtime/test/vk_queue_query_sync_test.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/runtime/test/vk_queue_query_sync_test.cpp b/runtime/test/vk_queue_query_sync_test.cpp index 49f4015c8..9aecd81cb 100644 --- a/runtime/test/vk_queue_query_sync_test.cpp +++ b/runtime/test/vk_queue_query_sync_test.cpp | |||
| @@ -29,10 +29,14 @@ namespace { | |||
| 29 | namespace driver { | 29 | namespace driver { |
| 30 | PFN_vkGetDeviceProcAddr real_get_device = nullptr; | 30 | PFN_vkGetDeviceProcAddr real_get_device = nullptr; |
| 31 | PFN_vkQueueSubmit real_submit = nullptr; | 31 | PFN_vkQueueSubmit real_submit = nullptr; |
| 32 | PFN_vkGetSemaphoreCounterValue real_counter = nullptr; | ||
| 32 | PFN_vkCmdCopyQueryPoolResults real_copy_queries = nullptr; | 33 | PFN_vkCmdCopyQueryPoolResults real_copy_queries = nullptr; |
| 33 | PFN_vkCmdFillBuffer real_fill_buffer = nullptr; | 34 | PFN_vkCmdFillBuffer real_fill_buffer = nullptr; |
| 34 | 35 | ||
| 35 | std::atomic<VkResult> fail_next_submit{VK_SUCCESS}; | 36 | std::atomic<VkResult> fail_next_submit{VK_SUCCESS}; |
| 37 | std::atomic<VkResult> fail_next_counter{VK_SUCCESS}; | ||
| 38 | std::atomic<unsigned> injected_counter_errors{0}; | ||
| 39 | std::thread::id counter_test_thread; | ||
| 36 | std::atomic<bool> capture_next_waits{false}; | 40 | std::atomic<bool> capture_next_waits{false}; |
| 37 | std::atomic<std::uint32_t> captured_wait_count{0}; | 41 | std::atomic<std::uint32_t> captured_wait_count{0}; |
| 38 | std::atomic<std::uintptr_t> captured_wait_sem{0}; | 42 | std::atomic<std::uintptr_t> captured_wait_sem{0}; |
| @@ -70,6 +74,18 @@ VKAPI_ATTR VkResult VKAPI_CALL queue_submit(VkQueue queue, std::uint32_t count, | |||
| 70 | return real_submit(queue, count, submits, fence); | 74 | return real_submit(queue, count, submits, fence); |
| 71 | } | 75 | } |
| 72 | 76 | ||
| 77 | VKAPI_ATTR VkResult VKAPI_CALL get_counter(VkDevice device, VkSemaphore semaphore, std::uint64_t* value) { | ||
| 78 | if (std::this_thread::get_id() == counter_test_thread) { | ||
| 79 | const VkResult result = fail_next_counter.exchange(VK_SUCCESS); | ||
| 80 | if (result != VK_SUCCESS) { | ||
| 81 | *value = 999; // failure output is undefined, so make accidental reuse detectable | ||
| 82 | injected_counter_errors.fetch_add(1); | ||
| 83 | return result; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | return real_counter(device, semaphore, value); | ||
| 87 | } | ||
| 88 | |||
| 73 | VKAPI_ATTR void VKAPI_CALL cmd_copy_query_pool_results(VkCommandBuffer cb, VkQueryPool pool, std::uint32_t first, | 89 | VKAPI_ATTR void VKAPI_CALL cmd_copy_query_pool_results(VkCommandBuffer cb, VkQueryPool pool, std::uint32_t first, |
| 74 | std::uint32_t count, VkBuffer dst, VkDeviceSize offset, | 90 | std::uint32_t count, VkBuffer dst, VkDeviceSize offset, |
| 75 | VkDeviceSize stride, VkQueryResultFlags flags) { | 91 | VkDeviceSize stride, VkQueryResultFlags flags) { |
| @@ -86,6 +102,7 @@ VKAPI_ATTR void VKAPI_CALL cmd_fill_buffer(VkCommandBuffer cb, VkBuffer dst, VkD | |||
| 86 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device(VkDevice device, const char* name) { | 102 | VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device(VkDevice device, const char* name) { |
| 87 | const std::string_view n = name; | 103 | const std::string_view n = name; |
| 88 | if (n == "vkQueueSubmit") return reinterpret_cast<PFN_vkVoidFunction>(queue_submit); | 104 | if (n == "vkQueueSubmit") return reinterpret_cast<PFN_vkVoidFunction>(queue_submit); |
| 105 | if (n == "vkGetSemaphoreCounterValue") return reinterpret_cast<PFN_vkVoidFunction>(get_counter); | ||
| 89 | if (n == "vkCmdCopyQueryPoolResults") return reinterpret_cast<PFN_vkVoidFunction>(cmd_copy_query_pool_results); | 106 | if (n == "vkCmdCopyQueryPoolResults") return reinterpret_cast<PFN_vkVoidFunction>(cmd_copy_query_pool_results); |
| 90 | if (n == "vkCmdFillBuffer") return reinterpret_cast<PFN_vkVoidFunction>(cmd_fill_buffer); | 107 | if (n == "vkCmdFillBuffer") return reinterpret_cast<PFN_vkVoidFunction>(cmd_fill_buffer); |
| 91 | return real_get_device(device, name); | 108 | return real_get_device(device, name); |
| @@ -94,6 +111,8 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device(VkDevice device, const char* | |||
| 94 | void install(PFN_vkGetDeviceProcAddr device_proc, VkDevice device) { | 111 | void install(PFN_vkGetDeviceProcAddr device_proc, VkDevice device) { |
| 95 | real_get_device = device_proc; | 112 | real_get_device = device_proc; |
| 96 | real_submit = reinterpret_cast<PFN_vkQueueSubmit>(device_proc(device, "vkQueueSubmit")); | 113 | real_submit = reinterpret_cast<PFN_vkQueueSubmit>(device_proc(device, "vkQueueSubmit")); |
| 114 | real_counter = reinterpret_cast<PFN_vkGetSemaphoreCounterValue>( | ||
| 115 | device_proc(device, "vkGetSemaphoreCounterValue")); | ||
| 97 | real_copy_queries = | 116 | real_copy_queries = |
| 98 | reinterpret_cast<PFN_vkCmdCopyQueryPoolResults>(device_proc(device, "vkCmdCopyQueryPoolResults")); | 117 | reinterpret_cast<PFN_vkCmdCopyQueryPoolResults>(device_proc(device, "vkCmdCopyQueryPoolResults")); |
| 99 | real_fill_buffer = reinterpret_cast<PFN_vkCmdFillBuffer>(device_proc(device, "vkCmdFillBuffer")); | 118 | real_fill_buffer = reinterpret_cast<PFN_vkCmdFillBuffer>(device_proc(device, "vkCmdFillBuffer")); |
| @@ -111,6 +130,7 @@ int main() { | |||
| 111 | return 77; | 130 | return 77; |
| 112 | } | 131 | } |
| 113 | driver::install(d.device_proc, d.device); | 132 | driver::install(d.device_proc, d.device); |
| 133 | driver::counter_test_thread = std::this_thread::get_id(); | ||
| 114 | 134 | ||
| 115 | const auto create_query_pool = d.fn<PFN_vkCreateQueryPool>("vkCreateQueryPool"); | 135 | const auto create_query_pool = d.fn<PFN_vkCreateQueryPool>("vkCreateQueryPool"); |
| 116 | const auto destroy_query_pool = d.fn<PFN_vkDestroyQueryPool>("vkDestroyQueryPool"); | 136 | const auto destroy_query_pool = d.fn<PFN_vkDestroyQueryPool>("vkDestroyQueryPool"); |
| @@ -129,6 +149,7 @@ int main() { | |||
| 129 | const VkQueryPool pool_race = make_occlusion_pool(2); | 149 | const VkQueryPool pool_race = make_occlusion_pool(2); |
| 130 | const VkQueryPool pool_stress = make_occlusion_pool(32); | 150 | const VkQueryPool pool_stress = make_occlusion_pool(32); |
| 131 | EXPECT(pool_uaf && pool_race && pool_stress); | 151 | EXPECT(pool_uaf && pool_race && pool_stress); |
| 152 | bool progress_loss_ok = true; // deferred verdict: release Vulkan query pools even when main is expected-red | ||
| 132 | 153 | ||
| 133 | { | 154 | { |
| 134 | VulkanContext context(driver::get_device, d.device, true); | 155 | VulkanContext context(driver::get_device, d.device, true); |
| @@ -408,6 +429,35 @@ int main() { | |||
| 408 | context.remove_query_pool(main_heap); | 429 | context.remove_query_pool(main_heap); |
| 409 | std::printf("queue/query sync: concurrent multi-queue query stress ok\n"); | 430 | std::printf("queue/query sync: concurrent multi-queue query stress ok\n"); |
| 410 | } | 431 | } |
| 432 | |||
| 433 | // 5. A progress-semaphore query in acquire() can be the first Vulkan operation to discover | ||
| 434 | // device loss. A transient query failure must not poison a healthy queue, while DEVICE_LOST | ||
| 435 | // must prevent acquiring/recycling and submitting new command buffers. | ||
| 436 | { | ||
| 437 | EXPECT(!context.is_device_lost()); | ||
| 438 | CommandList empty; | ||
| 439 | EXPECT(empty.close()); | ||
| 440 | const CommandList* ptr = ∅ | ||
| 441 | EXPECT(queue_a.idle() && queue_b.idle()); | ||
| 442 | (void)context.completed_retire_ticket(); // drain old submits before faulting queue's own progress query | ||
| 443 | driver::fail_next_counter.store(VK_ERROR_OUT_OF_HOST_MEMORY); | ||
| 444 | const ReplayResult transient = queue_a.execute({&ptr, 1}); | ||
| 445 | const bool transient_ok = transient == ReplayResult::success && !context.is_device_lost() && | ||
| 446 | driver::injected_counter_errors.load() == 1; | ||
| 447 | |||
| 448 | EXPECT(queue_a.idle()); | ||
| 449 | (void)context.completed_retire_ticket(); | ||
| 450 | driver::fail_next_counter.store(VK_ERROR_DEVICE_LOST); | ||
| 451 | const ReplayResult after_loss = queue_a.execute({&ptr, 1}); | ||
| 452 | const bool lost = context.is_device_lost(); | ||
| 453 | std::printf("queue/query sync: injected nonfatal execute=%d, device-loss execute=%d, " | ||
| 454 | "context_lost=%d, interceptions=%u\n", int(transient), int(after_loss), int(lost), | ||
| 455 | driver::injected_counter_errors.load()); | ||
| 456 | progress_loss_ok = transient_ok && after_loss == ReplayResult::unsupported && lost && | ||
| 457 | driver::injected_counter_errors.load() == 2; | ||
| 458 | std::printf("queue/query sync: progress counter device loss %s\n", | ||
| 459 | progress_loss_ok ? "marks context and rejects work" : "NOT propagated"); | ||
| 460 | } | ||
| 411 | } | 461 | } |
| 412 | 462 | ||
| 413 | destroy_query_pool(d.device, pool_uaf, nullptr); | 463 | destroy_query_pool(d.device, pool_uaf, nullptr); |
| @@ -415,6 +465,7 @@ int main() { | |||
| 415 | destroy_query_pool(d.device, pool_stress, nullptr); | 465 | destroy_query_pool(d.device, pool_stress, nullptr); |
| 416 | 466 | ||
| 417 | EXPECT(d.validation_errors() == 0); | 467 | EXPECT(d.validation_errors() == 0); |
| 468 | EXPECT(progress_loss_ok); | ||
| 418 | std::printf("vk_queue_query_sync_test: ok\n"); | 469 | std::printf("vk_queue_query_sync_test: ok\n"); |
| 419 | return 0; | 470 | return 0; |
| 420 | } | 471 | } |