Repository navigation
tools: extract, inspect, decode and map the PS\0\x09 PSO/shader cache - #4358
YaBulochka wants to merge 4 commits into
Conversation
tools/psocache_inspect.py reads a cache that starts with the PS\0\x09 magic and checks it against the 0x80 header, 0x70 graphics record, 0x18 compute record and 8-byte index layout: it bounds every region, checks that the meta index covers the meta blob and the shader index stays inside the code blob, parses the meta chunk lists (0x41/0x42/0x43) and counts s_endpgm and s_code_end in the code blob. A file that disagrees is printed region by region and the in-bounds checks still run; the exit code is 0 for the model, 1 for a disagreement, 2 for input that is not a cache. tests/test_psocache_inspect.py builds a synthetic cache (a 0x80 header, two graphics records, one compute record, two index entries, chunk records and two programs) and covers the model, an out-of-range record reference, a truncated file, a bad magic and a short file.
docs/pso_cache.md records the PS\0\x09 blob: the 0x80 header fields and which of their meanings are unproven, the 0x70 and 0x18 record regions, the two 8-byte index tables, the meta chunk records (0x41/0x42/0x43, the six 0x41 second-dword values and the 0x42 slot-shaped values), the s_endpgm and s_code_end markers and why their counts differ from the shader count. It also lists what is still unknown and how tools/psocache_inspect.py checks a carved copy. docs/README.md gets one row for the page.
|
Tested
Verified layout verification and bounds inspection logic against the documented 0x80 header / 0x70 / 0x18 record structures using synthetic test fixtures. AI-assisted. No game files. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 78fe8991 on Windows 11: python -I tests/test_psocache_inspect.py -> 10 tests, OK; compileall and git diff --check clean.
The tool and docs describe the measured PS\0x09 cache format with synthetic images only. No blocking issue.
tools/psocache_extract.py walks an RPF9 archive's stream table in order, inflates each stream to learn its extent and stops at the first stream whose output starts with the cache magic. It joins the following contiguous streams until the header's declared total is reached, writes the file inside the temporary directory and validates it with psocache_inspect. A --budget and --max-streams bound the search; a folder is scanned in sorted order and the report carries the archive index and the archive-internal stream offset only. psocache_inspect.py gains --meta (with --entry N and --limit N): it reports the chunk-record order, the per-kind 0x41 fields, the 0x42 slot bytes and the 0x41-kind to 0x42-middle-byte correlation over the records whose counts match. The 0x43 value is never printed. docs/pso_cache.md records the decoded shape with a confidence per claim and the remaining unknowns; docs/README.md names the new tool. tests/test_psocache_extract.py builds synthetic RPF9 archives and covers the contiguous split, folder scan, budget, stream limit, truncated chain and an output path outside the temporary directory. The inspect test now covers the meta decode, an entry listing and the CLI flags.
|
At Within each of those two records, the predicted and observed counts match for every class. A pairing that preserves class therefore exists in both records. Slot order could account for all four exceptions. The intended descriptor-to-slot bindings remain unknown. This check covers only equal-length lists. Method: map descriptor kinds |
|
I also checked the 15,068 records with more For this check I matched as many descriptors and slots of each class as possible within each record, using the three proposed kind→class mappings. Of 337,783 observed slots and 313,360 predictions, 313,333 match by class. The remaining slots comprise 15,617 in classes already predicted for that record, 149 in classes 0–2 absent from its predictions, and 8,684 in class 3. The net surplus reconciles to 24,423 after subtracting the 27 missing predictions. These counts describe class inventories. The roles of the extra slots remain open. Tested the per-record counting method on seven synthetic records, including simultaneous excess and deficit, zero predicted descriptors, and an out-of-vocabulary class. Windows 11, Ryzen 5 3600, CPython 3.14.10, CPU only. AI-assisted with Codex and Claude. |
tools/psocache_usersig.py resolves a graphics PSO to the chunk records its stage record names, decodes each 0x41 entry (kind, offset, key, count, space/base/size) and each 0x42 slot word (SS, II, RR), and computes the 32-dword cost as constants + 2 tables and as constants + 1 table. --limit N summarises the first N graphics PSOs, --entry N prints one, --json dumps the same report. It reuses the cache parser from psocache_inspect and never prints a hash. docs/pso_cache.md maps the graphics records to descriptor tables, ranges and 32-bit constants with a confidence per claim, gives the measured fit numbers and sketches how a CreateGraphicsPipelineState path would consume them. tests/test_psocache_usersig.py builds a two-PSO cache that covers SRV, UAV, CBV, Sampler, constants, a record that does not fit 32 dwords and extra slots, and checks the summary, the entry listing, --limit, --json and the error paths.
|
Checked I also calculated what the same records would cost under two hypothetical combined budgets. Both sum constants across distinct referenced records.
This makes the scope of the documentation’s fit claim explicit: every referenced record fits individually. Determining whether the runtime shares constants, tables, or budgets across stages requires separate binding evidence. Three synthetic controls passed, including repeated references and shared SS labels. All 28 upstream cache tests passed. Windows 11, Ryzen 5 3600, CPython 3.14.10, CPU only. AI-assisted with Codex and Claude. |
Adds the tools and the measured documentation for the game's PSO/shader cache (
PS\0\x09): an inspector, a reproducible extractor, a meta-chunk decoder, a graphics user-signature describer, anddocs/pso_cache.md. The cache sits compressed inside an RPF9 archive; the decompressed file is 275,540,780 bytes and every declared region sums to the file size with zero slack.Verified from the real cache
count × 0x70(25,471), computecount × 0x18(2,693), meta indexcount × 8(54,576), shader indexcount × 8(21,522), then meta blob then code blob;s_code_end, so it is alignment filler and 26,092s_endpgmis not 21,522 records;Meta chunks
Every list record is all
0x41chunks, then all0x42, then exactly one0x43, so a record belongs to one stage.0x41carries kind, an 8-byte-aligned offset, key, count, a packed register triple and a size of 2/4/8 bytes.0x42is a slot word0x00SS_IIRR; where the counts line up,IIis 0 for0x300(SRV) in 23,047 of 23,049 chunks, 1 for0x303(UAV) in 4,144 of 4,146, and 2 for all 6,1000x302(CBV), matchingD3D12_DESCRIPTOR_RANGE_TYPEorder.0x2sampler chunks and0x401never get a slot, consistent with static samplers not consuming user-data dwords. A record is not the 32-dword user-data block: offsets reach 0x820 and only 49.5% of0x41chunks fit in 128 bytes (5,581 of 20,318 records entirely).Graphics user signature
tools/psocache_usersig.pyreads a graphics PSO's chunk records and describes the user-data set: one distinctSSper descriptor table, one(SS, II)per range, one0x401per 32-bit-constants parameter, with element sizes 2/4/8 and the root-argument cost of the record. On the real cache every one of the 25,471 graphics PSOs fits the 32-dword contract under both cost models (15 dwords with 2 per table); the graphics records carry SRV 90,500, UAV 182,958, CBV 102,562 and 32-bit constants 90,500, and no sampler chunks. The doc records each field with a confidence, and states what is still ambiguous:SSversus register space, the table order,key/count,0x100, the extra slots withRR=2, whether a table costs 1 or 2 dwords, and whether0x43is the shader hash.Tools
tools/psocache_inspect.py: validates the magic, bounds every region, checks meta-index continuity and shader-index bounds, histograms chunk types and code markers,--meta/--entry/--limitdecode the chunk records.tools/psocache_extract.py: finds the cache in an RPF9 archive deterministically, inflates the stream chain (bounded by--budget/--max-streams), writes only to the system tmp, and validates the result with the inspector. On the real archive it stops at the first match in ~4.5 s and produces a byte-identical file on repeat.tools/psocache_usersig.py: the graphics user-signature describer above.tests/test_psocache_inspect.py(14),tests/test_psocache_extract.py(7) andtests/test_psocache_usersig.py(7) build synthetic caches and archives; no game data.pyteston the three test files: 28 passed. Docs tests andscripts/check_no_game_data.pyare clean;docs/pso_cache.mdhas no game bytes, dump file names or paths.