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 {
1907 left_side: vec![SB; rows],1907 left_side: vec![SB; rows],
1908 above_side_mi: vec![SB; cols * (SUB / MI)],1908 above_side_mi: vec![SB; cols * (SUB / MI)],
1909 left_side_mi: vec![SB; rows * (SUB / MI)],1909 left_side_mi: vec![SB; rows * (SUB / MI)],
1910- above_skip: vec![false; cols],1910+ // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an
1911- left_skip: vec![false; rows],1911+ // 8x8 inter leaf's left neighbour is the OTHER leaf row of the
1912- above_skip_mode: vec![false; cols],1912+ // 16x16 block beside it, which a SUB-grid slot cannot name
1913- left_skip_mode: vec![false; rows],1913+ // (class context-read-from-one-cell).
1914- above_inter: vec![false; cols],1914+ above_skip: vec![false; cols * (SUB / MI)],
1915- left_inter: vec![false; rows],1915+ left_skip: vec![false; rows * (SUB / MI)],
1916- above_ref: vec![-1; cols],1916+ above_skip_mode: vec![false; cols * (SUB / MI)],
1917- left_ref: vec![-1; rows],1917+ left_skip_mode: vec![false; rows * (SUB / MI)],
1918- above_ref1: vec![None; cols],1918+ above_inter: vec![false; cols * (SUB / MI)],
1919- left_ref1: vec![None; rows],1919+ left_inter: vec![false; rows * (SUB / MI)],
1920- above_comp_group_idx: vec![0; cols],1920+ above_ref: vec![-1; cols * (SUB / MI)],
1921- left_comp_group_idx: vec![0; rows],1921+ left_ref: vec![-1; rows * (SUB / MI)],
1922- above_compound_idx: vec![0; cols],1922+ above_ref1: vec![None; cols * (SUB / MI)],
1923- left_compound_idx: vec![0; rows],1923+ left_ref1: vec![None; rows * (SUB / MI)],
1924- above_filter: vec![[3u8; 2]; cols],1924+ above_comp_group_idx: vec![0; cols * (SUB / MI)],
1925- left_filter: vec![[3u8; 2]; rows],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)],
1926 mi_cols,1930 mi_cols,
1927 mi_rows,1931 mi_rows,
1928 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],1932 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -1965,6 +1969,11 @@ impl Neighbours {
1965 for i in sc0.min(sc1)..sc1 {1969 for i in sc0.min(sc1)..sc1 {
1966 self.above_mode[i] = DC_PRED;1970 self.above_mode[i] = DC_PRED;
1967 self.above_side[i] = SB;1971 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 {
1968 self.above_skip[i] = false;1977 self.above_skip[i] = false;
1969 self.above_skip_mode[i] = false;1978 self.above_skip_mode[i] = false;
1970 self.above_inter[i] = false;1979 self.above_inter[i] = false;
@@ -2271,8 +2280,37 @@ impl Neighbours {
2271 skip_mode: bool,2280 skip_mode: bool,
2272 ) {2281 ) {
2273 let (r, c) = at;2282 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;
2274 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;2312 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 {
2276 self.above_skip[c + cell] = skip;2314 self.above_skip[c + cell] = skip;
2277 self.above_skip_mode[c + cell] = skip_mode;2315 self.above_skip_mode[c + cell] = skip_mode;
2278 self.above_inter[c + cell] = is_inter;2316 self.above_inter[c + cell] = is_inter;
@@ -2290,7 +2328,7 @@ impl Neighbours {
2290 self.above_compound_idx[c + cell] = u8::from(altref);2328 self.above_compound_idx[c + cell] = u8::from(altref);
2291 self.above_filter[c + cell] = filter;2329 self.above_filter[c + cell] = filter;
2292 }2330 }
2293- for cell in 0..h_sub / SUB {2331+ for cell in 0..h_mi {
2294 self.left_skip[r + cell] = skip;2332 self.left_skip[r + cell] = skip;
2295 self.left_skip_mode[r + cell] = skip_mode;2333 self.left_skip_mode[r + cell] = skip_mode;
2296 self.left_inter[r + cell] = is_inter;2334 self.left_inter[r + cell] = is_inter;
@@ -2336,12 +2374,34 @@ impl Neighbours {
2336 compound_idx: u8,2374 compound_idx: u8,
2337 ) {2375 ) {
2338 let (r, c) = at;2376 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 {
2340 self.above_ref1[c + cell] = Some(ref1);2400 self.above_ref1[c + cell] = Some(ref1);
2341 self.above_comp_group_idx[c + cell] = comp_group_idx;2401 self.above_comp_group_idx[c + cell] = comp_group_idx;
2342 self.above_compound_idx[c + cell] = compound_idx;2402 self.above_compound_idx[c + cell] = compound_idx;
2343 }2403 }
2344- for cell in 0..h_sub / SUB {2404+ for cell in 0..h_mi {
2345 self.left_ref1[r + cell] = Some(ref1);2405 self.left_ref1[r + cell] = Some(ref1);
2346 self.left_comp_group_idx[r + cell] = comp_group_idx;2406 self.left_comp_group_idx[r + cell] = comp_group_idx;
2347 self.left_compound_idx[r + cell] = compound_idx;2407 self.left_compound_idx[r + cell] = compound_idx;
@@ -8430,7 +8490,7 @@ fn obmc_blend(
8430 // divide back down to that column.8490 // divide back down to that column.
8431 let (h_kind, v_kind) = neighbour_filter(8491 let (h_kind, v_kind) = neighbour_filter(
8432 interp_fixed,8492 interp_fixed,
8433- neighbours.above_filter[(mi_col + off4) / SUB_MI as usize],8493+ neighbours.above_filter[mi_col + off4],
8434 );8494 );
8435 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;8495 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
8436 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);8496 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
@@ -8454,7 +8514,7 @@ fn obmc_blend(
8454 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {8514 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {
8455 let (h_kind, v_kind) = neighbour_filter(8515 let (h_kind, v_kind) = neighbour_filter(
8456 interp_fixed,8516 interp_fixed,
8457- neighbours.left_filter[(mi_row + off4) / SUB_MI as usize],8517+ neighbours.left_filter[mi_row + off4],
8458 );8518 );
8459 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;8519 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
8460 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);8520 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
@@ -8495,10 +8555,17 @@ fn is_uni_comp_ref(ref0: i8, ref1: i8) -> bool {
8495 /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the8555 /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the
8496 /// above/left neighbour contributions [`Neighbours::record_inter`]/8556 /// above/left neighbour contributions [`Neighbours::record_inter`]/
8497 /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5.8557 /// [`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 {
8499 let _ = side;8566 let _ = side;
8500- let (r, c) = at;8567+ let (rmi, cmi) = at_mi;
8501- (neighbours.above_comp_group_idx[c] as usize + neighbours.left_comp_group_idx[r] as usize)8568+ (neighbours.above_comp_group_idx[cmi] as usize + neighbours.left_comp_group_idx[rmi] as usize)
8502 .min(5)8569 .min(5)
8503 }8570 }
8504 8571
@@ -8510,7 +8577,7 @@ fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side:
8510 #[allow(clippy::too_many_arguments)]8577 #[allow(clippy::too_many_arguments)]
8511 fn get_comp_index_context(8578 fn get_comp_index_context(
8512 neighbours: &Neighbours,8579 neighbours: &Neighbours,
8513- at: (usize, usize),8580+ at_mi: (usize, usize),
8514 side: usize,8581 side: usize,
8515 order_hint_bits: u32,8582 order_hint_bits: u32,
8516 cur_order_hint: u32,8583 cur_order_hint: u32,
@@ -8518,7 +8585,7 @@ fn get_comp_index_context(
8518 ref1_order_hint: u32,8585 ref1_order_hint: u32,
8519 ) -> usize {8586 ) -> usize {
8520 let _ = side;8587 let _ = side;
8521- let (r, c) = at;8588+ let (rmi, cmi) = at_mi;
8522 let fwd =8589 let fwd =
8523 crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint)8590 crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint)
8524 .abs();8591 .abs();
@@ -8526,8 +8593,8 @@ fn get_comp_index_context(
8526 crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint)8593 crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint)
8527 .abs();8594 .abs();
8528 let offset = usize::from(fwd == bck);8595 let offset = usize::from(fwd == bck);
8529- neighbours.above_compound_idx[c] as usize8596+ neighbours.above_compound_idx[cmi] as usize
8530- + neighbours.left_compound_idx[r] as usize8597+ + neighbours.left_compound_idx[rmi] as usize
8531 + 3 * offset8598 + 3 * offset
8532 }8599 }
8533 8600
@@ -8901,6 +8968,11 @@ fn decode_inter_block(
8901 frame_width: usize,8968 frame_width: usize,
8902 ) -> Result<()> {8969 ) -> Result<()> {
8903 let (r, c) = at;8970 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));
8904 let (px, py) = (c * SUB, r * SUB);8976 let (px, py) = (c * SUB, r * SUB);
8905 let (cpx, cpy) = (px / 2, py / 2);8977 let (cpx, cpy) = (px / 2, py / 2);
8906 let chroma_side = side / 2;8978 let chroma_side = side / 2;
@@ -8913,7 +8985,7 @@ fn decode_inter_block(
8913 );8985 );
8914 }8986 }
8915 let skip_mode_ctx =8987 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]);
8917 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read8989 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
8918 // MSAC tell so it can be diffed against an equivalent hook in libaom's8990 // MSAC tell so it can be diffed against an equivalent hook in libaom's
8919 // own `read_skip_mode`/`av1_get_skip_mode_context`.8991 // own `read_skip_mode`/`av1_get_skip_mode_context`.
@@ -8934,7 +9006,7 @@ fn decode_inter_block(
8934 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));9006 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
8935 }9007 }
8936 9008
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]);
8938 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;9010 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
8939 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);9011 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
8940 maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip);9012 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(
8952 r > neighbours.tile_row0_mi / (SUB / MI),9024 r > neighbours.tile_row0_mi / (SUB / MI),
8953 c > neighbours.tile_col0_mi / (SUB / MI),9025 c > neighbours.tile_col0_mi / (SUB / MI),
8954 );9026 );
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]);
8956 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);9028 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
8957 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;9029 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
8958 if std::env::var_os("EC_TRACE_MODE").is_some() {9030 if std::env::var_os("EC_TRACE_MODE").is_some() {
@@ -8985,24 +9057,24 @@ fn decode_inter_block(
8985 let above_nbr = has_above.then(|| NeighbourRef {9057 let above_nbr = has_above.then(|| NeighbourRef {
8986 is_inter: above_inter,9058 is_inter: above_inter,
8987 ref0: if above_inter {9059 ref0: if above_inter {
8988- neighbours.above_ref[c]9060+ neighbours.above_ref[cmi]
8989 } else {9061 } else {
8990 09062 0
8991 },9063 },
8992- ref1: neighbours.above_ref1[c],9064+ ref1: neighbours.above_ref1[cmi],
8993- uni: neighbours.above_ref1[c]9065+ uni: neighbours.above_ref1[cmi]
8994- .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[c], r1)),9066+ .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[cmi], r1)),
8995 });9067 });
8996 let left_nbr = has_left.then(|| NeighbourRef {9068 let left_nbr = has_left.then(|| NeighbourRef {
8997 is_inter: left_inter,9069 is_inter: left_inter,
8998 ref0: if left_inter {9070 ref0: if left_inter {
8999- neighbours.left_ref[r]9071+ neighbours.left_ref[rmi]
9000 } else {9072 } else {
9001 09073 0
9002 },9074 },
9003- ref1: neighbours.left_ref1[r],9075+ ref1: neighbours.left_ref1[rmi],
9004- uni: neighbours.left_ref1[r]9076+ uni: neighbours.left_ref1[rmi]
9005- .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)),9077+ .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
9006 });9078 });
9007 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {9079 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
9008 eprintln!(9080 eprintln!(
@@ -9021,8 +9093,8 @@ fn decode_inter_block(
9021 cdfs,9093 cdfs,
9022 above_nbr,9094 above_nbr,
9023 left_nbr,9095 left_nbr,
9024- neighbours.above_ref[c],9096+ neighbours.above_ref[cmi],
9025- neighbours.left_ref[r],9097+ neighbours.left_ref[rmi],
9026 )9098 )
9027 };9099 };
9028 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);9100 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
@@ -9099,17 +9171,17 @@ fn decode_inter_block(
9099 // real filter match down to the "no neighbour" sentinel9171 // real filter match down to the "no neighbour" sentinel
9100 // whenever the shared reference sits in the neighbour's SECOND9172 // whenever the shared reference sits in the neighbour's SECOND
9101 // slot (lane-av1idx r2).9173 // slot (lane-av1idx r2).
9102- let above_filter_ctx = if neighbours.above_ref[c] == ref09174+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref0
9103- || neighbours.above_ref1[c] == Some(ref0)9175+ || neighbours.above_ref1[cmi] == Some(ref0)
9104 {9176 {
9105- neighbours.above_filter[c]9177+ neighbours.above_filter[cmi]
9106 } else {9178 } else {
9107 [3, 3]9179 [3, 3]
9108 };9180 };
9109- let left_filter_ctx = if neighbours.left_ref[r] == ref09181+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref0
9110- || neighbours.left_ref1[r] == Some(ref0)9182+ || neighbours.left_ref1[rmi] == Some(ref0)
9111 {9183 {
9112- neighbours.left_filter[r]9184+ neighbours.left_filter[rmi]
9113 } else {9185 } else {
9114 [3, 3]9186 [3, 3]
9115 };9187 };
@@ -9159,7 +9231,7 @@ fn decode_inter_block(
9159 // there), so the gate reduces to the sequence header bit; kept9231 // there), so the gate reduces to the sequence header bit; kept
9160 // as an explicit call so a future smaller block size is not9232 // as an explicit call so a future smaller block size is not
9161 // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`).9233 // 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);
9163 let comp_group_idx = if !skip_mode9235 let comp_group_idx = if !skip_mode
9164 && enable_masked_compound9236 && enable_masked_compound
9165 && is_any_masked_compound_used_here(side)9237 && is_any_masked_compound_used_here(side)
@@ -9423,7 +9495,7 @@ fn decode_inter_block(
9423 {9495 {
9424 let idx_ctx = get_comp_index_context(9496 let idx_ctx = get_comp_index_context(
9425 neighbours,9497 neighbours,
9426- at,9498+ (rmi, cmi),
9427 side,9499 side,
9428 order_hint_bits,9500 order_hint_bits,
9429 order_hint,9501 order_hint,
@@ -9712,10 +9784,10 @@ fn decode_inter_block(
9712 read_single_ref(9784 read_single_ref(
9713 dec,9785 dec,
9714 cdfs,9786 cdfs,
9715- neighbours.above_ref[c],9787+ neighbours.above_ref[cmi],
9716- neighbours.above_ref1[c],9788+ neighbours.above_ref1[cmi],
9717- neighbours.left_ref[r],9789+ neighbours.left_ref[rmi],
9718- neighbours.left_ref1[r],9790+ neighbours.left_ref1[rmi],
9719 );9791 );
9720 ref_frame_for_lf = ref_frame;9792 ref_frame_for_lf = ref_frame;
9721 if std::env::var_os("EC_AV1_TELL").is_some() {9793 if std::env::var_os("EC_AV1_TELL").is_some() {
@@ -10089,17 +10161,17 @@ fn decode_inter_block(
10089 // lane-av1idx r2: also match on the neighbour's SECOND reference10161 // lane-av1idx r2: also match on the neighbour's SECOND reference
10090 // (`above_ref1`/`left_ref1`, real for a compound neighbour) --10162 // (`above_ref1`/`left_ref1`, real for a compound neighbour) --
10091 // see the 16x16 leaf's own comment above for the spec citation.10163 // see the 16x16 leaf's own comment above for the spec citation.
10092- let above_filter_ctx = if neighbours.above_ref[c] == ref_frame10164+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame
10093- || neighbours.above_ref1[c] == Some(ref_frame)10165+ || neighbours.above_ref1[cmi] == Some(ref_frame)
10094 {10166 {
10095- neighbours.above_filter[c]10167+ neighbours.above_filter[cmi]
10096 } else {10168 } else {
10097 [3, 3]10169 [3, 3]
10098 };10170 };
10099- let left_filter_ctx = if neighbours.left_ref[r] == ref_frame10171+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame
10100- || neighbours.left_ref1[r] == Some(ref_frame)10172+ || neighbours.left_ref1[rmi] == Some(ref_frame)
10101 {10173 {
10102- neighbours.left_filter[r]10174+ neighbours.left_filter[rmi]
10103 } else {10175 } else {
10104 [3, 3]10176 [3, 3]
10105 };10177 };
@@ -10717,11 +10789,6 @@ fn decode_inter_block8(
10717 base_q_idx: u8,10789 base_q_idx: u8,
10718 scan8: &[u16],10790 scan8: &[u16],
10719 scan4: &[u16],10791 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>)],
10725 allow_high_precision_mv: bool,10792 allow_high_precision_mv: bool,
10726 force_integer_mv: bool,10793 force_integer_mv: bool,
10727 // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path10794 // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path
@@ -10741,7 +10808,7 @@ fn decode_inter_block8(
10741 // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this10808 // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this
10742 // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,10809 // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either,
10743 // so its `skip_mode` context reuses the same [`SUB`]-grid10810 // so its `skip_mode` context reuses the same [`SUB`]-grid
10744- // `above_skip_mode[c]`/`left_skip_mode[r]` the enclosing 16x16 slot10811+ // `above_skip_mode[cmi]`/`left_skip_mode[rmi]` the enclosing 16x16 slot
10745 // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation10812 // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation
10746 // just above).10813 // just above).
10747 skip_mode_present: bool,10814 skip_mode_present: bool,
@@ -10779,6 +10846,13 @@ fn decode_inter_block8(
10779 // this block (mi 4,14 of the mandelbrot 8x8-split gate).10846 // this block (mi 4,14 of the mandelbrot 8x8-split gate).
10780 sign_bias_table: &SignBiasTable,10847 sign_bias_table: &SignBiasTable,
10781 global_motion: &[ec_av1_syntax::WarpParams; 7],10848 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>,
10782 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, (i8, Option<i8>))> {10856 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, (i8, Option<i8>))> {
10783 const LAST_FRAME: i8 = 1;10857 const LAST_FRAME: i8 = 1;
10784 let gm_table = build_gm_mv_table(10858 let gm_table = build_gm_mv_table(
@@ -10799,29 +10873,26 @@ fn decode_inter_block8(
10799 const CHROMA_SIDE: usize = 4;10873 const CHROMA_SIDE: usize = 4;
10800 10874
10801 let (r, c) = outer_at;10875 let (r, c) = outer_at;
10802- let mut above_skip = neighbours.above_skip[c];10876+ let _ = (r, c);
10803- let mut left_skip = neighbours.left_skip[r];10877+ // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
10804- let mut above_inter = neighbours.above_inter[c];10878+ // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the
10805- let mut left_inter = neighbours.left_inter[r];10879+ // left column of a 16x16's second leaf ROW is the previous 16x16 block's
10806- let mut above_ref0 = neighbours.above_ref[c];10880+ // bottom leaf, neither of which a SUB-grid slot can name.
10807- let mut above_ref1 = neighbours.above_ref1[c];10881+ let (rmi, cmi) = leaf_mi;
10808- let mut left_ref0 = neighbours.left_ref[r];10882+ // lane-inter8 r2: no sibling-leaf override any more -- each leaf stamps
10809- let mut left_ref1 = neighbours.left_ref1[r];10883+ // its own 2x2-mi span into the bands right after it decodes (the caller's
10810- for &((pr, pc), pskip, pinter, pref0, pref1) in prev_leaves {10884+ // `record_inter_rect_mi`), so a plain mi read already names the correct
10811- if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {10885+ // neighbour, including one belonging to the previous 16x16 block.
10812- above_skip = pskip;10886+ let above_skip = neighbours.above_skip[cmi];
10813- above_inter = pinter;10887+ let left_skip = neighbours.left_skip[rmi];
10814- above_ref0 = pref0;10888+ let above_inter = neighbours.above_inter[cmi];
10815- above_ref1 = pref1;10889+ let left_inter = neighbours.left_inter[rmi];
10816- } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {10890+ let above_ref0 = neighbours.above_ref[cmi];
10817- left_skip = pskip;10891+ let above_ref1 = neighbours.above_ref1[cmi];
10818- left_inter = pinter;10892+ let left_ref0 = neighbours.left_ref[rmi];
10819- left_ref0 = pref0;10893+ let left_ref1 = neighbours.left_ref1[rmi];
10820- left_ref1 = pref1;
10821- }
10822- }
10823 let skip_mode_ctx =10894 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]);
10825 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;10896 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
10826 if skip_mode {10897 if skip_mode {
10827 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));10898 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
@@ -10904,6 +10975,22 @@ fn decode_inter_block8(
10904 };10975 };
10905 leaf_refs = (ref0, Some(ref1));10976 leaf_refs = (ref0, Some(ref1));
10906 let (mi_row, mi_col) = leaf_mi;10977 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+ });
10907 // lane-av1comp: this leaf path has neither a real sign-bias10994 // lane-av1comp: this leaf path has neither a real sign-bias
10908 // table nor `tpl_frame` (see this function's own doc on the10995 // table nor `tpl_frame` (see this function's own doc on the
10909 // coarse `LAST_FRAME`-or-intra neighbour approximation10996 // coarse `LAST_FRAME`-or-intra neighbour approximation
@@ -10921,7 +11008,7 @@ fn decode_inter_block8(
10921 mi_rows as usize,11008 mi_rows as usize,
10922 sign_bias_table,11009 sign_bias_table,
10923 &gm_table,11010 &gm_table,
10924- None,11011+ comp_tpl,
10925 );11012 );
10926 let compound_mode = if skip_mode {11013 let compound_mode = if skip_mode {
10927 0 // NEAREST_NEARESTMV, forced -- no mode symbol read11014 0 // NEAREST_NEARESTMV, forced -- no mode symbol read
@@ -10964,7 +11051,7 @@ fn decode_inter_block8(
10964 // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid11051 // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid
10965 // slot -- the only granularity `Neighbours`' comp_group_idx/11052 // slot -- the only granularity `Neighbours`' comp_group_idx/
10966 // compound_idx arrays track.11053 // 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);
10968 let comp_group_idx = if !skip_mode11055 let comp_group_idx = if !skip_mode
10969 && enable_masked_compound11056 && enable_masked_compound
10970 && is_any_masked_compound_used_here(SIDE)11057 && is_any_masked_compound_used_here(SIDE)
@@ -11018,7 +11105,7 @@ fn decode_inter_block8(
11018 {11105 {
11019 let idx_ctx = get_comp_index_context(11106 let idx_ctx = get_comp_index_context(
11020 neighbours,11107 neighbours,
11021- outer_at,11108+ leaf_mi,
11022 SIDE,11109 SIDE,
11023 order_hint_bits,11110 order_hint_bits,
11024 order_hint,11111 order_hint,
@@ -11288,6 +11375,17 @@ fn decode_inter_block8(
11288 )?11375 )?
11289 .0;11376 .0;
11290 }11377 }
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 });
11291 return Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs));11389 return Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs));
11292 }11390 }
11293 }11391 }
@@ -11303,6 +11401,15 @@ fn decode_inter_block8(
11303 }11401 }
11304 11402
11305 let (mi_row, mi_col) = leaf_mi;11403 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+ });
11306 let stack = find_mv_stack_with_sign_bias(11413 let stack = find_mv_stack_with_sign_bias(
11307 grid,11414 grid,
11308 mi_row,11415 mi_row,
@@ -11314,7 +11421,7 @@ fn decode_inter_block8(
11314 mi_rows as usize,11421 mi_rows as usize,
11315 sign_bias_table,11422 sign_bias_table,
11316 &gm_table,11423 &gm_table,
11317- None,11424+ tpl,
11318 );11425 );
11319 11426
11320 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;11427 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(
12565 base_q_idx,12672 base_q_idx,
12566 &scan8,12673 &scan8,
12567 &scan4,12674 &scan4,
12568- &prev_leaves,
12569 allow_high_precision_mv,12675 allow_high_precision_mv,
12570 force_integer_mv,12676 force_integer_mv,
12571 reference_select,12677 reference_select,
@@ -12584,48 +12690,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12584 allow_screen_content_tools,12690 allow_screen_content_tools,
12585 &sign_bias_table,12691 &sign_bias_table,
12586 &global_motion,12692 &global_motion,
12693+ tpl_frame.as_ref(),
12587 )?;12694 )?;
12588 prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1));12695 prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1));
12589 last_skip_mode = skip_mode_leaf;12696 last_skip_mode = skip_mode_leaf;
12590 if compound_ctx8.is_some() {12697 if compound_ctx8.is_some() {
12591 last_compound_ctx = compound_ctx8;12698 last_compound_ctx = compound_ctx8;
12592 }12699 }
12593- }12700+ // lane-inter8 r2: stamp THIS leaf's own
12594- if let Some(&(_, skip, is_inter, _, _)) = prev_leaves.last() {12701+ // 2x2-mi span before the next leaf reads
12595- // corner-cut: `decode_inter_block8`'s12702+ // it as a neighbour -- the whole-16x16
12596- // leaves never read a switchable filter12703+ // stamp below only ever described the
12597- // (round-3 GLOBALMV refusal already12704+ // last leaf, so three quarters of the
12598- // bounds them away from the Regular-only12705+ // block carried the wrong skip/ref/inter
12599- // gap this round closes elsewhere); `[3,12706+ // state into the next block's contexts
12600- // 3]` is "no info", the same value an12707+ // (class context-read-from-one-cell).
12601- // intra neighbour records. Upgrade:12708+ // corner-cut: `[3, 3]` filter, as the
12602- // thread `interp_fixed`/`enable_dual_filter`12709+ // 16x16 stamp used -- `decode_inter_block8`
12603- // into `decode_inter_block8` once a12710+ // reads no switchable filter yet.
12604- // straddling 8x8 SWITCHABLE stream is on12711+ neighbours.record_inter_rect_mi(
12605- // hand to pin against.12712+ leaf_mi,
12606- neighbours.record_inter(12713+ 2,
12607- at16,12714+ 2,
12608- SUB,
12609 skip,12715 skip,
12610 is_inter,12716 is_inter,
12611- if is_inter { LAST_FRAME } else { -1 },12717+ leaf_refs.0,
12612 [3, 3],12718 [3, 3],
12613- last_skip_mode,12719+ skip_mode_leaf,
12614 );12720 );
12615- if let Some((ref0, ref1, group_idx, idx)) = last_compound_ctx {12721+ if let Some(ref1) = leaf_refs.1
12616- neighbours.record_inter(12722+ && let Some((_, _, group_idx, idx)) = compound_ctx8
12617- at16,12723+ {
12618- SUB,12724+ neighbours.record_compound_ctx_rect_mi(
12619- skip,12725+ leaf_mi, 2, 2, ref1, group_idx, idx,
12620- is_inter,
12621- ref0,
12622- [3, 3],
12623- last_skip_mode,
12624 );12726 );
12625- neighbours
12626- .record_compound_ctx(at16, SUB, ref1, group_idx, idx);
12627 }12727 }
12628 }12728 }
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.
12629 }12733 }
12630 }12734 }
12631 }12735 }
crates/ec-av1/src/stream.rsmodified+13 -18
@@ -2943,16 +2943,11 @@ mod tests {
2943 /// was refused by name until this round; the straddle path always ran the2943 /// was refused by name until this round; the straddle path always ran the
2944 /// same loop, so only [`decode::inter_sub16_split_hits`] -- which counts2944 /// same loop, so only [`decode::inter_sub16_split_hits`] -- which counts
2945 /// interior splits only -- proves the newly-lifted alphabet value fired.2945 /// 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.
2946 #[test]2950 #[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"]
2956 fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {2951 fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
2957 inter_sb_none_gate(2952 inter_sb_none_gate(
2958 "a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",2953 "a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",
@@ -2965,15 +2960,15 @@ mod tests {
2965 }2960 }
2966 2961
2967 #[test]2962 #[test]
2968- // lane-inter8 r1: RED, and ignored rather than deleted. The 16x16-level2963+ // lane-inter8 r2: still RED, and ignored rather than deleted -- the 8-bit
2969- // interior `PARTITION_SPLIT` and its four 8x8 leaves now decode without a2964+ // twin above is green, this 10-bit recipe stops at "an INTER 32x32
2970- // refusal, and the mode-info range ladder matches aomdec's `EC_MODE` for2965+ // partition type this decoder does not code (value=9)". That is OUR
2971- // 42 blocks, but block mi=(6,12) still diverges: `Neighbours`' above_*/2966+ // desync, proven: `EC_TRACE=1 aomdec` on the pinned stream reads
2972- // left_* arrays are 16x16-granular, so the LEFT neighbour of leaf (6,12)2967+ // 16 `bsize=9 value=3` (SPLIT) partitions and never a single value=9
2973- // resolves to whatever the previous 16x16 recorded rather than to that2968+ // anywhere (class refusal-from-own-desync; the r1 ledger line claiming
2974- // block's own bottom-right leaf (6,10). Un-ignore when the arrays are2969+ // aomenc emits PARTITION_VERT_4 despite --enable-1to4-partitions=0 is
2975- // mi-granular (see lanes/inter8-r1.report.md).2970+ // hereby disproven). The divergence itself is not yet bisected.
2976- #[ignore = "lane-inter8 r1: 8x8 leaf neighbour arrays are still 16x16-granular"]2971+ #[ignore = "lane-inter8 r2: 10-bit twin still desyncs (surfaces as a bogus 32x32 value=9 refusal); 8-bit gate is green"]
2977 fn a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {2972 fn a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
2978 inter_sb_none_gate(2973 inter_sb_none_gate(
2979 "a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",2974 "a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",