Skip to content

D3D12.X: reclaim idle put-aside allocators and retire orphaned batches - #2138

Open
Simon-CR wants to merge 1 commit into
xcl-dev:mainfrom
Simon-CR:pr/alloc-pool-reclaim-idle
Open

Simon-CR wants to merge 1 commit into
xcl-dev:mainfrom
Simon-CR:pr/alloc-pool-reclaim-idle

Conversation

@Simon-CR

@Simon-CR Simon-CR commented Nov 25, 2026 •

Copy link
Copy Markdown

Put-aside PC command allocators previously stayed dirty in the swap pool until the title happened to reset that exact title allocator again, holding native D3D12 command-allocator allocations and any pending unified-memory blocks indefinitely. In addition, releasing a title allocator with GPU work in flight dropped busy owned spare allocators without waiting for completion and left stale title-allocator references in command-list binding state, while forget_list ran before bind::forget and move_list could race with background reclamation on reset.

This change proactively resets idle put-aside PC allocators, trims excess idle spares per title allocator, keeps busy orphaned spares and title pending blocks tracked behind GPU fences until idle, and orders list release/reset retirement strictly before alloc_pool list disassociation.

What is in it

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs: add dirty tracking, reset_list_with_retire, retire_orphan_uma, reclaim_idle (skipping off-thread Reset on title-owned allocators and capping excess clean owned spares at 2 per allocator, plus deferring title-allocator pending UMA flushes until all backings for that title allocator are idle), forget fence-gated orphan capture, throttled maybe_reclaim_idle on reset/release, and three unit tests covering idle reclaim/trim, fence-gated orphan retirement, and mid-reset reclamation ordering
  • crates/xcl/src/hle/d3d12x/console_list.rs: add take_pending, free_uma_blocks, and pending_len_for_test helpers
  • crates/xcl/src/hle/d3d12x/bind.rs: add retire_uma_blocks (routing allocator == 0 through retire_orphan_uma) and on_title_allocator_release, dropping STATES lock before retirement in forget
  • crates/xcl/src/hle/d3d12x/real.rs and crates/xcl/src/hle/d3d12x/list_x.rs: order bind::forget before list_x::on_release and alloc_pool::forget_list (keeping dred::forget_list), clear dead title-allocator bindings on allocator release, and run reset state cleanup (and cl_reset DRED tracking) inside reset_list_with_retire before moving the list's backing

Tested

Regression run

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1373 (PresentX 1374)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19392 MB
xcl-smoke v1
commit: a6574154ea1175b2b2c5f57a355a7a9a01fef55d
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20545 MB

Not tested

  • Multi-minute world-load allocator-exhaustion soak on unmodified main alone (verified locally across a 240 s retail world-load soak alongside the stacked sparse-arena fallback PR, reducing held blocks from 5,006 across 212 allocators to 392 across 215), NVIDIA GPUs, Intel Arc GPUs, wave32-only GPUs, and Linux/Wine

AI use

  • Antigravity (frontier model; exact model identifier not exposed to agent) assisted with designing the reclaim/orphan-retirement state machine, porting/rebasing against main, adding the unit tests, running the test suite and smoke runs, and drafting this description. All builds, tests, and regression runs were executed locally on the hardware above.

@thehollowedone

Copy link
Copy Markdown

Independent focused run of 998564a3 on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.

cargo test --offline --locked -p xcl --lib --no-run, then separate runs of the test binary with --nocapture --test-threads=1: alloc_pool::tests 6 passed, bind::tests 6, console_list::tests 5, list_x::tests 29, and title_list::tests 1. Total 47 passed, 0 failed, 0 ignored, and no runtime SKIPPED notices. This includes the three new allocator retirement tests.

Focused synthetic coverage. Retail, memory savings and the workspace suite are outside this report. AI use: OpenAI Codex (GPT-6) ran the tests and drafted this report.

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with main (1363 here; 1353 and 1380 on the two main runs). The 3 new alloc_pool tests pass under Wine. Nothing in the log shows idle allocators being reclaimed, so this is a regression run only.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: 6e1e2befc7430126b1e7b98b5c3fe93813c866b6
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1353 (PresentX 1353)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 998564a3b5f6bde7303f0eb5a1faca4ff1386fbd
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1363 (PresentX 1363)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The second main run: 1380 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the whole test suite on this head, a long run where allocators go idle, native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the tests and the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Reclaim idle put-aside PC command allocators proactively via reset_list_with_retire and reclaim_idle, cap excess clean spares at 2 per allocator, hold orphaned busy spares and pending UMA blocks behind GPU fences until idle, and order bind::forget and list_x cleanup strictly before alloc_pool::forget_list and release.
@Simon-CR
Simon-CR force-pushed the pr/alloc-pool-reclaim-idle branch from 998564a to a657415 Compare November 25, 2026 14:47
@Simon-CR

Copy link
Copy Markdown
Author

Rebased cleanly onto current main (06c9f550 -> a6574154), preserving the new #2160/#2163 resubmit tracking (last_submit / recordings), #1592 DRED pipeline markers/reset hooks inside cl_reset & cl_release, and #929 title_list reset behavior. Thanks @thehollowedone, @JoaoPauluu, and @DavidM1911 for the earlier verification passes!

Re-tested on a6574154 (RX 9070 XT, Win10):

  • Targeted (--test-threads=1): alloc_pool 7/0 (both #2160 resubmit & all 3 reclaim tests pass), bind 7/0, console_list 5/0, list_x 34/0, title_list 3/0
  • Full workspace (--no-fail-fast -- --test-threads=4): 1266 passed, 2 pre-existing #2115 fuzz failures, 46 ignored
  • Paired 60 s smoke against 06c9f550: 1582 frames vs 1373 on main, 0 device removals, 0 crashes.

@GustavoEllwanger

Copy link
Copy Markdown
Contributor

Test report on head a657415, as is and merged onto current main 3ceb550 (merge 96a4009, no conflicts), on NVIDIA (32-lane waves) and AMD RDNA2 (native wave64).

Tested

  • AMD Ryzen 7 7700, Windows 11 build 26200.9974, Rust 1.95.0 MSVC, debug.
    • NVIDIA GeForce RTX 5060 (driver 32.0.16.1088), XCL_ADAPTER=5060
    • AMD Radeon RDNA2 iGPU (driver 32.0.21042.62), XCL_ADAPTER=Radeon
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
tree RTX 5060 RDNA2 iGPU
this PR, a657415 1268 passed, 0 failed, 46 ignored 1267 passed, 1 failed, 46 ignored
main 3ceb550 1346 passed, 1 failed, 46 ignored 1345 passed, 2 failed, 46 ignored
this PR merged onto 3ceb550 1349 passed, 1 failed, 46 ignored 1348 passed, 2 failed, 46 ignored

The failures are the same on main and on the merged tree, so none comes from this PR:

The new alloc_pool tests are flaky when they run in parallel

XCL_ADAPTER=5060 cargo test -p xcl --lib hle::d3d12x::alloc_pool -- --test-threads=8, 30 runs each:

tree tests result
main 3ceb550 4 30 passed, 0 failed
this PR, a657415 7 7 passed, 23 failed (two more sets of 30: 7 / 23 and 10 / 20)
this PR, tests serialized with a lock (local change, below) 7 30 passed, 0 failed

What the failing runs show:

  • The first panic is one test seeing another test's state, for example released_lists_leave_only_live_recordings_and_gpu_work_holding_the_backing at alloc_pool.rs:673 (no entry found for key on backings[&alloc] right after fence.value.set(7)), or forget_retires_busy_owned_spares_and_title_alloc_pending_after_gpu_fence at alloc_pool.rs:960 (left: 1, right: 0).
  • It poisons STATE, so the other tests then fail at STATE.lock().unwrap() (alloc_pool.rs:180 and :268).
  • In 22 of the 23 failing runs the binary then aborts with 0xc0000409 ("thread caused non-unwinding panic"), which takes down every other lib test in the same process.

My reading: all the tests share the global STATE, and maybe_reclaim_idle() (now called on every reset and release) reclaims what another test has just made idle. That is what reclaim is meant to do at runtime, so I don't see a runtime problem here, only test isolation. The whole suite passed on the RTX 5060 because fewer of these tests overlap there, but it can turn red on other machines.

A fix in the style of title_textures.rs / vram.rs (TEST_LOCK) that made the 30 runs pass here:

#[cfg(test)]
mod tests {
    use super::*;

    static TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
    fn serial() -> std::sync::MutexGuard<'static, ()> {
        TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner())
    }

    #[test]
    fn a_spare_whose_reset_fails_stays_available_for_retry() {
        let _serial = serial();
        // ...

with let _serial = serial(); as the first line of each of the 7 tests. Tests in list_x, bind and console_list that go through alloc_pool were not part of this stress run.

Not tested

  • A retail title or a smoke run.
  • A release build.

Tests run and this report drafted with Claude Code (Claude Opus 5.5); I checked the numbers against the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants