Repository navigation
shader_library: keep each state of a compute program, select by code hash (TOOLS-LIBRARY-COMPUTE-BY-HASH) - #1281
Conversation
…hash (TOOLS-LIBRARY-COMPUTE-BY-HASH) The run time finds a pipeline-library compute program by the SHA-256 of its code and of its record's state blob. shader_library.py kept one state per program, the last record's, so when two compute records used one program with different state blobs only one of the two pairs got an entry and a .state file. Each distinct state of a program is now written: the first under the program's name, each further one as <name>_state_<blob index>, with its own .code, .json, .state, listing and index entry. library.json names the entry of each record. A program with one state, the case of every program in the measured 1.0.2.1 library, is written exactly as before. --compute-hashes FILE writes only the compute programs whose code has one of the SHA-256 digests listed in FILE, with every state they are used with. It cannot be combined with --stages, and a digest no compute program has is an error before anything is written. tests/test_shader_library.py gets three tests on a synthetic library; all three fail on the base. The standard-library tests and the translator suite add no failing file. No retail library was read for this change. AI-assisted (Claude Code). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
66cad1b to
570db1d
Compare
|
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 |
37 upstream commits after 86dc3d8: ProjectLeonida#2138 (integration/boot-combined), ProjectLeonida#2094 (geometry-view eviction on range release, reaped after the replays that may name them), ProjectLeonida#998/ProjectLeonida#1317/ProjectLeonida#1281/ProjectLeonida#583 heads (pipeline-library compute programs by code hash, shader_disasm prints the dot4 op_sel words llvm-mc rejects, FSPX short prologue with the literal-form check), null-resource texture barriers and null-view RTV clears on the console list, and the removal of the title's executable addresses from code (read from the environment). Conflicts, on merit: - d3d12_xs_device.cpp: both. Our title heap sync (LEONIDA_TITLE_HEAP_SYNC) and upstream's null-RTV marks sit side by side; heap_release unregisters the sync or the range as before and also drops the heap's null-RTV marks; CreateDescriptorHeap keeps our desc argument and takes upstream's RTV real range. Our value-op/upload-ring slots and upstream's slot 146 barrier conversion both stay. - startup_trace.h: our thread and watchdog-table logging stays, and follows upstream's rule: the watchdog table's store and table RVAs come from LEONIDA_WATCHDOG_TABLE (off when unset, documented in runtime/README.md); upstream's environment-driven pool diagnostic replaces the fixed address. - fspx_unpack.py: ours (the code end is found from one rdna2_decode pass, not an llvm-mc run per s_endpgm: the OOM and 15-minute fix). Its test takes upstream's short-prologue case, which checks the literal form our code also requires. - rdna2spirv.py: ours (s_bitreplicate_b64_b32 into VCC in wave32 stays translated: 6 pipeline-library programs), plus the point behind upstream's refusal: in wave32 VCC's high word is data, so it is now written to vcc_hi as source bits 16..31 replicated (replicate_bits16, shared with the scalar form). Tests: ours kept, one added for the vcc_hi word; test_salu_flbit_64 keeps ours (this tree translates i64 of a lane mask). - xs_proxy_mock_test.cpp: upstream's empty Barrier call, our chained-submission reference count. Every line the merge removes from our side is upstream's own or one of the resolutions above (checked against the merge base, D:\GTA6\analysis\lostlines.sh). The touched Python suites pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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