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

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 forget_list, clear dead title-allocator bindings on allocator release, and run reset state cleanup inside reset_list_with_retire before moving the list's backing

Tested

Regression run

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1483 (PresentX 1483)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19090 MB
xcl-smoke v1
commit: 998564a3b5f6bde7303f0eb5a1faca4ff1386fbd
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1495 (PresentX 1495)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17109 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 142–257 across 42–84 allocators), 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 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.

Idle put-aside PC command allocators previously stayed dirty in the swap
pool indefinitely, holding D3D12 command-allocator memory and any
deferred UMA blocks until the title happened to reset that specific
title allocator again. Meanwhile, releasing a title allocator with work
in flight dropped busy owned spare tracking and abandoned pending UMA
blocks.

- alloc_pool: track Backing::dirty, proactively reset idle put-aside PC
  allocators (never dereferencing title-owned allocators off-thread) and
  trim excess clean owned spares above MAX_IDLE_SPARES_PER_ALLOC (2) via
  reclaim_idle, triggered with a 500 ms cooldown outside STATE lock on
  allocator reset and release.
- alloc_pool / console_list / bind / real / list_x: add reset_list_with_retire
  and order bind::forget before list_x::on_release and alloc_pool::forget_list
  so retired UMA blocks are recorded before list membership clears; track
  busy orphaned spares and title-allocator pending UMA through GPU
  fences via orphaned_spares, orphaned_retirements, and retire_orphan_uma;
  clear dead title allocator pointers in bind::on_title_allocator_release.
- Add unit tests covering idle spare reset/trim, title pending UMA safety
  while sibling spares are busy, fence-gated orphan retirement, and
  reset_list_with_retire ordering.

Assisted-by: Antigravity
@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!

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.

5 participants