Skip to content

wave64_halves: --census --why counts where the tier C reasons come from (new SHADER item) - #4686

Open
shdann wants to merge 1 commit into
ItsNotRexed:mainfrom
shdann:wave64-census-why
Open

shdann wants to merge 1 commit into
ItsNotRexed:mainfrom
shdann:wave64-census-why

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: none. It builds on no open pull request. The text conflicts with other open pull requests are in "Overlap".

What and why

The census of the wave64 graphics tiers (#3570) has 9,287 tier C shaders and about 30,000 reason entries. A reason name such as cross-lane or unsafe-vote-branch does not say which rule is missing. The research note for #94 thinks that most of tier C is compiler code for values that are the same in each lane, but that is not measured. This pull request adds the measurement. It changes no tier and no emitted SPIR-V.

1. tools/rdna2spirv.py --wave64-why (off by default). For each tier C wave64 VS/PS/GS, the index gets wave64_graphics_why: one line for each reason, in program order.

reason|sink|producer@exec|source@exec|source of the source
Field Meaning
sink the family of the instruction where the reason was found (export, store, vcc_branch, exec_write, ...)
producer the family of the first instruction that made the value depend on the partition (v_readfirstlane, s_bcnt, v_mbcnt, ...). For a reason that is about the instruction itself (a vote, a mask half), it is the sink
source the families of the instructions that wrote the operands of the producer (buffer_load, image, v_interp, valu, salu, s_load, v_cmp, input, const, ...)
source of the source the families of the instructions that wrote the operands of those
@launch, @narrowed, @both if EXEC was the launch mask at the producer and at the writes of the source

A line has instruction families only: no register number, no constant, no offset, no shader name. Examples from the hand-written tests:

cross-lane|export|v_readfirstlane@launch|buffer_load@launch|input+valu
cross-lane|export|v_readfirstlane@narrowed|valu@narrowed|input
unsafe-vote-branch|vcc_branch|vcc_branch@launch|v_cmp@launch|v_interp
stale-scalar|export|valu@launch|salu@both|const+salu
tainted-exec|exec_write|salu@narrowed|salu+v_cmp@both|const+salu+v_cmp+valu

The first line is the case of #4630 (a scalar read from a loaded VGPR). The second is the case of #2469 (a uniform value under a narrowed EXEC). The third is a vote on an interpolated value, which no rule can accept. The last is the break loop mask of my finding in #4571.

2. tools/wave64_halves.py --census <index.json> --why [--top N] prints counts only:

  • how many tier C entries have the lines;
  • the first reason of each shader (one line for each tier C shader), most frequent first;
  • the same lines counted by sink, by producer and by source;
  • for each reason, the first site in each shader that has it.

Without --why the census prints what it printed before.

How it is made. WhyAnalysis is a subclass of Analysis. It wraps entry, block, join and step and adds two tables to the state: the origin of the taint of each register, and the families that wrote each register. The base class makes all decisions. analyse(..., why=True) runs it as a second pass for a tier C program only, and drops its result if it fails or does not find the same reasons. No line of the existing analysis changes, so the open pull requests on tools/wave64_halves.py conflict with this one only where they also change analyse().

Tested

The numbers below are from the head 09f87b92 (with main 2d3369a4 merged in). The branch is now one commit on main 561b65a8 (head 9295fa29); my comment of the rebase has the runs at that head. One test listing changed in the rebase: the vote on a compare of a scalar copy is tier A on main since #4138, so the listing now compares the low bit of the vertex number. 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_why.py (12 tests) pass
tests/semantic/test_wave64_halves.py, test_wave64_halves_soundness.py 101 and 30 tests, pass
python -I -m unittest discover -s tests/semantic 6,257 tests (12 more than main), 3 failures and 3 errors. main 2d3369a4 gives 6,245 tests with the same 3 failures and 3 errors on this machine, compared by test name: test_loop_ballot_barrier (5) and test_vcmp16_opsel (1). None of them is in a file that this pull request changes
pytest on tests/test_wave64_halves_fixtures.py, test_shader_index.py, test_fssm_wave_size.py, test_w64_graphics_args.py, test_w64_graphics_reference.py, test_wave64_graphics_scan.py, the docs row tests, test_semantic_translator_use.py, test_text_write_line_endings.py, test_resource_hygiene.py 72 passed, 1 skipped (it needs llvm-mc)
python -I -m compileall -q make_game.py tools tests, git diff --check, scripts/check_no_game_data.py pass

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

  • 14 tier C listings (13 vertex and 1 pixel; one of them has two reasons). The lines in the translator's metadata are equal to lines that the test derives by hand. The cases are: v_readfirstlane_b32 of a loaded VGPR into an export and into a scalar branch; the same under a narrowed EXEC; a vote on a compare of a VALU result and of an interpolated value; lane id; lane count; v_readlane_b32; v_writelane_b32; a mask half; code on the EXEC-zero side; a stale SGPR; the break loop mask; s_ff1_i32_b64.
  • Each line has family names only and no digit.
  • Tier A and tier B listings have no lines.
  • Without --wave64-why, the index entry of each listing has no new key and is equal to the entry with the option minus that key, and the translator calls analyse() with why=False.
  • For each of the 16 listings, the second pass reports the same violations in the same order as the first pass, and the same idioms.
  • If the second pass raises, the tier and the reasons stay and only the lines are absent.
  • The census counts and prints no shader name; an index without the lines gives one line that says so.

One more check that is not in the tests: for the 372 analyses that test_wave64_halves.py, test_wave64_halves_soundness.py and the new file make, the second pass gave the same violations, idioms and v_readlane_b32 rewrite set as the first pass, and each of the 290 tier C analyses gave lines.

Cost. On a hand-written tier C listing of 2,402 instructions, analyse() took 109 ms and 276 ms with why=True; the full translation of that listing without the option took 0.22 s. This is why the option is off by default.

Not tested. The command line of rdna2spirv.py with --wave64-why from start to end: the translator needs SPIRV-Tools to write an index, and this machine has none. The tests set the option in the module and check that --help has it.

Request: please run it on the corpus

I have no copy of the game. If you have your own copy, 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

Toolchain. The translation needs the llvm-mc that the README asks for: LLVM 21 or newer with the AMDGPU target (CI installs LLVM 21; the corpus run in this thread used 23.1.5). With LLVM 15 each listing is refused by the encoding check of rdna2spirv.py (same_encoding: the old disassembler prints the op_sel field of a gfx1013 VOPC instruction as 0), so the index stays empty and there are no lines to count (reported by mewajda below). I did not test LLVM 16 to 20. shader_disasm.py --backend python needs no LLVM for the listings.

The most useful parts are the table "first reason of a shader" and the lines "first reason by producer" and "first reason by source". They show, for example, how many tier C shaders start with a v_readfirstlane of a buffer_load, of an image load or of a valu result, and if EXEC was the launch mask there. That says which of #4630, #2469, #4138 and the rules that are not written yet moves the most shaders.

Limits

  • A shader gives one line for each reason (the first site), not one line for each site.
  • "Source" is one level of writers and "source of the source" is a second level. A longer chain is not followed.
  • At a join, the origin is the earliest instruction and the writer families are united.
  • The families are prefixes of the opcode. valu and salu are all other vector and scalar instructions.

Overlap

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 option and the census.)

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

🤖 Generated with Claude Code

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 09f87b92 on Windows 11, Python 3.15.2: pass.

  • test_wave64_halves_why.py: 12 tests, OK. Control on main's tools: 1 failure + 11 errors (the --wave64-why / --census --why paths don't exist), so the suite pins the feature.
  • Sibling wave64 suites on the head, all green: test_wave64_halves (101), test_wave64_halves_soundness (30), test_wave64_emulate_opt (22), test_wave64_cross_half (9), test_wave64_vcc_data_branch (3).
  • git diff --check + python -I scripts/check_no_game_data.py: clean. No shader corpus here — the --why census run over the real index stays with the hardware-owner request in the PR.

No game files. AI-assisted (Devin).

@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 09f87b921 on Windows 11: tests/semantic/test_wave64_halves_why.py -> 12 tests, OK; test_wave64_halves.py -> 101 tests, OK; test_docs_table_rows.py 2 OK; git diff --check clean.

wave64_halves --census --why now reports where each tier-C reason comes from, with the --why counts tested against the analysis and the docs row corrected (no stray vertical bar). The new 287-line test covers the census totals and the reason breakdown. No blocking issue.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 09f87b9 merged with main 98fa503 on Linux (Python 3.12.16): pass - test_wave64_halves_why.py 12 OK; all tests/semantic/test_wave64*.py 210 OK; tests/test_docs_*.py all OK; negative control: tools/wave64_halves.py and tools/rdna2spirv.py from main, new test kept: FAILED (failures=1, errors=11) of 12.

@Kev-Ball

Copy link
Copy Markdown

Full 1.0.2.1 corpus census at 09f87b92, CachyOS Linux. 26,503/26,503 translated and passed Vulkan SPIR-V validation. The merged index contains 13,405 wave64 VS/PS/GS entries; all 8,245 tier-C entries have well-formed provenance. The per-shader first-reason counts sum to 8,245.

For the author’s v_readfirstlane question, 532 tier-C shaders have it as the producer in their first diagnostic. Here is the source-family breakdown, counted once per shader:

EXEC at producer VALU source Buffer-load source Image source Total
Narrowed 477 22 0 499
Launch mask 13 16 4 33

The source and producer EXEC tags agree in every one of those 532 rows. These counts describe the first diagnostic; a shader can have additional blockers, so estimating how many tiers move still takes a rule-specific before/after comparison.

Stage totals, top first-reason rows, and producer/source counts
Stage Tier A Tier B Tier C
GS 195 0 0
PS 3404 27 7543
VS 1455 79 702

First reason per tier-C shader, 20 most frequent combinations:

Reason Sink Producer Source Source of source Shaders
tainted-exec saveexec saveexec@narrowed salu+saveexec@narrowed const+salu+saveexec 609
tainted-branch vcc_branch salu@narrowed s_load+v_cmp@narrowed input+s_load+salu 584
unsafe-vote-branch vcc_branch vcc_branch@narrowed salu@narrowed v_cmp 541
tainted-branch vcc_branch salu@narrowed input+v_cmp@narrowed s_load 491
unsafe-vote-branch vcc_branch vcc_branch@narrowed salu@narrowed salu 456
unsafe-vote-branch scc_branch salu@narrowed salu@launch const 424
tainted-branch scc_branch v_readfirstlane@narrowed valu@narrowed valu 350
unsafe-vote-branch vcc_branch vcc_branch@launch salu@launch salu 332
tainted-branch vcc_branch salu@narrowed s_load+v_cmp@narrowed s_load+salu 286
tainted-branch vcc_branch salu@narrowed s_load+v_cmp@narrowed s_load 264
tainted-exec exec_write salu@narrowed salu@both const+salu 260
tainted-branch vcc_branch salu@narrowed salu+v_cmp@narrowed s_load 259
tainted-exec exec_write salu@narrowed salu@narrowed salu 228
tainted-branch vcc_branch salu@launch s_load+v_cmp@launch s_load 185
unsafe-vote-branch vcc_branch vcc_branch@narrowed salu@narrowed salu+v_cmp 160
tainted-branch vcc_branch salu@narrowed salu+v_cmp@narrowed const+s_load 152
tainted-branch vcc_branch salu@narrowed salu+v_cmp@narrowed input+s_load 131
tainted-branch vcc_branch salu@narrowed s_load+salu+v_cmp@narrowed const+s_load 125
tainted-branch vcc_branch salu@narrowed salu@narrowed s_load+v_cmp 122
mask-half valu valu@narrowed v_cmp+valu@narrowed v_cmp+valu 119

First reason by reason (top 20): tainted-branch 3,419, tainted-exec 2,159, unsafe-vote-branch 1,991, mask-half 293, cross-lane 238, first-lane 88, stale-scalar 52, waterfall-scalar 3, unsafe-execz-branch 2.

First reason by producer (top 20): salu@narrowed 4,374, vcc_branch@narrowed 1,187, saveexec@narrowed 628, salu@launch 624, v_readfirstlane@narrowed 499, vcc_branch@launch 380, valu@narrowed 165, s_load@narrowed 131, exec_write@narrowed 103, s_ff@narrowed 97, v_readfirstlane@launch 33, v_writelane@narrowed 10, valu@launch 9, movrel@narrowed 3, exec_branch@launch 2.

First reason by source (top 20): salu@narrowed 1,805, s_load+v_cmp@narrowed 1,344, salu@launch 840, salu+v_cmp@narrowed 736, salu+saveexec@narrowed 609, input+v_cmp@narrowed 540, valu@narrowed 510, s_load+v_cmp@launch 476, s_load+salu+v_cmp@narrowed 455, salu@both 339, s_load+salu@narrowed 126, v_cmp+valu@narrowed 119, input+salu+v_cmp@narrowed 57, salu+v_cmp@launch 42, input+v_cmp@launch 42, v_cmp@narrowed 30, salu+saveexec+v_cmp@narrowed 24, buffer_load@narrowed 22, s_load+salu+v_cmp@launch 18, buffer_load@launch 16.

Reproduction: verified the input shader archive against the repository manifest, disassembled for gfx1013 with LLVM 23.1.5, and ran rdna2spirv.py <disasm> --out <scratch> --wave64-why --no-asm --shard i/12 for all 12 shards, followed by --merge and wave64_halves.py --census <scratch>/index.json --why. Python 3.14.10, SPIRV-Tools 2026.4. I checked the shard input sets, all 26,503 merged metadata records, and the per-stage totals. No metadata errors.

Flag-off control on the same revision: --shard 0/128 selected 208 shaders, including 65 tier C. All 208 binaries were byte-identical with the flag on/off, and their index entries matched after removing only wave64_graphics_why. The 12 focused semantic tests also passed. AI-assisted; aggregate results only.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

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

@Kev-Ball thank you, the counts are what this option was made for. I read the largest rows and made hand-written listings that give the same lines.

1. The largest group has one cause: a mask destination that the listing prints as one SGPR (#2231).

Rows such as tainted-branch | vcc_branch | salu@narrowed | s_load+v_cmp@narrowed (584, 286, 264), ... | input+v_cmp@narrowed (491) and ... | salu+v_cmp@narrowed (259, 152, 131) say: a SALU instruction made the value partition-dependent, and its operands were written by a v_cmp and by one more, different instruction. That is a 64-bit mask instruction on a pair whose low register a v_cmp wrote and whose high register still has an older value for the analysis. #2231 (open) explains it: the corpus is disassembled for wave32, so a wave64 v_cmp_*_e64 prints its destination as one register (284,353 sites in 18,866 wave64 shaders, counted there).

s_buffer_load_dword s15, s[0:3], 0        ; an older scalar in s15
v_cmp_gt_u32_e32 vcc, 48, v0
s_and_saveexec_b64 s[12:13], vcc          ; EXEC narrowed
v_cmp_lt_u32_e64 s14, s8, v0              ; the corpus spelling: the wave writes s[14:15]
s_and_b64 vcc, exec, s[14:15]
s_cbranch_vccz 3
s_and_saveexec_b64 s[16:17], vcc
v_add_nc_u32_e32 v6, 1, v6
s_or_b64 exec, exec, s[16:17]
s_or_b64 exec, exec, s[12:13]

In your table "first reason by source", the sources that mix v_cmp with another writer are 3,710 of the 8,245 first reasons (s_load+v_cmp 1,344 + 476, salu+v_cmp 736 + 42, input+v_cmp 540 + 42, s_load+salu+v_cmp 455 + 18, input+salu+v_cmp 57). That is an upper limit for this cause, because a correct instruction on two masks can give salu+v_cmp also. So #2231 is the pull request that can move the most tier C first reasons. It conflicts with main at this time; #4794 has a merge of it with my resolution of the three conflicts.

2. A smaller part stays after #2231, in tools/wave64_halves.py. #2231 does not change that file, and its operands() still takes the destination as one register. Then the high register keeps the taint and the reaching definitions of its old value (a lane count, a first-lane copy, a scalar set behind a vote), and the shader is tier C tainted-exec although the two runs are equal. #4794 corrects it (Depends on: #2231).

3. The tainted-exec rows with salu@both and salu@narrowed sources (260, 228) have the form of the loop mask of #4656 (a mask accumulated with s_or_b64 round a loop). The row with 609 shaders (saveexec@narrowed | salu+saveexec@narrowed) is a saveexec that reads a pair with two different writers and no tainted operand, so the reason is a stale read; I cannot tell from the families if it is the loop mask or the one-register spelling.

4. Not explained yet: unsafe-vote-branch | vcc_branch | vcc_branch@narrowed | salu@narrowed (541, 456, 160) and unsafe-vote-branch | scc_branch (424). The line does not say why vote() refused the branch (no narrowing at the start of the run side, or code on the other side). I can add that as one more field in a follow-up when this pull request is merged.

Request. If you can, please run the tier census (and --why) again on an index translated at the merge commit 7aacc969 of #4794 (main and #2231) and at its head cdea51c1. The first gives the effect of #2231 on the tiers and the second the effect of #4794.

@mewajda

mewajda commented Nov 23, 2026 •

Copy link
Copy Markdown

Corpus run: partly blocked, and what I could measure. My own 1.0.2.1 copy, counts only, no shader names or code.

Corpus shape (shader_carve.py -> fssm_unpack.py -> shader_disasm.py on this box): 26,503 containers, 25,734 listings; stages ps 12,101, ms 9,282, cs 2,689, vs 2,236, gs 195.

The population this census needs (tools/wave64_graphics_scan.py, a different tool, so this is an independent check on your 9,287):

stage shaders wave64 with a selected opcode
vs 2,236 2,236 1,195
ps 12,101 10,974 8,050
gs 195 195 195
total 14,532 13,405 9,440

So 13,405 wave64 VS/PS/GS, of which 9,440 carry at least one candidate cross-half opcode. Your index's 9,287 tier C is consistent with that (the tier analysis then clears the tier A/B ones), which is the first independent confirmation of the count the #3570 census reports.

The translation needs LLVM 18 or newer: llvm-mc 15 refuses every listing. by the encoding check (same_encoding, tools/rdna2spirv.py:14164) with e.g.

v_cmpx_ge_f32_e64 at 0x584: the blob holds 7e0116d413010200, LLVM printed 000116d413010200 (a field the disassembler dropped)

That is the gfx1013 VOPC op_sel drop you fixed in #2026, from the other side: LLVM 15's disassembler prints the field as 0, so the check refuses the listing. All 24 shards wrote empty part files (13 min of CPU, 0 translated), so there are no wave64_graphics_why lines to count. CI uses LLVM 18 and the #2026 measurement used 21, so that is the toolchain to state in the PR body: with an older LLVM the encoding check is hit before --wave64-why.

shader_disasm.py --backend python writes the exact encodings the check compares, so LLVM is out of the loop there; see the follow-up for why that route then stops on the name.

Tests on the head, as a code read: tests/semantic/test_wave64_halves_why.py 12/12 and tests/semantic/test_wave64_halves.py 101/101 pass; the full tests/semantic discover run gives 3 failures + 3 errors, and the large one is pre-existing: test_loop_ballot_barrier.py fails identically on origin/main 98fa503f (3 failures, 2 errors), which @bobcatchris already recorded. So nothing in that run points at this PR.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified at this head: compileall clean; the wave64_halves why/soundness/regular semantic suites pass under python -I, the fixtures pytest file 9/9, the translator-use guard passes, and the docs guards confirm --census --why and --wave64-why are implemented as documented. One note for reviewers: this is not the docs one-liner the title suggests — it adds the second-pass WhyAnalysis to wave64_halves/rdna2spirv plus a new semantic test; the design.md row requirement is satisfied. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@mewajda

mewajda commented Nov 23, 2026 •

Copy link
Copy Markdown

Follow-up on the blocked corpus run, so the next volunteer does not repeat the dead ends.

The Python backend avoids the LLVM-15 encoding refusal, but its listing names do not match the carve names. shader_disasm.py --backend python over the 26,503 blobs takes 4 minutes and reports 26,503 clean, and its listings carry exact encodings, so same_encoding has nothing to refuse. What stops the translation is the name: the module line inside a blob is printed with a leading . where the carved file has ! (; .FSColor2HideBaseFullBevelMul_d17d2c71_Wrapped vs !FSColor2HideBaseFullBevelMul_d17d2c71_Wrapped.dxbc), and rdna2spirv.py looks the DXBC up by the name it read from the listing. 857 of the carved names have that shape; symlinking .!<name>.dxbc for each makes the pair resolve.

So there are two working routes to the census: LLVM 18+ (CI's toolchain, the straightforward one), or the Python backend plus those 857 symlinks. The population counts in my previous comment do not depend on that route.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

AI-assisted (Claude Code). No game files; synthetic names and blobs only (Windows 11, Python 3.14.7).

@mewajda thank you for the two reports.

1. LLVM version. The description now has a "Toolchain" paragraph: the translation needs the llvm-mc that the README asks for (LLVM 21 or newer with the AMDGPU target), and with LLVM 15 each listing is refused by same_encoding. One correction: ci.yml on main installs LLVM 21 (Install llvm-mc (LLVM 21) and spirv-tools), not 18. I did not test LLVM 16 to 20, so the paragraph makes no statement about them.

2. The . and ! names. I could not reproduce this on main 594f3485, so I did not post a finding. What I checked:

  • tools/shader_disasm.py gives each listing the name of its input file for the two backends: name = os.path.splitext(os.path.basename(path))[0], then <name>.s and the header line ; <name> code .... The Python backend (rdna2_decode.disasm_bytes) returns instruction text only and reads no name from the blob.
  • A synthetic blob (an s_endpgm behind a header with the code offset at 0xC0) with the file name !SynthName_0000_Wrapped.fssm, through shader_disasm.py <dir> --backend python: the result is !SynthName_0000_Wrapped.s and its first line is ; !SynthName_0000_Wrapped code 0xf8..0xfc (header), gfx1013, 0 invalid words. A file name that starts with . keeps its . in the same way.
  • tools/rdna2spirv.py does not read the name from that header line. shader_ir.parse_file takes the stem of the listing file, and the translator opens <parent folder>/<stem>.dxbc. For a hand-written listing with the file name !ps_synth_0000_Wrapped.s, the file that it opens is !ps_synth_0000_Wrapped.dxbc.
  • tools/fssm_unpack.py keeps the stem of the carved file (<stem>.dxbc to <stem>.fssm), and tools/shader_carve.py changes only the characters < > : " / \ | ? * in a name.

So on main no step changes ! to .. To find the cause on your machine, these three facts are sufficient, and none of them is game content: the commit of your checkout, the full shader_disasm.py command, and the first two characters of one such name in each of the three folders (the carve folder, fssm/ and disasm/). If the . is already there in fssm/, the step before the disassembler made it.

@mewajda

mewajda commented Nov 23, 2026 •

Copy link
Copy Markdown

Correction and a dead end, so nobody spends time on it: the Python-backend route does not resolve with the name symlinks I described. Creating .NAME.dxbc for every !NAME.dxbc fixes 857 names but the translation then fails on others (FileNotFoundError: .../.FVertexCxformMulGradientMask_ca5c80b4_Wrapped.dxbc), and that name has no carved file at all: the carve holds 25,737 files for 26,503 index entries, so ~766 module names have no DXBC of their own. The name in the listing header is not reliably the carve name, so the mapping cannot be reconstructed mechanically.

Use LLVM 18 or newer and the normal shader_disasm.py path, which is the toolchain the --why census is meant to run on. The population counts in my first comment stand: 13,405 wave64 VS/PS/GS, 9,440 with a candidate opcode, against the 9,287 tier C in the #3570 census.

@CuteBooty

Copy link
Copy Markdown

Tested 09f87b92 merged with main d974c88a on NVIDIA GeForce RTX 3070 (32-wide subgroups), driver 617.14, Windows 11: no change against main d974c88a, as the PR says.

  • runtime/test/shaders build.py: 242 shaders, 242 translated, 242 pass spirv-val, head and base.
  • check.py native: 153 of 188 pass, 35 skipped; with LEONIDA_W64_EMULATE=1: 184 of 188 pass, 4 skipped. Same status for every test as base, 0 fail.
  • Translated modules and index.json are byte-identical to base in both modes (496 of 496 files); tiers of the wave64 graphics fixtures A/B/C 10/7/13.

Not tested: --wave64-why and --census --why on the GPU (they only change the index when the option is given), and a 64-lane run.

AI-assisted (Claude Code).

@SebSilent

Copy link
Copy Markdown
Contributor

One robustness note on --census --why while I was checking a review finding on my #4892: census() iterates wave64_graphics_why unguarded (tools/wave64_halves.py:1673 in your tree), so a tier C entry whose field is null or an integer exits 1 with TypeError: 'NoneType' object is not iterable / TypeError: 'int' object is not iterable, and a string or a dict is accepted and counted as nothing. Reproduced on main d974c88a5 merged with 09f87b92 using synthetic one-entry indexes. Your writer always emits a list of strings and Kev-Ball's corpus run found all 8,245 tier C entries well formed, so it only bites a hand edited or truncated index.

I am fixing it as a second commit on #4892 (1a144957, claimed on #4816) because that is where the entry field checks now live: the field goes through the same list of strings test, and both census modes then print one ERROR line and exit 2. If you would rather carry it inside your PR, say so and I will move it. AI-assisted.

@mewajda

mewajda commented Nov 23, 2026

Copy link
Copy Markdown

Corpus census with --wave64-why. My own 1.0.2.1 copy; shader_carve.py -> fssm_unpack.py -> shader_disasm.py (LLVM 18.1.8, gfx1013) -> rdna2spirv.py --wave64-why in 24 shards -> --merge (26,503 entries) -> wave64_halves.py --census --why. SPIRV-Tools 2026.4 for spirv-as/spirv-val. Counts only, no names, no code.

Tiers (13,405 wave64 VS/PS/GS, which is the same total wave64_graphics_scan.py reports independently):

stage tier A tier B tier C
vs 1,455 79 702
ps 3,404 27 7,543
gs 195 0 0
all 5,054 (37.7%) 106 (0.8%) 8,245 (61.5%)

why: 8245 of 8245 tier C entries have wave64_graphics_why, so the option covers every tier C shader; the tier counts are unchanged from the #3570 census.

Reasons: tainted-branch 6,534, unsafe-vote-branch 6,525, tainted-exec 5,189, cross-lane 4,612, stale-scalar 3,487, mask-half 759, unsafe-execz-branch 583, first-lane 353, lane-id 152, waterfall-scalar 3, lane-count 1. Tier B idioms: readfirstlane-uniform 3,302, lane-spill 287, waterfall 35.

First reason of a shader (top 15, the table the issue asks for):

  609  tainted-exec|saveexec|saveexec@narrowed|salu+saveexec@narrowed|const+salu+saveexec
  584  tainted-branch|vcc_branch|salu@narrowed|s_load+v_cmp@narrowed|input+s_load+salu
  541  unsafe-vote-branch|vcc_branch|vcc_branch@narrowed|salu@narrowed|v_cmp
  491  tainted-branch|vcc_branch|salu@narrowed|input+v_cmp@narrowed|s_load
  456  unsafe-vote-branch|vcc_branch|vcc_branch@narrowed|salu@narrowed|salu
  424  unsafe-vote-branch|scc_branch|salu@narrowed|salu@launch|const
  350  tainted-branch|scc_branch|v_readfirstlane@narrowed|valu@narrowed|valu
  332  unsafe-vote-branch|vcc_branch|vcc_branch@launch|salu@launch|salu
  286  tainted-branch|vcc_branch|salu@narrowed|s_load+v_cmp@narrowed|s_load+salu
  264  tainted-branch|vcc_branch|salu@narrowed|s_load+v_cmp@narrowed|s_load
  260  tainted-exec|exec_write|salu@narrowed|salu@both|const+salu
  259  tainted-branch|vcc_branch|salu@narrowed|salu+v_cmp@narrowed|s_load
  228  tainted-exec|exec_write|salu@narrowed|salu@narrowed|salu
  185  tainted-branch|vcc_branch|salu@launch|s_load+v_cmp@launch|s_load
  160  unsafe-vote-branch|vcc_branch|vcc_branch@narrowed|salu@narrowed|salu+v_cmp

Margins (what would move the most shaders):

first reason by sink:     vcc_branch x4650, saveexec x1546, scc_branch x907, exec_write x613, valu x162,
                          export x134, s_load x131, s_bcnt x88, v_writelane x10, exec_branch x2, store x2
first reason by producer: salu@narrowed x4374, vcc_branch@narrowed x1187, saveexec@narrowed x628,
                          salu@launch x624, v_readfirstlane@narrowed x499, vcc_branch@launch x380,
                          valu@narrowed x165, s_load@narrowed x131, exec_write@narrowed x103,
                          s_ff@narrowed x97, v_readfirstlane@launch x33, v_writelane@narrowed x10,
                          valu@launch x9, movrel@narrowed x3, exec_branch@launch x2
first reason by source:   salu@narrowed x1805, s_load+v_cmp@narrowed x1344, salu@launch x840,
                          salu+v_cmp@narrowed x736, salu+saveexec@narrowed x609, input+v_cmp@narrowed x540,
                          valu@narrowed x510, s_load+v_cmp@launch x476, s_load+salu+v_cmp@narrowed x455,
                          salu@both x339, s_load+salu@narrowed x126, v_cmp+valu@narrowed x119

What the numbers say about the #94 hypothesis. "Most of tier C is compiler code for values that are the same in each lane" holds for the scalar-value half: salu@narrowed is the producer of 4,374 of the 8,245 (53%), and salu is the only source family on 3,505 of them (1,805 + 840 + 510 + 339 + …). The vector side disagrees: v_cmp appears in the source field of 3,620 shaders (s_load+v_cmp 1,344, salu+v_cmp 736, input+v_cmp 540, s_load+salu+v_cmp 455, …), and v_readfirstlane is the producer of 532 — so a mask built by v_cmp from a load or an input is the second-largest family, which the lane-uniform rewrite does not cover. saveexec as sink 1,546 with tainted-exec 5,189 puts the EXEC save/restore family third.

For the rules named in the issue: the EXEC family (saveexec/exec_write sinks, 2,159 shaders) is the one #4423 and #4624 touch; the v_readfirstlane producer (532) is #2469's; the s_load+v_cmp/input+v_cmp sources are the cross-lane mask case (#4138). The unsafe-execz-branch reason is almost always exec_branch@narrowed with a constant producer (581 of 583), i.e. a mask branch on an EXEC that is already narrowed — a narrow, single-shape rule.

Full command output available on request; nothing here names a shader.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 09f87b9 on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_wave64_halves_why.py" -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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>
@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Tested 9295fa2 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073.

  • pytest tests/semantic/test_wave64_halves_why.py -q: 12 passed.

Tools/tests/docs changes (wave64_halves/rdna2spirv helpers); no runtime C++ changes. GPU suite not re-run.

AI-assisted (OpenCode).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

AI-assisted (Claude Code). No game files; CPU only (Windows 11, Python 3.14.7).

Rebased on main 561b65a8; new head 9295fa29 (one commit, pushed with --force-with-lease).

  • Conflicts: analyse() in tools/wave64_halves.py (the result keeps the scalar_spills key of main next to the optional why key) and docs/design.md (the SHADER-10 row of main with the --why sentence put back in).
  • One test listing changed. The vote on a compare of a scalar copy is tier A on main since wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) #4138, so vs_why_vote_valu now compares the low bit of the vertex number. Its two expected lines are the same as before. The census output format did not change, so the corpus counts in this thread stay comparable.
Check at 9295fa29 Result
tests/semantic/test_wave64_halves_why.py 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 275 tests, pass
The second analysis pass against the first one, for the 446 analyses of the three test files above the same violations, idioms and rewrite set; each of the 326 tier C analyses gives lines
python -I -m unittest discover -s tests/semantic 6,162 tests, OK (main 561b65a8: 6,150 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)
compileall, scripts/check_no_game_data.py pass

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

AI-assisted (Claude Code). No game files; hand-written listings.

The description said that the command line of rdna2spirv.py was not tested from start to end on my machine. It is tested now (Windows 11, Python 3.14.7, llvm-mc 21.1.8, SPIRV-Tools v2026.4), at the head of #5970, which is this head plus one commit:

  • Three hand-written vertex listings (a refused vote, a lane id, a clean one) through rdna2spirv.py <disasm> --out <dir> with and without --wave64-why: the two runs exit 0 with tier A: 1, tier C: 2.
  • The index entries of the two runs are equal apart from the _why keys, and the three .spv files are byte-identical.
  • wave64_halves.py --census <index> --why on the index of the second run prints the tables (2 of 2 tier C entries have the lines).
  • tests/test_wave64_halves_fixtures.py with the tools on the path: 10 passed, 0 skipped.

@vanoizer

Copy link
Copy Markdown
Contributor

Tested 9295fa2 on AMD gfx1036 (26.11.2) and RTX 4070 Ti SUPER (621.14), Windows 11: pass.

  • PR tests: test_wave64_halves_why.py, 12 passed.
  • semantic: 6162 OK.
  • GPU: AMD 215/232, 0 failed. NVIDIA 183/232 native and 214/232 emulated; the only failure is ms_wave_info_s3, the same as on main.

Setup: Windows 11. GPUs are an AMD Ryzen 7 9800X3D iGPU (RDNA2 gfx1036, driver 26.11.2, subgroup 32..64) and an RTX 4070 Ti SUPER (NVIDIA 621.14, subgroup 32). Each PR was tested in its own worktree with:

  • the PR's own tests (pytest);
  • python -m unittest discover -s tests/semantic;
  • scripts/run_gpu_tests.py three times: AMD native wave64, NVIDIA native, and NVIDIA with LEONIDA_W64_EMULATE=1.

Baseline is main 561b65a8:

Run Passed
AMD native 215/232, 0 failed
NVIDIA native 183/232, 1 failed
NVIDIA emulated 214/232, 1 failed

The NVIDIA failure is ms_wave_info_s3 (known, #5741).

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.