Skip to content

D3D12.X: fall back to 256 KiB sparse arenas when coherent UMA is full - #2142

Open
Simon-CR wants to merge 2 commits into
xcl-dev:mainfrom
Simon-CR:pr/bind-sparse-arena-fallback
Open

Simon-CR wants to merge 2 commits into
xcl-dev:mainfrom
Simon-CR:pr/bind-sparse-arena-fallback

Conversation

@Simon-CR

Copy link
Copy Markdown

Stacked on #2138; only the top commit belongs here.

When coherent unified memory fills up during heavy scene recording, every draw still needs small chunks of unified memory for its per-draw shader tables and constant-buffer copies, and console middleware calls AllocateUploadMemory. Previously, when coherent unified memory ran out on a small request, recording either failed (unified memory is full) or risked allocating a separate 64 KiB sparse block for each tiny copy (burning sparse reservation blocks and virtual-address tiles on every small draw).

This change handles small upload and binding requests cleanly when coherent unified memory is full: first it asks the swap pool to reclaim idle put-aside PC command allocators (rate-limited to once every 50 ms across concurrent threads so threads do not thrash a contended pool) and retries coherent memory; if coherent memory is still full and sparse unified memory windows are enabled, it allocates one 256 KiB sparse block, seeds the command list's bump arena with it, and serves subsequent small draws out of that same 256 KiB block until the allocator resets (doing the same for console command lists on cl_allocate_upload_memory and uma_copy). Larger requests continue taking dedicated sparse blocks before falling back to coherent memory + reclaim.

What is in it

  • crates/xcl/src/gpu/uma.rs: split Arena::take_bump out of Arena::take, add Arena::seed_block (with overflow-safe bounds checks) so callers can attach a 256 KiB backing block to an active arena, and add unit test arena_seed_block_bump_allocates_and_tracks_block_once
  • crates/xcl/src/hle/d3d12x/bind.rs: add a 50 ms cooldown maybe_reclaim_alloc_pool retry, extract shared alloc_recording_uma / alloc_recording_uma_with fallback helper used by both allocate_upload_memory and bind_abi's copy closure (dropping redundant sparse blocks outside STATES if another thread seeds concurrently), plus unit test alloc_recording_uma_falls_back_to_sparse_arena_block_without_per_copy_churn and GPU test gpu_sparse_arena_fallback_maps_va_uploads_to_gpu_and_frees_on_reset
  • crates/xcl/src/hle/d3d12x/console_list.rs: share the 256 KiB sparse Arena block seeding fallback in cl_allocate_upload_memory and uma_copy when coherent unified memory is full

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: 583fe454b2f17a50abdf85f6a4f8a0e4a76b651c
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1551 (PresentX 1551)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17378 MB

Not tested

  • A multi-minute saturated-UMA stress soak in upstream main alone (verified locally across a 240 s retail world-load soak with 0 unified memory is full errors alongside the rest of the local patch set), 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 Arena::seed_block and the throttled reclaim/sparse fallback path, adding the unit and GPU 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
When coherent unified memory is exhausted, small per-draw root/CBV copies and AllocateUploadMemory requests first rate-limit idle allocator-pool reclamation (50 ms cooldown), then seed one 256 KiB sparse VA block into the list's Arena instead of claiming a 64 KiB sparse block per small copy, sharing it across subsequent bump allocations on both command lists and console command lists.
@JoaoPauluu

JoaoPauluu commented Nov 25, 2026 •

Copy link
Copy Markdown

A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with main (1379 here; 1353 and 1380 on the two main runs). The 6 new tests pass under Wine, the GPU one (gpu_sparse_arena_fallback_maps_va_uploads_to_gpu_and_frees_on_reset) included. In 60 s the coherent window here is far from full (the log's last coherent figure is 116/512 MB in this run), so the fallback is not reached; 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: 583fe454b2f17a50abdf85f6a4f8a0e4a76b651c
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1379 (PresentX 1379)
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 run that fills the coherent window, 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.

@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants