D3D12.X: stop retaining strong ID3D12CommandQueue refs in sparse tile quarantine and prune stale queue fences #2638
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2638
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Decodere on GitHub · 2026-11-26 04:00 UTC · original
Decodere:fix-sparse-queue-fences-com-ref-leak→main· +165 −51 · 1 files · 1 commits · openWhat 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.@ -1498,0 +1496,4 @@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();@luckyteagirl on GitHub · 2026-11-26 04:09 UTC · original
On 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.
@ -1498,0 +1496,4 @@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();@Decodere on GitHub · 2026-11-26 04:16 UTC · original
Good 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!@pickles976 on GitHub · 2026-11-26 04:43 UTC · original
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).@luckyteagirl on GitHub · 2026-11-26 04:09 UTC · original · reviewed
Source-derived production-path dependency on the open queue-release change; no local test run.
github-bot referenced this pull request2026-11-26 12:40:17 +00:00
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.