Shaders: lower v_swaprel_b32 #1569
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!1569
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1569"
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?
@piyonchu on GitHub · 2026-11-24 19:15 UTC · original
piyonchu:feat/lower-v-swaprel-b32→main· +171 −0 · 3 files · 3 commits · openChanges
crates/victory-shader/src/emit/lower.rs: Lowerv_swaprel_b32per the AMD RDNA2 ISA specification (AMD RDNA 2 Instruction Set Architecture Reference Guide, VOP1V_SWAPREL_B32), usingM0[9:0](0x3FF) as thesrc0VGPR offset andM0[25:16]((m0 >> 16) & 0x3FF) as thevdstVGPR offset (ignoring bits[15:10]and[31:26]), capturing both indexed values before issuing one guardedwrite_placedacross every VGPR ininst.writes(sorange.rs-bounded disjoint[dreg, dreg+end)and[sreg, sreg+end)ranges never stop early at the gap).crates/victory-shader/src/ir.rs: Deduplicatewritesforv_swaprel_b32whensrc0..vgprsanddst..vgprsoverlap soInst::writematches the deduplicated SSA register map (readsare already deduplicated ineffects).ir::tests::v_swaprel_b32_deduplicates_overlapping_vgpr_reads_and_writes(crates/victory-shader/src/ir.rs)emit::valu_tests::v_swaprel_b32_swaps_indexed_vgprs_and_respects_exec(crates/victory-shader/src/emit/valu_tests.rs) covering non-zerosrc0/vdstM0offsets, ignored upperM0bits (0xFC01_FC02), overlapping self-swap, and independents0 == 0(EXEC == 0) preservation under a valid nontrivialM0 = 0x0001_0002swap on GPU + WARP +dxil.dll.emit::valu_tests::v_swaprel_b32_constant_m0_swaps_distant_ranges(crates/victory-shader/src/emit/valu_tests.rs) covering constants_mov_b32 m0, 2with distantvdst = v1andsrc0 = v10sorange.rsbounds[v1, v4)and[v10, v13)separately.(Coordination note with
#498:#498also lowersv_movrelsd_2_b32. Happy to narrow#1569toir.rsoverlapping-VGPR deduplication + the GPU test or close if#498rebases and lands first.)Verification (Windows 11, RTX 4060 + WARP, SDK 10.0.26100.0, rebased onto
main63bcca4atf3f1f42)cargo clippy -p victory-shader --all-targets --all-features -- -D warnings -A clippy::needless_range_loop -A deprecated: pass.cargo test -p xtask: 6 passed, 0 failed (repository_passes_policyok).cargo test -p victory-shader --lib ir::: 10 passed, 0 failed.cargo test -p victory-shader --lib emit::lower::tests: 33 passed, 0 failed.cargo test -p victory-shader --lib v_swaprel_b32(default &VICTORY_WARP=1): 3 passed, 0 failed.git diff --check upstream/main..HEAD: clean.@geiyiliyabumo on GitHub · 2026-11-24 19:36 UTC · original
Verified commit
70ccb59on Windows 11 / AMD Radeon RX 9060 XT (RDNA4,gfx1200, SM 6.6) + WARP:cargo test -p victory-shader --lib: 122 passed, 0 failed, 1 ignored (including the newv_swaprel_b32GPU tests).AI-assisted; synthetic tests only, no game files.
@piyonchu on GitHub · 2026-11-25 01:06 UTC · original
Coordination note per
#1901/#813:#498already lowers bothv_movrelsd_2_b32andv_swaprel_b32(currently conflicting onlower.rs). Unlike#498, this PR (#1569) is rebased cleanly on4118f33(MERGEABLE) and also deduplicates overlapping relative-VGPR reads/writes incrates/victory-shader/src/ir.rs(v_swaprel_b32 v1, v1). If#498merges first, this PR can be narrowed to their.rsdeduplication andv_swaprel_b32test coverage (or closed if redundant).@Marvisak on GitHub · 2026-11-25 03:30 UTC · original · edited 2026-11-26 07:21 UTC
Automated triage for the maintainers.
Merge candidate. The gap from the last triage is fixed. In
e3910b7thev_swaprel_b32arm ofLower(crates/victory-shader/src/emit/lower.rs) walksinst.writes, so whenrange.rsbounds M0 the separate[dreg, …)and[sreg, …)ranges both get their guarded writes. Each register gets the other side's captured value when its offset matches.What I checked:
range.rsbounds by the largest M0, and both 10-bit offsets are at most M0, so the bounded ranges always contain the addressed registers. The newv_swaprel_b32_constant_m0_swaps_distant_ranges(s_mov_b32 m0, 2,v1andv10) expectsv1↔v12, which is correct, and it runs on hardware and WARP. Their.rsdedup of overlapping reads and writes and theM0[9:0]/M0[25:16]layout (public RDNA2 ISA guide) were already fine. #498 also lowers this instruction but conflicts withmain. This PR merges cleanly, so it is the one to look at.CI: passing.
Generated by Claude Code
@piyonchu on GitHub · 2026-11-25 04:02 UTC · original
Updated
#1569(bf722b8) to address all triage points:M0[9:0]andM0[25:16]): Updated theM0mask incrates/victory-shader/src/emit/lower.rsfrom0xFFto0x3FF(M0[9:0]forSRC0andM0[25:16]forVDST, ignoring[15:10]and[31:26]) to match the AMD RDNA2 ISA specification (AMD RDNA 2 Instruction Set Architecture Reference Guide, VOP1V_SWAPREL_B32) and#498, and added an upper-bits test case (0xFC01_FC02) invalu_tests.rs.main(940d32f) to pick up the headless GPU skip fixes (ccfb029/42363ab) and re-rancargo clippy,cargo test -p victory-shader --lib v_swaprel_b32(2/2 passed), andcargo test -p xtask(6/6 passed).#498coordination:#498remainsCONFLICTING(and also lowersv_movrelsd_2_b32), whereas#1569isMERGEABLEand also fixes overlapping-VGPRreads/writesdeduplication inir.rs. Happy to narrow#1569toir.rsdeduplication + the GPU test or close if#498rebases and lands first.@piyonchu on GitHub · 2026-11-26 02:44 UTC · original
Rebased onto
main(63bcca4, commit243596d) resolving thecrates/victory-shader/src/emit/valu_tests.rsconflict, and re-verified (cargo clippy,cargo test -p victory-shader --lib v_swaprel_b322/2 passed,cargo test -p xtask6/6 passed).@piyonchu on GitHub · 2026-11-26 05:13 UTC · original
Updated
#1569ine3910b7to address therange.rs-bounded gap issue:crates/victory-shader/src/emit/lower.rs: replaced thefor r in dreg.min(sreg)..=255u8loop (which broke at the first missing VGPR) with iterating directly over&inst.writes, so disjoint[dreg, dreg+end)and[sreg, sreg+end)ranges both get their guarded writes.crates/victory-shader/src/emit/valu_tests.rs: addedv_swaprel_b32_constant_m0_swaps_distant_rangeswiths_mov_b32 m0, 2and distantvdst = v1,src0 = v10.Verified locally after
e3910b7:cargo clippy -p victory-shader --all-targets -- -D warnings -A clippy::needless_range_loop -A deprecated: passcargo test -p victory-shader --lib v_swaprel_b32: 3 passed, 0 failedcargo test -p xtask: 6 passed, 0 failedgit diff --check upstream/main..HEAD: clean@catminou4 on GitHub · 2026-11-24 19:20 UTC · original · approved these changes
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (
ffe310e),cargo test -p victory-shader --locked→ 97. Execution/valu tests are#[cfg(all(test, windows))]and were not run here.v_swaprel_b32lowering captures both M0-relative source ranges before any write (overlap-safe), emits one guarded write per touched VGPR, andir.rsnow dedups the overlapping read/write ranges so SSA andInst::writeagree. The write loop breaks at the first VGPR with no write, matching the contiguous rangesir.rsmarks. Valu test covers dst<src, dst>src, self-swap and EXEC==0 preservation; the ir.rs dedup test runs on macOS (97 passed, +1).@fuzeofficlal on GitHub · 2026-11-26 12:40 UTC · original · reviewed
Splitting
M0[9:0]andM0[25:16], snapshotting both operands before writeback, deduplicating overlappingir.rsreads/writes, and iterating&inst.writesacrossrange.rs-disjoint spans (crates/victory-shader/src/emit/lower.rs:6166-6225) look sound for in-range swaps, andemit/lower.rsstays at 523,612 bytes (676 bytes under the limit).One test gap worth hardening: in
v_swaprel_b32_swaps_indexed_vgprs_and_respects_exec(crates/victory-shader/src/emit/valu_tests.rs:2335),EXECis only cleared whens3 == 0xFFFF_FFFF(src_off = 1023,dst_off = 1023), which hits no tracked VGPR (only 16 VGPRs declared), so that case would still pass even if theguardwere removed. ClearingEXECindependently on a valid nontrivial swap such asM0 = 0x0001_0002would exercise the guard directly. Also consider runningcargo fmtonir.rs:874/valu_tests.rs:2330and trimming the redundantr.retain(effectsalready deduplicates reads).Local verification on
e3910b76:xtask policy(191 files ok),clippy(default &--all-features) clean,ir::(10 passed),emit::lower::tests(33 passed), andv_swaprel_b32(3 passedon both RTX 5090 andVICTORY_WARP=1).@piyonchu on GitHub · 2026-11-26 13:58 UTC · original
Thanks for the thorough review, @fuzeofficlal! Addressed all three items in
f3f1f42:EXEC == 0guard test (crates/victory-shader/src/emit/valu_tests.rs): updatedv_swaprel_b32_swaps_indexed_vgprs_and_respects_execto clearexec_loindependently vias0 == 0on a valid nontrivial swap (M0 = 0x0001_0002,([0x00, 0x22, 0x33, 0x0001_0002], 0x00_33_22_00)), so removingguardnow causes a failure.r.retain(crates/victory-shader/src/ir.rs): dropped the duplicate read deduplication inv_swaprel_b32(relying oneffects's deduplication below).ir.rs(w.retain) andvalu_tests.rs(v_swaprel_b32_constant_m0_swaps_distant_ranges) withrustfmtconventions (lower.rsunchanged inf3f1f42).Verified on
f3f1f42:cargo clippy -p victory-shader --all-targets --all-features -- -D warnings -A clippy::needless_range_loop -A deprecated: passcargo test -p xtask: 6 passed, 0 failedcargo test -p victory-shader --lib ir::: 10 passed, 0 failedcargo test -p victory-shader --lib emit::lower::tests: 33 passed, 0 failedcargo test -p victory-shader --lib v_swaprel_b32(default &VICTORY_WARP=1): 3 passed, 0 failedgit diff --check upstream/main..HEAD: cleanView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.