Repository navigation
fix(shader): make the first-lane reads #522 refused exactly, and drop #548's per-host-wave fallback - #552
Conversation
…st wave's own pragyaangaur#548 lowers a program that halves refuse at a first-lane read (FIRST_ACROSS) once more without pragyaangaur#522's halves trigger, so each 32-lane host wave reads its own first lane. Nothing proves that lane holds the console's value: on the console every lane of a wave64 reads the wave's first active lane, and where the value differs between the halves the upper host wave reads another one. pragyaangaur#548's own test program shows it: v_readfirstlane_b32 s21, v0 counts a loop of v_readfirstlane_b32 s12, v0, and every lane stores s12. The console stores 0 in all 64 lanes of a group of 64 (thread 0 is the wave's first lane). With the fallback, D3DMetal on an M5 Pro stores 32 in lanes 32-63: the upper host wave's first lane is thread 32. So such a read is refused again, as pragyaangaur#522 did. A new GPU test runs the program on every adapter wherever it translates and compares each lane with the console, and pragyaangaur#548's test now asserts the refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lanes see v_readfirstlane_b32 reads a value not proven the same in every lane of the console wave, and refuses such a read where the halves cannot pass values (FIRST_ACROSS). The proof (lane_uniform) counts a guarded VALU write as alike only where no lane can be inactive, since inactive lanes keep the old value. So a read of a value computed under the read's own EXEC is refused in divergent code, though every lane the read can take holds it. In GTA VI that refused 8bb272e763f76148 and 91caf91cfd11d512 (1024 threads, LDS 12 KiB): an integer division by a constant-buffer value, whose reciprocal the console compiler computes in VALU from the scalar divisor and reads from the first lane, inside a v_cmpx region holding a loop, where the halves cannot meet. It translated before pragyaangaur#522 (d8f884e, d2b4889); since 05db3d0 it is refused and its dispatches are dropped. A read is now made by each host half by itself (first_lane::read_alone) where: 1. every instruction that made the value ran under the read's own EXEC value and computed it by plain VALU operations from constants and scalars: root parameters and what scalar loads and scalar ALU operations make of them, never a lane mask or a lane's value; so every lane active at the read holds the same function of the same scalars, which each half computes for itself in any halves translation; 2. only lanes active at the read see the result: every reader of it (or of a scalar made from it) is a scalar ALU operation, held to the same, or a vector instruction writing no scalar register under an EXEC no wider than the read's (compares into EXEC, s_and_saveexec, ANDs, s_andn2 and copies of such masks, and their phis); no branch, scalar memory access, or EXEC, VCC or M0 write takes it; 3. the read is in no cycle. Then a half with an active lane reads the console's value, and a half without one reads a value none of the readers in its lanes runs to see. Such reads no longer put a program in halves, and in halves they read the half's own first active lane with no exchange. Of the 2,734 compute programs in the title's shader pack, two now translate again (8bb272e763f76148's translation is byte for byte what d2b4889 made) and none is newly refused. 144 others translate differently: first-lane reads that pragyaangaur#522 passed between the halves, or put the program in halves for, are now made by each half. b538852f58c99307, in halves since pragyaangaur#522 for one such read (2,693 group barriers), is again what d8f884e made (none); group barriers drop by 4,119 in all. Tests: the read of a scalar-made value in an s_and_saveexec region gives the console's lanes on hardware with the active lanes in the lower half, the upper half (the lower host wave has none), both, or none, with and without halves; read after EXEC is restored it still passes the halves' first lanes between them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A heads-up from an M3 Max (D3DMetal 4.0b3, CrossOver 26.1, Series X). With #548's fallback dropped, six world programs are refused again on main Same recipe for both runs (diagnostics build, no per-list timing, captures at 0 to +400 world frames):
In game on So on a 32-lane host these reads still don't reach the exact path. Could the fallback stay until they do? I can test any variant in game on the M3 Max. |
|
Thanks, that is a clear report, and the dark cell matters more than the speed of any of this. The five programs refused at the first-lane read are the ones #548's fallback translated by reading each 32-lane half's own first lane. In these programs the read value looks alike in every lane, because it is built from scalars: the luminance downsample's loop counter steps on constant-buffer data, and the classifiers' values come from So the fix we are working on makes
We are checking offline which of the five that recovers, then will test them in game on an M5 Pro and open a PR. If you'd rather have the lit picture back on main until that lands, restoring #548's fallback is a single revert of that part of #552. That's your call; we can prepare it either way. Testing variants on your M3 Max once the PR is up would help a lot. Claude Code (Claude Opus 5.5). |
|
Status after checking the six programs offline (translated with main
Claude Code (Claude Opus 5.5). |
|
The same 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), on main
When the per-dispatch PR is up, I'll run it the same way: whether these six translate, the late cell brightness, and the frame time. Prepared with Claude Code. |
|
More on the dark cell: on an M5 Pro it comes mostly from I ran two local builds of
With B the cell interior (the characters, the bunks, the walls) is lit as it was before #522, in the cold run as well as the warm one. So the waterfall rule for Prepared with Claude Code. |
|
Thanks, that is a very useful split. Then The other part is ready too: while-shaped divergent loops in lockstep in halves, which recovers the two luminance downsample programs and four more refused ones exactly, with fewer barriers overall. On our M5 Pro both luminance programs translated in game with it. Results with both on the cell will follow. Claude Code (Claude Opus 5.5). |
…er with halves-once-slots The exchange the group runs once leaves out its leading barrier (VICTORY_HALVES_OWN_WORDS, on by default), so pragyaangaur#552's test expects three more barriers than the read alone with it on and four with it off. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
More data for the lockstep-loops part: the six programs still matter for how the cell looks, even with Two local builds of
The brightness and speed match, but the pictures don't. In the cell at the same moment of both runs, C draws the round table's top almost black, and its walls and characters come out cooler and a little dimmer. B looks as builds from before #522 did. I can't tell from frames which of the six makes the difference. The auto-exposure downsample and the shadow tiles would fit, though. I'll run your lockstep-loops PR the same way and compare these frames. Prepared with Claude Code. |
#548 is not exact
#548 handles a program that halves refuse at a first-lane read (
FIRST_ACROSS) by lowering it again without #522's halves trigger. Each 32-lane host wave then reads its own first lane. On the console, every lane of a wave64 reads the wave's first active lane. The upper host wave's first lane is console lane 32 or later. Wherever the value differs between the halves, the upper half reads something the console never reads.Counterexample: #548's own test program.
in_a_loop(&[v_readfirstlane_b32 s12, v0], 12, Count::FirstLane)without itsv_mbcnt, one group of 64 threads:a_first_lane_read_in_a_loop_matches_the_console_on_every_gpu(new) runs this program on every adapter wherever it translates, and compares each lane with the console. It fails on b407fa0 and passes on this branch.In the game. The programs #548 brings back that we inspected read values made from scalars:
23d507cbb6a22e86andb0095eb50222e808: a cascade loop counter that steps on constant-buffer data.eeed82b877b44b5f: a phi ofs_bferesults across ans_cselectbranch.ef154ebc9e03d1b1: a function ofs43under av_cmpx.8bb272e763f76148: a reciprocal of a constant-buffer divisor.By inspection, every lane that computes one of these values computes it alike. So we found no wrong in-game output from #548. Two cases were not checked:
7b2c3c1db2298f44,9991e29feaa26e3eand the other five, which were not inspected.Nothing in #548 checks any of this. The fallback applies to every program refused at
FIRST_ACROSS, including ones like the test above.The fix
lower_limitedretry andfirst_lane_halvesflag). fix(shader): fall back to the host waves' first lanes where halves refuse a first-lane read #548's test now asserts the refusal, with and withoutv_mbcnt.first_lane::read_alone). This brings back8bb272e763f76148and its twin91caf91cfd11d512exactly. Since fix(shader): fix v_readfirstlane_b32 in branches and empty EXEC on split wave64 (#512) #522, main refused them at 0x1d8:The program is a wave64 compute program with 1024 threads and 12 KiB of LDS. It divides by a constant-buffer value
s21the way the console compiler does, inside av_cmpxregion that also holds a loop, so the halves cannot meet there:lane_uniformcounts a guarded VALU write as alike only where no lane can be inactive, sov2is "maybe different". It is different only in lanes the read never takes.read_aloneproves three things for av_readfirstlane_b32:The value is the same in every lane the read can take. It comes from constants and scalars, by plain VALU operations under the read's own EXEC value. The scalars are root parameters and what
s_load*/s_buffer_load*and scalar ALU operations make of them, never lane masks, SCC or lane reads. Each half computes them for itself, as every halves translation already assumes for every scalar.Only lanes active at the read see the result. Every reader of it, or of a scalar made from it, is one of two things:
s_and_saveexec,s_and_b64/s_andn2_b64of such a mask,s_mov_b64copies and phis.No branch, scalar memory access, or EXEC / VCC / M0 write takes the result.
The read is in no cycle, so its EXEC value is one mask.
So a half with an active lane reads the console's value. A half without one reads a stale lane that none of its lanes ever sees. Such reads no longer put a program in halves. In halves, they read the half's own first active lane (
first_lane_in_wavewith the guard), with no exchange. Every other read is unchanged.The 10 other programs #548 brings back are refused again on this branch, as on #522 (listed below). Bringing them back exactly needs a uniformity proof
lane_uniformdoes not make yet: a loop-carried counter (its fixed point starts from nothing), and scalars froms_buffer_load(it trusts only root parameters).Before/after
Over all 2,734 compute programs the title passed in our runs:
8bb272e763f76148,91caf91cfd11d512b538852f58c99307The 10 programs refused again are the other ones #548's fallback brought back in our shader pack. #548 lists 7, but in ours it brings back 12. The 10 are:
23d507cbb6a22e86,26efd2ba098464bd,7b2c3c1db2298f44,9991e29feaa26e3e,b0095eb50222e808,b05fc3d9cc6f248e,b33d65393cc79e79,e1b8e701f0a02e50,eeed82b877b44b5f,ef154ebc9e03d1b1#522 refused all of them. The 144 programs that translate differently make first-lane reads #522 passed between the halves, or put the program in halves for, in each half instead. Their DXIL shrinks,
b538852f58c99307by 77%. That program is the main part of #522's GPU-time regression (see the issue draft).Tests
first_lane_reads_halves_cannot_pass_are_refused(fix(shader): fall back to the host waves' first lanes where halves refuse a first-lane read #548's test, now asserting the refusal).a_first_lane_read_in_a_loop_matches_the_console_on_every_gpu: fails on b407fa0 (32 of 64 and 64 of 128 lanes differ), passes here (the program is refused).readfirstlane_of_a_scalar_in_branch:s_buffer_load_dword s14, thenv4 = f32(s14) + 1.0andv_readfirstlane_b32 s12, v4in ans_and_saveexecregion with ans_cbranch_execz, thenv2 = s12inside the region (or, in the second variant, after EXEC is restored).a_first_lane_read_only_active_lanes_see_matches_the_console_on_every_gpucovers four cases, with and without halves:Every lane gives what the console gives:
42.0where active, else 0.a_first_lane_read_only_active_lanes_see_is_made_in_each_half: read inside, the program takes no exchange. Read after EXEC is restored, it still passes the halves' first lanes and ballots between them.Under Wine on an M5 Pro (D3DMetal), the whole victory-shader suite passes on this branch: 477 passed, 0 failed, 5 ignored. Native tests, clippy (
x86_64-pc-windows-gnullvm,--all-targets,-D warnings) andcargo xtask policypass.🤖 Generated with Claude Code