edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | //! Sub-8x8 inter and intra leaf decoders (split4 and rect2 paths). Moved out of `decode/mod.rs` (av1split D7); the items are unchanged apart from `pub(super)` visibility. |
| 2 | |
| 3 | use super::*; |
| 4 | |
| 5 | /// Decodes one 8x8 group that an inter frame's `partition_w8` symbol split |
| 6 | /// into four `BLOCK_4X4` inter blocks (lane-intersub8: `PARTITION_SPLIT` |
| 7 | /// below 8x8 -- traced live against the oracle `aomdec`'s own `EC_PART_VAL`, |
| 8 | /// which reads `bsize=3 value=3` on real inter frames, so the refusal this |
| 9 | /// replaces was NOT our own desync). |
| 10 | /// |
| 11 | /// The inter counterpart of [`decode_leaf_split4`], and a `BLOCK_4X4`-only |
| 12 | /// cut of [`decode_inter_block8`]: at `min(bw, bh) < 8` libaom switches off |
| 13 | /// half the inter syntax, and every one of those is a symbol NOT read here |
| 14 | /// (`decodemv.c` / `blockd.h`, oracle tree): |
| 15 | /// * `skip_mode`: `read_skip_mode` returns 0 without a symbol when |
| 16 | /// `!is_comp_ref_allowed(bsize)` (`AOMMIN(bw, bh) >= 8`, blockd.h). |
| 17 | /// * `comp_mode`: `read_block_reference_mode` returns `SINGLE_REFERENCE` on |
| 18 | /// the same predicate, so a sub-8x8 block is always single-reference. |
| 19 | /// * `interintra`: `is_interintra_allowed_bsize` starts at `BLOCK_8X8`. |
| 20 | /// * `motion_mode` / `obmc`: `motion_mode_allowed` returns |
| 21 | /// `SIMPLE_TRANSLATION` for `block_size_wide < 8 || block_size_high < 8`, |
| 22 | /// and `is_global_mv_block`'s own size term fails, so no warp either. |
| 23 | /// * tx size: `block_signals_txsize(bsize)` is `bsize > BLOCK_4X4` |
| 24 | /// (blockd.h:1027), so a `BLOCK_4X4` reads neither `tx_depth` nor a |
| 25 | /// `txfm_partition` bit even in `TX_MODE_SELECT` -- the transform is |
| 26 | /// `max_txsize_rect_lookup[BLOCK_4X4]` = `TX_4X4` |
| 27 | /// (`decodeframe.c:1164-1177`). |
| 28 | /// |
| 29 | /// Chroma is coded ONCE for the whole 8x8 group, on the last sub-block |
| 30 | /// (`is_chroma_reference`: `(mi_row & 1) && (mi_col & 1)` in 4:2:0), as one |
| 31 | /// `TX_4X4` unit per plane -- same rule and same neighbour-context tail as |
| 32 | /// [`decode_leaf_split4`]. Its PREDICTION is the sub8x8 one |
| 33 | /// (`dec_build_inter_predictors`'s `is_sub8x8` branch, `decodeframe.c`; spec |
| 34 | /// 7.11.3.1's `candRow`/`candCol` loop): four 2x2 chroma pieces, each built |
| 35 | /// from its own luma sub-block's reference, motion vector and interpolation |
| 36 | /// filters, never from the last sub-block's mv alone. |
| 37 | #[allow(clippy::too_many_arguments)] |
| 38 | pub(super) fn decode_inter_sub8_split4( |
| 39 | dec: &mut SymbolDecoder, |
| 40 | cdfs: &mut Cdfs, |
| 41 | neighbours: &mut Neighbours, |
| 42 | grid: &mut MiGrid, |
| 43 | group_mi: (usize, usize), |
| 44 | mi_cols: u32, |
| 45 | mi_rows: u32, |
| 46 | y: &mut PlaneBuf<'static>, |
| 47 | u: &mut PlaneBuf<'static>, |
| 48 | v: &mut PlaneBuf<'static>, |
| 49 | refpix: &RefPix<'_>, |
| 50 | sign_bias_table: &SignBiasTable, |
| 51 | global_motion: &[ec_av1_syntax::WarpParams; 7], |
| 52 | base_q_idx: u8, |
| 53 | scan4: &[u16], |
| 54 | allow_high_precision_mv: bool, |
| 55 | force_integer_mv: bool, |
| 56 | interp_fixed: Option<mc::InterpFilterKind>, |
| 57 | enable_dual_filter: bool, |
| 58 | tpl_frame: Option<&TplFrameArgs>, |
| 59 | reduced_tx_set: bool, |
| 60 | frame_size: (usize, usize), |
| 61 | fctx: &crate::decode::FrameCtx, |
| 62 | ) -> Result<()> { |
| 63 | const LAST_FRAME: i8 = 1; |
| 64 | const B4: usize = 4; |
| 65 | hit!(SUB8_INTER_SPLIT_HITS); |
| 66 | let (gr, gc) = group_mi; |
| 67 | let (gpx, gpy) = (gc * MI, gr * MI); |
| 68 | let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); |
| 69 | // Per-sub-block state the group's chroma prediction needs (spec |
| 70 | // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/ |
| 71 | // filters), indexed `dr * 2 + dc`. |
| 72 | let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] = |
| 73 | [None; 4]; |
| 74 | let mut first_tx_type = TxType::DctDct; |
| 75 | let mut sub0_tx_type = TxType::DctDct; |
| 76 | // This loop iteration's own sub-block luma `tx_type` (libaom `mbmi->tx_type` |
| 77 | // after its `read_tx_type`): the per-piece 4:4:4 chroma units inherit it |
| 78 | // (`av1_get_tx_type`, blockd.h -- inter chroma never codes its own symbol). |
| 79 | let mut piece_tx_type = TxType::DctDct; |
| 80 | let mut last_skip = true; |
| 81 | // Set when the chroma-reference (last) sub-block is INTRA: it coded the |
| 82 | // group's one chroma unit itself. |
| 83 | let mut intra_chroma = false; |
| 84 | // 4:4:4 (lane-av1-444): `is_chroma_reference` is unconditional at |
| 85 | // subsampling 0/0, so EVERY 4x4 sub-block codes its own 4x4 chroma unit |
| 86 | // right after its own luma (aomdec EC_COEFF on `av1-profile1-444.ivf` |
| 87 | // frame 1: plane 0,1,2 per leaf in leaf order) -- there is no shared |
| 88 | // group unit and no 2x2-piece group prediction. |
| 89 | let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; |
| 90 | // 4:2:2 (lane-av1-422sub8rect): `is_chroma_reference` for a BLOCK_4X4 |
| 91 | // piece at ss (1, 0) is `(mi_col & 0x01) || !(bw & 0x01) || !ss_x` |
| 92 | // == ODD mi_col (av1_common_int.h:1459) -- pieces 1 and 3 of the group |
| 93 | // are their plane's own chroma references and each codes its own |
| 94 | // TX_4X4 unit right after its luma, exactly the key-frame split-group |
| 95 | // behaviour the pinned t422 fixture's frame 0 traces (groups (18,54) |
| 96 | // and (30,42): U+V read on BOTH odd-column leaves) and frame 1's |
| 97 | // inter group at mi(12,2) repeats (U+V TX_4X4 ctx 8 on leaf (12,3) |
| 98 | // alone -- the bottom-right leaf was skipped, so it codes nothing). |
| 99 | // The 4:2:0 shared group unit never exists at 4:2:2. |
| 100 | let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; |
| 101 | for i in 0..4usize { |
| 102 | let (dr, dc) = (i / 2, i % 2); |
| 103 | let lmi = (gr + dr, gc + dc); |
| 104 | if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { |
| 105 | continue; |
| 106 | } |
| 107 | let (rmi, cmi) = lmi; |
| 108 | let (px, py) = (cmi * MI, rmi * MI); |
| 109 | inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, false, true, fctx); |
| 110 | // No `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_4X4)` is false. |
| 111 | let skip_ctx = |
| 112 | usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); |
| 113 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 114 | let ec_skip_post = if std::env::var_os("EC_DBG_SUB8").is_some() { |
| 115 | Some(dec.debug_state().0) |
| 116 | } else { |
| 117 | None |
| 118 | }; |
| 119 | inter_segment_id(dec, cdfs, rmi, cmi, 1, 1, skip, false, fctx); |
| 120 | maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); |
| 121 | maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); |
| 122 | maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); |
| 123 | let (has_above, has_left) = (rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi); |
| 124 | let ii_ctx = intra_inter_ctx( |
| 125 | has_above, |
| 126 | has_left, |
| 127 | neighbours.above_inter[cmi], |
| 128 | neighbours.left_inter[rmi], |
| 129 | ); |
| 130 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 131 | if std::env::var_os("EC_DBG_SUB8").is_some() { |
| 132 | eprintln!( |
| 133 | "EC_DBG piece mi=({rmi},{cmi}) skip={skip} skipctx={skip_ctx} skip_post={:?} is_inter={is_inter} iictx={ii_ctx} post={}", |
| 134 | ec_skip_post, |
| 135 | dec.debug_state().0 |
| 136 | ); |
| 137 | } |
| 138 | if !is_inter { |
| 139 | if crate::envflags::env_flag!("EC_SUB8INTRA") { |
| 140 | eprintln!( |
| 141 | "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}", |
| 142 | i == 3, |
| 143 | fctx.tx_select_inter.with(std::cell::Cell::get), |
| 144 | ); |
| 145 | } |
| 146 | // lane-sub8x4 r2: the refusal and its `EC_SUB8INTRA_DECODE` bypass |
| 147 | // are gone -- `a_real_aomenc_inter_sequence_with_intra_sub8x8_ |
| 148 | // leaves_decodes_pixel_exact` (stream.rs) decodes 12 real aomenc |
| 149 | // streams carrying this arm pixel-exact vs ffmpeg. |
| 150 | hit_do! { |
| 151 | SUB8_INTRA_RECT_HITS.with(|h| { |
| 152 | let mut st = h.get(); |
| 153 | st[4] += 1; |
| 154 | h.set(st); |
| 155 | }); |
| 156 | } |
| 157 | // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm -- |
| 158 | // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on |
| 159 | // the chroma-reference sub-blocks (`is_chroma_reference`: the |
| 160 | // LAST one under 4:2:0, BOTH odd-column ones at 4:2:2, every |
| 161 | // one at 4:4:4). |
| 162 | decode_intra_sub8_leaf( |
| 163 | dec, |
| 164 | cdfs, |
| 165 | neighbours, |
| 166 | grid, |
| 167 | group_mi, |
| 168 | lmi, |
| 169 | (B4, B4), |
| 170 | chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3, |
| 171 | skip, |
| 172 | scan4, |
| 173 | y, |
| 174 | u, |
| 175 | v, |
| 176 | base_q_idx, |
| 177 | fctx.enable_filter_intra_inter.with(std::cell::Cell::get), |
| 178 | fctx.tx_select_inter.with(std::cell::Cell::get), |
| 179 | reduced_tx_set, |
| 180 | fctx, |
| 181 | )?; |
| 182 | if i == 3 { |
| 183 | intra_chroma = true; |
| 184 | } |
| 185 | continue; |
| 186 | } |
| 187 | // Same print point as the oracle's `EC_MODE` (entry of |
| 188 | // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the |
| 189 | // two range ladders line up element for element. |
| 190 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 191 | eprintln!( |
| 192 | "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", |
| 193 | dec.debug_state().0 |
| 194 | ); |
| 195 | } |
| 196 | let ref_frame = read_single_ref( |
| 197 | dec, |
| 198 | cdfs, |
| 199 | neighbours.above_ref[cmi], |
| 200 | neighbours.above_ref1[cmi], |
| 201 | neighbours.left_ref[rmi], |
| 202 | neighbours.left_ref1[rmi], |
| 203 | ); |
| 204 | // lane-sub8group: this piece's reference SIZE at parse, its pictures |
| 205 | // inside the prediction closure below. |
| 206 | let (ref_width, ref_height) = ref_dims(ref_frame, refpix)?; |
| 207 | // lane-t900 r28: refusal lifted -- this sub-block's own reference may |
| 208 | // be scaled (superres); spec 7.11.3.3's walk is per reference, and |
| 209 | // each of the group's pieces (luma and its 2x2 chroma) carries its |
| 210 | // OWN factor because each can name a different `ref_frame`. |
| 211 | let luma_scale = scale_of((ref_width, ref_height), frame_size); |
| 212 | if !luma_scale.is_unscaled() { |
| 213 | hit!(SCALED_SUB8_HITS); |
| 214 | } |
| 215 | let gm_table = build_gm_mv_table( |
| 216 | global_motion, |
| 217 | rmi, |
| 218 | cmi, |
| 219 | 1, |
| 220 | 1, |
| 221 | allow_high_precision_mv, |
| 222 | force_integer_mv, |
| 223 | ); |
| 224 | let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { |
| 225 | field: t.field, |
| 226 | cur_offset_0: crate::motion_field::get_relative_dist( |
| 227 | t.order_hint_bits, |
| 228 | t.order_hint, |
| 229 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 230 | ), |
| 231 | allow_high_precision_mv, |
| 232 | force_integer_mv, |
| 233 | }); |
| 234 | let stack = crate::mvstack::find_mv_stack_with_sign_bias( |
| 235 | grid, |
| 236 | rmi, |
| 237 | cmi, |
| 238 | 1, |
| 239 | 1, |
| 240 | ref_frame, |
| 241 | mi_cols as usize, |
| 242 | mi_rows as usize, |
| 243 | sign_bias_table, |
| 244 | &gm_table, |
| 245 | tpl, |
| 246 | ); |
| 247 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 248 | if !not_new { |
| 249 | crate::census::mode(0); |
| 250 | } |
| 251 | let mut is_globalmv = false; |
| 252 | let (mv, is_new_mv) = if !not_new { |
| 253 | let mut idx = 0usize; |
| 254 | while idx < 2 && stack.entries.len() > idx + 1 { |
| 255 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 256 | break; |
| 257 | } |
| 258 | idx += 1; |
| 259 | } |
| 260 | let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); |
| 261 | ( |
| 262 | read_mv( |
| 263 | dec, |
| 264 | &mut cdfs.mv_comp, |
| 265 | &mut cdfs.mv_joint, |
| 266 | base_mv, |
| 267 | allow_high_precision_mv, |
| 268 | force_integer_mv, |
| 269 | fctx, |
| 270 | ), |
| 271 | true, |
| 272 | ) |
| 273 | } else { |
| 274 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; |
| 275 | if !not_zero { |
| 276 | crate::census::mode(1); |
| 277 | } |
| 278 | is_globalmv = !not_zero; |
| 279 | let mv = if !not_zero { |
| 280 | gm_table[(ref_frame - LAST_FRAME) as usize] |
| 281 | } else { |
| 282 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 283 | crate::census::mode(if nearest { 2 } else { 3 }); |
| 284 | if nearest { |
| 285 | stack.nearest_mv |
| 286 | } else { |
| 287 | let mut idx = 1usize; |
| 288 | while idx < 3 && stack.entries.len() > idx + 1 { |
| 289 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 290 | break; |
| 291 | } |
| 292 | idx += 1; |
| 293 | } |
| 294 | stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) |
| 295 | } |
| 296 | }; |
| 297 | (mv, false) |
| 298 | }; |
| 299 | // Same print point as the oracle's `EC_MODE_MV` (right after |
| 300 | // `assign_mv`), the second rung of the sub-8x8 range ladder. |
| 301 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 302 | eprintln!( |
| 303 | "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}", |
| 304 | mv.0, |
| 305 | mv.1, |
| 306 | dec.debug_state().0 |
| 307 | ); |
| 308 | } |
| 309 | // No `interintra` and no `motion_mode`/`obmc` symbol below 8x8 (see |
| 310 | // this function's own doc); `read_mb_interp_filter` still runs. |
| 311 | let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; |
| 312 | let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame |
| 313 | || neighbours.above_ref1[cmi] == Some(ref_frame) |
| 314 | { |
| 315 | neighbours.above_filter[cmi] |
| 316 | } else { |
| 317 | [3, 3] |
| 318 | }; |
| 319 | let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame |
| 320 | || neighbours.left_ref1[rmi] == Some(ref_frame) |
| 321 | { |
| 322 | neighbours.left_filter[rmi] |
| 323 | } else { |
| 324 | [3, 3] |
| 325 | }; |
| 326 | if crate::envflags::env_flag!("EC_AV1_IFDBG") { |
| 327 | eprintln!( |
| 328 | "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \ |
| 329 | above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}", |
| 330 | neighbours.above_ref[cmi], |
| 331 | neighbours.above_ref1[cmi], |
| 332 | neighbours.above_filter[cmi], |
| 333 | neighbours.left_ref[rmi], |
| 334 | neighbours.left_ref1[rmi], |
| 335 | neighbours.left_filter[rmi], |
| 336 | ); |
| 337 | } |
| 338 | // lane-t900 r9: this reader's sub-blocks have a 4-px side, and libaom |
| 339 | // `is_nontrans_global_motion` returns 0 for |
| 340 | // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model -- |
| 341 | // so a GLOBALMV sub-block here always reads its interp filter. |
| 342 | if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation { |
| 343 | hit!(GM_NONTRANS_SMALL_SIDE_HITS); |
| 344 | } |
| 345 | let gm_nontrans = false; |
| 346 | let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( |
| 347 | dec, |
| 348 | cdfs, |
| 349 | interp_fixed, |
| 350 | enable_dual_filter, |
| 351 | gm_nontrans, |
| 352 | above_filter_ctx, |
| 353 | left_filter_ctx, |
| 354 | false, |
| 355 | ); |
| 356 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 357 | eprintln!( |
| 358 | "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \ |
| 359 | ref0={ref_frame} mv0=({},{}) stack={} rng={}", |
| 360 | mv.0, |
| 361 | mv.1, |
| 362 | stack.entries.len(), |
| 363 | dec.debug_state().0 |
| 364 | ); |
| 365 | } |
| 366 | grid.set( |
| 367 | rmi, |
| 368 | cmi, |
| 369 | MiInfo { |
| 370 | is_inter: true, |
| 371 | ref_frame, |
| 372 | ref_frame1: NO_REF1, |
| 373 | mv1: (0, 0), |
| 374 | mv: mv16(mv), |
| 375 | is_new_mv, |
| 376 | size: 1, |
| 377 | size_h: 1, |
| 378 | is_global_mv0: false, |
| 379 | is_global_mv1: false, |
| 380 | }, |
| 381 | ); |
| 382 | piece[i] = Some((ref_frame, mv, h_filter, v_filter)); |
| 383 | // lane-sub8group: this piece's prediction as a closure, run at the push |
| 384 | // site, exactly like the 8x8 leaf's. |
| 385 | let build = move |_y: &mut PlaneBuf<'static>, |
| 386 | _u: &mut PlaneBuf<'static>, |
| 387 | _v: &mut PlaneBuf<'static>, |
| 388 | refpix: &RefPix<'_>, |
| 389 | fctx: &crate::decode::FrameCtx, |
| 390 | out: &mut [Vec<u16>; 3]| { |
| 391 | let Some((sref_y, _, _)) = ref_planes_deferred(ref_frame, refpix) else { |
| 392 | return; |
| 393 | }; |
| 394 | let mut pred_y = refill(std::mem::take(&mut out[0]), B4 * B4); |
| 395 | mc::predict_maybe_scaled( |
| 396 | &sref_y.data, |
| 397 | sref_y.width, |
| 398 | sref_y.true_width, |
| 399 | sref_y.true_height, |
| 400 | mv_to_q4(px, mv.1, 0), |
| 401 | mv_to_q4(py, mv.0, 0), |
| 402 | luma_scale, |
| 403 | B4, |
| 404 | B4, |
| 405 | h_filter, |
| 406 | v_filter, |
| 407 | &mut pred_y, |
| 408 | fctx, |
| 409 | ); |
| 410 | out[0] = pred_y; |
| 411 | }; |
| 412 | let pred_y: Vec<u16>; |
| 413 | let sy = if pred_deferred(refpix) { |
| 414 | push_pred(build); |
| 415 | Pred::Cur { plane: 0, stride: B4, off: 0 } |
| 416 | } else { |
| 417 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 418 | build(y, u, v, refpix, fctx, &mut built); |
| 419 | let [by, _, _] = built; |
| 420 | pred_y = by; |
| 421 | Pred::Inline(&pred_y, B4) |
| 422 | }; |
| 423 | // `BLOCK_4X4` never signals a transform size, so the luma unit is the |
| 424 | // whole block and `get_txb_ctx` takes its `plane_bsize == |
| 425 | // txsize_to_bsize[tx_size]` branch (`txb_skip_ctx = 0`, which |
| 426 | // `read_inter_plane`'s `plane_idx == 0` arm already assumes). |
| 427 | if skip { |
| 428 | push_mc(y, u, v, 0, px, py, B4, sy, &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 429 | neighbours.record_mi_luma_rect(lmi, B4, B4, &ZERO_RESIDUAL[..B4 * B4]); |
| 430 | } else { |
| 431 | let around = neighbours.around_mi(lmi, B4); |
| 432 | let (luma_grid, tx_type) = read_inter_plane( |
| 433 | dec, |
| 434 | cdfs, |
| 435 | if reduced_tx_set { |
| 436 | TxbSet::Luma4Inter |
| 437 | } else { |
| 438 | TxbSet::Luma4InterSet1 |
| 439 | }, |
| 440 | scan4, |
| 441 | 0, |
| 442 | around[0], |
| 443 | 0, |
| 444 | y, |
| 445 | u, |
| 446 | v, |
| 447 | px, |
| 448 | py, |
| 449 | B4, |
| 450 | base_q_idx, |
| 451 | sy, |
| 452 | None, |
| 453 | None, |
| 454 | fctx, |
| 455 | )?; |
| 456 | piece_tx_type = tx_type; |
| 457 | if i == 0 { |
| 458 | sub0_tx_type = tx_type; |
| 459 | } |
| 460 | if i == 3 { |
| 461 | // `av1_get_tx_type`'s chroma tail scales `blk_row`/`blk_col` |
| 462 | // back by the subsampling, but it indexes `xd->tx_type_map`, |
| 463 | // which `set_mi_offsets` (av1_common_int.h:1679) re-points to |
| 464 | // the CURRENT sub-block's own mi -- so the group's one chroma |
| 465 | // unit inherits the CHROMA-REFERENCE (last) sub-block's |
| 466 | // tx_type, never the group's first. lane-t900 r7: reading it |
| 467 | // off sub-block 0 left the entropy stream in sync (no symbol |
| 468 | // is coded for chroma) and inverted one 4x4 chroma unit on the |
| 469 | // wrong basis. |
| 470 | first_tx_type = tx_type; |
| 471 | } |
| 472 | neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid); |
| 473 | } |
| 474 | // lane-av1-444: `is_chroma_reference` is unconditional at ss 0/0 |
| 475 | // (av1_common_int.h:1459 -- `!subsampling_x`/`!subsampling_y` force |
| 476 | // both disjuncts true), so at 4:4:4 this 4x4 sub-block codes its own |
| 477 | // 4x4 U and V units right after its luma, plane order 0,1,2 per leaf |
| 478 | // (aomdec EC_COEFF on `av1-profile1-444.ivf` frame 1). Chroma MC is |
| 479 | // the piece's own mv and filters at the piece's own pixel position |
| 480 | // (ss 0: the chroma planes share luma's grid), and each unit's |
| 481 | // tx_type is its own piece's luma type -- an inter block's chroma |
| 482 | // plane never codes its own tx_type symbol but inherits the |
| 483 | // colocated luma transform's coded type verbatim (`av1_get_tx_type`, |
| 484 | // blockd.h), which decides the eob CDF's class-1 row |
| 485 | // (`eob_multi_ctx`, decodetxb.c:214). |
| 486 | if chroma_444 { |
| 487 | let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above"); |
| 488 | let build_c = move |_y: &mut PlaneBuf<'static>, |
| 489 | _u: &mut PlaneBuf<'static>, |
| 490 | _v: &mut PlaneBuf<'static>, |
| 491 | refpix: &RefPix<'_>, |
| 492 | fctx: &crate::decode::FrameCtx, |
| 493 | out: &mut [Vec<u16>; 3]| { |
| 494 | let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else { |
| 495 | return; |
| 496 | }; |
| 497 | let pc_scale = scale_of((pc_ref_y.true_width, pc_ref_y.true_height), frame_size); |
| 498 | let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); |
| 499 | let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); |
| 500 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 501 | let mut buf = vec![0u16; B4 * B4]; |
| 502 | mc::predict_maybe_scaled( |
| 503 | &plane.data, |
| 504 | plane.width, |
| 505 | plane.true_width, |
| 506 | plane.true_height, |
| 507 | mv_to_q4(px, pc_mv.1, ss_x(fctx)), |
| 508 | mv_to_q4(py, pc_mv.0, ss_x(fctx)), |
| 509 | pc_scale, |
| 510 | B4, |
| 511 | B4, |
| 512 | pc_hf, |
| 513 | pc_vf, |
| 514 | &mut buf, |
| 515 | fctx, |
| 516 | ); |
| 517 | dst.copy_from_slice(&buf); |
| 518 | } |
| 519 | out[1] = pred_u; |
| 520 | out[2] = pred_v; |
| 521 | }; |
| 522 | let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>); |
| 523 | let (su, sv) = if pred_deferred(refpix) { |
| 524 | push_pred(build_c); |
| 525 | (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 }) |
| 526 | } else { |
| 527 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 528 | build_c(y, u, v, refpix, fctx, &mut built); |
| 529 | let [_, bu, bv] = built; |
| 530 | (pred_cu, pred_cv) = (bu, bv); |
| 531 | (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4)) |
| 532 | }; |
| 533 | if skip { |
| 534 | push_mc(y, u, v, 1, px, py, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 535 | push_mc(y, u, v, 2, px, py, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx); |
| 536 | neighbours.record_mi_chroma(lmi, B4, B4, 1, &ZERO_RESIDUAL[..B4 * B4]); |
| 537 | neighbours.record_mi_chroma(lmi, B4, B4, 2, &ZERO_RESIDUAL[..B4 * B4]); |
| 538 | } else { |
| 539 | let ca = neighbours.around_mi(lmi, B4); |
| 540 | let (ug, _) = read_inter_plane( |
| 541 | dec, |
| 542 | cdfs, |
| 543 | TxbSet::Chroma4, |
| 544 | scan4, |
| 545 | 1, |
| 546 | ca[1], |
| 547 | 0, |
| 548 | y, |
| 549 | u, |
| 550 | v, |
| 551 | px, |
| 552 | py, |
| 553 | B4, |
| 554 | base_q_idx, |
| 555 | su, |
| 556 | Some(piece_tx_type), |
| 557 | None, |
| 558 | fctx, |
| 559 | )?; |
| 560 | let (vg, _) = read_inter_plane( |
| 561 | dec, |
| 562 | cdfs, |
| 563 | TxbSet::Chroma4, |
| 564 | scan4, |
| 565 | 2, |
| 566 | ca[2], |
| 567 | 0, |
| 568 | y, |
| 569 | u, |
| 570 | v, |
| 571 | px, |
| 572 | py, |
| 573 | B4, |
| 574 | base_q_idx, |
| 575 | sv, |
| 576 | Some(piece_tx_type), |
| 577 | None, |
| 578 | fctx, |
| 579 | )?; |
| 580 | neighbours.record_mi_chroma(lmi, B4, B4, 1, &ug); |
| 581 | neighbours.record_mi_chroma(lmi, B4, B4, 2, &vg); |
| 582 | } |
| 583 | // lane-av1-422sub8rect: the 4:2:2 per-piece arm. `is_chroma_reference` |
| 584 | // for a BLOCK_4X4 at ss (1, 0) is the odd mi_col (`av1_common_int.h` |
| 585 | // :1459), so THIS piece (right column of the group) is a chroma |
| 586 | // reference and codes its own U and V TX_4X4 units right after its |
| 587 | // luma -- measured on the pinned t422 fixture: frame 0 key-frame |
| 588 | // groups (18,54)/(30,42) read U+V on both odd-column leaves, and |
| 589 | // frame 1's inter group at mi(12,2) reads U+V TX_4X4 ctx 8 on leaf |
| 590 | // (12,3) alone (its bottom-right twin was skipped). |
| 591 | // |
| 592 | // The unit anchors at the FLOORED chroma cell |
| 593 | // (`av1_setup_dst_planes`' `(mi_col & !1) * MI >> ss_x`, the |
| 594 | // lane-av1-422kf2 rule), so the 4-px-wide square covers the group's |
| 595 | // whole chroma width, and the prediction walks |
| 596 | // `build_inter_predictors_sub8x8` (reconinter_template.inc): the |
| 597 | // left 2x4 half from the LEFT piece's own ref/mv/filters, the right |
| 598 | // 2x4 half from this piece's -- unless the left piece is intra (or |
| 599 | // off-frame), which makes `is_sub8x8_inter` false and predicts the |
| 600 | // whole 4x4 from THIS piece's own mv. A skipped reference piece |
| 601 | // still predicts (spec 7.11.3: `predict_inter_block_visit` runs |
| 602 | // before the `skip_txfm` guard) but codes no coefficients. |
| 603 | } else if chroma_422 && (cmi & 1) == 1 { |
| 604 | let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above"); |
| 605 | let unit_x = ((cmi & !1) * MI) >> ss_x(fctx); |
| 606 | let unit_y = py >> ss_y(fctx); |
| 607 | // `is_sub8x8_inter`'s left-neighbour probe (`mi[-1]`): the piece |
| 608 | // one mi to the LEFT, when it exists and is inter. |
| 609 | let piece_left = piece[i - 1]; |
| 610 | let build_c = move |_y: &mut PlaneBuf<'static>, |
| 611 | _u: &mut PlaneBuf<'static>, |
| 612 | _v: &mut PlaneBuf<'static>, |
| 613 | refpix: &RefPix<'_>, |
| 614 | fctx: &crate::decode::FrameCtx, |
| 615 | out: &mut [Vec<u16>; 3]| { |
| 616 | let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else { |
| 617 | return; |
| 618 | }; |
| 619 | let pc_scale = scale_of((pc_ref_y.true_width, pc_ref_y.true_height), frame_size); |
| 620 | // The left piece's own reference planes + mv/filters, when it |
| 621 | // is an inter piece (`is_sub8x8_inter`'s `mi[-1]` probe). |
| 622 | let left = piece_left |
| 623 | .as_ref() |
| 624 | .map(|&(l_ref, l_mv, l_hf, l_vf)| (l_ref, l_mv, l_hf, l_vf)) |
| 625 | .and_then(|(l_ref, l_mv, l_hf, l_vf)| { |
| 626 | ref_planes_deferred(l_ref, refpix).map(|planes| { |
| 627 | let (lp_y, _, _) = planes; |
| 628 | let l_scale = scale_of((lp_y.true_width, lp_y.true_height), frame_size); |
| 629 | (l_mv, l_hf, l_vf, planes, l_scale) |
| 630 | }) |
| 631 | }); |
| 632 | let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); |
| 633 | let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); |
| 634 | for (pi, (plane, dst)) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] |
| 635 | .into_iter() |
| 636 | .enumerate() |
| 637 | { |
| 638 | let mut buf = vec![0u16; B4 * B4]; |
| 639 | // Right 2x4 half: this piece's own ref/mv/filters. |
| 640 | let mut half = vec![0u16; 2 * 4]; |
| 641 | mc::predict_maybe_scaled( |
| 642 | &plane.data, |
| 643 | plane.width, |
| 644 | plane.true_width, |
| 645 | plane.true_height, |
| 646 | mv_to_q4(unit_x + 2, pc_mv.1, ss_x(fctx)), |
| 647 | mv_to_q4(unit_y, pc_mv.0, ss_y(fctx)), |
| 648 | pc_scale, |
| 649 | 2, |
| 650 | 4, |
| 651 | pc_hf, |
| 652 | pc_vf, |
| 653 | &mut half, |
| 654 | fctx, |
| 655 | ); |
| 656 | for row in 0..4 { |
| 657 | buf[row * B4 + 2..row * B4 + 4] |
| 658 | .copy_from_slice(&half[row * 2..row * 2 + 2]); |
| 659 | } |
| 660 | // Left 2x4 half: the LEFT piece's own mv/filters |
| 661 | // (sub8x8-inter); a mixed group (left piece intra or |
| 662 | // off-frame) predicts it from THIS piece too, which |
| 663 | // reduces to the whole-4x4-from-own rule. |
| 664 | let (l_mv, l_hf, l_vf, l_planes, l_scale) = match left { |
| 665 | Some((l_mv, l_hf, l_vf, l_planes, l_scale)) => { |
| 666 | (l_mv, l_hf, l_vf, l_planes, l_scale) |
| 667 | } |
| 668 | None => (pc_mv, pc_hf, pc_vf, (pc_ref_y, sref_u, sref_v), pc_scale), |
| 669 | }; |
| 670 | // lane-av1422sub8pix: the left half predicts from the |
| 671 | // LEFT piece's own plane of its reference -- U for the U |
| 672 | // iteration, V for the V one. The old `l_ref_u` grab |
| 673 | // fed the V plane's left half from the reference's U |
| 674 | // plane (V cols 44..45 of the t422 frame-1 groups read |
| 675 | // U samples; U was exact, V wasn't). |
| 676 | let l_ref = if pi == 0 { |
| 677 | let (_, u, _) = l_planes; |
| 678 | u |
| 679 | } else { |
| 680 | let (_, _, v) = l_planes; |
| 681 | v |
| 682 | }; |
| 683 | mc::predict_maybe_scaled( |
| 684 | &l_ref.data, |
| 685 | l_ref.width, |
| 686 | l_ref.true_width, |
| 687 | l_ref.true_height, |
| 688 | mv_to_q4(unit_x, l_mv.1, ss_x(fctx)), |
| 689 | mv_to_q4(unit_y, l_mv.0, ss_y(fctx)), |
| 690 | l_scale, |
| 691 | 2, |
| 692 | 4, |
| 693 | l_hf, |
| 694 | l_vf, |
| 695 | &mut half, |
| 696 | fctx, |
| 697 | ); |
| 698 | for row in 0..4 { |
| 699 | buf[row * B4..row * B4 + 2].copy_from_slice(&half[row * 2..row * 2 + 2]); |
| 700 | } |
| 701 | dst.copy_from_slice(&buf); |
| 702 | } |
| 703 | out[1] = pred_u; |
| 704 | out[2] = pred_v; |
| 705 | }; |
| 706 | let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>); |
| 707 | let (su, sv) = if pred_deferred(refpix) { |
| 708 | push_pred(build_c); |
| 709 | (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 }) |
| 710 | } else { |
| 711 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 712 | build_c(y, u, v, refpix, fctx, &mut built); |
| 713 | let [_, bu, bv] = built; |
| 714 | (pred_cu, pred_cv) = (bu, bv); |
| 715 | (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4)) |
| 716 | }; |
| 717 | // The unit's entropy context: one chroma cell wide, floored -- |
| 718 | // [`Neighbours::around_mi_422_chroma`] at the unit's own 8x4 |
| 719 | // luma span (the [`sub8_leaf_chroma422`] rule). |
| 720 | let ctx_mi = (rmi, cmi & !1); |
| 721 | let ca = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); |
| 722 | if skip { |
| 723 | push_mc( |
| 724 | y, |
| 725 | u, |
| 726 | v, |
| 727 | 1, |
| 728 | unit_x, |
| 729 | unit_y, |
| 730 | B4, |
| 731 | su, |
| 732 | &ZERO_RESIDUAL[..B4 * B4], |
| 733 | fctx, |
| 734 | ); |
| 735 | push_mc( |
| 736 | y, |
| 737 | u, |
| 738 | v, |
| 739 | 2, |
| 740 | unit_x, |
| 741 | unit_y, |
| 742 | B4, |
| 743 | sv, |
| 744 | &ZERO_RESIDUAL[..B4 * B4], |
| 745 | fctx, |
| 746 | ); |
| 747 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]); |
| 748 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]); |
| 749 | } else { |
| 750 | hit!(CHROMA422_INTER_SUB8_HITS); |
| 751 | let (ug, _) = read_inter_plane( |
| 752 | dec, |
| 753 | cdfs, |
| 754 | TxbSet::Chroma4, |
| 755 | scan4, |
| 756 | 1, |
| 757 | ca[1], |
| 758 | 0, |
| 759 | y, |
| 760 | u, |
| 761 | v, |
| 762 | unit_x, |
| 763 | unit_y, |
| 764 | B4, |
| 765 | base_q_idx, |
| 766 | su, |
| 767 | Some(piece_tx_type), |
| 768 | None, |
| 769 | fctx, |
| 770 | )?; |
| 771 | let (vg, _) = read_inter_plane( |
| 772 | dec, |
| 773 | cdfs, |
| 774 | TxbSet::Chroma4, |
| 775 | scan4, |
| 776 | 2, |
| 777 | ca[2], |
| 778 | 0, |
| 779 | y, |
| 780 | u, |
| 781 | v, |
| 782 | unit_x, |
| 783 | unit_y, |
| 784 | B4, |
| 785 | base_q_idx, |
| 786 | sv, |
| 787 | Some(piece_tx_type), |
| 788 | None, |
| 789 | fctx, |
| 790 | )?; |
| 791 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug); |
| 792 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg); |
| 793 | } |
| 794 | } |
| 795 | neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED); |
| 796 | neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false); |
| 797 | // lane-inter16ab r8 (same-shape sweep of the intra-strip band gap): |
| 798 | // a BLOCK_4X4 codes no `txfm_partition` symbol, but libaom still runs |
| 799 | // `set_txfm_ctxs(TX_4X4, 1, 1, skip && is_inter, xd)` for it -- both |
| 800 | // arms give 4 -- so the sub-block must publish 4 to the next block's |
| 801 | // var-tx context instead of leaving whatever the previous block left. |
| 802 | set_txfm_ctxs(neighbours, lmi, B4, 1, 1, false); |
| 803 | neighbours.fill_skip_grid_rect(lmi, 1, 1, skip); |
| 804 | neighbours.fill_lf_grid_rect( |
| 805 | lmi, |
| 806 | 1, |
| 807 | 1, |
| 808 | B4 as u8, |
| 809 | B4 as u8, |
| 810 | ref_frame.max(LAST_FRAME), |
| 811 | fctx, |
| 812 | ); |
| 813 | last_skip = skip; |
| 814 | } |
| 815 | // lane-av1-444: when the chroma-reference sub-block was INTRA it coded |
| 816 | // and reconstructed the group's one chroma unit itself. |
| 817 | // lane-av1-444 (f19): at ss 0/0 the group unit does not exist -- every |
| 818 | // piece coded its own U/V inside the loop above, and every piece also |
| 819 | // wrote its own `uv_mode` neighbour state: an inter piece through |
| 820 | // `record_inter_rect_mi`'s is_inter DC stamp (libaom leaves `uv_mode` |
| 821 | // unset on an inter mbmi, `is_smooth` reads 0), an INTRA piece through |
| 822 | // [`decode_intra_sub8_leaf`]'s chroma_444 arm (libaom's per-sub-block |
| 823 | // `mbmi->uv_mode` is real there -- frame 19 of the fixture reads |
| 824 | // uv 12/11/9/12 on the four pieces of the (42,54) group, and the next |
| 825 | // block's `get_intra_edge_filter_type` must see that SMOOTH_H left |
| 826 | // neighbour, not the DC_PRED this stamp used to paint over it). So the |
| 827 | // group-level stamp runs only where the 4:2:0 group unit is real. |
| 828 | // |
| 829 | // 4:2:0 "real" means the group unit was painted by the INTER arm below: |
| 830 | // when the chroma-reference sub-block was INTRA, that leaf's own tail |
| 831 | // ([`decode_intra_sub8_leaf`]) already recorded the group cell with its |
| 832 | // real `uv_predict_mode` -- possibly a SMOOTH mode the next block's |
| 833 | // chroma edge filter must see. The 444 delta's unconditional |
| 834 | // `!chroma_444` stamp ran after it and painted DC over the mi-exact |
| 835 | // cell, so every later chroma block read `intra_edge_filter_type` 0 |
| 836 | // where libaom (and the pre-delta tree) read 1 -- 188 chroma ops of the |
| 837 | // gm_small_side witness flipped their smooth flag and 10-bit film |
| 838 | // frames mismatched ffmpeg by +-1..7 (class |
| 839 | // `override-slot-on-one-arm`, this lane's own 10-bit film gate |
| 840 | // regression at 1ad7e0fc; port of lane-av1-cfl's 7c6dad53). |
| 841 | if !chroma_444 && !chroma_422 && !intra_chroma { |
| 842 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 843 | } |
| 844 | // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map |
| 845 | // needs EVERY writer): a sub-8x8 group published no palette state, so |
| 846 | // once an 8x8 leaf of the same row can BE a palette block, the group |
| 847 | // left the row's band holding that earlier block's size and the next |
| 848 | // intra block read `av1_get_palette_mode_ctx` one too high (measured: |
| 849 | // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers |
| 850 | // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` |
| 851 | // needs `bsize >= BLOCK_8X8`), so the group always clears. |
| 852 | record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); |
| 853 | if !chroma_444 && !chroma_422 && !intra_chroma { |
| 854 | // Chroma, once for the whole group, on the last sub-block's own `skip` |
| 855 | // flag -- prediction from all four sub-blocks (2x2 pieces), residual as |
| 856 | // one TX_4X4 unit per plane. lane-av1-422sub8rect: 4:2:2 never takes |
| 857 | // this arm -- the shared group unit does not exist at ss (1, 0); each |
| 858 | // odd-column piece coded its own chroma inside the loop above. |
| 859 | // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY |
| 860 | // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE |
| 861 | // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces. |
| 862 | let mixed = piece.iter().any(Option::is_none); |
| 863 | if mixed { |
| 864 | hit_do! { |
| 865 | SUB8_INTRA_RECT_HITS.with(|h| { |
| 866 | let mut st = h.get(); |
| 867 | st[3] += 1; |
| 868 | h.set(st); |
| 869 | }); |
| 870 | } |
| 871 | } |
| 872 | // lane-sub8group: the group's chroma pieces, built where they are |
| 873 | // written -- the pieces' refs/mvs/filters travel by value. |
| 874 | let build = move |_y: &mut PlaneBuf<'static>, |
| 875 | _u: &mut PlaneBuf<'static>, |
| 876 | _v: &mut PlaneBuf<'static>, |
| 877 | refpix: &RefPix<'_>, |
| 878 | fctx: &crate::decode::FrameCtx, |
| 879 | out: &mut [Vec<u16>; 3]| { |
| 880 | let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); |
| 881 | let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); |
| 882 | // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it. |
| 883 | #[allow(clippy::needless_range_loop)] |
| 884 | for i in 0..4usize { |
| 885 | let (dr, dc) = (i / 2, i % 2); |
| 886 | if mixed && i != 3 { |
| 887 | continue; |
| 888 | } |
| 889 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { |
| 890 | continue; |
| 891 | }; |
| 892 | let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) |
| 893 | else { |
| 894 | continue; |
| 895 | }; |
| 896 | let piece_scale = scale_of( |
| 897 | (piece_ref_y.true_width, piece_ref_y.true_height), |
| 898 | frame_size, |
| 899 | ); |
| 900 | let (ox, oy) = if mixed { |
| 901 | (cpx, cpy) |
| 902 | } else { |
| 903 | (cpx + dc * 2, cpy + dr * 2) |
| 904 | }; |
| 905 | let (pw, ph) = if mixed { (B4, B4) } else { (2, 2) }; |
| 906 | let (row0, col0) = if mixed { (0, 0) } else { (dr * 2, dc * 2) }; |
| 907 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 908 | let mut buf = vec![0u16; pw * ph]; |
| 909 | mc::predict_maybe_scaled( |
| 910 | &plane.data, |
| 911 | plane.width, |
| 912 | plane.true_width, |
| 913 | plane.true_height, |
| 914 | mv_to_q4(ox, mv.1, ss_x(fctx)), |
| 915 | mv_to_q4(oy, mv.0, ss_x(fctx)), |
| 916 | piece_scale, |
| 917 | pw, |
| 918 | ph, |
| 919 | h_filter, |
| 920 | v_filter, |
| 921 | &mut buf, |
| 922 | fctx, |
| 923 | ); |
| 924 | for row in 0..ph { |
| 925 | for col in 0..pw { |
| 926 | dst[(row0 + row) * B4 + col0 + col] = buf[row * pw + col]; |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | out[1] = pred_u; |
| 932 | out[2] = pred_v; |
| 933 | }; |
| 934 | let (pred_u, pred_v): (Vec<u16>, Vec<u16>); |
| 935 | let (su, sv) = if pred_deferred(refpix) { |
| 936 | push_pred(build); |
| 937 | (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 }) |
| 938 | } else { |
| 939 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 940 | build(y, u, v, refpix, fctx, &mut built); |
| 941 | let [_, bu, bv] = built; |
| 942 | (pred_u, pred_v) = (bu, bv); |
| 943 | (Pred::Inline(&pred_u, B4), Pred::Inline(&pred_v, B4)) |
| 944 | }; |
| 945 | let (u_grid, v_grid) = if last_skip { |
| 946 | push_mc( |
| 947 | y, |
| 948 | u, |
| 949 | v, |
| 950 | 1, |
| 951 | cpx, |
| 952 | cpy, |
| 953 | B4, |
| 954 | su, |
| 955 | &ZERO_RESIDUAL[..B4 * B4], |
| 956 | fctx, |
| 957 | ); |
| 958 | push_mc( |
| 959 | y, |
| 960 | u, |
| 961 | v, |
| 962 | 2, |
| 963 | cpx, |
| 964 | cpy, |
| 965 | B4, |
| 966 | sv, |
| 967 | &ZERO_RESIDUAL[..B4 * B4], |
| 968 | fctx, |
| 969 | ); |
| 970 | (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) |
| 971 | } else { |
| 972 | let around = neighbours.around_mi(group_mi, 8); |
| 973 | let ug = read_inter_plane( |
| 974 | dec, |
| 975 | cdfs, |
| 976 | TxbSet::Chroma4, |
| 977 | scan4, |
| 978 | 1, |
| 979 | around[1], |
| 980 | 0, |
| 981 | y, |
| 982 | u, |
| 983 | v, |
| 984 | cpx, |
| 985 | cpy, |
| 986 | B4, |
| 987 | base_q_idx, |
| 988 | su, |
| 989 | Some(first_tx_type), |
| 990 | None, |
| 991 | fctx, |
| 992 | )? |
| 993 | .0; |
| 994 | let vg = read_inter_plane( |
| 995 | dec, |
| 996 | cdfs, |
| 997 | TxbSet::Chroma4, |
| 998 | scan4, |
| 999 | 2, |
| 1000 | around[2], |
| 1001 | 0, |
| 1002 | y, |
| 1003 | u, |
| 1004 | v, |
| 1005 | cpx, |
| 1006 | cpy, |
| 1007 | B4, |
| 1008 | base_q_idx, |
| 1009 | sv, |
| 1010 | Some(first_tx_type), |
| 1011 | None, |
| 1012 | fctx, |
| 1013 | )? |
| 1014 | .0; |
| 1015 | let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); |
| 1016 | note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded); |
| 1017 | (ug, vg) |
| 1018 | }; |
| 1019 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 1020 | let bound_h = round_up_even(neighbours.mi_rows); |
| 1021 | let bound_w = round_up_even(neighbours.mi_cols); |
| 1022 | let u_state = neighbour_state(&u_grid); |
| 1023 | let v_state = neighbour_state(&v_grid); |
| 1024 | for cell in 0..2usize { |
| 1025 | if cell < 2usize.min(bound_h.saturating_sub(gr)) { |
| 1026 | neighbours.left[gr + cell][1] = u_state; |
| 1027 | neighbours.left[gr + cell][2] = v_state; |
| 1028 | } |
| 1029 | if cell < 2usize.min(bound_w.saturating_sub(gc)) { |
| 1030 | neighbours.above[gc + cell][1] = u_state; |
| 1031 | neighbours.above[gc + cell][2] = v_state; |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | // Same two neighbour tails [`decode_leaf_split4`] runs: the partition |
| 1036 | // context of a `BLOCK_4X4` subsize (`partition_context_lookup` bit 0 = 1, |
| 1037 | // reached by `side_mi = 4` here) and the group's chroma coefficient state. |
| 1038 | for cell in 0..2usize { |
| 1039 | neighbours.left_side_mi[gr + cell] = 4; |
| 1040 | neighbours.above_side_mi[gc + cell] = 4; |
| 1041 | } |
| 1042 | Ok(()) |
| 1043 | } |
| 1044 | |
| 1045 | /// One INTRA 8x4/4x8 leaf inside an INTER frame's sub-8x8 HORZ/VERT partition |
| 1046 | /// (lane-sub8intra) -- the shape [`decode_inter_sub8_rect2`] refused by name. |
| 1047 | /// Mode syntax is `read_intra_block_mode_info`'s (decodemv.c:1065), not the key |
| 1048 | /// frame's above/left pair: `y_mode[size_group_lookup[BLOCK_8X4] == 0]`, NO |
| 1049 | /// angle delta (`av1_use_angle_delta` needs `bsize >= BLOCK_8X8`), `uv_mode` + |
| 1050 | /// CfL alphas only on the chroma-reference sub-block (`is_chroma_reference`: |
| 1051 | /// the SECOND one under 4:2:0), then `filter_intra` off BLOCK_8X4/BLOCK_4X8's |
| 1052 | /// own class row (`av1_filter_intra_allowed_bsize` is `wide <= 32 && high <= |
| 1053 | /// 32`, so this shape is allowed). Everything below the mode read -- the tx |
| 1054 | /// depth symbol, the whole-leaf `TX_8X4`/`TX_4X8` or split `TX_4X4` walk, the |
| 1055 | /// 4x4 chroma unit at the group's origin -- is [`decode_leaf_rect8`]'s body for |
| 1056 | /// the same shape; the INTER-frame differences are the tx-depth context |
| 1057 | /// (`above_txfm`/`left_txfm`), |
| 1058 | /// `set_txfm_ctxs` publication, and the inter-side bands + mi map the caller's |
| 1059 | /// inter leaves also write (`is_inter = 0`, ref `INTRA_FRAME`, no interp |
| 1060 | /// filter). |
| 1061 | #[allow(clippy::too_many_arguments)] |
| 1062 | pub(super) fn decode_intra_sub8_leaf( |
| 1063 | dec: &mut SymbolDecoder, |
| 1064 | cdfs: &mut Cdfs, |
| 1065 | neighbours: &mut Neighbours, |
| 1066 | grid: &mut MiGrid, |
| 1067 | group_mi: (usize, usize), |
| 1068 | lmi: (usize, usize), |
| 1069 | // `(bw, bh)`: 8x4 / 4x8 under HORZ/VERT, 4x4 under SPLIT. |
| 1070 | (bw, bh): (usize, usize), |
| 1071 | has_chroma: bool, |
| 1072 | skip: bool, |
| 1073 | scan4: &[u16], |
| 1074 | y: &mut PlaneBuf<'static>, |
| 1075 | u: &mut PlaneBuf<'static>, |
| 1076 | v: &mut PlaneBuf<'static>, |
| 1077 | base_q_idx: u8, |
| 1078 | enable_filter_intra: bool, |
| 1079 | tx_select: bool, |
| 1080 | reduced_tx_set: bool, |
| 1081 | fctx: &crate::decode::FrameCtx, |
| 1082 | ) -> Result<usize> { |
| 1083 | // lane-av1mono: a monochrome leaf codes no chroma mode (libaom |
| 1084 | // `decodemv.c:933`). |
| 1085 | let has_chroma = has_chroma && !mono(fctx); |
| 1086 | let vert = bw < bh; |
| 1087 | let (w_mi, h_mi) = (bw / MI, bh / MI); |
| 1088 | let (gr, gc) = group_mi; |
| 1089 | let (r, c) = (gr / (SUB / MI), gc / (SUB / MI)); |
| 1090 | let (above_mode, left_mode) = neighbours.modes_above_left(r, c); |
| 1091 | let leaf_above = neighbours.mode_above_mi(lmi.0, lmi.1).unwrap_or(above_mode); |
| 1092 | let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode); |
| 1093 | let step = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); |
| 1094 | // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0` |
| 1095 | // (libaom common_data.h:61). |
| 1096 | crate::msac::SymbolDecoder::set_symr_cdf("y_mode"); |
| 1097 | let mode = dec.symbol(&mut cdfs.y_mode[0]); |
| 1098 | if step { |
| 1099 | eprintln!( |
| 1100 | "EC_ISTEP mi_row={} mi_col={} name=mode val={mode} rng={}", |
| 1101 | lmi.0, |
| 1102 | lmi.1, |
| 1103 | dec.debug_state().0 |
| 1104 | ); |
| 1105 | } |
| 1106 | // No angle delta below 8x8 (`av1_use_angle_delta`), for luma or chroma. |
| 1107 | let angle_delta_y = 0; |
| 1108 | let (uv_mode, alpha) = if has_chroma { |
| 1109 | // `is_cfl_allowed` (blockd.h): away from lossless it is |
| 1110 | // `wide <= 32 && high <= 32` -- true for this shape; at lossless the |
| 1111 | // CHROMA plane block must be a single TX_4X4, so at 4:4:4 only the |
| 1112 | // 4x4 leaf keeps the 14-symbol CFL alphabet while an 8x4/4x8 leaf |
| 1113 | // reads the 13-symbol `uv_mode_no_cfl` one (the t6 frame-1 8x4 leaf |
| 1114 | // desynced at its uv_mode symbol reading the CFL alphabet, |
| 1115 | // lane-av1llintercdf). At 4:2:0 a sub-8 shape's chroma block is |
| 1116 | // always 4x4-or-smaller, so the predicate stays true and this read |
| 1117 | // is unchanged. |
| 1118 | let uv_mode = if cfl_allowed_px(bw, bh, fctx) { |
| 1119 | crate::msac::SymbolDecoder::set_symr_cdf("uv_mode"); |
| 1120 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 1121 | } else { |
| 1122 | crate::msac::SymbolDecoder::set_symr_cdf("uv_mode"); |
| 1123 | dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) |
| 1124 | }; |
| 1125 | if step { |
| 1126 | eprintln!( |
| 1127 | "EC_ISTEP mi_row={} mi_col={} name=uv_mode val={uv_mode} rng={}", |
| 1128 | lmi.0, |
| 1129 | lmi.1, |
| 1130 | dec.debug_state().0 |
| 1131 | ); |
| 1132 | } |
| 1133 | if (9..=12).contains(&uv_mode) { |
| 1134 | hit!(SMOOTH_UV_HITS); |
| 1135 | } |
| 1136 | let alpha = if uv_mode == UV_CFL_PRED { |
| 1137 | Some(read_cfl_alphas(dec, cdfs)) |
| 1138 | } else { |
| 1139 | None |
| 1140 | }; |
| 1141 | if (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 1142 | hit!(DIRECTIONAL_UV_HITS); |
| 1143 | } |
| 1144 | (uv_mode, alpha) |
| 1145 | } else { |
| 1146 | (DC_PRED, None) |
| 1147 | }; |
| 1148 | let mut filter_intra = None; |
| 1149 | if mode == DC_PRED && enable_filter_intra { |
| 1150 | let fi_class = if bw == bh { |
| 1151 | filter_intra_size_class(bw).expect("BLOCK_4X4 has its own filter_intra row") |
| 1152 | } else { |
| 1153 | filter_intra_size_class_rect(bw, bh) |
| 1154 | .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize") |
| 1155 | }; |
| 1156 | let use_fi = dec.symbol(&mut cdfs.filter_intra[fi_class]); |
| 1157 | if step { |
| 1158 | eprintln!( |
| 1159 | "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={use_fi} rng={}", |
| 1160 | lmi.0, |
| 1161 | lmi.1, |
| 1162 | dec.debug_state().0 |
| 1163 | ); |
| 1164 | } |
| 1165 | if use_fi != 0 { |
| 1166 | hit!(FILTER_INTRA_HITS); |
| 1167 | hit!(FILTER_INTRA_RECT_HITS); |
| 1168 | hit!(FILTER_INTRA_RECT_SUB8_HITS); |
| 1169 | let fi = dec.symbol(&mut cdfs.filter_intra_mode); |
| 1170 | if step { |
| 1171 | eprintln!( |
| 1172 | "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}", |
| 1173 | lmi.0, |
| 1174 | lmi.1, |
| 1175 | dec.debug_state().0 |
| 1176 | ); |
| 1177 | } |
| 1178 | filter_intra = Some(fi); |
| 1179 | } |
| 1180 | } |
| 1181 | // `read_block_tx_size`' non-var-tx arm: an INTRA block of an inter frame |
| 1182 | // reads `read_tx_size(allow_select = 1)` -- `bsize_to_tx_size_cat |
| 1183 | // (BLOCK_4X8) == 0` (blockd.h:1344, depth table entry 1), the same |
| 1184 | // 2-symbol category [`decode_leaf_rect8`] reads -- with the var-tx |
| 1185 | // context bands, which on an inter frame are live. |
| 1186 | // `block_signals_txsize(BLOCK_4X4)` is false (blockd.h:1027): the 4x4 leaf |
| 1187 | // codes no depth symbol at all, its transform is its own size. |
| 1188 | // lane-av1mix: the lossless early return (`decodeframe.c:1203`) sits |
| 1189 | // before the `TX_MODE_SELECT` test, so a lossless-segment rect leaf codes |
| 1190 | // no depth symbol either (sweep of the class fixed at the key-frame pair |
| 1191 | // path). |
| 1192 | let depth = if tx_select && bw != bh && !lossless(fctx) { |
| 1193 | let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx); |
| 1194 | let d = dec.symbol(&mut cdfs.tx_size_cat0[ctx]); |
| 1195 | if step { |
| 1196 | eprintln!( |
| 1197 | "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=0 rng={}", |
| 1198 | lmi.0, |
| 1199 | lmi.1, |
| 1200 | dec.debug_state().0 |
| 1201 | ); |
| 1202 | } |
| 1203 | d |
| 1204 | } else { |
| 1205 | 0 |
| 1206 | }; |
| 1207 | if depth != 0 { |
| 1208 | hit!(TX_DEPTH_HITS); |
| 1209 | hit!(RECT8_SPLIT_TX_HITS); |
| 1210 | } |
| 1211 | let split = depth != 0 || (lossless(fctx) && bw != bh); |
| 1212 | let (px, py) = (lmi.1 * MI, lmi.0 * MI); |
| 1213 | let reach = if bw == bh { |
| 1214 | Reach::of(bw, px, py, y.width, y.height, fctx) |
| 1215 | } else { |
| 1216 | Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx) |
| 1217 | }; |
| 1218 | let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left); |
| 1219 | if smooth_neighbor { |
| 1220 | hit!(SMOOTH_LUMA_HITS); |
| 1221 | } |
| 1222 | neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode); |
| 1223 | let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; |
| 1224 | if split { |
| 1225 | // `sub_tx_size_map[TX_4X8] == TX_4X4`: two 4x4 units along the long |
| 1226 | // axis, each predicted off the previous one's reconstruction. |
| 1227 | for tu in 0..2usize { |
| 1228 | let tu_mi = if vert { |
| 1229 | (lmi.0 + tu, lmi.1) |
| 1230 | } else { |
| 1231 | (lmi.0, lmi.1 + tu) |
| 1232 | }; |
| 1233 | let (tu_px, tu_py) = (tu_mi.1 * MI, tu_mi.0 * MI); |
| 1234 | let tu_reach = tu_reach( |
| 1235 | bw, |
| 1236 | bh, |
| 1237 | tu_px - px, |
| 1238 | tu_py - py, |
| 1239 | 4, |
| 1240 | reach, |
| 1241 | px, |
| 1242 | py, |
| 1243 | y.width, |
| 1244 | y.height, |
| 1245 | fctx, |
| 1246 | ); |
| 1247 | if skip { |
| 1248 | let zeros = vec![0i32; 16]; |
| 1249 | push_intra( |
| 1250 | y, |
| 1251 | u, |
| 1252 | v, |
| 1253 | 0, |
| 1254 | tu_px, |
| 1255 | tu_py, |
| 1256 | 4, |
| 1257 | mode, |
| 1258 | angle_delta_y, |
| 1259 | tu_reach, |
| 1260 | &zeros, |
| 1261 | None, |
| 1262 | filter_intra, |
| 1263 | smooth_neighbor, |
| 1264 | fctx, |
| 1265 | ); |
| 1266 | neighbours.record_mi_luma(tu_mi, 4, &zeros); |
| 1267 | continue; |
| 1268 | } |
| 1269 | let tu_around = neighbours.around_mi(tu_mi, 4)[0]; |
| 1270 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); |
| 1271 | let tu_grid = read_plane( |
| 1272 | dec, |
| 1273 | cdfs, |
| 1274 | if reduced_tx_set { |
| 1275 | TxbSet::Luma4 |
| 1276 | } else { |
| 1277 | TxbSet::Luma4Set1 |
| 1278 | }, |
| 1279 | scan4, |
| 1280 | 0, |
| 1281 | tu_around, |
| 1282 | mode, |
| 1283 | mode, |
| 1284 | angle_delta_y, |
| 1285 | tu_reach, |
| 1286 | y, |
| 1287 | u, |
| 1288 | v, |
| 1289 | tu_px, |
| 1290 | tu_py, |
| 1291 | 4, |
| 1292 | TX4, |
| 1293 | base_q_idx, |
| 1294 | None, |
| 1295 | filter_intra, |
| 1296 | Some(tu_skip_ctx), |
| 1297 | smooth_neighbor, |
| 1298 | fctx, |
| 1299 | )?; |
| 1300 | neighbours.record_mi_luma(tu_mi, 4, &tu_grid); |
| 1301 | } |
| 1302 | } else if bw == bh { |
| 1303 | // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so `get_txb_ctx` |
| 1304 | // fixes `txb_skip_ctx` at 0 (`luma_skip_ctx: None`) -- the same square |
| 1305 | // reader [`decode_leaf_split4`] uses. |
| 1306 | if skip { |
| 1307 | push_intra( |
| 1308 | y, |
| 1309 | u, |
| 1310 | v, |
| 1311 | 0, |
| 1312 | px, |
| 1313 | py, |
| 1314 | 4, |
| 1315 | mode, |
| 1316 | angle_delta_y, |
| 1317 | reach, |
| 1318 | &ZERO_RESIDUAL[..16], |
| 1319 | None, |
| 1320 | filter_intra, |
| 1321 | smooth_neighbor, |
| 1322 | fctx, |
| 1323 | ); |
| 1324 | neighbours.record_mi_luma(lmi, 4, &ZERO_RESIDUAL[..16]); |
| 1325 | } else { |
| 1326 | let tu_around = neighbours.around_mi(lmi, 4)[0]; |
| 1327 | let tu_grid = read_plane( |
| 1328 | dec, |
| 1329 | cdfs, |
| 1330 | if reduced_tx_set { |
| 1331 | TxbSet::Luma4 |
| 1332 | } else { |
| 1333 | TxbSet::Luma4Set1 |
| 1334 | }, |
| 1335 | scan4, |
| 1336 | 0, |
| 1337 | tu_around, |
| 1338 | mode, |
| 1339 | mode, |
| 1340 | angle_delta_y, |
| 1341 | reach, |
| 1342 | y, |
| 1343 | u, |
| 1344 | v, |
| 1345 | px, |
| 1346 | py, |
| 1347 | 4, |
| 1348 | TX4, |
| 1349 | base_q_idx, |
| 1350 | None, |
| 1351 | filter_intra, |
| 1352 | None, |
| 1353 | smooth_neighbor, |
| 1354 | fctx, |
| 1355 | )?; |
| 1356 | neighbours.record_mi_luma(lmi, 4, &tu_grid); |
| 1357 | } |
| 1358 | } else { |
| 1359 | let grid_levels = if skip { |
| 1360 | let zeros = Grid::Zero(bw * bh); |
| 1361 | push_intra_rect( |
| 1362 | y, |
| 1363 | u, |
| 1364 | v, |
| 1365 | 0, |
| 1366 | px, |
| 1367 | py, |
| 1368 | bw, |
| 1369 | bh, |
| 1370 | mode, |
| 1371 | angle_delta_y, |
| 1372 | reach, |
| 1373 | &zeros, |
| 1374 | None, |
| 1375 | filter_intra, |
| 1376 | smooth_neighbor, |
| 1377 | fctx, |
| 1378 | ); |
| 1379 | zeros |
| 1380 | } else { |
| 1381 | // The leaf's luma TU *is* the leaf, so `get_txb_ctx` fixes |
| 1382 | // `txb_skip_ctx` at 0. |
| 1383 | let around = neighbours.around_mi_rect(lmi, bw, bh)[0]; |
| 1384 | let set = if reduced_tx_set { |
| 1385 | TxbSet::LumaRect4x8 |
| 1386 | } else { |
| 1387 | TxbSet::LumaRect4x8Set1 |
| 1388 | }; |
| 1389 | let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra)); |
| 1390 | let (levels, tx_type) = read_coeffs_rect( |
| 1391 | dec, |
| 1392 | &mut coding, |
| 1393 | scan, |
| 1394 | bw, |
| 1395 | bh, |
| 1396 | 0, |
| 1397 | dc_sign_ctx(around.2), |
| 1398 | TxType::DctDct, |
| 1399 | 0, |
| 1400 | )?; |
| 1401 | let residual = dequant_and_inverse_typed_wh( |
| 1402 | &levels, |
| 1403 | bw, |
| 1404 | bh, |
| 1405 | crate::decode::bit_depth(fctx), |
| 1406 | // lane-d792 sweep: the block's segment `SEG_LVL_ALT_Q`, as at |
| 1407 | // every other dequant site (class `parsed-then-discarded`). |
| 1408 | block_q_idx(fctx), |
| 1409 | plane_q_delta(0, fctx).0, |
| 1410 | plane_q_delta(0, fctx).1, |
| 1411 | tx_type, |
| 1412 | block_iqmatrix(fctx, 0, bw, bh, tx_type), |
| 1413 | ); |
| 1414 | push_intra_rect( |
| 1415 | y, |
| 1416 | u, |
| 1417 | v, |
| 1418 | 0, |
| 1419 | px, |
| 1420 | py, |
| 1421 | bw, |
| 1422 | bh, |
| 1423 | mode, |
| 1424 | angle_delta_y, |
| 1425 | reach, |
| 1426 | &residual, |
| 1427 | None, |
| 1428 | filter_intra, |
| 1429 | smooth_neighbor, |
| 1430 | fctx, |
| 1431 | ); |
| 1432 | levels |
| 1433 | }; |
| 1434 | let state = neighbour_state(&grid_levels); |
| 1435 | for cell in 0..h_mi { |
| 1436 | if lmi.0 + cell < neighbours.mi_rows { |
| 1437 | neighbours.left[lmi.0 + cell][0] = state; |
| 1438 | } |
| 1439 | } |
| 1440 | for cell in 0..w_mi { |
| 1441 | if lmi.1 + cell < neighbours.mi_cols { |
| 1442 | neighbours.above[lmi.1 + cell][0] = state; |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) }; |
| 1447 | neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); |
| 1448 | neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0, fctx); |
| 1449 | // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an |
| 1450 | // intra block of an inter frame publishes its TRANSFORM dims, never its |
| 1451 | // block dims (blockd.h). Missing this left the next block reading the |
| 1452 | // previous block's band (the lane-intra16x4 finding for the 16x4 strip). |
| 1453 | for i in 0..w_mi { |
| 1454 | if let Some(cell) = neighbours.above_txfm.get_mut(lmi.1 + i) { |
| 1455 | *cell = tx_w as u8; |
| 1456 | } |
| 1457 | } |
| 1458 | for i in 0..h_mi { |
| 1459 | if let Some(cell) = neighbours.left_txfm.get_mut(lmi.0 + i) { |
| 1460 | *cell = tx_h as u8; |
| 1461 | } |
| 1462 | } |
| 1463 | neighbours.above_mode[c] = mode; |
| 1464 | neighbours.left_mode[r] = mode; |
| 1465 | // The inter-side bands and the mi map, exactly as the square |
| 1466 | // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no |
| 1467 | // interpolation filter, no skip mode. |
| 1468 | neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false); |
| 1469 | grid.fill_rect( |
| 1470 | lmi.0, |
| 1471 | lmi.1, |
| 1472 | h_mi, |
| 1473 | w_mi, |
| 1474 | MiInfo { |
| 1475 | is_inter: false, |
| 1476 | ref_frame: -1, |
| 1477 | ref_frame1: NO_REF1, |
| 1478 | mv1: (0, 0), |
| 1479 | mv: (0, 0), |
| 1480 | is_new_mv: false, |
| 1481 | size: w_mi as u8, |
| 1482 | size_h: h_mi as u8, |
| 1483 | is_global_mv0: false, |
| 1484 | is_global_mv1: false, |
| 1485 | }, |
| 1486 | ); |
| 1487 | hit_do! { |
| 1488 | SUB8_INTRA_RECT_HITS.with(|h| { |
| 1489 | let mut s = h.get(); |
| 1490 | s[usize::from(vert)] += 1; |
| 1491 | s[2] += usize::from(has_chroma); |
| 1492 | h.set(s); |
| 1493 | }); |
| 1494 | } |
| 1495 | // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map |
| 1496 | // needs EVERY writer): a sub-8x8 group published no palette state, so |
| 1497 | // once an 8x8 leaf of the same row can BE a palette block, the group |
| 1498 | // left the row's band holding that earlier block's size and the next |
| 1499 | // intra block read `av1_get_palette_mode_ctx` one too high (measured: |
| 1500 | // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers |
| 1501 | // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` |
| 1502 | // needs `bsize >= BLOCK_8X8`), so the group always clears. |
| 1503 | // |
| 1504 | // lane-av1mono: this publish is NOT chroma work and must run BEFORE the |
| 1505 | // `!has_chroma` return below. libaom's mi grid holds |
| 1506 | // `palette_size[0] == 0` in every cell of such a group whatever the |
| 1507 | // plane count, and on a monochrome frame EVERY sub-8 leaf passes |
| 1508 | // `has_chroma == false`, so a publish placed after the return never ran |
| 1509 | // at all: the band kept an earlier palette block's size, the next block |
| 1510 | // read `palette_y_mode` off CDF row 1 where libaom reads row 0, decoded |
| 1511 | // a palette libaom never coded, and the tile desynced one block later |
| 1512 | // (measured: gray testsrc2 320x240, decode-order frame 33, mi(42,50), |
| 1513 | // ours ctx 2 where libaom gathers 1). |
| 1514 | record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); |
| 1515 | if !has_chroma { |
| 1516 | // lane-av1-422sub8rect: 4:2:2 has no shared group unit whose tail |
| 1517 | // would stamp the mi map (`is_chroma_reference` runs per piece), so |
| 1518 | // a non-referenced piece publishes its own cell -- libaom leaves |
| 1519 | // `uv_mode` unset on it, `is_smooth` reads 0, i.e. DC_PRED. |
| 1520 | if ss_x(fctx) == 1 && ss_y(fctx) == 0 { |
| 1521 | neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, DC_PRED); |
| 1522 | } |
| 1523 | return Ok(mode); |
| 1524 | } |
| 1525 | // lane-av1-422sub8rect: at 4:2:2 this (odd-column) piece is its plane's |
| 1526 | // OWN chroma reference -- the key-frame split group's per-leaf TX_4X4 |
| 1527 | // model, floored anchor and per-chroma-cell context included |
| 1528 | // ([`sub8_leaf_chroma422`], measured on the pinned t422 fixture frame 0: |
| 1529 | // groups (18,54)/(30,42) code U+V on both odd-column leaves), never a |
| 1530 | // shared group unit. Inter frames code no intrabc, so `intrabc_dv` is |
| 1531 | // `None` here. |
| 1532 | if ss_x(fctx) == 1 && ss_y(fctx) == 0 { |
| 1533 | sub8_leaf_chroma422( |
| 1534 | dec, |
| 1535 | cdfs, |
| 1536 | neighbours, |
| 1537 | lmi, |
| 1538 | uv_mode, |
| 1539 | 0, |
| 1540 | alpha, |
| 1541 | skip, |
| 1542 | None, |
| 1543 | y, |
| 1544 | u, |
| 1545 | v, |
| 1546 | scan4, |
| 1547 | base_q_idx, |
| 1548 | neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), |
| 1549 | (bw, bh), |
| 1550 | fctx, |
| 1551 | )?; |
| 1552 | return Ok(mode); |
| 1553 | } |
| 1554 | // The group's single 4x4 chroma unit, intra-predicted from THIS |
| 1555 | // (chroma-reference) sub-block's own `uv_mode` -- `is_sub8x8_inter` |
| 1556 | // (reconinter_template.inc:54) returns false as soon as any mi of the |
| 1557 | // group is intra, and the decoder reconstructs chroma with the |
| 1558 | // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s |
| 1559 | // post-loop chroma. |
| 1560 | // |
| 1561 | // lane-av1-444: at ss 0/0 EVERY piece is its own chroma reference |
| 1562 | // (`is_chroma_reference`, av1_common_int.h:1459), so the unit anchors at |
| 1563 | // the piece's own position with the piece's own shape -- a 4x4 unit under |
| 1564 | // SPLIT, the leaf's own 8x4/4x8 unit under HORZ/VERT (`ChromaRect8x4`, |
| 1565 | // tx_type from the uv mode via `Intra_Mode_To_Tx_Type`, which decides the |
| 1566 | // eob CDF's class-1 row, decodetxb.c:214). |
| 1567 | let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; |
| 1568 | let (gpx, gpy) = (gc * MI, gr * MI); |
| 1569 | let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); |
| 1570 | let (unit_x, unit_y) = if chroma_444 { (px, py) } else { (cpx, cpy) }; |
| 1571 | let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx); |
| 1572 | let reach_c = if chroma_444 && bw != bh { |
| 1573 | Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx) |
| 1574 | } else if chroma_444 { |
| 1575 | Reach::of(bw, px, py, y.width, y.height, fctx) |
| 1576 | } else { |
| 1577 | group_reach |
| 1578 | }; |
| 1579 | let (band_r, band_c) = if chroma_444 { |
| 1580 | (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI)) |
| 1581 | } else { |
| 1582 | (r, c) |
| 1583 | }; |
| 1584 | let smooth_neighbor_uv = neighbours.smooth_uv_neighbour( |
| 1585 | if chroma_444 { lmi.0 } else { gr }, |
| 1586 | if chroma_444 { lmi.1 } else { gc }, |
| 1587 | band_r, |
| 1588 | band_c, |
| 1589 | fctx, |
| 1590 | ); |
| 1591 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { |
| 1592 | DC_PRED |
| 1593 | } else { |
| 1594 | uv_mode |
| 1595 | }; |
| 1596 | let angle_delta_uv = 0; |
| 1597 | neighbours.above_uv_mode[band_c] = uv_predict_mode; |
| 1598 | neighbours.left_uv_mode[band_r] = uv_predict_mode; |
| 1599 | if chroma_444 { |
| 1600 | neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode); |
| 1601 | } else { |
| 1602 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); |
| 1603 | } |
| 1604 | |
| 1605 | let ac = alpha.map(|_| { |
| 1606 | if chroma_444 { |
| 1607 | cfl_src_rect(px, py, bw, bh) |
| 1608 | } else { |
| 1609 | cfl_src(gpx, gpy, 8) |
| 1610 | } |
| 1611 | }); |
| 1612 | let mut chroma_stamped_per_unit = false; |
| 1613 | let (u_grid, v_grid): (Grid, Grid) = if skip { |
| 1614 | if alpha.is_some() { |
| 1615 | hit!(CHROMA_SKIP_CFL_HITS); |
| 1616 | hit!(SKIP_CFL_HITS); |
| 1617 | } |
| 1618 | if chroma_444 && bw != bh { |
| 1619 | let zeros = Grid::Zero(bw * bh); |
| 1620 | push_intra_rect( |
| 1621 | y, |
| 1622 | u, |
| 1623 | v, |
| 1624 | 1, |
| 1625 | unit_x, |
| 1626 | unit_y, |
| 1627 | bw, |
| 1628 | bh, |
| 1629 | uv_predict_mode, |
| 1630 | angle_delta_uv, |
| 1631 | reach_c, |
| 1632 | &zeros, |
| 1633 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 1634 | None, |
| 1635 | smooth_neighbor_uv, |
| 1636 | fctx, |
| 1637 | ); |
| 1638 | push_intra_rect( |
| 1639 | y, |
| 1640 | u, |
| 1641 | v, |
| 1642 | 2, |
| 1643 | unit_x, |
| 1644 | unit_y, |
| 1645 | bw, |
| 1646 | bh, |
| 1647 | uv_predict_mode, |
| 1648 | angle_delta_uv, |
| 1649 | reach_c, |
| 1650 | &zeros, |
| 1651 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 1652 | None, |
| 1653 | smooth_neighbor_uv, |
| 1654 | fctx, |
| 1655 | ); |
| 1656 | (zeros, Grid::Zero(bw * bh)) |
| 1657 | } else { |
| 1658 | push_intra( |
| 1659 | y, |
| 1660 | u, |
| 1661 | v, |
| 1662 | 1, |
| 1663 | unit_x, |
| 1664 | unit_y, |
| 1665 | 4, |
| 1666 | uv_predict_mode, |
| 1667 | angle_delta_uv, |
| 1668 | reach_c, |
| 1669 | &ZERO_RESIDUAL[..16], |
| 1670 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 1671 | None, |
| 1672 | smooth_neighbor_uv, |
| 1673 | fctx, |
| 1674 | ); |
| 1675 | push_intra( |
| 1676 | y, |
| 1677 | u, |
| 1678 | v, |
| 1679 | 2, |
| 1680 | unit_x, |
| 1681 | unit_y, |
| 1682 | 4, |
| 1683 | uv_predict_mode, |
| 1684 | angle_delta_uv, |
| 1685 | reach_c, |
| 1686 | &ZERO_RESIDUAL[..16], |
| 1687 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 1688 | None, |
| 1689 | smooth_neighbor_uv, |
| 1690 | fctx, |
| 1691 | ); |
| 1692 | (Grid::Zero(16), Grid::Zero(16)) |
| 1693 | } |
| 1694 | } else if chroma_444 && bw != bh { |
| 1695 | if lossless(fctx) { |
| 1696 | // lane-av1sub8rect444: lossless codes TX_4X4 on EVERY plane |
| 1697 | // (`av1_get_tx_size`, blockd.h:1383), so this leaf's 8x4/4x8 |
| 1698 | // chroma plane block is a 1x2/2x1 raster of TX_4X4 units per |
| 1699 | // plane, PLANE-MAJOR -- the same per-unit walk |
| 1700 | // [`read_intra_chroma_lossless`] runs for whole blocks and this |
| 1701 | // leaf's own luma `split` runs above, not one TX_8X4/TX_4X8 |
| 1702 | // rect unit. The rect read was wrong twice over: its unit count |
| 1703 | // left the second unit's coefficients in the bitstream, and its |
| 1704 | // skip ctx fixed at above+left missed `get_txb_ctx`'s |
| 1705 | // plane-block-bigger-than-transform term (libaom ctx 10+above |
| 1706 | // +left, our tables' +3), where the oracle read ctx 11≡4. |
| 1707 | let (mut uo, mut vo) = (Vec::new(), Vec::new()); |
| 1708 | for plane_idx in 1..3 { |
| 1709 | for tu in 0..2usize { |
| 1710 | let (ox, oy) = if vert { (0, tu * 4) } else { (tu * 4, 0) }; |
| 1711 | // libaom's `max_blocks_wide/high` clip: a unit whose |
| 1712 | // origin is past the frame edge is not coded at all |
| 1713 | // (`decode_token_recon_block`). At 4:4:4 the unit's |
| 1714 | // chroma origin is the leaf's own (px, py). |
| 1715 | if px + ox >= u.true_width || py + oy >= u.true_height { |
| 1716 | continue; |
| 1717 | } |
| 1718 | // At 4:4:4 a TX_4X4 chroma unit IS one mi cell. |
| 1719 | let tu_mi = (lmi.0 + oy / MI, lmi.1 + ox / MI); |
| 1720 | let tu_around = neighbours.around_mi(tu_mi, MI); |
| 1721 | let tu_r = |
| 1722 | tu_reach(bw, bh, ox, oy, 4, reach_c, px, py, y.width, y.height, fctx); |
| 1723 | // The plane block (8x4/4x8) is bigger than the TX_4X4 |
| 1724 | // transform, so `get_txb_ctx`'s chroma ctx_offset is 10, |
| 1725 | // not 7 -- our chroma tables carry the offset-10 rows at |
| 1726 | // +3, the same `Some(3)` [`read_intra_chroma_lossless`] |
| 1727 | // derives from `blk_w > 4 || blk_h > 4`. |
| 1728 | let tu_grid = read_plane( |
| 1729 | dec, |
| 1730 | cdfs, |
| 1731 | TxbSet::Chroma4, |
| 1732 | scan4, |
| 1733 | plane_idx, |
| 1734 | tu_around[plane_idx], |
| 1735 | mode, |
| 1736 | uv_predict_mode, |
| 1737 | angle_delta_uv, |
| 1738 | tu_r, |
| 1739 | y, |
| 1740 | u, |
| 1741 | v, |
| 1742 | px + ox, |
| 1743 | py + oy, |
| 1744 | 4, |
| 1745 | TX4, |
| 1746 | base_q_idx, |
| 1747 | None, |
| 1748 | None, |
| 1749 | Some(3), |
| 1750 | smooth_neighbor_uv, |
| 1751 | fctx, |
| 1752 | )?; |
| 1753 | // The unit's own coefficient context, stamped per unit |
| 1754 | // (`av1_set_contexts`); the tail's whole-leaf chroma |
| 1755 | // stamp below is skipped for this shape. |
| 1756 | neighbours.record_mi_chroma(tu_mi, 4, 4, plane_idx, &tu_grid); |
| 1757 | hit!(CHROMA_SPLIT_TX_HITS); |
| 1758 | let dst = mu_units(if plane_idx == 1 { &mut uo } else { &mut vo }, bw * bh); |
| 1759 | for row in 0..4 { |
| 1760 | let start = (oy + row) * bw + ox; |
| 1761 | dst[start..start + 4].copy_from_slice(&tu_grid[row * 4..][..4]); |
| 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | chroma_stamped_per_unit = true; |
| 1766 | hit!(LLSUB8RECT444_CHROMA_WALK_HITS); |
| 1767 | ( |
| 1768 | if uo.is_empty() { |
| 1769 | Grid::Zero(bw * bh) |
| 1770 | } else { |
| 1771 | Grid::Own(uo) |
| 1772 | }, |
| 1773 | if vo.is_empty() { |
| 1774 | Grid::Zero(bw * bh) |
| 1775 | } else { |
| 1776 | Grid::Own(vo) |
| 1777 | }, |
| 1778 | ) |
| 1779 | } else { |
| 1780 | // The leaf's own TX_8X4/TX_4X8 chroma unit: it IS the chroma plane |
| 1781 | // block, so `get_txb_ctx` fixes the skip context at above+left. |
| 1782 | // lane-av1422gather3: 4:4:4-only -- this `ca` arm sits inside the |
| 1783 | // `chroma_444` guard (ss 0/0), so the 4:2:2 pair rule does not |
| 1784 | // apply here. Probed at ss (1,0) over all 21 committed 4:2:2 |
| 1785 | // cells: 0 hits. |
| 1786 | let ca = neighbours.around_mi_rect(lmi, bw, bh); |
| 1787 | let scan_c: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 }; |
| 1788 | let uv_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 1789 | let mut read_chroma = |plane: usize, |
| 1790 | around: (bool, bool, i32), |
| 1791 | alpha_uv: Option<(i32, CflSrc)>| |
| 1792 | -> Result<Grid> { |
| 1793 | let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, 0); |
| 1794 | let skip_ctx = usize::from(around.0) + usize::from(around.1); |
| 1795 | let (levels, tx_type) = read_coeffs_rect( |
| 1796 | dec, |
| 1797 | &mut coding, |
| 1798 | scan_c, |
| 1799 | bw, |
| 1800 | bh, |
| 1801 | skip_ctx, |
| 1802 | dc_sign_ctx(around.2), |
| 1803 | uv_tx, |
| 1804 | plane, |
| 1805 | )?; |
| 1806 | let residual = dequant_and_inverse_typed_wh( |
| 1807 | &levels, |
| 1808 | bw, |
| 1809 | bh, |
| 1810 | crate::decode::bit_depth(fctx), |
| 1811 | block_q_idx(fctx), |
| 1812 | plane_q_delta(plane, fctx).0, |
| 1813 | plane_q_delta(plane, fctx).1, |
| 1814 | tx_type, |
| 1815 | block_iqmatrix(fctx, plane, bw, bh, tx_type), |
| 1816 | ); |
| 1817 | push_intra_rect( |
| 1818 | y, |
| 1819 | u, |
| 1820 | v, |
| 1821 | plane, |
| 1822 | unit_x, |
| 1823 | unit_y, |
| 1824 | bw, |
| 1825 | bh, |
| 1826 | uv_predict_mode, |
| 1827 | angle_delta_uv, |
| 1828 | reach_c, |
| 1829 | &residual, |
| 1830 | alpha_uv, |
| 1831 | None, |
| 1832 | smooth_neighbor_uv, |
| 1833 | fctx, |
| 1834 | ); |
| 1835 | Ok(levels) |
| 1836 | }; |
| 1837 | let ug = read_chroma(1, ca[1], alpha.zip(ac).map(|((au, _), ac)| (au, ac)))?; |
| 1838 | let vg = read_chroma(2, ca[2], alpha.zip(ac).map(|((_, av), ac)| (av, ac)))?; |
| 1839 | (ug, vg) |
| 1840 | } |
| 1841 | } else { |
| 1842 | let chroma_around = neighbours.around_mi( |
| 1843 | if chroma_444 { lmi } else { group_mi }, |
| 1844 | if chroma_444 { 4 } else { 8 }, |
| 1845 | ); |
| 1846 | let ug = read_plane( |
| 1847 | dec, |
| 1848 | cdfs, |
| 1849 | TxbSet::Chroma4, |
| 1850 | scan4, |
| 1851 | 1, |
| 1852 | chroma_around[1], |
| 1853 | uv_mode, |
| 1854 | uv_predict_mode, |
| 1855 | angle_delta_uv, |
| 1856 | reach_c, |
| 1857 | y, |
| 1858 | u, |
| 1859 | v, |
| 1860 | unit_x, |
| 1861 | unit_y, |
| 1862 | 4, |
| 1863 | TX4, |
| 1864 | base_q_idx, |
| 1865 | alpha.zip(ac).map(|((au, _), ac)| (au, ac)), |
| 1866 | None, |
| 1867 | None, |
| 1868 | smooth_neighbor_uv, |
| 1869 | fctx, |
| 1870 | )?; |
| 1871 | let vg = read_plane( |
| 1872 | dec, |
| 1873 | cdfs, |
| 1874 | TxbSet::Chroma4, |
| 1875 | scan4, |
| 1876 | 2, |
| 1877 | chroma_around[2], |
| 1878 | uv_mode, |
| 1879 | uv_predict_mode, |
| 1880 | angle_delta_uv, |
| 1881 | reach_c, |
| 1882 | y, |
| 1883 | u, |
| 1884 | v, |
| 1885 | unit_x, |
| 1886 | unit_y, |
| 1887 | 4, |
| 1888 | TX4, |
| 1889 | base_q_idx, |
| 1890 | alpha.zip(ac).map(|((_, av), ac)| (av, ac)), |
| 1891 | None, |
| 1892 | None, |
| 1893 | smooth_neighbor_uv, |
| 1894 | fctx, |
| 1895 | )?; |
| 1896 | (ug, vg) |
| 1897 | }; |
| 1898 | // The 4:4:4 lossless walk above already stamped these bands PER UNIT |
| 1899 | // (raster-order last writer per cell, exactly libaom's per-entry last |
| 1900 | // update); the whole-leaf aggregate would clobber the two units' distinct |
| 1901 | // states with one, so it runs only for the one-unit shapes (the same rule |
| 1902 | // [`decode_leaf8`]'s intrabc arm and the inter 8x8 leaf obey). The walk |
| 1903 | // must skip the 4:2:0 group-tail below too: it spans the GROUP's two mi |
| 1904 | // rows/cols with one composed state, which would overwrite the walk's |
| 1905 | // own stamps with the whole-leaf aggregate. |
| 1906 | if chroma_444 { |
| 1907 | if !chroma_stamped_per_unit { |
| 1908 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &u_grid); |
| 1909 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &v_grid); |
| 1910 | } |
| 1911 | } else { |
| 1912 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 1913 | let bound_h = round_up_even(neighbours.mi_rows); |
| 1914 | let bound_w = round_up_even(neighbours.mi_cols); |
| 1915 | let u_state = neighbour_state(&u_grid); |
| 1916 | let v_state = neighbour_state(&v_grid); |
| 1917 | for cell in 0..2usize { |
| 1918 | if cell < 2usize.min(bound_h.saturating_sub(gr)) { |
| 1919 | neighbours.left[gr + cell][1] = u_state; |
| 1920 | neighbours.left[gr + cell][2] = v_state; |
| 1921 | } |
| 1922 | if cell < 2usize.min(bound_w.saturating_sub(gc)) { |
| 1923 | neighbours.above[gc + cell][1] = u_state; |
| 1924 | neighbours.above[gc + cell][2] = v_state; |
| 1925 | } |
| 1926 | } |
| 1927 | } |
| 1928 | Ok(mode) |
| 1929 | } |
| 1930 | |
| 1931 | /// Decodes a `PARTITION_HORZ`/`PARTITION_VERT` of one 8x8 INTER block into two |
| 1932 | /// `BLOCK_8X4`/`BLOCK_4X8` inter leaves (lane-intersub8 r3) -- the inter twin of |
| 1933 | /// [`decode_leaf_rect8`] and the rectangular sibling of |
| 1934 | /// [`decode_inter_sub8_split4`], whose element order it follows exactly. |
| 1935 | /// Per sub-block, in libaom `decodemv.c` `read_inter_frame_mode_info` order: |
| 1936 | /// |
| 1937 | /// * `segment_id`, `skip`, `cdef`/`delta_q`/`delta_lf`, `intra_inter`; |
| 1938 | /// * NO `skip_mode` symbol: `is_comp_ref_allowed(BLOCK_8X4)` is false |
| 1939 | /// (`av1_is_comp_ref_allowed` needs both sides >= 8), so |
| 1940 | /// `read_skip_mode` returns 0 without reading and `comp_mode` is never read |
| 1941 | /// either (`read_ref_frames`' `is_comp_ref_allowed` guard) -- single |
| 1942 | /// reference only; |
| 1943 | /// * NO `interintra` and NO `motion_mode`/OBMC/warp symbol: every one of those |
| 1944 | /// gates needs `block_size_wide >= 8 && block_size_high >= 8` |
| 1945 | /// (`is_interintra_allowed_bsize`, `motion_mode_allowed`), and one side is 4; |
| 1946 | /// * `read_mb_interp_filter` DOES run for both sub-blocks. |
| 1947 | /// |
| 1948 | /// The shape's own differences from the four-way split: |
| 1949 | /// |
| 1950 | /// * `block_signals_txsize(BLOCK_8X4)` is true (`bsize > BLOCK_4X4`, |
| 1951 | /// blockd.h:1027), so a non-skipped sub-block reads ONE `txfm_partition` |
| 1952 | /// symbol under `TX_MODE_SELECT` at `max_txsize_rect_lookup[BLOCK_8X4] == |
| 1953 | /// TX_8X4` ([`read_var_tx_size`]); split resolves to two `TX_4X4` units |
| 1954 | /// (`sub_tx_size_map[TX_8X4] == TX_4X4`, libaom's early return), no split to |
| 1955 | /// the whole-leaf `TX_8X4`; |
| 1956 | /// * the luma coefficient set is [`TxbSet::LumaRect8x4Inter`] (the 8x8 |
| 1957 | /// coefficient class with a 32-position `eob_pt` and the INTER `TX_4X4` |
| 1958 | /// `tx_type` row) for the whole-leaf unit, and the square |
| 1959 | /// [`TxbSet::Luma4Inter`] for a split `TX_4X4` unit; |
| 1960 | /// * chroma is coded ONCE, on the sub-block that is the chroma reference: |
| 1961 | /// `is_chroma_reference` (`av1_common_int.h`) is |
| 1962 | /// `((mi_row & 1) || !(bh4 & 1) || !ss_y) && ((mi_col & 1) || !(bw4 & 1) || |
| 1963 | /// !ss_x)`, i.e. under 4:2:0 the BOTTOM 8x4 (`bh4 == 1`, odd) and the RIGHT |
| 1964 | /// 4x8 (`bw4 == 1`) -- always the second sub-block here; |
| 1965 | /// * that chroma unit's prediction is the sub8x8 one (`reconinter.c` |
| 1966 | /// `build_inter_predictors_sub8x8`: `row_start = -(block_size_high == 4 && |
| 1967 | /// ss_y)`, `col_start = -(block_size_wide == 4 && ss_x)`), two 4x2 (HORZ) or |
| 1968 | /// 2x4 (VERT) chroma pieces, each from its OWN sub-block's reference, mv and |
| 1969 | /// interpolation filters. |
| 1970 | #[allow(clippy::too_many_arguments)] |
| 1971 | pub(super) fn decode_inter_sub8_rect2( |
| 1972 | dec: &mut SymbolDecoder, |
| 1973 | cdfs: &mut Cdfs, |
| 1974 | neighbours: &mut Neighbours, |
| 1975 | grid: &mut MiGrid, |
| 1976 | group_mi: (usize, usize), |
| 1977 | vert: bool, |
| 1978 | mi_cols: u32, |
| 1979 | mi_rows: u32, |
| 1980 | y: &mut PlaneBuf<'static>, |
| 1981 | u: &mut PlaneBuf<'static>, |
| 1982 | v: &mut PlaneBuf<'static>, |
| 1983 | refpix: &RefPix<'_>, |
| 1984 | sign_bias_table: &SignBiasTable, |
| 1985 | global_motion: &[ec_av1_syntax::WarpParams; 7], |
| 1986 | base_q_idx: u8, |
| 1987 | scan4: &[u16], |
| 1988 | allow_high_precision_mv: bool, |
| 1989 | force_integer_mv: bool, |
| 1990 | interp_fixed: Option<mc::InterpFilterKind>, |
| 1991 | enable_dual_filter: bool, |
| 1992 | tpl_frame: Option<&TplFrameArgs>, |
| 1993 | reduced_tx_set: bool, |
| 1994 | frame_size: (usize, usize), |
| 1995 | fctx: &crate::decode::FrameCtx, |
| 1996 | ) -> Result<()> { |
| 1997 | const LAST_FRAME: i8 = 1; |
| 1998 | // The 8x8 group's own square stride: both leaves' prediction buffers are |
| 1999 | // laid out at it, as every other rect inter unit here is. |
| 2000 | const SIDE: usize = 8; |
| 2001 | let (bw, bh) = if vert { |
| 2002 | (4usize, 8usize) |
| 2003 | } else { |
| 2004 | (8usize, 4usize) |
| 2005 | }; |
| 2006 | let (w_mi, h_mi) = (bw / MI, bh / MI); |
| 2007 | hit_do! { |
| 2008 | SUB8_INTER_RECT_HITS.with(|c| { |
| 2009 | let mut h = c.get(); |
| 2010 | h[usize::from(vert)] += 1; |
| 2011 | c.set(h); |
| 2012 | }); |
| 2013 | } |
| 2014 | let (gr, gc) = group_mi; |
| 2015 | let (gpx, gpy) = (gc * MI, gr * MI); |
| 2016 | let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); |
| 2017 | // Per-sub-block state the group's one chroma unit predicts from. |
| 2018 | let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] = |
| 2019 | [None; 2]; |
| 2020 | let mut first_tx_type = TxType::DctDct; |
| 2021 | let mut sub0_tx_type = TxType::DctDct; |
| 2022 | // lane-av1-444: `is_chroma_reference` is unconditional at subsampling 0/0 |
| 2023 | // (av1_common_int.h:1459), so every 8x4/4x8 piece is its own chroma |
| 2024 | // reference and codes its own 8x4/4x8 U/V units right after its luma -- |
| 2025 | // there is no shared group unit (aomdec EC_COEFF on |
| 2026 | // `av1-profile1-444.ivf` decode-order frame 1, mi (3,8)). |
| 2027 | let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; |
| 2028 | // lane-av1-422blockhalf: at ss (1,0) the chroma reference is PER PIECE |
| 2029 | // too, keyed by `is_chroma_reference`'s own terms: an 8x4 HORZ piece is |
| 2030 | // 2 mi wide (`!(bw & 1)`), so BOTH pieces of the group are references; |
| 2031 | // a 4x8 VERT piece is 1 mi wide, so only the ODD-column piece is |
| 2032 | // (`mi_col & 1`) -- measured on the pinned t422 fixture frame 1: the |
| 2033 | // horz group at mi (8,10)/(9,10) reads U+V TX_4X4 after EACH piece's |
| 2034 | // luma (rng 37134/37852 then 63752/50952), and the vert group at |
| 2035 | // (3,10)/(3,11) reads U+V on the odd-column piece (3,11) alone. The old |
| 2036 | // `i == 1` rule coded the group's chroma on the wrong piece (and, for |
| 2037 | // horz, half of the units) and desynced frame 1 at (8,10)'s uv_mode. |
| 2038 | let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; |
| 2039 | // 4:4:4: every piece. 4:2:2: both horz pieces, the odd-column vert piece. |
| 2040 | // 4:2:0 keeps its existing second-piece model untouched. |
| 2041 | let piece_is_chroma_ref = |i: usize| -> bool { |
| 2042 | if ss_x(fctx) == 0 && ss_y(fctx) == 0 { |
| 2043 | true |
| 2044 | } else if chroma_422 { |
| 2045 | !vert || ((gc + i) & 1) == 1 |
| 2046 | } else { |
| 2047 | i == 1 |
| 2048 | } |
| 2049 | }; |
| 2050 | // This piece's first transform's luma `tx_type` (libaom `mbmi->tx_type`): |
| 2051 | // an inter block's chroma plane never codes its own symbol but inherits |
| 2052 | // the colocated luma type (`av1_get_tx_type`, blockd.h:1291). |
| 2053 | let mut piece_tx_type = TxType::DctDct; |
| 2054 | let mut last_skip = true; |
| 2055 | // Set when the chroma-reference sub-block is INTRA: it coded the group's |
| 2056 | // one chroma unit itself. |
| 2057 | let mut intra_chroma = false; |
| 2058 | for i in 0..2usize { |
| 2059 | let lmi = if vert { (gr, gc + i) } else { (gr + i, gc) }; |
| 2060 | if lmi.0 >= mi_rows as usize || lmi.1 >= mi_cols as usize { |
| 2061 | continue; |
| 2062 | } |
| 2063 | // libaom's `xd->above_mbmi`/`xd->left_mbmi` are the neighbour block as |
| 2064 | // DECODED, so leaf 1 sees leaf 0's own `bsize` -- the group tail below |
| 2065 | // publishes the side bands only once both leaves are done, which left |
| 2066 | // leaf 1 reading whatever block preceded the GROUP. `get_tx_size_context` |
| 2067 | // (pred_common.h:342) takes `block_size_wide[above_mbmi->bsize]` from it, |
| 2068 | // so an intra 8x4 leaf 1 read `tx_size_cat0` row 1 where aomdec reads |
| 2069 | // row 2 (class tx-grid-published-block-side). |
| 2070 | if i == 1 { |
| 2071 | if vert { |
| 2072 | for cell in 0..h_mi { |
| 2073 | neighbours.left_side_mi[gr + cell] = bh as u8; |
| 2074 | } |
| 2075 | neighbours.above_side_mi[gc] = bw as u8; |
| 2076 | } else { |
| 2077 | for cell in 0..w_mi { |
| 2078 | neighbours.above_side_mi[gc + cell] = bw as u8; |
| 2079 | } |
| 2080 | neighbours.left_side_mi[gr] = bh as u8; |
| 2081 | } |
| 2082 | } |
| 2083 | let (rmi, cmi) = lmi; |
| 2084 | let (px, py) = (cmi * MI, rmi * MI); |
| 2085 | inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, false, true, fctx); |
| 2086 | let skip_ctx = |
| 2087 | usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]); |
| 2088 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; |
| 2089 | inter_segment_id(dec, cdfs, rmi, cmi, w_mi, h_mi, skip, false, fctx); |
| 2090 | maybe_read_cdef_idx(dec, rmi, cmi, (2, 2), skip, fctx); |
| 2091 | maybe_read_delta_q(dec, cdfs, rmi, cmi, false, skip, fctx); |
| 2092 | maybe_read_delta_lf(dec, cdfs, rmi, cmi, false, skip, fctx); |
| 2093 | let (has_above, has_left) = (rmi > neighbours.tile_row0_mi, cmi > neighbours.tile_col0_mi); |
| 2094 | let ii_ctx = intra_inter_ctx( |
| 2095 | has_above, |
| 2096 | has_left, |
| 2097 | neighbours.above_inter[cmi], |
| 2098 | neighbours.left_inter[rmi], |
| 2099 | ); |
| 2100 | let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; |
| 2101 | if !is_inter { |
| 2102 | if crate::envflags::env_flag!("EC_SUB8INTRA") { |
| 2103 | eprintln!( |
| 2104 | "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}", |
| 2105 | bw, |
| 2106 | bh, |
| 2107 | piece_is_chroma_ref(i), |
| 2108 | fctx.tx_select_inter.with(std::cell::Cell::get), |
| 2109 | ); |
| 2110 | } |
| 2111 | // lane-sub8x4 r2: refusal and bypass lifted -- see the split arm's |
| 2112 | // note above for the gate that proves this leaf. |
| 2113 | // Its chroma rule is `is_sub8x8_inter`'s: when the |
| 2114 | // chroma-reference (second) sub-block is the intra one, the |
| 2115 | // group's 4x4 chroma is coded and predicted INTRA there and the |
| 2116 | // inter chroma tail below is skipped entirely. |
| 2117 | decode_intra_sub8_leaf( |
| 2118 | dec, |
| 2119 | cdfs, |
| 2120 | neighbours, |
| 2121 | grid, |
| 2122 | group_mi, |
| 2123 | lmi, |
| 2124 | (bw, bh), |
| 2125 | piece_is_chroma_ref(i), |
| 2126 | skip, |
| 2127 | scan4, |
| 2128 | y, |
| 2129 | u, |
| 2130 | v, |
| 2131 | base_q_idx, |
| 2132 | fctx.enable_filter_intra_inter.with(std::cell::Cell::get), |
| 2133 | fctx.tx_select_inter.with(std::cell::Cell::get), |
| 2134 | reduced_tx_set, |
| 2135 | fctx, |
| 2136 | )?; |
| 2137 | if piece_is_chroma_ref(i) { |
| 2138 | intra_chroma = true; |
| 2139 | } |
| 2140 | continue; |
| 2141 | } |
| 2142 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 2143 | eprintln!( |
| 2144 | "EC_MODE mi_row={rmi} mi_col={cmi} rng={}", |
| 2145 | dec.debug_state().0 |
| 2146 | ); |
| 2147 | } |
| 2148 | let ref_frame = read_single_ref( |
| 2149 | dec, |
| 2150 | cdfs, |
| 2151 | neighbours.above_ref[cmi], |
| 2152 | neighbours.above_ref1[cmi], |
| 2153 | neighbours.left_ref[rmi], |
| 2154 | neighbours.left_ref1[rmi], |
| 2155 | ); |
| 2156 | // lane-sub8group: this piece's reference SIZE at parse, its pictures |
| 2157 | // inside the prediction closure below. |
| 2158 | let (ref_width, ref_height) = ref_dims(ref_frame, refpix)?; |
| 2159 | // lane-t900 r28: refusal lifted -- see the split arm above. |
| 2160 | let luma_scale = scale_of((ref_width, ref_height), frame_size); |
| 2161 | if !luma_scale.is_unscaled() { |
| 2162 | hit!(SCALED_SUB8_HITS); |
| 2163 | } |
| 2164 | let gm_table = build_gm_mv_table( |
| 2165 | global_motion, |
| 2166 | rmi, |
| 2167 | cmi, |
| 2168 | w_mi, |
| 2169 | h_mi, |
| 2170 | allow_high_precision_mv, |
| 2171 | force_integer_mv, |
| 2172 | ); |
| 2173 | let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { |
| 2174 | field: t.field, |
| 2175 | cur_offset_0: crate::motion_field::get_relative_dist( |
| 2176 | t.order_hint_bits, |
| 2177 | t.order_hint, |
| 2178 | t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], |
| 2179 | ), |
| 2180 | allow_high_precision_mv, |
| 2181 | force_integer_mv, |
| 2182 | }); |
| 2183 | let stack = crate::mvstack::find_mv_stack_with_sign_bias( |
| 2184 | grid, |
| 2185 | rmi, |
| 2186 | cmi, |
| 2187 | w_mi, |
| 2188 | h_mi, |
| 2189 | ref_frame, |
| 2190 | mi_cols as usize, |
| 2191 | mi_rows as usize, |
| 2192 | sign_bias_table, |
| 2193 | &gm_table, |
| 2194 | tpl, |
| 2195 | ); |
| 2196 | let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; |
| 2197 | if !not_new { |
| 2198 | crate::census::mode(0); |
| 2199 | } |
| 2200 | let mut is_globalmv = false; |
| 2201 | let (mv, is_new_mv) = if !not_new { |
| 2202 | let mut idx = 0usize; |
| 2203 | while idx < 2 && stack.entries.len() > idx + 1 { |
| 2204 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 2205 | break; |
| 2206 | } |
| 2207 | idx += 1; |
| 2208 | } |
| 2209 | let base_mv = stack.entries.get(idx).map_or(stack.pred_mv, |e| e.mv); |
| 2210 | ( |
| 2211 | read_mv( |
| 2212 | dec, |
| 2213 | &mut cdfs.mv_comp, |
| 2214 | &mut cdfs.mv_joint, |
| 2215 | base_mv, |
| 2216 | allow_high_precision_mv, |
| 2217 | force_integer_mv, |
| 2218 | fctx, |
| 2219 | ), |
| 2220 | true, |
| 2221 | ) |
| 2222 | } else { |
| 2223 | let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; |
| 2224 | if !not_zero { |
| 2225 | crate::census::mode(1); |
| 2226 | } |
| 2227 | is_globalmv = !not_zero; |
| 2228 | let mv = if !not_zero { |
| 2229 | gm_table[(ref_frame - LAST_FRAME) as usize] |
| 2230 | } else { |
| 2231 | let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; |
| 2232 | crate::census::mode(if nearest { 2 } else { 3 }); |
| 2233 | if nearest { |
| 2234 | stack.nearest_mv |
| 2235 | } else { |
| 2236 | let mut idx = 1usize; |
| 2237 | while idx < 3 && stack.entries.len() > idx + 1 { |
| 2238 | if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { |
| 2239 | break; |
| 2240 | } |
| 2241 | idx += 1; |
| 2242 | } |
| 2243 | stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) |
| 2244 | } |
| 2245 | }; |
| 2246 | (mv, false) |
| 2247 | }; |
| 2248 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 2249 | eprintln!( |
| 2250 | "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}", |
| 2251 | mv.0, |
| 2252 | mv.1, |
| 2253 | dec.debug_state().0 |
| 2254 | ); |
| 2255 | } |
| 2256 | let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; |
| 2257 | let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame |
| 2258 | || neighbours.above_ref1[cmi] == Some(ref_frame) |
| 2259 | { |
| 2260 | neighbours.above_filter[cmi] |
| 2261 | } else { |
| 2262 | [3, 3] |
| 2263 | }; |
| 2264 | let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame |
| 2265 | || neighbours.left_ref1[rmi] == Some(ref_frame) |
| 2266 | { |
| 2267 | neighbours.left_filter[rmi] |
| 2268 | } else { |
| 2269 | [3, 3] |
| 2270 | }; |
| 2271 | // lane-t900 r9: this reader's sub-blocks have a 4-px side, and libaom |
| 2272 | // `is_nontrans_global_motion` returns 0 for |
| 2273 | // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model -- |
| 2274 | // so a GLOBALMV sub-block here always reads its interp filter. |
| 2275 | if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation { |
| 2276 | hit!(GM_NONTRANS_SMALL_SIDE_HITS); |
| 2277 | } |
| 2278 | let gm_nontrans = false; |
| 2279 | let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( |
| 2280 | dec, |
| 2281 | cdfs, |
| 2282 | interp_fixed, |
| 2283 | enable_dual_filter, |
| 2284 | gm_nontrans, |
| 2285 | above_filter_ctx, |
| 2286 | left_filter_ctx, |
| 2287 | false, |
| 2288 | ); |
| 2289 | // `read_block_tx_size` (libaom `decodeframe.c`): unlike a `BLOCK_4X4`, |
| 2290 | // this shape signals its transform size. A non-skipped inter block |
| 2291 | // walks the var-tx tree from `max_txsize_rect_lookup[BLOCK_8X4]`; a |
| 2292 | // skipped one codes nothing and records its BLOCK size in both txfm |
| 2293 | // contexts (`set_txfm_ctxs`' `skip_inter` arm). |
| 2294 | let mut leaves: Vec<(usize, usize, usize, usize)> = Vec::new(); |
| 2295 | // lane-av1mixllfork: the same libaom ordering fix as the intrabc rect |
| 2296 | // leaf's (`parse_decode_block`, decodeframe.c:1237): the per-segment |
| 2297 | // `lossless` flag is a CONJUNCT of the var-tx condition, not its |
| 2298 | // `else` arm, so a lossless SEGMENT of a mixed-lossless inter frame |
| 2299 | // reads no `tx_size_cat1` symbol here and codes TX_4X4 per plane. |
| 2300 | if fctx.tx_select_inter.with(std::cell::Cell::get) && !skip && !lossless(fctx) { |
| 2301 | let max_w_mi = w_mi.min((mi_cols as usize).saturating_sub(cmi)); |
| 2302 | let max_h_mi = h_mi.min((mi_rows as usize).saturating_sub(rmi)); |
| 2303 | read_var_tx_size( |
| 2304 | dec, |
| 2305 | cdfs, |
| 2306 | neighbours, |
| 2307 | lmi, |
| 2308 | SIDE, |
| 2309 | (max_w_mi, max_h_mi), |
| 2310 | (bw, bh), |
| 2311 | 0, |
| 2312 | 0, |
| 2313 | 0, |
| 2314 | &mut leaves, |
| 2315 | ); |
| 2316 | } else if lossless(fctx) && !skip { |
| 2317 | // COUNTED ONLY WHEN THE SUPPRESSION IS THE CONJUNCT'S WORKING: the |
| 2318 | // else-if also fires for a leaf whose `tx_select_inter` is off, |
| 2319 | // where the tree would not have run either way. The refutation pass |
| 2320 | // measured 33 hits on a build with the conjunct REMOVED, which is |
| 2321 | // exactly that population -- so an unconditional hit proves only |
| 2322 | // "a lossless sub-8 leaf was walked", not "the conjunct suppressed |
| 2323 | // a tree". Guard it on the same term the conjunct uses. |
| 2324 | if fctx.tx_select_inter.with(std::cell::Cell::get) { |
| 2325 | hit!(SUB8_LOSSLESS_NO_VARTX); |
| 2326 | } |
| 2327 | // lane-lossless2: `read_block_tx_size` returns TX_4X4 before it |
| 2328 | // ever looks at `max_txsize_rect_lookup`, so an 8x4/4x8 leaf is |
| 2329 | // TWO 4x4 units, not one rect one. |
| 2330 | for row in 0..bh / MI { |
| 2331 | for col in 0..bw / MI { |
| 2332 | leaves.push((row, col, MI, MI)); |
| 2333 | } |
| 2334 | } |
| 2335 | set_txfm_ctxs(neighbours, lmi, MI, w_mi, h_mi, skip); |
| 2336 | } else { |
| 2337 | leaves.push((0, 0, bw, bh)); |
| 2338 | set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip); |
| 2339 | } |
| 2340 | if crate::envflags::env_flag!("EC_TRACE_MODE") { |
| 2341 | eprintln!( |
| 2342 | "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \ |
| 2343 | ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}", |
| 2344 | mv.0, |
| 2345 | mv.1, |
| 2346 | stack.entries.len(), |
| 2347 | leaves.len(), |
| 2348 | dec.debug_state().0 |
| 2349 | ); |
| 2350 | } |
| 2351 | grid_stamp_rect(grid, rmi, cmi, w_mi, h_mi, ref_frame, mv, is_new_mv); |
| 2352 | piece[i] = Some((ref_frame, mv, h_filter, v_filter)); |
| 2353 | // Prediction over the leaf's true footprint, laid out at the group's |
| 2354 | // square stride (what `reconstruct_mc_rect` and `read_inter_plane_rect` |
| 2355 | // index with). |
| 2356 | // lane-sub8group: this piece's prediction as a closure, run at the push |
| 2357 | // site, exactly like the 8x8 leaf's. |
| 2358 | let build = move |_y: &mut PlaneBuf<'static>, |
| 2359 | _u: &mut PlaneBuf<'static>, |
| 2360 | _v: &mut PlaneBuf<'static>, |
| 2361 | refpix: &RefPix<'_>, |
| 2362 | fctx: &crate::decode::FrameCtx, |
| 2363 | out: &mut [Vec<u16>; 3]| { |
| 2364 | let Some((sref_y, _, _)) = ref_planes_deferred(ref_frame, refpix) else { |
| 2365 | return; |
| 2366 | }; |
| 2367 | let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); |
| 2368 | let mut dense = vec![0u16; bw * bh]; |
| 2369 | mc::predict_maybe_scaled( |
| 2370 | &sref_y.data, |
| 2371 | sref_y.width, |
| 2372 | sref_y.true_width, |
| 2373 | sref_y.true_height, |
| 2374 | mv_to_q4(px, mv.1, 0), |
| 2375 | mv_to_q4(py, mv.0, 0), |
| 2376 | luma_scale, |
| 2377 | bw, |
| 2378 | bh, |
| 2379 | h_filter, |
| 2380 | v_filter, |
| 2381 | &mut dense, |
| 2382 | fctx, |
| 2383 | ); |
| 2384 | for row in 0..bh { |
| 2385 | pred_y[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); |
| 2386 | } |
| 2387 | out[0] = pred_y; |
| 2388 | }; |
| 2389 | let pred_y: Vec<u16>; |
| 2390 | let sy = if pred_deferred(refpix) { |
| 2391 | push_pred(build); |
| 2392 | Pred::Cur { plane: 0, stride: SIDE, off: 0 } |
| 2393 | } else { |
| 2394 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 2395 | build(y, u, v, refpix, fctx, &mut built); |
| 2396 | let [by, _, _] = built; |
| 2397 | pred_y = by; |
| 2398 | Pred::Inline(&pred_y, SIDE) |
| 2399 | }; |
| 2400 | if skip { |
| 2401 | push_mc_rect( |
| 2402 | y, |
| 2403 | u, |
| 2404 | v, |
| 2405 | 0, |
| 2406 | px, |
| 2407 | py, |
| 2408 | SIDE, |
| 2409 | bw, |
| 2410 | bh, |
| 2411 | sy, |
| 2412 | &ZERO_RESIDUAL[..SIDE * SIDE], |
| 2413 | fctx, |
| 2414 | ); |
| 2415 | neighbours.record_mi_luma_rect(lmi, bw, bh, &ZERO_RESIDUAL[..bw * bh]); |
| 2416 | neighbours.fill_lf_grid_rect( |
| 2417 | lmi, |
| 2418 | w_mi, |
| 2419 | h_mi, |
| 2420 | bw as u8, |
| 2421 | bh as u8, |
| 2422 | ref_frame.max(LAST_FRAME), |
| 2423 | fctx, |
| 2424 | ); |
| 2425 | } else { |
| 2426 | let (mut last_tw, mut last_th) = (bw, bh); |
| 2427 | for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() { |
| 2428 | let tu_mi = (rmi + row, cmi + col); |
| 2429 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 2430 | // This unit's offset into the block prediction (lane-sub8group). |
| 2431 | let start = row * MI * SIDE + col * MI; |
| 2432 | let (tu_grid, tu_tx_type) = if tw == th { |
| 2433 | // A split `TX_4X4` unit: square reader, its own |
| 2434 | // `get_txb_ctx_general` neighbour context (the unit is |
| 2435 | // smaller than its plane block, so the lone-TU 0 does not |
| 2436 | // apply). |
| 2437 | // lane-sub8group: the unit's window of the block |
| 2438 | // prediction, at the block's stride. |
| 2439 | let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI); |
| 2440 | read_inter_plane( |
| 2441 | dec, |
| 2442 | cdfs, |
| 2443 | if reduced_tx_set { |
| 2444 | TxbSet::Luma4Inter |
| 2445 | } else { |
| 2446 | TxbSet::Luma4InterSet1 |
| 2447 | }, |
| 2448 | scan4, |
| 2449 | 0, |
| 2450 | neighbours.around_mi(tu_mi, tw)[0], |
| 2451 | 0, |
| 2452 | y, |
| 2453 | u, |
| 2454 | v, |
| 2455 | tu_px, |
| 2456 | tu_py, |
| 2457 | tw, |
| 2458 | base_q_idx, |
| 2459 | sy.offset(start), |
| 2460 | None, |
| 2461 | Some(tu_skip_ctx), |
| 2462 | fctx, |
| 2463 | )? |
| 2464 | } else { |
| 2465 | // The whole leaf as one `TX_8X4`/`TX_4X8` unit: it IS the |
| 2466 | // plane block, so `get_txb_ctx_general` fixes `txb_skip_ctx` |
| 2467 | // at 0 (`luma_skip_ctx: None`). |
| 2468 | read_inter_plane_rect( |
| 2469 | dec, |
| 2470 | cdfs, |
| 2471 | if reduced_tx_set { |
| 2472 | TxbSet::LumaRect8x4Inter |
| 2473 | } else { |
| 2474 | TxbSet::LumaRect8x4InterSet1 |
| 2475 | }, |
| 2476 | (tw, th), |
| 2477 | SIDE, |
| 2478 | 0, |
| 2479 | neighbours.around_mi_rect(tu_mi, tw, th)[0], |
| 2480 | 0, |
| 2481 | y, |
| 2482 | u, |
| 2483 | v, |
| 2484 | tu_px, |
| 2485 | tu_py, |
| 2486 | sy.offset(start), |
| 2487 | None, |
| 2488 | None, |
| 2489 | fctx, |
| 2490 | )? |
| 2491 | }; |
| 2492 | if idx == 0 { |
| 2493 | piece_tx_type = tu_tx_type; |
| 2494 | } |
| 2495 | if idx == 0 && i == 0 { |
| 2496 | sub0_tx_type = tu_tx_type; |
| 2497 | } |
| 2498 | if idx == 0 && i == 1 { |
| 2499 | // `av1_get_tx_type` indexes `xd->tx_type_map`, which |
| 2500 | // `set_mi_offsets` (av1_common_int.h:1679) re-points to the |
| 2501 | // CURRENT sub-block: the group's one chroma unit inherits |
| 2502 | // the CHROMA-REFERENCE (second) sub-block's first transform |
| 2503 | // unit, never the first sub-block's (lane-t900 r7). |
| 2504 | first_tx_type = tu_tx_type; |
| 2505 | } |
| 2506 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); |
| 2507 | (last_tw, last_th) = (tw, th); |
| 2508 | } |
| 2509 | neighbours.fill_lf_grid_rect( |
| 2510 | lmi, |
| 2511 | w_mi, |
| 2512 | h_mi, |
| 2513 | last_tw as u8, |
| 2514 | last_th as u8, |
| 2515 | ref_frame.max(LAST_FRAME), |
| 2516 | fctx, |
| 2517 | ); |
| 2518 | } |
| 2519 | // lane-av1-444: at ss 0/0 this piece codes its OWN 8x4/4x8 U and V |
| 2520 | // units right after its luma, plane order 0,1,2 (libaom decodes each |
| 2521 | // piece as its own block: `decode_token_recon_block`'s plane-major |
| 2522 | // loop over `av1_get_max_uv_txsize(BLOCK_8X4, 0, 0) == TX_8X4`). The |
| 2523 | // unit's prediction is the piece's own mv/filters at the piece's own |
| 2524 | // pixel position (ss 0: the chroma planes share luma's grid), and its |
| 2525 | // tx_type is this piece's first luma transform's coded type. |
| 2526 | if chroma_444 { |
| 2527 | let build_c = move |_y: &mut PlaneBuf<'static>, |
| 2528 | _u: &mut PlaneBuf<'static>, |
| 2529 | _v: &mut PlaneBuf<'static>, |
| 2530 | refpix: &RefPix<'_>, |
| 2531 | fctx: &crate::decode::FrameCtx, |
| 2532 | out: &mut [Vec<u16>; 3]| { |
| 2533 | let Some((_, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) else { |
| 2534 | return; |
| 2535 | }; |
| 2536 | let piece_scale = scale_of((ref_width, ref_height), frame_size); |
| 2537 | let mut pred_u = refill(std::mem::take(&mut out[1]), SIDE * SIDE); |
| 2538 | let mut pred_v = refill(std::mem::take(&mut out[2]), SIDE * SIDE); |
| 2539 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 2540 | let mut dense = vec![0u16; bw * bh]; |
| 2541 | mc::predict_maybe_scaled( |
| 2542 | &plane.data, |
| 2543 | plane.width, |
| 2544 | plane.true_width, |
| 2545 | plane.true_height, |
| 2546 | mv_to_q4(px, mv.1, ss_x(fctx)), |
| 2547 | mv_to_q4(py, mv.0, ss_x(fctx)), |
| 2548 | piece_scale, |
| 2549 | bw, |
| 2550 | bh, |
| 2551 | h_filter, |
| 2552 | v_filter, |
| 2553 | &mut dense, |
| 2554 | fctx, |
| 2555 | ); |
| 2556 | for row in 0..bh { |
| 2557 | dst[row * SIDE..][..bw].copy_from_slice(&dense[row * bw..][..bw]); |
| 2558 | } |
| 2559 | } |
| 2560 | out[1] = pred_u; |
| 2561 | out[2] = pred_v; |
| 2562 | }; |
| 2563 | let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>); |
| 2564 | let (su, sv) = if pred_deferred(refpix) { |
| 2565 | push_pred(build_c); |
| 2566 | (Pred::Cur { plane: 1, stride: SIDE, off: 0 }, Pred::Cur { plane: 2, stride: SIDE, off: 0 }) |
| 2567 | } else { |
| 2568 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 2569 | build_c(y, u, v, refpix, fctx, &mut built); |
| 2570 | let [_, bu, bv] = built; |
| 2571 | (pred_cu, pred_cv) = (bu, bv); |
| 2572 | (Pred::Inline(&pred_cu, SIDE), Pred::Inline(&pred_cv, SIDE)) |
| 2573 | }; |
| 2574 | if skip { |
| 2575 | push_mc_rect( |
| 2576 | y, |
| 2577 | u, |
| 2578 | v, |
| 2579 | 1, |
| 2580 | px, |
| 2581 | py, |
| 2582 | SIDE, |
| 2583 | bw, |
| 2584 | bh, |
| 2585 | su, |
| 2586 | &ZERO_RESIDUAL[..SIDE * SIDE], |
| 2587 | fctx, |
| 2588 | ); |
| 2589 | push_mc_rect( |
| 2590 | y, |
| 2591 | u, |
| 2592 | v, |
| 2593 | 2, |
| 2594 | px, |
| 2595 | py, |
| 2596 | SIDE, |
| 2597 | bw, |
| 2598 | bh, |
| 2599 | sv, |
| 2600 | &ZERO_RESIDUAL[..SIDE * SIDE], |
| 2601 | fctx, |
| 2602 | ); |
| 2603 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &ZERO_RESIDUAL[..bw * bh]); |
| 2604 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &ZERO_RESIDUAL[..bw * bh]); |
| 2605 | } else if lossless(fctx) && !mono(fctx) { |
| 2606 | // lane-av1-llsub8b: lossless codes TX_4X4 on EVERY plane |
| 2607 | // (`av1_get_tx_size`, blockd.h:1383), so this 4:4:4 piece's |
| 2608 | // (8,4)/(4,8) chroma plane block is a 2x1/1x2 raster of |
| 2609 | // TX_4X4 units, not the ONE TX_8X4 rect unit the lossy arm |
| 2610 | // below reads -- that single rect is what tripped |
| 2611 | // `TxParams::run`'s WHT assert ((8,4) != (4,4), |
| 2612 | // decode.rs:2566). The walk stamps each unit's own |
| 2613 | // coefficient context, so -- unlike the lossy arm -- no |
| 2614 | // whole-block `record_mi_chroma` runs after it: the walk's |
| 2615 | // per-unit stamps ARE the block's chroma contexts (the same |
| 2616 | // rule `leaf8_inter_chroma_lossless`'s caller obeys). |
| 2617 | read_inter_chroma_lossless( |
| 2618 | y, |
| 2619 | u, |
| 2620 | v, |
| 2621 | dec, |
| 2622 | cdfs, |
| 2623 | neighbours, |
| 2624 | su, |
| 2625 | sv, |
| 2626 | (rmi, cmi), |
| 2627 | (px, py), |
| 2628 | (0, 0), |
| 2629 | (bw, bh), |
| 2630 | (bw, bh), |
| 2631 | SIDE, |
| 2632 | 0, |
| 2633 | base_q_idx, |
| 2634 | &mut Vec::new(), |
| 2635 | &mut Vec::new(), |
| 2636 | fctx, |
| 2637 | )?; |
| 2638 | } else { |
| 2639 | // lane-av1422gather3: 4:4:4-only -- this `ca` arm sits inside |
| 2640 | // the `chroma_444` guard (ss 0/0); the 4:2:2 per-piece arm |
| 2641 | // below already reads through `around_mi_422_chroma`. Probed |
| 2642 | // at ss (1,0) over all 21 committed 4:2:2 cells: 0 hits. |
| 2643 | let ca = neighbours.around_mi_rect(lmi, bw, bh); |
| 2644 | let (ug, _) = read_inter_plane_rect( |
| 2645 | dec, |
| 2646 | cdfs, |
| 2647 | TxbSet::ChromaRect8x4, |
| 2648 | (bw, bh), |
| 2649 | SIDE, |
| 2650 | 1, |
| 2651 | ca[1], |
| 2652 | 0, |
| 2653 | y, |
| 2654 | u, |
| 2655 | v, |
| 2656 | px, |
| 2657 | py, |
| 2658 | su, |
| 2659 | Some(piece_tx_type), |
| 2660 | None, |
| 2661 | fctx, |
| 2662 | )?; |
| 2663 | let (vg, _) = read_inter_plane_rect( |
| 2664 | dec, |
| 2665 | cdfs, |
| 2666 | TxbSet::ChromaRect8x4, |
| 2667 | (bw, bh), |
| 2668 | SIDE, |
| 2669 | 2, |
| 2670 | ca[2], |
| 2671 | 0, |
| 2672 | y, |
| 2673 | u, |
| 2674 | v, |
| 2675 | px, |
| 2676 | py, |
| 2677 | sv, |
| 2678 | Some(piece_tx_type), |
| 2679 | None, |
| 2680 | fctx, |
| 2681 | )?; |
| 2682 | neighbours.record_mi_chroma(lmi, bw, bh, 1, &ug); |
| 2683 | neighbours.record_mi_chroma(lmi, bw, bh, 2, &vg); |
| 2684 | } |
| 2685 | // lane-av1-422blockhalf: the 4:2:2 per-piece arm. The chroma |
| 2686 | // reference piece codes its own U and V TX_4X4 units right after its |
| 2687 | // luma -- both pieces of a horz group, the odd-column piece of a |
| 2688 | // vert one (see `piece_is_chroma_ref` above; measured on the pinned |
| 2689 | // t422 fixture frame 1, horz group (8,10)/(9,10) and vert group |
| 2690 | // (3,10)/(3,11)). The unit anchors at the FLOORED chroma cell |
| 2691 | // (`av1_setup_dst_planes`' `(mi_col & !1) * MI >> ss_x`, the |
| 2692 | // lane-av1-422kf2 rule) and reads through |
| 2693 | // [`Neighbours::around_mi_422_chroma`]'s per-chroma-cell context. |
| 2694 | // A horz piece IS 4x4 chroma (8 luma wide, ss_y 0): its unit |
| 2695 | // predicts whole from its own mv/filters. A vert piece is 2 chroma |
| 2696 | // px wide, so its 4-px unit predicts in halves -- |
| 2697 | // `build_inter_predictors_sub8x8`'s rule: the left 2x4 from the |
| 2698 | // piece to the LEFT (the group's own left piece, or the decoded |
| 2699 | // neighbour when the group starts on an odd column), the right 2x4 |
| 2700 | // from this piece. A skipped reference piece still predicts (spec |
| 2701 | // 7.11.3) but codes no coefficients. |
| 2702 | } else if chroma_422 && piece_is_chroma_ref(i) { |
| 2703 | const B4: usize = 4; |
| 2704 | let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above"); |
| 2705 | let unit_x = ((lmi.1 & !1) * MI) >> ss_x(fctx); |
| 2706 | let unit_y = py; |
| 2707 | // The left 2x4 half's source: the in-group left piece when this |
| 2708 | // piece is the group's second, else the decoded neighbour one mi |
| 2709 | // to the left (an odd-column group start). Its interp filters |
| 2710 | // are not on the mi grid, so an outside neighbour borrows this |
| 2711 | // piece's own. |
| 2712 | let left_piece = if i > 0 { |
| 2713 | piece[i - 1] |
| 2714 | } else if lmi.1 > 0 { |
| 2715 | grid.get(rmi, lmi.1 - 1).filter(|mi| mi.is_inter).map(|mi| { |
| 2716 | ( |
| 2717 | mi.ref_frame, |
| 2718 | (i32::from(mi.mv.0), i32::from(mi.mv.1)), |
| 2719 | pc_hf, |
| 2720 | pc_vf, |
| 2721 | ) |
| 2722 | }) |
| 2723 | } else { |
| 2724 | None |
| 2725 | }; |
| 2726 | let build_c = move |_y: &mut PlaneBuf<'static>, |
| 2727 | _u: &mut PlaneBuf<'static>, |
| 2728 | _v: &mut PlaneBuf<'static>, |
| 2729 | refpix: &RefPix<'_>, |
| 2730 | fctx: &crate::decode::FrameCtx, |
| 2731 | out: &mut [Vec<u16>; 3]| { |
| 2732 | let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else { |
| 2733 | return; |
| 2734 | }; |
| 2735 | let pc_scale = scale_of((pc_ref_y.true_width, pc_ref_y.true_height), frame_size); |
| 2736 | let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); |
| 2737 | let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); |
| 2738 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 2739 | let mut buf = vec![0u16; B4 * B4]; |
| 2740 | if vert { |
| 2741 | // Right 2x4 half: this piece's own ref/mv/filters. |
| 2742 | let mut half = vec![0u16; 2 * 4]; |
| 2743 | mc::predict_maybe_scaled( |
| 2744 | &plane.data, |
| 2745 | plane.width, |
| 2746 | plane.true_width, |
| 2747 | plane.true_height, |
| 2748 | mv_to_q4(unit_x + 2, pc_mv.1, ss_x(fctx)), |
| 2749 | mv_to_q4(unit_y, pc_mv.0, ss_y(fctx)), |
| 2750 | pc_scale, |
| 2751 | 2, |
| 2752 | 4, |
| 2753 | pc_hf, |
| 2754 | pc_vf, |
| 2755 | &mut half, |
| 2756 | fctx, |
| 2757 | ); |
| 2758 | for row in 0..4 { |
| 2759 | buf[row * B4 + 2..row * B4 + 4] |
| 2760 | .copy_from_slice(&half[row * 2..row * 2 + 2]); |
| 2761 | } |
| 2762 | // Left 2x4 half: the piece to the left (an |
| 2763 | // intra/off-frame neighbour reduces to whole-from-own, |
| 2764 | // `is_sub8x8_inter`'s rule). |
| 2765 | let (l_ref, l_mv, l_hf, l_vf) = match left_piece { |
| 2766 | Some((l_ref, l_mv, l_hf, l_vf)) => (l_ref, l_mv, l_hf, l_vf), |
| 2767 | None => (pc_ref, pc_mv, pc_hf, pc_vf), |
| 2768 | }; |
| 2769 | let Some((l_y, l_u, _)) = ref_planes_deferred(l_ref, refpix) else { |
| 2770 | continue; |
| 2771 | }; |
| 2772 | mc::predict_maybe_scaled( |
| 2773 | &l_u.data, |
| 2774 | l_u.width, |
| 2775 | l_u.true_width, |
| 2776 | l_u.true_height, |
| 2777 | mv_to_q4(unit_x, l_mv.1, ss_x(fctx)), |
| 2778 | mv_to_q4(unit_y, l_mv.0, ss_y(fctx)), |
| 2779 | scale_of((l_y.true_width, l_y.true_height), frame_size), |
| 2780 | 2, |
| 2781 | 4, |
| 2782 | l_hf, |
| 2783 | l_vf, |
| 2784 | &mut half, |
| 2785 | fctx, |
| 2786 | ); |
| 2787 | for row in 0..4 { |
| 2788 | buf[row * B4..row * B4 + 2] |
| 2789 | .copy_from_slice(&half[row * 2..row * 2 + 2]); |
| 2790 | } |
| 2791 | } else { |
| 2792 | mc::predict_maybe_scaled( |
| 2793 | &plane.data, |
| 2794 | plane.width, |
| 2795 | plane.true_width, |
| 2796 | plane.true_height, |
| 2797 | mv_to_q4(unit_x, pc_mv.1, ss_x(fctx)), |
| 2798 | mv_to_q4(unit_y, pc_mv.0, ss_y(fctx)), |
| 2799 | pc_scale, |
| 2800 | B4, |
| 2801 | B4, |
| 2802 | pc_hf, |
| 2803 | pc_vf, |
| 2804 | &mut buf, |
| 2805 | fctx, |
| 2806 | ); |
| 2807 | } |
| 2808 | dst.copy_from_slice(&buf); |
| 2809 | } |
| 2810 | out[1] = pred_u; |
| 2811 | out[2] = pred_v; |
| 2812 | }; |
| 2813 | let (pred_cu, pred_cv): (Vec<u16>, Vec<u16>); |
| 2814 | let (su, sv) = if pred_deferred(refpix) { |
| 2815 | push_pred(build_c); |
| 2816 | (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 }) |
| 2817 | } else { |
| 2818 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 2819 | build_c(y, u, v, refpix, fctx, &mut built); |
| 2820 | let [_, bu, bv] = built; |
| 2821 | (pred_cu, pred_cv) = (bu, bv); |
| 2822 | (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4)) |
| 2823 | }; |
| 2824 | let ctx_mi = (lmi.0, lmi.1 & !1); |
| 2825 | let ca = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); |
| 2826 | if skip { |
| 2827 | push_mc( |
| 2828 | y, |
| 2829 | u, |
| 2830 | v, |
| 2831 | 1, |
| 2832 | unit_x, |
| 2833 | unit_y, |
| 2834 | B4, |
| 2835 | su, |
| 2836 | &ZERO_RESIDUAL[..B4 * B4], |
| 2837 | fctx, |
| 2838 | ); |
| 2839 | push_mc( |
| 2840 | y, |
| 2841 | u, |
| 2842 | v, |
| 2843 | 2, |
| 2844 | unit_x, |
| 2845 | unit_y, |
| 2846 | B4, |
| 2847 | sv, |
| 2848 | &ZERO_RESIDUAL[..B4 * B4], |
| 2849 | fctx, |
| 2850 | ); |
| 2851 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]); |
| 2852 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]); |
| 2853 | } else { |
| 2854 | hit!(CHROMA422_INTER_SUB8_HITS); |
| 2855 | let (ug, _) = read_inter_plane( |
| 2856 | dec, |
| 2857 | cdfs, |
| 2858 | TxbSet::Chroma4, |
| 2859 | scan4, |
| 2860 | 1, |
| 2861 | ca[1], |
| 2862 | 0, |
| 2863 | y, |
| 2864 | u, |
| 2865 | v, |
| 2866 | unit_x, |
| 2867 | unit_y, |
| 2868 | B4, |
| 2869 | base_q_idx, |
| 2870 | su, |
| 2871 | Some(piece_tx_type), |
| 2872 | None, |
| 2873 | fctx, |
| 2874 | )?; |
| 2875 | let (vg, _) = read_inter_plane( |
| 2876 | dec, |
| 2877 | cdfs, |
| 2878 | TxbSet::Chroma4, |
| 2879 | scan4, |
| 2880 | 2, |
| 2881 | ca[2], |
| 2882 | 0, |
| 2883 | y, |
| 2884 | u, |
| 2885 | v, |
| 2886 | unit_x, |
| 2887 | unit_y, |
| 2888 | B4, |
| 2889 | base_q_idx, |
| 2890 | sv, |
| 2891 | Some(piece_tx_type), |
| 2892 | None, |
| 2893 | fctx, |
| 2894 | )?; |
| 2895 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug); |
| 2896 | neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg); |
| 2897 | } |
| 2898 | } |
| 2899 | neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED); |
| 2900 | neighbours.record_inter_rect_mi( |
| 2901 | lmi, |
| 2902 | w_mi, |
| 2903 | h_mi, |
| 2904 | skip, |
| 2905 | true, |
| 2906 | ref_frame, |
| 2907 | resolved_filter, |
| 2908 | false, |
| 2909 | ); |
| 2910 | neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip); |
| 2911 | last_skip = skip; |
| 2912 | } |
| 2913 | // lane-av1-444: at ss 0/0 the group unit does not exist -- each piece |
| 2914 | // coded its own U/V inside the loop above, and each piece wrote its own |
| 2915 | // uv neighbour state (inter pieces through `record_inter_rect_mi`'s |
| 2916 | // is_inter DC stamp, intra pieces through their own per-piece record). |
| 2917 | // The group-level DC stamp below stays 4:2:0-only: at ss 0/0 it painted |
| 2918 | // over an intra piece's real `uv_mode` and the next block's |
| 2919 | // `get_intra_edge_filter_type` lost the smooth neighbour (same class as |
| 2920 | // [`decode_inter_sub8_split4`]'s tail, frame 19 of the fixture). |
| 2921 | // 4:2:0 needs the same second half as the split twin: the stamp must run |
| 2922 | // only when the group unit was painted by the INTER arm below. When the |
| 2923 | // chroma-reference sub-block was INTRA, its own |
| 2924 | // [`decode_intra_sub8_leaf`] tail recorded the group cell with the real |
| 2925 | // `uv_predict_mode`, and this DC stamp ran after it and flattened the |
| 2926 | // mi-exact cell (class `override-slot-on-one-arm`, this lane's own |
| 2927 | // 10-bit film gate regression at 1ad7e0fc; port of lane-av1-cfl's |
| 2928 | // 7c6dad53). lane-av1-422blockhalf: 4:2:2 never takes it either -- the |
| 2929 | // group unit does not exist there; every chroma-reference piece coded |
| 2930 | // (and recorded) its own unit inside the loop above. |
| 2931 | if !chroma_444 && !chroma_422 && !intra_chroma { |
| 2932 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 2933 | } |
| 2934 | // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map |
| 2935 | // needs EVERY writer): a sub-8x8 group published no palette state, so |
| 2936 | // once an 8x8 leaf of the same row can BE a palette block, the group |
| 2937 | // left the row's band holding that earlier block's size and the next |
| 2938 | // intra block read `av1_get_palette_mode_ctx` one too high (measured: |
| 2939 | // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers |
| 2940 | // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` |
| 2941 | // needs `bsize >= BLOCK_8X8`), so the group always clears. |
| 2942 | record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); |
| 2943 | // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded |
| 2944 | // and reconstructed the group's one chroma unit itself. |
| 2945 | // lane-av1-422blockhalf: 4:2:2 never runs this tail -- the shared group |
| 2946 | // unit does not exist at ss (1,0); each chroma-reference piece coded its |
| 2947 | // own U/V TX_4X4 inside the loop above, exactly like the 4:4:4 arm. |
| 2948 | if !chroma_444 && !chroma_422 && !intra_chroma { |
| 2949 | // The group's single 4x4 chroma unit per plane, on the chroma-reference |
| 2950 | // (second) sub-block's own skip flag. |
| 2951 | const B4: usize = 4; |
| 2952 | // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY |
| 2953 | // mi of the group is intra, so a group whose chroma reference is inter but |
| 2954 | // whose sibling is INTRA does NOT get the two-piece sub8x8 prediction: the |
| 2955 | // ordinary 8x8-and-bigger path predicts the WHOLE 4x4 chroma unit from the |
| 2956 | // chroma-reference block's own mv, at the group's chroma origin |
| 2957 | // (`row_start`/`col_start` shift `pre_x`/`pre_y` there either way). |
| 2958 | let mixed = piece[0].is_none(); |
| 2959 | if mixed { |
| 2960 | hit_do! { |
| 2961 | SUB8_INTRA_RECT_HITS.with(|h| { |
| 2962 | let mut s = h.get(); |
| 2963 | s[3] += 1; |
| 2964 | h.set(s); |
| 2965 | }); |
| 2966 | } |
| 2967 | } |
| 2968 | let (piece_w, piece_h) = match (mixed, vert) { |
| 2969 | (true, _) => (B4, B4), |
| 2970 | (false, true) => (2usize, 4usize), |
| 2971 | (false, false) => (4usize, 2usize), |
| 2972 | }; |
| 2973 | // lane-sub8group: the group's chroma pieces, built where they are |
| 2974 | // written -- the pieces' refs/mvs/filters travel by value. |
| 2975 | let build = move |_y: &mut PlaneBuf<'static>, |
| 2976 | _u: &mut PlaneBuf<'static>, |
| 2977 | _v: &mut PlaneBuf<'static>, |
| 2978 | refpix: &RefPix<'_>, |
| 2979 | fctx: &crate::decode::FrameCtx, |
| 2980 | out: &mut [Vec<u16>; 3]| { |
| 2981 | let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); |
| 2982 | let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); |
| 2983 | // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it. |
| 2984 | #[allow(clippy::needless_range_loop)] |
| 2985 | for i in 0..2usize { |
| 2986 | let Some((ref_frame, mv, h_filter, v_filter)) = piece[i] else { |
| 2987 | continue; |
| 2988 | }; |
| 2989 | let Some((piece_ref_y, sref_u, sref_v)) = ref_planes_deferred(ref_frame, refpix) |
| 2990 | else { |
| 2991 | continue; |
| 2992 | }; |
| 2993 | let piece_scale = scale_of( |
| 2994 | (piece_ref_y.true_width, piece_ref_y.true_height), |
| 2995 | frame_size, |
| 2996 | ); |
| 2997 | let (ox, oy) = if mixed { |
| 2998 | (cpx, cpy) |
| 2999 | } else if vert { |
| 3000 | (cpx + i * piece_w, cpy) |
| 3001 | } else { |
| 3002 | (cpx, cpy + i * piece_h) |
| 3003 | }; |
| 3004 | let (dc, dr) = if mixed { |
| 3005 | (0, 0) |
| 3006 | } else if vert { |
| 3007 | (i * piece_w, 0) |
| 3008 | } else { |
| 3009 | (0, i * piece_h) |
| 3010 | }; |
| 3011 | for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { |
| 3012 | let mut buf = vec![0u16; piece_w * piece_h]; |
| 3013 | mc::predict_maybe_scaled( |
| 3014 | &plane.data, |
| 3015 | plane.width, |
| 3016 | plane.true_width, |
| 3017 | plane.true_height, |
| 3018 | mv_to_q4(ox, mv.1, ss_x(fctx)), |
| 3019 | mv_to_q4(oy, mv.0, ss_x(fctx)), |
| 3020 | piece_scale, |
| 3021 | piece_w, |
| 3022 | piece_h, |
| 3023 | h_filter, |
| 3024 | v_filter, |
| 3025 | &mut buf, |
| 3026 | fctx, |
| 3027 | ); |
| 3028 | for row in 0..piece_h { |
| 3029 | for col in 0..piece_w { |
| 3030 | dst[(dr + row) * B4 + dc + col] = buf[row * piece_w + col]; |
| 3031 | } |
| 3032 | } |
| 3033 | } |
| 3034 | } |
| 3035 | out[1] = pred_u; |
| 3036 | out[2] = pred_v; |
| 3037 | }; |
| 3038 | let (pred_u, pred_v): (Vec<u16>, Vec<u16>); |
| 3039 | let (su, sv) = if pred_deferred(refpix) { |
| 3040 | push_pred(build); |
| 3041 | (Pred::Cur { plane: 1, stride: B4, off: 0 }, Pred::Cur { plane: 2, stride: B4, off: 0 }) |
| 3042 | } else { |
| 3043 | let mut built: [Vec<u16>; 3] = Default::default(); |
| 3044 | build(y, u, v, refpix, fctx, &mut built); |
| 3045 | let [_, bu, bv] = built; |
| 3046 | (pred_u, pred_v) = (bu, bv); |
| 3047 | (Pred::Inline(&pred_u, B4), Pred::Inline(&pred_v, B4)) |
| 3048 | }; |
| 3049 | let (u_grid, v_grid) = if last_skip { |
| 3050 | push_mc( |
| 3051 | y, |
| 3052 | u, |
| 3053 | v, |
| 3054 | 1, |
| 3055 | cpx, |
| 3056 | cpy, |
| 3057 | B4, |
| 3058 | su, |
| 3059 | &ZERO_RESIDUAL[..B4 * B4], |
| 3060 | fctx, |
| 3061 | ); |
| 3062 | push_mc( |
| 3063 | y, |
| 3064 | u, |
| 3065 | v, |
| 3066 | 2, |
| 3067 | cpx, |
| 3068 | cpy, |
| 3069 | B4, |
| 3070 | sv, |
| 3071 | &ZERO_RESIDUAL[..B4 * B4], |
| 3072 | fctx, |
| 3073 | ); |
| 3074 | (Grid::Zero(B4 * B4), Grid::Zero(B4 * B4)) |
| 3075 | } else { |
| 3076 | let around = neighbours.around_mi(group_mi, 8); |
| 3077 | let ug = read_inter_plane( |
| 3078 | dec, |
| 3079 | cdfs, |
| 3080 | TxbSet::Chroma4, |
| 3081 | scan4, |
| 3082 | 1, |
| 3083 | around[1], |
| 3084 | 0, |
| 3085 | y, |
| 3086 | u, |
| 3087 | v, |
| 3088 | cpx, |
| 3089 | cpy, |
| 3090 | B4, |
| 3091 | base_q_idx, |
| 3092 | su, |
| 3093 | Some(first_tx_type), |
| 3094 | None, |
| 3095 | fctx, |
| 3096 | )? |
| 3097 | .0; |
| 3098 | let vg = read_inter_plane( |
| 3099 | dec, |
| 3100 | cdfs, |
| 3101 | TxbSet::Chroma4, |
| 3102 | scan4, |
| 3103 | 2, |
| 3104 | around[2], |
| 3105 | 0, |
| 3106 | y, |
| 3107 | u, |
| 3108 | v, |
| 3109 | cpx, |
| 3110 | cpy, |
| 3111 | B4, |
| 3112 | base_q_idx, |
| 3113 | sv, |
| 3114 | Some(first_tx_type), |
| 3115 | None, |
| 3116 | fctx, |
| 3117 | )? |
| 3118 | .0; |
| 3119 | let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0); |
| 3120 | note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded); |
| 3121 | (ug, vg) |
| 3122 | }; |
| 3123 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 3124 | let bound_h = round_up_even(neighbours.mi_rows); |
| 3125 | let bound_w = round_up_even(neighbours.mi_cols); |
| 3126 | let u_state = neighbour_state(&u_grid); |
| 3127 | let v_state = neighbour_state(&v_grid); |
| 3128 | for cell in 0..2usize { |
| 3129 | if cell < 2usize.min(bound_h.saturating_sub(gr)) { |
| 3130 | neighbours.left[gr + cell][1] = u_state; |
| 3131 | neighbours.left[gr + cell][2] = v_state; |
| 3132 | } |
| 3133 | if cell < 2usize.min(bound_w.saturating_sub(gc)) { |
| 3134 | neighbours.above[gc + cell][1] = u_state; |
| 3135 | neighbours.above[gc + cell][2] = v_state; |
| 3136 | } |
| 3137 | } |
| 3138 | } |
| 3139 | // `update_partition_context` writes `partition_context_lookup[subsize]` |
| 3140 | // over the whole 8x8 span -- BLOCK_4X8's width above and height left, the |
| 3141 | // same values [`decode_leaf_rect8`] writes for the intra shape. |
| 3142 | for cell in 0..2usize { |
| 3143 | neighbours.above_side_mi[gc + cell] = bw as u8; |
| 3144 | neighbours.left_side_mi[gr + cell] = bh as u8; |
| 3145 | } |
| 3146 | Ok(()) |
| 3147 | } |