diff options
| author | Diesel <dev.diesel@proton.me> | 2026-11-21 22:44:07 +0100 |
|---|---|---|
| committer | Diesel <dev.diesel@proton.me> | 2026-11-21 22:44:07 +0100 |
| commit | 5c1a1fbb6bf6f609eb4e61baa4961ce382743a4e (patch) | |
| tree | ac8ad90058b97ab241fdc65edae3d4628d20ee1e /docs/textures.md | |
| parent | c45309e29f21c1d5b75678db0e2dc2dd11cff25b (diff) | |
| parent | 4e390e0871d7265e629b51aca8ff99a15a6a6845 (diff) | |
Merge main to include the compute Y/Z harness test fix
Diffstat (limited to 'docs/textures.md')
| -rw-r--r-- | docs/textures.md | 195 |
1 files changed, 173 insertions, 22 deletions
diff --git a/docs/textures.md b/docs/textures.md index 7ed20c0ae..52b085931 100644 --- a/docs/textures.md +++ b/docs/textures.md | |||
| @@ -16,8 +16,9 @@ field. | |||
| 16 | | skipped | 48,220 | | 16 | | skipped | 48,220 | |
| 17 | 17 | ||
| 18 | **Bottom line:** the gap is measurable and the codec mapping is certain, but BCPack itself is | 18 | **Bottom line:** the gap is measurable and the codec mapping is certain, but BCPack itself is |
| 19 | not decodable from public facts. No decoder is added; the next tractable work is the compact | 19 | not decodable from public facts. No BCPack decoder is added. The compact mip chain, which the |
| 20 | packed tail, not BCPack. | 20 | first measurement called the next tractable work, is now decoded and validated below; the |
| 21 | remaining gap is BCPack. | ||
| 21 | 22 | ||
| 22 | This is the same 308,895 / 48,220 total already recorded in `docs/design.md`. The recount | 23 | This is the same 308,895 / 48,220 total already recorded in `docs/design.md`. The recount |
| 23 | splits the 48,220 by cause: the old "(BCPack or unmapped)" label hides 14,713 skips whose | 24 | splits the 48,220 by cause: the old "(BCPack or unmapped)" label hides 14,713 skips whose |
| @@ -96,8 +97,137 @@ The partial exports are a separate gap. Of the 210,292: | |||
| 96 | 97 | ||
| 97 | The packed-tail gap affects more textures than the BCPack skip count (196,257 partial | 98 | The packed-tail gap affects more textures than the BCPack skip count (196,257 partial |
| 98 | exports vs 33,507 skips), but it loses only the small mips. It is also not a BCPack problem: | 99 | exports vs 33,507 skips), but it loses only the small mips. It is also not a BCPack problem: |
| 99 | 196,257 textures stop at the last standalone mip because `UsableMipLimit = NonTailMipCount` | 100 | 196,257 textures stop at the descriptor's `non_tail` field because `UsableMipLimit = |
| 100 | for compact profiles, regardless of codec. | 101 | NonTailMipCount` for compact profiles, regardless of codec. The next section measures that |
| 102 | field against the layout and finds that it is not the tail boundary: most of the "packed | ||
| 103 | tail" is standalone mips the reader drops. | ||
| 104 | |||
| 105 | ## The compact mip chain | ||
| 106 | |||
| 107 | The 196,257 partial exports and the 14,030 compact-profile skips are the same layout | ||
| 108 | problem, not a codec problem. `tools/ttpf_mips.py` measures and decodes it; the counts below | ||
| 109 | come from its `scan` and `check` over the same 57 pools. | ||
| 110 | |||
| 111 | ### The descriptor mode is a flag plus a tile mode | ||
| 112 | |||
| 113 | `TtpfReader` reads the descriptor mode as one number (`b >> 23`) and selects a 64 KiB tile | ||
| 114 | only for mode 0. The observed values split into a low flag bit and a 4-bit Gfx10 tile mode at | ||
| 115 | bit 1: | ||
| 116 | |||
| 117 | | `(mode >> 1) & 0xF` | Gfx10 mode | Tile | Descriptors | | ||
| 118 | |---:|---|---:|---:| | ||
| 119 | | 0 | `SW_64KB_D` | 64 KiB | 39,283 | | ||
| 120 | | 1 | `SW_4KB_S` | 4 KiB | 70,497 | | ||
| 121 | | 2 | `SW_4KB_S` | 4 KiB | 195,957 | | ||
| 122 | | 3 | `SW_4KB_S` | 4 KiB | 50,811 | | ||
| 123 | | 9–12 | array/volume | — | 567 | | ||
| 124 | |||
| 125 | Modes 9–12 are exactly the 567 cube descriptors; the other 111 array/volume records use tile | ||
| 126 | mode 0 or 1. Bit 0 of the field is independent: modes 4/5 share tile mode 2, 6/7 share tile | ||
| 127 | mode 3, and 36/38 share tile modes 2/3. The reader's `mode == 0` test therefore gives a 4 KiB | ||
| 128 | layout to modes 1 and 32, which are 64 KiB. Fifteen mode 1/32 descriptors have a known element | ||
| 129 | size; all fifteen match a 64 KiB allocation span and one (`maps_4_7` #6034) decodes at | ||
| 130 | 0.00–0.33 levels (see below). The other 19 mode 1/32 records are the unknown-format ones in | ||
| 131 | the table below. | ||
| 132 | |||
| 133 | ### The layout is the AMD mip tail | ||
| 134 | |||
| 135 | The compact profile is the Gfx10 mip chain: standalone mips are padded to whole blocks and | ||
| 136 | stored smallest-first; a mip whose element count fits half a tile width and a tile height, | ||
| 137 | among the last 8 (4 KiB) or 12 (64 KiB) mips, goes into one shared tile at offset 0 at the | ||
| 138 | AMD entry offset (`m = max_tail - 1 - k`; `entry = m > 6 ? 16 << m : m << 8`). | ||
| 139 | |||
| 140 | On all 356,413 2D descriptors with a known element size — the 232,789 already-trusted compact | ||
| 141 | exports, the 14,011 layout-capable records the profile table rejects, and every non-compact | ||
| 142 | mode — the computed size equals `next_allocation - base`. There are **0 mismatches**. The | ||
| 143 | remaining 702 descriptors are 678 arrays/volumes and 24 formats without an element-size | ||
| 144 | mapping. | ||
| 145 | |||
| 146 | ### `non_tail` is not the layout boundary | ||
| 147 | |||
| 148 | The descriptor's 3-bit `non_tail` field (`b & 7`) is where the reader stops, and its note calls | ||
| 149 | the remaining mips "packed tail". The bytes do not follow that split: | ||
| 150 | |||
| 151 | - 177,111 of the 232,789 compact exports have `non_tail < first_tail`; 214,298 standalone | ||
| 152 | mips lie beyond the limit, 204,108 of them in zlib/raw chunks. | ||
| 153 | - 196,257 partial exports stop exactly at `non_tail`; 158,272 of them stop **before** the | ||
| 154 | computed tail boundary, and only 37,985 stop at it. | ||
| 155 | - Of the 1,072,068 missing mips, 1,065,138 are in zlib/raw chunks. That decodable part splits | ||
| 156 | into 193,019 standalone mips and 872,119 packed-tail mips; the other 6,930 missing mips (in | ||
| 157 | 1,166 textures) touch BCPack. | ||
| 158 | |||
| 159 | `UsableMipLimit = NonTailMipCount` therefore drops decodable standalone mips, not only the | ||
| 160 | tile. The allocation spans and the decoded content both put the tail at the computed index. | ||
| 161 | |||
| 162 | ### The 14,030 profile-table records | ||
| 163 | |||
| 164 | | | Textures | | ||
| 165 | |---|---:| | ||
| 166 | | same layout, new tuple (4 KiB) | 13,956 | | ||
| 167 | | same layout, modes 5/7/34/38 | 40 | | ||
| 168 | | same layout, 64 KiB (modes 1/32) | 15 | | ||
| 169 | | **layout resolved** | **14,011** | | ||
| 170 | | format without an element-size mapping | 19 | | ||
| 171 | | **total** | **14,030** | | ||
| 172 | |||
| 173 | - 11,570 have every mip in a zlib/raw chunk: all 35,727 mips decode (2.91 GiB decompressed). | ||
| 174 | - 469 more have a zlib/raw tail tile but a BCPack larger mip, so only their lower mips can be | ||
| 175 | exported. | ||
| 176 | - The 19 blocked records are mode 1 (64 KiB) with DXGI formats 156, 199, 211 and 226; the | ||
| 177 | format-to-element-size mapping is the only unknown, not the mip layout. | ||
| 178 | |||
| 179 | The five DXGI 11 (`R16G16B16A16_UNORM`) records are a separate one-line gap: DXGI 11 is 8 | ||
| 180 | bytes per element, but the vendored element table has no entry. Their layout then matches, | ||
| 181 | but uncompressed tiling is not validated, so they are not exported here. | ||
| 182 | |||
| 183 | ### Sample validation | ||
| 184 | |||
| 185 | `tools/ttpf_mips.py check` detiles one chain, decodes BC1/BC3/BC4/BC5 and compares each mip | ||
| 186 | with a 2x2 box downsample of its parent at BC-block resolution (one block is 4x4 pixels). A | ||
| 187 | correct chain is 0–4 levels, as in the SixNG notes; the control is the first tail mip detiled | ||
| 188 | at origin (0,0). | ||
| 189 | |||
| 190 | | Pool # | Descriptor | Mips | non_tail / first_tail | Max error | Tail control | | ||
| 191 | |---|---|---:|---:|---:|---:| | ||
| 192 | | `interiors_0_3` #19 | 512×256 BC1 | 7 | 1 / 3 | 0.38 | 126.06 | | ||
| 193 | | `interiors_0_3` #10 | 512×512 BC1 | 8 | 3 / 3 | 0.46 | 57.94 | | ||
| 194 | | `graphics` #43 | 64×512 BC1 | 10 | 1 / 3 | 1.08 | 132.31 | | ||
| 195 | | `interiors_2_3` #468 | 512×512 BC1 | 8 | 3 / 3 | 0.60 | 113.83 | | ||
| 196 | | `maps_0_7` #3217 | 128×128 BC1 | 6 | 0 / 1 | 0.79 | 114.71 | | ||
| 197 | | `peds_1_3` #527 | 512×512 BC1 | 8 | 3 / 3 | 3.87 | 83.83 | | ||
| 198 | | `maps_1_7` #1500 | 128×256 BC4 | 6 | 1 / 2 | 0.34 | 72.08 | | ||
| 199 | | `decorations_0_3` #818 | 128×128 BC5 | 6 | 1 / 2 | 0.02 | 85.48 | | ||
| 200 | | `interiors_1_3` #507 | 256×256 BC3 | 7 | 1 / 2 | 1.21 | 51.84 | | ||
| 201 | |||
| 202 | `interiors_0_3` #19 is a partial export: the reader emits one mip, while all seven decode and | ||
| 203 | match. `graphics` #43 and `interiors_2_3` #468 are tuples outside the table; `maps_0_7` #3217 | ||
| 204 | is mode 34 with `non_tail = 0`, which would leave zero standalone mips even if the mode gate | ||
| 205 | passed. | ||
| 206 | |||
| 207 | BC7 was checked on two samples with an external decoder (Pillow, not a dependency of the | ||
| 208 | tool): `terrain_4_7` #23 (512×512, 3 mips, 0.35–0.49) and `maps_4_7` #6034 (1024×1024, mode | ||
| 209 | 32, 64 KiB, 0.00–0.33, control 4.44). | ||
| 210 | |||
| 211 | For `interiors_0_3` #19 the tool reports the byte layout: mip 0 (512×256, 128×64 blocks) at | ||
| 212 | 24,576, mip 1 (256×128, 64×32) at 8,192, mip 2 (128×64, 32×16) at 4,096, then the 4 KiB tile | ||
| 213 | at 0 with mip 3 (64×32 px, 16×8 blocks) at origin (16,0), mip 4 (32×16 px, 8×4) at (8,8), | ||
| 214 | mip 5 (16×8 px, 4×2) at (0,12) and mip 6 (8×4 px, 2×1) at (0,8). The mip byte sizes 65,536 / | ||
| 215 | 16,384 / 4,096 / 1,024 / 256 / 64 / 16 are exactly the BC1 block counts, and the exported DDS | ||
| 216 | is 87,524 bytes (148 + 87,376). | ||
| 217 | |||
| 218 | ### What this unlocks | ||
| 219 | |||
| 220 | "Decompressed" is the block-linear BC payload size (`blocks × block bytes`), not the inflated | ||
| 221 | chunk size, which includes tile padding. | ||
| 222 | |||
| 223 | | | Textures | New mips | Decompressed | | ||
| 224 | |---|---:|---:|---:| | ||
| 225 | | partial exports that become complete | 195,091 | 1,065,138 | 1.69 GiB | | ||
| 226 | | compact skips that become complete | 11,570 | 35,727 | 2.91 GiB | | ||
| 227 | | **total** | **206,661** | **1,100,865** | **4.59 GiB** | | ||
| 228 | |||
| 229 | 1,166 of the 196,257 partials still miss 6,930 mips that touch BCPack; those and the 33,507 | ||
| 230 | fully blocked textures wait on the codec. Nothing here decodes BCPack. | ||
| 101 | 231 | ||
| 102 | ## What BCPack is | 232 | ## What BCPack is |
| 103 | 233 | ||
| @@ -265,25 +395,46 @@ and the algorithm class are known; the bitstream is not. | |||
| 265 | 395 | ||
| 266 | ## Next step | 396 | ## Next step |
| 267 | 397 | ||
| 268 | 1. **Do not fake a BCPack decoder.** The current fallback (export the largest lower mip that | 398 | 1. **Port the tile-mode split and the computed tail boundary.** In `TtpfReader`, select |
| 269 | is zlib/raw) is used by 5,845 textures and should stay. | 399 | `tile = 65536` when `((mode >> 1) & 0xF) == 0` and 4096 otherwise, replace |
| 270 | 2. **Fix the compact packed tail first.** 196,257 of the 210,292 partial exports stop at | 400 | `ValidatedCompactProfile` with the allocation-span check, and set `UsableMipLimit` to the |
| 271 | `NonTailMipCount`; the tail layout is documented (SixNG §5) and needs no BCPack decoder. | 401 | computed `FirstTail` (or `mips` when the tail tile is zlib/raw). On this install that |
| 272 | This is the largest tractable texture gap. | 402 | completes 206,661 textures without touching BCPack. |
| 273 | 3. **Then the small independent gaps:** 678 array/volume layouts and 5 DXGI 11 textures. | 403 | 2. **Decode BC6H/BC7 in the validator.** `tools/ttpf_mips.py` decodes BC1/3/4/5; the BC7 |
| 274 | Neither needs BCPack. | 404 | samples were checked with an external decoder. The layout is the same formula (16-byte |
| 275 | 4. **If a public decoder or bitstream spec appears under a compatible licence,** add it behind | 405 | elements), so this is validation breadth, not a new mapping. |
| 276 | `TtpfReader.DecodeChunk`; the container already carries the mode (codec id) and decoded | 406 | 3. **Identify DXGI 156/199/211/226 (19 records) and validate uncompressed tiling (formats |
| 277 | size, so no index work is needed. | 407 | 11, 28, 49, 56).** These are the remaining non-BCPack blockers besides arrays. |
| 278 | 5. **If someone resumes the reverse engineering,** use the hard check the SixNG notes propose: | 408 | 4. **Arrays/volumes: 678 descriptors.** 567 use tile modes 9–12 and 111 are 2-slice; no |
| 279 | every lane must consume exactly its byte budget and finish at the rANS lower bound, with a | 409 | validated slice layout exists yet. |
| 280 | fixed symbol count. Reference blocks are the missing input; none are public. | 410 | 5. **Do not fake a BCPack decoder.** The current fallback (export the largest lower mip that |
| 411 | is zlib/raw) is used by 5,845 textures and should stay. If a public decoder or bitstream | ||
| 412 | spec appears under a compatible licence, add it behind `TtpfReader.DecodeChunk`; the | ||
| 413 | container already carries the mode (codec id) and decoded size, so no index work is | ||
| 414 | needed. | ||
| 415 | 6. **If someone resumes the BCPack reverse engineering,** use the hard check the SixNG notes | ||
| 416 | propose: every lane must consume exactly its byte budget and finish at the rANS lower | ||
| 417 | bound, with a fixed symbol count. Reference blocks are the missing input; none are public. | ||
| 281 | 418 | ||
| 282 | ## Reproduce | 419 | ## Reproduce |
| 283 | 420 | ||
| 421 | `tools/ttpf_mips.py` is the read-only measurement and decode tool: | ||
| 422 | |||
| 423 | ``` | ||
| 424 | python -I tools/ttpf_mips.py scan <game root> --json scan.json | ||
| 425 | python -I tools/ttpf_mips.py layout <pool.ttpf> <index> | ||
| 426 | python -I tools/ttpf_mips.py check <pool.ttpf> <index> | ||
| 427 | python -I tools/ttpf_mips.py export <pool.ttpf> <index> <out.dds> | ||
| 428 | ``` | ||
| 429 | |||
| 430 | `scan` reproduces the 357,115 / 98,603 / 210,292 / 48,220 split of this note and adds the | ||
| 431 | layout and recovery columns. `check` reports the per-mip downsample error. `export` writes a | ||
| 432 | full BC chain only when every source mip is zlib/raw. The tool writes no texture data and | ||
| 433 | `tests/test_ttpf_mips.py` runs on a synthetic RDS5 pool, so the test needs no game files. | ||
| 434 | |||
| 284 | `rpf9dump ttpf` writes one `manifest.json` per pool with a `Limitation` field for every | 435 | `rpf9dump ttpf` writes one `manifest.json` per pool with a `Limitation` field for every |
| 285 | catalog record, and its summary line has the same `ok` / `skip` totals. The split above comes | 436 | catalog record, and its summary line has the same `ok` / `skip` totals. The first split above |
| 286 | from a read-only mirror of `TtpfReader`'s catalog checks: it mmaps each pool and reads only | 437 | came from a read-only mirror of `TtpfReader`'s catalog checks: it mmapped each pool and read |
| 287 | the 24-byte RDS5 header, the chunk table, the ETPF records and the chunk ranges. It writes no | 438 | only the 24-byte RDS5 header, the chunk table, the ETPF records and the chunk ranges, and it |
| 288 | texture data. The mirror is not committed because it duplicates `TtpfReader`; the counts are | 439 | wrote no texture data. `tools/ttpf_mips.py scan` is that mirror, now committed with the |
| 289 | the evidence. | 440 | compact-layout work; it reproduces the split and adds the recovery columns. |