Skip to content

shader_disasm: end the code range before a trailing constant-data block - #3402

Open
kapitche wants to merge 3 commits into
ItsNotRexed:mainfrom
kapitche:kap/disasm-const-trailer
Open

kapitche wants to merge 3 commits into
ItsNotRexed:mainfrom
kapitche:kap/disasm-const-trailer

Conversation

@kapitche

@kapitche kapitche commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted.

What broke: some carved blobs end with a constant-data block after the real code (s_endpgm, a dword count N, N data dwords, a closing s_endpgm, s_code_end padding). shader_disasm.code_range counted the data as code, so those blobs showed invalid words and a range that ends too late. Repro: a synthetic blob with that tail; code_range on main ends 8 dwords late (0x138 instead of 0x130 in the test).

Fix: data_block_start cuts the range at the count dword only when the count equals the distance to the closing s_endpgm and the dword before it is an s_endpgm; code_range applies it on the header path. The block is documented in docs/design.md. Because the listings depend on this tool, llvm_mc_signature() in make_game.py now also carries the sha256 of tools/shader_disasm.py, so an existing work folder re-disassembles instead of keeping the old, longer ranges.

Measured earlier on a 26,503-blob build (counts only): 1,473 blobs have such a block, all 1,473 decode with no invalid word once it is excluded, and none of the other 25,030 matches the pattern. The translator takes its re-anchor path only when a listing has invalid words, so these 1,473 listings now go through check_printed_encodings, whose docstring was measured on 25,030 listings. I have not rerun the full translation before/after, so that docstring is unchanged.

Tests: tests/test_shader_disasm.py (new cases: block cut, zero-length block, mismatched count not cut) and tests/test_shader_stage_resume.py (signature includes the tool digest); also test_make_game_resume.py, test_make_game_preflight.py, test_make_game_dry_run.py, test_fspx_shaders_stage.py, test_make_game_translator_flags.py, test_docs_design_rows.py. Ubuntu (WSL2), Python 3.12.16: all OK.
Negative control: with tools/shader_disasm.py from upstream/main the new block test fails (code ends 8 dwords late); with make_game.py from upstream/main the new signature test fails.

@bobcatchris

Copy link
Copy Markdown
Contributor

Independent CPU verification of 2c9b8620 (base f847748c), Windows 11 / Python 3.12, no game data and no GPU.

  • PR head: python -I tests/test_shader_disasm.py → 16/16 OK; python -I tests/test_docs_design_rows.py → 2/2 OK.
  • Untouched base with only the PR test file copied in → 15 passed, 1 failed: test_code_range_stops_before_a_constant_data_block reports code ending 8 dwords too late (0x138 instead of 0x130), so the trailing constant-data block is still counted as code.
  • python -m py_compile tools/shader_disasm.py: clean.

No blocker found from this check.

@paratustra

Copy link
Copy Markdown
Contributor

Code read at 2c9b862 (macOS, Python 3.15.2; tests/test_shader_disasm.py OK). The detector itself looks sound: a false match needs a second "program" whose first dword is a small integer equal to its own length, i.e. a leading v_cndmask_b32 v0, sN, v0 reading an unset VCC. Three things before this is reviewable:

  1. The description and the claim are rdna2spirv: s_incperflevel, s_decperflevel and s_wakeup as no-ops #2922's (s_incperflevel/s_decperflevel/s_wakeup as no-ops in rdna2spirv.py), not this change. The data-block work has no claim and no test report of its own.

  2. It changes which translator path 1,473 shaders take. translate() branches on info["invalid"] (tools/rdna2spirv.py ~12579): with invalid words it re-anchors against the blob; without them it runs check_printed_encodings, whose docstring measures "all 30,335,381 instructions of the 25,030 such listings". 26,503 − 1,473 = 25,030, so those 1,473 listings have never been through that check. Please run the translation over the corpus before and after and report translated and spirv-val-valid counts, as AGENTS.md asks for a change that alters the listings. If they hold, the docstring's 25,030 becomes 26,503.

  3. Existing work folders won't pick it up. disassembly_status (make_game.py) reuses the listings as long as the llvm-mc signature matches; shader_disasm.py isn't part of that fingerprint (it is for FSPX, via FSPX_TOOLS). Only fresh builds get the shorter ranges, so the counts in (2) differ between a new and an updated work folder. That may be acceptable, but it should be a decision, not a side effect.

Constant reads are unaffected as far as I can see: s_getpc_b64 addresses the whole FSSM blob through the code-base push constants, not the disassembled range.

No game files. AI-assisted (Claude Code).

@ramenbellic

Copy link
Copy Markdown

Code read of 2c9b862, plus a sample measurement on a local build of the game (counts only):

  • data_block_start (tools/shader_disasm.py:87-102) cuts only when the dword at the count position equals the distance to the closing s_endpgm and the dword before it is an s_endpgm (:100); code_range applies it only on the header path (:118). python -I tests/test_shader_disasm.py: 16 OK at the head, 20 OK on a trial merge with current main (clean).
  • Random sample of 500 carved blobs, PR's code_range vs main's (llvm-mc, gfx1013): 24 ranges changed, all 24 end earlier (by 10 to 642 dwords); those 24 had 350 invalid words under main's range and 0 under the PR's; the other 476 are unchanged. 24/500 is in line with the 1,473 / 26,503 in docs/design.md:471.
  • I agree with @paratustra's three points above (description is rdna2spirv: s_incperflevel, s_decperflevel and s_wakeup as no-ops #2922's; the 1,473 listings move to the check_printed_encodings path, so before/after translated and spirv-val counts are still needed; existing work folders keep their old listings). This sample doesn't answer the second one; I haven't run the full translation.

AI-assisted review (Claude Code); no approval or change request.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested 2c9b8620 on Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), AMD Radeon RX 9070 XT (AMD 26.11.2), Python 3.12.10: changes suggested.

run result
pytest tests/test_shader_disasm.py 16 passed, 6 subtests passed in 3.16s
python -m compileall -q make_game.py tools tests clean

Review: I read data_block_start and the code_range change (tools/shader_disasm.py:87-118), the new test, the design.md paragraph, and the translator and make_game.py code that reads the listings. The detector does not cut decodable code for N ≥ 1. I ran every count value 0..65536 as a dword through llvm-mc -mcpu=gfx1013: 65,536 are "invalid instruction encoding", and only 0 decodes (as v_illegal). So for N ≥ 1, a cut only lands where the old range already had an invalid word, and N = 0 drops just a v_illegal; s_endpgm pair. The new test fails on the base (as bobcatchris showed) and passes at the head. None of the other 9 open PRs that touch tools/shader_disasm.py adds or removes a line about code_range, ENDPGM or rfind. #3998 is the closest, and it only changes the failure bookkeeping in one()/main(). What still needs work is the PR text and the corpus measurement. paratustra raised the same points, and I checked them against the code:

  1. The PR description belongs to rdna2spirv: s_incperflevel, s_decperflevel and s_wakeup as no-ops #2922 (s_incperflevel/s_decperflevel/s_wakeup as no-ops; tools/rdna2spirv.py, tests/semantic/test_sopp_noops.py), and neither file is in this diff. The data-block change has no claim, repro or test report of its own. Please replace the body.
  2. tools/rdna2spirv.py:12579 branches on info["invalid"]. The blobs whose data block is cut lose their invalid words, so they move from the re-anchor + reachable_code path to check_printed_encodings. Its docstring (:12533) was measured on "the 25,030 such listings", and 26,503 − 1,473 = 25,030, so these listings have not been through that check. AGENTS.md:83-92 asks for translated and spirv-val-valid counts before and after a translator change. This PR changes the translator's input for 1,473 listings, so the same counts apply. Please run the full translation both ways and report them. If nothing drops, the docstring's 25,030 becomes 26,503.
  3. Question: make_game.py:761 reuses existing listings when disassembly_status matches the signature from llvm_mc_signature() (:647, the llvm-mc command and version only). shader_disasm.py is not part of it. So an existing work folder with disasm.done keeps the old, longer ranges, and only a fresh build gets the shorter ones. Is that intended, or should these listings be invalidated?

AI-assisted (Claude Code); I checked the results.

@thirteenhustler

Copy link
Copy Markdown

Tested 2c9b862 on Linux 6.12.113+, Python 3.12.3 (no GPU, no game data): pass.

Ran python -m compileall -q tools/shader_disasm.py tests/test_shader_disasm.py and python -I tests/test_shader_disasm.py: 16 tests, OK.

data_block_start (tools/shader_disasm.py:87) only cuts when the dword count N is exactly the number of dwords before the closing s_endpgm and the dword before that count is itself an s_endpgm. The range then ends at the count, so the real s_endpgm stays in the code and the data does not. The new test covers N of 0, 1, 8 and 32, a count that does not reach the closing s_endpgm, and a second real program (s_nop + s_endpgm) that must be kept. All of those match.

Please replace the PR description. It says this adds s_incperflevel, s_decperflevel and s_wakeup to NOOPS in tools/rdna2spirv.py. This diff does not touch that file. The title matches the change; the body describes a different one.

@sds-228 sds-228 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.

Code review of 2c9b862: no issues found. A trailing count-checked constant block is excluded from the decoded code range; tests cover zero-length and mismatched blocks. Targeted suite: 16 tests OK.

AI-assisted (OpenCode).

@kapitche

Copy link
Copy Markdown
Contributor Author

Thanks all. Pushed 41db9e81; it still merges cleanly with main 03b09a08 (checked with a trial merge).

  1. Description: you are right, it was rdna2spirv: s_incperflevel, s_decperflevel and s_wakeup as no-ops #2922's text. Replaced the body with this change's own (what broke, fix, tests, negative control). The claim/measurement reference is the 1,473 of 26,503 blobs already in docs/design.md.
  2. Translation counts: not done. The listings in question move to the check_printed_encodings path because they lose their invalid words (zneel's 0..65536 llvm-mc check agrees: a cut only lands where the old range already held an invalid word, and N=0 only drops a v_illegal; s_endpgm pair). I did not run a before/after translation of the full corpus (25k+ shaders, longer than I could run here), so the 25,030 in the check_printed_encodings docstring is left as is until someone has those counts. ramenbellic's 500-blob sample (24 changed, 350 invalid words to 0) is consistent with this but is not that run.
  3. Existing work folders: not intended. llvm_mc_signature() now also carries the sha256 of tools/shader_disasm.py, so disasm.done no longer matches and the stage re-disassembles (and re-translates) in an existing folder. New test test_signature_includes_the_disassembler_tool_digest in tests/test_shader_stage_resume.py fails with main's make_game.py.

Ran on Ubuntu (WSL2), Python 3.12.16: test_shader_stage_resume, test_shader_disasm, test_make_game_resume, test_make_game_preflight, test_make_game_dry_run, test_fspx_shaders_stage, test_make_game_translator_flags, test_docs_design_rows all OK.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: merges cleanly into current main; tests/test_shader_disasm.py passes (20 tests) and the three existing consumers of code_range (fspx_unpack 23, fssm_crosscheck 6, semantic printed_encoding 7) all pass unchanged. Data-block detection is pinned with hand-written blobs; the design.md note quotes aggregate counts only. Heads-up for maintainers: #4210 edits the same two files (tools/shader_disasm.py and tests/test_shader_disasm.py) and the two heads do NOT merge-trees cleanly — expect a rebase, not just ordering. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kacper-serewis kacper-serewis 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.

At 41db9e8, test_signature_includes_the_disassembler_tool_digest fails. Include the shader_disasm.py digest in the resume signature so existing work folders regenerate stale disassembly. All 16 disassembler tests and 44 other resume tests passed. Across all 26,503 cached blobs, 1,473 ranges shortened at a unique matching boundary and 25,030 stayed identical. AI-assisted CPU check; no GPU.

@kapitche

Copy link
Copy Markdown
Contributor Author

Before/after on my own 1.0.2.1 copy (26,503 FSSM blobs), main 03b09a0 vs this PR 41db9e8, same translator: counts below. Windows 11, Python 3.13.1, llvm-mc 23.1.6 (--mcpu gfx1013, --jobs 14, as make_game.py calls it). The PR head was merged with main 03b09a0 first; that merge is clean and git diff against main is exactly this PR's 4 files, so the disassembler change is the only variable. Both disassemblies were translated with the same current-main rdna2spirv.py --wave64-emulate (sharded, --no-asm), which runs spirv-val itself (--target-env vulkan1.2 --allow-offset-texture-operand).

Disassembly, all 26,503 blobs

main PR
clean 25,030 26,503
invalid words 1,473 0
listings that differ 1,473 (the same 1,473; the other 25,030 are byte-identical)

Translation. A full pass measured about 4 shaders/s here (~110 min per side), over the 60-minute budget I set, so I translated the 1,473 affected listings plus a 500-shader random control (fixed seed, over all 26,503; 26 of them are also affected, so 1,947 distinct shaders). The other 25,030 listings are byte-identical between main and PR, so their translator input is identical and I did not run them.

set main PR
1,473 affected translated 1,473 1,473
failed 0 0
spirv-val pass 1,473 1,473
SPIR-V byte-identical main vs PR 246
SPIR-V different 1,227
500 control translated / failed / spirv-val pass 500 / 0 / 500 500 / 0 / 500
SPIR-V byte-identical / different 478 / 22

In the control, the 474 shaders that are not among the 1,473 are byte-identical, and the 22 that differ are 22 of the 26 affected ones. All 1,473 affected listings pass check_printed_encodings (they translate), so the path change paratustra asked about did not reject any of them.

Why 1,227 differ. The listing with undecodable words used to go through reachable_code, so only code reachable from entry was translated. The listing without them keeps every instruction in the range, including dead padding after the last reachable s_endpgm (an s_nop run and/or a second s_endpgm). That tail becomes one extra unreachable block, which shifts the block-state constant ids by one; the instruction sequence and the line count of the module are otherwise the same. The 246 identical ones have no such tail beyond the single closing s_endpgm. Check: I re-translated 240 PR listings (200 that differ, 40 that are identical) with the instruction list cut to the entry-reachable code, and the 199 of the 200 that translated that way came out byte-identical to main's SPIR-V, as did all 40 of the others (the 1 that did not translate under that cut is not on the PR path). So the difference is the dead tail only; no reachable instruction changed.

If byte-stable output matters, applying reachable_code to the no-undecodable-words path too would make all 1,473 identical; I would do that as a separate translator change, not in this PR.

@kapitche

Copy link
Copy Markdown
Contributor Author

Follow-up to my measurement above, pushed as 0e37ea99 (main merged in first; the PR is now 4 files: tools/rdna2spirv.py, make_game.py, and two tests).

What changed:

  1. translate() now keeps only the entry-reachable code (fold_far_branches then reachable_code, the same two calls the undecodable-words path makes) for a listing whose code range ends right before a trailing constant-data block (trailing_data_block(): the range ends after an s_endpgm, the next dword is a count N, and the dword N+1 later is s_endpgm, the rule data_block_start uses). Every other listing is untouched. The constant-data handling in shader_disasm.py is unchanged.
  2. The dead code is not only tail padding. In the one shader I examined, the extra block came from a dead s_nop after an unconditional s_branch inside the body (a dead instruction after a branch is a leader), and the trailing s_endpgm that follows the real one was a second dead instruction. reachable_code drops both. Because the new listing has no undecodable words, translate() took the other branch and kept all of it.
  3. make_game.py: llvm_mc_signature() now includes the sha256 of tools/shader_disasm.py. The earlier head 41db9e81 carried the test for this but not the change, so test_signature_includes_the_disassembler_tool_digest failed there (as kacper-serewis reported). Passes now.

Measured on my own 1.0.2.1 copy (counts only). Windows 11, Python 3.13.1, llvm-mc 23.1.6, rdna2spirv.py --wave64-emulate --no-asm in 12-20 shards, spirv-val run by the translator. Same 1,473 affected blobs and a 500-blob random control (fixed seed; 24 of them are affected, 1,949 distinct shaders). A = pre-#3402 listings (old shader_disasm.py) with main's translator; B = the cut listings with main's translator; C = the cut listings with this head's translator.

A (before #3402) B (main, cut listings) C (this head)
1,473 affected: translated / spirv-val pass 1,473 / 1,473 1,473 / 1,473 1,473 / 1,473
500 control: translated / spirv-val pass 500 / 500 500 / 500 500 / 500
1,473 SPIR-V byte-identical to A 246 (1,227 differ) 1,473 (0 differ)
500 control byte-identical to A 479 (21 differ) 500 (0 differ)

So all 1,473 are byte-identical to the output before #3402, and the control is identical too. The earlier 1 of 240 that did not translate under the cut translates here; I did not isolate why, but fold_far_branches runs before reachable_code here and not in the experiment I described above.

New test: tests/semantic/test_trailing_data_block.py (synthetic wave64 CS under --wave64-emulate: a forward branch, an s_nop after an unconditional s_branch, the real s_endpgm, an s_nop run plus a second s_endpgm, then N, data, s_endpgm; must equal the translation without the dead code; a listing with no data block after it keeps its padding). Ubuntu (WSL2), Python 3.12.16: 3 tests OK. Negative control: with tools/rdna2spirv.py from upstream/main (same as the previous head) 2 of the 3 fail. Also OK on this head: test_shader_disasm, test_shader_stage_resume (45), test_make_game_resume, test_make_game_preflight, test_make_game_dry_run, test_fspx_shaders_stage, test_make_game_translator_flags, test_docs_design_rows, tests/semantic/test_printed_encoding.

tests/semantic as a whole: I ran unittest discover once on this head and once on main, both on Ubuntu 3.12.16, and each hit my 25-minute limit before finishing (no summary). The progress strings are identical up to the shorter one (5,177 tests): the same 3 failures and 2 errors at the same positions on both, so they are not from this change. I did not get a full pass/fail total.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0e37ea9 on Intel UHD 630 (CFL GT2), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: no change from main.

  • Full scripts/run_gpu_tests.py after a full build: 154/217 passed, 61 skipped. Main 3faac55 gives the same 154/217, 61 skipped on this machine (earlier run today).
  • The only two FAILs are the ones main also has here: cs_fmt_int_narrow (word 34: expected 0xffffffff, got 0x00000000) and cs_signed_zero_nan.
  • LEONIDA_VK_DEVICE=NoSuchDevice fails with "no Vulkan physical device matches", so the Intel device ran the suite.

The PR's own Python tests were not run here.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor Author

Full tests/semantic parity run, upstream/main 3faac557 vs main + this PR (head 0e37ea99, merged onto main with a local merge commit; the PR's merge base is older than main). Runner: #4357's scripts/run_semantic_tests.py (copied into scratch worktrees, not committed), wrapped to print one pass/FAIL/ERROR/SKIP line per test id. The three runs per platform were run at the same time.

platform tree files tests pass skip xfail fail/error (ids) wall
Linux, Python 3.12.16, -j6 main 396 6245 6224 16 1 4 216 s
Linux, Python 3.12.16, -j6 main + #3402 397 6248 6227 16 1 4 219 s
Windows, Python 3.13.1, -j4 main 396 6245 6224 16 1 4 532 s
Windows, Python 3.13.1, -j4 main + #3402 397 6248 6227 16 1 4 532 s

Per-test diff against main, both platforms: the only difference is the 3 new tests of test_trailing_data_block.py (all pass). Every other test id has the same outcome, and Linux and Windows agree test for test. The 4 failing ids are the same on main and on the PR (test_loop_ballot_barrier: 3 test ids, test_vcmp16_opsel: 1; not touched by this PR). The 16 SKIPs need spirv-val/spirv-as or llvm-mc, which these runs did not have.

So with the parallel runner the full suite finishes in about 4 minutes on Linux and 9 minutes on Windows, nowhere near the 25-minute limit that the earlier serial run hit.

Translator mutation ("v_and_b32": "OpBitwiseAnd" changed to "OpBitwiseOr" in U2, in all trees): main and main + #3402 fail exactly the same tests, 235 test ids in 76 files, on Linux and on Windows, and the per-test outputs are identical apart from the 3 new passing tests. (The 3 new tests do not involve v_and_b32 and stay green.)

Raw per-test tables are not attached; counts only.

gregoirener pushed a commit to gregoirener/Leonida-latest-backup-Monday-23-nov-Japanese-time- that referenced this pull request Nov 23, 2026
… does not carry

The branch's only commit adds test_signature_includes_the_disassembler_tool_digest; llvm_mc_signature() still
returns just the command and the version, so the test fails on the branch itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kapitche added a commit to kapitche/Leonida that referenced this pull request Nov 23, 2026
@kapitche
kapitche force-pushed the kap/disasm-const-trailer branch from 0e37ea9 to fb6c626 Compare November 23, 2026 12:41
@kapitche

Copy link
Copy Markdown
Contributor Author

@ItsNotRexed thanks. The reverted state on main is what was wrong: main now has the data_block_start change but not the llvm_mc_signature() change nor the test. Rebased onto upstream/main 561b65a8 (clean, no longer CONFLICTING) and pushed fb6c626b, three commits:

  1. tools/rdna2spirv.py + tests/semantic/test_trailing_data_block.py: translate only the entry-reachable code of a listing whose range ends before a constant-data block (kept as before; the one conflict with fspx_wave_size / hoist_reg_ptrs resolved by keeping both).
  2. make_game.py: llvm_mc_signature() returns the command, the version and the sha256 of tools/shader_disasm.py, so an existing work folder with disasm.done re-disassembles.
  3. tests/test_shader_stage_resume.py: test_signature_includes_the_disassembler_tool_digest restored (the same 11 lines the revert removed).

Ubuntu (WSL2), Python 3.12.16, -I: test_shader_stage_resume 47 OK, test_shader_disasm, test_make_game_resume, test_docs_design_rows, test_make_game_preflight (1 skipped), test_make_game_dry_run, test_fspx_shaders_stage, test_make_game_translator_flags OK, and unittest discover -s tests/semantic -p test_trailing_data_block.py 3 OK.
Negative control with make_game.py and tools/rdna2spirv.py from upstream/main: test_signature_includes_the_disassembler_tool_digest fails (1 of 47) and 2 of the 3 test_trailing_data_block tests fail; with the PR's files back they pass.

@nicknickalive

Copy link
Copy Markdown

Tested fb6c626 (trial-merged onto main 561b65a, fast-forward) on Windows 11 Pro 26200, Python 3.12, llvm-mc 23.1.6, NVIDIA GeForce RTX 5090 (610.88) machine: pass (no GPU-visible change).

  • tests/semantic/test_trailing_data_block.py 3/3, tests/test_shader_stage_resume.py 47/47, tests/test_shader_disasm.py 29/29 OK.
  • runtime/test/shaders/build.py: 261/261 translated, all pass spirv-val, and every .spv/.spvasm plus index.json is byte-identical to main 561b65a's build. As expected, no hand-written fixture has a trailing data block, so trailing_data_block() never fires on them. The GPU suite can't reach the new path, so I didn't rerun it. That needs carved blobs.

No game files. AI-assisted.

@ErayOzdayioglu

Copy link
Copy Markdown

Tested the current head 2524429 (the last check above was fb6c626) on Windows 11 26200, Python 3.12.10, llvm-mc 23.1.6, CPU only. pass, and the point @ItsNotRexed raised is addressed at this head:

  • tests/test_shader_stage_resume.py: 47 tests OK, including test_signature_includes_the_disassembler_tool_digest.
  • tests/semantic/test_trailing_data_block.py: 3 tests OK.
  • Controls, with one file at a time taken from the merge base 1cc6e3c:
    • make_game.py from the merge base: test_signature_includes_the_disassembler_tool_digest fails (1 of 47). So the restored test does depend on the make_game signature change carried in 369426a, rather than passing on its own as on the reverted branch.
    • tools/rdna2spirv.py from the merge base: 2 of 3 trailing-data tests fail (test_dead_padding_around_the_code_is_dropped, test_tail_variants_are_dropped_too).

AI-assisted: yes

@kapitche

Copy link
Copy Markdown
Contributor Author

Answering the open items. Status of reachable-code trimming: it landed in this PR (commit 901edf4, translate() keeps only the entry-reachable code for a listing whose range ends before a trailing constant-data block, via trailing_data_block()), together with the llvm_mc_signature() change and the restored digest test (kacper-serewis's change request and ItsNotRexed's revert note). Main was CONFLICTING (the one conflict was the Gen(...) line next to it, main added cache_active), so I rebased onto upstream/main 1cc6e3c and pushed 2524429; the PR is the same 4 files.

Measured again today, my own 1.0.2.1 copy, counts only, Linux, Python 3.12.16, llvm-mc 23.1.6 (--mcpu gfx1013), the same --wave64-emulate translator flags as before. The 1,473 listings that had undecodable words under the old range were re-disassembled with current disassembler code (all 1,473 clean, 1,451 distinct names) and translated twice, with main 1cc6e3c and with this head:

  • main: 1,473/1,473 translated and pass spirv-val. This head: 1,473/1,473 translated and pass spirv-val.
  • SPIR-V main vs this head: 241 of 1,451 files byte-identical, 1,210 differ (main's output is 104 to 400 bytes larger for the differing ones in the common cases: the dead tail after the last reachable s_endpgm as one extra unreachable block).
  • Reference: the same 1,473 original listings (with undecodable words, so through reachable_code as before the range change) translated with main. I ran this for 1,296 of the 1,451 files before the time box (stopped there, 155 not run): this head's SPIR-V is byte-identical to that reference in 1,296 of 1,296; main's translation of the shorter listings is byte-identical to it in only 232 of the 1,296.
    So with the trimming, the 1,227-ish SPIR-V differences from my earlier measurement are gone for every shader I compared, and nothing changed for the 25,030 listings that already decoded clean (their listings and so their translator input are identical). Not done: the last 155 files of the reference run, and no GPU runs on this head. Tests after the rebase: tests/semantic/test_trailing_data_block.py 3/3, tests/test_shader_stage_resume.py 47, tests/test_shader_disasm.py 29 all OK; with tools/rdna2spirv.py from main the trailing-block test fails 2 of 3.

@bobcatchris

Copy link
Copy Markdown
Contributor

Independent macOS check at head 2524429 (Apple M2, Python 3.13.18, llvm-mc 21.1.8). The disassembler now ends the code range before a trailing constant-data block, with synthetic semantic coverage and a stage-resume regression.

  • python -m unittest discover -s tests/semantic -p test_trailing_data_block.py: OK.
  • pytest -q tests/test_shader_stage_resume.py: 47 passed, 2 subtests passed, 0 failed.
  • Full GPU suite with a shared harness: 174/235 passed, 59 skipped, 2 failed (cs_fma_fused, ps_ssharp); 0 per-test status differences against current main's runner with the same harness. (The PR's base is older, hence the smaller total.)

No issue found; synthetic listings only.

AI-assisted.

@aslan2142

Copy link
Copy Markdown
Contributor

Independent check of 901edf49 for BUILD-1448, over all 1,473 shaders with a trailing constant-data block (you compared 1,296). With it, every one translates to SPIR-V byte-identical to the output from before the code range was cut, in default and --wave64-emulate mode. main alone matches on 246 of them.

What exists

  • main (dde82f27) already has shader_disasm.data_block_start, but translate() there does not trim the shortened listings.
  • shader_disasm: end the code range before a trailing constant-data block #3402 (open, head 25244291) adds trailing_data_block(). For a listing whose range ends right before a constant-data block, translate() keeps only the code reachable from entry (reachable_code(fold_far_branches(insns))). kapitche compared 1,296 of the outputs before stopping; this check covers all 1,473.

Method (my own 1.0.2.1 copy, counts only)

  • The 1,473 listings are the ones whose header line differs between the old gfx1013 disassembly (from before the code range was cut at the data block) and a fresh one made at main d90444f2:
    • All 1,473 old listings have undecodable words, and none of the new ones do.
    • The other 25,030 headers are identical.
  • I ran three translator/listing combinations, each with default flags and again with --wave64-emulate:
    • reference: main dde82f27 tools/rdna2spirv.py on the old listings. This is the path through reachable_code from before the range was cut, and only the listings changed since then, not the translator.
    • main: the same translator on the new listings.
    • shader_disasm: end the code range before a trailing constant-data block #3402: main dde82f27 with 901edf49's tools/rdna2spirv.py diff applied (clean, offset only), on the new listings.
  • I took the SHA-256 of every .spv and compared the hashes per output.

Result (the same in both flag modes)

translator on new listings translated pass spirv-val byte-identical to reference different
main 1,473 1,473 246 1,227
main + 901edf49 1,473 1,473 1,473 0

The reference run also translates 1,473/1,473, and all 1,473 pass spirv-val.

Conclusion: #3402 completes BUILD-1448, and nothing more is needed once it merges.

Linux, Python 3.14.10, SPIRV-Tools v2026.4, CPU only (no GPU run).

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

@thiefyzheng

Copy link
Copy Markdown

checked: full GPU suite at head 25244291f — 217/235 passed, 17 skipped. Same single cs_w32_salu64 FAIL, identical to plain main's on RDNA3/NAVI31 (see our main-level finding) — not attributable to this PR. Measured on a 7900 XTX (RADV NAVI31, Mesa 25.2.8.2), this PR's exact head, fresh worktree, repo-pinned Vulkan headers; synthetic fixtures only, no game data. AI-assisted (an agent fleet ran it).

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.