Mi-granular inter neighbour bands + three 8x8-leaf context defects (8-bit 8x8-split gate GREEN)
Browse files at this commitcbf9f543ddcd72ff297ee68a2b298e7d41533719Parent: 1bfb2cb- fix
- mi-granular inter neighbour bands + three 8x8-leaf context defects (8-bit 8x8-split gate GREEN)
2 changed files +239 -140
- crates/ec-av1/src/decode.rs +226 -122
- crates/ec-av1/src/stream.rs +13 -18
crates/ec-av1/src/decode.rsmodified+226 -122
| @@ -1907,22 +1907,26 @@ impl Neighbours { | ||
| 1907 | 1907 | left_side: vec![SB; rows], |
| 1908 | 1908 | above_side_mi: vec![SB; cols * (SUB / MI)], |
| 1909 | 1909 | 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)], | |
| 1926 | 1930 | mi_cols, |
| 1927 | 1931 | mi_rows, |
| 1928 | 1932 | skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)], |
| @@ -1965,6 +1969,11 @@ impl Neighbours { | ||
| 1965 | 1969 | for i in sc0.min(sc1)..sc1 { |
| 1966 | 1970 | self.above_mode[i] = DC_PRED; |
| 1967 | 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 | 1977 | self.above_skip[i] = false; |
| 1969 | 1978 | self.above_skip_mode[i] = false; |
| 1970 | 1979 | self.above_inter[i] = false; |
| @@ -2271,8 +2280,37 @@ impl Neighbours { | ||
| 2271 | 2280 | skip_mode: bool, |
| 2272 | 2281 | ) { |
| 2273 | 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 | 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 | 2314 | self.above_skip[c + cell] = skip; |
| 2277 | 2315 | self.above_skip_mode[c + cell] = skip_mode; |
| 2278 | 2316 | self.above_inter[c + cell] = is_inter; |
| @@ -2290,7 +2328,7 @@ impl Neighbours { | ||
| 2290 | 2328 | self.above_compound_idx[c + cell] = u8::from(altref); |
| 2291 | 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 | 2332 | self.left_skip[r + cell] = skip; |
| 2295 | 2333 | self.left_skip_mode[r + cell] = skip_mode; |
| 2296 | 2334 | self.left_inter[r + cell] = is_inter; |
| @@ -2336,12 +2374,34 @@ impl Neighbours { | ||
| 2336 | 2374 | compound_idx: u8, |
| 2337 | 2375 | ) { |
| 2338 | 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 | 2400 | self.above_ref1[c + cell] = Some(ref1); |
| 2341 | 2401 | self.above_comp_group_idx[c + cell] = comp_group_idx; |
| 2342 | 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 | 2405 | self.left_ref1[r + cell] = Some(ref1); |
| 2346 | 2406 | self.left_comp_group_idx[r + cell] = comp_group_idx; |
| 2347 | 2407 | self.left_compound_idx[r + cell] = compound_idx; |
| @@ -8430,7 +8490,7 @@ fn obmc_blend( | ||
| 8430 | 8490 | // divide back down to that column. |
| 8431 | 8491 | let (h_kind, v_kind) = neighbour_filter( |
| 8432 | 8492 | interp_fixed, |
| 8433 | - neighbours.above_filter[(mi_col + off4) / SUB_MI as usize], | |
| 8493 | + neighbours.above_filter[mi_col + off4], | |
| 8434 | 8494 | ); |
| 8435 | 8495 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 8436 | 8496 | let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); |
| @@ -8454,7 +8514,7 @@ fn obmc_blend( | ||
| 8454 | 8514 | for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) { |
| 8455 | 8515 | let (h_kind, v_kind) = neighbour_filter( |
| 8456 | 8516 | interp_fixed, |
| 8457 | - neighbours.left_filter[(mi_row + off4) / SUB_MI as usize], | |
| 8517 | + neighbours.left_filter[mi_row + off4], | |
| 8458 | 8518 | ); |
| 8459 | 8519 | let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; |
| 8460 | 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 | 8555 | /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the |
| 8496 | 8556 | /// above/left neighbour contributions [`Neighbours::record_inter`]/ |
| 8497 | 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 | 8566 | 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) | |
| 8502 | 8569 | .min(5) |
| 8503 | 8570 | } |
| 8504 | 8571 | |
| @@ -8510,7 +8577,7 @@ fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side: | ||
| 8510 | 8577 | #[allow(clippy::too_many_arguments)] |
| 8511 | 8578 | fn get_comp_index_context( |
| 8512 | 8579 | neighbours: &Neighbours, |
| 8513 | - at: (usize, usize), | |
| 8580 | + at_mi: (usize, usize), | |
| 8514 | 8581 | side: usize, |
| 8515 | 8582 | order_hint_bits: u32, |
| 8516 | 8583 | cur_order_hint: u32, |
| @@ -8518,7 +8585,7 @@ fn get_comp_index_context( | ||
| 8518 | 8585 | ref1_order_hint: u32, |
| 8519 | 8586 | ) -> usize { |
| 8520 | 8587 | let _ = side; |
| 8521 | - let (r, c) = at; | |
| 8588 | + let (rmi, cmi) = at_mi; | |
| 8522 | 8589 | let fwd = |
| 8523 | 8590 | crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint) |
| 8524 | 8591 | .abs(); |
| @@ -8526,8 +8593,8 @@ fn get_comp_index_context( | ||
| 8526 | 8593 | crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint) |
| 8527 | 8594 | .abs(); |
| 8528 | 8595 | 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 | |
| 8531 | 8598 | + 3 * offset |
| 8532 | 8599 | } |
| 8533 | 8600 | |
| @@ -8901,6 +8968,11 @@ fn decode_inter_block( | ||
| 8901 | 8968 | frame_width: usize, |
| 8902 | 8969 | ) -> Result<()> { |
| 8903 | 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 | 8976 | let (px, py) = (c * SUB, r * SUB); |
| 8905 | 8977 | let (cpx, cpy) = (px / 2, py / 2); |
| 8906 | 8978 | let chroma_side = side / 2; |
| @@ -8913,7 +8985,7 @@ fn decode_inter_block( | ||
| 8913 | 8985 | ); |
| 8914 | 8986 | } |
| 8915 | 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 | 8989 | // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read |
| 8918 | 8990 | // MSAC tell so it can be diffed against an equivalent hook in libaom's |
| 8919 | 8991 | // own `read_skip_mode`/`av1_get_skip_mode_context`. |
| @@ -8934,7 +9006,7 @@ fn decode_inter_block( | ||
| 8934 | 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 | 9010 | let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 8939 | 9011 | maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip); |
| 8940 | 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 | 9024 | r > neighbours.tile_row0_mi / (SUB / MI), |
| 8953 | 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 | 9028 | let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); |
| 8957 | 9029 | let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 8958 | 9030 | if std::env::var_os("EC_TRACE_MODE").is_some() { |
| @@ -8985,24 +9057,24 @@ fn decode_inter_block( | ||
| 8985 | 9057 | let above_nbr = has_above.then(|| NeighbourRef { |
| 8986 | 9058 | is_inter: above_inter, |
| 8987 | 9059 | ref0: if above_inter { |
| 8988 | - neighbours.above_ref[c] | |
| 9060 | + neighbours.above_ref[cmi] | |
| 8989 | 9061 | } else { |
| 8990 | 9062 | 0 |
| 8991 | 9063 | }, |
| 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)), | |
| 8995 | 9067 | }); |
| 8996 | 9068 | let left_nbr = has_left.then(|| NeighbourRef { |
| 8997 | 9069 | is_inter: left_inter, |
| 8998 | 9070 | ref0: if left_inter { |
| 8999 | - neighbours.left_ref[r] | |
| 9071 | + neighbours.left_ref[rmi] | |
| 9000 | 9072 | } else { |
| 9001 | 9073 | 0 |
| 9002 | 9074 | }, |
| 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)), | |
| 9006 | 9078 | }); |
| 9007 | 9079 | if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { |
| 9008 | 9080 | eprintln!( |
| @@ -9021,8 +9093,8 @@ fn decode_inter_block( | ||
| 9021 | 9093 | cdfs, |
| 9022 | 9094 | above_nbr, |
| 9023 | 9095 | left_nbr, |
| 9024 | - neighbours.above_ref[c], | |
| 9025 | - neighbours.left_ref[r], | |
| 9096 | + neighbours.above_ref[cmi], | |
| 9097 | + neighbours.left_ref[rmi], | |
| 9026 | 9098 | ) |
| 9027 | 9099 | }; |
| 9028 | 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 | 9171 | // real filter match down to the "no neighbour" sentinel |
| 9100 | 9172 | // whenever the shared reference sits in the neighbour's SECOND |
| 9101 | 9173 | // 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) | |
| 9104 | 9176 | { |
| 9105 | - neighbours.above_filter[c] | |
| 9177 | + neighbours.above_filter[cmi] | |
| 9106 | 9178 | } else { |
| 9107 | 9179 | [3, 3] |
| 9108 | 9180 | }; |
| 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) | |
| 9111 | 9183 | { |
| 9112 | - neighbours.left_filter[r] | |
| 9184 | + neighbours.left_filter[rmi] | |
| 9113 | 9185 | } else { |
| 9114 | 9186 | [3, 3] |
| 9115 | 9187 | }; |
| @@ -9159,7 +9231,7 @@ fn decode_inter_block( | ||
| 9159 | 9231 | // there), so the gate reduces to the sequence header bit; kept |
| 9160 | 9232 | // as an explicit call so a future smaller block size is not |
| 9161 | 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 | 9235 | let comp_group_idx = if !skip_mode |
| 9164 | 9236 | && enable_masked_compound |
| 9165 | 9237 | && is_any_masked_compound_used_here(side) |
| @@ -9423,7 +9495,7 @@ fn decode_inter_block( | ||
| 9423 | 9495 | { |
| 9424 | 9496 | let idx_ctx = get_comp_index_context( |
| 9425 | 9497 | neighbours, |
| 9426 | - at, | |
| 9498 | + (rmi, cmi), | |
| 9427 | 9499 | side, |
| 9428 | 9500 | order_hint_bits, |
| 9429 | 9501 | order_hint, |
| @@ -9712,10 +9784,10 @@ fn decode_inter_block( | ||
| 9712 | 9784 | read_single_ref( |
| 9713 | 9785 | dec, |
| 9714 | 9786 | 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], | |
| 9719 | 9791 | ); |
| 9720 | 9792 | ref_frame_for_lf = ref_frame; |
| 9721 | 9793 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| @@ -10089,17 +10161,17 @@ fn decode_inter_block( | ||
| 10089 | 10161 | // lane-av1idx r2: also match on the neighbour's SECOND reference |
| 10090 | 10162 | // (`above_ref1`/`left_ref1`, real for a compound neighbour) -- |
| 10091 | 10163 | // 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) | |
| 10094 | 10166 | { |
| 10095 | - neighbours.above_filter[c] | |
| 10167 | + neighbours.above_filter[cmi] | |
| 10096 | 10168 | } else { |
| 10097 | 10169 | [3, 3] |
| 10098 | 10170 | }; |
| 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) | |
| 10101 | 10173 | { |
| 10102 | - neighbours.left_filter[r] | |
| 10174 | + neighbours.left_filter[rmi] | |
| 10103 | 10175 | } else { |
| 10104 | 10176 | [3, 3] |
| 10105 | 10177 | }; |
| @@ -10717,11 +10789,6 @@ fn decode_inter_block8( | ||
| 10717 | 10789 | base_q_idx: u8, |
| 10718 | 10790 | scan8: &[u16], |
| 10719 | 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 | 10792 | allow_high_precision_mv: bool, |
| 10726 | 10793 | force_integer_mv: bool, |
| 10727 | 10794 | // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path |
| @@ -10741,7 +10808,7 @@ fn decode_inter_block8( | ||
| 10741 | 10808 | // lane-av1comp round 14: see [`decode_inter_block`]'s own doc -- this |
| 10742 | 10809 | // leaf has no per-leaf `above_skip_mode`/`left_skip_mode` array either, |
| 10743 | 10810 | // 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 | |
| 10745 | 10812 | // tracks (mirroring `above_skip`/`left_skip`'s own leaf approximation |
| 10746 | 10813 | // just above). |
| 10747 | 10814 | skip_mode_present: bool, |
| @@ -10779,6 +10846,13 @@ fn decode_inter_block8( | ||
| 10779 | 10846 | // this block (mi 4,14 of the mandelbrot 8x8-split gate). |
| 10780 | 10847 | sign_bias_table: &SignBiasTable, |
| 10781 | 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 | 10856 | ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, (i8, Option<i8>))> { |
| 10783 | 10857 | const LAST_FRAME: i8 = 1; |
| 10784 | 10858 | let gm_table = build_gm_mv_table( |
| @@ -10799,29 +10873,26 @@ fn decode_inter_block8( | ||
| 10799 | 10873 | const CHROMA_SIDE: usize = 4; |
| 10800 | 10874 | |
| 10801 | 10875 | 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]; | |
| 10823 | 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 | 10896 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| 10826 | 10897 | if skip_mode { |
| 10827 | 10898 | SKIP_MODE_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -10904,6 +10975,22 @@ fn decode_inter_block8( | ||
| 10904 | 10975 | }; |
| 10905 | 10976 | leaf_refs = (ref0, Some(ref1)); |
| 10906 | 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 | 10994 | // lane-av1comp: this leaf path has neither a real sign-bias |
| 10908 | 10995 | // table nor `tpl_frame` (see this function's own doc on the |
| 10909 | 10996 | // coarse `LAST_FRAME`-or-intra neighbour approximation |
| @@ -10921,7 +11008,7 @@ fn decode_inter_block8( | ||
| 10921 | 11008 | mi_rows as usize, |
| 10922 | 11009 | sign_bias_table, |
| 10923 | 11010 | &gm_table, |
| 10924 | - None, | |
| 11011 | + comp_tpl, | |
| 10925 | 11012 | ); |
| 10926 | 11013 | let compound_mode = if skip_mode { |
| 10927 | 11014 | 0 // NEAREST_NEARESTMV, forced -- no mode symbol read |
| @@ -10964,7 +11051,7 @@ fn decode_inter_block8( | ||
| 10964 | 11051 | // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid |
| 10965 | 11052 | // slot -- the only granularity `Neighbours`' comp_group_idx/ |
| 10966 | 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 | 11055 | let comp_group_idx = if !skip_mode |
| 10969 | 11056 | && enable_masked_compound |
| 10970 | 11057 | && is_any_masked_compound_used_here(SIDE) |
| @@ -11018,7 +11105,7 @@ fn decode_inter_block8( | ||
| 11018 | 11105 | { |
| 11019 | 11106 | let idx_ctx = get_comp_index_context( |
| 11020 | 11107 | neighbours, |
| 11021 | - outer_at, | |
| 11108 | + leaf_mi, | |
| 11022 | 11109 | SIDE, |
| 11023 | 11110 | order_hint_bits, |
| 11024 | 11111 | order_hint, |
| @@ -11288,6 +11375,17 @@ fn decode_inter_block8( | ||
| 11288 | 11375 | )? |
| 11289 | 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 | 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 | 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 | 11413 | let stack = find_mv_stack_with_sign_bias( |
| 11307 | 11414 | grid, |
| 11308 | 11415 | mi_row, |
| @@ -11314,7 +11421,7 @@ fn decode_inter_block8( | ||
| 11314 | 11421 | mi_rows as usize, |
| 11315 | 11422 | sign_bias_table, |
| 11316 | 11423 | &gm_table, |
| 11317 | - None, | |
| 11424 | + tpl, | |
| 11318 | 11425 | ); |
| 11319 | 11426 | |
| 11320 | 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 | 12672 | base_q_idx, |
| 12566 | 12673 | &scan8, |
| 12567 | 12674 | &scan4, |
| 12568 | - &prev_leaves, | |
| 12569 | 12675 | allow_high_precision_mv, |
| 12570 | 12676 | force_integer_mv, |
| 12571 | 12677 | reference_select, |
| @@ -12584,48 +12690,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 12584 | 12690 | allow_screen_content_tools, |
| 12585 | 12691 | &sign_bias_table, |
| 12586 | 12692 | &global_motion, |
| 12693 | + tpl_frame.as_ref(), | |
| 12587 | 12694 | )?; |
| 12588 | 12695 | prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1)); |
| 12589 | 12696 | last_skip_mode = skip_mode_leaf; |
| 12590 | 12697 | if compound_ctx8.is_some() { |
| 12591 | 12698 | last_compound_ctx = compound_ctx8; |
| 12592 | 12699 | } |
| 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, | |
| 12609 | 12715 | skip, |
| 12610 | 12716 | is_inter, |
| 12611 | - if is_inter { LAST_FRAME } else { -1 }, | |
| 12717 | + leaf_refs.0, | |
| 12612 | 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 { | |
| 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, | |
| 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 | 2943 | /// was refused by name until this round; the straddle path always ran the |
| 2944 | 2944 | /// same loop, so only [`decode::inter_sub16_split_hits`] -- which counts |
| 2945 | 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 | 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 | 2951 | fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() { |
| 2957 | 2952 | inter_sb_none_gate( |
| 2958 | 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 | 2962 | #[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"] | |
| 2977 | 2972 | fn a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() { |
| 2978 | 2973 | inter_sb_none_gate( |
| 2979 | 2974 | "a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact", |