Shaders: fix RPO resource tracking, SMEM alignment, raw VCC branch, and readlane/writelane semantics (#1249) #1336

Open
github-bot wants to merge 2 commits from github-bot/gh-1336 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 17:32 UTC · original
wbkepler:shader/rdna2-isa-and-rpo-fixes → main · +381 −21 · 5 files · 2 commits · open

Summary

Fixes five RDNA2 shader ISA and CFG tracking bugs identified in #1249:

  1. VIC-BT-024 (crates/victory-shader/src/resource.rs): Iterate resource::track() in reverse_postorder(&p.blocks) rather than raw vector index order so descriptor/waterfall s_loads in higher-indexed blocks (such as copies appended by structure::split_irreducible()) populate out.scalar before lower-indexed consumers inspect them.
  2. VIC-BT-025 (crates/victory-shader/src/emit/lower.rs): Mask each s_buffer_load_dword* address term (base, offset, soffset) independently with & !3u32 before summing (matching RDNA2 silicon where soffset = 3, offset = 3 resolves to byte +0, not +4).
  3. VIC-BT-026 (crates/victory-shader/src/structure.rs): Evaluate s_cbranch_vccz / s_cbranch_vccnz on raw vcc instead of vcc & exec (matching RDNA2 scalar VCC branch semantics; v_cmp already writes vcc under exec).
  4. VIC-BT-030 (crates/victory-shader/src/emit/lower.rs, wave.rs): Mask the S1 lane-select operand of v_readlane_b32 and v_writelane_b32 to S1 & 31 (Wave32) / S1 & 63 (Wave64) before waveReadLaneAt / lane_id == lane.
  5. VIC-BT-031 (crates/victory-shader/src/emit/lower.rs): Lower v_writelane_b32 unconditionally without gating the destination write on EXEC so SGPR spills to inactive lanes in divergent control flow are preserved.

Testing

  • Added 6 synthetic unit/DXIL tests across resource.rs, structure.rs, emit/wave.rs, and emit/lower.rs.
  • cargo clippy -p victory-shader --all-targets — clean
  • cargo test -p victory-shader — 126 passed, 0 failed (1 ignored benchmark)
  • cargo xtask policy — 154 files ok

(AI-assisted implementation and verification.)

**@⁠wbkepler** on GitHub · 2026-11-24 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1336) `wbkepler:shader/rdna2-isa-and-rpo-fixes` → `main` · +381 −21 · 5 files · 2 commits · open ## Summary Fixes five RDNA2 shader ISA and CFG tracking bugs identified in #1249: 1. **`VIC-BT-024` (`crates/victory-shader/src/resource.rs`)**: Iterate `resource::track()` in `reverse_postorder(&p.blocks)` rather than raw vector index order so descriptor/waterfall `s_load`s in higher-indexed blocks (such as copies appended by `structure::split_irreducible()`) populate `out.scalar` before lower-indexed consumers inspect them. 2. **`VIC-BT-025` (`crates/victory-shader/src/emit/lower.rs`)**: Mask each `s_buffer_load_dword*` address term (`base`, `offset`, `soffset`) independently with `& !3u32` before summing (matching RDNA2 silicon where `soffset = 3, offset = 3` resolves to byte `+0`, not `+4`). 3. **`VIC-BT-026` (`crates/victory-shader/src/structure.rs`)**: Evaluate `s_cbranch_vccz` / `s_cbranch_vccnz` on raw `vcc` instead of `vcc & exec` (matching RDNA2 scalar VCC branch semantics; `v_cmp` already writes `vcc` under `exec`). 4. **`VIC-BT-030` (`crates/victory-shader/src/emit/lower.rs`, `wave.rs`)**: Mask the `S1` lane-select operand of `v_readlane_b32` and `v_writelane_b32` to `S1 & 31` (Wave32) / `S1 & 63` (Wave64) before `waveReadLaneAt` / `lane_id == lane`. 5. **`VIC-BT-031` (`crates/victory-shader/src/emit/lower.rs`)**: Lower `v_writelane_b32` unconditionally without gating the destination write on `EXEC` so SGPR spills to inactive lanes in divergent control flow are preserved. ## Testing - Added 6 synthetic unit/DXIL tests across `resource.rs`, `structure.rs`, `emit/wave.rs`, and `emit/lower.rs`. - `cargo clippy -p victory-shader --all-targets` — clean - `cargo test -p victory-shader` — 126 passed, 0 failed (1 ignored benchmark) - `cargo xtask policy` — 154 files ok *(AI-assisted implementation and verification.)*
A computed lane in a pixel or vertex program is a host lane, and a 64-lane
host wave runs past the console's 32 lanes, so only console lanes wrap at
the console wave. Spill tracking now compares the console lanes it matches
modulo the wave too, as the lowering does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:02 +00:00
Author
Owner

@⁠dpalacios69 on GitHub · 2026-11-24 18:26 UTC · original

Independent check on Linux of head da23e89, merged onto current main (ffe310e; a fast-forward): cargo test -p victory-shader --locked passes (102 passed, 0 failed, 1 ignored). The 6 test(s) it adds run on Linux and pass. cargo clippy -p victory-shader --all-targets -- -D warnings shows nothing of its own, only the two unused-import errors in emit/mod.rs that main already has on Linux. No GPU run. AI-assisted; no game data.

**@⁠dpalacios69** on GitHub · 2026-11-24 18:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1336#issuecomment-7140652301) Independent check on Linux of head `da23e89`, merged onto current `main` (`ffe310e`; a fast-forward): `cargo test -p victory-shader --locked` passes (102 passed, 0 failed, 1 ignored). The 6 test(s) it adds run on Linux and pass. `cargo clippy -p victory-shader --all-targets -- -D warnings` shows nothing of its own, only the two unused-import errors in `emit/mod.rs` that `main` already has on Linux. No GPU run. AI-assisted; no game data.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original

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

Result: no count change against main.

Offline. I merged head da23e89 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 126, 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 19:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1336#issuecomment-7142658617) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head da23e89 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 126, 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

@⁠wbkepler on GitHub · 2026-11-24 21:05 UTC · original

Follow-up pushed in 4eead6e, prompted by a comparison with #1312 by @⁠ashrafsdrop, who gets the credit for this exception:

  • v_readlane_b32 host lanes: this PR masked every lane index by the console wave. In a pixel or vertex program, a computed lane (MaskData::Host) is a host lane, so on a 64-lane AMD host wave the mask cut off lanes 32–63. Those lanes are now left unmasked, the same exception #1312 makes. Constant (console) lanes and v_writelane_b32 are still masked. This had no effect on 32-lane NVIDIA hosts.
  • Spill tracking (resource.rs): the v_writelane/v_readlane SGPR spill matcher now compares constant lanes modulo the wave too. Without that, a spill to lane 35 would not match its restore from lane 3 once the lowering wraps them.
  • New unit test a_computed_host_lane_in_a_pixel_program_is_not_masked: in a pixel program, a computed lane 35 reaches waveReadLaneAt as 35, not 3.

Verified with clippy -D warnings (victory-shader + victory diagnostics), cargo test -p victory-shader (127 passed) and cargo xtask policy.

Note for the maintainer: this PR and #1312 overlap on the readlane/writelane lane masking and the write_i change. Either one can land first, and the other will need a rebase.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

**@⁠wbkepler** on GitHub · 2026-11-24 21:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1336#issuecomment-7144453943) Follow-up pushed in `4eead6e`, prompted by a comparison with #1312 by @⁠ashrafsdrop, who gets the credit for this exception: - **`v_readlane_b32` host lanes:** this PR masked every lane index by the console wave. In a pixel or vertex program, a computed lane (`MaskData::Host`) is a *host* lane, so on a 64-lane AMD host wave the mask cut off lanes 32–63. Those lanes are now left unmasked, the same exception #1312 makes. Constant (console) lanes and `v_writelane_b32` are still masked. This had no effect on 32-lane NVIDIA hosts. - **Spill tracking (`resource.rs`):** the `v_writelane`/`v_readlane` SGPR spill matcher now compares constant lanes modulo the wave too. Without that, a spill to lane 35 would not match its restore from lane 3 once the lowering wraps them. - New unit test `a_computed_host_lane_in_a_pixel_program_is_not_masked`: in a pixel program, a computed lane 35 reaches `waveReadLaneAt` as 35, not 3. Verified with clippy `-D warnings` (victory-shader + victory diagnostics), `cargo test -p victory-shader` (127 passed) and `cargo xtask policy`. Note for the maintainer: this PR and #1312 overlap on the readlane/writelane lane masking and the `write_i` change. Either one can land first, and the other will need a rebase. _AI-assisted (Claude Code); checked on Windows 11 / RTX 5090._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:22 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/wave.rs, crates/victory-shader/src/structure.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/1336#issuecomment-7149486746) <!-- victory-triage v1 head=4eead6e1163c003d45305987c9b060d39e37c1de verdict=needs-rebase at=2026-11-25T01:22:53Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/wave.rs`, `crates/victory-shader/src/structure.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/bitcode.rs
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/wave.rs
  • crates/victory-shader/src/structure.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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