From 4d36425492d9e255028293f7b4ad28d71dc79640 Mon Sep 17 00:00:00 2001 From: aldotms89 <119340049+aldotms89@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:39:56 -0600 Subject: [PATCH] Shader split: accept padded stored ZIP members Some archives append alignment bytes to stored entries. Validate the declared-size prefix against the directory CRC before falling back to Viper LZ4. A synthetic ZIP checks both acceptance and rejection. --- dm/gfx/tools/shader_split.py | 32 +++++++++++++---- dm/tools/tests/test_split_zip_padding.py | 44 ++++++++++++++++++++++++ docs/agents/symptoms.md | 1 + docs/reference/shaders.md | 8 +++++ 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 dm/tools/tests/test_split_zip_padding.py diff --git a/dm/gfx/tools/shader_split.py b/dm/gfx/tools/shader_split.py index ba2f3b58..f5ef5ca4 100644 --- a/dm/gfx/tools/shader_split.py +++ b/dm/gfx/tools/shader_split.py @@ -1421,15 +1421,24 @@ def program(x, at, label): VIPER_GLSLC = b'\x91\x68\x86\x19' VIPER_CHUNK = 0x10000 -def viper_zip_member(z, info): +# PEANUTS begin(upstream-candidate): share the raw stored-member read with the ZIP padding probe. +def zip_stored_bytes(z, info): + z.fp.seek(info.header_offset); h = z.fp.read(30) + if len(h) != 30 or h[:4] != ZIP: red(f'{z.filename or "zip"}/{info.filename}: no local header at {info.header_offset:#x}') + nlen, xlen = struct.unpack_from(' info.file_size: + prefix = memoryview(raw)[:info.file_size] + if zlib.crc32(prefix) == info.CRC: + return bytes(prefix) + return viper_zip_member(raw, info) return z.read(name) +# PEANUTS end(upstream-candidate) + def viper_shader(d, label): """Star Fox's shader binaries (its engine's _vrender_shader_binary_t, one per data.zip member): the GLSLC output magic, u32 code length, u32 control length, u32 0, a 64-bit hash, then the diff --git a/dm/tools/tests/test_split_zip_padding.py b/dm/tools/tests/test_split_zip_padding.py new file mode 100644 index 00000000..0248bafe --- /dev/null +++ b/dm/tools/tests/test_split_zip_padding.py @@ -0,0 +1,44 @@ +import io +import struct +import sys +import unittest +import zipfile +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[2] / 'gfx/tools')) +from shader_split import zip_member + + +class ZipPadding(unittest.TestCase): + def stored(self, payload, stored): + stream = io.BytesIO() + with zipfile.ZipFile(stream, 'w') as archive: + archive.writestr('shader.bin', payload) + data = bytearray(stream.getvalue()) + central = data.index(b'PK\x01\x02') + end = data.index(b'PK\x05\x06') + struct.pack_into('` replaces only the generated cold hint lookup with a 4 KiB page-to-pool candidate, preserving the hot helper path, all word loads/stores and the complete search. The host tables (switch DM_VK_PIDX) are not in this tree: without them the cache keeps the exact search. Missing/partial/out-of-window pages, invalid candidates and unavailable snapshots retain exact search. Candidates are range-checked; unordered or overlapping host intervals produce no candidates. Snapshots stay immutable until all recording and submitted uses retire. The four snapshot buffers do not add frames to the queue; pressure falls back without waiting. The mesh chain includes both the shader rewrite and host header contract, so sidecars require the matching APK. The design reference is [Anka Native](https://github.com/EddizEge/AnkaNative/blob/main/CHANGELOG_ANKA_NATIVE.md) (MIT); no implementation was copied. Its in-place reuse of a recording snapshot is unsuitable for this backend's partial submissions and is not used. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md), three heavy mesh modules on Adreno 830 / Qualcomm 891.14. Synthetic SPIR-V differential tests compare every output word and physical store against the original lookup, including fallback and boundary addresses; host tests cover page windows, overlap rejection and open/fence reuse under ASan/UBSan. Performance acceptance is recorded in the game note; default remains off. + + +### Stored ZIP shader members with trailing alignment padding + +- **Symptom:** a stored ZIP member fails to open during shader splitting because the member's sizes differ. +- **Cause:** the stored extent includes alignment bytes beyond the declared size. A size mismatch can also signal a Viper LZ4 member. +- **Fix:** accept the declared-size prefix when its CRC matches the directory entry. Otherwise pass the stored bytes to the Viper decoder. +- **Found on:** World War Z (`010099F013898000`).