Repository navigation
wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) - #4138
Conversation
|
Tested 03f7056 on real 32-wide subgroups: NVIDIA GeForce RTX 3070, fragment subgroup 32..32, driver 617.42, Windows 11 24H2. There, a wave64 pixel shader runs as two halves by default, which is exactly the case the uniform-vote rule says is exact. Pass.
Tier C fixtures are skipped here as documented (they need a device that can require both 64 and 32, or No game files. AI-assisted (Claude). |
|
Corpus yield request: I have no copy of the game, so the gain of this rule over the real shaders is unmeasured. If someone with their own 1.0.2.1 copy can run the census on this branch and on its merge base ( the numbers that matter are tier A/B/C for VS/PS/GS and the |
|
Tested at the head on Windows 11 / Python 3.13.0: the 10 The rule is right and conservative: all lanes agreeing gives A; a real lane vote ( Nits: Approve. AI-assisted review, no game files, no GPU. |
…niform mask stays cross-lane (review nits)
|
Thanks @tupacfan04, both nits taken: |
|
Note 🤖 Claude Opus 5.5 responding on behalf of labj1987 @tedin7 census on my own 1.0.2.1 copy (counts only, no game data),
Per shader: 16 move C -> A (13 VS, 3 PS), none moves to a worse tier, no shader gains a reason; |
|
Apple M2 attempt at the wave64 fixture, reported as a limitation rather than a pass. Setup: head 9c7a861, Apple M2 (Mac14,3), macOS 26.4, MoltenVK 1.4.2, subgroup 4..32, llvm-mc 23.1.6.
MoltenVK on this M2 reports AI-assisted. |
|
Thanks @labj1987, that is exactly the census I asked for: 16 shaders C -> A (13 VS, 3 PS), none worse, no shader gains a reason, |
|
Tested
AI-assisted (Claude Code). |
|
Independent synthetic GPU check of head
The Vulkan harness was built from |
|
Both open items from the description, measured on AMD Radeon RX 9070 XT (RDNA4), RADV GFX1201, Linux, with my own 1.0.2.1 copy. Tested 1. 64-lane GPU run of the fixtures: pass. RADV here can require both 64 and 32 for the fragment stage, so 2. Corpus census: 16 shaders move from tier C to A. I translated the 13,405 wave64 VS/PS/GS listings of the corpus twice with the same flags, at the merge base
Every other tier C reason and tier B idiom count is unchanged. The rule behaves as described. On this corpus most shaders that carry an Counts only; the indexes and SPIR-V stayed local and were deleted. |
|
AI-assisted review (Claude Code). I used no game files. All listings are hand-written. Head What I ran
Result: one defect. A pattern moves from tier C to tier A, and the two runs differ. The rule accepts a VGPR that is in
The 16-bit form does the same: replace the first two lines with To reproduce, from the repository root at this head: # python -I repro.py
import sys
sys.path.insert(0, "tests/semantic")
from test_wave64_halves import meta_of, vs, run_cut, out_param
body = ["v_lshlrev_b32_e32 v1, 8, v0",
"v_mov_b32_sdwa v1, s4 dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE src0_sel:DWORD",
"v_cmp_gt_u32_e32 vcc, 0x2000, v1", "s_cbranch_vccz 3", "v_mov_b32_e32 v6, 7", "s_mov_b32 s20, 1",
"s_branch 2", "v_mov_b32_e32 v6, 5", "s_mov_b32 s20, 2", "v_add_nc_u32_e32 v7, s20, v0"]
(tier, reasons, _), asm = meta_of("vs_uv_sdwa_partial", vs(body))
push = [0, 0, 0, 0, 9]
print(tier, reasons, out_param(run_cut(asm, 64, push))[32], out_param(run_cut(asm, 32, push))[32])
# this head: A [] (7, 33, 0, 0) (5, 34, 0, 0)Correction. #4373 makes a partial write read its destination, so the destination is uniform only if it was uniform before. I merged this head with #4373 What passed. Tier A here and equal results: your accepted shapes; the AND of two uniform masks ( |
… is uniform only if the whole register was (review: @shdann)
… the whole register (review of the partial-write rule)
|
Thanks @shdann, a real hole, and thanks @radv-tinker and @caua-an for the 64-wide runs and the census. Fixed in 747b431, without depending on #4373: a VALU write of part of a VGPR now keeps the register uniform only if the whole register already was (
Tests (
When #4373 lands it covers the same case for every taint, not only this rule; the two do not conflict in behaviour (one text conflict, as you saw). The +16 census was taken before this; the fix can only lower it, and I cannot recount without the corpus. AI-assisted (Claude Code). No game files. |
|
AI-assisted (Claude Code). No game files; hand-written listings; CPU wave interpreter only (Windows 11, Python 3.14.7). I tested the new head
The defect that I reported is corrected at this head. |
|
Tested 747b431 on NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24, subgroup 32..32) and AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003, subgroup 32..64), Windows 11 Home 26200: pass on the GPU side. Same laptop, one GPU at a time through
One run of each. No game files. AI-assisted (Claude Code). |
|
Tested 747b431 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
No game files. AI-assisted. |
|
Written and tested by a Claude Code session on my PC; I'm posting it for that session. Tested Setup: Windows 11 Pro 26200.
GPU
CPU
Trying to break the rule: these are on top of @shdann's 19 partial-write listings, and are kinds their list doesn't cover. Each is a compare whose sources look uniform but aren't, run through the
Results:
Synthetic fixtures only, no game files. AI-assisted (Claude Code). |
# Conflicts: # docs/design.md # runtime/test/shaders/w64_graphics.py # tests/semantic/test_wave64_halves.py # tests/test_wave64_halves_fixtures.py # tools/wave64_halves.py
|
Tested
No game files. AI-assisted (Claude Code). |
|
Census (TEST-1006) of Setup. Each PR is merged onto
These 16 are new tier A claims ("exact on any subgroup size"). I can't run them on a 64-wide GPU, so I only have the AI-assisted (Claude Code). Part of TEST-1006 on the coordination issue. |
|
Both items listed as "not measured" in the description, on my own 1.0.2.1 copy and an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass. I ran the PR's five commits ( Corpus (counts only):
64-lane GPU run of the new fixture: Also: AI-assisted (Claude Code). |
…es a wave-uniform VGPR A v_readfirstlane_b32 / v_readlane_b32 of a VGPR that a buffer_load loaded was tier C (cross-lane, tainted-branch) even when every lane loaded the same word, because only VALU results of scalars entered the uniform set st["u"]. Analysis.uniform_load puts the destination of a load into st["u"] when all of these hold: - a MUBUF buffer_load_* with idxen (idxen ignores ADD_TID_ENABLE; without idxen a run-time V# can add the lane number), not a d16 form; - EXEC is the launch mask; - the index and offset VGPRs are uniform, the descriptor and soffset are untainted scalars; - the shader has no store and no atomic (the two halves read the word one after the other). tests/semantic/test_wave64_uniform_load.py runs each hand-written vertex shader on spirv_wave_interp.py (with its memory) as one 64-lane wave and as two 32-lane waves: 5 accepted shapes are tier B and equal, 5 near misses are tier C and differ, 2 are classification only. spirv_wave_interp.py: the PhysicalStorageBuffer branch of OpLoad was inside OpAccessChain, behind a return, so a load through such a pointer raised IndexError. It is moved to OpLoad (MemoryLoad, 3 tests). The near miss with an index written in part (SDWA UNUSED_PRESERVE) relies on the partial-write rule that main has since ItsNotRexed#4138. No game data. The corpus effect is not measured. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claimed in the coordination issue as: new SHADER item (#3918 (comment))
What and why
tools/wave64_halves.pytreated everys_cbranch_vccz/vccnzas a lane vote: an if/else with code on both sides was tier Cunsafe-vote-branch, and a scalar set on either side and read after the join was tier Cstale-scalar. That is right for a varying compare (a half whose lanes all vote no runs the other side, the wave does not), but too strict when the compare is the same in every lane, which is what a compiler emits for a uniform float compare (RDNA2 has no scalar float compare).The rule: a
v_cmpmade while EXEC is the launch mask (st["f"]), whose sources are immediates, scalars that are no lane mask, or VGPRs written from those with EXEC the launch mask (st["u"]), and none of which carries a taint bit, writes a mask taggedUVOTE.s_mov_b64keeps the tag;s_and_b64of EXEC (still the launch mask) with aUVOTEmask keeps it (the LLVM formv_cmp_e64 s[14:15]+s_and_b64 vcc, exec, s[14:15]+vccnz). Ans_cbranch_vccz/vccnzon an untainted, non-staleUVOTEVCC is no lane vote: nounsafe-vote-branch, and it is not recorded invoted, so scalars defined behind it are notstale-scalar. Everything else is unchanged.Why it is exact: with EXEC equal to the launch mask, a compare of a value that is the same in every lane sets the bit of every launch lane or of none. A 32-lane half exists only when it has a launch lane, so its VCC is non-zero exactly when the wave's is: both halves take the side the wave takes, and every scalar on that side gets the value the wave gives it.
Two counterexamples the rule must not accept (both differ on the wave interpreter and stay tier C):
st["f"](EXEC == launch mask), not just a uniform value.v_readfirstlaneof a varying VGPR copied back to a VGPR:st["u"]accepts any non-mask SGPR source, even a tainted one, so the rule also requires no taint bit on every source and on the mask (the first lane is vertex 0 in the wave and vertex 32 in the second half).A third near miss found while writing it:
s_and_b64 vcc, exec, <lane mask>sets SCC as a vote on that lane mask, then a uniformv_cmprewrites VCC but not SCC, thens_cbranch_scc*. The uniform shortcut is therefore taken only forvccz/vccnz, never for an SCC vote; a test pins it.Not counted as a census idiom: in this module an idiom makes a shader tier B, and these programs are tier A (exact as translated, no rewrite), so
--censusshows the effect as fewerunsafe-vote-branch/stale-scalarreasons and more tier A.Tested
tests/semantic/test_wave64_halves.py, new classUniformVote(64 lanes against two waves of 32 onspirv_wave_interp.py, push constant s4 = 9 and s4 = 1, so both sides run): tier A and equal, with the words named, for avcczif/else with SGPRs set on both sides and read after the join, the LLVMv_cmp_e64+s_and_b64 vcc, exec+vccnzform, and a loop whose back edge is avccnzon an SGPR trip count; tier B (readfirstlane-uniform) and equal forv_readfirstlaneof a uniform value feeding the compare. Near misses tier C and different between 64 and 2x32: the compare under EXEC narrowed to lanes 0..31 with an SGPR read after the restore,v_readfirstlaneof a varying value, a compare on ans_bcnt1lane count, the uniform mask ANDed with a lane mask before the branch, and the SCC case above. On origin/main the four tier A/B tests fail (tier C) and the five near misses pass; with the change all pass. Turning on the shortcut for SCC votes makes the SCC test fail.runtime/test/shaders/ps_w64_a_uniform_vote.asm(s4 = 9 fromVKH_SGPRS: avcczif/else that is taken, the LLVMvccnzform that is not, a uniform loop of 9 trips; SGPRs set on both sides and exported), registered inw64_graphics.pyandtests/test_wave64_halves_fixtures.py: built with llvm-mc 21 and spirv-val, index tier A (tier Cstale-scalar,unsafe-vote-branchon origin/main).w64_graphics.pyon everyps_w64_*fixture:ps_w64_a_uniform_voteand the other nine tier A/B fixtures give their derived words; the eight tier C fixtures skip (they need a device that can require both sizes, orW64G_REF).tests/test_wave64_halves_fixtures.py9 passed; the docs row tests (test_design_contract_rows,test_docs_*) pass;python -m pytest -n 16 tests/semantic: 9 failures, all present on origin/main aa2988c (test_loop_ballot_barrierwave64-emulate subtests,test_mutationsv_mul_legacy anchor,test_cmp_class_f64rejected forms); nothing new.Not measured: how many corpus shaders move from tier C to A. That needs
--censusover a translated index of the game's shaders, which only someone with the game can run. A 64-lane GPU run of the new fixture (an AMD device that can require 64 and 32, orW64G_SAVE_REFon one) is also still open.Overlap: #2674 (pixel kill early exit) also edits
vote()with no logic overlap, and both add a fixture toFIXTURES/EXPECT, tests at the end oftest_wave64_halves.pyand text in the samedocs/design.mdrow; #2469 (SGPR spills, wider tier B idioms) editswave64_halves.pyand the same test file. Expect textual conflicts only; whichever lands second rebases.Independent review. A second agent (Codex) tried to break the rule. Its one candidate, a uniform mask whose high register is rewritten (
v_cmp_lt_u32_e64 s[14:15], 5, v1; s_mov_b32 s15, 0; s_mov_b64 vcc, s[14:15]), is already a lane vote (tier C:unsafe-vote-branch,stale-scalar); it is now a test (test_c_half_of_a_uniform_mask_rewritten). After that commit:tests/semantic/test_wave64_halves.py+tests/test_wave64_halves_fixtures.py: 92 passed (Linux, Python 3.13).Checklist
docs/design.md, with how it was confirmed.Prepared with the help of an AI coding agent; reviewed and tested as above.