shader: broadcast the first active lane in mesh shaders (Part of #3703) #3842

Merged
timbot103 merged 13 commits from upstream-pr/3842 into main 2026-12-03 04:12:34 +00:00
timbot103 commented 2026-12-02 08:42:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T08:42:14Z.


Part of #3703.

Summary

Extends v_readfirstlane_b32 lowering in src/gfx1013_direct_mesh.inl beyond full EXEC (part of the 813-program v_readfirstlane_b32 bucket, building on #3793):

  • Broadcasts the lowest active lane's value within each guest wave after EXEC narrows (CMPX, SAVEEXEC, and single-wave whole-wave EXECZ skips) using per-guest-wave groupshared atomicrmw umin + barriers, falling back to lane 0 when guest EXEC is empty per AMD RDNA 2 ISA §12.8.
  • Avoids barriers when the source is proven wave-uniform and complete, marks single-wave results group-uniform (waves == 1), and keeps per-lane skips, multi-wave skips, wave-varying branches, incomplete empty-EXEC sources, and SGPR/inline-constant sources refused.

Verification

  • ctest --preset pr --no-tests=error --output-on-failure -R '^native_mesh_readfirstlane_active_controls$': passed.
  • Debug (dev) and Release (release): 7/7 passed (native_mesh_readfirstlane|native_direct_mesh|native_direct_container), zero skips, zero new /W4 warnings on edited lines.
  • Hardware & software GPU readbacks: 48 draws (49,152 pixels) matched on WARP (10.0.26100.9818, wave4) and NVIDIA GeForce RTX 5080 (32.0.16.2140, wave32) across 1-wave and 2-wave guest wave32/wave64 groups on Windows 11 (26200.9974), with all 16 negative draws mismatching all 1,024 pixels.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, and git diff --check origin/main..HEAD passed.
  • Opened as Draft under #3514's 5-PR ready cap.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5602909113 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T08:42:14Z. --- Part of #3703. ### Summary Extends `v_readfirstlane_b32` lowering in `src/gfx1013_direct_mesh.inl` beyond full EXEC (part of the 813-program `v_readfirstlane_b32` bucket, building on #3793): - Broadcasts the lowest active lane's value within each guest wave after EXEC narrows (CMPX, SAVEEXEC, and single-wave whole-wave `EXECZ` skips) using per-guest-wave groupshared `atomicrmw umin` + barriers, falling back to lane 0 when guest EXEC is empty per AMD RDNA 2 ISA §12.8. - Avoids barriers when the source is proven wave-uniform and complete, marks single-wave results group-uniform (`waves == 1`), and keeps per-lane skips, multi-wave skips, wave-varying branches, incomplete empty-EXEC sources, and SGPR/inline-constant sources refused. ### Verification - `ctest --preset pr --no-tests=error --output-on-failure -R '^native_mesh_readfirstlane_active_controls$'`: passed. - Debug (`dev`) and Release (`release`): 7/7 passed (`native_mesh_readfirstlane|native_direct_mesh|native_direct_container`), zero skips, zero new `/W4` warnings on edited lines. - Hardware & software GPU readbacks: **48 draws (49,152 pixels)** matched on WARP (`10.0.26100.9818`, wave4) and NVIDIA GeForce RTX 5080 (`32.0.16.2140`, wave32) across 1-wave and 2-wave guest wave32/wave64 groups on Windows 11 (`26200.9974`), with all 16 negative draws mismatching all 1,024 pixels. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, and `git diff --check origin/main..HEAD` passed. - Opened as Draft under `#3514`'s 5-PR ready cap.
lukaslw-lab commented 2026-12-02 08:47:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T08:47:50Z.

Review: APPROVED


Reviewed e0f190ef (draft) by reading the diff; not built or run.

Verdict: approve. The first-active-lane broadcast matches RDNA2, including lane 0 for an empty EXEC, and every barrier stays in group-uniform control flow. No MUST.

  • SHOULD Run a before/after m86 census on f365f125. The uniform shortcut is tighter now (gfx1013_direct_mesh.inl:2369): under a skip whose guard is not the current lane mask, a proven-uniform source is accepted only if it is complete. That is right, because with an empty EXEC the guest reads lane 0, which an active-lanes-only value does not describe. But programs that took the shortcut before may now go to the broadcast or be refused. The census would show both effects on the 813-program row.
  • NIT This conflicts with #3806 in lower_mesh.
  • Checked, no finding:
    • Barriers (:2377): refused inside a branch, with pending forward edges, after a wave-varying branch (group_flow), and inside a per-lane skip or a whole-wave skip of a multi-wave group, including enclosing skips. So every thread reaches all three barriers.
    • Rank (:2389): lane 0 stores the sentinel width, then barrier, active lanes umin their lane, barrier, and the sentinel maps to lane 0. Then publish, barrier, load. The slots are per instruction and per wave, and the barriers separate each re-initialization from the previous iteration's reads.
    • uniform_inputs=waves==1 (:2412): a value broadcast within the only guest wave is group-uniform. With more waves it stays wave-only.
    • SGPR and inline-constant sources stay refused.

Tests: _controls is in the pr filter. The 48 WARP and hardware draws (1- and 2-wave groups, wave32 and wave64, with negative draws) ran only locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6147394035 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6147394035). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T08:47:50Z. **Review:** APPROVED --- Reviewed `e0f190ef` (draft) by reading the diff; not built or run. **Verdict: approve.** The first-active-lane broadcast matches RDNA2, including lane 0 for an empty EXEC, and every barrier stays in group-uniform control flow. No MUST. - **SHOULD** Run a before/after `m86` census on `f365f125`. The uniform shortcut is tighter now (`gfx1013_direct_mesh.inl:2369`): under a skip whose guard is not the current lane mask, a proven-uniform source is accepted only if it is complete. That is right, because with an empty EXEC the guest reads lane 0, which an active-lanes-only value does not describe. But programs that took the shortcut before may now go to the broadcast or be refused. The census would show both effects on the 813-program row. - **NIT** This conflicts with #3806 in `lower_mesh`. - Checked, no finding: - Barriers (`:2377`): refused inside a branch, with pending forward edges, after a wave-varying branch (`group_flow`), and inside a per-lane skip or a whole-wave skip of a multi-wave group, including enclosing skips. So every thread reaches all three barriers. - Rank (`:2389`): lane 0 stores the sentinel `width`, then barrier, active lanes `umin` their lane, barrier, and the sentinel maps to lane 0. Then publish, barrier, load. The slots are per instruction and per wave, and the barriers separate each re-initialization from the previous iteration's reads. - `uniform_inputs=waves==1` (`:2412`): a value broadcast within the only guest wave is group-uniform. With more waves it stays wave-only. - SGPR and inline-constant sources stay refused. Tests: `_controls` is in the `pr` filter. The 48 WARP and hardware draws (1- and 2-wave groups, wave32 and wave64, with negative draws) ran only locally.
lukaslw-lab commented 2026-12-02 09:23:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T09:23:06Z.


Census follow-up for the SHOULD in my review: f365f125 + this PR alone, same capture and method as #3703 / #3814 (6,685 distinct mesh programs, 6,436 pixel stages). Counts only.

Build Mesh translated Lost vs main Moved off v_readfirstlane_b32
f365f125 1,036 — —
f365f125 + #3842 1,036 0 0 of 621

No program changes its first refusal. In a small sample of the 621, the read sits right after a scalar if/else join, where an s_branch lands on it:

v_mul_lo_u32 vA, sX, vA
s_branch L
v_mov_b32 v4, v0          ; other arm
L: v_readfirstlane_b32 sN, vA

So the refusal comes from the forward-edge or join rule, not from narrowed EXEC. One sample was a buffer_load_format_x at a uniform index followed by the read, which is #3790's case. Not a defect in this PR: its shapes are fine, but this capture has none of them.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7340808721 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7340808721). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T09:23:06Z. --- Census follow-up for the SHOULD in my review: `f365f125` + this PR alone, same capture and method as #3703 / #3814 (6,685 distinct mesh programs, 6,436 pixel stages). Counts only. | Build | Mesh translated | Lost vs main | Moved off `v_readfirstlane_b32` | |---|---:|---:|---:| | `f365f125` | 1,036 | — | — | | `f365f125` + #3842 | 1,036 | 0 | **0** of 621 | No program changes its first refusal. In a small sample of the 621, the read sits right after a scalar if/else join, where an `s_branch` lands on it: ``` v_mul_lo_u32 vA, sX, vA s_branch L v_mov_b32 v4, v0 ; other arm L: v_readfirstlane_b32 sN, vA ``` So the refusal comes from the forward-edge or join rule, not from narrowed EXEC. One sample was a `buffer_load_format_x` at a uniform index followed by the read, which is #3790's case. Not a defect in this PR: its shapes are fine, but this capture has none of them.
lukaslw-lab commented 2026-12-02 20:25:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T20:25:07Z.

Review: APPROVED


Re-review on 25c3cdee (rebased on 5770f14e, plus the SAVEEXEC-arm broadcast and the opcode-shadowing fix).

Verdict: approve.

Census, same capture and method as before (6,685 distinct mesh programs), main 5770f14e vs this head:

Programs
Translate, main / with this PR 1,047 / 1,047
Lost / gained / first refusal moved 0 / 0 / 0

No v_readfirstlane_b32 first refusal in this capture (621 programs on 5770f14e with #3893) takes the new path yet, so this head is neutral here. The #3703 board row stays "part #3790; narrowed-skip and active-lane broadcast: #3842".

Checked:

  • The SAVEEXEC shape is dropped only for an if-only arm with a vector v_readfirstlane_b32, after validate_saveexec accepted it. An else arm keeps the diamond and still refuses (saveexec-else control).
  • First active lane: init → barrier → atomicrmw umin → barrier. The width sentinel maps an empty EXEC to lane 0, as RDNA 2 does. A separate LDS slot per instruction, and the barrier order also holds when the instruction repeats in a loop.
  • Refusal still covers a branch, forward targets, a wave-varying flow, and a whole-wave skip in a multi-wave group or under a per-lane parent.
  • state[i.dst] is now cleared on the proven path too, so an older provenance can no longer survive the write.

Update: the first run was on a main that refused 257 programs early (my #3707, #3892; fixed by #3893). I reran main 5770f14e and this head, both with that fix: 0 moved, 0 lost, 0 gained.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158339509 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6158339509). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T20:25:07Z. **Review:** APPROVED --- Re-review on `25c3cdee` (rebased on `5770f14e`, plus the SAVEEXEC-arm broadcast and the opcode-shadowing fix). **Verdict: approve.** Census, same capture and method as before (6,685 distinct mesh programs), main `5770f14e` vs this head: | | Programs | |---|---:| | Translate, main / with this PR | 1,047 / 1,047 | | Lost / gained / first refusal moved | 0 / 0 / 0 | No `v_readfirstlane_b32` first refusal in this capture (621 programs on `5770f14e` with #3893) takes the new path yet, so this head is neutral here. The #3703 board row stays "part #3790; narrowed-skip and active-lane broadcast: #3842". Checked: - The SAVEEXEC shape is dropped only for an if-only arm with a vector `v_readfirstlane_b32`, after `validate_saveexec` accepted it. An else arm keeps the diamond and still refuses (`saveexec-else` control). - First active lane: init → barrier → `atomicrmw umin` → barrier. The `width` sentinel maps an empty EXEC to lane 0, as RDNA 2 does. A separate LDS slot per instruction, and the barrier order also holds when the instruction repeats in a loop. - Refusal still covers a branch, forward targets, a wave-varying flow, and a whole-wave skip in a multi-wave group or under a per-lane parent. - `state[i.dst]` is now cleared on the proven path too, so an older provenance can no longer survive the write. Update: the first run was on a main that refused 257 programs early (my #3707, #3892; fixed by #3893). I reran main `5770f14e` and this head, both with that fix: 0 moved, 0 lost, 0 gained. AI-assisted.
timbot103 commented 2026-12-02 23:04:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T23:04:59Z.


Stacked on #3835. This branch includes its commits, so please land #3835 first. The two PRs conflict in the v_readfirstlane_b32 source handling.

  • The resolution keeps root selector provenance for full-EXEC v_readfirstlane_b32. Under narrowed EXEC it keeps this PR's source-completeness and barrier checks.
  • The reviewed commits 9e674263 and 25c3cdee are unchanged.

Tests, Windows 11 26200 with RTX 5080 and WARP. The mesh filter was native_direct_mesh|native_direct_container|native_mesh_ plus this PR's own tests. Every branch passed a full Debug build of every target, including the C++17 native_compute_pack_refusal_check.

  • Debug passed 19/19. Release passed 16/19, and the PR preset passed 3/3.
  • WARP and the RTX 5080 readbacks pass.
  • The Release failures are the existing asynchronous WARP allocation fixtures (accepted=1 refused=0). They also fail on a clean 67862ee4, and every one of them passed with X2W_SYNC_MESH_REQUESTS=1.

All six mesh PRs (#3832, #3835, #3838, #3842, #3843 and #3846) were also merged together onto 67862ee4. That combined tree passed 47/47 in Debug and 47/47 in Release, plus 8/8 under the PR preset. All 15 pairs merge cleanly.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7361540674 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7361540674). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T23:04:59Z. --- **Stacked on #3835.** This branch includes its commits, so please land #3835 first. The two PRs conflict in the `v_readfirstlane_b32` source handling. - The resolution keeps root selector provenance for full-EXEC `v_readfirstlane_b32`. Under narrowed EXEC it keeps this PR's source-completeness and barrier checks. - The reviewed commits `9e674263` and `25c3cdee` are unchanged. Tests, Windows 11 26200 with RTX 5080 and WARP. The mesh filter was `native_direct_mesh|native_direct_container|native_mesh_` plus this PR's own tests. Every branch passed a full Debug build of every target, including the C++17 `native_compute_pack_refusal_check`. - Debug passed 19/19. Release passed 16/19, and the PR preset passed 3/3. - WARP and the RTX 5080 readbacks pass. - The Release failures are the existing asynchronous WARP allocation fixtures (`accepted=1 refused=0`). They also fail on a clean `67862ee4`, and every one of them passed with `X2W_SYNC_MESH_REQUESTS=1`. All six mesh PRs (#3832, #3835, #3838, #3842, #3843 and #3846) were also merged together onto `67862ee4`. That combined tree passed 47/47 in Debug and 47/47 in Release, plus 8/8 under the PR preset. All 15 pairs merge cleanly.
timbot103 commented 2026-12-02 23:59:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T23:59:43Z.


Merged the updated #3835 (705d91ab, its fixture now uses a reserved-bit control that does not depend on #3833) into this stacked branch. The merge was clean. On main c42b7ce3 the mesh filter passes in Debug, and in Release apart from the existing asynchronous WARP allocation fixtures, which also fail on clean main and pass with X2W_SYNC_MESH_REQUESTS=1.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7362671801 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7362671801). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T23:59:43Z. --- Merged the updated #3835 (`705d91ab`, its fixture now uses a reserved-bit control that does not depend on #3833) into this stacked branch. The merge was clean. On main `c42b7ce3` the mesh filter passes in Debug, and in Release apart from the existing asynchronous WARP allocation fixtures, which also fail on clean main and pass with `X2W_SYNC_MESH_REQUESTS=1`.
timbot103 commented 2026-12-03 01:30:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T01:30:58Z.


Merged main (f3ab02fe), which now includes #3894. In the gfx1013_direct_mesh.inl conflict, full-EXEC broadcasts keep main's converged-join support, and narrowed EXEC keeps this PR's group-flow and source-completeness checks. 52390a13 restores the fixture's intended instruction order, because main moved the wave-ID read. This PR is still stacked on #3835. The PR preset passes 3/3. The remaining failures also fail on clean main: native_mesh_entry_registers_ir (fix PR coming) and the asynchronous WARP allocation fixtures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7364428712 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7364428712). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T01:30:58Z. --- Merged `main` (`f3ab02fe`), which now includes #3894. In the `gfx1013_direct_mesh.inl` conflict, full-EXEC broadcasts keep main's converged-join support, and narrowed EXEC keeps this PR's group-flow and source-completeness checks. `52390a13` restores the fixture's intended instruction order, because main moved the wave-ID read. This PR is still stacked on #3835. The PR preset passes 3/3. The remaining failures also fail on clean main: `native_mesh_entry_registers_ir` (fix PR coming) and the asynchronous WARP allocation fixtures.
timbot103 commented 2026-12-03 04:01:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T04:01:10Z.


No longer stacked: #3835 has merged. Merged main (41a83a9a) into this branch. The gfx1013_direct_mesh.inl conflict keeps main's root-provenance fast path alongside this PR's narrowed-EXEC checks. The diff against main now contains only this PR's own changes. The mesh filter passed 21/21 in Debug. Release passed 19/21; the 2 failures are the existing asynchronous WARP fixtures, which pass with X2W_SYNC_MESH_REQUESTS=1. The PR preset passed 3/3, and the RTX 5080 checks passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7367176801 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7367176801). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T04:01:10Z. --- No longer stacked: #3835 has merged. Merged `main` (`41a83a9a`) into this branch. The `gfx1013_direct_mesh.inl` conflict keeps main's root-provenance fast path alongside this PR's narrowed-EXEC checks. The diff against `main` now contains only this PR's own changes. The mesh filter passed 21/21 in Debug. Release passed 19/21; the 2 failures are the existing asynchronous WARP fixtures, which pass with `X2W_SYNC_MESH_REQUESTS=1`. The PR preset passed 3/3, and the RTX 5080 checks passed.
timbot103 commented 2026-12-03 04:01:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T04:01:29Z.


Marked Ready for review now that slots have freed up, keeping within 5 non-draft PRs per #3514. The branch merges cleanly with current main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7367182376 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7367182376). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T04:01:29Z. --- Marked Ready for review now that slots have freed up, keeping within 5 non-draft PRs per #3514. The branch merges cleanly with current `main`.
R0Y00 commented 2026-12-03 04:12:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T04:12:29Z.

Review: APPROVED


Independently reviewed 832ea56c, based on main 41a83a9a. I checked the retained root-provenance path, complete-source rule for empty EXEC, and rejection of barriers in the divergent or multi-wave skip cases. MSVC Debug ctest --preset dev --no-tests=error -j 1 -V -R '^native_mesh_readfirstlane_active' passed 3/3. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 both ran on Windows build 26300 with the D3D12 debug layer enabled, no skips. In a local rebuild, changing only the narrowed-EXEC leader back to lane 0 failed the first draw's readback on both adapters (1,024/1,024 pixels differed, zero debug errors). I restored the source. #3843 still depends on this change; the isolated trial merge with #3846 was clean.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6163571150 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6163571150). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T04:12:29Z. **Review:** APPROVED --- Independently reviewed `832ea56c`, based on `main` `41a83a9a`. I checked the retained root-provenance path, complete-source rule for empty EXEC, and rejection of barriers in the divergent or multi-wave skip cases. MSVC Debug `ctest --preset dev --no-tests=error -j 1 -V -R '^native_mesh_readfirstlane_active'` passed 3/3. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 both ran on Windows build 26300 with the D3D12 debug layer enabled, no skips. In a local rebuild, changing only the narrowed-EXEC leader back to lane 0 failed the first draw's readback on both adapters (1,024/1,024 pixels differed, zero debug errors). I restored the source. #3843 still depends on this change; the isolated trial merge with #3846 was clean.
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
R0Y00/Xbox2Windows!3842
No description provided.