Repository navigation
feature/cambi: size the reciprocal LUT for the window; don't rescale window_size on re-init - #1720
Open
scottlaird wants to merge 1 commit into
Open
scottlaird wants to merge 1 commit into
scottlaird wants to merge 1 commit into
Conversation
…window_size on re-init Since d655cef ("feature/cambi: add cambi_reciprocal_lut.h"), init rejects any scaled window whose area reaches the static LUT's 4226 entries, which covers windows up to 65: 4K at the default window_size. 8K (window 131), and any window_size option above 65 at 4K, now fail, though the options allow both (enc/src up to 7680x4320, window_size up to 127). The failure then compounds. init scaled s->window_size in place, and when init fails libvmaf calls it again for the next picture, so each retry doubled the window (131, 263, ... 65535). At 65535, max_window * max_window overflows int, the check passes, and extraction runs with a 65535-pixel window: ffmpeg's libvmaf filter with n_threads > 0 segfaults on 8K input. Build a larger LUT at init when the window needs one, starting from the static table so scores at 4K and below are bit-identical, and pass it down to c_value_pixel and the AVX2 path. Scale copies of window_size rather than the option, and bound the window's area by the uint16_t histogram counts in unsigned arithmetic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1719. Since d655cef, CAMBI rejects any scaled window over 65, which covers 4K at the default window_size and nothing larger. Because init scaled
window_sizein place and libvmaf retries a failed init on every picture, the window then doubled on each retry untilmax_window * max_windowoverflowedint. At that point the check passed, and extraction segfaulted.Changes
set_reciprocal_lut()chooses the LUT at init:1.0f / ifor the rest.CambiBuffersand is passed toc_value_pixel,calculate_c_valuesandcalculate_c_values_avx2. The AVX2 row function already took it as a parameter; the C row function ignored its parameter and used the global.enc_window_sizeholds the scaled encode window. Thewindow_sizeoption is no longer modified, so a retried init computes the same window.UINT16_MAX, in unsigned arithmetic. The histogram counts areuint16_t, so that's the real limit: 255 at most, which covers window_size 127 at 7680x4320.Scores are unchanged where CAMBI worked
At 4K and below the static table is still used, so scores are bit-identical to master. On 4-frame 1080p and 4K pairs, the frame and pooled JSON output of
vmaf --feature cambi=full_ref=trueis identical before and after the patch.At 8K they match d655cef^, which divided directly, to every printed digit:
The extended entries are correctly rounded
1.0f / i. I left the static table as it is, although 42 of its 4226 entries are one ULP off a correctly rounded1.0f / i(i = 82, 83, 244, 488, 504, ...). They look like the result of printing a double to 9 digits and then rounding to float. Regenerating it would change scores at 4K and below in the last digits, which doesn't belong in this fix.Tests
test_adjust_window_size: adds 7680x4320 with window_size 65 → 131.test_set_reciprocal_lut: covers the static table at 65, allocated tables at 131 and 255 (the second call replaces the first table instead of leaking it), and rejection at 257.test_init_window_size: initializes the real extractor twice with window_size=127 at 2560x1440. It checks that the option stays 127, the windows are 85, and the LUT covers 85².meson testpasses:HAVE_ASM, AVX2 CPU): 25/25.On x86-64, the AVX2 path and the C path (
--cpumask 65535) give identical frame and pooled output at 1080p, 4K and 8K. The 8K case uses the larger LUT through the AVX2 gather.Under
-Db_sanitize=address,undefined, the 8K and window_size=127 runs show no ASan or leak reports, andtest_cambipasses 22/22. UBSan does report one misalignedintstore inopt.cand one load infeature_name.c. Those come from theuint16_toption fields that #1658 fixes, and master's tools report the same pair.test_init_window_sizeis the first CAMBI test that creates the extractor through option parsing, so withhalt_on_error=1(meson's default for sanitized tests) it aborts on that store until #1658 is in.Conflicts with #1658. That PR changes
window_size,src_window_sizeandadjust_window_size()toint. Whichever lands second needsenc_window_sizechanged to match, which is a few lines. I'm happy to rebase onto it.Not addressed here: a failed init still leaks what it allocated before failing, on every retry. That's a separate issue in how failed inits are retried.
🤖 Generated with Claude Code