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) - #1541

Closed
AlxcBTW wants to merge 2 commits into
ProjectLeonida:mainfrom
AlxcBTW:shader10-v3
Closed

AlxcBTW wants to merge 2 commits into
ProjectLeonida:mainfrom
AlxcBTW:shader10-v3

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member

Rebased onto main after #291 (one commit; replaces #1494, which conflicted in tools/rdna2spirv.py; rebased rather than merged, as asked for that file). Re-run on the rebased commit: test_translate/test_shader_checks/fixtures 477 passed, 2 skipped; test_wave64_halves OK.

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

Copy link
Copy Markdown

Carried over from #1494, where I tested 4b054af (the same commit before the rebase) on NVIDIA GeForce RTX 3090 (Ampere, fragment and compute subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300. w64_graphics.py passes. scripts/run_gpu_tests.py fails: the 14 new fixtures have no checker there.

#1494's diff applied cleanly to main bb2e184. Runtime built from this PR (its vk_harness) with scripts\build_runtime.ps1, VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8.

  • build.py: 151 translated, all pass spirv-val.
  • runtime/test/shaders/w64_graphics.py, the first 32-only NVIDIA run of it:
    • Tier A and B: all 6 ok (a_one_lane, a_skip, b_ballot_atomic, b_readfirstlane, b_readlane_uniform, b_waterfall). The 32-lane images match the words the headers derive.
    • Tier C: all 8 SKIP (tier C needs a device that can require both 64 and 32, or W64G_REF), as expected on NVIDIA.
  • scripts/run_gpu_tests.py --build runtime\build: exit 1, 109/153 pass, 30 skipped. All 14 ps_w64_* show FAIL ... no checker defined. main gives 109/139 with exit 0 on the same GPU, so this PR would make the standard GPU suite fail everywhere. One fix is to skip these in run_gpu_tests.py, since w64_graphics.py runs them, or to give them a checker.
  • tests/semantic/test_wave64_halves.py: OK. I didn't run tests/test_wave64_halves_fixtures.py (it needs pytest, which isn't installed here).

Rechecked on this PR (ce305ec), applied to main 99f9989: run_gpu_tests.py --filter ps_w64 still gives 0/14 passed, exit 1, all 14 no checker defined. This branch's run_gpu_tests.py still never mentions ps_w64.

… (SHADER-10)

They compare one shader at a required fragment subgroup size of 64 and of 32,
which a single vk_harness run can't do; run_gpu_tests.py reported them as
"no checker defined". Reported by @Rainmaker33 in ProjectLeonida#1541.

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

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Thanks @Rainmaker33, that was a real bug. Fixed in 9749ddd7: run_gpu_tests.py now skips the ps_w64_* fixtures as "run by runtime/test/shaders/w64_graphics.py". They compare one shader at a required fragment subgroup size of 64 and of 32, and a single vk_harness run can't do that. On an RTX 5070, run_gpu_tests.py --filter ps_w64 gives 14 skipped and 0 failed, and tests/test_shader_checks.py passes.

Your tier-C SKIPs on a 32-only GPU are expected: proving that tier C differs needs a device that can require both 64 and 32. Thanks also for the first 32-only NVIDIA run of w64_graphics.py (tiers A and B, 6/6 ok).

AI-assisted (Claude Code).

@LloydNicholson

Copy link
Copy Markdown
Contributor

Tested 9749ddd7 on an AMD Radeon RX 9060 XT (RDNA4, gfx1200), RADV on Mesa 27.0.0-devel, Vulkan 1.4.366, Linux 7.3 (Fedora 44): pass. This is the "AMD + 32-wide" check from the coordination list, on a second AMD architecture besides the 880M.

RADV on this card can require subgroup size 32 or 64 for the fragment stage (requiredSubgroupSizeStages includes FRAGMENT), so the comparison ran both sizes natively, with no stand-in device.

  • runtime/test/shaders/w64_graphics.py: 14/14 ok.
    • Tier A (2) and tier B (4): the 64 and 32 images are equal, and match the derived words.
    • Tier C (8): the named words differ between 64 and 32, as the detector predicts.
  • scripts/run_gpu_tests.py (native Linux build of runtime/, llvm-mc 22.1.8, SPIRV-Tools 2026.1):
    • 160/160 translated, 160/160 pass spirv-val.
    • GPU tests: 141/155 passed, 14 skipped (the ps_w64_* fixtures, judged by w64_graphics.py above), 0 failed.
    • Tier census of the test shaders: A 3, B 4, C 8.
  • CPU tests:
    • unittest discover -s tests/semantic: 1304 OK.
    • pytest tests/test_wave64_halves_fixtures.py tests/test_translate.py tests/test_shader_checks.py: 477 passed, 2 skipped.

Not covered here: vertex and geometry shaders on the GPU (RADV doesn't list VERTEX/GEOMETRY in requiredSubgroupSizeStages either), and the corpus census (no game files used).

One note for other Linux testers: an old SPIRV-Tools (v2024.3) earlier on the PATH made every shader fail spirv-val with INVALID: ?, and run_gpu_tests.py then reports missing .spv (translation failed) for all of them. That's the environment, not this PR.

AI-assisted (Claude Code).

@gurvancampion

Copy link
Copy Markdown
Contributor

Tested 9749ddd on an RTX 5090 (NVIDIA 615.78.08, subgroup 32) and the Ryzen 7 9800X3D iGPU (RDNA2, gfx1036, RADV Mesa 26.2.5, subgroup 32..64), Linux 7.2 (Arch): pass. No game files.

This is the first RDNA2 check, after gfx1150, RDNA4 and Ampere. RDNA2 is the family the game's shaders target.

  • runtime/test/shaders/w64_graphics.py on RADV gfx1036, with the fragment subgroup size required to 64 and to 32 (W64G_SAVE_REF): 14/14 ok. Tiers A and B are equal, and tier C differs where the header says.
  • The same fixtures on the RTX 5090 against those RDNA2 64-lane images (W64G_REF): 14/14 ok.
  • scripts/run_gpu_tests.py --build runtime/build/linux: 5090 with LEONIDA_W64_EMULATE=1 141/155 (14 skipped, the ps_w64_* ones); 5090 native 111/155 (44 skipped); RADV native 141/155 (14 skipped). No failures. The "no checker defined" failures I saw at ce305ec are gone.
  • pytest tests/semantic/test_wave64_halves.py tests/test_wave64_halves_fixtures.py tests/test_translate.py tests/test_shader_checks.py: 534 passed, 2 skipped.

AI-assisted run (Claude Code).

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	docs/design.md
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
…AT_SUPPORT check, four tools' stdout

- run_gpu_tests.py: #1541's wave64 pixel fixtures (runtime/test/shaders/w64_graphics.py FIXTURES, tiers A-C) are
  checked by that runner; run_gpu_tests picked up their .asm and failed 14 of them with "no checker defined".
  It now leaves w64_graphics.FIXTURES to that runner.
- d3d12_d24_support_test (#1493): expected DEPTH_STENCIL in FORMAT_SUPPORT for R24G8_TYPELESS. Measured here, the
  host D3D12 (RTX 4060 Ti and WARP) reports 0x001010b0 for R24G8_TYPELESS and 0x003110b0 (DEPTH_STENCIL) only for
  D24_UNORM_S8_UINT, which #1511's per-format rules follow; the check now expects the bit for the typed format only.
- fma_mix_probe, text_tables, wave64_halves, xdxr_bvh: new tools without #1428's stdout errors='replace' guard.

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

Copy link
Copy Markdown

Tested 9749ddd on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass.

Native Linux build of runtime/ from this PR (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • tests/semantic: 1304 OK; tests/test_shader_checks.py: OK
  • build.py: 153 translated, 153 pass spirv-val
  • runtime/test/shaders/w64_graphics.py: tier A and B 6/6 ok; tier C 8 SKIP (expected: this GPU can only require 32)
  • run_gpu_tests.py: 160/160 translated and pass spirv-val; 111/155 passed, 44 skipped (wave64 without emulation + the 14 ps_w64_* fixtures), 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 141/155 passed, 14 skipped (ps_w64_*, run by w64_graphics.py), 0 failed

First Turing / Linux NVIDIA run of this PR, after @Rainmaker33's RTX 3090 on Windows.

AI-assisted run (Claude). Counts only, no game files involved.

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

This landed in 934bb0c (its commit ce305ec). The only thing left on the branch is the follow-up 9749ddd, a run_gpu_tests.py skip for the ps_w64_* fixtures. 21a8e07 already does the same thing on main (W64_GRAPHICS_ONLY), so I'm closing this as merged. Thanks @ItsNotRexed, and thanks @Rainmaker33, @LloydNicholson, @gurvancampion and @Impre-visible for the runs on Ampere, RDNA4, RDNA2 (gfx1036), Blackwell and Turing.

@AlxcBTW AlxcBTW closed this Nov 22, 2026
@wildheathen

Copy link
Copy Markdown
Contributor

SHADER-10 on the AMD Windows driver (the earlier runs here were RADV and the 880M): RDNA2 iGPU, plus an RTX 5080 in the same PC. Main a0acd33 (with 934bb0c7), Windows 11 26300, llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. AI-assisted run.

GPU:    AMD Radeon(TM) Graphics (Ryzen 7 9800X3D iGPU, RDNA2, 1002:13C0), AMD 32.0.21042.62 (amdvlk64), Vulkan 1.4.315
        NVIDIA GeForce RTX 5080, 621.24, Vulkan 1.4.357
build:  runtime/test/shaders/build.py: tier A 2, tier B 4, tier C 8

w64_graphics.py as is: tiers A and B ok on both GPUs (6/6 each); tier C SKIP on both, including the AMD. The AMD Windows driver lists only COMPUTE in requiredSubgroupSizeStages (RADV lists FRAGMENT too), so it can't be asked for 64 or 32 on the fragment stage, and W64G_SAVE_REF saves nothing there.

But its default fragment wave is 64. ps_w64_c_lane_id drawn with no required size gives lane ids 0..63 (64 distinct) on the AMD, and 0..31 on the 5080. So a default draw on this driver is the 64-lane reference. I compared AMD-default against 5080-default for every fixture, using the script's own comparable() and partition_dependent() (what W64G_REF does):

Fixtures Stable words Partition-dependent words Expected
tier A (2), tier B (4) equal equal (ballot_atomic: same counter and slot set) ok
tier C (8) equal differ (32 to 4096 of 4096 pixels) ok

0 unexpected. The detector's tiers hold between the AMD Windows driver at 64 and NVIDIA at 32.

Possible follow-up, not done here: on a device that can't require the fragment size, w64_graphics.py could detect a default 64-lane fragment wave (as with ps_w64_c_lane_id above) and use those runs as the 64-lane reference, instead of skipping tier C.

Same machine, run_gpu_tests.py at a0acd33 on the AMD iGPU: 155/163 passed, 8 skipped, 0 failed.

@Impre-visible

Copy link
Copy Markdown

The corpus census this PR's description asked for ("Corpus coverage is not measured ... please post the tier counts from --census"), from my own 1.0.2.1 copy. Counts only, no shader names.

Setup: make_game.py shaders stage at main 4eb6155 (so the classifier as merged, plus what landed since), llvm-mc 23.1.5, 26,503 listings, 26,487 translated and valid (the 16 others are the image_gather4_l border refusals of SHADER-348, all compute). Then python -I tools/wave64_halves.py --census <work>/shaders/spirv/index.json:

stage tier A tier B tier C
ps 1,454 3 8,574
vs 465 14 700
gs 0 0 195
all wave64 VS/PS/GS (11,405) 1,919 (16.8%) 17 (0.1%) 9,469 (83.0%)
  • Tier C reasons (a shader can have several): unsafe-vote-branch 8,175; tainted-branch 6,582; cross-lane 6,111; tainted-exec 4,959; stale-scalar 3,162; mask-half 758; unsafe-execz-branch 583; first-lane 353; lane-id 277; waterfall-scalar 167; lane-count 1.
  • Tier B idioms: readfirstlane-uniform 558; lane-spill 287; waterfall 35.

So on this copy about one wave64 graphics shader in six is exact on 32-wide subgroups as translated, and tier B adds almost nothing; the bulk of tier C is wave-wide votes and branches on them.

AI-assisted run (Claude). Counts only; nothing from the game leaves this machine.

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