Shaders: a folded program takes every branch on a lane mask wave-wide #3440
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3440
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3440"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Lyrnc on GitHub · 2026-11-29 23:22 UTC · original
Lyrnc:fix/w64-fold-lane-branches→main· +154 −2 · 3 files · 2 commits · closed without mergingNo 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 (
5c262d7b,05d1c564). On current main a program is folded first only withVICTORY_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
7995b81b. Main's1b4b6cd4had already takenKEYEDfrom 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 (80e8527f, "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 on7995b81bplus 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 (
829188e9, 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 (cbc69bbf): 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 on829188e9(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 cbc69bbf, 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. On80e8527f(main7995b81b+ 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 main7995b81bwithout this branch:VICTORY_SCALAR_SPLITS is not read by the translator any more(the stale name #3210 and #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 #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 on80e8527f.Earlier, on cbc69bbf (
829188e9base) plus a two-linemodfor 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 (5c262d7bturned folding off for its card time); the oracle counts on current main (they are on829188e9; only thecargoruns above are on7995b81b); 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; #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.05d1c564on main has since changed that order too. Both append tofolded_tests.rs.829188e9and reverted, its GPU half back as1b4b6cd4): its shader half (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. #3097 also appends tofolded_tests.rs.VICTORY_SCALAR_SPLITSfromKEYED(main lists it, but the translator no longer reads it since the #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
@nick0451 on GitHub · 2026-11-30 02:51 UTC · original
Exact translation check and an in-game look. The build is v2026.11.29.05 (
41adb551) with this PR merged onto it (head80e8527f).Translation (
victory translate --list,VICTORY_HOST_WAVE=32, all of the title's shaders: 26,180 programs, 25,789 with emitted DXIL):cascadeshadows_rendering:CS_ShadowRenderTiled*: the Cascades and Misc variants (CB, Alpha, Hair, HairAlpha, PPPC); most of the 37.tiled_lighting:CS_ClusterLightsWorldSpaceand...IntensityBased.indirect_diffuse_lighting:CS_DeferredFallback_{BVH,Voxels,Fallback}andCS_ResolveVBuffer_Voxels.sr_tracing:CS_ResolveVolumetricsandCS_DeferredFallbacksAlpha_SkyProbe.scattering_transmittance_system:CS_Gather,CS_Gather_ReferenceandCS_GatherDensityAreaForReadBack.firevbuffer*:CS_EntityFire*(4 programs).vfx_proj_decal_vbuffer:CS_ProjDecalResolve_Vectorized.ptx_prerender:ptfx_CS_PreRender{Sprite,Trail}.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
@dyshay on GitHub · 2026-11-30 03:12 UTC · original
Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch
janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with--profile diag --features diagnostics. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.80e8527fcftoe3169a07cf@Lyrnc on GitHub · 2026-11-30 18:59 UTC · original
@nick0451, thanks for the full translation check and the side-by-side starts. 37 programs changing and none failing is the expected picture. Only folded programs that branch on a lane mask take another form: the tiled shadow and light-cluster kernels, the deferred fallbacks, the gathers and the particle pre-render. The same scenes looking the same also fits. These are correctness cases the balcony and street frames don't happen to show.
The branch is rebased onto main
84bd61e2(v2026.11.30.02) and force-pushed (nowe3169a07). #3210 has landed, so main no longer listsVICTORY_SCALAR_SPLITSinKEYED, and the array there has 47 names. WithVICTORY_WAVE_FOLDED_LANESit has 48. The old second commit ("47 names") came out empty and was replaced by "Shader cache: KEYED holds 48 names with VICTORY_WAVE_FOLDED_LANES". The description's note about #3210 and #3061 is settled. #3308 would still change the length by one. The other conflict was only infolded_tests.rs, where main and this branch both add tests at the end; both sets are kept.Checks on
e3169a07(Windows 11, rustc 1.98.1, its own target dir):cargo check -p victory-shader -p victory-gpupasses.cargo test -p victory-shader --lib -- folded_tests: 22 passed, both new tests among them.cargo test -p victory-gpu --lib -- shader_cache: 11 passed, 1 failed.every_switch_of_the_translator_is_in_the_keystops at "VICTORY_ORACLE_RUNS is not read by the translator any more", a stale name in main's not-a-translation list, and it fails the same way on main84bd61e2without this branch. Before that point, the test's first check (every switch the translator reads is listed) passes, and so does everyKEYEDname,VICTORY_WAVE_FOLDED_LANESincluded.@dyshay, the head changed, so janus-prs needs the new one.
AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this reply.
e3169a07cfto6b4e52600fPull request closed