diff options
| author | YaBulochka <157796093+YaBulochka@users.noreply.github.com> | 2026-11-23 04:26:54 +0300 |
|---|---|---|
| committer | YaBulochka <157796093+YaBulochka@users.noreply.github.com> | 2026-11-23 04:26:54 +0300 |
| commit | bb360f84d924df9759cd1eefa80c272c80118717 (patch) | |
| tree | 8083f7da2b11039ea9b0ab6d711efdc7772b72de /docs/pso_cache.md | |
| parent | 78fe89915e10d84f091a29e316360913748effc3 (diff) | |
Add a reproducible cache extractor and decode the meta chunks
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.
Diffstat (limited to 'docs/pso_cache.md')
| -rw-r--r-- | docs/pso_cache.md | 86 |
1 files changed, 78 insertions, 8 deletions
diff --git a/docs/pso_cache.md b/docs/pso_cache.md index e06c41b74..43cadf906 100644 --- a/docs/pso_cache.md +++ b/docs/pso_cache.md | |||
| @@ -98,27 +98,97 @@ mapping is not proven here. | |||
| 98 | The third dword of a 0x42 chunk takes 26 distinct values shaped like 0x000SSIIRR (0x00070001, 0x000D0201 and so on), | 98 | The third dword of a 0x42 chunk takes 26 distinct values shaped like 0x000SSIIRR (0x00070001, 0x000D0201 and so on), |
| 99 | which is consistent with space/index/register slots, but the fields are not decoded. | 99 | which is consistent with space/index/register slots, but the fields are not decoded. |
| 100 | 100 | ||
| 101 | ## Meta records: what the chunks decode to | ||
| 102 | |||
| 103 | The chunk lists have a fixed order: all 0x41 chunks, then all 0x42 chunks, then exactly one 0x43. That holds for | ||
| 104 | 20,318 of 20,318 records, so one record belongs to one stage. The decode below is measured shape plus an | ||
| 105 | inference per field. | ||
| 106 | |||
| 107 | ### 0x41: user-data entries | ||
| 108 | |||
| 109 | | Word | Role measured | Confidence | | ||
| 110 | |---:|---|---| | ||
| 111 | | +0 | 0x41 kind | high | | ||
| 112 | | +4 | offset, always a multiple of 8, 0..0x820; zero for 0x2, 0x100 and 0x401 | high that it is 8-byte-granular; the table it points into is not identified | | ||
| 113 | | +8 | key 0..0x1fd; repeats, 0 is common | low, it is not a unique binding id | | ||
| 114 | | +0xc | count 0..0x800, 73 distinct for 0x300 | low | | ||
| 115 | | +0x10 | three bytes: `a` (bits 16..31), `b` (bits 8..15), size (bits 0..7) | high on the split, meaning below | | ||
| 116 | | +0x14 | 0xffffffff | measured | | ||
| 117 | | +0x18 | 0 | measured | | ||
| 118 | |||
| 119 | Per kind: 0x401 has offset 0, `b`=0, size 4 and `a`=1..24, consistent with a number of 32-bit constants | ||
| 120 | (medium); 0x2 has offset 0, `b`=5..13 and size 4 (sampler-like, medium); 0x100 has offset 0, `b`=6..11 and | ||
| 121 | size 2 (low); 0x300/0x302/0x303 carry the nonzero offsets, `b`=4..13, and size 4 or 8 (0x300, 0x303) or 4 | ||
| 122 | (0x302). Reading `b` as a register space and `a` as a base register for descriptors, or as a count for 0x401, | ||
| 123 | fits the values but has no independent check (medium/low). | ||
| 124 | |||
| 125 | ### 0x42: register slots | ||
| 126 | |||
| 127 | The slot splits as 0x00SS_IIRR: SS 1..16, II 0..3, RR 1..2. The slots follow the 0x41 descriptors in order. In | ||
| 128 | the 5,230 records where their counts are equal, positional pairing gives II=0 for 23,047 of 23,049 0x300 | ||
| 129 | entries, II=1 for 4,144 of 4,146 0x303 entries and II=2 for all 6,100 0x302 entries. That is the order | ||
| 130 | SRV=0, UAV=1, CBV=2 of D3D12_DESCRIPTOR_RANGE_TYPE, so II is probably the range type (medium-high). SS is | ||
| 131 | probably a register space or table index (medium) and RR (1 or 2) a width (low). | ||
| 132 | |||
| 133 | The 0x2 samplers and the 0x401 constants take no slot at all (0 of 13,897 and 0 of 33,596). Static samplers | ||
| 134 | taking no user-data dwords matches the layer's contract in [d3d12_vulkan.md](d3d12_vulkan.md) 3.5 (medium-high). | ||
| 135 | Another 15,068 records have more slots than descriptors, usually one or two; those extras all have RR=2, a | ||
| 136 | zero key and w4=0, with (SS,II) mostly (14,3), (2,0) or (10,0). They are not decoded (low). | ||
| 137 | |||
| 138 | ### Relation to the 32 user-data dwords | ||
| 139 | |||
| 140 | A 1:1 packing into the 32-dword root-argument block is not supported by the counts. A compute PSO's chunk | ||
| 141 | record has a median of 17 slots (max 281), and 0x41 offsets reach 0x820 (2,080 bytes); 199,074 of 402,328 | ||
| 142 | offsets (49.5%) fit inside 128 bytes, but only 5,581 of 20,318 records have all of theirs inside. The record | ||
| 143 | therefore describes a larger layout than the 32 dwords, and at most half of the 0x41 entries can be part of | ||
| 144 | that block (medium). No mapping from a slot to a user-SGPR index was confirmed. | ||
| 145 | |||
| 146 | ### Which PSOs reference which records | ||
| 147 | |||
| 148 | - A graphics PSO's u32 at +8 names a stage record (sizes 380..520) and +0xC an input-layout record; +0x50..+0x5C | ||
| 149 | are 0xFFFFFFFF in this corpus. | ||
| 150 | - The stage record names chunk records at +4 (entry 4 on 13,409 PSOs, entry 6 on 12,062), at +0x2C (entry 2 on | ||
| 151 | 25,469) and further at +0x78, +0x90, +0x150 and +0x1A4. Graphics PSOs share eight chunk records in total, not | ||
| 152 | one per PSO. | ||
| 153 | - A compute PSO's +8 and +0xC name 20- and 28-byte hash records, +0x10 a mixed record and +0x14 a chunk record | ||
| 154 | (2,693 references, 2,684 distinct records). | ||
| 155 | |||
| 101 | ## What remains unknown | 156 | ## What remains unknown |
| 102 | 157 | ||
| 103 | - The meaning of the two header strings, the 0x48 value and the six 0x41 second-dword values. The SRV/CBV/UAV/sampler | 158 | - The meaning of the two header strings, the 0x48 value and the six 0x41 second-dword values. The SRV/CBV/UAV/sampler |
| 104 | names are the external note's, not this file's. | 159 | names are the external note's, not this file's. |
| 105 | - The encoding of the 0x41 and 0x42 payload dwords and of the 8-byte values in the 0x70 records. The 0x43 16-byte | 160 | - The `a` and `b` bytes of 0x41 w5 and the SS/II/RR meanings of the 0x42 slot word: the readings above are |
| 106 | value was not matched against any hash in the package. | 161 | inferences from value ranges and order, not confirmed by the shader code. |
| 162 | - The encoding of the w3 key and w4 count, and the 15,068 records with extra slots. | ||
| 163 | - The 0x43 16-byte value was not matched against any hash in the package. | ||
| 107 | - The 30,909 meta entries that are not chunk lists. | 164 | - The 30,909 meta entries that are not chunk lists. |
| 108 | - Whether the code blob is raw RDNA2. The evidence is the two marker words and the `s_code_end` filler; no | 165 | - Whether the code blob is raw RDNA2. The evidence is the two marker words and the `s_code_end` filler; no |
| 109 | disassembly or translation was run on this blob. | 166 | disassembly or translation was run on this blob. |
| 110 | 167 | ||
| 111 | ## Checking a carved copy | 168 | ## Checking and carving a copy |
| 169 | |||
| 170 | `tools/psocache_extract.py` finds the cache in an RPF9 archive without the TOC: it walks the archive's stream | ||
| 171 | table in order, inflates each stream to learn its extent, keeps only the first 4 bytes, and stops at the first | ||
| 172 | stream whose output starts with the magic. It then appends the following contiguous streams (up to 1 MiB of zero | ||
| 173 | padding) until the header's declared total is reached, writes the file under the temporary directory and runs | ||
| 174 | the checks below. `--budget` bounds the compressed bytes examined and `--max-streams` the number of streams; a | ||
| 175 | source folder is scanned in sorted order and the report names the archive index and the stream offset, never the | ||
| 176 | path. | ||
| 177 | |||
| 178 | ``` | ||
| 179 | python -I tools/psocache_extract.py <archive.rpf|folder> <cache-in-tmp> | ||
| 180 | ``` | ||
| 112 | 181 | ||
| 113 | `tools/psocache_inspect.py` reads the cache file only: | 182 | `tools/psocache_inspect.py` reads the cache file only: |
| 114 | 183 | ||
| 115 | ``` | 184 | ``` |
| 116 | python -I tools/psocache_inspect.py <cache> | 185 | python -I tools/psocache_inspect.py <cache> --meta |
| 117 | ``` | 186 | ``` |
| 118 | 187 | ||
| 119 | It checks the magic, reads the four counts and two sizes above, bounds all six regions against the file, checks that | 188 | It checks the magic, reads the four counts and two sizes above, bounds all six regions against the file, checks that |
| 120 | the meta index is contiguous over the meta blob and that every shader entry stays inside the code blob, parses the | 189 | the meta index is contiguous over the meta blob and that every shader entry stays inside the code blob, parses the |
| 121 | chunk lists and counts `s_endpgm` and `s_code_end` in the code blob. It prints offsets, sizes and counts, names every | 190 | chunk lists and counts `s_endpgm` and `s_code_end` in the code blob. `--meta` adds the aggregate 0x41/0x42 decode |
| 122 | field that does not fit instead of stopping, and exits 0 when the regions add up to the file size, 1 on a | 191 | described above, `--entry N` lists one meta index entry and `--limit N` bounds how many records `--meta` reads. It |
| 123 | disagreement and 2 when the file is not a cache. `--json` prints the same report as JSON. It does not decode a chunk, | 192 | prints offsets, sizes and counts, names every field that does not fit instead of stopping, and exits 0 when the |
| 124 | disassemble the code or verify a hash. | 193 | regions add up to the file size, 1 on a disagreement and 2 when the file is not a cache. `--json` prints the same |
| 194 | report as JSON. It does not decode a chunk payload, disassemble the code or verify a hash. | ||