Skip to content

fix(shader): let each 32-lane half run a register-index waterfall itself - #589

Merged
pragyaangaur merged 3 commits into
pragyaangaur:mainfrom
hackgods:fix/first-lane-index-waterfall
Nov 28, 2026
Merged

pragyaangaur merged 3 commits into
pragyaangaur:mainfrom
hackgods:fix/first-lane-index-waterfall

Conversation

@hackgods

Copy link
Copy Markdown
Contributor

What. 11eeb27c2d15980d has been refused since #522. Our log:

GFX10 code at 0x484: a descriptor's address or format read as data is not supported

Its first-lane reads are the console compiler's register-index waterfall:

loop: v_readfirstlane_b32 s38, v28        ; an index a lane left holds
      v_cmp_eq_u32 s[6:7], s38, v28       ; the lanes holding it
      s_and_saveexec_b64 s[6:7], s[6:7]   ; run just those
      s_mov_b32 m0, s38
      v_movrels_b32 v31, v3               ; (or v_movreld_b32 v3, v29)
      s_xor_b64 exec, exec, s[6:7]        ; drop them
      s_cbranch_execnz loop

The resource tracker proves waterfall loops only at descriptor accesses. So #522's needs_first_lane sent the program to halves for these reads, and halves refused it. Before #522 it translated per host wave.

Why per half is exact here. Each host half visits each of its own lanes once, with m0 that lane's own index. The body only moves and computes that lane's registers. Four values never leave the loop:

  • the read's result;
  • m0;
  • the compare;
  • the saved EXEC.

So the iteration order and count, which differ from the console's, are never seen.

The change. first_lane::index_waterfalls recognises this loop shape, and its reads are made per half like read_alone's. The loop must be:

  • one block, read → v_cmp_eq_u32 of the read with its source → s_and_saveexec_b64 → body → s_xor_b64 exec, exec, saved → s_cbranch_execnz back to the read;
  • a body of only s_mov_b32 m0, read and vector ALU operations that write only VGPRs and read no other lane;
  • such that the read, m0, the compare and the saved mask are read nowhere outside the block.

Before/after. Over the 2,734 compute programs our runs passed:

  • 11eeb27c2d15980d translates again, byte for byte what d8f884e made;
  • no other program translates differently;
  • refused: 68 → 67.

Tests.

  • index_waterfall builds the loop over a per-lane v[3 + ((tid >> 2) & 7)]. a_register_index_waterfall_matches_the_console_on_every_gpu runs it in groups of 64 and 128, with and without v_mbcnt (in halves and not). Every lane gives index * 1000 + tid, as on the console.
  • a_register_index_waterfall_is_made_in_each_half covers both sides. Without v_mbcnt the program needs no halves, and with it it translates in halves. The read still takes halves where:
    • the read's result is read after the loop;
    • the body does scalar work (s_add_u32 s50, s50, 1).
  • the_index_waterfall_programs_are_what_their_comments_say.
  • Under Wine on an M5 Pro the whole victory-shader suite passes: 479 passed, 5 ignored. One of my own structural tests at first assumed the negative variants refuse; corrected, the three waterfall tests pass (3 of 3). Native tests, clippy (x86_64-pc-windows-gnullvm, -D warnings) and cargo xtask policy pass too.

🤖 Generated with Claude Code

pragyaangaur#522 sends a wave64 compute program to halves for any v_readfirstlane_b32
whose value may differ between lanes, and refuses the read where the
halves cannot meet. The console compiler's register-index waterfall is
such a read in a loop:

  loop: v_readfirstlane_b32 s, v       ; an index a lane left holds
        v_cmp_eq_u32 c, s, v           ; the lanes holding it
        s_and_saveexec_b64 m, c        ; run just those
        s_mov_b32 m0, s
        v_movrels_b32 / v_movreld_b32  ; register moves by m0
        s_xor_b64 exec, exec, m        ; drop them
        s_cbranch_execnz loop

The resource tracker proves waterfall loops only at descriptor accesses,
so this one sent 11eeb27c2d15980d to halves, which refused it; its
dispatches have been dropped since pragyaangaur#522.

Each host half runs such a loop exactly by itself: it visits each of its
lanes once, with m0 that lane's own index, and the body only moves and
computes that lane's registers. The read's result, m0, the compare and
the saved EXEC are seen nowhere outside the loop, so the order and number
of the iterations, which differ from the console's, are never seen.
first_lane::index_waterfalls recognises the loop by that shape (a body of
s_mov_b32 m0 and vector ALU operations writing only VGPRs, none reading
another lane), and its reads are made in each half like read_alone's.

11eeb27c2d15980d translates again, byte for byte what d8f884e made. No
other of the title's 2,734 compute programs translates differently.

Tests: the waterfall gives the console's lanes on hardware in groups of
64 and 128, in halves and not; it needs no halves, while with the read's
result seen after the loop, or scalar work in its body, the read still
takes halves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earpjonathan

Copy link
Copy Markdown
Contributor

Checked in game on an M5 Pro (48 GB, macOS 27.0.1, CrossOver 26.3 Wine with the repo's patches, D3DMetal 4.0 beta 3, Series X). For the test I merged this PR locally into main at d1609d9d. Same scripted opening as before, cold then warm, judged on the warm run:

  • 11eeb27c2d15980d translates. The six others (23d507cbb6a22e86, b0095eb50222e808, 7b2c3c1db2298f44, 9991e29feaa26e3e, eeed82b877b44b5f, ef154ebc9e03d1b1) are still refused, as expected. That's 37 refused compute programs in all.
  • The cell is lit. The last six captured world frames have a mean brightness of 45, 43, 49, 54, 54 and 55, against 17, 22, 22, 14, 12 and 12 for build A in my comment on fix(shader): make the first-lane reads #522 refused exactly, and drop #548's per-host-wave fallback #552 (six translated, 11eeb27c2d15980d refused). In the frames the room, the bunks and the characters are lit, in the cold run too.
  • The median frame is 384 ms, against 385 for A and 375 for B.

So this alone brings back most of the cell's light. I'll run the lockstep-loops part the same way when it's up.

Prepared with Claude Code.

@4TheDoctor

Copy link
Copy Markdown
Contributor

Checked in game on an M3 Max too (48 GB, macOS 27.2.1, CrossOver 26.1, D3DMetal 4.0 beta 3, Series X). I built this PR's head 753ca8f7 as is, so the only difference from my dark a31fcca1 run on #552 is this change. VICTORY_GPU_TIMING=0, 720 s, cold then warm.

  • 11eeb27c2d15980d translates and binds. It's the only refusal that changed against a31fcca1. The other first-lane ones are still refused, as on the M5 Pro.
  • The cell is lit again. Median brightness (out of 255) of the captured world frames in the cell: 29 to 34 warm, 28 to 30 cold, against 13 to 15 on a31fcca1 and 29 to 34 on c8e4f326, which drew the cell lit. The player, the bunk and the wall are visible, not a silhouette. (I use the median because the bright window dominates the mean: 51 to 56 here against 41 to 45.)
  • No frame cost I can see: world frame median from 450 s is 579 ms cold and 583 ms warm, against 597 ms for a31fcca1. No hangs and no ended command buffers in either run.
  • The BVH builder is still held back here (53 pipelines, 3 refused), so ray-traced shadows still don't run on this Mac.

Happy to run the lockstep-loops part the same way when it's up.

@earpjonathan

Copy link
Copy Markdown
Contributor

I tested this together with the other six open fixes on an M5 Pro (48 GB, CrossOver 26.3): #593, #605, #606, #608, #592 and #595, all merged onto d1609d9. Only halves_tests.rs conflicted, as 4TheDoctor noted, and keeping both sides was enough. I ran the same silent scripted opening into the cell, 420 s per run, and compared warm runs with a warm d1609d9 run:

  • Refused compute programs: 31, against 38 on d1609d9. The seven that now translate are 11eeb27c2d15980d, ef154ebc9e03d1b1, a1bf269d5b19f025, fdd56d97a806bcca, cbf9b65f2249ba96, 82a2ad6d07417d36 and 90a0692af4320129. None are newly refused.
  • The cell is lit: median luma of the world captures is 55, against 41 on d1609d9.
  • Median world frame: about 390–400 ms. Both builds were in the same range (370–400 ms) in other runs.
  • Four runs of the merged build (two cold, two warm). One warm run crashed early, about 30 frames after the title came up: an access violation inside the Windows heap's free, called from ir::build (ir.rs:180) through pipeline.rs:392 (written_used) on a pipeline-making thread. That points to heap corruption somewhere earlier rather than to that code. It didn't repeat in the other three runs or in three more runs of the same merge with a local change on top. I haven't seen it on any other build, so I can't tell yet whether one of these PRs is involved or whether it's just rare.

With all seven merged, the five first-lane programs from #552 (23d507cb, b0095eb5, 7b2c3c1d, 9991e29f, eeed82b8) are still the main thing missing from the cell's look. Shadows and the luminance pass are cooler and darker without them.

Prepared with Claude Code.

@hackgods

Copy link
Copy Markdown
Contributor Author

Thanks for the combined run. On the one crash, to narrow it down from our side:

A fault inside the heap's free during ir::build points to corruption from earlier in the process, which these wouldn't produce. If it repeats, the faulting address and whether it lies in a page our write tracking had protected would tell a lot. #591 (luminance pair) and our 9991 branch cover three of the five programs you list as still missing.

Claude Code (Claude Opus 5.5).

@earpjonathan

Copy link
Copy Markdown
Contributor

@hackgods Thanks, that rules those out. About the one fault: the faulting write was to address 0xa, inside the heap's free, with the heap base at 0x553a0000 below 4 GiB. So a freed block's links were overwritten, and nothing protected was touched directly. If it happens again, I'll check whether that block lies in or next to a range the title's memory tracking guards.

I'm running #591 on top of the same seven now, without any first-lane fallback, to see which of the five programs it brings back in the cell. I'll post the numbers here or on #591.

Prepared with Claude Code.

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.

4 participants