Skip to content

feat(shader): implement ds_permute_b32 - #334

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
adriadam10:feat/ds-permute
Oct 4, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
adriadam10:feat/ds-permute

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

ds_permute_b32 (DS 0xb2) threw DS opcode is not supported. The ISA sweep found it. It is the forward (scatter) form of ds_bpermute_b32: every lane sends data to lane ((addr + offset) >> 2) & 31 of its wave.

Semantics measured on an RDNA2 GPU (wave32, 6 address patterns: reversed, all to lane 0, random; with offset:8; with EXEC = low 16 lanes). All matched by a Python model:

  • If several lanes target the same lane, the highest sending lane wins.
  • An active lane that no one writes to gets 0.
  • Inactive lanes neither send nor receive.

Lowering: PermuteU32 runs 32 unrolled steps, one per source lane of the wave. Each step shuffles the data, the address and the EXEC bit from that lane and keeps it when the target is this lane. Later lanes overwrite earlier ones. It uses the same wave base (lane & ~31) as ds_bpermute_b32. It is costly (96 shuffles), so estimatedSpirvWords reports it as such. The opcode is rare.

Test agc_driver_ds_permute: random targets, ds_bpermute_b32 on the same inputs as a reference, offset:8, and partial EXEC. Expected values were captured on the RDNA2 GPU. On devices whose subgroups are narrower than a wave (lavapipe: 8 lanes) the test reports itself as skipped, like the other cross-lane tests.

Tested

Linux, full ctest (100) passes.

  • RADV (Radeon 660M): the test passes. lavapipe: skipped (subgroup 8).
  • With the lowest sending lane winning instead: permute_offset8 is 0x00001017, expected 0x0000101e.

Checklist

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Progress report (870bdd8 → 13ac232)

📈 GPU shader instructions: 73.24% (+0.08%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
DS DS_PERMUTE_B32

This was referenced Oct 2, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

A heads-up on an interaction with my open #304, which neither PR's tests would catch.

#304 adds WaveUniformValues in SpirvAnalysis.cpp: on the two-lane wave64 path, a value whose inputs are all wave-uniform is emitted once and shared by both halves. Cross-lane ops whose result can differ per lane even with uniform inputs are listed in LaneSource (BpermuteU32, SwizzleU32, WriteLane, ...).

PermuteU32 belongs in that list. With a uniform value and a uniform address, every lane writes to the same target lane, so only that lane gets the value and the rest read 0. Without the entry, #304 would treat that result as uniform and give the second half the first half's value.

Whichever of the two lands second needs this one line:

case IrOpcode::PermuteU32:

in LaneSource. If #334 merges first, I'll add it to #304.

@adriadam10

Copy link
Copy Markdown
Collaborator Author

Thanks, agreed: PermuteU32 is lane-dependent even with uniform inputs, so it belongs in LaneSource. LaneSource isn't on main yet, so nothing to add here for now. If #304 lands first I'll rebase and add the case line here; otherwise thanks for picking it up in #304. Could you ping me here when #304 gets merged?

@github-actions github-actions Bot added the build label Oct 2, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Ping as promised: #304 is merged now, so LaneSource in SpirvAnalysis.cpp is on main. On the merge result PermuteU32 is not in it, so WaveUniformValues treats a permute with uniform inputs (say every lane sends a constant to lane 0) as uniform, and the two-lane wave64 path would share one value across both halves even though only the target lane receives it. Could you rebase and add case IrOpcode::PermuteU32: next to BpermuteU32 there? Everything else looks right to me; I checked the 0xb2 encoding with llvm-mc for gfx1013.

adriadam10 and others added 2 commits October 4, 2026 08:19
ds_permute_b32 is the forward (scatter) counterpart of ds_bpermute_b32:
every active lane sends its data to lane ((addr + offset) >> 2) & 31 of
its wave. As measured on hardware, the highest sending lane wins, an
active lane nobody writes to gets 0 and inactive lanes neither send nor
receive. It lowers to one shuffle of the data, address and EXEC bit per
source lane, using the same wave base as ds_bpermute_b32.

Co-Authored-By: Claude <noreply@anthropic.com>
With uniform inputs every lane writes to the same target lane, so only
that lane receives the value; the two-lane wave64 path must not share it.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Thanks for the reminder. Rebased onto current main and added case IrOpcode::PermuteU32: to LaneSource, next to BpermuteU32. agc_driver_ds_permute and agc_driver_wave_uniform pass on RADV. My machine has no host with 32-wide subgroups, so I couldn't run the two-lane wave64 path locally.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for adding it. My RTX 4090 runs 32-wide subgroups, so I'll test the two-lane wave64 path (agc_driver_ds_permute and agc_driver_wave_uniform) here and merge once CI is green.

@oneandonlydean
oneandonlydean merged commit b0a4a99 into boykopovar:main Oct 4, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/ds-permute branch October 5, 2026 06:47
SP4C3B4R-8 pushed a commit to SP4C3B4R-8/AnyPS5 that referenced this pull request Oct 6, 2026
Takes the 13 gate-batch PRs that merged upstream (boykopovar#319 boykopovar#329 boykopovar#330 boykopovar#331 boykopovar#325
boykopovar#435 boykopovar#471 boykopovar#294 boykopovar#376 boykopovar#404 boykopovar#394 boykopovar#401 boykopovar#446) in place of astrobot's local
versions, as integ/gate-batch cab0eab had them: boykopovar#294 and boykopovar#376 in
astrobot's depth model (DepthTarget, state.depth), boykopovar#394 with the thick mip
tails, boykopovar#401 over astrobot's slab pool, boykopovar#471 keeping the settled single-lane
path. Also takes the rest of main since a818bee (boykopovar#532 boykopovar#340 boykopovar#486 boykopovar#484 boykopovar#316
boykopovar#243 boykopovar#334 boykopovar#434 boykopovar#437 boykopovar#470 boykopovar#373 boykopovar#452 boykopovar#455 and our upstreamed PRs, where
astrobot keeps its later revisions and env switches).

Resolution notes: relinker converter/matcher/tests are upstream's (boykopovar#432
decoder covers VEX RIP-relative followers); RecompileResult gains boykopovar#316's
hostSubgroupSize (set from request.target.subgroupSize); shader disk cache
format 9; boykopovar#452's scissor message; upstream's later live-stack and
memory-copy decode tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mgp3oZvembQziVNE2xARQK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build ci .github shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants