Skip to content

UMA: support 8/16 heap windows (5/13 coherent) with 3-sparse (12 GiB) cap - #1998

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
raylitebull:feat/heap-windows-16-v2
Nov 25, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
raylitebull:feat/heap-windows-16-v2

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Adds multi-coherent 8- and 16-window UMA layouts (XCL_HEAP_WINDOWS=1 with XCL_UMA_WINDOWS=8|16), while capping runtime sparse VRAM windows at 3 (12 GiB) so expanded layouts keep 5 or 13 committed coherent windows (max_coherent_windows), alongside sparse 64 KiB GPU-view mirror cleanup on release.

Part of #1833.

What is in it

  • crates/xcl/src/gpu/uma.rs: add MAX_HEAP_WINDOWS = 16, multi-coherent pool sizing (max_coherent_windows, max_coherent_bytes, coherent_window_sizes), 3-window (12 GiB) sparse cap on runtime 8/16-window layouts, and uma::tests (runtime_layout_supports_eight_and_sixteen_heap_windows, expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows).
  • crates/xcl/src/gpu/dxil/kernel.rs, crates/xcl/src/gpu/recomp/emit.rs, mod.rs, runner.rs: shader translation & DXIL validation support for expanded heap-window layouts (expanded_heap_window_shaders_translate_and_validate).
  • crates/xcl/src/hle/d3d12x/console_heap.rs & real.rs: expanded descriptor heap/window view registration.
  • crates/xcl/src/hle/kernelx.rs: register and clean up sparse 64 KiB GPU-view mirrors (sparse_64k_reservation_registers_gpu_view_mirror_and_releases_cleanly).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto 6567c5f (06308bc).
  • cargo check --workspace --tests: passed.
  • cargo test -p xcl --lib runtime_layout_supports_eight_and_sixteen_heap_windows: 1 passed, 0 failed.
  • cargo test -p xcl --lib expanded_heap_window_shaders_translate_and_validate: 1 passed, 0 failed.
  • cargo test -p xcl --lib expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows: 1 passed, 0 failed.
  • cargo test -p xcl --lib sparse_64k_reservation_registers_gpu_view_mirror_and_releases_cleanly: 1 passed, 0 failed.
  • Community GPU verification on exact head 06308bc:
    • @WebIdentity1 (NVIDIA RTX 3090, HLSL + Direct DXIL): 3/0/0 passed on 8- and 16-window tests (plus negative control 2/1/0).
    • @futurepro62 (NVIDIA RTX 5070 Ti: 990 passed, 0 failed, 43 ignored; AMD Radeon RDNA2 iGPU: 1000 passed, 0 failed, 45 ignored), including all 4 new #1998 tests.
    • @Anon64 (NVIDIA RTX 3060, 60 s scripts/smoke.ps1 pair vs main 80f4819): 1606 vs 1588 frames (101%), 0 device removals, 0 crashes, 24883 MB vs 25184 MB peak commit (98%).

Regression run
60 s scripts/smoke.ps1 pair on exact head 06308bc vs main 80f4819 (NVIDIA GeForce RTX 3060 12 GB, driver 581.80, Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s on a retail title), contributed by @Anon64:

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 06308bc61a16a1cd4fb395f8e3704f3aba41b757
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1606 (PresentX 1606)
presents per 2 s (last 3): 45 55 37
device removals: 0
crashes: 0
peak commit: 24883 MB

Not tested

  • Full world-loading gameplay or whether default settings reach the 8/16-window paths during the 60 s smoke; Intel Arc GPU execution; Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation, rebase onto 6567c5f, and unit tests; the author reviewed the diff and test output.

@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown

Verified expanded-window GPU access at 06308bc61a16a1cd4fb395f8e3704f3aba41b757 on RTX 3090. Adapted the existing high-window regression from #822 (e9705bb935c4a4e2064127d3f5bfa26fab89e674, same XCL GPL-2.0-only code) to check both 8 windows / window 7 and 16 windows / window 15, with 1 MiB committed per window. The test exercises scalar and buffer loads, global loads/stores/atomic-add, and a window-0 sentinel.

One coverage trap: tests::direct_or accepts at most four windows and otherwise returns HLSL, even with XCL_DIRECT_DXIL=1. The attached test explicitly calls the direct translator for expanded layouts, so these results cover both paths.

Tested — native Windows 10 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, DXC 1.8.2502.11, debug. Exact head plus the test-only patch below; no runtime changes in positive runs.

cargo test --locked -p xcl --lib -- gpu_memory_windows_above_4_gib gpu_memory_windows_from_the_heap gpu_memory_windows_beyond_the_root_uavs --test-threads=1 --show-output

Common environment: XCL_ADAPTER=3090, XCL_REQUIRE_GPU=wave64,mesh, XCL_SPLIT_WAVE64=1.

Source / translator Passed / failed / ignored Result
Head + test, XCL_DIRECT_DXIL unset 3 / 0 / 0 HLSL: both high windows and both two-window controls correct
Same source, XCL_DIRECT_DXIL=1 3 / 0 / 0 Direct DXIL: both high windows and both controls correct
Same source, only kernel::mem_windows restored to .clamp(1, 4), Direct DXIL 2 / 1 / 0 New test fails at window 7: scalar read (0, 0) instead of (0xC0FFEE, 0x1234); both controls still pass

Zero skips in all three runs. All 311 source-file hashes matched before/after, with XCL rebuilt at each source switch. The negative control changes only gpu/dxil/kernel.rs; the positive source manifests are identical. The inherited assertion text still says “window 1”; in the failing expanded case the actual target is window 7.

Not tested — full workspace suite, retail smoke/gameplay, runtime sparse/coherent allocation and mirror cleanup, multi-GiB memory pressure, graphics stages, AMD, or performance improvement. These results establish the high-window access path, not that this PR resolves world loading or reduces total memory. #822 remains relevant overlapping layout work; this is complementary test coverage for the current author-owned PR, not another implementation.

AI use — Codex (GPT-6) reviewed the paths, adapted the test with provenance, ran native tests and prepared this report.

Test-only patch (26 additions, 8 deletions)
diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs
index e1f73ef..bae2c2b 100644
--- a/crates/xcl/src/gpu/recomp/tests.rs
+++ b/crates/xcl/src/gpu/recomp/tests.rs
@@ -3237,23 +3237,32 @@ fn gpu_mesh_mode_reads_memory_windows() {
 /// accesses in window 0.
 #[test]
 fn gpu_memory_windows_above_4_gib() {
-    memory_windows_above_4_gib(false);
+    memory_windows_above_4_gib(2, false);
 }
 
 /// The same program with the windows taken from the descriptor heap (`Options::heap_windows`):
 /// same results, and no `switch` over windows in the HLSL.
 #[test]
 fn gpu_memory_windows_from_the_heap() {
-    memory_windows_above_4_gib(true);
+    memory_windows_above_4_gib(2, true);
 }
 
-fn memory_windows_above_4_gib(heap: bool) {
+// Adapted from XCL PR #822, e9705bb (GPL-2.0-only):
+// https://github.com/xcl-dev/xcl/pull/822. Also check 8 windows and explicit Direct DXIL.
+#[test]
+fn gpu_memory_windows_beyond_the_root_uavs() {
+    for windows in [8, 16] {
+        memory_windows_above_4_gib(windows, true);
+    }
+}
+
+fn memory_windows_above_4_gib(windows: usize, heap: bool) {
     if !gpu_ready() {
         return;
     }
-    let arena = crate::gpu::uma::Uma::with_windows(2, 1 << 20).unwrap();
-    let (w0, w1) = (arena.window(0).0 as u64, arena.window(1).0 as u64);
-    assert_eq!(w1 - w0, 1 << 32);
+    let arena = crate::gpu::uma::Uma::with_windows(windows, 1 << 20).unwrap();
+    let (w0, w1) = (arena.window(0).0 as u64, arena.window(windows - 1).0 as u64);
+    assert_eq!(w1 - w0, ((windows - 1) as u64) << 32);
     let word = |a: u64| unsafe { &mut *(a as *mut u32) };
     *word(w1 + 0x1000) = 0xC0FFEE;
     *word(w1 + 0x1004) = 0x1234;
@@ -3278,12 +3287,20 @@ fn memory_windows_above_4_gib(heap: bool) {
     let p = prog(&refs);
     let one = translate(&p, &Options::default()).unwrap();
     assert!(!one.hlsl.contains("mem1") && !one.hlsl.contains("xcl_w =") && !one.hlsl.contains("xcl_m"), "one window: the single-window HLSL");
-    let t = translate(&p, &on_gpu(Options { mem_windows: 2, heap_windows: heap, ..Default::default() })).unwrap();
+    let t = translate(&p, &on_gpu(Options { mem_windows: windows as u32, heap_windows: heap, ..Default::default() })).unwrap();
     assert!(t.hlsl.contains("RWByteAddressBuffer mem1 : register(u3)"));
     assert_eq!(t.hlsl.contains("switch (xcl_w)"), !heap, "heap windows: no switch over windows");
     assert_eq!(t.hlsl.contains("ResourceDescriptorHeap[NonUniformResourceIndex(0u + xcl_w)]"), heap);
     let hlsl_dxil = || super::dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).map_err(|e| format!("{e}\n{}", t.hlsl)).unwrap();
-    let dxil = direct_or(&p, &on_gpu(Options { mem_windows: 2, heap_windows: heap, ..Default::default() }), hlsl_dxil());
+    let dxil = if windows > 4 && runner::direct_dxil() {
+        // direct_or intentionally falls back above four windows: do not count that as DXIL coverage.
+        crate::gpu::dxil::kernel::translate(&p, crate::gpu::dxil::kernel::KernelOptions {
+            wave64: true, split: runner::split_wave64(),
+            mem_windows: windows as u32 | super::HEAP_WINDOWS, sampler_base: 0,
+        }).expect("expanded direct DXIL")
+    } else {
+        direct_or(&p, &on_gpu(Options { mem_windows: windows as u32, heap_windows: heap, ..Default::default() }), hlsl_dxil())
+    };
     let hi = |a: u64| (a >> 32) as u32;
     let mut st = KernelState::default();
     st.sgpr[2..4].copy_from_slice(&[(w1 + 0x1000) as u32, hi(w1)]);
@@ -3312,6 +3329,7 @@ fn memory_windows_above_4_gib(heap: bool) {
     }
     assert_eq!(*word(w1 + 0x6000), 64, "global_atomic_add in window 1");
     assert_eq!(*word(w0 + 0x6000), 0, "nothing in window 0 at the same low address");
+    println!("{windows} windows, target {}, direct={}: scalar/buffer/global loads, stores and atomic output correct", windows - 1, runner::direct_dxil());
 }
 
 /// Out-of-UMA addresses must NEVER alias onto live UMA windows via `& 3`:

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 06308bc (on its base 6567c5f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 990 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: runtime_layout_supports_eight_and_sixteen_heap_windows, expanded_heap_window_shaders_translate_and_validate, expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows, sparse_64k_reservation_registers_gpu_view_mirror_and_releases_cleanly.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1000 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 06308bc, based on main 80f4819. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 06308bc61a16a1cd4fb395f8e3704f3aba41b757
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1606 (PresentX 1606)
presents per 2 s (last 3): 45 55 37
device removals: 0
crashes: 0
peak commit: 24883 MB

No device removals or crashes; 101 % of main's frames, 98 % of its peak commit.

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@raylitebull

Copy link
Copy Markdown
Member Author

Thanks @Anon64 for running and sharing the 60 s scripts/smoke.ps1 pair on 06308bc vs 80f4819 (1606 vs 1588 frames, 0 device removals, 0 crashes, 24883 MB vs 25184 MB peak commit) — added to the PR description! Thanks also to @futurepro62 (RTX 5070 Ti + AMD Radeon RDNA2 iGPU full suite) and @WebIdentity1 (RTX 3090 8/16-window GPU verification) for verifying exact head 06308bc.

@raylitebull
raylitebull merged commit fb32c87 into xcl-dev:main Nov 25, 2026
2 of 3 checks passed
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

brothernog added a commit to brothernog/xcl that referenced this pull request Nov 25, 2026
…them

With heap windows (XCL_HEAP_WINDOWS=1) each memory access was guarded by
`[branch] if (xcl_w >= windows)`. The guard gives every access two paths,
and DXC's GVN can join their descriptor handles into a `phi` of
`%dx.types.Handle`; NVIDIA refused such programs with E_OUTOFMEMORY in
under a second (xcl-dev#756). Nothing in the form prevented it.

Now the index is clamped instead: `min(xcl_w, 16)` with all heap windows
in use, or a `select` with fewer, into ResourceDescriptorHeap. Slot
MEM_HEAP_NULL = MEM_HEAP_BASE + MAX_HEAP_WINDOWS, after the window views,
holds a null raw UAV: it reads 0 and drops stores and atomics, which is
what the switch's `default` does. One path per access, so no handle `phi`
can form. The shared heap's own allocations start after it.

Heap views also need D3D12_OPTIONS11's
AtomicInt64OnDescriptorHeapResourceSupported, for the 64-bit atomics on
the windows; a device without it gets no views, and the shaders keep the
switch over the root UAVs (window_views_failed).

Rebased onto main with xcl-dev#1992 and xcl-dev#1998 (16 heap windows, expanded-window
checks) by WebIdentity1's integration: the null view at
MEM_HEAP_BASE + MAX_HEAP_WINDOWS rather than + MAX_WINDOWS, which would
clamp valid higher windows; the window tests cover 4 / 8 / 16 layouts.

Co-authored-by: WebIdentity1 <212448219+WebIdentity1@users.noreply.github.com>
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.

5 participants