From 00832c18cd3e429d7d9357466a9514be4101dfe1 Mon Sep 17 00:00:00 2001 From: pmilewsskiedu-gif Date: Sun, 22 Nov 2026 20:51:10 -0500 Subject: Runtime: propagate queue progress counter device loss --- runtime/test/vk_queue_query_sync_test.cpp | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'runtime/test/vk_queue_query_sync_test.cpp') 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 { namespace driver { PFN_vkGetDeviceProcAddr real_get_device = nullptr; PFN_vkQueueSubmit real_submit = nullptr; +PFN_vkGetSemaphoreCounterValue real_counter = nullptr; PFN_vkCmdCopyQueryPoolResults real_copy_queries = nullptr; PFN_vkCmdFillBuffer real_fill_buffer = nullptr; std::atomic fail_next_submit{VK_SUCCESS}; +std::atomic fail_next_counter{VK_SUCCESS}; +std::atomic injected_counter_errors{0}; +std::thread::id counter_test_thread; std::atomic capture_next_waits{false}; std::atomic captured_wait_count{0}; std::atomic captured_wait_sem{0}; @@ -70,6 +74,18 @@ VKAPI_ATTR VkResult VKAPI_CALL queue_submit(VkQueue queue, std::uint32_t count, return real_submit(queue, count, submits, fence); } +VKAPI_ATTR VkResult VKAPI_CALL get_counter(VkDevice device, VkSemaphore semaphore, std::uint64_t* value) { + if (std::this_thread::get_id() == counter_test_thread) { + const VkResult result = fail_next_counter.exchange(VK_SUCCESS); + if (result != VK_SUCCESS) { + *value = 999; // failure output is undefined, so make accidental reuse detectable + injected_counter_errors.fetch_add(1); + return result; + } + } + return real_counter(device, semaphore, value); +} + VKAPI_ATTR void VKAPI_CALL cmd_copy_query_pool_results(VkCommandBuffer cb, VkQueryPool pool, std::uint32_t first, std::uint32_t count, VkBuffer dst, VkDeviceSize offset, VkDeviceSize stride, VkQueryResultFlags flags) { @@ -86,6 +102,7 @@ VKAPI_ATTR void VKAPI_CALL cmd_fill_buffer(VkCommandBuffer cb, VkBuffer dst, VkD VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device(VkDevice device, const char* name) { const std::string_view n = name; if (n == "vkQueueSubmit") return reinterpret_cast(queue_submit); + if (n == "vkGetSemaphoreCounterValue") return reinterpret_cast(get_counter); if (n == "vkCmdCopyQueryPoolResults") return reinterpret_cast(cmd_copy_query_pool_results); if (n == "vkCmdFillBuffer") return reinterpret_cast(cmd_fill_buffer); return real_get_device(device, name); @@ -94,6 +111,8 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device(VkDevice device, const char* void install(PFN_vkGetDeviceProcAddr device_proc, VkDevice device) { real_get_device = device_proc; real_submit = reinterpret_cast(device_proc(device, "vkQueueSubmit")); + real_counter = reinterpret_cast( + device_proc(device, "vkGetSemaphoreCounterValue")); real_copy_queries = reinterpret_cast(device_proc(device, "vkCmdCopyQueryPoolResults")); real_fill_buffer = reinterpret_cast(device_proc(device, "vkCmdFillBuffer")); @@ -111,6 +130,7 @@ int main() { return 77; } driver::install(d.device_proc, d.device); + driver::counter_test_thread = std::this_thread::get_id(); const auto create_query_pool = d.fn("vkCreateQueryPool"); const auto destroy_query_pool = d.fn("vkDestroyQueryPool"); @@ -129,6 +149,7 @@ int main() { const VkQueryPool pool_race = make_occlusion_pool(2); const VkQueryPool pool_stress = make_occlusion_pool(32); EXPECT(pool_uaf && pool_race && pool_stress); + bool progress_loss_ok = true; // deferred verdict: release Vulkan query pools even when main is expected-red { VulkanContext context(driver::get_device, d.device, true); @@ -341,6 +362,35 @@ int main() { context.remove_query_pool(main_heap); std::printf("queue/query sync: concurrent multi-queue query stress ok\n"); } + + // 5. A progress-semaphore query in acquire() can be the first Vulkan operation to discover + // device loss. A transient query failure must not poison a healthy queue, while DEVICE_LOST + // must prevent acquiring/recycling and submitting new command buffers. + { + EXPECT(!context.is_device_lost()); + CommandList empty; + EXPECT(empty.close()); + const CommandList* ptr = ∅ + EXPECT(queue_a.idle() && queue_b.idle()); + (void)context.completed_retire_ticket(); // drain old submits before faulting queue's own progress query + driver::fail_next_counter.store(VK_ERROR_OUT_OF_HOST_MEMORY); + const ReplayResult transient = queue_a.execute({&ptr, 1}); + const bool transient_ok = transient == ReplayResult::success && !context.is_device_lost() && + driver::injected_counter_errors.load() == 1; + + EXPECT(queue_a.idle()); + (void)context.completed_retire_ticket(); + driver::fail_next_counter.store(VK_ERROR_DEVICE_LOST); + const ReplayResult after_loss = queue_a.execute({&ptr, 1}); + const bool lost = context.is_device_lost(); + std::printf("queue/query sync: injected nonfatal execute=%d, device-loss execute=%d, " + "context_lost=%d, interceptions=%u\n", int(transient), int(after_loss), int(lost), + driver::injected_counter_errors.load()); + progress_loss_ok = transient_ok && after_loss == ReplayResult::unsupported && lost && + driver::injected_counter_errors.load() == 2; + std::printf("queue/query sync: progress counter device loss %s\n", + progress_loss_ok ? "marks context and rejects work" : "NOT propagated"); + } } destroy_query_pool(d.device, pool_uaf, nullptr); @@ -348,6 +398,7 @@ int main() { destroy_query_pool(d.device, pool_stress, nullptr); EXPECT(d.validation_errors() == 0); + EXPECT(progress_loss_ok); std::printf("vk_queue_query_sync_test: ok\n"); return 0; } -- cgit v1.2.3