Repository navigation
D3D12.X: stop retaining strong ID3D12CommandQueue refs in sparse tile quarantine and prune stale queue fences - #2638
Conversation
… quarantine and prune stale queue fences Stop storing cloned `ID3D12CommandQueue` COM pointers in `sparse::State::queue_fences` (`FxHashMap<usize, (ID3D12Fence, u64)>` instead of retaining strong references forever). Remove `note_queue` and `sync_known_queues`, borrow active queues transiently via `from_raw_borrowed` in `flush_parked_with` (passing the executing queue from `before_execute`), filter deduplicated same-device queues in a pre-pass before signaling, and unconditionally prune stale fence entries while existing `RetiredTiles` batches keep their own fence clones until drained. Eliminates the permanent title-queue COM refcount leak, stale fence leaks, and raw-pointer ABA collisions. Part of xcl-dev#1668 Part of xcl-dev#1773 Part of xcl-dev#1833 Assisted-by: Google Antigravity (Gemini 4 Neon)
luckyteagirl
left a comment
There was a problem hiding this comment.
Source-derived production-path dependency on the open queue-release change; no local test run.
| return false; | ||
| } | ||
| let mut raw_ptrs: Vec<*mut c_void> = | ||
| super::present::known_queues().into_iter().filter(|&raw| raw != 0).map(|raw| raw as *mut c_void).collect(); |
There was a problem hiding this comment.
On this PR's b49be18 base, present::known_queues() is a monotonically growing registry: present::note_execute AddRefs and stores each queue, and no path removes it. That retained ref also prevents q_release's zero-ref callback. As a result, flush_parked_with keeps passing every once-submitted queue into flush_parked_for; live_keys never loses those queue addresses, so the new fence-entry retain cannot prune released title queues in production on this base. The added pruning test supplies flush_parked_for(&[]) directly, bypassing that production source. The PR description already notes #1691 is separate; could this explicitly depend on/stack with #1691's queue-removal wiring, with an integration test through flush_parked_with after a title queue is released, or qualify the stale-fence-pruning claim until that lands? This is source review only; I did not run the test.
AI-assisted review: OpenAI Codex (GPT-6; exact serving variant unavailable) and two Luna subagents independently checked the current source and PR diff.
There was a problem hiding this comment.
Good catch — you're right about the b49be183 base. On current main, present::QUEUES is still monotonically growing until #1691 lands, so on this base standalone this PR removes sparse::State::queue_fences's strong ID3D12CommandQueue retention and puts the queue_fences.retain(...) pruning path in place, while production shrinking of present::known_queues() (and switching flush_parked_with to a ref-holding snapshot like #1691's present::known_queues_held() so concurrent q_release cannot race borrowed pointers) activates once #1691 merges.
Kept strictly scoped to crates/xcl/src/hle/d3d12x/sparse.rs rather than stacking on #1691 so it stays conflict-free with #1691's present.rs / late_release.rs / real.rs edits, and updated the PR description (both What is in it and Not tested) to qualify the production pruning claim and unit-test entry point (flush_parked_for) explicitly. Thanks for the careful source review!
|
Wine/NVIDIA cross-check of all four new/updated tests — 5/5 pass on the real adapter. Head Note on the environment:
So on this stack the fix verifies exactly as scoped: no strong Logs: |
…cl-dev#2531 + xcl-dev#2638) (cherry picked from commit fa5b533156ecdf632edcb1b703c54a16948928bf)
Replace sparse tile quarantine's process-lifetime command-queue references with temporary active-queue snapshots and independently owned completion fences. Include installed central retirement markers, wait through the short Preparing state, and fail closed when retirement cannot provide a trustworthy completion source.\n\nPrune raw queue keys only through the exact Stage C retirement callback before address reuse; in-flight batches retain their own fence clones.\n\nAdapted from xcl-dev#2638 after central queue retirement was active.\n\nAssisted-by: Codex (GPT-5.6-sol)
Replace sparse tile quarantine's process-lifetime command-queue references with temporary active-queue snapshots and independently owned completion fences. Include installed central retirement markers, wait through the short Preparing state, and fail closed when retirement cannot provide a trustworthy completion source.\n\nPrune raw queue keys only through the exact Stage C retirement callback before address reuse; in-flight batches retain their own fence clones.\n\nAdapted from xcl-dev#2638 after central queue retirement was active.\n\nAssisted-by: Codex (GPT-5.6-sol)
|
Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head Tested
Not tested
AI use
|
|
Native Windows validation of #2638 on RTX 3070 Tested
The fixtures drive sparse retirement directly. They checked that a flush does not add a strong queue reference, that stale queue-fence entries are pruned while pending tile batches still honor their fences, and that tiles become reusable after both queues complete. Not tested The original end-to-end submitted-queue limit in #1668, the full workspace suite, the base at runtime, retail world loading, and VRAM savings. On the pinned source, AI use Codex GPT-6.2 inspected the exact diff, built and ran the existing fixtures, verified the native adapter selection, and drafted this report. |
Replace sparse tile quarantine's process-lifetime command-queue references with temporary active-queue snapshots and independently owned completion fences. Include installed central retirement markers, wait through the short Preparing state, and fail closed when retirement cannot provide a trustworthy completion source.\n\nPrune raw queue keys only through the exact Stage C retirement callback before address reuse; in-flight batches retain their own fence clones.\n\nAdapted from xcl-dev#2638 after central queue retirement was active.\n\nAssisted-by: Codex (GPT-5.6-sol)
Replace sparse tile quarantine's process-lifetime command-queue references with temporary active-queue snapshots and independently owned completion fences. Include installed central retirement markers, wait through the short Preparing state, and fail closed when retirement cannot provide a trustworthy completion source. Prune raw queue keys only through the exact Stage C retirement callback before address reuse; in-flight batches retain their own fence clones. Adapted from xcl-dev#2638 after central queue retirement was active. Assisted-by: Codex (GPT-5.6-sol)
What is in it
Part of #1668
Part of #1773
Part of #1833
sparse::State::queue_fences(crates/xcl/src/hle/d3d12x/sparse.rs:238) previously storedFxHashMap<usize, (ID3D12CommandQueue, ID3D12Fence, u64)>, populated byState::note_queueon everybefore_execute,readback_after_execute, andsync_known_queuescall without ever removing entries:ID3D12CommandQueueintoqueue_fencespermanently leaked an extra strong COM reference on every title command queue that submitted work while sparse windows were active, keeping released title queues alive (refcount >= 2) and re-triggering D3D12.X: E_OUTOFMEMORY after 63 submitted command queues #1668's 63-submitted-queueE_OUTOFMEMORYlimit even whenpresent::QUEUESdrops its reference.queue_fencesindefinitely, leaking theirID3D12Fenceobjects and causingquarantine_tilesto keep signaling dead queues on everyflush_parked().note_queueshort-circuited onqueue_fences.contains_key(&key), creating a raw-pointer ABA hazard where a newly created queue allocated at a recycled address was ignored while the old leaked queue continued to be signaled.Scope and dependency note on
b49be183: On currentmain,present::QUEUES(present::note_execute/present::known_queues()) is still a monotonically growing registry until #1691 (or equivalent queue-removal wiring inpresent.rs/late_release.rs/real.rs) lands. On this base standalone, this PR immediately removessparse::State::queue_fences's strongID3D12CommandQueuereference retention and puts thequeue_fences.retain(...)pruning mechanism in place; production shrinking ofpresent::known_queues()— and switchingflush_parked_withto a ref-holding snapshot such as #1691'spresent::known_queues_held()so concurrentq_releasecannot race borrowed raw pointers — activates once #1691 lands. Kept strictly scoped tocrates/xcl/src/hle/d3d12x/sparse.rs(+165/-51lines;State::waitedandrelease_if_unuseduntouched) to avoid conflicting with #1691:State::queue_fencestoFxHashMap<usize, (ID3D12Fence, u64)>soStatenever clones or retains strongID3D12CommandQueuereferences.note_queueandsync_known_queues, and removeds.note_queue(queue)frombefore_executeandreadback_after_execute.flush_parkedinto:flush_parked(&mut self) -> booldelegating toflush_parked_with(None).flush_parked_with(&mut self, extra: Option<&ID3D12CommandQueue>) -> bool(called ass.flush_parked_with(Some(queue))inbefore_execute): returnsfalseimmediately whenself.parked.is_empty(), otherwise collects unique non-null raw queue pointers fromsuper::present::known_queues()plusextra, borrows them viaID3D12CommandQueue::from_raw_borrowed(zeroAddRef/Release), and delegates toflush_parked_for.flush_parked_for(&mut self, queues: &[&ID3D12CommandQueue]) -> bool: unmaps parked tiles, signalsself.queue, and callsquarantine_tiles_for(tiles, queues).quarantine_tiles_for:CreateFence/Signalfailure cannot falsely prune another live queue): deduplicates live same-device queues (skipping null pointers,self.queue, and foreign-device queues) intoactive+live_keys, then unconditionally prunes stale entries viaself.queue_fences.retain(|k, _| live_keys.contains(k)). Earlier in-flightRetiredTilesbatches remain safely gated because each batch owns its ownID3D12Fenceclone inmarks.!tiles.is_empty()): lazily creates(ID3D12Fence, 0)per live queue, signalsq.Signal(&fence, next), records(fence.clone(), next)inmarks, and preserves fail-closedmarks: Noneon anyCreateFence/Signalerror.XCL_WARP=1in test helpertest_state_with_reservedso WARP coverage runs locally without touching hardware GPUs, updatedflush_parked_quarantines_tiles_until_title_queues_finishto callflush_parked_for(&[&title_q]), and added three regression tests:flush_parked_does_not_retain_title_queue_com_refsflush_parked_prunes_stale_queue_fences_while_inflight_batches_stay_gatedrepeated_queue_quarantine_and_release_does_not_leak_queues_or_fences(80 create/quarantine/drop/prune cycles on one device)Tested
rustc 1.100.0, DXC1.9.2609.5 (01b62ad4), release builds.b49be183(XCL_WARP=1): a temporary probe calling unmodifieds.note_queue(&title_q)+s.flush_parked()failed withunmodified State::note_queue leaked a strong COM ref on title_q (1 -> 2).XCL_ADAPTER=warp,XCL_WARP=1):cargo test --release -p xcl --lib -- hle::d3d12x::sparse::tests:: --nocapture->20 passed; 0 failed; 1 ignored(pre-existing#[ignore]benchmarkearly_commit_timing;0skipped).cargo test --release -p xcl --lib -- hle::d3d12x::sparse::tests:: --nocapture->20 passed; 0 failed; 1 ignored(0skipped).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37binaries,1438passed,0failed,47ignored (0warnings insparse.rs),29pre-existing environment-gatedSKIPPEDlines (none insparse::tests):21wave64-only GPU tests (no wave64on RTX 4060 32-lane waves)3per-lane wave32 shader tests (refused)3D3D12 debug layer tests (no d3d12SDKLayers.dll/ debug layer unavailable)1heap-window OOM fallback test (no heap windows)1PSO driver-cache measurement test (cannot disable the driver cache)Regression run
Paired 60 s retail smoke (
scripts/smoke.ps1, RTX 4060): both base and HEAD sustained60 60 60presents per 2 s with0device removals and0crashes (1533vs1579total frames,13998 MBvs13974 MBpeak commit).Base (
origin/main):HEAD (
fix-sparse-queue-fences-com-ref-leak):Not tested
flush_parked_with/present::known_queues()and title churn of > 63 distinctID3D12CommandQueuelifetimes combined with#1691(present::QUEUESremoval +known_queues_held()), since#1691is an open PR in separate files (present.rs/late_release.rs/real.rs); onb49be183,present::known_queues()does not remove released queues yet, so the unit tests verify queue refcount invariance, stale fence pruning, in-flight gating, and 80-cycle create/quarantine/drop/prune resilience directly viaflush_parked_foron both WARP and RTX 4060.AI use
Google Antigravity (Gemini 4 Neon) authored the
sparse::State::queue_fencesrefactoring, regression tests, and verification runs; verified via failing-first probe, WARP and RTX 4060 unit tests, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.