Shaders: ds_permute_b32 scatters through a scratch in LDS #454

Closed
Melow-code wants to merge 1 commit from upstream-pr/454 into main
Melow-code commented 2026-11-25 01:02:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Melow-code on 2026-11-25T01:02:43Z.


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)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594702932 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/454). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-25T01:02:43Z. --- `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)
upstream-sync closed this pull request 2026-11-25 21:05:35 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!454
No description provided.