Shaders: lower v_swaprel_b32 and v_movrelsd_2_b32 (fix ready on a fork) #775

Open
opened 2026-11-26 04:13:57 +00:00 by github-bot · 3 comments
Owner

@⁠talakasse on GitHub · 2026-11-24 10:15 UTC · original

Pull requests are limited to collaborators, so I'm posting this here. The fix is one commit on top of current main, and GitHub reports that it merges cleanly:

Branch: https://github.com/talakasse/VIctory/tree/shader/swaprel
Commit: github.com/talakasse/VIctory@647eb52bed

git fetch https://github.com/talakasse/VIctory.git shader/swaprel
git cherry-pick 647eb52

What

The IR already modelled v_swaprel_b32 and v_movrelsd_2_b32 as M0-relative accesses (reads and writes over the range from the encoded register up to the program's VGPR count). The emitter did not handle either opcode. Their results became missing values, and any shader that used them failed to translate as soon as an effect read one.

  • v_movrelsd_2_b32: v[dst + M0[25:16]] = v[src + M0[9:0]]. This shares the v_movrel* lowering, which now takes separate source and destination indices.
  • v_swaprel_b32: swaps v[dst + M0[25:16]] and v[src + M0[9:0]]. The destination is written first and the source last, as on the console, so a register named by both keeps its value.
  • Helpers: the select chain over an M0-relative range moves into rel_read, alongside m0_halves and old_vgpr, and is shared with the existing v_movrel* arms.

IR fix

ir::effects deduplicated an instruction's reads but not its writes. For v_swaprel_b32 the two indexed ranges always overlap up to the last VGPR, so every register in the overlap was written twice. That gave it two SSA values: Inst::write returned the first one, while later readers saw the second, which was never defined ("a value defined after its use"). v_swap_b32 vN, vN had the same problem. Writes are now deduplicated the same way reads are.

Tests

  • emit::lower::tests::m0_relative_moves_with_two_indices_translate (all platforms): both opcodes, followed by an LDS store of their result, must lower. It fails without this change.
  • emit::valu_tests::m0_relative_swaps_and_moves_index_source_and_destination_apart (Windows, hardware and WARP): seven cases that check the values read back:
    • swaps in both directions;
    • both indices naming the same register;
    • v_movrelsd_2_b32 with every ignored M0 bit set.

Checked

  • cargo test -p victory-shader passes (97 tests), run on macOS on top of ffe310e.
  • cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings is clean.
  • The Windows GPU test and the rest of the workspace were not run locally.
  • The semantics follow the RDNA2 ISA reference. No capture from a title using these opcodes has been checked.

🤖 Generated with Claude Code

**@⁠talakasse** on GitHub · 2026-11-24 10:15 UTC · [original](https://github.com/Marvisak/VIctory/issues/775) Pull requests are limited to collaborators, so I'm posting this here. The fix is one commit on top of current `main`, and GitHub reports that it merges cleanly: **Branch:** https://github.com/talakasse/VIctory/tree/shader/swaprel **Commit:** https://github.com/talakasse/VIctory/commit/647eb52bed3f5ed77588cc60b949412b7ddaf586 ``` git fetch https://github.com/talakasse/VIctory.git shader/swaprel git cherry-pick 647eb52 ``` ## What The IR already modelled `v_swaprel_b32` and `v_movrelsd_2_b32` as M0-relative accesses (reads and writes over the range from the encoded register up to the program's VGPR count). The emitter did not handle either opcode. Their results became missing values, and any shader that used them failed to translate as soon as an effect read one. - **`v_movrelsd_2_b32`**: `v[dst + M0[25:16]] = v[src + M0[9:0]]`. This shares the `v_movrel*` lowering, which now takes separate source and destination indices. - **`v_swaprel_b32`**: swaps `v[dst + M0[25:16]]` and `v[src + M0[9:0]]`. The destination is written first and the source last, as on the console, so a register named by both keeps its value. - **Helpers**: the select chain over an M0-relative range moves into `rel_read`, alongside `m0_halves` and `old_vgpr`, and is shared with the existing `v_movrel*` arms. ## IR fix `ir::effects` deduplicated an instruction's reads but not its writes. For `v_swaprel_b32` the two indexed ranges always overlap up to the last VGPR, so every register in the overlap was written twice. That gave it two SSA values: `Inst::write` returned the first one, while later readers saw the second, which was never defined ("a value defined after its use"). `v_swap_b32 vN, vN` had the same problem. Writes are now deduplicated the same way reads are. ## Tests - **`emit::lower::tests::m0_relative_moves_with_two_indices_translate`** (all platforms): both opcodes, followed by an LDS store of their result, must lower. It fails without this change. - **`emit::valu_tests::m0_relative_swaps_and_moves_index_source_and_destination_apart`** (Windows, hardware and WARP): seven cases that check the values read back: - swaps in both directions; - both indices naming the same register; - `v_movrelsd_2_b32` with every ignored M0 bit set. ## Checked - `cargo test -p victory-shader` passes (97 tests), run on macOS on top of `ffe310e`. - `cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings` is clean. - The Windows GPU test and the rest of the workspace were **not** run locally. - The semantics follow the RDNA2 ISA reference. No capture from a title using these opcodes has been checked. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:57 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 10:28 UTC · original

Tested 647eb52 on native Windows 11 with an RTX 4070 Ti (driver 621.01) and software WARP. Both m0_relative tests passed, with no adapter skips.

I also ran a synthetic readback test that supplies M0 as a root constant and varies it between dispatches of the same shader. Both v_swaprel_b32 and v_movrelsd_2_b32 returned the expected values on both adapters. The same fixture fails to lower on the exact parent ffe310e, which reports v_swaprel_b32 as unsupported.

Offline comparison with DXIL validator 1.9.2602.17 found identical outcomes and diagnostics for all 25,901 matched program keys. Both revisions scanned 26,096 programs and validated 21,736. No gameplay test. AI-assisted testing and reporting.

**@⁠DrDarkDK** on GitHub · 2026-11-24 10:28 UTC · [original](https://github.com/Marvisak/VIctory/issues/775#issuecomment-7128832685) Tested `647eb52` on native Windows 11 with an RTX 4070 Ti (driver 621.01) and software WARP. Both `m0_relative` tests passed, with no adapter skips. I also ran a synthetic readback test that supplies `M0` as a root constant and varies it between dispatches of the same shader. Both `v_swaprel_b32` and `v_movrelsd_2_b32` returned the expected values on both adapters. The same fixture fails to lower on the exact parent `ffe310e`, which reports `v_swaprel_b32` as unsupported. Offline comparison with DXIL validator 1.9.2602.17 found identical outcomes and diagnostics for all 25,901 matched program keys. Both revisions scanned 26,096 programs and validated 21,736. No gameplay test. AI-assisted testing and reporting.
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 13:09 UTC · original

There are already two open PRs for these two instructions: #498 (NolanCotter, "lower v_movrelsd_2_b32 and v_swaprel_b32", splits M0 into [9:0] and [25:16] as the ISA describes) and #627 (also adds s_movrelsd_2_b32). DrDarkDK's results above would be worth repeating on #498, since it's the oldest and the closest to this branch. Then one version can be picked.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 13:09 UTC · [original](https://github.com/Marvisak/VIctory/issues/775#issuecomment-7132419065) There are already two open PRs for these two instructions: #498 (NolanCotter, "lower v_movrelsd_2_b32 and v_swaprel_b32", splits M0 into [9:0] and [25:16] as the ISA describes) and #627 (also adds `s_movrelsd_2_b32`). DrDarkDK's results above would be worth repeating on #498, since it's the oldest and the closest to this branch. Then one version can be picked.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:51 UTC · original

Automated triage for the maintainers.

Confirmed on main: the IR models v_swaprel_b32 and v_movrelsd_2_b32 (crates/victory-shader/src/ir.rs), but the emitter's M0-relative arm in crates/victory-shader/src/emit/lower.rs handles only v_movrels_b32, v_movreld_b32 and v_movrelsd_b32, so programs using either opcode do not translate.

Open pull request #498 already lowers both instructions. Please compare your branch with it and comment there, in particular on the ir::effects write deduplication, which may not be in #498. Or open your own pull request if yours differs. DrDarkDK's hardware results above would be worth repeating on #498.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:51 UTC · [original](https://github.com/Marvisak/VIctory/issues/775#issuecomment-7152311689) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T13:09:02Z at=2026-11-25T03:51:53Z --> Automated triage for the maintainers. Confirmed on `main`: the IR models `v_swaprel_b32` and `v_movrelsd_2_b32` (`crates/victory-shader/src/ir.rs`), but the emitter's M0-relative arm in `crates/victory-shader/src/emit/lower.rs` handles only `v_movrels_b32`, `v_movreld_b32` and `v_movrelsd_b32`, so programs using either opcode do not translate. Open pull request #498 already lowers both instructions. Please compare your branch with it and comment there, in particular on the `ir::effects` write deduplication, which may not be in #498. Or open your own pull request if yours differs. DrDarkDK's hardware results above would be worth repeating on #498. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#775
No description provided.