forge
Explore
Log in

Don't you dare go Hollow

A 16x16 inter leaf splits into four 8x8 ones on cost

Browse files at this commit

17448fad957f0c4c72caaa4a05bb6345b9959c96Ahmet Kaan GümüşParent: 62967a8
  • feat
    • a 16x16 inter leaf splits into four 8x8 ones on cost
Show full message
feat(av1): a 16x16 inter leaf splits into four 8x8 ones on cost

The quadtree now runs 32 -> 16 -> 8 inside an inter frame: a 16x16 leaf
wholly inside the frame that carries `eight` is written as a real
PARTITION_SPLIT at BLOCK_16X16 with four 8x8 leaves, where before only a
leaf the true frame edge cut through was ever split (and then on geometry,
with the edge's gathered flag). Same skipped-block prune one level up.

The desync this first shipped with was the skip/intra-inter neighbour
context: `Neighbours` kept it per 16x16 slot, so all four leaves read the
slot's coarse state and left only the last leaf's behind. Under a real
split the bottom-left leaf's above neighbour is the FIRST leaf and the
bottom-right's above and left are two different ones -- the arrays are now
per 4x4 mode-info unit, like `above_side_mi` already was, and each leaf
reads and records its own cells (which also retires the single-previous-
leaf override the straddling path used).

BD-rate vs libaom / rav1e, same 12-frame recipe:
  1080p  +294.5 -> +234.0  |  +215.8 -> +171.9
  2160p  +320.9 -> +260.3  |  +253.2 -> +203.2
  screen +395.6 -> +318.5  |  +181.1 -> +155.3
The 8-way split fires on 5.4% / 4.4% / 7.8% of 16x16 leaves.
crates/ec-av1/src/encode.rsmodified+109 -27
@@ -110,6 +110,17 @@ pub(crate) fn take_predicted_bits() -> Vec<f64> {
110110 PREDICTED_BITS.with(|p| std::mem::take(&mut *p.borrow_mut()))
111111 }
112112
113+/// Whether a 16x16 inter leaf may split into four 8x8 ones of its own.
114+const SPLIT_INTER_8: bool = true;
115+
116+/// [`SPLIT_INTER_8`], or what `EC_AV1_SPLIT_INTER8` names in a test build.
117+fn split_inter_8() -> bool {
118+ match std::env::var("EC_AV1_SPLIT_INTER8").ok() {
119+ Some(v) if cfg!(test) => v != "0",
120+ _ => SPLIT_INTER_8,
121+ }
122+}
123+
113124 /// Whether a 16x16 (or 8x8) leaf runs a motion search of its own beside the
114125 /// NEARESTMV candidate it always had.
115126 const LEAF_NEW_MV: bool = true;
@@ -142,9 +153,14 @@ fn split_inter_blocks() -> bool {
142153 /// How often each partition decision was taken since the last
143154 /// [`take_partition_hits`], so a gate can report how often a new partition
144155 /// fires rather than assume it does (gate-blind-to-feature). Index 0 is an
145-/// inter 32x32 block left whole, 1 one split into four 16x16 leaves.
146-static PARTITION_HITS: [std::sync::atomic::AtomicUsize; 2] =
147- [std::sync::atomic::AtomicUsize::new(0), std::sync::atomic::AtomicUsize::new(0)];
156+/// inter 32x32 block left whole, 1 one split into four 16x16 leaves; 2 is
157+/// such a leaf left whole, 3 one split into four 8x8 leaves of its own.
158+static PARTITION_HITS: [std::sync::atomic::AtomicUsize; 4] = [
159+ std::sync::atomic::AtomicUsize::new(0),
160+ std::sync::atomic::AtomicUsize::new(0),
161+ std::sync::atomic::AtomicUsize::new(0),
162+ std::sync::atomic::AtomicUsize::new(0),
163+];
148164
149165 /// Records one such decision.
150166 fn partition_hit(which: usize) {
@@ -153,8 +169,8 @@ fn partition_hit(which: usize) {
153169
154170 /// Takes (and clears) the counts.
155171 #[cfg(test)]
156-pub(crate) fn take_partition_hits() -> [usize; 2] {
157- [0, 1].map(|i| PARTITION_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
172+pub(crate) fn take_partition_hits() -> [usize; 4] {
173+ [0, 1, 2, 3].map(|i| PARTITION_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
158174 }
159175
160176 /// Whether a 32x32 block may be split into four 16x16 ones when the trial says
@@ -1965,11 +1981,16 @@ fn record_mi(grid: &mut MiGrid, mi_row: usize, mi_col: usize, size: u8, inter: O
19651981
19661982 /// The reconstructed samples one 32x32 square covers in all three planes, so
19671983 /// that a partition trial can be undone.
1968-fn snapshot(luma: &Plane, chroma: &[Plane; 2], (x, y): (usize, usize)) -> [Vec<u8>; 3] {
1984+fn snapshot(
1985+ luma: &Plane,
1986+ chroma: &[Plane; 2],
1987+ (x, y): (usize, usize),
1988+ side: usize,
1989+) -> [Vec<u8>; 3] {
19691990 [
1970- luma.snapshot(x, y, BLOCK),
1971- chroma[0].snapshot(x / 2, y / 2, BLOCK / 2),
1972- chroma[1].snapshot(x / 2, y / 2, BLOCK / 2),
1991+ luma.snapshot(x, y, side),
1992+ chroma[0].snapshot(x / 2, y / 2, side / 2),
1993+ chroma[1].snapshot(x / 2, y / 2, side / 2),
19731994 ]
19741995 }
19751996
@@ -1978,11 +1999,12 @@ fn restore(
19781999 luma: &mut Plane,
19792000 chroma: &mut [Plane; 2],
19802001 (x, y): (usize, usize),
2002+ side: usize,
19812003 saved: &[Vec<u8>; 3],
19822004 ) {
1983- luma.restore(x, y, BLOCK, &saved[0]);
1984- chroma[0].restore(x / 2, y / 2, BLOCK / 2, &saved[1]);
1985- chroma[1].restore(x / 2, y / 2, BLOCK / 2, &saved[2]);
2005+ luma.restore(x, y, side, &saved[0]);
2006+ chroma[0].restore(x / 2, y / 2, side / 2, &saved[1]);
2007+ chroma[1].restore(x / 2, y / 2, side / 2, &saved[2]);
19862008 }
19872009
19882010 /// Keeps the DC candidate plus the cheapest `top_k` (or fewer, once DC is set
@@ -2385,7 +2407,7 @@ pub(crate) fn encode_key_frame_inner(
23852407 }
23862408 let (x, y) = (col * BLOCK, row * BLOCK);
23872409 let (c0, r0) = (col * 2, row * 2);
2388- let base = snapshot(&luma, &chroma, (x, y));
2410+ let base = snapshot(&luma, &chroma, (x, y), BLOCK);
23892411
23902412 // spec `decode_partition`'s hasRows/hasCols recomputed at this
23912413 // 32x32 block's own half (see `crate::tile::has_half`): the
@@ -2459,11 +2481,11 @@ pub(crate) fn encode_key_frame_inner(
24592481 &mode_bits(above_mode[c0], left_mode[r0]), fctx,
24602482 );
24612483 cost_whole += search.lambda * partition_bits(BLOCK, false);
2462- let after_whole = snapshot(&luma, &chroma, (x, y));
2484+ let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);
24632485
24642486 // What four 16x16 blocks cost instead, each searched against
24652487 // the reconstruction the ones before it left.
2466- restore(&mut luma, &mut chroma, (x, y), &base);
2488+ restore(&mut luma, &mut chroma, (x, y), BLOCK, &base);
24672489 let mut split = Vec::with_capacity(4);
24682490 let mut cost_split = search.lambda
24692491 * (partition_bits(BLOCK, true) + 4.0 * partition_bits(SUB, false));
@@ -2545,7 +2567,7 @@ pub(crate) fn encode_key_frame_inner(
25452567 modes.extend_from_slice(&split_modes);
25462568 blocks.push(Quadrant::Split(split));
25472569 } else {
2548- restore(&mut luma, &mut chroma, (x, y), &after_whole);
2570+ restore(&mut luma, &mut chroma, (x, y), BLOCK, &after_whole);
25492571 for cell in 0..2 {
25502572 above_mode[c0 + cell] = whole.mode;
25512573 left_mode[r0 + cell] = whole.mode;
@@ -3284,7 +3306,7 @@ pub(crate) fn encode_inter_frame(
32843306 let stack =
32853307 find_mv_stack(&grid, mi_row, mi_col, 8, 8, LAST_FRAME, mi_cols, mi_rows);
32863308
3287- let base = snapshot(&luma, &chroma, (x, y));
3309+ let base = snapshot(&luma, &chroma, (x, y), BLOCK);
32883310 let (block, mut cost_whole) = search_inter_block(
32893311 &mut luma,
32903312 &mut chroma,
@@ -3296,7 +3318,7 @@ pub(crate) fn encode_inter_frame(
32963318 &stack, fctx,
32973319 );
32983320 cost_whole += search.lambda * partition_bits(BLOCK, false);
3299- let after_whole = snapshot(&luma, &chroma, (x, y));
3321+ let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);
33003322
33013323 // What four 16x16 leaves cost instead (spec
33023324 // PARTITION_SPLIT at BLOCK_32X32, which
@@ -3326,20 +3348,20 @@ pub(crate) fn encode_inter_frame(
33263348 });
33273349 let split = (!block.skip && leaves_legal && split_inter_blocks())
33283350 .then(|| {
3329- restore(&mut luma, &mut chroma, (x, y), &base);
3330- let mut cost = search.lambda
3331- * (partition_bits(BLOCK, true)
3332- + 4.0 * partition_bits(SUB, false));
3351+ restore(&mut luma, &mut chroma, (x, y), BLOCK, &base);
3352+ let mut cost = search.lambda * partition_bits(BLOCK, true);
33333353 let mut leaves = Vec::with_capacity(4);
33343354 for &(sr, sc) in &leaf_positions {
33353355 let (mi_row, mi_col) = (sr * 4, sc * 4);
3356+ let (lx, ly) = (sc * SUB, sr * SUB);
3357+ let leaf_base = snapshot(&luma, &chroma, (lx, ly), SUB);
33363358 let stack = find_mv_stack(
33373359 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
33383360 );
33393361 let (leaf, leaf_cost) = code_square_inter(
33403362 &mut luma,
33413363 &mut chroma,
3342- (sc * SUB, sr * SUB),
3364+ (lx, ly),
33433365 SUB,
33443366 &search,
33453367 &mode_bits_table,
@@ -3347,6 +3369,63 @@ pub(crate) fn encode_inter_frame(
33473369 &ref_y8,
33483370 &stack, fctx,
33493371 );
3372+ let leaf_cost = leaf_cost
3373+ + search.lambda * partition_bits(SUB, false);
3374+ let after_leaf = snapshot(&luma, &chroma, (lx, ly), SUB);
3375+
3376+ // And what four 8x8 leaves cost instead --
3377+ // the same tree one step further down, which
3378+ // the writer codes as a real PARTITION_SPLIT
3379+ // at BLOCK_16X16 (lane-av1rd2). Same
3380+ // skipped-block prune as the level above.
3381+ let eight = (!leaf.skip && split_inter_8())
3382+ .then(|| {
3383+ restore(
3384+ &mut luma, &mut chroma, (lx, ly), SUB, &leaf_base,
3385+ );
3386+ let mut cost8 = search.lambda
3387+ * (partition_bits(SUB, true)
3388+ + 4.0 * partition_bits(8, false));
3389+ let mut eight = Vec::with_capacity(4);
3390+ for i in 0..4 {
3391+ let (mr, mc) =
3392+ (mi_row + (i / 2) * 2, mi_col + (i % 2) * 2);
3393+ let stack8 = find_mv_stack(
3394+ &grid, mr, mc, 2, 2, LAST_FRAME, mi_cols, mi_rows,
3395+ );
3396+ let (leaf8, cost) = code_square_inter(
3397+ &mut luma,
3398+ &mut chroma,
3399+ (lx + (i % 2) * 8, ly + (i / 2) * 8),
3400+ 8,
3401+ &search,
3402+ &mode_bits_table,
3403+ reference,
3404+ &ref_y8,
3405+ &stack8, fctx,
3406+ );
3407+ cost8 += cost;
3408+ record_mi(&mut grid, mr, mc, 2, leaf8.inter);
3409+ eight.push(leaf8);
3410+ }
3411+ (eight, cost8)
3412+ });
3413+ match eight {
3414+ Some((eight, cost8)) if cost8 < leaf_cost => {
3415+ partition_hit(3);
3416+ cost += cost8;
3417+ leaves.push(BlockCoeffs {
3418+ eight: Some(eight),
3419+ ..BlockCoeffs::default()
3420+ });
3421+ continue;
3422+ }
3423+ Some(_) => restore(
3424+ &mut luma, &mut chroma, (lx, ly), SUB, &after_leaf,
3425+ ),
3426+ None => {}
3427+ }
3428+ partition_hit(2);
33503429 cost += leaf_cost;
33513430 record_mi(&mut grid, mi_row, mi_col, 4, leaf.inter);
33523431 leaves.push(leaf);
@@ -3362,7 +3441,7 @@ pub(crate) fn encode_inter_frame(
33623441 blocks[r32 * cols + c32] = Quadrant::Split(leaves);
33633442 continue;
33643443 }
3365- restore(&mut luma, &mut chroma, (x, y), &after_whole);
3444+ restore(&mut luma, &mut chroma, (x, y), BLOCK, &after_whole);
33663445 }
33673446 partition_hit(0);
33683447 record_mi(&mut grid, mi_row, mi_col, 8, block.inter);
@@ -6324,11 +6403,14 @@ mod tests {
63246403 // How often the inter split actually fired over this clip's four
63256404 // encodes, against the whole 32x32 that was the only outcome
63266405 // before (gate-blind-to-feature).
6327- let [whole32, split32] = take_partition_hits();
6406+ let [whole32, split32, whole16, split16] = take_partition_hits();
63286407 eprintln!(
6329- "{name}: inter 32x32 split into 16s {split32} of {} blocks ({:.1}%)",
6408+ "{name}: inter 32x32 split into 16s {split32} of {} blocks ({:.1}%); \
6409+ 16x16 leaves split into 8s {split16} of {} ({:.1}%)",
63306410 whole32 + split32,
6331- 100.0 * split32 as f64 / (whole32 + split32).max(1) as f64
6411+ 100.0 * split32 as f64 / (whole32 + split32).max(1) as f64,
6412+ whole16 + split16,
6413+ 100.0 * split16 as f64 / (whole16 + split16).max(1) as f64
63326414 );
63336415 let (aom, aom_wall) =
63346416 external_ladder(&source, width, height, "libaom-av1", &aom_points);
crates/ec-av1/src/tile.rsmodified+84 -37
@@ -629,6 +629,9 @@ struct Neighbours {
629629 left_side_mi: Vec<usize>,
630630 /// Whether the neighbour carried no residual, for [`sb_coeff_inter_frame_tile`]'s
631631 /// skip context. Unused (and left at its default) by the key frame writers.
632+ /// Kept per 4x4 mode-info unit, like [`Self::above_side_mi`] and for the
633+ /// same reason: under a real PARTITION_SPLIT to 8x8 the four leaves of a
634+ /// 16x16 read (and leave) different contexts inside one [`SUB`] slot.
632635 above_skip: Vec<bool>,
633636 /// The same, down the left edge.
634637 left_skip: Vec<bool>,
@@ -676,10 +679,10 @@ impl Neighbours {
676679 left_side: vec![SB; rows],
677680 above_side_mi: vec![SB; cols * (SUB / MI)],
678681 left_side_mi: vec![SB; rows * (SUB / MI)],
679- above_skip: vec![false; cols],
680- left_skip: vec![false; rows],
681- above_inter: vec![false; cols],
682- left_inter: vec![false; rows],
682+ above_skip: vec![false; cols * (SUB / MI)],
683+ left_skip: vec![false; rows * (SUB / MI)],
684+ above_inter: vec![false; cols * (SUB / MI)],
685+ left_inter: vec![false; rows * (SUB / MI)],
683686 mi_cols,
684687 mi_rows,
685688 }
@@ -768,11 +771,17 @@ impl Neighbours {
768771 /// fills for the coefficient and mode state.
769772 fn record_inter(&mut self, at: (usize, usize), side: usize, skip: bool, is_inter: bool) {
770773 let (r, c) = at;
771- for cell in 0..side / SUB {
772- self.above_skip[c + cell] = skip;
773- self.left_skip[r + cell] = skip;
774- self.above_inter[c + cell] = is_inter;
775- self.left_inter[r + cell] = is_inter;
774+ self.record_inter_mi((r * (SUB / MI), c * (SUB / MI)), side, skip, is_inter);
775+ }
776+
777+ /// [`Self::record_inter`] taking the block's position directly in 4x4
778+ /// mode-info units, for a block finer than one [`SUB`] slot.
779+ fn record_inter_mi(&mut self, (mi_r, mi_c): (usize, usize), side: usize, skip: bool, is_inter: bool) {
780+ for cell in 0..side / MI {
781+ self.above_skip[mi_c + cell] = skip;
782+ self.left_skip[mi_r + cell] = skip;
783+ self.above_inter[mi_c + cell] = is_inter;
784+ self.left_inter[mi_r + cell] = is_inter;
776785 }
777786 }
778787
@@ -1682,6 +1691,7 @@ pub(crate) fn partition_bits(side: usize, split: bool) -> f64 {
16821691 let cdf: &[u16] = match side {
16831692 SB => &cdfs.partition_w64[0],
16841693 BLOCK => &cdfs.partition_w32[0],
1694+ TX8 => &cdfs.partition_w8[0],
16851695 _ => &cdfs.partition_w16[0],
16861696 };
16871697 let symbol = if split {
@@ -2368,6 +2378,50 @@ pub fn sb_coeff_inter_frame_tile(
23682378 let at16 = (sr, sc);
23692379 if has_cols16 && has_rows16 {
23702380 let ctx16 = neighbours.partition_ctx(at16, SUB);
2381+ // A 16x16 leaf wholly inside the frame that
2382+ // carries `eight` split itself further, on
2383+ // cost rather than on geometry (lane-av1rd2):
2384+ // spec PARTITION_SPLIT at BLOCK_16X16, then
2385+ // the same four 8x8 leaves the straddling
2386+ // branch below writes -- all four inside, so
2387+ // the partition symbol is a real one rather
2388+ // than the edge's gathered flag.
2389+ if let Some(leaves) = &leaf.eight {
2390+ if leaves.len() != 4 {
2391+ return Err(Error::unsupported(
2392+ "AV1 tile",
2393+ "a 16x16 inter-frame block inside the frame that splits needs all four 8x8 leaves",
2394+ ));
2395+ }
2396+ enc.symbol(PARTITION_SPLIT, &mut cdfs.partition_w16[ctx16]);
2397+ let (mi_row0, mi_col0) =
2398+ (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
2399+ for (i, leaf8) in leaves.iter().enumerate() {
2400+ let leaf_mi = (
2401+ (mi_row0 + (i as u32 / 2) * 2) as usize,
2402+ (mi_col0 + (i as u32 % 2) * 2) as usize,
2403+ );
2404+ let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
2405+ enc.symbol(
2406+ PARTITION_NONE,
2407+ &mut cdfs.partition_w8[leaf_ctx],
2408+ );
2409+ let (skip, is_inter) = write_inter_frame_leaf8(
2410+ &mut enc,
2411+ &mut cdfs,
2412+ &mut neighbours,
2413+ &mut grid,
2414+ mi_cols,
2415+ mi_rows,
2416+ leaf8,
2417+ leaf_mi,
2418+ &scan8,
2419+ &scan4,
2420+ )?;
2421+ let _ = (skip, is_inter);
2422+ }
2423+ continue;
2424+ }
23712425 enc.symbol(PARTITION_NONE, &mut cdfs.partition_w16[ctx16]);
23722426 write_inter_frame_leaf(
23732427 &mut enc,
@@ -2413,7 +2467,6 @@ pub fn sb_coeff_inter_frame_tile(
24132467 `eight` entry per 8x8 leaf inside the true frame",
24142468 ));
24152469 }
2416- let mut prev_leaf: Option<((usize, usize), bool, bool)> = None;
24172470 for (leaf8, (mr, mc)) in leaves.iter().zip(leaf_positions) {
24182471 let leaf_mi = (mr as usize, mc as usize);
24192472 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
@@ -2426,22 +2479,18 @@ pub fn sb_coeff_inter_frame_tile(
24262479 mi_cols,
24272480 mi_rows,
24282481 leaf8,
2429- at16,
24302482 leaf_mi,
24312483 &scan8,
24322484 &scan4,
2433- prev_leaf,
24342485 )?;
2435- prev_leaf = Some((leaf_mi, skip, is_inter));
2486+ let _ = (skip, is_inter);
24362487 }
24372488 // Same write-back-once-from-the-last-leaf rule
24382489 // as the key frame search's `write_leaf8`
24392490 // caller (r15): the SUB-grid skip/inter arrays
24402491 // are otherwise left stale for the next
24412492 // 16x16 slot.
2442- if let Some((_, skip, is_inter)) = prev_leaf {
2443- neighbours.record_inter(at16, SUB, skip, is_inter);
2444- }
2493+
24452494 }
24462495 }
24472496 continue;
@@ -2451,13 +2500,14 @@ pub fn sb_coeff_inter_frame_tile(
24512500 let (r, c) = at;
24522501 let has_above = r32 > 0;
24532502 let has_left = c32 > 0;
2454- let skip_ctx =
2455- usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
2503+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2504+ let skip_ctx = usize::from(neighbours.above_skip[mi_c])
2505+ + usize::from(neighbours.left_skip[mi_r]);
24562506 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
24572507
24582508 let is_inter = block.inter.is_some();
24592509 let (above_inter, left_inter) =
2460- (neighbours.above_inter[c], neighbours.left_inter[r]);
2510+ (neighbours.above_inter[mi_c], neighbours.left_inter[mi_r]);
24612511 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
24622512 enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]);
24632513
@@ -2649,11 +2699,12 @@ fn write_inter_frame_leaf(
26492699 const LAST_FRAME: i8 = 1;
26502700
26512701 let (r, c) = at;
2652- let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
2702+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2703+ let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]);
26532704 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
26542705
26552706 let (has_above, has_left) = (r > 0, c > 0);
2656- let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]);
2707+ let (above_inter, left_inter) = (neighbours.above_inter[mi_c], neighbours.left_inter[mi_r]);
26572708 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
26582709 let is_inter = block.inter.is_some();
26592710 enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]);
@@ -2812,11 +2863,9 @@ fn write_inter_frame_leaf8(
28122863 mi_cols: u32,
28132864 mi_rows: u32,
28142865 block: &BlockCoeffs,
2815- outer_at: (usize, usize),
28162866 leaf_mi: (usize, usize),
28172867 scan8: &Vec<u16>,
28182868 scan4: &Vec<u16>,
2819- prev_leaf: Option<((usize, usize), bool, bool)>,
28202869 ) -> Result<(bool, bool)> {
28212870 if block.inter.is_none() && usize::from(block.mode) >= INTRA_MODES {
28222871 return Err(Error::unsupported(
@@ -2834,20 +2883,16 @@ fn write_inter_frame_leaf8(
28342883 /// branches.
28352884 const LAST_FRAME: i8 = 1;
28362885
2837- let (r, c) = outer_at;
2838- let mut above_skip = neighbours.above_skip[c];
2839- let mut left_skip = neighbours.left_skip[r];
2840- let mut above_inter = neighbours.above_inter[c];
2841- let mut left_inter = neighbours.left_inter[r];
2842- if let Some(((pr, pc), pskip, pinter)) = prev_leaf {
2843- if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {
2844- above_skip = pskip;
2845- above_inter = pinter;
2846- } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {
2847- left_skip = pskip;
2848- left_inter = pinter;
2849- }
2850- }
2886+ // This leaf's own 4x4 mode-info cells, not the enclosing 16x16 slot's:
2887+ // under a real PARTITION_SPLIT all four leaves are coded, so the
2888+ // bottom-left leaf's true above neighbour is the FIRST leaf and the
2889+ // bottom-right's above and left are two DIFFERENT ones (lane-av1rd2 --
2890+ // reading the coarse slot desynced the stream, and so did an override
2891+ // that remembered only the previous leaf).
2892+ let above_skip = neighbours.above_skip[leaf_mi.1];
2893+ let left_skip = neighbours.left_skip[leaf_mi.0];
2894+ let above_inter = neighbours.above_inter[leaf_mi.1];
2895+ let left_inter = neighbours.left_inter[leaf_mi.0];
28512896 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
28522897 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
28532898
@@ -2964,6 +3009,7 @@ fn write_inter_frame_leaf8(
29643009 vec![0i32; TX4 * TX4],
29653010 ];
29663011 neighbours.record_mi(leaf_mi, 8, &zero_grids);
3012+ neighbours.record_inter_mi(leaf_mi, 8, block.skip, block.inter.is_some());
29673013 } else {
29683014 let grids = [
29693015 level_grid(&block.luma, TX8)?,
@@ -2980,6 +3026,7 @@ fn write_inter_frame_leaf8(
29803026 mode_for_tx,
29813027 );
29823028 neighbours.record_mi(leaf_mi, 8, &grids);
3029+ neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter);
29833030 }
29843031 Ok((block.skip, is_inter))
29853032 }