tools: chain_check.py, one page of counts for the whole shader chain (TOOL-CHAIN-CHECK) #2231

Open
github-bot wants to merge 4 commits from github-bot/gh-2231 into main AGit
Owner

@⁠MoonEyes on GitHub · 2026-11-26 08:51 UTC · original
MoonEyes:tools/chain-check → main · +1213 −0 · 3 files · 4 commits · open

Claimed in the coordination issue as: TOOL-CHAIN-CHECK

What and why

The shader chain (game files → llvm-mc → translator → SPIR-V → runtime pipelines) fails quietly link by link. On one Windows machine, llvm-mc 21.1.8 left 840 of the 2,684 compute programs of the pipeline library untranslated (839 "fall-through into undecodable words", 1 s_sethalt; #1923 measures the same gap). At boot the runtime then logged 843 slot 67 ... failed with 0x80070057 lines. Today nothing connects those two counts: the build prints no "N of M" for the library, and boot.ps1's digest shows neither slot failures nor failed CreatePipelineState calls.

tools/chain_check.py prints one page with one block per link, each with OK / WARN / FAIL and its most likely cause, then the weakest link:

  • tools: the llvm-mc each family was disassembled with (disasm.done, <family>_build.json) and its AMDGPU target, spirv-val, and the recorded translator digest against the same digest recomputed from make_game.py's TRANSLATION_SOURCES (a test pins it equal to translation_sources_digest());
  • per family (game, library, FSPX, BVH, exe): unpacked, listings, listings with rejected words (invalid_words), translated (index entries with their .spv), up to 5 refusal reasons from logs/shaders.log;
  • contract: tagged vs plain modules (#2098) and which of the runtime's folders exist (fspx_compute...);
  • runtime, from --log: modules loaded, failed slot calls by slot and HRESULT, failed D3D12 calls, compute builds, compile-gate waits, device faults, exit code.

Counts and fixed words only. A refusal reason is printed only when it matches a message rdna2spirv.py raises (read from its source), with a variable part kept only when it is a mnemonic of tools/rdna2_isa_tables.py or a built-in exception name; everything else counts as other. A D3D12 method name from a trace is printed only when it is a string literal of the runtime's sources (or Interface::Method with such an interface), and the end of a boot digest only in the three forms boot.ps1 writes. Paths appear only with --show-paths. Standard library only. It reads files; probing runs only llvm-mc --version, spirv-val --version and git rev-parse (--no-probe runs nothing). Exit 0 (a report), 1 with --strict on FAIL, 2 for bad arguments. Documented in docs/dev-tools.md.

Not done here (possible follow-up, separate PR): making make_game.py print "N of M translated" for the library and FSPX and warn on llvm-mc older than 23, and adding the slot failures, failed CreatePipelineState calls and tagged/plain count to scripts/windows-boot/boot.ps1's digest. The tool reports; it does not fix, retranslate or change any threshold of the build.

Sample report (real work folder after a full build with llvm-mc 21.1.8, and one 783 s boot; work folder path removed):

chain check
[WARN] tools
  llvm-mc     recorded 21.1.8 in 5 (5 records, amdgcn yes, via wsl); LLVM_MC now 21.1.8
  spirv-val   v2026.4
  translator  local dafa68abb710 in 5; checkout 7fb850e4e08b at a73a57e13; stale: bvh, exe, fspx, game, library
[OK] game  game programs (shaders.rpf)
  expected 26503  listings 26503  translated 26503 (100.0%)  failed 0
[FAIL] library  pipeline library compute
  expected 2684  listings 2684 (944 with rejected words)  translated 1844 (68.7%)  failed 840
  reasons     839 fall-through into undecodable words; 1 s_sethalt
  cause: llvm-mc 21.x leaves undecodable words (839 refusals; #1923)
[FAIL] fspx  FidelityFX FSPX
  expected 29  listings 29 (11 with rejected words)  translated 22 (75.9%)  failed 7
[OK] bvh  BVH builder  (52/52)    [OK] exe  executable  (12/12)
[WARN] contract
  modules     plain 28433; translator default tagged
  folders     present fspx, bvh, exe, library; absent fspx_compute, fspx_gfx
[FAIL] runtime
  loaded      total 28433, fspx 1866, fspx_compute 0, fspx_gfx 0, bvh 52, exe 12; descriptor table plain
  slot fails  slot 67 0x80070057 843; no translated compute shader 843
  d3d12       ID3D12Device2::CreatePipelineState failed 4, ID3D12Device2::CreatePipelineState unsupported 1
  pipelines   compute builds 830 (slow 40); compile gate waits 0
  device      fault lines 0, device lost lines 0, stalled dispatch lines 0; exit code none logged; boot.ps1: ran its full time limit (783 s), stopped
weakest link: library [FAIL]: llvm-mc 21.x leaves undecodable words (839 refusals; #1923)

(abridged: the cause lines of the tools, game, fspx, bvh, exe, contract and runtime blocks and the fspx reasons line are left out, and the bvh/exe count lines are shortened)

Tested

  • python -I tests/test_chain_check.py: 23 tests OK (synthetic work folders built by the test: broken and clean chains, mixed llvm-mc versions, refusal reasons and trace method names closed to what the sources contain, an index entry without its .spv is not counted, the 1% threshold on both sides, no names/paths without --show-paths, empty and partial folders give n/a or a verdict, --strict, --help thresholds, digest equal to make_game.translation_sources_digest(), UTF-16 log with and without BOM). One test reads the runtime sources and boot.ps1 and checks the 21 format-string fragments the log patterns depend on, so a reworded log line fails the test instead of silently reporting zero.
  • tests/test_runner_calls_all_tests.py 3 OK, tests/test_ci_registration.py 16 OK, all 13 tests/test_docs_*.py OK.
  • python -I scripts/check_no_game_data.py tools/chain_check.py tests/test_chain_check.py docs/dev-tools.md: exit 0; git diff --check origin/main..HEAD clean.
  • Real run: a full work folder (26,503 + 2,684 + 29 + 52 + 12 programs) and a 1.25-million-line boot log, about 28 s.

GPUs tested: n/a for the tool; the sample report comes from an NVIDIA RTX 4060, driver 610.88

AI-assisted: yes (Claude Code, Claude Opus 5.5, wrote the tool and its test; a second agent reviewed it)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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. (n/a: no translator change)

🤖 Generated with Claude Code

**@⁠MoonEyes** on GitHub · 2026-11-26 08:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2231) `MoonEyes:tools/chain-check` → `main` · +1213 −0 · 3 files · 4 commits · open Claimed in the coordination issue as: [TOOL-CHAIN-CHECK](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why The shader chain (game files → llvm-mc → translator → SPIR-V → runtime pipelines) fails quietly link by link. On one Windows machine, llvm-mc 21.1.8 left 840 of the 2,684 compute programs of the pipeline library untranslated (839 "fall-through into undecodable words", 1 `s_sethalt`; #1923 measures the same gap). At boot the runtime then logged 843 `slot 67 ... failed with 0x80070057` lines. Today nothing connects those two counts: the build prints no "N of M" for the library, and `boot.ps1`'s digest shows neither slot failures nor failed `CreatePipelineState` calls. `tools/chain_check.py` prints one page with one block per link, each with OK / WARN / FAIL and its most likely cause, then the weakest link: - tools: the llvm-mc each family was disassembled with (`disasm.done`, `<family>_build.json`) and its AMDGPU target, spirv-val, and the recorded translator digest against the same digest recomputed from `make_game.py`'s `TRANSLATION_SOURCES` (a test pins it equal to `translation_sources_digest()`); - per family (game, library, FSPX, BVH, exe): unpacked, listings, listings with rejected words (`invalid_words`), translated (index entries with their `.spv`), up to 5 refusal reasons from `logs/shaders.log`; - contract: tagged vs plain modules (#2098) and which of the runtime's folders exist (`fspx_compute`...); - runtime, from `--log`: modules loaded, failed slot calls by slot and HRESULT, failed D3D12 calls, compute builds, compile-gate waits, device faults, exit code. Counts and fixed words only. A refusal reason is printed only when it matches a message `rdna2spirv.py` raises (read from its source), with a variable part kept only when it is a mnemonic of `tools/rdna2_isa_tables.py` or a built-in exception name; everything else counts as `other`. A D3D12 method name from a trace is printed only when it is a string literal of the runtime's sources (or `Interface::Method` with such an interface), and the end of a boot digest only in the three forms `boot.ps1` writes. Paths appear only with `--show-paths`. Standard library only. It reads files; probing runs only `llvm-mc --version`, `spirv-val --version` and `git rev-parse` (`--no-probe` runs nothing). Exit 0 (a report), 1 with `--strict` on FAIL, 2 for bad arguments. Documented in `docs/dev-tools.md`. Not done here (possible follow-up, separate PR): making `make_game.py` print "N of M translated" for the library and FSPX and warn on llvm-mc older than 23, and adding the slot failures, failed `CreatePipelineState` calls and tagged/plain count to `scripts/windows-boot/boot.ps1`'s digest. The tool reports; it does not fix, retranslate or change any threshold of the build. Sample report (real work folder after a full build with llvm-mc 21.1.8, and one 783 s boot; work folder path removed): ``` chain check [WARN] tools llvm-mc recorded 21.1.8 in 5 (5 records, amdgcn yes, via wsl); LLVM_MC now 21.1.8 spirv-val v2026.4 translator local dafa68abb710 in 5; checkout 7fb850e4e08b at a73a57e13; stale: bvh, exe, fspx, game, library [OK] game game programs (shaders.rpf) expected 26503 listings 26503 translated 26503 (100.0%) failed 0 [FAIL] library pipeline library compute expected 2684 listings 2684 (944 with rejected words) translated 1844 (68.7%) failed 840 reasons 839 fall-through into undecodable words; 1 s_sethalt cause: llvm-mc 21.x leaves undecodable words (839 refusals; #1923) [FAIL] fspx FidelityFX FSPX expected 29 listings 29 (11 with rejected words) translated 22 (75.9%) failed 7 [OK] bvh BVH builder (52/52) [OK] exe executable (12/12) [WARN] contract modules plain 28433; translator default tagged folders present fspx, bvh, exe, library; absent fspx_compute, fspx_gfx [FAIL] runtime loaded total 28433, fspx 1866, fspx_compute 0, fspx_gfx 0, bvh 52, exe 12; descriptor table plain slot fails slot 67 0x80070057 843; no translated compute shader 843 d3d12 ID3D12Device2::CreatePipelineState failed 4, ID3D12Device2::CreatePipelineState unsupported 1 pipelines compute builds 830 (slow 40); compile gate waits 0 device fault lines 0, device lost lines 0, stalled dispatch lines 0; exit code none logged; boot.ps1: ran its full time limit (783 s), stopped weakest link: library [FAIL]: llvm-mc 21.x leaves undecodable words (839 refusals; #1923) ``` (abridged: the cause lines of the tools, game, fspx, bvh, exe, contract and runtime blocks and the fspx reasons line are left out, and the bvh/exe count lines are shortened) ### Tested - `python -I tests/test_chain_check.py`: 23 tests OK (synthetic work folders built by the test: broken and clean chains, mixed llvm-mc versions, refusal reasons and trace method names closed to what the sources contain, an index entry without its `.spv` is not counted, the 1% threshold on both sides, no names/paths without `--show-paths`, empty and partial folders give n/a or a verdict, `--strict`, `--help` thresholds, digest equal to `make_game.translation_sources_digest()`, UTF-16 log with and without BOM). One test reads the runtime sources and `boot.ps1` and checks the 21 format-string fragments the log patterns depend on, so a reworded log line fails the test instead of silently reporting zero. - `tests/test_runner_calls_all_tests.py` 3 OK, `tests/test_ci_registration.py` 16 OK, all 13 `tests/test_docs_*.py` OK. - `python -I scripts/check_no_game_data.py tools/chain_check.py tests/test_chain_check.py docs/dev-tools.md`: exit 0; `git diff --check origin/main..HEAD` clean. - Real run: a full work folder (26,503 + 2,684 + 29 + 52 + 12 programs) and a 1.25-million-line boot log, about 28 s. GPUs tested: n/a for the tool; the sample report comes from an NVIDIA RTX 4060, driver 610.88 AI-assisted: yes (Claude Code, Claude Opus 5.5, wrote the tool and its test; a second agent reviewed it) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The links between the game files and the GPU fail quietly: an llvm-mc whose
gfx1013 decoder rejects words leaves pipeline library programs untranslated,
a translation from older translator sources keeps loading after the module
contract changed, and the runtime's slot-67 refusals sit in a large log.

tools/chain_check.py reads a make_game.py work folder (and optionally one
run's log) and prints one block per link with OK/WARN/FAIL and the most
likely cause: llvm-mc and spirv-val versions and the translator digest
against this checkout; unpacked, listed and translated programs per family
with up to 5 refusal reasons; tagged/plain modules and runtime folders;
loaded modules, failed slot and D3D12 calls, builds, gate waits, faults and
the exit code. The last line names the weakest link.

Counts and fixed words only: refusal reasons are matched against the
messages rdna2spirv.py raises, anything else counts as "other", and paths
appear only with --show-paths. Exit 0 by default, 1 with --strict on FAIL.
Standard library only; documented in docs/dev-tools.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of TOOL-CHAIN-CHECK found three filters that were not closed:

- a refusal reason's variable part is kept only when it is an instruction
  of tools/rdna2_isa_tables.py (_dpp/_sdwa/_e32/_e64 removed) or a built-in
  exception name; any other token is "#", a reason matching no translator
  message is "other";
- a [d3d12-trace] method is printed only when it is a string literal of
  runtime/shims or runtime/src, or Interface::Method / Interface::SlotN
  built from them; anything else counts as "(other)";
- boot.ps1's ending is accepted in its three forms only, else "other"; an
  exit code it names is used when the log has none.

Also: "device-fault: submitted dispatch" lines are counted apart (a stall
prints them) and the cause reads "device lost, faulted or stalled"; more
modules than programs is WARN; amdgcn reads n/a without a record; a
missing translated index with shard files reads "translation in progress
or interrupted"; a UTF-16 log without BOM is detected from its zero bytes;
the mixed and LEONIDA_DESCRIPTOR_TABLE-forced descriptor table lines are
read.

The test pins each runtime and boot.ps1 format string the regexes depend
on, and covers the missing-.spv count, the 1% bound (99/100 WARN, 197/200
FAIL) and names slipped into trace, digest and reason lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The trace test now feeds PS_Secret::Slot12 and expects one more "(other)";
the reasons test feeds "translator error SecretError" and expects
"translator error #"; the runtime pins add the slot-57 failure fprintf
of d3d12_xs_device.cpp. dev-tools.md says which trace names and digest
endings are printed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:23:57 +00:00
Author
Owner

@⁠GrahamboJangles on GitHub · 2026-11-26 10:11 UTC · original

Ran the suite here rather than only reading it — Windows 11, CPython 3.14 (the author's runs were Linux/3.13), at head 044e27122 vs base a73a57e13.

  • The diff is three new files (+1207/−0, nothing existing touched): tools/chain_check.py, tests/test_chain_check.py, docs/dev-tools.md.
  • python -I tests/test_chain_check.py -v at head, branch pr2231: 23 tests, 23 OK, 6.6 s. The base has no chain_check files (git ls-tree a73a57e13 finds none), so the delta is 0 → 23 — every test exercises the new tool; nothing pre-existing was displaced.
  • Live runs of the tool itself, matching the documented exit-code contract:
    • python -I tools/chain_check.py /nonexistent-folder-xyz → exit 2 (bad arguments);
    • python -I tools/chain_check.py . --no-probe on a folder with no shader tree → all blocks n/a ("not unpacked in this work folder"), exit 0 — the graceful partial-folder path works end to end, not just under unittest.
  • Repo gates at head: python -I scripts/check_no_game_data.py quiet, exit 0 (the new tool and docs pass the no-game-data scan, including the free-text-closing rules in its header); python3 -m compileall -q clean on both new files; python -I tests/test_ci_registration.py -v → 16 tests OK, so the new tool doesn't desync the CI registration tests.
  • Behaviour checks I traced against the code: an index entry whose .spv is absent is not counted as translated (family_block filters present via os.path.isfile, and test_entry_without_module_is_not_translated pins it); the FAIL_FRACTION boundary matches the docstring's "99 of 100 is WARN, 197 of 200 is FAIL" arithmetic and test_threshold_bounds covers both edges; the deliberate broad except (Exception, SystemExit) around the LLVM_MC probe is the one noqa:ed spot, and it is the documented intent ("a broken LLVM_MC is reported, not raised").

Merge state as read today: mergeable=true, mergeStateStatus=unstable with change-scope and no-game-data both pending (no failures) — CI just hadn't settled when I checked.

VERDICT: OK on the evidence I could run — 23/23 local, gates clean, live runs reproduce the documented contract; CPython 3.14 on Windows reproduces the same counts as the author's Linux/3.13 run. I read ~520 of the 775 tool lines closely (helpers, repo side, blocks); the runtime-log tail I lean on the closed-set regexes plus test_utf16_log/test_no_names_or_log_text_printed for, so the free-text closing is test-backed but not personally line-verified end to end.

**@⁠GrahamboJangles** on GitHub · 2026-11-26 10:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2231#issuecomment-7189030840) Ran the suite here rather than only reading it — Windows 11, CPython 3.14 (the author's runs were Linux/3.13), at head `044e27122` vs base `a73a57e13`. - The diff is three new files (+1207/−0, nothing existing touched): `tools/chain_check.py`, `tests/test_chain_check.py`, `docs/dev-tools.md`. - `python -I tests/test_chain_check.py -v` at head, branch `pr2231`: **23 tests, 23 OK, 6.6 s.** The base has no chain_check files (`git ls-tree a73a57e13` finds none), so the delta is 0 → 23 — every test exercises the new tool; nothing pre-existing was displaced. - Live runs of the tool itself, matching the documented exit-code contract: - `python -I tools/chain_check.py /nonexistent-folder-xyz` → exit **2** (bad arguments); - `python -I tools/chain_check.py . --no-probe` on a folder with no shader tree → all blocks `n/a` ("not unpacked in this work folder"), exit **0** — the graceful partial-folder path works end to end, not just under unittest. - Repo gates at head: `python -I scripts/check_no_game_data.py` quiet, exit **0** (the new tool and docs pass the no-game-data scan, including the free-text-closing rules in its header); `python3 -m compileall -q` clean on both new files; `python -I tests/test_ci_registration.py -v` → 16 tests OK, so the new tool doesn't desync the CI registration tests. - Behaviour checks I traced against the code: an index entry whose `.spv` is absent is not counted as translated (`family_block` filters `present` via `os.path.isfile`, and `test_entry_without_module_is_not_translated` pins it); the FAIL_FRACTION boundary matches the docstring's "99 of 100 is WARN, 197 of 200 is FAIL" arithmetic and `test_threshold_bounds` covers both edges; the deliberate broad `except (Exception, SystemExit)` around the LLVM_MC probe is the one noqa:ed spot, and it is the documented intent ("a broken LLVM_MC is reported, not raised"). Merge state as read today: `mergeable=true`, `mergeStateStatus=unstable` with `change-scope` and `no-game-data` both **pending** (no failures) — CI just hadn't settled when I checked. VERDICT: OK on the evidence I could run — 23/23 local, gates clean, live runs reproduce the documented contract; CPython 3.14 on Windows reproduces the same counts as the author's Linux/3.13 run. I read ~520 of the 775 tool lines closely (helpers, repo side, blocks); the runtime-log tail I lean on the closed-set regexes plus `test_utf16_log`/`test_no_names_or_log_text_printed` for, so the free-text closing is test-backed but not personally line-verified end to end.
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 10:12 UTC · original

Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. python -I tests/test_chain_check.py: 23 tests OK with this PR (the tool is new, so there is no main baseline to fail against). compileall clean.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 10:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2231#issuecomment-7189061314) Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. python -I tests/test_chain_check.py: 23 tests OK with this PR (the tool is new, so there is no main baseline to fail against). compileall clean. AI-assisted: yes (Claude Code)
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 11:12 UTC · original · reviewed

Windows 11: 23/23 chain check tests passed, including strict exit status, absent data and path/name redaction in counts-only output. Tested with synthetic fixtures. No findings.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 11:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2231#pullrequestreview-6073136103) · **reviewed** Windows 11: 23/23 chain check tests passed, including strict exit status, absent data and path/name redaction in counts-only output. Tested with synthetic fixtures. No findings. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2231/head:github-bot/gh-2231'
git switch 'github-bot/gh-2231'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2231'
git switch 'github-bot/gh-2231'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2231'
git switch 'github-bot/gh-2231'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2231'
git switch 'main'
git merge --squash 'github-bot/gh-2231'
git switch 'main'
git merge --ff-only 'github-bot/gh-2231'
git switch 'main'
git merge 'github-bot/gh-2231'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.