Direct DXIL: memory windows through the descriptor heap (XCL_HEAP_WINDOWS) #1693

Manually merged
github merged 1 commit from gh-pr/1693/head into gh-pr/1693/base 2026-11-26 05:01:51 +00:00
Owner

@⁠bmjask on GitHub · 2026-11-24 19:20 UTC · original
bmjask:dxil/heap-windows → main · +233 −54 · 8 files · 1 commits · merged 2026-11-24 19:43 UTC

Follow-up to #1426.

The direct RDNA2→DXIL translator used to refuse programs that take their memory windows from the descriptor heap (XCL_HEAP_WINDOWS=1, recomp::HEAP_WINDOWS in the window count) and sent them to the HLSL path. With this PR it translates them.

What is in it

  • gpu/dxil/lower_window.rs (new file): window w is a RWByteAddressBuffer from ResourceDescriptorHeap[NonUniformResourceIndex(MEM_HEAP_BASE + w)] (createHandleFromHeap + annotateHandle, globallycoherent in compute mode, like the root windows). It sits behind one w < windows check instead of a switch over the root UAVs u2... A w outside the windows reads 0 and drops its stores and atomics, as the HLSL xcl_m* heap accessors do. All memory accesses (loads, stores, atomics including 64-bit and CAS loops, format and typed buffer loads, SMEM, BVH) go through with_mem, so they all use it. 64-bit atomics on heap handles set AtomicInt64Heap.
  • Window selection now matches the HLSL kernel's window_read / window_write (#1426 still used hi & 3). The window comes from the 64-bit effective address (carry / borrow, V# stride bits masked) minus the UMA base (IO_UMA_BASE_HI). A read with hi == 0 goes to window 0; any other address outside the windows matches none. This applies to the root-UAV form too, so out-of-UMA pointers no longer alias a live window there either.
  • kernel.rs: the refusal is removed; mem_windows() builds the root or heap windows. TRANSLATOR_VERSION goes 4 → 5, so cached direct translations are rebuilt.
  • Small call-site edits in lower_mem.rs / lower_image.rs (window(..) → window_at / buffer_window / flat_window(.., write)), one heap_mem field in Lw, and Shader::heap_raw_buffer_uav.
  • Tests: direct_or passes HEAP_WINDOWS when Options::heap_windows is set. gpu_memory_windows_from_the_heap, gpu_heap_windows_reject_out_of_uma_aliasing and gpu_memory_windows_reject_out_of_uma_aliasing now run through the direct path under XCL_DIRECT_DXIL and are checked on the GPU. The 64-bit atomics test also validates the heap form.

Tested

  • RTX 4090, Windows 11 26200, rustc 1.100.0, debug tests / release smoke.
  • cargo test -p xcl --lib gpu::dxil: 80 passed, 0 failed, 1 ignored.
  • cargo test -p xcl --lib gpu::recomp with XCL_DIRECT_DXIL=1 and =all, each with XCL_HEAP_WINDOWS=0 and =1: 194 passed, 0 failed, 18 ignored in all four. The GPU window tests (gpu_memory_windows_*, gpu_heap_windows_reject_out_of_uma_aliasing, mesh, BVH64) ran on the GPU through the direct path, validator-clean.
  • cargo test --workspace -- --test-threads=4: 858 passed, 0 failed, 42 ignored (SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware – no wave64 path on this adapter; heap_window_out_of_memory_falls_back_to_the_switch_form – no heap windows by default).
  • DXIL size, direct path, root vs heap form: memory_windows_above_4_gib 5608 → 5328 B (−5 %).
  • Title run with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 (PR head, A pressed at 10/15/20/25/30/40 s, 60 s): 1454 frames shown (presents per 2 s at the end 43 46 40), 0 device removals, 0 crashes, peak commit 19441 MB. Fallback counts and PSO times were not collected.

Regression run
Both runs were back to back on a quiet machine, with XCL_PRESS_A_AT=10,15,20,25,30,40 (A pressed at those seconds).

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1451 (PresentX 1451)
presents per 2 s (last 3): 40 39 14
device removals: 0
crashes: 0
peak commit: 21068 MB

PR:

xcl-smoke v1
commit: b5d63226df1fe6044e50054310109f96790b6a3f
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1468 (PresentX 1468)
presents per 2 s (last 3): 42 47 19
device removals: 0
crashes: 0
peak commit: 20203 MB

Not tested

  • Direct-path fallback counts (XCL_DIRECT_DXIL_STATS=1) and PSO build times in the title run.
  • Heap windows on a GPU without wave64 / with only Shader Model 6.6 heap indexing limits other than the 4090's.

AI use

  • Claude Code (Claude Opus 5.5): wrote the implementation and tests, ran the tests and the smoke runs, and wrote this description.

🤖 Generated with Claude Code

**@⁠bmjask** on GitHub · 2026-11-24 19:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1693) `bmjask:dxil/heap-windows` → `main` · +233 −54 · 8 files · 1 commits · merged 2026-11-24 19:43 UTC Follow-up to #1426. The direct RDNA2→DXIL translator used to refuse programs that take their memory windows from the descriptor heap (`XCL_HEAP_WINDOWS=1`, `recomp::HEAP_WINDOWS` in the window count) and sent them to the HLSL path. With this PR it translates them. **What is in it** - `gpu/dxil/lower_window.rs` (new file): window `w` is a `RWByteAddressBuffer` from `ResourceDescriptorHeap[NonUniformResourceIndex(MEM_HEAP_BASE + w)]` (`createHandleFromHeap` + `annotateHandle`, `globallycoherent` in compute mode, like the root windows). It sits behind one `w < windows` check instead of a switch over the root UAVs u2... A `w` outside the windows reads 0 and drops its stores and atomics, as the HLSL `xcl_m*` heap accessors do. All memory accesses (loads, stores, atomics including 64-bit and CAS loops, format and typed buffer loads, SMEM, BVH) go through `with_mem`, so they all use it. 64-bit atomics on heap handles set `AtomicInt64Heap`. - Window selection now matches the HLSL kernel's `window_read` / `window_write` (#1426 still used `hi & 3`). The window comes from the 64-bit effective address (carry / borrow, V# stride bits masked) minus the UMA base (`IO_UMA_BASE_HI`). A read with `hi == 0` goes to window 0; any other address outside the windows matches none. This applies to the root-UAV form too, so out-of-UMA pointers no longer alias a live window there either. - `kernel.rs`: the refusal is removed; `mem_windows()` builds the root or heap windows. `TRANSLATOR_VERSION` goes 4 → 5, so cached direct translations are rebuilt. - Small call-site edits in `lower_mem.rs` / `lower_image.rs` (`window(..)` → `window_at` / `buffer_window` / `flat_window(.., write)`), one `heap_mem` field in `Lw`, and `Shader::heap_raw_buffer_uav`. - Tests: `direct_or` passes `HEAP_WINDOWS` when `Options::heap_windows` is set. `gpu_memory_windows_from_the_heap`, `gpu_heap_windows_reject_out_of_uma_aliasing` and `gpu_memory_windows_reject_out_of_uma_aliasing` now run through the direct path under `XCL_DIRECT_DXIL` and are checked on the GPU. The 64-bit atomics test also validates the heap form. **Tested** - RTX 4090, Windows 11 26200, rustc 1.100.0, debug tests / release smoke. - `cargo test -p xcl --lib gpu::dxil`: 80 passed, 0 failed, 1 ignored. - `cargo test -p xcl --lib gpu::recomp` with `XCL_DIRECT_DXIL=1` and `=all`, each with `XCL_HEAP_WINDOWS=0` and `=1`: 194 passed, 0 failed, 18 ignored in all four. The GPU window tests (`gpu_memory_windows_*`, `gpu_heap_windows_reject_out_of_uma_aliasing`, mesh, BVH64) ran on the GPU through the direct path, validator-clean. - `cargo test --workspace -- --test-threads=4`: 858 passed, 0 failed, 42 ignored (SKIPPED GPU tests: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` – no wave64 path on this adapter; `heap_window_out_of_memory_falls_back_to_the_switch_form` – no heap windows by default). - DXIL size, direct path, root vs heap form: `memory_windows_above_4_gib` 5608 → 5328 B (−5 %). - Title run with `XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1` (PR head, A pressed at 10/15/20/25/30/40 s, 60 s): 1454 frames shown (presents per 2 s at the end 43 46 40), 0 device removals, 0 crashes, peak commit 19441 MB. Fallback counts and PSO times were not collected. **Regression run** Both runs were back to back on a quiet machine, with `XCL_PRESS_A_AT=10,15,20,25,30,40` (A pressed at those seconds). main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 4090 title: game seconds: 60 exit: 0x0 frames shown: 1451 (PresentX 1451) presents per 2 s (last 3): 40 39 14 device removals: 0 crashes: 0 peak commit: 21068 MB ``` PR: ``` xcl-smoke v1 commit: b5d63226df1fe6044e50054310109f96790b6a3f gpu: NVIDIA GeForce RTX 4090 title: game seconds: 60 exit: 0x0 frames shown: 1468 (PresentX 1468) presents per 2 s (last 3): 42 47 19 device removals: 0 crashes: 0 peak commit: 20203 MB ``` **Not tested** - Direct-path fallback counts (`XCL_DIRECT_DXIL_STATS=1`) and PSO build times in the title run. - Heap windows on a GPU without wave64 / with only Shader Model 6.6 heap indexing limits other than the 4090's. **AI use** - Claude Code (Claude Opus 5.5): wrote the implementation and tests, ran the tests and the smoke runs, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The direct translator no longer refuses heap windows: with recomp::HEAP_WINDOWS
in the window count, window w is a RWByteAddressBuffer from
ResourceDescriptorHeap[NonUniformResourceIndex(MEM_HEAP_BASE + w)]
(globallycoherent in compute mode, as the root windows), behind one bounds
check instead of a switch over u2.. root UAVs.

Window selection now matches the HLSL kernel's window_read / window_write:
the 64-bit effective address (carry / borrow, V# stride bits masked) minus
the UMA base; a read with hi == 0 goes to window 0; any other address outside
the windows reads 0 and drops its stores and atomics (root and heap form).

TRANSLATOR_VERSION 5. The heap-window GPU tests run through the direct path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:01:50 +00:00
github manually merged commit b5d63226df into gh-pr/1693/base 2026-11-26 05:01:51 +00:00
Author
Owner

@⁠raylitebull on GitHub · 2026-11-24 19:44 UTC · original

Tested on Windows 11 with an AMD Radeon RX 9070 XT (16191 MiB VRAM, RDNA4, native wave64) on a local merge branch based on c160d86.

Setup & tested configuration

  • Local test branch: c160d86 + #1693 (b5d6322, merged cleanly with zero conflicts) + #1679 (ee85bc2) + #751, #1288, #1005, #1053, #1195, #1529, #1584, #1661 (release build).
  • Flags: XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=1, XCL_NETWORK=0, XCL_SKIP_BINK=1, XCL_MUTE_TTS=1 (300 s run on a newer retail title).

Observed results

  • Exit: 0x0 after full 300.00 s (0 crashes, 0 device removals, 0 OOMs).
  • Frames shown: 1,914 (PresentX 1914; 651 translated PSOs, 19,207 unique shaders).
  • Memory: 25,644 MB peak commit (11,926 MB working set, 13,065 MB process VRAM / 14,515 MB adapter VRAM, 8,791 MB target pages).
  • Streaming & visuals: 75,653 DirectStorage requests (4,201 MB streamed, 2,041 failed); captured 4K loading frames showed clean output with no visual corruption.
  • Merge note for maintainers: #1693 (b5d6322) and #1679 (ee85bc2) have a small 2-line overlap in crates/xcl/src/gpu/dxil/kernel.rs (keeping both || geo.is_some() and the mem_windows(...) call resolves cleanly).

Not tested

  • Cold-cache direct-DXIL shader compilation (dxil_cache logged 1,288 hits / 0 misses / 0 compilations on pre-warmed caches).
  • Standalone #1693 without #1679/bundle PRs, cargo test --workspace, NVIDIA/Intel GPUs, and 3D in-world frames past the 300 s loading carousel.
**@⁠raylitebull** on GitHub · 2026-11-24 19:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/1693#issuecomment-7142528039) Tested on Windows 11 with an AMD Radeon RX 9070 XT (16191 MiB VRAM, RDNA4, native wave64) on a local merge branch based on `c160d86`. **Setup & tested configuration** - Local test branch: `c160d86` + `#1693` (`b5d6322`, merged cleanly with zero conflicts) + `#1679` (`ee85bc2`) + `#751`, `#1288`, `#1005`, `#1053`, `#1195`, `#1529`, `#1584`, `#1661` (release build). - Flags: `XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=1`, `XCL_NETWORK=0`, `XCL_SKIP_BINK=1`, `XCL_MUTE_TTS=1` (300 s run on a newer retail title). **Observed results** - Exit: `0x0` after full `300.00 s` (`0` crashes, `0` device removals, `0` OOMs). - Frames shown: `1,914` (`PresentX 1914`; `651` translated PSOs, `19,207` unique shaders). - Memory: `25,644 MB` peak commit (`11,926 MB` working set, `13,065 MB` process VRAM / `14,515 MB` adapter VRAM, `8,791 MB` target pages). - Streaming & visuals: `75,653` DirectStorage requests (`4,201 MB` streamed, `2,041` failed); captured 4K loading frames showed clean output with no visual corruption. - Merge note for maintainers: `#1693` (`b5d6322`) and `#1679` (`ee85bc2`) have a small 2-line overlap in `crates/xcl/src/gpu/dxil/kernel.rs` (keeping both `|| geo.is_some()` and the `mem_windows(...)` call resolves cleanly). **Not tested** - Cold-cache direct-DXIL shader compilation (`dxil_cache` logged `1,288` hits / `0` misses / `0` compilations on pre-warmed caches). - Standalone `#1693` without `#1679`/bundle PRs, `cargo test --workspace`, NVIDIA/Intel GPUs, and 3D in-world frames past the 300 s loading carousel.
Author
Owner

@⁠thiagocalile on GitHub · 2026-11-24 20:27 UTC · original

Tested commit b5d63226df1fe6044e50054310109f96790b6a3f on an AMD Radeon RX 6600 (RDNA2, native 64-lane waves): all targeted tests passed.

Tested

  • Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver 32.0.21045.29003; XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11, debug build.
  • XCL_ADAPTER=radeon cargo test -p xcl --lib gpu::dxil -- --test-threads=4: 80 passed, 0 failed, 1 ignored (25.1s).
  • XCL_ADAPTER=radeon XCL_HEAP_WINDOWS=1 cargo test -p xcl --test gpu_compute_e2e -- --nocapture: 4 passed, 0 failed, 0 ignored (34.86s).
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 855 passed, 3 failed, 42 ignored (37.83s).
    • The 3 workspace failures are pre-existing on main on this RX 6600 (placed_title_textures_share_vram_and_preserve_pixels: 3D mip subresource mismatch, plus 2 mutex-poison cascades transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory; tracked by #1028).
    • SKIPPED (not counted as coverage): heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows (plus D3D12 debug-layer tests skip because d3d12SDKLayers.dll is not installed).

Not tested

  • Retail title run (scripts/smoke.ps1 — no game executable here), D3D12 debug layer, NVIDIA / Intel GPUs, Linux / Wine.

AI use

  • Antigravity (Gemini 4 Neon) ran the test suites on my RX 6600 and drafted this report; I checked the results before posting.
**@⁠thiagocalile** on GitHub · 2026-11-24 20:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1693#issuecomment-7143567813) Tested commit `b5d63226df1fe6044e50054310109f96790b6a3f` on an AMD Radeon RX 6600 (RDNA2, native 64-lane waves): all targeted tests passed. **Tested** - Hardware: AMD Radeon RX 6600 (8146 MiB VRAM, RDNA2, native wave64 + mesh shaders, driver `32.0.21045.29003`; `XCL_ADAPTER=radeon`), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (`10.0.26200.0`), Rust `1.100.0` (`stable-x86_64-pc-windows-msvc`), DXC `1.8.2502.11`, debug build. - `XCL_ADAPTER=radeon cargo test -p xcl --lib gpu::dxil -- --test-threads=4`: **80 passed, 0 failed, 1 ignored** (`25.1s`). - `XCL_ADAPTER=radeon XCL_HEAP_WINDOWS=1 cargo test -p xcl --test gpu_compute_e2e -- --nocapture`: **4 passed, 0 failed, 0 ignored** (`34.86s`). - `XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4`: **855 passed, 3 failed, 42 ignored** (`37.83s`). - The 3 workspace failures are pre-existing on `main` on this RX 6600 (`placed_title_textures_share_vram_and_preserve_pixels`: 3D mip subresource mismatch, plus 2 mutex-poison cascades `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory`; tracked by #1028). - `SKIPPED` (not counted as coverage): `heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows` (plus D3D12 debug-layer tests skip because `d3d12SDKLayers.dll` is not installed). **Not tested** - Retail title run (`scripts/smoke.ps1` — no game executable here), D3D12 debug layer, NVIDIA / Intel GPUs, Linux / Wine. **AI use** - Antigravity (Gemini 4 Neon) ran the test suites on my RX 6600 and drafted this report; I checked the results before posting.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 22:02 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 22:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/1693#issuecomment-7145727794) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~23 ignored. Thanks!
Author
Owner

@⁠bmjask on GitHub · 2026-11-24 22:06 UTC · original

Thanks @⁠raylitebull (RX 9070 XT, 300 s, plus the kernel.rs merge note with #1679) and @⁠thiagocalile (RX 6600: gpu::dxil 80/0/1, gpu_compute_e2e with heap windows 4/0/0; the 3 workspace failures are the ones tracked in #1028).

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @⁠bmjask.

**@⁠bmjask** on GitHub · 2026-11-24 22:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/1693#issuecomment-7145808686) Thanks @⁠raylitebull (RX 9070 XT, 300 s, plus the `kernel.rs` merge note with #1679) and @⁠thiagocalile (RX 6600: `gpu::dxil` 80/0/1, `gpu_compute_e2e` with heap windows 4/0/0; the 3 workspace failures are the ones tracked in #1028). AI use: Claude Code (Claude Opus 5.5) wrote this comment for @⁠bmjask.
This discussion has been locked. Commenting is limited to contributors.
No description provided.