Repository navigation
Conversation
… decode and block_means A zero-dependency Rust crate, loaded through ctypes like tools/bcpack_calibration, ports the element copy of detile / detile_volume_slice, the BC4/BC5/BC6H/BC7 decoders behind decode_pixels and block_means (all BC kinds) step for step, so the bytes and the IEEE bits of every double are identical. The BPTC tables and BC6H header plans are passed from bcpack_tables_bptc / bcpack, not copied. Any call the library refuses (element outside the allocation, short payload, other buffer types) runs the Python code, which keeps its own result or error. Each block kind is checked against the Python decoder and means on seeded random blocks once and stays in Python if a double differs. LEONIDA_TTPF_NATIVE=0 turns it off. detile 13x-27x, detile_volume 16x, block_means 11x-13x, BC6H/BC7 decode_pixels 4.5x-12x (random synthetic data, Zen 3). tests/test_ttpf_native.py compares both paths; CI builds the crate and runs it with test_ttpf_mips.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item: PERF-TTPF-NATIVE (claimed in #8504). Same pattern as #6308 and #8447 (
tools/bc7_native); does not depend on either, and touches none oftools/dds_png.py,tools/bc7_native/,tools/bcpack.py,tools/bcpack_calibration/.What
An optional Rust crate,
tools/ttpf_native(no dependencies,cdylibloaded throughctypes), with step-for-step ports of thesetools/ttpf_mips.pyloops:detileanddetile_volume_slice(Python still builds the X/Y bit tables and row bases and passes them in);decode_pixels;block_means, for every BC kind (BC1-BC7).Every integer step and every double operation is the Python one, in the same order, so the detiled bytes and the IEEE bits of every double are identical (
-0.0included). The BPTC partition/anchor tables and the BC6H header bit plans are passed in frombcpack_tables_bptc.load_bc7()andbcpack._BC6H_INFO/_bc6h_plan, not copied into Rust.How it hooks in (small, away from the open ttpf_mips PRs)
detile, two to three lines at the top ofdetile,detile_volume_slice,decode_pixelsandblock_means, and[]→_pixel_list()in_decode_bc1_rows/_decode_bc4_rows. I checked the hunks of ttpf_mips: protect history directory metadata during export #7682, ttpf_mips: use the one shared report-path guard, so a case-only --json/--out is refused #5938, TEST-1506: Preserve the minimum signed BC6H endpoint during texture decoding #6120, ttpf_mips: report a descriptor with no allocation span as blocked #8027, feat(tools): add vram subcommand to ttpf_mips to project linear VRAM and mip-drop savings #8406, fix(textures): emit positive zero after signed BC6H scaling #6175 and ASSET-602: Stream texture-pool DDS exports without retaining the complete payload #7134: none of them touch these lines.decode_pixelsstill returns a list of(r, g, b)tuples. For BC4/BC5/BC6H/BC7 the library returns each distinct float and each distinct pixel once, so equal pixels share one tuple, as the Python BC1/BC4 decoders already do. BC1-BC3 keep the Python decoder: it already shares a tuple per palette entry, and building the list from native output was not faster (measured below).listsubclass that remembers the blocks it came from.block_meanson it decodes those blocks again natively and averages them there, without reading the tuples back. Any in-place change to the list drops the blocks, andblock_meansthen runs in Python.LEONIDA_TTPF_NATIVE=0is set (plain lists then), and for every call the library refuses (an element outside the allocation, a short payload, a buffer other than bytes/bytearray/byte memoryview). So those inputs keep their exact Python result or error.tests/test_ttpf_native.pyfails on it in CI.Tests (no game data; synthetic random input only)
tests/test_ttpf_native.py(18 tests) compares exact bytes / double bits:block_meansunder 5 crops × 5 block sizes × 4 grids per format, including grids that are not the decoded one; mutation after decode (set, slice, append,+=, sort); plain lists never take the native path;LEONIDA_TTPF_NATIVE=0(plain lists, same hex output as native), a missing library, a wrong ABI version, a failed self-check, and a deliberately diverging Python BC7 decoder being caught.Run on Windows 11, AMD Ryzen (Zen 3, family 25 model 33), Python 3.12, Rust 1.100.0. CPU only; no GPU or driver involved.
cargo build --release --locked --offlineandcargo test --release --locked --offline(9 Rust tests), 0 warnings, also withRUSTFLAGS="-D warnings"python -m compileall -q make_game.py tools tests: okpython -I tests/test_ttpf_native.py: 18 OK (withLEONIDA_TTPF_NATIVE=0: 16 skipped, 2 OK)python -I tests/test_ttpf_mips.py: 93 OK with native, 93 OK withLEONIDA_TTPF_NATIVE=0(this includes the existing BC1/BC4 peak-memory and shared-tuple test)python -I scripts/check_no_game_data.pyon every changed file: cleantests/semanticnot run (the translator is untouched).CI: a new step in the same job as the BCPack calibration build. It builds and tests the crate, asserts that the library loads, then runs
test_ttpf_native.pyandtest_ttpf_mips.pyagainst it. It sits after the rpf9dump diagnostics step, so it does not overlap the step #8447 adds.Benchmarks (best of 3-5, random synthetic data; "before" = same code with
LEONIDA_TTPF_NATIVE=0)detileBC1 1024x1024, 4 KiB tilesdetileBC7 1024x1024, 64 KiB tilesdetileRGBA8 1024x1024, 4 KiB tilesdetile_volume256x256x32, 8-byte voxelsblock_meansBC1 512x512block_meansBC3 512x512block_meansBC4 512x512block_meansBC5 512x512block_meansBC6H SF16 512x512block_meansBC7 512x512decode_pixelsBC7 512x512, 512 distinct blocksdecode_pixelsBC6H UF16 512x512, 512 distinct blocksdecode_pixelsBC7 512x512, every block randomdecode_pixelsBC6H SF16 512x512, every block randomdecode_pixelsBC5 512x512, every block randomdecode_pixelsBC4 512x512, every block randomdecode_pixelsBC1 512x512 (Python decoder both times)_check_mip_chainBC7 512x512, 7 mips_check_mip_chainBC6H 512x512, 7 mips_check_mip_chainBC1 512x512, 7 mipsLimits, stated plainly:
detileandblock_meansreach 11x-27x because their output is bytes, or one tuple per block.decode_pixelsmust still build one Python tuple per pixel, about 0.1-0.3 µs each when every pixel differs, so on fully random data it caps at 2x-5x. It reaches 10x-12x when blocks repeat, as they do in real textures. The wholecheckchain is now dominated bypredict_child_means, which this PR leaves in Python. It could use the same remembered-blocks list in a follow-up, which I'll post as afinding:in the coordination issue.AI-assisted: written with Claude Code (Claude Opus 5.5). I reviewed and ran everything listed above.
🤖 Generated with Claude Code