Repository navigation
Runtime: keep a resource released while a queue holds work until that work is submitted (D3D-203) - #4557
Runtime: keep a resource released while a queue holds work until that work is submitted (D3D-203)#4557requiemsnkrp wants to merge 1 commit into
Conversation
…submitted (D3D-203) Since ItsNotRexed#1654 the deletion queue retires a released resource's Vulkan objects on the completed prefix of device-wide submission tickets, so queues that complete out of submission order no longer free early. Work a queue holds on the CPU (Wait-before-Signal, queue_holds.h) has no ticket and names resources by ID, resolved when it is replayed: a resource released after B's later work completed was destroyed (and unregistered at once), and the held batch then failed with result 2 (unresolved resource), or resolved a reused address. - queue_holds.h: every held operation takes a place (held_added / held_removed, replacing held_changed); after_held() parks a release until every operation held at that moment, on any queue, has run or been dropped (later holds do not delay it); run_released() runs ready releases with no queue lock held, at the end of pump_ready() and from ~VulkanQueue. One atomic load when nothing is held. - vulkan_backend.h: VulkanQueue gives each Deferred op its place, returns it after run() (so the submission is recorded first), on fence release and at teardown; DeferredDeletionQueue::size() and VulkanContext::deferred_destructions() for tests. - d3d12_com_object.h: Object::Release calls Derived::final_release (default: delete). Resource::final_release parks the whole object through after_held(), so its ID, binding and Vulkan objects stay; ~Resource then runs as before and its objects take tickets after the held submissions. - d3d12_com.h / d3d12_vulkan_device.cpp: rt::d3d12::deferred_destruction(device) {kept, waiting} for tests. - queue_holds_test (CPU): out-of-order removal across queues, later holds ignored, runs once. - d3d12_queue_handover_test: queue A holds stage[0] -> readback behind a CPU-signalled Wait, queue B's later work completes four times, stage[0] is released in between: kept 2, waiting 0; the CPU Signal submits A's batch (kept 0, waiting 2), the readback is exact, two more B rounds destroy the objects (0/0). The never-signalled and released-fence cases check a resource only the dropped batch names is kept, then destroyed with it. With the parking disabled the case finds both destroyed before the Signal and the batch fails with result 2. RTX 3060 / 617.14, LEONIDA_VK_VALIDATION=1 (sync validation): 372 layer cases, 0 errors. - docs/d3d12_vulkan.md 4.4: deferred destruction across queues, what is still not covered. AI-assisted.
Kam471
left a comment
There was a problem hiding this comment.
Built and ran both tests at bd1d2b53 on Windows 11, RTX 5070 Ti: exit 0 for both.
d3d12_queue_handover_test: Vulkan layer 372 cases passed, every one exact; Host D3D12 (NVIDIA GeForce RTX 5070 Ti) 369 cases passed, every one exact. The held-resource scenarios reportreleased while held, after 4 completed submissions on queue B: kept 2, waiting 0, thenCPU Signal (held batch submitted): kept 0, waiting 2, thenkept 0, waiting 0after the batch completes. A never-signaled fence is held, does not affect other queues, and destroys without a hang (with the diagnostic naming the waiter).queue_holds_test:releases waited for the operations held before them, in any completion order, and ran once.
git diff --check clean.
|
Verified Hardware & validation results (
|
Kam471
left a comment
There was a problem hiding this comment.
Coordination note: #4570 (queue_holds_release_test) also edits runtime/src/queue_holds.h and the same execute_lists/Signal paths in runtime/src/vulkan_backend.h. It fixes the pending()-then-hold() window against remove_fence, which is complementary to this PR's place accounting, but the two overlap textually. Whichever lands first, the other needs a rebase and a fresh run; #4570 was verified independently at 299c98f1 (queue_holds_release_test passes).
|
Tested bd1d2b5 on NVIDIA GeForce RTX 4070 (driver 617.42), Windows 11 (26300), MSVC 19.44, scripts/build_runtime.ps1 (Ninja), RelWithDebInfo: pass. ctest 155/155 (GameInput disabled, no SDL3), including the new d3d12_queue_handover and queue_holds tests. I also read AI-assisted: read together with Codex (gpt-6.1-terra); I checked the snapshot logic against the code. |
|
Tested |
What and why
D3D-203 (claim). The out-of-order case the item names is already handled on
mainby @kovaaper's #1654: each submission takes a device-wide ticket on its own queue's timeline and only the completed prefix retires (retire_tickets_testcovers "A gated, B finishes first"). One hole remained: work a queue holds on the CPU (Wait-before-Signal,queue_holds.h, whose docs already said "D3D-203"). A held batch has no ticket yet and names resources by COM pointer, looked up only at replay.Failure on
main(reproduced): queue AWait(F,1)(F signalled by the CPU later), thenExecuteCommandListsreading R → held. Queue B submits and completes.Release(R)→remove_resourceat once; R's image and memory go after B's next completed submission. The CPU signals F; A's batch can't find R:[rt] d3d12: a held ExecuteCommandLists failed when it was released (result 2); nothing was submitted. With a new resource at the same address, the batch would use that one instead.Change
queue_holds.h: each held operation gets a sequence number (held_added/held_removed);after_held(release)parks a release until every operation held at that moment, on any queue, is submitted or dropped (later holds don't delay it);run_released()runs ready releases with no queue lock held (end ofpump_ready(),~VulkanQueue). Nothing held: one atomic load; no per-command work or allocation.vulkan_backend.h: an operation is marked done only afterrun(), so its ticket exists first (also on fence release / queue destruction).DeferredDeletionQueue::size(),VulkanContext::deferred_destructions()for tests.d3d12_com_object.h:Object::ReleasecallsDerived::final_release(default: delete).d3d12_vulkan_device.cpp:Resource::final_releaseparks the whole object (ID, registration, Vulkan objects all stay valid — a held batch also reaches resources through descriptors and must not see a reused address);~Resourcethen runs unchanged and its objects get tickets after the held submissions. Dropped held work (queue destroyed, fence released, device lost) releases its parked resources; a parked resource keeps its device reference, so shutdown still drains normally.rt::d3d12::deferred_destruction(device)→{kept, waiting}. Docs:docs/d3d12_vulkan.md§4.4 "Deferred destruction across queues" replaces the "not pinned, D3D-203" note.Tested (NVIDIA GeForce RTX 3060, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0,
LEONIDA_VK_VALIDATION=1+ sync validation)New
released_while_heldind3d12_queue_handover_test(A = DIRECT gated by a CPU-signalledWait, B = COPY); readback matches byte for byte:main's behaviour):kept 0, waiting 0, the check fails, stderr shows the "held ExecuteCommandLists failed" line above.queue_holds_test: removal in any order across queues, later holds ignored, each release runs once.vk_/d3d12_tests run under validation. Full ctest (no window tests): 142/142 vs 141/141 onmain03b09a0 (the newqueue_holds).git merge-tree).Open (not in this PR)
No game files. AI-assisted (Claude).