GPU: keep command queues alive while HELD tracks pending work #3253
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3255"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T14:44:14Z.
Summary
queue::execute,queue::signal, andqueue::waitpreviously stored raw*const Queueaddresses (this as usize) inHELDwithout retaining a COM reference to the queue object. Under D3D12, a title may legally release anID3D12CommandQueuewhile submitted command lists, signals, or fence waits are still pending. Doing so freedBox<Queue>whileHELDstill tracked items under that address, causing two bugs:pump()(for safety-valve warnings and released-work accounting) andaccount_frame()calledkind(queue)on the freedQueuepointer.account_frame()also dropped theHELDmutex before readingkind(*queue), racing withpump_helddraining and freeing the queue concurrently.ID3D12CommandQueuereused the freedBox<Queue>address, its independent work was queued behind the released queue's blocked wait inHELD, stalling unrelated submissions (including the work meant to unblock the wait).Changes
HELDinHolding { held, pinned }incrates/victory-gpu/src/queue.rs:Holding::pushcallsobject::add_ref(queue)once per distinct queue when itsHELDFIFO becomes non-empty and records its address inpinned.pumptakes theHELDlock guard by value, finishes allkind(queue)reads while drained queues are still pinned, extracts drained queues viaHolding::take_drained(), drops theHELDlock, and then callsrelease(queue)outside the lock (preserving lock ordering without nestingHELD -> PRIVATE).account_frameresolveskind(queue)intou32queue kinds while still holdingHELD.crates/victory-gpu/src/queue.rs:released_queue_holding_work_stays_alive_and_does_not_alias_new_queues(reproduces the UAF + ABA address-reuse deadlock before the fix and verifies clean drain + zero D3D12 debug layer messages after).held_queue_pinning_handles_multiple_items_signals_waits_and_concurrent_accounting(covers single-ref deduplication across multiple lists and heldSignal,Item::FenceWaitpinning/unpinning, and concurrentaccount_framevs.pump_helddrain).Verification
cargo test -p victory-gpu --lockedtargeted queue/hold/fence tests: 20 passed (RTX 5090 default, RTX 5090 +VICTORY_D3D12_DEBUG=1 --features diagnostics --test-threads=1, and WARP +VICTORY_D3D12_DEBUG=1 --features diagnostics --test-threads=1).victory-gpusuite on WARP (VICTORY_D3D12_WARP=1 --features diagnostics --locked): 248 passed, 0 failed, 1 ignored.cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features: clean.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T14:47:36Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):
eleased_queue_holding_work_stays_alive_and_does_not_alias_new_queues).
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:48:38Z.
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:cargo test -p victory-gpu --lib: 233 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.Both new tests —
released_queue_holding_work_stays_alive_and_does_not_alias_new_queuesandheld_queue_pinning_handles_multiple_items_signals_waits_and_concurrent_accounting— are in that count and pass, so the pinning/aliasing accounting is exercised against a real device. Synthetic only. AI-assisted.Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T01:47:19Z.
Heads-up: this conflicts with #3227 in
queue.rs; a resolution that keeps both fixes, tested on WARPThis head
a4690408and #32278ef3f17dboth start from main63bcca43and both redefinequeue::Holding. Here it's a struct that pins queues; in #3227 it'sHeld<_, KeptFence>.git merge-treegives 5 conflict hunks inqueue.rs:Holding,signal,wait, and the two test blocks. So whichever lands second needs a rebase. I found no mention of the pairing on either PR, and neither is in #3409's tested set.Smallest resolution I tested. Keep #3227's
KeptFenceunchanged, keep this PR'sHoldingwith #3227's token type, and keep all three tests. Production hunks:pumpauto-merges correctly: #3227'sKeptFenceclosures are used throughguard.held, andtake_drainedandreleaserun after the lock is dropped.On that tree,
cargo build -p victory-gpu --libandcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features) are clean. WARPqueue::+hold::+fence::pass 21/21, also with each test in its own process.Do the existing tests still cover both fixes after the merge? I changed one thing at a time and ran each test in its own process.
Detected:
object::add_refinHolding::push(this PR's pin removed)KeptFenceholds no reference (#3227's keep removed)cross_queue_fence_wait_keeps_fence_alive_until_satisfied("queued Signal holds one reference": 1, want 2)Not detected:
waitpushes unconditionally (this PR's side of that hunk)Within the tested cases, this change makes no observable difference in behaviour: an already-satisfied wait is popped and its fence reference dropped at the next pump. That doesn't establish the change is harmless in general. No test pins that choice, so the resolution above keeps #3227's check.
Lock order, within the code I read.
KeptFencecan release a fence's last reference whileHELDis held, andrelease_boxedthen takesPRIVATE. This PR moves queue releases out ofHELDfor that reason. In the mergedqueue.rs,fence.rsandobject.rs, main'spumpalready releases fences underHELD(fence::let_goin its signal closure), and none of theprivate_data()callers there call into the queue code. So I found no new lock cycle in those files. I didn't audit other modules for code that takesPRIVATEand thenHELD.The full resolved
queue.rsdiff is available on request.Windows 11, Ryzen 7 7445HS, WARP, synthetic data only.
AI-assisted (Claude Code).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.