shader_library: keep each state of a compute program, select by code hash (TOOLS-LIBRARY-COMPUTE-BY-HASH) #1281
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1281
Loading…
Reference in a new issue
No description provided.
Delete branch "split/tools-library-compute-by-hash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Rebased onto
bfef489cat570db1d5. Main already supports selecting by hash and writing distinct state variants. This diff omits the redundant stateless output when a program also has stateful records, improves the diagnostics and retains the output and overlap tests. All 25 shader-library tests passed.Claimed in the coordination issue as: TOOLS-LIBRARY-COMPUTE-BY-HASH (claim).
Part of the split of #984 into small pull requests.
Depends on: none
Overlaps: #984 is the parent integration. #583 and #998 (both open) change one line inside the loop this pull request rewrites in
tools/shader_library.py("prologue": start == fspx_unpack.PROLOGUE_SIZEbecomesstart > 0), and #998 also addscompute=Trueto thedisasm.disasm(...)call below it. Neither is repeated here: the integration branch carried thestart > 0line together with this change, and it is left as main has it. Merged three-way (each PR's diff applied to the base, then merged into this branch), #583 and #998 each conflict intools/shader_library.pyat that one place, because the line they change is next to a line this change removes; the resolution keeps their line. #1021 merges cleanly.What and why
Two changes to
tools/shader_library.py, the tool that unpacks the pipeline library ofshaders.rpf.1. Each state of a compute program gets its entry. The run time finds a library compute program by two keys, the SHA-256 of its code and of its record's state blob (
docs/fspx.md, "Build and run-time lookup"), andmake_game.pyalready allows "the same kind-6 bytes with different kind-0 entries" in the translation index. The tool, however, kept one state per program:so when two compute records used one program with different state blobs, the last record's blob was written as
fspx/<name>.stateand the other pair of keys had no entry at all: no.state, no listing, nothing for the translator to build.Now every distinct state is written. The first one met keeps the program's name; each further one is written as
<name>_state_<blob index>with its own.code,.json,.state, listing, carved container andindex.jsonentry. Records whose blobs hold the same bytes share an entry, a record without a state names the program itself, andlibrary.jsonnames the entry each record means. A program with a single state is written exactly as before. That is every program of the measured library:docs/shader_library.mdcounts one distinct state-blob index per compute program in 1.0.2.1 (2,684 programs, 2,693 records), so this is a latent fault there and not one that was seen to lose a pipeline. No retail library was read for this pull request.2.
--compute-hashes FILE. Writes only the compute programs whose code has one of the SHA-256 digests listed inFILE(whitespace-separated, any case): thefspx_code_sha256of the translation index, which is also the key under which the run time looks a program up. Every state such a program is used with is written. It replaces--stages(argparse refuses both together) and needs--out. A file that cannot be read, is empty or holds a word that is not 64 hex digits is a usage error, and a digest that no compute program has is an error; both are reported before any output is created. The digest is the one the run time prints for a program it has no translation for ([rt] d3d12: no translated compute shader for FSPX kind-6 ... sha256 <digest>,runtime/shims/d3d12_vulkan_device.cpp), so the programs a run reported can be unpacked and disassembled without unpacking the whole library.library.jsonkeeps both whole pipeline tables whatever was selected, as with--stages.Tested
Linux (CachyOS, kernel 7.3.5), Python 3.14. One commit on
6293c1c4f.python3 -I tests/test_shader_library.py: 24 tests pass (21 before, 3 new). The new ones use one synthetic library: a compute program with three state blobs, two of them the same bytes, and one record without a state; a second compute program that uses one of those blobs; a pixel program.test_program_with_two_states_gets_an_entry_for_each(--stages cs): three entries with.code,.jsonand.stateeach; the two entries of the first program have the same code key and each its own state key (shader_meta.collect);library.jsonnames the right entry for all five records;--saveonto the further state's file is refused before anything is written.test_compute_hashes_select_programs_by_their_code: a file with the digest in upper case between blank lines selects the first program with both states and nothing of the second;library.jsonkeeps both tables.test_compute_hashes_are_checked_before_anything_is_written:--stagestogether with the option, the option without--out, an empty file, a blank one, 63 digits, a second word that is no digest, a0xprefix and a missing file are usage errors; an unknown digest and the pixel program's digest are errors; no output folder exists afterwards.6293c1c4fwith only the test file replaced): all 3 new tests fail. On that library the base writes two entries and two.statefiles: the first program has no entry with its second state, andlibrary.jsongives that record the same name as the others. The option does not exist there.python3 -I tests/test_library_shaders_stage.py(17 tests, themake_game.pystep that runs this tool) andtests/test_fspx_shaders_stage.py(24 tests): pass.python3 -I tests/test_docs_cli_flags.py(4 tests, the flags the docs name exist): passes.ci.ymlruns it (compileall, everytests/test_*.pyoutsidetests/semantic, the semantic suite, the tracked-file guard), on the committed tree: one failing file,tests/test_imhex_patterns.py, which fails on the base commit too and is the only one there. Semantic suite: 470 files, 6,168 tests, 0 files failed, the same counts as the base.python3 -I scripts/check_no_game_data.py: passes.Not run: a retail
shaders.rpf(so no count of programs with more than one state beyond the figure already in the docs), themake_game.pylibrary step on real data, llvm-mc on the new entries' listings (the new tests do not use--disasm), native Windows or macOS, the runtime build (no C++ or build file changes).GPUs tested: none (a file unpacker).
AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.
Checklist
6293c1c4f, one commit.docs/design.md; the option and the naming are indocs/shader_library.md.🤖 Generated with Claude Code
Reviewed 570db1d: runs of tests/test_shader_library.py on the PR (25/25 pass) and on main with the PR's test file copied in (the 3 new tests fail there, the 22 others pass), plus tests/test_library_shaders_stage.py on both trees (17 OK, 1 skip: no spirv-as/spirv-val here). Probes on synthetic libraries (stateless-first mixed program, blob dedup, stateless-only, --compute-hashes edges) found no bug: outputs stay self-consistent, stateless-only extraction is byte-identical to main, and an empty --compute-hashes filename now errors instead of silently ignoring the filter. One note: main already keeps every distinct state and per-record names since #984, so the real delta here is the stateless-record alias and the --compute-hashes polish, not the message's premise. AI-assisted review.
Recommendation: Merge