ttpf: single mips without a tail, cube mip counts, 3D volumes #37

Manually merged
github merged 1 commit from gh-pr/37/head into gh-pr/37/base 2026-11-26 20:04:50 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-23 04:43 UTC · original
holdmysocks:fix/ttpf-layout → master · +246 −82 · 3 files · 1 commits · merged 2026-11-23 12:08 UTC

Fixes three ttpf texture-store layout problems. The layout rules come from AMD's public addrlib (Gfx10 swizzle patterns, MIT) and from measurements on the game files.

1. Single-mip textures decoded blank

addrlib builds a mip tail only when a surface has more than one mip, so a single mip starts at offset 0 even when it would fit in the tail. Also, in tile mode 1 a mip field of 1 means one mip:

  • Store spacing says 1 on all 4,071 of these textures where it can tell, and never says 2.
  • The small ones whose whole chain fits in one block hold their data at offset 0. For example, 16×8 RGBA8 fills the 256-byte blocks 0 and 2 of its 4 KiB block, exactly the SW_4KB_S footprint.

Check: 2,251 small textures, all decoding blank before (0.000 of pixels non-zero), now 0.94 non-zero on average with coherent images. This includes 125 16×8 RGBA8 textures and 3 single-mip cubes.

2. Cubes lost their smallest mips

The cube mip count is the mip field + copies − 1, where copies = tile mode − 8. On every cube the stored mips run to exactly that mip, and the tail slot after it is empty:

Cube Mip field Copies Mips Next slot empty
64×64 BC7 4 2 5 42 / 42 faces
128×128 BC7 4 3 6 18 / 18
256×256 BC7 2 4 5 5 / 6

Check: On the 43 64×64 BC7 cubes with mip field 6, the restored 1×1 mip differs from the 2×2 mip box-filtered by 2.20 levels on average. For comparison, mip 5 against mip 4 differs by 3.02. Three cubes that had no layout before (128×128 and 256×256) now decode.

3. 3D textures were read as 2D arrays

Descriptor d1 bits 20–23 give the resource kind: 2 = 2D, 4 = cube, 6 = 3D, 10 = 2D array. On 3D textures the array-size field is the depth.

The volumes use the 3D SW_4KB_S pattern (addrlib's SW_4K_S3, without XOR), which interleaves Z into each 4 KiB brick:

  • 8×8×8 bricks for 8-byte elements
  • 8×16×16 bricks for 2-byte elements
  • bricks ordered x, then y, then z

Only those two element sizes, with one mip, are mapped; other volumes are rejected. This replaces the brute-forced "split 2-byte array" special case. That case was the R16F volume: its depth of 8 leaves the top Z bit 0, which is the "every other KiB unused" pattern.

Volume Slice-to-slice diff, before → after In-slice step, before → after
32×64×32 R16G16B16A16F 37.5 → 5.7 6.6 → 3.2
32×32×32 R16G16B16A16F 85.6 → 5.2 11.1 → 8.7
256×32×8 R16F 42.4 → 0.36 1.55 → 2.35

The old R16F order had been fitted to in-slice smoothness only. The new decode is a clean, smooth lookup curve, nearly identical in every slice. The old decode showed seams every 8 rows; the new one has none.

Regression check

I compared the layout of all 357,115 textures (mip count, size, mip 0 placement) before and after. Only the groups above changed.

Tests

  • New unit tests on synthetic data: single-mip offset 0, 3D brick addressing and round-trip, rejection of unmeasured element sizes, cube and tile-mode-1 mip counts, and 3D descriptors.
  • cargo test --release --locked passes.
**@⁠holdmysocks** on GitHub · 2026-11-23 04:43 UTC · [original](https://github.com/holdmysocks/SixNG/pull/37) `holdmysocks:fix/ttpf-layout` → `master` · +246 −82 · 3 files · 1 commits · merged 2026-11-23 12:08 UTC Fixes three ttpf texture-store layout problems. The layout rules come from AMD's public addrlib (Gfx10 swizzle patterns, MIT) and from measurements on the game files. ## 1. Single-mip textures decoded blank addrlib builds a mip tail only when a surface has more than one mip, so a single mip starts at offset 0 even when it would fit in the tail. Also, in tile mode 1 a mip field of 1 means one mip: - Store spacing says 1 on all 4,071 of these textures where it can tell, and never says 2. - The small ones whose whole chain fits in one block hold their data at offset 0. For example, 16×8 RGBA8 fills the 256-byte blocks 0 and 2 of its 4 KiB block, exactly the `SW_4KB_S` footprint. **Check:** 2,251 small textures, all decoding blank before (0.000 of pixels non-zero), now 0.94 non-zero on average with coherent images. This includes 125 16×8 RGBA8 textures and 3 single-mip cubes. ## 2. Cubes lost their smallest mips The cube mip count is the mip field + copies − 1, where copies = tile mode − 8. On every cube the stored mips run to exactly that mip, and the tail slot after it is empty: | Cube | Mip field | Copies | Mips | Next slot empty | |---|---|---|---|---| | 64×64 BC7 | 4 | 2 | 5 | 42 / 42 faces | | 128×128 BC7 | 4 | 3 | 6 | 18 / 18 | | 256×256 BC7 | 2 | 4 | 5 | 5 / 6 | **Check:** On the 43 64×64 BC7 cubes with mip field 6, the restored 1×1 mip differs from the 2×2 mip box-filtered by 2.20 levels on average. For comparison, mip 5 against mip 4 differs by 3.02. Three cubes that had no layout before (128×128 and 256×256) now decode. ## 3. 3D textures were read as 2D arrays Descriptor d1 bits 20–23 give the resource kind: 2 = 2D, 4 = cube, 6 = 3D, 10 = 2D array. On 3D textures the array-size field is the depth. The volumes use the 3D `SW_4KB_S` pattern (addrlib's `SW_4K_S3`, without XOR), which interleaves Z into each 4 KiB brick: - 8×8×8 bricks for 8-byte elements - 8×16×16 bricks for 2-byte elements - bricks ordered x, then y, then z Only those two element sizes, with one mip, are mapped; other volumes are rejected. This replaces the brute-forced "split 2-byte array" special case. That case was the R16F volume: its depth of 8 leaves the top Z bit 0, which is the "every other KiB unused" pattern. | Volume | Slice-to-slice diff, before → after | In-slice step, before → after | |---|---|---| | 32×64×32 R16G16B16A16F | 37.5 → 5.7 | 6.6 → 3.2 | | 32×32×32 R16G16B16A16F | 85.6 → 5.2 | 11.1 → 8.7 | | 256×32×8 R16F | 42.4 → 0.36 | 1.55 → 2.35 | The old R16F order had been fitted to in-slice smoothness only. The new decode is a clean, smooth lookup curve, nearly identical in every slice. The old decode showed seams every 8 rows; the new one has none. ## Regression check I compared the layout of all 357,115 textures (mip count, size, mip 0 placement) before and after. Only the groups above changed. ## Tests - New unit tests on synthetic data: single-mip offset 0, 3D brick addressing and round-trip, rejection of unmeasured element sizes, cube and tile-mode-1 mip counts, and 3D descriptors. - `cargo test --release --locked` passes.
- A single-mip surface has no mip tail and starts at offset 0 (AMD addrlib
  builds a tail only for more than one mip). Tile mode 1 with mip field 1
  holds one mip. Together these fix 2,251 small textures (16x8 RGBA8
  sprites and similar) that decoded blank.
- Cube mip count = mip field + copies - 1. On every cube the stored mips
  run to exactly that mip and the next tail slot is empty. A 64x64 BC7
  cube now keeps its 1x1 mip, and three cubes that had no layout decode.
- 3D textures (d1 bits 20-23 = 6; the array-size field is the depth) use
  the Gfx10 SW_4KB_S 3D pattern from AMD addrlib, with Z interleaved into
  each 4 KiB brick. Only the element sizes found on volumes (2 and 8 bytes,
  one mip) are mapped; the rest are rejected. This replaces the brute-forced
  "split 2-byte array" order, which was the R16F volume.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:04:49 +00:00
github manually merged commit 66c6e9e794 into gh-pr/37/base 2026-11-26 20:04:50 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.