D3D12.X: detach retired segments and reclaim idle aside allocators #2697
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2707"
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 Saksukella on 2026-11-26T07:51:59Z.
What is in it
crates/xcl/src/hle/d3d12x/alloc_pool.rs:retire_recording(list)to detach a retired split segment or superseded primary list from its oldBacking.userswhile preservingBacking.marksandlast_submit(so GPU completion fences andin_flight(list)remain fully enforced).Backing.already_resetand reclaim idlefree()put-aside backings ontitle_resetso their held UMA arena blocks and scratch buffers return promptly instead of remaining pinned until a future busy swap on that exact title allocator.STATEbefore callingreset_pc_allocator/CreateCommandAllocatorso COM callbacks during allocator reset or resource teardown (such as dropping a pooled preludeID3D12CommandAllocator->real::alloc_release->alloc_pool::forget) cannot self-deadlock onSTATE, and release pending UMA blocks per free backing onforget.title_reset/reset_listraces whileSTATEis unlocked: trackBacking.resetting(Backing::free()requires!self.resetting) with aCondvar(RESET_DONE), reserve the backing inreset_listbefore invoking nativeReset(rolling back onhr < 0), and wait cleanly if a backing is mid-reset.retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight,clean_title_reset_reclaims_idle_aside_backings_once,stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets,reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure, andreset_list_waits_while_backing_is_resetting.crates/xcl/src/hle/d3d12x/bind.rs&crates/xcl/src/hle/d3d12x/real.rs:bind::State.allocator(and thereforeconsole_list::PENDINGUMA blocks) by the native PC allocator backing (alloc_pool::recording_backing/alloc_pool::current) rather than the logical title allocator, and moveconsole_list::allocator_reset(raw)intoreal::reset_pc_allocator(raw)so swapping away from an in-flight primary backing never frees its UMA blocks while the GPU can still read them.crates/xcl/src/hle/d3d12x/title_list.rs&crates/xcl/src/hle/d3d12x/list_x.rs:alloc_pool::retire_recordingwhentitle_list::resetmoves old split/stand-in segments intospares(and forprimarywhen replaced by astand_in, retiring its UMA blocks viabind::reset(primary, 0, 0)), input_spare, and forKickoffX-reclaimed segments inlist_x.rsafteralloc_pool::executedmarks them.Tested
32.0.32029.2010), 24-thread x86_64 CPU, 32 GB RAM, Windows;rustc 1.100.0 (0ef1bc386 2026-11-09); debug (tests) and release (xcl.exe).cargo test -p xcl --lib hle::d3d12x::alloc_pool::tests -- --test-threads=1: 9 passed, 0 failed (0.11s, includingstalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets,reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure, andreset_list_waits_while_backing_is_resetting).cargo test -p xcl --lib hle::d3d12x::bind::tests -- --test-threads=1: 8 passed, 0 failed (0.38s).cargo test -p xcl --lib hle::d3d12x::title_list::tests -- --test-threads=1: 3 passed, 0 failed (0.01s).amd-dev(b5c0275f): previouslycoherentUMA exhausted4095/4095 MB(547 blocks held for 236 allocatorsat63.7k draws / 34.6k dispatches), triggeringunified memory is fulland0x887a0006; with this fix held blocks dropped by >72% (152 blocks / 75 allocators,4046/4095 MBat65.5k draws / 47.0k dispatches) with0unified memory is fullwarnings.Regression run
Not tested
cargo test --workspacewas run on the same baseb49be183in #2703 (1434passed; pre-existing RDNA 4fuzz_validate_and_gpu_1/3failures).AI use
resetting/Condvarconcurrency guard, writing unit tests, and running local tests and smoke verification. All diffs and measurements were reviewed and verified locally on hardware.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T08:18:56Z.
Review: COMMENTED
At head
7879954925faaa048293f28857febf9eb8aa503b, the newbind::reset(primary, 0, 0)runs precisely whentitle_list::resetselects a stand-in because the primary PC list is still in flight (title_list.rs:157-201).bind::resetmoves that primary recording's UMA blocks toconsole_list::PENDINGunder its old logical title allocator (bind.rs:75-87). A subsequent successful title-allocatorResetcan swap to a different native backing while the old primary is still in flight, butreal::alloc_resetunconditionally callsconsole_list::allocator_reset(this)on success (real.rs:7047-7057), which frees all pending blocks under that logical allocator. The GPU can therefore still read blocks freed by the new stand-in path. Before this PR, the stand-in branch did not transfer the primary's bind blocks at that point. Could those blocks stay owned by the old primary/native backing until its fence completes, with the pending-key/reset path tracking that backing rather than the logical allocator? A regression with a GPU-stalled primary, stand-in list reset, and title-allocator reset would distinguish the two lifetimes.This is an exact-head source review; I did not run a GPU-stalled title reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) traced the interleaving; I checked the bind, pool, and allocator-reset paths before posting.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-26T08:14:57Z.
Rerun on the new head
1a3b698(the two lifetime fixes from thehollowedone's review): passes on NVIDIA, and each of the 3 newalloc_pooltests fails when the fix it guards is put back.cargo test --workspace --no-fail-fast -- --test-threads=4,1a3b698(its base is currentmainb49be18, so this is also the merged tree)SKIPPEDlinesreset_list_preserves_previous_backing_until_native_success,forget_does_not_release_a_busy_original_backing_twice_and_reclaims_when_idle,forget_racing_mid_reset_list_cleans_up_on_rollback_and_commit, alone, 40 runs eachhle::d3d12x::alloc_pool::(12 tests),--test-threads=8, 40 runstry_reserve_backingback tomove_list(s, list, backing)(old backing detached before Reset succeeds), each new test alonereset_list_preserves_…fails (s.backings[&old].users.contains(&list)),forget_racing_…fails;forget_does_not_…passesforgetdrops a busy backing instead of pushing it toorphaned(the old behaviour), each new test aloneforget_does_not_…fails (s.orphaned.iter().any(…)),forget_racing_…fails (committed forgotten backing must not recreate a zombie backing);reset_list_preserves_…passese2etest_title_draws_with_a_root_signature_under_the_debug_layermain: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exitWith both mutations, running the whole
alloc_pool::module fails 6 to 9 of its 12 tests, because one failure poisons the shared state for the rest; alone, only the tests above fail. Same RTX 3060 (driver 610.88), Rust 1.100.0, debug. Not tested: a title, AMD / Intel.AI use: Claude Code (Claude Opus 5.5) ran the tests and mutations and wrote this rerun.
Rerun on
dff6edc: still passed on NVIDIA.cargo test --workspace --no-fail-fast -- --test-threads=4,dff6edcmerged ontomainb49be18(clean)SKIPPEDlinesalloc_pool::+title_list::+bind::+console_list::+real::dispatch_chain::(29 tests),--test-threads=8, 30 runshle::d3d12x::list_x::tests::,--test-threads=4, 100 runsa_dispatch_with_a_pipeline_still_building_waits_at_the_submit7×,rotating_queue_…1×, the twomainflakesRerun on
f796b9e: still passed on NVIDIA, and the new test was stable.cargo test --workspace --no-fail-fast -- --test-threads=4,f796b9emerged ontomainb49be18(clean)SKIPPEDlinesstalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets), alone, 40 runs eachalloc_pool::+title_list::+bind::+console_list::+real::dispatch_chain::(27 tests),--test-threads=8, 30 runshle::d3d12x::list_x::tests::,--test-threads=4, 100 runsa_dispatch_with_a_pipeline_still_building_waits_at_the_submit, themainflakee2edebug-layer testmain(3× id 93, 1× id 1046, 1× warning id 820, 8× id 0)First run, on
7879954: NVIDIA run: passed; both new tests stable,list_xno different frommainin parallel, debug-layer messages as onmain.Tested:
7879954merged ontomainb49be18(clean). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, Graphics Tools (D3D12 debug layer) installed.cargo test --workspace --no-fail-fast -- --test-threads=4SKIPPEDlinesretired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight,clean_title_reset_reclaims_idle_aside_backings_once, alone, 40 runs eachhle::d3d12x::alloc_pool::+title_list::+real::dispatch_chain::(11 tests),--test-threads=8, 30 runshle::d3d12x::list_x::tests::,--test-threads=4, 100 runsa_dispatch_with_a_pipeline_still_building_waits_at_the_submit(7×) androtating_queue_self_deadlock_…(3×), the two that flake onmainthe same way (#2118, #2547)e2etest_title_draws_with_a_root_signature_under_the_debug_layer, merged vsmainNot tested: a title run, Intel, a release build.
AI use: Claude Code (Claude Opus 5.5) ran the suite, the repeats and the debug-layer comparison, and wrote this report.
Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T08:48:47Z.
Test report: passes on NVIDIA. Exact head
78799549(its base is currentmainb49be18, so head = merged).Tested
cargo test --workspace -- --test-threads=4: 1437 passed, 0 failed, 47 ignored; the 2 new tests passmainon this machine (wave64, debug layer, Developer Mode, heap windows)Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by Saksukella on 2026-11-26T08:55:33Z.
Good catch @luckyteagirl — fixed in
f796b9e6.bind::State.allocator(and thusconsole_list::PENDING) is now keyed by the native PC allocator backing (alloc_pool::recording_backing/alloc_pool::current) rather than the logical title allocator, andconsole_list::allocator_resetnow runs insidereal::reset_pc_allocator(and for free backings inalloc_pool::forget) rather than unconditionally onalloc_reset(this). Added the regression teststalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resetscovering a GPU-stalled primary, stand-in reset, title-allocator swap reset, and post-fence reclaim. Re-ranalloc_pool(7/7),bind(8/8),title_list(3/3), and a 60s RX 9070 XT smoke run (1669 frames, 0 removals, 0 crashes).Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-26T09:25:12Z.
A gap in
retire_recording's call sites, found while reading this PR next to #2404 (a code read, not a run). At068671d:title_list::reclaim_for_kickoff(list_x.rs:3330). That moves the reclaimed segments, the active one included, into the wrapper'sspares(title_list.rs:344) withoutretire_recording.priorin the loop that follows, and the active segment atalloc_pool::executed(q_raw, &one)(list_x.rs:3355). After that they stay in their old backing'susers, the way the Reset path's segments did before this PR. So that PC allocator stays "aside with a list on it" until the spare is reset elsewhere.executed()marks them. Detached before it, the submit would leave their backing unmarked, and the backing could be reset while the GPU runs it.Suggested fix: call
super::alloc_pool::retire_recording(seg);in thefor seg in reclaimedloop atlist_x.rs:3377-3380(next tobind::resetandclear_segment_state), which runs after line 3355.AI use: Claude Code with Claude Opus 5.5 read the code and wrote this note.
Imported from ivall/xcl. Originally posted by Saksukella on 2026-11-26T09:39:02Z.
Good catch @Kalmarv — added
super::alloc_pool::retire_recording(seg);in theKickoffXreclaimed-segments loop atlist_x.rs(afteralloc_pool::executedmarks them) indff6edc7(along with dropping an orphanedResetCurrentbacking ifforgetraced). Re-ranalloc_pool::tests(9/9) and 60s RX 9070 XT smoke (1669 frames, 0 removals, 0 crashes).Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-26T09:46:16Z.
Exact-head allocator lifetime check on
dff6edc7(including the new KickoffX change). I found two paths the current nine allocator tests do not cover. Both fail with the test-only witnesses below; the existing nine pass.try_reserve_backingmoves a list from old backing A to current backing B before calling nativeReset(B). If a concurrent title allocator reset reclaims the now apparently free A, andReset(B)fails,rollback_backingrestores the list→A mapping after A's commands have been discarded. The witness starts with a closed recording on A, resets toward B, reclaims A inside the reset callback, returnsE_FAIL, and observes A was reset. The existing rollback test starts with no previous recording. Reservation · Reset/rollback. Microsoft says an allocator reset reuses the memory behind recorded commands and must wait for GPU work on that allocator: allocator Reset contract.forget(A)visits[A, B, A]. The first A visit removes its busyBacking; the second sees no record, treats A as free, and callsconsole_list::allocator_reset(A). The witness leaves A held by a live recording and confirms its pending UMA entry has disappeared. With actual UMA blocks, that reset path callsfree_uma. Release loop · UMA release.For the first path, reserve B while keeping A's existing user until native Reset succeeds; then move the association. On failure, release only the temporary B reservation. For the second, deduplicate backing IDs before inspecting/removing them. Deduplication alone prevents the early drain but does not solve eventual cleanup: a busy backing's pending UMA and fence/list ownership must survive final title-allocator release until safe reclamation, including allocator-address reuse.
Tested: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, rustc 1.99.1 MSVC, debug. On this head with only the two test functions added:
cargo test --offline --locked -p xcl --lib reset_list_preserves_previous_backing_until_native_success -- --nocapture --test-threads=1: 0 passed, 1 failed; previous A was reset before the native callback returned.cargo test --offline --locked -p xcl --lib forget_does_not_release_a_busy_original_backing_twice -- --nocapture --test-threads=1: 0 passed, 1 failed; pending entry was empty.hle::d3d12x::alloc_pool::testswith those two names skipped: 9 passed, 0 failed.Test-only diff against
dff6edc7These are synthetic state tests; they do not reproduce a retail crash or measure GPU memory pressure. I did not run the full workspace suite or paired smoke on this head. No game files or diagnostics were used.
AI use: Codex (GPT-6.2 Sol) inspected the paths, added and ran the witnesses, and drafted this comment; Codex (GPT-6.2 Astra) independently reviewed the allocator lifetimes.
Imported from ivall/xcl. Originally posted by Saksukella on 2026-11-26T11:33:41Z.
Thanks @thehollowedone — both lifetime witnesses are fixed in
59cc732a+1a3b6981:try_reserve_backingnow pins the target backing without detachingprevuntil nativeResetsucceeds (commit_backingdetachesoldon success;rollback_backingreleases only the temporary target reservation on failure).forget(alloc)now sorts & deduplicates backing IDs before inspection and moves any still-busy backing intoState.orphaned(detached froms.backingsfor address-reuse safety while preserving itsusers/marksacrossexecuted/retire_recording/forget_list/title_resetuntil safe reclamation, including concurrentforgetracing withreset_listandfinish_aside).Added
reset_list_preserves_previous_backing_until_native_success,forget_does_not_release_a_busy_original_backing_twice_and_reclaims_when_idle, andforget_racing_mid_reset_list_cleans_up_on_rollback_and_commit(12/12alloc_pool::testspass) and re-ran 60s RX 9070 XT smoke (1669 frames, 16379 MB, 0 removals, 0 crashes).Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T12:49:57Z.
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2707 at
1a3b698195d70f8c7d36fdd87678e2ed4df7bc00(parent59cc732a32bb3e838012844d370eba03a55ba0a2; merge-baseorigin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.Setup
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)title: 29640639viascripts/smoke.ps1 -Seconds 60(XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)Targeted RTX 4060 release unit tests (
1a3b6981)cargo test --release -p xcl --lib hle::d3d12x::alloc_pool:: -- --test-threads=4(3 consecutive parallel runs): 12 passed, 0 failed, 0 ignored × 3 (0.22 s,0.20 s,0.23 s,0skipped, exit0), covering all 8 new lifetime/concurrency tests (retired_segment_releases_backing_after_gpu_completes_while_preserving_in_flight,clean_title_reset_reclaims_idle_aside_backings_once,stalled_primary_stand_in_reset_keeps_uma_blocks_until_native_backing_resets,reset_list_blocks_concurrent_title_reset_and_rolls_back_on_failure,reset_list_waits_while_backing_is_resetting,reset_list_preserves_previous_backing_until_native_success,forget_does_not_release_a_busy_original_backing_twice_and_reclaims_when_idle, andforget_racing_mid_reset_list_cleans_up_on_rollback_and_commit).cargo test --release -p xcl --lib hle::d3d12x::bind:: -- --test-threads=4: 8 passed, 0 failed, 0 ignored (0.32 s,0skipped, exit0).cargo test --release -p xcl --lib hle::d3d12x::title_list:: -- --test-threads=4: 3 passed, 0 failed, 0 ignored (0.02 s,0skipped, exit0).cargo test --release -p xcl --lib hle::d3d12x::list_x:: -- --test-threads=4: 40 passed, 0 failed, 0 ignored (0.69 s,0skipped, exit0).cargo test --release -p xcl --lib hle::d3d12x::real:: -- --test-threads=4: 60 passed, 0 failed, 0 ignored (0.66 s,0skipped, exit0).Observations
alloc_pool::,bind::,title_list::,list_x::,real::), including 3 consecutive parallel passes ofalloc_pool::, passed cleanly on this RTX 4060 host with0skips and0flakes.exit: 0x0,1564frames shown,60 60 60steady-state presents per 2 s,0device removals,0crashes,13964 MBpeak commit vsorigin/mainb49be183's14018 MB/1518frames).Paired 60 s RTX 4060 smoke (
b49be183vs1a3b6981)Merge-base
origin/main(b49be183):PR #2707 head (
1a3b6981):Limits of coverage
1a3b6981(only targetedalloc_pool::,bind::,title_list::,list_x::, andreal::release tests plus paired quiet 60 s smoke).alloc_pool::testssuite above).RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.AI use
Ran the targeted release unit tests and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from
cargo testandscripts/smoke.ps1outputs.Imported from ivall/xcl. Originally posted by throny on 2026-11-26T17:19:00Z.
Two contributors checked independently and found that #2138 solves the same problem in a different way: #1607, group D132. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by Saksukella on 2026-11-26T17:33:43Z.
Thanks for the triage note! Quick comparison for maintainers:
#2707is a minimal single-file fix confined toalloc_pool.rs(already picked intoamd-devasc5951d21), whereas#2138addresses the broader cross-module list/binding retirement across 5 files (alloc_pool.rs,bind.rs,console_list.rs,list_x.rs,real.rs). Happy to defer to whichever approach maintainers prefer onmain.Imported from ivall/xcl. Originally posted by throny on 2026-11-27T06:08:34Z.
Two contributors checked independently and found that #1071 #1453 #2936 solves the same problem in a different way: #1607, group D147. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:45:52Z.
Triage (#1607) – head
1a3b698Main contains this PR's changes, re-implemented in three commits.
31930d8("retire spare recordings and reclaim idle allocators") addsalloc_pool::retire_recordingat the same call sites with identical hunks inlist_x.rs:kickoff_xandtitle_list.rs(resetwith the stand-in primary,put_spare). It also resets idle aside backings outsideSTATE(reclaim_idle_aside,already_reset).057f463keys pending UMA to the native backing (bind::native_backing,console_list::allocator_resetmoved intoreset_pc_allocator).0ac14d3keeps busy backings alive past the title's final Release, which is whatorphaneddoes here.Main guards concurrent resets with backing probes and generation tokens, not the
resettingflag and theRESET_DONEwait. The remainingtitle_reset/reset_listrewrite here conflicts with that and would replace it.#2138 (group D132) solves the same idle-spare problem another way. #1071 and #1453 (group D147) deal with the retired-segment pins.
Recommendation: close (superseded by main commits
31930d8,057f463,0ac14d3).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:58:49Z.
Closing as superseded: this change is already on
main(31930d85). main alloc_pool.rs has retire_recording, reclaim_idle_aside, already_reset, resetting tokens, native-backing retention and many tests (31930d85,057f463a,0ac14d3c); reworked design covers the PR's reset/rollback/forget casesTwo 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