rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash) (SHADER-SUB-CO-SAME) #930

Manually merged
github merged 1 commit from gh-pr/930/head into gh-pr/930/base 2026-11-26 09:28:52 +00:00
Owner

@⁠fin-github on GitHub · 2026-11-24 15:17 UTC · original
fin-github:shader/sub-co-same-operand → main · +216 −11 · 3 files · 1 commits · merged 2026-11-24 22:12 UTC

Claimed in the coordination issue as: SHADER-SUB-CO-SAME (#14)

Supersedes draft #324, carried over from the original repository. This is the same commit rebased onto current main, with the original author (Wail) kept and git cherry-pick -x recording where it came from. The change and its explanation are theirs; see #324 for the original description.

Rebase note: one conflict in docs/design.md, where main had rewritten the neighbouring push-constant row. I kept main's row and inserted the new carry-out row before it.

Tested

  • tests/semantic/test_sub_co_same_operand.py: 6 tests pass.
  • Full translator suite python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6114 tests, 0 failed.
  • Not yet confirmed on hardware. The crash repro (crosslane_fuzz.py --seed 880317 --wave 64 --w64-native on AMD's proprietary Windows driver 25.30, Ryzen 5 7600X iGPU, gfx1036) needs llvm-mc with the AMDGPU target, which isn't installed on this machine yet. I'll post the before/after result here.
  • python -I scripts/check_no_game_data.py on the changed files: clean.

Windows 11 (10.0.26200), Python 3.14.4. No game files, nothing online.

AI-assisted (Claude Code): rebasing, conflict resolution and test runs.

**@⁠fin-github** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/930) `fin-github:shader/sub-co-same-operand` → `main` · +216 −11 · 3 files · 1 commits · merged 2026-11-24 22:12 UTC Claimed in the coordination issue as: `SHADER-SUB-CO-SAME` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Supersedes draft #324, carried over from the original repository. This is the same commit rebased onto current `main`, with the original author (Wail) kept and `git cherry-pick -x` recording where it came from. The change and its explanation are theirs; see #324 for the original description. Rebase note: one conflict in `docs/design.md`, where `main` had rewritten the neighbouring push-constant row. I kept `main`'s row and inserted the new carry-out row before it. ### Tested - `tests/semantic/test_sub_co_same_operand.py`: 6 tests pass. - Full translator suite `python -I scripts/run_semantic_tests.py tests/semantic`: 466 files, 6114 tests, 0 failed. - **Not yet confirmed on hardware.** The crash repro (`crosslane_fuzz.py --seed 880317 --wave 64 --w64-native` on AMD's proprietary Windows driver 25.30, Ryzen 5 7600X iGPU, gfx1036) needs llvm-mc with the AMDGPU target, which isn't installed on this machine yet. I'll post the before/after result here. - `python -I scripts/check_no_game_data.py` on the changed files: clean. Windows 11 (10.0.26200), Python 3.14.4. No game files, nothing online. AI-assisted (Claude Code): rebasing, conflict resolution and test runs.
v_sub_co_u32 / v_subrev_co_u32 and their _ci_ forms with the same operand
twice were translated to OpISubBorrow %x %x. AMD's Windows driver dies with
an access violation (0xC0000005 in amdvlk64.dll, 32.0.21037.1004 and
32.0.21045.29003, gfx1036) creating a native wave64 compute pipeline in which
that borrow predicates the value operand of an OpGroupNonUniformShuffle.

x - x is 0 with no borrow, so these forms now emit D = 0 - carry in and
borrow out = carry in, with no OpISubBorrow. Values are unchanged; other
operand pairs are translated as before.

Found with crosslane_fuzz.py --seed 880317 --wave 64 --w64-native
--no-maskdata --dpp --ext --programs 400 on a Ryzen 9 9950X3D iGPU:
programs 1 and 181 were harness errors (exit 3221225477) and now match
(399 of 400 match; the other differs only in a hypothesis op, as before).

- docs/design.md: contract row "Carry-out subtract of a register from itself"
- tests/semantic/test_sub_co_same_operand.py: values and borrow mask in
  wave32 and native wave64, the emitted form with --wave64-emulate

Not counted over the corpus, and two different registers holding equal
values still reach OpISubBorrow.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:28:51 +00:00
github manually merged commit 474dbe2bed into gh-pr/930/base 2026-11-26 09:28:52 +00:00
github-bot referenced this pull request from a commit 2026-11-26 09:33:30 +00:00
github-bot referenced this pull request from a commit 2026-11-26 09:34:32 +00:00
github-bot referenced this pull request from a commit 2026-11-26 09:38:54 +00:00
Author
Owner

@⁠SweatierKey on GitHub · 2026-11-24 15:35 UTC · original · approved these changes

Independent verification on origin/main@a28927849:

  • tests/semantic/test_sub_co_same_operand.py (LEONIDA_REQUIRE_SPIRV_TOOLS=1): 6/6 PASS (wave32, native wave64, --wave64-emulate; with and without clamp; verifies no OpISubBorrow is emitted for same-register operands and distinct equal-value registers still use OpISubBorrow).
  • tests/semantic/test_carry_exec_mask.py (LEONIDA_REQUIRE_SPIRV_TOOLS=1): 9/9 PASS.
  • spirv-as --target-env vulkan1.3 + spirv-val --target-env vulkan1.3: 24/24 PASS across all 4 ops (v_sub_co_u32, v_subrev_co_u32, v_sub_co_ci_u32, v_subrev_co_ci_u32) × {clamp=False, True} × {wave32, wave64-native, wave64-emulate}.
  • tests/test_docs_links.py: 16/16 PASS; scripts/check_no_game_data.py: clean.

Clean workaround for the amdvlk64.dll pipeline-creation AV while preserving exact borrow/clamp/EXEC semantics.

AI-assisted: yes

**@⁠SweatierKey** on GitHub · 2026-11-24 15:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/930#pullrequestreview-6042344943) · **approved these changes** Independent verification on `origin/main@a28927849`: - `tests/semantic/test_sub_co_same_operand.py` (`LEONIDA_REQUIRE_SPIRV_TOOLS=1`): `6/6` PASS (wave32, native wave64, `--wave64-emulate`; with and without `clamp`; verifies no `OpISubBorrow` is emitted for same-register operands and distinct equal-value registers still use `OpISubBorrow`). - `tests/semantic/test_carry_exec_mask.py` (`LEONIDA_REQUIRE_SPIRV_TOOLS=1`): `9/9` PASS. - `spirv-as --target-env vulkan1.3` + `spirv-val --target-env vulkan1.3`: `24/24` PASS across all 4 ops (`v_sub_co_u32`, `v_subrev_co_u32`, `v_sub_co_ci_u32`, `v_subrev_co_ci_u32`) × `{clamp=False, True}` × `{wave32, wave64-native, wave64-emulate}`. - `tests/test_docs_links.py`: `16/16` PASS; `scripts/check_no_game_data.py`: clean. Clean workaround for the `amdvlk64.dll` pipeline-creation AV while preserving exact borrow/clamp/EXEC semantics. AI-assisted: yes
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 22:12 UTC · original

Merged. Checked locally on main 4a50cafc7 + 474dbe2be:

  • Claim: valid. SHADER-SUB-CO-SAME was posted at 15:02 UTC, before this PR, and is unedited. #739 and #1093 carried the same patch and were closed as duplicates of this one.
  • The change is value-preserving: for x - x the difference is 0 with no borrow, so D = 0 - carry in and the borrow out is the carry in. That is what the general path computes, written without OpISubBorrow %x %x.
  • tests/semantic/test_sub_co_same_operand.py: against main's translator it fails (6 tests, 24 failures); with this PR it passes (6 tests).
  • Semantic suite on the merge: 472 files, 6,183 tests, 0 files failed.
  • Also clean: the 12 test_docs_* files and check_no_game_data.py on the three changed files. The contract row is in docs/design.md.
  • Others' runs of the same patch (posted on #739): macOS on an Apple M5 Pro, Windows on gfx1036 with driver 32.0.21045.29003 and on an RX 9070, and the full GPU suite on an RTX 3080 Ti, all passing.

One open point, moved here from #739: snain0511's minimal repro does not crash the driver on the base translator either, so the exact shape that crashes amdvlk64.dll is still not reproduced. If you have it, a note here would help.

AI-assisted (Claude Code, Claude Fable 5.2).

**@⁠aslan2142** on GitHub · 2026-11-24 22:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/930#issuecomment-7145931863) Merged. Checked locally on `main` `4a50cafc7` + `474dbe2be`: - **Claim:** valid. `SHADER-SUB-CO-SAME` was posted at 15:02 UTC, before this PR, and is unedited. #739 and #1093 carried the same patch and were closed as duplicates of this one. - **The change is value-preserving:** for `x - x` the difference is 0 with no borrow, so D = 0 - carry in and the borrow out is the carry in. That is what the general path computes, written without `OpISubBorrow %x %x`. - **`tests/semantic/test_sub_co_same_operand.py`:** against `main`'s translator it fails (6 tests, 24 failures); with this PR it passes (6 tests). - **Semantic suite on the merge:** 472 files, 6,183 tests, 0 files failed. - **Also clean:** the 12 `test_docs_*` files and `check_no_game_data.py` on the three changed files. The contract row is in `docs/design.md`. - **Others' runs of the same patch** (posted on #739): macOS on an Apple M5 Pro, Windows on gfx1036 with driver 32.0.21045.29003 and on an RX 9070, and the full GPU suite on an RTX 3080 Ti, all passing. One open point, moved here from #739: snain0511's minimal repro does not crash the driver on the base translator either, so the exact shape that crashes `amdvlk64.dll` is still not reproduced. If you have it, a note here would help. AI-assisted (Claude Code, Claude Fable 5.2).
This discussion has been locked. Commenting is limited to contributors.
No description provided.