Repository navigation
Conversation
A folded wave64 program (crate::fold) keeps the console's scalar branches, and one host wave is one console wave, so the console's branches on lane masks are exact taken wave-wide. They were taken per lane unless the program uses LDS or barriers or sets EXEC to every lane again. Per lane, a host lane whose two console lanes are both outside EXEC leaves the region: - a scalar the region writes (v_readlane_b32, v_readfirstlane_b32, any scalar instruction) keeps its old value in that lane after the join, where the console ran the region and every lane reads the new value; - a loop whose exit is the SCC of a mask operation (v_cmpx, s_andn2_b64, s_cbranch_scc0) stops counting rounds in the lanes that left. Wrong wherever lanes of both halves are out of EXEC at once: alternate lanes, one lane of the upper half, sparse masks. Measured against gfx1036 in wave64 (hand-written programs, hw_oracle) on the RTX 5080 and on the Radeon iGPU as a 32-lane host: of 151 one-wave cases the translation folds 118; 13 of them differed (v_readlane in a branch at lanes 0/31/32/63 with alternate lanes or lane 40, the break loops), 0 with this, and none of the others changed. Folded by force, a vccz/vccnz vote on such a mask and a scalar written in a branch read after the join are exact too. Every branch on a lane mask (EXEC, VCC, SCC of a mask operation) is now taken wave-wide in a folded program. Where that structure fails the program takes the per-lane forms as before; VICTORY_WAVE_FOLDED_LANES=1 takes them always (in the shader cache key). Tests: scalars_written_in_a_branch_on_exec_are_the_waves_after_the_join, a_loop_left_on_the_scc_of_a_mask_operation_counts_the_waves_rounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Exact translation check and an in-game look. The build is v2026.11.29.05 ( Translation (
In game. RTX 3090, Series S, frame generation and RT off. Frozen saves of the balcony (noon) and a city street. 2 starts per build per save, alternating, screenshots 45 s and 90 s into the world:
🤖 Generated with Claude Code |
|
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch |
No issue filed: found while checking the wave64 folding (
crate::fold) against a wave64 card with hand-written programs.What it changes
What was wrong. A folded wave64 program runs one console wave as one host wave, two console lanes per host lane, and keeps the console's scalar code.
folded()still took its branches on lane masks per lane, unless the program uses LDS or barriers, sets EXEC to every lane again, or has lane conditions too large to follow. Per lane, a host lane whose two console lanes are both outside EXEC leaves the region, where the console wave runs it once for all its lanes:v_readlane_b32,v_readfirstlane_b32, any scalar instruction) keeps its old value in that lane after the join, where every console lane reads the new one;v_cmpx,s_andn2_b64,s_cbranch_scc0) stops counting rounds in the lanes that left.It is wrong only where both console lanes of a host lane (lanes t and t + 32) are out of EXEC while other lanes are in: alternate lanes, one lane of the upper half, sparse masks, or lanes leaving a loop one by one. An EXEC of all lanes or of one half does not show it.
What this does.
folded()first builds the structure with every branch on a lane mask taken wave-wide: the EXEC branches, then every branch the structure names as one on a lane mask (Structured::wave_any: VCC, SCC of a mask operation). One host wave is one console wave, so that is the console's control flow. Wherestructure_widefails for that set, the forms before this change are taken as they were.VICTORY_WAVE_FOLDED_LANES=1takes them always. The switch is in the shader cache key (KEYED, second commit), soevery_switch_of_the_translator_is_in_the_keystill holds. Programs that are not folded do not change.With folding off by default (5c262d7, 05d1c56). On current main a program is folded first only with
VICTORY_WAVE_FOLDED=1. By defaultfolded()is still reached for programs the exact forms do not take, before deep skips, wave-wide branches and the approximate forms, and once more as a last resort;VICTORY_WAVE_FOLDED=0leaves it out. This change applies to every program that reachesfolded(): by default to those fallback programs, with=1to every folded program, with=0to none. How many of the title's programs fold by default on current main was not measured here.Merging. Rebased onto main 7995b81. Main's 1b4b6cd had already taken
KEYEDfrom 45 to 46 names (VICTORY_SCALAR_SPLITS), so the old second commit's[&str; 46]edit was empty there, and the array held 47 names in a 46-element array. The second commit (80e8527, "Shader cache: KEYED holds 47 names with VICTORY_WAVE_FOLDED_LANES") now makes it[&str; 47]; 47 is the count of names in the array on 7995b81 plus this branch. If #3210 or #3061 (which drop the staleVICTORY_SCALAR_SPLITS) or #3308 (which addsVICTORY_WIDE_SHADOW_TILES) lands first, the length has to be counted again: a one-line conflict.Credit: no code from other pull requests.
How it was tested
GPU and profile: RTX 5080 and the Ryzen 7 9800X3D's integrated Radeon (gfx1036), Windows 11. Shader tests on the cards, not a run of the game; no Series X/S profile, resolution, DLSS, frame generation or ray tracing involved.
Oracle: 219 hand-written one-wave GFX10 wave64 programs (one 64-thread group, three sets of 151, 15 and 53), run natively in wave64 on the gfx1036 with hw_oracle. The same programs are translated by
emit::emitfor a host of 32-lane waves (every form it tries), run on the RTX 5080 and on the Radeon as a 32-lane host, and all 16 outputs of all 64 lanes are compared. The harness is local (emit::fw64_local_tests, not in this branch):VICTORY_ADAPTER=nvidia|radeon LOCAL_FW64_HOSTWAVE=32 LOCAL_FW64_OUT=<file> VICTORY_WAVE_WHY=1 <test exe> --ignored --exact --nocapture --test-threads=1 emit::fw64_local_tests::<local_fw64_wave_wide|local_fw64x_wave_wide|local_nx_cases>, withLOCAL_FW64_FOLD=1for the forced folds below.Before (829188e, where folding was still on by default): 156 exact, 51 differ, 12 refused, the same on both cards. 137 of the 219 are folded (118 + 15 + 4).
After (cbc69bb): 169 exact, 38 differ, 12 refused, the same on both cards. All 137 folded programs take the new structure; none falls back. 13 programs went from differing to exact:
v_readlane_b32inside an EXEC branch at lanes 0, 31, 32 and 63 with alternate lanes or lane 40 alone (8), and the loops left ons_cbranch_scc0afters_andn2_b64(5: all lanes, lower half, upper half, alternate lanes, sparse). None went the other way. The 38 that still differ differ the same way on 829188e (v_writelane_b32in a branch among them).Folded by force (the harness calling
folded()directly; 204 programs, RTX 5080): 155 exact, 34 differ, 15 refused before; 181, 8, 15 after. The 26 that became exact addv_readfirstlane_b32in a branch, vote loops, avccz/vccnzvote on such a mask and a scalar instruction in a branch read after the join. None went the other way. This run was on the first build of cbc69bb, before its last amend; the run above was repeated on the final commit with the same counts.New tests
scalars_written_in_a_branch_on_exec_are_the_waves_after_the_joinanda_loop_left_on_the_scc_of_a_mask_operation_counts_the_waves_rounds(seven masks over both halves, lane reads at 0, 32 and 63): pass on both cards. WithVICTORY_WAVE_FOLDED_LANES=1(the old forms) both fail on both cards (lane 1, v_readlane in the branch;lane 0, rounds).For shader changes, the wave sizes tested (32 and/or 64 lanes): console wave64 programs on a host of 32-lane waves (RTX 5080, and the Radeon held to 32), checked against the gfx1036 in wave64. Not on a host of 64-lane waves.
cargo testpassed for the crates it touches: partly. On 80e8527 (main 7995b81 + the two commits), RTX 5080:cargo check -p victory-gpu: passes (the rebasedKEYEDbuilds).cargo test -p victory-shader --lib -- folded_tests fold::: 19 passed, 0 failed (454 filtered out), with both new tests.cargo test -p victory-gpu --lib -- every_switch_of_the_translator_is_in_the_key: fails, as it does on main 7995b81 without this branch:VICTORY_SCALAR_SPLITS is not read by the translator any more(the stale name gpu(shader_cache): drop stale VICTORY_SCALAR_SPLITS from KEYED #3210 and Tests: four races, the BCPack oracle, the shader key's stale names, and a loop-latch test #3061 drop). The test's first check, that every switch the translator reads is in the key, passes before that, soVICTORY_WAVE_FOLDED_LANESis keyed. WithVICTORY_SCALAR_SPLITStaken out ofKEYEDby hand ([&str; 46], as gpu(shader_cache): drop stale VICTORY_SCALAR_SPLITS from KEYED #3210 would leave it; not committed), the test gets through everyKEYEDname,VICTORY_WAVE_FOLDED_LANESincluded, and stops at the next stale name on main,VICTORY_ORACLE_RUNSin its not-a-translation list (main has nooracle_tests.rs).cargo clippy -p victory-shader --all-targets -- -D warningsandcargo clippy -p victory-gpu --all-targets -- -D warnings: both stop in victory-shader on main's own code (unused imports inemit/lower/analysis.rs:6andemit/lower.rs:594,while_immutable_conditioninemit/lower/analysis.rs:467,too_many_argumentsinnative.rs:1655). Without-D warnings, victory-gpu gives the same 25 lib and 24 test warnings as main. None of these is on a line this branch touches.victory-shadersuite was not run on 80e8527.Earlier, on cbc69bb (829188e base) plus a two-line
modfor the local harness, built withcargo test -j 6 -p victory-shader --lib --no-run, then the test binary:VICTORY_ADAPTER=nvidia|radeon <exe> --nocapture --test-threads=1 emit::folded_tests: 19 passed, 0 failed on each card;VICTORY_WAVE_FOLDED_LANES=1 VICTORY_ADAPTER=nvidia|radeon <exe> --test-threads=1 emit::folded_tests::scalars_written emit::folded_tests::a_loop_left: 0 passed, 2 failed on each card, as meant;<exe> --test-threads=4 structure emit::wave64_tests emit::folded_tests emit::lower fold:: emit::crosslane_tests(RTX 5080): 115 passed, 0 failed, 1 ignored.Not tested: the game, with
VICTORY_WAVE_FOLDED=1or with the default fallback; the card time of folded programs with this change (5c262d7 turned folding off for its card time); the oracle counts on current main (they are on 829188e; only thecargoruns above are on 7995b81); Series S; cards other than the RTX 5080 and the gfx1036.In game: pending. An earlier in-game A/B is void: its build reused a stale victory-shader from a shared target dir. It is being redone and the result will be posted here.
Checked for overlap
widens_exec, so a program that restores EXEC from a saved mask takes its EXEC branches wave-wide. With this branch such a program normally takes all its lane-mask branches wave-wide beforewidens_execis asked; Keep folded Wave64 branches converged across EXEC restores #2265's test was not run here. The two change adjacent lines infolded()and both append tofolded_tests.rs, so they conflict textually.folded()sits inemit_strict's order, and a 255-register cap; not what happens inside a folded program. 05d1c56 on main has since changed that order too. Both append tofolded_tests.rs.lower::scalar_splits,VICTORY_SCALAR_SPLITS) takes branches wave-wide for the scalars written in them, the same kind of bug, in the unfolded lowering (widen), not infolded(). That half is not on main. No shared lines with this branch exceptKEYED.read_phisinlower.rs, a loop header's join of the EXEC pair). Another place, also about loops over lane masks in folded programs; not tested together.fold.rs: EXEC_LO at block leaders, the sign of inline constants in the upper mask half), not the structure. shader(fold): mark EXEC_LO dirty at basic-block leaders #3097 also appends tofolded_tests.rs.VICTORY_SCALAR_SPLITSfromKEYED(main lists it, but the translator no longer reads it since the Preserve guest-wave shader state and reclaim idle host memory under pressure #479 revert). Whichever lands first decides the length this branch'sKEYEDneeds (see Merging).VICTORY_WIDE_SHADOW_TILEStoKEYEDon the same line; a textual conflict on the array length only.AI use
Claude Code (Claude Opus 5.5) found the cause with the oracle programs, wrote the change, the tests and the oracle programs, ran the measurements and wrote this description. No code from other authors.
🤖 Generated with Claude Code