Shaders: lower ds_permute_b32 and ds_nop #2152

Open
github-bot wants to merge 1 commit from github-bot/gh-2152 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 06:19 UTC · original
fuzeofficlal:fix/shader-ds-permute-b32-1481 → main · +740 −1 · 3 files · 1 commits · open

Problem

gfx10::opcodes, gfx10::fields, and Lower::inst already recognize ds_permute_b32 (0x0b2) and ds_nop (0x014), whereas Lower::ds (crates/victory-shader/src/emit/lower.rs) only lowers ds_swizzle_b32 and ds_bpermute_b32 before requiring an LDS allocation and falling through to Err("an LDS operation") (#1481). Neither instruction accesses physical LDS memory.

Changes

  • ds_nop (0x014): Return Ok(()) as a no-op without requiring allocated LDS, and omit ds_nop from Lower::inst side-effect marking.
  • ds_permute_b32 (0x0b2): Lower forward cross-lane scatter within each 32-lane sub-vector (0..31, and 32..63 independently in Wave64 per the RDNA2 ISA) using waveActiveBallot and uniform-lane waveReadLaneAt: active lanes route vdata to ((vaddr + offset) >> 2) & 31 within their half, unwritten active destinations read 0, and inactive destination lanes retain their prior vdst value.
  • Add emit::ds_permute_tests covering Wave32 bijection/unaligned/offset/partial-EXEC/collision arbitration, Wave64 32-lane half isolation, zero-LDS ds_nop execution, and non-compute stage refusal (dxil.dll validated, verified on RTX 5090 Wave32, AMD Radeon Graphics Wave32/Wave64, and D3D12 WARP).

Part of #1481.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152) `fuzeofficlal:fix/shader-ds-permute-b32-1481` → `main` · +740 −1 · 3 files · 1 commits · open ### Problem `gfx10::opcodes`, `gfx10::fields`, and `Lower::inst` already recognize `ds_permute_b32` (`0x0b2`) and `ds_nop` (`0x014`), whereas `Lower::ds` (`crates/victory-shader/src/emit/lower.rs`) only lowers `ds_swizzle_b32` and `ds_bpermute_b32` before requiring an LDS allocation and falling through to `Err("an LDS operation")` (#1481). Neither instruction accesses physical LDS memory. ### Changes - **`ds_nop` (`0x014`)**: Return `Ok(())` as a no-op without requiring allocated LDS, and omit `ds_nop` from `Lower::inst` side-effect marking. - **`ds_permute_b32` (`0x0b2`)**: Lower forward cross-lane scatter within each 32-lane sub-vector (`0..31`, and `32..63` independently in Wave64 per the RDNA2 ISA) using `waveActiveBallot` and uniform-lane `waveReadLaneAt`: active lanes route `vdata` to `((vaddr + offset) >> 2) & 31` within their half, unwritten active destinations read `0`, and inactive destination lanes retain their prior `vdst` value. - Add `emit::ds_permute_tests` covering Wave32 bijection/unaligned/offset/partial-`EXEC`/collision arbitration, Wave64 32-lane half isolation, zero-LDS `ds_nop` execution, and non-compute stage refusal (`dxil.dll` validated, verified on RTX 5090 Wave32, AMD Radeon Graphics Wave32/Wave64, and D3D12 WARP). Part of #1481.
Lower ds_permute_b32 via wave lane reads (preserving RDNA2 half-wave semantics on Wave64 per ISA 10.4.4) and ds_nop as a no-op, with hardware/WARP/DXIL regression tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:18 +00:00
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:16 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head d8150fcb onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#issuecomment-7156815513) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head d8150fcb onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 11:24 UTC · original · edited 2026-11-26 03:24 UTC

Automated triage for the maintainers.

Verdict: merge candidate (unchanged). Thanks for the rebase. At 72cd605 the ds_permute_b32 and ds_nop handling in Lower::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 in ds_permute_tests.rs, which now uses Host::from_device(device) to match emit/host.rs on main.

#573 (the matching ds_bpermute_b32 fix) has landed since the last review, so main and this PR now use the same 32-lane-half semantics.

CI: passing (check). Merges cleanly.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 11:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#issuecomment-7161003706) · edited 2026-11-26 03:24 UTC <!-- victory-triage v1 head=72cd6051575c8ab777a4036960f22006ce3aeb62 verdict=merge-candidate at=2026-11-26T03:24:38Z --> Automated triage for the maintainers. **Verdict: merge candidate** (unchanged). Thanks for the rebase. At `72cd605` the `ds_permute_b32` and `ds_nop` handling in `Lower::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 in `ds_permute_tests.rs`, which now uses `Host::from_device(device)` to match `emit/host.rs` on `main`. #573 (the matching `ds_bpermute_b32` fix) has landed since the last review, so `main` and this PR now use the same 32-lane-half semantics. CI: passing (`check`). Merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 12:08 UTC · original

Updated in 5e8053c6 with the RDNA2 ISA citation in Lower::ds, while leaving ds_bpermute_b32 untouched here so this PR stays conflict-free with #573 (verdict=merge-candidate), which already fixes ds_bpermute_b32 to use the same 32-lane half-wave indexing.

RDNA2 Wave64 Half-Wave Semantics

  1. AMD RDNA 2 ISA Reference Guide (§10.4.4, LDS Lane-permute Ops):

    "Note that in wave64 mode the permute operates only across 32 lanes at a time of each half of a wave64. In other words, it executes as if it were two independent wave32's. Each half-wave can use indices in the range 0–31 to reference lanes in that same half-wave."

  2. LLVM AMDGPU Backend (llvm/lib/Target/AMDGPU/GCNSubtarget.h):
    GCNSubtarget::supportsWaveWideBPermute() returns (getGeneration() <= GFX9 || getGeneration() >= GFX12) || isWave32() — false on GFX10/RDNA2 in Wave64, where full-wave shuffles must synthesize cross-half movement separately via v_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.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 12:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#issuecomment-7161970169) Updated in `5e8053c6` with the RDNA2 ISA citation in `Lower::ds`, while leaving `ds_bpermute_b32` untouched here so this PR stays conflict-free with #573 (`verdict=merge-candidate`), which already fixes `ds_bpermute_b32` to use the same 32-lane half-wave indexing. ### RDNA2 Wave64 Half-Wave Semantics 1. **AMD RDNA 2 ISA Reference Guide (§10.4.4, *LDS Lane-permute Ops*)**: > *"Note that in wave64 mode the permute operates only across 32 lanes at a time of each half of a wave64. In other words, it executes as if it were two independent wave32's. Each half-wave can use indices in the range 0–31 to reference lanes in that same half-wave."* 2. **LLVM AMDGPU Backend (`llvm/lib/Target/AMDGPU/GCNSubtarget.h`)**: `GCNSubtarget::supportsWaveWideBPermute()` returns `(getGeneration() <= GFX9 || getGeneration() >= GFX12) || isWave32()` — `false` on GFX10/RDNA2 in Wave64, where full-wave shuffles must synthesize cross-half movement separately via `v_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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:56 UTC · original

Rebased onto current main (63bcca43) and updated ds_permute_tests.rs for the Host::from_device(device) signature change; all 37 ds_permute / lower tests, clippy, and policy checks pass.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#issuecomment-7181257628) Rebased onto current `main` (`63bcca43`) and updated `ds_permute_tests.rs` for the `Host::from_device(device)` signature change; all 37 `ds_permute` / `lower` tests, clippy, and policy checks pass.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 06:23 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib emit::ds_permute_tests:: — 4 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean lowering of ds_permute_b32 and ds_nop with thorough end-to-end GPU+WARP test coverage in ds_permute_tests.rs. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 06:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#pullrequestreview-6052792657) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib emit::ds_permute_tests::` — **4 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`184 files ok`) Clean lowering of `ds_permute_b32` and `ds_nop` with thorough end-to-end GPU+WARP test coverage in `ds_permute_tests.rs`. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 06:49 UTC · original · approved these changes

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.

**@⁠catminou4** on GitHub · 2026-11-25 06:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#pullrequestreview-6053075926) · **approved these changes** 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.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-26 18:38 UTC · original

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 lane
guard) and branched (s_and_saveexec_b64 + s_cbranch_execz, a DXIL if). Windows 11, Rust pinned, debug.
No game files were used.

Tested (merged onto main 63bcca4; Radeon, wave64):

  • ds_permute_b32 with address (lane + k) * 4, k = 1, 31, 32, 33, 63, 64, 100, under all 8 masks and both EXEC
    forms: 112 of 112 exact (main refuses them: LDS the program does not allocate). That includes the hardware's
    32-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).
  • No other instruction of the table changed result.

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.

**@⁠Lyrnc** on GitHub · 2026-11-26 18:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2152#issuecomment-7200694546) 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 lane guard) and branched (`s_and_saveexec_b64` + `s_cbranch_execz`, a DXIL `if`). Windows 11, Rust pinned, debug. No game files were used. **Tested** (merged onto main 63bcca4; Radeon, wave64): - `ds_permute_b32` with address `(lane + k) * 4`, k = 1, 31, 32, 33, 63, 64, 100, under all 8 masks and both EXEC forms: 112 of 112 exact (main refuses them: `LDS the program does not allocate`). That includes the hardware's 32-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). - No other instruction of the table changed result. **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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2152/head:github-bot/gh-2152'
git switch 'github-bot/gh-2152'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2152'
git switch 'github-bot/gh-2152'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2152'
git switch 'github-bot/gh-2152'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2152'
git switch 'main'
git merge --squash 'github-bot/gh-2152'
git switch 'main'
git merge --ff-only 'github-bot/gh-2152'
git switch 'main'
git merge 'github-bot/gh-2152'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2152
No description provided.