diff options
| author | pmilewsskiedu-gif <pmilewsskiedu-gif@users.noreply.github.com> | 2026-11-22 20:51:10 -0500 |
|---|---|---|
| committer | pmilewsskiedu-gif <pmilewsskiedu-gif@users.noreply.github.com> | 2026-11-22 20:51:10 -0500 |
| commit | 00832c18cd3e429d7d9357466a9514be4101dfe1 (patch) | |
| tree | d7a151d5c2cc1b394ab2db4d9ebc21096d75102c /runtime/test/vk_queue_query_sync_test.cpp | |
| parent | 03b09a086592a197db64d91655c6e65c30764d96 (diff) | |
Runtime: propagate queue progress counter device loss
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 a03e369b9..913e1b102 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); |
| @@ -341,6 +362,35 @@ int main() { | |||
| 341 | context.remove_query_pool(main_heap); | 362 | context.remove_query_pool(main_heap); |
| 342 | std::printf("queue/query sync: concurrent multi-queue query stress ok\n"); | 363 | std::printf("queue/query sync: concurrent multi-queue query stress ok\n"); |
| 343 | } | 364 | } |
| 365 | |||
| 366 | // 5. A progress-semaphore query in acquire() can be the first Vulkan operation to discover | ||
| 367 | // device loss. A transient query failure must not poison a healthy queue, while DEVICE_LOST | ||
| 368 | // must prevent acquiring/recycling and submitting new command buffers. | ||
| 369 | { | ||
| 370 | EXPECT(!context.is_device_lost()); | ||
| 371 | CommandList empty; | ||
| 372 | EXPECT(empty.close()); | ||
| 373 | const CommandList* ptr = ∅ | ||
| 374 | EXPECT(queue_a.idle() && queue_b.idle()); | ||
| 375 | (void)context.completed_retire_ticket(); // drain old submits before faulting queue's own progress query | ||
| 376 | driver::fail_next_counter.store(VK_ERROR_OUT_OF_HOST_MEMORY); | ||
| 377 | const ReplayResult transient = queue_a.execute({&ptr, 1}); | ||
| 378 | const bool transient_ok = transient == ReplayResult::success && !context.is_device_lost() && | ||
| 379 | driver::injected_counter_errors.load() == 1; | ||
| 380 | |||
| 381 | EXPECT(queue_a.idle()); | ||
| 382 | (void)context.completed_retire_ticket(); | ||
| 383 | driver::fail_next_counter.store(VK_ERROR_DEVICE_LOST); | ||
| 384 | const ReplayResult after_loss = queue_a.execute({&ptr, 1}); | ||
| 385 | const bool lost = context.is_device_lost(); | ||
| 386 | std::printf("queue/query sync: injected nonfatal execute=%d, device-loss execute=%d, " | ||
| 387 | "context_lost=%d, interceptions=%u\n", int(transient), int(after_loss), int(lost), | ||
| 388 | driver::injected_counter_errors.load()); | ||
| 389 | progress_loss_ok = transient_ok && after_loss == ReplayResult::unsupported && lost && | ||
| 390 | driver::injected_counter_errors.load() == 2; | ||
| 391 | std::printf("queue/query sync: progress counter device loss %s\n", | ||
| 392 | progress_loss_ok ? "marks context and rejects work" : "NOT propagated"); | ||
| 393 | } | ||
| 344 | } | 394 | } |
| 345 | 395 | ||
| 346 | destroy_query_pool(d.device, pool_uaf, nullptr); | 396 | destroy_query_pool(d.device, pool_uaf, nullptr); |
| @@ -348,6 +398,7 @@ int main() { | |||
| 348 | destroy_query_pool(d.device, pool_stress, nullptr); | 398 | destroy_query_pool(d.device, pool_stress, nullptr); |
| 349 | 399 | ||
| 350 | EXPECT(d.validation_errors() == 0); | 400 | EXPECT(d.validation_errors() == 0); |
| 401 | EXPECT(progress_loss_ok); | ||
| 351 | std::printf("vk_queue_query_sync_test: ok\n"); | 402 | std::printf("vk_queue_query_sync_test: ok\n"); |
| 352 | return 0; | 403 | return 0; |
| 353 | } | 404 | } |