Repository navigation
D3D12.X: detach retired segments and reclaim idle aside allocators - #2707
Saksukella wants to merge 4 commits into
Conversation
|
Rerun on the new head
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. |
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.