Skip to content

wave64_halves: a waterfall proof needs equality of the whole word (SHADER-WATERFALL-FULL-WORD) - #1320

Closed
Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/shader-waterfall-full-word
Closed

Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/shader-waterfall-full-word

Conversation

@Moriz82

@Moriz82 Moriz82 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased onto bfef489c at 2e133360. Main already has the classifier from #984. This diff adds the expanded whole-word comparison tests and clarifies the contract. The focused suite passed 128 tests. Earlier GPU results refer to the earlier head.

Claimed in the coordination issue as: SHADER-WATERFALL-FULL-WORD (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #1257 (open, TEST-WATERFALL-DESCRIPTOR) adds a CPU test that each lane fetches from its own descriptor-table entry in a waterfall loop; the integration's own table-execution test, its fixture and the interpreter support it needs are therefore not in this pull request, which keeps only the proof fix and its regression test. #805, #1091, #187 and #508 (open) also edit tools/wave64_halves.py; none of them changes the waterfall compare in cmp_tag (#1091 adds a method just above it).

What and why

tools/wave64_halves.py decides whether a wave64 vertex, pixel or geometry shader gives the same results when its wave is cut into two 32-lane halves, and the translator records the answer as wave64_graphics A/B/C. Tier B includes the waterfall loop: read a word from the first active lane, select the lanes that hold the same word, run the body with that scalar, retire them, repeat. The proof is that every selected lane holds the word that was read.

cmp_tag accepted any v_cmp_eq_* of the scalar against the VGPR it was read from as that proof. That is only true for an equality of the whole unmodified 32-bit word:

  • v_cmp_eq_f32 takes +0.0 and −0.0 as equal. With lanes 0..31 at +0.0 and lanes 32..63 at −0.0, the wave runs all 64 lanes with the bits of lane 0, while the second half reads −0.0 from its own first lane.
  • v_cmp_eq_u16 / _i16 and an SDWA compare of the low halves ignore the high half in the same way.

In each case the two runs differ, and the shader was still recorded as tier B, the tier the module describes as invariant by construction.

The change takes only v_cmp_eq_u32 and v_cmp_eq_i32 (and their v_cmpx forms, _e32 or _e64), with no SDWA or DPP, no modifier and no abs/neg on a source. Any other compare tags no waterfall, so the loop is tier C with the reasons cross-lane and tainted-exec. A 64-bit equality is no longer taken either; that is conservative, since it does imply the low word.

The restriction follows Marvisak/VIctory's waterfall check (GPL-3.0, commit b1c8306), which takes an unmodified u32 or i32 equality and also a 64-bit one; it is credited in the source and in the contract row.

What this does not do

  • It does not change translated code. The tier is metadata (the shader index key wave64_graphics), a warning by default and an error only with --wave64-graphics error.
  • Corpus effect is not measured: no translated corpus was used for this change. A shader whose waterfall compares another way moves from B to C; the census numbers in docs/design.md (35 waterfall idioms) were not re-run.
  • Seen while testing and not fixed here: the proof does not ask for the retire-and-repeat loop. A single selection without the loop (v_readfirstlane, v_cmp_eq_u32, s_and_saveexec_b64, a body, EXEC restored) is recorded as tier B with the idiom waterfall although the lanes outside the first lane's group are handled by a half and not by the wave (64 lanes against two waves of 32 differ). That is the same on the base commit and needs its own change.

Tested

Linux (CachyOS, kernel 7.3.5), Python 3.14, SPIRV-Tools v2026.4. Based on 6293c1c4f.

  • python3 -I tests/semantic/test_wave64_halves.py: 127 tests pass. The new test_waterfall_needs_whole_word_integer_equality runs the loop on the wave interpreter with 64 lanes and with two waves of 32, lanes 0..31 holding one word and lanes 32..63 another. For v_cmp_eq_f32 and v_cmpx_eq_f32 (words 0 / 0x80000000) and for v_cmp_eq_u16, v_cmp_eq_i16, v_cmpx_eq_u16 and v_cmp_eq_u32_sdwa with WORD_0 selects (words 0 / 0x10000) the wave writes 0 to all 64 lanes, the halves write the second word to lanes 32..63, and the tier is C. For v_cmp_eq_u32_e32, v_cmp_eq_i32_e32, v_cmp_eq_u32_e64, v_cmpx_eq_u32_e32 and v_cmpx_eq_i32_e32 on the same words both runs give each lane its own word and the tier is B. The v_cmpx loops narrow EXEC from a copy saved at the head of the loop.
  • The same file with the tools of the base commit (LEONIDA_TOOLS_DIR=<export of 6293c1c4f>/tools): 6 failing subtests, the six partial compares, each 'B' != 'C' after the two runs were seen to differ. The five integer controls pass there too.
  • python3 -I scripts/run_semantic_tests.py tests/semantic -p 'test_wave64_halves*.py' -j 1: 175 tests, OK. python3 -I -m pytest -q tests/test_wave64_halves_fixtures.py: 10 passed (the *_w64_* GPU fixtures keep their tiers; their three waterfalls compare with v_cmp_eq_u32_e32).
  • The Python CI steps (compileall; each tests/test_*.py outside tests/semantic with python3 -I <file>, or pytest where it has no __main__; python3 -I scripts/run_semantic_tests.py tests/semantic -j 2; the tracked-file guard) on the committed tree: one failing file, tests/test_imhex_patterns.py, which fails on the base commit too (the same 6 of its 9 tests). Semantic suite: 470 files, 6,169 tests, 0 files failed (base: 470 files, 6,168 tests, 0 failed).
  • python3 -I scripts/check_no_game_data.py: passes.

Not run: a GPU (runtime/test/shaders/w64_graphics.py), the corpus census, native Windows or macOS, the runtime build (no C++ or build file changes).

GPUs tested: none (wave interpreter on the CPU only).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: the compare the waterfall proof accepts, its regression test and its contract row.
  • No game data, keys or decryption; the test programs are hand-written.
  • The rule is in the contract table of docs/design.md ("Wave64 graphics: the waterfall compare"), with how it was checked and what is not measured.

🤖 Generated with Claude Code

@whoalin1

Copy link
Copy Markdown
Contributor

Independent GPU verification — verified, no regressions found (AI-assisted, verified by a Devin subagent on real hardware; no game data used).

Tested head 2ed5cede. Runtime test binaries from a origin/main (4a50cafc7) build — this PR touches only tools/ + tests; llvm-mc = WSL LLVM 21.1.8; spirv-as/spirv-val from Vulkan SDK 1.4.363.0.

Semantic suite (CPU):

  • python -I scripts/run_semantic_tests.py tests/semantic -p "test_wave64*.py" → 13 files, 266 tests, 0 failed
  • python -I scripts/run_semantic_tests.py tests/semantic (full) → 470 files, 6,169 tests, 0 failed in 521 s

AMD Radeon iGPU (gfx1035, driver 24.10.24) — VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1:

  • run_gpu_tests.py --filter w64: 26/27 PASS, 1 SKIP (ps_w64x_readlane — device cannot require a 64-wide fragment subgroup). All cs_w64*/cs_w64x_*/cs_wqm_w64*/cs_dpp_w64 and ms_w64x_ballot (4096/4096 px) pass.
  • run_gpu_tests.py --filter wave: cs_wave64_ballot PASS, cs_wavemask PASS; ms_wave_info_s3 FAIL = known pre-existing crash (cfg_structure / rdna2spirv: unwrap tautological %pc guards in structured CFGs (ms_wave_info_s3 AMD crash, SHADER-STRUCTURED-PC-UNWRAP) #808).
  • LEONIDA_W64_EMULATE=1 --filter w64: 25/27 — all cs_* PASS; ms_w64x_ballot timed out / GPU hang (killed at 300 s). The identical hang reproduces on origin/main @ 51a6074d2 with the same env → pre-existing, not a regression.
  • w64_graphics.py on all 28 ps_/vs_/gs_w64_* fixtures (built with LEONIDA_PC_TAIL_UBO=1): every tier A and B fixture ok, including ps_w64_b_waterfall, vs_w64_b_waterfall, gs_w64_a_ring; all tier C fixtures SKIP — the AMD Windows driver cannot require both 64- and 32-wide fragment subgroups (documented device limitation, not a failure).

NVIDIA RTX 4070 SUPER — VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~:

  • Native --filter w64: all 27 SKIP (subgroup 32..32, no wave64) — expected on this device.
  • LEONIDA_W64_EMULATE=1 --filter w64: 26/27 PASS, 1 SKIP; ms_w64x_ballot PASS (4096/4096 px exact).
  • w64_graphics.py (fixtures built without --pc-tail-ubo): every tier A and B fixture ok including both waterfall fixtures; tier C all SKIP (device can require only 32).

The stricter whole-word waterfall proof (v_cmp_eq_i32/u32 only, no f32/u16/sdwa/dpp/mods) classifies the new semantic fixtures correctly and no GPU fixture regressed on either GPU.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
…ADER-WATERFALL-FULL-WORD)

The tier B waterfall proof says that every lane the compare selects
holds the word v_readfirstlane read. cmp_tag took any v_cmp_eq_* of the
scalar against its VGPR as that proof. A float equality selects +0.0 and
-0.0 together, and a 16-bit or SDWA compare ignores part of the word, so
the wave runs lanes with another word under the first lane's scalar
while a 32-lane half reads its own first lane: the program is not
partition invariant, and was recorded as tier B.

Take only v_cmp_eq_u32 / v_cmp_eq_i32 (and the v_cmpx forms), without
SDWA, DPP, modifiers or abs/neg on a source. Anything else is no
waterfall and the loop is tier C. A 64-bit equality is not taken either,
which is conservative.

tests/semantic/test_wave64_halves.py runs the loop on 64 lanes and on
two waves of 32 with two words that compare equal in part: with
v_cmp_eq_f32, v_cmp_eq_u16, v_cmp_eq_i16, v_cmp_eq_u32_sdwa,
v_cmpx_eq_f32 and v_cmpx_eq_u16 the runs differ and the tier is C; with
v_cmp_eq_u32, v_cmp_eq_i32 and their v_cmpx forms they are equal and
the tier stays B. With the tools of the base commit the six partial
compares report tier B. The semantic suite and the Python CI files add
no failing file. The corpus census was not re-run and no GPU was used.

The restriction follows Marvisak/VIctory's waterfall check (GPL-3.0,
commit b1c8306), which takes an unmodified u32 or i32 equality and also
a 64-bit one.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Moriz82
Moriz82 force-pushed the split/shader-waterfall-full-word branch from 2ed5ced to 2e13336 Compare November 25, 2026 03:38
@Moriz82

Moriz82 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the independent GPU runs. #984 brought the whole-word classifier into main. I rebased onto bfef489c and kept the expanded execution coverage for float, halfword, SDWA, and integer comparisons, including the v_cmpx forms. All 128 focused CPU tests passed on 2e133360. The GPU results above are for the earlier head.

AI-assisted.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@Moriz82 Moriz82 closed this by deleting the head repository Nov 26, 2026
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