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

Merged
timbot103 merged 2 commits from upstream-pr/3793 into main 2026-12-02 05:25:05 +00:00
timbot103 commented 2026-12-01 22:54:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-01T22:54:47Z.


Part of #2413, #3416.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5596126129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3793). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-01T22:54:47Z. --- Part of #2413, #3416. 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.
R0Y00 commented 2026-12-02 02:09:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T02:09:37Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7332537178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3793#issuecomment-7332537178). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T02:09:37Z. --- 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.
timbot103 commented 2026-12-02 03:04:20 +00:00 (Migrated from github.com)

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


@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.)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7333500035 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3793#issuecomment-7333500035). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T03:04:20Z. --- @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.)*
R0Y00 commented 2026-12-02 05:24:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:24:37Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145225692 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3793#pullrequestreview-6145225692). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:24:37Z. **Review:** APPROVED --- 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.
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!3793
No description provided.