compute: return lane 0 for an empty EXEC in split-halves v_readfirstlane_b32 #3356

Manually merged
github merged 1 commit from github-bot/gh-3354 into gh-pr/3354/base 2026-11-29 08:57:44 +00:00 AGit
Owner

@⁠Not-Saii on GitHub · 2026-11-28 12:55 UTC · original
Not-Saii:compute/wave64-split-readfirstlane-empty → main · +224 −1 · 4 files · 1 commits · merged 2026-11-29 08:54 UTC

Change

A guest wave64 that runs as split halves (two host wave32s exchanging words through group memory) took the upper
half's first active lane whenever EXEC's low word was zero. Under an empty EXEC, v_readfirstlane_b32 therefore
returned guest lane 32 instead of lane 0. The split-halves select now takes the upper half only when EXEC's high word
is not zero. Each half reads its own lane 0 when its EXEC word is zero, so an empty EXEC keeps the lower half's lane 0.
Virtual-wave groups (packed slot-67 state) run each wave as split halves and go through the same select.

This pull request no longer depends on #3354, which is closed. It is one commit, a9101ed7, on main 212d4b5f.

  • src/gfx1013_direct_compute.inl: the split-halves select in v_readfirstlane_b32.
  • tests/native_wave64_readfirstlane_empty_check.py and tests/cmake/native_wave64_readfirstlane_empty.cmake: a
    new fixture. The last guest wave sets EXEC to 0 and stores v_readfirstlane_b32 of (v0 << 8) | 5 for every
    lane. It runs with 64 threads (split halves) and with 128 threads under the packed slot-67 state (virtual waves).
  • docs/experiments/native-wave64-readfirstlane-empty.md: the note, commands and result.

Verification

Commit a9101ed7, Debug build, Windows 11 build 26300, NVIDIA GeForce RTX 4090
(adapter=NVIDIA GeForce RTX 4090 vendor=10de device=2684, driver=32.0.16.1088), D3D12, DXC from Windows SDK
10.0.26100, debug layer not enabled.

cmake --build --preset dev --target compile_dxil native_store_replay
ctest --preset dev --no-tests=error -j 1 -R '^native_wave64_readfirstlane_empty_' -V
  • native_wave64_readfirstlane_empty_controls passed: both requests compile to 64 host threads with exchange
    memory, and the 128-thread request without the packed state is refused ("multi-wave64 exchange requires converged
    group control flow").
  • native_wave64_readfirstlane_empty_hardware passed: both requests matched the model in all 2,064 words, guards
    included.
  • No capability skips.

tests/docs_links_check.py and tests/bidi_controls_check.py passed.

Evidence and follow-up

Negative control: with the old select (select(cmp("ne", low, "0"), candidates[0], candidates[1])) put back in
the same tree, ctest --preset dev --no-tests=error -j 1 -R '^native_wave64_readfirstlane_empty_hardware$' -V
failed on both requests:

64 threads (split halves): mismatch at word 8 (got 0x00002005, expected 0x00000005)
128 threads (virtual waves): mismatch at word 264 (got 0x00006005, expected 0x00004005)

Both readbacks were the lane-32 value. The fixture also checks, on every run, that the readback differs from the
lane-32 expectation.

The program is source-built, assembled with LLVM 15.0.7 (clang -cc1as, gfx1013, +wavefrontsize64). One
adapter was tested; WARP was not run. Only an EXEC of 0 is covered here.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠Not-Saii** on GitHub · 2026-11-28 12:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3354) `Not-Saii:compute/wave64-split-readfirstlane-empty` → `main` · +224 −1 · 4 files · 1 commits · merged 2026-11-29 08:54 UTC ## Change A guest wave64 that runs as split halves (two host wave32s exchanging words through group memory) took the upper half's first active lane whenever EXEC's low word was zero. Under an empty EXEC, `v_readfirstlane_b32` therefore returned guest lane 32 instead of lane 0. The split-halves select now takes the upper half only when EXEC's high word is not zero. Each half reads its own lane 0 when its EXEC word is zero, so an empty EXEC keeps the lower half's lane 0. Virtual-wave groups (packed slot-67 state) run each wave as split halves and go through the same select. This pull request no longer depends on #3354, which is closed. It is one commit, `a9101ed7`, on `main` `212d4b5f`. - `src/gfx1013_direct_compute.inl`: the split-halves select in `v_readfirstlane_b32`. - `tests/native_wave64_readfirstlane_empty_check.py` and `tests/cmake/native_wave64_readfirstlane_empty.cmake`: a new fixture. The last guest wave sets EXEC to 0 and stores `v_readfirstlane_b32` of `(v0 << 8) | 5` for every lane. It runs with 64 threads (split halves) and with 128 threads under the packed slot-67 state (virtual waves). - `docs/experiments/native-wave64-readfirstlane-empty.md`: the note, commands and result. ## Verification Commit `a9101ed7`, Debug build, Windows 11 build 26300, NVIDIA GeForce RTX 4090 (`adapter=NVIDIA GeForce RTX 4090 vendor=10de device=2684`, `driver=32.0.16.1088`), D3D12, DXC from Windows SDK 10.0.26100, debug layer not enabled. ```powershell cmake --build --preset dev --target compile_dxil native_store_replay ctest --preset dev --no-tests=error -j 1 -R '^native_wave64_readfirstlane_empty_' -V ``` - `native_wave64_readfirstlane_empty_controls` passed: both requests compile to 64 host threads with exchange memory, and the 128-thread request without the packed state is refused ("multi-wave64 exchange requires converged group control flow"). - `native_wave64_readfirstlane_empty_hardware` passed: both requests matched the model in all 2,064 words, guards included. - No capability skips. `tests/docs_links_check.py` and `tests/bidi_controls_check.py` passed. ## Evidence and follow-up Negative control: with the old select (`select(cmp("ne", low, "0"), candidates[0], candidates[1])`) put back in the same tree, `ctest --preset dev --no-tests=error -j 1 -R '^native_wave64_readfirstlane_empty_hardware$' -V` failed on both requests: ``` 64 threads (split halves): mismatch at word 8 (got 0x00002005, expected 0x00000005) 128 threads (virtual waves): mismatch at word 264 (got 0x00006005, expected 0x00004005) ``` Both readbacks were the lane-32 value. The fixture also checks, on every run, that the readback differs from the lane-32 expectation. The program is source-built, assembled with LLVM 15.0.7 (`clang -cc1as`, gfx1013, `+wavefrontsize64`). One adapter was tested; WARP was not run. Only an EXEC of 0 is covered here. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Direct compute runs a guest wave64 as two host wave32s that exchange mask
words at group barriers. Guest waves that branch apart reach a different
number of those barriers, so a group of more than one guest wave with a
conditional branch and a mask write, lane read, LDS access or s_barrier
was refused ("multi-wave64 exchange requires converged group control
flow"). Such a group now runs one host wave32 per guest wave64: host lane
j carries guest lanes j and j + 32, and each vector instruction is emitted
once per lane set. Every other request compiles to the same module.

When a wave can end or skip an s_barrier that the others reach, the
program gets one barrier site in a loop, so every thread passes the same
barrier the same number of times. An s_barrier inside a guest loop is
refused.

New tests native_wave64_lane_pairs_controls and _hardware: ten
source-built programs with CPU models and 16 negative controls, run as
lane pairs (128 and 256 threads) and as split halves (64 threads).
native_direct_container_check expects its two divergent multi-wave cases
to compile as lane pairs and checks that the converged one keeps split
halves.

Refs #3237

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
A guest wave64 that runs as split halves took the upper half's first
active lane whenever EXEC's low word was zero, so v_readfirstlane_b32
under an empty EXEC returned guest lane 32. It now takes the upper half
only when EXEC's high word is not zero, as the lane-pair lowering does,
and an empty EXEC returns lane 0.

native_wave64_lane_pairs_check.py asserts readfirstlane_empty for the
64-thread split-halves run as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 12:57:19 +00:00
github-bot force-pushed github-bot/gh-3354 from 02cda8438a to 71c69b6e2e 2026-11-28 13:38:20 +00:00 Compare
github-bot force-pushed github-bot/gh-3354 from 71c69b6e2e to 71627ab220 2026-11-28 20:04:41 +00:00 Compare
Author
Owner

@⁠KelboLive on GitHub · 2026-11-28 20:54 UTC · original · approved these changes

LGTM — correct fix for empty EXEC in split-halves v_readfirstlane_b32.

Adds a select that falls through to the high word's first active lane when the low word is zero, returning lane 0 for an entirely empty EXEC. The fixture's readfirstlane_empty program verifies both layouts (lane pairs and split halves) match the expected lane 0 behavior.

Ready to land.

**@⁠KelboLive** on GitHub · 2026-11-28 20:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3354#pullrequestreview-6100049600) · **approved these changes** LGTM — correct fix for empty EXEC in split-halves v_readfirstlane_b32. Adds a select that falls through to the high word's first active lane when the low word is zero, returning lane 0 for an entirely empty EXEC. The fixture's readfirstlane_empty program verifies both layouts (lane pairs and split halves) match the expected lane 0 behavior. Ready to land.
Author
Owner

@⁠KelboLive on GitHub · 2026-11-28 21:57 UTC · original · approved these changes

LGTM — correct fix for empty EXEC in split-halves v_readfirstlane_b32.

Adds a select that falls through to the high word's first active lane when the low word is zero, returning lane 0 for an entirely empty EXEC. The fixture's readfirstlane_empty program verifies both layouts (lane pairs and split halves) match the expected lane 0 behavior.

Ready to land.

**@⁠KelboLive** on GitHub · 2026-11-28 21:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3354#pullrequestreview-6100254265) · **approved these changes** LGTM — correct fix for empty EXEC in split-halves v_readfirstlane_b32. Adds a select that falls through to the high word's first active lane when the low word is zero, returning lane 0 for an entirely empty EXEC. The fixture's readfirstlane_empty program verifies both layouts (lane pairs and split halves) match the expected lane 0 behavior. Ready to land.
github-bot force-pushed github-bot/gh-3354 from 71627ab220 to a9101ed711 2026-11-29 01:53:38 +00:00 Compare
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 02:10 UTC · original · approved these changes

Approving head a9101ed7. Diff read against main 212d4b5f; nothing built or run.

The select at src/gfx1013_direct_compute.inl:3512 returns the first active lane for every EXEC: low word non-zero takes the lower half, low zero and high non-zero takes the upper half, both zero takes the lower half. Each half already reads its own lane 0 for an empty word (line 3507), and exchange_halves returns the lower half first, so an empty EXEC now gives guest lane 0 instead of lane 32. Only this path changes; the mesh, graphics and gfx2hlsl handlers are untouched.

Non-blocking: the fixture only sets EXEC to 0, as the Limits section says. By reading, each of these one-line changes to line 3512 makes the select always return candidates[0], which still passes the fixture but breaks the case where the first active lane is in the upper half (EXEC low word 0, high word non-zero):

  • inner select(cmp("ne", read(127), "0"), candidates[1], candidates[0]) -> candidates[0]
  • inner cmp("ne", read(127), "0") -> cmp("ne", low, "0")
  • outer cmp("ne", low, "0") -> cmp("ne", read(127), "0")

I found no other test that runs a split-halves v_readfirstlane_b32 with that EXEC. A second request with, for example, EXEC = 0x0000000400000000 (expected: the value of guest lane 34) would cover it.

CI is green, but neither new test ran on this PR: the pr test preset's include list does not match native_wave64_readfirstlane_empty_*. On pushes to main the dev preset runs with -E '_hardware$', so only _controls is in CI.

**@⁠Leyukaka** on GitHub · 2026-11-29 02:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3354#pullrequestreview-6101023715) · **approved these changes** Approving head `a9101ed7`. Diff read against `main` `212d4b5f`; nothing built or run. The select at `src/gfx1013_direct_compute.inl:3512` returns the first active lane for every EXEC: low word non-zero takes the lower half, low zero and high non-zero takes the upper half, both zero takes the lower half. Each half already reads its own lane 0 for an empty word (line 3507), and `exchange_halves` returns the lower half first, so an empty EXEC now gives guest lane 0 instead of lane 32. Only this path changes; the mesh, graphics and gfx2hlsl handlers are untouched. Non-blocking: the fixture only sets EXEC to 0, as the Limits section says. By reading, each of these one-line changes to line 3512 makes the select always return `candidates[0]`, which still passes the fixture but breaks the case where the first active lane is in the upper half (EXEC low word 0, high word non-zero): - inner `select(cmp("ne", read(127), "0"), candidates[1], candidates[0])` -> `candidates[0]` - inner `cmp("ne", read(127), "0")` -> `cmp("ne", low, "0")` - outer `cmp("ne", low, "0")` -> `cmp("ne", read(127), "0")` I found no other test that runs a split-halves `v_readfirstlane_b32` with that EXEC. A second request with, for example, EXEC = `0x0000000400000000` (expected: the value of guest lane 34) would cover it. CI is green, but neither new test ran on this PR: the `pr` test preset's include list does not match `native_wave64_readfirstlane_empty_*`. On pushes to `main` the dev preset runs with `-E '_hardware$'`, so only `_controls` is in CI.
github-bot changed target branch from main to gh-pr/3354/base 2026-11-29 08:57:43 +00:00
github manually merged commit a9101ed711 into gh-pr/3354/base 2026-11-29 08:57:44 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.