diff options
| author | Kam471 <115741199+Kam471@users.noreply.github.com> | 2026-11-21 18:24:25 +0000 |
|---|---|---|
| committer | Kam471 <115741199+Kam471@users.noreply.github.com> | 2026-11-21 18:26:19 +0000 |
| commit | df87229ce4dec9e2f40cffd208b88977befbca6f (patch) | |
| tree | 5a1f1efffa1144db258496f24a5b1e80619a157a /docs/textures.md | |
| parent | 793b06f12765571ed5e126d1d8944cec6a4dc805 (diff) | |
docs: measure the BCPack texture gap and the next step
Diffstat (limited to 'docs/textures.md')
| -rw-r--r-- | docs/textures.md | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/docs/textures.md b/docs/textures.md new file mode 100644 index 000000000..7ed20c0ae --- /dev/null +++ b/docs/textures.md | |||
| @@ -0,0 +1,289 @@ | |||
| 1 | # Textures: the BCPack gap | ||
| 2 | |||
| 3 | Measured on 2026-11-21 from one retail Xbox Series install (1.0.2.1). The corpus is all 57 | ||
| 4 | RDS5 texture pools: 46 under `data/ttdb/**` and 11 under `pack/<name>/data/ttdb/**`, 57.94 GiB | ||
| 5 | of files. Nothing below reproduces game data; every number is an aggregate or a descriptor | ||
| 6 | field. | ||
| 7 | |||
| 8 | ## Outcome | ||
| 9 | |||
| 10 | | | Textures | | ||
| 11 | |---|---:| | ||
| 12 | | catalog entries | 357,115 | | ||
| 13 | | exported with the complete source mip chain | 98,603 | | ||
| 14 | | exported with fewer mips | 210,292 | | ||
| 15 | | exported at least one mip | 308,895 | | ||
| 16 | | skipped | 48,220 | | ||
| 17 | |||
| 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 | ||
| 20 | packed tail, not BCPack. | ||
| 21 | |||
| 22 | 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 | recorded limitation is a layout/format check, not the codec, and overstates unmapped, which | ||
| 25 | is zero. | ||
| 26 | |||
| 27 | ## Skip breakdown | ||
| 28 | |||
| 29 | | Cause | Textures | | ||
| 30 | |---|---:| | ||
| 31 | | BCPack blocks every usable mip (`TtpfReader`: "All source mips require…") | 33,507 | | ||
| 32 | | compact mip mapping not in the validated profile table | 14,030 | | ||
| 33 | | 2D array / volume descriptor (`dimension != 1` or `depth != 1`) | 678 | | ||
| 34 | | element format not in the parser table (DXGI 11, `R16G16B16A16_UNORM`) | 5 | | ||
| 35 | | no mapped allocation ("unmapped shard") | 0 | | ||
| 36 | | **total** | **48,220** | | ||
| 37 | |||
| 38 | The compact row is not one thing: | ||
| 39 | |||
| 40 | - 13,979 of the 14,030 carry the descriptor's auxiliary-mapping bits. 13,954 of those are | ||
| 41 | mode 4 or 6; the other 25 are modes 5, 7, 36 and 38. The other 51 compact records are modes | ||
| 42 | 1, 32 or 34 without the aux flag. | ||
| 43 | - 11,570 of the 14,030 have no BCPack chunk anywhere. They fail because | ||
| 44 | `ValidatedCompactProfile` has no entry for their | ||
| 45 | `(mode, width, height, mips, nonTail, bytes)` tuple, not because of a codec. | ||
| 46 | - 19 compact records could not be mapped to a layout for the storage cross-tab. They are | ||
| 47 | included in the 14,030 and also fail the profile table. | ||
| 48 | |||
| 49 | The five format-11 records are 4×4, 8×4 or 128×4 `R16G16B16A16_UNORM`; the parser's | ||
| 50 | element-size table has no 8-byte entry for format 11. The 678 array/volume records are | ||
| 51 | non-2D descriptors (arrays or volumes), which the reader deliberately rejects until it has a | ||
| 52 | validated slice layout. | ||
| 53 | |||
| 54 | ## The BCPack footprint | ||
| 55 | |||
| 56 | The skip count is only the fully blocked textures. Counting mip 0 and the lower mips | ||
| 57 | independently of the parser's profile checks gives the full footprint: | ||
| 58 | |||
| 59 | | mip 0 | lower mips | Textures | | ||
| 60 | |---|---|---:| | ||
| 61 | | zlib/raw | zlib/raw | 305,264 | | ||
| 62 | | BCPack | at least one zlib/raw | 14,935 | | ||
| 63 | | zlib/raw | at least one BCPack | 9,999 | | ||
| 64 | | BCPack | every mip BCPack | 26,215 | | ||
| 65 | | no usable layout | — | 702 | | ||
| 66 | | **total** | | **357,115** | | ||
| 67 | |||
| 68 | - **41,150 textures have BCPack in mip 0** (26,215 + 14,935). | ||
| 69 | - **26,215 have no zlib/raw mip at all**, so they cannot export anything. | ||
| 70 | - 5,845 export from a lower mip because mip 0 is BCPack (`BaseMipLevel > 0`). | ||
| 71 | - 9,090 of the 14,935 are still skipped: 8,515 because no usable mip is entirely zlib/raw | ||
| 72 | (the zlib block is mixed with BCPack or outside the usable range), 575 because the compact | ||
| 73 | profile is not validated. | ||
| 74 | - 9,356 export the top mip but stop before at least one BCPack lower mip; 643 more are | ||
| 75 | skipped for the compact profile before an export can happen. | ||
| 76 | |||
| 77 | Cross-tabulated against the skip table: | ||
| 78 | |||
| 79 | | Parser cause | all zlib | mip 0 zlib, lower BCPack | mip 0 BCPack, lower zlib | all BCPack | no layout | total | | ||
| 80 | |---|---:|---:|---:|---:|---:|---:| | ||
| 81 | | BCPack | 0 | 0 | 8,515 | 24,992 | 0 | 33,507 | | ||
| 82 | | compact profile | 11,570 | 643 | 575 | 1,223 | 19 | 14,030 | | ||
| 83 | | array/volume | 0 | 0 | 0 | 0 | 678 | 678 | | ||
| 84 | | format 11 | 0 | 0 | 0 | 0 | 5 | 5 | | ||
| 85 | | **total** | **11,570** | **643** | **9,090** | **26,215** | **702** | **48,220** | | ||
| 86 | |||
| 87 | The partial exports are a separate gap. Of the 210,292: | ||
| 88 | |||
| 89 | | Partial reason | Textures | | ||
| 90 | |---|---:| | ||
| 91 | | compact profile, standalone mips exported, packed tail missing | 196,257 | | ||
| 92 | | lower mips BCPack | 8,052 | | ||
| 93 | | catalog top-only record | 314 | | ||
| 94 | | other (lower-mip export, mixed ranges) | 5,669 | | ||
| 95 | | **total** | **210,292** | | ||
| 96 | |||
| 97 | 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 | 196,257 textures stop at the last standalone mip because `UsableMipLimit = NonTailMipCount` | ||
| 100 | for compact profiles, regardless of codec. | ||
| 101 | |||
| 102 | ## What BCPack is | ||
| 103 | |||
| 104 | BCPack is the Xbox Series hardware decompression codec for BCn texture data. The public GDK | ||
| 105 | enum exposes seven modes, one per BCn format (BC1–BC7); DirectStorage applies it after DEFLATE | ||
| 106 | and before the optional swizzle. It is not a replacement for BCn: it is an entropy-coded | ||
| 107 | preconditioner whose output is a standard BCn block stream. That is why a BCPack chunk has a | ||
| 108 | BCn codec id, not a separate texture format, and why the container can mix zlib and BCPack | ||
| 109 | chunks inside one texture. | ||
| 110 | |||
| 111 | ## What the container says | ||
| 112 | |||
| 113 | The RDS5 index is readable without game code: | ||
| 114 | |||
| 115 | | Field | Value | | ||
| 116 | |---|---| | ||
| 117 | | magic | `RDS5` at 0x00 | | ||
| 118 | | virtual size | 56 bits at 0x08; top byte 0x16 | | ||
| 119 | | entry count | u32 at 0x04; `chunks = count − 2`, and the table's last entry is the sentinel | | ||
| 120 | | chunk table | 0x18, 8 bytes per entry, `(count − 1) * 8` bytes | | ||
| 121 | | ETPF index | `align(0x18 + (count − 1) * 8, 0x100)`; version 634 (`0x27A`) | | ||
| 122 | | texture records | a 16-byte ETPF header, then `area` bytes of records (at least 16 × textures) | | ||
| 123 | | asset keys | one u64 per record after the descriptor array; IDs are 32 bytes each | | ||
| 124 | |||
| 125 | Chunk entry `(u64 value)`: | ||
| 126 | |||
| 127 | | Field | Bits | Meaning | | ||
| 128 | |---|---:|---| | ||
| 129 | | physical offset | 0–25 | × 256; 256-byte aligned | | ||
| 130 | | codec | 26–29 | 0 raw, 1–7 BCPack BC1–BC7, 8 zlib | | ||
| 131 | | virtual offset | 30–51 | × 4096; 4 KiB aligned | | ||
| 132 | | padding | 52–63 | 12-bit byte count at the end of the physical range | | ||
| 133 | |||
| 134 | The parser reads 357,115 texture records and 1,026,833 chunks from the 57 pools with no | ||
| 135 | exceptions. The chunk table's offsets are 256-byte aligned (physical) and 4 KiB aligned | ||
| 136 | (virtual), and the virtual ranges cover every allocation the parser could lay out. The | ||
| 137 | 12-bit padding on BCPack chunks is zero-filled (see the header section). | ||
| 138 | |||
| 139 | ### Codec ids are the BCPack mode | ||
| 140 | |||
| 141 | The on-disk codec ids are `0x04, 0x0C, 0x10, 0x14, 0x18, 0x1C, 0x20`; shifting right by 26 | ||
| 142 | normalizes them to 1, 3, 4, 5, 6, 7, 8. Across **1,026,833 chunks there is not one | ||
| 143 | format/codec mismatch**: | ||
| 144 | |||
| 145 | | codec | BCn mode | DXGI formats seen | Chunks | Packed MiB | Decoded MiB | Saving | | ||
| 146 | |---:|---|---|---:|---:|---:|---:| | ||
| 147 | | 0 | raw | 83, 98, 99 | 5 | 0.1 | 0.1 | 0.0% | | ||
| 148 | | 1 | BC1 | 71, 72 | 102,725 | 10,637.9 | 14,630.9 | 27.3% | | ||
| 149 | | 2 | BC2 | — | 0 | — | — | — | | ||
| 150 | | 3 | BC3 | 77, 78 | 35 | 7.4 | 10.1 | 26.3% | | ||
| 151 | | 4 | BC4 | 80 | 77 | 1.4 | 1.5 | 6.2% | | ||
| 152 | | 5 | BC5 | 83 | 333 | 60.6 | 74.6 | 18.8% | | ||
| 153 | | 6 | BC6H | 95, 96 | 268 | 67.8 | 79.1 | 14.2% | | ||
| 154 | | 7 | BC7 | 98, 99 | 5,167 | 1,097.3 | 1,221.5 | 10.2% | | ||
| 155 | | 8 | zlib (RFC 1950) | all | 918,223 | 47,179.3 | 128,529.3 | 63.3% | | ||
| 156 | | **total** | | | **1,026,833** | **59,051.8** | **144,547.1** | **59.1%** | | ||
| 157 | |||
| 158 | BCPack is 11.6 GiB of the 57.7 GiB chunk payload (20.1%), and BC1 is 10.4 GiB of that | ||
| 159 | (89.6%). The saving column is `1 − Σ packed / Σ decoded`; it includes tile padding, so it is | ||
| 160 | not the codec's saving on block data alone. | ||
| 161 | |||
| 162 | This mapping is the strongest evidence that the codec field is the GDK's | ||
| 163 | `DSTORAGE_BCPACK_MODE` (1 = BC1 … 7 = BC7), not a generic compression id. The field is per | ||
| 164 | chunk, so a texture can mix zlib and BCPack mips; 15,201 partial exports do. | ||
| 165 | |||
| 166 | ### The descriptor `mode` is tiling, not codec | ||
| 167 | |||
| 168 | The ETPF descriptor's `mode` field (`b >> 23`) is the mip/tile family: mode 0 uses 64 KiB | ||
| 169 | blocks (`SW_64KB_D`), every other observed mode uses 4 KiB blocks (`SW_4KB_S`). It is | ||
| 170 | independent of the chunk codec. Formats 71/72 use 8-byte BC1 blocks, 74/75/77/78/83/84/95/96/ | ||
| 171 | 98/99 use 16-byte blocks, and 80/81 use 8-byte BC4 blocks. No BC2 (codec 2) texture exists in | ||
| 172 | this install. | ||
| 173 | |||
| 174 | ## The chunk header | ||
| 175 | |||
| 176 | A BCPack chunk is not a self-describing container. A 256-byte dump of the first chunk of | ||
| 177 | each of the three entries below contains no magic, version, total length or format at offset | ||
| 178 | 0. The only readable structure is the lane record area: | ||
| 179 | |||
| 180 | - The independent SixNG notes describe the first 48 bytes as eight lane records, | ||
| 181 | column-interleaved: one byte per lane per round, six rounds. The byte-1 regularity below is | ||
| 182 | consistent with that layout. | ||
| 183 | - The rest is entropy-coded lane data (rANS renormalization and prefetch in the SixNG | ||
| 184 | description). Entropy on 300 sampled chunks per codec is 7.96–7.99 bits/byte. No | ||
| 185 | general-purpose wrapper was found in the sampled chunks; zlib, gzip, bzip2 and LZMA reject | ||
| 186 | the first bytes, and raw-deflate attempts on random data are not a valid stream. | ||
| 187 | - Padding is zero-filled: every padding run starts with zero bytes (checked `min(16, pad)` | ||
| 188 | bytes of all 108,229 padded BCPack chunks: 102,368 BC1, 35 BC3, 76 BC4, 332 BC5, 268 BC6H, | ||
| 189 | 5,150 BC7). That is how the physical ranges reach the next 256-byte boundary. | ||
| 190 | |||
| 191 | Three skipped entries, with the fields the container actually exposes: | ||
| 192 | |||
| 193 | | Pool / index | Descriptor | Allocation | Chunks | | ||
| 194 | |---|---|---:|---| | ||
| 195 | | `graphics/ttdb_graphics.ttpf` #309 | 128×128 BC1_UNORM, 8 mips, mode 2 (4 KiB) | 12,288 B | 1 × codec 1: packed 7,648, pad 544 | | ||
| 196 | | `ui/ttdb_ui.ttpf` #0 | 512×512 BC1_UNORM, 1 mip, mode 0 (64 KiB) | 131,072 B | 1 × codec 1: packed 87,933, pad 899 | | ||
| 197 | | `terrain/ttdb_terrain_0_7.ttpf` #1537 | 512×1024 BC7_UNORM, 8 mips, mode 4 (4 KiB) | 700,416 B | 4 × codec 7; top chunk packed 499,734 of 524,288, pad 234 | | ||
| 198 | |||
| 199 | The first two bytes of those payloads are lane 0 and lane 1 modes: `0x1f 0xde`, | ||
| 200 | `0x35 0xde`, and `0x30 0x30`. The full-corpus counts are the useful part: | ||
| 201 | |||
| 202 | | Codec | Chunks | Byte 1 value | Count | | ||
| 203 | |---|---:|---|---:| | ||
| 204 | | 1 (BC1) | 102,725 | `0xde` | 102,725 / 102,725 | | ||
| 205 | | 3 (BC3) | 35 | `0xdb` | 35 / 35 | | ||
| 206 | | 4 (BC4) | 77 | `0xde` | 77 / 77 | | ||
| 207 | | 5 (BC5) | 333 | `0xdb` | 333 / 333 | | ||
| 208 | | 6 (BC6H) | 268 | `0x30`–`0x36` | 268 / 268 | | ||
| 209 | | 7 (BC7) | 5,167 | `0x30`–`0x33` | 4,978 / 5,167 | | ||
| 210 | |||
| 211 | The byte-1 value is constant within a codec (BC1/BC4 use `0xde`, BC3/BC5 use `0xdb`), and it | ||
| 212 | is the only fixed-offset value found. Byte 0 is often `0x30`–`0x37` on BC1, but the rest | ||
| 213 | includes `0x14`–`0x1f`, `0x5f` and `0xde`, so it is not a magic. BC6H uses only `0x30`–`0x36`; | ||
| 214 | BC7 has no constant byte 1 and its remaining 189 records use `0xdb`, `0x1c`–`0x1e` and | ||
| 215 | similar lane modes. The 256-byte dumps are not committed because they are game bytes; the | ||
| 216 | table above and the container descriptors are the readable facts. | ||
| 217 | |||
| 218 | ## Public sources and licences | ||
| 219 | |||
| 220 | | Source | Facts used | Licence / use | | ||
| 221 | |---|---|---| | ||
| 222 | | [DSTORAGE_BCPACK_MODE](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/enums/dstorage_bcpack_mode) | Modes 1–7 are BC1, BC2, BC3, BC4, BC5, BC6H, BC7; Xbox Series only | [Microsoft Learn Terms of Use](https://learn.microsoft.com/en-us/legal/termsofuse): informational, personal/non-commercial use; linked and paraphrased, no text or code copied | | ||
| 223 | | [DirectStorage overview](https://learn.microsoft.com/en-us/gaming/gdk/docs/features/console/storage/directstorage/directstorage-overview) | BCPack is a custom entropy coder for BCn data; colour endpoints are separated from palette indices and coded with rANS; decompression order is DEFLATE, BCPack, swizzle | Same Microsoft Learn terms; linked and paraphrased | | ||
| 224 | | [SixNG, `formats/06-bcpack.md`](https://github.com/walkthestars/GTA6-Asset-Info/blob/main/formats/06-bcpack.md) | Independent notes: 0% decoded, no public specification or decoder, lane/header observations, open unknowns | [GPL-3.0](https://github.com/walkthestars/GTA6-Asset-Info/blob/main/LICENSE); notes only, no code copied | | ||
| 225 | | [SixNG, `formats/05-ttpf.md`](https://github.com/walkthestars/GTA6-Asset-Info/blob/main/formats/05-ttpf.md) | Independent codec-id table and pool structure | GPL-3.0; notes only | | ||
| 226 | | [rpf9-explorer](https://github.com/breadbbbb/rpf9-explorer) | The `TtpfReader` catalog checks and limitation strings measured here | [MIT](https://github.com/breadbbbb/rpf9-explorer/blob/main/README.md) | | ||
| 227 | | [GitHub repository search `bcpack`](https://github.com/search?q=bcpack&type=repositories) | No BCPack decoder; the only GTA VI result is the GPL-3.0 notes above | Search on 2026-11-21 | | ||
| 228 | |||
| 229 | Microsoft's documentation gives the algorithm class and the mode enum, not the bitstream. | ||
| 230 | The public enum is documented for Xbox Series consoles; this note does not cover an Xbox One | ||
| 231 | variant. No public bitstream specification and no open-source BCPack decoder were found: the | ||
| 232 | SixNG notes are documentation, and the only open code found for this format is the container | ||
| 233 | parser (`rpf9-explorer`, MIT). The SixNG notes reach the same conclusion from the data: the | ||
| 234 | rANS coder and stream layout are partly mapped, there is no decoder, and BC1 is the only mode | ||
| 235 | studied beyond its headers. | ||
| 236 | |||
| 237 | ## Why there is no decoder in this change | ||
| 238 | |||
| 239 | A clean-room decoder needs a published bitstream description or a reference implementation | ||
| 240 | under a compatible licence. Neither was found publicly. The public facts stop well short of a | ||
| 241 | block decoder: | ||
| 242 | |||
| 243 | 1. **Models.** The rANS frequency tables for the endpoint planes and the adaptive models for | ||
| 244 | the index lanes are not published. Without them the symbol stream cannot be decoded. | ||
| 245 | 2. **Record layout.** Varying plane and extension lanes have no understood byte-length field; | ||
| 246 | the constant lanes do, but they are only the easy case. | ||
| 247 | 3. **Lane semantics.** What lane 0 codes, how the four index lanes map to 2-bit indices, and | ||
| 248 | how extension lanes are ordered are unknown. | ||
| 249 | 4. **Block order and timing.** Whether blocks are linear or swizzled, and exactly when a lane | ||
| 250 | reads versus decodes within a round, are not settled. | ||
| 251 | 5. **Modes.** Public notes only studied BC1; BC4, BC5 and BC7 streams are unstudied beyond | ||
| 252 | their headers. | ||
| 253 | |||
| 254 | The payload is **not** a documented BC7 or BC6H variant. BCPack decompresses *to* standard | ||
| 255 | BC1–BC7 blocks; the compressed stream is a separate entropy-coded representation. A decoder | ||
| 256 | built from synthetic blocks would test our guesses, not the format. | ||
| 257 | |||
| 258 | The console-side decompressor is hardware; the GDK implementation is not public source and | ||
| 259 | is not usable in a GPL-3.0 program. This change does not link it, copy it or work around it. | ||
| 260 | No DRM, key or protection work was done; only already-plain chunk bytes were read. | ||
| 261 | |||
| 262 | **What is missing, in one line:** the rANS models, the varying/extension lane record | ||
| 263 | layouts, lane-0/index-lane semantics, block order, and the BC4/5/6H/7 streams. The container | ||
| 264 | and the algorithm class are known; the bitstream is not. | ||
| 265 | |||
| 266 | ## Next step | ||
| 267 | |||
| 268 | 1. **Do not fake a BCPack decoder.** The current fallback (export the largest lower mip that | ||
| 269 | is zlib/raw) is used by 5,845 textures and should stay. | ||
| 270 | 2. **Fix the compact packed tail first.** 196,257 of the 210,292 partial exports stop at | ||
| 271 | `NonTailMipCount`; the tail layout is documented (SixNG §5) and needs no BCPack decoder. | ||
| 272 | This is the largest tractable texture gap. | ||
| 273 | 3. **Then the small independent gaps:** 678 array/volume layouts and 5 DXGI 11 textures. | ||
| 274 | Neither needs BCPack. | ||
| 275 | 4. **If a public decoder or bitstream spec appears under a compatible licence,** add it behind | ||
| 276 | `TtpfReader.DecodeChunk`; the container already carries the mode (codec id) and decoded | ||
| 277 | size, so no index work is needed. | ||
| 278 | 5. **If someone resumes the reverse engineering,** use the hard check the SixNG notes propose: | ||
| 279 | every lane must consume exactly its byte budget and finish at the rANS lower bound, with a | ||
| 280 | fixed symbol count. Reference blocks are the missing input; none are public. | ||
| 281 | |||
| 282 | ## Reproduce | ||
| 283 | |||
| 284 | `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 | ||
| 286 | from a read-only mirror of `TtpfReader`'s catalog checks: it mmaps each pool and reads only | ||
| 287 | the 24-byte RDS5 header, the chunk table, the ETPF records and the chunk ranges. It writes no | ||
| 288 | texture data. The mirror is not committed because it duplicates `TtpfReader`; the counts are | ||
| 289 | the evidence. | ||