feat(victory-shader): implement v_swaprel_b32, v_movrelsd_2_b32, and s_movrelsd_2_b32 lowering #627
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!627
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/627/head"
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?
@Amit89-beep on GitHub · 2026-11-24 05:54 UTC · original
Amit89-beep:feat/v-swaprel-movrelsd2-lowering→main· +417 −38 · 3 files · 2 commits · closed without mergingSummary
Implements IR register-effect tracking and DXIL lowering for three previously unhandled relative/indexed instructions in
victory-shader:v_swaprel_b32(VOP1 opcode0x068): atomically swapsv[dst + M0] ↔ v[src + M0]v_movrelsd_2_b32(VOP1 opcode0x048): GFX10.3 dual-source indexed vector move (v[dst + M0] = v[src0 + M0]and basev[dst] = v[src1])s_movrelsd_2_b32(SOP1 opcode0x049): scalar relative swap (sdst = s[ssrc + M0]; s[ssrc + M0] = sdst_old) across valid SGPRs0..106Details of Changes
crates/victory-shader/src/ir.rs:s_movrelsd_2_b32underFields::Sopto track both indexed read and write register spans (0..106) along withM0as an implicit read dependency.v_swaprel_tracks_both_indexed_reads_and_writesands_movrelsd_2_tracks_dual_indexed_sgpr_effects.crates/victory-shader/src/emit/lower.rs:s_movrelsd_2_b32insop()using dynamicselectchains while preserving untouched SGPR slots.v_swaprel_b32andv_movrelsd_2_b32invalu_op()with proper aliasing handling whensrc == dst.v_swaprel_b32_lowers_through_select_chains,v_movrelsd_2_b32_lowers_cleanly,s_movrelsd_2_b32_lowers_cleanly, andv_movrels_and_movreld_round_trip_through_dxil.Verification
cargo fmt --package victory-shader --check(clean)cargo clippy -p victory-shader --all-targets(0 warnings, 0 errors)cargo test -p victory-shader(all 75 unit tests pass)@Lyrnc on GitHub · 2026-11-24 06:02 UTC · original
RDNA2 hardware measurement of the three opcodes: on gfx1036 none of the three behaves as described here. All three split M0 into two fields, and none of them is a swap with a shared offset or a second move.
Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (GFX10.3 / RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) fills 16 VGPRs (
v10..v25) or 16 SGPRs (s20..s35) with distinct values, sets M0, runs one instruction, and reads every register back. RDNA2 desktop silicon, not the console's. No game data.v_swaprel_b32 v12, v110x00010000v_swaprel_b32 v12, v110x00030002v_movrelsd_2_b32 v12, v110x00010000v_movrelsd_2_b32 v12, v110x00050003s_movrelsd_2_b32 s22, s210x00010000s_movrelsd_2_b32 s22, s210x00020001s_movrelsd_2_b32 s22, s210x00030002s_movrelsd_2_b32 s22, s210x04000003For all three:
src + M0[9:0]and the destinationdst + M0[25:16]. Bits 10-15 and 26-31 are ignored. 11 M0 values for the vector forms (listed on #498, which lowers them this way), 10 fors_movrelsd_2_b32.v_swaprel_b32swapsv[dst + M0[25:16]]withv[src + M0[9:0]], notv[dst + M0]withv[src + M0]. WithM0 = 0x00010000the description's form would index 65536 registers out.v_movrelsd_2_b32makes one move.v[dst]is not also written from another source.s_movrelsd_2_b32is a move with the same split, not a swap: the source SGPR keeps its value in every run.s_movrels_b32ands_movreld_b32(as in #608) use the whole M0, as their descriptions say.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.
@CaravelaLabs on GitHub · 2026-11-24 13:05 UTC · original
Thanks @Amit89-beep — this merges cleanly onto main
ffe310e.cargo test -p victory-shader --libis 102 passed / 0 failed / 1 ignored (Linux, rustc 1.98.1). Main on the same commit is 96 / 0 / 1.The M0 split matches what @Lyrnc measured and what @mercuryVM asked for. One swap on
66a3ec5is still wrong when the two index ranges overlap, which they do whenever the source base is at or below the destination address.With v1=17, v2=34, v3=51, constant-folding the select chains this lowerer builds:
v_swaprel_b32 v2, v1, M0=0, should swap v1 and v2. v2 stays 34 (both end as 34).v_swaprel_b32 v2, v1, M0=0x00010000, should swap v1 and v3. v3 stays 51 (both end as 51).The source side is written. The destination side is written first, then the source-range scatter puts the original value back, because that register is in the source range and is not the source target.
v_swaprel_b32 v1, v3with M0=0 (destination outside the source range) andv_swaprel_b32 v2, v2come out right, so this is only the different-base arm.@catminou4's note about aliasing slots was on the previous head. The new lower tests only check that emit returns Ok, and those two VOP tests also pass on main without this lowering, so they do not catch this.
s_movrelsd_2_b32does fail on main (Unsupported). The0xBE80_0380word in those tests iss_mov_b32 s0, 0, nots_mov_b32 m0, 0(0xBEFC0380), so they never set M0 either.AI-assisted; tests run on this machine.
@Amit89-beep on GitHub · 2026-11-24 13:36 UTC · original
Great catch — thank you for the detailed trace.
Fixed in
7dac1ae:v_swaprel_b32: Replaced the two separate loops with a single pass overmin(sreg, dreg)..=255, evaluating destination and source matches independently per register. This prevents the source loop from restoring old values when the spans overlap (sreg <= dreg).readsandwritesinir::builddeduplicate registers so overlapping ranges don't allocate duplicate SSA values.0xBE80_0380(s0) to0xBEFC_0380(m0).v_swaprel_and_movrelsd_match_rdna2_on_hostinvalu_tests.rsrunning on the host GPU/WARP runner, covering bothM0=0(swappingv1↔v2) andM0=0x00010000(swappingv1↔v3, preservingv2), as well asv_movrelsd_2_b32.@CaravelaLabs on GitHub · 2026-11-24 14:10 UTC · original
Thanks @Amit89-beep — re-folded the two overlap cases on
7dac1ae.With v1=17, v2=34, v3=51, the select chains now come out right:
v_swaprel_b32 v2, v1, M0=0: v1=34, v2=17 (v3 stays 51)v_swaprel_b32 v2, v1, M0=0x10000: v1=51, v3=17 (v2 stays 34)The no-overlap case (
v1, v3, M0=0) and the same-base case (v2, v2, M0=0x10000) still match too. This is a constant-fold of the chains this lowerer builds, not a GPU run.AI-assisted; tests run on this machine.
@Marvisak on GitHub · 2026-11-25 00:26 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #498. Same two VALU instructions as #498 with the same M0 split, plus s_movrelsd_2_b32 and register tracking in ir.rs that main's range.rs has since reworked (
e0034c2a). Its description of the semantics does not match its own code. No title use.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