Skip to content

Recompiler: heap-window shaders reach all 16 window slots of the heap - #3096

Closed
CharlyRien wants to merge 3 commits into
xcl-dev:mainfrom
CharlyRien:pr/heap-window-slots
Closed

CharlyRien wants to merge 3 commits into
xcl-dev:mainfrom
CharlyRien:pr/heap-window-slots

Conversation

@CharlyRien

@CharlyRien CharlyRien commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

With XCL_HEAP_WINDOWS=1 a translated program takes memory window k from descriptor MEM_HEAP_BASE + k of the shared heap. The heap already reserves 16 window slots (MAX_HEAP_WINDOWS), but both translators stop at the unified block's own window count, and only the layout's windows are written.

This PR lets a heap-window program select all 16 slots, and gives the slots past the layout's windows null views. Nothing changes for a title: an address outside the windows still reads 0 and drops its writes. It prepares for memory that XCL maps into those slots later, without translating the shaders again. That is the next PR, the title's GPU-view memory (#3097), stacked on this one.

Still not on main 7a649b0: lower_mem.rs bounds the window index by self.mems.len(), set_window_views writes windows.len().max(MAX_WINDOWS) views, and runner::run_in_region clamps to the arena's windows. #1695 and #2427 (both open, both conflicting with main) change the same accessors to drop the guard; neither raises the bound to the 16 slots.

What is in it

First commit (@MacieGx's, ported from his tree onto current main):

  • crates/xcl/src/gpu/recomp/emit.rs: the heap accessors test the window index against 16, not against the program's window count. Out-of-window accesses go to the null descriptors (MEM_NULL_LOAD / MEM_NULL_STORE); the bound sits before that select.
  • crates/xcl/src/gpu/dxil/lower_mem.rs: the same bound on the direct path (heap_window_bound), including the direct flat-heap path.
  • crates/xcl/src/gpu/dxil/kernel.rs: TRANSLATOR_VERSION goes from 12 to 13.
  • crates/xcl/src/hle/d3d12x/console_heap.rs: main already gives a (0, 0) window and the slots up to 4 null views; set_window_views now writes null raw UAVs up to all 16 slots. The completeness rule still follows the layout.
  • crates/xcl/src/gpu/recomp/runner.rs: the test runner's heap (run_in_region) does the same.
  • Tests:
    • the HLSL bound with 2, 4, 8 and 16 windows, and without heap windows;
    • the direct bound;
    • the null views that set_window_views makes for 1, 8 and 16 windows.

Second commit (from an independent review):

  • runner.rs (dispatch_with, the backend-hook pipelines of gpu_compute_e2e): heap slots 0..3 stay views of mem, as the root form's four windows, and the slots past them are null views, as run_in_region and the runtime.
  • The test of the case without heap windows checks the switch over the program's own windows (case 1 present, case 2 absent, no descriptor heap), instead of an assertion that held by construction.

Third commit (found by the full suite on an earlier head): gpu::uma::tests::expanded_heap_window_shaders_translate_and_validate asserted the old bound (the program's 8 windows); it now checks the 16-slot bound.

8 files, +88 / −18 for the three commits. The translator identity changes (the HLSL text and the direct translator's version), so every shader is translated once more.

Tested

  • Head 370e1c7 on main 7a649b0 (rebased 29/11, no conflict). RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631; Rust 1.100.0, release tests.
  • Measured on this head, CPU only (XCL_ADAPTER=warp, so the GPU tests run on WARP or skip; XCL_REQUIRE_GPU unset; the tests that open the hardware adapter whatever XCL_ADAPTER says left out with --skip):
    • cargo test --release -p xcl --lib -- gpu::dxil::core_tests gpu::recomp::heap_window_tests gpu::uma::tests hle::d3d12x::console_heap::tests shaders::pipeline_library::tests shaders::warm_library::tests --test-threads=4: 79 passed, 7 failed, 1 ignored; 14 of the passes are GPU tests that skipped. The 7 failures are 6 shaders::pipeline_library::tests and shaders::warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable: CreateComputePipelineState returns E_INVALIDARG on this machine's WARP, which has no SM 6.6 (the other 6 then fail on the poisoned lock or the same error). That is a local artefact of a WARP run here, not the CI failure (an entry count, 3 against 2). This PR's tests passed: heap_windows_select_every_heap_slot (HLSL and direct), expanded_heap_window_shaders_translate_and_validate, the 22 console_heap tests run; its GPU tests (gpu_heap_windows_*) skipped ("no GPU").
    • The same filters on main 7a649b0: the same 7 failures with the same errors, nothing else failed (408 passed, 7 failed, 19 ignored for the union of the filters of our five PRs).
    • The build has the same 18 compiler warnings as main 7a649b0 (no new one).
  • Read, CI: the last "Build and test (Windows, no GPU)" failure on this PR (head 03580be) was 4 tests outside it: shaders::pipeline_library::tests::{builder_deduplicates_names_and_atomically_replaces_output, graphics_pipeline_round_trips_through_serialized_library, mesh_pipeline_round_trips_through_serialized_library} and shaders::warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable. main's own CI failed the same 4 on 227d2cb (run 46201186646); they passed on main fa20459, d8bd9a3 and 7a649b0. main 7a649b0's CI fails 8 other tests, all in hle::d3d12x::title_textures::tests (run 46261846646): a red Build and test on this head with those 8 is main's.
  • Not rerun on this head (GPU and title runs): the earlier results below are of head 8956fb4 on main e429936.
    • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug, same machine): 2128 passed, 9 failed, 48 ignored. The 9 are the 9 tests main e429936 itself failed on a GPU, the same names as in this report on an RTX 4080. The tests this PR adds or changes passed, among them gpu_heap_windows_reject_out_of_uma_aliasing and gpu_heap_windows_divergent_lanes_match_switch_form, which read window 4 of a 2-window arena through a null slot.
    • Tested elsewhere (reports in this thread, not our runs): Aniseto, RTX 5070 Ti 16 GB, head 8956fb4d: heap_windows_select_every_heap_slot, "2 passed; 0 failed"; JJAutoCompare, Ryzen 7 3800X, head ba92a2a8: three CPU tests of this PR, 3 passed.

Regression run
Not made on this head yet: the pair below is of main e429936 and the earlier head 8956fb4, so the "PR description" check stays red until a scripts/smoke.ps1 pair of this head is added. It stays a draft.

Earlier pair: same machine, same title, 200 s, the same scripted A presses (XCL_PRESS_A_AT), XCL_PREPARE=0, no XCL_* switch set (so the root-UAV form, not the heap windows), both through main's scripts/smoke.ps1.

main:

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 2442 (PresentX 2442)
presents per 2 s (last 3): 1 1 1
device removals: 0
crashes: 0
peak commit: 31737 MB

earlier head 8956fb4:

xcl-smoke v1
commit: 8956fb4df1de19a6a06dd2839b616f244313e9fe
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1853 (PresentX 1854)
presents per 2 s (last 3): 8 8 5
device removals: 0
crashes: 0
peak commit: 31959 MB
  • Measured: no device removal and no crash; the head's frames are 75.9 % of main's, under CONTRIBUTING's 80 %. Presents per 25 s: main 603 / 510 / 693 / 401 / 64 / 78 / 53 / 39, the head 376 / 616 / 543 / 68 / 67 / 81 / 45 / 54; in the world (100–200 s) the head presented 247 frames and main 235. main's own 200 s runs on this machine gave 1,723 (6089122), then 1,908, 2,442 and 1,744 frames (three runs of e429936).
  • Read: the last 2 s slice at 60 frames a second (menu screens before the title loads) ends at 69 s on the head and at 83 s on main.
  • Deduced: with this switch off the changed code is not on the title's path, so this pair does not show a slowdown of the PR; it does not show its absence either.

Not tested

  • A title run of this head, and one with XCL_HEAP_WINDOWS=1 (the regression pair runs the default, root-UAV form). The stacked D3D12.X: XCL_VIEW_MEM=1 maps the title's GPU-view memory into heap windows 4..15 #3097 ran one with XCL_HEAP_WINDOWS=1 on an earlier head.
  • The GPU tests on this head (the run above is CPU only).
  • AMD and Intel GPUs. By the D3D12 spec, a null UAV reads 0 and an atomic on it returns 0; that was only checked on this NVIDIA card, on the earlier head.

Testing on other setups is welcome. So far this has only run on one RTX 3090 (Resizable BAR off). Results from AMD and Intel GPUs, other NVIDIA generations, or Resizable BAR on would help most. The suite plus a scripts/smoke.ps1 block, as a comment here, is enough.

AI use
AI use: the port of the first commit onto main (with the null views and the tests), the review fixes, the rebases, the test runs and this description were done with Claude Code (Claude Opus 5.5), checked by me.

🤖 Generated with Claude Code

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean ba92a2a893f9a8ced71bb4a1060b59f2bca94571 on Windows 11 x64 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC debug. I reran the pinned stock libtest with <libtest.exe> --exact <test> --nocapture for each of these CPU tests.

  • gpu::recomp::heap_window_tests::heap_windows_select_every_heap_slot checked the emitted HLSL 16-slot guards for 2, 4, 8, and 16 heap windows. The two-window root-UAV switch included case 1u: return mem1. and omitted both case 2u: and ResourceDescriptorHeap[.
  • gpu::dxil::core_tests::heap_windows_select_every_heap_slot checked that the direct-DXIL bound helper returns 16 for 2, 3, 4, 8, and 16 unified windows.
  • hle::d3d12x::console_heap::tests::window_views_do_not_hold_global_during_device_calls checked descriptor initialization with 15, 8, and 0 null views for 1, 8, and 16 windows. The mock device callbacks verified the global heap mutex was available.

3 passed, 0 failed, 0 ignored, 0 runtime skips. Each process exited 0 with 2,030 tests filtered out.

Not tested

GPU workloads, full DXIL emission and validation, the benchmark, the base revision, the #3097 stack, retail titles, or the full suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified the stock executable, reran the tests and wrote this report.

@Aniseto

Aniseto commented Nov 28, 2026

Copy link
Copy Markdown

Ran the all-window-slot test at 8956fb4d on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib heap_windows_select_every_heap_slot -- --test-threads=1
2 passed; 0 failed; 0 ignored; 0 measured; 2029 filtered out      (exit 0)

Both matching tests pass, covering the 16-slot heap-window bound in the expanded layout. They are translation-level tests; I did not enable XCL_HEAP_WINDOWS=1 in a real session. The thread has one other test report but no 5070 Ti, so this adds a second Blackwell datapoint with driver 32.0.16.2124.

Not tested: a real session with XCL_HEAP_WINDOWS=1, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@CharlyRien

Copy link
Copy Markdown
Contributor Author

@Aniseto thanks for running the slot-bound tests on 8956fb4d on a 5070 Ti; I added your result to the description under "Tested elsewhere", as the two translation-level tests it is. If you have the time, a scripts/smoke.ps1 block from that card (this head and a main commit, same title and length) would be the first one from another machine.

AI use: Claude Code, model Claude Opus 5.5, read the thread and wrote this reply.

@Anon64

Anon64 commented Nov 28, 2026

Copy link
Copy Markdown

Second-machine smoke pair (RTX 3060 12 GB) for #3097's head fe2d5b7c, which includes this PR, against main b937fbab: comment on #3097. 100.2 % of main's frames, 98.9 % of its peak commit, no device removal or crash; XCL_PREPARE=0, default heap windows (the 16-window setup was not exercised).

AI use: Claude Code (Claude Opus 5.5) ran the smoke runs and wrote this note.

@andrewDoing

Copy link
Copy Markdown
Contributor

High-slot execution on the new main integration commit 765b2c5bfff6754e8c9886a73e188a86aca3c64c: I ran a test-only RDNA2 compute fixture on RTX 5070, NVIDIA 616.92, using the production translator and native run_in_arena runner. This tests the heap-window shader behavior discussed here on the integrated baseline; the separate #3097 title-view uploader is absent from this commit.

One 64-lane dispatch spread loads, stores and atomic adds across 16 distinguishable windows. Each had 1 MiB of backing and a different input marker at each lane offset. Lane 63 instead used an out-of-range window whose low four bits match slot 15. Its load and returning atomic read zero and its store left every destination untouched.

Translation path Lane loads correct Store locations checked, including untouched canaries Per-window atomic totals
HLSL + DXC 64/64 1,024/1,024 Four in slots 0–14, three in slot 15
Direct DXIL 64/64 1,024/1,024 Same

This covers divergent shader access and real GPU readback, including slots 8–15. The runner supplied the descriptors; title discovery, sparse uploads, graphics stages and retail smoke were outside this fixture.

AI use: OpenAI Codex adapted the fixture, ran both translations, and prepared this report.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory 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:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 28, 2026
@CharlyRien

Copy link
Copy Markdown
Contributor Author

Rebased on main 7db2f39 (after #3203); head 03580be. Tests (cargo test --release -p xcl --lib, XCL_REQUIRE_GPU=mesh, this PR's modules: heap_window_tests, console_heap, uma::tests, core_tests::heap_windows*): 51 passed, 0 failed. The compiler warnings are the same 18 as main's.

What changed in the rebase:

  • main now gives a (0, 0) window and the slots up to 4 null views itself. set_window_views keeps that and writes null views up to all 16 slots (MAX_HEAP_WINDOWS); the completeness rule still follows the layout. The old "aliases window 0" wording and test are gone.
  • TRANSLATOR_VERSION bump redone: main is at 12, so 12 → 13 (our commit had 9 → 10).
  • The description above still describes the e429936 head; the regression pair there is of 8956fb4.

For comparison, main 7db2f39 itself, run with these filters and those of our other PRs, same setting, has 7 failures, all skips that XCL_REQUIRE_GPU=mesh turns into failures on this card: six lower_dxil::tests::*_on_the_gpu ("…, wave64: no wave64") and bind::tests::two_pass_binds_set_the_shared_view_heap ("no heap windows").

The branch merges with main 227d2cb without conflict (not tested there).

Setup: RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631, Rust 1.100.0, release tests, XCL_REQUIRE_GPU=mesh.

AI use: Claude Code with Claude Opus 5.5 did the rebase, ran the tests and wrote this. The person running these tests asked for it.

@CharlyRien

Copy link
Copy Markdown
Contributor Author

The red "Build and test" on 03580be is the same 4 tests as on #3230, outside this PR: shaders::pipeline_library::tests::{builder_deduplicates_names_and_atomically_replaces_output, graphics_pipeline_round_trips_through_serialized_library, mesh_pipeline_round_trips_through_serialized_library} and shaders::warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable. The first fails on an entry count (3 against 2) and the others on the lock it poisoned: the shared library-builder state that #3221 and #3183 address. The heap-window tests, and the TRANSLATOR_VERSION bump to 13, did not fail. #3097, which carries this PR's three commits, passed the same job. We cannot rerun it from here.

AI use: Claude Code with Claude Opus 5.5 read the CI log and wrote this.

MacieGx and others added 3 commits November 29, 2026 14:27
With XCL_HEAP_WINDOWS=1 a translated program takes memory window k from
descriptor MEM_HEAP_BASE + k of the shared heap, and both translators stop at
the unified block's own window count (an address past it reads 0). The heap
already reserves MAX_HEAP_WINDOWS (16) window slots, but only the layout's
windows are written; the others were never read.

Both translators now let a heap-window program select any of the 16 slots
(HLSL: mem_accessors; direct DXIL: lower_mem::heap_window_bound, translator
version 13), and set_window_views gives every slot past the layout's windows a
null UAV, which reads 0 and drops writes, as the old bound did. The test
runner's heap (run_in_arena) does the same. Nothing changes for a title: an
address outside the windows still reads 0. It lets memory XCL maps into those
slots later (the title's memory outside the unified block) be read without
translating the shaders again.

Main already gives a `(0, 0)` window and the slots up to 4 null views; this
extends that to the 16 slots (set_window_views writes MAX_HEAP_WINDOWS views,
the completeness rule still follows the layout).

Tests: the HLSL bound for 2 / 4 / 8 / 16 windows and without heap windows, the
direct bound, the null views set_window_views makes for 1, 8 and 16 windows.
gpu_heap_windows_reject_out_of_uma_aliasing and
gpu_heap_windows_divergent_lanes_match_switch_form read window 4 of a 2-window
arena: a null slot now.

Ported from the lab tree where MacieGx made the shader side reach the slots past
the unified block (HLSL and direct DXIL).

Co-Authored-By: CharlyRien <9572419+CharlyRien@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- runner::dispatch_with (the backend-hook PSOs of gpu_compute_e2e): heap slots 0..MAX_WINDOWS
  stay views of `mem`, as the root form's four windows, and the slots past them are null views,
  as run_in_arena and the runtime.
- heap_windows_select_every_heap_slot: the case without heap windows now checks the switch over
  the program's own windows (case 1 present, case 2 absent, no descriptor heap), instead of an
  assertion that held by construction.

From an independent review of the PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gpu::uma::tests::expanded_heap_window_shaders_translate_and_validate asserted that the HLSL
heap accessors range-check against the program's own window count (8); with the previous
commits a heap-window program selects every heap window slot, so the bound is 16 for 8 and 16
windows alike. Found by the full suite on this PR's head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
@CharlyRien

Copy link
Copy Markdown
Contributor Author

Rebased on main 7a649b0; head 370e1c7 (no conflict). Measured, CPU only (cargo test --release -p xcl --lib, this PR's modules + the library tests): 79 passed, 7 failed (14 of the passes are skipped GPU tests); heap_windows_select_every_heap_slot, expanded_heap_window_shaders_translate_and_validate and the 22 console_heap tests run passed. The 7 failures are the 6 shaders::pipeline_library::tests and warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable, the same 7 with the same errors on main 7a649b0 here: E_INVALIDARG from CreateComputePipelineState on this machine's WARP (no SM 6.6). Deduced: a local artefact of WARP here, not the CI failure mode. No GPU run on the card, no title run.

Read, CI: the 4 pipeline_library / warm_library failures of our previous CI runs were main's own on 227d2cb (run 46201186646) and passed on main since fa20459; main 7a649b0 now fails 8 hle::d3d12x::title_textures::tests in CI (run 46261846646), so a red Build and test with those 8 is main's. "PR description" stays red only for the xcl-smoke pair of the new head, which needs a title run (not made: CPU only this time).

Description refreshed (Tested, Regression run, AI use).

Stack: RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631; Rust 1.100.0, release tests, XCL_ADAPTER=warp, XCL_REQUIRE_GPU unset.

AI use: rebase, test runs and this comment done with Claude Code (Claude Opus 5.5), checked by me.

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: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:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants