D3D12 has no WaveSize for graphics shaders, so the driver picks the wave
size of a wave64 VS / PS. On an RX 6600 XT (RDNA2, reports 32-64 lanes) the
driver runs pixel shaders in waves of 32, but `wave32_only()` is false for a
32-64 range, so VS / PS did not get the `upper_lanes` form and `v_readlane`
32 wrapped to lane 0: gpu_wave64_ps_whole_wave_reductions summed twice
(928 vs 464), issue #42.
`pso::graphics_wave32` (range includes 32) now decides the split flag for
VS / PS at PSO creation (plain, mesh and GS pipelines' PS), in the test
runner and in `xcl shaders --precompile`; compute, mesh and geometry
programs keep `wave32_only`. The form checks the wave size at run time,
so a driver that picks 64 lanes is unaffected.
Tested on an RX 6600 XT (driver 32.0.21045.29003): cargo test --workspace, 569 passed, 0 failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FSrXQbQ1CgygrnUUsgR2st
On a GPU with 32-lane waves only (NVIDIA) the driver runs a console wave64
VS / PS in waves of 32: a console wave whose lanes 32..63 are not populated.
Those lanes exist on the console (inactive) and hold what v_writelane or
whole-wave code put there; here they do not exist, and WaveReadLaneAt of a
lane >= 32 reads lane & 31.
The 749 programs wave_hazards flagged in the retail pack (748 PS, 1 VS):
- 1 082 reads in 436 programs: whole-wave reductions (identity into the
lanes outside the mask, DPP8 xor 1/2/4, row_mirror, v_permlanex16,
v_readlane 32 for the upper half; min_u32 / max_u32 / or_b32). Right only
because lane 32 reads lane 0 and those ops are idempotent.
- 355 reads in 353 programs: waterfall reads, v_readlane v, s_ff1(mask &
EXEC) - a lane < 32. Right.
- 200 reads in 11 programs: SGPR spill slots in lanes 32..47. Wrong: the
v_writelane is lost, the read gets another slot.
upper_lanes.rs follows what the console's lanes 32..63 hold through the
program (forward pass: EXEC's upper word through the SGPRs as 0 / all ones /
anything; per VGPR lane unwritten / a constant / a spill slot / unknown,
evaluating whole-wave moves, selects, integer min / max / logic / add and
their DPP forms). With split_wave64 a wave64 VS / PS reads a lane >= 32 that
holds a constant as the constant, and a spill slot from a scalar shadow its
v_writelanes also write, when WaveGetLaneCount() < 64. Spill slots < 32 come
from their shadows at any wave size: a lane a partial wave did not launch
loses its slot (287 PS spill to lanes < 32). Only programs with such a read
get the form (613 of the pack; DXC compiles all). Without split_wave64 the
HLSL of all 26 698 programs is unchanged, and so is the 32-lane form of the
other modes (digests compared with main, retail_wave64_graphics_lane_forms).
wave_hazards now reports only reads the pass cannot follow: none in the pack.
GPU tests on an RTX 5070 Ti: gpu_wave64_ps_whole_wave_reductions (the pack's
reduction as min and as a sum, and the waterfall read, per hardware wave
against a console wave of the same lanes), gpu_wave64_ps_spill_slots (full
target and a 6-pixel triangle), gpu_wave64_vs_spill_slots_and_identity (3
vertices). With the old form all three fail there.
Not exact yet, on every GPU: whole-wave code in a partial wave reads lanes
the PC never launched. On the 5070 Ti they read 0, so a min reduction gives
0 in a partial pixel wave (325 programs have one); max / or are right.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
pack::scan rejected record names with a `:` (`alphaResolve:CS_…_Wrapped`), so 2 634 of
the 26 503 records of the retail shader pack were missing (55 more were found only under a
truncated alias name). Names may now be qualified; issues #34 and #36.
The new compute shaders exposed three translator gaps, all general:
- ds_swizzle_b32 told its modes apart wrongly: the bit mode with xor >= 16 (0x401F swaps
the 16-lane halves) was rejected as FFT/rotate, while real FFT/rotate offsets were taken
for quad permute. Now as the ISA defines all four modes.
- The compiler's far jump (s_getpc_b64, add of a constant, s_setpc_b64) beyond the
s_branch range is resolved to a direct branch (rdna2::resolve_far_jumps).
- term() and the block emission scanned all instructions per block; a 76 699-instruction
program with 15 995 blocks did not finish translating. Binary search: 4.7 s.
Survey of the whole pack: 26 698 / 26 698 FSSM variants in full, 0 errors (90 s, debug).
Expanded the review of XNetworking Rust implementation, emphasizing the importance of zero-initialization, proper handling of struct padding, and clear documentation for future changes. Added guidelines for working with AI agents and independent review processes before pull requests.
- README: what works (area, details, how it is verified) and what is missing (needs the exe /
not done yet / not planned), requirements incl. the system XGameRuntime.
- gallery/ removed: renders of game shaders do not belong in the repository (the ignored test
still writes them to a local XCL_GALLERY_DIR).
- THIRD_PARTY.md: AMD addrlib (tiling tables, mip chain layout) and the Windows XGameRuntime
(thunk protocol facts, forwarded APIs).
- HANDOFF / design spec: personal paths replaced by placeholders.