tombox-xshader: lower ds_swizzle_b32 bit and quad modes in compute shaders #184

Closed
MeNoSkills wants to merge 1 commit from upstream-pr/184 into main
MeNoSkills commented 2026-11-22 22:02:18 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by MeNoSkills on 2026-11-22T22:02:18Z.


Until now ds_swizzle_b32 translated only in a pixel shader with QDMode (bit 15); any other use, including every use in a compute shader, failed with "ds_swizzle outside a pixel shader" (or "without QDMode unsupported"). It is used by compute shaders for lane exchanges within a 32-lane group.

Change

In a compute shader, ds_swizzle_b32 now goes through the same lane-exchange lowering as ds_bpermute_b32 (WaveReadLaneAt, or the groupshared exchange when the shader has no LDS). The source lane inside the 32-lane group is computed per lane from the offset:

  • bit mode (offset[15] = 0): ((lane & offset[4:0]) | offset[9:5]) ^ offset[14:10]
  • quad mode (offset[15] = 1 and offset < 0xC000): (lane & ~3) | ((offset[7:0] >> (2 * (lane & 3))) & 3)

Offsets >= 0xC000 (the rotate and FFT modes) are refused with a message that names them; I do not have the ISA text to check their semantics, so I did not guess. The pixel-shader quad path is unchanged.

Tests

  • exec_mem::ds::ds_swizzle_compute: 12 bit-mode offsets (identity 0x001f, neighbour swap 0x041f, xor 16 = 0x401f, and-masks, broadcast of a lane, mixed masks, 0x7fff) and 8 quad permutations, on 64 threads (two groups of 32), against a reference computed from the formulas above. 20/20 on WARP and on an RTX 4070 Ti; without the change all 20 fail with "ds_swizzle outside a pixel shader".
  • exec_mem::ds::ds_swizzle_rotate_and_fft_are_refused_in_compute.
  • Regression runs on the RTX (Windows 10 19045, MSVC): --lib 85, --test synthetic 22, --test isa_sweep 2 (541 mnemonics), --test mesh 24, --test exec ds_ 18, all passing. pr_gate: 0 problems.

Not verified

No real shader: I do not have a title dump. The source-lane formulas come from the DS_SWIZZLE_B32 description, not from a console shader. Wave64 is not covered (compute here is two 32-lane groups).

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6548364681 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/184). Originally posted by [MeNoSkills](https://github.com/MeNoSkills) on 2026-11-22T22:02:18Z. --- Until now ds_swizzle_b32 translated only in a pixel shader with QDMode (bit 15); any other use, including every use in a compute shader, failed with "ds_swizzle outside a pixel shader" (or "without QDMode unsupported"). It is used by compute shaders for lane exchanges within a 32-lane group. ## Change In a compute shader, ds_swizzle_b32 now goes through the same lane-exchange lowering as ds_bpermute_b32 (WaveReadLaneAt, or the groupshared exchange when the shader has no LDS). The source lane inside the 32-lane group is computed per lane from the offset: - bit mode (offset[15] = 0): ((lane & offset[4:0]) | offset[9:5]) ^ offset[14:10] - quad mode (offset[15] = 1 and offset < 0xC000): (lane & ~3) | ((offset[7:0] >> (2 * (lane & 3))) & 3) Offsets >= 0xC000 (the rotate and FFT modes) are refused with a message that names them; I do not have the ISA text to check their semantics, so I did not guess. The pixel-shader quad path is unchanged. ## Tests - `exec_mem::ds::ds_swizzle_compute`: 12 bit-mode offsets (identity 0x001f, neighbour swap 0x041f, xor 16 = 0x401f, and-masks, broadcast of a lane, mixed masks, 0x7fff) and 8 quad permutations, on 64 threads (two groups of 32), against a reference computed from the formulas above. 20/20 on WARP and on an RTX 4070 Ti; without the change all 20 fail with "ds_swizzle outside a pixel shader". - `exec_mem::ds::ds_swizzle_rotate_and_fft_are_refused_in_compute`. - Regression runs on the RTX (Windows 10 19045, MSVC): `--lib` 85, `--test synthetic` 22, `--test isa_sweep` 2 (541 mnemonics), `--test mesh` 24, `--test exec ds_` 18, all passing. pr_gate: 0 problems. ## Not verified No real shader: I do not have a title dump. The source-lane formulas come from the DS_SWIZZLE_B32 description, not from a console shader. Wave64 is not covered (compute here is two 32-lane groups).
omonkeyz commented 2026-11-22 23:23:23 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T23:23:23Z.


Applied in 3828799 (merged in 42511d7) with your authorship kept, thanks. The full tombox-xshader suite passes on WARP.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7087536952 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/184#issuecomment-7087536952). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T23:23:23Z. --- Applied in 3828799 (merged in 42511d7) with your authorship kept, thanks. The full tombox-xshader suite passes on WARP.

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
omonkeyz/xbox-emulator!184
No description provided.