Repository navigation
perf(bcpack): 128-bit register BitWriter, lazy BPTC state init, index_row LUT, and portable decode test - #1974
Closed
quietfold wants to merge 1 commit into
Conversation
5 tasks done
3 of 4 tasks
Collaborator
|
Closing this PR in favor of #2567 ( Side-by-side comparison:
Because (AI-assisted review.) |
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.
Claim:
RT-BCPACK-DECODE-FAST-BITWRITER-AND-BPTC(claim comment#7168983247on #1608).Independent of #1935 (
runtime/src/bcpack_stream.h, untouched here); the two optimizations compose cleanly.Optimizations (
runtime/src/bcpack.cpp)BitWriterfor BC6H/BC7:while (bits > 0)memory-RMW byte loops (called 82+ times per BC6H block) and per-blockfill_n(dest, 16, 0)pre-zeroing with twouint64_taccumulators (lo/hi) and a singleput1()helper, flushed in two 64-bit little-endian stores (with portable big-endian fallback).decode():decode()call zero-initialized botharray<Endpoints, 256> classic{}(8 KiB) andarray<BptcState, 256> bptc{}(59 KiB) on the stack, even when decoding classic codecs or small mipmaps.codec >= 6vscodec < 6into separate trivially default-constructible ring buffers without up-front zeroing (bothrebuild_classicandrebuild_bptconly readpast[(i - d) & 255]when0 < d <= i, after that slot was written).zero/ history fallback and per-block zeroing elimination (rebuild_bptc):kZeroBc6andkZeroBc7constants and only constructs a stackhist_statewheneslot >= 0 || islot >= 0, skipping 232 bytes of stack zeroing + BC6 endpoint/index fill on steady-state blocks (i >= 256).bc6Modes/bc7Config, eliminates the 232-bytenext = {}wipe per BPTC block by explicitly zeroing only unused BC7 endpoint/secondary-index slots, and uses a 6-byte little-endianmemcpyinrebuild_classic.kUnzigEven[256]/kUnzigOdd[256]LUTs forindex_row(): replaces the per-pixel bit-extraction andunzig()arithmetic inside the 4–8× per-block index loop.bcpack_decode(runtime/test/bcpack_decode_test.cpp): verifies all 6 codecs (BC1, BC3, BC4, BC5, BC6H, BC7) bit-exactly againstdstorage_vectors.pywith bothfast_entropy = true/false, calibration profile history (missing-profile,confirmed,unconfirmed-predictor,fitted), classic fitted gating, and invalid/misaligned/truncated inputs.Verification
bcpack_decode_testcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werror-O2vsmain(including full rANS entropy decode, best of 5 runs, Apple Silicon):python3 -I scripts/check_no_game_data.pyon all 3 changed files andpython3 -I tests/test_text_write_line_endings.py: all passed.