Shaders: mask M0[7:0] on v_movrel* and allow scalar/const src0 on v_movreld_b32 #1340

Open
AscilCH wants to merge 1 commit from upstream-pr/1340 into main
AscilCH commented 2026-11-24 17:33:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T17:33:12Z.


Bugs

In crates/victory-shader/src/emit/lower.rs, the M0-relative VGPR move instructions had two issues against the RDNA2 (GFX10.3) ISA:

  1. v_movrels_b32, v_movreld_b32, and v_movrelsd_b32 compared the full 32-bit M0 register instead of M0[7:0] (& 0xFF). On RDNA2, relative VGPR indexing only uses the low 8 bits of M0; any non-zero bits in M0[31:8] caused v_movrels_b32 to read 0 and v_movreld_b32/v_movrelsd_b32 to silently drop writes.
  2. v_movreld_b32 rejected non-VGPR src0 operands with Unsupported { what: "an M0-relative move" }, even though only vdst is M0-indexed on RDNA2 and src0 is any general VOP1 source (VGPR, SGPR, inline constant, or literal).

Reproduction (Before Fix)

With a synthetic RDNA2 compute shader lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, Windows 11) and WARP:

hardware: v_movrels_b32(m0=0x00010002) = 0x00000000, want 0x33330002

And lowering v_movreld_b32 v1, s0 or v_movreld_b32 v1, 42 failed with Unsupported { what: "an M0-relative move" }.

Fix

  • Mask M0 with 0xFF before comparing against each VGPR offset k.
  • Require Operand::Vector on src0 only when indexed_src (v_movrels_b32 / v_movrelsd_b32); read v_movreld_b32 src0 via s(self, 0)? so SGPRs, inline constants, and literals work, and reject unsupported modifiers.
  • Added hardware + WARP + dxil.dll test emit::valu_tests::v_movrel_masks_m0_and_accepts_scalar_src0 testing M0[31:8] != 0 across v_movrels_b32, v_movreld_b32, and v_movrelsd_b32, plus SGPR and inline-constant src0 on v_movreld_b32.

Verification

Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK dxil.dll:

  • rustfmt --edition 2024 --check on valu_tests.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- v_movrel_masks_m0_and_accepts_scalar_src0 --nocapture --test-threads=1: passed (hardware + WARP + dxil.dll)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587698473 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1340). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T17:33:12Z. --- ### Bugs In `crates/victory-shader/src/emit/lower.rs`, the M0-relative VGPR move instructions had two issues against the RDNA2 (GFX10.3) ISA: 1. **`v_movrels_b32`, `v_movreld_b32`, and `v_movrelsd_b32` compared the full 32-bit `M0` register** instead of `M0[7:0]` (`& 0xFF`). On RDNA2, relative VGPR indexing only uses the low 8 bits of `M0`; any non-zero bits in `M0[31:8]` caused `v_movrels_b32` to read `0` and `v_movreld_b32`/`v_movrelsd_b32` to silently drop writes. 2. **`v_movreld_b32` rejected non-VGPR `src0` operands** with `Unsupported { what: "an M0-relative move" }`, even though only `vdst` is M0-indexed on RDNA2 and `src0` is any general VOP1 source (VGPR, SGPR, inline constant, or literal). ### Reproduction (Before Fix) With a synthetic RDNA2 compute shader lowered to DXIL and executed on hardware (NVIDIA RTX 3050 6GB Laptop GPU, Windows 11) and WARP: ```text hardware: v_movrels_b32(m0=0x00010002) = 0x00000000, want 0x33330002 ``` And lowering `v_movreld_b32 v1, s0` or `v_movreld_b32 v1, 42` failed with `Unsupported { what: "an M0-relative move" }`. ### Fix - Mask `M0` with `0xFF` before comparing against each VGPR offset `k`. - Require `Operand::Vector` on `src0` only when `indexed_src` (`v_movrels_b32` / `v_movrelsd_b32`); read `v_movreld_b32` `src0` via `s(self, 0)?` so SGPRs, inline constants, and literals work, and reject unsupported modifiers. - Added hardware + WARP + `dxil.dll` test `emit::valu_tests::v_movrel_masks_m0_and_accepts_scalar_src0` testing `M0[31:8] != 0` across `v_movrels_b32`, `v_movreld_b32`, and `v_movrelsd_b32`, plus SGPR and inline-constant `src0` on `v_movreld_b32`. ### Verification Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK `dxil.dll`: - `rustfmt --edition 2024 --check` on `valu_tests.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- v_movrel_masks_m0_and_accepts_scalar_src0 --nocapture --test-threads=1`: passed (hardware + WARP + `dxil.dll`) - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `121 passed, 0 failed, 1 ignored`
marquezinii commented 2026-11-24 19:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:33:49Z.


Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 89189ec. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 121 passed, 0 failed, 1 ignored. v_movrel_masks_m0_and_accepts_scalar_src0 passes on the hardware adapter and WARP.

A question on the main claim. The tests check the M0[7:0] masking against the translation's own reference, so they show the lowering does what the PR intends, not what the hardware does. Which part of the RDNA 2 ISA document says only M0[7:0] is used for the relative VGPR index? The instruction descriptions I know write it as VGPR[S0 + M0]. A citation, or a native run like the D16 probes on #1437/#1441, would settle it. The src0 part (an SGPR or a constant as the source of v_movreld_b32) is independent and looks right to me.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140819299 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1340#issuecomment-7140819299). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:33:49Z. --- Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `89189ec`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 121 passed, 0 failed, 1 ignored. `v_movrel_masks_m0_and_accepts_scalar_src0` passes on the hardware adapter and WARP. A question on the main claim. The tests check the `M0[7:0]` masking against the translation's own reference, so they show the lowering does what the PR intends, not what the hardware does. Which part of the RDNA 2 ISA document says only `M0[7:0]` is used for the relative VGPR index? The instruction descriptions I know write it as `VGPR[S0 + M0]`. A citation, or a native run like the D16 probes on #1437/#1441, would settle it. The `src0` part (an SGPR or a constant as the source of `v_movreld_b32`) is independent and looks right to me.
catminou4 commented 2026-11-24 21:02:10 +00:00 (Migrated from github.com)

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

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 → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Masks M0[7:0] on v_movrel* and allows scalar/const src0 on v_movreld; v_movrel_masks_m0_and_accepts_scalar_src0.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046559883 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1340#pullrequestreview-6046559883). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:59Z. **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 → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Masks M0[7:0] on v_movrel* and allows scalar/const src0 on v_movreld; v_movrel_masks_m0_and_accepts_scalar_src0.
Marvisak commented 2026-11-25 02:05:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:23:17Z.


Automated triage for the maintainers.

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


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149493002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1340#issuecomment-7149493002). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:23:17Z. --- <!-- victory-triage v1 head=89189ecdbef26c3e3e76131529843bd0aa6a3b64 verdict=needs-rebase at=2026-11-25T01:23:16Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 02:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:47Z.


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

Result: no count change against main.

Offline. I merged head 89189ec 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:7149985531 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1340#issuecomment-7149985531). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:48:47Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 89189ec 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).
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/1340:upstream-pr/1340'
git switch 'upstream-pr/1340'

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/1340'
git switch 'upstream-pr/1340'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1340'
git switch 'upstream-pr/1340'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1340'
git switch 'main'
git merge --squash 'upstream-pr/1340'
git switch 'main'
git merge --ff-only 'upstream-pr/1340'
git switch 'main'
git merge 'upstream-pr/1340'
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!1340
No description provided.