tools: read each shader's root-layout and used-resource tables from its FSSM record, with a census (FSSM-ROOT-LAYOUT-TABLES) #1445

Merged
QemmHD merged 1 commit from upstream-pr/1445 into main 2026-11-28 11:41:16 +00:00
QemmHD commented 2026-11-25 00:22:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-25T00:22:28Z.


Claimed in the coordination issue as: FSSM-ROOT-LAYOUT-TABLES (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147663051)

What and why

docs/d3d12_vulkan.md §3.5 works out where root arguments arrive from the user SGPRs the shaders read, and it calls the graphics bases (s8 for VS/PS/GS, s16 for mesh) a hypothesis: that census can't see root-parameter indices or a spill. Each native program's FSSM record names two tables that state the layout directly: a root-layout table and a used-resource table. This PR reads them.

  • tools/fssm_root_layout.py (new): root_tables(fssm) returns each program's two tables. It raises FssmLayoutError for a bad header, a record or code range outside the payload, overlapping records, or a table that runs past the payload or overlaps a record, the code or the other table. Its command line prints the tables of a file or folder as JSON, or writes them with --out.
  • tools/root_layout_census.py <your work folder> (new): prints counts per hardware stage. That covers the lowest SGPR a parameter arrives in, dwords per root type, the root types used, the compute spill start, and how many programs agree with the §3.5 hypothesis, with reasons for the rest. It also counts anything that would show the reading to be wrong. With no input, it says so.

The record layout follows VIctory's reading (Marvisak/VIctory, GPL-3.0, crates/victory-shader/src/native.rs). The parser was written for this repository from that layout, and no VIctory code is copied. §3.5 says field by field which parts are VIctory's reading and which this corpus's earlier measurements already support: the two table offsets line up with the header's code_end/meta_ptr words from docs/fssm_crosscheck.md.

No retranslation is needed. tools/fssm_unpack.py and every other file in make_game.py's TRANSLATION_SOURCES are untouched, and neither new file is imported by the translator or make_game.py, so an already translated shader library stays valid. As with any new file under tools/, an interrupted --jobs translation restarts its shard parts.

Nothing here was run on real shader data. The offsets need a census on a real library to confirm; the open questions are listed in §3.5. The runtime doesn't use the tables yet. Wiring them into rt::rootsig::pack_stage is a follow-up, and it complements #974 and #1009 by giving them a measured layout.

Tested

  • python -I tests/test_fssm_root_layout.py: 32 tests on hand-built records. They cover constants, a root descriptor, tables, an immediate sampler, a heap and a spilled compute layout; truncated, overlapping and overflowing tables; every prefix and 4,000 seeded corruptions; both command lines; and a check that the two tools stay out of the translation inputs. Seven hand mutations of the bounds checks each make it fail.
  • test_fssm_unpack, test_pal_stages, test_fssm_header, test_fssm_crosscheck, test_missing_input_exit_codes, test_text_write_line_endings and test_ci_registration pass.
  • The repository-consistency set (test_cmake_, test_shader_stage_resume, test_runtime_paths, test_docs_, test_make_game_, test_check_no_game_data, test_run_semantic_tests, test_ctest_registration): 578 passed, 5 skipped.
  • python -m compileall -q tools scripts make_game.py, and scripts/check_no_game_data.py on the changed files.

GPUs tested: n/a (tooling; no GPU)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • 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 rule)

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5482684021 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1445). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-25T00:22:28Z. --- Claimed in the coordination issue as: FSSM-ROOT-LAYOUT-TABLES (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7147663051) ### What and why `docs/d3d12_vulkan.md` §3.5 works out where root arguments arrive from the user SGPRs the shaders read, and it calls the graphics bases (s8 for VS/PS/GS, s16 for mesh) a hypothesis: that census can't see root-parameter indices or a spill. Each native program's FSSM record names two tables that state the layout directly: a root-layout table and a used-resource table. This PR reads them. - **`tools/fssm_root_layout.py`** (new): `root_tables(fssm)` returns each program's two tables. It raises `FssmLayoutError` for a bad header, a record or code range outside the payload, overlapping records, or a table that runs past the payload or overlaps a record, the code or the other table. Its command line prints the tables of a file or folder as JSON, or writes them with `--out`. - **`tools/root_layout_census.py <your work folder>`** (new): prints counts per hardware stage. That covers the lowest SGPR a parameter arrives in, dwords per root type, the root types used, the compute spill start, and how many programs agree with the §3.5 hypothesis, with reasons for the rest. It also counts anything that would show the reading to be wrong. With no input, it says so. The record layout follows VIctory's reading (Marvisak/VIctory, GPL-3.0, `crates/victory-shader/src/native.rs`). The parser was written for this repository from that layout, and no VIctory code is copied. §3.5 says field by field which parts are VIctory's reading and which this corpus's earlier measurements already support: the two table offsets line up with the header's `code_end`/`meta_ptr` words from `docs/fssm_crosscheck.md`. **No retranslation is needed.** `tools/fssm_unpack.py` and every other file in `make_game.py`'s `TRANSLATION_SOURCES` are untouched, and neither new file is imported by the translator or `make_game.py`, so an already translated shader library stays valid. As with any new file under `tools/`, an interrupted `--jobs` translation restarts its shard parts. **Nothing here was run on real shader data.** The offsets need a census on a real library to confirm; the open questions are listed in §3.5. The runtime doesn't use the tables yet. Wiring them into `rt::rootsig::pack_stage` is a follow-up, and it complements #974 and #1009 by giving them a measured layout. ### Tested - `python -I tests/test_fssm_root_layout.py`: 32 tests on hand-built records. They cover constants, a root descriptor, tables, an immediate sampler, a heap and a spilled compute layout; truncated, overlapping and overflowing tables; every prefix and 4,000 seeded corruptions; both command lines; and a check that the two tools stay out of the translation inputs. Seven hand mutations of the bounds checks each make it fail. - test_fssm_unpack, test_pal_stages, test_fssm_header, test_fssm_crosscheck, test_missing_input_exit_codes, test_text_write_line_endings and test_ci_registration pass. - The repository-consistency set (test_cmake_*, test_shader_stage_resume, test_runtime_paths, test_docs_*, test_make_game_*, test_check_no_game_data*, test_run_semantic_tests, test_ctest_registration): 578 passed, 5 skipped. - `python -m compileall -q tools scripts make_game.py`, and `scripts/check_no_game_data.py` on the changed files. GPUs tested: n/a (tooling; no GPU) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator rule) AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
sodove commented 2026-11-28 11:26:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:26:38Z.


#1445 | head 62137d42f8e5ed3974f6b537fb825f9cea26e4b5 | python3 -I tests/test_fssm_root_layout.py -v, python3 -I tests/test_missing_input_exit_codes.py -v | red: import error (fssm_root_layout absent, 0 tests ran) / 2 run, 2 failures | green: 32 passed / 2 passed | Import and CLI failures → pass

The baseline FSSM test stopped during import. The separate missing-input CLI tests also failed on main. With the merge, 32 FSSM layout tests and both CLI tests passed using synthetic inputs.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238554962 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1445#issuecomment-7238554962). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:26:38Z. --- #1445 | head `62137d42f8e5ed3974f6b537fb825f9cea26e4b5` | `python3 -I tests/test_fssm_root_layout.py -v`, `python3 -I tests/test_missing_input_exit_codes.py -v` | red: import error (fssm_root_layout absent, 0 tests ran) / 2 run, 2 failures | green: 32 passed / 2 passed | **Import and CLI failures → pass** The baseline FSSM test stopped during import. The separate missing-input CLI tests also failed on main. With the merge, 32 FSSM layout tests and both CLI tests passed using synthetic inputs. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:41:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:41:18Z.


Merged, thank you @QemmHD! This PR (tools: read each shader's root-layout and used-resource tables from its FSSM record, with a census (FSSM-ROOT-LAYOUT-TABLES)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238716521 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1445#issuecomment-7238716521). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:41:18Z. --- Merged, thank you @QemmHD! This PR (tools: read each shader's root-layout and used-resource tables from its FSSM record, with a census (FSSM-ROOT-LAYOUT-TABLES)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1445
No description provided.