Skip to content

rdna2spirv: a wave64 VALU mask operand printed as one SGPR is the pair (SHADER-W64-SDST-PAIR) - #1021

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
DadaCap:w64-sdst-pair
Nov 24, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
DadaCap:w64-sdst-pair

Conversation

@DadaCap

@DadaCap DadaCap commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Claim: SHADER-W64-SDST-PAIR (#14 (comment)).

The shader listings come from llvm-mc without +wavefrontsize64, so a VALU instruction's lane-mask SGPR is printed as one register: v_cmp_gt_u32_e64 s8, ... for the s[8:9] a wave64 writes, v_cndmask_b32_e64 ..., s10 for the s[10:11] it reads. The translator wrote s8 alone. A scalar 64-bit instruction prints the pair, and mask_src gives lanes 32..63 the high register's bit (since 804f4ae), so after s_mov_b64 exec, s[8:9] those lanes had whatever s9 held before. The semantic tests print the pair, so none of them saw it.

widen_wave64_masks makes the operand the pair once a program is known to be wave64: v_cmp_* with an SDST, the carry out and in of v_*_co_*, v_div_scale, v_mad_[ui]64_[ui]32 and the mask of v_cndmask.

How it was found: a 128-thread pipeline-library compute shader (lib_cs_03141) hung an RTX 5080 (device lost) while the retail title's loading screen runs. The translated shader also loops for ever in test_wave64_emulate_opt.run_emulated_workgroup with the title's own constants; with this it ends after 76 barriers, and the title gets past it.

Tested

  • tests/semantic/test_wave64_single_sdst.py (new): both printed forms translate to the same module, natively and emulated, and all 64 lanes are run. On main: 2 failures, 1 error.
  • scripts/run_semantic_tests.py tests/semantic: 470 files, 6,165 tests; the one file that fails, test_image_cube_store_glc, cannot start llvm-mc on this machine (FileNotFoundError).
  • Corpus, with --wave64-emulate, on my boot stack (main plus other open pull requests): 26,503 translated before and after, the 2,671 pipeline-library programs too, none lost. I did not run spirv-val over the new modules separately; the translator's own assembly step accepted them all.
  • RTX 5080, driver 621.24, Windows 11. No game data.

The modules have to be translated again (make_game.py --stages shaders).

AI-assisted (Claude Code, Opus 5.5).

🤖 Generated with Claude Code

…r (SHADER-W64-SDST-PAIR)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quartz-heron-58

Copy link
Copy Markdown
Contributor

Retail check on a second NVIDIA card, with the fence loss made visible by #1028 (which builds on #980).

Setup: boot-prototype at 9173e790 plus #980 and #1028 cherry-picked; RTX 4080, driver 621.24, Windows 11 26300, MSVC; own 1.0.2.1 copy; LEONIDA_LAZY_PSO=1, LEONIDA_GPU_REGION_MB=10240, LEONIDA_AUTOPRESS=1, the OBS capture layer disabled, no LEONIDA_SKIP_INT3. Shaders: the whole stage translated again (main corpus, pipeline library, FSPX, BVH, executable) with this pull request's commit bc7143b5 merged with #674, #593 and #957. One conflict, with #674: widen_wave64_masks and restore_vcc_tuples are added at the same place in tools/rdna2spirv.py; I kept both. test_wave64_single_sdst.py, test_vcc_tuple_fallback.py and test_dpp_compare.py pass in that tree. 26,503 of 26,503 corpus shaders and 2,623 of 2,684 library programs translate and pass spirv-val, the same counts as without this commit.

shaders without this PR shaders with it
runs 5 on this tree while #1028 was being written, the fault report printed in 2 of them 1
stop the title's fatal exit at 74 to 79 s the same exit at 89.5 s
loss seen as a fence counter of UINT64_MAX, then vkDeviceWaitIdle returning VK_ERROR_DEVICE_LOST the same
VK_EXT_device_fault report 3 and 2 address faults in those 2 runs, all INSTRUCTION_POINTER_UNKNOWN, addresses 0x2000af410 to 0x2000af700 INSTRUCTION_POINTER_FAULT at 0x2000ceee0, and one entry of type NONE with address 0xb700000000, precision 0x1000
nvlddmkm event 153 at the stop 2 or 3 6

So on this card the device is still lost during the load, but not the same way: the report changes from the hang shape to a fault with an address, about 12 s later. That fits the endless dispatch being gone and a second problem behind it. One run with the fix, so it shows the change, not a rate.

Lines that are in the log of the run with the fix and in none of the 12 earlier runs on this machine, all just before the loss: first calls of list slots 85, 51, 129, 61, 39, 86 and 26 and device slot 71; unimplemented ID3D12Device8::CreateSamplerFeedbackUnorderedAccessView; ExecuteIndirect with a DISPATCH_MESH signature is not replayed yet; nothing was recorded; RehydrateRaytracingAccelerationStructureBatched2X is not implemented yet; E_NOTIMPL; WriteToSubresource/ReadFromSubresource staging copy failed; replay result 10. I have not established which of them, if any, leads to the fault.

Not checked: whether lib_cs_03141 is dispatched in my run (I do not log dispatches), and the semantic suite beyond the three files above. On your note that VK_EXT_device_fault reported nothing for the hang: here it answers only after vkDeviceWaitIdle has returned VK_ERROR_DEVICE_LOST; before that the count query returns VK_ERROR_UNKNOWN (details in #1028).

Counts and driver addresses only, no game data. AI-assisted.

@fin-github fin-github left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • tests/semantic/test_wave64_single_sdst.py on the PR: 3 tests OK. The same file against main (3295055):
    2 failures and 1 error, so it catches the bug.
  • unittest discover -s tests/semantic -p "test_wave64*.py": 268 tests OK.

Question: the e64 forms can also print vcc_lo as the SDST (v_cmp_gt_u32_e64 vcc_lo, ...,
v_cndmask_b32_e64 ..., vcc_lo). widen_wave64_masks leaves special operands alone, which
test_wave32_keeps_single_registers asserts for the e32 case. I see the existing vcc_lo handling
(vcc_half_keeps_mask, rdna2spirv.py:1629, and the mask-destination path near 6058). Does that already give the
e64 vcc_lo SDST the full VCC in wave64? If so, a single line in the docstring or the design.md row would save the
next reader from asking the same thing.

Nit: in elif op.startswith("v_") and "_co_" in op or op in (...), and binds tighter than or, which is what
you want here. Parentheses would make that clear at a glance.

Tested on Windows 11 Pro 26200, CPython 3.14.4, MSVC from VS 18 Community, applied on main 3295055. No GPU or game files used. AI-assisted (Claude Code).

@DadaCap

DadaCap commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@quartz-heron-58 thank you, this is a very useful check, and the vkDeviceWaitIdle tip works here too: with it, my report gives an address where the fault query answered nothing before.

Two of your new lines are explained:

After both, the remaining fault on my RTX 5080 was a read in a 24 GiB GPU window (protection 0x801) outside the region. Covering it with a sparse buffer gave one run with no device loss; that run still ended later in an access violation I have not looked into.

On the conflict with #674: keeping both functions is right.

AI-assisted.

@milk4sale

Copy link
Copy Markdown
Contributor

Tested on another setup, with counts over the whole corpus (1.0.2.1, all 26,503 listings, llvm-mc backend), this head bc7143b5f alone:

  • The premise holds on every listing. In the wave64 shaders all 292,733 compares into a one-register SGPR name an even register, and so do all 6,988 carry-outs; wave32 code names an odd one in 137,832 of 299,058 compares. No listing names a pair. LLVM 23.1.4 assembles v_cmp_gt_u32_e64 s4, 40, v1 (default) and ... s[4:5], ... (+wavefrontsize64) to the same eight bytes.
  • Reach. On main, 13,314 wave64 shaders (7,120 PS, 4,918 MS, 664 CS, 612 VS) read such a pair back with a 64-bit scalar op while the mask analysis knew nothing of the high register: 162,431 reads, mostly s_and_b64 (86,137), s_or_b64 (50,843) and s_and_saveexec_b64 (15,399).
  • Full translation, no --wave64-emulate: 26,503 translated, 26,503 pass spirv-val. 19,453 modules differ from main 1504c1af6, all wave64 (MS 9,282 of 9,282, PS 8,021 of 10,974, VS 1,169 of 2,236, CS 786 of 1,154, GS 195 of 195); none of the 2,662 wave32 modules changes.
  • A side effect worth having: SHADER-10 tiers (wave64 VS/PS/GS on 32-wide subgroups, wave64_halves.py --census). The halves analysis took the pair for "a lane mask combined with a register that is not one". With this change 504 shaders leave tier C and none enters it: A 5,059 -> 5,267, B 101 -> 397, C 8,245 -> 7,741; tainted-branch 6,534 -> 1,181.
  • GPU. A compute fixture in the one-register form (six compares and a carry-out, read back by s_and_b64, s_or_b64, s_xor_b64, s_andn2_b64, s_and_saveexec_b64, s_mov_b64 exec, s_bcnt1/s_ff1 and SCC, with another mask, 0 or nothing in the high register beforehand): RTX 4070 Ti, Linux, driver 620.70.06, subgroup 32, LEONIDA_W64_EMULATE=1. main stores none of its eight ISA-derived words, this branch all eight. It is tests: a GPU fixture and whole-corpus counts for one-register wave64 mask destinations (TEST-W64-SDST-PAIR-GPU) #1090, stacked on this one (TEST-W64-SDST-PAIR-GPU).
  • scripts/run_semantic_tests.py tests/semantic on this head plus that fixture: 472 files, 6,176 tests, 0 files failed.
  • wave64_halves: a vote on a scalar compare under whole-quad EXEC is no lane vote (SHADER-W64-WQM-UVOTE) #1091 (SHADER-W64-WQM-UVOTE) also builds on this: with the pair in place, a uniform vote under s_wqm_b64 exec, exec becomes visible to the halves analysis, and 452 more pixel shaders leave tier C.

Not checked: a 64-wide device (--require-wave64), and the retail title. Counts and opcode names only, no game data. AI-assisted (Claude Code).

@thesubtleties

Copy link
Copy Markdown
Contributor

Tested bc7143b5f (#1021) and 9f1a072f7 (#1090), each merged onto main 3aa97542. NVIDIA RTX 3080 (620.73.04) and AMD Raphael RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS.

This runs translated SPIR-V, not native RDNA2 code. Not tested: game corpus. AI-assisted (Claude Code)

@aslan2142

Copy link
Copy Markdown
Collaborator

Merged. Thanks, and thanks to everyone who tested it. Checked locally on main 0f98d193c + bc7143b5f:

  • Claim: valid. SHADER-W64-SDST-PAIR was posted at 16:38 UTC, before this PR, and is unedited.
  • tests/semantic/test_wave64_single_sdst.py: against main's translator it gives 2 failures and 1 error; with this PR all 3 tests pass.
  • Semantic suite on the merge: 474 files, 6,194 tests, 0 files failed. The 12 test_docs_* files, test_text_write_line_endings and check_no_game_data.py on the three changed files are clean.
  • Counts over the corpus (1.0.2.1, 26,503 listings): 19,453 of the 23,841 wave64 shaders print a VALU mask operand as one SGPR; none uses an odd register, none is already printed as a pair, none is at s105 or above. A slice of 832 shaders translates and passes spirv-val 832 of 832 before and after.
  • CI did not run on this PR (the workflows were waiting for approval), so the merge rests on the runs above and on the reports here from milk4sale, thesubtleties and quartz-heron-58.

On fin-github's question: yes, an e64 vcc_lo mask already means the full VCC in wave64: mask_dst stores vcc_lo to the whole %vcc and mask_src loads %vcc for it. A line saying so in the docstring would help the next reader.

Two small things for a follow-up, neither blocking:

#1090 and #1091 are stacked on this one and can move now.

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

milk4sale added a commit to milk4sale/leonida that referenced this pull request Nov 24, 2026
main now holds ProjectLeonida#1021 (SHADER-W64-SDST-PAIR), which this branch was stacked on. No conflict by hand: the
TEST-W64-SDST-PAIR-GPU row stays right under ProjectLeonida#1021's row in docs/design.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Kokonotcu added a commit to Kokonotcu/leonida that referenced this pull request Nov 25, 2026
…r (upstream ProjectLeonida#1021)

Adopted from upstream PR ProjectLeonida#1021 (SHADER-W64-SDST-PAIR, DadaCap): beyond the v_cmp destination 6822488 widened,
carry-in/out operands, the v_cndmask_b32_e64 selector and the v_mad_*64 / v_div_scale SDSTs of a wave64 program are
pairs too when llvm-mc listed them in its 32-lane form. CS_Prop_BatchCull (library 1405) still looped on the GPU with
only the compares widened; its module changes with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants