[PR #1282] [CLOSED] shader_disasm: list a wave64 program for wave64 (TOOLS-DISASM-WAVE-SIZE) #1313

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

📋 Pull Request Information

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

Base: main ← Head: split/tools-disasm-wave-size


📝 Commits (1)

  • f6290b4 shader_disasm: list a wave64 program for wave64 (TOOLS-DISASM-WAVE-SIZE)

📊 Changes

4 files changed (+140 additions, -4 deletions)

View changed files

📝 docs/design.md (+9 -0)
➕ tests/semantic/test_disasm_wave64_mask_pair.py (+81 -0)
📝 tests/test_fspx_unpack.py (+18 -2)
📝 tests/test_shader_library.py (+32 -2)

📄 Description

Rebased onto bfef489c at f6290b41. Main already sets the disassembler wave size. This diff adds coverage through FSPX unpacking, pipeline-library extraction and translation. The four focused suites passed 91 tests with one skip.

Claimed in the coordination issue as: TOOLS-DISASM-WAVE-SIZE (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #1021 (open, SHADER-W64-SDST-PAIR) repairs the same listings from the other side: widen_wave64_masks in tools/rdna2spirv.py turns a single-register mask operand into the pair once a program is known to be wave64. The integration branch had that repair too (widen_wave64_valu_masks); it is the same change as #1021 and is not in this pull request. This one makes the disassembler write the pair in the first place, which #1021 does not touch (it says the listings "come from llvm-mc without +wavefrontsize64"). The two do not conflict and either order works: with both, a new listing already has the pairs and the repair finds nothing to widen; an old listing is repaired by #1021. #998 (open) adds compute=True to the same two disasm.disasm(...) calls in fspx_unpack.py and shader_library.py and a parameter to disasm(): a textual conflict on those lines, both keywords stay. Merged three-way with each open pull request that touches these files (its diff applied to the base, then merged into this branch): #623, #908, #861, #583 and #1021 merge cleanly; #998 conflicts on those two call lines and nowhere else. #957 and #281 also change tools/shader_disasm.py, but their diffs do not apply to this base, so they were not tried.

What and why

llvm-mc lists the lane-mask operands of a VALU instruction for the wave size it is told, and wave32 is its default for the CPUs used here. For the same bytes (llvm-mc 23.1.5, gfx1013):

default with -mattr=-wavefrontsize32,+wavefrontsize64
v_cmp_gt_u32_e64 s8, 40, v0 v_cmp_gt_u32_e64 s[8:9], 40, v0
v_cndmask_b32_e64 v5, 2, 3, s10 v_cndmask_b32_e64 v5, 2, 3, s[10:11]
v_add_co_ci_u32_e64 v5, s8, v5, 4, s10 v_add_co_ci_u32_e64 v5, s[8:9], v5, 4, s[10:11]
v_cmp_gt_u32_e32 vcc_lo, 48, v0 v_cmp_gt_u32_e32 vcc, 48, v0

The same holds for the SDWA compares, v_cmp_class, the other carry instructions, v_div_scale and v_mad_[ui]64_[ui]32. Nothing else differs: same instructions, same printed encodings.

A wave64 program writes and reads both registers. The translator takes the listing at its word, so from the default listing the high register keeps its old value, and a later 64-bit scalar use of the pair (s_mov_b64 exec, s[8:9], s_and_saveexec_b64, a v_cndmask on a pair that s_mov_b64 wrote) gives lanes 32..63 the wrong bits.

shader_disasm.disasm(code, mcpu, backend, wave32) already takes the wave size, and shader_disasm.py already reads it from the FSSM header, but only the Python decoder (--backend python) used it. The llvm-mc backend, the default, ignored it. And fspx_unpack.py --disasm and shader_library.py --disasm did not pass it, although both have the program's dispatch state (wave32 in the index they write).

This pull request:

  • passes -mattr=-wavefrontsize32,+wavefrontsize64 to llvm-mc when wave32 is false; the command for a wave32 program is byte for byte what it was;
  • makes fspx_unpack.py --disasm and shader_library.py --disasm pass the wave size of the dispatch state. A graphics program of the pipeline library has no dispatch state and keeps the default, as before;
  • says so in docs/design.md, "Disassembling shaders".

What changes for a build. The FidelityFX, BVH and pipeline-library steps name shader_disasm.py among their tools and are redone. The game's own shaders are disassembled again only when disasm.done no longer matches (it records llvm-mc, not the tool), so an existing work folder keeps its listings until that step is redone; both spellings are valid input for the translator. By docs/design.md 23,841 of the 26,503 shaders are wave64, so a fresh disassembly lists those with pairs and vcc.

Not measured: the corpus. No game shader was disassembled or translated for this pull request, so there are no before and after counts of translated and spirv-val-clean shaders. What was measured is below, on hand-written programs. #1021 reports a full-corpus run of the equivalent translator-side change on its author's stack (26,503 translated before and after); that is its measurement, not one made here.

Tested

Linux (CachyOS, kernel 7.3.5), Python 3.14, LLVM llvm-mc 23.1.5. One commit on 6293c1c4f.

  • python3 -I tests/test_shader_disasm.py: 32 tests pass (30 before, 2 new). test_llvm_mc_is_told_the_fssm_wave_size runs the tool on a synthetic FSSM blob with a stand-in for llvm-mc that prints the -mattr option it was started with: the option is there under a wave64 header and absent under a wave32 one. test_real_llvm_mc_names_the_mask_pair_of_a_wave64_program uses the real llvm-mc and is skipped without one that has the AMDGPU target: a hand-encoded v_cmp_gt_u32_e64 is listed with s[8:9] under a wave64 header and with s8 under a wave32 one.
  • python3 -I tests/test_fspx_unpack.py: 35 tests pass, 1 skipped as on the base (1 new): fspx_unpack.py --disasm with the stand-in, once with a wave64 and once with a wave32 dispatch state.
  • python3 -I tests/test_shader_library.py: 22 tests pass (1 new): shader_library.py --disasm with the stand-in on a synthetic library. The wave64 compute program gets the option; the wave32 compute program and the pixel program do not.
  • python3 -I tests/semantic/test_disasm_wave64_mask_pair.py (new, 3 tests pass): a hand-written wave64 program of nine instructions, its words given in the file, goes through shader_disasm.disasm(), the translator and the test interpreter on 64 lanes. One test takes the Python decoder's listing and needs nothing else; it passes on the base too and is the control. One takes llvm-mc's listing and is skipped without llvm-mc. One checks that the wave32 listing of the same bytes is what it was.
  • The same tests with the tools of the base commit (an export of 6293c1c4f; the three tests/test_*.py files of this branch beside its tools/, and LEONIDA_TOOLS_DIR for the semantic file): 5 tests fail. The stand-in is started without the option in test_shader_disasm.py, test_fspx_unpack.py and test_shader_library.py (3), the real llvm-mc lists s8 (1), and in test_llvm_mc_listing lanes 33..39 store 7 instead of 9 and lane 52 stores 9 instead of 7: 56 of 64 lanes right, 64 of 64 with this change.
  • The CI loop as ci.yml runs it (compileall, every tests/test_*.py outside tests/semantic, the semantic suite, the tracked-file guard), on the committed tree: one failing file, tests/test_imhex_patterns.py, which fails on the base commit too and is the only one there. Semantic suite: 471 files, 6,171 tests, 0 files failed (the base: 470 files, 6,168 tests; the difference is the new file).
  • python3 -I scripts/check_no_game_data.py: passes.

A sweep that is not part of the change (llvm-mc 23.1.5, the translator of the base): 24 hand-written wave64 compute programs, one or two per affected form and three with a 64-bit scalar use of the mask, each disassembled with the default and with the wave64 option, translated natively and with --wave64-emulate (48 pairs of translations) and run on 64 lanes where the test interpreter has the instructions.

  • The 8 translatable programs whose mask is VCC give the same module from both listings (16 of 48).
  • No program is refused from one listing and taken from the other. The two v_div_scale_f32 programs are refused from both (4 of 48).
  • The 14 remaining programs name an SGPR mask and give different modules (28 of 48). In 3 of them the default listing gives wrong lanes and the wave64 listing the expected ones, native and emulated alike (6): a compare into s[8:9] followed by s_mov_b64 exec, s[8:9] (lanes 33..39 and 52 wrong, with s9 preset to 0x100001), the same with s_and_saveexec_b64, and v_cndmask_b32_e64 on a pair written by s_mov_b64 s[8:9], 0xff (lanes 32..39 wrong). 19 give the same 64 words from both listings, and 3 the test interpreter cannot run (an instruction it lacks).

Not run: the game's shader corpus and its FSPX and pipeline-library programs (see above), llvm-mc 21 (the option is the one runtime/test/shaders/*.asm already name in their ; mattr: lines), a GPU, native Windows or macOS, the runtime build (no C++ or build file changes).

GPUs tested: none (the disassembler command line, a CPU interpreter).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: the wave size reaches llvm-mc, from the three tools that know it.
  • No game data, keys or decryption; every program in the tests is hand-written.
  • No translator rule changed, so no row in the contract table; the listing convention is in docs/design.md, "Disassembling shaders".

🤖 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/1282 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/tools-disasm-wave-size` --- ### 📝 Commits (1) - [`f6290b4`](https://github.com/ubiquitarianism/leonida/commit/f6290b41ea437596f4c0d83e20d196680bd2d0c4) shader_disasm: list a wave64 program for wave64 (TOOLS-DISASM-WAVE-SIZE) ### 📊 Changes **4 files changed** (+140 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+9 -0) ➕ `tests/semantic/test_disasm_wave64_mask_pair.py` (+81 -0) 📝 `tests/test_fspx_unpack.py` (+18 -2) 📝 `tests/test_shader_library.py` (+32 -2) </details> ### 📄 Description **Rebased onto `bfef489c` at `f6290b41`.** Main already sets the disassembler wave size. This diff adds coverage through FSPX unpacking, pipeline-library extraction and translation. The four focused suites passed 91 tests with one skip. Claimed in the coordination issue as: TOOLS-DISASM-WAVE-SIZE ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144674660)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #1021 (open, SHADER-W64-SDST-PAIR) repairs the same listings from the other side: `widen_wave64_masks` in `tools/rdna2spirv.py` turns a single-register mask operand into the pair once a program is known to be wave64. The integration branch had that repair too (`widen_wave64_valu_masks`); it is the same change as #1021 and is **not** in this pull request. This one makes the disassembler write the pair in the first place, which #1021 does not touch (it says the listings "come from llvm-mc without `+wavefrontsize64`"). The two do not conflict and either order works: with both, a new listing already has the pairs and the repair finds nothing to widen; an old listing is repaired by #1021. #998 (open) adds `compute=True` to the same two `disasm.disasm(...)` calls in `fspx_unpack.py` and `shader_library.py` and a parameter to `disasm()`: a textual conflict on those lines, both keywords stay. Merged three-way with each open pull request that touches these files (its diff applied to the base, then merged into this branch): #623, #908, #861, #583 and #1021 merge cleanly; #998 conflicts on those two call lines and nowhere else. #957 and #281 also change `tools/shader_disasm.py`, but their diffs do not apply to this base, so they were not tried. ### What and why llvm-mc lists the lane-mask operands of a VALU instruction for the wave size it is told, and wave32 is its default for the CPUs used here. For the same bytes (llvm-mc 23.1.5, `gfx1013`): | default | with `-mattr=-wavefrontsize32,+wavefrontsize64` | |---|---| | `v_cmp_gt_u32_e64 s8, 40, v0` | `v_cmp_gt_u32_e64 s[8:9], 40, v0` | | `v_cndmask_b32_e64 v5, 2, 3, s10` | `v_cndmask_b32_e64 v5, 2, 3, s[10:11]` | | `v_add_co_ci_u32_e64 v5, s8, v5, 4, s10` | `v_add_co_ci_u32_e64 v5, s[8:9], v5, 4, s[10:11]` | | `v_cmp_gt_u32_e32 vcc_lo, 48, v0` | `v_cmp_gt_u32_e32 vcc, 48, v0` | The same holds for the SDWA compares, `v_cmp_class`, the other carry instructions, `v_div_scale` and `v_mad_[ui]64_[ui]32`. Nothing else differs: same instructions, same printed encodings. A wave64 program writes and reads both registers. The translator takes the listing at its word, so from the default listing the high register keeps its old value, and a later 64-bit scalar use of the pair (`s_mov_b64 exec, s[8:9]`, `s_and_saveexec_b64`, a `v_cndmask` on a pair that `s_mov_b64` wrote) gives lanes 32..63 the wrong bits. `shader_disasm.disasm(code, mcpu, backend, wave32)` already takes the wave size, and `shader_disasm.py` already reads it from the FSSM header, but only the Python decoder (`--backend python`) used it. The llvm-mc backend, the default, ignored it. And `fspx_unpack.py --disasm` and `shader_library.py --disasm` did not pass it, although both have the program's dispatch state (`wave32` in the index they write). This pull request: - passes `-mattr=-wavefrontsize32,+wavefrontsize64` to llvm-mc when `wave32` is false; the command for a wave32 program is byte for byte what it was; - makes `fspx_unpack.py --disasm` and `shader_library.py --disasm` pass the wave size of the dispatch state. A graphics program of the pipeline library has no dispatch state and keeps the default, as before; - says so in `docs/design.md`, "Disassembling shaders". **What changes for a build.** The FidelityFX, BVH and pipeline-library steps name `shader_disasm.py` among their tools and are redone. The game's own shaders are disassembled again only when `disasm.done` no longer matches (it records llvm-mc, not the tool), so an existing work folder keeps its listings until that step is redone; both spellings are valid input for the translator. By `docs/design.md` 23,841 of the 26,503 shaders are wave64, so a fresh disassembly lists those with pairs and `vcc`. **Not measured: the corpus.** No game shader was disassembled or translated for this pull request, so there are no before and after counts of translated and `spirv-val`-clean shaders. What was measured is below, on hand-written programs. #1021 reports a full-corpus run of the equivalent translator-side change on its author's stack (26,503 translated before and after); that is its measurement, not one made here. ### Tested Linux (CachyOS, kernel 7.3.5), Python 3.14, LLVM `llvm-mc` 23.1.5. One commit on `6293c1c4f`. - `python3 -I tests/test_shader_disasm.py`: 32 tests pass (30 before, 2 new). `test_llvm_mc_is_told_the_fssm_wave_size` runs the tool on a synthetic FSSM blob with a stand-in for llvm-mc that prints the `-mattr` option it was started with: the option is there under a wave64 header and absent under a wave32 one. `test_real_llvm_mc_names_the_mask_pair_of_a_wave64_program` uses the real llvm-mc and is skipped without one that has the AMDGPU target: a hand-encoded `v_cmp_gt_u32_e64` is listed with `s[8:9]` under a wave64 header and with `s8` under a wave32 one. - `python3 -I tests/test_fspx_unpack.py`: 35 tests pass, 1 skipped as on the base (1 new): `fspx_unpack.py --disasm` with the stand-in, once with a wave64 and once with a wave32 dispatch state. - `python3 -I tests/test_shader_library.py`: 22 tests pass (1 new): `shader_library.py --disasm` with the stand-in on a synthetic library. The wave64 compute program gets the option; the wave32 compute program and the pixel program do not. - `python3 -I tests/semantic/test_disasm_wave64_mask_pair.py` (new, 3 tests pass): a hand-written wave64 program of nine instructions, its words given in the file, goes through `shader_disasm.disasm()`, the translator and the test interpreter on 64 lanes. One test takes the Python decoder's listing and needs nothing else; it passes on the base too and is the control. One takes llvm-mc's listing and is skipped without llvm-mc. One checks that the wave32 listing of the same bytes is what it was. - The same tests with the tools of the base commit (an export of `6293c1c4f`; the three `tests/test_*.py` files of this branch beside its `tools/`, and `LEONIDA_TOOLS_DIR` for the semantic file): **5 tests fail**. The stand-in is started without the option in `test_shader_disasm.py`, `test_fspx_unpack.py` and `test_shader_library.py` (3), the real llvm-mc lists `s8` (1), and in `test_llvm_mc_listing` lanes 33..39 store 7 instead of 9 and lane 52 stores 9 instead of 7: 56 of 64 lanes right, 64 of 64 with this change. - The CI loop as `ci.yml` runs it (compileall, every `tests/test_*.py` outside `tests/semantic`, the semantic suite, the tracked-file guard), on the committed tree: one failing file, `tests/test_imhex_patterns.py`, which fails on the base commit too and is the only one there. Semantic suite: 471 files, 6,171 tests, 0 files failed (the base: 470 files, 6,168 tests; the difference is the new file). - `python3 -I scripts/check_no_game_data.py`: passes. A sweep that is not part of the change (`llvm-mc` 23.1.5, the translator of the base): 24 hand-written wave64 compute programs, one or two per affected form and three with a 64-bit scalar use of the mask, each disassembled with the default and with the wave64 option, translated natively and with `--wave64-emulate` (48 pairs of translations) and run on 64 lanes where the test interpreter has the instructions. - The 8 translatable programs whose mask is VCC give the **same module** from both listings (16 of 48). - No program is refused from one listing and taken from the other. The two `v_div_scale_f32` programs are refused from both (4 of 48). - The 14 remaining programs name an SGPR mask and give different modules (28 of 48). In 3 of them the default listing gives wrong lanes and the wave64 listing the expected ones, native and emulated alike (6): a compare into `s[8:9]` followed by `s_mov_b64 exec, s[8:9]` (lanes 33..39 and 52 wrong, with `s9` preset to 0x100001), the same with `s_and_saveexec_b64`, and `v_cndmask_b32_e64` on a pair written by `s_mov_b64 s[8:9], 0xff` (lanes 32..39 wrong). 19 give the same 64 words from both listings, and 3 the test interpreter cannot run (an instruction it lacks). Not run: the game's shader corpus and its FSPX and pipeline-library programs (see above), llvm-mc 21 (the option is the one `runtime/test/shaders/*.asm` already name in their `; mattr:` lines), a GPU, native Windows or macOS, the runtime build (no C++ or build file changes). GPUs tested: none (the disassembler command line, a CPU interpreter). AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named. ### Checklist - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: the wave size reaches llvm-mc, from the three tools that know it. - [x] No game data, keys or decryption; every program in the tests is hand-written. - [x] No translator rule changed, so no row in the contract table; the listing convention is in `docs/design.md`, "Disassembling shaders". 🤖 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:20:49 +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#1313
No description provided.