feat: WaveSync and the guest wave size for compute: wave-wide gathers through groupshared memory #2791
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2791
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2791/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@tedin7 on GitHub · 2026-11-26 09:35 UTC · original
tedin7:x2w-wavesync-compute→main· +366 −19 · 6 files · 1 commits · closed without mergingPart of #1723
What this unblocks: wave-wide answers (any lane, first lane, one lane) for compute programs in a guest wave that the host splits arbitrarily, and
v_readfirstlane_b32of a per-lane VGPR; the base for the tick-mode and wave-wide EXEC work that stacks on it.Source: DirectX-Specs, HLSL shader model 6.0 wave intrinsics and "groupshared" memory with
GroupMemoryBarrierWithGroupSync(no host wave intrinsic is used); AMD "RDNA 2" Instruction Set Architecture reference guide, sections on wave32/wave64 execution, the EXEC mask andV_READFIRSTLANE_B32(lowest lane with its EXEC bit set; lane 0 when EXEC is zero).What changed
WaveSync(tools/startup/gfx2hlsl.py): a thread publishes its bit and value into groupshared words, the group meets at one barrier, every thread reads its guest wave's word:gather_any,gather_first,gather_lane. Buffers rotate by site number so a site never reuses a word still being read. A site is only legal where control flow is uniform across the group, otherwiseUnsupported. A guest wave iswaveconsecutive threads in linear thread order (32 or 64), so the result does not depend on the host wave size (WARP has 4-lane waves).ComputePipeline(..., wave=None)takes the guest wave size, or reads it from the program's mask operations (exec_lo/_b32forms: 32;exec,exec_hi,_b64forms or a pair-destination compare: 64; none or mixed: unknown, no gather is emitted). It emits theWaveSyncdeclarations and prologue only when a site was used.v_readfirstlane_b32of a VGPR that is not proven wave-uniform becomes agather_firstsite (EXEC bit as the active expression; lane 0 of the wave when EXEC is zero), for groups up to 1024 threads. Programs with any branch not proved the same for every lane are refused after the pass (the barrier must be reached by every thread), as is an unknown guest wave size.vcc_lofor a compare, and a branch on exec names no wave size.What stays refused
s_cbranch_execzskips are the next step (wave-wide EXEC decisions) and are not in this PR.Tests
startup_gfx2hlsl_wavesync_check.py(text and refusals of the three gathers, uniform-flow refusal, wave and group limits); registered asstartup_gfx2hlsl_wavesync.startup_compute_waterfall.py(run bystartup_compute_readfirstlane): first-lane programs for groups of 4, 32, 33, 64 (wave 32) and 64 (wave 64), wave inference unit checks, and a WARP dispatch case with 32- and 64-thread groups (one and two guest waves) and seven EXEC thresholds, each compared with a CPU reference per guest wave, plus a wrong-lane control (lane 0 instead of the first enabled lane).startup_gfx2hlsl_compute_check.py: a per-lane address read translates with a known wave and is refused without one.startup_compute_readfirstlane_check.py: a thread-id source now translates through the gather; the lane-mask controls still refuse.Verification
python3 -B tests/startup_gfx2hlsl_wavesync_check.py,tests/startup_compute_readfirstlane_check.py --llvm-mc llvm-mc-19,tests/startup_gfx2hlsl_compute_check.pyall rc=0.tests/startup_*check.pyset differs from main only by the new check (rc=0).InterlockedMinwas not compiled with DXC/FXC here.AI-assisted; commands listed were executed locally.
@RavenCurseBurg on GitHub · 2026-11-26 09:56 UTC · original
I will test WaveSync on non-1D thread groups with an incomplete final guest wave. I will compare first/any/indexed gathers with a CPU reference on WARP, UHD 770 and RTX 4060, including an empty mask, missing final-wave lane, and a wrong-lane control.
@tedin7 on GitHub · 2026-11-26 10:12 UTC · original
Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.
@RavenCurseBurg on GitHub · 2026-11-26 10:31 UTC · original
I tested the WaveSync helpers at
2c7d1bb7with 3D groups (5,4,3) and (7,5,2), guest wave sizes 32 and 64, and loops of 1, 2, 3, 4 and 7 rounds. The output address usesSV_GroupIndex, independently of the helper's linearization. A CPU reference checks four words per thread (first lane, its value, any bit, indexed value) and all remaining sentinel words in the 320-word UAV. The mask foranyis independent of the first-lane mask, including a case with no first lane and a true any result.On WARP, Intel UHD 770 and RTX 4060, each of the 20 original cases matched all 320 words. As a control I compiled a shader that requests a neighboring lane. It matched its independently predicted output in all 20 cases. Compared with the original reference it failed in exactly 17 cases per adapter, with precisely the predicted number of different words (32, 60, 64 or 70). In the other three cases both indices were absent from a 60-thread partial wave64 and both correctly returned zero.
Reproduction script. From that checkout:
Use
hardwarewithXBOX2WINDOWS_ADAPTER=IntelorNVIDIAfor the physical runs. Windows 11 26100.9711, WARP 10.0.26100.9711, Intel 32.0.101.5973, NVIDIA 32.0.15.9579, DXC SM 6.0, D3D12 debug layer unavailable. The probe instantiates the PR's WaveSync helpers directly. AI-assisted with Codex.Pull request closed