Skip to content

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

Merged
ivall merged 5 commits into
xcl-dev:mainfrom
Foniass:wave64-on-wave32
Nov 23, 2026
Merged

ivall merged 5 commits into
xcl-dev:mainfrom
Foniass:wave64-on-wave32

Conversation

@Foniass

@Foniass Foniass commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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 WIP: Experimental FidelityFX Xbox GPU compatibility — Wave64 emulation and NVIDIA support #33 (@ElHombreAlex). The protocol here is new (double-buffered slots, arrival counters, barriers where legal). Expand bounded GPU compatibility coverage #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 and others added 5 commits November 23, 2026 00:23
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]>
…ng wave32 halves

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]>
… any more

`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]>
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]>
@Foniass

Foniass commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

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

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

Merge options

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

Lum7nt commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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 (Support MSAA tiled texture placement and layout calculations #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
ivall merged commit 9f353e7 into xcl-dev:main Nov 23, 2026
ivall added a commit that referenced this pull request Nov 23, 2026
…oups

The console forms a group's waves from consecutive thread indices; the PC driver need not.
Measured on the RX 9070 (RDNA4): an 8 x 8 (x 4) or 16 x 4 group is laid out in 2 x 2 quads
(lanes 0, 1, 4, 5, 8, 9 ... hold SV_GroupIndex 0, 1, 2, 3, ...), 1-D groups in order – so
every native translation of a 2-D / 3-D console compute program read the wrong lanes with
DPP, readlane, ds_bpermute, mbcnt (prefix sums, compaction). #67 handles this for the split
form; now the native form does the same: each hardware wave takes the next 32 / 64 console
threads as it arrives (a groupshared counter – the top LDS word while the waves take their
threads when the program uses all 32 KB), lane l the l-th of them. 1-D groups (and VS, PS,
mesh, geometry) keep their HLSL. gpu_split_wave64_waves_diverge (#67) failed natively on AMD
for 8 x 8 x 4 and passes now.
ivall added a commit that referenced this pull request Nov 23, 2026
…U too

RDNA runs both wave sizes, so the NVIDIA path (#67) can be checked on AMD: pipelines
(wave32_only_for_device) and the test runner take the split form. With it the workspace
tests pass on the RX 9070, retail shader pack tests included.
ivall added a commit that referenced this pull request Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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 added a commit that referenced this pull request Nov 23, 2026
#67 removed gpu_ready_wave32; gpu_ready (a GPU with 32- or 64-lane waves, DXC) is what #46's
gpu_waves needs.
ivall added a commit that referenced this pull request Nov 23, 2026
Conflict with #67 resolved: the in-memory shader cache sits in console_to_dxil_for and its
key has split_wave64 (the split and native forms are different DXIL).
ivall pushed a commit that referenced this pull request Nov 23, 2026
The f64 NEG source modifier was emitted as -x and ABS as abs(x). DXIL
has no fneg: DXC writes -x as fsub -0.0, x, and IEEE leaves the sign
of a NaN result open, so a negated NaN kept its sign on NVIDIA
(v_frexp_mant_f64 with NEG on 0x7FF8000000000001). The hardware
modifiers only flip or clear the sign bit; they are now that, on the
high dword.

Cherry-picked from #72 (ec446ec) without #71, which #67 superseded; the
test gates on gpu_ready (#67: wave64 programs run split on 32-lane GPUs).
ivall added a commit that referenced this pull request Nov 23, 2026
Conflict with #67 resolved: main's split-aware LDS slot after the address read stays; the
addtid forms also keep clear of the split wave64 exchange (XCL_X_LDS_TOP).
ivall added a commit that referenced this pull request Nov 23, 2026
ivall pushed a commit that referenced this pull request Nov 23, 2026
In the split wave64 form (#67) every mask write exchanges the two wave32
halves' ballots. A mask whose readers take only the reading lane's own bit
(v_cndmask_b32's selector, the carry-in of v_add_co_ci / v_sub(rev)_co_ci)
needs no exchange: xcl_x_ballot_local gives the half's own word.

x64_masks.rs finds them with a backward liveness pass over the SGPRs. A
register is whole-live when some path may read its whole value before it is
written again. The rules follow the emitter, not only the operand tables:
s_cmov*, s_addk, s_mulk, s_bitset*, s_movreld and SDWA compares into their
SDST are not overwrites; s_movrels reads every register from its base; SDWA
scalar sources and SMEM register offsets are reads; EXEC, indirect jumps, the
kernel runner's end and loop exits through LOOP_GUARD count as whole reads
(loop ranges from the translator's loop_ranges, now shared). Masks into NULL
or constant false are never exchanged. Geometry mode keeps its exchanges.
XCL_X64_ALL_MASKS=1 exchanges every mask, for comparison.

bench_split_wave64 now counts each iteration's exchanges and times GPU work
only (runner::dispatch_timed: timestamps, median of 9; before, the wall time
of a whole dispatch with pipeline creation and copies). RTX 3090, all masks
(3 runs) vs default (5 runs), split / wave32:
- mask only: 1.64-1.68x -> 1.04-1.11x (one console wave per group),
  3.90-4.14x -> 1.07-1.16x (four, counter-paired)
- with a v_readfirstlane: 1.99-2.02x -> 1.74-1.81x, 6.45-6.64x -> 4.09-4.34x
The benchmark's mask is exactly the kind the pass keeps local: it shows the
exchange gone, not how much real shaders gain.

Tests: 16 for the analysis, gpu_split_wave64_lane_local_masks,
gpu_split_wave64_masks_read_whole_after_partial_writes (one kernel per rule;
the halves' SGPRs differ without it) and
gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves (counter-paired,
waves on different paths). Workspace, release, RTX 3090: 459 passed, 0 failed;
XCL_WAVE64_SPIN=1: 224 passed. Not checked: real compute shaders (Minecraft's
273 wave64 programs as compute have 38 mask writes, all local), AMD.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
…pelineX) are UAV barriers

FlushGpuCacheRangeX and FlushShaderCacheRangeX of the newer list layout were answered with nothing.
They are how a title orders a pass behind the one that wrote what it reads: a retail title calls them
thousands of times a minute, and its compute passes (the ones that write indirect arguments and the
ones that read them) had no order there. FlushPipelineX (xcl-dev#67, newer layout xcl-dev#69) as well; at xcl-dev#69 a
newer-layout title's call ran Write32BitValueBottomOfPipeX with the flags as the address.

The PC has no ranges of caches: a UAV barrier for all resources, on direct and compute lists.

Test: cache_flushes_are_uav_barriers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants