feat(shader): implement ds_permute_b32 #334
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/334"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T06:58:45Z.
What
ds_permute_b32(DS 0xb2) threwDS opcode is not supported. The ISA sweep found it. It is the forward (scatter) form ofds_bpermute_b32: every lane sendsdatato lane((addr + offset) >> 2) & 31of 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:Lowering:
PermuteU32runs 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) asds_bpermute_b32. It is costly (96 shuffles), soestimatedSpirvWordsreports it as such. The opcode is rare.Test
agc_driver_ds_permute: random targets,ds_bpermute_b32on 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.
permute_offset8 is 0x00001017, expected 0x0000101e.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T06:59:44Z.
Progress report (
870bdd8→13ac232)📈 GPU shader instructions: 73.24% (+0.08%, +1 implemented instructions)
✅ 1 implemented
DS_PERMUTE_B32Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T10:01:56Z.
A heads-up on an interaction with my open #304, which neither PR's tests would catch.
#304 adds
WaveUniformValuesinSpirvAnalysis.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 inLaneSource(BpermuteU32,SwizzleU32,WriteLane, ...).PermuteU32belongs 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:
in
LaneSource. If #334 merges first, I'll add it to #304.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T10:06:49Z.
Thanks, agreed:
PermuteU32is lane-dependent even with uniform inputs, so it belongs inLaneSource.LaneSourceisn't on main yet, so nothing to add here for now. If #304 lands first I'll rebase and add thecaseline here; otherwise thanks for picking it up in #304. Could you ping me here when #304 gets merged?Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:41:43Z.
Ping as promised: #304 is merged now, so
LaneSourceinSpirvAnalysis.cppis on main. On the merge resultPermuteU32is not in it, soWaveUniformValuestreats 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 addcase IrOpcode::PermuteU32:next toBpermuteU32there? Everything else looks right to me; I checked the 0xb2 encoding with llvm-mc for gfx1013.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:21:35Z.
Thanks for the reminder. Rebased onto current main and added
case IrOpcode::PermuteU32:toLaneSource, next toBpermuteU32.agc_driver_ds_permuteandagc_driver_wave_uniformpass on RADV. My machine has no host with 32-wide subgroups, so I couldn't run the two-lane wave64 path locally.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T06:29:25Z.
Thanks for adding it. My RTX 4090 runs 32-wide subgroups, so I'll test the two-lane wave64 path (
agc_driver_ds_permuteandagc_driver_wave_uniform) here and merge once CI is green.