forge
Explore
Log in

Don't you dare go Hollow

Mi-granular inter neighbour bands + three 8x8-leaf context defects (8-bit 8x8-split gate GREEN)

Browse files at this commit

cbf9f543ddcd72ff297ee68a2b298e7d41533719Ahmet Kaan GümüşParent: 1bfb2cb
  • fix
    • mi-granular inter neighbour bands + three 8x8-leaf context defects (8-bit 8x8-split gate GREEN)
Show full message
fix(av1): mi-granular inter neighbour bands + three 8x8-leaf context defects (8-bit 8x8-split gate GREEN)

lane-inter8 r2. `Neighbours`' inter side bands (skip, skip_mode, is_inter,
ref0/ref1, comp_group_idx, compound_idx, interp filter) were SUB(16px)-granular,
so all four 8x8 leaves of a split 16x16 shared one slot. They are now mi(4px)
granular (`record_inter_rect_mi` / `record_compound_ctx_rect_mi`, readers index
by mi), which makes the r1 `prev_leaves` sibling-override hack unnecessary --
each leaf stamps its own 2x2-mi span right after it decodes.

Two further defects that the granularity change exposed, both class
context-read-from-one-cell:

1. `decode_inter_block8`'s COMPOUND arm `return`ed before the end-of-function
   `record_mi`/`fill_lf_grid` the single-ref arm falls through to. Every leaf in
   the gate's stream is compound, so a split 16x16 left `above_side_mi` at 16:
   the 16x16 below it computed partition ctx 0 instead of 1 and read
   PARTITION_NONE where aomdec read PARTITION_SPLIT.
2. `get_comp_group_idx_context`/`get_comp_index_context` took the leaf's
   ENCLOSING 16x16 corner (`outer_at`); they now take mi coordinates and the
   leaf passes its own.

Also threaded the frame's temporal mv field (`tpl_frame`) into the leaf's two mv
stacks, which passed `None` while `decode_inter_block` one level up always
passed it (class parsed-then-discarded). Alignment only: it did not move this
stream's ladder (no `use_ref_frame_mvs` here).

Gate a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact is
GREEN and un-ignored (4 frames pixel-exact vs ffmpeg, interior-split counter
asserted). aomdec EC_MODE ladder 42/57 -> 57/57. The 10-bit twin stays ignored:
it dies on "an INTER 32x32 partition type ... (value=9)", and `EC_TRACE=1
aomdec` proves that stream contains no value=9 anywhere -- our own desync
(class refusal-from-own-desync), disproving the r1 ledger line that blamed
aomenc for emitting PARTITION_VERT_4.
crates/ec-av1/src/decode.rsmodified+226 -122
@@ -1907,22 +1907,26 @@ impl Neighbours {
19071907 left_side: vec![SB; rows],
19081908 above_side_mi: vec![SB; cols * (SUB / MI)],
19091909 left_side_mi: vec![SB; rows * (SUB / MI)],
1910- above_skip: vec![false; cols],
1911- left_skip: vec![false; rows],
1912- above_skip_mode: vec![false; cols],
1913- left_skip_mode: vec![false; rows],
1914- above_inter: vec![false; cols],
1915- left_inter: vec![false; rows],
1916- above_ref: vec![-1; cols],
1917- left_ref: vec![-1; rows],
1918- above_ref1: vec![None; cols],
1919- left_ref1: vec![None; rows],
1920- above_comp_group_idx: vec![0; cols],
1921- left_comp_group_idx: vec![0; rows],
1922- above_compound_idx: vec![0; cols],
1923- left_compound_idx: vec![0; rows],
1924- above_filter: vec![[3u8; 2]; cols],
1925- left_filter: vec![[3u8; 2]; rows],
1910+ // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an
1911+ // 8x8 inter leaf's left neighbour is the OTHER leaf row of the
1912+ // 16x16 block beside it, which a SUB-grid slot cannot name
1913+ // (class context-read-from-one-cell).
1914+ above_skip: vec![false; cols * (SUB / MI)],
1915+ left_skip: vec![false; rows * (SUB / MI)],
1916+ above_skip_mode: vec![false; cols * (SUB / MI)],
1917+ left_skip_mode: vec![false; rows * (SUB / MI)],
1918+ above_inter: vec![false; cols * (SUB / MI)],
1919+ left_inter: vec![false; rows * (SUB / MI)],
1920+ above_ref: vec![-1; cols * (SUB / MI)],
1921+ left_ref: vec![-1; rows * (SUB / MI)],
1922+ above_ref1: vec![None; cols * (SUB / MI)],
1923+ left_ref1: vec![None; rows * (SUB / MI)],
1924+ above_comp_group_idx: vec![0; cols * (SUB / MI)],
1925+ left_comp_group_idx: vec![0; rows * (SUB / MI)],
1926+ above_compound_idx: vec![0; cols * (SUB / MI)],
1927+ left_compound_idx: vec![0; rows * (SUB / MI)],
1928+ above_filter: vec![[3u8; 2]; cols * (SUB / MI)],
1929+ left_filter: vec![[3u8; 2]; rows * (SUB / MI)],
19261930 mi_cols,
19271931 mi_rows,
19281932 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -1965,6 +1969,11 @@ impl Neighbours {
19651969 for i in sc0.min(sc1)..sc1 {
19661970 self.above_mode[i] = DC_PRED;
19671971 self.above_side[i] = SB;
1972+ }
1973+ // lane-inter8 r2: the inter bands are mi-granular, so they reset over
1974+ // the tile's own mi column span directly.
1975+ let mend = col1_mi.min(self.above_skip.len());
1976+ for i in col0_mi.min(mend)..mend {
19681977 self.above_skip[i] = false;
19691978 self.above_skip_mode[i] = false;
19701979 self.above_inter[i] = false;
@@ -2271,8 +2280,37 @@ impl Neighbours {
22712280 skip_mode: bool,
22722281 ) {
22732282 let (r, c) = at;
2283+ self.record_inter_rect_mi(
2284+ (r * (SUB / MI), c * (SUB / MI)),
2285+ w_sub / MI,
2286+ h_sub / MI,
2287+ skip,
2288+ is_inter,
2289+ ref_frame,
2290+ filter,
2291+ skip_mode,
2292+ );
2293+ }
2294+
2295+ /// [`Self::record_inter_rect`] in mi (4px) units -- lane-inter8 r2: an
2296+ /// 8x8 leaf covers 2x2 mi, half a [`SUB`] cell in each direction, so the
2297+ /// side bands are written (and read) per mi. Every [`SUB`]-unit caller
2298+ /// routes through the wrapper above.
2299+ #[allow(clippy::too_many_arguments)]
2300+ fn record_inter_rect_mi(
2301+ &mut self,
2302+ at_mi: (usize, usize),
2303+ w_mi: usize,
2304+ h_mi: usize,
2305+ skip: bool,
2306+ is_inter: bool,
2307+ ref_frame: i8,
2308+ filter: [u8; 2],
2309+ skip_mode: bool,
2310+ ) {
2311+ let (r, c) = at_mi;
22742312 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
2275- for cell in 0..w_sub / SUB {
2313+ for cell in 0..w_mi {
22762314 self.above_skip[c + cell] = skip;
22772315 self.above_skip_mode[c + cell] = skip_mode;
22782316 self.above_inter[c + cell] = is_inter;
@@ -2290,7 +2328,7 @@ impl Neighbours {
22902328 self.above_compound_idx[c + cell] = u8::from(altref);
22912329 self.above_filter[c + cell] = filter;
22922330 }
2293- for cell in 0..h_sub / SUB {
2331+ for cell in 0..h_mi {
22942332 self.left_skip[r + cell] = skip;
22952333 self.left_skip_mode[r + cell] = skip_mode;
22962334 self.left_inter[r + cell] = is_inter;
@@ -2336,12 +2374,34 @@ impl Neighbours {
23362374 compound_idx: u8,
23372375 ) {
23382376 let (r, c) = at;
2339- for cell in 0..w_sub / SUB {
2377+ self.record_compound_ctx_rect_mi(
2378+ (r * (SUB / MI), c * (SUB / MI)),
2379+ w_sub / MI,
2380+ h_sub / MI,
2381+ ref1,
2382+ comp_group_idx,
2383+ compound_idx,
2384+ );
2385+ }
2386+
2387+ /// [`Self::record_compound_ctx_rect`] in mi units (lane-inter8 r2, see
2388+ /// [`Self::record_inter_rect_mi`]).
2389+ fn record_compound_ctx_rect_mi(
2390+ &mut self,
2391+ at_mi: (usize, usize),
2392+ w_mi: usize,
2393+ h_mi: usize,
2394+ ref1: i8,
2395+ comp_group_idx: u8,
2396+ compound_idx: u8,
2397+ ) {
2398+ let (r, c) = at_mi;
2399+ for cell in 0..w_mi {
23402400 self.above_ref1[c + cell] = Some(ref1);
23412401 self.above_comp_group_idx[c + cell] = comp_group_idx;
23422402 self.above_compound_idx[c + cell] = compound_idx;
23432403 }
2344- for cell in 0..h_sub / SUB {
2404+ for cell in 0..h_mi {
23452405 self.left_ref1[r + cell] = Some(ref1);
23462406 self.left_comp_group_idx[r + cell] = comp_group_idx;
23472407 self.left_compound_idx[r + cell] = compound_idx;
@@ -8430,7 +8490,7 @@ fn obmc_blend(
84308490 // divide back down to that column.
84318491 let (h_kind, v_kind) = neighbour_filter(
84328492 interp_fixed,
8433- neighbours.above_filter[(mi_col + off4) / SUB_MI as usize],
8493+ neighbours.above_filter[mi_col + off4],
84348494 );
84358495 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
84368496 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
@@ -8454,7 +8514,7 @@ fn obmc_blend(
84548514 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {
84558515 let (h_kind, v_kind) = neighbour_filter(
84568516 interp_fixed,
8457- neighbours.left_filter[(mi_row + off4) / SUB_MI as usize],
8517+ neighbours.left_filter[mi_row + off4],
84588518 );
84598519 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
84608520 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
@@ -8495,10 +8555,17 @@ fn is_uni_comp_ref(ref0: i8, ref1: i8) -> bool {
84958555 /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the
84968556 /// above/left neighbour contributions [`Neighbours::record_inter`]/
84978557 /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5.
8498-fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side: usize) -> usize {
8558+/// lane-inter8 r2: `at_mi` is the block's own top-left in 4x4 mi units --
8559+/// an 8x8 leaf used to pass its enclosing 16x16's corner here, so all four
8560+/// leaves read the same neighbour cell (class context-read-from-one-cell).
8561+fn get_comp_group_idx_context(
8562+ neighbours: &Neighbours,
8563+ at_mi: (usize, usize),
8564+ side: usize,
8565+) -> usize {
84998566 let _ = side;
8500- let (r, c) = at;
8501- (neighbours.above_comp_group_idx[c] as usize + neighbours.left_comp_group_idx[r] as usize)
8567+ let (rmi, cmi) = at_mi;
8568+ (neighbours.above_comp_group_idx[cmi] as usize + neighbours.left_comp_group_idx[rmi] as usize)
85028569 .min(5)
85038570 }
85048571
@@ -8510,7 +8577,7 @@ fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side:
85108577 #[allow(clippy::too_many_arguments)]
85118578 fn get_comp_index_context(
85128579 neighbours: &Neighbours,
8513- at: (usize, usize),
8580+ at_mi: (usize, usize),
85148581 side: usize,
85158582 order_hint_bits: u32,
85168583 cur_order_hint: u32,
@@ -8518,7 +8585,7 @@ fn get_comp_index_context(
85188585 ref1_order_hint: u32,
85198586 ) -> usize {
85208587 let _ = side;
8521- let (r, c) = at;
8588+ let (rmi, cmi) = at_mi;
85228589 let fwd =
85238590 crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint)
85248591 .abs();
@@ -8526,8 +8593,8 @@ fn get_comp_index_context(
85268593 crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint)
85278594 .abs();
85288595 let offset = usize::from(fwd == bck);
8529- neighbours.above_compound_idx[c] as usize
8530- + neighbours.left_compound_idx[r] as usize
8596+ neighbours.above_compound_idx[cmi] as usize
8597+ + neighbours.left_compound_idx[rmi] as usize
85318598 + 3 * offset
85328599 }
85338600
@@ -8901,6 +8968,11 @@ fn decode_inter_block(
89018968 frame_width: usize,
89028969 ) -> Result<()> {
89038970 let (r, c) = at;
8971+ // lane-inter8 r2: the inter side bands are mi-granular; this block's own
8972+ // above/left neighbour is the mi cell at its top-left corner (libaom
8973+ // `above_mbmi` = mi(mi_row - 1, mi_col)), so a SUB-aligned block reads
8974+ // exactly what it read before.
8975+ let (rmi, cmi) = (r * (SUB / MI), c * (SUB / MI));
89048976 let (px, py) = (c * SUB, r * SUB);
89058977 let (cpx, cpy) = (px / 2, py / 2);
89068978 let chroma_side = side / 2;
@@ -8913,7 +8985,7 @@ fn decode_inter_block(
89138985 );
89148986 }
89158987 let skip_mode_ctx =
8916- usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
8988+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
89178989 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
89188990 // MSAC tell so it can be diffed against an equivalent hook in libaom's
89198991 // own `read_skip_mode`/`av1_get_skip_mode_context`.
@@ -8934,7 +9006,7 @@ fn decode_inter_block(
89349006 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
89359007 }
89369008
8937- let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
9009+ let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
89389010 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
89399011 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
89409012 maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);
@@ -8952,7 +9024,7 @@ fn decode_inter_block(
89529024 r > neighbours.tile_row0_mi / (SUB / MI),
89539025 c > neighbours.tile_col0_mi / (SUB / MI),
89549026 );
8955- let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]);
9027+ let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]);
89569028 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
89579029 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
89589030 if std::env::var_os("EC_TRACE_MODE").is_some() {
@@ -8985,24 +9057,24 @@ fn decode_inter_block(
89859057 let above_nbr = has_above.then(|| NeighbourRef {
89869058 is_inter: above_inter,
89879059 ref0: if above_inter {
8988- neighbours.above_ref[c]
9060+ neighbours.above_ref[cmi]
89899061 } else {
89909062 0
89919063 },
8992- ref1: neighbours.above_ref1[c],
8993- uni: neighbours.above_ref1[c]
8994- .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[c], r1)),
9064+ ref1: neighbours.above_ref1[cmi],
9065+ uni: neighbours.above_ref1[cmi]
9066+ .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[cmi], r1)),
89959067 });
89969068 let left_nbr = has_left.then(|| NeighbourRef {
89979069 is_inter: left_inter,
89989070 ref0: if left_inter {
8999- neighbours.left_ref[r]
9071+ neighbours.left_ref[rmi]
90009072 } else {
90019073 0
90029074 },
9003- ref1: neighbours.left_ref1[r],
9004- uni: neighbours.left_ref1[r]
9005- .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)),
9075+ ref1: neighbours.left_ref1[rmi],
9076+ uni: neighbours.left_ref1[rmi]
9077+ .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
90069078 });
90079079 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
90089080 eprintln!(
@@ -9021,8 +9093,8 @@ fn decode_inter_block(
90219093 cdfs,
90229094 above_nbr,
90239095 left_nbr,
9024- neighbours.above_ref[c],
9025- neighbours.left_ref[r],
9096+ neighbours.above_ref[cmi],
9097+ neighbours.left_ref[rmi],
90269098 )
90279099 };
90289100 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
@@ -9099,17 +9171,17 @@ fn decode_inter_block(
90999171 // real filter match down to the "no neighbour" sentinel
91009172 // whenever the shared reference sits in the neighbour's SECOND
91019173 // slot (lane-av1idx r2).
9102- let above_filter_ctx = if neighbours.above_ref[c] == ref0
9103- || neighbours.above_ref1[c] == Some(ref0)
9174+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref0
9175+ || neighbours.above_ref1[cmi] == Some(ref0)
91049176 {
9105- neighbours.above_filter[c]
9177+ neighbours.above_filter[cmi]
91069178 } else {
91079179 [3, 3]
91089180 };
9109- let left_filter_ctx = if neighbours.left_ref[r] == ref0
9110- || neighbours.left_ref1[r] == Some(ref0)
9181+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref0
9182+ || neighbours.left_ref1[rmi] == Some(ref0)
91119183 {
9112- neighbours.left_filter[r]
9184+ neighbours.left_filter[rmi]
91139185 } else {
91149186 [3, 3]
91159187 };
@@ -9159,7 +9231,7 @@ fn decode_inter_block(
91599231 // there), so the gate reduces to the sequence header bit; kept
91609232 // as an explicit call so a future smaller block size is not
91619233 // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`).
9162- let group_ctx = get_comp_group_idx_context(neighbours, at, side);
9234+ let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
91639235 let comp_group_idx = if !skip_mode
91649236 && enable_masked_compound
91659237 && is_any_masked_compound_used_here(side)
@@ -9423,7 +9495,7 @@ fn decode_inter_block(
94239495 {
94249496 let idx_ctx = get_comp_index_context(
94259497 neighbours,
9426- at,
9498+ (rmi, cmi),
94279499 side,
94289500 order_hint_bits,
94299501 order_hint,
@@ -9712,10 +9784,10 @@ fn decode_inter_block(
97129784 read_single_ref(
97139785 dec,
97149786 cdfs,
9715- neighbours.above_ref[c],
9716- neighbours.above_ref1[c],
9717- neighbours.left_ref[r],
9718- neighbours.left_ref1[r],
9787+ neighbours.above_ref[cmi],
9788+ neighbours.above_ref1[cmi],
9789+ neighbours.left_ref[rmi],
9790+ neighbours.left_ref1[rmi],
97199791 );
97209792 ref_frame_for_lf = ref_frame;
97219793 if std::env::var_os("EC_AV1_TELL").is_some() {
@@ -10089,17 +10161,17 @@ fn decode_inter_block(
1008910161 // lane-av1idx r2: also match on the neighbour's SECOND reference
1009010162 // (`above_ref1`/`left_ref1`, real for a compound neighbour) --
1009110163 // see the 16x16 leaf's own comment above for the spec citation.
10092- let above_filter_ctx = if neighbours.above_ref[c] == ref_frame
10093- || neighbours.above_ref1[c] == Some(ref_frame)
10164+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
10165+ || neighbours.above_ref1[cmi] == Some(ref_frame)
1009410166 {
10095- neighbours.above_filter[c]
10167+ neighbours.above_filter[cmi]
1009610168 } else {
1009710169 [3, 3]
1009810170 };
10099- let left_filter_ctx = if neighbours.left_ref[r] == ref_frame
10100- || neighbours.left_ref1[r] == Some(ref_frame)
10171+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
10172+ || neighbours.left_ref1[rmi] == Some(ref_frame)
1010110173 {
10102- neighbours.left_filter[r]
10174+ neighbours.left_filter[rmi]
1010310175 } else {
1010410176 [3, 3]
1010510177 };
@@ -10717,11 +10789,6 @@ fn decode_inter_block8(
1071710789 base_q_idx: u8,
1071810790 scan8: &[u16],
1071910791 scan4: &[u16],
10720- // lane-inter8 r1: every leaf of this 16x16 decoded so far, not just the
10721- // previous one -- the bottom-LEFT leaf's above neighbour is leaf 0, which
10722- // a single `prev_leaf` (leaf 1) never names (class
10723- // context-read-from-one-cell).
10724- prev_leaves: &[((usize, usize), bool, bool, i8, Option<i8>)],
1072510792 allow_high_precision_mv: bool,
1072610793 force_integer_mv: bool,
1072710794 // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
@@ -10741,7 +10808,7 @@ fn decode_inter_block8(
1074110808 // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
1074210809 // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
1074310810 // so its `skip_mode` context reuses the same [`SUB`]-grid
10744- // `above_skip_mode[c]`/`left_skip_mode[r]` the enclosing 16x16 slot
10811+ // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
1074510812 // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
1074610813 // just above).
1074710814 skip_mode_present: bool,
@@ -10779,6 +10846,13 @@ fn decode_inter_block8(
1077910846 // this block (mi 4,14 of the mandelbrot 8x8-split gate).
1078010847 sign_bias_table: &SignBiasTable,
1078110848 global_motion: &[ec_av1_syntax::WarpParams; 7],
10849+ // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which
10850+ // [`decode_inter_block`] one level up has always passed and this leaf
10851+ // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds
10852+ // fewer candidates here than in the reference decoder, which changes the
10853+ // mode contexts AND the number of `drl_mode` bits read (class parsed
10854+ // then discarded).
10855+ tpl_frame: Option<&TplFrameArgs>,
1078210856 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, (i8, Option<i8>))> {
1078310857 const LAST_FRAME: i8 = 1;
1078410858 let gm_table = build_gm_mv_table(
@@ -10799,29 +10873,26 @@ fn decode_inter_block8(
1079910873 const CHROMA_SIDE: usize = 4;
1080010874
1080110875 let (r, c) = outer_at;
10802- let mut above_skip = neighbours.above_skip[c];
10803- let mut left_skip = neighbours.left_skip[r];
10804- let mut above_inter = neighbours.above_inter[c];
10805- let mut left_inter = neighbours.left_inter[r];
10806- let mut above_ref0 = neighbours.above_ref[c];
10807- let mut above_ref1 = neighbours.above_ref1[c];
10808- let mut left_ref0 = neighbours.left_ref[r];
10809- let mut left_ref1 = neighbours.left_ref1[r];
10810- for &((pr, pc), pskip, pinter, pref0, pref1) in prev_leaves {
10811- if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {
10812- above_skip = pskip;
10813- above_inter = pinter;
10814- above_ref0 = pref0;
10815- above_ref1 = pref1;
10816- } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {
10817- left_skip = pskip;
10818- left_inter = pinter;
10819- left_ref0 = pref0;
10820- left_ref1 = pref1;
10821- }
10822- }
10876+ let _ = (r, c);
10877+ // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
10878+ // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
10879+ // left column of a 16x16's second leaf ROW is the previous 16x16 block's
10880+ // bottom leaf, neither of which a SUB-grid slot can name.
10881+ let (rmi, cmi) = leaf_mi;
10882+ // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
10883+ // its own 2x2-mi span into the bands right after it decodes (the caller's
10884+ // `record_inter_rect_mi`), so a plain mi read already names the correct
10885+ // neighbour, including one belonging to the previous 16x16 block.
10886+ let above_skip = neighbours.above_skip[cmi];
10887+ let left_skip = neighbours.left_skip[rmi];
10888+ let above_inter = neighbours.above_inter[cmi];
10889+ let left_inter = neighbours.left_inter[rmi];
10890+ let above_ref0 = neighbours.above_ref[cmi];
10891+ let above_ref1 = neighbours.above_ref1[cmi];
10892+ let left_ref0 = neighbours.left_ref[rmi];
10893+ let left_ref1 = neighbours.left_ref1[rmi];
1082310894 let skip_mode_ctx =
10824- usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
10895+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
1082510896 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
1082610897 if skip_mode {
1082710898 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
@@ -10904,6 +10975,22 @@ fn decode_inter_block8(
1090410975 };
1090510976 leaf_refs = (ref0, Some(ref1));
1090610977 let (mi_row, mi_col) = leaf_mi;
10978+ // spec 7.10.2.8, mirroring [`decode_inter_block`]'s own
10979+ // `comp_tpl` build (`use_ref_frame_mvs` frames only).
10980+ let comp_tpl = tpl_frame.map(|t| crate::mvstack::CompoundTplArgs {
10981+ field: t.field,
10982+ cur_offset_0: crate::motion_field::get_relative_dist(
10983+ t.order_hint_bits,
10984+ t.order_hint,
10985+ t.ref_order_hints[(ref0 - LAST_FRAME) as usize],
10986+ ),
10987+ cur_offset_1: crate::motion_field::get_relative_dist(
10988+ t.order_hint_bits,
10989+ t.order_hint,
10990+ t.ref_order_hints[(ref1 - LAST_FRAME) as usize],
10991+ ),
10992+ allow_high_precision_mv,
10993+ });
1090710994 // lane-av1comp: this leaf path has neither a real sign-bias
1090810995 // table nor `tpl_frame` (see this function's own doc on the
1090910996 // coarse `LAST_FRAME`-or-intra neighbour approximation
@@ -10921,7 +11008,7 @@ fn decode_inter_block8(
1092111008 mi_rows as usize,
1092211009 sign_bias_table,
1092311010 &gm_table,
10924- None,
11011+ comp_tpl,
1092511012 );
1092611013 let compound_mode = if skip_mode {
1092711014 0 // NEAREST_NEARESTMV, forced -- no mode symbol read
@@ -10964,7 +11051,7 @@ fn decode_inter_block8(
1096411051 // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid
1096511052 // slot -- the only granularity `Neighbours`' comp_group_idx/
1096611053 // compound_idx arrays track.
10967- let group_ctx = get_comp_group_idx_context(neighbours, outer_at, SIDE);
11054+ let group_ctx = get_comp_group_idx_context(neighbours, leaf_mi, SIDE);
1096811055 let comp_group_idx = if !skip_mode
1096911056 && enable_masked_compound
1097011057 && is_any_masked_compound_used_here(SIDE)
@@ -11018,7 +11105,7 @@ fn decode_inter_block8(
1101811105 {
1101911106 let idx_ctx = get_comp_index_context(
1102011107 neighbours,
11021- outer_at,
11108+ leaf_mi,
1102211109 SIDE,
1102311110 order_hint_bits,
1102411111 order_hint,
@@ -11288,6 +11375,17 @@ fn decode_inter_block8(
1128811375 )?
1128911376 .0;
1129011377 }
11378+ // lane-inter8 r2: the COMPOUND leaf used to return here
11379+ // WITHOUT the end-of-function `record_mi`/`fill_lf_grid` the
11380+ // single-ref path falls through to -- so a compound 8x8 leaf
11381+ // left `above_side_mi`/`left_side_mi` (the next block's
11382+ // partition context), the per-plane coefficient level state
11383+ // and the loop-filter grid describing whatever block was
11384+ // there before. Every leaf of the gate's stream is compound,
11385+ // so the 16x16 below a split block read partition ctx 0
11386+ // instead of 1 and mis-read PARTITION_SPLIT as NONE.
11387+ neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
11388+ neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 });
1129111389 return Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs));
1129211390 }
1129311391 }
@@ -11303,6 +11401,15 @@ fn decode_inter_block8(
1130311401 }
1130411402
1130511403 let (mi_row, mi_col) = leaf_mi;
11404+ let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs {
11405+ field: t.field,
11406+ cur_offset_0: crate::motion_field::get_relative_dist(
11407+ t.order_hint_bits,
11408+ t.order_hint,
11409+ t.ref_order_hints[(LAST_FRAME - LAST_FRAME) as usize],
11410+ ),
11411+ allow_high_precision_mv,
11412+ });
1130611413 let stack = find_mv_stack_with_sign_bias(
1130711414 grid,
1130811415 mi_row,
@@ -11314,7 +11421,7 @@ fn decode_inter_block8(
1131411421 mi_rows as usize,
1131511422 sign_bias_table,
1131611423 &gm_table,
11317- None,
11424+ tpl,
1131811425 );
1131911426
1132011427 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
@@ -12565,7 +12672,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1256512672 base_q_idx,
1256612673 &scan8,
1256712674 &scan4,
12568- &prev_leaves,
1256912675 allow_high_precision_mv,
1257012676 force_integer_mv,
1257112677 reference_select,
@@ -12584,48 +12690,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1258412690 allow_screen_content_tools,
1258512691 &sign_bias_table,
1258612692 &global_motion,
12693+ tpl_frame.as_ref(),
1258712694 )?;
1258812695 prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1));
1258912696 last_skip_mode = skip_mode_leaf;
1259012697 if compound_ctx8.is_some() {
1259112698 last_compound_ctx = compound_ctx8;
1259212699 }
12593- }
12594- if let Some(&(_, skip, is_inter, _, _)) = prev_leaves.last() {
12595- // corner-cut: `decode_inter_block8`'s
12596- // leaves never read a switchable filter
12597- // (round-3 GLOBALMV refusal already
12598- // bounds them away from the Regular-only
12599- // gap this round closes elsewhere); `[3,
12600- // 3]` is "no info", the same value an
12601- // intra neighbour records. Upgrade:
12602- // thread `interp_fixed`/`enable_dual_filter`
12603- // into `decode_inter_block8` once a
12604- // straddling 8x8 SWITCHABLE stream is on
12605- // hand to pin against.
12606- neighbours.record_inter(
12607- at16,
12608- SUB,
12700+ // lane-inter8 r2: stamp THIS leaf's own
12701+ // 2x2-mi span before the next leaf reads
12702+ // it as a neighbour -- the whole-16x16
12703+ // stamp below only ever described the
12704+ // last leaf, so three quarters of the
12705+ // block carried the wrong skip/ref/inter
12706+ // state into the next block's contexts
12707+ // (class context-read-from-one-cell).
12708+ // corner-cut: `[3, 3]` filter, as the
12709+ // 16x16 stamp used -- `decode_inter_block8`
12710+ // reads no switchable filter yet.
12711+ neighbours.record_inter_rect_mi(
12712+ leaf_mi,
12713+ 2,
12714+ 2,
1260912715 skip,
1261012716 is_inter,
12611- if is_inter { LAST_FRAME } else { -1 },
12717+ leaf_refs.0,
1261212718 [3, 3],
12613- last_skip_mode,
12719+ skip_mode_leaf,
1261412720 );
12615- if let Some((ref0, ref1, group_idx, idx)) = last_compound_ctx {
12616- neighbours.record_inter(
12617- at16,
12618- SUB,
12619- skip,
12620- is_inter,
12621- ref0,
12622- [3, 3],
12623- last_skip_mode,
12721+ if let Some(ref1) = leaf_refs.1
12722+ && let Some((_, _, group_idx, idx)) = compound_ctx8
12723+ {
12724+ neighbours.record_compound_ctx_rect_mi(
12725+ leaf_mi, 2, 2, ref1, group_idx, idx,
1262412726 );
12625- neighbours
12626- .record_compound_ctx(at16, SUB, ref1, group_idx, idx);
1262712727 }
1262812728 }
12729+ // lane-inter8 r2: the four per-leaf
12730+ // `record_inter_rect_mi` stamps above replace
12731+ // the single whole-16x16 one that used to run
12732+ // here with the LAST leaf's state.
1262912733 }
1263012734 }
1263112735 }
crates/ec-av1/src/stream.rsmodified+13 -18
@@ -2943,16 +2943,11 @@ mod tests {
29432943 /// was refused by name until this round; the straddle path always ran the
29442944 /// same loop, so only [`decode::inter_sub16_split_hits`] -- which counts
29452945 /// interior splits only -- proves the newly-lifted alphabet value fired.
2946+ // lane-inter8 r2: GREEN. The neighbour side bands are mi-granular, every
2947+ // leaf stamps its own 2x2-mi span (including the compound-return path
2948+ // that used to skip `record_mi` entirely) and the compound
2949+ // group/index contexts read the LEAF's mi cell, not its 16x16's corner.
29462950 #[test]
2947- // lane-inter8 r1: RED, and ignored rather than deleted. The 16x16-level
2948- // interior `PARTITION_SPLIT` and its four 8x8 leaves now decode without a
2949- // refusal, and the mode-info range ladder matches aomdec's `EC_MODE` for
2950- // 42 blocks, but block mi=(6,12) still diverges: `Neighbours`' above_*/
2951- // left_* arrays are 16x16-granular, so the LEFT neighbour of leaf (6,12)
2952- // resolves to whatever the previous 16x16 recorded rather than to that
2953- // block's own bottom-right leaf (6,10). Un-ignore when the arrays are
2954- // mi-granular (see lanes/inter8-r1.report.md).
2955- #[ignore = "lane-inter8 r1: 8x8 leaf neighbour arrays are still 16x16-granular"]
29562951 fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
29572952 inter_sb_none_gate(
29582953 "a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",
@@ -2965,15 +2960,15 @@ mod tests {
29652960 }
29662961
29672962 #[test]
2968- // lane-inter8 r1: RED, and ignored rather than deleted. The 16x16-level
2969- // interior `PARTITION_SPLIT` and its four 8x8 leaves now decode without a
2970- // refusal, and the mode-info range ladder matches aomdec's `EC_MODE` for
2971- // 42 blocks, but block mi=(6,12) still diverges: `Neighbours`' above_*/
2972- // left_* arrays are 16x16-granular, so the LEFT neighbour of leaf (6,12)
2973- // resolves to whatever the previous 16x16 recorded rather than to that
2974- // block's own bottom-right leaf (6,10). Un-ignore when the arrays are
2975- // mi-granular (see lanes/inter8-r1.report.md).
2976- #[ignore = "lane-inter8 r1: 8x8 leaf neighbour arrays are still 16x16-granular"]
2963+ // lane-inter8 r2: still RED, and ignored rather than deleted -- the 8-bit
2964+ // twin above is green, this 10-bit recipe stops at "an INTER 32x32
2965+ // partition type this decoder does not code (value=9)". That is OUR
2966+ // desync, proven: `EC_TRACE=1 aomdec` on the pinned stream reads
2967+ // 16 `bsize=9 value=3` (SPLIT) partitions and never a single value=9
2968+ // anywhere (class refusal-from-own-desync; the r1 ledger line claiming
2969+ // aomenc emits PARTITION_VERT_4 despite --enable-1to4-partitions=0 is
2970+ // hereby disproven). The divergence itself is not yet bisected.
2971+ #[ignore = "lane-inter8 r2: 10-bit twin still desyncs (surfaces as a bogus 32x32 value=9 refusal); 8-bit gate is green"]
29772972 fn a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
29782973 inter_sb_none_gate(
29792974 "a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",