Skip to content

tools: decode the pipeline-library compute programs llvm-mc refuses - #998

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
Kokonotcu:fix/library-compute-decode
Nov 26, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
Kokonotcu:fix/library-compute-decode

Conversation

@Kokonotcu

@Kokonotcu Kokonotcu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

llvm-mc 21 cannot decode SMEM loads whose SOFFSET is null (0x7D). Because of that, whole pipeline-library compute programs of 1.0.2.1 disassembled with invalid words and failed to translate. A retail boot also reached 50 more library programs that had no translation; dumped from the running game, all 50 now translate and pass spirv-val.

Changes

  • shader_disasm: for compute programs (compute=True, passed by shader_library and fspx_unpack), it falls back to rdna2_decode.disasm_bytes when that leaves fewer invalid words than llvm-mc.
  • rdna2_decode: VOPC with DPP16/DPP8 is decoded as the 8-byte form it is.
  • fspx_unpack.code_range:
    • some programs carry a 24-byte hash prologue (two VOP3 words, then s_inst_prefetch) instead of 36 bytes; two or three hash words now count (shader_library uses the same range);
    • --last-endpgm: early exits branch past the first s_endpgm, and data after the code can hold s_endpgm words, so a program ends at the first s_endpgm whose listing keeps every branch inside the code.
  • rdna2spirv:
    • SMEM with vcc as its base reads the vcc_lo/vcc_hi pair.
    • s_flbit_i32_b64 of a lane mask reads the wave's 64-bit mask (18 library programs), as s_ff1_i32_b64 already does.
    • s_bitreplicate_b64_b32 of a lane mask into plain scalar data replicates the wave's mask word (6 library programs). From a constant into vcc it sets each lane's bit as the exec form does (6 programs).
    • v_cmp_*_dpp into vcc (12 compares in reductions) is taken when every lane writes (full row/bank masks with bound_ctrl:1, or DPP8).
  • Tests:
    • test_salu_flbit_64: the lane-mask case now translates; the subgroup op is outside the single-invocation interpreter, so the test checks that.
    • test_fspx_unpack: the invalid-word case takes the decoder's listing; new cases cover the two-word prologue, code_range_last and branch checks.
    • test_salu_quadmask_bitreplicate: new case for bitreplicate into vcc.

Result

Library programs: 2633 of 2684 translated after the first commit; the 50 the retail boot then dumped as missing all translate after the second.

Testing

These pass:

  • tests/semantic/test_salu_flbit_64.py
  • tests/semantic/test_salu_quadmask_bitreplicate.py
  • tests/test_fspx_unpack.py
  • tests/test_shader_library.py
  • tests/test_rdna2_decode.py
  • tests/test_shader_disasm.py
  • tests/test_rdna2spirv_decode.py

The VOPC-DPP path is checked only by spirv-val, since the interpreter runs no subgroup ops. Tested on an RTX 3080 Laptop, i7-11800H, Windows 10.

🤖 Generated with Claude Code

Kokonotcu and others added 3 commits November 24, 2026 08:42
llvm-mc 21 cannot decode SMEM loads whose SOFFSET is null (0x7D), so whole
pipeline-library compute programs of 1.0.2.1 came out with invalid words
and failed to translate. For compute programs, shader_disasm now falls back
to rdna2_decode when that decodes more of the program, and rdna2_decode
reads VOPC with DPP16/DPP8 as the 8-byte form it is.

rdna2spirv:
- SMEM with vcc as its base reads the vcc_lo/vcc_hi pair.
- s_flbit_i32_b64 of a lane mask reads the wave's 64-bit mask (18 library
  programs), as s_ff1_i32_b64 already does.
- s_bitreplicate_b64_b32 of a lane mask into plain scalar data replicates
  the wave's mask word (6 library programs); into exec/vcc it stays
  Unsupported.

test_salu_flbit_64: the lane-mask case now translates (the subgroup op is
outside the single-invocation interpreter), so the test checks that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alid words

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The retail boot reached 50 pipeline-library compute programs that had no
translation. Dumped from the running game, they all translate and pass
spirv-val after these changes:

- fspx_unpack.code_range: some programs carry a 24-byte hash prologue
  (two VOP3 words, then s_inst_prefetch) instead of 36 bytes; two or three
  hash words now count (shader_library uses the same range).
- fspx_unpack --last-endpgm: early exits branch past the first s_endpgm,
  and data after the code can hold s_endpgm words, so a program ends at
  the first s_endpgm whose listing keeps every branch inside the code.
- rdna2spirv: v_cmp_*_dpp into vcc (12 compares in reductions), taken when
  every lane writes (full row/bank masks with bound_ctrl:1, or DPP8).
- rdna2spirv: s_bitreplicate_b64_b32 of a constant into vcc (6 programs),
  as the exec form does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
…te programs llvm-mc refuses

Conflicts with ProjectLeonida#583 (merged just before) in fspx_unpack.code_range and its
test: both handle the two-hash-word, 24-byte prologue of some pipeline-library
programs. ProjectLeonida#998's version counts the hash words (two or three) and covers
ProjectLeonida#583's case, so it is kept; ProjectLeonida#583's two constants, used only there, are
dropped and its measurement comment (50 of 2,684 programs) stays. Both PRs'
tests are kept and pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dezmonius

Copy link
Copy Markdown
Contributor

Independent check of head bec14f225 on Windows 10 22H2, i7-7700K, RTX 5070 / NVIDIA 610.88, LLVM 23.1.5, Vulkan backend.

I matched the three slot-67 failures in a local DadaCap boot-prototype run (9173e790) to three programs absent from its translated library. The baseline listings each contained seven invalid words. With the PR head's decode/translation tools, all three disassembled with zero invalid words, translated with wave64 emulation, and passed spirv-val.

On the same runtime, supplementing the shader index with only those three translations removed the three slot-67 E_INVALIDARG failures. Both runs reached Vulkan presentations and reproduced the same later title exception at +0xb5a5f8 reading 0x68; the captured frames were black.

The PR head's test_fspx_unpack.py, test_shader_disasm.py, and test_rdna2_decode.py passed (85 passed, one skipped). No game data, shader binaries, disassembly, captures, or raw logs attached. AI-assisted (Codex).

@bobcatchris bobcatchris 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.

Reviewed bec14f225 on a second vendor and LLVM version: Windows 11, LLVM 21.1.8, Python 3.12, an AMD Radeon RX 7900 XTX in the box but no GPU work. AI-assisted.

Tests. The seven files you list pass (145 tests).

Rebase. It is 257 commits behind main (507029d1e) and conflicts in two files. Both conflicts are in code main already has from the VOPC-DPP change: the compare-with-DPP-src0 block in tools/rdna2_decode.py, and the compare branch of the DPP path in tools/rdna2spirv.py. I merged main in locally and took main's side of both. That leaves your rdna2_decode.py identical to main and your diff at 7 files, +154/−23. One trap: your self.dpp_guard = None if lane_mask_dst else write merges cleanly, but lane_mask_dst is then defined nowhere, and main already returns before that line for compares. It should go back to self.dpp_guard = write; left as it is, every DPP instruction that is not a compare raises NameError. With that, your seven files plus test_dpp_compare and test_dpp_eager_subgroup pass (161 tests).

Coverage. The first 700 compute programs of the 1.0.2.1 library in index order, --wave64-emulate, each tree with its own listing path:

tree translated pass spirv-val
main 599 of 700 599
this PR merged on main 700 of 700 700
  • The 101 refusals on main are 90 fall-through into undecodable words, 6 undecodable words (cannot re-anchor), 4 s_flbit_i32_b64 of a lane mask and 1 s_bitreplicate_b64_b32 on a lane mask.
  • 96 of the 700 listings take the decoder fallback, and all 96 translate.
  • Nothing that main translates is lost. 592 of the 599 shared modules are byte-identical. The other 7 (lib_cs_00857 to lib_cs_00867) differ only by two or three OpAccessChain each: they hold s_bitreplicate_b64_b32 exec, IMM, which is the exec path you changed, so this is a behaviour change for programs main already translated.

The stated cause. The docstring says llvm-mc 21 does not decode SMEM loads whose SOFFSET is null. On 21.1.8 it decodes those: s_load_dwordx8 s[16:23], s[2:3], null assembles and disassembles. What it rejects is a scalar register tuple that reaches s106/s107:

  • s_load_dwordx4/x8/x16 with its data at s[104:107], s[100:107] or s[96:107];
  • s_buffer_load_* with its four-register descriptor at s[104:107];
  • from the listings, image instructions with the sampler at s[104:107].

In the 115 flagged listings I had at the time, the 40 most common shapes of the rejected words come to about 3,200 of this kind against 37 of any other. Your fix covers them either way, because the decoder prints the [s100,...,vcc_lo,vcc_hi] form shader_ir.py already reads. The comment should name the tuple, so that the rule says how it was confirmed.

One decision to make in the open. On a program that takes the fallback, the listing's encodings are the code bytes (finish() stores code[pc:pc + nbytes]), so check_printed_encodings can no longer see a word llvm-mc would have printed differently; and the decoder does not check must-be-zero bits. I flipped every bit of a set of reference instructions and compared the two decoders. Where llvm-mc rejects or renormalises a flip, the decoder returns the same instruction for the scalar-memory reserved bits (w0 13, 15, 17 and w1 21 to 24) and for DPP16 w1[17].

  • Over all 2,684 compute programs (17.7M instructions) no scalar-memory reserved bit is ever set.
  • DPP16 w1[17] is set in 24 instructions of 4 programs: lib_cs_21476, lib_cs_21500, lib_cs_21520, lib_cs_21521.
  • main translates 1 of those 4 and refuses 3. With this PR all 4 translate, with the bit read as clear.

main refuses a reachable word of that kind, so this changes the policy for those programs. Either is defensible, but I think it should be a choice in the PR and not a side effect of the fallback. The smallest options are to have the fallback listing count such words and refuse, or to write the choice into the contract table.

Contract table. The PR changes two rules that docs/design.md still describes the old way. The s_flbit_i32_b64 row says a pair that lane_masks.py marks as a lane mask stays Unsupported. The s_quadmask/s_bitreplicate row says a lane-mask source or an EXEC/VCC destination raises Unsupported. Neither row is updated, and the fallback listing is a third rule without a row.

Not run. No translated program on a GPU. --last-endpgm and branch_closed_end only through test_fspx_unpack.py. The other 1,984 programs are not compared yet; I will add the full-corpus count when I have it.

Recommendation: Fix first. The rebase and the contract rows; the rest as you decide.

@bobcatchris

Copy link
Copy Markdown
Contributor

Full-corpus numbers, as promised: all 2,684 compute programs of the 1.0.2.1 library, --wave64-emulate, LLVM 21.1.8, each tree with its own listing path. main at 507029d1e; this PR merged on it with the two conflicts resolved as in my review.

tree translated pass spirv-val
main 1,688 of 2,684 1,688
this PR merged on main 2,683 of 2,684 2,683
  • Refusals on main (996): 942 fall-through into undecodable words, 20 branch into data, 18 s_flbit_i32_b64 of a lane mask, 9 undecodable words (cannot re-anchor), 6 s_bitreplicate_b64_b32 on a lane mask, 1 reachable instruction with normalized encoding.
  • Refusals with this PR (1): s_sethalt, in lib_cs_21475, a program of 14 instructions.
  • Listings under the PR's rule: 973 programs have words llvm-mc rejects on main. 923 of them take the decoder listing, 50 get a different code range (the shorter prologue, so they go through disasm(compute=True) afresh), and 21 of those 50 still carry invalid words. The other 1,711 listings are unchanged.
  • Nothing lost. All 1,688 programs main translates also translate with the PR. 1,678 modules are byte-identical. The 10 that differ are 9 that hold s_bitreplicate_b64_b32 exec, IMM (lib_cs_00857 to lib_cs_00867, plus lib_cs_01990 and lib_cs_02039), and lib_cs_21521, whose range now starts after the 24-byte prologue where main listed from offset 0.

Correction to my first review. Its 700-program sample was the first 700 in index order, and that is not a fair sample: the programs with rejected words cluster by index. Per decile of the 2,684, 18, 41, 100, 146, 73, 144, 197, 133, 46 and 25 are flagged. The sample showed 14% of programs refused; the whole corpus is 37%.

Order of merging. #623 hands llvm-mc its input in 64-byte lines. With main's single line the listing step echoes the whole program before every warning: on this package it wrote 8.9 GB for its first 170 flagged listings and stopped with no space left on the drive. With #623's input the same 2,684 listings take 96 seconds and 1.5 GB, with byte-identical listing text. The two PRs touch tools/shader_disasm.py in different places (run_mc and INVALID_AT against disasm), so they should merge independently; whoever lands second will want to re-run the count.

Still not run: nothing on a GPU, and --last-endpgm / branch_closed_end only through test_fspx_unpack.py.

@bobcatchris

bobcatchris commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

GPU results, to close the "not run" line from my review: I built this PR's runtime test runners (RelWithDebInfo, MSVC 19.39, Ninja) and ran the GPU shader suite on the machine from my first review — Windows 11, AMD Radeon RX 7900 XTX (gfx1100), driver 26.10.1, Vulkan SDK 1.4.341. AI-assisted.

suite result
native 234/252 passed, 16 skipped, 2 failed
LEONIDA_W64_EMULATE=1 234/252 passed, 16 skipped, same 2 failed

The two failures are cs_imgload_tfe and cs_imgload_d16_tfe: on the r32 sint view all 64 texels are bad, texel(5,3) = 2071 where 71 is expected — exactly +2000, the two status VGPRs keeping their seeded 1000, so the TFE fetch status is not delivered on this driver.

They are not from this PR. I built the merge-base 82a2aabcc the same way and ran the suite: native passes and fails the same 234 and 2, with the same 2071.

What this adds to the review: the ops the PR changes are covered by fixtures that passed on the 7900 XTX in both modes, including cs_w32_new_ops (the s_bitreplicate_b64_b32 expected words from the contract table), the ten cs_dpp* fixtures and cs_w32_salu64. The s_flbit_i32_b64 and s_bitreplicate lane-mask paths the PR newly allows are still only spirv-val-checked, since no fixture exercises them yet — that part of my "not run" stands.

Separately, and good news rather than a tracker item: the same two fixtures pass on cdb003ea1, the tree my 2026-11-24 session measured (236/252 there, zero failures), and this PR's base is an ancestor of that tree (251 commits behind it). So the TFE fetch status already has a fix on newer main, the failures above are only the 257-commits-stale base, and the rebase this PR needs anyway will pick the fix up. Nothing to do here.

@bobcatchris

Copy link
Copy Markdown
Contributor

I rebased the three commits onto current main (f78385646) and tested the result end to end, because the review said "rebase first" and the base had grown 257 commits past what the measurements ran on. The branch is on my fork as bobcatchris/Leonida@pr-998-rebased — four commits: your three, then one commit of mine that carries the conflict resolutions (clearly attributed, AI-assisted). Squash or cherry-pick from it as you prefer; I did not touch your PR branch.

What main landed since your base, and how the conflicts resolved

  • d04655943 (SHADER-VOPC-DPP, rdna2spirv, shader_disasm: VOPC compares in DPP form (SHADER-VOPC-DPP) #957): the VOPC-with-DPP decoder words your first commit adds. Taken from main; your decoder change is redundant.
  • 1ea2ffbca: s_flbit_i32_b64 of a lane mask (wave64) and bitreplicate into EXEC/VCC (VCC wave64 only) via a mask_dst helper. Kept main's forms; kept your wider constant-to-VCC rule, because the six pipeline-library programs that use it are wave32, which main's restriction refuses — my commit restores your behaviour with main's store helper.
  • ce98fbefe: restores vcc-tuple words into the listing from the blob. Not enough on its own (see below); your listing-level fallback stays the thing that closes the gap.
  • TOOLS-DISASM-WAVE-SIZE (shader_disasm: list a wave64 program for wave64 (TOOLS-DISASM-WAVE-SIZE) #1282): wave32= threading through disasm. Combined with your compute=True.
  • main also gained its own two-carrier prologue detector (fspx_prologue_probe), stricter than yours. Took main's; your test_two_word_prologue fixture needed its second VOP3 word changed to the probe-validated 0x03FE0100 shape to match.
  • The dpp_guard = None if lane_mask_dst else write line merges silently and then breaks every non-compare DPP instruction (lane_mask_dst no longer exists). If you rebase by hand, that line goes back to self.dpp_guard = write; main returns before it for compares.

Verification, all on the rebased branch

check result
semantic suite (repo runner) 486 files, 6,277 tests, 0 failed
library corpus, --wave64-emulate 2,683 of 2,684 translate and pass spirv-val (only s_sethalt refuses) — same as your PR head's numbers
GPU suite, RX 7900 XTX (gfx1100), driver 26.10.1 244 pass, 18 skip, 1 fail
GPU suite, LEONIDA_W64_EMULATE=1 same

The corpus number is the headline: main at the same commit translates 1,688 of 2,684. The 995-program gap survives main's ce98fbefe, so your listing-level fallback remains the fix that matters.

On the GPU suite: the one failure is cs_imgatomic_ext (6 of 64 sint words hold the 0x0badf00d sentinel). I built plain current main and ran the same fixture: identical failure, so it is pre-existing on main and not yours — a new main-side gfx1100 regression relative to the 2026-11-24 run, unclaimed as far as I saw. cs_imgload_tfe/cs_imgload_d16_tfe now pass, confirming the TFE fix I inferred last comment. cs_texture_uav needed d3d12_texture_uav_test built with cl + vcvars (my earlier run only lacked the binary); it passes.

Still only spirv-val-checked: the s_flbit_i32_b64/s_bitreplicate lane-mask-source paths — no fixture exercises them yet.

Not pushed to your branch, not merged, and nothing dispatched in the title. Build note for reviewers on Windows: configure with cl.exe under a Developer Prompt; my first configure here picked ROCm's clang++.exe and mis-built the d3d12 runners silently.

@aslan2142
aslan2142 merged commit c9b3ec1 into ProjectLeonida:main Nov 26, 2026
11 of 13 checks passed
milk4sale pushed a commit to milk4sale/leonida that referenced this pull request Nov 26, 2026
…ct-table sentence

ProjectLeonida#998 added the rule (a 32-bit EXEC/VCC half as S0, read through Gen.wave_mask) without a test
or a design.md entry. test_lane_mask_bitreplicate_flbit.py now runs it on every lane of a
wave64 in the CPU interpreter, from exec_lo/exec_hi and from a compare's vcc_lo/vcc_hi, against
the ISA pseudocode. design.md says it is interpreter-checked only, not measured on hardware, and
that a VCC destination stays wave64-only (ProjectLeonida#984's rule).
Kokonotcu added a commit to Kokonotcu/leonida that referenced this pull request Nov 26, 2026
37 upstream commits after 86dc3d8: ProjectLeonida#2138 (integration/boot-combined), ProjectLeonida#2094 (geometry-view eviction on range
release, reaped after the replays that may name them), ProjectLeonida#998/ProjectLeonida#1317/ProjectLeonida#1281/ProjectLeonida#583 heads (pipeline-library compute
programs by code hash, shader_disasm prints the dot4 op_sel words llvm-mc rejects, FSPX short prologue with the
literal-form check), null-resource texture barriers and null-view RTV clears on the console list, and the removal
of the title's executable addresses from code (read from the environment).

Conflicts, on merit:
- d3d12_xs_device.cpp: both. Our title heap sync (LEONIDA_TITLE_HEAP_SYNC) and upstream's null-RTV marks sit side
  by side; heap_release unregisters the sync or the range as before and also drops the heap's null-RTV marks;
  CreateDescriptorHeap keeps our desc argument and takes upstream's RTV real range. Our value-op/upload-ring
  slots and upstream's slot 146 barrier conversion both stay.
- startup_trace.h: our thread and watchdog-table logging stays, and follows upstream's rule: the watchdog table's
  store and table RVAs come from LEONIDA_WATCHDOG_TABLE (off when unset, documented in runtime/README.md);
  upstream's environment-driven pool diagnostic replaces the fixed address.
- fspx_unpack.py: ours (the code end is found from one rdna2_decode pass, not an llvm-mc run per s_endpgm: the
  OOM and 15-minute fix). Its test takes upstream's short-prologue case, which checks the literal form our code
  also requires.
- rdna2spirv.py: ours (s_bitreplicate_b64_b32 into VCC in wave32 stays translated: 6 pipeline-library programs),
  plus the point behind upstream's refusal: in wave32 VCC's high word is data, so it is now written to vcc_hi as
  source bits 16..31 replicated (replicate_bits16, shared with the scalar form). Tests: ours kept, one added for
  the vcc_hi word; test_salu_flbit_64 keeps ours (this tree translates i64 of a lane mask).
- xs_proxy_mock_test.cpp: upstream's empty Barrier call, our chained-submission reference count.

Every line the merge removes from our side is upstream's own or one of the resolutions above (checked against the
merge base, D:\GTA6\analysis\lostlines.sh). The touched Python suites pass.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants