xshader: support QDMode ds_swizzle_b32 in compute shaders #70

Manually merged
github merged 1 commit from gh-pr/70/head into gh-pr/70/base 2026-11-26 06:29:10 +00:00
Owner

@⁠JohnVonWells on GitHub · 2026-11-24 15:56 UTC · original
xshader/compute-quad-swizzle → main · +866 −4 · 6 files · 1 commits · merged 2026-11-24 19:48 UTC

Problem

An ordinary compute ds_swizzle_b32 refused every offset with bit 15 set (emit_compute_swizzle, raw[0] & 0x3_8000). Bit 15 selects QDMode (RDNA2 ISA, DS_SWIZZLE_B32): lane i of each quad reads lane offset[2i+1:2i] of the same quad. Pixel shaders and the wave32 resolve path already lower QDMode. Ordinary compute shaders did not.

The log shared in #39 (3086e0b) has two compute shaders refused with unsupported compute DS swizzle encoding (a7311ea4…, e6559079…). GDS is the only other bit the old check covered, and GDS makes no sense on a swizzle, so QDMode is the likely cause.

Change

  • emit_compute_swizzle lowers QDMode through the existing group-shared exchange: tb_swizzle[(tb_lane & ~3u) | ((pattern >> (2u * (tb_lane & 3u))) & 3u)]. Inactive lanes still contribute 0 and skip the write, as in bit-mask mode.
  • Only offsets 0x8000..0x80ff are accepted, the same bound as the resolve path. GDS, bit 16 and the other high offset bits stay refused.
  • Bit-mask mode is unchanged.

Validation

  • Unit tests (hlsl/compute_swizzle.rs): QDMode lowering including the source register, bit-mask regression, and refusal of 0x8100, 0xe000, 0xffff, bit 16 and GDS. The QDMode test fails on the previous code. Shader compiler: 83 passed. Python suite: 128 passed.
  • GPU control (tools/check_compute_swizzle.py, modelled on check_wave_guard.py): it runs the translator's real output for 8 QDMode offsets (identity, reverse, pair/half swaps, broadcasts, irregular) and 5 bit-mask offsets under 8 lane masks (full, odd, lane 0, empty, 4 random). It compares all 384 words of the guarded buffer. 104/104 matched on an RX 6950 XT (1002:73a5), Proton Experimental 11.0-20261112, DXC 1.9.2609. Evidence: evidence/scarlett-compute-swizzle-control.json.
  • Negative control: the same cases built with a deliberately wrong QDMode shift (>> (lane & 3)): 34 cases mismatched, all QDMode, no bit-mask case.

AI-assisted contribution.

🤖 Generated with Claude Code

**@⁠JohnVonWells** on GitHub · 2026-11-24 15:56 UTC · [original](https://github.com/brcly/TuxBox/pull/70) `xshader/compute-quad-swizzle` → `main` · +866 −4 · 6 files · 1 commits · merged 2026-11-24 19:48 UTC ## Problem An ordinary compute `ds_swizzle_b32` refused every offset with bit 15 set (`emit_compute_swizzle`, `raw[0] & 0x3_8000`). Bit 15 selects QDMode (RDNA2 ISA, `DS_SWIZZLE_B32`): lane *i* of each quad reads lane `offset[2i+1:2i]` of the same quad. Pixel shaders and the wave32 resolve path already lower QDMode. Ordinary compute shaders did not. The log shared in #39 (`3086e0b`) has two compute shaders refused with `unsupported compute DS swizzle encoding` (`a7311ea4…`, `e6559079…`). GDS is the only other bit the old check covered, and GDS makes no sense on a swizzle, so QDMode is the likely cause. ## Change - `emit_compute_swizzle` lowers QDMode through the existing group-shared exchange: `tb_swizzle[(tb_lane & ~3u) | ((pattern >> (2u * (tb_lane & 3u))) & 3u)]`. Inactive lanes still contribute 0 and skip the write, as in bit-mask mode. - Only offsets `0x8000..0x80ff` are accepted, the same bound as the resolve path. GDS, bit 16 and the other high offset bits stay refused. - Bit-mask mode is unchanged. ## Validation - **Unit tests** (`hlsl/compute_swizzle.rs`): QDMode lowering including the source register, bit-mask regression, and refusal of `0x8100`, `0xe000`, `0xffff`, bit 16 and GDS. The QDMode test fails on the previous code. Shader compiler: 83 passed. Python suite: 128 passed. - **GPU control** (`tools/check_compute_swizzle.py`, modelled on `check_wave_guard.py`): it runs the translator's real output for 8 QDMode offsets (identity, reverse, pair/half swaps, broadcasts, irregular) and 5 bit-mask offsets under 8 lane masks (full, odd, lane 0, empty, 4 random). It compares all 384 words of the guarded buffer. **104/104 matched** on an RX 6950 XT (`1002:73a5`), Proton Experimental 11.0-20261112, DXC 1.9.2609. Evidence: `evidence/scarlett-compute-swizzle-control.json`. - **Negative control**: the same cases built with a deliberately wrong QDMode shift (`>> (lane & 3)`): 34 cases mismatched, all QDMode, no bit-mask case. AI-assisted contribution. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An ordinary compute ds_swizzle_b32 refused every offset with bit 15 set,
which is QDMode (RDNA2 ISA DS_SWIZZLE_B32): lane i of each quad reads
lane offset[2i+1:2i] of the same quad. Pixel shaders and the resolve
path already lower QDMode. Lower it through the existing group-shared
exchange, accepting only offsets 0x8000..0x80ff as the resolve path
does. GDS, bit 16 and the other high offset bits stay refused.

Two ProjectScarlett compute shaders in the current-main log shared in
QDMode, but GDS is the only other bit the old check covered.

A GPU control runs the translator's output for 8 QDMode and 5 bit-mask
offsets under 8 lane masks: 104/104 match on an RX 6950 XT with Proton
Experimental. The same cases built with a deliberately wrong QDMode
shift mismatch in 34 QDMode cases and no bit-mask case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:29:09 +00:00
github manually merged commit 8fed08c66e into gh-pr/70/base 2026-11-26 06:29:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.