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

Merged
Foniass merged 5 commits from upstream-pr/67 into main 2026-11-23 09:59:31 +00:00
Foniass commented 2026-11-22 23:26:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-22T23:26:47Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:6549195017 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/67). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-22T23:26:47Z. --- ## 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)
upstream-sync closed this pull request 2026-11-24 06:57:00 +00:00
Foniass commented 2026-11-24 07:00:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-23T02:39:09Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7090105968 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/67#issuecomment-7090105968). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-23T02:39:09Z. --- **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.
Lum7nt commented 2026-11-24 07:00:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Lum7nt on 2026-11-23T05:54:32Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7092837551 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/67#issuecomment-7092837551). Originally posted by [Lum7nt](https://github.com/Lum7nt) on 2026-11-23T05:54:32Z. --- 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.
ivall commented 2026-11-24 07:00:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T09:59:47Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7097359134 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/67#issuecomment-7097359134). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T09:59:47Z. --- 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.
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
xcl-dev/xcl!66
No description provided.