Skip to content

Memory: the 16-window layout keeps 4 runtime sparse windows - #3517

Open
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/sparse-windows-4
Open

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/sparse-windows-4

Conversation

@CharlyRien

@CharlyRien CharlyRien commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

The 16-window layout (XCL_UMA_WINDOWS=16) now keeps 4 runtime sparse windows instead of 3. The 4- and 8-window layouts keep 3. XCL_SPARSE_WINDOWS=<n> (1 to 8) overrides the count for any layout.

Why: a retail title's BVH builder works in a 3.39 GB MEM_RESERVE | MEM_64K_PAGES reservation (0xd4920000 bytes, protect 0x2404), made once sparse windows 1..2 are taken. With 3 sparse windows it finds no room and becomes plain write-watched memory, which shaders read as zeros, so every acceleration structure the title builds stays empty. With 4 it lands in window 3, where the GPU sees it. The 16-window layout already leaves 5 of its windows empty (3 sparse + 1 coherent + 6 view), so the 4th sparse window costs no address space: 4 + 1 + 6 = 11 of 16.

claudetools-gh found this and proposed the same XCL_SPARSE_WINDOWS switch on #505 (comment 7273597036): with main's root-constant clamp 82b7cb3e and a 4th sparse window, the title builds real BVHs without crashing and the room gets bounce light, on an RTX 5070 Ti. This PR is his switch with 4 as the 16-window default. main already has 82b7cb3e (#1319), so this PR needs nothing else.

Part of #505.

What is in it
One commit:

  • crates/xcl/src/gpu/uma.rs:
    • SIXTEEN_WINDOW_SPARSE_WINDOWS = 4, next to MAX_RUNTIME_SPARSE_WINDOWS = 3 (now the 4- and 8-window value);
    • runtime_sparse_windows(windows): XCL_SPARSE_WINDOWS (parsed and clamped to 1..=8), else the layout's default. It replaces the constant at the only two places that bound the sparse windows: max_coherent_windows (through max_coherent_windows_for) and reserve_runtime;
    • nothing else moves: the coherent and view windows follow the sparse ones as before (coherent window 4, views 5..10, 11..15 reserved and empty), and every runtime user finds them through committed_window() / is_sparse_window() / is_view_window(). A coherent plan in the 16-window layout can now take 6 windows instead of 7.
  • Tests (uma.rs):
    • new: sparse_windows_setting_parses_clamps_and_fits_the_layout (parse, clamp, per-layout default; for 1..=8 sparse windows the 16-window layout still fits), sixteen_windows_keep_four_sparse_windows (the 16-window layout's windows, the whole aperture reserved, the write-watch regions), a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window (with windows 1..2 taken, a 0xd4920000 reservation lands in window 3, and 6.09 GB more takes no other window). The last two use only APIs main has, and fail on main, where the reservation gets no room;
    • existing layout tests follow the new indices (runtime_layout_supports_eight_and_sixteen_heap_windows, the_series_x_plan_is_pinned, sparse_alloc_above_keeps_window_0_for_the_title, sparse_reserve_keeps_single_window_reservations_inside_one_window, view_windows_hold_gpu_views, expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows).
  • crates/xcl/src/hle/d3d12x/console_heap.rs (test only): title_memory_holds_a_heap_only_in_window_0 probes the coherent window and a view window at their new indices.
  • crates/xcl/src/gpu/recomp/tests.rs (test only): gpu_sparse_vram_descriptors_buffers_and_xmem runs a 4-root-UAV program that expects the coherent window at window 3. With XCL_UMA_WINDOWS=16 that is now window 4, so the test skips there (SKIPPED …: the coherent window is not window 3); XCL_SPARSE_WINDOWS=3 runs it with 16 windows. The default 4-window run is unchanged.
  • README.md: XCL_SPARSE_WINDOWS in the switch list.

+148 / −36 in 4 files; about 30 of them are runtime lines, the rest tests and docs.

Tested

Regression run
Same machine as under Tested, same title, 60 s each, both through main d52ff48's scripts/smoke.ps1, XCL_PREPARE=0, the same scripted A presses (XCL_PRESS_A_AT), every other XCL_* unset (so the default 4-window layout, which this PR does not change: see Not tested). Each run started from its own copy of the same shader cache, made by another main commit, so cold for both. The head is on main 9dfbe3ea; the main run is of main d52ff48 (8 commits earlier): the check asks for a commit of main.

main d52ff48:

xcl-smoke v1
commit: d52ff48caade1f5350d513bfffd370396dadfeb6
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 517 (PresentX 517)
presents per 2 s (last 3): 61 60 61
device removals: 0
crashes: 0
peak commit: 15968 MB

This PR's head 0b4283d1:

xcl-smoke v1
commit: 0b4283d147b7bd5f93a9cc3d83433cdcdef9762f
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 593 (PresentX 593)
presents per 2 s (last 3): 61 61 60
device removals: 0
crashes: 0
peak commit: 15947 MB

Not tested

  • This PR's head on the retail title with XCL_UMA_WINDOWS=16: the A/B above is on our lab tree, not on this head, and the regression runs use the default 4-window layout, which this PR does not touch.
  • Other GPUs: AMD at all, NVIDIA cards with less than 24 GB (the extra video memory matters more there), the RTX 5070 Ti result is claudetools-gh's.
  • Other titles with 16 windows: a title whose large MEM_64K_PAGES reservations now fit in 16 GiB of sparse windows gets them in video memory, which is what the cap of 3 was there to avoid.
  • Acceleration-structure node counts from the GPU side on our card: our CPU-side log line (acceleration structure at …: 0 nodes) said 0 nodes in both runs; claudetools-gh's GPU-side read-back on an RTX 5070 Ti shows real trees, and that the CPU-side walk does not see the GPU's writes.
  • The whole suite with XCL_UMA_WINDOWS=16 XCL_HEAP_WINDOWS=1; Windows 10 and Wine.

AI use
AI use: the port of the switch, the new default, the tests, the A/B runs and their readings, and this description were done with Claude Code (Claude Opus 5.5), checked and posted by me. The switch itself is claudetools-gh's (#505).

🤖 Generated with Claude Code

The 16-window layout (XCL_UMA_WINDOWS=16) now reserves 4 sparse VRAM
windows instead of 3: 4 sparse + 1 coherent + 6 view windows still fit in
16, and the 4th window was one of the 5 it left empty, so it costs no
address space. The 4- and 8-window layouts keep 3.

A retail title's BVH builder works in a 3.39 GB MEM_RESERVE | MEM_64K_PAGES
reservation made once windows 1..2 are taken. With 3 sparse windows it
found no room and became plain write-watched memory, which shaders read as
zeros, so every acceleration structure stayed empty (xcl-dev#505). With
4 it lands in window 3, where the GPU sees it.

XCL_SPARSE_WINDOWS=<n> (1..=8) overrides the count for any layout
(README). A coherent plan in the 16-window layout now gets at most 6
windows instead of 7.

Tests: the setting's parse, clamp and per-layout default and the layout
accounting for 1..=8 sparse windows; the 16-window layout's windows; the
3.39 GB reservation landing in window 3 (fails on main, where it gets no
room). Existing layout tests follow the new window indices; the GPU test
of the 4-root-UAV program skips when the coherent window is not window 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 30, 2026
@CharlyRien
CharlyRien marked this pull request as ready for review November 30, 2026 11:08

@andresd-cerebras andresd-cerebras left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdrawn.

@thehollowedone

Copy link
Copy Markdown
Contributor

Focused follow-up on head 0b4283d: the default 16-window layout puts coherent memory in window 4, while pso::in_switch_form translates only windows 0–3. That fallback is used when the driver refuses a heap-window pipeline with E_OUTOFMEMORY. It cannot access both the new sparse window 3 and coherent window 4; swapping their positions would only change which one it loses.

I added the test-only regression below to a clean merge of this head onto main d0832e6. cargo test --offline --locked -p xcl --lib first_coherent_window_remains_reachable_by_switch_fallback -- --test-threads=1 failed 0 passed, 1 failed, 0 ignored with the default 16-window layout: “the switch fallback translates 4 windows but coherent memory starts in window 4.” On the same merged code with XCL_SPARSE_WINDOWS=3, it passed 1 passed, 0 failed, 0 ignored. This checks the layout and translation reach; I did not force a GPU pipeline fallback or run the full suite or a title.

For the intended four-sparse-window behavior, the fallback needs a path that can address both sparse window 3 and coherent window 4. Please carry the wider reach through translation, root signature and binding, and test a forced fallback that reads distinct nonzero sentinels from both in one dispatch. Keeping three sparse windows as the default until that path works would avoid introducing the gap while the wider fallback is developed.

Test-only regression diff
diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs
index 5d9df8ff..69ee1f26 100644
--- a/crates/xcl/src/gpu/uma.rs
+++ b/crates/xcl/src/gpu/uma.rs
@@ -1276,6 +1276,20 @@ pub fn get() -> Option<&'static Uma> {
 mod tests {
     use super::*;
 
+    #[test]
+    fn first_coherent_window_remains_reachable_by_switch_fallback() {
+        let u = Uma::for_runtime_windows(16 << 20, RUNTIME_COMMITTED_CAP, MAX_HEAP_WINDOWS)
+            .expect("16-window aperture");
+        let coherent = u.committed_window().expect("coherent window");
+        let reachable = crate::gpu::recomp::pso::in_switch_form(|| {
+            crate::gpu::recomp::pso::windows_for(u.shader_windows() as u32)
+        }) as usize;
+        assert!(
+            coherent < reachable,
+            "the switch fallback translates {reachable} windows but coherent memory starts in window {coherent}"
+        );
+    }
+
     /// Arena blocks come from XCL's pool while the title holds the rest of window 0, and go
     /// back to it when freed.
     #[test]

AI use: OpenAI Codex (GPT-6.2 Sol) wrote and ran the focused test and drafted this report; OpenAI Codex (GPT-6.2 Astra) reviewed the fallback design.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 0b4283d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2899 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (uma.rs +137/-35, console_heap.rs and recomp/tests.rs tests, README). Nothing changes by default: only XCL_UMA_WINDOWS=16 (which needs XCL_HEAP_WINDOWS=1) gets 4 sparse windows, with the coherent window moving to 4, the views to 5..10, and the coherent cap dropping from 7 to 6 windows; runtime users find windows by kind (committed_window() / is_sparse_window() / is_view_window()), so nothing is hard-wired to window 3. Findings: (1) nothing measures this head with XCL_UMA_WINDOWS=16: the PR's smoke pair uses the default 4-window layout this doesn't touch, and the retail A/B is from a lab tree. (2) #2905 places physical page homes from the top of the last sparse window (sparse_end()) down, which with this PR is window 3, the window the BVH reservation needs; both also edit the_series_x_plan_is_pinned, so whichever merges second needs a rebase that keeps both in mind. (3) recomp/tests.rs ~5273 suggests XCL_SPARSE_WINDOWS=3 to run that test with 16 windows, but that setting makes the new uma.rs layout tests fail in the same run. (4) On main, a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window fails because the reservation fits in window 0, not because there's no room; the test doesn't fill window 0 as the retail title does. (5) With 4 windows, XCL_SPARSE_WINDOWS above 3 does nothing, while the README says 1 to 8. Fine: the layout fits 16 windows for 1..=8 sparse windows and the whole aperture stays reserved; no conflict with #3546.
performance: no smoke run (the default path doesn't reach this change); not measured. Nothing changes by default (the 16-window layout needs XCL_UMA_WINDOWS=16 and XCL_HEAP_WINDOWS=1), so no smoke run; the opt-in layout is unmeasured on this head.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added the needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) label Dec 1, 2026
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 0b4283d

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 0b4283d

No other open PR changes the number of sparse windows. #3521/#3522 also target XboxBvhBuilder memory, but under XCL_SPARSE_LAZY=1 (tiles with no video memory), not a reservation that finds no room in the sparse windows; they do not overlap.
Notes on the diff: uma.rs:max_coherent_windows for 16 windows drops from 7 to 6, so a coherent need above 6 windows is now cut to 6 unless XCL_SPARSE_WINDOWS=3. The doc comment on MAX_RUNTIME_SPARSE_WINDOWS warns that more sparse VA pulls large startup MEM_64K_PAGES heaps into sparse VRAM (tile-mapping stalls); a 4th window brings that risk back for 16 windows. In recomp/tests.rs, gpu_sparse_vram_descriptors_buffers_and_xmem now calls skip_test whenever the coherent window is not window 3, so it skips by default with 16 windows: that is a configuration skip, not a missing-hardware skip. The README says 1 to 8, but with 4 windows more than 3 has no effect.
Recommendation: keep open.

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

@brainhay5

Copy link
Copy Markdown

merge-check claim withdrawn
Our automated merge-check loop claimed this PR and then stopped before posting a check — two loops were running at once and both are now shut down. No check from us is coming, so this claim is void and the head is free for someone else to take.

AI use: an agent posted this withdrawal.

@Hurtibabi

Hurtibabi commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 6bfb5c5
head: 0b4283d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2907 passed, 0 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no d3d12SDKLayers.dll, 2 no heap windows, 1 no D3D12 debug layer, 1 cannot disable the driver cache without Developer Mode); failing: none
review: read the whole diff (uma.rs, recomp/tests.rs, console_heap.rs, README). (1) With XCL_UMA_WINDOWS=16 the coherent window moves from 3 to 4, but the switch form that with_switch_fallback (real.rs ~5175) uses when the driver refuses a heap-window pipeline (#156) reaches only windows 0..3 (pso::windows_for_mode, emit.rs ~5079). Such pipelines lose the coherent window (title coherent memory, per-draw args, readback buffers) and read it as 0. This confirms thehollowedone's finding; I ran their test-only regression (first_coherent_window_remains_reachable_by_switch_fallback, added to the merge and removed again, not part of the counts above): cargo test -p xcl --lib first_coherent_window_remains_reachable_by_switch_fallback -- --test-threads=1 -> 0 passed, 1 failed ("the switch fallback translates 4 windows but coherent memory starts in window 4"); with XCL_SPARSE_WINDOWS=3 -> 1 passed, 0 failed. The PR does not mention this, and gpu_sparse_vram_descriptors_buffers_and_xmem now skips exactly this case with a configuration reason, not a missing-hardware one. (2) The new layout tests read XCL_SPARSE_WINDOWS through for_runtime_windows, so the XCL_SPARSE_WINDOWS=3 run suggested in recomp/tests.rs makes sixteen_windows_keep_four_sparse_windows and a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window fail in that run (from the code, not run). (3) With 4 windows, values above 3 have no effect (reserve_runtime takes (windows - coh_wins).min(n)), while the README says 1 to 8. Nothing changes in the default 4-window layout. No duplicate: no open or merged PR changes the sparse window count (#1998 introduced the cap of 3; #3097 was closed), and #1607 has no group for it. Not tested: this head with XCL_UMA_WINDOWS=16 XCL_HEAP_WINDOWS=1 on a title, a forced switch-form fallback on the GPU, AMD.
performance: default layout unchanged, so no frame-time or memory cost by default (reasoned, no smoke run). With XCL_UMA_WINDOWS=16 more title memory can land in sparse VRAM; not measured here (the PR reports about 420 MB more video memory at the peak on its lab tree).
verdict: not yet: with 16 windows the switch-form fallback (#156) no longer reaches the coherent window (finding 1, reproduced with a test); not covered by the PR's tests or description
hardware / tool and model: NVIDIA GeForce RTX 4090 (driver 621.40 / 32.0.16.2140), Intel Core i7-14700K, Windows 11 Pro 10.0.26200.9974, rustc 1.100.1, debug / Claude Code, Claude Opus 5.5 (claude-opus-5-5)

@github-actions github-actions Bot added checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants