Skip to content

tools: sgd5_pass_pipelines.py turns every stored SGD5 pass into a shader_link_check batch manifest - #5207

Open
Pipodi wants to merge 4 commits into
ItsNotRexed:mainfrom
Pipodi:pass-manifest
Open

Pipodi wants to merge 4 commits into
ItsNotRexed:mainfrom
Pipodi:pass-manifest

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new SHADER item, building the graphics pipelines the effect database defines (claim). This is its census step; #5199 is the translator fix the census found.

Depends on: none. The tool runs on main. On main the link check it enables reports the 301 VS+GS+PS failures that #5199 fixes.

What and why

Today the pipeline check pairs each translated shader with a stub partner, and shader_link_check.py checks only pairs listed by hand. The game's own pairings are known: every stored SGD5 pass (tools/sgd5_effects.py, docs/sgd5_render_states.md) names its VS or MS (+GS) + PS and selects rasterizer, depth/stencil and blend rows.

tools/sgd5_pass_pipelines.py <shaders.rpf> <carve index.json> --out manifest.json [--spirv-dir DIR] [--passes passes.json]:

  • Walks every stored pass of both databases. It joins each program to the carve index by program_identity()'s carve offset and names it by the entry's file stem, which is unique; display names repeat. Two different index entries at one offset are an error, so the result never depends on the index order (found by @kacper-serewis); the real index has 26,503 distinct offsets.
  • Writes a shader_link_check.py batch manifest with one pipeline per distinct graphics programme set that has a PS, sorted, named pNNNNN_<first stem>.
  • Skips compute passes, passes with no program or no PS, and stage sets batch does not take (shader_link_check.CHAINS), and counts each. With --spirv-dir, it also leaves out sets whose .spv is missing.
  • --passes writes one row per pass with its programs and the raster/depth/blend selector bytes, for the next step: creating the pipelines with their real partners and states.
  • If no set is left (for example an empty --spirv-dir), it prints the counts and exits 1 without writing the manifest, because batch refuses an empty list (found by @whattheflop).
  • Same guards as read_database: the SGD5 signature and a truncated region. Stdlib only. The archive is opened read-only and each effect region is read once, with no mmap.

A paragraph in docs/sgd5_render_states.md says how to run it with batch.

Tested

Windows 11, own 1.0.2.1 copy, Python 3.13.

  • Real run (about 10 s): 28,798 passes. 16,325 distinct graphics sets with a PS written. Skipped: 2,863 compute, 3,560 with no PS, 1 with no program. Stage mix: ms+ps 17,145; vs+ps 4,865; vs+gs+ps 364; ms alone 3,525; vs alone 35. The manifest is byte-identical across every follow-up commit up to the head.
  • shader_link_check.py batch on that manifest over a full translation of main 3faac55 (LLVM 23.1.5): 16,024 compatible, 301 incompatible (all VS+GS+PS, fixed by rdna2spirv: number GS varyings by rank past SV_Position, as the VS and PS do #5199). On rdna2spirv: number GS varyings by rank past SV_Position, as the VS and PS do #5199's head: 16,325 compatible, 0 incompatible.
  • python -I tests/test_sgd5_pass_pipelines.py (synthetic databases from tests/test_sgd5_effects.py's builders: VS+PS, VS+GS+PS, compute skipped, a duplicate set written once, state bytes in --passes, the --spirv-dir filter, ms+gs+ps skipped, nothing left → exit 1 and no manifest, conflicting index entries refused in both orders): OK. tests/test_sgd5_effects.py, tests/test_ci_registration.py, tests/test_docs_links.py, tests/test_text_write_line_endings.py and python -m compileall -q tools tests: OK.
  • Independent run by @Kev-Ball on CachyOS, own 1.0.2.1 copy, against both translations of their make_game: the shaders stage translates with --opt unless --no-spirv-opt (-36.5% SPIR-V) #4760 run (optimization off and on) (comment): the same 28,798 passes and 16,325 pipelines, every module present; batch gives the same 301 VS+GS+PS incompatible and 0 invalid, and all 16,325 reports match across the toggle. @Atomic258: the test passes at the head and fails on the parent commit.
  • No translator change, so no corpus run of its own.

AI-assisted: yes (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Counts only; the test databases are synthetic; the manifest and pass rows stay in the user's work folder.
  • 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

Pipodi and others added 2 commits November 23, 2026 09:48
…der_link_check batch manifest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… keep only the stage sets shader_link_check takes

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

Copy link
Copy Markdown

Checked the SGD5 manifest at 0e8354b5 against both translations from my #4760 run (Xbox 1.0.2.1, translator 690b9711, wave64 emulation, optimization off and on). The real carve index and archive yielded 28,798 passes and 16,325 distinct graphics pipelines. Every referenced module was present in both translations.

I ran shader_link_check.py batch twice with that same manifest and default linkage rules, then compared each pipeline’s status, link count and diagnostics. All 16,325 reports matched across the optimization toggle. Both runs classified 12,221 MS+PS and 3,803 VS+PS pipelines as compatible. The same 301 VS+GS+PS pipelines were incompatible, with zero invalid pipelines. This independently reproduces the reported pre-#5199 result and checks that enabling #4760’s optimization preserves the observed stage interfaces under this check.

CPU-only on CachyOS. This was static shader linkage; Vulkan pipeline creation with the real partners and render states remains a separate test. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — PASS: test_sgd5_pass_pipelines.py 3/3 at head; parent fails 1 (SGD5 signature/truncated-region checks absent). AI-assisted (Devin); no game files.

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Kev-Ball. Same 28,798 / 16,325 from your own carve, and the same 301 on a different translator head, is the reproduction this needed. Running the manifest across #4760's optimization toggle is a use I hadn't thought of. Pipeline creation with the real partners in vk_pipeline_check is the next step, and is under way. Thanks @Atomic258 for the parent-commit control. Both added to Tested.

AI-assisted (Claude Code).

@whattheflop

Copy link
Copy Markdown
Contributor

Independent AI-assisted Windows end-to-end CLI check at 0e8354b5. The carver recovered nine DXC-compiled programs from two synthetic SGD5 databases. The generator resolved repeated display names by carve offset, retained the expected state selectors and reduced 11 passes to six distinct pipelines. Reordering the carve index left the manifest byte-identical. Omitting the GS module removed exactly the two geometry chains.

Using the full manifest, batch reported 4 compatible / 2 incompatible with this branch's translator, and 6 / 0 with #5199 5e576dbe. Only the GS binary changed, and all eight modules per revision passed Vulkan 1.2 validation. This checks static interfaces and the actual CLI handoff.

One normal case breaks the documented handoff: a valid empty --spirv-dir filters out all sets, and the generator exits 0 with {"version":1,"pipelines":[]}. Batch then exits 2 with pipelines must be a nonempty list. The producer and batch reader need to agree on the empty result. Synthetic inputs and CPU only.

…ch batch refuses

Reported by whattheflop in ItsNotRexed#5207: an empty --spirv-dir left no set, the tool wrote
{"pipelines": []} and exited 0, and shader_link_check.py batch then exited 2.

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

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @whattheflop, good catch. Fixed in 2e1c588: when no set is left, the tool prints its counts and exits 1 without writing the manifest, since batch refuses an empty list. A test covers it (an empty --spirv-dir gives exit 1 and no file). The real run is unchanged: it still writes 16,325 sets. Added to the body.

AI-assisted (Claude Code).

@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 0e8354b conflicting carve-index entries sharing an offset silently change the selected shader. Reversing the index in a six-pass synthetic case changed the pixel shader in two passes. Both orders reported five resolved rows and two pipelines. Please reject conflicting entries at the same offset and test both input orders. The cached index had 26,503 distinct offsets in 26,503 entries. All 12,221 distinct stored mesh/pixel offset pairs in the independent inventory mapped correctly. That inventory does not retain state selectors or pass multiplicity.

AI-assisted independent review.

…offset

Reported by kacper-serewis in ItsNotRexed#5207: with such entries the selected shader depended on the
index order. The same entry listed twice is still accepted.

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

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis, agreed. Fixed in a4a87ba: census() now raises when two different carve-index entries share an offset, and the CLI prints one error line and exits 1. The same entry listed twice is still accepted. The new test puts a conflicting PS entry at the end and then at the start of your six-pass case, and expects the error in both orders, plus the harmless duplicate. On the real index (26,503 distinct offsets, as you found) the manifest is byte-identical at the head. Thanks also for the 12,221 MS/PS offset-pair cross-check.

AI-assisted (Claude Code).

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted Windows rerun at a4a87bab of the same six-pipeline CLI fixture. The all-filtered case now exits 1 with no pipeline left to write, creates no new manifest, and preserves an existing manifest byte-for-byte. The requested pass report is still written. This closes the empty-manifest handoff finding.

Repeating an identical carve entry in either order left both reports unchanged. Two independently carved shaders at the same offset were rejected in either order, with exit 1 and no output files. The canonical six-pipeline manifest and stage results were unchanged, and all five focused tests passed. Synthetic inputs only.

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

Whole-package follow-up on the earlier 0e8354b revision: 28,797/28,797 emitted pass rows agreed with an independent walk in stored order, including raster, depth and blend selectors. Of 28,798 stored passes, one selected no program. Removing 2,863 compute passes and 3,560 without a pixel shader left 22,374 graphics occurrences and 16,325 distinct pipelines before the optional SPIR-V availability filter. The check reused effect-boundary parsing and program-offset resolution but decoded technique lengths, pass selectors and state bytes separately. This comparison predates a4a87ba.

AI-assisted independent CPU review.

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

The conflicting-offset finding is resolved at a4a87ba. Both index orders returned status 1 and preserved both existing outputs. An identical duplicate yielded byte-identical output. All five focused tests passed. This was a synthetic CPU recheck; the whole-package row comparison reported earlier ran at 0e8354b.

AI-assisted independent review.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested a4a87ba on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_sgd5_pass_pipelines.py -> Ran 5 tests, OK
  • New tool - no upstream/main control possible; tests import and exercise it.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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.

5 participants