Skip to content

wave64_halves: --census --why says which condition of vote() refused a vote (new SHADER item) - #5970

Open
shdann wants to merge 2 commits into
ItsNotRexed:mainfrom
shdann:wave64-why-vote
Open

shdann wants to merge 2 commits into
ItsNotRexed:mainfrom
shdann:wave64-why-vote

Conversation

@shdann

@shdann shdann commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new SHADER item (claim)

Depends on: #4686

This branch is #4686 (9295fa29, one commit on main 561b65a8) with one commit on top (d7ee0e7f). The change of this pull request is the last commit only.

What and why

The census of #4686 on the corpus (8,245 tier C shaders) has about 1,400 shaders whose first reason is a refused vote: unsafe-vote-branch | vcc_branch | ... (541 + 456 + 160 in the largest rows) and unsafe-vote-branch | scc_branch | ... (424). Its lines say where the voted mask came from. They do not say why vote() refused the branch, and that is what decides which rule can help: a run side that does some scalar work before it narrows EXEC, an if/else (#5747 tried that shape), or an early exit.

This pull request adds that information to the same option. It changes no tier and no emitted SPIR-V.

1. tools/rdna2spirv.py --wave64-why also writes wave64_graphics_vote_why for a tier C shader that has a refused vote: the distinct lines of its refused votes, in program order, at most 8.

reason|condition|run:family|other:family
Field Meaning
reason unsafe-vote-branch (a vote on a mask) or unsafe-execz-branch (a vote on EXEC)
condition the part of vote() that failed, see below
run:family the instruction family at the start of the side that runs when some lane votes yes
other:family the instruction family at the start of the other side; join when that side has no code of its own
Condition Meaning
no-narrowing the run side does not start by narrowing EXEC to the voted mask; the other side is the join
other-side-joins the run side narrows, but the other side has code of its own and then meets the run side again (an if/else)
other-side-exits the same, but the other side never meets the run side (an early exit)
no-narrowing+other-side-joins, no-narrowing+other-side-exits the two together
one-way the branch has one successor

For a vote on EXEC the run side needs no narrowing, so the condition is other-side-joins or other-side-exits. A line has reason names, condition names and instruction families only. Examples from the hand-written tests:

unsafe-vote-branch|no-narrowing|run:valu|other:join
unsafe-vote-branch|no-narrowing|run:s_load|other:join
unsafe-vote-branch|other-side-joins|run:saveexec|other:exec_write
unsafe-vote-branch|other-side-exits|run:saveexec|other:valu
unsafe-execz-branch|other-side-joins|run:valu|other:salu

The second line is a run side that loads a scalar and then narrows. The third is the two-sided if/else of #5747.

2. tools/wave64_halves.py --census <index.json> --why prints, after the tables of #4686:

  • how many tier C entries have the lines;
  • the conditions, where a shader counts once for each condition that it has;
  • the first refused vote of each shader, most frequent first;
  • all lines, where a shader counts once for each line that it has.

How it is made. WhyAnalysis (the second analysis pass of #4686) wraps vote(). The base class decides. When it reports one of the two reasons, the wrapper calls the same helpers that vote() uses (narrows, reaches, past_jumps) to name the condition. No line of the base class changes.

Tested

Head d7ee0e7f. Windows 11 Pro (10.0.26200), Python 3.14.7, CPU only. No GPU. No llvm-mc and no SPIRV-Tools on this machine, so I did not build the GPU fixtures and I did not run spirv-val. No game files.

Check Result
New tests/semantic/test_wave64_halves_vote_why.py 8 tests, pass
tests/semantic/test_wave64_halves_why.py (of #4686; two of its tests now ignore the new key) 12 tests, pass
tests/semantic/test_wave64_halves.py, test_wave64_halves_soundness.py 125 and 33 tests, pass
All tests/semantic/test_wave64*.py, test_w64*.py, the interpreter test and the two saveexec tests 283 tests, pass
The second analysis pass against the first one, for the 446 analyses of the wave64 halves test files the same violations, idioms and rewrite set
python -I -m unittest discover -s tests/semantic 6,170 tests, OK (main 561b65a8: 6,150 tests, OK; #4686 9295fa29: 6,162 tests, OK)
pytest on the wave64 fixture tests, test_lane_masks.py, test_shader_index.py, the docs row tests and the hygiene tests 77 passed, 1 skipped (it needs llvm-mc)
python -I -m compileall -q tools tests, scripts/check_no_game_data.py pass

What the new tests check, all on hand-written vertex listings:

  • 9 tier C listings with a refused vote. The lines in the translator's metadata are equal to lines that the test derives by hand: no narrowing with a VALU instruction first; a scalar load before the narrowing; an SCC vote on a mask pair; an if/else with a narrowed run side; the two-sided if/else; an if/else with no narrowing; an other side that exports and ends the program; a vote on EXEC whose zero side writes an SGPR; and a listing with three refused votes of two kinds (two lines, in program order).
  • Each line has reason names, condition names and family names only.
  • A tier A listing with an accepted vote and a tier C listing with no vote have no lines.
  • Without --wave64-why the index entry has no new key; with it, the tier, the reasons and all other keys of the entry are the same.
  • The census counts and prints no shader name; an index without the lines gives one line that says so.

The command line from start to end (added later, with llvm-mc 21.1.8 and SPIRV-Tools v2026.4 on this machine): three hand-written vertex listings through rdna2spirv.py <disasm> --out <dir> with and without --wave64-why, then wave64_halves.py --census <index> --why. The two runs exit 0; the index entries are equal apart from the two _why keys; the .spv files are byte-identical; the census prints the two sets of tables. tests/test_wave64_halves_fixtures.py with the tools: 10 passed, 0 skipped.

Request: please run it on the corpus

I have no copy of the game. If you have your own copy and LLVM 21 or newer, please translate the wave64 VS/PS/GS with the option and post the counts (the output has no shader name and no code):

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

The useful parts are the line "refused votes by condition" and the table "first refused vote of a shader". They show if the refused votes are mostly run sides that do not start with the narrowing (and which instruction family comes first), if/else shapes, or early exits.

Limits

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. (No new rule; the row describes the new index key and the census tables.)

🤖 Generated with Claude Code

shdann and others added 2 commits November 23, 2026 14:52
Tier C has about 3 reasons per shader, and a reason name does not say which missing rule is behind it.
analyse(..., why=True) now gives, for a tier C program, one line per reason in program order:

    reason|sink|producer@exec|source@exec|source of the source

with instruction families only: the instruction where the reason was found, the first instruction that
made the value depend on the partition, the instructions that wrote the producer's operands and the ones
that wrote the operands of those, and if EXEC was the launch mask at the producer and at the source writes.

- WhyAnalysis is a subclass of Analysis that wraps entry, block, join and step with two side tables. It
  runs as a second pass for tier C programs only, and its result is dropped if it fails or finds other
  reasons, so it cannot change a tier.
- rdna2spirv.py --wave64-why writes the lines to the index as wave64_graphics_why. Without the option the
  index and the translation time are as before. The emitted SPIR-V is the same in the two cases.
- wave64_halves.py --census <index> --why [--top N] prints the counts: the first reason of each shader,
  its marginals by sink, producer and source, and the first site of each reason. No names, no code.

tests/semantic/test_wave64_halves_why.py: 14 hand-written tier C listings with the lines derived by hand.

No game data. Not run on the corpus.

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

The census of ItsNotRexed#4686 on the corpus has about 1,400 first reasons that are a refused vote (unsafe-vote-branch),
and its lines do not say why vote() refused the branch.

WhyAnalysis now wraps vote(): when the base class reports unsafe-vote-branch or unsafe-execz-branch, it adds
one line

    reason|condition|run:family|other:family

with the condition that failed (no-narrowing, other-side-joins, other-side-exits, the two together, one-way)
and the instruction family at the start of the side that runs on a yes vote and of the other side ("join"
when that side has no code of its own). analyse(..., why=True) gives the distinct lines in program order
(at most 8) as "vote_why"; rdna2spirv.py --wave64-why writes them to the index as
wave64_graphics_vote_why; wave64_halves.py --census --why counts them by condition, by first line and by
line. No tier and no SPIR-V changes; without the option the index is as before.

tests/semantic/test_wave64_halves_vote_why.py: 9 hand-written listings with the lines derived by hand.

Builds on ItsNotRexed#4686. No game data. Not run on the corpus.

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

Kev-Ball commented Nov 23, 2026 •

Copy link
Copy Markdown

Completed the Xbox 1.0.2.1 corpus run on d7ee0e7fe with --wave64-why. Across 32 shards, all 26,503 ordinary listings translated and passed spirv-val. The merged --census --why reproduces the condition counts and first five shapes reported below.

I also counted distinct shaders to separate prevalence from the first refusal. Of the 6,496 tier-C shaders with recorded refused votes, 6,235 contain unsafe-vote-branch | no-narrowing+other-side-joins, 5,709 have it first, and 4,057 have it as their only recorded condition. So 526 shaders with that condition already encounter a different one first. The tagged population is 6,222 pixel and 274 vertex shaders.

Across all tagged shaders, 2,287 record multiple distinct reason/condition pairs and 656 reach the eight-line cap. These are counts of recorded evidence, not estimates of tier promotions. AI-assisted QA.

@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Tested d7ee0e7 on Windows 11, Python 3.14, CPU part only: pass. Full tests/semantic suite run per file, 0 failures (6,170 tests; main at the merge base 561b65a has 6,150, also 0 failures); targeted wave64 files OK; compileall, check_no_game_data, git diff --check pass. Not done: the --census --why corpus run over the disassembly and the AMD GPU part, left for another tester. AI-assisted (Claude Code).

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown

Package corpus census completed on a 40-core Linux server with the 1.0.2.1 package and 64 GiB RAM. 26,503 entries translated and the merged index passed; 29 FSPX entries: 21 translated, 8 undecodable by the existing fallback. All 8,245 tier-C entries carried wave64_graphics_why.

Aggregate:

  • Tier A: 5,059 (37.7%)
  • Tier B: 101 (0.8%)
  • Tier C: 8,245 (61.5%)
  • 6,496 of 8,245 tier-C entries have refused-vote fields

Refused-vote conditions:

  • no-narrowing + other-side-joins: 6,235 shaders
  • other-side-exits: 1,432
  • no-narrowing: 878
  • unsafe-execz-branch + other-side-joins: 583
  • no-narrowing + other-side-exits: 495
  • unsafe-vote-branch + other-side-joins: 2

Top first refused-vote shapes:

  • no-narrowing + other-side-joins, run:s_load/other:s_load: 1,128
  • no-narrowing + other-side-joins, run:valu/other:salu: 931
  • no-narrowing + other-side-joins, run:valu/other:valu: 727
  • no-narrowing + other-side-joins, run:v_cmp/other:dpp: 478
  • no-narrowing + other-side-joins, run:valu/other:s_load: 394

No shader names or shader code are included. Counts only.

AI-assisted (Copilot).

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