Skip to content

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

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

KDenKC wants to merge 2 commits 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.

Stacked on #3349: the branch is main 1c8b5514 + #3349's commit unchanged (42bd1090, Kalmarv) + this PR's commit 87c10e69; only the top commit belongs here.

It 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, 87c10e69: the fixes and their tests)

  • 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/lower_mem.rs scalar_flat_read (the flat s_buffer_load path from Recompiler: direct DXIL CS/MS IR cuts (rodata skip, scalar/flat windows, wave64 mask elision, sampler waterfall) #3500) and gpu/dxil/lower_window.rs high_one_slot (the carry case's slot for a high dword of one): an address outside the windows takes MEM_NULL_LOAD too, not window 0 (bmjask's review). The scalar read's dwords stay masked as before.
  • Tests:
    • gpu/dxil/core_tests.rs raw_loads_in_root_windows_are_branchless: the flat form selects the null-load view, and a program of one s_buffer_load alone does too (that part fails without the scalar_flat_read change).
    • gpu/dxil/module/opt.rs the_flat_read_carry_rewrite_keeps_the_null_select: the optimizer's FlatRead carry rewrite turns the read's bounds test and slot into carry selects and leaves its null select in place (Foniass's review).
  • Rebased onto main 1c8b551, stacked on D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349. Before that, on 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 87c10e69 (main 1c8b5514 + D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349's commit + this commit):
    • cargo test --workspace --no-fail-fast -- --test-threads=4: 2903 passed, 5 failed, 51 ignored. The 5 fail on main 1c8b5514 too: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, the 3 stream_recheck_* tests, and e2e test_title_runs_and_game_folder_is_untouched. SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no debug layer, 1 driver cache cannot be disabled). The run leaves out the 3 uma_driver tests, as every run on this VM.
    • The scalar test, red without the scalar_flat_read change (the test commit alone on main 1c8b5514): scalar flat heap reads must select the null-load view (descriptor 20), test result: FAILED. 0 passed; 1 failed; green with it: test result: ok. 1 passed; 0 failed.
    • -- the_flat_read_carry_rewrite_keeps_the_null_select: 1 passed, 0 failed.
  • Earlier head 2d3e3fe1 (main d52ff48c + the first fix), same machine:
    • 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, 600 s each, JIT (XCL_PREPARE=0), seeded profile and held Enter. The main block is reused from the earlier gate-batch-t pair and was validated against the full main SHA and network line. Heap windows were on, but XCL_HEAP_FLAT was unset, so this smoke checks the default path rather than the opt-in path changed here. Head frames are 114% of main and peak commit is 102.2% of main; both are within the smoke limits.

main 1c8b5514 (reused block):

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

#3486 head 87c10e69:

xcl-smoke v1
commit: 87c10e692424c5f212cadb99b88df0fb6b3f5e14
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1962 (PresentX 1963)
presents per 2 s (last 3): 2 2 2
device removals: 0
crashes: 0
peak commit: 48639 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.
  • A smoke pair with XCL_HEAP_FLAT=1 at this head.

AI use

  • Claude Code (Claude Opus 5.5, Claude Sonnet 5.5), Codex (GPT-6.2-Sol), Antigravity (Gemini 4 Neon, Gemini 4 Hydrogen): an agent swarm wrote, tested, reviewed and described this change.

🤖 Generated with Claude Code

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

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
Collaborator

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

@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 2d3e3fe1: 2 finding(s). 1 are inline. These are on lines outside the diff:

crates/xcl/src/gpu/dxil/lower_mem.rs:1191: scalar_flat_read, the flat s_buffer_load path from #3500, still computes slot = sel(valid, w, 0) + MEM_HEAP_BASE, so an out-of-window access still reads window 0's descriptor, the root cause this PR fixes in with_mem_i32s. Under XCL_HEAP_FLAT=1, an s_buffer_load whose V# high word is outside the windows still runs rawBufferLoad on window 0 (only masked afterwards by lim = 0). raw_loads_in_root_windows_are_branchless includes S_BUFFER_LOAD_DWORDX4 and still passes because it only checks that some select uses , i32 20. high_one_slot (lower_window.rs:170) has the same window-0 fallback, so a shared heap_load_slot(ok, w) returning sel(ok, w + MEM_HEAP_BASE, MEM_NULL_LOAD) used at all three sites would fix them together.


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.

if let (Some((hi, (valid1, slot1))), Value::Inst(test), Value::Inst(slot)) = (carry_case, inside, i) {
self.s.m.flat_reads.push(super::module::FlatRead { hi, test, slot, valid1, slot1 });
}
let null = self.c(crate::gpu::recomp::MEM_NULL_LOAD);

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.

Flat reads now index MEM_NULL_LOAD (descriptor 20) as a RWByteAddressBuffer, but on main that slot holds a Texture2D null SRV. console_heap::shared_heap runs null_window_views (line 503) before fill_nulls(MEM_HEAP_BASE..cap) (line 511), which copies an even-index Texture2D SRV over slot 20. That ordering is fixed in #3349, which is still open, and this branch isn't stacked on it. If this merges first, with XCL_HEAP_FLAT=1 and heap windows on, any lane with VAR_WIN >= mems.len() or a false EXEC/num_records guard creates a raw-buffer UAV handle from a Texture2D SRV descriptor. That descriptor-type mismatch is undefined: garbage reads, a GBV error, or device removal. The regression run at 2d3e3fe had XCL_HEAP_FLAT unset, so this path wasn't exercised. Stacking on #3349, or including its 3-line reorder here, would make it safe to merge alone.

@KDenKC
KDenKC force-pushed the fix/heap-flat-null-view branch from 2d3e3fe to df2d4d0 Compare December 2, 2026 09:55
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head df2d4d0, since 2d3e3fe, diff read, not a merge-check; checks red):

New:

  • The smoke block is stale. The PR's xcl-smoke block names 2d3e3fe1, not the head df2d4d0f (the reason PR description is red).
  • The description does not cover the scalar change. df2d4d0f also changes scalar_flat_read (lower_mem.rs ~1191-1198) and adds a scalar test, but What is in it lists only with_mem_i32s and every Tested result is at 2d3e3fe1, before it.

Fine: the null select comes after the descriptor-index add, so after the carry rewrite a lane with no valid window still gets MEM_NULL_LOAD and the window-0 fallback in high_one_slot can no longer be reached; values are still masked; opt-in (XCL_HEAP_FLAT); the scalar test reaches scalar_flat_read.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Pipodi

Pipodi commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: df2d4d0
merge: clean (merge commit d5e88baec8118dc557a45f3145ca87b438075968)
build: cargo build --workspace -> ok (and cargo build --release -p xcl -> ok)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 0 failed, 51 ignored; failing: none. 25 SKIPPED lines (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). raw_loads_in_root_windows_are_branchless runs and passes; with the base's lower_mem.rs it fails at core_tests.rs:1503 (vector flat read), and with only the scalar_flat_read hunk reverted it fails at core_tests.rs:1549 (scalar flat read), so both new assertions catch their half of the change.
review:

  • Merge order (blocking): on this base MEM_NULL_LOAD (descriptor 20) is not a raw buffer UAV. console_heap::shared_heap writes null_window_views (console_heap.rs:503) and then fill_nulls(MEM_HEAP_BASE..cap) (:511) copies the null block over it; 20 is even, so it ends up a Texture2D null SRV (null_views_in, :555-562). With XCL_HEAP_FLAT=1, every lane outside the windows or under a false guard now binds that descriptor as a raw UAV, where before it read window 0 at a bounds-checked address and the value was masked to 0 anyway. The description says it depends on D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349 (still open), but the PR is not stacked on it and merges into main alone. It has to land after D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349.
  • Correct otherwise: only loads take this path (with_mem_i32s callers: buffer loads in lower_mem.rs:337, image/BVH loads in lower_image.rs:176/285); stores and atomics keep the guarded with_mem_many_tys form. The null select sits after the descriptor-index add, so opt.rs 1424-1441 can rewrite test/slot for the high-dword carry and a lane with no valid window still gets MEM_NULL_LOAD; ok is inside there (the carry case requires no guard). high_one_slot's window-0 fallback is no longer reachable. Values stay masked to 0.
  • Test gap (minor): the test checks only that a select ... i32 20 exists in the disassembly, not that the carry-rewritten form (FlatRead) keeps it.
  • Scope: 34 lines, one commit, opt-in path only. The PR description still lists only with_mem_i32s and has test results and a smoke block from 2d3e3fe1, not from this head (PR description check is red).
    performance: XCL_HEAP_FLAT is off by default, so the default path is unchanged. The flat path gains one select per read. Smoke pair on the retail title, 60 s, same scripted presses on both sides, one untimed warm-up run before each: main 1611 frames, peak commit 19846 MB; merge 1600 frames (99.3 %), 20310 MB (102.3 %); 0 device removals and 0 crashes on both. The smoke runs do not set XCL_HEAP_FLAT, so they do not reach the changed code.

main (base):

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 PR merged into base:

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

verdict: not yet: merge after #3349 (on main today MEM_NULL_LOAD is a Texture2D null SRV, so the flat path would bind it as a raw UAV); rebase or stack on it and the rest holds
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 suite, release smoke. Claude Code, Claude Opus 5.5 (ran the merge, build, suite, revert test and smoke pair, and wrote this check).

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@Pipodi thanks for picking this up; a heads-up so your merge-check isn't wasted: a new head is coming shortly. It adds bmjask's last point (high_one_slot also takes the null view), a test for the FlatRead carry rewrite that Foniass asked for, and it will be stacked on #3349 (which provides the raw-UAV null view this PR relies on). I'll post here the moment it's pushed.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

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. The scalar flat read (s_buffer_load in the
flat form, `scalar_flat_read`) picked window 0 the same way for an
address outside the windows; it takes the null view too (its dwords
were and are masked as well), and so does the carry case's slot for a
high dword of one (`high_one_slot`).

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, and, for a program of one s_buffer_load alone,
that the scalar flat read does (it fails without the scalar change).
the_flat_read_carry_rewrite_keeps_the_null_select (module/opt.rs) checks
that the optimizer's FlatRead carry rewrite turns the read's bounds test
and slot into carry selects and leaves its null select in place.

Stacked on xcl-dev#3349: MEM_NULL_LOAD is only the null view once xcl-dev#3349 writes
it after fill_nulls in shared_heap; before that, descriptor 20 holds a
Texture2D null SRV.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KDenKC
KDenKC force-pushed the fix/heap-flat-null-view branch from df2d4d0 to 87c10e6 Compare December 2, 2026 10:51
@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@Pipodi the new head is pushed: 87c10e69, stacked on #3349 (main 1c8b5514 + #3349's commit unchanged + this PR's one commit). Since df2d4d0f: high_one_slot also takes the null view, and a test for the FlatRead carry rewrite (the_flat_read_carry_rewrite_keeps_the_null_select). Whole suite at 87c10e69 on an RTX 3090: 2903 passed, 5 failed (the same 5 as main), 51 ignored, 28 SKIPPED. The description and a new smoke pair follow.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@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 and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 87c10e6, since df2d4d0, diff read, not a merge-check; checks red):

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@Pipodi @Foniass New head 87c10e69 (stacked on #3349) has its regression pair: 600 s smoke on an RTX 5090, main 1c8b5514 1724 frames, 0 removals, 47581 MB peak commit; 87c10e69 1962 frames, 0 removals, 48639 MB. Both blocks are in the description's Regression run, and the whole suite at 87c10e69 on an RTX 3090 is 2903 passed, 5 failed (the same 5 as main), 51 ignored.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@Pipodi

Pipodi commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 1c8b551
head: 87c10e6
merge: clean (merge commit be998edb2b43389df9d7c753461e62c7fa913dd1). The PR is stacked on #3349 (still open), so this merge brings #3349's commit too: 42bd109 here has the same git patch-id --stable as #3349's head 5dc64ea. Merging #3349 first and then this PR is also clean and gives the identical tree (0-line diff against be998edb).
build: cargo build --workspace -> ok (and cargo build --release -p xcl -> ok)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2908 passed, 3 failed, 51 ignored; failing: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels (title_textures.rs:6368, "superseded unaligned extra_pages must be reclaimed immediately"), and stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload and stream_recheck_schedule_catches_late_writes_and_resets_milestones (PoisonError after the first one). They are flaky and fail on the base too: cargo test -p xcl --lib title_textures, run 3 times on each side: the merge passed 3/3 (65 passed); the base 1c8b551 failed run 1 (the same placed_... and stream_recheck_schedule_...) and passed runs 2 and 3. This PR touches none of that code. 25 SKIPPED lines (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache). raw_loads_in_root_windows_are_branchless, the_flat_read_carry_rewrite_keeps_the_null_select and #3349's shared_heap_preserves_null_window_raw_uavs run and pass.
Reverting fixes, with the tests kept: base lower_mem.rs -> raw_loads_... fails at core_tests.rs:1503 (vector flat read); only the scalar_flat_read hunk reverted -> fails at :1549 (scalar flat read). Both earlier results hold. The new the_flat_read_carry_rewrite_keeps_the_null_select still passes with the base lower_mem.rs and lower_window.rs together (no recompiler change at all): it builds its IR by hand and checks the unchanged opt.rs rewrite, so it locks that behaviour in rather than failing without this PR. Reverting only the lower_window.rs hunk (high_one_slot) passes every test.
review:

  • The merge-order point from my check on df2d4d0 is resolved: the merge result now has D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349's fix, so MEM_NULL_LOAD is a raw buffer UAV when the flat path binds it. Whoever merges should either merge D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349 first (then this PR adds only its own commit, see merge:) or close D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349 as included here; both give the same tree.
  • New since df2d4d0: high_one_slot (lower_window.rs) falls back to MEM_NULL_LOAD instead of window 0. This is correct but no test catches it, and on the flat-read path it cannot be reached. Its only user is the FlatRead carry rewrite: the slot becomes carry ? slot1 : window 0 and the read's test carry ? valid1 : true, and the null select on top already picks MEM_NULL_LOAD whenever valid1 is false. That makes it consistency only, which is how the commit message presents it.
  • Test (minor): see tests:. The new carry test is a guard on the optimizer and does not fail without the change. The vector and scalar assertions in raw_loads_... are the ones that fail without it.
  • The rest of the diff is unchanged from df2d4d0 and still holds: only loads take the flat path, stores and atomics keep the guarded form, and values stay masked to 0. I read the whole diff (lower_mem.rs, lower_window.rs, core_tests.rs, module/opt.rs, and D3D12.X: write MEM_NULL_LOAD/MEM_NULL_STORE raw UAVs after fill_nulls in shared_heap #3349's console_heap.rs change and test).
    performance: no cost by default: XCL_HEAP_FLAT (and XCL_HEAP_WINDOWS) are off, so the default path is unchanged. The flat path gains one select per read. Smoke pair on the retail title, 60 s, same scripted presses on both sides, one untimed warm-up run before each: main 1611 frames, peak commit 19846 MB; merge 1598 frames (99.2 %), 19965 MB (100.6 %); 0 device removals and 0 crashes on both. Those runs do not reach the changed code.
    Extra, not a regression pair: one more run of the merge with XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1 (same 60 s and presses, warm-up first). The log confirms heap windows were on ("memory windows from the shared descriptor heap"); XCL_HEAP_FLAT came from the same environment but the log does not print it. It showed 1347 frames, peak commit 21980 MB, 0 device removals, 0 crashes. It is not comparable to the default runs: a different shader key set.

main (base):

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 PR merged into base:

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

extra, this PR merged into base with XCL_HEAP_WINDOWS=1 XCL_HEAP_FLAT=1:

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

verdict: safe to merge (it lands #3349's commit too: merge #3349 first or close it as included)
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 suite, release smoke. Claude Code, Claude Opus 5.5 (ran the merge, build, suite, reruns, revert tests and smoke runs, and wrote this check).

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 2, 2026
@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: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) needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants