Shaders: s_cbranch_vccz/vccnz tests raw VCC, not VCC & EXEC #2406

Open
github-bot wants to merge 1 commit from github-bot/gh-2406 into main AGit
Owner

@⁠makmatvey on GitHub · 2026-11-25 13:04 UTC · original
makmatvey:cursor/shaders-vcc-branch-raw-1c6e → main · +55 −6 · 1 files · 1 commits · open

What

s_cbranch_vccz / s_cbranch_vccnz on the console test the full VCC register. Structuring used VCC & EXEC, so a branch flipped when only inactive lanes held VCC bits (an earlier compare left them, or a scalar write set them after EXEC was narrowed).

Tracked as VIC-BT-026 in #1249. Related focused slice of the stalled bundle in #1336 (needs rebase).

Change

In crates/victory-shader/src/structure.rs, the VCC branch arms use the lane's VCC bit alone. EXEC branches are unchanged.

Tests

  • cargo test -p victory-shader --locked --lib cbranch_vcc_tests_raw_vcc_without_exec_masking — pass
  • cargo test -p victory-shader --locked --lib structure:: — 12 passed, 1 ignored
  • cargo clippy -p victory-shader --locked -- -D warnings — clean

No game data used.

**@⁠makmatvey** on GitHub · 2026-11-25 13:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406) `makmatvey:cursor/shaders-vcc-branch-raw-1c6e` → `main` · +55 −6 · 1 files · 1 commits · open ## What `s_cbranch_vccz` / `s_cbranch_vccnz` on the console test the full VCC register. Structuring used `VCC & EXEC`, so a branch flipped when only inactive lanes held VCC bits (an earlier compare left them, or a scalar write set them after EXEC was narrowed). Tracked as VIC-BT-026 in #1249. Related focused slice of the stalled bundle in #1336 (needs rebase). ## Change In `crates/victory-shader/src/structure.rs`, the VCC branch arms use the lane's VCC bit alone. EXEC branches are unchanged. ## Tests - `cargo test -p victory-shader --locked --lib cbranch_vcc_tests_raw_vcc_without_exec_masking` — pass - `cargo test -p victory-shader --locked --lib structure::` — 12 passed, 1 ignored - `cargo clippy -p victory-shader --locked -- -D warnings` — clean No game data used.
Hardware compares the full VCC register. Masking with EXEC flipped the
branch when only inactive lanes held VCC bits. Synthetic test under a
narrowed EXEC with an explicit VCC write.

Co-authored-by: Matsvey Makushenka <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:04:54 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 13:22 UTC · original · edited 2026-11-25 13:53 UTC

Duplicate check: this and #2405 (ashrafsdrop, opened 31 s earlier) make the same edit in structure.rs. So does the older #1336 (wbkepler, 2026-11-24, now conflicting): it has the same vcc hunk and the same cbranch_vcc_tests_raw_vcc_without_exec_masking test as this PR (added in an edit). Both replace self.b.and(vcc, exec) with raw vcc for s_cbranch_vccz / s_cbranch_vccnz.

Correction (edited): I first wrote that either one fixes it. From reading main 940d32f, neither changes behaviour. exec(inst) returns Bool::TRUE when the instruction doesn't read EXEC (structure.rs:914-919), and the VCC branches don't read it, so and(vcc, exec) already reduces to vcc. steven-seagull27 ran both PRs' tests on the parent and they pass there (comment). The bug that's left is in neither PR: the branch is decided per lane from the lane's VCC bit, not wave-wide from VCC != 0. His test-only commit e0b10c17 fails on all three trees.

The differences:

  • This PR also moves the self.exec(inst) read into the s_cbranch_execz / execnz arms. That doesn't change behaviour either.
  • The tests differ. #2405 checks the branch condition is the v_cmp's lane bool after a v_cmpx that changes EXEC. This one checks constant VCC under an EXEC of 0.

AI-assisted (Claude Code). Read from the two diffs and main only; nothing run.

**@⁠upipibi** on GitHub · 2026-11-25 13:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7163678951) · edited 2026-11-25 13:53 UTC Duplicate check: this and #2405 (ashrafsdrop, opened 31 s earlier) make the same edit in `structure.rs`. So does the older #1336 (wbkepler, 2026-11-24, now conflicting): it has the same `vcc` hunk and the same `cbranch_vcc_tests_raw_vcc_without_exec_masking` test as this PR (added in an edit). Both replace `self.b.and(vcc, exec)` with raw `vcc` for `s_cbranch_vccz` / `s_cbranch_vccnz`. **Correction (edited):** I first wrote that either one fixes it. From reading `main` `940d32f`, neither changes behaviour. `exec(inst)` returns `Bool::TRUE` when the instruction doesn't read EXEC (`structure.rs:914-919`), and the VCC branches don't read it, so `and(vcc, exec)` already reduces to `vcc`. steven-seagull27 ran both PRs' tests on the parent and they pass there ([comment](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2405)). The bug that's left is in neither PR: the branch is decided per lane from the lane's VCC bit, not wave-wide from `VCC != 0`. His test-only commit `e0b10c17` fails on all three trees. The differences: - This PR also moves the `self.exec(inst)` read into the `s_cbranch_execz` / `execnz` arms. That doesn't change behaviour either. - The tests differ. #2405 checks the branch condition is the `v_cmp`'s lane bool after a `v_cmpx` that changes EXEC. This one checks constant VCC under an EXEC of 0. AI-assisted (Claude Code). Read from the two diffs and `main` only; nothing run.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 13:34 UTC · original

WARP verification + comparison with #2405

Tested: PR head 583fc17689225a0e08e3c35cc5efa2d839d05e1a, on origin/main 940d32f69b22265690a0b5a15d6ded572ba33baf (the PR is one commit on that base, so the merge was a no-op).
Environment: VICTORY_D3D12_WARP=1 (software WARP), Windows 11 Pro 10.0.26200, rustc 1.98.1, DXC 1.9.0.5512 (dxcompiler), dxil.dll 1.8.2502.11 on PATH.

Command Result
cargo test -p victory-shader --lib --locked ok: 248 passed, 0 failed, 3 ignored (two benchmarks and one defect_ test, all ignored on main too)
cargo clippy -p victory-shader --all-targets --locked -- -D warnings exit 0
cargo xtask policy asset policy: 182 files ok, exit 0

The new test structure::tests::cbranch_vcc_tests_raw_vcc_without_exec_masking ran and passed (not skipped). I did not run it against unpatched main, so I have not shown that it fails without the fix.

Diff comparison with #2405 (same file, same lines in Lanes::branch in structure.rs). I agree with the earlier duplicate-check comment, and I ran the code, which that comment did not:

  • Code: the resulting Bool is identical to #2405. This PR also moves the exec() read into the execz / execnz arms and adds a comment explaining why VCC is not masked. That has no behavioural effect.
  • Tests: this PR uses constant VCC (s_mov_b32 vcc_lo, -1 / 0) under a v_cmpx-narrowed EXEC and checks Bool::TRUE. #2405 uses a per-lane v_cmp result and checks the lane atom and its polarity, so it exercises a symbolic VCC. The two cover different cases. Either PR could take the other's test.
  • Neither PR changes how wave64 reads the high half of VCC. I did not test wave64.

Limits: WARP only, no physical hardware GPU, no game files or dumps. Diff reviewed in full: the only changes are in structure.rs, with no process, network or filesystem actions.

AI use: Claude Code (Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-25 13:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7163975254) **WARP verification + comparison with #2405** Tested: PR head `583fc17689225a0e08e3c35cc5efa2d839d05e1a`, on `origin/main` `940d32f69b22265690a0b5a15d6ded572ba33baf` (the PR is one commit on that base, so the merge was a no-op). Environment: `VICTORY_D3D12_WARP=1` (software WARP), Windows 11 Pro 10.0.26200, rustc 1.98.1, DXC 1.9.0.5512 (dxcompiler), dxil.dll 1.8.2502.11 on `PATH`. | Command | Result | |---|---| | `cargo test -p victory-shader --lib --locked` | ok: 248 passed, 0 failed, 3 ignored (two benchmarks and one `defect_` test, all ignored on main too) | | `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` | exit 0 | | `cargo xtask policy` | `asset policy: 182 files ok`, exit 0 | The new test `structure::tests::cbranch_vcc_tests_raw_vcc_without_exec_masking` ran and passed (not skipped). I did not run it against unpatched main, so I have not shown that it fails without the fix. **Diff comparison with #2405** (same file, same lines in `Lanes::branch` in `structure.rs`). I agree with the earlier duplicate-check comment, and I ran the code, which that comment did not: - Code: the resulting `Bool` is identical to #2405. This PR also moves the `exec()` read into the `execz` / `execnz` arms and adds a comment explaining why VCC is not masked. That has no behavioural effect. - Tests: this PR uses constant VCC (`s_mov_b32 vcc_lo, -1` / `0`) under a `v_cmpx`-narrowed EXEC and checks `Bool::TRUE`. #2405 uses a per-lane `v_cmp` result and checks the lane atom and its polarity, so it exercises a symbolic VCC. The two cover different cases. Either PR could take the other's test. - Neither PR changes how wave64 reads the high half of VCC. I did not test wave64. Limits: WARP only, no physical hardware GPU, no game files or dumps. Diff reviewed in full: the only changes are in `structure.rs`, with no process, network or filesystem actions. AI use: Claude Code (Claude Sonnet 5.5)
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 13:35 UTC · original

I ran a Wave32 readback on this head (583fc17), #2405 and their common parent. All three still split a scalar branch across lanes when VCC has only bit 0 set and a later compare narrows EXEC to lane 1. For s_cbranch_vccnz, lane 0 stored 11 and lanes 1–31 stored 23. The scalar result should be 11 for all 32. The complementary vccz case was also wrong in 31/32 lanes; the zero-VCC controls matched throughout.

The RTX 5080, built-in WARP and WARP 1.0.22 returned the same output arrays. I also ran this PR’s structural test on the parent, where it already passes. The test-only commit applies to either PR. Full per-opcode results and rerun instructions · Wave32 reproducer

AI-assisted with Codex. Synthetic shaders only.

**@⁠steven-seagull27** on GitHub · 2026-11-25 13:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7164000167) I ran a Wave32 readback on this head (`583fc17`), #2405 and their common parent. All three still split a scalar branch across lanes when VCC has only bit 0 set and a later compare narrows EXEC to lane 1. For `s_cbranch_vccnz`, lane 0 stored 11 and lanes 1–31 stored 23. The scalar result should be 11 for all 32. The complementary `vccz` case was also wrong in 31/32 lanes; the zero-VCC controls matched throughout. The RTX 5080, built-in WARP and WARP 1.0.22 returned the same output arrays. I also ran this PR’s structural test on the parent, where it already passes. The test-only commit applies to either PR. [Full per-opcode results and rerun instructions](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2405) · [Wave32 reproducer](https://github.com/steven-seagull27/VIctory/commit/e0b10c17b1de49abe7d469f120803eec42429044) AI-assisted with Codex. Synthetic shaders only.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 14:26 UTC · original

I pushed the same wave-wide branch fix based on this PR’s head. To apply it on 583fc17, run the following commands.

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2406-vcc-wave-integration
git cherry-pick 86fde8a4873167908ab14c8d682078ef2e62fa70
cargo test --locked -p victory-shader --lib vcc_branch -- --test-threads=1 --nocapture

The original mixed-lane test went from 62/128 wrong to 0/128 wrong on both the RTX 5080 and WARP 1.0.22. The RTX also matched all 872 Wave32 words in the two-wave tests. WARP 1.0.22 matched both full-wave groups (512 Wave32 words and 1,024 Wave64 words). Its 45-thread Wave32 group missed 26/360 words, which a native HLSL ballot reproduces. Its 85-thread Wave64 group returned 38, 0, 0, 0, 16 and 8 incorrect words out of 680 across six fresh processes. An optimized native HLSL shader also reproduced intermittent wrong decisions on this runtime. Built-in WARP skipped the fixed-width shaders. Full comparison and compiler limits

AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-25 14:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7165295264) I pushed the [same wave-wide branch fix based on this PR’s head](https://github.com/steven-seagull27/VIctory/commit/86fde8a4873167908ab14c8d682078ef2e62fa70). To apply it on `583fc17`, run the following commands. ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2406-vcc-wave-integration git cherry-pick 86fde8a4873167908ab14c8d682078ef2e62fa70 cargo test --locked -p victory-shader --lib vcc_branch -- --test-threads=1 --nocapture ``` The original mixed-lane test went from 62/128 wrong to **0/128 wrong** on both the RTX 5080 and WARP 1.0.22. The RTX also matched all 872 Wave32 words in the two-wave tests. WARP 1.0.22 matched both full-wave groups (512 Wave32 words and 1,024 Wave64 words). Its 45-thread Wave32 group missed 26/360 words, which a native HLSL ballot reproduces. Its 85-thread Wave64 group returned 38, 0, 0, 0, 16 and 8 incorrect words out of 680 across six fresh processes. An optimized native HLSL shader also reproduced intermittent wrong decisions on this runtime. Built-in WARP skipped the fixed-width shaders. [Full comparison and compiler limits](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2405) AI-assisted with Codex.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:31 UTC · original

Automated triage for the maintainers.

Proposed close (no change in behaviour). As with #2405: in crates/victory-shader/src/structure.rs, Lanes::exec returns Bool::TRUE for an instruction that does not read EXEC, and ir.rs gives s_cbranch_vccz/s_cbranch_vccnz only a VCC read, so and(vcc, exec) was already vcc; moving the exec() call into the execz/execnz arms makes no difference either. The new test cbranch_vcc_tests_raw_vcc_without_exec_masking passes on the parent 940d32f too, and the added comment describes a behaviour change this diff does not make. What is actually wrong, per the readbacks in the comments, is that the branch is decided per lane rather than once for the wave from VCC != 0; a PR that fixes that, with a test that fails on main, would be welcome. CI: passing.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7166977386) <!-- victory-triage v1 head=583fc17689225a0e08e3c35cc5efa2d839d05e1a verdict=proposed-close at=2026-11-25T15:33:00Z --> Automated triage for the maintainers. **Proposed close (no change in behaviour).** As with #2405: in `crates/victory-shader/src/structure.rs`, `Lanes::exec` returns `Bool::TRUE` for an instruction that does not read EXEC, and `ir.rs` gives `s_cbranch_vccz`/`s_cbranch_vccnz` only a VCC read, so `and(vcc, exec)` was already `vcc`; moving the `exec()` call into the `execz`/`execnz` arms makes no difference either. The new test `cbranch_vcc_tests_raw_vcc_without_exec_masking` passes on the parent `940d32f` too, and the added comment describes a behaviour change this diff does not make. What is actually wrong, per the readbacks in the comments, is that the branch is decided per lane rather than once for the wave from `VCC != 0`; a PR that fixes that, with a test that fails on `main`, would be welcome. CI: passing. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 16:51 UTC · original

The EXEC-mask removal is right — hardware tests raw VCC (VCCZ/VCCNZ reflect the whole scalar register, and inactive lanes can hold VCC bits), so masking with EXEC can flip the branch.

One level the fix doesn't reach: s_cbranch_vcc* is uniform — the whole wave takes one path (VCCZ is a scalar flag, not per-lane). Keeping vcc as a per-lane Bool still lets the structurer treat it as divergent, which is the deeper bug #2405 fixes (scalar-mask preservation + bounded uniform counter, with Wave32/Wave64 readback tests failing on main). For triage: this is a correct partial fix; #2405 is the complete one — merging order matters for the test expectations each asserts.

**@⁠kotekompotek** on GitHub · 2026-11-25 16:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7168648379) The EXEC-mask removal is right — hardware tests raw `VCC` (`VCCZ`/`VCCNZ` reflect the whole scalar register, and inactive lanes can hold VCC bits), so masking with EXEC can flip the branch. One level the fix doesn't reach: `s_cbranch_vcc*` is *uniform* — the whole wave takes one path (VCCZ is a scalar flag, not per-lane). Keeping `vcc` as a per-lane `Bool` still lets the structurer treat it as divergent, which is the deeper bug #2405 fixes (scalar-mask preservation + bounded uniform counter, with Wave32/Wave64 readback tests failing on main). For triage: this is a correct partial fix; #2405 is the complete one — merging order matters for the test expectations each asserts.
Author
Owner

@⁠zed6000 on GitHub · 2026-11-25 21:40 UTC · original

Measured offline on the title's shaders (the method in #1247): this head (583fc17) merged onto main 13f91ca (a clean merge), compared program by program over shaders.rpf 1.0.2.1 with dxil.dll 1.8.2502: 0 gained, 0 lost. For comparison, #2405, which targets the same s_cbranch_vccz/vccnz semantics, loses 1,829 programs on the same base (details there). Offline counts only; no program names or data.

**@⁠zed6000** on GitHub · 2026-11-25 21:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7175386489) Measured offline on the title's shaders (the method in #1247): this head (`583fc17`) merged onto main `13f91ca` (a clean merge), compared program by program over `shaders.rpf` 1.0.2.1 with dxil.dll 1.8.2502: **0 gained, 0 lost**. For comparison, #2405, which targets the same `s_cbranch_vccz`/`vccnz` semantics, loses 1,829 programs on the same base (details there). Offline counts only; no program names or data.
Author
Owner

@⁠zed6000 on GitHub · 2026-11-25 21:47 UTC · original

Following up for anyone picking up the wave-wide fix suggested above: steven-seagull27's 86fde8a on top of this head, merged onto 13f91ca, loses 18,170 programs offline (mostly "a scalar VCC branch requiring the guest wave width": 14,095). This head alone loses none. #2405, which carries the same fix plus a per-lane fallback, loses 1,829. The breakdown is on #2405. Offline counts only; no program names or data.

**@⁠zed6000** on GitHub · 2026-11-25 21:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7175550301) Following up for anyone picking up the wave-wide fix suggested above: steven-seagull27's [`86fde8a`](https://github.com/steven-seagull27/VIctory/commit/86fde8a4873167908ab14c8d682078ef2e62fa70) on top of this head, merged onto `13f91ca`, loses **18,170 programs** offline (mostly "a scalar VCC branch requiring the guest wave width": 14,095). This head alone loses none. #2405, which carries the same fix plus a per-lane fallback, loses 1,829. The breakdown is on #2405. Offline counts only; no program names or data.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 01:20 UTC · original

Updating my earlier cherry-pick recommendation after @⁠zed6000’s A/B. I withdraw 86fde8a as a release candidate. On the same shader archive and base, your head 583fc17 lost zero validated programs, my cherry-pick lost 18,170, and #2405’s revised 34c7ec2 lost 1,829. Changing the result from a wrong translation to an explicit refusal can be appropriate for an individual shader. These counts do establish a release cost. Same-base comparison

The mixed-lane test still distinguishes the implementations. The raw-VCC head gave 62/128 wrong output words on my RTX 5080. The wave-wide version gave 0/128 there, and @⁠upipibi independently got 0/128 on an RTX 3070. #2405 has taken the wave-wide commit with authorship, so I’m following up there on preserving compiler proofs. RTX 3070 readbacks

AI-assisted with Codex.

**@⁠steven-seagull27** on GitHub · 2026-11-26 01:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2406#issuecomment-7179681871) Updating my earlier cherry-pick recommendation after @⁠zed6000’s A/B. **I withdraw `86fde8a` as a release candidate.** On the same shader archive and base, your head `583fc17` lost zero validated programs, my cherry-pick lost 18,170, and #2405’s revised `34c7ec2` lost 1,829. Changing the result from a wrong translation to an explicit refusal can be appropriate for an individual shader. These counts do establish a release cost. [Same-base comparison](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2405) The mixed-lane test still distinguishes the implementations. The raw-VCC head gave 62/128 wrong output words on my RTX 5080. The wave-wide version gave 0/128 there, and @⁠upipibi independently got 0/128 on an RTX 3070. #2405 has taken the wave-wide commit with authorship, so I’m following up there on preserving compiler proofs. [RTX 3070 readbacks](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2405) AI-assisted with Codex.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2406/head:github-bot/gh-2406'
git switch 'github-bot/gh-2406'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2406'
git switch 'github-bot/gh-2406'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2406'
git switch 'github-bot/gh-2406'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2406'
git switch 'main'
git merge --squash 'github-bot/gh-2406'
git switch 'main'
git merge --ff-only 'github-bot/gh-2406'
git switch 'main'
git merge 'github-bot/gh-2406'
git push origin 'main'
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!2406
No description provided.