Skip to content

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

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
maximecmb:sparse-take-back-retired-pool
Nov 24, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
maximecmb:sparse-take-back-retired-pool

Conversation

@maximecmb

@maximecmb maximecmb commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 Memory: decommitted sparse tiles stay mapped until the next submit #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

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 <noreply@anthropic.com>
@ettehn

ettehn commented Nov 24, 2026

Copy link
Copy Markdown

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.

@ClosetPie107

Copy link
Copy Markdown

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

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

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.

@maximecmb
maximecmb marked this pull request as ready for review November 24, 2026 08:46
@ivall
ivall merged commit 6922eaf into xcl-dev:main Nov 24, 2026
2 of 3 checks passed
@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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.

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.

Memory: a sparse alloc/free loop makes a new 64 MiB pool each cycle; lib tests fill a 12 GB card (#348's test)

4 participants