Skip to content

Translator: ds_permute_b32, the forward (scatter) cross-lane permute (SHADER-90) - #628

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
esteban-dcp:translator-shader-90
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
esteban-dcp:translator-shader-90

Conversation

@esteban-dcp

Copy link
Copy Markdown

SHADER-90 (claimed in #374): ds_permute_b32, the forward (scatter) cross-lane permute, which the translator still rejected. Unblocks FUZZ-10 (@FreddyxS).

Semantics (RDNA2 ISA, DS_PERMUTE_B32 opcode 178 and §10.4.4)

  • Each active source lane i writes data0[i] into destination lane floor((addr[i] + offset) / 4) mod 32; a destination nobody targets gets 0 (tmp[] = 0 in the pseudocode, not its old VDST); a source lane that is off in EXEC does not propagate; a destination lane that is off in EXEC keeps its VDST.
  • Several sources to one lane: the pseudocode says the highest-numbered source thread wins, the prose says it is not predictable. I take the highest lane; the tests only use collision lanes where any writer is accepted.
  • Wave64: §10.4.4 says the permute operates on 32 lanes at a time, "as if it were two independent wave32's", so it is mod 32 within the lane's own half (mirrors ds_bpermute_b32), not the literal mod 64 of the pseudocode. Confirmed on a GPU (below).

What

  • tools/rdna2spirv.py: each source lane publishes its target lane plus one (0 = off in EXEC); each destination lane scans the 32 sources of its half in order and keeps the last match. Native wave32/wave64: a shuffle of target and data per source, with a ballot guard for lanes missing from a partial wave. --wave64-emulate: two buffer rounds and a Function variable %x_perm. Code size is about 90 lines per instance (wave32) and about 330 under emulation; I accepted that for a rare instruction. ds_permute is also added to the two LDS-size scans that skip ds_swizzle/ds_bpermute.
  • tests/semantic/test_ds_permute.py (+ two fixtures via regen_fixtures.py, one line in test_lds_basic_alloc.py): identity, rotation, reversal, collisions (any writer), unwritten lanes, inactive sources, non-zero offset:. On the unchanged translator: Unsupported: ds_permute_b32 (21 errors); making inactive sources propagate their data also fails 9 cases.
  • runtime/test/shaders/cs_w32_permute.asm and cs_w64x_permute.asm (the wave64 one because the wave32 test never reaches the emulated path or the per-half behaviour, lane 32 gets lane 63's data), registered in check.py (WAVE32_LANE_DUMPS too: it needs 32 lanes, so it is skipped on llvmpipe) and run_gpu_tests.py.
  • docs/design.md (LDS row, the "rejected" note removed) and docs/shader_validation.md.
  • tools/lds_fuzz.py is untouched on purpose: its "rejected" comment is FUZZ-10's (@FreddyxS) and Translator: ds_read_u8/i8_d16[_hi] 8-bit LDS reads into a 16-bit half (SHADER-85) #592 edits the same lines. shader_validation.md now says the translator supports it and the fuzzer does not generate it yet.

Tested

Linux 7.3.5 (CachyOS), python -I scripts/run_gpu_tests.py --build runtime/build/linux, each GPU pinned with VK_LOADER_DRIVERS_SELECT (device line checked), VK_LOADER_LAYERS_DISABLE=~implicit~, on current main + this commit:

  • NVIDIA RTX 4050 Laptop (Ada), driver 620.73.04, subgroup 32: 90 translated, 90 pass spirv-val; 60/87 passed, 27 wave64 skipped; with LEONIDA_W64_EMULATE=1: 87/87
  • AMD Radeon 740M (RDNA3, RADV, Mesa 26.3.1), subgroup 32..64: 87/87 (native wave64 ran at subgroup 64)
  • cs_w32_permute = 218 29 8 211 0 15 99 15 on all three runs; cs_w64x_permute = 218 442 435 239 0 99 239 232 on emulation and RADV
  • CPU: unittest discover -s tests/semantic 810 OK; regen_fixtures.py --check clean; spirv-val clean for wave32, wave64, emulated and emulated with a partial wave

Not covered: the partial-wave guard in native mode has only spirv-val, not a value test, and --wave64-emulate has no CPU test (the interpreter rejects Workgroup memory), only the GPU test. Also: plain wave32 ds_bpermute_b32 on main still returns an inactive source lane's value instead of 0 (shader_validation.md cites #253 for that fix, which is not on main); I did not touch ds_bpermute. No game files used. AI-assisted (Claude Code).

🤖 Generated with Claude Code

…(SHADER-90)

Each source lane on in EXEC sends its data to lane ((addr + offset) >> 2) mod 32
of its own half (like ds_bpermute_b32); a destination nobody targets gets 0, an
off destination keeps its VDST. Highest-numbered source wins a collision.
Native: per-source shuffles with a ballot guard for missing lanes; wave64
emulation: two buffer rounds and a %x_perm variable.

Tests: tests/semantic/test_ds_permute.py, GPU tests cs_w32_permute and
cs_w64x_permute. Contract row in docs/design.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 01:23

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

read through both paths. native: a ballot guard for missing lanes, then 32 shuffles of target and data, last match wins, which is the highest source as in the pseudocode. emulated: two rounds plus %x_perm. the per-half mod 32 is backed by the gpu runs. semantic tests pass merged with main (810).

the ds_bpermute thing u mention (wave32 returns an inactive source lane's value instead of 0) sounds like it should get its own issue if #253 is stuck.

TL;DR: looks right and is tested on two gpus, approved. ds_bpermute might need its own issue. AI-assisted review (Claude Code).

@esteban-dcp

Copy link
Copy Markdown
Author

Thanks for the review. The wave32 ds_bpermute_b32 inactive-source case is already tracked as SHADER-31 / #253 (conflicting with main, needs its author's rebase), and the lds_fuzz run that shows it is in the TEST-71 comment on #634 (the same 21 programs on both vendors, all bpermute with the source lane off in EXEC). I did not open a duplicate issue; if #253 stalls I will open one and link it here.

@ItsNotRexed
ItsNotRexed merged commit c0a93d2 into ItsNotRexed:main Nov 22, 2026
8 of 9 checks passed
@Pierre-Kookis

Copy link
Copy Markdown
Contributor

AMD + 32-wide check of #628, tested at the merged head 0726e3f, on one machine.

Setup: Windows 11. AMD Radeon Graphics (Ryzen 7 7800X3D iGPU, RDNA2), driver 32.0.21043.5001, subgroup 32..64. RTX 4070 Ti SUPER, driver 610.88, subgroup 32. Test programs from main c432cdc (llvm-mingw clang), llvm-mc 23.1.6.

cs_w32_permute cs_w64x_permute suite
AMD native PASS 218 29 8 211 0 15 99 15 PASS 218 442 435 239 0 99 239 232 82/87, 5 skipped (mesh)
NVIDIA, no emulation PASS (same words) SKIP (no 64-wide subgroup) 60/87, 27 skipped
NVIDIA LEONIDA_W64_EMULATE=1 PASS (same words) PASS (same words) 87/87

tests/semantic/test_ds_permute.py: 5 OK. All of tests/semantic: 810 OK.

lds_fuzz.py seed 1 gives 7 mismatches per run, the same as main. All of them are the masked wave32 ds_bpermute inactive-lane case that #253 fixes (0 with #253), so nothing comes from this PR.

(AI-assisted run, counts only.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants