Shaders: scalars written in lane-divergent branches reach every lane after the join (port of avatarmanz#405) #73

Closed
simbaui4life wants to merge 0 commits from upstream-pr/73 into main
simbaui4life commented 2026-11-27 16:14:59 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by simbaui4life on 2026-11-27T16:14:59Z.


A port of avatarmanz/VIctory-7900XTX#405, review fix included. It builds on #70 (the oracle tests): that commit is included, and only the last commit is new.

Cause: on the console a wave runs a lane-divergent branch once, with EXEC narrowed. An SGPR or SCC written inside the branch is one value for the whole wave. Lowered as per-lane control flow, the write happens only on the lanes that took the branch, so after the join the "scalar" differs from lane to lane. Example from the fuzzer:

v_cmp_gt_u32  vcc, s22, v3
s_and_saveexec_b32 s40, vcc_lo
s_mov_b32     s27, s19          ; only in the branch
s_or_b32      exec_lo, exec_lo, s40
; s27 from every lane: console = s19 everywhere, here = s19 only where v3 < s22

What this does

  • lower::scalar_splits finds the lane branches whose region writes a scalar that a block after the join reads with different origins on its paths. It follows s_mov copies.
  • emit(), for compute only, takes exactly those branches wave-wide through this fork's widen().
    • A console wave64 on 32-lane host waves needs group barriers for this, so there it applies only with VICTORY_WAVE_WIDE=1, as widen() already did.
    • Everything else keeps its per-lane form.
  • widen() takes one new parameter, scalar_splits: Option<&[usize]>, which keeps it at seven arguments for clippy.
    • Some(branches) seeds those branches and adds new scalar splits each round.
    • None (VICTORY_SCALAR_SPLITS=0) does neither, in every caller, the fallbacks included. That is the review fix of avatarmanz#405.
    • The fork's own parameters (active-lane loops, groups of several console waves) are unchanged.
  • VICTORY_SCALAR_SPLITS is added to the switch list in shader_cache.rs.
  • VICTORY_WAVE_WIDE is read through lower::wave_wide_on(), so the test can switch it per thread.

Tested (RTX 4070 Ti, driver 621.01)

  • oracle_scalars_written_in_lane_branches_reach_every_lane: 9 shapes, for all, some or no lanes, wave32 and wave64. It fails at 26 places without the change.
  • widen_takes_scalar_splits_only_when_asked (translation only, runs in CI): it fails if the expansion is unconditional.
  • Base 288 passed; this branch 292 passed. Together with the s_min/s_max and lane PR: 293 passed. Clippy -D warnings is clean.

Not tested:

  • in the game (no game data here): how often such shaders occur and what changes on screen;
  • the cost of the wave-wide branches.

No game data in the commits.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5529746608 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/73). Originally posted by [simbaui4life](https://github.com/simbaui4life) on 2026-11-27T16:14:59Z. --- A port of avatarmanz/VIctory-7900XTX#405, review fix included. It **builds on #70** (the oracle tests): that commit is included, and only the last commit is new. **Cause:** on the console a wave runs a lane-divergent branch once, with EXEC narrowed. An SGPR or SCC written inside the branch is one value for the whole wave. Lowered as per-lane control flow, the write happens only on the lanes that took the branch, so after the join the "scalar" differs from lane to lane. Example from the fuzzer: ``` v_cmp_gt_u32 vcc, s22, v3 s_and_saveexec_b32 s40, vcc_lo s_mov_b32 s27, s19 ; only in the branch s_or_b32 exec_lo, exec_lo, s40 ; s27 from every lane: console = s19 everywhere, here = s19 only where v3 < s22 ``` **What this does** - `lower::scalar_splits` finds the lane branches whose region writes a scalar that a block after the join reads with different origins on its paths. It follows `s_mov` copies. - `emit()`, for compute only, takes exactly those branches wave-wide through this fork's `widen()`. - A console wave64 on 32-lane host waves needs group barriers for this, so there it applies only with `VICTORY_WAVE_WIDE=1`, as `widen()` already did. - Everything else keeps its per-lane form. - **`widen()` takes one new parameter,** `scalar_splits: Option<&[usize]>`, which keeps it at seven arguments for clippy. - `Some(branches)` seeds those branches and adds new scalar splits each round. - `None` (`VICTORY_SCALAR_SPLITS=0`) does neither, in every caller, the fallbacks included. That is the review fix of avatarmanz#405. - The fork's own parameters (active-lane loops, groups of several console waves) are unchanged. - `VICTORY_SCALAR_SPLITS` is added to the switch list in `shader_cache.rs`. - `VICTORY_WAVE_WIDE` is read through `lower::wave_wide_on()`, so the test can switch it per thread. **Tested** (RTX 4070 Ti, driver 621.01) - `oracle_scalars_written_in_lane_branches_reach_every_lane`: 9 shapes, for all, some or no lanes, wave32 and wave64. It fails at 26 places without the change. - `widen_takes_scalar_splits_only_when_asked` (translation only, runs in CI): it fails if the expansion is unconditional. - Base 288 passed; this branch 292 passed. Together with the s_min/s_max and lane PR: 293 passed. Clippy `-D warnings` is clean. **Not tested:** - in the game (no game data here): how often such shaders occur and what changes on screen; - the cost of the wave-wide branches. No game data in the commits. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Dukestar69 commented 2026-11-27 16:29:49 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Dukestar69 on 2026-11-27T16:29:49Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090):

  • cargo test -p victory-shader --lib oracle_tests:: passed (4/4, including oracle_scalars_written_in_lane_branches_reach_every_lane)
  • cargo test -p victory-shader --lib emit::tests:: passed (21/21)
  • cargo clippy -p victory-shader --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (280 files ok)
  • Note: this branch includes commit 62eed99 from #70.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6091000941 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/73#pullrequestreview-6091000941). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T16:29:49Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090): - `cargo test -p victory-shader --lib oracle_tests::` passed (4/4, including `oracle_scalars_written_in_lane_branches_reach_every_lane`) - `cargo test -p victory-shader --lib emit::tests::` passed (21/21) - `cargo clippy -p victory-shader --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`280 files ok`) - Note: this branch includes commit `62eed99` from #70. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!73
No description provided.