Shaders: s_cbranch_vccz/vccnz on a scalar VCC decide once for the wave (#2780, on #2836) #3021

Open
wwwwwwww3333333 wants to merge 5 commits from upstream-pr/3023 into main
wwwwwwww3333333 commented 2026-11-26 03:36:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-26T03:36:39Z.


Fixes the open point of #2780 that both #2783 and #2836 leave (noted in the triage there): s_cbranch_vccz/s_cbranch_vccnz test VCC as a whole (RDNA2 ISA, 12.5: VCCZ is VCC == 0), one decision for the wave, not each lane's bit.

Built on #2836: its two commits are kept as they are (Devin, @kotekompotek), rebased onto main 63bcca4. The third commit is this change.

What changes

  • A VCC that is a pair the structure pass cannot see into (Atom::Opaque, both dwords since #2836) now gives a new Atom::Nonzero(lo, hi) at the branch, the same in every lane, lowered as (lo | hi) != 0. The branch is uniform (uniform_join and the translate counts treat it so).
  • A constant VCC other than all lanes or none is taken.
  • No wave operation and no forced wave size, so 32-lane hosts are not affected.
  • shortcut (marked in the code): a VCC from lane results (compares) still branches per lane. That is the same as the hardware while VCC is set only in lanes of EXEC and the skipped block does nothing in lanes whose bit is clear.

GPU test synthetic_tests::vcc_branches_test_the_whole_mask: a full wave64 group, VCC written by two s_mov_b32, v4 = 17 on the taken path and 43 otherwise. Lanes taking s_cbranch_vccz with only VCC_HI set (the hardware takes none):

tree lanes taking the branch
main 63bcca4 64
main + #2836 63 (all but lane 32)
this PR 0, and every lane right in all six cases (VCC_HI only, VCC zero, VCC_LO only; vccz and vccnz)

RX 6750 XT (driver 32.0.21045.29003) and WARP. This replaces a CPU replay with a GPU run; the numbers for main and #2836 match the ones reported on #2780.

Also: structure::tests::vcc_branches_on_scalar_masks_are_uniform checks the branch's condition is Atom::Nonzero alone, without a GPU.

Suites (Windows 11, Rust 1.98.1 MSVC): victory-shader 305 passed, twice. cargo clippy -p victory-shader --all-targets -- -D warnings: clean. cargo check -p victory: clean.

Not measured: any title. Unit tests only, no game files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1

<!-- greyfinch-sync:Marvisak/VIctory:issue:5503528976 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-26T03:36:39Z. --- Fixes the open point of #2780 that both #2783 and #2836 leave (noted in the triage there): `s_cbranch_vccz`/`s_cbranch_vccnz` test VCC as a whole (RDNA2 ISA, 12.5: VCCZ is VCC == 0), one decision for the wave, not each lane's bit. Built on #2836: its two commits are kept as they are (Devin, @kotekompotek), rebased onto main 63bcca4. The third commit is this change. **What changes** - A VCC that is a pair the structure pass cannot see into (`Atom::Opaque`, both dwords since #2836) now gives a new `Atom::Nonzero(lo, hi)` at the branch, the same in every lane, lowered as `(lo | hi) != 0`. The branch is uniform (`uniform_join` and the translate counts treat it so). - A constant VCC other than all lanes or none is taken. - No wave operation and no forced wave size, so 32-lane hosts are not affected. - shortcut (marked in the code): a VCC from lane results (compares) still branches per lane. That is the same as the hardware while VCC is set only in lanes of EXEC and the skipped block does nothing in lanes whose bit is clear. **GPU test** `synthetic_tests::vcc_branches_test_the_whole_mask`: a full wave64 group, VCC written by two `s_mov_b32`, v4 = 17 on the taken path and 43 otherwise. Lanes taking `s_cbranch_vccz` with only VCC_HI set (the hardware takes none): | tree | lanes taking the branch | |---|---| | main 63bcca4 | 64 | | main + #2836 | 63 (all but lane 32) | | this PR | 0, and every lane right in all six cases (VCC_HI only, VCC zero, VCC_LO only; vccz and vccnz) | RX 6750 XT (driver 32.0.21045.29003) and WARP. This replaces a CPU replay with a GPU run; the numbers for main and #2836 match the ones reported on #2780. **Also:** `structure::tests::vcc_branches_on_scalar_masks_are_uniform` checks the branch's condition is `Atom::Nonzero` alone, without a GPU. **Suites** (Windows 11, Rust 1.98.1 MSVC): victory-shader 305 passed, twice. `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. `cargo check -p victory`: clean. **Not measured:** any title. Unit tests only, no game files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
fuzeofficlal commented 2026-11-26 03:56:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:56:42Z.

Review: CHANGES_REQUESTED


Reviewed 8fc606d0 against main (63bcca43; emit/lower.rs stays at 520,714 bytes, safely under the 512 KiB limit). Two concrete issues to fix before merge:

  1. Scalar VCC expressions beyond a single positive Atom::Opaque / Atom::Constant still fall back to a per-lane branch (crates/victory-shader/src/structure.rs:1371-1383)

    • whole only matches Some((Atom::Opaque(lo, hi), Bool::FALSE, Bool::TRUE)) and Some((Atom::Constant(_), Bool::FALSE, Bool::TRUE)).
    • Any scalar wave64 mask operation that produces a negated or compound BDD over scalar atoms — for example:
      • s_not_b64 vcc, s[2:3] (produces (Atom::Opaque(lo, hi), Bool::TRUE, Bool::FALSE)),
      • s_cselect_b64 vcc, 1, 2 (in structure.rs:1120, builds ite(Atom::Uniform(scc), Atom::Constant(1), Atom::Constant(2)), whose root is Atom::Uniform(scc)), or
      • scalar masks merged at a CFG join (Atom::Phi)
        misses whole and falls through to self.b.and(vcc, exec). For s_cselect_b64 vcc, 1, 2 + s_cbranch_vccnz, the whole wave must take the branch for either SCC value, but falling back to per-lane vcc & exec causes only lane 0 or lane 1 to take it (and a CFG join can produce a mask PHI whose scalar inputs the wave64 emitter rejects).
  2. Test coverage gaps (crates/victory-shader/src/emit/synthetic_tests.rs:681-684, crates/victory-shader/src/structure.rs:1767)

    • In vcc_branches_test_the_whole_mask, host.compute_pipeline(&shader) errors continue and assert!(ran > 0) is only checked once across all 6 cases. If the key vcc_hi = 1 case fails pipeline creation while vcc = 0 succeeds, the test still passes silently. Tracking a per-case run count (or failing on pipeline creation once a valid SM 6.6 device is created) avoids hiding regressions.
    • In structure.rs:1767, the second fixture sets vcc_lo = 0 and vcc_hi = -1 via two s_mov_b32 instructions, which creates Atom::Opaque(lo, hi) rather than Atom::Constant, so the Atom::Constant arm at structure.rs:1377 isn't actually exercised (and the assertion accepts either Bool::TRUE or Atom::Nonzero). Using a 64-bit constant move (e.g. s_mov_b64 vcc, 1) or testing s_cselect_b64 / s_not_b64 would directly cover the non-Opaque paths.
<!-- greyfinch-sync:Marvisak/VIctory:review:6068343460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#pullrequestreview-6068343460). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:56:42Z. **Review:** CHANGES_REQUESTED --- Reviewed `8fc606d0` against `main` (`63bcca43`; `emit/lower.rs` stays at 520,714 bytes, safely under the 512 KiB limit). Two concrete issues to fix before merge: 1. **Scalar `VCC` expressions beyond a single positive `Atom::Opaque` / `Atom::Constant` still fall back to a per-lane branch (`crates/victory-shader/src/structure.rs:1371-1383`)** - `whole` only matches `Some((Atom::Opaque(lo, hi), Bool::FALSE, Bool::TRUE))` and `Some((Atom::Constant(_), Bool::FALSE, Bool::TRUE))`. - Any scalar wave64 mask operation that produces a negated or compound BDD over scalar atoms — for example: - `s_not_b64 vcc, s[2:3]` (produces `(Atom::Opaque(lo, hi), Bool::TRUE, Bool::FALSE)`), - `s_cselect_b64 vcc, 1, 2` (in `structure.rs:1120`, builds `ite(Atom::Uniform(scc), Atom::Constant(1), Atom::Constant(2))`, whose root is `Atom::Uniform(scc)`), or - scalar masks merged at a CFG join (`Atom::Phi`) misses `whole` and falls through to `self.b.and(vcc, exec)`. For `s_cselect_b64 vcc, 1, 2` + `s_cbranch_vccnz`, the whole wave must take the branch for either `SCC` value, but falling back to per-lane `vcc & exec` causes only lane 0 or lane 1 to take it (and a CFG join can produce a mask PHI whose scalar inputs the wave64 emitter rejects). 2. **Test coverage gaps (`crates/victory-shader/src/emit/synthetic_tests.rs:681-684`, `crates/victory-shader/src/structure.rs:1767`)** - In `vcc_branches_test_the_whole_mask`, `host.compute_pipeline(&shader)` errors `continue` and `assert!(ran > 0)` is only checked once across all 6 cases. If the key `vcc_hi = 1` case fails pipeline creation while `vcc = 0` succeeds, the test still passes silently. Tracking a per-case run count (or failing on pipeline creation once a valid SM 6.6 device is created) avoids hiding regressions. - In `structure.rs:1767`, the second fixture sets `vcc_lo = 0` and `vcc_hi = -1` via two `s_mov_b32` instructions, which creates `Atom::Opaque(lo, hi)` rather than `Atom::Constant`, so the `Atom::Constant` arm at `structure.rs:1377` isn't actually exercised (and the assertion accepts either `Bool::TRUE` or `Atom::Nonzero`). Using a 64-bit constant move (e.g. `s_mov_b64 vcc, 1`) or testing `s_cselect_b64` / `s_not_b64` would directly cover the non-`Opaque` paths.
zed6000 commented 2026-11-26 04:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-26T04:02:27Z.


Measured offline on the title's shaders (the method in #1247): head 8fc606d merged onto main 63bcca4 (a clean merge, security-reviewed first), victory translate --validate --list over shaders.rpf 1.0.2.1, program by program: 0 gained, 0 lost. All 24,850 programs that validate on main still validate. Since this is the same VCC-branch area where #2405's head lost 1,829 programs (and the hardware-exact variant on #2406 lost 18,170), that's the number that matters here: the wave-uniform reading of scalar VCC doesn't cost this title anything. Offline counts only; no program names or data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182241074 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7182241074). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-26T04:02:27Z. --- Measured offline on the title's shaders (the method in #1247): head `8fc606d` merged onto `main` `63bcca4` (a clean merge, security-reviewed first), `victory translate --validate --list` over `shaders.rpf` 1.0.2.1, program by program: **0 gained, 0 lost.** All 24,850 programs that validate on `main` still validate. Since this is the same VCC-branch area where #2405's head lost 1,829 programs (and the hardware-exact variant on #2406 lost 18,170), that's the number that matters here: the wave-uniform reading of scalar VCC doesn't cost this title anything. Offline counts only; no program names or data.
steven-seagull27 commented 2026-11-26 04:06:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T04:03:41Z.


On 8fc606d, all six checked-in cases passed on the RTX 5080 (621.40), Windows’ built-in WARP and WARP 1.0.22: 0/384 wrong lane values per device. A separate Wave64 test found a remaining issue inside the positive Atom::Nonzero case. An SGPR copied into VCC can already have a different host value in each lane.

The fixture initializes s12 = 0, sets EXEC to just lane 0, and uses s_cbranch_execz to skip s_mov_b32 s12, 1 only if EXEC is empty. Lane 0 exists, so the scalar write executes once for the guest wave. It then restores EXEC, copies s12 to vcc_lo, clears vcc_hi, and branches. The branch should see VCC = 1 for every lane. These are counts read from the UAV on all three devices:

Selected lane Branch Expected taken Actual taken
0, 1, or 32 s_cbranch_vccnz 64 1
0, 1, or 32 s_cbranch_vccz 0 63
64 (absent) s_cbranch_vccnz 0 0
64 (absent) s_cbranch_vccz 64 64

That’s 378/512 wrong lane values per device across the eight cases. With lane 0 selected, WARP 1.0.22 also gives 63/64 wrong on parent fd2b765 for vccnz. RTX and built-in WARP skip that parent Wave64 pipeline. The PR’s original uniform scalar controls pass on all three.

I put a conservative guard and low/high-word regression on the fork. It follows scalar inputs through copies and operations before treating a VCC word as wave-wide. When a contributing scalar phi can select different incoming edges across lanes, it returns an explicit refusal. The regression fails on this PR head and passes with the guard. On all three devices the six original readbacks still pass, along with 1,728/1,728 additional results for constant VCC values under empty, single-lane and full EXEC. This guard covers the joined scalar input. The reviewer’s s_not_b64 and s_cselect_b64 expression cases are separate.

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3023-vcc-scalar-join
git cherry-pick 6e9e8463cad4b34841543c34968bef93a2dfc022
cargo test -p victory-shader --lib --locked vcc_branch

Shader Clippy with -D warnings and asset policy passed. AI-assisted; synthetic fixtures only. Title coverage is unmeasured.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182259123 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7182259123). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T04:03:41Z. --- On `8fc606d`, all six checked-in cases passed on the RTX 5080 (621.40), Windows’ built-in WARP and WARP 1.0.22: **0/384 wrong lane values per device**. A separate Wave64 test found a remaining issue inside the positive `Atom::Nonzero` case. An SGPR copied into VCC can already have a different host value in each lane. The fixture initializes `s12 = 0`, sets EXEC to just lane 0, and uses `s_cbranch_execz` to skip `s_mov_b32 s12, 1` only if EXEC is empty. Lane 0 exists, so the scalar write executes once for the guest wave. It then restores EXEC, copies `s12` to `vcc_lo`, clears `vcc_hi`, and branches. The branch should see VCC = 1 for every lane. These are counts read from the UAV on all three devices: | Selected lane | Branch | Expected taken | Actual taken | |---|---|---:|---:| | 0, 1, or 32 | `s_cbranch_vccnz` | 64 | 1 | | 0, 1, or 32 | `s_cbranch_vccz` | 0 | 63 | | 64 (absent) | `s_cbranch_vccnz` | 0 | 0 | | 64 (absent) | `s_cbranch_vccz` | 64 | 64 | That’s **378/512 wrong lane values per device** across the eight cases. With lane 0 selected, WARP 1.0.22 also gives 63/64 wrong on parent `fd2b765` for `vccnz`. RTX and built-in WARP skip that parent Wave64 pipeline. The PR’s original uniform scalar controls pass on all three. I put a conservative [guard and low/high-word regression on the fork](https://github.com/steven-seagull27/VIctory/commit/6e9e8463cad4b34841543c34968bef93a2dfc022). It follows scalar inputs through copies and operations before treating a VCC word as wave-wide. When a contributing scalar phi can select different incoming edges across lanes, it returns an explicit refusal. The regression fails on this PR head and passes with the guard. On all three devices the six original readbacks still pass, along with **1,728/1,728** additional results for constant VCC values under empty, single-lane and full EXEC. This guard covers the joined scalar input. The reviewer’s `s_not_b64` and `s_cselect_b64` expression cases are separate. ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3023-vcc-scalar-join git cherry-pick 6e9e8463cad4b34841543c34968bef93a2dfc022 cargo test -p victory-shader --lib --locked vcc_branch ``` Shader Clippy with `-D warnings` and asset policy passed. AI-assisted; synthetic fixtures only. Title coverage is unmeasured.
kotekompotek commented 2026-11-26 04:41:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:41:35Z.

Review: APPROVED


LGTM — making Atom::Opaque carry the pair (lo,hi) explicitly removes the fragile pair_high lookup; Nonzero ORs both dwords under wave64 with the hi!=lo dedup. cbranch_vccz/vccnz on a scalar VCC deciding on pair-nonzero matches hardware.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068641335 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#pullrequestreview-6068641335). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:41:35Z. **Review:** APPROVED --- LGTM — making Atom::Opaque carry the pair (lo,hi) explicitly removes the fragile pair_high lookup; Nonzero ORs both dwords under wave64 with the hi!=lo dedup. cbranch_vccz/vccnz on a scalar VCC deciding on pair-nonzero matches hardware.
wwwwwwww3333333 commented 2026-11-26 06:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-26T05:47:47Z.


Thanks @fuzeofficlal, both points were right, and thanks @steven-seagull27 for the guard.

  • Scalar expressions (3228393): a VCC whose diagram tests only atoms held in scalars (opaque pairs, constants, SCC selects) is now one condition for the wave, however it was combined. With constants and SCC alone it is decided in the structure pass, lane by lane over the constants, so s_cselect_b64 vcc, 1, 2 and s_mov_b64 vcc, 1 give TRUE. With an opaque pair (s_not_b64, s_and_b64 with a constant) it becomes Atom::Any, lowered as the mask's two words and tested for zero (VCC_LO alone in wave32). Steven's join guard also runs on the pairs inside it. A VCC from compares or from a mask join (Atom::Phi) still branches per lane, the shortcut already marked in the code.
  • Tests: vcc_branches_test_the_whole_mask now fails if a device runs some cases but makes no pipeline for others. It has 14 cases, including s_mov_b64, s_cselect_b64 (2 and 0), s_not_b64 (hi bit only, and zero) and s_and_b64. The structure test now covers s_mov_b64, s_cselect_b64, s_not_b64 and s_and_b64 directly.
  • steven-seagull27's guard (91f3915) is on the branch with his authorship.

On an RX 6750 XT and WARP, every lane took the expected path in all 14 cases, both ways. Before this, s_cselect_b64 2 and s_and_b64 2 took the branch in lane 1 alone, and s_not_b64 hi 1 in lane 32 alone. victory-shader passed 307 of 307, and Clippy with -D warnings, cargo check -p victory and the xtask tests are clean. lower.rs is 521,058 bytes. The title's shaders are not measured on this head: @zed6000's 0/0 count was on 8fc606d.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183812685 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7183812685). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-26T05:47:47Z. --- Thanks @fuzeofficlal, both points were right, and thanks @steven-seagull27 for the guard. - **Scalar expressions** (3228393): a VCC whose diagram tests only atoms held in scalars (opaque pairs, constants, SCC selects) is now one condition for the wave, however it was combined. With constants and SCC alone it is decided in the structure pass, lane by lane over the constants, so `s_cselect_b64 vcc, 1, 2` and `s_mov_b64 vcc, 1` give TRUE. With an opaque pair (`s_not_b64`, `s_and_b64` with a constant) it becomes `Atom::Any`, lowered as the mask's two words and tested for zero (VCC_LO alone in wave32). Steven's join guard also runs on the pairs inside it. A VCC from compares or from a mask join (`Atom::Phi`) still branches per lane, the shortcut already marked in the code. - **Tests:** `vcc_branches_test_the_whole_mask` now fails if a device runs some cases but makes no pipeline for others. It has 14 cases, including `s_mov_b64`, `s_cselect_b64` (2 and 0), `s_not_b64` (hi bit only, and zero) and `s_and_b64`. The structure test now covers `s_mov_b64`, `s_cselect_b64`, `s_not_b64` and `s_and_b64` directly. - **steven-seagull27's guard** (91f3915) is on the branch with his authorship. On an RX 6750 XT and WARP, every lane took the expected path in all 14 cases, both ways. Before this, `s_cselect_b64 2` and `s_and_b64 2` took the branch in lane 1 alone, and `s_not_b64 hi 1` in lane 32 alone. victory-shader passed 307 of 307, and Clippy with `-D warnings`, `cargo check -p victory` and the xtask tests are clean. `lower.rs` is 521,058 bytes. The title's shaders are not measured on this head: @zed6000's 0/0 count was on 8fc606d.
Marvisak commented 2026-11-26 07:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:18:48Z.


Automated triage for the maintainers.

The direction is right and the evidence is cited: RDNA2 ISA 12.5 (VCCZ tests the whole of VCC), with GPU readbacks on an RX 6750 XT and WARP. The change spans structure.rs, emit/lower.rs and the new emit/lower/scalar_vcc.rs:

  • Lanes::whole turns a VCC built only from scalar atoms into one condition for the wave: Atom::Nonzero for an opaque pair, a per-lane fold over constants (Bools::some_lane), or Atom::Any for scalar expressions.
  • Atom::Opaque now carries both dwords of the pair, replacing pair_high's guess at the next register (from #2836).
  • check_scalar_vcc_joins refuses a VCC fed by a scalar phi that can diverge across lanes.
  • The per-lane shortcut for VCC built from compares is marked in the code.

Update after the author's reply: merge order is settled. The first two commits here (64c89b9, fd2b765) are #2836's two commits rebased onto main with the same messages, so reviewing this PR alone and closing #2836 in its favour is the maintainer's call.

What is still needed before it can be recommended:

  • A title measurement on this head. The only shader-pack count (0 gained / 0 lost) was on 8fc606d. Since then the head adds Atom::Any lowering through mask_words and a new refusal ("a scalar VCC branch depending on a divergent scalar join"), and either could cost programs. #2405 lost 1,829 programs in this same area. A program-by-program count on 3228393 (gained/lost) from anyone with the title's shaders would settle it.

CI check: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184306314 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7184306314). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:18:48Z. --- <!-- victory-triage v1 head=322839300283a9a4561da8303a935b3f1b0c864b verdict=needs-work at=2026-11-26T08:20:18Z --> Automated triage for the maintainers. The direction is right and the evidence is cited: RDNA2 ISA 12.5 (VCCZ tests the whole of VCC), with GPU readbacks on an RX 6750 XT and WARP. The change spans `structure.rs`, `emit/lower.rs` and the new `emit/lower/scalar_vcc.rs`: - `Lanes::whole` turns a VCC built only from scalar atoms into one condition for the wave: `Atom::Nonzero` for an opaque pair, a per-lane fold over constants (`Bools::some_lane`), or `Atom::Any` for scalar expressions. - `Atom::Opaque` now carries both dwords of the pair, replacing `pair_high`'s guess at the next register (from #2836). - `check_scalar_vcc_joins` refuses a VCC fed by a scalar phi that can diverge across lanes. - The per-lane shortcut for VCC built from compares is marked in the code. **Update after the author's reply:** merge order is settled. The first two commits here (`64c89b9`, `fd2b765`) are #2836's two commits rebased onto main with the same messages, so reviewing this PR alone and closing #2836 in its favour is the maintainer's call. What is still needed before it can be recommended: - **A title measurement on this head.** The only shader-pack count (0 gained / 0 lost) was on `8fc606d`. Since then the head adds `Atom::Any` lowering through `mask_words` and a new refusal ("a scalar VCC branch depending on a divergent scalar join"), and either could cost programs. #2405 lost 1,829 programs in this same area. A program-by-program count on `3228393` (gained/lost) from anyone with the title's shaders would settle it. CI `check`: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
wwwwwwww3333333 commented 2026-11-26 09:06:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-26T08:09:13Z.


Thanks for the triage.

Merge order: #3023 carries #2836's two commits unchanged, so I'd suggest closing #2836 in favour of this PR and reviewing one stack. If you'd rather land #2836 first, say so and I'll rebase this PR onto it so only the guard and the whole-VCC commits remain.

Title count: I can't measure the title's shaders on 3228393 (I have no dump here). The new parts since 8fc606d are Atom::Any lowering and the divergent-scalar-join refusal. @zed6000, if you can rerun your offline count on 3228393, a gained/lost number would settle that point. Until then it is unmeasured, and I'm not claiming a safe count.

Unit tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186249549 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7186249549). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-26T08:09:13Z. --- Thanks for the triage. Merge order: #3023 carries #2836's two commits unchanged, so I'd suggest closing #2836 in favour of this PR and reviewing one stack. If you'd rather land #2836 first, say so and I'll rebase this PR onto it so only the guard and the whole-VCC commits remain. Title count: I can't measure the title's shaders on 3228393 (I have no dump here). The new parts since 8fc606d are `Atom::Any` lowering and the divergent-scalar-join refusal. @zed6000, if you can rerun your offline count on 3228393, a gained/lost number would settle that point. Until then it is unmeasured, and I'm not claiming a safe count. Unit tests only, no game files.
playcations commented 2026-11-27 06:01:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by playcations on 2026-11-27T06:01:31Z.


Independent NVIDIA/Linux validation of head 322839300283a9a4561da8303a935b3f1b0c864b: all 14 current vcc_branches_test_the_whole_mask cases passed, checking all 64 UAV outputs per case (896/896 values). This includes the split-dword, b64 move, SCC select, NOT and AND controls.

Environment: Ubuntu 26.04.1, RTX 5060 Ti 16 GiB, NVIDIA 595.99.02, Wine 11.22 Staging, vkd3d-proton 3.1 and DXVK 3.2. Queried the adapter from the created D3D12 device's LUID: NVIDIA vendor 10de, device 2d04, software flag clear, WaveLaneCountMin/Max = 32/32.

For this private test run I changed only the test harness: one required Host::new(false) device, asserted the actual adapter IDs/name/software flag, required the public Microsoft DXIL validator to load and validate each shader, removed the WARP loop and all hardware/pipeline skip paths, and required exactly 14 completed cases. VICTORY_WARP was unset. No shader/runtime implementation changes were applied. The Windows test binary was cross-built with Rust 1.98.1 / cargo-xwin; the CPU-only divergent-scalar-source refusal test also passed.

This is a Linux/Wine synthetic readback result, not native Windows acceptance or title coverage. No game files were mounted or run. It does not settle the outstanding gained/lost title-shader count requested in triage. AI-assisted with Codex; the harness changes and captured adapter/readback logs were reviewed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211148468 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7211148468). Originally posted by [playcations](https://github.com/playcations) on 2026-11-27T06:01:31Z. --- Independent NVIDIA/Linux validation of head `322839300283a9a4561da8303a935b3f1b0c864b`: all 14 current `vcc_branches_test_the_whole_mask` cases passed, checking all 64 UAV outputs per case (896/896 values). This includes the split-dword, b64 move, SCC select, NOT and AND controls. Environment: Ubuntu 26.04.1, RTX 5060 Ti 16 GiB, NVIDIA 595.99.02, Wine 11.22 Staging, vkd3d-proton 3.1 and DXVK 3.2. Queried the adapter from the created D3D12 device's LUID: NVIDIA vendor `10de`, device `2d04`, software flag clear, `WaveLaneCountMin/Max = 32/32`. For this private test run I changed only the test harness: one required `Host::new(false)` device, asserted the actual adapter IDs/name/software flag, required the public Microsoft DXIL validator to load and validate each shader, removed the WARP loop and all hardware/pipeline skip paths, and required exactly 14 completed cases. `VICTORY_WARP` was unset. No shader/runtime implementation changes were applied. The Windows test binary was cross-built with Rust 1.98.1 / cargo-xwin; the CPU-only divergent-scalar-source refusal test also passed. This is a Linux/Wine synthetic readback result, not native Windows acceptance or title coverage. No game files were mounted or run. It does not settle the outstanding gained/lost title-shader count requested in triage. AI-assisted with Codex; the harness changes and captured adapter/readback logs were reviewed.
playcations commented 2026-11-27 06:39:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by playcations on 2026-11-27T06:39:49Z.


Follow-up for the outstanding title-shader count on current head 322839300283a9a4561da8303a935b3f1b0c864b: 0 emitted programs gained / 0 lost, and 0 validator passes gained / 0 lost, against main 63bcca43c6a00a758510398fa43096ce7e4f7df0.

I ran the offline translate --validate --list --jobs 4 pass on the same read-only primary shader archive for both builds. It held 26,503 containers; the translator skipped 614 duplicate native parts and scanned 26,084 native programs. Both releases used Rust 1.98.1 / cargo-xwin and the same public Microsoft DXIL validator under Wine 11.22 Staging. No pipelines were created, and no game or GPU was run during these passes.

Stage Programs Emitted, main → PR Validated, main → PR Gained / lost
Vertex 2,191 2,191 → 2,191 2,191 → 2,191 0 / 0
Pixel 12,056 12,055 → 12,055 12,055 → 12,055 0 / 0
Compute 2,682 2,658 → 2,658 1,910 → 1,910 0 / 0
Mesh 8,765 8,765 → 8,765 8,694 → 8,694 0 / 0

The other 390 native programs are Es/Gs (195 each), which do not emit here. The stock CLI lists 25,889 outcomes but silently omits the 195 Es programs because its offline path does not raise I/O for Es. I accounted for them explicitly with a separate native-part inventory, rather than counting them as validated.

For program-by-program matching, the inventory maps every source alias to native-part identity + stage. This matters because the threaded passes can choose different aliases among duplicate containers. The complete canonical populations and every listed outcome matched; emitted/validated counts also reconcile with the CLI's stage totals. The input bytes and release EXE hashes were checked, and the archive stayed unchanged. Raw identities, labels and individual outcomes remain private; none are posted here.

This is a count/validator result for that archive, not a byte-for-byte DXIL comparison, rendering acceptance, all possible title resources, or a gameplay claim. The earlier strict NVIDIA synthetic result is separate. The only private source edits in this PR build were the test-only adapter/skip assertions already described; release translator/runtime source was unchanged. AI-assisted with Codex GPT-6.1 Sol; comparison code, six synthetic reconciliation checks and final totals reviewed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211732030 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7211732030). Originally posted by [playcations](https://github.com/playcations) on 2026-11-27T06:39:49Z. --- Follow-up for the outstanding title-shader count on current head `322839300283a9a4561da8303a935b3f1b0c864b`: **0 emitted programs gained / 0 lost**, and **0 validator passes gained / 0 lost**, against main `63bcca43c6a00a758510398fa43096ce7e4f7df0`. I ran the offline `translate --validate --list --jobs 4` pass on the same read-only primary shader archive for both builds. It held 26,503 containers; the translator skipped 614 duplicate native parts and scanned 26,084 native programs. Both releases used Rust 1.98.1 / cargo-xwin and the same public Microsoft DXIL validator under Wine 11.22 Staging. No pipelines were created, and no game or GPU was run during these passes. | Stage | Programs | Emitted, main → PR | Validated, main → PR | Gained / lost | |---|---:|---:|---:|---:| | Vertex | 2,191 | 2,191 → 2,191 | 2,191 → 2,191 | 0 / 0 | | Pixel | 12,056 | 12,055 → 12,055 | 12,055 → 12,055 | 0 / 0 | | Compute | 2,682 | 2,658 → 2,658 | 1,910 → 1,910 | 0 / 0 | | Mesh | 8,765 | 8,765 → 8,765 | 8,694 → 8,694 | 0 / 0 | The other 390 native programs are Es/Gs (195 each), which do not emit here. The stock CLI lists 25,889 outcomes but silently omits the 195 Es programs because its offline path does not raise I/O for Es. I accounted for them explicitly with a separate native-part inventory, rather than counting them as validated. For program-by-program matching, the inventory maps every source alias to native-part identity + stage. This matters because the threaded passes can choose different aliases among duplicate containers. The complete canonical populations and every listed outcome matched; emitted/validated counts also reconcile with the CLI's stage totals. The input bytes and release EXE hashes were checked, and the archive stayed unchanged. Raw identities, labels and individual outcomes remain private; none are posted here. This is a count/validator result for that archive, not a byte-for-byte DXIL comparison, rendering acceptance, all possible title resources, or a gameplay claim. The earlier strict NVIDIA synthetic result is separate. The only private source edits in this PR build were the test-only adapter/skip assertions already described; release translator/runtime source was unchanged. AI-assisted with Codex GPT-6.1 Sol; comparison code, six synthetic reconciliation checks and final totals reviewed.
ZeOs360 commented 2026-11-28 12:09:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-28T12:09:47Z.


In-game data for this PR on AMD: it fixes the cause of #3486's consistent early writes. Plus one
latent gap at v_cndmask_b32 that no game shader hits.

#3486 is the ray-tracing BVH builder's 4 GiB writes. Setup: RX 7800 XT, Windows 11, GTA6 with ray
tracing through the open RT PRs (#2098 #2118 #2703 #2841 #2810 #2501).

The cause is the builder's digit scan f6eb6498409ca974 (wave64, 64 threads, 4 digits per lane). It
carries lane 31's running sum into lanes 32..63 with a mask set by halves:

s_mov_b32 s6, 0
s_mov_b32 s7, -1
v_readlane_b32 s8, v1, 31
v_cndmask_b32 v6, 0, s8, s[6:7]

On main lanes 32..63 tested s6, so digits 128..255 lacked the lower half's total. Snapshots of the
sort's buffers between passes (local diagnostic) showed this in all three LBVH trees of the builder's
first list:

  • the per-block histogram matched a CPU count exactly;
  • the scan's upper half was off by exactly the lower half's total;
  • the radix scatter (e63d22c4) wrote colliding positions and lost keys;
  • f28a33a8 built broken trees from them;
  • 5552dac6a2b7a1fd read wrong parent and child indices, and its 32-bit offsets wrapped.

10-minute runs, counting that pass's wrapped-offset sites:

tree sites first one after the builder starts
RT stack, 2 runs 54, 44 21 s, 21 s
RT stack + a global UAV barrier before every builder dispatch 63 19 s
RT stack + this PR (#3023 at 3228393) 70, all in frames 2017-2031 3 min 52 s
RT stack + this PR + the select change below, 2 runs 0, 0 none
RT stack + our own version of #2836's change, snapshots on 0 none

Notes on those runs:

  • The select change below alters no game shader: a check over all 25,985 containers found no
    v_cndmask_b32 where it differs. So those two runs translate the game exactly as this PR does.
  • One of them ended at 5 minutes at a known title fault, after frame 2035, which is past the window
    where this PR's own run had its burst. Another such run ended earlier (frame 1950) and is not
    counted.
  • Our own version lacks this PR's branch commits.

Without the change, the wraps started within about 20 s of the builder starting in every run. That
includes two more runs, one with a snapshot diagnostic and one with an idxen range check: 38 and 46
sites, the first at 19-20 s. With it, three of four runs had none. The burst in one run, about 4
minutes in, is intermittent and probably has another cause; @upipibi's note on #3486 about compacted
sizes would be a candidate.

With this PR, a GPU copy of that carry passes on the RX 7800 XT: lanes 0..15 and 48..63 take the
value for s6 = 0xffff, s7 = 0xffff0000. On main lanes 32..47 take it and 48..63 do not. A full
translation of the game's shaders refuses the same 229 containers with this PR as without it.

The latent gap. Lanes::finish still collapses masks and other to the low dword
(masks: … (lo, m), other: … (lo, m)), and v_cndmask_b32 looks its mask up by the low dword alone
(self.x.st.masks.get(&m).or_else(|| self.x.st.other.get(&m))). Since Atom::Opaque now holds both
dwords, two masks that share a low dword are two atoms but one map entry, and whichever survives
answers both selects. This GPU test fails with this PR on the RX 7800 XT: lanes 32..63 get 0, the
first mask.

#[test]
fn wave64_selects_on_two_masks_with_one_low_dword_stay_apart() {
    // s6 = 0 for both masks; s7 = 0, then -1: the first select takes s8 in
    // no lane, the second in lanes 32..63.
    let body = [
        0x4A02_00FF, 0x0000_1000, // v_add_nc_u32 v1, 0x1000, v0
        0xBE86_0380,              // s_mov_b32 s6, 0
        0xBE87_0380,              // s_mov_b32 s7, 0
        0xD760_0008, 0x0001_3F01, // v_readlane_b32 s8, v1, 31
        0xD501_0006, 0x0018_1080, // v_cndmask_b32 v6, 0, s8, s[6:7]
        0xBE87_03C1,              // s_mov_b32 s7, -1
        0xD501_0007, 0x0018_1080, // v_cndmask_b32 v7, 0, s8, s[6:7]
        0x4A06_0F06,              // v_add_nc_u32 v3, v6, v7
    ];
    let want: Vec<u32> = (0..64).map(|l| if l < 32 { 0 } else { 0x101F }).collect();
    run_permute_cs(true, &body, &want);
}

It passes with a lookup by both dwords. Lanes::step already registers the pair for every select
(self.mask(k)), so the lookup always finds it:

// structure.rs, Structured, next to paired_masks:
paired_other: Map<Key, Bool>,

pub(crate) fn select_mask(&self, low: Value, high: Option<Value>) -> Option<Bool> {
    match high {
        Some(high) => self
            .paired_masks
            .get(&(low, high))
            .or_else(|| self.paired_other.get(&(low, high))),
        None => self.masks.get(&low).or_else(|| self.other.get(&low)),
    }
    .copied()
}
// Lanes::finish:
paired_other: if self.p.wave64 { self.other } else { Map::default() },

// lower.rs, "v_cndmask_b32" with an SGPR mask:
let high = if self.x.native.wave64 { inst.read(Reg::S(code + 1)) } else { None };
let m = inst
    .read(Reg::S(code))
    .and_then(|m| self.x.st.select_mask(m, high))
    .ok_or("a select on an untracked mask")?;

Your PR's own tests still pass with it. Since nothing in the game hits this, it can just as well be a
follow-up after this PR.

AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon;
the GPU tests and in-game runs were made on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7239036206 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3023#issuecomment-7239036206). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-28T12:09:47Z. --- In-game data for this PR on AMD: it fixes the cause of #3486's consistent early writes. Plus one latent gap at `v_cndmask_b32` that no game shader hits. **#3486** is the ray-tracing BVH builder's 4 GiB writes. Setup: RX 7800 XT, Windows 11, GTA6 with ray tracing through the open RT PRs (#2098 #2118 #2703 #2841 #2810 #2501). The cause is the builder's digit scan `f6eb6498409ca974` (wave64, 64 threads, 4 digits per lane). It carries lane 31's running sum into lanes 32..63 with a mask set by halves: ``` s_mov_b32 s6, 0 s_mov_b32 s7, -1 v_readlane_b32 s8, v1, 31 v_cndmask_b32 v6, 0, s8, s[6:7] ``` On `main` lanes 32..63 tested s6, so digits 128..255 lacked the lower half's total. Snapshots of the sort's buffers between passes (local diagnostic) showed this in all three LBVH trees of the builder's first list: - the per-block histogram matched a CPU count exactly; - the scan's upper half was off by exactly the lower half's total; - the radix scatter (`e63d22c4`) wrote colliding positions and lost keys; - `f28a33a8` built broken trees from them; - `5552dac6a2b7a1fd` read wrong parent and child indices, and its 32-bit offsets wrapped. 10-minute runs, counting that pass's wrapped-offset sites: | tree | sites | first one after the builder starts | |---|---|---| | RT stack, 2 runs | 54, 44 | 21 s, 21 s | | RT stack + a global UAV barrier before every builder dispatch | 63 | 19 s | | RT stack + this PR (#3023 at 3228393) | 70, all in frames 2017-2031 | 3 min 52 s | | RT stack + this PR + the select change below, 2 runs | 0, 0 | none | | RT stack + our own version of #2836's change, snapshots on | 0 | none | Notes on those runs: - The select change below alters no game shader: a check over all 25,985 containers found no `v_cndmask_b32` where it differs. So those two runs translate the game exactly as this PR does. - One of them ended at 5 minutes at a known title fault, after frame 2035, which is past the window where this PR's own run had its burst. Another such run ended earlier (frame 1950) and is not counted. - Our own version lacks this PR's branch commits. Without the change, the wraps started within about 20 s of the builder starting in every run. That includes two more runs, one with a snapshot diagnostic and one with an idxen range check: 38 and 46 sites, the first at 19-20 s. With it, three of four runs had none. The burst in one run, about 4 minutes in, is intermittent and probably has another cause; @upipibi's note on #3486 about compacted sizes would be a candidate. With this PR, a GPU copy of that carry passes on the RX 7800 XT: lanes 0..15 and 48..63 take the value for `s6 = 0xffff`, `s7 = 0xffff0000`. On `main` lanes 32..47 take it and 48..63 do not. A full translation of the game's shaders refuses the same 229 containers with this PR as without it. **The latent gap.** `Lanes::finish` still collapses `masks` and `other` to the low dword (`masks: … (lo, m)`, `other: … (lo, m)`), and `v_cndmask_b32` looks its mask up by the low dword alone (`self.x.st.masks.get(&m).or_else(|| self.x.st.other.get(&m))`). Since `Atom::Opaque` now holds both dwords, two masks that share a low dword are two atoms but one map entry, and whichever survives answers both selects. This GPU test fails with this PR on the RX 7800 XT: lanes 32..63 get 0, the first mask. ```rust #[test] fn wave64_selects_on_two_masks_with_one_low_dword_stay_apart() { // s6 = 0 for both masks; s7 = 0, then -1: the first select takes s8 in // no lane, the second in lanes 32..63. let body = [ 0x4A02_00FF, 0x0000_1000, // v_add_nc_u32 v1, 0x1000, v0 0xBE86_0380, // s_mov_b32 s6, 0 0xBE87_0380, // s_mov_b32 s7, 0 0xD760_0008, 0x0001_3F01, // v_readlane_b32 s8, v1, 31 0xD501_0006, 0x0018_1080, // v_cndmask_b32 v6, 0, s8, s[6:7] 0xBE87_03C1, // s_mov_b32 s7, -1 0xD501_0007, 0x0018_1080, // v_cndmask_b32 v7, 0, s8, s[6:7] 0x4A06_0F06, // v_add_nc_u32 v3, v6, v7 ]; let want: Vec<u32> = (0..64).map(|l| if l < 32 { 0 } else { 0x101F }).collect(); run_permute_cs(true, &body, &want); } ``` It passes with a lookup by both dwords. `Lanes::step` already registers the pair for every select (`self.mask(k)`), so the lookup always finds it: ```rust // structure.rs, Structured, next to paired_masks: paired_other: Map<Key, Bool>, pub(crate) fn select_mask(&self, low: Value, high: Option<Value>) -> Option<Bool> { match high { Some(high) => self .paired_masks .get(&(low, high)) .or_else(|| self.paired_other.get(&(low, high))), None => self.masks.get(&low).or_else(|| self.other.get(&low)), } .copied() } // Lanes::finish: paired_other: if self.p.wave64 { self.other } else { Map::default() }, // lower.rs, "v_cndmask_b32" with an SGPR mask: let high = if self.x.native.wave64 { inst.read(Reg::S(code + 1)) } else { None }; let m = inst .read(Reg::S(code)) .and_then(|m| self.x.st.select_mask(m, high)) .ok_or("a select on an untracked mask")?; ``` Your PR's own tests still pass with it. Since nothing in the game hits this, it can just as well be a follow-up after this PR. AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon; the GPU tests and in-game runs were made on my machine.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3023:upstream-pr/3023'
git switch 'upstream-pr/3023'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3023'
git switch 'upstream-pr/3023'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3023'
git switch 'upstream-pr/3023'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3023'
git switch 'main'
git merge --squash 'upstream-pr/3023'
git switch 'main'
git merge --ff-only 'upstream-pr/3023'
git switch 'main'
git merge 'upstream-pr/3023'
git push origin 'main'
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
Marvisak/VIctory!3021
No description provided.