Skip to content

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

Closed
Andretuta wants to merge 1 commit into
mainfrom
old-pr/10058
Closed

Andretuta wants to merge 1 commit into
mainfrom
old-pr/10058

Conversation

@Andretuta

Copy link
Copy Markdown
Collaborator

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

…(AMD Windows driver crash)

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 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Collaborator

This carry-over of old upstream PR 10058 has been taken over in #930, so I'm closing this draft as #17 describes. The branch old-pr/10058 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 closed this Nov 24, 2026
YaBulochka added a commit to YaBulochka/leonida-1 that referenced this pull request Nov 25, 2026
…ax, wrxchg b64)

Six wave32 fixtures for the docs/design.md rows 321, 322 and 324, each an
eight-word dump and lane 0 alone running the atomics:

- cs_w32_lds_mskor (ProjectLeonida#321): ds_mskor_b32 and ds_mskor_rtn_b32, including DATA2
  bits outside DATA being ORed in (0x11223344, mask 0x0000FFFF, DATA2 8 ->
  0x11220008) and the rtn old word.
- cs_w32_lds_atomics_incdec / _atomics_rtn (ProjectLeonida#322): ds_inc/dec/rsub_u32 at the
  DATA-1, DATA, above-DATA, 0 and 1 boundaries, the rsub wrap, and the pre-op
  word each _rtn_ form returns.
- cs_w32_lds_minmax_f32 (ProjectLeonida#322): ds_min/max_f32 and the returning forms with a
  qNaN in either operand, -0/+0 and +inf/-inf.
- cs_w32_lds_wrxchg_b64 (ProjectLeonida#324): ds_wrxchg_rtn_b64 and ds_wrxchg2_rtn_b64, the
  old pair, vdst order at *8 offsets 1 and 2, and the words written.
- cs_w32_lds_wrxchg2st64_b64 (ProjectLeonida#324): ds_wrxchg2st64_rtn_b64 at *64 offsets 1
  and 2 (0x200/0x400) over a 2 KiB LDS, with *8 markers so a wrong unit fails.

Registered in check.py (CS_DUMPS and both wave32 lists), run_gpu_tests.py
(every table and the wave64 exclusion), and regen_fixtures.py. Pinned by
tests/semantic/test_batch5_gpu_fixtures.py, which runs the same eight words
through spirv_mini_interp.

Both runners pass on the RDNA2 iGPU (gfx1036, RADV Mesa 27.0.0-devel), 8/8
words per fixture. No translator mismatch appeared.
@aslan2142
aslan2142 deleted the old-pr/10058 branch December 1, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants