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
Collaborator

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
Collaborator

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
@Decodere

Decodere commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Diff review (head 0b4283d14, read-only code review — not a test report):

Clean layout math in uma.rs for adding a 4th sparse window to the 16-window aperture without disturbing the default 4-window layout. Two concrete issues remain on 0b4283d14:

  1. with_switch_fallback still caps shaders at 4 windows (0..3), cutting off coherent window 4 in the 16-window layout (crates/xcl/src/gpu/uma.rs:48, :59, :360-362; crates/xcl/src/hle/d3d12x/real.rs:5146-5159; crates/xcl/src/gpu/recomp/pso.rs:147-161, :176-185; crates/xcl/src/hle/d3d12x/bind.rs:5287-5290):
    With XCL_UMA_WINDOWS=16 (MAX_HEAP_WINDOWS), raising the default sparse window count to SIXTEEN_WINDOW_SPARSE_WINDOWS = 4 (uma.rs:48, :59) moves the first coherent window from window 3 to window 4 (uma.rs:360-362, :379). Whenever the driver refuses a heap-window pipeline with E_OUTOFMEMORY, with_switch_fallback (real.rs:5146-5159) rebuilds it inside pso::in_switch_form (pso.rs:176-185), where windows_for_mode(n, false) (pso.rs:148, :155-160) caps translation to MAX_WINDOWS = 4 (root UAVs 0..3 bound at bind.rs:5287-5290). Any pipeline taking switch fallback in the 16-window layout can no longer address coherent memory in window 4 (reads return 0), which is also why gpu_sparse_vram_descriptors_buffers_and_xmem had to skip when u.committed_window() != Some(3) (crates/xcl/src/gpu/recomp/tests.rs:5270-5275). Either keeping the coherent window within switch-fallback reach or extending fallback addressing to cover window 4 avoids silent data loss on driver OOM fallback.

  2. Unit tests are sensitive to ambient XCL_SPARSE_WINDOWS (crates/xcl/src/gpu/uma.rs:52-54, :77-79, :96-97, :349-362, :1507-1587, :1713-1755, :1810-1830):
    Uma::for_runtime_windows, max_coherent_windows, and coherent_window_sizes all call runtime_sparse_windows(windows) (uma.rs:52-54), which reads live std::env::var("XCL_SPARSE_WINDOWS"). However, the updated/new tests (runtime_layout_supports_eight_and_sixteen_heap_windows at uma.rs:1507, the_series_x_plan_is_pinned at :1558, sixteen_windows_keep_four_sparse_windows at :1713, a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window at :1741, and expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows at :1810) assert the default 4-sparse-window layout. Running cargo test with XCL_SPARSE_WINDOWS=3 (as suggested in crates/xcl/src/gpu/recomp/tests.rs:5271) therefore fails those 5 unit tests in the same run. Passing an explicit sparse-window count into reserve_runtime / test helpers (reading XCL_SPARSE_WINDOWS only in uma::get()) decouples unit tests from the environment.

Minor note: README.md:360-363 documents XCL_SPARSE_WINDOWS as 1 to 8, whereas in the 4-window layout reserve_runtime caps sparse_wins at windows - coh_wins = 3 (uma.rs:362), so values above 3 have no effect with 4 windows (and values above 7 have none with 8).

AI use: Antigravity (Gemini 4 Neon) audited the full diff against main and drafted this review.

@Gevroska

Gevroska commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

I compared the production sparse allocator on main 1c8b5514 and head 0b4283d1 using native Windows VirtualAlloc. With the 16-window layout active, I held windows 1 and 2 and requested a 3.32 GiB reservation.

Window 0 at the time of the request Main PR head
Available Reserved in window 0 Reserved in window 3
1 GiB already held No sparse reservation Reserved in window 3

Setting XCL_SPARSE_WINDOWS=3 on the PR restored the main result in both cases. An independent repeat reproduced all six process-level controls.

This identifies a case where the fourth sparse window preserves a reservation that main cannot satisfy. The fixture exercised the CPU allocator only. The separate question raised above about a fallback shader reaching coherent window 4 still needs GPU validation.

OpenAI Codex GPT-6.2 Sol ran the test, a separate GPT-6.2 Sol agent repeated it, and GPT-6.2 Astra drafted this comment.

I reviewed and approved this comment before posting.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 0b4283d1: 3 finding(s). 3 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

Comment thread crates/xcl/src/gpu/uma.rs
/// windows it leaves empty (4 sparse + 1 coherent + 6 view windows of 16), so it costs no address
/// space. A retail title's BVH builder works in a 3.5 GB `MEM_RESERVE | MEM_64K_PAGES` reservation
/// made once windows 1..2 are taken: with 3 it found no room and became plain write-watched
/// memory, which shaders read as zeros (every acceleration structure stayed empty).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With 4 sparse windows, the 16-window layout's coherent window moves from window 3 to window 4, which pipelines in the switch form (4 root UAVs, windows 0..3 only) can't reach. With XCL_UMA_WINDOWS=16 and XCL_HEAP_WINDOWS=1 on NVIDIA, a big program that gets E_OUTOFMEMORY with heap windows is rebuilt in the switch form by real::with_switch_fallback (real.rs:5145-5158). The same happens to every pipeline when console_heap::window_views_failed() turns pso::heap_windows() off. Window 3 is now an empty sparse window, so per-draw arguments, readback buffers, spilled root tables and coherent-window GPU heaps read 0 in those pipelines, and their writes are dropped. The skip added to gpu_sparse_vram_descriptors_buffers_and_xmem ("4 root-UAV windows do not reach" window 4) shows the regression rather than testing it.

Comment thread crates/xcl/src/gpu/uma.rs
/// layout's default).
fn sparse_windows_setting(v: Option<&str>, windows: usize) -> usize {
let default = if windows == MAX_HEAP_WINDOWS { SIXTEEN_WINDOW_SPARSE_WINDOWS } else { MAX_RUNTIME_SPARSE_WINDOWS };
v.and_then(|v| v.trim().parse::<usize>().ok()).map_or(default, |n| n.clamp(1, 8))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

XCL_SPARSE_WINDOWS is clamped to 1..=8, so 7 or 8 sparse windows give the title 27.5+ GiB of sparse space, and its 24 GiB MEM_64K_PAGES CPU view then lands in sparse VRAM. With XCL_UMA_WINDOWS=16 (or 8) and XCL_SPARSE_WINDOWS=7, kernelx::VirtualAlloc sends the retail title's 24 GiB CPU-view reservation to sparse_reserve, which now finds room, so 24 GiB becomes tiled video memory, which the view windows were built to prevent (see the sparse_end doc). The upper bound has to depend on the layout (below 6 for 16 windows, similar for 8). Values outside it are clamped or ignored with no log line.

Comment thread crates/xcl/src/gpu/uma.rs
windows.saturating_sub(MAX_RUNTIME_SPARSE_WINDOWS + view_windows(windows)).max(1)
windows.saturating_sub(sparse + view_windows(windows)).max(1)
} else {
1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not certain about this one: the 16-window coherent cap drops from 7 to 6 windows, so stored coherent needs between ~24 and ~28 GB are now cut down. A title whose coherent_file holds a ~26 GB need (with enough commit) used to get 7 coherent windows. Now coherent_window_sizes stops at 6 x 4095 MB, and the GPU heaps past that leave the coherent window. note_coherent_need / settle_coherent_need also report the smaller cap.

@Pipodi

Pipodi commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: 0b4283d
merge: clean
build: cargo build --workspace -> ok (and cargo build --release -p xcl -> ok)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache); failing: none. Fail-without: on the merge with XCL_SPARSE_WINDOWS=3 (main's 3-window layout), cargo test -p xcl --lib gpu::uma::tests -> 15 passed, 7 failed, including the new sixteen_windows_keep_four_sparse_windows and a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window.
review: read the whole diff (uma.rs, recomp/tests.rs, console_heap.rs, README). (1) Confirmed, and it is what the two checks weigh differently: with XCL_UMA_WINDOWS=16 the coherent window moves from 3 to 4, and the switch form that with_switch_fallback (real.rs ~5178) builds when the driver refuses a heap-window pipeline reaches only windows 0..3 (pso::windows_for_mode), so such a pipeline reads title coherent memory, per-draw args and readback buffers as 0. thehollowedone's test-only regression on this merge (added, then removed; not in the counts above): default -> 0 passed, 1 failed ("the switch fallback translates 4 windows but coherent memory starts in window 4"); XCL_SPARSE_WINDOWS=3 -> 1 passed. In the runs below and in earlier 16-window runs here the fallback never fired (0 "building it in the switch form" lines on the RTX 4090), so it bites only where the driver returns E_OUTOFMEMORY, but then silently. Both earlier checks agree nothing changes by default; the PR exists for the 16-window layout, and there it opens this gap, which its tests skip (gpu_sparse_vram_descriptors_buffers_and_xmem skips with a configuration reason). (2) The 4th window takes more than the BVH scratch: with 16 windows the title's 99776-page (6236 MiB) physical-page block now fits the sparse windows, so its homes go there instead of plain memory (the run with XCL_SPARSE_WINDOWS=3 logs "AllocateTitlePhysicalPages(99776): no room in unified memory – their home is plain memory"; the default 16-window run does not). Every home committed there also takes a video-memory tile. (3) The layout tests read XCL_SPARSE_WINDOWS from the environment: a suite run with XCL_SPARSE_WINDOWS=3, as recomp/tests.rs suggests for that GPU test, fails 7 uma.rs tests (measured above). (4) README "1 to 8": with 4 windows values above 3 change nothing.
performance: default 4-window layout unchanged (measured: smoke pair below). Opt-in 16-window layout costs memory: 60 s smoke runs of this merge on the retail title with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_UMA_SHADOW=1 XCL_COHERENT_HEAPS=sparse:16: default (4 sparse) vs XCL_SPARSE_WINDOWS=3, at 60 s sparse CPU copy 6722 vs 6085 MB and sparse tiles (video) 6768 vs 6131 MB (+637 MB each); peak commit 25104 vs 27072 MB and frames 1522 vs 1605, both within noise of one run each, no removal or crash. In an earlier local run on the retail title's intro cinematic (older base, same 16-window settings) the same change grew from there to about +4 GB sparse CPU copy and +4 GB video tiles (27 GB of video memory against a 23 GB budget), a 24 % dearer write-watch look, and peak commit reaching our 52 GB kill cap; XCL_SPARSE_WINDOWS=3 avoided it. Not measured on this head past 60 s.
verdict: not yet: (1) with 16 windows the switch-form fallback no longer reaches the coherent window (reproduced with a test, not covered by the PR's tests or description); (2) the 4th window also takes the title's 6.2 GB physical-page homes into video memory, which needs a measurement past the menu or a limit to the BVH scratch case
hardware / tool and model: NVIDIA GeForce RTX 4090 24 GB, driver 621.40; Intel Core i9-13900K, 32 GB; Windows 11 build 26300; rustc 1.100.0, debug (tests) / release (smoke) / Claude Code, Claude Opus 5.5

Regression run (default layout, 60 s, standard presses, gamesave moved aside, one warm-up first)
main:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19846 MB

this merge (main 1c8b551 + head 0b4283d):

xcl-smoke v1
commit: c47e3bdc37a3e6b8dc6fd4d632d0999e0c652062
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1559 (PresentX 1559)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 20053 MB

AI-written (Claude Code, Claude Opus 5.5) and posted by Pipodi.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

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.

10 participants