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

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

@⁠AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/v-movrel-m0-mask-8bit → main · +116 −6 · 2 files · 1 commits · open

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
**@⁠AscilCH** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1340) `AscilCH:fix/v-movrel-m0-mask-8bit` → `main` · +116 −6 · 2 files · 1 commits · open ### 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`
In crates/victory-shader/src/emit/lower.rs:
1. v_movrels_b32, v_movreld_b32, and v_movrelsd_b32 compared the full
   32-bit M0 register against each VGPR offset k instead of M0[7:0].
   On RDNA2 (GFX10.3), only the low 8 bits of M0 index relative VGPRs;
   any non-zero bits in M0[31:8] caused v_movrels_b32 to return 0 and
   v_movreld_b32/v_movrelsd_b32 to silently drop writes.
2. v_movreld_b32 required src0 to be a VGPR even though only dst is
   M0-indexed and src0 is a general VOP1 source (VGPR, SGPR, inline
   constant, or literal), rejecting valid instructions like
   `v_movreld_b32 v1, s0` and `v_movreld_b32 v1, 42`.

Fix:
- Mask M0 with 0xFF before comparing against VGPR offset k.
- Require Operand::Vector for src0 only on v_movrels_b32 and
  v_movrelsd_b32, allowing v_movreld_b32 to read any VOP1 source via
  src(inst, 0), and reject unsupported modifiers.
- Add hardware + WARP + dxil.dll test
  emit::valu_tests::v_movrel_masks_m0_and_accepts_scalar_src0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:11 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:33 UTC · original

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.

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

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1340#issuecomment-7149493002) <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1340#issuecomment-7149985531) ### 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.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/1340/head:github-bot/gh-1340'
git switch 'github-bot/gh-1340'

Merge

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