Skip to content

wave64_halves: a vote on a scalar compare under whole-quad EXEC is no lane vote (SHADER-W64-WQM-UVOTE) - #1091

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
milk4sale:shader-w64-wqm-uvote
Nov 24, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
milk4sale:shader-w64-wqm-uvote

Conversation

@milk4sale

Copy link
Copy Markdown
Contributor

Item: SHADER-W64-WQM-UVOTE

Depends on: #1021 (its commit is the first one in this branch; only the second is this change)

A pixel shader that needs derivatives starts with s_wqm_b64 exec, exec. LLVM branches on wave-uniform conditions inside that region the way it does anywhere: v_cmp_* sN of scalars, s_and_b64 vcc, exec, s[N:N+1], s_cbranch_vccnz. SHADER-10 took that for no lane vote only while EXEC was the launch mask, so under the whole quads it was tier C unsafe-vote-branch.

Why it is exact

  • The compare reads immediates and scalars only, so it is the same in every lane: its mask is every lane of EXEC or none.
  • EXEC is the whole quads of the launch mask. A quad is four consecutive lanes and never straddles the two 32-lane halves, and a half that runs has a launch lane. So EXEC has a lane in every half that runs, and each half votes as the wave does.

What stays tier C

  • A VGPR source, even one SHADER-10 calls uniform: it was written under the launch mask and the helper lanes never got it.
  • The whole quads of a narrowed EXEC, and any narrowing after the s_wqm_b64: a half can be empty.
  • Whole quads saved and put back, or made in a register and copied to EXEC: only the write by s_wqm_b64 exec, exec is modelled.
  • A path on which a scalar was read out of a uniform VGPR from a lane the launch mask may not have written (v_readlane_b32, or v_readfirstlane_b32 while EXEC is not the launch mask).

Corpus (1.0.2.1, all 26,503, wave64_halves.analyse on every wave64 VS/PS/GS)

Baseline is #1021 on main 3ed8e50b7. Without #1021 the listings' one-register destinations hide the vote behind tainted-branch.

A B C
#1021 5,267 397 7,741
#1021 + this 5,719 397 7,289

452 pixel shaders go from C to A. No shader moves from A or B to C, and no vertex or geometry shader moves. unsafe-vote-branch 7,362 -> 6,861, tainted-exec 5,829 -> 5,793, stale-scalar 3,287 -> 3,254.

Tested

  • tests/semantic/test_wave64_halves_wqm_uvote.py (new, 18 tests): the accepted forms in both printed forms of the destination, ten near misses that stay tier C, and a vertex and a pixel shader run on the wave interpreter as one wave of 64 lanes and as two of 32, equal and equal to the derived words. With rdna2spirv: a wave64 VALU mask operand printed as one SGPR is the pair (SHADER-W64-SDST-PAIR) #1021 alone 14 of them fail.
  • GPU: ps_w64_a_wqm_uniform_vote through runtime/test/shaders/w64_graphics.py on an NVIDIA GeForce RTX 4070 Ti, Linux, driver 620.70.06, subgroup 32 only: the words its header derives. That device has one subgroup size, so the 64-lane image was not drawn, and the full-screen draw has no partly covered quad. It confirms the translated SPIR-V against the ISA reference, not native RDNA2 behaviour.
  • python -I scripts/run_semantic_tests.py tests/semantic: 472 files, 6,186 tests, 0 files failed. tests/test_wave64_halves_fixtures.py and the test_w64_graphics*.py files: 22 passed.

Overlap

#805 edits the same lines of uniform_cmp and the state dict. It handles EXEC after it is put back from whole quads; this handles the compare under them. They merge by hand; whichever lands second needs a rebase.

No game data: counts and opcode names only. AI-assisted (Claude Code).

🤖 Generated with Claude Code

DadaCap and others added 2 commits November 24, 2026 18:00
…r (SHADER-W64-SDST-PAIR)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… lane vote (SHADER-W64-WQM-UVOTE)

A pixel shader that needs derivatives starts with s_wqm_b64 exec, exec, and LLVM branches on wave-uniform conditions
inside that region as it does anywhere: v_cmp_* sN of scalars, s_and_b64 vcc, exec, s[N:N+1], s_cbranch_vccnz.
SHADER-10 took that for no lane vote only while EXEC was the launch mask, so here it was unsafe-vote-branch.

A compare of immediates and scalars is the same in every lane, so its mask is every lane of EXEC or none; the whole
quads of the launch mask have a lane in every 32-lane half that runs (a quad never straddles the halves). The analysis
carries "EXEC is the whole quads of the launch mask" as a dataflow fact, set by s_wqm_b64 exec, exec under the launch
mask and dropped by every other EXEC write. VGPR sources stay refused there, and so does a path on which a scalar was
read out of a uniform VGPR from a lane the launch mask may not have written.

Corpus (1.0.2.1, all 26,503, on top of SHADER-W64-SDST-PAIR): 452 pixel shaders go from tier C to A, none moves the
other way: C 7,741 to 7,289.

Tests: tests/semantic/test_wave64_halves_wqm_uvote.py; GPU fixture ps_w64_a_wqm_uniform_vote (RTX 4070 Ti, 620.70.06).

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

@abnalstlll-byte abnalstlll-byte 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.

Reviewed and verified. Precise analysis in ools/wave64_halves.py recognizing that under whole-quad EXEC (s_wqm_b64 exec, exec), scalar comparisons evaluate identically across quads without lane divergence, safely promoting 452 pixel shaders from Tier C to Tier A without false positives. Validated with ests/semantic/test_wave64_halves_wqm_uvote.py (18/18 PASS) and semantic test runner. 100% clean-room compliant.

@madhyn

madhyn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested f03418595 on Arch Linux + NVIDIA RTX 3060 Ti (595.58.03 / Vulkan):

  • python3 -m unittest tests/semantic/test_wave64_halves_wqm_uvote.py tests/semantic/test_wave64_single_sdst.py: 21 tests passed
  • python3 -I runtime/test/shaders/w64_graphics.py runtime/build/linux runtime/build/linux ps_w64_a_wqm_uniform_vote: ps_w64_a_wqm_uniform_vote A ok

AI-assisted: yes

Brings the branch up to date with main 68d1331. No conflicts; the merged tree was tested before the push (every standalone
test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since ProjectLeonida#930).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@aslan2142
aslan2142 merged commit d9f0a98 into ProjectLeonida:main Nov 24, 2026
4 of 5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged. Checked locally on main 22372d867 + 6c5c079ef:

  • Claim: valid. SHADER-W64-WQM-UVOTE was posted at 18:13 UTC, before this PR, and is unedited. With rdna2spirv: a wave64 VALU mask operand printed as one SGPR is the pair (SHADER-W64-SDST-PAIR) #1021 in main, the diff is only this change.
  • The rule is narrow: only s_wqm_b64 exec, exec from the launch mask sets it, and every other EXEC write clears it; a join keeps it only when both paths have it; VGPR sources are refused; and the qr cut-off covers scalars read from lanes the launch mask may not have written.
  • Tests: 14 of 18 in test_wave64_halves_wqm_uvote.py and the fixture tier check fail on main; all pass with this change.
  • GPU: ps_w64_a_wqm_uniform_vote and the other 20 ps_w64_* cases pass on an RDNA2 iGPU (RADV, Mesa 26.3.1). llvmpipe skips them all, since it can't require 32 or 64 lanes.
  • On the merge: the semantic suite passes (475 files, 6,212 tests, 0 files failed); test_run_gpu_tests, test_shader_checks pass; the 13 docs and writer tests pass; check_no_game_data.py is clean on the 6 changed files.
  • CI had not finished on this head.

For #805, which now conflicts in tools/wave64_halves.py, the hand merge is:

#187 and #1320 get an easy docs/design.md conflict (adjacent rows).

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

@ohshitwaddup

Copy link
Copy Markdown
Contributor

Hardware follow-up on the gap this PR's row records. docs/design.md ends that row with:

"…on an NVIDIA GeForce RTX 4070 Ti (Linux, driver 620.70.06, 32 only). That device has one subgroup size, so the 64-lane image was not drawn there and the full-screen draw has no partly covered quad; the run confirms the translated SPIR-V against the ISA reference, not native RDNA2 behaviour."

I have a card that can draw the 64-lane image. Here is the measurement, on main at b4b7756e (rebased worktree) with a runtime built from the same tree, build.py 288/288 translated and spirv-val clean.

Device

AMD Radeon RX 6900 XT — RDNA2 / GFX1030, Navi 21, PCI 1002:73bf. RADV NAVI21, Mesa 26.2.4, Vulkan 1.4.354 (conformance 1.4.5.3). minSubgroupSize 32, maxSubgroupSize 64, default 64.

w64_graphics.py ps_w64_a_wqm_uniform_vote

ps_w64_a_wqm_uniform_vote    A  ok          (exit 0)

That is the documented command, but "ok" alone does not say whether the 64-lane image was drawn — a fixture whose 64 request was silently ignored would also read "ok". So I called w64_graphics.draw() directly for each size and read the applied flag it derives from the harness's own fragment subgroup size: N line:

size=64     applied=True    pixels=4096   expected_problem('')
size=32     applied=True    pixels=4096   expected_problem('')
size=None   applied=None    pixels=4096   expected_problem('')   (device default = 64)

comparable(64) == comparable(32): True

applied=True at size 64 is the part the RTX 4070 Ti could not produce: the device confirmed the required fragment subgroup size took effect, and 4096 pixels came back. expected_problem is empty at every size, so the words match the header's derivation, and the 64 and 32 images are identical, which is what tier A requires. The default draw (no size requested) also lands on 64 here and gives the same words.

First pixels, identical at all three sizes: (0x7,0xb,0x24,0x1b) (0x8,0xb,0x24,0x1b) (0x9,0xb,0x24,0x1b) (0xa,0xb,0x24,0x1b).

So the two things the row says were not established now are, on this device: the 64-lane image was drawn, and tier A holds on native RDNA2 rather than only against the ISA reference on a 32-only device.

What this does and does not settle

Does: the row's own reservation about RDNA2 is answerable — a native 64-wide RADV device at required size 64 gives the header's words, and the 64/32 partition does not change the image.

Does not: it is one card, one driver (Mesa 26.2.4), one run per size. It says nothing about Intel's narrow-subgroup behaviour, and nothing about the corpus counts in the row, which I did not re-derive. The row's CPU-side reasoning about partly covered quads is confirmed by a full-screen draw on a 64-wide device, not by a partial-quad case — the fixture draws full-screen by design, so that clause still rests on the argument, not on silicon.

Suggested wording for the clause, if you want it: replace "not native RDNA2 behaviour" with the 64-wide result above (RX 6900 XT, RADV Mesa 26.2.4, required fragment subgroup size 64, identical to 32). I have not edited the row — that is this PR's author's call, and a rebase on a docs-only change while the tree moves at ~15 commits/hour would only add work.

Two incidental notes from the same run, offered because they may save someone time:

  • The full suite on this card at b4b7756e is 240/256 passed, 16 skipped, 0 failed. cs_imgload_tfe / cs_imgload_d16_tfe now pass, so PR tests: correct resident TFE status expectations (SHADER-1266) #892 fixed what several GPU records (including the RX 6900 XT record in gpu-test-results: AMD Radeon RX 6900 XT (RDNA2, RADV Mesa 26.2.4) on main 21625bc (GPU-RX6900XT) #631) list as their only failure.
  • cs_dpp_cmp.asm, merged recently, does not assemble with llvm-mc 22.1.8: v_cmp_gt_f32_dpp ... dpp8:[...] gives error: dpp variant of this instruction is not supported. It needs a 23.x llvm-mc. Because build.py aborts on the first failure, anyone on a distro LLVM 22 cannot build the fixtures directory at all — I had to set that one file aside to get a full build. docs/testing.md says LLVM 21+, so either the documented floor or that fixture probably wants a note.

AI-assisted (Hermes Agent): ran the fixture on the RX 6900 XT, read the applied flag per size, and confirmed the suite total above.

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.

6 participants