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

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

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: 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: 3f3d7627a0616932f1b9abfe2f4d6c85a081514d
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1568 (PresentX 1568)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16108 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, porting/rebasing onto the updated #2138 base, 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.

@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!

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.
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.
@Simon-CR
Simon-CR force-pushed the pr/bind-sparse-arena-fallback branch from 583fe45 to 3f3d762 Compare November 25, 2026 14:52
@Simon-CR

Copy link
Copy Markdown
Author

Rebased cleanly onto the updated #2138 head (a6574154, on main 06c9f550) -> 3f3d7627. Thanks @JoaoPauluu and @DavidM1911 for the earlier checks!

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

  • Targeted (--test-threads=1): gpu::uma 13/0, bind 9/0, console_list 5/0, XCL_HEAP_WINDOWS=1 gpu_sparse_arena_fallback 1/0
  • Full workspace (--no-fail-fast -- --test-threads=4): 1269 passed, 2 pre-existing #2115 fuzz failures, 46 ignored
  • Paired 60 s smoke against 06c9f550: 1568 frames (16108 MB peak commit) vs 1373 (19392 MB) on main, 0 device removals, 0 crashes.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

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