From 0ee3ba419fd7f8a6a48c6cc11375bbae3778bacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 17:37:59 +0300 Subject: [PATCH] fix(av1): OBMC overlappable-neighbour walk never ported libaom's mi_step==1 chroma-pair merge `overlappable_above`/`overlappable_left` (obmc.h `foreach_overlappable_nb_*`) skipped the "4-wide/4-tall neighbour is half of a chroma pair" case as unreachable; the 16x16-level 1:4 partitions made it reachable. The 16x16 block right of a HORZ_4 whose strip 0 is inter and strips 1..3 intra counted that inter strip as overlappable, so we read a motion_mode symbol libaom never wrote (its walk snaps back to the pair's even row and reads the INTRA strip 1), desyncing the tile at the next coefficient: first TU all_zero=1 vs the reference's eob=59. After the fix the 8-bit 192x128 witness matches aomdec on 620/620 all_zero symbols (value and range) up to another lane's sub-8x8 intra refusal, and a new gate recipe (horizontal-bar source, cq63, --min-partition-size=8, 192x128, 5 intra 16x4 strips) decodes 6 frames bit-exact vs ffmpeg. Gate run once with --include-ignored: still RED, on attempt 0 only -- a mismatch r1 measured as another shape (99 rows above that stream's first strip) which panics before the new arm runs, so the test stays #[ignore]d with that measurement and the refusal stays in place behind EC_INTRA16X4_DECODE. --- crates/ec-av1/src/decode.rs | 41 ++++++++++++++++----- crates/ec-av1/src/stream.rs | 40 +++++++++++++++------ lanes/intra16x4-r2.handoff.md | 67 +++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 lanes/intra16x4-r2.handoff.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5528a793..283c08df 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -18084,10 +18084,17 @@ fn ref_planes<'a>( /// unit at a time, and does not itself count as a step). `max_neighbors` /// caller-bounds the scan: `1` for the eligibility check (any hit at all), /// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the -/// real blend pass. Round 1 corner-cut: libaom's own "4-wide block, treat as -/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) is -/// not ported -- no block this decoder codes is narrower than 8px, so it -/// never fires here regardless of what a neighbour's own decoder was. +/// real blend pass. lane-intra16x4 r2: libaom's own "4-wide block, treat as +/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) IS +/// ported below -- the round-1 note that no block is narrower than 8px stopped +/// being true when the 1:4 partitions landed. A 16x4 / 4x16 strip has +/// `mi_size_high`/`mi_size_wide` 1, so libaom snaps the walk back to the pair's +/// even index, reads the ODD (chroma-carrying) half as the neighbour and steps +/// by 2. Measured: the 16x16 block right of a 16x16-level HORZ_4 partition +/// whose strip 0 is inter and strips 1..3 intra counted that inter strip as +/// overlappable here, while libaom's pair merge reads the INTRA strip 1 and +/// counts none -- so we read a `motion_mode` symbol libaom never wrote (class +/// `symbol-consumption-gap`), desyncing the tile at the next coefficient. fn overlappable_above( grid: &MiGrid, mi_row: usize, @@ -18104,8 +18111,17 @@ fn overlappable_above( let mut col = mi_col; while col < end_col && out.len() < max_neighbors { let cell = grid.get(mi_row - 1, col); - let step = cell.map_or(1, |c| c.size).max(1); - if let Some(info) = cell { + let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize); + let mut nb = cell; + if step == 1 { + // The pair merge: the walk snaps back to the pair's even column + // and the ODD half (the chroma-carrying one) is the neighbour for + // both -- a 4-wide 1:4 strip is never an OBMC source on its own. + col &= !1; + nb = grid.get(mi_row - 1, col + 1); + step = 2; + } + if let Some(info) = nb { if info.is_inter { out.push((col - mi_col, step.min(end_col - col), *info)); } @@ -18135,8 +18151,17 @@ fn overlappable_left( let cell = grid.get(row, mi_col - 1); // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's // width (8) would swallow the strip below it. - let step = cell.map_or(1, |c| c.size_h).max(1); - if let Some(info) = cell { + let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize); + let mut nb = cell; + if step == 1 { + // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x4 + // strip) is half of a chroma pair and the pair's SECOND row is the + // neighbour for both. + row &= !1; + nb = grid.get(row + 1, mi_col - 1); + step = 2; + } + if let Some(info) = nb { if info.is_inter { out.push((row - mi_row, step.min(end_row - row), *info)); } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 33115438..358eb087 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -10995,10 +10995,14 @@ mod tests { #[test] - #[ignore = "RED at lane-intra16x4 r1: the decode path is behind \ - EC_INTRA16X4_DECODE=1 and still mismatches ffmpeg (attempt 1, 8-bit, 192x128 \ - cq60: frame 1 luma differs from (175, 0), 8400 px, with the two intra 16x4 \ - strips at mi(1,40)/(3,40) themselves exact) -- lanes/intra16x4-r1.report.md"] + #[ignore = "RED at lane-intra16x4 r2, but NOT on this lane's shape: the r2 OBMC \ + pair-merge fix makes the decode entropy-exact through the intra 16x4 strips \ + (620/620 all_zero symbols match aomdec, value and range), and the new arm 4 \ + (bar_h, cq63, --min-partition-size=8, 192x128, 5 strips) decodes 6 frames \ + bit-exact vs ffmpeg outside the harness. Attempt 0 (noise, cq60, 128x128) \ + still mismatches from (122, 13) -- 99 rows ABOVE its first strip, measured in \ + r1 as another shape's defect -- and panics before arm 4 runs. Un-ignore once \ + attempt 0's defect is owned -- lanes/intra16x4-r2.handoff.md"] // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER // frame's 16x16-level 1:4 partition -- the wall all six of his film cuts // stopped at once lane-rectres landed. The shape's chroma is the pair's: @@ -11036,11 +11040,18 @@ mod tests { // aomenc's RD pick intra at 16x4), `prod` an `X*Y` product sinusoid // under temporal noise; `_v` transposes the structure so the RD picks // PARTITION_VERT_4. - const RECIPES: [(&str, u32, usize, usize); 4] = [ - ("noise", 60, 128, 128), - ("bar", 60, 192, 128), - ("prod_v", 56, 128, 128), - ("prod", 56, 160, 128), + // lane-intra16x4 r2: the last field is `--min-partition-size` -- the + // `bar_h` recipe (a horizontal bar sweeping DOWN the frame) at + // `--min-partition-size=8` is the one recipe of the r2 96-run sweep + // (`~/.cache/intra16x4-tmp/sweep_r2.sh`) that fires intra 16x4 strips + // WITHOUT also carrying the sub-8x8 intra block another lane refuses, + // so it is the arm that can be pixel-compared at all. + const RECIPES: [(&str, u32, usize, usize, u32); 5] = [ + ("noise", 60, 128, 128, 4), + ("bar", 60, 192, 128, 4), + ("prod_v", 56, 128, 128, 4), + ("prod", 56, 160, 128, 4), + ("bar_h", 63, 192, 128, 8), ]; // [16x4 intra strips, 4x16 intra strips, of which chroma-reference]: // how many pixel-exact attempts fired each, over both bit depths. @@ -11054,7 +11065,7 @@ mod tests { (0u32, 0u32, 0u32, 0u32); let mut arms_proved = [0u32; 3]; for attempt in 0..RECIPES.len() as u32 { - let (kind, cq, width, height) = RECIPES[attempt as usize]; + let (kind, cq, width, height, min_part) = RECIPES[attempt as usize]; let duration = frame_count as f64 / 25.0; // Both sources are deterministic (two identical y4m hashes, // report): `random()` here is geq's own indexed PRNG and the @@ -11070,6 +11081,12 @@ mod tests { ), "", ), + "bar_h" => ( + format!( + "if(lt(mod(Y+N*37,{height}),24),random(N*100+X+Y)*255,128+50*sin(X/7))" + ), + "", + ), "prod_v" => ( "128+60*sin((X*Y+N*97)/13)+50*sin((Y+N*11)/5)".to_string(), ",noise=alls=25:allf=t:all_seed=11", @@ -11100,6 +11117,7 @@ mod tests { String::from_utf8_lossy(&y4m.stderr) ); let cq_arg = format!("--cq-level={cq}"); + let min_part_arg = format!("--min-partition-size={min_part}"); let depth_arg = format!("--bit-depth={bit_depth}"); let input_depth_arg = format!("--input-bit-depth={bit_depth}"); let args: Vec<&str> = vec![ @@ -11113,7 +11131,7 @@ mod tests { "--enable-tx-size-search=1", "--enable-rect-partitions=1", "--enable-ab-partitions=1", "--enable-1to4-partitions=1", "--enable-intra-edge-filter=1", - "--min-partition-size=4", "--max-partition-size=16", + &min_part_arg, "--max-partition-size=16", "--obu", "-o", "-", "-", ]; let mut child = Command::new(aomenc_path()) diff --git a/lanes/intra16x4-r2.handoff.md b/lanes/intra16x4-r2.handoff.md new file mode 100644 index 00000000..c5630c11 --- /dev/null +++ b/lanes/intra16x4-r2.handoff.md @@ -0,0 +1,67 @@ +# lane-intra16x4 r2 HANDOFF + +## Root cause (found, fixed, minimal) + +`overlappable_above` / `overlappable_left` (`crates/ec-av1/src/decode.rs` ~18092 / ~18130) +never ported libaom's `mi_step == 1` chroma-pair merge from +`av1/common/obmc.h` (`foreach_overlappable_nb_above` / `foreach_overlappable_nb_left`). +Round 1's doc comment declared it unreachable ("no block this decoder codes is narrower +than 8px") -- the 1:4 partitions made it reachable: a 16x4 / 4x16 strip has +`mi_size_high` / `mi_size_wide` == 1, so libaom snaps the walk back to the pair's EVEN +index, reads the ODD (chroma-carrying) half as the neighbour and steps by 2. + +Witness `~/.cache/intra16x4-tmp/s5.obu`, frame 1, block mi(0,44) (16x16, right of a +16x16-level HORZ_4 whose strip 0 is inter and strips 1..3 intra): + +* our walk read mi(0,43) = the INTER strip 0 -> 1 overlappable neighbour -> + `motion_mode_allowed` true -> we READ a `motion_mode` symbol; +* libaom's pair merge reads mi(1,43) = the INTRA strip 1 -> 0 overlappable neighbours -> + `read_motion_mode` returns SIMPLE_TRANSLATION WITHOUT reading a symbol. + +Class `symbol-consumption-gap`: rng 39440 -> ours 34918, aomdec 38204 (its +`EC_ISTEP2 name=motion_mode` print is unconditional, so an equal rng there means the +symbol was NOT read). The tile desynced at the very next coefficient: the first TU of +mi(0,44) read `all_zero=1` where libaom reads `all_zero=0, eob=59`, which is the +"prediction only, no residual" smooth block at px(176..178, 0..15) the r1 pixel +measurement saw as "first luma diff (175,0), 8400 px". + +The fix is inside the two walk functions only -- every caller (eligibility at ~20908 and +~24493, the OBMC blend pass at ~18716/18746) routes through them. + +## Proof + +* Entropy ladder AFTER the fix, `s5.obu`, ours `EC_TRACE_COEFF` vs instrumented aomdec + `EC_TRACE_COEFF`: 620/620 `tag=all_zero` symbols identical in value AND range, up to the + point our decoder stops on another lane's refusal ("an intra 8x4/4x8 block inside an + inter frame's sub-8x8 HORZ/VERT partition"). Before the fix the first divergence was the + 4th block of frame 1's 3rd superblock row. +* New green witness (r2 96-run sweep `~/.cache/intra16x4-tmp/sweep_r2.sh`): + `bar_h` source (a horizontal bar sweeping DOWN), cq 63, `--min-partition-size=8`, + 192x128, 8-bit -> 5 intra 16x4 strips (2 chroma-reference), 6 frames decoded and + `cmp` EXACT against `ffmpeg -i ... -f rawvideo` (`~/.cache/intra16x4-tmp/g_8.obu`, + md5 `2eaafd9eb56fbf9d597820ad74c9c4e3`). The 10-bit build of the same recipe decodes + 6 frames but fires 0 strips (out of scope). + +## Gate + refusal state + +`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact` +gained that recipe as attempt 4 (`RECIPES` is now 5-wide with a per-arm +`--min-partition-size`). Run once with `--include-ignored --nocapture`: **RED, and not on +this lane's shape** -- attempt 0 (`noise`, cq60, 128x128) mismatches from (122, 13), +5466 px on frame 1, which r1 already measured as 99 rows ABOVE that stream's first strip +(strips at px(80,112)/(80,120)); it panics before attempt 4 runs. The test is therefore +still `#[ignore]`d, with that measurement in its reason string. + +**The refusal is NOT lifted**: `EC_INTRA16X4_DECODE=1` is still the bypass, +`refusal_inventory.rs` / `gate_coverage.rs` untouched. + +## Next step + +1. Own attempt 0's defect (128x128 cq60 `noise`, first diff (122,13) frame 1, arms + [2,0,0]) -- ladder it the same way; it is a DIFFERENT shape and it is the only thing + between this lane and a green gate. +2. Then reorder/prune `RECIPES` (or make the mismatch of an out-of-scope-for-this-shape + arm non-fatal only with a named owner), un-ignore, lift the refusal, update + `refusal_inventory.rs` + `gate_coverage.rs`. +3. Not run this round (turn cap): the full `cargo test -p ec-av1 --lib` suite and the film + probes.