D3D12.X: stop retaining strong ID3D12CommandQueue refs in sparse tile quarantine and prune stale queue fences #2628
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2638"
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 ivall/xcl. Originally posted by Decodere on 2026-11-26T04:00:44Z.
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 #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.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T04:09:33Z.
Review: COMMENTED
Source-derived production-path dependency on the open queue-release change; no local test run.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T04:16:34Z.
Review: COMMENTED
No description provided.
Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-26T04:43:07Z.
Wine/NVIDIA cross-check of all four new/updated tests — 5/5 pass on the real adapter. Head
647234a21299ea308ba27d3ececab0f5db2bf6d2, Linux + Wine 11.0, vkd3d-proton 3.2.0 (2576c0b4adfae4a), NVIDIA 590.48.1, RTX 4060 Laptop GPU 8 GiB,--locked --target x86_64-pc-windows-msvc, one test thread, freshCompiling xcl .../xcl-pr2638/...provenance for each leg,DXVK_CONFIG='dxgi.hideNvidiaGpu = False'.Note on the environment:
XCL_WARP=1has no WARP under Wine (DXVK falls back to the NVIDIA adapter), so both legs below ran against the real device.flush_parkedfilter (4 tests, 4/4, 2.22 s):flush_parked_does_not_free_or_reuse_tiles_while_unmap_is_in_flight,flush_parked_does_not_retain_title_queue_com_refs,flush_parked_prunes_stale_queue_fences_while_inflight_batches_stay_gated,flush_parked_quarantines_tiles_until_title_queues_finish— all on the RTX 4060 Laptop, including the new COM-refcount invariance and stale-fence pruning checks.repeated_queue_quarantine_and_release_does_not_leak_queues_or_fences— 1/1 pass (1.03 s): the 80 create/quarantine/drop/prune cycles ran clean on the real device.So on this stack the fix verifies exactly as scoped: no strong
ID3D12CommandQueueretention inqueue_fences, stale fences pruned while in-flightRetiredTilesbatches stay gated. The acknowledged dependency gap stands as written: withpresent::QUEUESstill monotonic on this base, production pruning ofknown_queues()itself waits on #1691 — no end-to-end >63-queue title churn measured here, and no title run.Logs:
.compat-xcl/logs/verify-pr2638-wine-quarantine.log,verify-pr2638-wine-80cycles.log(local). AI-assisted verification and report (OpenAI Codex).Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T04:09:33Z.
Code review location:
crates/xcl/src/hle/d3d12x/sparse.rs; line 1499On this PR's
b49be18base,present::known_queues()is a monotonically growing registry:present::note_executeAddRefs and stores each queue, and no path removes it. That retained ref also preventsq_release's zero-ref callback. As a result,flush_parked_withkeeps passing every once-submitted queue intoflush_parked_for;live_keysnever loses those queue addresses, so the new fence-entryretaincannot prune released title queues in production on this base. The added pruning test suppliesflush_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 throughflush_parked_withafter 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.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T04:16:34Z.
Code review location:
crates/xcl/src/hle/d3d12x/sparse.rs; line 1499Good catch — you're right about the
b49be183base. On currentmain,present::QUEUESis still monotonically growing until #1691 lands, so on this base standalone this PR removessparse::State::queue_fences's strongID3D12CommandQueueretention and puts thequeue_fences.retain(...)pruning path in place, while production shrinking ofpresent::known_queues()(and switchingflush_parked_withto a ref-holding snapshot like #1691'spresent::known_queues_held()so concurrentq_releasecannot race borrowed pointers) activates once #1691 merges.Kept strictly scoped to
crates/xcl/src/hle/d3d12x/sparse.rsrather than stacking on #1691 so it stays conflict-free with #1691'spresent.rs/late_release.rs/real.rsedits, 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!Imported from ivall/xcl. Originally posted by rgroenewoudt on 2026-11-26T16:50:11Z.
Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head
647234a: no new failures; the sparse tests behave as onmain.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4: 1436 passed, 2 failed, 47 ignored. The 2 failures arefuzz_validate_and_gpu_1(seed 722) and_3(seed 1599), the AMD ones from #2115, not touched here.cargo test -p xcl --lib -- hle:: --test-threads=12, 20 runs:a_dispatch_with_a_pipeline_still_building_waits_at_the_submitfailed 12/20 anda_tile_decommitted_and_committed_again_keeps_its_video_memory3/20. The same loop on the same baseb49be18without this PR gave 13/20 and 2/20 on this card, so no change either way (#2775 addresses the second one).heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Not tested
AI use
Imported from ivall/xcl. Originally posted by razormontana on 2026-11-26T20:20:12Z.
Native Windows validation of #2638 on RTX 3070
Tested
647234a21299ea308ba27d3ececab0f5db2bf6d2, based onb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7. Windows 11 Pro build 22631, Intel Core i7-10700K, 32 GB RAM, NVIDIA GeForce RTX 3070 8 GB, driver 617.42 (32.0.16.1742), Rust 1.100.0 MSVC, debug.XCL_ADAPTER=3070withXCL_WARPand external game sample variables unset. An independent D3D12 probe used the same default-device selection as the fixtures and identified the RTX 3070 (8,018 MiB dedicated, no software flag).cargo test --offline --locked -j 1 -p xcl --lib --no-runcompiled the library tests.cargo test --offline --locked -j 1 -p xcl --lib hle::d3d12x::sparse::tests::flush_parked_ -- --test-threads=1 --nocapturereported 4 passed, 0 failed, 0 ignored, and 0 explicit skips.cargo test --offline --locked -j 1 -p xcl --lib hle::d3d12x::sparse::tests::repeated_queue_quarantine_and_release_does_not_leak_queues_or_fences -- --exact --test-threads=1 --nocapturereported 1 passed, 0 failed, 0 ignored, and 0 explicit skips. The fixture completed 80 sequential queue lifecycles.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,
present::note_executestill retains submitted queues in the registry read bypresent::known_queues(). #1691 changes that separate submit-tracking path and was outside this validation. A combined review should check that queue references stay valid from the snapshot through fence signaling.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.
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T01:54:02Z.
Triage note: this no longer merges with current
main(mergeable=false), so it cannot be built or tested as it stands.Why I am asking rather than just noting it: we have run fifteen mergeable candidates on the retail title on an RTX 5070 Ti, and every one still stops presenting at 50–80 s (device removed, surfacing ~88 s later on the next allocation). The PRs whose descriptions actually match that symptom are the ones that no longer apply — this is one of them. A rebase would make it testable again, and we will run it and report the numbers.
If it has been superseded by merged work, saying so is enough and it can be closed.
AI use: an agent posted this triage note.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:31:41Z.
Triage (#1607) – head
647234amain has this change. Commit
22f80d5("D3D12.X: retire sparse queue fences without owning queues") says it was adapted from this PR. Insparse.rsmain'squeue_fencesisFxHashMap<usize, (ID3D12Fence, u64)>, andquarantine_tiles_forsignals a temporary snapshot of the live queues, so no queue is kept alive. In-flight batches keep their own fence clones. Stale keys are removed byforget_queuewhen a queue is retired, before its address can be reused, not by the prune-on-flush used here. #1691 (same issue #1668) changeslate_release.rs/present.rs/real.rsand does not overlap this diff.Recommendation: close (superseded by main commit
22f80d5).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:56:03Z.
Closing as superseded: this change is already on
main(22f80d5e). main sparse.rs queue_fences is FxHashMap<usize,(ID3D12Fence,u64)> (non-owning) and quarantine_tiles_for takes the live queues and prunes stale fences; remove_queue_fence on queue forgetTwo independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed