Repository navigation
Shaders: scalars leave divergent loops and branches as the wave's last path left them - #269
TheHoracio wants to merge 2 commits into
Conversation
…t path left them The console runs a divergent loop until its last lane leaves, and each path of a divergent branch that some lane takes, with one set of scalar registers. After the loop or the join every lane reads the scalars the last iteration or path left. The lowering ran scalar code per lane, so each lane left with its own path's values: a loop's exit mask or a scalar counter read after the loop came out as 1, 2, 3, ... across a 64-lane wave instead of 64, with no error. For compute programs (their host waves are the console's): - Scalar set operations on lane masks (s_and/or/xor/andn2/orn2/nand/nor/ xnor/not/mov) get their value as a number from their sources' numbers, instead of stopping with "a lane mask read as data". A mask grown inside a branch no longer stops with "a lane mask holding lanes elsewhere read as data". - Entering the single exit block of a loop, the scalars the loop wrote and code after it reads take the value of the lanes with the highest iteration count (the loop counters LOOP_LIMIT already keeps). - Entering a join that is not a loop header, its scalar phis take the value of the lanes that came the latest path in code order. Pixel, vertex and mesh programs are unchanged: their host waves need not be the console's, so a host wave's value could mix console waves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inner loop's exit runs inside the outer loop's body, and the outer loop's next iteration reads the inner loop's final value through its header phi. On main each lane reads its own outer times inner count (1, 2, ... 16); with the loop exit values every lane reads the wave's 16. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Test report on NVIDIA, which the description lists as not tested: the four new tests fail on a 32-lane host. Tested
The two wrong-value results are what each 32-lane half would count on its own: lanes 0-31 loop at most 32 times (and at most 2 inner x 4 outer = 8 in the nested test), lanes 32-63 at most 64 (4 x 4 = 16). So the 64-thread group runs here as two host waves that each stop at their own last lane. For the two pipeline failures I have only a guess, not checked: both programs count a 64-bit mask with Two of the tests also Not tested
Follow-up: together with #233 (same machine, local only)
So on a 32-lane host the split in #233 does not by itself give the scalar-in-a-divergent-loop result this PR checks: those two programs read no other lane, so they are split in halves and each half stops at its own last lane. That experiment is my change to the test helper, not part of either PR.
|
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
A result from an AMD GPU that forms 32-lane waves, following the NVIDIA report above. Tested
So it is not only hosts without 64-lane waves: this Radeon driver runs a compute shader that declares no wave size in waves of 32 although it offers 64 (the RX 7800 XT in the description evidently forms 64). The two scalar programs read no mask as a number and no other lane, so they declare no wave size, and the maxima are taken per host wave. The two mask tests pass on the Radeon because reading a mask as data makes the program declare A possible fix inside this PR: make a program the new code applies to declare the console's wave size (the same condition that sets For those hosts there is an alternative I tried: #233 / #320 add a "console flow" (every lane runs every block, branches taken wave-wide), where scalars are the wave's own by construction. With a local switch sending these four programs through it, all four are exact on both adapters here, the RTX 5070 in two 32-lane halves. Details in my reply on #233. Neither PR selects that form for these programs today, so this is a note on how the two could fit together, not a claim that they already do. Not tested: release build, the title (no game files used). AI-assisted. |
|
Test report on AMD RDNA4 and Windows 10, with the before/after count the description asks for. Tested
Per-program diff of the two
So on this title the change clears this blocker, but on its own it brings no compute program to validation yet; Not tested
AI use
|
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
@BlueMew, your before/after counts clarify what to compare with the console-flow experiment on #233. The mask refusal clears for 268 compute programs, and 242 then stop at descriptor reads. Validation counts measure that next blocker. The scalar result after a divergent loop still needs the execution check from the four synthetic programs. Thanks for reporting the two measurements separately. AI-assisted (Codex). |
|
tested this on my rx 6600 xt. 2 of the 4 gpu tests failed because the translated compute shader ran in wave32 instead of the required wave64. added a fix that requests the console wave size when emitting wave reductions. all 4 tests now pass across 10 consecutive runs. fix: |
… the wave's last path left them Conflicts: the new tests sit after the f16 class compare tests. As in the merge of this PR into shader/compute (2e03f3cb), scalars taken wave-wide after divergent loops and joins (and lane masks combined there) need a host wave that is the console wave: a wave64 program split into two 32-lane halves takes the console flow instead, or fails where only per-lane code is allowed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream PR #298 (lane masks spilled to VGPR lanes and read back), the two mesh commits (a lane mask's "has lanes" test and reductions over the host's wave) and PR #269 (scalars leave divergent loops and branches as the wave's last path left them). #269's new tests pass here on the RTX 4060 Ti (32 lanes), so none is ignored. Conflicts: - lower.rs: both sides' fields and helpers (guard_slots and mask_sccs with #298's mask_spills, mask_set_op and only_scc_read); the lane-read test skips both our SGPR spills (`dead`) and #298's mask spills; the mask SCC arm and #298's LANE_MASK arm side by side; data joins try the lazy barycentric first, then take #269's loop finals. - structure.rs: our console_pending with #269's idom; paired_masks stays where our tree sets it last. - valu_tests.rs: both test sets. - sgpr_spill.rs: a spilled else-mask that the per-lane form refused unforwarded now lowers there, since #298 takes the reload for the mask itself; the test asks for that, and for the console flow or the per-lane form when the lowering may choose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng once Head 3ca9456 (TG0000). Conflicts: - structure.rs: #999's normalised ite and direct-mapped memo keep our node-overflow bail-out (no memo writes after it); our memo cap (MAX_MEMO) goes, the cache is bounded by itself. - lower.rs: missing_phis judges each edge as our fill_phis does: lazy barycentrics first, a loop's final value on edges from outside it (#269), and a descriptor's dword left undefined (descriptor_dword) instead of a redo. fill_phis keeps its own redo arms, one phi each. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wers in pixel and vertex programs Head 986fa6d (undeadhuman37). Conflict in fill_phis: the edge keeps our lazy barycentrics and #269's loop finals, then #1073's ballot. #999's missing_phis (merged before) would redo such a phi before fill_phis ever reaches the ballot, so it now makes the ballots first and takes a mask dword that has one as a value. #1073's test passes the host target to emit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Taken from try/wave64: - #189 Wave64Mode (native / wave32 / emulate) and its LDS emulation of 64-lane waves (its helpers in emit/lower/wave64.rs, keeping lower.rs under the 512 KiB policy limit), selected with VICTORY_WAVE64_EMULATE (emulate|1|force, wave32|32, native|0, auto). Default (auto) is Native, which keeps our Target-based path; the mode is part of the shader cache key. Their wave64 tests (wave64_tests.rs, host recommendation test). - #940 mesh lanes counted the host's way when an emulate mode is chosen. - Wave scalars and whole-wave sections: sections skip dead SGPR spills as ours did; wave scalars stay off under the emulate modes. - Translator inferences: a descriptor read only as data, and a scalar use point, infer the view (ported onto our descriptor_data). - 1 MiB windows for title memory outside buffers (shadow.rs). - Trace every mesh draw (draw.rs); WARP adapter check in the test host. - #737 mip drop floor: VICTORY_TEXTURE_MIP_DROP_MIN_SIZE now defaults to 2048 (spares the 1920x1080 artwork). Kept from our side: - Target (--host-lanes, host wave sizes), split halves, console flow, whole-wave sections with SGPR-spill (dead) filtering, lane-mask lowering, #298, #269, waterfall, wave scalars (off under emulate modes). - Our VICTORY_TEXTURE_MIP_DROP (#1296: auto for <= 8 GB, NPOT exemption, subresource mapping and copy routing around dropped mips, SRV mip adjustment): list.rs, resource.rs, texture.rs, descriptor/host.rs are ours apart from the floor default. - Shader cache: VSH3 magic, KeySpec/store for offline warming, cache errors after a good translation, target key (+ wave64 mode byte). - Write-watch journal, CommittedRegions, bindless plans, copystat counters, compute early start, #1388 queue thread, #1418, #704 raw view pool/stride table, the 16 MiB stack in build.rs. Left out: #729 Agility SDK opt-in (build.rs exports, agility.rs, README note): without D3D12Core.dll beside the exe the runtime throws D3D12_ERROR_INVALID_REDISTRIBUTABLE at startup, and Windows 11 needs none. Their host-recommended Wave32 default (it never remapped lanes on NVIDIA). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on #233 that tried #269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The loop form compilers emit keeps the lanes that are done in an exit mask that starts as 0 (s_mov_b64 s[2:3], 0; in the loop s_or_b64 s[2:3], vcc, s[2:3] and s_andn2_b64 exec, exec, s[2:3]). In the console flow every mask join is a phi, and its incoming values had to be masks derived from EXEC or a VALU result, so such a loop stopped with "a lane-mask join of an untracked mask". `Structured::others` gives the lane's bit of the other values read as masks (constants, uniform selects, opaque ones), and the console flow's mask joins take them. The per-lane form is unchanged. New test: a loop in that form with a lane read in every iteration and the exit mask counted afterwards. It was refused on an RTX 5070 before and is exact there (in two halves) and on a Radeon iGPU now. Found through the test report on Marvisak#233 that tried Marvisak#269's programs. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…arvisak#269) A guarded texture in view memory that the guard saw no write to was hashed every eighth frame only. A texture the title rewrites through another view (the startup screens, video frames) changes where the guard cannot see it, so it was shown up to eight frames stale: repeated frames and flicker at startup and in the intro, gone with VICTORY_TEXTURE_GUARD=0. Each hash that finds a texture changed now notes the frame (`Last::rehash`, used by every hashing path), and for 16 frames after that the guard does not skip the texture. One that keeps changing is hashed at every check; one that stops goes back to taking turns, so still textures keep the guard's saving. The skip decision is a function (`guard_skips`) with unit tests. Not yet checked in the game: the change is to when a texture is hashed, not to what is read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
…arvisak#269) A guarded texture in view memory that the guard saw no write to was hashed every eighth frame only. A texture the title rewrites through another view (the startup screens, video frames) changes where the guard cannot see it, so it was shown up to eight frames stale: repeated frames and flicker at startup and in the intro, gone with VICTORY_TEXTURE_GUARD=0. Each hash that finds a texture changed now notes the frame (`Last::rehash`, used by every hashing path), and for 16 frames after that the guard does not skip the texture. One that keeps changing is hashed at every check; one that stops goes back to taking turns, so still textures keep the guard's saving. The skip decision is a function (`guard_skips`) with unit tests. Not yet checked in the game: the change is to when a texture is hashed, not to what is read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nches as the wave's last path left them) into the integration Both sides' arms and tests kept. Waterfall loops are left out of the wave-wide scalars (each lane runs them once with its own descriptor), and a set operation's mask gets a number only where the program reads one (mask_numbers), so if/else masks take no ballots nothing reads. The spilled else-mask test now expects the unforwarded program to translate too: its number comes from the set operation's sources. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
On the console, a wave has one set of scalar registers. A divergent loop runs until its last lane leaves, and each path of a divergent branch that some lane takes runs in code order. So after the loop or the join, every lane reads the scalars that the last iteration or path left. The lowering runs scalar code per lane, so each lane left with its own path's values. That gives wrong numbers with no error, or a refused shader:
s_or_b64 s[2:3], vcc, s[2:3]) or a scalar counter (s_add_u32) read after a divergent loop came out as 1, 2, 3, … 64 across a 64-lane wave, instead of 64 in every lane.a lane mask holding lanes elsewhere read as data. In the run reported on Testers post specs and test results here #49, this was the second most common reason a shader did not translate (80 of 370).Change (
crates/victory-shader/src/emit/lower.rs, compute programs only)s_{and,or,xor,andn2,orn2,nand,nor,xnor,not,mov}_b{32,64}) get their value as a number from their sources' numbers, instead of stopping witha lane mask read as data.LOOP_LIMITalready keeps: onewaveActiveOpmax of the count, then one per value.Pixel, vertex and mesh programs are unchanged. Their host waves need not be the console's (an RX 7800 XT runs wave32 pixel programs 64 lanes wide, see #125), so a host wave's value could mix console waves.
Shortcuts, also in comments:
Tests
Four GPU tests in
valu_tests.rs. They use a newbuild_lanes_cs: a 64-lane wave64 compute fixture that stores v0 per lane. All synthetic, no game data.maind2a4baeloop_exit_mask_counted_after_the_loopscalar_counted_in_a_divergent_loop_read_after_itmask_grown_inside_a_branch_counted_after_ita lane mask holding lanes elsewhere read as datascalar_counted_in_nested_divergent_loopsTested
rust-toolchain.toml); debug.cargo test --workspace --no-fail-fast: 268 passed, 0 failed, 4 ignored (main: 264 / 0 / 4).cargo clippy -p victory-shader --all-targets: no warnings.cargo fmt --check -p victory-shader: clean.cargo xtask policy: 151 files ok.Not tested
victory translate --validateon your own pack, before and after, would show how many more compute shaders translate.AI use
🤖 Generated with Claude Code