wip(av1): compound MC wired in the 8x8 leaf path, ref1/uni threaded to neighbours
Browse files at this commit1324c3df15d8ca145102899ba8f0ff6f21b3ffceParent: fed4a601 changed file +599 -280
- crates/ec-av1/src/decode.rs +599 -280
crates/ec-av1/src/decode.rsmodified+599 -280
| @@ -988,16 +988,24 @@ impl Neighbours { | ||
| 988 | 988 | /// a real compound block's own `comp_group_idx`/`compound_idx` bits |
| 989 | 989 | /// (libaom `has_second_ref(mbmi)` branch of `get_comp_group_idx_context`/ |
| 990 | 990 | /// `get_comp_index_context`) -- called right after `record_inter` for |
| 991 | - /// the same `at`/`side`, only on the `COMPOUND_REFERENCE` path. | |
| 991 | + /// the same `at`/`side`, only on the `COMPOUND_REFERENCE` path. Also | |
| 992 | + /// stamps `above_ref1`/`left_ref1` with the block's real second | |
| 993 | + /// reference, which `record_inter` always clears to `None` (lane-av1comp: | |
| 994 | + /// this is the one caller that actually knows it) -- so the next block's | |
| 995 | + /// [`NeighbourRef`](crate::mvstack::NeighbourRef) sees a real compound | |
| 996 | + /// neighbour instead of `record_inter`'s single-ref default. | |
| 992 | 997 | fn record_compound_ctx( |
| 993 | 998 | &mut self, |
| 994 | 999 | at: (usize, usize), |
| 995 | 1000 | side: usize, |
| 1001 | + ref1: i8, | |
| 996 | 1002 | comp_group_idx: u8, |
| 997 | 1003 | compound_idx: u8, |
| 998 | 1004 | ) { |
| 999 | 1005 | let (r, c) = at; |
| 1000 | 1006 | for cell in 0..side / SUB { |
| 1007 | + self.above_ref1[c + cell] = Some(ref1); | |
| 1008 | + self.left_ref1[r + cell] = Some(ref1); | |
| 1001 | 1009 | self.above_comp_group_idx[c + cell] = comp_group_idx; |
| 1002 | 1010 | self.left_comp_group_idx[r + cell] = comp_group_idx; |
| 1003 | 1011 | self.above_compound_idx[c + cell] = compound_idx; |
| @@ -3907,6 +3915,19 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { | ||
| 3907 | 3915 | side.min(side) >= 8 |
| 3908 | 3916 | } |
| 3909 | 3917 | |
| 3918 | +/// Whether a compound reference pair is unidirectional (both references on | |
| 3919 | +/// the same temporal side of the current frame) -- `has_uni_comp_refs` | |
| 3920 | +/// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: | |
| 3921 | +/// a pair is `UNIDIR_COMP_REFERENCE` exactly when neither reference is | |
| 3922 | +/// backward-while-the-other-is-forward, i.e. `is_backward(ref0) == | |
| 3923 | +/// is_backward(ref1)`). Used to build a real | |
| 3924 | +/// [`crate::mvstack::NeighbourRef::uni`] once `ref1` is known, matching | |
| 3925 | +/// [`crate::mvstack::comp_reference_type_ctx`]'s own `is_backward` calls. | |
| 3926 | +fn is_uni_comp_ref(ref0: i8, ref1: i8) -> bool { | |
| 3927 | + let backward = |r: i8| (BWDREF_FRAME..=ALTREF_FRAME).contains(&r); | |
| 3928 | + backward(ref0) == backward(ref1) | |
| 3929 | +} | |
| 3930 | + | |
| 3910 | 3931 | /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the |
| 3911 | 3932 | /// above/left neighbour contributions [`Neighbours::record_inter`]/ |
| 3912 | 3933 | /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5. |
| @@ -3941,7 +3962,9 @@ fn get_comp_index_context( | ||
| 3941 | 3962 | crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint) |
| 3942 | 3963 | .abs(); |
| 3943 | 3964 | let offset = usize::from(fwd == bck); |
| 3944 | - neighbours.above_compound_idx[c] as usize + neighbours.left_compound_idx[r] as usize + 3 * offset | |
| 3965 | + neighbours.above_compound_idx[c] as usize | |
| 3966 | + + neighbours.left_compound_idx[r] as usize | |
| 3967 | + + 3 * offset | |
| 3945 | 3968 | } |
| 3946 | 3969 | |
| 3947 | 3970 | fn read_comp_mode( |
| @@ -4234,7 +4257,7 @@ fn decode_inter_block( | ||
| 4234 | 4257 | // `COMPOUND_REFERENCE` block -- applied to `neighbours` *after* the |
| 4235 | 4258 | // common `record_inter` call below (which would otherwise stamp the |
| 4236 | 4259 | // single-ref ALTREF-special-case default over it). |
| 4237 | - let mut compound_ctx: Option<(u8, u8)> = None; | |
| 4260 | + let mut compound_ctx: Option<(i8, u8, u8)> = None; | |
| 4238 | 4261 | if is_inter { |
| 4239 | 4262 | let above_nbr = has_above.then(|| NeighbourRef { |
| 4240 | 4263 | is_inter: above_inter, |
| @@ -4244,7 +4267,8 @@ fn decode_inter_block( | ||
| 4244 | 4267 | 0 |
| 4245 | 4268 | }, |
| 4246 | 4269 | ref1: neighbours.above_ref1[c], |
| 4247 | - uni: false, | |
| 4270 | + uni: neighbours.above_ref1[c] | |
| 4271 | + .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[c], r1)), | |
| 4248 | 4272 | }); |
| 4249 | 4273 | let left_nbr = has_left.then(|| NeighbourRef { |
| 4250 | 4274 | is_inter: left_inter, |
| @@ -4254,7 +4278,8 @@ fn decode_inter_block( | ||
| 4254 | 4278 | 0 |
| 4255 | 4279 | }, |
| 4256 | 4280 | ref1: neighbours.left_ref1[r], |
| 4257 | - uni: false, | |
| 4281 | + uni: neighbours.left_ref1[r] | |
| 4282 | + .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)), | |
| 4258 | 4283 | }); |
| 4259 | 4284 | let is_compound = reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr); |
| 4260 | 4285 | if is_compound { |
| @@ -4297,12 +4322,8 @@ fn decode_inter_block( | ||
| 4297 | 4322 | sign_bias_table, |
| 4298 | 4323 | comp_tpl, |
| 4299 | 4324 | ); |
| 4300 | - let compound_mode = read_inter_compound_mode( | |
| 4301 | - dec, | |
| 4302 | - cdfs, | |
| 4303 | - comp_stack.new_mv_ctx, | |
| 4304 | - comp_stack.ref_mv_ctx, | |
| 4305 | - ); | |
| 4325 | + let compound_mode = | |
| 4326 | + read_inter_compound_mode(dec, cdfs, comp_stack.new_mv_ctx, comp_stack.ref_mv_ctx); | |
| 4306 | 4327 | let (mv0, mv1) = assign_compound_mv( |
| 4307 | 4328 | dec, |
| 4308 | 4329 | cdfs, |
| @@ -4400,7 +4421,7 @@ fn decode_inter_block( | ||
| 4400 | 4421 | } else { |
| 4401 | 4422 | (8, 8, 1u8) |
| 4402 | 4423 | }; |
| 4403 | - compound_ctx = Some((comp_group_idx as u8, compound_idx)); | |
| 4424 | + compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); | |
| 4404 | 4425 | |
| 4405 | 4426 | let mut inter0_y = vec![0i32; side * side]; |
| 4406 | 4427 | mc::predict_compound_intermediate( |
| @@ -4563,281 +4584,282 @@ fn decode_inter_block( | ||
| 4563 | 4584 | )?; |
| 4564 | 4585 | } |
| 4565 | 4586 | } else { |
| 4566 | - let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | |
| 4567 | - ref_frame_for_lf = ref_frame; | |
| 4568 | - // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own | |
| 4569 | - // stacked defects (lf_level ref/mode-delta forwarding, the | |
| 4570 | - // switchable_interp ref-frame ctx gate, and a film-grain synthesis | |
| 4571 | - // gap that looked like a GOLDEN MC bug by survivor bias -- see the | |
| 4572 | - // ledger) are all closed; GOLDEN_FRAME decodes live via `other_refs` | |
| 4573 | - // below same as every other non-`LAST_FRAME` reference. lane-av1refs | |
| 4574 | - // widens this from GOLDEN alone to every reference `read_single_ref` | |
| 4575 | - // can name. | |
| 4576 | - let (py_ref, pu_ref, pv_ref) = if ref_frame == LAST_FRAME { | |
| 4577 | - (ref_y, ref_u, ref_v) | |
| 4578 | - } else { | |
| 4579 | - match other_refs[ref_frame as usize] { | |
| 4580 | - Some((ry, ru, rv)) => (ry, ru, rv), | |
| 4581 | - None => { | |
| 4582 | - return Err(unsupported( | |
| 4583 | - "a reference frame selected with no picture at this frame's own \ | |
| 4587 | + let ref_frame = | |
| 4588 | + read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | |
| 4589 | + ref_frame_for_lf = ref_frame; | |
| 4590 | + // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own | |
| 4591 | + // stacked defects (lf_level ref/mode-delta forwarding, the | |
| 4592 | + // switchable_interp ref-frame ctx gate, and a film-grain synthesis | |
| 4593 | + // gap that looked like a GOLDEN MC bug by survivor bias -- see the | |
| 4594 | + // ledger) are all closed; GOLDEN_FRAME decodes live via `other_refs` | |
| 4595 | + // below same as every other non-`LAST_FRAME` reference. lane-av1refs | |
| 4596 | + // widens this from GOLDEN alone to every reference `read_single_ref` | |
| 4597 | + // can name. | |
| 4598 | + let (py_ref, pu_ref, pv_ref) = if ref_frame == LAST_FRAME { | |
| 4599 | + (ref_y, ref_u, ref_v) | |
| 4600 | + } else { | |
| 4601 | + match other_refs[ref_frame as usize] { | |
| 4602 | + Some((ry, ru, rv)) => (ry, ru, rv), | |
| 4603 | + None => { | |
| 4604 | + return Err(unsupported( | |
| 4605 | + "a reference frame selected with no picture at this frame's own \ | |
| 4584 | 4606 | ref_frame_idx slot for it", |
| 4585 | - )); | |
| 4607 | + )); | |
| 4608 | + } | |
| 4586 | 4609 | } |
| 4587 | - } | |
| 4588 | - }; | |
| 4610 | + }; | |
| 4589 | 4611 | |
| 4590 | - let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | |
| 4591 | - let bw4 = side / 4; | |
| 4592 | - // spec 7.10.2.8: only reached when the frame header set | |
| 4593 | - // `use_ref_frame_mvs` (`tpl_frame` is `Some` then, `None` | |
| 4594 | - // otherwise) -- `cur_offset_0` is this query block's own resolved | |
| 4595 | - // `ref_frame`'s distance from the current frame (spec 7.9.3), | |
| 4596 | - // recomputed per block since different blocks pick different refs. | |
| 4597 | - let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { | |
| 4598 | - field: t.field, | |
| 4599 | - cur_offset_0: crate::motion_field::get_relative_dist( | |
| 4600 | - t.order_hint_bits, | |
| 4601 | - t.order_hint, | |
| 4602 | - t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], | |
| 4603 | - ), | |
| 4604 | - allow_high_precision_mv, | |
| 4605 | - }); | |
| 4606 | - let stack = find_mv_stack_with_sign_bias( | |
| 4607 | - grid, | |
| 4608 | - mi_row, | |
| 4609 | - mi_col, | |
| 4610 | - bw4, | |
| 4611 | - bw4, | |
| 4612 | - ref_frame, | |
| 4613 | - mi_cols as usize, | |
| 4614 | - mi_rows as usize, | |
| 4615 | - sign_bias_table, | |
| 4616 | - tpl, | |
| 4617 | - ); | |
| 4618 | - let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; | |
| 4619 | - let mut is_globalmv = false; | |
| 4620 | - let (mv, is_new_mv) = if !not_new { | |
| 4621 | - // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): | |
| 4622 | - // read at most two `drl_mode` bits, one per stack entry past the | |
| 4623 | - // first, stopping at the first `0`. The chosen index selects | |
| 4624 | - // which stack entry `read_mv`'s base predictor comes from | |
| 4625 | - // (spec 7.10.2.10 `assign_mv`'s `PredMv = RefStackMv[RefMvIdx]`) | |
| 4626 | - // -- entry 0 (`stack.pred_mv`) only when the loop never advances. | |
| 4627 | - let mut idx = 0usize; | |
| 4628 | - while idx < 2 && stack.entries.len() > idx + 1 { | |
| 4629 | - if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | |
| 4630 | - break; | |
| 4631 | - } | |
| 4632 | - idx += 1; | |
| 4633 | - } | |
| 4634 | - let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); | |
| 4635 | - ( | |
| 4636 | - read_mv( | |
| 4637 | - dec, | |
| 4638 | - &mut cdfs.mv_comp, | |
| 4639 | - &mut cdfs.mv_joint, | |
| 4640 | - base_mv, | |
| 4641 | - allow_high_precision_mv, | |
| 4612 | + let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); | |
| 4613 | + let bw4 = side / 4; | |
| 4614 | + // spec 7.10.2.8: only reached when the frame header set | |
| 4615 | + // `use_ref_frame_mvs` (`tpl_frame` is `Some` then, `None` | |
| 4616 | + // otherwise) -- `cur_offset_0` is this query block's own resolved | |
| 4617 | + // `ref_frame`'s distance from the current frame (spec 7.9.3), | |
| 4618 | + // recomputed per block since different blocks pick different refs. | |
| 4619 | + let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { | |
| 4620 | + field: t.field, | |
| 4621 | + cur_offset_0: crate::motion_field::get_relative_dist( | |
| 4622 | + t.order_hint_bits, | |
| 4623 | + t.order_hint, | |
| 4624 | + t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], | |
| 4642 | 4625 | ), |
| 4643 | - true, | |
| 4644 | - ) | |
| 4645 | - } else { | |
| 4646 | - let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; | |
| 4647 | - is_globalmv = !not_zero; | |
| 4648 | - let mv = if !not_zero { | |
| 4649 | - // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1) under the | |
| 4650 | - // `GmType::IDENTITY` this crate's `decode_stream` requires of | |
| 4651 | - // every inter frame's `LAST_FRAME` entry (any other warp | |
| 4652 | - // model is refused before the tile decoder is ever called). | |
| 4653 | - (0, 0) | |
| 4626 | + allow_high_precision_mv, | |
| 4627 | + }); | |
| 4628 | + let stack = find_mv_stack_with_sign_bias( | |
| 4629 | + grid, | |
| 4630 | + mi_row, | |
| 4631 | + mi_col, | |
| 4632 | + bw4, | |
| 4633 | + bw4, | |
| 4634 | + ref_frame, | |
| 4635 | + mi_cols as usize, | |
| 4636 | + mi_rows as usize, | |
| 4637 | + sign_bias_table, | |
| 4638 | + tpl, | |
| 4639 | + ); | |
| 4640 | + let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; | |
| 4641 | + let mut is_globalmv = false; | |
| 4642 | + let (mv, is_new_mv) = if !not_new { | |
| 4643 | + // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): | |
| 4644 | + // read at most two `drl_mode` bits, one per stack entry past the | |
| 4645 | + // first, stopping at the first `0`. The chosen index selects | |
| 4646 | + // which stack entry `read_mv`'s base predictor comes from | |
| 4647 | + // (spec 7.10.2.10 `assign_mv`'s `PredMv = RefStackMv[RefMvIdx]`) | |
| 4648 | + // -- entry 0 (`stack.pred_mv`) only when the loop never advances. | |
| 4649 | + let mut idx = 0usize; | |
| 4650 | + while idx < 2 && stack.entries.len() > idx + 1 { | |
| 4651 | + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | |
| 4652 | + break; | |
| 4653 | + } | |
| 4654 | + idx += 1; | |
| 4655 | + } | |
| 4656 | + let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); | |
| 4657 | + ( | |
| 4658 | + read_mv( | |
| 4659 | + dec, | |
| 4660 | + &mut cdfs.mv_comp, | |
| 4661 | + &mut cdfs.mv_joint, | |
| 4662 | + base_mv, | |
| 4663 | + allow_high_precision_mv, | |
| 4664 | + ), | |
| 4665 | + true, | |
| 4666 | + ) | |
| 4654 | 4667 | } else { |
| 4655 | - let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; | |
| 4656 | - if nearest { | |
| 4657 | - stack.nearest_mv | |
| 4668 | + let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; | |
| 4669 | + is_globalmv = !not_zero; | |
| 4670 | + let mv = if !not_zero { | |
| 4671 | + // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1) under the | |
| 4672 | + // `GmType::IDENTITY` this crate's `decode_stream` requires of | |
| 4673 | + // every inter frame's `LAST_FRAME` entry (any other warp | |
| 4674 | + // model is refused before the tile decoder is ever called). | |
| 4675 | + (0, 0) | |
| 4658 | 4676 | } else { |
| 4659 | - // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting | |
| 4660 | - // at 1): read at most two more `drl_mode` bits, one per stack | |
| 4661 | - // entry past the second, stopping at the first `0`. | |
| 4662 | - // `drl_ctx[idx]` is the context between `entries[idx]` and | |
| 4663 | - // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is | |
| 4664 | - // exactly the pair this index is choosing between. | |
| 4665 | - let mut idx = 1usize; | |
| 4666 | - while idx < 3 && stack.entries.len() > idx + 1 { | |
| 4667 | - if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | |
| 4668 | - break; | |
| 4677 | + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; | |
| 4678 | + if nearest { | |
| 4679 | + stack.nearest_mv | |
| 4680 | + } else { | |
| 4681 | + // NEARMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting | |
| 4682 | + // at 1): read at most two more `drl_mode` bits, one per stack | |
| 4683 | + // entry past the second, stopping at the first `0`. | |
| 4684 | + // `drl_ctx[idx]` is the context between `entries[idx]` and | |
| 4685 | + // `entries[idx + 1]` (`MvStack::drl_ctx`'s own doc), which is | |
| 4686 | + // exactly the pair this index is choosing between. | |
| 4687 | + let mut idx = 1usize; | |
| 4688 | + while idx < 3 && stack.entries.len() > idx + 1 { | |
| 4689 | + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { | |
| 4690 | + break; | |
| 4691 | + } | |
| 4692 | + idx += 1; | |
| 4669 | 4693 | } |
| 4670 | - idx += 1; | |
| 4694 | + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) | |
| 4671 | 4695 | } |
| 4672 | - stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) | |
| 4673 | - } | |
| 4696 | + }; | |
| 4697 | + (mv, false) | |
| 4674 | 4698 | }; |
| 4675 | - (mv, false) | |
| 4676 | - }; | |
| 4677 | - // spec `get_ref_filter_type`: a neighbour's own filter only feeds | |
| 4678 | - // this block's switchable_interp context when that neighbour coded | |
| 4679 | - // the SAME reference frame this block is about to read -- a | |
| 4680 | - // different-ref neighbour reads as "no neighbour" ([3, 3], the | |
| 4681 | - // sentinel `Neighbours::new` already seeds unset slots with), | |
| 4682 | - // exactly like an intra neighbour. Without this gate, a GOLDEN_FRAME | |
| 4683 | - // block next to a LAST_FRAME one inherits that neighbour's filter | |
| 4684 | - // choice into its own context, corrupting the symbol it reads. | |
| 4685 | - let above_filter_ctx = if neighbours.above_ref[c] == ref_frame { | |
| 4686 | - neighbours.above_filter[c] | |
| 4687 | - } else { | |
| 4688 | - [3, 3] | |
| 4689 | - }; | |
| 4690 | - let left_filter_ctx = if neighbours.left_ref[r] == ref_frame { | |
| 4691 | - neighbours.left_filter[r] | |
| 4692 | - } else { | |
| 4693 | - [3, 3] | |
| 4694 | - }; | |
| 4695 | - let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | |
| 4696 | - dec, | |
| 4697 | - cdfs, | |
| 4698 | - interp_fixed, | |
| 4699 | - enable_dual_filter, | |
| 4700 | - is_globalmv, | |
| 4701 | - above_filter_ctx, | |
| 4702 | - left_filter_ctx, | |
| 4703 | - ); | |
| 4704 | - block_filter = resolved_filter; | |
| 4705 | - globalmv_for_lf = is_globalmv; | |
| 4706 | - if std::env::var_os("EC_AV1_TRACE").is_some() { | |
| 4707 | - eprintln!( | |
| 4708 | - "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?}", | |
| 4709 | - skip as u8, mv.0, mv.1, block_filter | |
| 4699 | + // spec `get_ref_filter_type`: a neighbour's own filter only feeds | |
| 4700 | + // this block's switchable_interp context when that neighbour coded | |
| 4701 | + // the SAME reference frame this block is about to read -- a | |
| 4702 | + // different-ref neighbour reads as "no neighbour" ([3, 3], the | |
| 4703 | + // sentinel `Neighbours::new` already seeds unset slots with), | |
| 4704 | + // exactly like an intra neighbour. Without this gate, a GOLDEN_FRAME | |
| 4705 | + // block next to a LAST_FRAME one inherits that neighbour's filter | |
| 4706 | + // choice into its own context, corrupting the symbol it reads. | |
| 4707 | + let above_filter_ctx = if neighbours.above_ref[c] == ref_frame { | |
| 4708 | + neighbours.above_filter[c] | |
| 4709 | + } else { | |
| 4710 | + [3, 3] | |
| 4711 | + }; | |
| 4712 | + let left_filter_ctx = if neighbours.left_ref[r] == ref_frame { | |
| 4713 | + neighbours.left_filter[r] | |
| 4714 | + } else { | |
| 4715 | + [3, 3] | |
| 4716 | + }; | |
| 4717 | + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | |
| 4718 | + dec, | |
| 4719 | + cdfs, | |
| 4720 | + interp_fixed, | |
| 4721 | + enable_dual_filter, | |
| 4722 | + is_globalmv, | |
| 4723 | + above_filter_ctx, | |
| 4724 | + left_filter_ctx, | |
| 4710 | 4725 | ); |
| 4711 | - } | |
| 4712 | - for dr in 0..bw4 { | |
| 4713 | - for dc in 0..bw4 { | |
| 4714 | - grid.set( | |
| 4715 | - mi_row + dr, | |
| 4716 | - mi_col + dc, | |
| 4717 | - MiInfo { | |
| 4718 | - is_inter: true, | |
| 4719 | - ref_frame, | |
| 4720 | - ref_frame1: None, | |
| 4721 | - mv1: None, | |
| 4722 | - mv, | |
| 4723 | - is_new_mv, | |
| 4724 | - size: bw4, | |
| 4725 | - }, | |
| 4726 | + block_filter = resolved_filter; | |
| 4727 | + globalmv_for_lf = is_globalmv; | |
| 4728 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | |
| 4729 | + eprintln!( | |
| 4730 | + "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?}", | |
| 4731 | + skip as u8, mv.0, mv.1, block_filter | |
| 4726 | 4732 | ); |
| 4727 | 4733 | } |
| 4728 | - } | |
| 4729 | - mode_for_tx = 0; | |
| 4730 | - | |
| 4731 | - let mut pred_y = vec![0u8; side * side]; | |
| 4732 | - mc::predict_with_filters( | |
| 4733 | - &py_ref.data, | |
| 4734 | - py_ref.width, | |
| 4735 | - py_ref.true_width, | |
| 4736 | - py_ref.true_height, | |
| 4737 | - mv_to_q4(px, mv.1, true), | |
| 4738 | - mv_to_q4(py, mv.0, true), | |
| 4739 | - side, | |
| 4740 | - side, | |
| 4741 | - h_filter, | |
| 4742 | - v_filter, | |
| 4743 | - &mut pred_y, | |
| 4744 | - ); | |
| 4745 | - let mut pred_u = vec![0u8; chroma_side * chroma_side]; | |
| 4746 | - mc::predict_with_filters( | |
| 4747 | - &pu_ref.data, | |
| 4748 | - pu_ref.width, | |
| 4749 | - pu_ref.true_width, | |
| 4750 | - pu_ref.true_height, | |
| 4751 | - mv_to_q4(cpx, mv.1, false), | |
| 4752 | - mv_to_q4(cpy, mv.0, false), | |
| 4753 | - chroma_side, | |
| 4754 | - chroma_side, | |
| 4755 | - h_filter, | |
| 4756 | - v_filter, | |
| 4757 | - &mut pred_u, | |
| 4758 | - ); | |
| 4759 | - let mut pred_v = vec![0u8; chroma_side * chroma_side]; | |
| 4760 | - mc::predict_with_filters( | |
| 4761 | - &pv_ref.data, | |
| 4762 | - pv_ref.width, | |
| 4763 | - pv_ref.true_width, | |
| 4764 | - pv_ref.true_height, | |
| 4765 | - mv_to_q4(cpx, mv.1, false), | |
| 4766 | - mv_to_q4(cpy, mv.0, false), | |
| 4767 | - chroma_side, | |
| 4768 | - chroma_side, | |
| 4769 | - h_filter, | |
| 4770 | - v_filter, | |
| 4771 | - &mut pred_v, | |
| 4772 | - ); | |
| 4734 | + for dr in 0..bw4 { | |
| 4735 | + for dc in 0..bw4 { | |
| 4736 | + grid.set( | |
| 4737 | + mi_row + dr, | |
| 4738 | + mi_col + dc, | |
| 4739 | + MiInfo { | |
| 4740 | + is_inter: true, | |
| 4741 | + ref_frame, | |
| 4742 | + ref_frame1: None, | |
| 4743 | + mv1: None, | |
| 4744 | + mv, | |
| 4745 | + is_new_mv, | |
| 4746 | + size: bw4, | |
| 4747 | + }, | |
| 4748 | + ); | |
| 4749 | + } | |
| 4750 | + } | |
| 4751 | + mode_for_tx = 0; | |
| 4773 | 4752 | |
| 4774 | - if skip { | |
| 4775 | - y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); | |
| 4776 | - u.reconstruct_mc( | |
| 4777 | - cpx, | |
| 4778 | - cpy, | |
| 4779 | - chroma_side, | |
| 4780 | - &pred_u, | |
| 4781 | - &vec![0i32; chroma_side * chroma_side], | |
| 4753 | + let mut pred_y = vec![0u8; side * side]; | |
| 4754 | + mc::predict_with_filters( | |
| 4755 | + &py_ref.data, | |
| 4756 | + py_ref.width, | |
| 4757 | + py_ref.true_width, | |
| 4758 | + py_ref.true_height, | |
| 4759 | + mv_to_q4(px, mv.1, true), | |
| 4760 | + mv_to_q4(py, mv.0, true), | |
| 4761 | + side, | |
| 4762 | + side, | |
| 4763 | + h_filter, | |
| 4764 | + v_filter, | |
| 4765 | + &mut pred_y, | |
| 4782 | 4766 | ); |
| 4783 | - v.reconstruct_mc( | |
| 4784 | - cpx, | |
| 4785 | - cpy, | |
| 4767 | + let mut pred_u = vec![0u8; chroma_side * chroma_side]; | |
| 4768 | + mc::predict_with_filters( | |
| 4769 | + &pu_ref.data, | |
| 4770 | + pu_ref.width, | |
| 4771 | + pu_ref.true_width, | |
| 4772 | + pu_ref.true_height, | |
| 4773 | + mv_to_q4(cpx, mv.1, false), | |
| 4774 | + mv_to_q4(cpy, mv.0, false), | |
| 4786 | 4775 | chroma_side, |
| 4787 | - &pred_v, | |
| 4788 | - &vec![0i32; chroma_side * chroma_side], | |
| 4776 | + chroma_side, | |
| 4777 | + h_filter, | |
| 4778 | + v_filter, | |
| 4779 | + &mut pred_u, | |
| 4789 | 4780 | ); |
| 4790 | - luma_grid = vec![0i32; side * side]; | |
| 4791 | - u_grid = vec![0i32; chroma_side * chroma_side]; | |
| 4792 | - v_grid = vec![0i32; chroma_side * chroma_side]; | |
| 4793 | - } else { | |
| 4794 | - let around = neighbours.around(at, side); | |
| 4795 | - luma_grid = read_inter_plane( | |
| 4796 | - dec, | |
| 4797 | - cdfs, | |
| 4798 | - luma_set_inter, | |
| 4799 | - scan_luma, | |
| 4800 | - 0, | |
| 4801 | - around[0], | |
| 4802 | - mode_for_tx, | |
| 4803 | - y, | |
| 4804 | - px, | |
| 4805 | - py, | |
| 4806 | - side, | |
| 4807 | - base_q_idx, | |
| 4808 | - &pred_y, | |
| 4809 | - )?; | |
| 4810 | - u_grid = read_inter_plane( | |
| 4811 | - dec, | |
| 4812 | - cdfs, | |
| 4813 | - chroma_set, | |
| 4814 | - scan_chroma, | |
| 4815 | - 1, | |
| 4816 | - around[1], | |
| 4817 | - mode_for_tx, | |
| 4818 | - u, | |
| 4819 | - cpx, | |
| 4820 | - cpy, | |
| 4781 | + let mut pred_v = vec![0u8; chroma_side * chroma_side]; | |
| 4782 | + mc::predict_with_filters( | |
| 4783 | + &pv_ref.data, | |
| 4784 | + pv_ref.width, | |
| 4785 | + pv_ref.true_width, | |
| 4786 | + pv_ref.true_height, | |
| 4787 | + mv_to_q4(cpx, mv.1, false), | |
| 4788 | + mv_to_q4(cpy, mv.0, false), | |
| 4821 | 4789 | chroma_side, |
| 4822 | - base_q_idx, | |
| 4823 | - &pred_u, | |
| 4824 | - )?; | |
| 4825 | - v_grid = read_inter_plane( | |
| 4826 | - dec, | |
| 4827 | - cdfs, | |
| 4828 | - chroma_set, | |
| 4829 | - scan_chroma, | |
| 4830 | - 2, | |
| 4831 | - around[2], | |
| 4832 | - mode_for_tx, | |
| 4833 | - v, | |
| 4834 | - cpx, | |
| 4835 | - cpy, | |
| 4836 | 4790 | chroma_side, |
| 4837 | - base_q_idx, | |
| 4838 | - &pred_v, | |
| 4839 | - )?; | |
| 4840 | - } | |
| 4791 | + h_filter, | |
| 4792 | + v_filter, | |
| 4793 | + &mut pred_v, | |
| 4794 | + ); | |
| 4795 | + | |
| 4796 | + if skip { | |
| 4797 | + y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); | |
| 4798 | + u.reconstruct_mc( | |
| 4799 | + cpx, | |
| 4800 | + cpy, | |
| 4801 | + chroma_side, | |
| 4802 | + &pred_u, | |
| 4803 | + &vec![0i32; chroma_side * chroma_side], | |
| 4804 | + ); | |
| 4805 | + v.reconstruct_mc( | |
| 4806 | + cpx, | |
| 4807 | + cpy, | |
| 4808 | + chroma_side, | |
| 4809 | + &pred_v, | |
| 4810 | + &vec![0i32; chroma_side * chroma_side], | |
| 4811 | + ); | |
| 4812 | + luma_grid = vec![0i32; side * side]; | |
| 4813 | + u_grid = vec![0i32; chroma_side * chroma_side]; | |
| 4814 | + v_grid = vec![0i32; chroma_side * chroma_side]; | |
| 4815 | + } else { | |
| 4816 | + let around = neighbours.around(at, side); | |
| 4817 | + luma_grid = read_inter_plane( | |
| 4818 | + dec, | |
| 4819 | + cdfs, | |
| 4820 | + luma_set_inter, | |
| 4821 | + scan_luma, | |
| 4822 | + 0, | |
| 4823 | + around[0], | |
| 4824 | + mode_for_tx, | |
| 4825 | + y, | |
| 4826 | + px, | |
| 4827 | + py, | |
| 4828 | + side, | |
| 4829 | + base_q_idx, | |
| 4830 | + &pred_y, | |
| 4831 | + )?; | |
| 4832 | + u_grid = read_inter_plane( | |
| 4833 | + dec, | |
| 4834 | + cdfs, | |
| 4835 | + chroma_set, | |
| 4836 | + scan_chroma, | |
| 4837 | + 1, | |
| 4838 | + around[1], | |
| 4839 | + mode_for_tx, | |
| 4840 | + u, | |
| 4841 | + cpx, | |
| 4842 | + cpy, | |
| 4843 | + chroma_side, | |
| 4844 | + base_q_idx, | |
| 4845 | + &pred_u, | |
| 4846 | + )?; | |
| 4847 | + v_grid = read_inter_plane( | |
| 4848 | + dec, | |
| 4849 | + cdfs, | |
| 4850 | + chroma_set, | |
| 4851 | + scan_chroma, | |
| 4852 | + 2, | |
| 4853 | + around[2], | |
| 4854 | + mode_for_tx, | |
| 4855 | + v, | |
| 4856 | + cpx, | |
| 4857 | + cpy, | |
| 4858 | + chroma_side, | |
| 4859 | + base_q_idx, | |
| 4860 | + &pred_v, | |
| 4861 | + )?; | |
| 4862 | + } | |
| 4841 | 4863 | } |
| 4842 | 4864 | } else { |
| 4843 | 4865 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); |
| @@ -4994,8 +5016,8 @@ fn decode_inter_block( | ||
| 4994 | 5016 | } |
| 4995 | 5017 | neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); |
| 4996 | 5018 | neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter); |
| 4997 | - if let Some((group_idx, idx)) = compound_ctx { | |
| 4998 | - neighbours.record_compound_ctx(at, side, group_idx, idx); | |
| 5019 | + if let Some((ref1, group_idx, idx)) = compound_ctx { | |
| 5020 | + neighbours.record_compound_ctx(at, side, ref1, group_idx, idx); | |
| 4999 | 5021 | } |
| 5000 | 5022 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 5001 | 5023 | neighbours.fill_lf_grid( |
| @@ -5043,6 +5065,7 @@ fn decode_inter_block8( | ||
| 5043 | 5065 | ref_y: &PlaneBuf, |
| 5044 | 5066 | ref_u: &PlaneBuf, |
| 5045 | 5067 | ref_v: &PlaneBuf, |
| 5068 | + other_refs: &RefSlots, | |
| 5046 | 5069 | base_q_idx: u8, |
| 5047 | 5070 | scan8: &[u16], |
| 5048 | 5071 | scan4: &[u16], |
| @@ -5053,7 +5076,18 @@ fn decode_inter_block8( | ||
| 5053 | 5076 | // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s |
| 5054 | 5077 | // context uses that same approximation. |
| 5055 | 5078 | reference_select: bool, |
| 5056 | -) -> Result<(bool, bool)> { | |
| 5079 | + enable_masked_compound: bool, | |
| 5080 | + enable_jnt_comp: bool, | |
| 5081 | + order_hint_bits: u32, | |
| 5082 | + order_hint: u32, | |
| 5083 | + ref_order_hints: [u32; 7], | |
| 5084 | + // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a | |
| 5085 | + // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 | |
| 5086 | + // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own | |
| 5087 | + // `compound_ctx` local, just handed back instead of applied here (this | |
| 5088 | + // fn's `neighbours` recording happens once for the whole straddling | |
| 5089 | + // 16x16 block, after every leaf). | |
| 5090 | +) -> Result<(bool, bool, Option<(i8, i8, u8, u8)>)> { | |
| 5057 | 5091 | const LAST_FRAME: i8 = 1; |
| 5058 | 5092 | /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). |
| 5059 | 5093 | const SIZE_GROUP_8: usize = 1; |
| @@ -5086,6 +5120,7 @@ fn decode_inter_block8( | ||
| 5086 | 5120 | |
| 5087 | 5121 | let mode_for_tx; |
| 5088 | 5122 | let (luma_grid, u_grid, v_grid); |
| 5123 | + let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; | |
| 5089 | 5124 | if is_inter { |
| 5090 | 5125 | if reference_select { |
| 5091 | 5126 | let above_nbr = has_above.then(|| NeighbourRef { |
| @@ -5142,18 +5177,247 @@ fn decode_inter_block8( | ||
| 5142 | 5177 | comp_stack.new_mv_ctx, |
| 5143 | 5178 | comp_stack.ref_mv_ctx, |
| 5144 | 5179 | ); |
| 5145 | - let _mv_pair = assign_compound_mv( | |
| 5180 | + let (mv0, mv1) = assign_compound_mv( | |
| 5146 | 5181 | dec, |
| 5147 | 5182 | cdfs, |
| 5148 | 5183 | &comp_stack, |
| 5149 | 5184 | compound_mode, |
| 5150 | 5185 | allow_high_precision_mv, |
| 5151 | 5186 | ); |
| 5152 | - return Err(unsupported( | |
| 5153 | - "a COMPOUND_REFERENCE 8x8 leaf (comp_mode/comp_ref/inter_compound_mode/\ | |
| 5154 | - compound DRL/MV assignment read correctly; two-reference motion \ | |
| 5155 | - compensation is not wired yet -- lane-av1comp)", | |
| 5156 | - )); | |
| 5187 | + | |
| 5188 | + // spec 5.11.25: same gating [`decode_inter_block`]'s own | |
| 5189 | + // compound arm uses, keyed off `outer_at`'s [`SUB`]-grid | |
| 5190 | + // slot -- the only granularity `Neighbours`' comp_group_idx/ | |
| 5191 | + // compound_idx arrays track. | |
| 5192 | + let group_ctx = get_comp_group_idx_context(neighbours, outer_at, SIDE); | |
| 5193 | + let comp_group_idx = | |
| 5194 | + if enable_masked_compound && is_any_masked_compound_used_here(SIDE) { | |
| 5195 | + dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) | |
| 5196 | + } else { | |
| 5197 | + 0 | |
| 5198 | + }; | |
| 5199 | + if comp_group_idx == 1 { | |
| 5200 | + return Err(unsupported( | |
| 5201 | + "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\ | |
| 5202 | + diffwtd) -- this decoder's compound blend is the plain distance-\ | |
| 5203 | + weighted/simple-average combine only, lane-av1comp", | |
| 5204 | + )); | |
| 5205 | + } | |
| 5206 | + let (fwd_offset, bck_offset, compound_idx) = if enable_jnt_comp { | |
| 5207 | + let idx_ctx = get_comp_index_context( | |
| 5208 | + neighbours, | |
| 5209 | + outer_at, | |
| 5210 | + SIDE, | |
| 5211 | + order_hint_bits, | |
| 5212 | + order_hint, | |
| 5213 | + ref_order_hints[(ref0 - LAST_FRAME) as usize], | |
| 5214 | + ref_order_hints[(ref1 - LAST_FRAME) as usize], | |
| 5215 | + ); | |
| 5216 | + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); | |
| 5217 | + if idx == 1 { | |
| 5218 | + (8, 8, 1u8) | |
| 5219 | + } else { | |
| 5220 | + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( | |
| 5221 | + order_hint_bits, | |
| 5222 | + order_hint, | |
| 5223 | + ref_order_hints[(ref0 - LAST_FRAME) as usize], | |
| 5224 | + ref_order_hints[(ref1 - LAST_FRAME) as usize], | |
| 5225 | + ); | |
| 5226 | + (fwd, bck, 0u8) | |
| 5227 | + } | |
| 5228 | + } else { | |
| 5229 | + (8, 8, 1u8) | |
| 5230 | + }; | |
| 5231 | + compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx)); | |
| 5232 | + | |
| 5233 | + let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; | |
| 5234 | + let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; | |
| 5235 | + | |
| 5236 | + for dr in 0..2 { | |
| 5237 | + for dc in 0..2 { | |
| 5238 | + grid.set( | |
| 5239 | + mi_row + dr, | |
| 5240 | + mi_col + dc, | |
| 5241 | + MiInfo { | |
| 5242 | + is_inter: true, | |
| 5243 | + ref_frame: ref0, | |
| 5244 | + ref_frame1: Some(ref1), | |
| 5245 | + mv1: Some(mv1), | |
| 5246 | + mv: mv0, | |
| 5247 | + is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7), | |
| 5248 | + size: 2, | |
| 5249 | + }, | |
| 5250 | + ); | |
| 5251 | + } | |
| 5252 | + } | |
| 5253 | + mode_for_tx = 0; | |
| 5254 | + | |
| 5255 | + // lane-av1comp corner-cut, matching this leaf's single-ref | |
| 5256 | + // arm below (`mc::predict`'s own fixed-Regular default): | |
| 5257 | + // `decode_inter_block8` never resolves a switchable filter, | |
| 5258 | + // so both compound taps use `Regular` too. | |
| 5259 | + use mc::InterpFilterKind::Regular; | |
| 5260 | + let mut inter0_y = vec![0i32; SIDE * SIDE]; | |
| 5261 | + mc::predict_compound_intermediate( | |
| 5262 | + &py0.data, | |
| 5263 | + py0.width, | |
| 5264 | + py0.true_width, | |
| 5265 | + py0.true_height, | |
| 5266 | + mv_to_q4(px, mv0.1, true), | |
| 5267 | + mv_to_q4(py, mv0.0, true), | |
| 5268 | + SIDE, | |
| 5269 | + SIDE, | |
| 5270 | + Regular, | |
| 5271 | + Regular, | |
| 5272 | + &mut inter0_y, | |
| 5273 | + ); | |
| 5274 | + let mut inter1_y = vec![0i32; SIDE * SIDE]; | |
| 5275 | + mc::predict_compound_intermediate( | |
| 5276 | + &py1.data, | |
| 5277 | + py1.width, | |
| 5278 | + py1.true_width, | |
| 5279 | + py1.true_height, | |
| 5280 | + mv_to_q4(px, mv1.1, true), | |
| 5281 | + mv_to_q4(py, mv1.0, true), | |
| 5282 | + SIDE, | |
| 5283 | + SIDE, | |
| 5284 | + Regular, | |
| 5285 | + Regular, | |
| 5286 | + &mut inter1_y, | |
| 5287 | + ); | |
| 5288 | + let mut pred_y = vec![0u8; SIDE * SIDE]; | |
| 5289 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | |
| 5290 | + | |
| 5291 | + let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5292 | + mc::predict_compound_intermediate( | |
| 5293 | + &pu0.data, | |
| 5294 | + pu0.width, | |
| 5295 | + pu0.true_width, | |
| 5296 | + pu0.true_height, | |
| 5297 | + mv_to_q4(cpx, mv0.1, false), | |
| 5298 | + mv_to_q4(cpy, mv0.0, false), | |
| 5299 | + CHROMA_SIDE, | |
| 5300 | + CHROMA_SIDE, | |
| 5301 | + Regular, | |
| 5302 | + Regular, | |
| 5303 | + &mut inter0_u, | |
| 5304 | + ); | |
| 5305 | + let mut inter1_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5306 | + mc::predict_compound_intermediate( | |
| 5307 | + &pu1.data, | |
| 5308 | + pu1.width, | |
| 5309 | + pu1.true_width, | |
| 5310 | + pu1.true_height, | |
| 5311 | + mv_to_q4(cpx, mv1.1, false), | |
| 5312 | + mv_to_q4(cpy, mv1.0, false), | |
| 5313 | + CHROMA_SIDE, | |
| 5314 | + CHROMA_SIDE, | |
| 5315 | + Regular, | |
| 5316 | + Regular, | |
| 5317 | + &mut inter1_u, | |
| 5318 | + ); | |
| 5319 | + let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5320 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | |
| 5321 | + | |
| 5322 | + let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5323 | + mc::predict_compound_intermediate( | |
| 5324 | + &pv0.data, | |
| 5325 | + pv0.width, | |
| 5326 | + pv0.true_width, | |
| 5327 | + pv0.true_height, | |
| 5328 | + mv_to_q4(cpx, mv0.1, false), | |
| 5329 | + mv_to_q4(cpy, mv0.0, false), | |
| 5330 | + CHROMA_SIDE, | |
| 5331 | + CHROMA_SIDE, | |
| 5332 | + Regular, | |
| 5333 | + Regular, | |
| 5334 | + &mut inter0_v, | |
| 5335 | + ); | |
| 5336 | + let mut inter1_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5337 | + mc::predict_compound_intermediate( | |
| 5338 | + &pv1.data, | |
| 5339 | + pv1.width, | |
| 5340 | + pv1.true_width, | |
| 5341 | + pv1.true_height, | |
| 5342 | + mv_to_q4(cpx, mv1.1, false), | |
| 5343 | + mv_to_q4(cpy, mv1.0, false), | |
| 5344 | + CHROMA_SIDE, | |
| 5345 | + CHROMA_SIDE, | |
| 5346 | + Regular, | |
| 5347 | + Regular, | |
| 5348 | + &mut inter1_v, | |
| 5349 | + ); | |
| 5350 | + let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5351 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | |
| 5352 | + | |
| 5353 | + if skip { | |
| 5354 | + y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); | |
| 5355 | + u.reconstruct_mc( | |
| 5356 | + cpx, | |
| 5357 | + cpy, | |
| 5358 | + CHROMA_SIDE, | |
| 5359 | + &pred_u, | |
| 5360 | + &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], | |
| 5361 | + ); | |
| 5362 | + v.reconstruct_mc( | |
| 5363 | + cpx, | |
| 5364 | + cpy, | |
| 5365 | + CHROMA_SIDE, | |
| 5366 | + &pred_v, | |
| 5367 | + &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], | |
| 5368 | + ); | |
| 5369 | + luma_grid = vec![0i32; SIDE * SIDE]; | |
| 5370 | + u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5371 | + v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | |
| 5372 | + } else { | |
| 5373 | + let around = neighbours.around_mi(leaf_mi, 8); | |
| 5374 | + luma_grid = read_inter_plane( | |
| 5375 | + dec, | |
| 5376 | + cdfs, | |
| 5377 | + TxbSet::Luma8Inter, | |
| 5378 | + scan8, | |
| 5379 | + 0, | |
| 5380 | + around[0], | |
| 5381 | + mode_for_tx, | |
| 5382 | + y, | |
| 5383 | + px, | |
| 5384 | + py, | |
| 5385 | + SIDE, | |
| 5386 | + base_q_idx, | |
| 5387 | + &pred_y, | |
| 5388 | + )?; | |
| 5389 | + u_grid = read_inter_plane( | |
| 5390 | + dec, | |
| 5391 | + cdfs, | |
| 5392 | + TxbSet::Chroma4, | |
| 5393 | + scan4, | |
| 5394 | + 1, | |
| 5395 | + around[1], | |
| 5396 | + mode_for_tx, | |
| 5397 | + u, | |
| 5398 | + cpx, | |
| 5399 | + cpy, | |
| 5400 | + CHROMA_SIDE, | |
| 5401 | + base_q_idx, | |
| 5402 | + &pred_u, | |
| 5403 | + )?; | |
| 5404 | + v_grid = read_inter_plane( | |
| 5405 | + dec, | |
| 5406 | + cdfs, | |
| 5407 | + TxbSet::Chroma4, | |
| 5408 | + scan4, | |
| 5409 | + 2, | |
| 5410 | + around[2], | |
| 5411 | + mode_for_tx, | |
| 5412 | + v, | |
| 5413 | + cpx, | |
| 5414 | + cpy, | |
| 5415 | + CHROMA_SIDE, | |
| 5416 | + base_q_idx, | |
| 5417 | + &pred_v, | |
| 5418 | + )?; | |
| 5419 | + } | |
| 5420 | + return Ok((skip, is_inter, compound_ctx8)); | |
| 5157 | 5421 | } |
| 5158 | 5422 | } |
| 5159 | 5423 | let sr_ctx = single_ref_ctx(above_inter || left_inter); |
| @@ -5495,7 +5759,7 @@ fn decode_inter_block8( | ||
| 5495 | 5759 | } |
| 5496 | 5760 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 5497 | 5761 | neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 }); |
| 5498 | - Ok((skip, is_inter)) | |
| 5762 | + Ok((skip, is_inter, compound_ctx8)) | |
| 5499 | 5763 | } |
| 5500 | 5764 | |
| 5501 | 5765 | /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, |
| @@ -5876,6 +6140,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 5876 | 6140 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 5877 | 6141 | .collect(); |
| 5878 | 6142 | let mut prev_leaf: Option<((usize, usize), bool, bool)> = None; |
| 6143 | + let mut last_compound_ctx: Option<(i8, i8, u8, u8)> = None; | |
| 5879 | 6144 | for (mr, mc) in leaf_positions { |
| 5880 | 6145 | let leaf_mi = (mr as usize, mc as usize); |
| 5881 | 6146 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); |
| @@ -5885,7 +6150,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 5885 | 6150 | "a partition below 8x8 (this encoder never writes one)", |
| 5886 | 6151 | )); |
| 5887 | 6152 | } |
| 5888 | - let (skip, is_inter) = decode_inter_block8( | |
| 6153 | + let (skip, is_inter, compound_ctx8) = decode_inter_block8( | |
| 5889 | 6154 | &mut dec, |
| 5890 | 6155 | &mut cdfs, |
| 5891 | 6156 | &mut neighbours, |
| @@ -5900,14 +6165,23 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 5900 | 6165 | &ref_y, |
| 5901 | 6166 | &ref_u, |
| 5902 | 6167 | &ref_v, |
| 6168 | + &ref_slots, | |
| 5903 | 6169 | base_q_idx, |
| 5904 | 6170 | &scan8, |
| 5905 | 6171 | &scan4, |
| 5906 | 6172 | prev_leaf, |
| 5907 | 6173 | allow_high_precision_mv, |
| 5908 | 6174 | reference_select, |
| 6175 | + enable_masked_compound, | |
| 6176 | + enable_jnt_comp, | |
| 6177 | + order_hint_bits, | |
| 6178 | + order_hint, | |
| 6179 | + ref_order_hints, | |
| 5909 | 6180 | )?; |
| 5910 | 6181 | prev_leaf = Some((leaf_mi, skip, is_inter)); |
| 6182 | + if compound_ctx8.is_some() { | |
| 6183 | + last_compound_ctx = compound_ctx8; | |
| 6184 | + } | |
| 5911 | 6185 | } |
| 5912 | 6186 | if let Some((_, skip, is_inter)) = prev_leaf { |
| 5913 | 6187 | // corner-cut: `decode_inter_block8`'s |
| @@ -5929,6 +6203,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 5929 | 6203 | if is_inter { LAST_FRAME } else { -1 }, |
| 5930 | 6204 | [3, 3], |
| 5931 | 6205 | ); |
| 6206 | + if let Some((ref0, ref1, group_idx, idx)) = last_compound_ctx { | |
| 6207 | + neighbours.record_inter( | |
| 6208 | + at16, | |
| 6209 | + SUB, | |
| 6210 | + skip, | |
| 6211 | + is_inter, | |
| 6212 | + ref0, | |
| 6213 | + [3, 3], | |
| 6214 | + ); | |
| 6215 | + neighbours | |
| 6216 | + .record_compound_ctx(at16, SUB, ref1, group_idx, idx); | |
| 6217 | + } | |
| 5932 | 6218 | } |
| 5933 | 6219 | } |
| 5934 | 6220 | } |
| @@ -6000,6 +6286,39 @@ mod tests { | ||
| 6000 | 6286 | // this decoder's one target, and the round-trip test below is against |
| 6001 | 6287 | // that path with real quantised residual, not a synthetic all-DC frame. |
| 6002 | 6288 | |
| 6289 | + /// `is_uni_comp_ref` (lane-av1comp): a pair is unidirectional exactly | |
| 6290 | + /// when both references sit on the same temporal side -- the three | |
| 6291 | + /// `uni_comp_ref` bitstream pairs (LAST/LAST2, LAST/LAST3, LAST/GOLDEN) | |
| 6292 | + /// all read `true`, a forward/backward mix (LAST/BWDREF) reads `false`, | |
| 6293 | + /// and a same-side non-`uni_comp_ref` pair (BWDREF/ALTREF) still reads | |
| 6294 | + /// `true` (spec `has_uni_comp_refs` is symmetric in the reference set, | |
| 6295 | + /// not just the three enumerated syntax pairs). | |
| 6296 | + #[test] | |
| 6297 | + fn is_uni_comp_ref_matches_forward_backward_sides() { | |
| 6298 | + assert!(is_uni_comp_ref(LAST_FRAME, LAST2_FRAME)); | |
| 6299 | + assert!(is_uni_comp_ref(LAST_FRAME, LAST3_FRAME)); | |
| 6300 | + assert!(is_uni_comp_ref(LAST_FRAME, GOLDEN_FRAME)); | |
| 6301 | + assert!(is_uni_comp_ref(BWDREF_FRAME, ALTREF_FRAME)); | |
| 6302 | + assert!(!is_uni_comp_ref(LAST_FRAME, BWDREF_FRAME)); | |
| 6303 | + assert!(!is_uni_comp_ref(GOLDEN_FRAME, ALTREF_FRAME)); | |
| 6304 | + } | |
| 6305 | + | |
| 6306 | + /// [`Neighbours::record_compound_ctx`] stamps `above_ref1`/`left_ref1` | |
| 6307 | + /// with the real second reference (lane-av1comp round 12: previously | |
| 6308 | + /// always cleared to `None` by `record_inter`, so the next block's own | |
| 6309 | + /// `NeighbourRef::uni` -- and `comp_reference_type_ctx` downstream of it | |
| 6310 | + /// -- could never see a real compound neighbour). | |
| 6311 | + #[test] | |
| 6312 | + fn record_compound_ctx_stamps_ref1_for_the_next_block_to_read() { | |
| 6313 | + let mut n = Neighbours::new(4, 4, 16, 16); | |
| 6314 | + n.record_inter((0, 0), SUB, false, true, LAST_FRAME, [3, 3]); | |
| 6315 | + assert_eq!(n.above_ref1[0], None, "record_inter alone never sets ref1"); | |
| 6316 | + n.record_compound_ctx((0, 0), SUB, ALTREF_FRAME, 0, 1); | |
| 6317 | + assert_eq!(n.above_ref1[0], Some(ALTREF_FRAME)); | |
| 6318 | + assert_eq!(n.left_ref1[0], Some(ALTREF_FRAME)); | |
| 6319 | + assert!(!is_uni_comp_ref(LAST_FRAME, n.above_ref1[0].unwrap())); | |
| 6320 | + } | |
| 6321 | + | |
| 6003 | 6322 | /// [`cdf::COMPOUND_MODE_CTX_MAP`] folded by hand against libaom's |
| 6004 | 6323 | /// `av1_mode_context_analyzer` compound branch (`mvref_common.h`): |
| 6005 | 6324 | /// `comp_ctx = compound_mode_ctx_map[refmv_ctx >> 1][min(newmv_ctx, 4)]` |