D3D12.X: a sparse pool retired a moment ago is taken back (#913) #923

Manually merged
github merged 1 commit from gh-pr/923/head into gh-pr/923/base 2026-11-26 04:36:59 +00:00
Owner

@⁠maximecmb on GitHub · 2026-11-24 08:23 UTC · original
sparse-take-back-retired-pool → main · +87 −1 · 1 files · 1 commits · merged 2026-11-24 09:31 UTC

Fixes #913.

Freeing the last tile in use of a 64 MiB sparse pool retires the pool for at least 2 s (retire_free_pools); the next tile allocation found the free list empty and take_tile made a new heap. A free / alloc loop therefore made a new pool every time: #913 counted 288 pools and about 18 GB asked of a 12 GB card in one test (a_freed_block_is_decommitted_before_its_address_is_reused), and lib test runs on 12 GB cards fail with E_OUTOFMEMORY. A title that frees and allocates the same way gets the same growth.

take_tile now takes back the most recently retired pool before it creates a heap. Its tiles are flagged for clearing (reused), as the freed tiles of a pool in use already are when they are handed out again at once, so this is no less safe than the existing reuse.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: take_tile takes a retired pool back first; the pool registration both paths share is add_pool.
  • Same file: a_pool_retired_a_moment_ago_is_taken_back – a tile freed and taken 8 times in a row gets the one retired pool back each time (flagged for clearing) instead of a new heap. It fails without the change (a new, unflagged heap comes back).

Tested

  • NVIDIA GeForce RTX 5080 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug, DXC 1.9.2602.17
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on this branch: 717 passed, 0 failed, 41 ignored
  • SKIPPED on this adapter (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware; no XCL_SAMPLE_* set
  • Peak video memory (nvidia-smi, sampled every 0.5 s) during cargo test -p xcl --lib -- --test-threads=4, one run each:
tree peak VRAM lib tests
main 09940bb 15 816 MiB (of 16 GB) 672 passed, 3 failed
this branch 3 488 MiB 676 passed, 0 failed

main's failures: placed_title_textures_share_vram_and_preserve_pixels (the #718 cubemap check), then transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on its poisoned lock. That the cubemap failure comes from the memory pressure is not shown, only that it went with it here.

Regression run
main:

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1650 (PresentX 1650)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14620 MB

This PR:

xcl-smoke v1
commit: 71bda9339a3364b1b804a1bf47f8d66dbb286280
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14610 MB

A first pair of runs, made right after each build, did not compare: main 1618 frames / 16 414 MB, this PR 1488 frames / 21 586 MB (over the 125 % limit), its last 2-second samples at 3–4 presents. The two runs' XCL_ACTIVITY lines show why: both go through the same loading steps, and this PR's run reached them about 12 s sooner (the DirectStorage burst that takes target pages from 3.6 to 4.5 GB came at 44–46 s instead of 56–60 s), so its window ended in the next stage – 12 000 DirectStorage requests per 2 s, target pages to 6.6 GB – which main's never reached. At the same step the sparse pools this PR changes were the same in both (1 024 MB); the extra commit was in target pages (vram.rs). The pair above was made afterwards with warm caches for both builds, in the order main → this PR.

Not tested

  • AMD, 12 GB cards (the issue's reporter's case), a release build of the tests
  • a retail title's own pool churn: the regression run will show it does not regress, not how often a title hits this
  • with #532, which changes the same area differently (decommitted tiles stay parked in their pool): it adds lines at the top of take_tile, next to this change, and a parked field to State, which the new test's State literal would then need. Whichever lands second needs a small rebase

AI use

  • Claude Code, Claude Opus 5.5: wrote the fix, the test and this description, and ran the tests and the VRAM measurement above.

🤖 Generated with Claude Code

**@⁠maximecmb** on GitHub · 2026-11-24 08:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/923) `sparse-take-back-retired-pool` → `main` · +87 −1 · 1 files · 1 commits · merged 2026-11-24 09:31 UTC Fixes #913. Freeing the last tile in use of a 64 MiB sparse pool retires the pool for at least 2 s (`retire_free_pools`); the next tile allocation found the free list empty and `take_tile` made a new heap. A free / alloc loop therefore made a new pool every time: #913 counted 288 pools and about 18 GB asked of a 12 GB card in one test (`a_freed_block_is_decommitted_before_its_address_is_reused`), and lib test runs on 12 GB cards fail with `E_OUTOFMEMORY`. A title that frees and allocates the same way gets the same growth. `take_tile` now takes back the most recently retired pool before it creates a heap. Its tiles are flagged for clearing (`reused`), as the freed tiles of a pool in use already are when they are handed out again at once, so this is no less safe than the existing reuse. **What is in it** - `crates/xcl/src/hle/d3d12x/sparse.rs`: `take_tile` takes a retired pool back first; the pool registration both paths share is `add_pool`. - Same file: `a_pool_retired_a_moment_ago_is_taken_back` – a tile freed and taken 8 times in a row gets the one retired pool back each time (flagged for clearing) instead of a new heap. It fails without the change (a new, unflagged heap comes back). **Tested** - NVIDIA GeForce RTX 5080 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug, DXC 1.9.2602.17 - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` on this branch: 717 passed, 0 failed, 41 ignored - SKIPPED on this adapter (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`; no `XCL_SAMPLE_*` set - Peak video memory (`nvidia-smi`, sampled every 0.5 s) during `cargo test -p xcl --lib -- --test-threads=4`, one run each: | tree | peak VRAM | lib tests | |---|---|---| | `main` 09940bb | 15 816 MiB (of 16 GB) | 672 passed, 3 failed | | this branch | 3 488 MiB | 676 passed, 0 failed | `main`'s failures: `placed_title_textures_share_vram_and_preserve_pixels` (the #718 cubemap check), then `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory` on its poisoned lock. That the cubemap failure comes from the memory pressure is not shown, only that it went with it here. **Regression run** `main`: ``` xcl-smoke v1 commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323 gpu: NVIDIA GeForce RTX 5080 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1650 (PresentX 1650) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14620 MB ``` This PR: ``` xcl-smoke v1 commit: 71bda9339a3364b1b804a1bf47f8d66dbb286280 gpu: NVIDIA GeForce RTX 5080 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14610 MB ``` A first pair of runs, made right after each build, did not compare: `main` 1618 frames / 16 414 MB, this PR 1488 frames / 21 586 MB (over the 125 % limit), its last 2-second samples at 3–4 presents. The two runs' `XCL_ACTIVITY` lines show why: both go through the same loading steps, and this PR's run reached them about 12 s sooner (the DirectStorage burst that takes target pages from 3.6 to 4.5 GB came at 44–46 s instead of 56–60 s), so its window ended in the next stage – 12 000 DirectStorage requests per 2 s, target pages to 6.6 GB – which `main`'s never reached. At the same step the sparse pools this PR changes were the same in both (1 024 MB); the extra commit was in target pages (`vram.rs`). The pair above was made afterwards with warm caches for both builds, in the order main → this PR. **Not tested** - AMD, 12 GB cards (the issue's reporter's case), a release build of the tests - a retail title's own pool churn: the regression run will show it does not regress, not how often a title hits this - with #532, which changes the same area differently (decommitted tiles stay parked in their pool): it adds lines at the top of `take_tile`, next to this change, and a `parked` field to `State`, which the new test's `State` literal would then need. Whichever lands second needs a small rebase **AI use** - Claude Code, Claude Opus 5.5: wrote the fix, the test and this description, and ran the tests and the VRAM measurement above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Freeing the last tile in use of a 64 MiB pool retires the pool for at
least 2 s; the next tile allocation found the free list empty and made a
new heap. A free / alloc loop thus made a new pool each time: #913 counted
288 pools and about 18 GB asked of a 12 GB card in one test.

take_tile now takes back the most recently retired pool before creating a
heap. Its tiles are flagged for clearing, as freed tiles of a pool in use
already are when they are reused at once.

Measured on an RTX 5080 16 GB, peak video memory during
`cargo test -p xcl --lib -- --test-threads=4` (one run each): main
09940bb 15816 MiB with 3 failed tests (the #718 cubemap check and two
poisoned-lock follow-ons); with this change 3488 MiB, 0 failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:57 +00:00
github manually merged commit 71bda9339a into gh-pr/923/base 2026-11-26 04:36:59 +00:00
Author
Owner

@⁠ettehn on GitHub · 2026-11-24 08:32 UTC · original

On a 12 GB RTX 5070 Ti Laptop GPU (Windows, driver 621.24), this change reduced peak device-wide VRAM use by about 9 GiB in the debug library suite. Two runs per commit, in base → PR → PR → base order. I built both clean worktrees before measuring and sampled nvidia-smi every 250 ms during cargo test --offline --locked -p xcl --lib -- --test-threads=4.

Commit Peak VRAM (MiB) Passed / failed / ignored
09940bb 11,469 672 / 3 / 21
71bda93 2,186 676 / 0 / 21
71bda93 2,499 676 / 0 / 21
09940bb 11,687 675 / 0 / 21

Idle samples before the runs were 899–920 MiB. The three failures in the first base run were the cubemap reuse check and the two tests that subsequently saw a poisoned lock. The second base run passed at the higher peak. This confirms the memory reduction on a 12 GB card. Retail world loading and per-process residency were outside this measurement.

OpenAI Codex (GPT-6.2 Astra) assisted with verification.

**@⁠ettehn** on GitHub · 2026-11-24 08:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/923#issuecomment-7126251865) On a 12 GB RTX 5070 Ti Laptop GPU (Windows, driver 621.24), this change reduced peak device-wide VRAM use by about 9 GiB in the debug library suite. Two runs per commit, in base → PR → PR → base order. I built both clean worktrees before measuring and sampled `nvidia-smi` every 250 ms during `cargo test --offline --locked -p xcl --lib -- --test-threads=4`. | Commit | Peak VRAM (MiB) | Passed / failed / ignored | | --- | ---: | --- | | `09940bb` | 11,469 | 672 / 3 / 21 | | `71bda93` | 2,186 | 676 / 0 / 21 | | `71bda93` | 2,499 | 676 / 0 / 21 | | `09940bb` | 11,687 | 675 / 0 / 21 | Idle samples before the runs were 899–920 MiB. The three failures in the first base run were the cubemap reuse check and the two tests that subsequently saw a poisoned lock. The second base run passed at the higher peak. This confirms the memory reduction on a 12 GB card. Retail world loading and per-process residency were outside this measurement. OpenAI Codex (GPT-6.2 Astra) assisted with verification.
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-24 08:45 UTC · original

Tested on AMD under Linux / Wine: it fixes #913 there too. Video memory went from the full 16 GB card to ~2.3 GB.

Tested

  • AMD Radeon RX 9070 16 GB (RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GB RAM, CachyOS, kernel 7.3.5. Proton Experimental's Wine (experimental-11.0-20261112), vkd3d-proton v3.1 + #257's patch (-Db_ndebug=true, dxil-spirv 53aac418), DXVK v3.1.1-209, DXC 1.9.2609.5. Rust 1.96.0, x86_64-pc-windows-gnu, release.
  • This PR's head 71bda93 against its base main 1ec4c98. The lib test binary runs under Wine with VKD3D_CONFIG=ignore_shared_fence XCL_NETWORK=0 XCL_ADAPTER=9070. Peak VRAM comes from amdgpu's mem_info_vram_used, sampled every 0.2 s.
  • --test-threads=4 --skip write_buffer_immediate_on_open_existing_heap_visible_to_cpu. That list_x test causes a separate device loss on this stack (see the edited comment in #175), so I left it out of both sides.
tree lib result (passed / failed / ignored) peak VRAM gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes
1ec4c98, 3 runs 664 / 9 / 21; aborted; 668 / 5 / 21 16 290–16 303 MiB (card full) fails with Timeout(5000) (title_textures.rs:1291), then 3 PoisonError failures. The aborted run lost the device (0x887a0005) during a title-texture upload
71bda93, 3 runs 670 / 5 / 21 every run 2 296–2 298 MiB in runs 2–3 (run 1 read 15 881 MiB, probably the previous run's memory not yet freed) passes
  • The 5 left on the head are this stack's known ones: gpu_f64_roots and gpu_f64_math_random (#530), gpu_nonfused_mad_and_mac_prevent_fma_contraction (#676), and the XMA2 and Opus GetState tests (#890).
  • a_pool_retired_a_moment_ago_is_taken_back: 3 of 3 pass.
  • Rechecked the base after main moved: 077ce40 still shows the problem (665 / 9, 16 287–16 295 MiB peak, gpu_mirror_upload… fails, 2 of 2). The commits since 1ec4c98 don't touch sparse.rs.

Not tested: the head rebased onto 077ce40, Windows, a retail title, #532.

AI use: T3 Code (Claude Opus 5.5) built both trees, ran the tests and wrote this comment from the logs. The runs are real, on the hardware above, and I checked the report before posting.

**@⁠ClosetPie107** on GitHub · 2026-11-24 08:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/923#issuecomment-7126534036) Tested on AMD under Linux / Wine: it fixes #913 there too. Video memory went from the full 16 GB card to ~2.3 GB. **Tested** - AMD Radeon RX 9070 16 GB (RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GB RAM, CachyOS, kernel 7.3.5. Proton Experimental's Wine (`experimental-11.0-20261112`), vkd3d-proton v3.1 + #257's patch (`-Db_ndebug=true`, dxil-spirv `53aac418`), DXVK `v3.1.1-209`, DXC 1.9.2609.5. Rust 1.96.0, `x86_64-pc-windows-gnu`, release. - This PR's head `71bda93` against its base `main` `1ec4c98`. The lib test binary runs under Wine with `VKD3D_CONFIG=ignore_shared_fence XCL_NETWORK=0 XCL_ADAPTER=9070`. Peak VRAM comes from amdgpu's `mem_info_vram_used`, sampled every 0.2 s. - `--test-threads=4 --skip write_buffer_immediate_on_open_existing_heap_visible_to_cpu`. That `list_x` test causes a separate device loss on this stack (see the edited comment in #175), so I left it out of both sides. | tree | lib result (passed / failed / ignored) | peak VRAM | `gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes` | |---|---|---|---| | `1ec4c98`, 3 runs | 664 / 9 / 21; aborted; 668 / 5 / 21 | 16 290–16 303 MiB (card full) | fails with `Timeout(5000)` (`title_textures.rs:1291`), then 3 `PoisonError` failures. The aborted run lost the device (`0x887a0005`) during a title-texture upload | | `71bda93`, 3 runs | **670 / 5 / 21** every run | **2 296–2 298 MiB** in runs 2–3 (run 1 read 15 881 MiB, probably the previous run's memory not yet freed) | passes | - The 5 left on the head are this stack's known ones: `gpu_f64_roots` and `gpu_f64_math_random` (#530), `gpu_nonfused_mad_and_mac_prevent_fma_contraction` (#676), and the XMA2 and Opus `GetState` tests (#890). - `a_pool_retired_a_moment_ago_is_taken_back`: 3 of 3 pass. - Rechecked the base after `main` moved: `077ce40` still shows the problem (665 / 9, 16 287–16 295 MiB peak, `gpu_mirror_upload…` fails, 2 of 2). The commits since `1ec4c98` don't touch `sparse.rs`. **Not tested:** the head rebased onto `077ce40`, Windows, a retail title, #532. **AI use:** T3 Code (Claude Opus 5.5) built both trees, ran the tests and wrote this comment from the logs. The runs are real, on the hardware above, and I checked the report before posting.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 09:31 UTC · original

Merged (6bac4b4). Checked on an RX 9070 (RDNA4) on main 6bac4b4 together with #923 and #849: cargo test --workspace -- --test-threads=4 - 678 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps and starts loading the world (the run then hits this machine's commit limit, not a crash). Picked over #930, which a tester saw fail the sparse e2e check.

**@⁠ivall** on GitHub · 2026-11-24 09:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/923#issuecomment-7127543698) Merged (6bac4b4). Checked on an RX 9070 (RDNA4) on main 6bac4b4 together with #923 and #849: `cargo test --workspace -- --test-threads=4` - 678 unit tests passed, 0 failed; the retail game plays its intro and menus at 30 fps and starts loading the world (the run then hits this machine's commit limit, not a crash). Picked over #930, which a tester saw fail the sparse e2e check.
This discussion has been locked. Commenting is limited to contributors.
No description provided.