Skip to content

Translator: wave64 VS/PS/GS on 32-wide subgroups when the halves can't tell — tier A/B/C analysis (SHADER-10) - #1494

Closed
AlxcBTW wants to merge 1 commit into
ItsNotRexed:mainfrom
AlxcBTW:shader10-half-invariance-v2
Closed

AlxcBTW wants to merge 1 commit into
ItsNotRexed:mainfrom
AlxcBTW:shader10-half-invariance-v2

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What and why

This is the implementation part of SHADER-10 (claimed in #1218; @kahlio76's first part, the documentation and flagging, stays theirs).

A wave64 VS/PS/GS on a 32-wide subgroup is exact only if its results don't change when the wave is cut into two 32-lane halves. The host forms graphics subgroups, so there is no partner half to exchange with.

tools/wave64_halves.py classifies each wave64 VS/PS/GS from its code:

  • Tier A: exact as translated.
  • Tier B: exact by construction. This covers waterfall loops, wave-aggregated atomics, and readfirstlane/readlane of values proven to be the same in every lane. Wave-aggregated atomics are exact as a set of slots, but the order within a wave is not preserved.
  • Tier C: not exact. This covers lane counts, ranks and ids, readlane of varying data, scalar state defined behind a vote, masks read as data, and similar cases.

Output and flags:

  • The tier, reasons and idioms go into index.json as wave64_graphics, wave64_graphics_reasons and wave64_graphics_idioms.
  • --wave64-graphics warn|error|off marks and counts tier C, refuses it, or skips the analysis.
  • python tools/wave64_halves.py --census <index.json> prints tier counts without shader names.

One rewrite: v_readlane of a proven-uniform VGPR reads the lane's own copy.

This complements #1132 (wave64_graphics_scan.py). Two independent adversarial reviews (about 100 probe programs) found soundness holes; each one is fixed and is now a test.

Tested

  • Semantic tests (57): vertex shaders run as one 64-lane wave and as two 32-lane waves on the strict wave interpreter. Tiers A and B must agree; tier C must differ or be classified C.
  • GPU fixtures (14 ps_w64_*): run through runtime/test/shaders/w64_graphics.py on the Radeon 880M (AMD 26.11.2), with the fragment subgroup size required to 64 and to 32. Tiers A and B match; tier C differs. The RTX 5070 (617.42, 32 only) was compared against the 880M@64 images and agrees.
  • tests/test_translate.py: 427 passed, 2 skipped (ms_f16_pack, no synthetic DXBC). tests/test_shader_checks.py passes.
  • Byte identity vs main: 148 of 149 test shaders are identical. The only difference is the intended readlane rewrite (ps_w64_b_readlane_uniform).
  • Earlier head (before rebasing onto main): run_gpu_lab on both GPUs passed (880M 121/124, 5070 93/124 with the 64-wide compute tests skipped), and full pytest gave 3384 passed.

Honest limits

  • Corpus coverage is not measured. It needs a run over the game's shaders by someone who has them; please post the tier counts from --census.
  • Two cases are covered only by semantic tests, with no GPU fixture: a rank-only store address, and an all-lanes atomic add of a count.
  • The wave interpreter can't detect "mask combined with data", because it models the 64-bit pair per lane. Those tests check classification only.
  • Not GPU-tested: vertex shaders (the 880M can't require a vertex subgroup size, so the interpreter covers them), geometry shaders, and the in-half permutes (ds_bpermute, v_permlane16, ds_swizzle, v_permlanex16).
  • Not checked: helper lanes in partial quads.

Checklist

  • No game data
  • New rule in the docs/design.md contract table, with how it was confirmed
  • Tests run

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…t tell (SHADER-10)

tools/wave64_halves.py classifies each wave64 VS/PS/GS by partition
invariance: A exact as translated, B exact by construction (waterfall loops,
wave-aggregated atomics up to slot order, readfirstlane/readlane of values
that are the same in every lane), C not exact (lane counts/ranks/ids,
readlane of varying data, stale scalars behind votes, masks as data, ...).
index.json gets wave64_graphics, wave64_graphics_reasons and
wave64_graphics_idioms; --wave64-graphics warn|error|off (error refuses
tier C). One rewrite: readlane of a proven-uniform VGPR reads the own copy.
--census prints tier counts from an index.json. ps_w64_* fixtures,
w64_graphics.py (fragment subgroup size required 64 vs 32) and semantic
tests; vk_harness gets VKH_HEAP_DUMP and a subgroup-size report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1541: the same single commit, rebased onto main after #291 (it conflicted in tools/rdna2spirv.py, and force-pushing isn't available to me, so it's a new branch).

@AlxcBTW AlxcBTW closed this Nov 22, 2026
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tried 4b054af merged onto main on an AMD Radeon RX 9070 (RDNA4), AMD 26.11.2, Windows 11 (runtime rebuilt, llvm-mc 21.1.8). There's one integration problem.

scripts/run_gpu_tests.py runs every .asm in runtime/test/shaders/, and the 14 new ps_w64_* fixtures have no checker there:

  FAIL  ps_w64_a_one_lane     no checker defined
  FAIL  ps_w64_a_skip         no checker defined
  FAIL  ps_w64_b_ballot_atomic  no checker defined
  ...

So the suite goes from all-pass on main to 139/153 both natively and with LEONIDA_W64_EMULATE=1, and every tester's run_gpu_tests run and the llvmpipe job would show 14 failures. The other 139 pass, so nothing else regressed.

Two ways out:

  • give run_gpu_tests.py a branch that hands ps_w64_* to w64_graphics.py's judging, or skips them with a pointer to it;
  • or keep the fixtures out of the directory run_gpu_tests.py globs.

I didn't run w64_graphics.py itself here; I can if you want an RDNA4 data point for the tiers.

AI-assisted (Claude Code).

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.

2 participants