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

Closed
opened 2026-11-26 20:20:57 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1320
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/shader-waterfall-full-word


📝 Commits (1)

  • 2e13336 wave64_halves: a waterfall proof needs equality of the whole word (SHADER-WATERFALL-FULL-WORD)

📊 Changes

3 files changed (+36 additions, -2 deletions)

View changed files

📝 docs/design.md (+1 -0)
📝 tests/semantic/test_wave64_halves.py (+33 -0)
📝 tools/wave64_halves.py (+2 -2)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1320 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/shader-waterfall-full-word` --- ### 📝 Commits (1) - [`2e13336`](https://github.com/ubiquitarianism/leonida/commit/2e133360e64d30b6cbb268eea129cb94f4cae1fd) wave64_halves: a waterfall proof needs equality of the whole word (SHADER-WATERFALL-FULL-WORD) ### 📊 Changes **3 files changed** (+36 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) 📝 `tests/semantic/test_wave64_halves.py` (+33 -0) 📝 `tools/wave64_halves.py` (+2 -2) </details> ### 📄 Description **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](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145465860)). 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 - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: the compare the waterfall proof accepts, its regression test and its contract row. - [x] No game data, keys or decryption; the test programs are hand-written. - [x] 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:57 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1350
No description provided.