lane-av1-llpred2: skip_chroma_above reads the frame ss pair, not a rect-over-chroma_side ratio
Browse files at this commit0db45d1743d47963e97f77d3b3f6b76e756142c7Parent: ab305463 changed files +132 -7
- crates/ec-av1/src/decode.rs +68 -7
- crates/ec-av1/src/encode.rs +2 -0
- lanes/av1llpred2.report.md +62 -0
crates/ec-av1/src/decode.rsmodified+68 -7
| @@ -29853,6 +29853,13 @@ pub(crate) fn obmc_plan( | ||
| 29853 | 29853 | side: usize, |
| 29854 | 29854 | write_w: usize, |
| 29855 | 29855 | 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, | |
| 29856 | 29863 | chroma_side: usize, |
| 29857 | 29864 | px: usize, |
| 29858 | 29865 | py: usize, |
| @@ -29903,13 +29910,13 @@ pub(crate) fn obmc_plan( | ||
| 29903 | 29910 | // lane-av1-llpred: the old luma-shape list `(8,8)|(16,8)|(8,16)` |
| 29904 | 29911 | // hardcoded the 4:2:0 plane sizes; at 4:4:4 the plane block is the luma |
| 29905 | 29912 | // 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); | |
| 29913 | 29920 | let mut above = Vec::new(); |
| 29914 | 29921 | for (off4, span4, nb, src4) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) |
| 29915 | 29922 | { |
| @@ -29981,6 +29988,56 @@ pub(crate) fn obmc_plan( | ||
| 29981 | 29988 | }) |
| 29982 | 29989 | } |
| 29983 | 29990 | |
| 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 | + | |
| 29984 | 30041 | /// One OBMC neighbour as the PARSE thread resolved it (lane-defer8): every |
| 29985 | 30042 | /// value [`obmc_run`] needs that lives in the mode-info grid or the |
| 29986 | 30043 | /// neighbour bands, which the parse keeps overwriting as it walks on. |
| @@ -32938,6 +32995,8 @@ fn decode_inter_block( | ||
| 32938 | 32995 | side, |
| 32939 | 32996 | write_w, |
| 32940 | 32997 | write_h, |
| 32998 | + ss_x(fctx), | |
| 32999 | + ss_y(fctx), | |
| 32941 | 33000 | chroma_side, |
| 32942 | 33001 | px, |
| 32943 | 33002 | py, |
| @@ -38279,6 +38338,8 @@ fn decode_inter_block8( | ||
| 38279 | 38338 | SIDE, |
| 38280 | 38339 | SIDE, |
| 38281 | 38340 | SIDE, |
| 38341 | + ss_x(fctx), | |
| 38342 | + ss_y(fctx), | |
| 38282 | 38343 | chroma_side, |
| 38283 | 38344 | px, |
| 38284 | 38345 | py, |
crates/ec-av1/src/encode.rsmodified+2 -0
| @@ -6801,6 +6801,8 @@ fn obmc_prediction( | ||
| 6801 | 6801 | side, |
| 6802 | 6802 | side, |
| 6803 | 6803 | side, |
| 6804 | + crate::decode::ss_x(fctx), | |
| 6805 | + crate::decode::ss_y(fctx), | |
| 6804 | 6806 | side / 2, |
| 6805 | 6807 | x, |
| 6806 | 6808 | 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. |