shader: broadcast lane-0 value for full-EXEC mesh v_readfirstlane_b32 (Part of #2413, #3416) #3795

Manually merged
github merged 2 commits from github-bot/gh-3793 into gh-pr/3793/base 2026-12-02 05:30:16 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-01 22:54 UTC · original
timbot103:shader/mesh-readfirstlane-broadcast → main · +289 −24 · 7 files · 2 commits · merged 2026-12-02 05:25 UTC

Part of #2413, #3418.

Lowers lane-varying _readfirstlane_b32 sD, vS in the C++ direct mesh frontend (src/gfx1013_direct_mesh.inl) when EXEC is full and control flow is provably threadgroup-uniform, using a per-guest-wave groupshared lane-0 broadcast instead of WaveReadLaneFirst.

Summary

  • Per-guest-wave broadcast: Allocates a dedicated groupshared [waves x i32] slot per instruction (accounted against DXIL's 32 KiB groupshared budget alongside meshCounts and export scratch), has guest lane 0 (wave_lane == 0) store S, synchronizes with @⁠dx.op.barrier(i32 80, i32 9), and loads slot[wave_number] for every lane. Matches guest wave64 lane 0 across both host wave32 and wave64.
  • Zero-overhead fast path: Proven-uniform sources stay on the existing fast path with zero groupshared allocations and zero barriers.
  • Strict uniformity & soundness guards:
    • Refuses broadcast unless ull_exec && !branch && !exec_skip && forward.empty() && group_flow.
    • Resets state[i.dst] = {} and uniform_inputs = false so the result is wave-uniform (
      emember_scalar), never falsely group-uniform or carrying root-constant provenance.
    • Tightens uniform_inputs for s_bitset0_b32/s_bitset1_b32 (reads dst) and full-EXEC requirement on _mov_b32/ _readfirstlane_b32.

Verification (source-built fixtures only)

Environment: Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100.0 DXC.

  • Debug (dev): ctest --preset dev --no-tests=error -R 'native_direct_mesh|native_direct_container' -V — 2/2 passed (23.64 s).
  • Release (
    elease):
    ctest --preset release --no-tests=error -R 'native_direct_mesh|native_direct_container' -V — 2/2 passed (21.17 s).
  • git diff --check origin/main..HEAD clean.

AI-assisted.

**@⁠timbot103** on GitHub · 2026-12-01 22:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3793) `timbot103:shader/mesh-readfirstlane-broadcast` → `main` · +289 −24 · 7 files · 2 commits · merged 2026-12-02 05:25 UTC Part of #2413, #3418. Lowers lane-varying _readfirstlane_b32 sD, vS in the C++ direct mesh frontend (src/gfx1013_direct_mesh.inl) when EXEC is full and control flow is provably threadgroup-uniform, using a per-guest-wave groupshared lane-0 broadcast instead of WaveReadLaneFirst. ### Summary - **Per-guest-wave broadcast:** Allocates a dedicated groupshared [waves x i32] slot per instruction (accounted against DXIL's 32 KiB groupshared budget alongside meshCounts and export scratch), has guest lane 0 (wave_lane == 0) store S, synchronizes with @⁠dx.op.barrier(i32 80, i32 9), and loads slot[wave_number] for every lane. Matches guest wave64 lane 0 across both host wave32 and wave64. - **Zero-overhead fast path:** Proven-uniform sources stay on the existing fast path with zero groupshared allocations and zero barriers. - **Strict uniformity & soundness guards:** - Refuses broadcast unless ull_exec && !branch && !exec_skip && forward.empty() && group_flow. - Resets state[i.dst] = {} and uniform_inputs = false so the result is wave-uniform ( emember_scalar), never falsely group-uniform or carrying root-constant provenance. - Tightens uniform_inputs for s_bitset0_b32/s_bitset1_b32 (reads dst) and full-EXEC requirement on _mov_b32/ _readfirstlane_b32. ### Verification (source-built fixtures only) Environment: Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100.0 DXC. - **Debug (dev):** ctest --preset dev --no-tests=error -R 'native_direct_mesh|native_direct_container' -V — **2/2 passed** (23.64 s). - **Release ( elease):** ctest --preset release --no-tests=error -R 'native_direct_mesh|native_direct_container' -V — **2/2 passed** (21.17 s). - git diff --check origin/main..HEAD clean. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 22:55:32 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 02:09 UTC · original

The DXIL controls cover the broadcast shape and convergence refusals. Please add a source-built GPU readback that reaches this barrier and checks distinct lane-0 values from at least two guest waves in one group, ideally on host wave32 and wave64. That would exercise both the slot indexing and barrier behavior on the actual mesh path.

**@⁠R0Y00** on GitHub · 2026-12-02 02:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3793#issuecomment-7332537178) The DXIL controls cover the broadcast shape and convergence refusals. Please add a source-built GPU readback that reaches this barrier and checks distinct lane-0 values from at least two guest waves in one group, ideally on host wave32 and wave64. That would exercise both the slot indexing and barrier behavior on the actual mesh path.
github-bot force-pushed github-bot/gh-3793 from 276ba83400 to ee96f6cc72 2026-12-02 03:04:39 +00:00 Compare
Author
Owner

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

@⁠R0Y00 Rebased onto origin/main (2b870868 -> ee96f6cc) and added a source-built multi-wave GPU readback fixture (tests/native_mesh_readfirstlane_check.py, registered in tests/cmake/native_mesh_readfirstlane.cmake and included in the pr preset).

What the readback exercises

  • Compiles 128-thread source-built mesh shaders through compile_dxil (gfx1013-raw-ms) for both guest wave64 (2 guest waves per group, mesh1 128 128 4 2 128 64) and guest wave32 (4 guest waves per group, mesh1 128 128 4 2 128 32), asserts the groupshared broadcast + barrier DXIL shape (assert_readfirstlane_broadcast), and renders a 32x32 target via offscreen_check --mesh-multi.
  • Each thread computes v6 = flat_tid + 1 and executes v_readfirstlane_b32 s18, v6, then exports s18 through PARAM0 to a pixel shader that writes value / 255.0 to the red channel.
  • Left-half and right-half quads reference upper-half vertices of two distinct guest waves — vertices 32..35 (guest wave 0) and 96..99 (guest wave 1) for guest wave64, and 16..19 (guest wave 0) and 48..51 (guest wave 1) for guest wave32 — so every rendered vertex sits in a different host wave from its guest wave's lane 0 on narrower hosts (proving the groupshared barrier and slot indexing across host waves), while the guest wave32 case also separates two guest waves within lanes 0..63 on a host wave64 GPU.
  • Includes a swapped-value mutant control (v6 = (flat_tid ^ wave_size) + 1) for both wave sizes, confirming 1024/1024 pixel mismatches against the original reference and 0/1024 mismatches against the swapped reference (65/1 for wave64, 33/1 for wave32).

Verification (Windows 11 26200.9974, MSVC 19.44, SDK 10.0.26100.0)

Both Debug (dev) and Release (release) passed 8/8 (native_direct_container, native_direct_mesh, mesh_multi_draw_{warp,hardware}, native_mesh_readfirstlane_{warp,hardware}, standin_exports_check, startup_stubs_ci_check; 37.07 s in Release, zero /W4 warnings in changed files):

Backend Adapter / Driver Host wave range Guest wave64 (1/65, swapped 65/1) Guest wave32 (1/33, swapped 33/1)
WARP Microsoft Basic Render Driver 10.0.26100.9818 min=4, max=4 (mesh_shader_tier=0xa) 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched
Hardware NVIDIA GeForce RTX 5080 32.0.16.2140 min=32, max=32 (mesh_shader_tier=0xa) 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched

(Note: this host has WARP wave4 and RTX 5080 wave32 adapters, no native wave64 GPU; D3D12 debug layer unavailable on this Windows build.)

**@⁠timbot103** on GitHub · 2026-12-02 03:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3793#issuecomment-7333500035) @⁠R0Y00 Rebased onto `origin/main` (`2b870868` -> `ee96f6cc`) and added a source-built multi-wave GPU readback fixture (`tests/native_mesh_readfirstlane_check.py`, registered in `tests/cmake/native_mesh_readfirstlane.cmake` and included in the `pr` preset). ### What the readback exercises - Compiles 128-thread source-built mesh shaders through `compile_dxil` (`gfx1013-raw-ms`) for both **guest wave64** (2 guest waves per group, `mesh1 128 128 4 2 128 64`) and **guest wave32** (4 guest waves per group, `mesh1 128 128 4 2 128 32`), asserts the groupshared broadcast + barrier DXIL shape (`assert_readfirstlane_broadcast`), and renders a 32x32 target via `offscreen_check --mesh-multi`. - Each thread computes `v6 = flat_tid + 1` and executes `v_readfirstlane_b32 s18, v6`, then exports `s18` through `PARAM0` to a pixel shader that writes `value / 255.0` to the red channel. - Left-half and right-half quads reference **upper-half vertices** of two distinct guest waves — vertices `32..35` (guest wave 0) and `96..99` (guest wave 1) for guest wave64, and `16..19` (guest wave 0) and `48..51` (guest wave 1) for guest wave32 — so every rendered vertex sits in a different host wave from its guest wave's lane 0 on narrower hosts (proving the groupshared barrier and slot indexing across host waves), while the guest wave32 case also separates two guest waves within lanes `0..63` on a host wave64 GPU. - Includes a swapped-value mutant control (`v6 = (flat_tid ^ wave_size) + 1`) for both wave sizes, confirming **1024/1024 pixel mismatches** against the original reference and **0/1024 mismatches** against the swapped reference (`65`/`1` for wave64, `33`/`1` for wave32). ### Verification (Windows 11 `26200.9974`, MSVC `19.44`, SDK `10.0.26100.0`) Both Debug (`dev`) and Release (`release`) passed **8/8** (`native_direct_container`, `native_direct_mesh`, `mesh_multi_draw_{warp,hardware}`, `native_mesh_readfirstlane_{warp,hardware}`, `standin_exports_check`, `startup_stubs_ci_check`; 37.07 s in Release, zero `/W4` warnings in changed files): | Backend | Adapter / Driver | Host wave range | Guest wave64 (`1`/`65`, swapped `65`/`1`) | Guest wave32 (`1`/`33`, swapped `33`/`1`) | |---|---|---|---|---| | WARP | Microsoft Basic Render Driver `10.0.26100.9818` | `min=4, max=4` (`mesh_shader_tier=0xa`) | 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched | 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched | | Hardware | NVIDIA GeForce RTX 5080 `32.0.16.2140` | `min=32, max=32` (`mesh_shader_tier=0xa`) | 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched | 1024/1024 matched, 1024/1024 mutant caught, 1024/1024 swapped matched | *(Note: this host has WARP wave4 and RTX 5080 wave32 adapters, no native wave64 GPU; D3D12 debug layer unavailable on this Windows build.)*
github-bot force-pushed github-bot/gh-3793 from ee96f6cc72 to b21d4bd031 2026-12-02 03:11:10 +00:00 Compare
github-bot force-pushed github-bot/gh-3793 from b21d4bd031 to 194abbb22a 2026-12-02 03:29:16 +00:00 Compare
github-bot changed target branch from main to gh-pr/3793/base 2026-12-02 05:30:09 +00:00
github manually merged commit 194abbb22a into gh-pr/3793/base 2026-12-02 05:30:11 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 05:24 UTC · original · approved these changes

Thanks for adding the multi-wave readback. At 194abbb2 on Windows 11 build 26300.9974, ctest --preset dev --no-tests=error -j 1 -R '^(native_mesh_readfirstlane|mesh_multi_draw)_(warp|hardware)$' --output-on-failure passed 4/4. WARP (10.0.26100.9818, host wave4) and RTX 4060 Laptop (32.0.16.1656, host wave32) matched 1024 pixels for both guest wave sizes with the debug layer enabled. The swap control mismatched all 1024 original pixels and matched the swapped reference. Physical host wave64 coverage remains open.

**@⁠R0Y00** on GitHub · 2026-12-02 05:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3793#pullrequestreview-6145225692) · **approved these changes** Thanks for adding the multi-wave readback. At `194abbb2` on Windows 11 build 26300.9974, `ctest --preset dev --no-tests=error -j 1 -R '^(native_mesh_readfirstlane|mesh_multi_draw)_(warp|hardware)$' --output-on-failure` passed 4/4. WARP (10.0.26100.9818, host wave4) and RTX 4060 Laptop (32.0.16.1656, host wave32) matched 1024 pixels for both guest wave sizes with the debug layer enabled. The swap control mismatched all 1024 original pixels and matched the swapped reference. Physical host wave64 coverage remains open.
This discussion has been locked. Commenting is limited to contributors.
No description provided.