forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llpred2: skip_chroma_above reads the frame ss pair, not a rect-over-chroma_side ratio

Browse files at this commit

0db45d1743d47963e97f77d3b3f6b76e756142c7Ahmet Kaan GümüşParent: ab30546
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.rsmodified+68 -7
@@ -29853,6 +29853,13 @@ pub(crate) fn obmc_plan(
2985329853 side: usize,
2985429854 write_w: usize,
2985529855 write_h: usize,
29856+ // lane-av1-llpred2: the FRAME's own subsampling pair -- the same pair the
29857+ // chroma window half in [`obmc_run`] shifts by. A rect strip's ss cannot
29858+ // be derived from a rect size over the square `chroma_side`: that ratio
29859+ // gave a 16x8 strip at 4:2:0 ss=(1,0) (losing its above-chroma skip) and
29860+ // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic).
29861+ ss_x: usize,
29862+ ss_y: usize,
2985629863 chroma_side: usize,
2985729864 px: usize,
2985829865 py: usize,
@@ -29903,13 +29910,13 @@ pub(crate) fn obmc_plan(
2990329910 // lane-av1-llpred: the old luma-shape list `(8,8)|(16,8)|(8,16)`
2990429911 // hardcoded the 4:2:0 plane sizes; at 4:4:4 the plane block is the luma
2990529912 // block itself (never 4-wide), so every one of those blocks was silently
29906- // missing its above-pass chroma OBMC blend. Derive ss from `chroma_side`
29907- // (`obmc_plan` has no `fctx`, and the encoder callsite passes the same
29908- // square pair).
29909- let ss_x = (write_w / chroma_side).trailing_zeros() as usize;
29910- let ss_y = (write_h / chroma_side).trailing_zeros() as usize;
29911- let skip_chroma_above =
29912- matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8));
29913+ // missing its above-pass chroma OBMC blend.
29914+ // lane-av1-llpred2: ss is the FRAME's own pair (`ss_x`/`ss_y(fctx)`, the
29915+ // same values [`obmc_run`]'s chroma windows shift by), never a ratio of
29916+ // the rect write size over the square `chroma_side` -- that ratio gave a
29917+ // 4:2:0 16x8 strip ss=(1,0) and dropped its above-chroma skip, and at
29918+ // 4:4:4 divided to zero (`trailing_zeros(0)` = 64, a debug shift panic).
29919+ let skip_chroma_above = obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y);
2991329920 let mut above = Vec::new();
2991429921 for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
2991529922 {
@@ -29981,6 +29988,56 @@ pub(crate) fn obmc_plan(
2998129988 })
2998229989 }
2998329990
29991+/// `av1_skip_u4x4_pred_in_obmc`'s above-pass decision (libaom
29992+/// `reconinter.c` 829): the PLANE block (`write_w >> ss_x`, `write_h >>
29993+/// ss_y`) is 4x4, 8x4 or 4x8. `ss_x`/`ss_y` are the FRAME's own pair -- the
29994+/// same values [`obmc_run`]'s chroma windows shift by -- never a ratio over
29995+/// the square `chroma_side` (lane-av1-llpred2: that ratio dropped the
29996+/// 4:2:0 16x8/8x16 skip and shifted by 64 at 4:4:4). Pure so the check
29997+/// below pins the rect-strip decision without decoding a stream.
29998+pub(crate) fn obmc_skip_chroma_above(
29999+ write_w: usize,
30000+ write_h: usize,
30001+ ss_x: usize,
30002+ ss_y: usize,
30003+) -> bool {
30004+ matches!(
30005+ (write_w >> ss_x, write_h >> ss_y),
30006+ (4, 4) | (8, 4) | (4, 8)
30007+ )
30008+}
30009+
30010+#[cfg(test)]
30011+mod obmc_skip_chroma_tests {
30012+ use super::obmc_skip_chroma_above;
30013+
30014+ /// lane-av1-llpred2: the above-chroma skip keys off the PLANE block
30015+ /// under the frame's own ss pair. At 4:2:0 a 16x8/8x16 rect strip's
30016+ /// plane block is 8x4/4x8 and MUST still skip (the old `chroma_side`
30017+ /// ratio read ss=(1,0) off a 16x8 strip and made it blend); at 4:4:4
30018+ /// the plane block is the luma block, so only true 4-wide/high shapes
30019+ /// skip and the shift never leaves `usize` range (the old ratio's
30020+ /// `trailing_zeros(0)` = 64 panicked a debug build).
30021+ #[test]
30022+ fn rect_strips_skip_above_chroma_at_420_and_shift_never_overflows() {
30023+ // 4:2:0 (ss 1,1): 8x8 -> 4x4, 16x8 -> 8x4, 8x16 -> 4x8 all skip.
30024+ assert!(obmc_skip_chroma_above(8, 8, 1, 1));
30025+ assert!(obmc_skip_chroma_above(16, 8, 1, 1));
30026+ assert!(obmc_skip_chroma_above(8, 16, 1, 1));
30027+ // ... larger plane blocks blend, exactly libaom's own list.
30028+ assert!(!obmc_skip_chroma_above(16, 16, 1, 1));
30029+ assert!(!obmc_skip_chroma_above(32, 16, 1, 1));
30030+ assert!(!obmc_skip_chroma_above(16, 32, 1, 1));
30031+ // 4:4:4 (ss 0,0): the plane block is the luma block itself.
30032+ assert!(obmc_skip_chroma_above(4, 4, 0, 0));
30033+ assert!(obmc_skip_chroma_above(8, 4, 0, 0));
30034+ assert!(obmc_skip_chroma_above(4, 8, 0, 0));
30035+ assert!(!obmc_skip_chroma_above(8, 8, 0, 0));
30036+ assert!(!obmc_skip_chroma_above(16, 8, 0, 0));
30037+ assert!(!obmc_skip_chroma_above(8, 16, 0, 0));
30038+ }
30039+}
30040+
2998430041 /// One OBMC neighbour as the PARSE thread resolved it (lane-defer8): every
2998530042 /// value [`obmc_run`] needs that lives in the mode-info grid or the
2998630043 /// neighbour bands, which the parse keeps overwriting as it walks on.
@@ -32938,6 +32995,8 @@ fn decode_inter_block(
3293832995 side,
3293932996 write_w,
3294032997 write_h,
32998+ ss_x(fctx),
32999+ ss_y(fctx),
3294133000 chroma_side,
3294233001 px,
3294333002 py,
@@ -38279,6 +38338,8 @@ fn decode_inter_block8(
3827938338 SIDE,
3828038339 SIDE,
3828138340 SIDE,
38341+ ss_x(fctx),
38342+ ss_y(fctx),
3828238343 chroma_side,
3828338344 px,
3828438345 py,
crates/ec-av1/src/encode.rsmodified+2 -0
@@ -6801,6 +6801,8 @@ fn obmc_prediction(
68016801 side,
68026802 side,
68036803 side,
6804+ crate::decode::ss_x(fctx),
6805+ crate::decode::ss_y(fctx),
68046806 side / 2,
68056807 x,
68066808 y,
lanes/av1llpred2.report.mdadded+62 -0
@@ -0,0 +1,62 @@
1+# lane-av1-llpred2: `skip_chroma_above` must read the frame's own ss pair, not a rect-over-square ratio
2+
3+## Ticket
4+
5+Reviewer FAIL on 71f07edd's `obmc_plan`: both ss axes were derived from ONE
6+square chroma side, `ss = trailing_zeros(write_w|write_h / chroma_side)`.
7+Two defects, one root:
8+
9+1. 4:2:0, a 16x8 strip: `write_h/chroma_side = 8/8 = 1`, `trailing_zeros(1)`
10+ = 0, so ss=(1,0) and the plane block read (8,8) — `skip_chroma_above`
11+ went FALSE. The old pre-llpred code skipped, and libaom's
12+ `av1_skip_u4x4_pred_in_obmc` (reconinter.c 829) skips on the PLANE block
13+ `(8,4)` (frame ss (1,1)). Every 4:2:0 16x8/8x16 OBMC strip blended a
14+ chroma above pass the reference never blends (and would desync a
15+ stream that carries one).
16+2. 4:4:4, a 16x8 strip: `write_h/chroma_side = 8/16 = 0`,
17+ `trailing_zeros(0)` = 64, `write_h >> 64` panics in a debug build.
18+ The parent lane's byte-exact claim was measured in a release build,
19+ where the out-of-range shift wraps instead of panicking.
20+
21+## Change (this tree @ 71f07edd + the fix)
22+
23+`obmc_plan` takes `ss_x`/`ss_y` — the FRAME's own pair, exactly what the
24+chroma window half in `obmc_run` shifts by (`ss_x(fctx)`/`ss_y(fctx)`) —
25+and the decision moved to a pure helper:
26+
27+```rust
28+pub(crate) fn obmc_skip_chroma_above(write_w, write_h, ss_x, ss_y) -> bool {
29+ matches!((write_w >> ss_x, write_h >> ss_y), (4, 4) | (8, 4) | (4, 8))
30+}
31+```
32+
33+All three callsites pass the frame pair: `decode_inter_block`,
34+`decode_inter_block8` (`ss_x(fctx), ss_y(fctx)`), and the encoder's
35+`obmc_prediction` (`crate::decode::ss_x(fctx)`, 4:2:0-only encoder). No
36+ratio over `chroma_side` survives; `trailing_zeros` of anything is gone.
37+The window-size half that reduces to `/2` at 4:2:0 is untouched, and the
38+reserved 4:2:0 group-tail chroma arm is untouched.
39+
40+## Proof (debug build, `dev` profile throughout)
41+
42+- Decision check (new `obmc_skip_chroma_tests`):
43+ `rect_strips_skip_above_chroma_at_420_and_shift_never_overflows` pins
44+ 4:2:0 (16,8,1,1) and (8,16,1,1) → SKIP (with (8,8,1,1), and
45+ (16,16)/(32,16)/(16,32) → blend), and 4:4:4 → only true 4-wide/high
46+ shapes skip, (16,8,0,0)/(8,16,0,0)/(8,8,0,0) → blend with no shift
47+ out of `usize` range. No hit-counter gate was added: the skip
48+ decision itself is what is proven.
49+- 6-frame 4:4:4 stream, DEBUG decode probe: fixture
50+ `/tmp/llintra8/testsrc2_min8.obu`
51+ sha256 `04fb6d38de5382e647bfb70b6a17802f1fccc5502e6698c0394167891f2b27dc`,
52+ `$HOME/.cache/cargo-target-av1llpred2/debug/examples/decode_probe`
53+ → 6 frames, 221184 bytes, `cmp`-equal to fresh
54+ `$HOME/.cache/aom-oracle/build/aomdec --rawvideo`. Byte-exact, now in
55+ a build that would have panicked on the old code.
56+- 4:2:0 non-regression: `cargo test -p ec-av1 --lib -- obmc_skip_chroma
57+ a_lossless` → 7 passed, 0 failed (the new check + the 4:2:0 lossless
58+ libaom gates, the 444 min-partition-64 inter gate, the sb128 pair, the
59+ 16x4 pair).
60+- `cargo check -p ec-av1 --all-targets`
61+ (`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1llpred2`): 0 warnings,
62+ 0 errors.