Repository navigation
D3D12.X: detach retired segments and reclaim idle aside allocators - #2707
Saksukella wants to merge 6 commits into
Conversation
|
Rerun on the new head
With both mutations, running the whole AI use: Claude Code (Claude Opus 5.5) ran the tests and mutations and wrote this rerun. Rerun on
Rerun on
First run, on Tested:
Not 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. |
luckyteagirl
left a comment
There was a problem hiding this comment.
At head 7879954925faaa048293f28857febf9eb8aa503b, the new bind::reset(primary, 0, 0) runs precisely when title_list::reset selects a stand-in because the primary PC list is still in flight (title_list.rs:157-201). bind::reset moves that primary recording's UMA blocks to console_list::PENDING under its old logical title allocator (bind.rs:75-87). A subsequent successful title-allocator Reset can swap to a different native backing while the old primary is still in flight, but real::alloc_reset unconditionally calls console_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.
|
Test report: passes on NVIDIA. Exact head Tested
Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
|
Good catch @luckyteagirl — fixed in |
|
A gap in
Suggested fix: call AI use: Claude Code with Claude Opus 5.5 read the code and wrote this note. |
…phaned ResetCurrent backings
|
Good catch @Kalmarv — added |
|
Exact-head allocator lifetime check on
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:
Test-only diff against dff6edcdiff --git a/crates/xcl/src/hle/d3d12x/alloc_pool.rs b/crates/xcl/src/hle/d3d12x/alloc_pool.rs
index df8a39e..f558306 100644
--- a/crates/xcl/src/hle/d3d12x/alloc_pool.rs
+++ b/crates/xcl/src/hle/d3d12x/alloc_pool.rs
@@ -1092,6 +1092,66 @@ mod tests {
unsafe { forget(alloc) };
}
+ #[test]
+ fn reset_list_preserves_previous_backing_until_native_success() {
+ let mut ids = Box::new([0u8; 5]);
+ let base = ids.as_mut_ptr() as usize;
+ let (alloc, old, current, spare, list) = (base, base + 1, base + 2, base + 3, base + 4);
+ {
+ let mut g = STATE.lock().unwrap();
+ let s = g.get_or_insert_with(State::default);
+ s.types.insert(alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+ s.cur.insert(alloc, current);
+ s.aside.insert(alloc, vec![old, spare]);
+ s.backings.insert(spare, Backing { already_reset: true, ..Backing::default() });
+ move_list(s, list, old);
+ }
+
+ let mut native_resets = Vec::new();
+ let hr = reset_list(list, alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0, |backing| {
+ assert_eq!(backing, current);
+ let mut g = STATE.lock().unwrap();
+ let s = g.as_mut().unwrap();
+ assert_eq!(
+ unsafe { title_reset_in(s, alloc as *mut c_void, |raw| {
+ native_resets.push(raw as usize);
+ 0
+ }) },
+ Some(0)
+ );
+ crate::util::E_FAIL
+ });
+
+ assert_eq!(hr, crate::util::E_FAIL);
+ assert_eq!(recording_backing(list), Some(old));
+ assert!(!native_resets.contains(&old), "the previous recording was reset before native Reset succeeded");
+ }
+
+ #[test]
+ fn forget_does_not_release_a_busy_original_backing_twice() {
+ let mut ids = Box::new([0u8; 3]);
+ let base = ids.as_mut_ptr() as usize;
+ let (alloc, next, list) = (base, base + 1, base + 2);
+ {
+ let mut g = STATE.lock().unwrap();
+ let s = g.get_or_insert_with(State::default);
+ s.types.insert(alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+ s.aside.insert(alloc, vec![alloc]);
+ s.cur.insert(alloc, next);
+ move_list(s, list, alloc);
+ s.backings.entry(next).or_default().users.insert(list + 1);
+ }
+ super::super::console_list::hold_until_reset(alloc, vec![0x1111]);
+
+ unsafe { forget(alloc) };
+
+ assert_eq!(
+ super::super::console_list::take_pending_for_test(alloc),
+ vec![0x1111],
+ "a live old recording must keep its pending UMA blocks"
+ );
+ }
+
#[test]
fn reset_list_waits_while_backing_is_resetting() {
let mut ids = Box::new([0u8; 2]);These 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. |
…sy backings on forget
|
Thanks @thehollowedone — both lifetime witnesses are fixed in
Added |
|
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2707 at Setup
Targeted RTX 4060 release unit tests (
|
Runs 4-6 on an RTX 5080 grew non-local video memory to 45 GB within a minute of the first intro frames and ended in E_OUTOFMEMORY and a device removal; run 7 with XCL_ALLOC_SWAP=0 stayed near 16 GB. The entry records the cause and the user's decision to adopt xcl-dev#2725, xcl-dev#2549, xcl-dev#2581 and xcl-dev#2707 through the gate. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018RbZY1Ag73eDeCUZHpW3is
Commit: 1a3b698 Reviewer: Claude Code (Claude Opus 5.5), Opus worker, full read (findings) Review findings, none stopping the merge: most new unit tests drive the test-only copy title_reset_in, not the rewritten title_reset; xcl-dev#2725 must be ported onto the new title_reset instead of merged; reset_list can return E_FAIL after 5 s on a resetting backing. Conflict in crates/xcl/src/hle/d3d12x/alloc_pool.rs (reset_list): our side has the telemetry_list_reset call, the PR replaces the bookkeeping. The PR's bookkeeping is taken and the telemetry call is kept after every successful native Reset, also on the PR's new early-return path.
…s are left out With draws off the title's thread, a retail title on an RTX 5080 still stopped presenting 70 s after its loading screen: 31 of 32 compute waits built the pipeline in the call (up to 15 s each), and it then sat for 450 s behind about 35 ray-tracing resolve programs of 700 to 940 KB of DXIL that take up to 167 s each in the driver compiler. A waiting compute bind no longer takes the build job: the build is marked wanted, goes ahead of the workers' queue and is waited for, at most XCL_PSO_COMPUTE_WAIT_MS (default 120 s, 0: no limit); after that the pipeline is late and its dispatches are skipped until it is built. XCL_PSO_IMAGE_SKIP is now on unless set to 0: a big compute program that writes only images is not waited for and not put off to the submit. It writes no buffer, so no ExecuteIndirect can read stale counts from it. Tested on Windows 11, RTX 5080, driver 32.0.16.2140, on top of xcl-dev#2581, xcl-dev#2549 and xcl-dev#2707: cargo test -p xcl --lib -- pso_async:: bind:: list_x:: alloc_pool:: title_list:: : 95 passed, 0 failed; whole suite 1639 passed, 4 failed (the dxil fuzz_validate_and_gpu_0..3 that fail on this GPU without the change), 47 ignored, 45 SKIPPED lines. Not tested on AMD. Unit U5 of the stall-fix entry in decisions.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018RbZY1Ag73eDeCUZHpW3is
|
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. |
|
Thanks for the triage note! Quick comparison for maintainers: |
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 D3D12.X: bypass title hooks for own_work ExecuteCommandLists #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.