Skip to content

D3D12.X: reuse a retired sparse pool once its unmap fence has completed - #930

Closed
DavidM1911 wants to merge 2 commits into
xcl-dev:mainfrom
DavidM1911:sparse-reuse-retired
Closed

DavidM1911 wants to merge 2 commits into
xcl-dev:mainfrom
DavidM1911:sparse-reuse-retired

Conversation

@DavidM1911

@DavidM1911 DavidM1911 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #913.

retire_free_pools parks a fully-free 64 MiB pool heap for at least 2 s, but take_tile only ever popped self.free or called CreateHeap — it never looked at retired. An alloc/free cycle inside that window therefore minted a fresh 64 MiB heap every time: the #348 lib test asked a 12 GB card for ~18 GB of pools.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: the pool-placement tail of take_tile is factored into adopt_heap; before CreateHeap, take_tile now adopts the oldest retired heap whose unmap fence value has already completed (GetCompletedValue() >= retired.value). Heaps still inside their fence/age window stay retired, so the decommit-before-reuse ordering from Memory: a freed sparse block is decommitted before its address is reused #348 is preserved, and retire_free_pools still shrinks pools/free the same way.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc, rebased on main 09940bb:
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a baseline is stale relative to the rebase; closest fresh main smoke on this machine:

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14437 MB

this PR's head bd2e4c6:

xcl-smoke v1
commit: bd2e4c6fa1e0f1f7c2d7a25e6bc4a740dfbd5d08
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14530 MB

Not tested

AI use

  • Devin (SWE-2 Flash Medium): implemented the change, ran the suites and smoke runs.

retire_free_pools parks a fully-free 64 MiB heap for at least 2 s, but take_tile only popped the free list or created a new heap, so an alloc/free cycle inside that window minted a fresh heap each time — the lib test from xcl-dev#348 asked a 12 GB card for ~18 GB. take_tile now adopts the oldest retired heap whose fence value has completed; heaps still inside their window stay retired.
@ettehn

ettehn commented Nov 24, 2026 •

Copy link
Copy Markdown

Resolved on e78e2df. Retested on the RTX 5070 Ti Laptop. The clean head passed the full debug library suite (675 passed, 0 failed, 21 ignored). In a second checkout with only the original test probe added, all eight completed-fence retirement/reuse rounds now returned the clearing flag. The same probe failed on round 0 at bd2e4c6.

On bd2e4c6, the first tile returned from a retired heap misses the normal clearing step. In take_tile, the retired-heap branch returns (self.adopt_heap(heap), false). The caller queues (t, TILE) in to_zero only when that flag is true. Fence completion establishes that unmapping finished; it does not clear the heap contents. The other tiles from the very same heap get the clearing flag when popped from self.free.

Reproduced on native Windows (RTX 5070 Ti Laptop) with the pool-retirement test from #923 and a D3D12 fence explicitly completed at the pool's retirement value. The fresh heap correctly returned false; the first reacquisition failed the reused assertion in round 0. Changing just the retired-heap return to (self.adopt_heap(heap), true) passed all eight retirement/reuse rounds. The sparse filter with the probe included finished with 15 passed, 0 failed, 1 ignored. This checks the clearing decision; I haven't measured visible effects in a retail title.

12 GB VRAM measurements on clean heads. I ran the debug library suite (cargo test -p xcl --lib -- --test-threads=4) on both proposed fixes sharing parent 09940bb, sampling device-wide nvidia-smi memory every 250 ms on the RTX 5070 Ti Laptop (driver 621.24). Order and peaks: #930 bd2e4c6 4,477 MiB; #923 71bda93 2,183 MiB; #923 2,331 MiB; #930 5,388 MiB. Starting samples were 903–982 MiB. All four runs passed (675 tests on #930, 676 on #923, 21 ignored each). The same parent previously peaked at 11,469 and 11,687 MiB on this machine. These #930 measurements used the submitted code before my local clearing-flag change. Two runs per head, library workload only.

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

Originally posted by @ettehn in #930 (comment)

Originally posted by @ettehn in #930 (comment)

@dcastell1

Copy link
Copy Markdown

This patch fails the sparse e2e check on Windows, twice in a row, with the same value:

cargo test --workspace -- --test-threads=4
test result: FAILED. 690 passed; 2 failed; 25 ignored   (exit 101)

thread 'test_title_runs_and_game_folder_is_untouched' panicked at crates\xcl\tests\e2e.rs:132:5:
failed checks in the test title:
[FAIL] D3D12.X: async ring-buffered sparse uploads (80 MiB across 20 submits + reused-tile zeroing):
       reused tile untouched chunk was not zeroed: 0xa5000010

thread 'test_title_draws_with_a_root_signature_under_the_debug_layer' panicked at crates\xcl\tests\e2e.rs:267:5:
the test title did not run to the end

0xa5000010 is the test's own pattern coming back, so a tile that the retired pool hands out again is not zeroed before the next use — the zeroing that the 20-submit upload path relies on is skipped for a reused tile. Without the patch the same two tests pass (713 passed, 0 failed, 41 ignored on this box), so it is this change's reuse path rather than the test.

Environment: Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, main@beaa245 plus this PR applied with patch -p1 (clean, no fuzz). Two full runs, same failure. Tree restored afterwards; no game data.

AI-assisted (opencode): applied the patch to a built tree, ran the suite twice, reverted it.

@Lifither

Copy link
Copy Markdown

RX 590 on native Windows: sparse-upload e2e passes on e78e2df

Tested on clean main 077ce40c3e371cf3df8c57985b1cc6b1db39e75a and clean PR head e78e2df6dcd951d1392f091a0f63c8f8fcf0aaa9, in separate build directories. Radeon RX 590 Series (8135 MiB), driver 31.0.21923.1000, Ryzen 5 5600G, Windows 11 build 26300, Rust 1.100.0 MSVC x64, DXC 1.9.2609.5, debug builds. XCL logged the RX 590 in every run.

cargo build --locked --workspace
cargo test --locked -p xcl --test e2e test_title_runs_and_game_folder_is_untouched -- --exact --nocapture

Both builds passed. I alternated the e2e runs three times. Each revision passed 3/3 runs, with one case executed and zero failures, ignored tests or skips per run. The synthetic title ran to completion, rendered and read back its triangle, and passed the 80 MiB / 20-submit sparse-upload check including reused-tile zeroing in all six runs. The stale readback from the RTX 5090 report did not reproduce on this setup.

Not tested: The debug-layer variant, full workspace suite, peak VRAM, the exact repeated pool-retirement stress case in #913, and retail startup or rendering.

AI use: OpenAI Codex (GPT-6, exact variant unavailable) ran the tests, checked the logs, and drafted this report. No XCL code changes.

@dcastell1

Copy link
Copy Markdown

Heads-up: my failure above was measured on main@beaa245 with the head the PR had then, so it is not a verdict on e78e2df. I am re-running clean main@077ce40 and this PR at e78e2df in separate build directories now, with the same e2e check, and will post the pair (main and PR) when it finishes. If the zeroing is fixed on the new head, ignore the earlier comment; if it still shows, you get the same value with the current SHAs.

@dcastell1

Copy link
Copy Markdown

Retraction on the current pair: the failure does not reproduce, and my earlier comment was against stale SHAs.

On this box, same machine and command, in the same tree:

clean main 077ce40 (baseline)   : 716 passed; 0 failed; 41 ignored   (exit 0)
this PR at e78e2df on 077ce40   : 716 passed; 0 failed; 41 ignored   (exit 0)

The sparse e2e check (reused tile untouched chunk was not zeroed: 0xa5000010) that failed twice on beaa245 with the earlier head now passes, so whatever changed between those heads fixed the zeroing path. No failure to chase here from my side; sorry for the noise.

Environment unchanged: Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, patch -p1 clean. Tree restored afterwards; no game data.

AI-assisted (opencode): rebuilt on the new base, ran both pairs, reverted.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded by #923 (merged in 6bac4b4), which takes a retired pool back the same way and passed the sparse e2e check here. 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.

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

5 participants