Wave64 console programs on GPUs with 32-lane waves only (NVIDIA) #67

Manually merged
github merged 5 commits from gh-pr/67/head into gh-pr/67/base 2026-11-26 04:07:42 +00:00
Owner

@⁠Foniass on GitHub · 2026-11-22 23:26 UTC · original
Foniass:wave64-on-wave32 → main · +799 −163 · 11 files · 5 commits · merged 2026-11-23 09:59 UTC

Wave64 console programs on GPUs with 32-lane waves only (NVIDIA)

NVIDIA's D3D12 wave range is 32..32, so [WaveSize(64)] shaders are rejected: wave64 compute pipelines were refused (their dispatches skipped every frame) and mesh / ES+GS programs ran as independent halves without cross-half operations (#14, #39). (An earlier version of this text guessed that skipped compute work caused Minecraft's flicker on NVIDIA. It doesn't: Minecraft dispatches no compute work at all. The flicker was lost descriptor heaps, fixed in #84.)

On such a GPU (same detection, pso::wave32_only_for_device) each console wave of a wave64 kernel / compute / mesh / ES+GS program now runs as two hardware wave32s of one thread group that exchange through groupshared wherever a value must be whole-wave: masks, v_readlane / v_readfirstlane, ds_bpermute, GLC scalar loads. Both halves hold identical EXEC / VCC / SGPRs and take the same branches, so the recompiler's uniform-branch assumption still holds; DPP / swizzle / permlane stay within a half. One console wave per group meets at group barriers; several meet pairwise through double-buffered slots and arrival counters (bounded: a fault degrades the output, never hangs). Hardware waves take console thread ids as they arrive, because NVIDIA does not form waves from consecutive SV_GroupIndex for 3-D groups (8×8×4). Design, hazards, cost: docs/wave64-on-wave32.md.

  • Native path: byte-identical HLSL for every native translation the test suite makes (dumped and diffed against main). Not re-run on AMD hardware: the machine's AMD iGPU is disabled.
  • RTX 5070 Ti: workspace, release: 373 passed, 0 failed, 35 ignored (the new benchmark). SKIPPED …: no wave64 lines: 39 on main, 2 here. The two left: gpu_wave32_program_in_wave64_hardware, which needs 64-lane hardware, and the native-wave64 half of gpu_geometry_wave32_prefix_count_over_a_mask (its split half runs). The runner checks that both halves end with the same SGPRs; XCL_WAVE64_SPIN=1 (counter variant everywhere) passes too. New tests: cross-half ops, four diverging console waves per group in 1-D / 3-D groups, mesh form; bench_split_wave64 (ignored).
  • Cost (bench_split_wave64, worst case, one mask exchange per 8 instructions): 1.3× with one console wave per group, ~5× with four (waiting waves keep issuing). Real shaders do far more work per mask. Next step: no exchange for masks used only lane by lane (v_cmp + v_cndmask).
  • Still open on NVIDIA: wave64 VS / PS that read lanes 32..63 – they run in 32-lane waves where those lanes do not exist, and groupshared is not available there.
  • Also: the half-local form nothing generates any more is removed; GPU tests skip cleanly on WARP (it accepts neither 32- nor 64-lane shaders); a ds_add_rtn test now allows the old values to wrap around 0xFFFFFFFF.
  • Credit: the groupshared rendezvous in the LDS tail and the [WaveSize(64)] finding come from #33 (@⁠ElHombreAlex). The protocol here is new (double-buffered slots, arrival counters, barriers where legal). #35's mesh lowering is separate and untouched.

The UAV-barrier and v_fract_f32 fixes found during this work are in a separate PR: #68.

Not checked: retail shaders (no shader pack on this machine). Minecraft exercises none of it (0 compute dispatches, VS / PS only); with this PR (and #84, #86) its menu runs at 60 fps without flicker and a world loads.

🤖 Generated with Claude Code

**@⁠Foniass** on GitHub · 2026-11-22 23:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/67) `Foniass:wave64-on-wave32` → `main` · +799 −163 · 11 files · 5 commits · merged 2026-11-23 09:59 UTC ## Wave64 console programs on GPUs with 32-lane waves only (NVIDIA) NVIDIA's D3D12 wave range is 32..32, so `[WaveSize(64)]` shaders are rejected: wave64 compute pipelines were refused (their dispatches skipped every frame) and mesh / ES+GS programs ran as independent halves without cross-half operations (#14, #39). (An earlier version of this text guessed that skipped compute work caused Minecraft's flicker on NVIDIA. It doesn't: Minecraft dispatches no compute work at all. The flicker was lost descriptor heaps, fixed in #84.) On such a GPU (same detection, `pso::wave32_only_for_device`) each console wave of a wave64 kernel / compute / mesh / ES+GS program now runs as two hardware wave32s of one thread group that exchange through groupshared wherever a value must be whole-wave: masks, `v_readlane` / `v_readfirstlane`, `ds_bpermute`, GLC scalar loads. Both halves hold identical EXEC / VCC / SGPRs and take the same branches, so the recompiler's uniform-branch assumption still holds; DPP / swizzle / permlane stay within a half. One console wave per group meets at group barriers; several meet pairwise through double-buffered slots and arrival counters (bounded: a fault degrades the output, never hangs). Hardware waves take console thread ids as they arrive, because NVIDIA does not form waves from consecutive `SV_GroupIndex` for 3-D groups (8×8×4). Design, hazards, cost: `docs/wave64-on-wave32.md`. - **Native path:** byte-identical HLSL for every native translation the test suite makes (dumped and diffed against main). Not re-run on AMD hardware: the machine's AMD iGPU is disabled. - **RTX 5070 Ti:** workspace, release: 373 passed, 0 failed, 35 ignored (the new benchmark). `SKIPPED …: no wave64` lines: 39 on main, 2 here. The two left: `gpu_wave32_program_in_wave64_hardware`, which needs 64-lane hardware, and the native-wave64 half of `gpu_geometry_wave32_prefix_count_over_a_mask` (its split half runs). The runner checks that both halves end with the same SGPRs; `XCL_WAVE64_SPIN=1` (counter variant everywhere) passes too. New tests: cross-half ops, four diverging console waves per group in 1-D / 3-D groups, mesh form; `bench_split_wave64` (ignored). - **Cost** (`bench_split_wave64`, worst case, one mask exchange per 8 instructions): 1.3× with one console wave per group, ~5× with four (waiting waves keep issuing). Real shaders do far more work per mask. Next step: no exchange for masks used only lane by lane (`v_cmp` + `v_cndmask`). - **Still open on NVIDIA:** wave64 VS / PS that read lanes 32..63 – they run in 32-lane waves where those lanes do not exist, and groupshared is not available there. - **Also:** the half-local form nothing generates any more is removed; GPU tests skip cleanly on WARP (it accepts neither 32- nor 64-lane shaders); a `ds_add_rtn` test now allows the old values to wrap around 0xFFFFFFFF. - **Credit:** the groupshared rendezvous in the LDS tail and the `[WaveSize(64)]` finding come from #33 (@⁠ElHombreAlex). The protocol here is new (double-buffered slots, arrival counters, barriers where legal). #35's mesh lowering is separate and untouched. The UAV-barrier and `v_fract_f32` fixes found during this work are in a separate PR: #68. Not checked: retail shaders (no shader pack on this machine). Minecraft exercises none of it (0 compute dispatches, VS / PS only); with this PR (and #84, #86) its menu runs at 60 fps without flicker and a world loads. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
LDS is not zeroed between dispatches, so the counter starts from whatever the
previous shader left there; when that was 0xFFFFFFFF the 64 old values are
0xFFFFFFFF, 0, 1, …, 62 – correct, but the sorted comparison expected a run
without the wrap and failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NVIDIA's D3D12 wave range is 32..32, so a [WaveSize(64)] compute shader is
rejected at PSO creation: wave64 compute programs were refused there (their
dispatches skipped every frame), and mesh / ES+GS programs ran as two
independent halves only when they had no cross-half operation.

Now, when the device cannot run 64-lane waves (the same detection as before,
`pso::wave32_only_for_device`), each console wave of a wave64 kernel, compute,
mesh or ES+GS program runs as two hardware wave32s of the same thread group
that exchange through groupshared memory wherever a value has to be the whole
wave's: every mask (ballot), v_readlane / v_readfirstlane, ds_bpermute and GLC
scalar loads. Both halves then hold the full 64-bit EXEC / VCC and identical
SGPRs and take every branch the same way; DPP, ds_swizzle and v_permlane(x)16
stay inside a half and need nothing. One console wave per group meets at group
barriers; several (mesh, compute > 64 threads) meet pairwise through
double-buffered slots and arrival counters, bounded so that a desynchronised
pair degrades instead of hanging the GPU. Hardware threads take console thread
ids in the order their waves arrive: NVIDIA does not form waves from
consecutive thread indices for 3-D groups (8 x 8 x 4).

GPUs with 64-lane waves get byte-identical HLSL for every native translation
the test suite makes. Design, hazards and measured cost:
docs/wave64-on-wave32.md. The idea of a groupshared rendezvous kept in the LDS
tail, and the finding that NVIDIA rejects [WaveSize(64)], come from PR #33
(ElHombreAlex); the protocol here is new (double-buffered slots, counted
arrivals, barriers where they are legal).

Tests: the instruction tests run on 32-lane GPUs too (`runner::options`), and
the kernel runner fails when the two halves end with different SGPRs; new
tests for cross-half masks, lane reads and scalar loads, for four diverging
console waves per group in 1-D and 3-D groups, mesh form checks, and an
ignored benchmark (`bench_split_wave64`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`xcl_logical_wave64` (two independent halves, each with only its own mask
word) was set by split geometry and split mesh translation, which now use the
exchanging split form. It stayed `false` everywhere, so removing its branches
from `ballot` / `rla` changes no generated shader's behaviour; the hazard
list's doc says what it is still good for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The split wave64 form needs [WaveSize(32)]; WARP takes neither 32 nor 64, so
the instruction tests now skip there (`runner::wave64_programs_supported`)
instead of failing at PSO creation, and the two geometry tests that always
ran the [WaveSize(32)] form use the same check (`gpu_ready_wave32` is gone).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:40 +00:00
github manually merged commit 66e23c5d65 into gh-pr/67/base 2026-11-26 04:07:42 +00:00
Author
Owner

@⁠Foniass on GitHub · 2026-11-23 02:39 UTC · original

Overlap with #70, #71 and #72, to make the choice easier for the reviewer.

This PR and @⁠gefydev's #70 / #71 / #72 solve the same problem: wave64 console programs on GPUs with 32-lane waves only (NVIDIA). They conflict (emit.rs, pso.rs, runner.rs, real.rs, tests.rs), so only one approach can go in as is. Here are both, run on the same machine.

How they differ

  • #70: a wave64 compute program runs as two independent wave32 halves. A program whose halves must exchange values (whole-wave masks, v_readlane, DPP / swizzle reductions) is still refused, as mesh programs are on main.
  • #71: the same split for the GPU test kernels. #72 is an f64 NEG / ABS sign fix on top of #71.
  • #67: the halves exchange through groupshared wherever a value must be whole-wave, so those programs run too. It covers compute, test kernels, mesh and ES+GS.

Test suite: RTX 5070 Ti, driver 32.0.16.2114. Each column is merged onto current main (dd713e3), then cargo build --workspace --release and cargo test --workspace --release.

passed failed SKIPPED … no wave64
main 372 0 41
#67 373 0 2
#70 375 0 41
#72 (includes #71) 373 0 18
#70 + #72 376 0 18
#67 + #72's f64 commit ec446ec 373 0 2
  • These 16 GPU tests run and pass with #67 but are still skipped with #70 + #72: far_jumps_are_direct_branches, gpu_built_bvh_nodes_match_the_cpu_node_test, gpu_bvh64_intersect_ray_across_memory_windows_and_grazing, gpu_compute_mode_dispatch_abi, gpu_divergence_through_exec, gpu_ds_swizzle_modes, gpu_format_stores_atomics_global_lds, gpu_graphics_vs_ps_draw, gpu_memory_windows_above_4_gib, gpu_mesh_mode_two_passes, gpu_scalar_loop_and_scc, gpu_sdwa_dpp_and_cross_lane, gpu_sparse_vram_descriptors_buffers_and_xmem, gpu_triangle_pair_and_box16_nodes, gpu_tsharp_to_d3d12_resources, gpu_unified_memory_arena.
  • #78's end-to-end compute test (gpu_compute_e2e) fails on main (0x80070057) and passes both with #67 and with #70 + #72. #78 merges cleanly with either.
  • #72's f64 fix is useful either way. Cherry-picked onto #67 it needs one change in its test (gpu_ready_wave32 → gpu_ready, since that helper comes from #71), then everything passes.
  • Minecraft doesn't tell them apart: it dispatches no compute work at all. With #67 (and #84, #86) its menu runs at 60 fps without flicker, and a world loads.
  • Not checked: #67 on an AMD GPU (none here). #70 and #71 already have outside results on RTX 4060, RTX 5070 and an AMD iGPU.

Merge options

  • #67: #70 and #71 are covered, and #72's f64 commit can go in on its own with the one-line test change.
  • #70 – #72 first: #67 can be rebased on them, so that what remains of it is the cross-half exchange.

Both sets build and pass together with the other open PRs that touch the same files: main + #84 + #86 + #68 + #67 + #69, and main + #84 + #86 + #68 + #70 + #72 + #78 + #69.

**@⁠Foniass** on GitHub · 2026-11-23 02:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/67#issuecomment-7090105968) **Overlap with #70, #71 and #72**, to make the choice easier for the reviewer. This PR and @⁠gefydev's #70 / #71 / #72 solve the same problem: wave64 console programs on GPUs with 32-lane waves only (NVIDIA). They conflict (`emit.rs`, `pso.rs`, `runner.rs`, `real.rs`, `tests.rs`), so only one approach can go in as is. Here are both, run on the same machine. **How they differ** - #70: a wave64 compute program runs as two independent wave32 halves. A program whose halves must exchange values (whole-wave masks, `v_readlane`, DPP / swizzle reductions) is still refused, as mesh programs are on `main`. - #71: the same split for the GPU test kernels. #72 is an f64 NEG / ABS sign fix on top of #71. - #67: the halves exchange through groupshared wherever a value must be whole-wave, so those programs run too. It covers compute, test kernels, mesh and ES+GS. **Test suite**: RTX 5070 Ti, driver 32.0.16.2114. Each column is merged onto current `main` (`dd713e3`), then `cargo build --workspace --release` and `cargo test --workspace --release`. | | passed | failed | `SKIPPED … no wave64` | |---|---|---|---| | `main` | 372 | 0 | 41 | | #67 | 373 | 0 | 2 | | #70 | 375 | 0 | 41 | | #72 (includes #71) | 373 | 0 | 18 | | #70 + #72 | 376 | 0 | 18 | | #67 + #72's f64 commit `ec446ec` | 373 | 0 | 2 | - These 16 GPU tests run and pass with #67 but are still skipped with #70 + #72: `far_jumps_are_direct_branches`, `gpu_built_bvh_nodes_match_the_cpu_node_test`, `gpu_bvh64_intersect_ray_across_memory_windows_and_grazing`, `gpu_compute_mode_dispatch_abi`, `gpu_divergence_through_exec`, `gpu_ds_swizzle_modes`, `gpu_format_stores_atomics_global_lds`, `gpu_graphics_vs_ps_draw`, `gpu_memory_windows_above_4_gib`, `gpu_mesh_mode_two_passes`, `gpu_scalar_loop_and_scc`, `gpu_sdwa_dpp_and_cross_lane`, `gpu_sparse_vram_descriptors_buffers_and_xmem`, `gpu_triangle_pair_and_box16_nodes`, `gpu_tsharp_to_d3d12_resources`, `gpu_unified_memory_arena`. - #78's end-to-end compute test (`gpu_compute_e2e`) fails on `main` (`0x80070057`) and passes both with #67 and with #70 + #72. #78 merges cleanly with either. - #72's f64 fix is useful either way. Cherry-picked onto #67 it needs one change in its test (`gpu_ready_wave32` → `gpu_ready`, since that helper comes from #71), then everything passes. - Minecraft doesn't tell them apart: it dispatches no compute work at all. With #67 (and #84, #86) its menu runs at 60 fps without flicker, and a world loads. - Not checked: #67 on an AMD GPU (none here). #70 and #71 already have outside results on RTX 4060, RTX 5070 and an AMD iGPU. **Merge options** - **#67:** #70 and #71 are covered, and #72's f64 commit can go in on its own with the one-line test change. - **#70 – #72 first:** #67 can be rebased on them, so that what remains of it is the cross-half exchange. Both sets build and pass together with the other open PRs that touch the same files: `main` + #84 + #86 + #68 + #67 + #69, and `main` + #84 + #86 + #68 + #70 + #72 + #78 + #69.
Author
Owner

@⁠Lum7nt on GitHub · 2026-11-23 05:54 UTC · original

Tested this branch locally on Windows — all 19 dedicated unit tests for mesh_dispatch, mesh_wave, and wave-split recompilation pass cleanly.

Key architectural strengths verified:

  1. Zero-overhead native path: wave32_only_for_device accurately queries D3D12_FEATURE_DATA_D3D12_OPTIONS1 (WaveLaneCountMax < 64). On AMD/RDNA2 hardware supporting 64-lane waves, shaders compile with native [WaveSize(64)] without any groupshared preamble or runtime overhead.
  2. Deadlock safety via CFG taint analysis: The static analysis in mesh_wave effectively tracks mask/branch divergence across the CFG, ensuring paired-wave barrier synchronization (GroupMemoryBarrierWithGroupSync) is never placed in wave-divergent execution paths that would hang the GPU on NVIDIA.
  3. Merge compatibility: Merges cleanly with main and alongside our MSAA work (#43) with only a trivial 1-line resolution in Cargo.toml (from the workspace ttpf-viewer cleanup).

Excellent work solving Wave64 semantics for 32-lane architectures.

**@⁠Lum7nt** on GitHub · 2026-11-23 05:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/67#issuecomment-7092837551) Tested this branch locally on Windows — all 19 dedicated unit tests for `mesh_dispatch`, `mesh_wave`, and wave-split recompilation pass cleanly. Key architectural strengths verified: 1. **Zero-overhead native path**: `wave32_only_for_device` accurately queries `D3D12_FEATURE_DATA_D3D12_OPTIONS1` (`WaveLaneCountMax < 64`). On AMD/RDNA2 hardware supporting 64-lane waves, shaders compile with native `[WaveSize(64)]` without any groupshared preamble or runtime overhead. 2. **Deadlock safety via CFG taint analysis**: The static analysis in `mesh_wave` effectively tracks mask/branch divergence across the CFG, ensuring paired-wave barrier synchronization (`GroupMemoryBarrierWithGroupSync`) is never placed in wave-divergent execution paths that would hang the GPU on NVIDIA. 3. **Merge compatibility**: Merges cleanly with `main` and alongside our MSAA work (#43) with only a trivial 1-line resolution in `Cargo.toml` (from the workspace `ttpf-viewer` cleanup). Excellent work solving Wave64 semantics for 32-lane architectures.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 09:59 UTC · original

Merged. Checked on an RX 9070 (RDNA4): cargo test --workspace with the retail samples (shader pack, console DLLs, texture archive) – natively, and with XCL_SPLIT_WAVE64=1 (new in ba905cf: forces the split wave64 form on RDNA, which runs both wave sizes, so the NVIDIA path can be checked on AMD). XDefiant (title screen correct, 6 299 translated pipelines, 0 translation errors), Minecraft and Unicorn Overlord run.

One thing it found on AMD: gpu_split_wave64_waves_diverge failed on the native wave64 path for 8×8×4. The RX 9070 driver also does not form waves from consecutive SV_GroupIndex for 2-D / 3-D groups – it lays them out in 2×2 quads (an 8×8 group's lanes 0, 1, 4, 5, 8, 9 … hold indices 0, 1, 2, 3 …; 1-D groups are in order). So every native 2-D / 3-D console compute translation read the wrong lanes. 46a1c3f applies your arrival-order idea to the native form too (each hardware wave takes the next 32 / 64 console threads, a groupshared counter – the top LDS word while waves take their threads if the program uses all 32 KB); 1-D groups keep their HLSL. The test passes natively and split on AMD now.

**@⁠ivall** on GitHub · 2026-11-23 09:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/67#issuecomment-7097359134) Merged. Checked on an RX 9070 (RDNA4): `cargo test --workspace` with the retail samples (shader pack, console DLLs, texture archive) – natively, and with `XCL_SPLIT_WAVE64=1` (new in ba905cf: forces the split wave64 form on RDNA, which runs both wave sizes, so the NVIDIA path can be checked on AMD). XDefiant (title screen correct, 6 299 translated pipelines, 0 translation errors), Minecraft and Unicorn Overlord run. **One thing it found on AMD:** `gpu_split_wave64_waves_diverge` failed on the *native* wave64 path for `8×8×4`. The RX 9070 driver also does not form waves from consecutive `SV_GroupIndex` for 2-D / 3-D groups – it lays them out in 2×2 quads (an 8×8 group's lanes 0, 1, 4, 5, 8, 9 … hold indices 0, 1, 2, 3 …; 1-D groups are in order). So every native 2-D / 3-D console compute translation read the wrong lanes. 46a1c3f applies your arrival-order idea to the native form too (each hardware wave takes the next 32 / 64 console threads, a groupshared counter – the top LDS word while waves take their threads if the program uses all 32 KB); 1-D groups keep their HLSL. The test passes natively and split on AMD now.
This discussion has been locked. Commenting is limited to contributors.
No description provided.