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

Closed
github-bot wants to merge 2 commits from gh-pr/1404/head into gh-pr/1404/base
Owner

@⁠ashrafsdrop on GitHub · 2026-11-24 17:46 UTC · original
ashrafsdrop:shader/vcc-branch-no-exec → main · +30 −3 · 1 files · 2 commits · closed without merging

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.
**@⁠ashrafsdrop** on GitHub · 2026-11-24 17:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1404) `ashrafsdrop:shader/vcc-branch-no-exec` → `main` · +30 −3 · 1 files · 2 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:35 +00:00
github-bot closed this pull request 2026-11-26 04:30:35 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:09 UTC · original

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7140253097) 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.*
Author
Owner

@⁠ashrafsdrop on GitHub · 2026-11-24 18:25 UTC · original

@⁠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.

**@⁠ashrafsdrop** on GitHub · 2026-11-24 18:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7140614706) @⁠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.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7143985955) ### 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:39 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1404#issuecomment-7148748585) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1404
No description provided.