-
Notifications
You must be signed in to change notification settings - Fork 30
Add i16 sample type support for modular decoding #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hjanuschka
wants to merge
4
commits into
libjxl:main
Choose a base branch
from
hjanuschka:i16-sample-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Initial infrastructure for supporting i16 samples in modular decoding, enabling 50% memory bandwidth reduction for 8-16 bit images. This PR adds: - ModularSample trait with wrapping arithmetic and i64 conversion - Implementations for i16 and i32 TODO (full implementation requires ~2000 lines across 13 files): - Make ModularChannel<T> generic over sample type - Make PredictionData<T> generic - Update ModularChannelDecoder trait - Update decode/channel.rs implementations - Update tree.rs and predict.rs prediction functions - Update transform functions (rct, squeeze, palette) - Add SIMD support for i16 vectors
- ModularChannelGeneric<T> with type alias ModularChannel = ModularChannelGeneric<i32> - PredictionDataGeneric<T> with type alias PredictionData = PredictionDataGeneric<i32> - PredictionDataI64 for intermediate prediction calculations - All existing code continues to use i32 via type aliases
Benchmark @ d4fac3e |
- make_pixel<T> now generic over ModularSample type - All decode functions use make_pixel::<i32> for backward compat - ModularSample::from_i64 uses direct cast for i32, saturating for i16 - All 481 tests pass
- Add ModularChannelI16 type alias and data_i16 field to ModularBuffer - Add ensure_i32() method for on-demand i16→i32 conversion - Add i16 decode path (decode_modular_subbitstream_i16, decode_modular_channel_i16) - Add i16 dispatch in read_stream() when no transforms and bit_depth <= 16 - Add ensure_i32 calls in transform apply before accessing i32 data - 50% memory bandwidth reduction for 8-16 bit images without transforms
Member
|
Let's do this later. We would want to implement 16-bit SIMD transforms too, and 16-bit buffers; the benefits of just using 16 bits for the entropy decoding buffers are minimal. |
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.
Add i16 sample type support for modular decoding, enabling 50% memory bandwidth reduction for 8-16 bit images.
Based on jxl-oxide's sealed trait pattern.
Changes
Infrastructure:
ModularSampletrait with wrapping arithmetic and i64 conversionModularChannelGeneric<T>withModularChannelalias for i32PredictionDataGeneric<T>withPredictionDataalias for i32PredictionDataI64for intermediate calculationsDecode pipeline:
make_pixel<T>generic over sample typemake_pixel::<i32>ModularSample::from_i64: direct cast for i32, saturating for i16All 481 tests pass.
Design Notes
Transforms stay i32: RCT, squeeze, and palette transforms use SIMD operations (
I32SimdVec) for performance. Keeping them i32-only is intentional - the decode loop (many pixels) benefits from i16, while transforms (applied once per region) benefit from SIMD optimization.To use i16 samples: Pass
i16as the type parameter toModularChannelGenericandmake_pixel. For channels without transforms, this provides 50% memory bandwidth reduction. For channels with transforms, use i32.