Skip to content

wave64_halves: a vote on a compare that is uniform in the active lanes of a narrowed EXEC is no lane vote (SHADER-1086) - #6963

Open
shdann wants to merge 1 commit into
ItsNotRexed:mainfrom
shdann:wave64-uniform-vote-narrowed
Open

shdann wants to merge 1 commit into
ItsNotRexed:mainfrom
shdann:wave64-uniform-vote-narrowed

Conversation

@shdann

@shdann shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-1086 (claim)

What and why

The census of #5970 on the corpus (iksZ2, counts only) has 6,496 tier C shaders with a refused vote, and 6,235 of them have the condition no-narrowing+other-side-joins: an if/else where the run side does not narrow EXEC to the voted mask. The top first shapes are run:s_load, other:s_load (1,128), run:valu, other:salu (931) and run:valu, other:valu (727).

I wrote these shapes by hand and ran them on the wave interpreter as one wave of 64 lanes and as two waves of 32. The result:

  • A vote on a varying compare with code on the two sides is not exact. The two halves take different sides. This is the known defect, and it stays tier C.
  • A vote on a compare that is the same in every active lane is exact, also when EXEC is narrowed, under the conditions below. main accepts this vote only when EXEC is the launch mask (wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) #4138). Under a narrowed EXEC it is tier C, because a half can have no active lane.

This pull request accepts the second class. It changes the tier only. It changes no emitted SPIR-V.

The rule (Analysis.uniform_region in tools/wave64_halves.py). An s_cbranch_vccz or s_cbranch_vccnz is no lane vote when all of these are true:

  1. VCC comes from a v_cmp whose sources are the same in every active lane: immediates, untainted scalars that are no lane mask, and VGPRs that are uniform in the active lanes (st["ua"]). The form s_and_b64 vcc, exec, s[..] is accepted too.
  2. Between the compare and the branch, EXEC is the same or is only narrowed.
  3. The two sides of the branch meet again at a join block before the end of the program.
  4. No side makes EXEC wider than it was at the vote. A side can narrow EXEC. It can also set EXEC from EXEC copies and compare results that the side made itself, so a side can have an if/else or a loop of its own.

Why it is exact. A half that has an active lane has the same compare result as the wave, and votes as the wave does. A half that has no active lane has an empty mask. It takes the no side, whatever the wave does, but all its lanes are off. Condition 4 keeps them off up to the join, in the wave and in the half, so no lane work of a side can differ. Condition 3 puts the half back on the path of the wave.

Scalars. The rule does not cover them. The vote stays in the set of votes, so an SGPR or SCC that a side sets and that is read after the join is stale-scalar, as after any lane vote. A scalar that a side sets and uses in the side only is accepted (the s_load shape).

Compare with #5747 (SHADER-739)

#5747 accepts a different shape: a vote on a lane mask where one side narrows EXEC to the mask and the other side narrows EXEC to its complement. This pull request needs no narrowing in the sides, but it needs a compare that is uniform in the active lanes. A branch that one rule accepts, the other rule does not look at. The two change vote() in different places; the second to merge has a small text merge.

Tested

Head e67881f5, on main 1cc6e3c1. Windows 11 Pro (10.0.26200), Python 3.14.7, LLVM 21.1.8 (llvm-mc), SPIRV-Tools v2026.4. No game files.

Check Result
New tests/semantic/test_wave64_uniform_vote_narrowed.py 18 tests, pass
tests/semantic/test_wave64_halves.py, test_wave64_halves_soundness.py 125 and 33 tests, pass (one expected reason changed, see below)
All tests/semantic/test_wave64*.py, test_w64*.py, the interpreter test and the two saveexec tests 284 tests, pass
python -I -m unittest discover -s tests/semantic 5,839 tests, pass (6 skipped). main 1cc6e3c1 on the same machine: 5,821 tests, pass (6 skipped). The 18 more tests are the new file
pytest on the wave64 fixture tests (with llvm-mc), test_lane_masks.py, test_shader_index.py, the docs row tests and the hygiene tests 79 passed, 1 failed. The failure is tests/test_text_write_line_endings.py (tools/f64_omod_probe.py:268); it fails on main 1cc6e3c1 too
python -I -m compileall -q tools tests, scripts/check_no_game_data.py pass
tools/rdna2spirv.py <disasm> --out <dir> from start to end, 7 hand-written listings, main against this branch 7 translated, 7 valid for spirv-val on each. 4 listings move from tier C to tier A, 3 near misses stay tier C. All 7 .spv files are byte-identical
GPU: new fixture ps_w64_a_uniform_vote_narrowed with runtime/test/shaders/w64_graphics.py NVIDIA GeForce RTX 4090, driver 621.01, required subgroup size 32: the image is equal to the derived words. AMD Radeon iGPU, AMD driver 26.3.1, default size: the same

What the new tests check. All listings are hand-written vertex shaders. Each runs with s4 = 9 (the compare says yes) and s4 = 1 (no). EXEC is narrowed to lanes 0..47 (the two halves have active lanes) and to lanes 0..31 (the second half has none).

Accepted, 12 listings. Each is tier A, gives the same words in the two runs, and gives the words that the test derives:

  • lane work on the two sides (run:valu, other:valu);
  • each side loads a scalar and uses it in the side (run:s_load, other:s_load);
  • a skip with no other side;
  • the form s_and_b64 vcc, exec, s[..]; an SGPR against an immediate;
  • a side with an if/else of its own; a side with a loop of its own;
  • a second uniform vote in a side, and one after the join;
  • the vote mask read as a mask after EXEC is restored.

Near misses, 39 listings. Each is tier C, and the test shows a lane whose words differ between the two runs:

  • an SGPR that the two sides set, read after EXEC is restored (stale-scalar); the same for SCC;
  • a side that makes EXEC wider, in 15 forms, on the yes side and on the no side: s_mov_b64 exec from the launch mask, s_or_b64 and s_xor_b64 with the saved mask, s_or_saveexec_b64, s_andn2_saveexec_b64, s_andn2_wrexec_b64, s_andn2_b64 exec, s[..], exec, s_not_b64, s_orn2_b64, s_mov_b64 exec, -1, s_wqm_b64, s_nand_saveexec_b64 and s_orn2_saveexec_b64 with an EXEC copy, an EXEC copy that is rewritten, an EXEC copy with one half rewritten;
  • the other side ends the program;
  • the branch comes after EXEC is restored (two forms);
  • the same mask voted again after the restore;
  • a VGPR that was made uniform under another EXEC;
  • a mask register that a side sets and that becomes EXEC after the join;
  • a varying compare.

One changed test. UniformVote.test_c_compare_under_a_narrowed_exec in tests/semantic/test_wave64_halves.py (the near miss of #4138) is tier C before and after, and its two runs differ before and after. Its reason was unsafe-vote-branch and is stale-scalar now: the vote is exact, and the scalar that the sides set is what differs. I changed only the reason name in the test.

The GPU fixture. ps_w64_a_uniform_vote_narrowed narrows EXEC to the pixels with x < 20 and makes three uniform votes: an if/else, the s_and_b64 vcc, exec form with an inner if on one side, and an if/else where each side sets a scalar and uses it in the side. The RTX 4090 has 32-lane subgroups only and the AMD driver did not accept a required fragment size, so the check is the image against the derived words. The comparison of 64 lanes against 32 lanes on one GPU was not run.

Request: please run the census

I have no copy of the game. If you have your own copy and LLVM 21 or newer, please run the census on main 1cc6e3c1 and on this branch, and post the tier counts and the number of changed binaries (counts only):

python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --out <scratch>        # or with --shard i/n and --merge
python -I tools/wave64_halves.py --census <scratch>/index.json

The expected result: some shaders move from tier C to tier A or B, no shader moves down, and no binary changes. I cannot estimate the number. The 6,235 shaders of the census condition are an upper limit: the census does not say if the compare is uniform, and a shader stays tier C when it has another reason.

Limits

  • Only s_cbranch_vccz and s_cbranch_vccnz. A vote through SCC (s_cmp_*_u64 on a mask pair) is not covered.
  • A side that comes back to the vote (a loop with the vote in it) is not judged and stays tier C.
  • A side that restores EXEC before the join is tier C, also when the restore is harmless.
  • Not measured on the corpus.

Overlap

AI-assisted: yes (Claude Code). It wrote the change and ran all the checks above on this machine.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code

…s of a narrowed EXEC is no lane vote

A v_cmp whose sources are the same in every active lane gives all the active
lanes or none. A half that has an active lane votes as the wave does. A half
that has none takes the no side with all its lanes off. That is exact when the
two sides of the s_cbranch_vccz/vccnz meet again and no side makes EXEC wider
than it was at the vote (Analysis.uniform_region). The vote stays a vote for
stale-scalar.

Hand-written listings only: 12 accepted shapes and 39 near misses on the wave
interpreter (64 lanes against 2 x 32), and the GPU fixture
ps_w64_a_uniform_vote_narrowed. No emitted SPIR-V changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@iksZ2 you ran the census of #5970 that this rule comes from (6,235 shaders with no-narrowing+other-side-joins). If you have time, please run the two commands of the section "Request: please run the census" on main 1cc6e3c1 and on this head (e67881f5), and post the tier counts and the number of changed binaries. Counts only. AI-assisted (Claude Code).

@Mortify7612

Copy link
Copy Markdown

Tested e67881f5 merged onto main 3e3ec2d0 (clean) on AMD Radeon RX 9060 XT (RDNA4, GFX1200, subgroup 32..64), RADV Mesa 25.0.7, Debian 12 Linux, the driver w64_graphics.py is written for: pass.

build.py (A 12, B 8, C 13), then LEONIDA_VK_DEVICE=GFX1200 w64_graphics.py <out> runtime/build/linux (vk_harness from main b4adb750): exit 0, 22 ok, 8 SKIP, none differed.

  • New fixture: ps_w64_a_uniform_vote_narrowed A ok.
  • The 8 skips are all tier C pixel fixtures, SKIP (tier C needs a device that can require both 64 and 32, or W64G_REF). This Mesa does not list the fragment stage for a required subgroup size, the same reason ps_w64x_readlane skips in run_gpu_tests.py. The VS/GS tiers ran both ways through RADV_PERFTEST=gewave32.

AI-assisted (Claude Code).

@junaydirfan

Copy link
Copy Markdown

Tested e67881f5 merged into main 21e72aab (clean) on Linux (CachyOS), with runtime/test/shaders/w64_graphics.py:

GPU driver ps_w64_a_uniform_vote_narrowed the rest of w64_graphics.py vs main
RTX 4080 Laptop NVIDIA 620.73.04 ok same (17 ok, 12 skipped)
Intel Raptor Lake-S iGPU (Xe-LP) Mesa ANV 26.3.1 SKIP: ANV can't require a fragment subgroup size, and runs 16 live lanes there same (5 ok, 25 skipped)

With main's tools/wave64_halves.py swapped in, the fixture is also ok on the 4080. That matches "it changes the tier only": the image checks the derived words, not the tier. Neither GPU here can require both 64 and 32, so I couldn't run the tier C comparison either. run_gpu_tests.py is unchanged on both GPUs (Intel 204/237, 0 failed; 4080 219/237, its one failure being main's ms_wave_info_s3).

@soldsawn

Copy link
Copy Markdown

Independent Windows 11 / NVIDIA RTX 4060 check at head e67881f50d (AI-assisted, no game files).

  • Environment: Windows 11, MSVC 19.44.35230.0 (RelWithDebInfo, Ninja), NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.1714, 32-lane subgroups).
  • tests/semantic/test_wave64_uniform_vote_narrowed.py: Ran 18 tests in 6.454s OK.
  • tests/semantic/test_wave64_halves.py: Ran 125 tests in 7.199s OK.
  • runtime/test/shaders/build.py runtime/build ps_w64_a_uniform_vote_narrowed vs_ids: 2 shaders: 2 translated, 2 pass spirv-val (wave64 VS/PS/GS on 32-wide subgroups: tier A: 1).
  • runtime/test/shaders/w64_graphics.py runtime/build runtime/build ps_w64_a_uniform_vote_narrowed: ps_w64_a_uniform_vote_narrowed A ok.

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.

4 participants