D3D12.X: a placed sparse buffer can wait for its tiles until first use #2788

Open
MacieGx wants to merge 1 commit from upstream-pr/2798 into main
MacieGx commented 2026-11-26 13:50:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by MacieGx on 2026-11-26T13:50:32Z.


A placed sparse buffer can now be made without video memory and get its tiles when a list is about to use one of its addresses. This is preparation with no change in behaviour: nothing places a buffer lazily yet. The next PR uses it for the GPU-only buffers that the newer retail title places outside the memory windows; today those get an empty V#, so their light, ray and tile lists read as empty. Part of #505.

Why lazily: the title places 128 or more such buffers (about 580 MB) at start. In a lab tree that gave all of them video memory at once, the runs ran out of RAM before the world. Placed lazily, 108 buffers / 526 MB were in use 25 s into the world (573 of 578 MB by 365 s in a longer run).

#2539 (open) also changes sparse::place_buffer; whichever lands second rebases. #637 (open) mirrors views of buffers outside UMA from their CPU pages, which these GPU-only buffers do not have.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • place_buffer_when(.., lazy), with place_buffer = place_buffer_when(.., false) as before;
    • use_range(va, len) maps the waiting buffers in that range, and checks two atomics before it takes the state's lock;
    • State::back_buffer (the tile mapping place_buffer did inline), take_lazy, lazy_bounds;
    • forget_in drops a buffer released before its first use;
    • two tests.

Tested

  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24, Windows 11 Pro 26200, Rust stable MSVC, debug.
  • cargo test -p xcl --lib -- hle::d3d12x::sparse --test-threads=4: 19 passed, 0 failed, 1 ignored (the two new tests among them), no SKIPPED lines.
  • NVIDIA GeForce RTX 5080 16 GB (driver 621.24 = 32.0.16.2124), AMD Ryzen 7 5800X3D, 32 GB, Windows 11 Pro 10.0.26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, release.
  • cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4 on 1b11d3d: 1433 passed, 4 failed, 47 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState: out of memory (0x8007000E)), which fail on main as well. SKIPPED (the same as on main): 21 "no wave64", 3 refused by the per-lane form, heap_window_out_of_memory_falls_back_to_the_switch_form, pso_measurement_compiles_an_exact_synthetic_record.

Regression run
main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1383 (PresentX 1383)
presents per 2 s (last 3): 35 52 56
device removals: 0
crashes: 0
peak commit: 19703 MB

this PR:

xcl-smoke v1
commit: 1b11d3d54f2380d9a680192a8214246b97fc6ee8
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14966 MB

Not tested

  • The lazy path in a title: it has no caller in this PR. The lab tree's version of it, with its callers, ran in the newer retail title (runs R1 to O16).
  • AMD and Intel GPUs.

AI use

  • Claude Code with Claude Opus 5.5: ported the lab's lazy placement onto main's sparse state, wrote the tests and this description; Claude Opus 5.5 (coordinating) ran the full suite and the regression runs and reviewed the diff.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5511240549 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2798). Originally posted by [MacieGx](https://github.com/MacieGx) on 2026-11-26T13:50:32Z. --- A placed sparse buffer can now be made without video memory and get its tiles when a list is about to use one of its addresses. This is preparation with no change in behaviour: nothing places a buffer lazily yet. The next PR uses it for the GPU-only buffers that the newer retail title places outside the memory windows; today those get an empty V#, so their light, ray and tile lists read as empty. Part of #505. Why lazily: the title places 128 or more such buffers (about 580 MB) at start. In a lab tree that gave all of them video memory at once, the runs ran out of RAM before the world. Placed lazily, 108 buffers / 526 MB were in use 25 s into the world (573 of 578 MB by 365 s in a longer run). #2539 (open) also changes `sparse::place_buffer`; whichever lands second rebases. #637 (open) mirrors views of buffers outside UMA from their CPU pages, which these GPU-only buffers do not have. **What is in it** - `crates/xcl/src/hle/d3d12x/sparse.rs`: - `place_buffer_when(.., lazy)`, with `place_buffer` = `place_buffer_when(.., false)` as before; - `use_range(va, len)` maps the waiting buffers in that range, and checks two atomics before it takes the state's lock; - `State::back_buffer` (the tile mapping `place_buffer` did inline), `take_lazy`, `lazy_bounds`; - `forget_in` drops a buffer released before its first use; - two tests. **Tested** - NVIDIA GeForce RTX 5080 16 GB, driver 621.24, Windows 11 Pro 26200, Rust stable MSVC, debug. - `cargo test -p xcl --lib -- hle::d3d12x::sparse --test-threads=4`: 19 passed, 0 failed, 1 ignored (the two new tests among them), no SKIPPED lines. - NVIDIA GeForce RTX 5080 16 GB (driver 621.24 = 32.0.16.2124), AMD Ryzen 7 5800X3D, 32 GB, Windows 11 Pro 10.0.26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, release. - `cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4` on `1b11d3d`: 1433 passed, 4 failed, 47 ignored. The 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3` (`CreateComputePipelineState: out of memory (0x8007000E)`), which fail on `main` as well. SKIPPED (the same as on `main`): 21 "no wave64", 3 refused by the per-lane form, `heap_window_out_of_memory_falls_back_to_the_switch_form`, `pso_measurement_compiles_an_exact_synthetic_record`. **Regression run** main: ``` xcl-smoke v1 commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb gpu: NVIDIA GeForce RTX 5080 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 1383 (PresentX 1383) presents per 2 s (last 3): 35 52 56 device removals: 0 crashes: 0 peak commit: 19703 MB ``` this PR: ``` xcl-smoke v1 commit: 1b11d3d54f2380d9a680192a8214246b97fc6ee8 gpu: NVIDIA GeForce RTX 5080 title: 16b5e5d4 seconds: 60 exit: 0x0 frames shown: 1617 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14966 MB ``` **Not tested** - The lazy path in a title: it has no caller in this PR. The lab tree's version of it, with its callers, ran in the newer retail title (runs R1 to O16). - AMD and Intel GPUs. **AI use** - Claude Code with Claude Opus 5.5: ported the lab's lazy placement onto `main`'s sparse state, wrote the tests and this description; Claude Opus 5.5 (coordinating) ran the full suite and the regression runs and reviewed the diff. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DarkPanda69 commented 2026-11-26 15:03:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T14:25:44Z.


AMD run for the Not tested line.

Tested: pass, head 1b11d3d applied on main b49be18, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X.
cargo test -p xcl --lib -- hle::d3d12x::sparse --test-threads=4 --nocapture:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: 19 passed, 0 failed, 1 ignored, 0 SKIPPED. a_lazy_buffer_gets_its_tiles_at_its_first_use and use_range_outside_the_lazy_buffers_does_not_wait_for_the_state ok.

The sparse tests make their device with D3D12CreateDevice(None, ..), so they take the first adapter (the RX 9070 XT here) and XCL_ADAPTER doesn't move them. A run with XCL_ADAPTER=3060 gives the same counts but is not an NVIDIA result.

Not tested: the lazy path in a title; Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7194807075 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2798#issuecomment-7194807075). Originally posted by [DarkPanda69](https://github.com/DarkPanda69) on 2026-11-26T14:25:44Z. --- AMD run for the **Not tested** line. **Tested:** pass, head `1b11d3d` applied on `main` `b49be18`, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X. `cargo test -p xcl --lib -- hle::d3d12x::sparse --test-threads=4 --nocapture`: - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: 19 passed, 0 failed, 1 ignored, 0 SKIPPED. `a_lazy_buffer_gets_its_tiles_at_its_first_use` and `use_range_outside_the_lazy_buffers_does_not_wait_for_the_state` ok. The sparse tests make their device with `D3D12CreateDevice(None, ..)`, so they take the first adapter (the RX 9070 XT here) and `XCL_ADAPTER` doesn't move them. A run with `XCL_ADAPTER=3060` gives the same counts but is not an NVIDIA result. **Not tested:** the lazy path in a title; Intel. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Decodere commented 2026-11-26 15:03:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T14:46:29Z.


Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2798 at 1b11d3d54f2380d9a680192a8214246b97fc6ee8 (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted RTX 4060 release unit tests (1b11d3d5)

  • cargo test --release -p xcl --lib use_range_outside_the_lazy_buffers_does_not_wait_for_the_state -- --nocapture: 1 passed, 0 failed, 0 ignored (0.00 s, exit 0).
  • cargo test --release -p xcl --lib a_lazy_buffer_gets_its_tiles_at_its_first_use -- --nocapture: 1 passed, 0 failed, 0 ignored (0.23 s, ran live on RTX 4060, 0 skipped, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=4: 19 passed, 0 failed, 1 ignored (0.38 s, early_commit_timing ignored, 0 skipped, exit 0).

Observations

  • Both new lazy sparse-buffer tests (use_range_outside_the_lazy_buffers_does_not_wait_for_the_state and live RTX 4060 a_lazy_buffer_gets_its_tiles_at_its_first_use) plus all 19 hle::d3d12x::sparse:: tests passed cleanly in --release on exact head 1b11d3d5 with 0 skips.
  • Quiet 60 s retail smoke ran cleanly (exit: 0x0, 1558 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 14019 MB peak commit, 6176 MB peak / 6115 MB end local VRAM vs parent b49be183's 14018 MB / 1518 frames — matching baseline as expected before PR #2799 wires callers to place_buffer_when).

Paired 60 s RTX 4060 smoke (b49be183 vs 1b11d3d5)

Parent origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2798 head (1b11d3d5):

xcl-smoke v1
commit: 1b11d3d54f2380d9a680192a8214246b97fc6ee8
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1558 (PresentX 1558)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14019 MB

Limits of coverage

  • Full workspace test suite was not re-run on 1b11d3d5 (only targeted hle::d3d12x::sparse:: release tests plus paired quiet 60 s smoke).
  • PR #2798 introduces the lazy sparse-buffer API (place_buffer_when / use_range) without changing live retail callers yet; end-to-end retail VRAM reduction is verified on the stacked PR #2799 (321ada6a).
  • Single discrete NVIDIA 8 GB GPU (RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.

AI use

Ran the targeted release unit tests and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from cargo test and scripts/smoke.ps1 outputs.

<!-- greyfinch-sync:ivall/xcl:comment:7195307818 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2798#issuecomment-7195307818). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T14:46:29Z. --- **Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2798 at `1b11d3d54f2380d9a680192a8214246b97fc6ee8`** (exact parent `origin/main` `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`). Measurements and targeted test results only; not a full source review. ### Setup - **GPU:** NVIDIA GeForce RTX 4060 (8 GB / `7956 MiB` reported by D3D12), driver `32.0.16.2114` (NVIDIA `621.14`, WDDM 3.2) - **CPU / RAM / OS:** Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (`31.9 GiB` usable), Windows 11 Home `26200` - **Toolchain / caches:** `rustc 1.100.0 (0ef1bc386 2026-11-09)`, DXC `1.9.2609.5`, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs) - **Workload:** Retail workload `title: 29640639` via `scripts/smoke.ps1 -Seconds 60` (`XCL_NETWORK=0 XCL_ACTIVITY=1`, default flags, no input) ### Targeted RTX 4060 release unit tests (`1b11d3d5`) - `cargo test --release -p xcl --lib use_range_outside_the_lazy_buffers_does_not_wait_for_the_state -- --nocapture`: **1 passed, 0 failed, 0 ignored** (`0.00 s`, exit `0`). - `cargo test --release -p xcl --lib a_lazy_buffer_gets_its_tiles_at_its_first_use -- --nocapture`: **1 passed, 0 failed, 0 ignored** (`0.23 s`, ran live on RTX 4060, `0` skipped, exit `0`). - `cargo test --release -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=4`: **19 passed, 0 failed, 1 ignored** (`0.38 s`, `early_commit_timing` ignored, `0` skipped, exit `0`). ### Observations - Both new lazy sparse-buffer tests (`use_range_outside_the_lazy_buffers_does_not_wait_for_the_state` and live RTX 4060 `a_lazy_buffer_gets_its_tiles_at_its_first_use`) plus all 19 `hle::d3d12x::sparse::` tests passed cleanly in `--release` on exact head `1b11d3d5` with `0` skips. - Quiet 60 s retail smoke ran cleanly (`exit: 0x0`, `1558` frames shown, `60 60 60` steady-state presents per 2 s, `0` device removals, `0` crashes, `14019 MB` peak commit, `6176 MB` peak / `6115 MB` end local VRAM vs parent `b49be183`'s `14018 MB` / `1518` frames — matching baseline as expected before PR #2799 wires callers to `place_buffer_when`). ### Paired 60 s RTX 4060 smoke (`b49be183` vs `1b11d3d5`) Parent `origin/main` (`b49be183`): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1518 (PresentX 1518) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14018 MB ``` PR #2798 head (`1b11d3d5`): ``` xcl-smoke v1 commit: 1b11d3d54f2380d9a680192a8214246b97fc6ee8 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1558 (PresentX 1558) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14019 MB ``` ### Limits of coverage - Full workspace test suite was not re-run on `1b11d3d5` (only targeted `hle::d3d12x::sparse::` release tests plus paired quiet 60 s smoke). - PR #2798 introduces the lazy sparse-buffer API (`place_buffer_when` / `use_range`) without changing live retail callers yet; end-to-end retail VRAM reduction is verified on the stacked PR #2799 (`321ada6a`). - Single discrete NVIDIA 8 GB GPU (`RTX 4060`) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host. ### AI use Ran the targeted release unit tests and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from `cargo test` and `scripts/smoke.ps1` outputs.
CharlyRien commented 2026-11-30 05:59:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-30T05:59:23Z.


This conflicts with main now. Together with #2799 it brought the characters' bodies back on the retail title for us (RTX 3090), in a targeted form; details, and our port rebased onto current main, in https://github.com/xcl-dev/xcl/pull/2799 (latest comments). I can post a test report once it is rebased.

AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

<!-- greyfinch-sync:ivall/xcl:comment:7270194680 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2798#issuecomment-7270194680). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-11-30T05:59:23Z. --- This conflicts with `main` now. Together with #2799 it brought the characters' bodies back on the retail title for us (RTX 3090), in a targeted form; details, and our port rebased onto current `main`, in https://github.com/xcl-dev/xcl/pull/2799 (latest comments). I can post a test report once it is rebased. AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.
Foniass commented 2026-12-01 08:58:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:58:58Z.


Triage (#1607) – head 1b11d3d

#2799 and #2801 are stacked on this PR, not duplicates. Main's XCL_SPARSE_LAZY (#2897) delays video memory for committed window tiles; it does not delay placed buffers, which is what place_buffer_when(.., lazy)/use_range here do. Main's sparse.rs has since been restructured (place_buffer_in, PLACEMENT lock), so this conflicts. Two points to check in sparse.rs:

  • Unlike main's lazy commits, nothing checks for tiled resources tier 2. On tier 1, a GPU access that use_range did not catch hits an unmapped tile, which is undefined.
  • use_range AddRefs a raw resource pointer from State::lazy. A last Release on another thread while STATE is held only queues forget_buffer, so the pointer may already be freed.
    Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7306047066 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2798#issuecomment-7306047066). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:58:58Z. --- **Triage (#1607)** – head 1b11d3d #2799 and #2801 are stacked on this PR, not duplicates. Main's `XCL_SPARSE_LAZY` (#2897) delays video memory for committed window tiles; it does not delay placed buffers, which is what `place_buffer_when(.., lazy)`/`use_range` here do. Main's `sparse.rs` has since been restructured (`place_buffer_in`, `PLACEMENT` lock), so this conflicts. Two points to check in `sparse.rs`: - Unlike main's lazy commits, nothing checks for tiled resources tier 2. On tier 1, a GPU access that `use_range` did not catch hits an unmapped tile, which is undefined. - `use_range` AddRefs a raw resource pointer from `State::lazy`. A last Release on another thread while `STATE` is held only queues `forget_buffer`, so the pointer may already be freed. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2798:upstream-pr/2798'
git switch 'upstream-pr/2798'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2798'
git switch 'upstream-pr/2798'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2798'
git switch 'upstream-pr/2798'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2798'
git switch 'main'
git merge --squash 'upstream-pr/2798'
git switch 'main'
git merge --ff-only 'upstream-pr/2798'
git switch 'main'
git merge 'upstream-pr/2798'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2788
No description provided.