[PR #324] [CLOSED] rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash) #377

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

📋 Pull Request Information

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

Base: main ← Head: old-pr/10058


📝 Commits (1)

  • 183d63f rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash)

📊 Changes

3 files changed (+216 additions, -11 deletions)

View changed files

📝 docs/design.md (+1 -0)
➕ tests/semantic/test_sub_co_same_operand.py (+194 -0)
📝 tools/rdna2spirv.py (+21 -11)

📄 Description

Carried over from old PR 10058 by wail-arch in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10058, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
wail-arch: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117121094 (new SHADER item, no ID assigned yet)

What and why

v_sub_co_u32 / v_subrev_co_u32 (and the _ci_ forms) whose two sources are the same operand were translated to OpISubBorrow %x %x. AMD's Windows driver dies with an access violation (0xC0000005 in amdvlk64.dll) creating a native wave64 compute pipeline in which that borrow predicates the value operand of an OpGroupNonUniformShuffle.

Found with crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400: programs 1 and 181 (cs_xl64_88034340952, cs_xl64_88034341132) were harness errors, exit 3221225477, on every run. Fault offsets 0xafeb87 in 32.0.21037.1004 (25.12.1) and 0xaff2d7 in 32.0.21045.29003 (26.11.2). vk_pipeline_check crashes on the same SPIR-V, so it is pipeline creation, before any dispatch. The --wave64-emulate form never crashed.

Reduced to:

  • (a) v_subrev_co_u32_e64 v6, s[18:19], v1, v1 + ds_permute_b32 + ds_swizzle_b32 + s_bcnt0_i32_b64
  • (b) v_sub_co_u32_e64 v4, s[18:19], v1, v1 + s_and_saveexec_b64 s[22:23], s[18:19] + ds_bpermute_b32

Edits of the translated module of (b), 3 runs each:

Edit Result
unchanged crash 3/3
OpISubBorrow with literally the same id twice crash 3/3
borrow of the first subtract only crash 3/3
no OpGroupNonUniformAny crash 3/3
shuffle index is always this lane crash 3/3
borrow of two different registers (v1 - v3) ok
mask from x < x or x != x ok
OpISubBorrow %x %c0, OpISubBorrow %c0 %x, OpIAddCarry %x %x ok
literal false mask ok
shuffle value not predicated, shuffle of literal 0, no shuffle ok

The change: x - x is 0 with no borrow, so the translator now writes D = 0 - carry in and borrow out = carry in for these forms (D = 0 and no borrow without a carry in), with no OpISubBorrow. Values are unchanged; other operand pairs are translated as before. New contract row in docs/design.md: "Carry-out subtract of a register from itself". New test: tests/semantic/test_sub_co_same_operand.py.

Same driver as #4613 (wrong values from two native wave64 shuffles) and #857 (crash on emulated lds_fuzz programs), different trigger.

Tested

GPU:      AMD Radeon(TM) Graphics, Ryzen 9 9950X3D iGPU (RDNA2, gfx1036, PCI 1002:13C0), subgroup 32..64
Drivers:  AMD 25.12.1 (32.0.21037.1004) and 26.11.2 (32.0.21045.29003); RTX 5080 on NVIDIA 617.14
OS:       Windows 11 Pro 25H2, build 26200.9974
Compiler: VS 2022 Build Tools 17.14.45, MSVC 19.44.35230, Windows SDK 10.0.26100, Ninja RelWithDebInfo
Tools:    llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, SPIRV-Tools v2026.4, Python 3.12.10

On main c1f6b5bb5 (this branch's base), iGPU on 26.11.2 unless noted:

  • The two-program repro (--programs 2, same flags): harness error with the upstream translator, 2/2 match with this change.
  • The 400-program run: 399 match, 0 harness errors, 1 hypothesis-only (cs_xl64_88034341203); emulate 400/400. On 5d74c2723 before the change: 397 match, 2 harness errors, the same 1 hypothesis-only.
  • tests/semantic/test_sub_co_same_operand.py (new): 6 tests pass (wave32 and native wave64 run in spirv_mini_interp, the emulated form checked by its text); 24 failures against the unchanged translator.
  • scripts/run_semantic_tests.py tests/semantic: 460 files, 6052 tests, 4 files fail: test_exec_computed, test_image_atomics_guard, test_sopc_validation, test_unary_f16_validation. Each fails with the same count (2, 47, 1, 15) with the upstream translator, so none comes from this change.
  • scripts/run_gpu_tests.py, 248 shaders translated and valid: iGPU 227/248 passed, 17 skipped, 4 failed (cs_imgload_tfe, cs_imgload_d16_tfe, cs_w32_exec_computed, cs_w64_exec_computed); RTX 5080 195/248 passed, 49 skipped, 4 failed (the first three plus ms_wave_info_s3, #8306). The tfe and exec_computed tests fail the same way with the upstream translator on both GPUs.
  • crosslane_fuzz.py --programs 300 --seed 880317 --wave both --no-maskdata --dpp --ext on the RTX 5080 (run on 5d74c2723 with this change): 150/150 wave32 native, 150/150 wave64 emulate.

Not run: runtime/ does not build with MSVC on c1f6b5bb5 (d3d12_xs_device.cpp:1606, d3d12_vulkan_device.cpp:10001, acphal.cpp:146/167; #9812), so the D3D12 ctest targets were not run. The standalone Vulkan tools build and were rebuilt from this base. The only carry-out subtract in runtime/test/shaders is ps_ops2.asm:13, with two different operands, so no test shader contains the form this changes.

Limits:

  • No corpus count: whether a game shader has a carry-out subtract of a register from itself is unmeasured (no package here).
  • Two different registers holding equal values still reach OpISubBorrow; only the same-operand form is covered.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), 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


🔄 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/324 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `old-pr/10058` --- ### 📝 Commits (1) - [`183d63f`](https://github.com/ubiquitarianism/leonida/commit/183d63f553a4c049f0073bb54a0b0adbac5d68d0) rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash) ### 📊 Changes **3 files changed** (+216 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) ➕ `tests/semantic/test_sub_co_same_operand.py` (+194 -0) 📝 `tools/rdna2spirv.py` (+21 -11) </details> ### 📄 Description > Carried over from **old PR 10058** by `wail-arch` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10058`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `wail-arch`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117121094 (new SHADER item, no ID assigned yet) ### What and why `v_sub_co_u32` / `v_subrev_co_u32` (and the `_ci_` forms) whose two sources are the same operand were translated to `OpISubBorrow %x %x`. AMD's Windows driver dies with an access violation (`0xC0000005` in `amdvlk64.dll`) creating a native wave64 compute pipeline in which that borrow predicates the value operand of an `OpGroupNonUniformShuffle`. Found with `crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400`: programs 1 and 181 (`cs_xl64_88034340952`, `cs_xl64_88034341132`) were harness errors, exit 3221225477, on every run. Fault offsets `0xafeb87` in 32.0.21037.1004 (25.12.1) and `0xaff2d7` in 32.0.21045.29003 (26.11.2). `vk_pipeline_check` crashes on the same SPIR-V, so it is pipeline creation, before any dispatch. The `--wave64-emulate` form never crashed. Reduced to: - (a) `v_subrev_co_u32_e64 v6, s[18:19], v1, v1` + `ds_permute_b32` + `ds_swizzle_b32` + `s_bcnt0_i32_b64` - (b) `v_sub_co_u32_e64 v4, s[18:19], v1, v1` + `s_and_saveexec_b64 s[22:23], s[18:19]` + `ds_bpermute_b32` Edits of the translated module of (b), 3 runs each: | Edit | Result | |---|---| | unchanged | crash 3/3 | | `OpISubBorrow` with literally the same id twice | crash 3/3 | | borrow of the first subtract only | crash 3/3 | | no `OpGroupNonUniformAny` | crash 3/3 | | shuffle index is always this lane | crash 3/3 | | borrow of two different registers (v1 - v3) | ok | | mask from `x < x` or `x != x` | ok | | `OpISubBorrow %x %c0`, `OpISubBorrow %c0 %x`, `OpIAddCarry %x %x` | ok | | literal `false` mask | ok | | shuffle value not predicated, shuffle of literal 0, no shuffle | ok | **The change:** x - x is 0 with no borrow, so the translator now writes D = 0 - carry in and borrow out = carry in for these forms (D = 0 and no borrow without a carry in), with no `OpISubBorrow`. Values are unchanged; other operand pairs are translated as before. New contract row in `docs/design.md`: "Carry-out subtract of a register from itself". New test: `tests/semantic/test_sub_co_same_operand.py`. Same driver as `#4613` (wrong values from two native wave64 shuffles) and `#857` (crash on emulated `lds_fuzz` programs), different trigger. ### Tested ``` GPU: AMD Radeon(TM) Graphics, Ryzen 9 9950X3D iGPU (RDNA2, gfx1036, PCI 1002:13C0), subgroup 32..64 Drivers: AMD 25.12.1 (32.0.21037.1004) and 26.11.2 (32.0.21045.29003); RTX 5080 on NVIDIA 617.14 OS: Windows 11 Pro 25H2, build 26200.9974 Compiler: VS 2022 Build Tools 17.14.45, MSVC 19.44.35230, Windows SDK 10.0.26100, Ninja RelWithDebInfo Tools: llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, SPIRV-Tools v2026.4, Python 3.12.10 ``` On main `c1f6b5bb5` (this branch's base), iGPU on 26.11.2 unless noted: - The two-program repro (`--programs 2`, same flags): harness error with the upstream translator, 2/2 match with this change. - The 400-program run: 399 match, 0 harness errors, 1 hypothesis-only (`cs_xl64_88034341203`); emulate 400/400. On `5d74c2723` before the change: 397 match, 2 harness errors, the same 1 hypothesis-only. - `tests/semantic/test_sub_co_same_operand.py` (new): 6 tests pass (wave32 and native wave64 run in `spirv_mini_interp`, the emulated form checked by its text); 24 failures against the unchanged translator. - `scripts/run_semantic_tests.py tests/semantic`: 460 files, 6052 tests, 4 files fail: `test_exec_computed`, `test_image_atomics_guard`, `test_sopc_validation`, `test_unary_f16_validation`. Each fails with the same count (2, 47, 1, 15) with the upstream translator, so none comes from this change. - `scripts/run_gpu_tests.py`, 248 shaders translated and valid: iGPU 227/248 passed, 17 skipped, 4 failed (`cs_imgload_tfe`, `cs_imgload_d16_tfe`, `cs_w32_exec_computed`, `cs_w64_exec_computed`); RTX 5080 195/248 passed, 49 skipped, 4 failed (the first three plus `ms_wave_info_s3`, `#8306`). The `tfe` and `exec_computed` tests fail the same way with the upstream translator on both GPUs. - `crosslane_fuzz.py --programs 300 --seed 880317 --wave both --no-maskdata --dpp --ext` on the RTX 5080 (run on `5d74c2723` with this change): 150/150 wave32 native, 150/150 wave64 emulate. Not run: `runtime/` does not build with MSVC on `c1f6b5bb5` (`d3d12_xs_device.cpp:1606`, `d3d12_vulkan_device.cpp:10001`, `acphal.cpp:146/167`; `#9812`), so the D3D12 `ctest` targets were not run. The standalone Vulkan tools build and were rebuilt from this base. The only carry-out subtract in `runtime/test/shaders` is `ps_ops2.asm:13`, with two different operands, so no test shader contains the form this changes. Limits: - No corpus count: whether a game shader has a carry-out subtract of a register from itself is unmeasured (no package here). - Two different registers holding equal values still reach `OpISubBorrow`; only the same-operand form is covered. AI-assisted: yes (Claude Code) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:41 +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#377
No description provided.