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

Manually merged
github merged 13 commits from github-bot/gh-3842 into gh-pr/3842/base 2026-12-03 04:17:29 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-02 08:42 UTC · original
timbot103:shader/mesh-readfirstlane-skip → main · +260 −16 · 5 files · 13 commits · merged 2026-12-03 04:12 UTC

Part of #3705.

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 #3795):

  • 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.
**@⁠timbot103** on GitHub · 2026-12-02 08:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842) `timbot103:shader/mesh-readfirstlane-skip` → `main` · +260 −16 · 5 files · 13 commits · merged 2026-12-03 04:12 UTC Part of #3705. ### 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 #3795): - 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.
Use per-guest-wave shared storage to select the minimum active lane, with lane zero as the empty-EXEC fallback. Require group convergence for each barrier and cover CMPX, SAVEEXEC, and whole-wave skips with draw readbacks.

Part of #3703
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 08:45:21 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 08:47 UTC · original · approved these changes

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 #3808 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** on GitHub · 2026-12-02 08:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6147394035) · **approved these changes** 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 #3808 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.
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 09:23 UTC · original

Census follow-up for the SHOULD in my review: f365f125 + this PR alone, same capture and method as #3705 / #3816 (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 + #3844 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 #3792's case. Not a defect in this PR: its shapes are fine, but this capture has none of them.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 09:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7340808721) Census follow-up for the SHOULD in my review: `f365f125` + this PR alone, same capture and method as #3705 / #3816 (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` + #3844 | 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 #3792's case. Not a defect in this PR: its shapes are fine, but this capture has none of them.
Keep the uniform scalar loop lowering alongside the validated in-place SAVEEXEC narrowing for a first-active-lane broadcast. Preserve the SAVEEXEC arm refusal controls.
github-bot force-pushed github-bot/gh-3842 from ccff4f7e20 to 25c3cdee4a 2026-12-02 12:37:42 +00:00 Compare
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 20:25 UTC · original · approved these changes

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 #3895) takes the new path yet, so this head is neutral here. The #3705 board row stays "part #3792; narrowed-skip and active-lane broadcast: #3844".

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 #3709, #3894; fixed by #3895). I reran main 5770f14e and this head, both with that fix: 0 moved, 0 lost, 0 gained.

AI-assisted.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 20:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6158339509) · **approved these changes** 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 #3895) takes the new path yet, so this head is neutral here. The #3705 board row stays "part #3792; narrowed-skip and active-lane broadcast: #3844". 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 #3709, #3894; fixed by #3895). I reran main `5770f14e` and this head, both with that fix: 0 moved, 0 lost, 0 gained. AI-assisted.
Part of #3703
# Conflicts:
#	src/gfx1013_direct_mesh.inl
Keep the full-EXEC root value identity from the heap proof and apply first-active-lane completeness checks to the remaining uniform and broadcast paths.
The full Texture1D descriptor path on main rebuilt only the mask from the root constant. Share selector lowering with typed buffer loads so the DXIL slot and the reported selector agree for shifted fields and immediate displacements.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 23:04 UTC · original

Stacked on #3837. This branch includes its commits, so please land #3837 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 (#3834, #3837, #3840, #3844, #3845 and #3848) 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** on GitHub · 2026-12-02 23:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7361540674) **Stacked on #3837.** This branch includes its commits, so please land #3837 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 (#3834, #3837, #3840, #3844, #3845 and #3848) 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.
The shared graphics decoder can admit DLC and GLC for read-only scalar loads. Exercise a reserved bit in the address word so the refusal control checks unsupported addressing under either decoder policy.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 23:59 UTC · original

Merged the updated #3837 (705d91ab, its fixture now uses a reserved-bit control that does not depend on #3835) 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** on GitHub · 2026-12-02 23:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7362671801) Merged the updated #3837 (`705d91ab`, its fixture now uses a reserved-bit control that does not depend on #3835) 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`.
# Conflicts:
#	src/gfx1013_direct_mesh.inl
The full-EXEC join fixture now reads the wave ID before allocation. Locate the shared instructions before arranging the active-lane entry so the count and wave32 lane proof still modify the intended words.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-03 01:30 UTC · original

Merged main (f3ab02fe), which now includes #3896. 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 #3837. 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** on GitHub · 2026-12-03 01:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7364428712) Merged `main` (`f3ab02fe`), which now includes #3896. 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 #3837. 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.
# Conflicts:
#	src/gfx1013_direct_mesh.inl
Author
Owner

@⁠timbot103 on GitHub · 2026-12-03 04:01 UTC · original

No longer stacked: #3837 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** on GitHub · 2026-12-03 04:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7367176801) No longer stacked: #3837 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.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-03 04:01 UTC · original

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

**@⁠timbot103** on GitHub · 2026-12-03 04:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#issuecomment-7367182376) Marked Ready for review now that slots have freed up, keeping within 5 non-draft PRs per #3516. The branch merges cleanly with current `main`.
github-bot changed target branch from main to gh-pr/3842/base 2026-12-03 04:17:25 +00:00
github manually merged commit 832ea56c97 into gh-pr/3842/base 2026-12-03 04:17:29 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 04:12 UTC · original · approved these changes

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. #3845 still depends on this change; the isolated trial merge with #3848 was clean.

**@⁠R0Y00** on GitHub · 2026-12-03 04:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3842#pullrequestreview-6163571150) · **approved these changes** 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. #3845 still depends on this change; the isolated trial merge with #3848 was clean.
This discussion has been locked. Commenting is limited to contributors.
No description provided.