Repository navigation
bcpack: strict BC3 and BC5 block rebuild in Rust (~45x-47x end to end) - #6308
Conversation
tools/bcpack_calibration already exports `unpack` (third_party/bcpack-rs). decode_lanes now tries it first and keeps the Python model for the streams it refuses, so strict output is unchanged. About 60x faster on the entropy layer and 12x end to end for BC1 on synthetic chunks; LEONIDA_BCPACK_NATIVE=0 turns it off. tests/test_bcpack_native.py checks the two agree (skipped when the library is not built). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
third_party/bcpack-rs follows the hardware RTL and has no virtual zero bytes, so it refused every q = 0 fragment whose omitted trailing zero comes before a symbol, and those chunks fell back to Python. tools/bcpack_calibration now exports unpack_model, a line-by-line port of _decode_lanes_raw fed bcpack.py's own probability tables: it accepts exactly the streams Python accepts, with the same symbols (8,000 synthetic chunks, sound and corrupt, single and multi-fragment: 0 disagreements). About 30x on the lane layer and 10x end to end for BC1, q = 0 included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the lanes decode_blocks (tools/bcpack_calibration/src/blocks.rs) ports _bc1_blocks and _bc4_blocks and runs them on the lanes of unpack_model without building Python lists. It takes only the strict path: a non-zero lane 1 or a history entry that is not confirmed hands the whole chunk back to Python, so errors and provisional entries do not change. Synthetic 16,384-block chunks: BC1 420 -> 23 ms, BC4 540 -> 14 ms against Python, same SHA-256. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the lanes decode_blocks now also takes codecs 3 and 5, with the same contract as BC1 and BC4: only the strict path is native. A non-zero lane 1, a history entry that is not confirmed, an out-of-range symbol or a stream the lane model refuses returns -1, and Python decodes the chunk itself, so output, errors and provisional entries do not change. LEONIDA_BCPACK_NATIVE=0 still turns it off. _decode_blocks_native also returns None when the history argument is rejected by the loader, so Python raises that error after the lanes as it always did. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Checked strict decoding at
Every accepted chunk matched byte-for-byte, including the returned provisional-label set. All 352 refusals matched the Python exception type and message ( |
|
Thanks @Kev-Ball for verifying all 368 retail BC3/BC5 chunks — 100% byte-identical, with all 16 built-in strict chunks covered. Much appreciated. |
shayderrr
left a comment
There was a problem hiding this comment.
Review
Reviewed change in PR #6308: bcpack: strict BC3 and BC5 block rebuild in Rust (~45x-47x end to end).
Scope: tests/test_bcpack_native.py, tools/bcpack.py, tools/bcpack_calibration/README.md, +3 more
Diff: +1182 / -1 across 6 file(s).
The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.
Reviewed by shayderrr via automated batch review.
Kam471
left a comment
There was a problem hiding this comment.
Head 7e4a5a64b, main 561b65a83 (0 behind); git diff --check clean. Stacked on #6188 (open): this diff includes its BC1/BC4 and Rust lane-model commits, so merge order matters.
cargo build --release --locked --offline --manifest-path tools/bcpack_calibration/Cargo.toml-> OK (2.1s)- before the build:
12 skipped; after:python -I -m pytest tests/test_bcpack_native.py -q-> 12 passed, 754 subtests
BC3/BC5 rebuild is bit-exact against the Python strict path across the randomized and encoder-round-trip cases, and the lane(1)==0 / confirmed-history gating falls back to Python as designed. First-frame: none (offline texture export tool, no runtime path). Merge after #6188.
|
Thanks @TG0000 - I went through this change and the diff around tests/test_bcpack_native.py. The change is tight, the rationale matches the code, and nothing here needs another pass from my side. Approved and squash-merging it into main now. Nice work. |
Extends the Rust BCPack strict block rebuilder in
tools/bcpack_calibrationto cover BC3 and BC5 in the same native call as the lane decode, delivering ~45×–47× end-to-end speedup over pure Python (~6.4×–6.6× over lanes-only) with bit-exact parity.Depends on: #6188
What changed
tools/bcpack_calibration/src/blocks.rs: adds bit-exact strictbc3andbc5block rebuilders plusdist8andpair_bitshelpers.tools/bcpack_calibration/src/lib.rs: wires codecs3(BC3) and5(BC5) intodecode_blocks, and adds alanes != 12C-ABI guard.tools/bcpack.py: registers BC3 and BC5 in_NATIVE_BLOCKS; widens_decode_blocks_nativehistory-loader exception handling to(ValueError, TypeError, OSError)so invalid history arguments fall back to Python and preserve exact error ordering (after lane decode).tests/test_bcpack_native.py: adds 7 tests inNativeBlockRebuildTestcovering BC3/BC5 randomized equivalence, exact synthetic encoder round-trip, refusals/fallbacks (lane 1, size, corrupt/truncated chunks), confirmed/unconfirmed/unknown built-in history, external history, invalid-history error ordering, and negative controls (swapped LUT rows +LEONIDA_BCPACK_NATIVE=0).tools/bcpack_calibration/README.md: documents BC3/BC5 support and measured synthetic speedups.Python remains the reference and fallback: any non-strict mode, non-zero lane 1, unconfirmed/unknown history entry, out-of-range symbol, or refused lane stream falls back to pure Python unchanged (
LEONIDA_BCPACK_NATIVE=0disables the native path).third_party/bcpack-rsis untouched.Verification (Windows 11, Ryzen 9 5900X, CPython 3.12.10, Rust release build, CPU only, synthetic inputs, no game files)
python -I tests/test_bcpack_native.py: 12/12 OK (all 12 skip withLEONIDA_BCPACK_NATIVE=0)python -I tests/test_bcpack.py: 17/17 OK (both default native andLEONIDA_BCPACK_NATIVE=0)test_bcpack_tables.py(34/34),test_bcpack_history_calib.py(19/19),test_ttpf_mips.py(77/77),test_ttpf_assets.py(28/28, 3 skipped),test_calibrated_texture_extra.py(24/24)935 mspure Python →126.5 mslanes-only →19.8 msnative (47.2× vs Python, 6.4× vs lanes-only)908 mspure Python →130.8 mslanes-only →19.9 msnative (45.5× vs Python, 6.6× vs lanes-only)AI-assisted (Claude Sonnet 5.5 implementation, Claude Opus 5.5 review). Claimed in #6214.