diff options
| author | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 22:58:39 -0700 |
|---|---|---|
| committer | nicolas <44988633+nschlaepfer@users.noreply.github.com> | 2026-11-21 22:58:39 -0700 |
| commit | 1db06d0e2e2c6c9561b2b9979a85b18e090dbc7b (patch) | |
| tree | e45bb39b251411677587fc02b4a6fa3fd52679e6 /tools/tex_export.py | |
| parent | 067d3e8b97189fcf272dc699fdbb871eae496660 (diff) | |
Export texture formats covered by the indexed tile layouts
Diffstat (limited to 'tools/tex_export.py')
| -rw-r--r-- | tools/tex_export.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/tools/tex_export.py b/tools/tex_export.py index 5a03a1d64..08a1fc6c0 100644 --- a/tools/tex_export.py +++ b/tools/tex_export.py | |||
| @@ -5,11 +5,13 @@ This carve exporter cannot apply it: the carved descriptor has no tile-mode fiel | |||
| 5 | allocation span, so the first/last heuristic below stays the only verified placement here. | 5 | allocation span, so the first/last heuristic below stays the only verified placement here. |
| 6 | 6 | ||
| 7 | For each texture: | 7 | For each texture: |
| 8 | - element size from the DXGI format (BC: 8/16 bytes per 4x4 block; uncompressed: bytes per pixel) | 8 | - element size from tex_headers.FMT_INFO (BC: 8/16 bytes per 4x4 block; uncompressed: bytes per pixel); only |
| 9 | 1/2/4/8/16-byte elements have a SW_4K_S equation, so 12-byte R32G32B32 stays unsupported | ||
| 9 | - the top mip is either at the data offset or at the end of the mip chain (GFX10 stores mips smallest first); | 10 | - the top mip is either at the data offset or at the end of the mip chain (GFX10 stores mips smallest first); |
| 10 | both are detiled and the smoother one wins (scored on the decoded image where Pillow can decode the format, | 11 | both are detiled and the smoother one wins (scored on the decoded image where Pillow can decode the format, |
| 11 | otherwise on raw element bytes) | 12 | otherwise on raw element bytes) |
| 12 | - writes <out>/<archive>/<cpu blob>_<q index>_<WxH>_<format>.dds and records the choice in export_log.json | 13 | - writes <out>/<archive>/<cpu blob>_<q index>_<WxH>_<format>.dds and records the choice in export_log.json, |
| 14 | with "heuristic": true whenever two distinct placements fitted (the pick is a score, not a verified layout) | ||
| 13 | 15 | ||
| 14 | Usage: | 16 | Usage: |
| 15 | python -I tex_export.py <textures_index.json> <carve dir> <out dir> [--limit N] [--png] | 17 | python -I tex_export.py <textures_index.json> <carve dir> <out dir> [--limit N] [--png] |
| @@ -26,15 +28,14 @@ import numpy as np | |||
| 26 | 28 | ||
| 27 | sys.path.insert(0, os.path.dirname(__file__)) | 29 | sys.path.insert(0, os.path.dirname(__file__)) |
| 28 | from amd_swizzle import _parity, equation, load # noqa: E402 | 30 | from amd_swizzle import _parity, equation, load # noqa: E402 |
| 31 | from tex_headers import FMT_INFO # noqa: E402 | ||
| 29 | 32 | ||
| 30 | # DXGI format -> (bytes per element, block dimension) | 33 | # DXGI format -> (bytes per element, block dimension), from the indexer's table; eq4k has SW_4K_S equations |
| 31 | FMT = {71: (8, 4), 72: (8, 4), 80: (8, 4), 81: (8, 4), 74: (16, 4), 77: (16, 4), 78: (16, 4), 83: (16, 4), | 34 | # for 1/2/4/8/16-byte elements only, so 12-byte R32G32B32 (6, 7, 8) is left out and reported unsupported. |
| 32 | 84: (16, 4), 95: (16, 4), 96: (16, 4), 98: (16, 4), 99: (16, 4), 28: (4, 1), 29: (4, 1), 87: (4, 1), | 35 | FMT = {fmt: info for fmt, info in FMT_INFO.items() if info[0] in (1, 2, 4, 8, 16)} |
| 33 | 91: (4, 1), 24: (4, 1), 26: (4, 1), 41: (4, 1), 34: (4, 1), 10: (8, 1), 2: (16, 1), 56: (2, 1), 54: (2, 1), | 36 | PILLOW_OK = {71, 72, 74, 75, 77, 78, 80, 81, 83, 84, 98, 99, 28, 29, 87, 91} |
| 34 | 49: (2, 1), 61: (1, 1)} | ||
| 35 | PILLOW_OK = {71, 72, 74, 77, 78, 80, 81, 83, 84, 98, 99, 28, 29, 87, 91} | ||
| 36 | # Pillow can't open sRGB DXGI codes; the bytes are identical to the UNORM twin, so decode with that for scoring. | 37 | # Pillow can't open sRGB DXGI codes; the bytes are identical to the UNORM twin, so decode with that for scoring. |
| 37 | DECODE_AS = {72: 71, 78: 77, 99: 98, 29: 28, 91: 87} | 38 | DECODE_AS = {72: 71, 75: 74, 78: 77, 99: 98, 29: 28, 91: 87} |
| 38 | 39 | ||
| 39 | _EQ = {} | 40 | _EQ = {} |
| 40 | _PATTERNS = [] # (nibbles, tables) from addrlib, read on first use so the module imports without the header | 41 | _PATTERNS = [] # (nibbles, tables) from addrlib, read on first use so the module imports without the header |
| @@ -72,7 +73,12 @@ def level_bytes(we, he, bpe, bw, bh): | |||
| 72 | def dds_bytes(w, h, fmt, payload): | 73 | def dds_bytes(w, h, fmt, payload): |
| 73 | hdr = bytearray(128) | 74 | hdr = bytearray(128) |
| 74 | hdr[0:4] = b"DDS " | 75 | hdr[0:4] = b"DDS " |
| 75 | struct.pack_into("<IIIIIII", hdr, 4, 124, 0x1007 | 0x80000, h, w, len(payload), 0, 1) | 76 | bpe, blk = FMT[fmt] |
| 77 | if blk == 1: # DDSD_PITCH: bytes in one row of the top mip | ||
| 78 | flags, pitch = 0x1007 | 0x8, w * bpe | ||
| 79 | else: # DDSD_LINEARSIZE: bytes in the whole top mip | ||
| 80 | flags, pitch = 0x1007 | 0x80000, len(payload) | ||
| 81 | struct.pack_into("<IIIIIII", hdr, 4, 124, flags, h, w, pitch, 0, 1) | ||
| 76 | struct.pack_into("<II4s", hdr, 76, 32, 4, b"DX10") | 82 | struct.pack_into("<II4s", hdr, 76, 32, 4, b"DX10") |
| 77 | struct.pack_into("<I", hdr, 108, 0x1000) | 83 | struct.pack_into("<I", hdr, 108, 0x1000) |
| 78 | return bytes(hdr) + struct.pack("<IIIII", fmt, 3, 0, 1, 0) + payload | 84 | return bytes(hdr) + struct.pack("<IIIII", fmt, 3, 0, 1, 0) + payload |
| @@ -132,7 +138,8 @@ def export_one(t, carve, out, blob_cache): | |||
| 132 | os.makedirs(d, exist_ok=True) | 138 | os.makedirs(d, exist_ok=True) |
| 133 | with open(os.path.join(d, name), "wb") as f: | 139 | with open(os.path.join(d, name), "wb") as f: |
| 134 | f.write(dds_bytes(w, h, fmt, payload)) | 140 | f.write(dds_bytes(w, h, fmt, payload)) |
| 135 | t["export"] = {"file": name, "place": place, "score": round(s, 4)} | 141 | # two placements that fit at different offsets leave the pick to the score, not to a known layout |
| 142 | t["export"] = {"file": name, "place": place, "score": round(s, 4), "heuristic": len(cands) > 1 and chain > top} | ||
| 136 | return "ok:" + place | 143 | return "ok:" + place |
| 137 | 144 | ||
| 138 | 145 | ||