Repository navigation
bcpack: Rust port of the lane-array model for the strict path (~30x lane layer, ~10x BC1 end to end) - #6029
Closed
TG0000 wants to merge 2 commits into
Closed
bcpack: Rust port of the lane-array model for the strict path (~30x lane layer, ~10x BC1 end to end)#6029TG0000 wants to merge 2 commits into
TG0000 wants to merge 2 commits into
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>
|
Tested Commands & Results (synthetic inputs only, no game files)
Code Audit Notes (non-blocking)
|
Contributor
Author
|
Thanks @kirigayakazima for the thorough Windows + MSVC rustc 1.99 verification and audit! Good note on the C-ABI null-pointer and \checked_mul\ guards in \unpack_model\ — we'll keep that in mind for follow-up hardening (and keep #6029\ clean as-is since all Python callers pass valid non-empty buffers). AI-assisted. |
Contributor
Author
|
Closing as superseded: all of #6029's Rust lane model was squash-merged into \main\ via #6308 (\3c10d234). Thanks again @kirigayakazima for testing! |
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.
Claimed in #5781 (comment).
What
tools/bcpack.decode_lanes()is the lane (entropy) layer of the default strict BCPack path used byttpf_mipsand the assets stage. It now runs a Rust port of the lane-array model whentools/bcpack_calibrationis built.unpack_model(tools/bcpack_calibration/src/model.rs): a line-by-line port of_decode_lanes_raw, virtual zero bytes included.bcpack.pypasses it its own probability tables, so both sides use the same models.ctypesonly, no NumPy.LEONIDA_BCPACK_NATIVE=0turns it off.Why not the existing
unpack(third_party/bcpack-rs)The first commit used it. It follows the hardware RTL, which has no virtual zero bytes. As a result it refuses every
q = 0fragment whose omitted trailing zero byte comes before a symbol (docs/textures.md,flush = 1), and those chunks fell back to Python with no speed-up. The second commit replaces it with the model port.unpackand the calibrated path are not changed.Measured (synthetic chunks only, no game files)
bcpack.decodeend to end, 3 BC1 chunks of 16,384 blocks,q = 0The 8,000 chunks include sound ones, single- and multi-fragment ones (mixed widths,
qand flush), and ones that are corrupted, cut short or followed by trailing bytes. Result: 3,705 accepted by both with identical lanes, 2,017 refused by both, 0 accepted by only one side, 0 mismatches.Notes and findings (not fixed here)
third_party/bcpack-rsdisagree on validity: virtual zeros, as above. Which one real chunks need can only be counted with the game. The calibrated path already falls back to Python whenunpackrefuses.tools/bcpack_tables.pyandthird_party/bcpack-rs/src/tables.rs(q = 8, 10, 13, 14, off by 1 to 3 in a few bands). The default lane widths are at most 8, so width 9 is not reached today.decode(). It is the next step.Tested
python -I tests/test_bcpack_native.py(new: equivalence in both directions,q = 0and virtual zeros, the off switch),test_bcpack.py,test_bcpack_tables.py,test_bcpack_history_calib.py,test_ttpf_mips.py,test_ttpf_assets.py,test_calibrated_texture_extra.py: pass, with and withoutLEONIDA_BCPACK_NATIVE=0.test_bcpack_tool.py: 2 failures that are already onmainon Windows (repr-doubled paths in messages; fixed by tools: print a refused or unreadable path as typed, not through repr() (5 tests fail on Windows) #5927 / tools: print Windows paths in error messages without repr() doubling #6049). This PR does not touch that tool.cargo build --release --locked --offline --manifest-path tools/bcpack_calibration/Cargo.toml(cargo 1.100.0).AI-assisted (Claude Code).
🤖 Generated with Claude Code