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

Closed
LewisCodesWebsites wants to merge 1 commit from upstream-pr/1093 into main
LewisCodesWebsites commented 2026-11-24 18:18:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by LewisCodesWebsites on 2026-11-24T18:18:23Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5477856001 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093). Originally posted by [LewisCodesWebsites](https://github.com/LewisCodesWebsites) on 2026-11-24T18:18:23Z. --- 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
tiguan26 commented 2026-11-24 18:25:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-24T18:25:13Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140619075 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7140619075). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-24T18:25:13Z. --- 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).
KernelSmoker commented 2026-11-24 18:40:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T18:40:31Z.

Review: APPROVED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6045211268 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093#pullrequestreview-6045211268). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T18:40:31Z. **Review:** APPROVED --- 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.
Deedlyy commented 2026-11-24 20:18:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:18:45Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143348707 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7143348707). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:18:45Z. --- **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
adrianmjim commented 2026-11-24 21:42:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-24T21:42:51Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145291717 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7145291717). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-24T21:42:51Z. --- 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`.
aslan2142 commented 2026-11-24 22:09:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T22:09:13Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145872322 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1093#issuecomment-7145872322). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T22:09:13Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1093
No description provided.