Skip to content

ttpf_mips: predict BC child mip means with the optional native decoder - #8837

Open
Raxstreams wants to merge 2 commits into
ItsNotRexed:mainfrom
Raxstreams:codex/ttpf-native-child-means
Open

Raxstreams wants to merge 2 commits into
ItsNotRexed:mainfrom
Raxstreams:codex/ttpf-native-child-means

Conversation

@Raxstreams

@Raxstreams Raxstreams commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as native child-mip mean prediction, following @TG0000’s performance finding. No item ID has been assigned.

Depends on: #8735

What and why

The mip checker still predicts child block means in Python after the optional native decoder produces the parent pixels. Use the original BC blocks remembered by that decoded list to predict the child means in Rust. The kernel sums parent samples in the same order as Python and respects visible mip bounds, including one-texel axes and padded storage.

The Python path handles modified pixel lists, non-BC data, or unavailable native prediction. Existing ABI 1 libraries retain their original kernels. The per-format startup comparison also checks prediction when the loaded library provides it.

The follow-up is commit 351d35fe9, on top of #8735. Follow-up diff

Tested

Windows 11 25H2, Ryzen 7 5800X, CPython 3.14.2, Rust 1.100.0 MSVC. CPU-only work on synthetic inputs. GPU and driver were unused.

  • Offline release build with -D warnings and all 9 Rust tests passed.
  • test_ttpf_native.py: 21 passed with the library, including exact bit checks across BC formats, clipped and padded mips, and modified-list fallback. With the library disabled, 2 passed and 19 skipped. test_ttpf_mips.py: 93 passed in each mode.
  • The original ttpf_mips: optional native kernels (tools/ttpf_native) for detile, BC decode and block_means (PERF-TTPF-NATIVE) #8735 DLL still uses native block means with the updated Python code and falls back for child prediction.
  • Median of five runs on a synthetic 512×512 BC7 chain. The first prediction went from 188.04 ms to 6.72 ms (28.0×). With only the prediction path toggled, the seven-mip check went from 471.46 ms to 218.09 ms (2.16×). The returned means and predictions matched bit for bit and the reported errors matched.
  • Compileall, make_game.py --help, git diff --check, and the game-data checker passed. The stack merges cleanly with main 867d922f0.
  • On Ubuntu 24.04 x86-64 (WSL2), Rust 1.100.0 and Python 3.12, the offline release build with -D warnings passed. All 9 Rust tests, 21 native Python tests, and 93 mip tests passed with the Linux shared library.
  • The full translator suite ran 5,957 tests in 447 files. The two existing failing files were test_image_atomics_guard and test_image_store_d16 (tests: fix image atomics guard and image_store d16 tests after #4473 and #6805 #7608).

AI-assisted: yes (Codex).

Checklist

  • Synthetic inputs only. The changed files passed the game-data check.
  • Translator contract entry (inapplicable to this asset-tool change).

TG0000 and others added 2 commits November 23, 2026 20:20
… 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>
@catminou4

Copy link
Copy Markdown

Tested on Apple M1 Max, macOS 27.2.1 arm64, Python 3.12.16: python -I tests/test_ttpf_native.py → 21 tests OK (19 skipped — native-binary cases need the Rust build). No game files. AI-assisted (Devin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants