Skip to content

Shaders: lower ds_permute_b32 and ds_nop - #2152

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-ds-permute-b32-1481
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-ds-permute-b32-1481

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. ds_permute_b32 and ds_nop lowered — permute + nop ops.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head d8150fc 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).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. Thanks for the citation. It settles the Wave64 point. RDNA 2 ISA §10.4.4 ("LDS Lane-permute Ops") says that in wave64 the permute runs as two independent 32-lane halves. That matches ds_permute_b32 in Lower::ds (crates/victory-shader/src/emit/lower.rs, (me & !31) | (to & 31)), and the comment there now cites it. main's full-wave ds_bpermute_b32 is the one that disagrees. #573 (already a merge candidate) fixes it to the same half-wave indexing, so the two PRs are consistent and don't touch the same lines.

The rest is unchanged from the last review and right:

  • ds_nop is a no-op that needs no LDS.
  • For Wave32, sources are visited in ascending order, so the highest active source wins a collision.
  • Active lanes that receive nothing get 0, and inactive lanes keep vdst.

ds_permute_tests.rs checks values on the GPU. CI check passes at 5e8053c.

For the maintainers: no title program starts translating because of this (offline count above), so it is a correctness addition. Land it together with #573.


Generated by Claude Code

gfx10::fields and Lower::inst already recognize ds_permute_b32 (0x0b2)
and ds_nop (0x014), but Lower::ds only handled ds_swizzle_b32 and
ds_bpermute_b32 before requiring an LDS allocation and falling through
to "an LDS operation" (Marvisak#1481). Neither instruction touches LDS memory.

Lower ds_nop as a no-op (and omit it from side-effect marking), and
lower ds_permute_b32 as a forward cross-lane scatter within each
32-lane sub-vector (0..31, and 32..63 independently in wave64 per the
RDNA2 ISA): active lanes route their source dword to ((addr + offset)
>> 2) & 31 within their half, unwritten active destinations read 0, and
inactive destination lanes retain their previous value.

Part of Marvisak#1481.
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-ds-permute-b32-1481 branch from d8150fc to 5e8053c Compare November 25, 2026 12:08
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants