Shaders: ds_permute_b32 scatters through a scratch in LDS #454

Closed
github-bot wants to merge 1 commit from gh-pr/454/head into gh-pr/454/base
Owner

@⁠Melow-code on GitHub · 2026-11-25 01:02 UTC · original
fix/scatter-ds-permute-b32 → main · +95 −0 · 2 files · 1 commits · closed without merging

ds_permute_b32 was not lowered: it fell to the generic LDS path, which is not what the instruction does.

Each active lane gives its data register to the lane its address plus the offset names in dwords, within the 32-lane half of the calling lane (the ISA confines the permute there in wave64). The console writes a scratch that starts at zero and each active destination lane reads a slot of its own, so a destination nobody targets reads zero.

The lowering zeroes the slot of the calling lane, runs a group barrier, has every lane write the slot its address names, runs another barrier, and reads the slot of the calling lane. The scratch holds a dword per lane of every console wave in the group, past the LDS of the program, addressed by the console thread, so the two host waves of a split console wave never hit the same slot. A barrier needs every lane: in a block some lanes leave, this refuses (a wave-wide structuring of the block would open it).

Verification

  • cargo test --locked -p victory-shader --lib on Linux: 173 passed, two ignored.
  • Two new tests: a straight-line scatter lowers (a_scatter_permute_writes_the_lane_its_address_names), and a scatter in a branch refuses (a_scatter_permute_in_a_branch_is_refused).
  • No new clippy pedantic warning on the touched lines.

The GPU readback of the scatter needs a Windows host, outside this run.

Assisted-by: DeepSeek V4 Pro (OpenCode)

**@⁠Melow-code** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/454) `fix/scatter-ds-permute-b32` → `main` · +95 −0 · 2 files · 1 commits · closed without merging `ds_permute_b32` was not lowered: it fell to the generic LDS path, which is not what the instruction does. Each active lane gives its data register to the lane its address plus the offset names in dwords, within the 32-lane half of the calling lane (the ISA confines the permute there in wave64). The console writes a scratch that starts at zero and each active destination lane reads a slot of its own, so a destination nobody targets reads zero. The lowering zeroes the slot of the calling lane, runs a group barrier, has every lane write the slot its address names, runs another barrier, and reads the slot of the calling lane. The scratch holds a dword per lane of every console wave in the group, past the LDS of the program, addressed by the console thread, so the two host waves of a split console wave never hit the same slot. A barrier needs every lane: in a block some lanes leave, this refuses (a wave-wide structuring of the block would open it). ## Verification - `cargo test --locked -p victory-shader --lib` on Linux: 173 passed, two ignored. - Two new tests: a straight-line scatter lowers (`a_scatter_permute_writes_the_lane_its_address_names`), and a scatter in a branch refuses (`a_scatter_permute_in_a_branch_is_refused`). - No new clippy pedantic warning on the touched lines. The GPU readback of the scatter needs a Windows host, outside this run. Assisted-by: DeepSeek V4 Pro (OpenCode)
ds_permute_b32 was not lowered: it fell to the generic LDS path, which
is not what the instruction does. Each active lane gives its data
register to the lane its address plus the offset names in dwords,
within the 32-lane half of the calling lane (the ISA confines the permute
there in wave64). The console writes a scratch that starts at zero and
each active destination lane reads a slot of its own, so a destination
nobody targets reads zero.

The lowering zeroes the slot of the calling lane, runs a group barrier,
has every lane write the slot its address names, runs another barrier,
and reads the slot of the calling lane. The scratch holds a dword per lane
of every console wave in the group, past the LDS of the program, addressed
by the console thread, so the two host waves of a split console wave
never hit the same slot. A barrier needs every lane: in a block some
lanes leave, this refuses (a wave-wide structuring of the block would
open it).

Two tests: a straight-line scatter lowers, and a scatter in a branch
refuses. Written with DeepSeek V4 Pro (OpenCode).

Assisted-by: DeepSeek V4 Pro (OpenCode)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:41 +00:00
github-bot closed this pull request 2026-11-26 03:43:41 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.