wip(av1): WARPED_CAUSAL motion_mode alphabet + num_proj_ref -- COMPILING WIP
Browse files at this commitbd6939de344069a4032bf90532ddef1521bc9301Parent: a370dc23 changed files +253 -22
- crates/ec-av1/src/cdf.rs +14 -0
- crates/ec-av1/src/cdf_state.rs +8 -0
- crates/ec-av1/src/decode.rs +231 -22
crates/ec-av1/src/cdf.rsmodified+14 -0
| @@ -1218,6 +1218,20 @@ pub const OBMC: [[u16; 3]; 4] = [ | ||
| 1218 | 1218 | [30128, 32768, 0], |
| 1219 | 1219 | ]; |
| 1220 | 1220 | |
| 1221 | +/// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize | |
| 1222 | +/// rows only (`BLOCK_8X8`/`16X16`/`32X32`/`64X64` -- indices 3/6/9/12 of | |
| 1223 | +/// libaom's `BLOCK_SIZES_ALL`, same square subset [`OBMC`] keeps): the | |
| 1224 | +/// 3-symbol `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet | |
| 1225 | +/// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` | |
| 1226 | +/// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` | |
| 1227 | +/// under `allow_warped_motion`) -- lane-warp round 1. | |
| 1228 | +pub const MOTION_MODE: [[u16; 4]; 4] = [ | |
| 1229 | + [7651, 24760, 32768, 0], | |
| 1230 | + [19419, 26810, 32768, 0], | |
| 1231 | + [26260, 29116, 32768, 0], | |
| 1232 | + [29516, 30701, 32768, 0], | |
| 1233 | +]; | |
| 1234 | + | |
| 1221 | 1235 | /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by |
| 1222 | 1236 | /// `size_group_lookup[bsize]` (0..=3) -- read only when the sequence header's |
| 1223 | 1237 | /// `enable_interintra_compound` is set and `is_interintra_allowed(mbmi)` |
crates/ec-av1/src/cdf_state.rsmodified+8 -0
| @@ -327,6 +327,12 @@ pub(crate) struct Cdfs { | ||
| 327 | 327 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- |
| 328 | 328 | /// this decoder only ever codes those four square sizes). |
| 329 | 329 | pub obmc: [[u16; 3]; 4], |
| 330 | + /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol | |
| 331 | + /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read | |
| 332 | + /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to | |
| 333 | + /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. | |
| 334 | + /// lane-warp round 1. | |
| 335 | + pub motion_mode: [[u16; 4]; 4], | |
| 330 | 336 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see |
| 331 | 337 | /// `cdf::INTERINTRA`'s own doc. |
| 332 | 338 | pub interintra: [[u16; 3]; 4], |
| @@ -561,6 +567,7 @@ impl Cdfs { | ||
| 561 | 567 | reset2(&mut self.comp_mode); |
| 562 | 568 | reset2(&mut self.skip_mode); |
| 563 | 569 | reset2(&mut self.obmc); |
| 570 | + reset2(&mut self.motion_mode); | |
| 564 | 571 | reset2(&mut self.interintra); |
| 565 | 572 | reset2(&mut self.inter_compound_mode); |
| 566 | 573 | reset2(&mut self.comp_ref_type); |
| @@ -1003,6 +1010,7 @@ impl Cdfs { | ||
| 1003 | 1010 | comp_bwdref: cdf::COMP_BWDREF, |
| 1004 | 1011 | skip_mode: cdf::SKIP_MODE, |
| 1005 | 1012 | obmc: cdf::OBMC, |
| 1013 | + motion_mode: cdf::MOTION_MODE, | |
| 1006 | 1014 | interintra: cdf::INTERINTRA, |
| 1007 | 1015 | comp_group_idx: cdf::COMP_GROUP_IDX, |
| 1008 | 1016 | compound_idx: cdf::COMPOUND_IDX, |
crates/ec-av1/src/decode.rsmodified+231 -22
| @@ -176,6 +176,19 @@ pub(crate) fn obmc_hits() -> usize { | ||
| 176 | 176 | /// 8x8-leaf OBMC block apart from a 16x16+ one. |
| 177 | 177 | static OBMC_HITS_8: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 178 | 178 | |
| 179 | +/// lane-warp round 1: how many blocks resolved `motion_mode_allowed` to | |
| 180 | +/// `WARPED_CAUSAL`-eligible (3-symbol read, `num_proj_ref >= 1` under | |
| 181 | +/// `allow_warped_motion`) AND the symbol actually decoded to `WARPED_CAUSAL` | |
| 182 | +/// -- the gate's proof that a fixture really exercises the alphabet this | |
| 183 | +/// round changed, even though the block itself still refuses (warp | |
| 184 | +/// estimation/filter not ported). | |
| 185 | +static WARP_SELECTED_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | |
| 186 | + | |
| 187 | +/// Current value of [`WARP_SELECTED_HITS`]. | |
| 188 | +pub(crate) fn warp_selected_hits() -> usize { | |
| 189 | + WARP_SELECTED_HITS.load(std::sync::atomic::Ordering::Relaxed) | |
| 190 | +} | |
| 191 | + | |
| 179 | 192 | /// Current value of [`OBMC_HITS_8`]. |
| 180 | 193 | pub(crate) fn obmc_hits_8() -> usize { |
| 181 | 194 | OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed) |
| @@ -4107,6 +4120,165 @@ fn overlappable_left( | ||
| 4107 | 4120 | out |
| 4108 | 4121 | } |
| 4109 | 4122 | |
| 4123 | +/// `has_top_right` (`av1/common/mvref_common.c`), reduced to the | |
| 4124 | +/// square-block, fixed-64px-superblock case this decoder ever reaches: no | |
| 4125 | +/// rectangular partition (`VERT`/`HORZ`/`_4`/`VERT_A`) ever produces an | |
| 4126 | +/// inter leaf here (`xd->width == xd->height` always), so libaom's own | |
| 4127 | +/// rect-partition branches (`xd->width < xd->height`, `xd->width > | |
| 4128 | +/// xd->height`, `PARTITION_VERT_A`) never fire and are dropped. `bs` is the | |
| 4129 | +/// block's own side in 4x4 (`mi`) units. | |
| 4130 | +fn has_top_right(mi_row: usize, mi_col: usize, bs: usize) -> bool { | |
| 4131 | + let sb_mi_size = SB_MI as usize; | |
| 4132 | + let mask_row = mi_row & (sb_mi_size - 1); | |
| 4133 | + let mask_col = mi_col & (sb_mi_size - 1); | |
| 4134 | + if bs > sb_mi_size { | |
| 4135 | + return false; | |
| 4136 | + } | |
| 4137 | + let mut has_tr = !((mask_row & bs != 0) && (mask_col & bs != 0)); | |
| 4138 | + let mut b = bs; | |
| 4139 | + while b < sb_mi_size { | |
| 4140 | + if mask_col & b != 0 { | |
| 4141 | + if (mask_col & (2 * b) != 0) && (mask_row & (2 * b) != 0) { | |
| 4142 | + has_tr = false; | |
| 4143 | + break; | |
| 4144 | + } | |
| 4145 | + } else { | |
| 4146 | + break; | |
| 4147 | + } | |
| 4148 | + b <<= 1; | |
| 4149 | + } | |
| 4150 | + has_tr | |
| 4151 | +} | |
| 4152 | + | |
| 4153 | +/// `av1_findSamples`' sample *count* only (`mvref_common.c`): the number of | |
| 4154 | +/// above/left/top-left/top-right neighbours (up to `LEAST_SQUARES_SAMPLES_MAX | |
| 4155 | +/// = 8`) that share this block's own single reference frame and are | |
| 4156 | +/// themselves single-ref -- exactly `mbmi->num_proj_ref`. The actual sample | |
| 4157 | +/// coordinates (`record_samples`, `pts`/`pts_inref`) feed the warp parameter | |
| 4158 | +/// *estimation* (`av1_find_projection`), not ported this round -- only the | |
| 4159 | +/// count is needed to resolve `motion_mode_allowed`'s `WARPED_CAUSAL` vs | |
| 4160 | +/// `OBMC_CAUSAL` alphabet choice (spec 5.11.24), so that's all this port | |
| 4161 | +/// keeps. `bw4` is the block's own side in 4x4 units (square, so also | |
| 4162 | +/// `bh4`; a real block's `xd->width`/`xd->height` in libaom are also mi | |
| 4163 | +/// units of that same square side here). | |
| 4164 | +fn num_proj_ref( | |
| 4165 | + grid: &MiGrid, | |
| 4166 | + mi_row: usize, | |
| 4167 | + mi_col: usize, | |
| 4168 | + bw4: usize, | |
| 4169 | + mi_cols: usize, | |
| 4170 | + mi_rows: usize, | |
| 4171 | + ref_frame: i8, | |
| 4172 | +) -> u8 { | |
| 4173 | + const MAX: u8 = 8; | |
| 4174 | + let up_available = mi_row > 0; | |
| 4175 | + let left_available = mi_col > 0; | |
| 4176 | + let mut np = 0u8; | |
| 4177 | + let single_ref_match = |info: &MiInfo| info.ref_frame == ref_frame && info.ref_frame1.is_none(); | |
| 4178 | + let mut do_tl = true; | |
| 4179 | + let mut do_tr = true; | |
| 4180 | + | |
| 4181 | + if up_available { | |
| 4182 | + let above = grid.get(mi_row - 1, mi_col); | |
| 4183 | + let superblock_width = above.map_or(1, |c| c.size).max(1); | |
| 4184 | + if bw4 <= superblock_width { | |
| 4185 | + let col_offset = -((mi_col % superblock_width) as isize); | |
| 4186 | + if col_offset < 0 { | |
| 4187 | + do_tl = false; | |
| 4188 | + } | |
| 4189 | + if col_offset + superblock_width as isize > bw4 as isize { | |
| 4190 | + do_tr = false; | |
| 4191 | + } | |
| 4192 | + if let Some(info) = above { | |
| 4193 | + if single_ref_match(info) { | |
| 4194 | + np += 1; | |
| 4195 | + if np >= MAX { | |
| 4196 | + return MAX; | |
| 4197 | + } | |
| 4198 | + } | |
| 4199 | + } | |
| 4200 | + } else { | |
| 4201 | + let mut i = 0usize; | |
| 4202 | + let limit = bw4.min(mi_cols.saturating_sub(mi_col)); | |
| 4203 | + while i < limit { | |
| 4204 | + let cell = grid.get(mi_row - 1, mi_col + i); | |
| 4205 | + let sw = cell.map_or(1, |c| c.size).max(1); | |
| 4206 | + if let Some(info) = cell { | |
| 4207 | + if single_ref_match(info) { | |
| 4208 | + np += 1; | |
| 4209 | + if np >= MAX { | |
| 4210 | + return MAX; | |
| 4211 | + } | |
| 4212 | + } | |
| 4213 | + } | |
| 4214 | + i += sw; | |
| 4215 | + } | |
| 4216 | + } | |
| 4217 | + } | |
| 4218 | + | |
| 4219 | + if left_available { | |
| 4220 | + let left = grid.get(mi_row, mi_col - 1); | |
| 4221 | + let superblock_height = left.map_or(1, |c| c.size).max(1); | |
| 4222 | + if bw4 <= superblock_height { | |
| 4223 | + let row_offset = -((mi_row % superblock_height) as isize); | |
| 4224 | + if row_offset < 0 { | |
| 4225 | + do_tl = false; | |
| 4226 | + } | |
| 4227 | + if let Some(info) = left { | |
| 4228 | + if single_ref_match(info) { | |
| 4229 | + np += 1; | |
| 4230 | + if np >= MAX { | |
| 4231 | + return MAX; | |
| 4232 | + } | |
| 4233 | + } | |
| 4234 | + } | |
| 4235 | + } else { | |
| 4236 | + let mut i = 0usize; | |
| 4237 | + let limit = bw4.min(mi_rows.saturating_sub(mi_row)); | |
| 4238 | + while i < limit { | |
| 4239 | + let cell = grid.get(mi_row + i, mi_col - 1); | |
| 4240 | + let sh = cell.map_or(1, |c| c.size).max(1); | |
| 4241 | + if let Some(info) = cell { | |
| 4242 | + if single_ref_match(info) { | |
| 4243 | + np += 1; | |
| 4244 | + if np >= MAX { | |
| 4245 | + return MAX; | |
| 4246 | + } | |
| 4247 | + } | |
| 4248 | + } | |
| 4249 | + i += sh; | |
| 4250 | + } | |
| 4251 | + } | |
| 4252 | + } | |
| 4253 | + | |
| 4254 | + if do_tl && left_available && up_available { | |
| 4255 | + if let Some(info) = grid.get(mi_row - 1, mi_col - 1) { | |
| 4256 | + if single_ref_match(info) { | |
| 4257 | + np += 1; | |
| 4258 | + if np >= MAX { | |
| 4259 | + return MAX; | |
| 4260 | + } | |
| 4261 | + } | |
| 4262 | + } | |
| 4263 | + } | |
| 4264 | + | |
| 4265 | + if do_tr && has_top_right(mi_row, mi_col, bw4) { | |
| 4266 | + let tr_col = mi_col + bw4; | |
| 4267 | + if mi_row > 0 && tr_col < mi_cols { | |
| 4268 | + if let Some(info) = grid.get(mi_row - 1, tr_col) { | |
| 4269 | + if single_ref_match(info) { | |
| 4270 | + np += 1; | |
| 4271 | + if np >= MAX { | |
| 4272 | + return MAX; | |
| 4273 | + } | |
| 4274 | + } | |
| 4275 | + } | |
| 4276 | + } | |
| 4277 | + } | |
| 4278 | + | |
| 4279 | + np | |
| 4280 | +} | |
| 4281 | + | |
| 4110 | 4282 | /// `av1_get_obmc_mask` (`reconinter.c`): the per-position blend weight |
| 4111 | 4283 | /// (`AOM_BLEND_A64` numerator, out of 64) for the neighbour's own |
| 4112 | 4284 | /// contribution's *complement* -- i.e. `dst = (mask*orig + (64-mask)*nbr + |
| @@ -5474,18 +5646,37 @@ fn decode_inter_block( | ||
| 5474 | 5646 | .is_empty()); |
| 5475 | 5647 | let mut obmc_selected = false; |
| 5476 | 5648 | if motion_mode_eligible { |
| 5477 | - if allow_warped_motion { | |
| 5478 | - return Err(unsupported( | |
| 5479 | - "a motion-variation-eligible block under allow_warped_motion=1 \ | |
| 5480 | - (round 1 only reads the 2-symbol obmc_cdf; telling OBMC_CAUSAL \ | |
| 5481 | - from WARPED_CAUSAL needs av1_findSamples, not ported)", | |
| 5482 | - )); | |
| 5483 | - } | |
| 5484 | 5649 | // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. |
| 5485 | 5650 | let bsize_idx = (side.trailing_zeros() - 3) as usize; |
| 5486 | - obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1; | |
| 5487 | - if obmc_selected { | |
| 5488 | - OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 5651 | + // lane-warp round 1: `motion_mode_allowed` reads the 3-symbol | |
| 5652 | + // `motion_mode_cdf` instead of the 2-symbol `obmc_cdf` exactly | |
| 5653 | + // when `num_proj_ref >= 1` under `allow_warped_motion` (see | |
| 5654 | + // `num_proj_ref`'s own doc -- only the *count* is ported, | |
| 5655 | + // not the sample coordinates the warp estimation needs). | |
| 5656 | + let warp_eligible = allow_warped_motion | |
| 5657 | + && num_proj_ref(grid, mi_row, mi_col, bw4, mi_cols as usize, mi_rows as usize, ref_frame) >= 1; | |
| 5658 | + if warp_eligible { | |
| 5659 | + let mode = dec.symbol(&mut cdfs.motion_mode[bsize_idx]); | |
| 5660 | + match mode { | |
| 5661 | + 0 => {} | |
| 5662 | + 1 => { | |
| 5663 | + obmc_selected = true; | |
| 5664 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 5665 | + } | |
| 5666 | + _ => { | |
| 5667 | + WARP_SELECTED_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 5668 | + return Err(unsupported( | |
| 5669 | + "a block that coded WARPED_CAUSAL (motion_mode == 2): \ | |
| 5670 | + av1_find_projection/the affine warp filter are not \ | |
| 5671 | + ported, only motion_mode_allowed's alphabet choice is", | |
| 5672 | + )); | |
| 5673 | + } | |
| 5674 | + } | |
| 5675 | + } else { | |
| 5676 | + obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1; | |
| 5677 | + if obmc_selected { | |
| 5678 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 5679 | + } | |
| 5489 | 5680 | } |
| 5490 | 5681 | } |
| 5491 | 5682 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| @@ -6445,18 +6636,36 @@ fn decode_inter_block8( | ||
| 6445 | 6636 | || !overlappable_left(grid, mi_row, mi_col, 2, mi_rows as usize, 1).is_empty()); |
| 6446 | 6637 | let mut obmc_selected = false; |
| 6447 | 6638 | if motion_mode_eligible { |
| 6448 | - if allow_warped_motion { | |
| 6449 | - return Err(unsupported( | |
| 6450 | - "a motion-variation-eligible 8x8 leaf under allow_warped_motion=1 \ | |
| 6451 | - (round 3 only reads the 2-symbol obmc_cdf; telling OBMC_CAUSAL \ | |
| 6452 | - from WARPED_CAUSAL needs av1_findSamples, not ported)", | |
| 6453 | - )); | |
| 6454 | - } | |
| 6455 | - // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. | |
| 6456 | - obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1; | |
| 6457 | - if obmc_selected { | |
| 6458 | - OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6459 | - OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6639 | + // lane-warp round 1: same 3-vs-2-symbol split as the 16x16+ leaf | |
| 6640 | + // (see its own doc) -- this leaf is always `LAST_FRAME`-only | |
| 6641 | + // (grid.set below hardcodes it). | |
| 6642 | + let warp_eligible = allow_warped_motion | |
| 6643 | + && num_proj_ref(grid, mi_row, mi_col, 2, mi_cols as usize, mi_rows as usize, LAST_FRAME) >= 1; | |
| 6644 | + if warp_eligible { | |
| 6645 | + let mode = dec.symbol(&mut cdfs.motion_mode[0]); | |
| 6646 | + match mode { | |
| 6647 | + 0 => {} | |
| 6648 | + 1 => { | |
| 6649 | + obmc_selected = true; | |
| 6650 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6651 | + OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6652 | + } | |
| 6653 | + _ => { | |
| 6654 | + WARP_SELECTED_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6655 | + return Err(unsupported( | |
| 6656 | + "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): \ | |
| 6657 | + av1_find_projection/the affine warp filter are not \ | |
| 6658 | + ported, only motion_mode_allowed's alphabet choice is", | |
| 6659 | + )); | |
| 6660 | + } | |
| 6661 | + } | |
| 6662 | + } else { | |
| 6663 | + // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. | |
| 6664 | + obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1; | |
| 6665 | + if obmc_selected { | |
| 6666 | + OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6667 | + OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 6668 | + } | |
| 6460 | 6669 | } |
| 6461 | 6670 | } |
| 6462 | 6671 | for dr in 0..2 { |