rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash) (OLD-10058) #1093

Closed
github-bot wants to merge 1 commit from gh-pr/1093/head into gh-pr/1093/base
Owner

@⁠LewisCodesWebsites on GitHub · 2026-11-24 18:18 UTC · original
LewisCodesWebsites:carry/old-10058 → main · +216 −11 · 3 files · 1 commits · closed without merging

Claimed in the coordination issue as: OLD-10058 (#14)

Supersedes: #324 (carries forward old PR 10058 by @⁠wail-arch, rebased onto main 3aa975421; their commit and authorship are kept, the only change is resolving a docs/design.md conflict by adding the new contract row next to main's current pc-tail row)

What and why

v_sub_co_u32 / v_subrev_co_u32 (and the _ci_ forms) with the same register as both sources were translated to OpISubBorrow %x %x, and AMD's Windows driver crashes (0xC0000005 in amdvlk64.dll) creating a native wave64 pipeline in which that borrow predicates a subgroup shuffle. x - x is always 0 with no borrow, so this writes the result out directly. It is the same crash as my finding in #14.

Tested

  • python -I tools/crosslane_fuzz.py --ext --dpp --wave 64 --modes native --w64-native --no-maskdata --programs 1000 --seed 20261124: main gives 6 harness errors (exit 3221225477, all in amdvlk64.dll at the same offset); this branch gives 0 (999 match, 1 hyp_only).
  • The reduced 7-instruction reproducer from my finding in #14 crashes on main and runs with 0 mismatches on this branch.
  • tests/semantic/test_sub_co_same_operand.py: 6/6. scripts/run_semantic_tests.py tests/semantic: 6173 of 6174 pass; the one failure, test_image_cube_store_glc, fails the same way on main on this machine (FileNotFoundError launching a tool at line 282), so it is unrelated.
  • tests/test_docs_design_rows.py, tests/test_docs_table_rows.py, tests/test_docs_links.py, tests/test_text_write_line_endings.py: OK.

GPUs tested: AMD Radeon 660M (RDNA2 iGPU, gfx1035), Adrenalin 32.0.21045.1000 (Vulkan driver 2.0.353), Windows 11 26200

AI-assisted: yes (Claude and OpenCode ran the rebase and the tests; I reviewed them)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pRhqKwVhndiVZH8fawThh

**@⁠LewisCodesWebsites** on GitHub · 2026-11-24 18:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093) `LewisCodesWebsites:carry/old-10058` → `main` · +216 −11 · 3 files · 1 commits · closed without merging Claimed in the coordination issue as: OLD-10058 (#14) Supersedes: #324 (carries forward old PR 10058 by @⁠wail-arch, rebased onto `main` 3aa975421; their commit and authorship are kept, the only change is resolving a `docs/design.md` conflict by adding the new contract row next to main's current pc-tail row) ### What and why `v_sub_co_u32` / `v_subrev_co_u32` (and the `_ci_` forms) with the same register as both sources were translated to `OpISubBorrow %x %x`, and AMD's Windows driver crashes (`0xC0000005` in `amdvlk64.dll`) creating a native wave64 pipeline in which that borrow predicates a subgroup shuffle. x - x is always 0 with no borrow, so this writes the result out directly. It is the same crash as my finding in #14. ### Tested - `python -I tools/crosslane_fuzz.py --ext --dpp --wave 64 --modes native --w64-native --no-maskdata --programs 1000 --seed 20261124`: `main` gives 6 harness errors (exit 3221225477, all in `amdvlk64.dll` at the same offset); this branch gives 0 (999 match, 1 hyp_only). - The reduced 7-instruction reproducer from my finding in #14 crashes on `main` and runs with 0 mismatches on this branch. - `tests/semantic/test_sub_co_same_operand.py`: 6/6. `scripts/run_semantic_tests.py tests/semantic`: 6173 of 6174 pass; the one failure, `test_image_cube_store_glc`, fails the same way on `main` on this machine (`FileNotFoundError` launching a tool at line 282), so it is unrelated. - `tests/test_docs_design_rows.py`, `tests/test_docs_table_rows.py`, `tests/test_docs_links.py`, `tests/test_text_write_line_endings.py`: OK. GPUs tested: AMD Radeon 660M (RDNA2 iGPU, gfx1035), Adrenalin 32.0.21045.1000 (Vulkan driver 2.0.353), Windows 11 26200 AI-assisted: yes (Claude and OpenCode ran the rebase and the tests; I reviewed them) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015pRhqKwVhndiVZH8fawThh
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:37:49 +00:00
github-bot closed this pull request 2026-11-26 09:37:49 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-24 18:25 UTC · original

Checked a17d0e7 merged into current main (3aa9754): it merges cleanly. Linux, Python 3.13, no GPU, so I could not check the driver crash itself.

  • The new branch is right for the carry-in forms too: x - x - cin is 0 - cin with the borrow out equal to cin, which is what it emits (OpISub 0 cin, carry = cin).
  • tests/semantic/test_sub_co_same_operand.py 6/6; tests/test_docs_design_rows.py, test_docs_table_rows.py and test_docs_links.py pass.
  • Same register through a modifier, where the two reads are not the same value: v_sub_co_ci_u32_dpp v2, vcc, v1, v1, vcc quad_perm:[0,0,0,0] is refused (mask destination) on main and here, and v_sub_co_ci_u32_sdwa v2, vcc, v1, v1, vcc ... src0_sel:WORD_1 src1_sel:WORD_0 gives the same words on this branch as on main, so the shortcut does not change those.

That SDWA check turned up a separate bug on main, not caused by this PR: for v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 the SDWA source selects land one operand early (insn() starts them at args[1], which is the carry-out vcc for these ops), so src0_sel is dropped and src1_sel narrows src0. I'll post it in #14 separately. Once that is fixed, srcs[0] == srcs[1] stays safe, since two reads with different selects carry different sdwa_sel and compare unequal.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-24 18:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7140619075) Checked a17d0e7 merged into current `main` (3aa9754): it merges cleanly. Linux, Python 3.13, no GPU, so I could not check the driver crash itself. - The new branch is right for the carry-in forms too: `x - x - cin` is `0 - cin` with the borrow out equal to `cin`, which is what it emits (`OpISub 0 cin`, carry = `cin`). - `tests/semantic/test_sub_co_same_operand.py` 6/6; `tests/test_docs_design_rows.py`, `test_docs_table_rows.py` and `test_docs_links.py` pass. - Same register through a modifier, where the two reads are not the same value: `v_sub_co_ci_u32_dpp v2, vcc, v1, v1, vcc quad_perm:[0,0,0,0]` is refused (`mask destination`) on main and here, and `v_sub_co_ci_u32_sdwa v2, vcc, v1, v1, vcc ... src0_sel:WORD_1 src1_sel:WORD_0` gives the same words on this branch as on main, so the shortcut does not change those. That SDWA check turned up a separate bug on main, not caused by this PR: for `v_add_co_ci_u32`, `v_sub_co_ci_u32` and `v_subrev_co_ci_u32` the SDWA source selects land one operand early (`insn()` starts them at `args[1]`, which is the carry-out `vcc` for these ops), so `src0_sel` is dropped and `src1_sel` narrows src0. I'll post it in #14 separately. Once that is fixed, `srcs[0] == srcs[1]` stays safe, since two reads with different selects carry different `sdwa_sel` and compare unequal. AI-assisted (Claude).
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 18:40 UTC · original · approved these changes

Reviewed exact head a17d0e70ac. The focused semantic suite passed 6/6; generated same-operand wave32 SPIR-V passed spirv-as and spirv-val for Vulkan 1.2. I also built this PR's vk_compute_test target and ran the synthetic wave32 shader on an NVIDIA GeForce RTX 3090 (subgroup 32). All 32 dispatched lanes / 96 output words matched the fixture: active-lane D values, carry-in borrow bits, and wave mask popcount 2. This validates the translated shader behavior on NVIDIA; it does not reproduce or validate the reported AMD Windows driver crash. PR is GitHub-mergeable at review time.

**@⁠KernelSmoker** on GitHub · 2026-11-24 18:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093#pullrequestreview-6045211268) · **approved these changes** Reviewed exact head a17d0e70acde838ec099d0240f9d8f454473665f. The focused semantic suite passed 6/6; generated same-operand wave32 SPIR-V passed spirv-as and spirv-val for Vulkan 1.2. I also built this PR's vk_compute_test target and ran the synthetic wave32 shader on an NVIDIA GeForce RTX 3090 (subgroup 32). All 32 dispatched lanes / 96 output words matched the fixture: active-lane D values, carry-in borrow bits, and wave mask popcount 2. This validates the translated shader behavior on NVIDIA; it does not reproduce or validate the reported AMD Windows driver crash. PR is GitHub-mergeable at review time.
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:18 UTC · original

Recommendation: [MERGE]

Reasoning: Fixes the AMD Windows driver crash by emitting x - x (and the carry-in forms) as a constant zero/borrow instead of OpISubBorrow %x %x, carrying #324 with authorship kept. Small translator change with a 194-line semantic test; independently checked by tiguan26 (merge into main, semantic logic) and KernelSmoker (spirv-val plus RTX 3090 readback). The AMD crash itself has not been reproduced by a second person. #324 can be closed once this lands. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 5/10

**@⁠Deedlyy** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7143348707) **Recommendation:** [MERGE] **Reasoning:** Fixes the AMD Windows driver crash by emitting `x - x` (and the carry-in forms) as a constant zero/borrow instead of `OpISubBorrow %x %x`, carrying #324 with authorship kept. Small translator change with a 194-line semantic test; independently checked by tiguan26 (merge into main, semantic logic) and KernelSmoker (spirv-val plus RTX 3090 readback). The AMD crash itself has not been reproduced by a second person. #324 can be closed once this lands. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. Merge once the queued checks are green. **Impact level:** 5/10
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-24 21:42 UTC · original

Tested a17d0e70a applied onto main 66d4f5aa3 on an AMD Radeon RX 7900 XT. This is a discrete RDNA3 card on the current proprietary driver, a different one from the gfx1035/gfx1036 iGPUs where the crash was measured. Setup: AMD Radeon RX 7900 XT (RDNA3, gfx1100), AMD proprietary driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5. No game files.

The PR's repro on the GPU. tools/crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400, with vk_compute_test from a main build and --translator pointing at each tree:

wave64 native wave64 emulate
main 66d4f5aa3 400 match, 0 mismatch, 0 harness errors 400 match, 0 mismatch, 0 harness errors
this PR 400 match, 0 mismatch, 0 harness errors 400 match, 0 mismatch, 0 harness errors

The amdvlk64.dll crash does not reproduce here: main already runs programs 1 and 181 of this seed without a harness error. So on this card and driver the change makes no visible difference, and it causes no regression.

CPU check. tests/semantic/test_sub_co_same_operand.py passes 6/6 on the PR. Copied onto main, it fails only its 24 assertNotIn('OpISubBorrow', ...) subtests, and every value check passes. So the new lowering gives the same results as the old OpISubBorrow chain, as expected for x - x.

**@⁠adrianmjim** on GitHub · 2026-11-24 21:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7145291717) Tested a17d0e70a applied onto main 66d4f5aa3 on an AMD Radeon RX 7900 XT. This is a discrete RDNA3 card on the current proprietary driver, a different one from the gfx1035/gfx1036 iGPUs where the crash was measured. Setup: AMD Radeon RX 7900 XT (RDNA3, gfx1100), AMD proprietary driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5. No game files. **The PR's repro on the GPU.** `tools/crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400`, with `vk_compute_test` from a `main` build and `--translator` pointing at each tree: | | wave64 native | wave64 emulate | |---|---|---| | main `66d4f5aa3` | 400 match, 0 mismatch, **0 harness errors** | 400 match, 0 mismatch, 0 harness errors | | this PR | 400 match, 0 mismatch, 0 harness errors | 400 match, 0 mismatch, 0 harness errors | The `amdvlk64.dll` crash does not reproduce here: `main` already runs programs 1 and 181 of this seed without a harness error. So on this card and driver the change makes no visible difference, and it causes no regression. **CPU check.** `tests/semantic/test_sub_co_same_operand.py` passes 6/6 on the PR. Copied onto `main`, it fails only its 24 `assertNotIn('OpISubBorrow', ...)` subtests, and every value check passes. So the new lowering gives the same results as the old `OpISubBorrow` chain, as expected for `x - x`.
Author
Owner

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

Thanks for carrying this forward. I'm closing this as a duplicate of #930.

  • Merged onto main, this PR, #930 and #739 are the same patch (git patch-id --stable matches) and give the same tree.
  • #930 was claimed as SHADER-SUB-CO-SAME at 15:02 UTC and opened at 15:17 UTC. The OLD-10058 claim for this PR came at 17:42 UTC, when #930 was already open for the same draft (#324).
  • If you see something here that #930 lacks, please say so on #930.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 22:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7145872322) Thanks for carrying this forward. I'm closing this as a duplicate of #930. - Merged onto `main`, this PR, #930 and #739 are the same patch (`git patch-id --stable` matches) and give the same tree. - #930 was claimed as `SHADER-SUB-CO-SAME` at 15:02 UTC and opened at 15:17 UTC. The `OLD-10058` claim for this PR came at 17:42 UTC, when #930 was already open for the same draft (#324). - If you see something here that #930 lacks, please say so on #930. AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.