wip(av1): compound r11 — comp_group_idx/compound_idx read, MC blend wired in main path
Browse files at this commitfed4a603588295872efccf8feef885c51e77ea29Parent: 181a7844 changed files +456 -6
- crates/ec-av1/src/cdf.rs +28 -0
- crates/ec-av1/src/cdf_state.rs +11 -0
- crates/ec-av1/src/decode.rs +408 -6
- crates/ec-av1/src/stream.rs +9 -0
crates/ec-av1/src/cdf.rsmodified+28 -0
| @@ -1201,6 +1201,34 @@ pub const COMP_REF_TYPE: [[u16; 3]; 5] = [ | |||
| 1201 | [22475, 32768, 0], | 1201 | [22475, 32768, 0], |
| 1202 | ]; | 1202 | ]; |
| 1203 | 1203 | ||
| 1204 | +/// `Default_Comp_Group_Idx_Cdf` (spec 9.4, libaom `default_comp_group_idx_cdfs`): | ||
| 1205 | +/// whether a compound block's `comp_group_idx` picks masked compound (`1`) | ||
| 1206 | +/// over the plain distance-weighted/simple-average blend (`0`), indexed by | ||
| 1207 | +/// `get_comp_group_idx_context` -- only read when `seq.enable_masked_compound` | ||
| 1208 | +/// and the block size is masked-compound-eligible (lane-av1comp). | ||
| 1209 | +pub const COMP_GROUP_IDX: [[u16; 3]; 6] = [ | ||
| 1210 | + [26607, 32768, 0], | ||
| 1211 | + [22891, 32768, 0], | ||
| 1212 | + [18840, 32768, 0], | ||
| 1213 | + [24594, 32768, 0], | ||
| 1214 | + [19934, 32768, 0], | ||
| 1215 | + [22674, 32768, 0], | ||
| 1216 | +]; | ||
| 1217 | + | ||
| 1218 | +/// `Default_Compound_Idx_Cdf` (spec 9.4, libaom `default_compound_idx_cdfs`): | ||
| 1219 | +/// whether a compound block's `compound_idx` picks the simple average | ||
| 1220 | +/// (`1`) or [`crate::compound::dist_wtd_comp_weight_assign`]'s distance | ||
| 1221 | +/// weights (`0`), indexed by `get_comp_index_context` -- only read when | ||
| 1222 | +/// `seq.enable_jnt_comp` (lane-av1comp). | ||
| 1223 | +pub const COMPOUND_IDX: [[u16; 3]; 6] = [ | ||
| 1224 | + [18244, 32768, 0], | ||
| 1225 | + [12865, 32768, 0], | ||
| 1226 | + [7053, 32768, 0], | ||
| 1227 | + [13259, 32768, 0], | ||
| 1228 | + [9334, 32768, 0], | ||
| 1229 | + [4644, 32768, 0], | ||
| 1230 | +]; | ||
| 1231 | + | ||
| 1204 | /// `Default_Uni_Comp_Ref_Cdf` (spec 9.4, `default_uni_comp_ref_cdf`): the | 1232 | /// `Default_Uni_Comp_Ref_Cdf` (spec 9.4, `default_uni_comp_ref_cdf`): the |
| 1205 | /// three binary decisions narrowing a unidirectional compound pair down to | 1233 | /// three binary decisions narrowing a unidirectional compound pair down to |
| 1206 | /// one of `{BWDREF,ALTREF}`/`{LAST,LAST2}`/`{LAST,LAST3}`/`{LAST,GOLDEN}`. | 1234 | /// one of `{BWDREF,ALTREF}`/`{LAST,LAST2}`/`{LAST,LAST3}`/`{LAST,GOLDEN}`. |
crates/ec-av1/src/cdf_state.rsmodified+11 -0
| @@ -308,6 +308,13 @@ pub(crate) struct Cdfs { | |||
| 308 | pub comp_ref: [[[u16; 3]; 3]; 3], | 308 | pub comp_ref: [[[u16; 3]; 3]; 3], |
| 309 | /// The two binary decisions of a bidirectional pair's backward ref. | 309 | /// The two binary decisions of a bidirectional pair's backward ref. |
| 310 | pub comp_bwdref: [[[u16; 3]; 2]; 3], | 310 | pub comp_bwdref: [[[u16; 3]; 2]; 3], |
| 311 | + /// Whether a compound block's `comp_group_idx` picks masked compound | ||
| 312 | + /// (lane-av1comp, spec 5.11.25's `comp_group_idx`). | ||
| 313 | + pub comp_group_idx: [[u16; 3]; 6], | ||
| 314 | + /// Whether a compound block's `compound_idx` picks the simple average | ||
| 315 | + /// over the distance-weighted blend (lane-av1comp, spec 5.11.25's | ||
| 316 | + /// `compound_idx`). | ||
| 317 | + pub compound_idx: [[u16; 3]; 6], | ||
| 311 | /// The luma mode of an inter frame's intra block, by its size group. | 318 | /// The luma mode of an inter frame's intra block, by its size group. |
| 312 | pub y_mode: [[u16; 14]; 4], | 319 | pub y_mode: [[u16; 14]; 4], |
| 313 | /// Whether an inter block codes its motion vector explicitly. | 320 | /// Whether an inter block codes its motion vector explicitly. |
| @@ -521,6 +528,8 @@ impl Cdfs { | |||
| 521 | reset3(&mut self.uni_comp_ref); | 528 | reset3(&mut self.uni_comp_ref); |
| 522 | reset3(&mut self.comp_ref); | 529 | reset3(&mut self.comp_ref); |
| 523 | reset3(&mut self.comp_bwdref); | 530 | reset3(&mut self.comp_bwdref); |
| 531 | + reset2(&mut self.comp_group_idx); | ||
| 532 | + reset2(&mut self.compound_idx); | ||
| 524 | reset2(&mut self.y_mode); | 533 | reset2(&mut self.y_mode); |
| 525 | reset2(&mut self.new_mv); | 534 | reset2(&mut self.new_mv); |
| 526 | reset2(&mut self.zero_mv); | 535 | reset2(&mut self.zero_mv); |
| @@ -951,6 +960,8 @@ impl Cdfs { | |||
| 951 | uni_comp_ref: cdf::UNI_COMP_REF, | 960 | uni_comp_ref: cdf::UNI_COMP_REF, |
| 952 | comp_ref: cdf::COMP_REF, | 961 | comp_ref: cdf::COMP_REF, |
| 953 | comp_bwdref: cdf::COMP_BWDREF, | 962 | comp_bwdref: cdf::COMP_BWDREF, |
| 963 | + comp_group_idx: cdf::COMP_GROUP_IDX, | ||
| 964 | + compound_idx: cdf::COMPOUND_IDX, | ||
| 954 | y_mode: cdf::Y_MODE, | 965 | y_mode: cdf::Y_MODE, |
| 955 | new_mv: cdf::NEW_MV, | 966 | new_mv: cdf::NEW_MV, |
| 956 | zero_mv: cdf::ZERO_MV, | 967 | zero_mv: cdf::ZERO_MV, |
crates/ec-av1/src/decode.rsmodified+408 -6
| @@ -784,6 +784,15 @@ struct Neighbours { | |||
| 784 | /// (no decode path here ever produces a compound block yet). | 784 | /// (no decode path here ever produces a compound block yet). |
| 785 | above_ref1: Vec<Option<i8>>, | 785 | above_ref1: Vec<Option<i8>>, |
| 786 | left_ref1: Vec<Option<i8>>, | 786 | left_ref1: Vec<Option<i8>>, |
| 787 | + /// The precomputed `get_comp_group_idx_context`/`get_comp_index_context` | ||
| 788 | + /// neighbour contribution (spec 5.11.25, libaom `pred_common.h`): | ||
| 789 | + /// a compound neighbour's own `comp_group_idx`/`compound_idx` bit, or | ||
| 790 | + /// the "ref_frame[0] == ALTREF_FRAME" special case (`3`/`1`) for a | ||
| 791 | + /// single-ref one, or `0` for intra/unavailable -- lane-av1comp. | ||
| 792 | + above_comp_group_idx: Vec<u8>, | ||
| 793 | + left_comp_group_idx: Vec<u8>, | ||
| 794 | + above_compound_idx: Vec<u8>, | ||
| 795 | + left_compound_idx: Vec<u8>, | ||
| 787 | /// `interp_filter[0]`/`[1]` (horizontal/vertical kernel index, 0..=2, or | 796 | /// `interp_filter[0]`/`[1]` (horizontal/vertical kernel index, 0..=2, or |
| 788 | /// `3` = "no info": an intra neighbour or the frame's own border) of the | 797 | /// `3` = "no info": an intra neighbour or the frame's own border) of the |
| 789 | /// block above/left of this column/row -- spec | 798 | /// block above/left of this column/row -- spec |
| @@ -838,6 +847,10 @@ impl Neighbours { | |||
| 838 | left_ref: vec![-1; rows], | 847 | left_ref: vec![-1; rows], |
| 839 | above_ref1: vec![None; cols], | 848 | above_ref1: vec![None; cols], |
| 840 | left_ref1: vec![None; rows], | 849 | left_ref1: vec![None; rows], |
| 850 | + above_comp_group_idx: vec![0; cols], | ||
| 851 | + left_comp_group_idx: vec![0; rows], | ||
| 852 | + above_compound_idx: vec![0; cols], | ||
| 853 | + left_compound_idx: vec![0; rows], | ||
| 841 | above_filter: vec![[3u8; 2]; cols], | 854 | above_filter: vec![[3u8; 2]; cols], |
| 842 | left_filter: vec![[3u8; 2]; rows], | 855 | left_filter: vec![[3u8; 2]; rows], |
| 843 | mi_cols, | 856 | mi_cols, |
| @@ -922,6 +935,8 @@ impl Neighbours { | |||
| 922 | self.left_inter.iter_mut().for_each(|i| *i = false); | 935 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| 923 | self.left_ref.iter_mut().for_each(|r| *r = -1); | 936 | self.left_ref.iter_mut().for_each(|r| *r = -1); |
| 924 | self.left_ref1.iter_mut().for_each(|r| *r = None); | 937 | self.left_ref1.iter_mut().for_each(|r| *r = None); |
| 938 | + self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); | ||
| 939 | + self.left_compound_idx.iter_mut().for_each(|r| *r = 0); | ||
| 925 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); | 940 | self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); |
| 926 | } | 941 | } |
| 927 | 942 | ||
| @@ -954,11 +969,42 @@ impl Neighbours { | |||
| 954 | // parameter this becomes lands with `read_ref_frames`. | 969 | // parameter this becomes lands with `read_ref_frames`. |
| 955 | self.above_ref1[c + cell] = None; | 970 | self.above_ref1[c + cell] = None; |
| 956 | self.left_ref1[r + cell] = None; | 971 | self.left_ref1[r + cell] = None; |
| 972 | + // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s | ||
| 973 | + // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads | ||
| 974 | + // as `3`/`1` even though this block has no second reference. | ||
| 975 | + // `record_compound_ctx` overwrites this with the real bit for an | ||
| 976 | + // actual compound block's cells, called right after this one. | ||
| 977 | + let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME; | ||
| 978 | + self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 }; | ||
| 979 | + self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 }; | ||
| 980 | + self.above_compound_idx[c + cell] = u8::from(altref); | ||
| 981 | + self.left_compound_idx[r + cell] = u8::from(altref); | ||
| 957 | self.above_filter[c + cell] = filter; | 982 | self.above_filter[c + cell] = filter; |
| 958 | self.left_filter[r + cell] = filter; | 983 | self.left_filter[r + cell] = filter; |
| 959 | } | 984 | } |
| 960 | } | 985 | } |
| 961 | 986 | ||
| 987 | + /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with | ||
| 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`/ | ||
| 990 | + /// `get_comp_index_context`) -- called right after `record_inter` for | ||
| 991 | + /// the same `at`/`side`, only on the `COMPOUND_REFERENCE` path. | ||
| 992 | + fn record_compound_ctx( | ||
| 993 | + &mut self, | ||
| 994 | + at: (usize, usize), | ||
| 995 | + side: usize, | ||
| 996 | + comp_group_idx: u8, | ||
| 997 | + compound_idx: u8, | ||
| 998 | + ) { | ||
| 999 | + let (r, c) = at; | ||
| 1000 | + for cell in 0..side / SUB { | ||
| 1001 | + self.above_comp_group_idx[c + cell] = comp_group_idx; | ||
| 1002 | + self.left_comp_group_idx[r + cell] = comp_group_idx; | ||
| 1003 | + self.above_compound_idx[c + cell] = compound_idx; | ||
| 1004 | + self.left_compound_idx[r + cell] = compound_idx; | ||
| 1005 | + } | ||
| 1006 | + } | ||
| 1007 | + | ||
| 962 | /// The context of a block's partition symbol: delegates to the mi-precise | 1008 | /// The context of a block's partition symbol: delegates to the mi-precise |
| 963 | /// reader (same pattern as `around`/`around_mi`) -- `above_side`/ | 1009 | /// reader (same pattern as `around`/`around_mi`) -- `above_side`/ |
| 964 | /// `left_side` are only ever advanced in whole-[`SUB`] steps by | 1010 | /// `left_side` are only ever advanced in whole-[`SUB`] steps by |
| @@ -3827,6 +3873,77 @@ fn read_single_ref(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, above_ref: i8, left | |||
| 3827 | /// own doc. Called from [`decode_inter_block`] once its own `reference_select` | 3873 | /// own doc. Called from [`decode_inter_block`] once its own `reference_select` |
| 3828 | /// parameter is set; [`decode_inter_block8`]'s 8x8 leaf path gates the same | 3874 | /// parameter is set; [`decode_inter_block8`]'s 8x8 leaf path gates the same |
| 3829 | /// way with a coarser (`LAST_FRAME`-only) neighbour shape. | 3875 | /// way with a coarser (`LAST_FRAME`-only) neighbour shape. |
| 3876 | +/// Resolves a compound reference's own planes -- the same `ref_frame == | ||
| 3877 | +/// LAST_FRAME -> ref_y/u/v, else other_refs[ref_frame]` lookup | ||
| 3878 | +/// [`decode_inter_block`]'s single-ref path already does, factored out so | ||
| 3879 | +/// the compound path can call it twice (lane-av1comp). | ||
| 3880 | +fn ref_planes<'a>( | ||
| 3881 | + ref_frame: i8, | ||
| 3882 | + ref_y: &'a PlaneBuf, | ||
| 3883 | + ref_u: &'a PlaneBuf, | ||
| 3884 | + ref_v: &'a PlaneBuf, | ||
| 3885 | + other_refs: &'a RefSlots, | ||
| 3886 | +) -> Result<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)> { | ||
| 3887 | + if ref_frame == LAST_FRAME { | ||
| 3888 | + Ok((ref_y, ref_u, ref_v)) | ||
| 3889 | + } else { | ||
| 3890 | + match other_refs[ref_frame as usize] { | ||
| 3891 | + Some((ry, ru, rv)) => Ok((ry, ru, rv)), | ||
| 3892 | + None => Err(unsupported( | ||
| 3893 | + "a reference frame selected with no picture at this frame's own \ | ||
| 3894 | + ref_frame_idx slot for it", | ||
| 3895 | + )), | ||
| 3896 | + } | ||
| 3897 | + } | ||
| 3898 | +} | ||
| 3899 | + | ||
| 3900 | +/// `is_any_masked_compound_used` (libaom `reconinter.h`), specialised to | ||
| 3901 | +/// the square block sizes this decoder ever decodes (32/16/8, all | ||
| 3902 | +/// `min(w,h) >= 8`, `is_comp_ref_allowed` true): `COMPOUND_DIFFWTD` is then | ||
| 3903 | +/// always `is_interinter_compound_used`, so the function is always `true` | ||
| 3904 | +/// for `side` -- kept as a named call (rather than inlined `true`) so a | ||
| 3905 | +/// future sub-8 block size does not silently misdecode a real stream. | ||
| 3906 | +fn is_any_masked_compound_used_here(side: usize) -> bool { | ||
| 3907 | + side.min(side) >= 8 | ||
| 3908 | +} | ||
| 3909 | + | ||
| 3910 | +/// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the | ||
| 3911 | +/// above/left neighbour contributions [`Neighbours::record_inter`]/ | ||
| 3912 | +/// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5. | ||
| 3913 | +fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side: usize) -> usize { | ||
| 3914 | + let _ = side; | ||
| 3915 | + let (r, c) = at; | ||
| 3916 | + (neighbours.above_comp_group_idx[c] as usize + neighbours.left_comp_group_idx[r] as usize) | ||
| 3917 | + .min(5) | ||
| 3918 | +} | ||
| 3919 | + | ||
| 3920 | +/// `get_comp_index_context` (libaom `pred_common.h`): the above/left | ||
| 3921 | +/// neighbour bits plus `3 * (fwd == bck)`, where `fwd`/`bck` are this | ||
| 3922 | +/// block's own two references' distances from the current frame (spec | ||
| 3923 | +/// 7.11.3.15's `get_relative_dist`, same convention | ||
| 3924 | +/// [`crate::compound::dist_wtd_comp_weight_assign`] uses). | ||
| 3925 | +#[allow(clippy::too_many_arguments)] | ||
| 3926 | +fn get_comp_index_context( | ||
| 3927 | + neighbours: &Neighbours, | ||
| 3928 | + at: (usize, usize), | ||
| 3929 | + side: usize, | ||
| 3930 | + order_hint_bits: u32, | ||
| 3931 | + cur_order_hint: u32, | ||
| 3932 | + ref0_order_hint: u32, | ||
| 3933 | + ref1_order_hint: u32, | ||
| 3934 | +) -> usize { | ||
| 3935 | + let _ = side; | ||
| 3936 | + let (r, c) = at; | ||
| 3937 | + let fwd = | ||
| 3938 | + crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint) | ||
| 3939 | + .abs(); | ||
| 3940 | + let bck = | ||
| 3941 | + crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint) | ||
| 3942 | + .abs(); | ||
| 3943 | + let offset = usize::from(fwd == bck); | ||
| 3944 | + neighbours.above_compound_idx[c] as usize + neighbours.left_compound_idx[r] as usize + 3 * offset | ||
| 3945 | +} | ||
| 3946 | + | ||
| 3830 | fn read_comp_mode( | 3947 | fn read_comp_mode( |
| 3831 | dec: &mut SymbolDecoder, | 3948 | dec: &mut SymbolDecoder, |
| 3832 | cdfs: &mut Cdfs, | 3949 | cdfs: &mut Cdfs, |
| @@ -4084,6 +4201,16 @@ fn decode_inter_block( | |||
| 4084 | // `COMPOUND_REFERENCE`, since two-reference motion compensation is not | 4201 | // `COMPOUND_REFERENCE`, since two-reference motion compensation is not |
| 4085 | // wired yet. | 4202 | // wired yet. |
| 4086 | reference_select: bool, | 4203 | reference_select: bool, |
| 4204 | + // lane-av1comp: `seq_params`' own masked-compound/distance-weighted- | ||
| 4205 | + // compound enable bits, gating `comp_group_idx`/`compound_idx` | ||
| 4206 | + // (spec 5.11.25) -- always present (unlike `tpl_frame`), since the | ||
| 4207 | + // compound blend weights need this frame's own order hint regardless | ||
| 4208 | + // of `use_ref_frame_mvs`. | ||
| 4209 | + enable_masked_compound: bool, | ||
| 4210 | + enable_jnt_comp: bool, | ||
| 4211 | + order_hint_bits: u32, | ||
| 4212 | + order_hint: u32, | ||
| 4213 | + ref_order_hints: [u32; 7], | ||
| 4087 | ) -> Result<()> { | 4214 | ) -> Result<()> { |
| 4088 | let (r, c) = at; | 4215 | let (r, c) = at; |
| 4089 | let (px, py) = (c * SUB, r * SUB); | 4216 | let (px, py) = (c * SUB, r * SUB); |
| @@ -4103,8 +4230,12 @@ fn decode_inter_block( | |||
| 4103 | let block_filter; | 4230 | let block_filter; |
| 4104 | let ref_frame_for_lf; | 4231 | let ref_frame_for_lf; |
| 4105 | let globalmv_for_lf; | 4232 | let globalmv_for_lf; |
| 4233 | + // lane-av1comp: `Some((comp_group_idx, compound_idx))` only for a real | ||
| 4234 | + // `COMPOUND_REFERENCE` block -- applied to `neighbours` *after* the | ||
| 4235 | + // common `record_inter` call below (which would otherwise stamp the | ||
| 4236 | + // single-ref ALTREF-special-case default over it). | ||
| 4237 | + let mut compound_ctx: Option<(u8, u8)> = None; | ||
| 4106 | if is_inter { | 4238 | if is_inter { |
| 4107 | - if reference_select { | ||
| 4108 | let above_nbr = has_above.then(|| NeighbourRef { | 4239 | let above_nbr = has_above.then(|| NeighbourRef { |
| 4109 | is_inter: above_inter, | 4240 | is_inter: above_inter, |
| 4110 | ref0: if above_inter { | 4241 | ref0: if above_inter { |
| @@ -4125,7 +4256,8 @@ fn decode_inter_block( | |||
| 4125 | ref1: neighbours.left_ref1[r], | 4256 | ref1: neighbours.left_ref1[r], |
| 4126 | uni: false, | 4257 | uni: false, |
| 4127 | }); | 4258 | }); |
| 4128 | - if read_comp_mode(dec, cdfs, above_nbr, left_nbr) { | 4259 | + let is_compound = reference_select && read_comp_mode(dec, cdfs, above_nbr, left_nbr); |
| 4260 | + if is_compound { | ||
| 4129 | let (ref0, ref1) = read_compound_ref_frames( | 4261 | let (ref0, ref1) = read_compound_ref_frames( |
| 4130 | dec, | 4262 | dec, |
| 4131 | cdfs, | 4263 | cdfs, |
| @@ -4171,20 +4303,266 @@ fn decode_inter_block( | |||
| 4171 | comp_stack.new_mv_ctx, | 4303 | comp_stack.new_mv_ctx, |
| 4172 | comp_stack.ref_mv_ctx, | 4304 | comp_stack.ref_mv_ctx, |
| 4173 | ); | 4305 | ); |
| 4174 | - let _mv_pair = assign_compound_mv( | 4306 | + let (mv0, mv1) = assign_compound_mv( |
| 4175 | dec, | 4307 | dec, |
| 4176 | cdfs, | 4308 | cdfs, |
| 4177 | &comp_stack, | 4309 | &comp_stack, |
| 4178 | compound_mode, | 4310 | compound_mode, |
| 4179 | allow_high_precision_mv, | 4311 | allow_high_precision_mv, |
| 4180 | ); | 4312 | ); |
| 4313 | + let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV | ||
| 4314 | + let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; | ||
| 4315 | + let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; | ||
| 4316 | + let above_filter_ctx = if neighbours.above_ref[c] == ref0 { | ||
| 4317 | + neighbours.above_filter[c] | ||
| 4318 | + } else { | ||
| 4319 | + [3, 3] | ||
| 4320 | + }; | ||
| 4321 | + let left_filter_ctx = if neighbours.left_ref[r] == ref0 { | ||
| 4322 | + neighbours.left_filter[r] | ||
| 4323 | + } else { | ||
| 4324 | + [3, 3] | ||
| 4325 | + }; | ||
| 4326 | + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 4327 | + dec, | ||
| 4328 | + cdfs, | ||
| 4329 | + interp_fixed, | ||
| 4330 | + enable_dual_filter, | ||
| 4331 | + is_globalmv, | ||
| 4332 | + above_filter_ctx, | ||
| 4333 | + left_filter_ctx, | ||
| 4334 | + ); | ||
| 4335 | + block_filter = resolved_filter; | ||
| 4336 | + globalmv_for_lf = is_globalmv; | ||
| 4337 | + ref_frame_for_lf = ref0; | ||
| 4338 | + mode_for_tx = 0; | ||
| 4339 | + for dr in 0..bw4 { | ||
| 4340 | + for dc in 0..bw4 { | ||
| 4341 | + grid.set( | ||
| 4342 | + mi_row + dr, | ||
| 4343 | + mi_col + dc, | ||
| 4344 | + MiInfo { | ||
| 4345 | + is_inter: true, | ||
| 4346 | + ref_frame: ref0, | ||
| 4347 | + ref_frame1: Some(ref1), | ||
| 4348 | + mv1: Some(mv1), | ||
| 4349 | + mv: mv0, | ||
| 4350 | + is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7), | ||
| 4351 | + size: bw4, | ||
| 4352 | + }, | ||
| 4353 | + ); | ||
| 4354 | + } | ||
| 4355 | + } | ||
| 4356 | + // spec 5.11.25's `comp_group_idx`/`compound_idx`: only read when | ||
| 4357 | + // masked compound / distance-weighted compound are actually | ||
| 4358 | + // enabled for this stream -- `is_any_masked_compound_used_here` | ||
| 4359 | + // is `true` for every block size this decoder ever reaches | ||
| 4360 | + // (`min(side,side) >= 8`, `COMPOUND_DIFFWTD` always eligible | ||
| 4361 | + // there), so the gate reduces to the sequence header bit; kept | ||
| 4362 | + // as an explicit call so a future smaller block size is not | ||
| 4363 | + // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`). | ||
| 4364 | + let group_ctx = get_comp_group_idx_context(neighbours, at, side); | ||
| 4365 | + let comp_group_idx = if enable_masked_compound && is_any_masked_compound_used_here(side) | ||
| 4366 | + { | ||
| 4367 | + dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) | ||
| 4368 | + } else { | ||
| 4369 | + 0 | ||
| 4370 | + }; | ||
| 4371 | + if comp_group_idx == 1 { | ||
| 4181 | return Err(unsupported( | 4372 | return Err(unsupported( |
| 4182 | - "a COMPOUND_REFERENCE block (comp_mode/comp_ref/inter_compound_mode/\ | 4373 | + "a masked COMPOUND_REFERENCE block (comp_group_idx == 1, wedge/\ |
| 4183 | - compound DRL/MV assignment read correctly; two-reference motion \ | 4374 | + diffwtd) -- this decoder's compound blend is the plain distance-\ |
| 4184 | - compensation is not wired yet -- lane-av1comp)", | 4375 | + weighted/simple-average combine only, lane-av1comp", |
| 4185 | )); | 4376 | )); |
| 4186 | } | 4377 | } |
| 4378 | + let (fwd_offset, bck_offset, compound_idx) = if enable_jnt_comp { | ||
| 4379 | + let idx_ctx = get_comp_index_context( | ||
| 4380 | + neighbours, | ||
| 4381 | + at, | ||
| 4382 | + side, | ||
| 4383 | + order_hint_bits, | ||
| 4384 | + order_hint, | ||
| 4385 | + ref_order_hints[(ref0 - LAST_FRAME) as usize], | ||
| 4386 | + ref_order_hints[(ref1 - LAST_FRAME) as usize], | ||
| 4387 | + ); | ||
| 4388 | + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); | ||
| 4389 | + if idx == 1 { | ||
| 4390 | + (8, 8, 1u8) | ||
| 4391 | + } else { | ||
| 4392 | + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( | ||
| 4393 | + order_hint_bits, | ||
| 4394 | + order_hint, | ||
| 4395 | + ref_order_hints[(ref0 - LAST_FRAME) as usize], | ||
| 4396 | + ref_order_hints[(ref1 - LAST_FRAME) as usize], | ||
| 4397 | + ); | ||
| 4398 | + (fwd, bck, 0u8) | ||
| 4187 | } | 4399 | } |
| 4400 | + } else { | ||
| 4401 | + (8, 8, 1u8) | ||
| 4402 | + }; | ||
| 4403 | + compound_ctx = Some((comp_group_idx as u8, compound_idx)); | ||
| 4404 | + | ||
| 4405 | + let mut inter0_y = vec![0i32; side * side]; | ||
| 4406 | + mc::predict_compound_intermediate( | ||
| 4407 | + &py0.data, | ||
| 4408 | + py0.width, | ||
| 4409 | + py0.true_width, | ||
| 4410 | + py0.true_height, | ||
| 4411 | + mv_to_q4(px, mv0.1, true), | ||
| 4412 | + mv_to_q4(py, mv0.0, true), | ||
| 4413 | + side, | ||
| 4414 | + side, | ||
| 4415 | + h_filter, | ||
| 4416 | + v_filter, | ||
| 4417 | + &mut inter0_y, | ||
| 4418 | + ); | ||
| 4419 | + let mut inter1_y = vec![0i32; side * side]; | ||
| 4420 | + mc::predict_compound_intermediate( | ||
| 4421 | + &py1.data, | ||
| 4422 | + py1.width, | ||
| 4423 | + py1.true_width, | ||
| 4424 | + py1.true_height, | ||
| 4425 | + mv_to_q4(px, mv1.1, true), | ||
| 4426 | + mv_to_q4(py, mv1.0, true), | ||
| 4427 | + side, | ||
| 4428 | + side, | ||
| 4429 | + h_filter, | ||
| 4430 | + v_filter, | ||
| 4431 | + &mut inter1_y, | ||
| 4432 | + ); | ||
| 4433 | + let mut pred_y = vec![0u8; side * side]; | ||
| 4434 | + mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | ||
| 4435 | + | ||
| 4436 | + let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | ||
| 4437 | + mc::predict_compound_intermediate( | ||
| 4438 | + &pu0.data, | ||
| 4439 | + pu0.width, | ||
| 4440 | + pu0.true_width, | ||
| 4441 | + pu0.true_height, | ||
| 4442 | + mv_to_q4(cpx, mv0.1, false), | ||
| 4443 | + mv_to_q4(cpy, mv0.0, false), | ||
| 4444 | + chroma_side, | ||
| 4445 | + chroma_side, | ||
| 4446 | + h_filter, | ||
| 4447 | + v_filter, | ||
| 4448 | + &mut inter0_u, | ||
| 4449 | + ); | ||
| 4450 | + let mut inter1_u = vec![0i32; chroma_side * chroma_side]; | ||
| 4451 | + mc::predict_compound_intermediate( | ||
| 4452 | + &pu1.data, | ||
| 4453 | + pu1.width, | ||
| 4454 | + pu1.true_width, | ||
| 4455 | + pu1.true_height, | ||
| 4456 | + mv_to_q4(cpx, mv1.1, false), | ||
| 4457 | + mv_to_q4(cpy, mv1.0, false), | ||
| 4458 | + chroma_side, | ||
| 4459 | + chroma_side, | ||
| 4460 | + h_filter, | ||
| 4461 | + v_filter, | ||
| 4462 | + &mut inter1_u, | ||
| 4463 | + ); | ||
| 4464 | + let mut pred_u = vec![0u8; chroma_side * chroma_side]; | ||
| 4465 | + mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u); | ||
| 4466 | + | ||
| 4467 | + let mut inter0_v = vec![0i32; chroma_side * chroma_side]; | ||
| 4468 | + mc::predict_compound_intermediate( | ||
| 4469 | + &pv0.data, | ||
| 4470 | + pv0.width, | ||
| 4471 | + pv0.true_width, | ||
| 4472 | + pv0.true_height, | ||
| 4473 | + mv_to_q4(cpx, mv0.1, false), | ||
| 4474 | + mv_to_q4(cpy, mv0.0, false), | ||
| 4475 | + chroma_side, | ||
| 4476 | + chroma_side, | ||
| 4477 | + h_filter, | ||
| 4478 | + v_filter, | ||
| 4479 | + &mut inter0_v, | ||
| 4480 | + ); | ||
| 4481 | + let mut inter1_v = vec![0i32; chroma_side * chroma_side]; | ||
| 4482 | + mc::predict_compound_intermediate( | ||
| 4483 | + &pv1.data, | ||
| 4484 | + pv1.width, | ||
| 4485 | + pv1.true_width, | ||
| 4486 | + pv1.true_height, | ||
| 4487 | + mv_to_q4(cpx, mv1.1, false), | ||
| 4488 | + mv_to_q4(cpy, mv1.0, false), | ||
| 4489 | + chroma_side, | ||
| 4490 | + chroma_side, | ||
| 4491 | + h_filter, | ||
| 4492 | + v_filter, | ||
| 4493 | + &mut inter1_v, | ||
| 4494 | + ); | ||
| 4495 | + let mut pred_v = vec![0u8; chroma_side * chroma_side]; | ||
| 4496 | + mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); | ||
| 4497 | + | ||
| 4498 | + if skip { | ||
| 4499 | + y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]); | ||
| 4500 | + u.reconstruct_mc( | ||
| 4501 | + cpx, | ||
| 4502 | + cpy, | ||
| 4503 | + chroma_side, | ||
| 4504 | + &pred_u, | ||
| 4505 | + &vec![0i32; chroma_side * chroma_side], | ||
| 4506 | + ); | ||
| 4507 | + v.reconstruct_mc( | ||
| 4508 | + cpx, | ||
| 4509 | + cpy, | ||
| 4510 | + chroma_side, | ||
| 4511 | + &pred_v, | ||
| 4512 | + &vec![0i32; chroma_side * chroma_side], | ||
| 4513 | + ); | ||
| 4514 | + luma_grid = vec![0i32; side * side]; | ||
| 4515 | + u_grid = vec![0i32; chroma_side * chroma_side]; | ||
| 4516 | + v_grid = vec![0i32; chroma_side * chroma_side]; | ||
| 4517 | + } else { | ||
| 4518 | + let around = neighbours.around(at, side); | ||
| 4519 | + luma_grid = read_inter_plane( | ||
| 4520 | + dec, | ||
| 4521 | + cdfs, | ||
| 4522 | + luma_set_inter, | ||
| 4523 | + scan_luma, | ||
| 4524 | + 0, | ||
| 4525 | + around[0], | ||
| 4526 | + mode_for_tx, | ||
| 4527 | + y, | ||
| 4528 | + px, | ||
| 4529 | + py, | ||
| 4530 | + side, | ||
| 4531 | + base_q_idx, | ||
| 4532 | + &pred_y, | ||
| 4533 | + )?; | ||
| 4534 | + u_grid = read_inter_plane( | ||
| 4535 | + dec, | ||
| 4536 | + cdfs, | ||
| 4537 | + chroma_set, | ||
| 4538 | + scan_chroma, | ||
| 4539 | + 1, | ||
| 4540 | + around[1], | ||
| 4541 | + mode_for_tx, | ||
| 4542 | + u, | ||
| 4543 | + cpx, | ||
| 4544 | + cpy, | ||
| 4545 | + chroma_side, | ||
| 4546 | + base_q_idx, | ||
| 4547 | + &pred_u, | ||
| 4548 | + )?; | ||
| 4549 | + v_grid = read_inter_plane( | ||
| 4550 | + dec, | ||
| 4551 | + cdfs, | ||
| 4552 | + chroma_set, | ||
| 4553 | + scan_chroma, | ||
| 4554 | + 2, | ||
| 4555 | + around[2], | ||
| 4556 | + mode_for_tx, | ||
| 4557 | + v, | ||
| 4558 | + cpx, | ||
| 4559 | + cpy, | ||
| 4560 | + chroma_side, | ||
| 4561 | + base_q_idx, | ||
| 4562 | + &pred_v, | ||
| 4563 | + )?; | ||
| 4564 | + } | ||
| 4565 | + } else { | ||
| 4188 | let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | 4566 | let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); |
| 4189 | ref_frame_for_lf = ref_frame; | 4567 | ref_frame_for_lf = ref_frame; |
| 4190 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own | 4568 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own |
| @@ -4460,6 +4838,7 @@ fn decode_inter_block( | |||
| 4460 | &pred_v, | 4838 | &pred_v, |
| 4461 | )?; | 4839 | )?; |
| 4462 | } | 4840 | } |
| 4841 | + } | ||
| 4463 | } else { | 4842 | } else { |
| 4464 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); | 4843 | let mode = dec.symbol(&mut cdfs.y_mode[size_group]); |
| 4465 | if mode >= 13 { | 4844 | if mode >= 13 { |
| @@ -4615,6 +4994,9 @@ fn decode_inter_block( | |||
| 4615 | } | 4994 | } |
| 4616 | neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); | 4995 | neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); |
| 4617 | neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter); | 4996 | 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); | ||
| 4999 | + } | ||
| 4618 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); | 5000 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 4619 | neighbours.fill_lf_grid( | 5001 | neighbours.fill_lf_grid( |
| 4620 | (r * (SUB / MI), c * (SUB / MI)), | 5002 | (r * (SUB / MI), c * (SUB / MI)), |
| @@ -5166,6 +5548,8 @@ pub fn decode_inter_frame_tile( | |||
| 5166 | [0; 7], | 5548 | [0; 7], |
| 5167 | None, | 5549 | None, |
| 5168 | reference_select, | 5550 | reference_select, |
| 5551 | + false, | ||
| 5552 | + false, | ||
| 5169 | ) | 5553 | ) |
| 5170 | .map(|(picture, _, _)| picture) | 5554 | .map(|(picture, _, _)| picture) |
| 5171 | } | 5555 | } |
| @@ -5203,6 +5587,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 5203 | // lane-av1comp: this frame header's own `reference_select` bit, threaded | 5587 | // lane-av1comp: this frame header's own `reference_select` bit, threaded |
| 5204 | // to every `decode_inter_block`/`decode_inter_block8` call below. | 5588 | // to every `decode_inter_block`/`decode_inter_block8` call below. |
| 5205 | reference_select: bool, | 5589 | reference_select: bool, |
| 5590 | + // lane-av1comp: `seq_params`' own compound-blend enable bits. | ||
| 5591 | + enable_masked_compound: bool, | ||
| 5592 | + enable_jnt_comp: bool, | ||
| 5206 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { | 5593 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 5207 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { | 5594 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 5208 | field, | 5595 | field, |
| @@ -5400,6 +5787,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 5400 | enable_dual_filter, | 5787 | enable_dual_filter, |
| 5401 | tpl_frame.as_ref(), | 5788 | tpl_frame.as_ref(), |
| 5402 | reference_select, | 5789 | reference_select, |
| 5790 | + enable_masked_compound, | ||
| 5791 | + enable_jnt_comp, | ||
| 5792 | + order_hint_bits, | ||
| 5793 | + order_hint, | ||
| 5794 | + ref_order_hints, | ||
| 5403 | )?; | 5795 | )?; |
| 5404 | } | 5796 | } |
| 5405 | PARTITION_SPLIT => { | 5797 | PARTITION_SPLIT => { |
| @@ -5459,6 +5851,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 5459 | enable_dual_filter, | 5851 | enable_dual_filter, |
| 5460 | tpl_frame.as_ref(), | 5852 | tpl_frame.as_ref(), |
| 5461 | reference_select, | 5853 | reference_select, |
| 5854 | + enable_masked_compound, | ||
| 5855 | + enable_jnt_comp, | ||
| 5856 | + order_hint_bits, | ||
| 5857 | + order_hint, | ||
| 5858 | + ref_order_hints, | ||
| 5462 | )?; | 5859 | )?; |
| 5463 | } else { | 5860 | } else { |
| 5464 | let ctx16 = neighbours.partition_ctx(at16, SUB); | 5861 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| @@ -6231,6 +6628,11 @@ mod tests { | |||
| 6231 | false, | 6628 | false, |
| 6232 | None, | 6629 | None, |
| 6233 | false, | 6630 | false, |
| 6631 | + false, | ||
| 6632 | + false, | ||
| 6633 | + 0, | ||
| 6634 | + 0, | ||
| 6635 | + [0; 7], | ||
| 6234 | ) | 6636 | ) |
| 6235 | .unwrap(); | 6637 | .unwrap(); |
| 6236 | 6638 | ||
crates/ec-av1/src/stream.rsmodified+9 -0
| @@ -219,6 +219,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 219 | let enable_edge_filter = parser | 219 | let enable_edge_filter = parser |
| 220 | .sequence_header() | 220 | .sequence_header() |
| 221 | .is_some_and(|seq| seq.enable_intra_edge_filter); | 221 | .is_some_and(|seq| seq.enable_intra_edge_filter); |
| 222 | + // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits. | ||
| 223 | + let enable_masked_compound = parser | ||
| 224 | + .sequence_header() | ||
| 225 | + .is_some_and(|seq| seq.enable_masked_compound); | ||
| 226 | + let enable_jnt_comp = parser | ||
| 227 | + .sequence_header() | ||
| 228 | + .is_some_and(|seq| seq.enable_jnt_comp); | ||
| 222 | let interp_fixed = match header.interpolation_filter { | 229 | let interp_fixed = match header.interpolation_filter { |
| 223 | ec_av1_syntax::InterpolationFilter::Switchable => None, | 230 | ec_av1_syntax::InterpolationFilter::Switchable => None, |
| 224 | fixed => Some(crate::mc::InterpFilterKind::from_header(fixed)), | 231 | fixed => Some(crate::mc::InterpFilterKind::from_header(fixed)), |
| @@ -339,6 +346,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 339 | ref_order_hints, | 346 | ref_order_hints, |
| 340 | tpl_field.as_ref(), | 347 | tpl_field.as_ref(), |
| 341 | header.reference_select, | 348 | header.reference_select, |
| 349 | + enable_masked_compound, | ||
| 350 | + enable_jnt_comp, | ||
| 342 | )? | 351 | )? |
| 343 | }; | 352 | }; |
| 344 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's | 353 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's |