wip(av1): compound MC wired in the 8x8 leaf path, ref1/uni threaded to neighbours
Browse files at this commit1324c3df15d8ca145102899ba8f0ff6f21b3ffceParent: fed4a601 changed file +341 -22
- crates/ec-av1/src/decode.rs +341 -22
crates/ec-av1/src/decode.rsmodified+341 -22
| @@ -988,16 +988,24 @@ impl Neighbours { | |||
| 988 | /// a real compound block's own `comp_group_idx`/`compound_idx` bits | 988 | /// a real compound block's own `comp_group_idx`/`compound_idx` bits |
| 989 | /// (libaom `has_second_ref(mbmi)` branch of `get_comp_group_idx_context`/ | 989 | /// (libaom `has_second_ref(mbmi)` branch of `get_comp_group_idx_context`/ |
| 990 | /// `get_comp_index_context`) -- called right after `record_inter` for | 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 | fn record_compound_ctx( | 997 | fn record_compound_ctx( |
| 993 | &mut self, | 998 | &mut self, |
| 994 | at: (usize, usize), | 999 | at: (usize, usize), |
| 995 | side: usize, | 1000 | side: usize, |
| 1001 | + ref1: i8, | ||
| 996 | comp_group_idx: u8, | 1002 | comp_group_idx: u8, |
| 997 | compound_idx: u8, | 1003 | compound_idx: u8, |
| 998 | ) { | 1004 | ) { |
| 999 | let (r, c) = at; | 1005 | let (r, c) = at; |
| 1000 | for cell in 0..side / SUB { | 1006 | for cell in 0..side / SUB { |
| 1007 | + self.above_ref1[c + cell] = Some(ref1); | ||
| 1008 | + self.left_ref1[r + cell] = Some(ref1); | ||
| 1001 | self.above_comp_group_idx[c + cell] = comp_group_idx; | 1009 | self.above_comp_group_idx[c + cell] = comp_group_idx; |
| 1002 | self.left_comp_group_idx[r + cell] = comp_group_idx; | 1010 | self.left_comp_group_idx[r + cell] = comp_group_idx; |
| 1003 | self.above_compound_idx[c + cell] = compound_idx; | 1011 | self.above_compound_idx[c + cell] = compound_idx; |
| @@ -3907,6 +3915,19 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { | |||
| 3907 | side.min(side) >= 8 | 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 | /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the | 3931 | /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the |
| 3911 | /// above/left neighbour contributions [`Neighbours::record_inter`]/ | 3932 | /// above/left neighbour contributions [`Neighbours::record_inter`]/ |
| 3912 | /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5. | 3933 | /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5. |
| @@ -3941,7 +3962,9 @@ fn get_comp_index_context( | |||
| 3941 | crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint) | 3962 | crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint) |
| 3942 | .abs(); | 3963 | .abs(); |
| 3943 | let offset = usize::from(fwd == bck); | 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 | fn read_comp_mode( | 3970 | fn read_comp_mode( |
| @@ -4234,7 +4257,7 @@ fn decode_inter_block( | |||
| 4234 | // `COMPOUND_REFERENCE` block -- applied to `neighbours` *after* the | 4257 | // `COMPOUND_REFERENCE` block -- applied to `neighbours` *after* the |
| 4235 | // common `record_inter` call below (which would otherwise stamp the | 4258 | // common `record_inter` call below (which would otherwise stamp the |
| 4236 | // single-ref ALTREF-special-case default over it). | 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 | if is_inter { | 4261 | if is_inter { |
| 4239 | let above_nbr = has_above.then(|| NeighbourRef { | 4262 | let above_nbr = has_above.then(|| NeighbourRef { |
| 4240 | is_inter: above_inter, | 4263 | is_inter: above_inter, |
| @@ -4244,7 +4267,8 @@ fn decode_inter_block( | |||
| 4244 | 0 | 4267 | 0 |
| 4245 | }, | 4268 | }, |
| 4246 | ref1: neighbours.above_ref1[c], | 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 | let left_nbr = has_left.then(|| NeighbourRef { | 4273 | let left_nbr = has_left.then(|| NeighbourRef { |
| 4250 | is_inter: left_inter, | 4274 | is_inter: left_inter, |
| @@ -4254,7 +4278,8 @@ fn decode_inter_block( | |||
| 4254 | 0 | 4278 | 0 |
| 4255 | }, | 4279 | }, |
| 4256 | ref1: neighbours.left_ref1[r], | 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 | let is_compound = reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr); | 4284 | let is_compound = reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr); |
| 4260 | if is_compound { | 4285 | if is_compound { |
| @@ -4297,12 +4322,8 @@ fn decode_inter_block( | |||
| 4297 | sign_bias_table, | 4322 | sign_bias_table, |
| 4298 | comp_tpl, | 4323 | comp_tpl, |
| 4299 | ); | 4324 | ); |
| 4300 | - let compound_mode = read_inter_compound_mode( | 4325 | + let compound_mode = |
| 4301 | - dec, | 4326 | + read_inter_compound_mode(dec, cdfs, comp_stack.new_mv_ctx, comp_stack.ref_mv_ctx); |
| 4302 | - cdfs, | ||
| 4303 | - comp_stack.new_mv_ctx, | ||
| 4304 | - comp_stack.ref_mv_ctx, | ||
| 4305 | - ); | ||
| 4306 | let (mv0, mv1) = assign_compound_mv( | 4327 | let (mv0, mv1) = assign_compound_mv( |
| 4307 | dec, | 4328 | dec, |
| 4308 | cdfs, | 4329 | cdfs, |
| @@ -4400,7 +4421,7 @@ fn decode_inter_block( | |||
| 4400 | } else { | 4421 | } else { |
| 4401 | (8, 8, 1u8) | 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 | let mut inter0_y = vec![0i32; side * side]; | 4426 | let mut inter0_y = vec![0i32; side * side]; |
| 4406 | mc::predict_compound_intermediate( | 4427 | mc::predict_compound_intermediate( |
| @@ -4563,7 +4584,8 @@ fn decode_inter_block( | |||
| 4563 | )?; | 4584 | )?; |
| 4564 | } | 4585 | } |
| 4565 | } else { | 4586 | } else { |
| 4566 | - let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | 4587 | + let ref_frame = |
| 4588 | + read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | ||
| 4567 | ref_frame_for_lf = ref_frame; | 4589 | ref_frame_for_lf = ref_frame; |
| 4568 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own | 4590 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own |
| 4569 | // stacked defects (lf_level ref/mode-delta forwarding, the | 4591 | // stacked defects (lf_level ref/mode-delta forwarding, the |
| @@ -4994,8 +5016,8 @@ fn decode_inter_block( | |||
| 4994 | } | 5016 | } |
| 4995 | neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); | 5017 | neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); |
| 4996 | neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter); | 5018 | neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter); |
| 4997 | - if let Some((group_idx, idx)) = compound_ctx { | 5019 | + if let Some((ref1, group_idx, idx)) = compound_ctx { |
| 4998 | - neighbours.record_compound_ctx(at, side, group_idx, idx); | 5020 | + neighbours.record_compound_ctx(at, side, ref1, group_idx, idx); |
| 4999 | } | 5021 | } |
| 5000 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); | 5022 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 5001 | neighbours.fill_lf_grid( | 5023 | neighbours.fill_lf_grid( |
| @@ -5043,6 +5065,7 @@ fn decode_inter_block8( | |||
| 5043 | ref_y: &PlaneBuf, | 5065 | ref_y: &PlaneBuf, |
| 5044 | ref_u: &PlaneBuf, | 5066 | ref_u: &PlaneBuf, |
| 5045 | ref_v: &PlaneBuf, | 5067 | ref_v: &PlaneBuf, |
| 5068 | + other_refs: &RefSlots, | ||
| 5046 | base_q_idx: u8, | 5069 | base_q_idx: u8, |
| 5047 | scan8: &[u16], | 5070 | scan8: &[u16], |
| 5048 | scan4: &[u16], | 5071 | scan4: &[u16], |
| @@ -5053,7 +5076,18 @@ fn decode_inter_block8( | |||
| 5053 | // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s | 5076 | // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s |
| 5054 | // context uses that same approximation. | 5077 | // context uses that same approximation. |
| 5055 | reference_select: bool, | 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 | const LAST_FRAME: i8 = 1; | 5091 | const LAST_FRAME: i8 = 1; |
| 5058 | /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). | 5092 | /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). |
| 5059 | const SIZE_GROUP_8: usize = 1; | 5093 | const SIZE_GROUP_8: usize = 1; |
| @@ -5086,6 +5120,7 @@ fn decode_inter_block8( | |||
| 5086 | 5120 | ||
| 5087 | let mode_for_tx; | 5121 | let mode_for_tx; |
| 5088 | let (luma_grid, u_grid, v_grid); | 5122 | let (luma_grid, u_grid, v_grid); |
| 5123 | + let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; | ||
| 5089 | if is_inter { | 5124 | if is_inter { |
| 5090 | if reference_select { | 5125 | if reference_select { |
| 5091 | let above_nbr = has_above.then(|| NeighbourRef { | 5126 | let above_nbr = has_above.then(|| NeighbourRef { |
| @@ -5142,19 +5177,248 @@ fn decode_inter_block8( | |||
| 5142 | comp_stack.new_mv_ctx, | 5177 | comp_stack.new_mv_ctx, |
| 5143 | comp_stack.ref_mv_ctx, | 5178 | comp_stack.ref_mv_ctx, |
| 5144 | ); | 5179 | ); |
| 5145 | - let _mv_pair = assign_compound_mv( | 5180 | + let (mv0, mv1) = assign_compound_mv( |
| 5146 | dec, | 5181 | dec, |
| 5147 | cdfs, | 5182 | cdfs, |
| 5148 | &comp_stack, | 5183 | &comp_stack, |
| 5149 | compound_mode, | 5184 | compound_mode, |
| 5150 | allow_high_precision_mv, | 5185 | allow_high_precision_mv, |
| 5151 | ); | 5186 | ); |
| 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 { | ||
| 5152 | return Err(unsupported( | 5200 | return Err(unsupported( |
| 5153 | - "a COMPOUND_REFERENCE 8x8 leaf (comp_mode/comp_ref/inter_compound_mode/\ | 5201 | + "a masked COMPOUND_REFERENCE 8x8 leaf (comp_group_idx == 1, wedge/\ |
| 5154 | - compound DRL/MV assignment read correctly; two-reference motion \ | 5202 | + diffwtd) -- this decoder's compound blend is the plain distance-\ |
| 5155 | - compensation is not wired yet -- lane-av1comp)", | 5203 | + weighted/simple-average combine only, lane-av1comp", |
| 5156 | )); | 5204 | )); |
| 5157 | } | 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)); | ||
| 5421 | + } | ||
| 5158 | } | 5422 | } |
| 5159 | let sr_ctx = single_ref_ctx(above_inter || left_inter); | 5423 | let sr_ctx = single_ref_ctx(above_inter || left_inter); |
| 5160 | let p1 = dec.symbol(&mut cdfs.single_ref[sr_ctx][0]); | 5424 | let p1 = dec.symbol(&mut cdfs.single_ref[sr_ctx][0]); |
| @@ -5495,7 +5759,7 @@ fn decode_inter_block8( | |||
| 5495 | } | 5759 | } |
| 5496 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 5760 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 5497 | neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 }); | 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 | /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, | 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 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) | 6140 | .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) |
| 5877 | .collect(); | 6141 | .collect(); |
| 5878 | let mut prev_leaf: Option<((usize, usize), bool, bool)> = None; | 6142 | let mut prev_leaf: Option<((usize, usize), bool, bool)> = None; |
| 6143 | + let mut last_compound_ctx: Option<(i8, i8, u8, u8)> = None; | ||
| 5879 | for (mr, mc) in leaf_positions { | 6144 | for (mr, mc) in leaf_positions { |
| 5880 | let leaf_mi = (mr as usize, mc as usize); | 6145 | let leaf_mi = (mr as usize, mc as usize); |
| 5881 | let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); | 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 | "a partition below 8x8 (this encoder never writes one)", | 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 | &mut dec, | 6154 | &mut dec, |
| 5890 | &mut cdfs, | 6155 | &mut cdfs, |
| 5891 | &mut neighbours, | 6156 | &mut neighbours, |
| @@ -5900,14 +6165,23 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 5900 | &ref_y, | 6165 | &ref_y, |
| 5901 | &ref_u, | 6166 | &ref_u, |
| 5902 | &ref_v, | 6167 | &ref_v, |
| 6168 | + &ref_slots, | ||
| 5903 | base_q_idx, | 6169 | base_q_idx, |
| 5904 | &scan8, | 6170 | &scan8, |
| 5905 | &scan4, | 6171 | &scan4, |
| 5906 | prev_leaf, | 6172 | prev_leaf, |
| 5907 | allow_high_precision_mv, | 6173 | allow_high_precision_mv, |
| 5908 | reference_select, | 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 | prev_leaf = Some((leaf_mi, skip, is_inter)); | 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 | if let Some((_, skip, is_inter)) = prev_leaf { | 6186 | if let Some((_, skip, is_inter)) = prev_leaf { |
| 5913 | // corner-cut: `decode_inter_block8`'s | 6187 | // corner-cut: `decode_inter_block8`'s |
| @@ -5929,6 +6203,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 5929 | if is_inter { LAST_FRAME } else { -1 }, | 6203 | if is_inter { LAST_FRAME } else { -1 }, |
| 5930 | [3, 3], | 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 | // this decoder's one target, and the round-trip test below is against | 6286 | // this decoder's one target, and the round-trip test below is against |
| 6001 | // that path with real quantised residual, not a synthetic all-DC frame. | 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 | /// [`cdf::COMPOUND_MODE_CTX_MAP`] folded by hand against libaom's | 6322 | /// [`cdf::COMPOUND_MODE_CTX_MAP`] folded by hand against libaom's |
| 6004 | /// `av1_mode_context_analyzer` compound branch (`mvref_common.h`): | 6323 | /// `av1_mode_context_analyzer` compound branch (`mvref_common.h`): |
| 6005 | /// `comp_ctx = compound_mode_ctx_map[refmv_ctx >> 1][min(newmv_ctx, 4)]` | 6324 | /// `comp_ctx = compound_mode_ctx_map[refmv_ctx >> 1][min(newmv_ctx, 4)]` |