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

Closed
github-bot wants to merge 2 commits from gh-pr/930/head into gh-pr/930/base
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 08:37 UTC · original
DavidM1911:sparse-reuse-retired → main · +28 −12 · 1 files · 2 commits · closed without merging

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 #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:
    • cargo test -p xcl --lib sparse: 13 passed, 0 failed, 1 ignored
    • cargo test -p xcl --lib -- --test-threads=4: 675 passed, 0 failed, 21 ignored (one earlier parallel run hit the known coherent_buffer_sanitizes_console_flags_and_state flake reported in #913; it passes standalone and on rerun)
    • cargo test --workspace -- --test-threads=4: 694 passed, 1 failed (same flake), 25 ignored
  • 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

  • The exact #348 test scenario on a 12 GB card (this machine has an 8 GB RTX 3060 Ti); the reuse path is exercised by the sparse tests but the VRAM-exhaustion repro itself was not rerun
  • Interaction with open #532 (same file, different functions — take_tile/retire_free_pools vs decommit parking); whichever lands second may need a small rebase

AI use

  • Devin (SWE-2 Flash Medium): implemented the change, ran the suites and smoke runs.
**@⁠DavidM1911** on GitHub · 2026-11-24 08:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/930) `DavidM1911:sparse-reuse-retired` → `main` · +28 −12 · 1 files · 2 commits · closed without merging 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 #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`: - `cargo test -p xcl --lib sparse`: 13 passed, 0 failed, 1 ignored - `cargo test -p xcl --lib -- --test-threads=4`: 675 passed, 0 failed, 21 ignored (one earlier parallel run hit the known `coherent_buffer_sanitizes_console_flags_and_state` flake reported in #913; it passes standalone and on rerun) - `cargo test --workspace -- --test-threads=4`: 694 passed, 1 failed (same flake), 25 ignored - 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** - The exact #348 test scenario on a 12 GB card (this machine has an 8 GB RTX 3060 Ti); the reuse path is exercised by the sparse tests but the VRAM-exhaustion repro itself was not rerun - Interaction with open #532 (same file, different functions — `take_tile`/`retire_free_pools` vs decommit parking); whichever lands second may need a small rebase **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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:37:20 +00:00
github-bot closed this pull request 2026-11-26 04:37:20 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 08:56 UTC · original

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.

**@⁠dcastell1** on GitHub · 2026-11-24 08:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7126762348) 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.
Author
Owner

@⁠ettehn on GitHub · 2026-11-24 08:46 UTC · original · edited 2026-11-24 08:58 UTC

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 https://github.com/ivall/xcl/issues/930#issuecomment-7126555760

Originally posted by @⁠ettehn in https://github.com/ivall/xcl/issues/930#issuecomment-7126555760

**@⁠ettehn** on GitHub · 2026-11-24 08:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7126555760) · edited 2026-11-24 08:58 UTC **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 https://github.com/ivall/xcl/issues/930#issuecomment-7126555760_ _Originally posted by @⁠ettehn in https://github.com/ivall/xcl/issues/930#issuecomment-7126555760_
Author
Owner

@⁠Lifither on GitHub · 2026-11-24 09:12 UTC · original

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.

**@⁠Lifither** on GitHub · 2026-11-24 09:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7127102790) ### 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. ```powershell 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.
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 09:22 UTC · original

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** on GitHub · 2026-11-24 09:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7127312920) 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.
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 09:23 UTC · original

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.

**@⁠dcastell1** on GitHub · 2026-11-24 09:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7127359499) 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.
Author
Owner

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

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!

**@⁠ivall** on GitHub · 2026-11-24 09:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/930#issuecomment-7127544678) 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!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.