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

Open
github-bot wants to merge 2 commits from github-bot/gh-2142 into main AGit
Owner

@⁠Simon-CR on GitHub · 2026-11-25 06:06 UTC · original
Simon-CR:pr/bind-sparse-arena-fallback → main · +1143 −108 · 6 files · 2 commits · open

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

  • Hardware & OS: AMD Radeon RX 9070 XT (driver 32.0.32015.7029), AMD Ryzen 7 5800X, Windows 10 Pro 26H2 (Build 26300.9974), rustc 1.100.0 (0ef1bc386 2026-11-09)
  • Targeted suites (cargo test -p xcl --lib ... -- --test-threads=1): gpu::uma::tests 13 passed / 0 failed / 0 ignored; hle::d3d12x::bind::tests 9 passed / 0 failed / 0 ignored; hle::d3d12x::console_list::tests 5 passed / 0 failed / 0 ignored; XCL_HEAP_WINDOWS=1 standalone hle::d3d12x::bind::tests::gpu_sparse_arena_fallback 1 passed / 0 failed / 0 ignored
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1269 passed, 2 failed (only pre-existing gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599 reproduced on unmodified origin/main 06c9f550, tracked in #2115 / #1679), 46 ignored across 23 test result summaries (debug build)
  • SKIPPED tests: gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D); test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows; uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))
  • Release build (cargo build --release -p xcl) and 60 s retail title run (5ec87c56) completed cleanly with 0 device removals and 0 crashes; peak commit was 16108 MB vs 19392 MB on main

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.
**@⁠Simon-CR** on GitHub · 2026-11-25 06:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2142) `Simon-CR:pr/bind-sparse-arena-fallback` → `main` · +1143 −108 · 6 files · 2 commits · open 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** - Hardware & OS: AMD Radeon RX 9070 XT (driver 32.0.32015.7029), AMD Ryzen 7 5800X, Windows 10 Pro 26H2 (Build 26300.9974), `rustc 1.100.0 (0ef1bc386 2026-11-09)` - Targeted suites (`cargo test -p xcl --lib ... -- --test-threads=1`): `gpu::uma::tests` 13 passed / 0 failed / 0 ignored; `hle::d3d12x::bind::tests` 9 passed / 0 failed / 0 ignored; `hle::d3d12x::console_list::tests` 5 passed / 0 failed / 0 ignored; `XCL_HEAP_WINDOWS=1` standalone `hle::d3d12x::bind::tests::gpu_sparse_arena_fallback` 1 passed / 0 failed / 0 ignored - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1269 passed, 2 failed (only pre-existing `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599 reproduced on unmodified `origin/main` `06c9f550`, tracked in #2115 / #1679), 46 ignored across 23 test result summaries (debug build) - `SKIPPED` tests: gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)); shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D); test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows; uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)) - Release build (`cargo build --release -p xcl`) and 60 s retail title run (`5ec87c56`) completed cleanly with 0 device removals and 0 crashes; peak commit was 16108 MB vs 19392 MB on `main` **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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:20:21 +00:00
Author
Owner

@⁠JoaoPauluu on GitHub · 2026-11-25 06:25 UTC · original

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

  • RTX 3060 12 GB (NVIDIA 620.70.06), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for x86_64-pc-windows-gnu. 583fe45 as it is (based on 6020a33) and main 6e1e2be, no uncommitted changes. Retail title 1.0.2.1, scripts/linux/smoke.sh (#257) for 60 s, no input. Runs in order: main, #2138, #2142, main. New lib tests under Wine, one test per process.

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.
**@⁠JoaoPauluu** on GitHub · 2026-11-25 06:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/2142#issuecomment-7154775941) 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** - RTX 3060 12 GB (NVIDIA 620.70.06), i5-10400F, 16 GB, CachyOS (kernel 7.3.3), Proton Experimental 11.0-20261112 with the patched vkd3d-proton 3.1 from #257, DXC 1.9.2609.5. Release, cross-built for `x86_64-pc-windows-gnu`. `583fe45` as it is (based on `6020a33`) and `main` `6e1e2be`, no uncommitted changes. Retail title 1.0.2.1, `scripts/linux/smoke.sh` (#257) for 60 s, no input. Runs in order: main, #2138, #2142, main. New lib tests under Wine, one test per process. **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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 06:49 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2142#issuecomment-7155194544) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠Simon-CR on GitHub · 2026-11-25 14:52 UTC · original

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.
**@⁠Simon-CR** on GitHub · 2026-11-25 14:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/2142#issuecomment-7165948583) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 08:15 UTC · original

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.

**@⁠DavidM1911** on GitHub · 2026-11-26 08:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/2142#issuecomment-7186370726) 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.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/list_x.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2142/head:github-bot/gh-2142'
git switch 'github-bot/gh-2142'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2142'
git switch 'github-bot/gh-2142'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2142'
git switch 'github-bot/gh-2142'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2142'
git switch 'main'
git merge --squash 'github-bot/gh-2142'
git switch 'main'
git merge --ff-only 'github-bot/gh-2142'
git switch 'main'
git merge 'github-bot/gh-2142'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.