Skip to content

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

Open
MacieGx wants to merge 1 commit into
xcl-dev:mainfrom
MacieGx:sparse/lazy-placed-buffers
Open

MacieGx wants to merge 1 commit into
xcl-dev:mainfrom
MacieGx:sparse/lazy-placed-buffers

Conversation

@MacieGx

@MacieGx MacieGx commented Nov 26, 2026

Copy link
Copy Markdown

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

Preparation for buffers a title places outside the memory windows
(xcl-dev#505), not called yet: `sparse::place_buffer_when(.., lazy)` makes
the reserved resource without tiles and `sparse::use_range(va, len)`
gives the lazily placed buffers there the window's video memory when
a list is about to use an address of them. `place_buffer` is
`place_buffer_when(.., false)` and behaves as before.

The newer retail title places 128+ GPU-only buffers (~580 MB) at
start; in a lab tree that gave them all video memory at once it ran
out of RAM before the world, and lazily it had 108 / 526 MB in use
25 s into the world. `use_range` checks two atomics before it takes
the sparse state's lock, so a call for an address outside every lazy
buffer costs nothing. A lazy buffer released before its first use
leaves the list in `forget_in`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DarkPanda69

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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 D3D12.X: GPU-only buffers placed outside the memory windows live in them #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

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.

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.

3 participants