Skip to content

wave64_halves: a vote on EXEC ends with a new EXEC, plus GPU test ps_w64_c_vote_rewrite (SHADER-820) - #4620

Open
LouisRiverstone wants to merge 4 commits into
ItsNotRexed:mainfrom
LouisRiverstone:w64-halves-stale-vote
Open

LouisRiverstone wants to merge 4 commits into
ItsNotRexed:mainfrom
LouisRiverstone:w64-halves-stale-vote

Conversation

@LouisRiverstone

@LouisRiverstone LouisRiverstone commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

SHADER-820: the GPU fixture for the rewritten-vote-mask rule.

Status after main moved. The rule itself is on main as 2cbc8e046, which is this PR's first commit: a vote on a mask ends when the mask register is rewritten before the branch, so the branch is tier C tainted-branch. main's tests now expect that result. This PR had later changed it to a "stale vote" reported as unsafe-vote-branch, but only to satisfy an older test. Both tiers are C, so the change is dropped, and tools/wave64_halves.py, docs/design.md and tests/semantic are main's.

And a fix for the EXEC case (@shdann): a vote on EXEC now ends when EXEC gets a new value from an op that leaves SCC alone (s_mov_b64, s_cselect_b64, s_cmov_b64 or v_cmpx into EXEC). Before, main called such shaders tier A even though 1×64 and 2×32 differ. The fix is in tools/wave64_halves.py exec_write(), with tests in test_wave64_halves_soundness.py and a clause in the SHADER-10 row.

What this PR adds. runtime/test/shaders/ps_w64_c_vote_rewrite.asm (fixture by @AwkGrep256), registered in w64_graphics.py and expected as tier C tainted-branch in tests/test_wave64_halves_fixtures.py. Only pixel (0, 0) is in the voted mask. The branch still decides on the old mask, while the run side narrows EXEC to the new one, so a 64-lane wave and two 32-lane waves write different v6 in the other half's pixels.

Verify.

  • python -I -m pytest -q tests/test_wave64_halves_fixtures.py: 10 passed.
  • test_wave64_halves*.py (discovered from tests/semantic): OK.
  • On llvmpipe (subgroup 8) the GPU fixture skips. It needs a device with 64- and 32-lane subgroups, as the earlier RTX and Radeon runs on this PR had.

No game files.

AI-assisted (Claude Code): I reviewed and ran the tests above.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 7708d08f on Windows 11: tests/semantic/test_wave64_halves_soundness.py -> 33 tests, OK; tests/semantic/test_wave64_halves.py -> 73 tests, OK; git diff --check clean.

The change drops the ("vote", mask) SCC tag when either register of the voted pair is rewritten, so a later s_cbranch_scc is not treated as a vote on the new mask; the reduced repro and the tier-C expectation are in the added case.

Duplicate/overlap: #4619 covers the same rewritten-vote-mask issue as part of a larger wave64_halves change (narrowed-EXEC off-lane taints plus this vote fix). The two branches conflict in tools/wave64_halves.py (git merge-tree refs/remotes/pr/4619 refs/remotes/pr/4620 -> conflict). You claimed SHADER-820 first (03:10), so the coordinator may prefer this focused fix and have #4619 drop its vote-mask hunk on rebase; either order leaves one redundant hunk. Flagged on both.

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @Kam471 for the run and for spotting the overlap with #4619. This PR is only the SCC-vote check at the top of put() (SHADER-820, claimed at 03:10), and #4619 is SHADER-819's narrowed-EXEC taint plus the same vote fix. Whichever lands first, the other drops that hunk on rebase. I'll do it here if #4619 goes first. The two sets of regression tests don't overlap, so both can stay.

@theswiss24

Copy link
Copy Markdown

Tested 7708d08f (contains main d0835dd9) on two GPUs in a Dell Latitude 5501 (Linux Mint 22.3), test programs built from main d0835dd9 (this PR changes no C++), llvm-mc 20.1.2, LEONIDA_W64_EMULATE=1: pass. Every test has the same result as main on each device:

GPU driver run_gpu_tests.py
NVIDIA MX150 (Pascal) 580.178.04 185/210 passed, 25 skipped, 0 failed
Intel UHD 630 (Gen9.5, subgroup 8..32) Mesa ANV 25.2.8 181/210 passed, 27 skipped, 2 failed, the same 2 as main (cs_fmt_int_narrow, my finding in #4571, and cs_signed_zero_nan, the known Mesa 25.2 NIR issue)

No game files.

Tested and written by Claude (Claude Code), posting from @theswiss24's account.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested head 7708d08f — Windows, CPython 3.15.2, CPU only, synthetic fixtures, no game files: pass.

  • python -m unittest discover -s tests/semantic -p "test_wave64_halves_soundness.py" -> 33/33 OK.
  • Control (main's tools/wave64_halves.py + this test file): 2 failures — the rewritten-vote-mask cases are not handled on main, as intended.
  • git diff --check and scripts/check_no_game_data.py clean.
  • Heads-up: this overlaps Tools: wave64_halves, a VGPR written under a narrowed EXEC is tier C once EXEC widens #4619 — both patch the same vote-tag tracking in tools/wave64_halves.py for the mask-register-rewrite case (that one tagged SHADER-820 too). Whichever lands first will conflict with the other.

AI-assisted (Devin).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 7708d08 merged with main d0835dd on WSL2 Ubuntu (Python 3.12.16) and native Windows 11 (Python 3.13.1): pass.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 7708d08 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.

@tupacfan04

Copy link
Copy Markdown
Contributor

Approved with nits. The fix at tools/wave64_halves.py:380-387 is sound; 131 passed / 1 skipped, compileall clean, merge clean. Negative control: the 3 new tests fail on main's tool ('A' != 'C') and pass on the PR.

Two branches it names or adds are untested: s_cselect_b64 (:381) and a 32-bit write to the pair's second register (+1 at :386). It also overlaps #4619 in the same functions (no textual conflict), so whichever lands second should keep both behaviours.

AI-assisted review, no game files, no GPU.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Census (TEST-1006) of 7708d08f against its merge base main d0835dd9, from my own 1.0.2.1 copy. Counts only.

Setup. Native mode (halves_analysis returns early under --wave64-emulate). The run covers the 13,405 wave64 VS/PS/GS, picked by the FSSM wave-size flag and the carve-index stage; no other shader reaches wave64_halves. WSL Ubuntu, Python 3.14.4, llvm-mc 21.1.8, SPIRV-Tools v2026.1.

Result: no tier moves.

d0835dd9 7708d08f
translated 13,405 13,405
pass spirv-val 13,401 13,401
tier A / B / C (--census) 4,033 / 85 / 9,283 4,033 / 85 / 9,283
.spv byte-identical 13,401 of 13,401
  • One reason change. One PS loses unsafe-vote-branch. It was already tier C and keeps tainted-branch, tainted-exec and first-lane. That's the PR's rule working: once the mask is rewritten, the branch is judged as a plain SCC branch, which this shader already failed. So the corpus has exactly one vote whose mask is rewritten before its branch, and that shader was already refused.
  • 4 PS fail spirv-val on both sides. The same 4 fail at both commits, with Operand ... requires a previous definition. The undefined operand is %fmt_size_arr's length constant, so this is SHADER-718 (Translator: constants assemble asks for late are defined too #3902, rdna2spirv: register the buffer-format table constants before the dump #4466), not this PR.

Tested on CPU only (no GPU run), under WSL on Windows 11.

@SweatierKey

Copy link
Copy Markdown
Contributor

Tested 703dfc93 on Linux (x86_64, Python 3.13.5, SPIRV-Tools on PATH): 1 failure in tests/semantic/test_wave64_halves.py (passes on main 2d3369a4).

What I ran:

  • git diff --check main...HEAD: clean.
  • PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_wave64_halves_soundness.py tests/semantic/test_wave64_halves.py: 133 passed, 1 failed:
    FAIL: test_c_mask_redefined_or_not_the_vote (tests.semantic.test_wave64_halves.KillExit.test_c_mask_redefined_or_not_the_vote)
    tests/semantic/test_wave64_halves.py:881:
      self.tier("ps_kill_redef", kill(KILL + ["s_mov_b64 s[20:21], exec"], RUN_WQM, EXIT_PS),
                "C", contains=["unsafe-vote-branch"])
    AssertionError: False is not true : ps_kill_redef: reasons ['tainted-branch'] lack ['unsafe-vote-branch']
    
  • Control on main (2d3369a4): test_c_mask_redefined_or_not_the_vote passes.

Cause:

  • The new invalidation of st["g"]["scc"] when s_mov_b64 s[20:21], exec overwrites the voted pair works as intended (still Tier C), so the branch now falls through to the tainted-branch reason rather than unsafe-vote-branch. KillExit.test_c_mask_redefined_or_not_the_vote in tests/semantic/test_wave64_halves.py just needs its expected reason updated (or checked) to match the new invalidation behavior.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 703dfc9 merged with main 98fa503 on Linux (Python 3.12.16): concern - test_wave64_halves_soundness.py 33 OK, tests/test_docs_.py OK, negative control (tools/wave64_halves.py and docs from main, PR tests kept): 2 failures of 33. But the full tests/semantic/test_wave64.py run is 201 tests with 1 failure: test_wave64_halves.py KillExit.test_c_mask_redefined_or_not_the_vote (line 881, ps_kill_redef: 'reasons [tainted-branch] lack [unsafe-vote-branch]'). It passes on main 98fa503 alone and fails with the PR's tools/wave64_halves.py, so the PR changes that shader's reason (still tier C); that test's expectation, or the rule, needs updating in this PR.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Census (TEST-1006) of the new head 703dfc93, merged onto today's main 0db7fed5 (with #2674): same result as at 7708d08f, no tier moves.

Setup. Each PR is merged onto main 0db7fed5 (clean merge) and compared with 0db7fed5 itself, from my own 1.0.2.1 copy, counts only. Native mode: halves_analysis returns early under --wave64-emulate. The run covers the 13,405 wave64 VS/PS/GS, picked by the FSSM wave-size flag and the carve-index stage; no other shader reaches wave64_halves. WSL Ubuntu, Python 3.14.4, llvm-mc 21.1.8, SPIRV-Tools v2026.1, CPU only. Both sides translate all 13,405 and pass spirv-val on all 13,405. The .spv files are byte-identical on both sides, so only the tier metadata changes. On 0db7fed5, wave64_halves.py --census gives A 5,054 / B 106 / C 8,245 (VS 1,455 / 79 / 702, PS 3,404 / 27 / 7,543, GS 195 A).

The merge gives the same A 5,054 / B 106 / C 8,245. Only one PS changes: it was already tier C, loses
unsafe-vote-branch, and keeps tainted-branch, tainted-exec and first-lane. Tier C unsafe-vote-branch goes
from 6,525 to 6,524. That is the same single shader as at the previous head.

AI-assisted (Claude Code). Part of TEST-1006 on the coordination issue.

… unsafe-vote-branch

Rebased on main, which added test_c_mask_redefined_or_not_the_vote (ItsNotRexed#2674's
kill rule): a mask rewritten after its vote must be tier C with reason
unsafe-vote-branch. Dropping the SCC vote tag made it tier C with
tainted-branch instead. put() now turns the tag into ('stale_vote', ...), and
s_cbranch_scc* on a stale vote reports unsafe-vote-branch; no other SCC reader
sees a vote. docs/design.md wording follows.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Rebased on main (7bfba131). main added test_c_mask_redefined_or_not_the_vote (#2674's kill rule), which expects a mask rewritten after its vote to be tier C with reason unsafe-vote-branch. Dropping the vote tag gave tier C with tainted-branch, so the tag now becomes a stale vote, and a branch on it reports unsafe-vote-branch. shdann's three listings are still tier C and still diverge 1×64 vs 2×32. test_wave64_halves.py passes 101/101, test_wave64_halves_soundness.py 33/33, and the fixtures 9/9. The full semantic suite shows only main's three known test_loop_ballot_barrier failures.

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @SweatierKey, @kapitche and @465d6a0eac. The test_c_mask_redefined_or_not_the_vote failure you all saw at 703dfc93 (the rebase head) is fixed in 7bfba131. Instead of dropping the SCC vote tag, a rewritten mask now leaves a stale vote, and s_cbranch_scc* on it reports unsafe-vote-branch, the reason main's #2674 kill rule expects. So that test passes unchanged, and test_wave64_halves.py is 101/101.

@465d6a0eac, thanks for the census: no tier moves, and .spv byte-identical. With 7bfba131, the one PS that lost unsafe-vote-branch at 703dfc93 should keep it again, because its branch is on a stale vote. If you rerun the census on the new head, I'd expect no reason change either.

@DenRakEiw

Copy link
Copy Markdown

Tested PR #4620 (7bfba131209a5360a0e938cb5970f27ec4f52bf8) on Windows 11 / Python 3.12.10.

  • Trial merge against origin/main (d974c88a): clean (exit 0), git diff --cached --check passed.
  • Tests:
    • python -m unittest discover -s tests/semantic -p test_wave64_halves_soundness.py: Ran 33 tests in 1.668s — OK
    • python -I tests/test_docs_design_rows.py: Ran 4 tests in 0.062s — OK
  • Code read: When Analysis.put() overwrites either register of an active "vote" tag's mask before a branch (without an op that re-tags scc), it downgrades the scc tag to "stale_vote" so s_cbranch_scc0/s_cbranch_scc1 reports unsafe-vote-branch instead of accepting the stale vote.

AI-assisted review (Gemini 4 Neon).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @DenRakEiw, on the current head 7bfba131 (the stale-vote version). Nothing is pending here.

@AwkGrep256

Copy link
Copy Markdown
Contributor

Tested 7bfba13 on Linux (CachyOS, kernel 7.3.5, Mesa 26.3.1-arch3.5 RADV): RX 9070 XT (gfx1201) and the Ryzen 7 9800X3D iGPU (gfx1036). Pass, and the bug is real on hardware.

  • I wrote your listing as a pixel fixture (ps_w64_c_vote_rewrite, below). Only pixel (0, 0) is in the voted mask, then v_cmp_le_u32_e64 s[20:21], 0, v4 rewrites the pair before s_cbranch_scc0.
  • Classifier: main (ec34b54f) calls it tier A; this PR calls it tier C unsafe-vote-branch.
  • GPU: w64_graphics.py draws it with the fragment subgroup size required to 64 and to 32. On both GPUs the images differ in r0 and agree in r1, i.e. tier C. The existing ps_w64_c_vote_stale passes alongside it as a control.
  • tests/semantic/test_wave64_halves_soundness.py + tests/test_wave64_halves_fixtures.py: 42 passed.

To turn this into a GPU regression test, add the fixture to runtime/test/shaders/, register it in w64_graphics.py as "ps_w64_c_vote_rewrite": ("C", _c_vote_stale, {}), and add it to EXPECT in tests/test_wave64_halves_fixtures.py. It uses the same eight interpolation lines and header as ps_w64_c_vote_stale, then:

v_or_b32_e32 v4, v2, v3
v_mov_b32_e32 v6, 0
v_cmp_eq_u32_e32 vcc, 0, v4
s_and_b64 s[20:21], exec, vcc
s_cmp_lg_u64 s[20:21], 0
v_cmp_le_u32_e64 s[20:21], 0, v4
s_cbranch_scc0 3
s_and_b64 exec, exec, s[20:21]
v_mov_b32_e32 v6, 1
s_mov_b64 exec, s[10:11]
v_cndmask_b32_e64 v7, 0, 1, vcc
v_mov_b32_e32 v8, 0
exp mrt0 v6, v7, v8, v8 done vm
s_endpgm

AI-assisted (Claude Code).

… its branch

@AwkGrep256's pixel fixture of shdann's listing (ItsNotRexed#4620): only pixel (0, 0) is in
the voted mask, then v_cmp_le_u32_e64 rewrites s[20:21] before s_cbranch_scc0.
On an RX 9070 XT and a gfx1036 iGPU (RADV) the images drawn at fragment
subgroup sizes 64 and 32 differ in r0 and agree in r1: tier C. main classifies
it tier A, this PR tier C unsafe-vote-branch. Registered in w64_graphics.py
with _c_vote_stale's expectation and in test_wave64_halves_fixtures.py's
EXPECT (which fails with main's wave64_halves.py).
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @AwkGrep256, that's the proof on hardware this PR lacked: main calls the shader tier A, and the 64- and 32-lane images really differ in r0 on the RX 9070 XT and the gfx1036 iGPU. I added your fixture as suggested in e877a6f4:

  • runtime/test/shaders/ps_w64_c_vote_rewrite.asm, with your body, ps_w64_c_vote_stale's header, and a header that credits you
  • "ps_w64_c_vote_rewrite": ("C", _c_vote_stale, {}) in w64_graphics.py
  • ("C", ["unsafe-vote-branch"], None) in EXPECT

tests/test_wave64_halves_fixtures.py passes 9/9, and with main's wave64_halves.py the new entry fails, so it pins the fix. I can't draw it here: llvmpipe's subgroup is 8, too narrow for the 64-lane run.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Census (TEST-1006) of e877a6f4, the stale-vote version: no change on the corpus.

Merged onto main d974c88a and compared with my 0db7fed5 run (tools/ differs only in three unrelated scripts), over the 13,405 wave64 VS/PS/GS of my own copy, counts only. The tiers are A 5,054 / B 106 / C 8,245 on both sides, no shader's reason set changes, and the .spv files are byte-identical. The one PS that lost unsafe-vote-branch at 7708d08f and 703dfc93 now keeps it, because a rewritten mask leaves a stale vote that reports the same reason. That's what the new head intends. It was tier C either way.

AI-assisted (Claude Code).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @465d6a0eac. A full-corpus census with no tier and no reason-set change, and .spv byte-identical, is the best evidence this can get. The one PS keeping unsafe-vote-branch is what the stale-vote version was for. Thanks also @kapitche.

@kapitche

Copy link
Copy Markdown
Contributor

Tested e877a6f merged with main d974c88 on Linux (Python 3.12.16) and native Windows (Python 3.13.1): pass.

  • Full tests/semantic/test_wave64*.py on Linux: 201 tests OK (all in the run, including test_wave64_halves.py). test_wave64_halves_soundness.py: 33 OK on Linux and 33 OK on Windows. tests/test_docs_*.py: all OK.
  • Negative control (tools/wave64_halves.py and docs/design.md from main, PR tests kept): test_wave64_halves_soundness.py 2 failures of 33.
  • Earlier issue (703dfc9): test_wave64_halves.py KillExit.test_c_mask_redefined_or_not_the_vote failed with 'reasons [tainted-branch] lack [unsafe-vote-branch]'. Resolved: that test passes at this head (201 of 201 OK).
  • Not run: tests/test_wave64_halves_fixtures.py here (it needs conftest on the path, which -I removes), and the GPU shader ps_w64_c_vote_rewrite.asm.

@KkelebekK

Copy link
Copy Markdown

Tested e877a6f4 (merge-base 2d3369a4; git merge-tree against current main 3faac557 is clean) on AMD Radeon 780M (RADV PHOENIX, Mesa 26.2.6, gfx1103, real wave64) and NVIDIA RTX 4070 Laptop (620.70.06), CachyOS Linux 7.3.4, Python 3.14.10, llvm-mc 23.1.4, SPIRV-Tools v2026.4: pass.

This PR changes no C++ (runtime/ has only the new fixture and one w64_graphics.py line), so the test programs were built from main af70fc78.

  • New fixture, runtime/test/shaders/w64_graphics.py (28 fixtures after this PR, built with build.py, run with vk_harness):
    • 780M, wave64 vs RADV_PERFTEST=gewave32: 28 ok, 0 skip, ps_w64_c_vote_rewrite is C ok (its words differ between the two sizes, as the header says).
    • RTX 4070 (32 only): the 64-lane run saved from the 780M with W64G_SAVE_REF and compared with W64G_REF: 28 ok, 0 skip, ps_w64_c_vote_rewrite C ok. Without a reference the tier C rows are SKIP, as documented.
  • python -I -m pytest -q tests/test_wave64_halves_fixtures.py: 9 passed. python -I -m unittest discover -s tests/semantic -p "test_wave64*.py": 201 OK, including test_wave64_halves.py KillExit.test_c_mask_redefined_or_not_the_vote (the failure reported at 703dfc93 is fixed at this head). tests/test_docs*.py: 30 OK.
  • Control, merge-base tools/wave64_halves.py plus this PR's test, fixture and w64_graphics.py: test_vote_on_a_rewritten_pair_is_unsafe and test_vote_on_a_rewritten_vcc_is_unsafe fail ('A' != 'C', 2 of 33), and test_fixtures_are_classified_as_their_headers_say fails on the new fixture (base says tier A, expected C).
  • Independent encoding check of the fixture with llvm-mc -mcpu=gfx1036 -mattr=+wavefrontsize64 -show-inst -show-encoding: v_cmp_le_u32_e64 s[20:21], 0, v4 is [0x14,0x00,0xc3,0xd4,0x80,0x08,0x02,0x02], operands (SGPR20_SGPR21, Imm 0, VGPR4): sdst s[20:21], src0 0, src1 v4, so it is 0 <= v4, true in every lane, as the header says; s_cmp_lg_u64 s[20:21], 0 and s_and_b64 s[20:21], exec, vcc also decode as written. Caveat: the GPU runs the translator's SPIR-V, not the machine code, so the encoding check and the GPU result cover different halves of the claim.
  • Three extra cases of my own through the PR's assert_tier_c_and_diverges harness (not in the PR): s_cselect_b64 s[20:21], exec, 0 is tier C and diverges (tier C on the base already); s_mov_b32 s21, ... (high word only) is tier C and diverges on the PR, tier A on the base; s_mov_b32 s20, ... (low word only) is tier C on the PR (tier A on the base), but my variant does not make 1x64 and 2x32 diverge, so I am not claiming a divergence for it.
  • scripts/run_gpu_tests.py (full suite, 217 tests; the new fixture is not part of it), per-test status identical to main 3faac557, 0 FAIL:
Configuration Result
780M, plain (native wave64) 202/217 passed, 15 skipped
RTX 4070, plain 170/217 passed, 47 skipped
RTX 4070, LEONIDA_W64_EMULATE=1 201/217 passed, 16 skipped

Overlap: it merges cleanly with #4596, #4892 and #4863 (pairwise git merge-tree). I did not test it against #4619.

Synthetic inputs only, no game data. AI-assisted.

@bunbeans2-arch

Copy link
Copy Markdown

GPU run of head e877a6f on an AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), Windows 11 23H2. build.py and then
w64_graphics.py give 24 ok and 4 skipped (VS/GS tier C without RADV), rc 0, including
ps_w64_c_vote_rewrite C ok. At required subgroup sizes 64 and 32, the rewritten-vote shader gives different words,
as the new tier C says. The game-free GPU suite: 202/217 passed, 15 skipped.
This is AMD's own Windows driver; the AMD runs above are RADV.
AI-assisted (Claude Code). No game files.

@memorypressure

Copy link
Copy Markdown

Verified on Linux against main 3faac55: merges cleanly, compileall clean, tests/test_wave64_halves_fixtures.py 9 passed under pytest, the soundness suite 33 passed, and on the merged tree all 201 wave64 semantic tests plus the four tests/ wave64 suites and the docs guards pass. The new ps_w64_c_vote_rewrite.asm is a hand-written listing and the design.md row carries the SHADER-820 rule per house convention. Heads-up: #4619 edits the same two files with a complementary rule — the two auto-merge cleanly, worth a joint regression run if both land. GPU fixture run not performed (CPU-only check); checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @kapitche, @KkelebekK (Radeon 780M, with the merge-base control) and @memorypressure. #4619's complementary rule auto-merges with this one; once both land, a joint run of test_wave64_halves*.py is worth doing, and I'll post it.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
gregoirener pushed a commit to gregoirener/Leonida-latest-backup-Monday-23-nov-Japanese-time- that referenced this pull request Nov 23, 2026
…SHADER-820 (ItsNotRexed#4620)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…GPU fixture

main has this PR's first commit (2cbc8e0: a rewritten vote mask ends the
vote, so the branch is tier C tainted-branch) and its tests now expect that.
The later change to a stale vote / unsafe-vote-branch only answered the old
test, so it is dropped: tools/wave64_halves.py, docs/design.md and
tests/semantic are main's. What remains is ps_w64_c_vote_rewrite (@AwkGrep256),
expected tier C tainted-branch.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Merged current main in 8738952f. main already has this PR's first commit (2cbc8e046), and its tests now expect tainted-branch for a rewritten vote mask. So I dropped my later stale_vote / unsafe-vote-branch change, which had only answered the older test, and the PR is now just the GPU fixture ps_w64_c_vote_rewrite (by @AwkGrep256), expected tier C tainted-branch. I've updated the title and description to match.

@LouisRiverstone LouisRiverstone changed the title wave64_halves: a vote on a mask ends when the mask register is rewritten (SHADER-820) GPU test ps_w64_c_vote_rewrite: a vote whose mask is rewritten before its branch (SHADER-820) Nov 23, 2026
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review (Claude Code). No game files; hand-written listings; CPU wave interpreter only (Windows 11, Python 3.14.7).

Head 8738952f (its tools/wave64_halves.py is that of main 561b65a8, where the rule of SHADER-820 is now). I ran 19 hand-written vertex listings as one 64-lane wave and as two 32-lane waves.

What is correct. The three listings of the finding are tier C tainted-branch, and the two runs differ. These other writers of the voted register between the compare and s_cbranch_scc0 are tier C also: s_cselect_b64 into the pair, s_mov_b32 into the high or the low register, s_movk_i32 into the high register, a v_cmp_*_e64 with the pair or with one register as the destination, a carry-out (v_add_co_u32_e64 v9, s[20:21], ...), v_readfirstlane_b32, s_buffer_load_dword, and s_mov_b64 s[21:22], exec (one register of the pair). The two controls (no write, and a new vote on the new mask) are tier A with equal results.

One case is still tier A: the vote is on EXEC, and EXEC gets a new value before the branch.

put() does not handle EXEC, so the ("vote", "exec") tag on SCC stays when EXEC is written. s_mov_b64 exec, ... does not write SCC. Then the branch is a vote on the old EXEC, and vote() accepts it as an EXEC vote, for which the run side needs no narrowing.

v_cmp_eq_u32_e32 vcc, 2, v0           ; v0 = lane number: only lane 2
s_and_saveexec_b64 s[12:13], vcc      ; SCC = (EXEC != 0): the vote
s_mov_b64 exec, s[10:11]              ; EXEC = launch mask; SCC does not change
s_cbranch_scc0 1
v_add_nc_u32_e32 v6, 9, v6            ; all lanes of the wave; the second half voted no and skips

Tier A with no reasons. One 64-lane wave exports v6 = 9 in lanes 32 to 63, two 32-lane waves export 0 (32 lanes differ). The same occurs when the vote comes from s_and_b64 exec, exec, vcc or from s_bcnt1_i32_b64 s6, exec (with EXEC narrowed for the count and restored after it).

To reproduce, from the repository root at this head or at main 561b65a8:

# 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_cmp_eq_u32_e32 vcc, 2, v0", "s_and_saveexec_b64 s[12:13], vcc", "s_mov_b64 exec, s[10:11]",
        "s_cbranch_scc0 1", "v_add_nc_u32_e32 v6, 9, v6"]
(tier, reasons, _), asm = meta_of("vs_exec_vote_rewritten", vs(body))
whole, halves = out_param(run_cut(asm, 64)), out_param(run_cut(asm, 32))
print(tier, reasons, whole[32][:1], halves[32][:1])      # A [] (9,) (0,)

Proposal: in exec_write(), remove a ("vote", "exec") tag from SCC when the instruction writes EXEC and does not write SCC (s_mov_b64 exec, ..., v_cmpx, s_cselect_b64 exec, ...). The instructions that write EXEC and SCC together set a new tag after that, as they do now. This is a defect of the rule on main, not of the fixture that this pull request adds; I put it here because this is the thread of SHADER-820.

…aves SCC alone (SHADER-820)

@shdann on ItsNotRexed#4620: put() skips EXEC, so ('vote', 'exec') on SCC outlived
s_mov_b64 exec / s_cselect_b64 exec / v_cmpx, none of which writes SCC; the
branch then voted on the old EXEC while the run side used the new one, and
the shader was tier A although one 64-lane wave and two 32-lane waves differ
(lanes 32..63). exec_write() now drops that tag on such writes, and on any
other EXEC write it does not model; s_cselect_b64/s_cmov_b64 into EXEC no
longer mark SCC as a fresh vote either.

Tests (test_wave64_halves_soundness.py): the saveexec / s_and_b64 exec votes
followed by s_mov_b64 or s_cselect_b64 into EXEC, and the s_bcnt1 count with
EXEC restored, are tier C and diverge; a kept and a re-voted EXEC stay tier A
and invariant. With main's rule the new tests fail 4 subtests. All wave64
suites pass.
@LouisRiverstone

Copy link
Copy Markdown
Contributor Author

Thanks @shdann. That's a real hole, and your repro made it quick to confirm. I've fixed it here, since this is the SHADER-820 thread: 2dd34ba5.

The fix

  • exec_write() now drops a ("vote", "exec") tag on SCC when EXEC gets a new value from an op that leaves SCC alone: s_mov_b64, s_cselect_b64, s_cmov_b64 or v_cmpx. It does the same for any other EXEC write it doesn't model.
  • Ops that write SCC from the new EXEC still set a new tag, as before.
  • s_cselect_b64 exec, ... also no longer marks SCC as a fresh vote: it doesn't write SCC.

Your cases, now tier C tainted-branch and diverging 1×64 vs 2×32

  • the s_and_saveexec_b64 vote, then s_mov_b64 exec
  • the s_and_b64 exec, exec, vcc vote, then s_mov_b64 exec
  • the s_and_saveexec_b64 vote, then s_cselect_b64 exec
  • the s_bcnt1_i32_b64 count with EXEC narrowed and restored

Controls, still tier A and invariant: a kept EXEC, and one re-voted by a second s_and_saveexec_b64.

These cases are in test_wave64_halves_soundness.py. With main's rule the new tests fail 4 subtests. All of test_wave64*.py, the four tests/test_wave64* suites and the fixture classification pass. I also added a clause to the SHADER-10 row. The corpus census isn't re-measured here.

@LouisRiverstone LouisRiverstone changed the title GPU test ps_w64_c_vote_rewrite: a vote whose mask is rewritten before its branch (SHADER-820) wave64_halves: a vote on EXEC ends with a new EXEC, plus GPU test ps_w64_c_vote_rewrite (SHADER-820) Nov 23, 2026
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review (Claude Code). No game files; hand-written listings; CPU wave interpreter only (Windows 11, Python 3.14.7).

I tested the new head 2dd34ba5 with 31 listings (one 64-lane wave against two 32-lane waves): pass. tests/semantic/test_wave64_halves.py (125 tests) and test_wave64_halves_soundness.py (35 tests) pass.

  • The listing of my review and its two other forms are tier C tainted-branch.
  • These are tier C also, and the two runs differ for each: the vote from s_and_saveexec_b64, s_and_b64 exec, s_cmp_lg_u64 exec, 0, s_wqm_b64 exec or s_bcnt1_i32_b64 of EXEC, followed by s_mov_b64 exec, ...; s_cselect_b64 exec, ... after the vote; v_cmpx and then s_mov_b64 exec; 32-bit writes to exec_hi and exec_lo (mask-half).
  • The 19 listings of my first comment give the same results as before.
  • Controls that stay tier A with equal results: s_cbranch_scc0 directly after s_and_saveexec_b64; s_cbranch_execz; and a restore with s_or_b64 exec, exec, s[12:13] before the branch (that instruction writes SCC from the new EXEC).

One conservative result, no defect: s_and_saveexec_b64, then v_cmpx_gt_u32_e32 64, v0, then s_cbranch_scc0 is tier C tainted-branch now, and its two runs are equal. The v_cmpx only narrows EXEC, so the vote on the wider EXEC is still safe. If a census shows that this shape occurs, a narrowing can keep the tag.

@AwkGrep256

Copy link
Copy Markdown
Contributor

Tested 2dd34ba on CachyOS, RADV/Mesa 26.3.1, LLVM 23.1.5: pass.

GPU (runtime/test/shaders/w64_graphics.py, fixture built with runtime/test/shaders/build.py):

  • AMD Radeon RX 9070 XT (RADV GFX1201) and AMD Radeon Graphics (Ryzen 7 9800X3D iGPU, RADV gfx1036): ps_w64_c_vote_rewrite C ok on both, so one 64-lane wave and two 32-lane halves really give different words there.
  • Control: with tools/wave64_halves.py from before SHADER-820 (2cbc8e046^) the translator puts the fixture in tier A (tier A: 2 in the build summary), while the same GPU run still shows the two sizes differ. So that tier was wrong, and C is right.

CPU: tests/semantic/test_wave64_halves_soundness.py OK; tests/test_wave64_halves_fixtures.py 10 passed.

Note: main already has the first SHADER-820 rule, so this fixture is C on main too; it doesn't exercise 2dd34ba5's EXEC-without-SCC case on the GPU, which the new CPU test covers.

AI-assisted.

@sennecools

Copy link
Copy Markdown

Tested 2dd34ba5 (applied on main 561b65a8) on Windows 11 with AMD's own Windows driver: pass. The earlier AMD-Windows run was on e877a6f4.

  • CPU: tests/test_wave64_halves_fixtures.py 10 passed. test_wave64_halves*.py 162 OK.
  • RX 9070 XT (gfx1201, driver 32.0.32029.2010): ps_w64_c_vote_rewrite C ok in 3 of 3 runs. Full w64_graphics.py: 26 ok, 4 skipped (the VS/GS tier C rows, which need RADV).
  • @shdann's EXEC case on the GPU. This is the part of 2dd34ba5 that the fixture doesn't exercise. I wrote it as a scratch pixel fixture (not pushed) with ps_w64_c_vote_stale's header and r0/r1 layout. The body is v_cmp_eq_u32_e32 vcc, 0, v4 / s_and_saveexec_b64 s[12:13], vcc / s_mov_b64 exec, s[10:11] / s_cbranch_scc0 1 / v_mov_b32_e32 v6, 1.
    • This PR's wave64_halves.py calls it tier C tainted-branch. main's calls it tier A.
    • On the 9070 XT the images at required subgroup size 64 and 32 differ in r0 (C ok, 2 of 2). So the new EXEC rule is right on hardware too. Worth adding as a second fixture if you want the GPU to pin it.
  • Ryzen 7 9800X3D iGPU (gfx1036, driver 32.0.21045): all A/B rows ok, but every tier C pixel row skips: this driver can't require either subgroup size. W64G_REF with a 64-lane reference saved on the 9070 doesn't help here either: the iGPU's default run equals the reference for ps_w64_c_vote_rewrite, ps_w64_c_vote_stale (already on main) and the scratch fixture alike. So its default fragment wave looks like 64, and the reference check only fits 32-only devices. That's a harness limit, not this PR.
  • Side note: run_gpu_tests.py --filter ps_w64_c_vote_rewrite reports "matched no GPU test cases", because w64_graphics fixtures are excluded there. build.py followed by w64_graphics.py is the runner.

No game files. AI-assisted.

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.