Shaders: scalars written in lane-divergent branches reach every lane after the join #405
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!405
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-405"
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?
@simbaui4life on GitHub · 2026-11-27 00:20 UTC · original
simbaui4life:fix/scalars-after-lane-branches→main· +2115 −5 · 5 files · 3 commits · openBuilds on #403 (the oracle tests): its commit is included here, and only the last commit is new.
Overlaps: #81 (Pavl3000) changes the same
widen()andbranches_around; whichever lands second needs a rebase, and I can rebase this one onto #81. #286 (an SGPR after a scalar loop, per half) and Belobug/VIctory-Belobug-AMD#352 (a scalar counted in a loop that lanes leave at different iterations) are the same family of fault in loops; this PR covers lane-divergent branches only.Cause: on the console a wave runs both sides of a lane-divergent branch, with EXEC narrowed. An SGPR or SCC written inside the branch is then one value for the whole wave. Lowered as per-lane control flow, that write happens only on the lanes that took the branch. After the join, the "scalar" therefore differs from lane to lane: lanes that skipped the branch keep the old value. Minimal example from the fuzzer (wave32 and wave64):
What this does
lower::scalar_splitsfinds the lane branches whose region writes a scalar (SGPR or SCC; EXEC and lane masks excluded) that a block after the join reads as a phi with different origins on its paths. It followss_movcopies, so a copy of an older value counts too.emit(), compute programs only, takes exactly those branches wave-wide through the existingwiden()/structure_wide, as the console does. Everything else keeps its per-lane form.widen()now takes them as a seed and adds any thatscalar_splitsstill finds afterstructure_wide.VICTORY_WAVE_WIDE=1, aswiden()already did. Without it, the per-lane form stays.VICTORY_SCALAR_SPLITS=0turns it off. It is in the shader cache key (victory-gpu/src/shader_cache.rs) beside the other switches that pick a form.VICTORY_WAVE_WHYprints what was taken wave-wide.VICTORY_WAVE_WIDEis read throughlower::wave_wide_on(), so the test can turn it on for its own thread instead of changing the environment that other tests read.TRANSLATOR_VERSION1 → 2. #404, #353 and #354 also go 1 → 2, so whichever lands later needs the next number.Tested (RTX 4070 Ti, driver 621.01, Windows 11 26200)
oracle_scalars_written_in_lane_branches_reach_every_lanecovers 9 shapes:v_readfirstlaneandv_readlanein the branchEach shape runs for all, some and no lanes, split on the thread id and on a hash, with masks as data or not, in wave32 and wave64. Without the change it fails at 26 places; with it, it passes.
This branch: clippy as in CI,
--all-featuresas well, andcargo test -p victory-shader(305 passed, 0 failed).cargo clippy -p victory-gpu --all-targets -- -D warningsreports 4 errors, all in files this PR does not touch (list.rs,watch.rs,host/panel.rs,host/place.rs), as on main.Fuzzer with
VICTORY_WAVE_WIDE=1, seed 2, 300 programs per wave size: differing programs went from 50 to 13 (wave32) and 40 to 15 (wave64). With seed 4, 400 programs, none of the rest are this class; they are the open VCC findings listed in #403.Not tested:
No game data in the commits.
🤖 Generated with Claude Code
@UwUCammie on GitHub · 2026-11-27 00:46 UTC · original
I noticed one path where
VICTORY_SCALAR_SPLITS=0still takes the new scalar branches wave-wide. It skips the first probe inemit, but the existing wave64 and lane-mask fallbacks callwidenwith an empty seed. The loop inwidenstill callsscalar_splitsand extendswidein both cases.For an off/on comparison, could you pass the same switch into
widenand guard the scalar-only expansion with it? The existing expansion frombranches_aroundcan stay enabled. Call site · Expansion@simbaui4life on GitHub · 2026-11-27 15:26 UTC · original
Good catch, thanks.
widen()now takes the switch (abf5c1f):emit()passestrue;lower::scalar_splits_on().So
VICTORY_SCALAR_SPLITS=0reaches every caller, and thebranches_aroundexpansion is unchanged.New test:
widen_takes_scalar_splits_only_when_asked. It runs translation only, so it needs no GPU and runs in CI. With an empty seed, it checks that the switch decides whether the scalar branch is taken wave-wide, and it fails if the expansion is made unconditional again.This branch:
cargo test -p victory-shader306 passed, clippy-D warningsclean, also with--all-features(RTX 4070 Ti).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.