From 0db45d1743d47963e97f77d3b3f6b76e756142c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 25 Sep 2026 16:26:40 +0300 Subject: [PATCH] lane-av1-llpred2: skip_chroma_above reads the frame ss pair, not a rect-over-chroma_side ratio obmc_plan derived ss from trailing_zeros(write / chroma_side) on ONE square side: a 4:2:0 16x8 strip read ss=(1,0) and lost its above-chroma skip (libaom's av1_skip_u4x4_pred_in_obmc skips the plane block 8x4 under frame ss (1,1)), and a 4:4:4 16x8 strip divided 8/16=0 so trailing_zeros(0)=64 panicked a debug build on the shift. The decision is now the pure obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y) over the frame's own pair -- the same values obmc_run's chroma windows shift by -- fed by ss_x(fctx)/ss_y(fctx) at all three callsites (decode_inter_block, decode_inter_block8, the encoder's obmc_prediction). A unit check pins the 4:2:0 16x8/8x16 skip and the 4:4:4 shapes; the 6-frame 444 fixture is cmp-exact against aomdec in a debug decode probe, and the a_lossless 4:2:0 gates stay green. --- crates/ec-av1/src/decode.rs | 75 +++++++++++++++++++++++++++++++++---- crates/ec-av1/src/encode.rs | 2 + lanes/av1llpred2.report.md | 62 ++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 lanes/av1llpred2.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 2b6b382c..87766878 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -29853,6 +29853,13 @@ pub(crate) fn obmc_plan( side: usize, write_w: usize, write_h: usize, + // lane-av1-llpred2: the FRAME's own subsampling pair -- the same pair the + // chroma window half in [`obmc_run`] shifts by. A rect strip's ss cannot + // be derived from a rect size over the square `chroma_side`: that ratio + // gave a 16x8 strip at 4:2:0 ss=(1,0) (losing its above-chroma skip) and + // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic). + ss_x: usize, + ss_y: usize, chroma_side: usize, px: usize, py: usize, @@ -29903,13 +29910,13 @@ pub(crate) fn obmc_plan( // lane-av1-llpred: the old luma-shape list `(8,8)|(16,8)|(8,16)` // hardcoded the 4:2:0 plane sizes; at 4:4:4 the plane block is the luma // block itself (never 4-wide), so every one of those blocks was silently - // missing its above-pass chroma OBMC blend. Derive ss from `chroma_side` - // (`obmc_plan` has no `fctx`, and the encoder callsite passes the same - // square pair). - let ss_x = (write_w / chroma_side).trailing_zeros() as usize; - let ss_y = (write_h / chroma_side).trailing_zeros() as usize; - let skip_chroma_above = - matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8)); + // missing its above-pass chroma OBMC blend. + // lane-av1-llpred2: ss is the FRAME's own pair (`ss_x`/`ss_y(fctx)`, the + // same values [`obmc_run`]'s chroma windows shift by), never a ratio of + // the rect write size over the square `chroma_side` -- that ratio gave a + // 4:2:0 16x8 strip ss=(1,0) and dropped its above-chroma skip, and at + // 4:4:4 divided to zero (`trailing_zeros(0)` = 64, a debug shift panic). + let skip_chroma_above = obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y); let mut above = Vec::new(); for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) { @@ -29981,6 +29988,56 @@ pub(crate) fn obmc_plan( }) } +/// `av1_skip_u4x4_pred_in_obmc`'s above-pass decision (libaom +/// `reconinter.c` 829): the PLANE block (`write_w >> ss_x`, `write_h >> +/// ss_y`) is 4x4, 8x4 or 4x8. `ss_x`/`ss_y` are the FRAME's own pair -- the +/// same values [`obmc_run`]'s chroma windows shift by -- never a ratio over +/// the square `chroma_side` (lane-av1-llpred2: that ratio dropped the +/// 4:2:0 16x8/8x16 skip and shifted by 64 at 4:4:4). Pure so the check +/// below pins the rect-strip decision without decoding a stream. +pub(crate) fn obmc_skip_chroma_above( + write_w: usize, + write_h: usize, + ss_x: usize, + ss_y: usize, +) -> bool { + matches!( + (write_w >> ss_x, write_h >> ss_y), + (4, 4) | (8, 4) | (4, 8) + ) +} + +#[cfg(test)] +mod obmc_skip_chroma_tests { + use super::obmc_skip_chroma_above; + + /// lane-av1-llpred2: the above-chroma skip keys off the PLANE block + /// under the frame's own ss pair. At 4:2:0 a 16x8/8x16 rect strip's + /// plane block is 8x4/4x8 and MUST still skip (the old `chroma_side` + /// ratio read ss=(1,0) off a 16x8 strip and made it blend); at 4:4:4 + /// the plane block is the luma block, so only true 4-wide/high shapes + /// skip and the shift never leaves `usize` range (the old ratio's + /// `trailing_zeros(0)` = 64 panicked a debug build). + #[test] + fn rect_strips_skip_above_chroma_at_420_and_shift_never_overflows() { + // 4:2:0 (ss 1,1): 8x8 -> 4x4, 16x8 -> 8x4, 8x16 -> 4x8 all skip. + assert!(obmc_skip_chroma_above(8, 8, 1, 1)); + assert!(obmc_skip_chroma_above(16, 8, 1, 1)); + assert!(obmc_skip_chroma_above(8, 16, 1, 1)); + // ... larger plane blocks blend, exactly libaom's own list. + assert!(!obmc_skip_chroma_above(16, 16, 1, 1)); + assert!(!obmc_skip_chroma_above(32, 16, 1, 1)); + assert!(!obmc_skip_chroma_above(16, 32, 1, 1)); + // 4:4:4 (ss 0,0): the plane block is the luma block itself. + assert!(obmc_skip_chroma_above(4, 4, 0, 0)); + assert!(obmc_skip_chroma_above(8, 4, 0, 0)); + assert!(obmc_skip_chroma_above(4, 8, 0, 0)); + assert!(!obmc_skip_chroma_above(8, 8, 0, 0)); + assert!(!obmc_skip_chroma_above(16, 8, 0, 0)); + assert!(!obmc_skip_chroma_above(8, 16, 0, 0)); + } +} + /// One OBMC neighbour as the PARSE thread resolved it (lane-defer8): every /// value [`obmc_run`] needs that lives in the mode-info grid or the /// neighbour bands, which the parse keeps overwriting as it walks on. @@ -32938,6 +32995,8 @@ fn decode_inter_block( side, write_w, write_h, + ss_x(fctx), + ss_y(fctx), chroma_side, px, py, @@ -38279,6 +38338,8 @@ fn decode_inter_block8( SIDE, SIDE, SIDE, + ss_x(fctx), + ss_y(fctx), chroma_side, px, py, diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index eb48b255..7a07443d 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -6801,6 +6801,8 @@ fn obmc_prediction( side, side, side, + crate::decode::ss_x(fctx), + crate::decode::ss_y(fctx), side / 2, x, y, diff --git a/lanes/av1llpred2.report.md b/lanes/av1llpred2.report.md new file mode 100644 index 00000000..8aa2e48e --- /dev/null +++ b/lanes/av1llpred2.report.md @@ -0,0 +1,62 @@ +# lane-av1-llpred2: `skip_chroma_above` must read the frame's own ss pair, not a rect-over-square ratio + +## Ticket + +Reviewer FAIL on 71f07edd's `obmc_plan`: both ss axes were derived from ONE +square chroma side, `ss = trailing_zeros(write_w|write_h / chroma_side)`. +Two defects, one root: + +1. 4:2:0, a 16x8 strip: `write_h/chroma_side = 8/8 = 1`, `trailing_zeros(1)` + = 0, so ss=(1,0) and the plane block read (8,8) — `skip_chroma_above` + went FALSE. The old pre-llpred code skipped, and libaom's + `av1_skip_u4x4_pred_in_obmc` (reconinter.c 829) skips on the PLANE block + `(8,4)` (frame ss (1,1)). Every 4:2:0 16x8/8x16 OBMC strip blended a + chroma above pass the reference never blends (and would desync a + stream that carries one). +2. 4:4:4, a 16x8 strip: `write_h/chroma_side = 8/16 = 0`, + `trailing_zeros(0)` = 64, `write_h >> 64` panics in a debug build. + The parent lane's byte-exact claim was measured in a release build, + where the out-of-range shift wraps instead of panicking. + +## Change (this tree @ 71f07edd + the fix) + +`obmc_plan` takes `ss_x`/`ss_y` — the FRAME's own pair, exactly what the +chroma window half in `obmc_run` shifts by (`ss_x(fctx)`/`ss_y(fctx)`) — +and the decision moved to a pure helper: + +```rust +pub(crate) fn obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y) -> bool { + matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8)) +} +``` + +All three callsites pass the frame pair: `decode_inter_block`, +`decode_inter_block8` (`ss_x(fctx), ss_y(fctx)`), and the encoder's +`obmc_prediction` (`crate::decode::ss_x(fctx)`, 4:2:0-only encoder). No +ratio over `chroma_side` survives; `trailing_zeros` of anything is gone. +The window-size half that reduces to `/2` at 4:2:0 is untouched, and the +reserved 4:2:0 group-tail chroma arm is untouched. + +## Proof (debug build, `dev` profile throughout) + +- Decision check (new `obmc_skip_chroma_tests`): + `rect_strips_skip_above_chroma_at_420_and_shift_never_overflows` pins + 4:2:0 (16,8,1,1) and (8,16,1,1) → SKIP (with (8,8,1,1), and + (16,16)/(32,16)/(16,32) → blend), and 4:4:4 → only true 4-wide/high + shapes skip, (16,8,0,0)/(8,16,0,0)/(8,8,0,0) → blend with no shift + out of `usize` range. No hit-counter gate was added: the skip + decision itself is what is proven. +- 6-frame 4:4:4 stream, DEBUG decode probe: fixture + `/tmp/llintra8/testsrc2_min8.obu` + sha256 `04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc`, + `$HOME/.cache/cargo-target-av1llpred2/debug/examples/decode_probe` + → 6 frames, 221184 bytes, `cmp`-equal to fresh + `$HOME/.cache/aom-oracle/build/aomdec --rawvideo`. Byte-exact, now in + a build that would have panicked on the old code. +- 4:2:0 non-regression: `cargo test -p ec-av1 --lib -- obmc_skip_chroma + a_lossless` → 7 passed, 0 failed (the new check + the 4:2:0 lossless + libaom gates, the 444 min-partition-64 inter gate, the sb128 pair, the + 16x4 pair). +- `cargo check -p ec-av1 --all-targets` + (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1llpred2`): 0 warnings, + 0 errors.