shader: lower v_movrelsd_2_b32 and v_swaprel_b32 #498

Open
NolanCotter wants to merge 2 commits from upstream-pr/498 into main
NolanCotter commented 2026-11-24 04:08:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NolanCotter on 2026-11-24T04:08:45Z.


Depends on #404 (shares the lowers_lds test helper; rebases to one commit once it lands).

Summary

  • Lowers v_movrelsd_2_b32 and v_swaprel_b32 — the two M0-relative VGPR ops the IR already enumerates (ir.rs marks both (true, true) and v_swaprel_b32's src range as a write) but the emitter refused at integer()'s fallthrough.
  • Both split M0 in two fields: the source's offset is M0[9:0], the destination's M0[25:16] — the RDNA2 ISA's opcode description. The existing movrels select chains factor into read_at/write_at closures and the plain movrel forms keep the whole-M0 index.
  • v_swaprel_b32 writes both operand ranges, so a register can carry two write tokens (reads resolve to the last): write_at picks first/last token and seeds the old value from what an earlier chain wrote, which also makes a swap of equal indices a no-op.
  • Smoke test m0_split_relative_moves hand-encodes v[5+20] = v[1+10] / v[5+20] <-> v[1+10] with M0 = (20 << 16) | 10 feeding an LDS store; refused on main, lowers now.

Test plan

  • cargo test -p victory-shader — 58 passed
  • cargo clippy -p victory-shader — clean
  • cargo fmt --check — clean

AI-assisted (Devin). Field split verified against the RDNA2 ISA opcode description (source M0[9:0], destination M0[25:16]); no game files used.

Generated with Devin

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574399203 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T04:08:45Z. --- Depends on #404 (shares the `lowers_lds` test helper; rebases to one commit once it lands). ## Summary - Lowers `v_movrelsd_2_b32` and `v_swaprel_b32` — the two M0-relative VGPR ops the IR already enumerates (ir.rs marks both `(true, true)` and `v_swaprel_b32`'s src range as a write) but the emitter refused at `integer()`'s fallthrough. - Both split M0 in two fields: the source's offset is M0[9:0], the destination's M0[25:16] — the RDNA2 ISA's opcode description. The existing movrels select chains factor into `read_at`/`write_at` closures and the plain movrel forms keep the whole-M0 index. - `v_swaprel_b32` writes both operand ranges, so a register can carry two write tokens (reads resolve to the last): `write_at` picks first/last token and seeds the old value from what an earlier chain wrote, which also makes a swap of equal indices a no-op. - Smoke test `m0_split_relative_moves` hand-encodes `v[5+20] = v[1+10]` / `v[5+20] <-> v[1+10]` with M0 = (20 << 16) | 10 feeding an LDS store; refused on main, lowers now. #### Test plan - [x] `cargo test -p victory-shader` — 58 passed - [x] `cargo clippy -p victory-shader` — clean - [x] `cargo fmt --check` — clean AI-assisted (Devin). Field split verified against the RDNA2 ISA opcode description (source M0[9:0], destination M0[25:16]); no game files used. Generated with [Devin](https://devin.ai)
LAKSHYA-cmd-tech commented 2026-11-24 06:53:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T04:50:02Z.

Review: APPROVED


Verified on Windows 11 D3D12:

  • All 71 tests in \ ictory-shader\ pass, including \m0_split_relative_moves.
  • Relative VGPR addressing with M0 source/dest field splits matches RDNA2 ISA opcode specifications.
  • \cargo clippy -p victory-shader\ clean with zero warnings.
  • \cargo xtask policy\ passes (151 files checked, zero asset policy violations).
<!-- greyfinch-sync:Marvisak/VIctory:review:6033803172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#pullrequestreview-6033803172). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T04:50:02Z. **Review:** APPROVED --- Verified on Windows 11 D3D12: - All 71 tests in \ ictory-shader\ pass, including \m0_split_relative_moves\. - Relative VGPR addressing with M0 source/dest field splits matches RDNA2 ISA opcode specifications. - \cargo clippy -p victory-shader\ clean with zero warnings. - \cargo xtask policy\ passes (151 files checked, zero asset policy violations).
Lyrnc commented 2026-11-24 06:56:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T05:53:52Z.


RDNA2 hardware measurement of the M0 split: it matches this PR.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) fills v10..v25 with distinct values, sets M0, and runs one op v12, v11 per run, for 11 M0 values. Reading back all 16 registers shows which one was written from which. RDNA2 desktop silicon, not the console's. No game data.

M0 v_movrelsd_2_b32 v12, v11 v_swaprel_b32 v12, v11
0x00000000 v12 = v11 v11 <-> v12
0x00000001 v12 = v12 (no change) no change (same register)
0x00010000 v13 = v11 v11 <-> v13
0x00030002 v15 = v13 v13 <-> v15
0x00050003 v17 = v14 v14 <-> v17
0x000a0004 v22 = v15 v15 <-> v22
0x00070007 v19 = v18 v18 <-> v19
0x0000fc01 v12 = v12 (no change) no change
0x00020400 v14 = v11 v11 <-> v14
0xfc020001 v14 = v12 v12 <-> v14
0x04000003 v12 = v14 v12 <-> v14
  • The source offset is M0[9:0] and the destination offset M0[25:16], as in your lowering. Bits 10-15 and 26-31 are ignored: rows 0x0000fc01, 0x00020400, 0xfc020001 and 0x04000003.
  • v_swaprel_b32 writes both registers, and with equal indices it changes nothing. That is the no-op your write_at token handling gives.
  • No other register in v10..v25 changed in any run.

For reference, in the same runs v_movrels_b32, v_movreld_b32 and v_movrelsd_b32 used the whole M0 as the index. With M0 = 0x00010000 the source is far outside the allocation, and v_movrels_b32 read 0.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123377684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7123377684). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T05:53:52Z. --- RDNA2 hardware measurement of the M0 split: **it matches this PR.** **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) fills `v10..v25` with distinct values, sets M0, and runs one `op v12, v11` per run, for 11 M0 values. Reading back all 16 registers shows which one was written from which. RDNA2 desktop silicon, not the console's. No game data. | M0 | `v_movrelsd_2_b32 v12, v11` | `v_swaprel_b32 v12, v11` | |---|---|---| | `0x00000000` | v12 = v11 | v11 <-> v12 | | `0x00000001` | v12 = v12 (no change) | no change (same register) | | `0x00010000` | v13 = v11 | v11 <-> v13 | | `0x00030002` | v15 = v13 | v13 <-> v15 | | `0x00050003` | v17 = v14 | v14 <-> v17 | | `0x000a0004` | v22 = v15 | v15 <-> v22 | | `0x00070007` | v19 = v18 | v18 <-> v19 | | `0x0000fc01` | v12 = v12 (no change) | no change | | `0x00020400` | v14 = v11 | v11 <-> v14 | | `0xfc020001` | v14 = v12 | v12 <-> v14 | | `0x04000003` | v12 = v14 | v12 <-> v14 | - The source offset is M0[9:0] and the destination offset M0[25:16], as in your lowering. Bits 10-15 and 26-31 are ignored: rows `0x0000fc01`, `0x00020400`, `0xfc020001` and `0x04000003`. - `v_swaprel_b32` writes both registers, and with equal indices it changes nothing. That is the no-op your `write_at` token handling gives. - No other register in `v10..v25` changed in any run. For reference, in the same runs `v_movrels_b32`, `v_movreld_b32` and `v_movrelsd_b32` used the whole M0 as the index. With M0 = `0x00010000` the source is far outside the allocation, and `v_movrels_b32` read 0. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
slint6614-dev commented 2026-11-24 11:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T10:42:33Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417).

CS 1441 / 1418 (+1 validated); VS/PS and MS unchanged.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129139485 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7129139485). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T10:42:33Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current main c7a5f49 (main: CS 1440 / 1417). CS 1441 / **1418** (+1 validated); VS/PS and MS unchanged.
mercuryVM commented 2026-11-24 13:01:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:23:08Z.

Review: APPROVED


Tested 4f48c59 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 passes as part of the #576 stack (72 passed), including m0_split_relative_moves. cargo clippy -p victory-shader --all-targets is clean. This commit is on mercuryVM/VIctory main via #576.

  • The M0 split is right per the RDNA2 ISA: the source offset is M0[9:0] and the destination M0[25:16] for both v_movrelsd_2_b32 and v_swaprel_b32. The other movrel forms keep the full M0.
  • Overlap: #627 (now updated, and also correct) lowers the same two VOP1 forms plus s_movrelsd_2_b32. Only one should land. If this one goes first, #627 shrinks to the SOP1 form.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039118424 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#pullrequestreview-6039118424). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T12:23:08Z. **Review:** APPROVED --- Tested 4f48c59 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` passes as part of the #576 stack (72 passed), including `m0_split_relative_moves`. `cargo clippy -p victory-shader --all-targets` is clean. This commit is on mercuryVM/VIctory main via #576. - The M0 split is right per the RDNA2 ISA: the source offset is `M0[9:0]` and the destination `M0[25:16]` for both `v_movrelsd_2_b32` and `v_swaprel_b32`. The other movrel forms keep the full M0. - Overlap: #627 (now updated, and also correct) lowers the same two VOP1 forms plus `s_movrelsd_2_b32`. Only one should land. If this one goes first, #627 shrinks to the SOP1 form. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 13:02:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:36:16Z.


Triage note: this overlaps #627, which implements the same instructions (v_swaprel_b32, v_movrelsd_2_b32, plus s_movrelsd_2_b32) with ir.rs effects tracking and a round-trip test, and currently merges cleanly with main. This PR (#498) has mergeable=false against current main (ffe310e). Whichever the maintainer prefers, the other needs a rebase — flagging so review effort isn't duplicated.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131669765 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7131669765). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:36:16Z. --- Triage note: this overlaps **#627**, which implements the same instructions (`v_swaprel_b32`, `v_movrelsd_2_b32`, plus `s_movrelsd_2_b32`) with `ir.rs` effects tracking and a round-trip test, and currently merges cleanly with main. This PR (#498) has `mergeable=false` against current main (`ffe310e`). Whichever the maintainer prefers, the other needs a rebase — flagging so review effort isn't duplicated.
DrDarkDK commented 2026-11-24 14:04:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-24T13:40:06Z.


I reran the dynamic-M0 readback fixture from #775 on this PR’s head (4f48c59). On native Windows 11, v_swaprel_b32 and v_movrelsd_2_b32 returned the expected values across all four M0 inputs per instruction on both RTX 4070 Ti (621.01) and WARP. The fixture sets M0 from a root constant and varies it between dispatches of the same shader. No adapter skips.

m0_split_relative_moves also passed. Synthetic tests only. AI-assisted testing and reporting.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133161521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7133161521). Originally posted by [DrDarkDK](https://github.com/DrDarkDK) on 2026-11-24T13:40:06Z. --- I reran the dynamic-M0 readback fixture from #775 on this PR’s head (`4f48c59`). On native Windows 11, `v_swaprel_b32` and `v_movrelsd_2_b32` returned the expected values across all four M0 inputs per instruction on both RTX 4070 Ti (621.01) and WARP. The fixture sets M0 from a root constant and varies it between dispatches of the same shader. No adapter skips. `m0_split_relative_moves` also passed. Synthetic tests only. AI-assisted testing and reporting.
Yaekai commented 2026-11-24 17:04:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Yaekai on 2026-11-24T16:40:52Z.


Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head 4f48c59:

  • cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 64 passed, 0 failed.
  • cargo clippy -p victory-shader -- -D warnings: 0 warnings.
  • Live GTA VI (1.0.2.1, --console series-s, 19-min world run): no regressions. Ready to merge once rebased on main!
<!-- greyfinch-sync:Marvisak/VIctory:comment:7138042334 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7138042334). Originally posted by [Yaekai](https://github.com/Yaekai) on 2026-11-24T16:40:52Z. --- Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head `4f48c59`: - `cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests`: 64 passed, 0 failed. - `cargo clippy -p victory-shader -- -D warnings`: 0 warnings. - Live GTA VI (`1.0.2.1`, `--console series-s`, 19-min world run): no regressions. Ready to merge once rebased on `main`!
Marvisak commented 2026-11-25 01:07:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:21:31Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148425283 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7148425283). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:21:31Z. --- <!-- victory-triage v1 head=4f48c59608ca01359f1058ab4fa6bc9175862e57 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
andrewpozdnakov7-jpg commented 2026-11-25 12:03:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T11:39:53Z.


I extracted the v_movrelsd_2_b32 portion of 4f48c59 onto 940d32f in 20828f1 with the original Git author intact. The existing move code uses the source and destination M0 fields for this opcode. The separate swap PR #1569 merges cleanly with this branch.

f150609 reads back three destination registers for four synthetic M0 values. 940d32f rejected the instruction as Unsupported. On the rebase all 12 WARP results match, including differing source and destination offsets, unrelated M0 bits, and unchanged neighboring registers. All 29 VALU tests pass with Microsoft DXIL validation. Strict shader Clippy and staged asset policy pass.

If you adopt the readback in a combined commit, please retain Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. Claim

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161339234 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/498#issuecomment-7161339234). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T11:39:53Z. --- I extracted the `v_movrelsd_2_b32` portion of `4f48c59` onto `940d32f` in [`20828f1`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/20828f1c9638396b75227c31a6d19d8f192445c1) with the original Git author intact. The existing move code uses the source and destination M0 fields for this opcode. The separate swap PR #1569 merges cleanly with this branch. [`f150609`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/f1506097027a7a3ab06df4a9e5dbce08b48b7998) reads back three destination registers for four synthetic M0 values. `940d32f` rejected the instruction as `Unsupported`. On the rebase all 12 WARP results match, including differing source and destination offsets, unrelated M0 bits, and unchanged neighboring registers. All 29 VALU tests pass with Microsoft DXIL validation. Strict shader Clippy and staged asset policy pass. If you adopt the readback in a combined commit, please retain `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. [Claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7161267263)
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/498:upstream-pr/498'
git switch 'upstream-pr/498'

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