Shaders: test raw VCC on s_cbranch_vccz and vccnz without EXEC masking #1403

Closed
ashrafsdrop wants to merge 2 commits from upstream-pr/1404 into main
ashrafsdrop commented 2026-11-24 17:46:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-24T17:46:49Z.


Summary
Resolves VIC-BT-026 from #1249:

  • s_cbranch_vccz and s_cbranch_vccnz branch conditions in crates/victory-shader/src/structure.rs were masked against EXEC via self.b.and(vcc, exec).
  • Per the RDNA2 ISA manual, VCC-based conditional branches test raw VCC (VCC == 0 or VCC != 0), irrespective of EXEC.
  • Evaluates vcc directly for s_cbranch_vccnz and not(vcc) for s_cbranch_vccz.
  • Adds unit test vcc_branch_tests_raw_vcc_without_exec in structure.rs.

Verification

  • cargo test -p victory-shader: 121 tests passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets --all-features -- -D warnings: clean, 0 warnings.
  • cargo run -p xtask -- policy: 154 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587934501 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404). Originally posted by [ashrafsdrop](https://github.com/ashrafsdrop) on 2026-11-24T17:46:49Z. --- Summary Resolves VIC-BT-026 from #1249: - `s_cbranch_vccz` and `s_cbranch_vccnz` branch conditions in `crates/victory-shader/src/structure.rs` were masked against `EXEC` via `self.b.and(vcc, exec)`. - Per the RDNA2 ISA manual, VCC-based conditional branches test raw VCC (`VCC == 0` or `VCC != 0`), irrespective of EXEC. - Evaluates `vcc` directly for `s_cbranch_vccnz` and `not(vcc)` for `s_cbranch_vccz`. - Adds unit test `vcc_branch_tests_raw_vcc_without_exec` in `structure.rs`. Verification - `cargo test -p victory-shader`: 121 tests passed, 0 failed. - `cargo clippy -p victory-shader --all-targets --all-features -- -D warnings`: clean, 0 warnings. - `cargo run -p xtask -- policy`: 154 files ok.
catminou4 commented 2026-11-24 18:05:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:52:30Z.

Review: APPROVED


s_cbranch_vccz/vccnz no longer ANDs the lane condition with EXEC — matching hardware, which tests raw VCC. The removed b.and(vcc, exec) was modeling exec-masked lanes; inactive lanes' stale VCC bits do count on real hardware for these scalar branches, so this is a correctness fix for divergence analysis. The new structure test pins the BDD shape (single Lane atom, no exec conjunct) and runs on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 97 passed, 0 failed.

<!-- greyfinch-sync:Marvisak/VIctory:review:6044527151 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#pullrequestreview-6044527151). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:52:30Z. **Review:** APPROVED --- s_cbranch_vccz/vccnz no longer ANDs the lane condition with EXEC — matching hardware, which tests raw VCC. The removed `b.and(vcc, exec)` was modeling exec-masked lanes; inactive lanes' stale VCC bits do count on real hardware for these scalar branches, so this is a correctness fix for divergence analysis. The new structure test pins the BDD shape (single Lane atom, no exec conjunct) and runs on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p victory-shader --locked`. Shader execution tests (valu_tests/host/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 97 passed, 0 failed.
geiyiliyabumo commented 2026-11-24 19:04:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T18:09:59Z.


Independent verification and code review of \8ae748e\ on Windows 11 / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib structure: 6 passed, 0 failed
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 154 files ok

One test-sensitivity note on \ cc_branch_tests_raw_vcc_without_exec\ (\structure.rs:1214):
In the test program, \EXEC\ is never narrowed before \s_cbranch_vccnz, so \exec == Bool::TRUE\ and \self.b.and(vcc, exec)\ already simplified to \ cc\ on \main\—meaning the test passes even without the production fix. Narrowing \EXEC\ (e.g. via \ cmpx*\ or \s_and_saveexec_b32\ after setting \ cc) before \s_cbranch_vccnz\ will make the test actually fail on \main\ and prove raw \VCC\ semantics.

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140253097 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7140253097). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T18:09:59Z. --- Independent verification and code review of \8ae748e\ on **Windows 11 / Rust 1.98.1 MSVC**: - Merge check vs \main\ (\ fe310e\): clean - \cargo test -p victory-shader --lib structure\: **6 passed, 0 failed** - \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and \--all-features\): clean - \cargo xtask policy\: 154 files ok **One test-sensitivity note on \ cc_branch_tests_raw_vcc_without_exec\ (\structure.rs:1214\):** In the test program, \EXEC\ is never narrowed before \s_cbranch_vccnz\, so \exec == Bool::TRUE\ and \self.b.and(vcc, exec)\ already simplified to \ cc\ on \main\—meaning the test passes even without the production fix. Narrowing \EXEC\ (e.g. via \ _cmpx_*\ or \s_and_saveexec_b32\ after setting \ cc\) before \s_cbranch_vccnz\ will make the test actually fail on \main\ and prove raw \VCC\ semantics. *AI-assisted; synthetic tests only, no game files.*
ashrafsdrop commented 2026-11-24 19:04:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ashrafsdrop on 2026-11-24T18:25:02Z.


@geiyiliyabumo Good eye on the test structure.

Looking into crates/victory-shader/src/ir.rs (effects()), s_cbranch_vccz and s_cbranch_vccnz only register VCC in their read set (r.extend(mask(VCC))), never EXEC (which is only read by s_cbranch_exec{z,nz}).

Because s_cbranch_vcc* does not read EXEC, self.exec(inst) inside branch() returned Bool::TRUE by definition (the fallback for any instruction with no EXEC operand in its read set). Thus self.b.and(vcc, exec) on main was dead code that always evaluated to vcc & TRUE == vcc, regardless of preceding instructions.

Removing the conjunct formally decouples the branch evaluation from EXEC in accordance with the RDNA2 ISA manual.

Pushed commit 6f0badc adding an explicit support check to vcc_branch_tests_raw_vcc_without_exec:

assert_eq!(s.bools.support(when), vec![Atom::Lane(cmp)]);

This guarantees the BDD representation has zero dependency on EXEC or any extraneous atoms.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140614706 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7140614706). Originally posted by [ashrafsdrop](https://github.com/ashrafsdrop) on 2026-11-24T18:25:02Z. --- @geiyiliyabumo Good eye on the test structure. Looking into `crates/victory-shader/src/ir.rs` (`effects()`), `s_cbranch_vccz` and `s_cbranch_vccnz` only register `VCC` in their read set (`r.extend(mask(VCC))`), never `EXEC` (which is only read by `s_cbranch_exec{z,nz}`). Because `s_cbranch_vcc*` does not read `EXEC`, `self.exec(inst)` inside `branch()` returned `Bool::TRUE` by definition (the fallback for any instruction with no `EXEC` operand in its read set). Thus `self.b.and(vcc, exec)` on `main` was dead code that always evaluated to `vcc & TRUE == vcc`, regardless of preceding instructions. Removing the conjunct formally decouples the branch evaluation from `EXEC` in accordance with the RDNA2 ISA manual. Pushed commit `6f0badc` adding an explicit support check to `vcc_branch_tests_raw_vcc_without_exec`: ```rust assert_eq!(s.bools.support(when), vec![Atom::Lane(cmp)]); ``` This guarantees the BDD representation has zero dependency on `EXEC` or any extraneous atoms.
catminou4 commented 2026-11-24 21:02:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:50:19Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers structure/lowering unit tests.

Raw VCC branch test: vcc_branch_tests_raw_vcc_without_exec verifies s_cbranch_vccz/vccnz read raw VCC without EXEC masking, and bools.support reports the lane compare atom.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047177484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#pullrequestreview-6047177484). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:50:19Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers structure/lowering unit tests. Raw VCC branch test: vcc_branch_tests_raw_vcc_without_exec verifies s_cbranch_vccz/vccnz read raw VCC without EXEC masking, and bools.support reports the lane compare atom.
sinan-cmyk commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:44:07Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 6f0badc onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143985955 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7143985955). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:44:07Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 6f0badc onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:06:30 +00:00
Marvisak commented 2026-11-25 01:08:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:39:57Z.


Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Removes & exec from the per-lane condition of s_cbranch_vccz/vccnz. In the per-lane model a compare mask already carries EXEC, so the two differ only for lanes outside EXEC, which do no work; nothing is fixed, the fact that taken lanes are in EXEC is lost, and the new test passes on main unchanged.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148748585 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7148748585). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:39:57Z. --- Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Removes `& exec` from the per-lane condition of s_cbranch_vccz/vccnz. In the per-lane model a compare mask already carries EXEC, so the two differ only for lanes outside EXEC, which do no work; nothing is fixed, the fact that taken lanes are in EXEC is lost, and the new test passes on main unchanged. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

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
Marvisak/VIctory!1403
No description provided.