Repository navigation
shader-compiler: portable Wave64 ballot, vote & exec lowering for non-64-wide GPUs (#151) - #201
Open
Vladimir-Human wants to merge 2 commits into
Open
Vladimir-Human wants to merge 2 commits into
Vladimir-Human wants to merge 2 commits into
Conversation
…, prefix counts, and cross-half reads Support compute threadgroups (nx, ny, nz) where T = nx * ny * nz is a positive multiple of 64 (<= 1024), partitioning groupshared scratch per 64-lane logical wave via flattened thread index (wave_id = gindex >> 6, lane64 = gindex & 63u, half_id = (lane64 >> 5) & 1u, lane32 = lane64 & 31u). Lower 64-lane WaveActiveBallot, WaveActiveAnyTrue, WaveActiveAllTrue, WaveActiveCountBits, WavePrefixCountBits, FirstActive, v_readfirstlane_b32, cross-half WaveReadLaneAt, v_permlanex16_b32, and 64-lane reductions onto portable groupshared helpers with strict 3-level (Group > Wave > Divergent) uniformity and loop-convergence verification, hoisting wave-uniform forward skip barriers and refusing lane-divergent or wave-varying loop sites so Wave32-only GPUs run cleanly without [WaveSize(64)] and without deadlocks.
- F1: avoid
ul clobber by hi(Null) on PostAnyTrue(Null) 64-bit logic votes via dedicated w64_null{idx} register.
- F2: extract per-lane bit when writing Ballot64 results into �xec/�cc via s_mov_b64, s_cmov_b64, s_cselect_b64, or 64-bit logic ops.
- F3: support s_*_wrexec_b64 and s_{nor,xnor,orn1}_saveexec_b64 alongside saveexec_b64.
- F4: treat Literal(u32::MAX) as zero-extended low-32 mask (not 64-bit -1), promoting to Ballot64 for exact (0xffffffffu, 0u) compares/logic.
- F5: promote s_<logic>_b64 combining �xec/�cc with scalar SGPR pairs or non-mask constants so �xec/�cc is balloted before bitwise logic.
- F6: preserve s_cmov_b64 mask/ballot provenance, mark s_wqm_b64/SDWA �_cmp_*/�xec_snapshots destinations as unpromotable Mask, and guard is_ballot_word_mov against SDWA/modifiers.
- F7: refuse unhandled 32-bit/non-lowered �xec/�cc reads (s_wqm_b32, s_bcnt1_i32_b32, etc.) instead of falling through to native Wave* intrinsics or 1-bit flags.
- F8: decode VOP3 �_readfirstlane_b32 scalar dst (
aw[0] & 127, 125 => Null) in both uniformity analysis and emission so multi-wave dependent barriers hoist properly.
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AI-assisted implementation towards #151 adding portable Wave64 ballot, vote, and first-lane lowering in
tools/shader-compiler(hlsl::portable_wave64) so console Wave64 compute shaders using subgroup ballots/votes (WaveActiveBallot,WaveActiveAnyTrue,WaveActiveAllTrue,WaveReadLaneFirst, scalar-mask logic/s_mov_b64/s_cmov_b64/s_cselect_b64/s_*_wrexec_b64/s_*_saveexec_b64, 64-bitBallot64propagation intoexec/vcc/scc) run reliably across non-64-wide host GPUs (e.g., Wave32-only GPUs where nativeWaveActiveBallot()only covers 32 lanes), without requiring[WaveSize(64)].Whenever a shader uses constructs that cannot be statically proven safe to rewrite (divergent control flow across votes, multi-wave wave-varying barriers without uniform provenance, non-multiple-of-64 groups, unhandled 32-bit
ExecLo/VccLoors_wqm/SDWA/exec_snapshotsconsumers), the pass cleanly declines lowering and preserves existing behavior.Highlights
uniformity.rs): Tracks group-uniform values (including VOP3v_readfirstlane_b32scalar destinations), hoists provably group-uniform subgroup votes out of convergent regions when needed, and verifies barrier/control-flow convergence across[64*N, 1, 1]and multi-dimensional workgroups (e.g.,[8,8,1],[4,4,4]).masks.rs): Distinguishes 64-bitBallot64lane-mask registers from raw 64-bit masks andOpnd::Null, supports scalar/mask logic promotion (s_and/s_or/s_xor/s_andn2/s_nand/s_nor/s_xnor/s_orn1/s_orn2),s_cmov_b64,s_cselect_b64,s_*_wrexec_b64,s_*_saveexec_b64, and separates-1(all-64-ones) from0xffff_ffffliterals.emit.rs): Emitsgroupshareduint2per-wave ballot scratch (wave_id = gindex >> 6,(lane & 63u)) with EXEC-masked accumulation and barriers strictly isolated to proven convergent sites. Zero changes toruntime/d3d12.git merge-treeagainst bothorigin/mainand PR xshader: lower constant-lane v_readlane_b32 for Wave32 and portable Wave64 #185.Verification (
079143b16)python -m unittest discover -s tests -p "test_repository_hygiene.py" -v: 4/4 passed (all new/modified.rsmodules well under limit).cargo test --manifest-path tools/shader-compiler/Cargo.toml: 334 unit + 2 integration passed (0 warnings).cargo test --manifest-path runtime/d3d12/Cargo.toml -- --test-threads=1: 134/134 passed.python build.py lanes+lanes.exe --adapter 10de:2783 --selftest all: 15/15 passed.10de:2783,wave_min=32 wave_max=32, DXCcs_6_0&cs_6_6-WX, D3D12 Debug Layer):139,520/139,520words bit-exact) + independent 64/64 adversarial multi-group ([64,1,1],[128,1,1],[8,8,1],[4,4,4]) & 15/15 convergence repro suite,debug_errors=0 debug_warnings=0.Refs #151.
Co-Authored-By: AI Assistant