xshader: wave32 lane ops address the guest half on 64-lane host waves #62

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

@⁠QuentinDanblon on GitHub · 2026-11-21 22:02 UTC · original
QuentinDanblon:fix/wave32-lane-halves → main · +90 −7 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader: wave32 guest lane numbering on 64-lane host waves

Exports changed (exports.txt rows): none

Source of the behaviour: RDNA2 ISA (wave32 lanes 0-31). The observation that AMD drivers can run fragment subgroups 64 wide comes from americas-recomp (GPL, observation only, measured on Vulkan with an RX 7800 XT).

Guest lane numbers were used as absolute host lane indices (WaveReadLaneAt(x, lane & 31), writelane comparing WaveGetLaneIndex() == lane & 31, the DPP row mask row_mask >> (lane >> 4), and STATUS EXECZ/VCCZ via a whole-wave AnyTrue). On a host that runs 64-lane waves, host lanes 32-63 are a second guest wave and would read or write the first one's lanes. ds_ext.rs already used the half base.

  • guest_lane(L) = (WaveGetLaneIndex() & ~31) | (L & 31) for wave32 guests (wave64 guests unchanged), used by v_readlane and v_writelane.
  • guest_any(c): STATUS EXECZ/VCCZ use the ballot word of the lane's own half.
  • DPP row-mask index uses (l >> 4) & 1 for wave32 guests.
  • GDS ds_append/ds_consume (upstream's WaveActiveBallot version) count and elect within the lane's half.
  • On ≤32-lane hosts the half base is 0: one AND/OR more, same results.

Tests

  • WARP: --test opcodes 23/23, including the new lane_numbering_follows_guest_wave (it checks the emitted HLSL for wave32 and that wave64 output is unchanged).

  • WARP: --test exec vop::lanes, exec_mem::ds and exec_mem::gds pass, 12/12.

  • Earlier, on the pre-sync base, the RTX 5090 lane tests passed: readlane/writelane 15/15, permlane 128/128, DPP 406/406.

  • No adapter here runs 64-lane waves (RTX 5090, Intel UHD 770, WARP), so the 64-wide case itself is not executed.

  • cargo test -p tombox-xshader (lane subsets) passes

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

**@⁠QuentinDanblon** on GitHub · 2026-11-21 22:02 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/62) `QuentinDanblon:fix/wave32-lane-halves` → `main` · +90 −7 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader: wave32 guest lane numbering on 64-lane host waves **Exports changed (exports.txt rows):** none **Source of the behaviour:** RDNA2 ISA (wave32 lanes 0-31). The observation that AMD drivers can run fragment subgroups 64 wide comes from americas-recomp (GPL, observation only, measured on Vulkan with an RX 7800 XT). Guest lane numbers were used as absolute host lane indices (`WaveReadLaneAt(x, lane & 31)`, writelane comparing `WaveGetLaneIndex() == lane & 31`, the DPP row mask `row_mask >> (lane >> 4)`, and STATUS EXECZ/VCCZ via a whole-wave AnyTrue). On a host that runs 64-lane waves, host lanes 32-63 are a second guest wave and would read or write the first one's lanes. `ds_ext.rs` already used the half base. - `guest_lane(L)` = `(WaveGetLaneIndex() & ~31) | (L & 31)` for wave32 guests (wave64 guests unchanged), used by v_readlane and v_writelane. - `guest_any(c)`: STATUS EXECZ/VCCZ use the ballot word of the lane's own half. - DPP row-mask index uses `(l >> 4) & 1` for wave32 guests. - GDS `ds_append`/`ds_consume` (upstream's WaveActiveBallot version) count and elect within the lane's half. - On ≤32-lane hosts the half base is 0: one AND/OR more, same results. ### Tests - WARP: `--test opcodes` 23/23, including the new `lane_numbering_follows_guest_wave` (it checks the emitted HLSL for wave32 and that wave64 output is unchanged). - WARP: `--test exec` vop::lanes, exec_mem::ds and exec_mem::gds pass, 12/12. - Earlier, on the pre-sync base, the RTX 5090 lane tests passed: readlane/writelane 15/15, permlane 128/128, DPP 406/406. - **No adapter here runs 64-lane waves** (RTX 5090, Intel UHD 770, WARP), so the 64-wide case itself is not executed. - [x] `cargo test -p tombox-xshader` (lane subsets) passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
D3D12 lets the driver choose the wave size, and AMD drivers can run PS/CS
at wave64. A wave32 guest program can then share one host wave with a
second guest wave in host lanes 32-63. Before this change, lane-numbered ops
used absolute host lanes: v_readlane read WaveReadLaneAt(x, L & 31),
v_writelane compared WaveGetLaneIndex() with L & 31, the DPP row mask
indexed with lane >> 4, and STATUS EXECZ/VCCZ used WaveActiveAnyTrue over
the whole host wave. On a 64-lane host, the upper guest wave therefore read
and wrote the lower guest wave's lanes.

For wave32 guests (mesh::wave_size heuristic, computed before the wave
lowerings), guest lane L now maps to host lane
(WaveGetLaneIndex() & ~31) | (L & 31). The DPP row mask uses
(lane >> 4) & 1, and EXECZ/VCCZ use the WaveActiveBallot word of the
lane's 32-lane half. On hosts with 32 lanes or fewer the base is 0, so
results there are unchanged. GDS ds_append/ds_consume (WaveActiveBallot
lowering) count and elect their leader in the same 32-lane half, so each
guest wave gets its own counter base.

Audited and left as is: DPP source lanes and permlane16/x16 stay inside
their row or 32-lane half. ds_permute/bpermute already used the half base.
QuadReadLaneAt is local to the quad. readfirstlane, mbcnt and s_bcnt1 are
lane-local in the one-lane-per-invocation model.

Wave64 guests keep their exact previous lowering. The whole-wave
WaveActive*/WavePrefix* lowerings only match wave64 code, and emitting them
in a wave32 program is now an explicit error.

No adapter here exposes 64-lane waves (WaveLaneCountMin..Max: RTX 5090
32..32, UHD 770 16..16, WARP 4..4). The new test
opcodes::lane_numbering_follows_guest_wave therefore checks the generated
source only. The 64-lane case has not been executed.

Credit: the 64-lane AMD fragment subgroup measurement (RX 7800 XT, Vulkan)
comes from americas-recomp. It was used as an observation source only, and
no code was taken (GPL-2.0).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:08:55 +00:00
github-bot closed this pull request 2026-11-26 06:08:55 +00:00
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 12:03 UTC · original

Folded into #61 (commit 8630ef2, same change rebased on 51f5319), so that everything about real hardware is in one PR. Closing this one.

**@⁠QuentinDanblon** on GitHub · 2026-11-22 12:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/62#issuecomment-7078851293) Folded into #61 (commit `8630ef2`, same change rebased on `51f5319`), so that everything about real hardware is in one PR. Closing this one.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

Main's history was rewritten, which auto-closed this PR. It is applied in 93861d6 (merged in 81a1252) with your authorship kept, thanks! (via #61's rebased copy). The added comment lines were stripped on the applied copy (the project keeps code free of comment lines).

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/62#issuecomment-7079639139) Main's history was rewritten, which auto-closed this PR. It is applied in 93861d6 (merged in 81a1252) with your authorship kept, thanks! (via #61's rebased copy). The added comment lines were stripped on the applied copy (the project keeps code free of comment lines).

Pull request closed

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