Shaders: lower ds_permute_b32 and ds_nop #2150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2152"
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 fuzeofficlal on 2026-11-25T06:19:50Z.
Problem
gfx10::opcodes,gfx10::fields, andLower::instalready recognizeds_permute_b32(0x0b2) andds_nop(0x014), whereasLower::ds(crates/victory-shader/src/emit/lower.rs) only lowersds_swizzle_b32andds_bpermute_b32before requiring an LDS allocation and falling through toErr("an LDS operation")(#1481). Neither instruction accesses physical LDS memory.Changes
ds_nop(0x014): ReturnOk(())as a no-op without requiring allocated LDS, and omitds_nopfromLower::instside-effect marking.ds_permute_b32(0x0b2): Lower forward cross-lane scatter within each 32-lane sub-vector (0..31, and32..63independently in Wave64 per the RDNA2 ISA) usingwaveActiveBallotand uniform-lanewaveReadLaneAt: active lanes routevdatato((vaddr + offset) >> 2) & 31within their half, unwritten active destinations read0, and inactive destination lanes retain their priorvdstvalue.emit::ds_permute_testscovering Wave32 bijection/unaligned/offset/partial-EXEC/collision arbitration, Wave64 32-lane half isolation, zero-LDSds_nopexecution, and non-compute stage refusal (dxil.dllvalidated, verified on RTX 5090 Wave32, AMD Radeon Graphics Wave32/Wave64, and D3D12 WARP).Part of #1481.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:23:53Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib emit::ds_permute_tests::— 4 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (184 files ok)Clean lowering of
ds_permute_b32andds_nopwith thorough end-to-end GPU+WARP test coverage inds_permute_tests.rs. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:49:55Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. ds_permute_b32 and ds_nop lowered — permute + nop ops.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:16:03Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
d8150fcbontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T11:24:23Z.
Automated triage for the maintainers.
Verdict: merge candidate (unchanged). Thanks for the rebase. At
72cd605theds_permute_b32andds_nophandling inLower::ds(crates/victory-shader/src/emit/lower.rs) is the same as the reviewed version. That includes the RDNA2 ISA §10.4.4 half-wave indexing, the highest active source winning a collision, and 0 for lanes that receive nothing. The only change is inds_permute_tests.rs, which now usesHost::from_device(device)to matchemit/host.rsonmain.#573 (the matching
ds_bpermute_b32fix) has landed since the last review, somainand this PR now use the same 32-lane-half semantics.CI: passing (
check). Merges cleanly.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T12:08:21Z.
Updated in
5e8053c6with the RDNA2 ISA citation inLower::ds, while leavingds_bpermute_b32untouched here so this PR stays conflict-free with #573 (verdict=merge-candidate), which already fixesds_bpermute_b32to use the same 32-lane half-wave indexing.RDNA2 Wave64 Half-Wave Semantics
AMD RDNA 2 ISA Reference Guide (§10.4.4, LDS Lane-permute Ops):
LLVM AMDGPU Backend (
llvm/lib/Target/AMDGPU/GCNSubtarget.h):GCNSubtarget::supportsWaveWideBPermute()returns(getGeneration() <= GFX9 || getGeneration() >= GFX12) || isWave32()—falseon GFX10/RDNA2 in Wave64, where full-wave shuffles must synthesize cross-half movement separately viav_permlane64_b32.Once both #573 (
ds_bpermute_b32) and this PR (ds_permute_b32+ds_nop) land, both permute instructions match RDNA2's(lane_index() & !31) | (((addr + offset) >> 2) & 31)behavior.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T02:56:46Z.
Rebased onto current
main(63bcca43) and updatedds_permute_tests.rsfor theHost::from_device(device)signature change; all 37ds_permute/lowertests, clippy, and policy checks pass.Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T18:38:42Z.
Wave64 hardware check of
72cd605.Checked against a hardware table measured on an AMD Radeon iGPU (gfx1036, RDNA 2, Ryzen 7 9800X3D) in native
wave64: 64 cross-lane instructions x 8 EXEC masks (all, lo32, hi32, all but lane 0, alternate lanes, lane 40 alone,
lanes 31+32, a sparse mask). Each case was assembled with the same assembler, run through VIctory as a wave64
compute program of 64 threads on the same Radeon through D3D12 (WaveSize 64, dxil.dll validated), and all 64
lanes compared with the hardware. EXEC is narrowed two ways: straight-line (
v_cmpx_ne_u32, lowered with a laneguard) and branched (
s_and_saveexec_b64+s_cbranch_execz, a DXILif). Windows 11, Rust pinned, debug.No game files were used.
Tested (merged onto main
63bcca4; Radeon, wave64):ds_permute_b32with address(lane + k) * 4, k = 1, 31, 32, 33, 63, 64, 100, under all 8 masks and both EXECforms: 112 of 112 exact (main refuses them:
LDS the program does not allocate). That includes the hardware's32-lane halves (k = 32 sends to the lane itself, k = 100 sends lane 0 to lane 4 and lane 32 to lane 36) and 0 for
an active lane no active lane sends to (e.g. all but lane 0, k = 1: lane 1 gets 0).
Not tested: collisions (two lanes sending to one; the table has none), NVIDIA (wave64), the title.
AI use: Claude Code (Claude Opus 5.5) built the harness and the hardware table, ran them on the GPU above and wrote this report; the numbers come from those runs.
View 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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.