From f8007dda67f9c45757b63df5c5fd8377647da4ae Mon Sep 17 00:00:00 2001 From: AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:02:33 +0100 Subject: Queue holds: review fixes (Present ordering, pins, timeline monotonicity, fence lifetime, teardown, docs) - Present is queued behind held work (QueueHolds::after_held) and submitted in order by the releasing thread. - Held batches keep the pipeline states and root signatures of their lists; fences a queue waits on or signals are kept until the submission has completed on the GPU (a D3D12 queue holds them). - A held Signal released below an unheld one on the same fence leaves the Vulkan signal out (claimed under the submit lock). - A queue destroyed with held Signals completes the CPU waits on their fences and reports it. - A failed held batch is reported (take_held_failure, last_execute_result), its waits stay for the next submission, and the Signal behind it still signals. - d3d12_queue_handover_test: pairs, two-thread signalling stress, held Signal of a released fence, shared fence, teardown with a CPU waiter; --two-queues and --shared-queue modes on a caller-owned device. - Tests for each fix in vk_presenter_sync_test, vk_queue_query_sync_test and d3d12_m4_compute_test; docs section 4.4. Co-Authored-By: Claude Opus 5.5 --- runtime/test/vk_queue_query_sync_test.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 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..b7237b911 100644 --- a/runtime/test/vk_queue_query_sync_test.cpp +++ b/runtime/test/vk_queue_query_sync_test.cpp @@ -291,6 +291,46 @@ int main() { std::printf("queue/query sync: pending Wait() preserved across failed vkQueueSubmit ok\n"); } + // 3b. The same for a batch held behind a Wait with no submitted Signal (queue_holds.h): its submission + // fails when the CPU Signal releases it, the failure is reported through take_held_failure(), and its + // waits stay for the next submission, as when the call is not held. A Signal queued behind the failed + // batch still runs. + { + VulkanFence gate(context, 0), after(context, 0); + EXPECT(gate.semaphore() != VK_NULL_HANDLE && after.semaphore() != VK_NULL_HANDLE); + const std::uint64_t pattern = 0x0badf00dcafe1234ULL; + std::memcpy(src_ptr, &pattern, sizeof(pattern)); + std::memset(dst_ptr, 0, sizeof(pattern)); + CommandList copy_list; + EXPECT(copy_list.copy_buffer({2, 0, 1, 0, sizeof(pattern)})); + EXPECT(copy_list.close()); + const CommandList* ptr = ©_list; + + queue_a.wait(gate.semaphore(), 1); + EXPECT(queue_a.execute({&ptr, 1}) == ReplayResult::success); // held: the Signal is not submitted yet + EXPECT(queue_a.signal(after.semaphore(), 1)); // held behind it + EXPECT(after.completed() == 0 && queue_a.take_held_failure() == ReplayResult::success); + driver::fail_next_submit.store(VK_ERROR_OUT_OF_HOST_MEMORY); + EXPECT(gate.signal(1)); // releases the batch on this thread + EXPECT(queue_a.take_held_failure() == ReplayResult::unsupported); + EXPECT(queue_a.take_held_failure() == ReplayResult::success); // reported once + EXPECT(queue_a.idle() && after.completed() == 1); // the Signal behind it still signaled + + driver::captured_wait_count.store(0); + driver::captured_wait_sem.store(0); + driver::captured_wait_val.store(0); + driver::capture_next_waits.store(true); + EXPECT(queue_a.execute({&ptr, 1}) == ReplayResult::success); + EXPECT(queue_a.idle()); + EXPECT(driver::captured_wait_count.load() == 1); // the failed batch's wait on (gate, 1) came along + EXPECT(driver::captured_wait_sem.load() == reinterpret_cast(gate.semaphore())); + EXPECT(driver::captured_wait_val.load() == 1); + std::uint64_t got = 0; + std::memcpy(&got, dst_ptr, sizeof(got)); + EXPECT(got == pattern); + std::printf("queue/query sync: failed held batch reported, its wait kept for the retry, Signal behind it ran\n"); + } + // 4. Concurrent multi-queue EndQuery + ResolveQueries + temporary query pool add/remove stress. // Each iteration uses a distinct query slot so no slot is reset while another submission resolves it. { -- cgit v1.2.3