Skip to content

Recompiler: flat heap reads outside the windows take the null view - #3486

Open
KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:fix/heap-flat-null-view
Open

KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:fix/heap-flat-null-view

Conversation

@KDenKC

@KDenKC KDenKC commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

With XCL_HEAP_FLAT=1 (heap windows on), the direct DXIL translator reads a compute program's heap memory windows without a branch (2f52333). The access runs for every lane, and a lane outside the windows or under a false guard (a buffer index past num_records, a lane EXEC leaves out) had its value set to zero afterwards. But its access went to window 0's descriptor, at the address it was given. So it read window 0's memory at an address the program never reaches: the guarded form branches around that access, and the HLSL accessors (409cf07) send it to the null view MEM_NULL_LOAD. Now the direct form selects MEM_NULL_LOAD for it too, so it touches no window's memory.

Depends on #3349.

Needs #3349 for the null view to be a buffer: on main, console_heap::shared_heap runs fill_nulls after null_window_views and writes a Texture2D null SRV over MEM_NULL_LOAD, which the HLSL accessors already select today. #3349 writes the raw-UAV null views after fill_nulls. Kalmarv's #2428 (flat heap windows by default on NVIDIA) still has the window-0 select.

Related: #2626 (a compute dispatch's GPU VA 0 fault on the first world frame), #2403, #2088.

What is in it (one commit: the test and the fix)

  • gpu/dxil/lower_mem.rs with_mem_i32s: the flat form selects descriptor MEM_NULL_LOAD instead of window 0 for an access outside the windows or under a false guard. Its callers only load (memory loads and the BVH node loads), so the null load view is the one.
  • gpu/dxil/core_tests.rs raw_loads_in_root_windows_are_branchless: the flat form selects the null-load view.
  • Rebased onto main d52ff48. Recompiler: direct DXIL CS/MS IR cuts (rodata skip, scalar/flat windows, wave64 mask elision, sampler waterfall) #3500 (b5973e3) touched the same lines but did not change this: its flat read still selects window 0 (sel(ok, w, 0)) for an access outside the windows. Its FlatRead record keeps pointing at the descriptor-index add, which its carry rewrite changes; the null select is after that add, and ok is inside (also rewritten), so the carry form keeps the null view too.

Tested

  • NVIDIA GeForce RTX 3090 24 GB (VM), driver 621.24, Intel i7-10700T, Windows 11 build 26300.9974, Rust 1.99.1, debug, at this head 2d3e3fe1 (main d52ff48c + this commit):
    • Red, at 63fbc611 (main d52ff48c + the test only): cargo test -p xcl --lib -- raw_loads_in_root_windows_are_branchless --nocapture --test-threads=1:
      thread 'gpu::dxil::core_tests::raw_loads_in_root_windows_are_branchless' (1360) panicked at crates\xcl\src\gpu\dxil\core_tests.rs:1463:9:
      flat heap reads must select the null-load view (descriptor 20):
      test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 2764 filtered out; finished in 0.24s
      
    • Green, at 2d3e3fe1, the same command:
      test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2764 filtered out; finished in 0.12s
      
    • cargo test --workspace --no-fail-fast -- --test-threads=4 (leaving out the 3 uma_driver tests that need a GPU upload segment this VM has not): 2868 passed, 6 failed, 51 ignored. SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no debug layer, 1 driver cache cannot be disabled). The 6 failures: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, the 3 stream_recheck_* tests, and test_title_runs_and_game_folder_is_untouched.
    • Main d52ff48c on the same machine fails the same tests: gpu_direct_image_get_resinfo_d16, the 3 stream_recheck_* and test_title_runs_and_game_folder_is_untouched. Its parallel run lost the lib binary, so its lib tests come from a one-thread rerun that left out all of uma_driver::tests (2721 passed, 5 failed, 31 ignored); its counts are not comparable to the line above, the failing names are.
  • (the earlier head, before the rebase) RTX 5090 32 GB, driver 621.24, Ryzen 7 9800X3D, the retail title, XCL_HEAP_FLAT=1 with heap windows, the debug layer and DRED on, XCL_PREPARE=0, 200 s. The change is in our integration build of open PRs (93d11d74: the same commit on top of it); the build under it alone (1b108007) is the "before":
    • before (1b108007), the device is removed on the first world frame:
      [   75.235][11864][INFO ] D3D12.X: split command list (type 2) around mid-list Wait after Write64 (#2)
      [   75.654][37400][ERROR] D3D12 device removed: 0x887a0006 The GPU will not respond to more commands, most likely because of an invalid command passed by the calling application.
      [   75.655][37400][ERROR] DRED device state: 7
      [   75.655][37400][ERROR] DRED page fault at GPU VA 0x0 = window 10 + 0x0; allocations there: []; recently freed: []
      
    • with this change (93d11d74), the frame is drawn and the run ends at its timer:
      [   77.993][41660][INFO ] D3D12.X: split command list (type 2) around mid-list Wait after Write64 (#1)
      [   78.554][39156][INFO ] activity (2 s): 1 presents, 34 submits, 4995 draws, 7278 dispatches, 2 frame-event waits (0 timed out), 1 frame statistics (0 not flipped)
      [  201.010][41788][INFO ] process ends (thread 41788)
      19:12:29 pid 28360 exit code 0 (0x00000000)
      device removed lines: 0; DRED lines (past the 'DRED on' start line): 0
      
      The debug layer's other errors in that run: ids 1422, 527, 538 and 1047, 8 each (uninitialized placed targets, barrier states and the sparse queue race, seen before this change too); none of them a device removal.

Regression run
RTX 5090 32 GB, driver 621.40, the retail title, 600 s each, scripts/smoke.ps1 with preparation off (XCL_PREPARE=0), each run starting from its own copy of the same translated cache (made by main). Both runs used this machine's usual settings (XCL_UMA_WINDOWS=16, XCL_UMA_DRIVER=mixed:1536:1792, XCL_COHERENT_MB=4095, XCL_HUGE_PSO_CONCURRENCY=3), XCL_DRED=1, and XCL_SKIP_CS=95cc13288a27a96e (the compute program whose compact form hangs on RTX 50, #3516), left XCL_HEAP_FLAT unset (off, as by default), and held Enter from the first frame (the same input in both).

The pair shows boot and loading with held input and no device removal in either run, and a peak commit at 101.5 % of main's; most of each run is shader compiles with few presents, so its frame counts say nothing about speed.

main 9dfbe3e:

xcl-smoke v1
commit: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 2797 (PresentX 2797)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 46900 MB

this head 2d3e3fe1:

xcl-smoke v1
commit: 2d3e3fe111598096165b7ec2a41e1fcc788cc91d
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 2599 (PresentX 2599)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 47592 MB

Not tested

  • The run above is on our integration build, not on main + this commit alone; the title's first world frame is the only place it was seen.
  • A GPU run that shows the old access fault: the test runner's window buffers return zero out of range, so the difference is only in which descriptor is read (checked in the DXIL).
  • AMD and Intel.

AI use

  • An agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 3.8 Flash (tools: Claude Code, Codex, Antigravity). Claude Opus 5.5 found the bug and wrote the fix and test; Gemini 4 Neon searched for duplicates and the null-view order; Claude Sonnet 5.5 ran the 5090; the swarm ran the tests and wrote this description.

🤖 Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

@github-actions github-actions Bot added 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) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
XCL_HEAP_FLAT=1 reads a compute program's heap memory windows without a
branch (2f52333): the access runs for every lane, and a lane outside the
windows or under a false guard (a buffer index past num_records, an EXEC-
masked lane) had its value set to zero afterwards. But its access went to
window 0's descriptor, at the address it was given, so it read window 0's
memory at an address the program never reaches: the guarded form branches
around it, and the HLSL accessors (409cf07) send it to the null view
MEM_NULL_LOAD. The direct form now selects MEM_NULL_LOAD for it as well,
so it touches no window's memory.

On the RTX 5090, the retail title with XCL_HEAP_FLAT=1 hung on its first
world frame (DRED: a page fault in a compute dispatch); with it off it ran
past 200 s.

Test: raw_loads_in_root_windows_are_branchless checks that the flat form
selects the null-load view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KDenKC
KDenKC force-pushed the fix/heap-flat-null-view branch from b7eeaa8 to 2d3e3fe Compare November 30, 2026 06:39
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@KDenKC
KDenKC marked this pull request as ready for review December 1, 2026 02:40
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: 2d3e3fe
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2896 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 (lower_mem.rs +6/-2, core_tests.rs +3). Nothing changes by default (XCL_HEAP_FLAT is opt-in) and there's no added cost (the select moves after the add). A lane outside the windows, or under a false guard, now reads descriptor MEM_NULL_LOAD instead of window 0's view at its own address; values are still zeroed (sel(ok, v, z), ~431) and every caller only loads. Findings: (1) on main, descriptor 20 isn't a raw UAV yet: shared_heap writes it in null_window_views (console_heap.rs ~503), then fill_nulls (~511) replaces it with a null Texture2D SRV, and set_window_views only rewrites 4..19. Until #3349 is merged, these lanes access a descriptor of the wrong type (undefined; the HLSL accessors already do this today). The PR says it needs #3349 but isn't stacked on it, so it should merge after #3349. (2) The new assertion (core_tests.rs ~1463) only checks that some select ... i32 20 exists; the carry-rewrite form (opt.rs ~1424-1441) is argued, not tested. No smoke run: flat reads are off by default. Fine: in the carry case ok is the rewritten inside and slot is the add it replaces, so the null select still applies, and the test failed before the fix.
performance: no smoke run (the default path doesn't reach this change); not measured.
verdict: safe to merge after #3349 (on its own, the lanes it redirects read a descriptor that isn't a raw UAV yet; that's undefined, but it is opt-in and no worse than the HLSL accessors today)
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
@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

Ran the named raw_loads_in_root_windows_are_branchless test at 2d3e3fe1 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), 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, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu::dxil::core_tests::raw_loads_in_root_windows_are_branchless -- --test-threads=1
1 passed; 0 failed; 0 ignored; 2764 filtered out      (exit 0)

The new test passes at this head; the author's red run without the fix is not repeated here. This adapter is NVIDIA, where the flat heap windows are relevant.

Not tested: the full workspace suite, a GPU run showing the original fault, a title run, XCL_HEAP_FLAT=1 in the world, the dependency on #3349, AMD adapters, Wine, wave64 hosts, release profile, game data.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 2d3e3fe

No open or merged PR makes the same change. Main (after #3500) still has sel(ok, w, 0) in with_mem_i32s, and #2428 keeps the window-0 select.
The null select comes after the descriptor-index add that FlatRead records, so the optimizer's carry rewrite of test/slot still feeds sel(ok, slot, MEM_NULL_LOAD). That looks right.
This depends on #3349 (open): until then main's shared_heap writes a Texture2D null SRV over MEM_NULL_LOAD, and this path would bind that descriptor as a raw buffer UAV. It should merge after #3349, or say so at the top of the description.
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
head: 2d3e3fe

1 similar comment
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: 2d3e3fe

@brainhay5

Copy link
Copy Markdown

merge-check
base: 493dbd3
head: 2d3e3fe
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2899 passed, 1 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) ready-to-merge Has 2 independent safe merge-checks on current head (#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: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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants