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.
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.