Shaders: lower v_swaprel_b32 and v_movrelsd_2_b32 (fix ready on a fork) #775
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by talakasse on 2026-11-24T10:15:14Z.
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@647eb52bedWhat
The IR already modelled
v_swaprel_b32andv_movrelsd_2_b32as 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 thev_movrel*lowering, which now takes separate source and destination indices.v_swaprel_b32: swapsv[dst + M0[25:16]]andv[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.rel_read, alongsidem0_halvesandold_vgpr, and is shared with the existingv_movrel*arms.IR fix
ir::effectsdeduplicated an instruction's reads but not its writes. Forv_swaprel_b32the 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::writereturned the first one, while later readers saw the second, which was never defined ("a value defined after its use").v_swap_b32 vN, vNhad 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:v_movrelsd_2_b32with every ignored M0 bit set.Checked
cargo test -p victory-shaderpasses (97 tests), run on macOS on top offfe310e.cargo clippy -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warningsis clean.🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-24T10:28:38Z.
Tested
647eb52on native Windows 11 with an RTX 4070 Ti (driver 621.01) and software WARP. Bothm0_relativetests passed, with no adapter skips.I also ran a synthetic readback test that supplies
M0as a root constant and varies it between dispatches of the same shader. Bothv_swaprel_b32andv_movrelsd_2_b32returned the expected values on both adapters. The same fixture fails to lower on the exact parentffe310e, which reportsv_swaprel_b32as 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.
Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T13:09:02Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:51:54Z.
Automated triage for the maintainers.
Confirmed on
main: the IR modelsv_swaprel_b32andv_movrelsd_2_b32(crates/victory-shader/src/ir.rs), but the emitter's M0-relative arm incrates/victory-shader/src/emit/lower.rshandles onlyv_movrels_b32,v_movreld_b32andv_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::effectswrite 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