feat(victory-shader): implement s_movrels_b32 and s_movreld_b32 lowering #608

Closed
github-bot wants to merge 2 commits from gh-pr/608/head into gh-pr/608/base
Owner

@⁠Amit89-beep on GitHub · 2026-11-24 05:29 UTC · original
Amit89-beep:fix/s-movrel-lowering → main · +233 −82 · 3 files · 2 commits · closed without merging

Summary

Implements IR lowering and DXIL emission support for GFX10 scalar relative-indexing move instructions (s_movrels_b32 and s_movreld_b32) in victory-shader, replacing the previous ShaderError::Unsupported path.

Changes

  • IR Lowering (crates/victory-shader/src/ir.rs):
    • Implemented s_movrels_b32 (sdst = sgpr[src_base + m0]) for relative scalar source reads indexed by M0.
    • Implemented s_movreld_b32 (sgpr[dst_base + m0] = ssrc) for relative scalar destination writes indexed by M0.
    • Added SGPR index bounds clamping/masking so out-of-range M0 offsets cannot produce out-of-bounds SGPR accesses or invalid DXIL IR.
  • Tests:
    • Added unit tests covering static and dynamic M0 offsets for both s_movrels_b32 and s_movreld_b32, verifying round-trip register updates and DXIL emission/validation.

Verification

  • cargo fmt --check
  • cargo clippy -p victory-shader --all-targets
  • cargo test -p victory-shader
**@⁠Amit89-beep** on GitHub · 2026-11-24 05:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/608) `Amit89-beep:fix/s-movrel-lowering` → `main` · +233 −82 · 3 files · 2 commits · closed without merging ## Summary Implements IR lowering and DXIL emission support for GFX10 scalar relative-indexing move instructions (`s_movrels_b32` and `s_movreld_b32`) in `victory-shader`, replacing the previous `ShaderError::Unsupported` path. ## Changes - **IR Lowering (`crates/victory-shader/src/ir.rs`):** - Implemented `s_movrels_b32` (`sdst = sgpr[src_base + m0]`) for relative scalar source reads indexed by `M0`. - Implemented `s_movreld_b32` (`sgpr[dst_base + m0] = ssrc`) for relative scalar destination writes indexed by `M0`. - Added SGPR index bounds clamping/masking so out-of-range `M0` offsets cannot produce out-of-bounds SGPR accesses or invalid DXIL IR. - **Tests:** - Added unit tests covering static and dynamic `M0` offsets for both `s_movrels_b32` and `s_movreld_b32`, verifying round-trip register updates and DXIL emission/validation. ## Verification - `cargo fmt --check` - `cargo clippy -p victory-shader --all-targets` - `cargo test -p victory-shader`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:09:52 +00:00
github-bot closed this pull request 2026-11-26 04:09:52 +00:00
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:02 UTC · original

RDNA2 hardware check of the two rules: they match.

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 s20..s35 with distinct values, sets M0, runs one instruction and reads all 16 back. RDNA2 desktop silicon, not the console's. No game data.

Instruction M0 = 0 M0 = 1 M0 = 2 M0 = 3
s_movrels_b32 s22, s21 s22 = s21 s22 = s22 (no change) s22 = s23 s22 = s24
s_movreld_b32 s22, s21 s22 = s21 s23 = s21 s24 = s21 s25 = s21

So sdst = s[src + M0] and s[dst + M0] = src with the whole M0, as here. Nothing else in the window changed.

Out of range: with M0 = 0x00010000 or 0x41, s_movrels_b32 read values that are none of the window's (0x057a9400, 0x35a00002), and s_movreld_b32 changed nothing in the window. So the hardware gives no defined result there, and your clamping is a choice rather than a semantic.

In case a follow-up adds the 64-bit forms: in the same runs s_movrels_b64 / s_movreld_b64 rounded the index down to even (M0 = 1 behaves as 0, 3 as 2).

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.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/608#issuecomment-7123512312) RDNA2 hardware check of the two rules: **they match.** **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 `s20..s35` with distinct values, sets M0, runs one instruction and reads all 16 back. RDNA2 desktop silicon, not the console's. No game data. | Instruction | M0 = 0 | M0 = 1 | M0 = 2 | M0 = 3 | |---|---|---|---|---| | `s_movrels_b32 s22, s21` | s22 = s21 | s22 = s22 (no change) | s22 = s23 | s22 = s24 | | `s_movreld_b32 s22, s21` | s22 = s21 | s23 = s21 | s24 = s21 | s25 = s21 | So `sdst = s[src + M0]` and `s[dst + M0] = src` with the whole M0, as here. Nothing else in the window changed. Out of range: with M0 = `0x00010000` or `0x41`, `s_movrels_b32` read values that are none of the window's (`0x057a9400`, `0x35a00002`), and `s_movreld_b32` changed nothing in the window. So the hardware gives no defined result there, and your clamping is a choice rather than a semantic. In case a follow-up adds the 64-bit forms: in the same runs `s_movrels_b64` / `s_movreld_b64` rounded the index down to even (M0 = 1 behaves as 0, 3 as 2). 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.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:24 UTC · original

Merged onto main @ ffe310eb, this PR (cc6b6984) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7443 (and 7455, 7466, 7478, 7490) calls the lowers(&words) test helper. Since 25b0f888 it is lowers(words, rsrc2); main's tests pass 0. Clippy also flags half_shift as an unused import at lower.rs:7031.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

**@⁠alexdeliu** on GitHub · 2026-11-24 17:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/608#issuecomment-7139137451) Merged onto `main` @ `ffe310eb`, this PR (`cc6b6984`) no longer compiles its tests. `crates/victory-shader/src/emit/lower.rs:7443` (and 7455, 7466, 7478, 7490) calls the `lowers(&words)` test helper. Since 25b0f888 it is `lowers(words, rsrc2)`; main's tests pass `0`. Clippy also flags `half_shift` as an unused import at `lower.rs:7031`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:26 UTC · original

Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/608#issuecomment-7148505147) Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!608
No description provided.