forge
Explore
Log in

Don't you dare go Hollow

OBMC overlappable-neighbour walk never ported libaom's mi_step==1 chroma-pair merge

Browse files at this commit

0ee3ba419fd7f8a6a48c6cc11375bbae3778bacdAhmet Kaan GümüşParent: e5f8021
  • fix
    • OBMC overlappable-neighbour walk never ported libaom's mi_step==1 chroma-pair merge
Show full message
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.rsmodified+33 -8
@@ -18084,10 +18084,17 @@ fn ref_planes<'a>(
1808418084 /// unit at a time, and does not itself count as a step). `max_neighbors`
1808518085 /// caller-bounds the scan: `1` for the eligibility check (any hit at all),
1808618086 /// `av1_build_obmc_inter_prediction`'s own `max_neighbor_obmc` table for the
18087-/// real blend pass. Round 1 corner-cut: libaom's own "4-wide block, treat as
18088-/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) is
18089-/// not ported -- no block this decoder codes is narrower than 8px, so it
18090-/// never fires here regardless of what a neighbour's own decoder was.
18087+/// real blend pass. lane-intra16x4 r2: libaom's own "4-wide block, treat as
18088+/// half of a chroma pair" merge (`obmc.h`'s `mi_step == 1` special case) IS
18089+/// ported below -- the round-1 note that no block is narrower than 8px stopped
18090+/// being true when the 1:4 partitions landed. A 16x4 / 4x16 strip has
18091+/// `mi_size_high`/`mi_size_wide` 1, so libaom snaps the walk back to the pair's
18092+/// even index, reads the ODD (chroma-carrying) half as the neighbour and steps
18093+/// by 2. Measured: the 16x16 block right of a 16x16-level HORZ_4 partition
18094+/// whose strip 0 is inter and strips 1..3 intra counted that inter strip as
18095+/// overlappable here, while libaom's pair merge reads the INTRA strip 1 and
18096+/// counts none -- so we read a `motion_mode` symbol libaom never wrote (class
18097+/// `symbol-consumption-gap`), desyncing the tile at the next coefficient.
1809118098 fn overlappable_above(
1809218099 grid: &MiGrid,
1809318100 mi_row: usize,
@@ -18104,8 +18111,17 @@ fn overlappable_above(
1810418111 let mut col = mi_col;
1810518112 while col < end_col && out.len() < max_neighbors {
1810618113 let cell = grid.get(mi_row - 1, col);
18107- let step = cell.map_or(1, |c| c.size).max(1);
18108- if let Some(info) = cell {
18114+ let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize);
18115+ let mut nb = cell;
18116+ if step == 1 {
18117+ // The pair merge: the walk snaps back to the pair's even column
18118+ // and the ODD half (the chroma-carrying one) is the neighbour for
18119+ // both -- a 4-wide 1:4 strip is never an OBMC source on its own.
18120+ col &= !1;
18121+ nb = grid.get(mi_row - 1, col + 1);
18122+ step = 2;
18123+ }
18124+ if let Some(info) = nb {
1810918125 if info.is_inter {
1811018126 out.push((col - mi_col, step.min(end_col - col), *info));
1811118127 }
@@ -18135,8 +18151,17 @@ fn overlappable_left(
1813518151 let cell = grid.get(row, mi_col - 1);
1813618152 // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's
1813718153 // width (8) would swallow the strip below it.
18138- let step = cell.map_or(1, |c| c.size_h).max(1);
18139- if let Some(info) = cell {
18154+ let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize);
18155+ let mut nb = cell;
18156+ if step == 1 {
18157+ // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x4
18158+ // strip) is half of a chroma pair and the pair's SECOND row is the
18159+ // neighbour for both.
18160+ row &= !1;
18161+ nb = grid.get(row + 1, mi_col - 1);
18162+ step = 2;
18163+ }
18164+ if let Some(info) = nb {
1814018165 if info.is_inter {
1814118166 out.push((row - mi_row, step.min(end_row - row), *info));
1814218167 }
crates/ec-av1/src/stream.rsmodified+29 -11
@@ -10995,10 +10995,14 @@ mod tests {
1099510995
1099610996
1099710997 #[test]
10998- #[ignore = "RED at lane-intra16x4 r1: the decode path is behind \
10999- EC_INTRA16X4_DECODE=1 and still mismatches ffmpeg (attempt 1, 8-bit, 192x128 \
11000- cq60: frame 1 luma differs from (175, 0), 8400 px, with the two intra 16x4 \
11001- strips at mi(1,40)/(3,40) themselves exact) -- lanes/intra16x4-r1.report.md"]
10998+ #[ignore = "RED at lane-intra16x4 r2, but NOT on this lane's shape: the r2 OBMC \
10999+ pair-merge fix makes the decode entropy-exact through the intra 16x4 strips \
11000+ (620/620 all_zero symbols match aomdec, value and range), and the new arm 4 \
11001+ (bar_h, cq63, --min-partition-size=8, 192x128, 5 strips) decodes 6 frames \
11002+ bit-exact vs ffmpeg outside the harness. Attempt 0 (noise, cq60, 128x128) \
11003+ still mismatches from (122, 13) -- 99 rows ABOVE its first strip, measured in \
11004+ r1 as another shape's defect -- and panics before arm 4 runs. Un-ignore once \
11005+ attempt 0's defect is owned -- lanes/intra16x4-r2.handoff.md"]
1100211006 // lane-intra16x4 r1: an INTRA-coded 16x4 / 4x16 strip inside an INTER
1100311007 // frame's 16x16-level 1:4 partition -- the wall all six of his film cuts
1100411008 // stopped at once lane-rectres landed. The shape's chroma is the pair's:
@@ -11036,11 +11040,18 @@ mod tests {
1103611040 // aomenc's RD pick intra at 16x4), `prod` an `X*Y` product sinusoid
1103711041 // under temporal noise; `_v` transposes the structure so the RD picks
1103811042 // PARTITION_VERT_4.
11039- const RECIPES: [(&str, u32, usize, usize); 4] = [
11040- ("noise", 60, 128, 128),
11041- ("bar", 60, 192, 128),
11042- ("prod_v", 56, 128, 128),
11043- ("prod", 56, 160, 128),
11043+ // lane-intra16x4 r2: the last field is `--min-partition-size` -- the
11044+ // `bar_h` recipe (a horizontal bar sweeping DOWN the frame) at
11045+ // `--min-partition-size=8` is the one recipe of the r2 96-run sweep
11046+ // (`~/.cache/intra16x4-tmp/sweep_r2.sh`) that fires intra 16x4 strips
11047+ // WITHOUT also carrying the sub-8x8 intra block another lane refuses,
11048+ // so it is the arm that can be pixel-compared at all.
11049+ const RECIPES: [(&str, u32, usize, usize, u32); 5] = [
11050+ ("noise", 60, 128, 128, 4),
11051+ ("bar", 60, 192, 128, 4),
11052+ ("prod_v", 56, 128, 128, 4),
11053+ ("prod", 56, 160, 128, 4),
11054+ ("bar_h", 63, 192, 128, 8),
1104411055 ];
1104511056 // [16x4 intra strips, 4x16 intra strips, of which chroma-reference]:
1104611057 // how many pixel-exact attempts fired each, over both bit depths.
@@ -11054,7 +11065,7 @@ mod tests {
1105411065 (0u32, 0u32, 0u32, 0u32);
1105511066 let mut arms_proved = [0u32; 3];
1105611067 for attempt in 0..RECIPES.len() as u32 {
11057- let (kind, cq, width, height) = RECIPES[attempt as usize];
11068+ let (kind, cq, width, height, min_part) = RECIPES[attempt as usize];
1105811069 let duration = frame_count as f64 / 25.0;
1105911070 // Both sources are deterministic (two identical y4m hashes,
1106011071 // report): `random()` here is geq's own indexed PRNG and the
@@ -11070,6 +11081,12 @@ mod tests {
1107011081 ),
1107111082 "",
1107211083 ),
11084+ "bar_h" => (
11085+ format!(
11086+ "if(lt(mod(Y+N*37,{height}),24),random(N*100+X+Y)*255,128+50*sin(X/7))"
11087+ ),
11088+ "",
11089+ ),
1107311090 "prod_v" => (
1107411091 "128+60*sin((X*Y+N*97)/13)+50*sin((Y+N*11)/5)".to_string(),
1107511092 ",noise=alls=25:allf=t:all_seed=11",
@@ -11100,6 +11117,7 @@ mod tests {
1110011117 String::from_utf8_lossy(&y4m.stderr)
1110111118 );
1110211119 let cq_arg = format!("--cq-level={cq}");
11120+ let min_part_arg = format!("--min-partition-size={min_part}");
1110311121 let depth_arg = format!("--bit-depth={bit_depth}");
1110411122 let input_depth_arg = format!("--input-bit-depth={bit_depth}");
1110511123 let args: Vec<&str> = vec![
@@ -11113,7 +11131,7 @@ mod tests {
1111311131 "--enable-tx-size-search=1", "--enable-rect-partitions=1",
1111411132 "--enable-ab-partitions=1", "--enable-1to4-partitions=1",
1111511133 "--enable-intra-edge-filter=1",
11116- "--min-partition-size=4", "--max-partition-size=16",
11134+ &min_part_arg, "--max-partition-size=16",
1111711135 "--obu", "-o", "-", "-",
1111811136 ];
1111911137 let mut child = Command::new(aomenc_path())
lanes/intra16x4-r2.handoff.mdadded+67 -0
@@ -0,0 +1,67 @@
1+# lane-intra16x4 r2 HANDOFF
2+
3+## Root cause (found, fixed, minimal)
4+
5+`overlappable_above` / `overlappable_left` (`crates/ec-av1/src/decode.rs` ~18092 / ~18130)
6+never ported libaom's `mi_step == 1` chroma-pair merge from
7+`av1/common/obmc.h` (`foreach_overlappable_nb_above` / `foreach_overlappable_nb_left`).
8+Round 1's doc comment declared it unreachable ("no block this decoder codes is narrower
9+than 8px") -- the 1:4 partitions made it reachable: a 16x4 / 4x16 strip has
10+`mi_size_high` / `mi_size_wide` == 1, so libaom snaps the walk back to the pair's EVEN
11+index, reads the ODD (chroma-carrying) half as the neighbour and steps by 2.
12+
13+Witness `~/.cache/intra16x4-tmp/s5.obu`, frame 1, block mi(0,44) (16x16, right of a
14+16x16-level HORZ_4 whose strip 0 is inter and strips 1..3 intra):
15+
16+* our walk read mi(0,43) = the INTER strip 0 -> 1 overlappable neighbour ->
17+ `motion_mode_allowed` true -> we READ a `motion_mode` symbol;
18+* libaom's pair merge reads mi(1,43) = the INTRA strip 1 -> 0 overlappable neighbours ->
19+ `read_motion_mode` returns SIMPLE_TRANSLATION WITHOUT reading a symbol.
20+
21+Class `symbol-consumption-gap`: rng 39440 -> ours 34918, aomdec 38204 (its
22+`EC_ISTEP2 name=motion_mode` print is unconditional, so an equal rng there means the
23+symbol was NOT read). The tile desynced at the very next coefficient: the first TU of
24+mi(0,44) read `all_zero=1` where libaom reads `all_zero=0, eob=59`, which is the
25+"prediction only, no residual" smooth block at px(176..178, 0..15) the r1 pixel
26+measurement saw as "first luma diff (175,0), 8400 px".
27+
28+The fix is inside the two walk functions only -- every caller (eligibility at ~20908 and
29+~24493, the OBMC blend pass at ~18716/18746) routes through them.
30+
31+## Proof
32+
33+* Entropy ladder AFTER the fix, `s5.obu`, ours `EC_TRACE_COEFF` vs instrumented aomdec
34+ `EC_TRACE_COEFF`: 620/620 `tag=all_zero` symbols identical in value AND range, up to the
35+ point our decoder stops on another lane's refusal ("an intra 8x4/4x8 block inside an
36+ inter frame's sub-8x8 HORZ/VERT partition"). Before the fix the first divergence was the
37+ 4th block of frame 1's 3rd superblock row.
38+* New green witness (r2 96-run sweep `~/.cache/intra16x4-tmp/sweep_r2.sh`):
39+ `bar_h` source (a horizontal bar sweeping DOWN), cq 63, `--min-partition-size=8`,
40+ 192x128, 8-bit -> 5 intra 16x4 strips (2 chroma-reference), 6 frames decoded and
41+ `cmp` EXACT against `ffmpeg -i ... -f rawvideo` (`~/.cache/intra16x4-tmp/g_8.obu`,
42+ md5 `2eaafd9eb56fbf9d597820ad74c9c4e3`). The 10-bit build of the same recipe decodes
43+ 6 frames but fires 0 strips (out of scope).
44+
45+## Gate + refusal state
46+
47+`a_real_aomenc_inter_sequence_with_intra_16x4_strips_in_1to4_partitions_decodes_pixel_exact`
48+gained that recipe as attempt 4 (`RECIPES` is now 5-wide with a per-arm
49+`--min-partition-size`). Run once with `--include-ignored --nocapture`: **RED, and not on
50+this lane's shape** -- attempt 0 (`noise`, cq60, 128x128) mismatches from (122, 13),
51+5466 px on frame 1, which r1 already measured as 99 rows ABOVE that stream's first strip
52+(strips at px(80,112)/(80,120)); it panics before attempt 4 runs. The test is therefore
53+still `#[ignore]`d, with that measurement in its reason string.
54+
55+**The refusal is NOT lifted**: `EC_INTRA16X4_DECODE=1` is still the bypass,
56+`refusal_inventory.rs` / `gate_coverage.rs` untouched.
57+
58+## Next step
59+
60+1. Own attempt 0's defect (128x128 cq60 `noise`, first diff (122,13) frame 1, arms
61+ [2,0,0]) -- ladder it the same way; it is a DIFFERENT shape and it is the only thing
62+ between this lane and a green gate.
63+2. Then reorder/prune `RECIPES` (or make the mismatch of an out-of-scope-for-this-shape
64+ arm non-fatal only with a named owner), un-ignore, lift the refusal, update
65+ `refusal_inventory.rs` + `gate_coverage.rs`.
66+3. Not run this round (turn cap): the full `cargo test -p ec-av1 --lib` suite and the film
67+ probes.