diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 8036e855..281a18b7 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -552,7 +552,7 @@ pub(crate) fn warp_plane_suppress_hits() -> usize { /// block dimensions decide it -- never the square `side`/`chroma_side`, which /// for a rectangular luma block (8x16, 16x8) or a PARTITION_HORZ/VERT strip is /// bigger than the real block in one axis. -fn warp_plane_allowed(w: usize, h: usize) -> bool { +pub(crate) fn warp_plane_allowed(w: usize, h: usize) -> bool { if w >= 8 && h >= 8 { return true; } @@ -24220,7 +24220,7 @@ fn has_top_right(mi_row: usize, mi_col: usize, bs: usize, fctx: &crate::decode:: /// own `bw`/`bh` (fed to [`crate::warp::record_sample`]'s offset formula) /// come from the *neighbour* cell's own coded size, not this block's. #[allow(clippy::too_many_arguments)] -fn find_samples( +pub(crate) fn find_samples( grid: &MiGrid, mi_row: usize, mi_col: usize, @@ -24378,7 +24378,7 @@ fn find_samples( /// `motion_mode_allowed` needs to pick the 3-symbol `motion_mode_cdf` over /// the 2-symbol `obmc_cdf` (spec 5.11.24). #[allow(clippy::too_many_arguments)] -fn num_proj_ref( +pub(crate) fn num_proj_ref( grid: &MiGrid, mi_row: usize, mi_col: usize, @@ -32053,6 +32053,12 @@ fn decode_inter_block8( mc::scale_factor(ref_width, frame_width) != mc::REF_NO_SCALE; let warp_eligible = allow_warped_motion && !ref_is_scaled && !force_integer_mv && proj_ok; + if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + eprintln!( + "EC_MM8 mi_row={mi_row} mi_col={mi_col} proj={} warp_elig={} awm={}", + proj_ok as u8, warp_eligible as u8, allow_warped_motion as u8 + ); + } if allow_warped_motion && proj_ok && ref_is_scaled { hit!(SCALED_WARP_SUPPRESSED_HITS); } @@ -33086,7 +33092,7 @@ pub(crate) fn decode_inter_frame_tile( loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, enable_dual_filter, reference_select, tx_select, &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false, - switchable_motion_mode, fctx, + switchable_motion_mode, false, fctx, ) } @@ -33132,6 +33138,12 @@ pub(crate) fn decode_inter_frame_tile_lr( // crate's own encoder writes once inter blocks started carrying a // `motion_mode` symbol (class: test asserts against a stale header). switchable_motion_mode: bool, + // lane-av1obmc2: this frame header's own `allow_warped_motion` (spec + // 5.9.2) -- what picks the 3-symbol `motion_mode_cdf` alphabet over the + // 2-symbol `obmc_cdf` one at a block with a warp sample. Hard-coding + // `false` here desynced every stream this crate's encoder writes with the + // warp knob on: the same stale-header class as the parameter above. + allow_warped_motion: bool, fctx: &crate::decode::FrameCtx, ) -> Result { let single_tile = TileInfo { @@ -33161,6 +33173,7 @@ pub(crate) fn decode_inter_frame_tile_lr( sign_bias, allow_screen_content_tools, switchable_motion_mode, + allow_warped_motion, fctx, ) } @@ -33196,6 +33209,12 @@ pub(crate) fn decode_inter_frame_tiles_lr( // crate's own encoder writes once inter blocks started carrying a // `motion_mode` symbol (class: test asserts against a stale header). switchable_motion_mode: bool, + // lane-av1obmc2: this frame header's own `allow_warped_motion` (spec + // 5.9.2) -- what picks the 3-symbol `motion_mode_cdf` alphabet over the + // 2-symbol `obmc_cdf` one at a block with a warp sample. Hard-coding + // `false` here desynced every stream this crate's encoder writes with the + // warp knob on: the same stale-header class as the parameter above. + allow_warped_motion: bool, fctx: &crate::decode::FrameCtx, ) -> Result { decode_inter_frame_tile_with_cdfs( @@ -33231,7 +33250,7 @@ pub(crate) fn decode_inter_frame_tiles_lr( true, tx_select, switchable_motion_mode, - false, + allow_warped_motion, allow_screen_content_tools, DeltaParams::default(), // `enable_filter_intra`: this crate's own encoder never writes the @@ -37784,6 +37803,10 @@ mod tests { // Same stale-header class: the bit that makes this frame's // inter blocks carry a `motion_mode` symbol. frame.switchable_motion_mode, + // These GOP round trips decode a tile the encoder wrote, so + // the warp bit must be the one it wrote too (lane-av1obmc2); + // the encoder only sets it under `EC_AV1_WARP`. + crate::envflags::env_flag!("EC_AV1_WARP"), fctx, ) .unwrap(); @@ -38118,6 +38141,10 @@ mod tests { // Same stale-header class: the bit that makes this frame's // inter blocks carry a `motion_mode` symbol. frame.switchable_motion_mode, + // These GOP round trips decode a tile the encoder wrote, so + // the warp bit must be the one it wrote too (lane-av1obmc2); + // the encoder only sets it under `EC_AV1_WARP`. + crate::envflags::env_flag!("EC_AV1_WARP"), fctx, ) .unwrap(); diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 5cd72b5e..30903b68 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1028,7 +1028,10 @@ pub(crate) fn key_frame_headers_colour( additional_frame_id_length: 0, enable_interintra_compound: false, enable_masked_compound: false, - enable_warped_motion: false, + // lane-av1obmc2: the sequence bit `allow_warped_motion` is gated on + // (spec 5.5.2). Set only under the warp knob, so the DEFAULT sequence + // header is byte-identical to the streams before this lane. + enable_warped_motion: crate::envflags::env_flag!("EC_AV1_WARP"), enable_dual_filter: false, enable_jnt_comp: false, enable_ref_frame_mvs: false, @@ -1166,9 +1169,14 @@ pub fn inter_frame_headers_slots( // to the OBMC knob rather than always on: with every block choosing // SIMPLE_TRANSLATION the symbol is pure cost (+0.07% / +0.02% on the // gate clip), so the DEFAULT path writes no motion_mode syntax at all - // and stays byte-identical to the streams before this lane. A future - // warp knob joins this disjunction. - is_motion_mode_switchable: crate::envflags::env_flag!("EC_AV1_OBMC"), + // and stays byte-identical to the streams before this lane. + // lane-av1obmc2: the warp knob joins that disjunction, and turns on + // `allow_warped_motion` besides -- which is what makes an eligible + // block read the 3-symbol `motion_mode_cdf` alphabet instead of the + // 2-symbol `obmc_cdf` one (libaom `motion_mode_allowed`). + is_motion_mode_switchable: crate::envflags::env_flag!("EC_AV1_OBMC") + || crate::envflags::env_flag!("EC_AV1_WARP"), + allow_warped_motion: crate::envflags::env_flag!("EC_AV1_WARP"), use_ref_frame_mvs: false, // Forces `get_tx_set` (spec 5.11.48) to the two-symbol // `TX_SET_INTER_3` for every inter transform below 32x32 -- the only @@ -2439,14 +2447,173 @@ impl Reach { } /// What one symbol costs against a CDF, in bits. -/// What the `motion_mode`/`obmc` symbol costs (spec 5.11.24), off the default -/// table rather than the tile's adapted one -- the same static-CDF estimate -/// every other symbol in this search is priced with. -fn obmc_bits(write_w: usize, write_h: usize, obmc: bool) -> f64 { +/// The smallest LEAF an OBMC candidate is offered for, so the census can +/// attribute the tool's effect by footprint (`EC_AV1_OBMC_MIN`, default 8 -- +/// every leaf; 16 or 32 turn the smaller leaves off). Only read when +/// `EC_AV1_OBMC` is on, and never by the 32x32 whole-block candidate. +/// +/// MEASURED at native, `EC_AV1_OBMC=1` throughout, BD vs libaom / vs rav1e +/// (12 frames, four quantizers, the standing keep table): +/// +/// | min side | film 1080p | film 2160p | screen | +/// |---|---|---|---| +/// | OBMC off | +18.0 / +0.7 | +47.3 / +19.2 | +59.4 / -10.0 | +/// | 32 (32x32 only) | +18.4 / +1.1 | +47.3 / +19.2 | +59.1 / -10.0 | +/// | 16 | +18.4 / +1.1 | +47.3 / +19.2 | +59.3 / -10.0 | +/// | 8 (every leaf) | +18.7 / +1.4 | +47.3 / +19.2 | +59.3 / -10.0 | +/// +/// So the leaves are not the thing that was holding OBMC back: at 8x8 the +/// candidate WINS 9704 of the 11462 leaves that code the symbol on the 1080p +/// film -- 85% of them, far past libaom's own rate -- and costs another 0.3 +/// BD points on top of the 0.4 the 32x32 candidate already costs. A tool +/// that wins the local RD on five blocks in six and loses ladder bytes is +/// the `local-RD-on-references` class again, not a missing footprint. The +/// tool stays OFF by default; the upgrade path is the price, not the size +/// (the 640x384 arm reads +78.9/+36.4, +94.9/+56.3, +54.2/+0.8 at min side 8 +/// against +78.8/+36.1, +95.1/+56.4, +54.5/+1.1 off -- two rows down, the +/// 1080p film up, i.e. the same disagreement between the two gates). +fn obmc_min_side() -> usize { + static N: std::sync::OnceLock = std::sync::OnceLock::new(); + *N.get_or_init(|| { + std::env::var("EC_AV1_OBMC_MIN") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(8) + }) +} + +/// What the `motion_mode`/`obmc` symbol costs (spec 5.11.24), off the tables +/// this frame's writer really starts from (`tile::obmc_symbol_bits`) -- the +/// same frame-CDF price the coefficients of a non-screen frame are estimated +/// with, not the static default table. +/// The same price for whichever alphabet the writer will really use for this +/// block: `warp_alphabet` is `motion_mode_allowed`'s 3-symbol choice +/// (`allow_warped_motion` and at least one warp sample), otherwise the +/// 2-symbol `obmc` one. Both sides of every motion-mode comparison in the +/// search pay it, so the alphabet cancels out of a comparison and only its +/// per-value spread decides. +fn motion_mode_bits(write_w: usize, write_h: usize, motion: u8, warp_alphabet: bool) -> f64 { let Some(row) = crate::decode::motion_mode_cdf_row(write_w, write_h) else { return 0.0; }; - symbol_bits(&cdf::OBMC[row], usize::from(obmc)) + match warp_alphabet { + true => crate::tile::motion_mode_symbol_bits(row, motion), + false => crate::tile::obmc_symbol_bits(row, motion == 1), + } +} + +/// MEASURED 2026-09-06 and NOT KEPT ON BY DEFAULT (`EC_AV1_WARP=1` turns the +/// candidate, the header's `allow_warped_motion` and the sequence's +/// `enable_warped_motion` on together). BD vs libaom / vs rav1e, the standing +/// native keep table, against the same build with the knob off: +/// +/// | clip | warp on | off | +/// |---|---|---| +/// | film 1080p | +18.7 / +1.6 | +18.0 / +0.7 | +/// | film 2160p | +47.3 / +19.2 | +47.3 / +19.2 | +/// | screen | +59.2 / -9.9 | +59.4 / -10.0 | +/// +/// One row flat, one 0.2 down against libaom and 0.1 up against rav1e, and +/// the 1080p film 0.7/0.9 UP -- the keep rule wants two down and one flat, so +/// it stays off. The 640x384 arm reads +78.7/+36.5, +95.1/+56.4, +54.7/+1.2 +/// against +78.8/+36.1, +95.1/+56.4, +54.5/+1.1. The census says the tool +/// fires: 7.0% / 2.7% / 2.4% of the blocks that code a motion_mode symbol +/// take WARPED_CAUSAL at native (197+91+2441 blocks on the 1080p film), so +/// this is a measured loss, not an inert knob. Same shape as the OBMC +/// candidate above it (`obmc_min_side`): a local RD win that does not convert +/// into ladder bytes. +/// +/// The WARPED_CAUSAL prediction of one square single-reference block: the +/// decoder's own warp-sample walk (`decode::find_samples` + +/// `warp::select_samples`), least-squares model (`warp::find_projection`) and +/// affine predictor (`warp::warp_affine`), driven off the encoder's own mi +/// grid -- never a second implementation of any of the three. `None` when the +/// block would code no motion_mode symbol at all, when it has no warp sample +/// (the writer then codes the 2-symbol alphabet, which has no WARPED value), +/// or when the projection is not filter-representable (the decoder would then +/// predict translationally, so the mode is pure cost). +#[allow(clippy::too_many_arguments)] +fn warp_prediction( + grid: &MiGrid, + (mi_row, mi_col): (usize, usize), + (mi_rows, mi_cols): (usize, usize), + (x, y): (usize, usize), + side: usize, + mv: (i32, i32), + ref_frame: i8, + ref_planes: [(&[u16], usize, usize, usize); 3], + fctx: &crate::decode::FrameCtx, +) -> Option<[Vec; 3]> { + let n4 = side / 4; + if !crate::decode::has_overlappable_neighbour(grid, mi_row, mi_col, n4, n4, mi_cols, mi_rows) { + return None; + } + let mut samples = crate::decode::find_samples( + grid, mi_row, mi_col, n4, n4, mi_cols, mi_rows, ref_frame, fctx, + ); + if samples.is_empty() { + return None; + } + if samples.len() > 1 { + crate::warp::select_samples(mv, &mut samples, side as i32, side as i32); + } + let params = crate::warp::find_projection( + &samples, + side as i32, + side as i32, + mv.1, + mv.0, + mi_row as i32, + mi_col as i32, + )?; + let mut pred = [ + vec![0u16; side * side], + vec![0u16; side * side / 4], + vec![0u16; side * side / 4], + ]; + // The translational prediction first, exactly as the decoder builds it, + // then the affine one over the planes whose OWN block is at least 8x8 + // (libaom `av1_init_warp_params` bails below that, so an 8x8 luma block's + // 4x4 chroma stays translational). + for (i, r) in ref_planes.into_iter().enumerate() { + let luma_plane = i == 0; + let (px, py) = if luma_plane { (x, y) } else { (x / 2, y / 2) }; + let s = if luma_plane { side } else { side / 2 }; + mc::predict( + r.0, + r.1, + r.2, + r.3, + mv_to_q4(px, mv.1, luma_plane), + mv_to_q4(py, mv.0, luma_plane), + s, + s, + &mut pred[i], + fctx, + ); + if crate::decode::warp_plane_allowed(s, s) { + let (sub, cside) = (usize::from(!luma_plane) as i32, s as i32); + crate::warp::warp_affine( + ¶ms, + r.0, + r.2 as i32, + r.3 as i32, + r.1 as i32, + &mut pred[i], + px as i32, + py as i32, + cside, + cside, + cside, + sub, + sub, + fctx, + ); + } + } + let [py_buf, pu_buf, pv_buf] = pred; + let u8s = |b: &[u16]| b.iter().map(|&v| v as u8).collect::>(); + Some([u8s(&py_buf), u8s(&pu_buf), u8s(&pv_buf)]) } pub(crate) fn symbol_bits(cdf: &[u16], symbol: usize) -> f64 { @@ -3595,6 +3762,86 @@ fn leaf_compound_stacks<'a>( .collect() } +/// The OBMC prediction of one square single-reference block: this block's own +/// translation prediction (`mc::predict`) with every bordering above/left +/// neighbour blended into the overlap strips by the DECODER's own plan and +/// blend ([`crate::decode::obmc_plan`] / [`crate::decode::obmc_run`]), so what +/// the search prices is what a decoder reconstructs -- never a second +/// implementation of the blend. `None` when the block has no overlappable +/// neighbour at all (the writer would then code no `motion_mode` symbol) or +/// when the plan cannot be built (a neighbour naming a reference this encode +/// does not hold). +#[allow(clippy::too_many_arguments)] +fn obmc_prediction( + grid: &MiGrid, + (mi_row, mi_col): (usize, usize), + (mi_rows, mi_cols): (usize, usize), + (x, y): (usize, usize), + side: usize, + mv: (i32, i32), + refs: &[Option<&Picture>; 8], + // This block's OWN reference planes, luma then both chroma, each as + // (samples, stride, true width, true height). + ref_planes: [(&[u16], usize, usize, usize); 3], + frame_width: usize, + fctx: &crate::decode::FrameCtx, +) -> Option<[Vec; 3]> { + let n4 = side / 4; + if !crate::decode::has_overlappable_neighbour(grid, mi_row, mi_col, n4, n4, mi_cols, mi_rows) { + return None; + } + let refpix = crate::decode::RefPix::ready(*refs); + let plan = crate::decode::obmc_plan( + grid, + &[], + &[], + mi_row, + mi_col, + n4, + n4, + mi_rows, + mi_cols, + side, + side, + side, + side / 2, + x, + y, + x / 2, + y / 2, + &refpix, + Some(mc::InterpFilterKind::Regular), + frame_width, + ) + .ok()?; + let mut pred = [ + vec![0u16; side * side], + vec![0u16; side * side / 4], + vec![0u16; side * side / 4], + ]; + for (i, r) in ref_planes.into_iter().enumerate() { + let luma_plane = i == 0; + let (px, py) = if luma_plane { (x, y) } else { (x / 2, y / 2) }; + let s = if luma_plane { side } else { side / 2 }; + mc::predict( + r.0, + r.1, + r.2, + r.3, + mv_to_q4(px, mv.1, luma_plane), + mv_to_q4(py, mv.0, luma_plane), + s, + s, + &mut pred[i], + fctx, + ); + } + let [mut py_buf, mut pu_buf, mut pv_buf] = pred; + crate::decode::obmc_run(&plan, &refpix, &mut py_buf, &mut pu_buf, &mut pv_buf, fctx); + let u8s = |b: &[u16]| b.iter().map(|&v| v as u8).collect::>(); + Some([u8s(&py_buf), u8s(&pu_buf), u8s(&pv_buf)]) +} + fn code_square_inter( luma: &mut Plane, chroma: &mut [Plane; 2], @@ -3608,6 +3855,17 @@ fn code_square_inter( // leaf's own `bw4`/`bh4` (empty on a frame that does not code // `reference_select`, and at the straddling call sites). compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], + // lane-av1obmc2: the mi grid this leaf's neighbours were published into + // (`record_mi`, in the writer's own coding order) and this leaf's place in + // it -- what the OBMC candidate's eligibility walk and neighbour plan + // read, the same state the tile writer reads when it codes the leaf's + // `motion_mode` symbol. + grid: &MiGrid, + (mi_row, mi_col): (usize, usize), + (mi_rows, mi_cols): (usize, usize), + // Every picture an OBMC neighbour can name: a leaf only searches LAST, + // but the neighbours it blends may be GOLDEN/ALTREF blocks. + refs: &[Option<&Picture>; 8], fctx: &crate::decode::FrameCtx, ) -> (BlockCoeffs, f64) { let (intra_block, intra_cost) = @@ -3747,6 +4005,21 @@ fn code_square_inter( // prices for a whole block -- `motion::search` from `pred_mv`, rounded to // a vector the residual syntax can name -- at this leaf's own side. let mut best: (f64, Option<(Trial, Trial, Trial, bool, InterInfo)>) = (inter_cost, None); + // The `NEARESTMV` candidate `inter_cost` prices, named once so the OBMC + // re-price below can hand it back as the winner's own mode info. + let nearest_info = InterInfo { + ref1: None, + mv1: (0, 0), + ref_frame: crate::mvstack::LAST_FRAME, + mode: InterMode::NearestMv, + mv, + ref_mv_idx: 0, + }; + // What the current SINGLE-REFERENCE winner pays in mode/reference/mv + // syntax, apart from its residual: the OBMC candidate re-prices the same + // syntax against a different prediction, so both sides of that comparison + // carry it. + let mut single_syntax = intra_inter_bits(true) + single_ref_bits + mode_bits_inter; // This leaf's own `NEWMV` vector, kept whether or not it won the // single-reference comparison: it seeds the compound half-new candidate // below, exactly as `search_inter_block` seeds its own from the searches @@ -3823,6 +4096,11 @@ fn code_square_inter( luma_new.bits + u_new.bits + v_new.bits }); if cost_new < best.0 { + single_syntax = intra_inter_bits(true) + + single_ref_bits + + symbol_bits(&cdf::NEW_MV[stack.new_mv_ctx], 0) + + drl_bits + + mv_bits; best = ( cost_new, Some(( @@ -4037,6 +4315,112 @@ fn code_square_inter( } } + // lane-av1obmc2: the OBMC candidate at a 16x16 / 8x8 LEAF (spec + // `motion_mode == OBMC_CAUSAL`), offered to this leaf's single-reference + // winner -- libaom's `motion_mode_allowed` refuses a compound block, and + // the writer codes no symbol for one. The prediction is the decoder's own + // plan and blend over the neighbours this leaf's `grid` already carries + // (published by `record_mi` in the writer's coding order), so the + // reconstruction priced here is the one a decoder rebuilds. lane-av1obmc + // offered this only at 32x32, which is not where libaom cashes its OBMC + // gain. + let mut motion_won = 0u8; + let single = match &best.1 { + None => Some(nearest_info), + Some((_, _, _, _, info)) if info.ref1.is_none() => Some(*info), + Some(_) => None, + }; + if let Some(info) = single.filter(|i| { + (crate::envflags::env_flag!("EC_AV1_OBMC") || crate::envflags::env_flag!("EC_AV1_WARP")) + && i.ref_frame == crate::mvstack::LAST_FRAME + }) { + let planes = [ + (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), + (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), + (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), + ]; + // Which alphabet this block's writer will code the symbol against + // (`tile::write_motion_mode`, libaom `motion_mode_allowed`): the + // 3-symbol one only under `allow_warped_motion` and at least one warp + // sample. Mirrored here so the candidates are priced against the + // table the tile really narrows. + let warp_alphabet = crate::envflags::env_flag!("EC_AV1_WARP") + && crate::decode::num_proj_ref( + grid, + mi_row, + mi_col, + side / 4, + side / 4, + mi_cols, + mi_rows, + info.ref_frame, + fctx, + ) >= 1; + let mm = |m: u8| motion_mode_bits(side, side, m, warp_alphabet); + let mut candidates: Vec<(u8, [Vec; 3])> = Vec::new(); + if crate::envflags::env_flag!("EC_AV1_OBMC") && side >= obmc_min_side() { + if let Some(pred) = obmc_prediction( + grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + (x, y), + side, + info.mv, + refs, + planes, + reference.width, + fctx, + ) { + candidates.push((1, pred)); + } + } + if warp_alphabet { + if let Some(pred) = warp_prediction( + grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + (x, y), + side, + info.mv, + info.ref_frame, + planes, + fctx, + ) { + candidates.push((2, pred)); + } + } + for (motion, pred) in candidates { + let luma_o = luma.code_from_prediction( + x, y, side, &pred[0], false, search.base_q_idx, search.deadzone, luma_set, + ); + let u_o = chroma[0].code_from_prediction( + x / 2, y / 2, side / 2, &pred[1], false, search.base_q_idx, search.deadzone, + chroma_set, + ); + let v_o = chroma[1].code_from_prediction( + x / 2, y / 2, side / 2, &pred[2], false, search.base_q_idx, search.deadzone, + chroma_set, + ); + let skip_o = luma_o.levels.iter().all(|&l| l == 0) + && u_o.levels.iter().all(|&l| l == 0) + && v_o.levels.iter().all(|&l| l == 0); + let cost_o = luma_o.sse + + u_o.sse + + v_o.sse + + search.lambda + * (skip_bits(skip_o) + + single_syntax + + mm(motion) + + if skip_o { 0.0 } else { luma_o.bits + u_o.bits + v_o.bits }); + // The incumbent pays the motion_mode symbol IT would code, so + // both sides of the comparison carry that syntax. + if cost_o < best.0 + search.lambda * mm(motion_won) { + motion_won = motion; + best = (cost_o, Some((luma_o, u_o, v_o, skip_o, info))); + } + } + } + if let (cost, Some((luma_new, u_new, v_new, skip_new, info))) = best { if cost < intra_cost { // A compound winner commits the flat trial it was priced from: @@ -4059,7 +4443,10 @@ fn code_square_inter( // +1.4 against the +78.8/+95.1/+54.5 and +36.1/+56.4/+1.4 of the // same build without it. The static-CDF estimate was NOT what // held the compound var-tx trial back. The flat trial stays. - let (levels, tx_depth, dcost) = if info.ref1.is_some() { + // An OBMC winner commits the flat trial too: `commit_inter_luma` + // re-predicts each var-tx unit by plain translation, which is not + // the prediction this candidate was priced from. + let (levels, tx_depth, dcost) = if info.ref1.is_some() || motion_won != 0 { luma.commit(x, y, side, &luma_new); (luma_new.levels.clone(), 0, 0.0) } else { @@ -4085,7 +4472,7 @@ fn code_square_inter( palette_uv: None, tx_depth, inter: Some(info), - obmc: false, + motion_mode: motion_won, }, cost + dcost, ); @@ -4117,7 +4504,7 @@ fn code_square_inter( palette: None, palette_uv: None, tx_depth, - obmc: false, + motion_mode: 0, inter: Some(InterInfo { ref1: None, mv1: (0, 0), @@ -6516,117 +6903,117 @@ fn search_inter_block( // that is where libaom cashes most of its OBMC gain), and the symbol/ // residual price here is the static-CDF estimate. let mut best = best; - let mut obmc_won = false; - if let Some(info) = best.inter.filter(|i| i.ref1.is_none()) { - if crate::envflags::env_flag!("EC_AV1_OBMC") - && crate::decode::has_overlappable_neighbour(grid, mi_row, mi_col, 8, 8, mi_cols, mi_rows) - { - let mut refs: [Option<&Picture>; 8] = [None; 8]; - refs[LAST_FRAME as usize] = Some(reference); - for &(r, p, _) in extra { - refs[r as usize] = Some(p); - } - let refpix = crate::decode::RefPix::ready(refs); - let plan = crate::decode::obmc_plan( + let mut motion_won = 0u8; + if let Some(info) = best.inter.filter(|i| { + i.ref1.is_none() + && (crate::envflags::env_flag!("EC_AV1_OBMC") + || crate::envflags::env_flag!("EC_AV1_WARP")) + }) { + let mut refs: [Option<&Picture>; 8] = [None; 8]; + refs[LAST_FRAME as usize] = Some(reference); + for &(r, p, _) in extra { + refs[r as usize] = Some(p); + } + // This block's OWN reference planes: the single-reference winner may + // be one of the extra references, not LAST. + let planes: [(&[u16], usize, usize, usize); 3] = + match extra.iter().find(|(r, _, _)| *r == info.ref_frame) { + Some(&(_, g, _)) => [ + (g.y.as_slice(), g.width, luma.true_width, luma.true_height), + (g.u.as_slice(), g.width / 2, chroma[0].true_width, chroma[0].true_height), + (g.v.as_slice(), g.width / 2, chroma[1].true_width, chroma[1].true_height), + ], + None => [ + (ref_luma.0.as_slice(), ref_luma.1, ref_luma.2, ref_luma.3), + (ref_u.0.as_slice(), ref_u.1, ref_u.2, ref_u.3), + (ref_v.0.as_slice(), ref_v.1, ref_v.2, ref_v.3), + ], + }; + // The alphabet `tile::write_motion_mode` will code this block's + // symbol against, mirrored term for term (libaom + // `motion_mode_allowed`). + let warp_alphabet = crate::envflags::env_flag!("EC_AV1_WARP") + && crate::decode::num_proj_ref( grid, - &[], - &[], mi_row, mi_col, 8, 8, - mi_rows, mi_cols, + mi_rows, + info.ref_frame, + fctx, + ) >= 1; + let mm = |m: u8| motion_mode_bits(BLOCK, BLOCK, m, warp_alphabet); + let mut candidates: Vec<(u8, [Vec; 3])> = Vec::new(); + if crate::envflags::env_flag!("EC_AV1_OBMC") { + if let Some(pred) = obmc_prediction( + grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + (x, y), BLOCK, - BLOCK, - BLOCK, - BLOCK / 2, - x, - y, - x / 2, - y / 2, - &refpix, - Some(mc::InterpFilterKind::Regular), + info.mv, + &refs, + planes, reference.width, + fctx, + ) { + candidates.push((1, pred)); + } + } + if warp_alphabet { + if let Some(pred) = warp_prediction( + grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + (x, y), + BLOCK, + info.mv, + info.ref_frame, + planes, + fctx, + ) { + candidates.push((2, pred)); + } + } + for (motion, pred) in candidates { + let luma_trial = luma.code_from_prediction( + x, y, BLOCK, &pred[0], false, search.base_q_idx, search.deadzone, + TxbSet::Luma32Inter, ); - if let Ok(plan) = plan { - let (ref_luma, ref_u, ref_v) = match extra - .iter() - .find(|(r, _, _)| *r == info.ref_frame) - { - Some(&(_, g, _)) => ( - (&g.y, g.width, luma.true_width, luma.true_height), - (&g.u, g.width / 2, chroma[0].true_width, chroma[0].true_height), - (&g.v, g.width / 2, chroma[1].true_width, chroma[1].true_height), - ), - None => (ref_luma, ref_u, ref_v), + let u = chroma[0].code_from_prediction( + x / 2, y / 2, BLOCK / 2, &pred[1], false, search.base_q_idx, search.deadzone, + chroma_set, + ); + let v = chroma[1].code_from_prediction( + x / 2, y / 2, BLOCK / 2, &pred[2], false, search.base_q_idx, search.deadzone, + chroma_set, + ); + let skip = luma_trial.levels.iter().all(|&l| l == 0) + && u.levels.iter().all(|&l| l == 0) + && v.levels.iter().all(|&l| l == 0); + let cost = luma_trial.sse + + u.sse + + v.sse + + search.lambda + * (skip_bits(skip) + + intra_inter_bits(true) + + best.mode_bits + + mm(motion) + + if skip { 0.0 } else { luma_trial.bits + u.bits + v.bits }); + if cost < best.cost + search.lambda * mm(motion_won) { + motion_won = motion; + best = Candidate { + cost, + luma: luma_trial, + u, + v, + mode: DC_PRED, + skip, + mode_bits: best.mode_bits, + inter: best.inter, }; - let mv = info.mv; - let mut pred = [ - vec![0u16; BLOCK * BLOCK], - vec![0u16; BLOCK * BLOCK / 4], - vec![0u16; BLOCK * BLOCK / 4], - ]; - for (i, (r, luma_plane)) in - [(ref_luma, true), (ref_u, false), (ref_v, false)].into_iter().enumerate() - { - let (px, py) = if luma_plane { (x, y) } else { (x / 2, y / 2) }; - let side = if luma_plane { BLOCK } else { BLOCK / 2 }; - mc::predict( - r.0, - r.1, - r.2, - r.3, - mv_to_q4(px, mv.1, luma_plane), - mv_to_q4(py, mv.0, luma_plane), - side, - side, - &mut pred[i], - fctx, - ); - } - let [mut py_buf, mut pu_buf, mut pv_buf] = pred; - crate::decode::obmc_run( - &plan, &refpix, &mut py_buf, &mut pu_buf, &mut pv_buf, fctx, - ); - let u8s = |b: &[u16]| b.iter().map(|&v| v as u8).collect::>(); - let luma_trial = luma.code_from_prediction( - x, y, BLOCK, &u8s(&py_buf), false, search.base_q_idx, search.deadzone, - TxbSet::Luma32Inter, - ); - let u = chroma[0].code_from_prediction( - x / 2, y / 2, BLOCK / 2, &u8s(&pu_buf), false, search.base_q_idx, - search.deadzone, chroma_set, - ); - let v = chroma[1].code_from_prediction( - x / 2, y / 2, BLOCK / 2, &u8s(&pv_buf), false, search.base_q_idx, - search.deadzone, chroma_set, - ); - let skip = luma_trial.levels.iter().all(|&l| l == 0) - && u.levels.iter().all(|&l| l == 0) - && v.levels.iter().all(|&l| l == 0); - let cost = luma_trial.sse - + u.sse - + v.sse - + search.lambda - * (skip_bits(skip) - + intra_inter_bits(true) - + best.mode_bits - + obmc_bits(BLOCK, BLOCK, true) - + if skip { 0.0 } else { luma_trial.bits + u.bits + v.bits }); - if cost < best.cost + search.lambda * obmc_bits(BLOCK, BLOCK, false) { - obmc_won = true; - best = Candidate { - cost, - luma: luma_trial, - u, - v, - mode: DC_PRED, - skip, - mode_bits: best.mode_bits, - inter: best.inter, - }; - } } } } @@ -6651,7 +7038,7 @@ fn search_inter_block( uv_mode: DC_PRED, skip: best.skip, inter: best.inter, - obmc: obmc_won, + motion_mode: motion_won, eight: None, dv: None, palette: None, @@ -6932,6 +7319,12 @@ pub(crate) fn encode_inter_frame( clip_planes_to_tile(&mut luma, &mut chroma, rect); let mut grid = MiGrid::new(mi_cols, mi_rows); grid.set_sign_bias(sign_bias); + // lane-av1obmc2: every picture an OBMC neighbour of a LEAF can name, + // built once per tile job (`obmc_prediction`). + let mut obmc_refs: [Option<&Picture>; 8] = [None; 8]; + obmc_refs[crate::mvstack::LAST_FRAME as usize] = Some(reference); + obmc_refs[crate::mvstack::GOLDEN_FRAME as usize] = golden; + obmc_refs[crate::mvstack::ALTREF_FRAME as usize] = altref; grid.set_tile_bounds( rect.mi_row0 as usize, rect.mi_col0 as usize, @@ -7100,7 +7493,13 @@ pub(crate) fn encode_inter_frame( &search, &mode_bits_table, reference, - &stack, &cstacks, fctx, + &stack, + &cstacks, + &grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + &obmc_refs, + fctx, ); let leaf_cost = leaf_cost + search.lambda * partition_bits(SUB, false); @@ -7161,7 +7560,13 @@ pub(crate) fn encode_inter_frame( &search, &mode_bits_table, reference, - &stack8, &cstacks8, fctx, + &stack8, + &cstacks8, + &grid, + (mr, mc), + (mi_rows, mi_cols), + &obmc_refs, + fctx, ); cost8 += cost; record_mi(&mut grid, mr, mc, 2, leaf8.inter); @@ -7266,7 +7671,13 @@ pub(crate) fn encode_inter_frame( &search, &mode_bits_table, reference, - &stack, &cstacks, fctx, + &stack, + &cstacks, + &grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + &obmc_refs, + fctx, ); // One publication point for every coded leaf // (`record_mi`): this site used to spell the vote @@ -7303,7 +7714,13 @@ pub(crate) fn encode_inter_frame( &search, &mode_bits_table, reference, - &stack, &cstacks, fctx, + &stack, + &cstacks, + &grid, + (mi_row, mi_col), + (mi_rows, mi_cols), + &obmc_refs, + fctx, ); // Same publication point as the 16x16 // straddling leaf above (`record_mi`). @@ -7374,6 +7791,7 @@ pub(crate) fn encode_inter_frame( let start_cdfs = CdfSnapshot(cdfs); let reference_select_bit = header.reference_select; let switchable_motion_mode = header.is_motion_mode_switchable; + let warped_motion = header.allow_warped_motion; let order_hint_bits = seq.order_hint_bits; let lr_horz = crate::restoration::count_units(header.frame_width, 64) as u32; let lr_vert = crate::restoration::count_units(header.frame_height, 64) as u32; @@ -7396,6 +7814,7 @@ pub(crate) fn encode_inter_frame( // Thread-locals: every tile job arms its own worker. crate::tile::arm_reference_select(reference_select_bit); crate::tile::arm_motion_mode(switchable_motion_mode); + crate::tile::arm_warped_motion(warped_motion); crate::tile::arm_order_hints(order_hint_bits, order_hint, order_hints); crate::tile::arm_screen(screen); let mut cdfs = start_cdfs.0.clone(); @@ -7523,6 +7942,7 @@ pub(crate) fn encode_inter_frame( sign_bias, h.allow_screen_content_tools, switchable_motion_mode, + h.allow_warped_motion, fctx, ) }, @@ -8326,7 +8746,7 @@ mod tests { mv: (0, 0), ref_mv_idx: 0, }), - obmc: false, + motion_mode: 0, }; let skipped_block = BlockCoeffs { skip: true, @@ -8350,6 +8770,7 @@ mod tests { // `is_motion_mode_switchable`, so the writer must be armed with it // too or the decoder reads a `motion_mode` symbol nobody wrote. crate::tile::arm_motion_mode(inter_header.is_motion_mode_switchable); + crate::tile::arm_warped_motion(inter_header.allow_warped_motion); let tile = crate::tile::sb_coeff_inter_frame_tile(inter_header.mi_cols, inter_header.mi_rows, 100, &blocks) .unwrap(); @@ -11441,10 +11862,12 @@ mod tests { // `gate-blind-to-feature`). let mm = crate::tile::take_motion_mode_hits(); eprintln!( - "{name}: motion_mode 32x32 SIMPLE={} OBMC={} | 16x16 SIMPLE={} OBMC={} | \ - 8x8 SIMPLE={} OBMC={} ({:.1}% OBMC of {} eligible)", - mm[0], mm[1], mm[2], mm[3], mm[4], mm[5], - 100.0 * (mm[1] + mm[3] + mm[5]) as f64 / mm.iter().sum::().max(1) as f64, + "{name}: motion_mode 32x32 SIMPLE={} OBMC={} WARP={} | 16x16 SIMPLE={} OBMC={} \ + WARP={} | 8x8 SIMPLE={} OBMC={} WARP={} ({:.1}% OBMC / {:.1}% WARP of {} \ + eligible)", + mm[0], mm[1], mm[2], mm[3], mm[4], mm[5], mm[6], mm[7], mm[8], + 100.0 * (mm[1] + mm[4] + mm[7]) as f64 / mm.iter().sum::().max(1) as f64, + 100.0 * (mm[2] + mm[5] + mm[8]) as f64 / mm.iter().sum::().max(1) as f64, mm.iter().sum::(), ); let (aom, aom_wall) = @@ -11654,6 +12077,21 @@ mod tests { // the real side, a screen clip none of them. let (price_default, price_real) = crate::tile::take_pricing_hits(); eprintln!("{name}: pricer armings default={price_default} real={price_real}"); + // lane-av1obmc2: the same motion_mode census the 640x384 gate + // prints (class `gate-blind-to-feature`) -- how many blocks coded + // the symbol at each footprint and how many took OBMC. Without it + // the native table, which is the standing keep table, could not + // say whether the tool fired at all. + let mm = crate::tile::take_motion_mode_hits(); + eprintln!( + "{name}: motion_mode 32x32 SIMPLE={} OBMC={} WARP={} | 16x16 SIMPLE={} OBMC={} \ + WARP={} | 8x8 SIMPLE={} OBMC={} WARP={} ({:.1}% OBMC / {:.1}% WARP of {} \ + eligible)", + mm[0], mm[1], mm[2], mm[3], mm[4], mm[5], mm[6], mm[7], mm[8], + 100.0 * (mm[1] + mm[4] + mm[7]) as f64 / mm.iter().sum::().max(1) as f64, + 100.0 * (mm[2] + mm[5] + mm[8]) as f64 / mm.iter().sum::().max(1) as f64, + mm.iter().sum::(), + ); let palette = crate::tile::take_palette_hits(); let palette_uv = crate::tile::take_palette_uv_hits(); let ibc = crate::tile::take_intrabc_hits(); diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index f22967bc..77deb122 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -390,6 +390,28 @@ thread_local! { static MOTION_MODE: std::cell::Cell = const { std::cell::Cell::new(false) }; } +thread_local! { + /// This frame header's own `allow_warped_motion` bit (spec 5.9.2): with + /// it set, every block libaom's `motion_mode_allowed` accepts AND that + /// has at least one warp sample (`num_proj_ref >= 1`) reads the 3-symbol + /// `motion_mode_cdf` alphabet instead of the 2-symbol `obmc_cdf` one. + /// lane-av1obmc2. + static WARPED_MOTION: std::cell::Cell = const { std::cell::Cell::new(false) }; + /// The frame geometry the warp-sample walk needs (`num_proj_ref` -> + /// `has_top_right`), which is only ever this writer's own superblock + /// size. Every stream this crate writes uses a 64 superblock, which is + /// `FrameCtx::new`'s default. + /// corner-cut: ceiling is a 128-superblock WRITER -- it must arm the real + /// frame context here (or take one as a parameter) or the warp-sample + /// walk reads the wrong `has_top_right` geometry. + static WRITER_FCTX: crate::decode::FrameCtx = crate::decode::FrameCtx::new(); +} + +/// Arms [`WARPED_MOTION`] for the next tile written on this thread. +pub(crate) fn arm_warped_motion(on: bool) { + WARPED_MOTION.with(|c| c.set(on)); +} + /// Arms the frame's `is_motion_mode_switchable` bit for the next tile written /// on this thread; cleared by [`CdefIdxGuard`] when that writer returns. pub(crate) fn arm_motion_mode(on: bool) { @@ -401,16 +423,40 @@ pub(crate) fn arm_motion_mode(on: bool) { /// -- the histogram a gate prints so that "OBMC is on" is a measurement, not /// a claim (class `gate-blind-to-feature`). Index: `0 + 2 * bucket` for /// SIMPLE, `1 + 2 * bucket` for OBMC, bucket 0/1/2 = 32x32/16x16/8x8. -static MOTION_MODE_HITS: [std::sync::atomic::AtomicUsize; 6] = - [const { std::sync::atomic::AtomicUsize::new(0) }; 6]; +static MOTION_MODE_HITS: [std::sync::atomic::AtomicUsize; 9] = + [const { std::sync::atomic::AtomicUsize::new(0) }; 9]; /// Reads [`MOTION_MODE_HITS`] and zeroes it, so a gate can attribute the /// counts to its own encode. #[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(crate) fn take_motion_mode_hits() -> [usize; 6] { +pub(crate) fn take_motion_mode_hits() -> [usize; 9] { std::array::from_fn(|i| MOTION_MODE_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed)) } +/// What the 3-symbol `motion_mode` symbol costs, in bits, against the same +/// frame tables [`obmc_symbol_bits`] prices the 2-symbol alphabet off -- +/// which alphabet a block reads is `motion_mode_allowed`'s own choice +/// ([`write_motion_mode`]). +pub(crate) fn motion_mode_symbol_bits(row: usize, motion: u8) -> f64 { + PRICING_BASE.with_borrow(|slot| match slot.as_deref() { + Some(s) => crate::encode::symbol_bits(&s.0.motion_mode[row], usize::from(motion)), + None => crate::encode::symbol_bits(&crate::cdf::MOTION_MODE[row], usize::from(motion)), + }) +} + +/// What the `motion_mode`/`obmc` symbol costs, in bits, against the tables +/// this frame's writer really starts from ([`arm_pricing_cdfs`]) -- the same +/// tables the coefficients are priced off since lane-av1price2, rather than +/// the static defaults the symbol used to be estimated with. Falls back to +/// the default table whenever the search is armed with the defaults (a key +/// frame, or a screen frame the gate turned off). +pub(crate) fn obmc_symbol_bits(row: usize, obmc: bool) -> f64 { + PRICING_BASE.with_borrow(|slot| match slot.as_deref() { + Some(s) => crate::encode::symbol_bits(&s.0.obmc[row], usize::from(obmc)), + None => crate::encode::symbol_bits(&crate::cdf::OBMC[row], usize::from(obmc)), + }) +} + /// `read_motion_mode`'s write side (spec 5.11.24), called on a /// single-reference inter block right after its MV syntax and before the /// (never switchable here) interpolation filter -- libaom's own sequential @@ -432,7 +478,12 @@ fn write_motion_mode( (bw4, bh4): (usize, usize), (write_w, write_h): (usize, usize), (mi_cols, mi_rows): (usize, usize), - obmc: bool, + // This block's own reference, for the warp-sample walk that picks the + // alphabet (`num_proj_ref`). + ref_frame: i8, + // 0 SIMPLE_TRANSLATION, 1 OBMC_CAUSAL, 2 WARPED_CAUSAL -- what the + // encoder's search committed for this block. + motion: u8, ) -> Result<()> { let eligible = MOTION_MODE.with(std::cell::Cell::get) && write_w.min(write_h) >= 8 @@ -440,9 +491,15 @@ fn write_motion_mode( grid, mi_row, mi_col, bw4, bh4, mi_cols, mi_rows, ); if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { + let proj = WRITER_FCTX.with(|fctx| { + crate::decode::num_proj_ref( + grid, mi_row, mi_col, bw4, bh4, mi_cols, mi_rows, ref_frame, fctx, + ) + }); eprintln!( - "EC_MMW mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={}", - eligible as u8 + "EC_MMW mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} proj={proj} warp_armed={} motion={motion}", + eligible as u8, + WARPED_MOTION.with(std::cell::Cell::get) as u8, ); } if !eligible { @@ -450,7 +507,7 @@ fn write_motion_mode( // codes as SIMPLE_TRANSLATION: its reconstruction is not the // decoder's (class encoder-grid-drift), which is exactly what the // `EC_COMP_MISMATCH` rung exists to catch. - if obmc && crate::envflags::env_flag!("EC_COMP_MISMATCH") { + if motion != 0 && crate::envflags::env_flag!("EC_COMP_MISMATCH") { eprintln!( "EC_COMP_MISMATCH motion_mode enc=OBMC wrote=SIMPLE mi=({mi_row},{mi_col}) wh=({write_w}x{write_h})" ); @@ -463,13 +520,37 @@ fn write_motion_mode( format!("a {write_w}x{write_h} block has no motion_mode CDF row"), ) })?; - enc.symbol(usize::from(obmc), &mut cdfs.obmc[row]); + // libaom `motion_mode_allowed`: the 3-symbol `motion_mode_cdf` alphabet + // exactly when `allow_warped_motion` is on and the block has at least one + // warp sample. The other two vetoes libaom applies there cannot fire for + // a stream this encoder writes -- it codes no scaled reference and no + // inter frame with `force_integer_mv` -- and the decoder checks all three + // (`decode.rs`'s `warp_eligible`), so the two sides agree term for term. + let warp_alphabet = WARPED_MOTION.with(std::cell::Cell::get) + && WRITER_FCTX.with(|fctx| { + crate::decode::num_proj_ref( + grid, mi_row, mi_col, bw4, bh4, mi_cols, mi_rows, ref_frame, fctx, + ) + }) >= 1; + if warp_alphabet { + enc.symbol(usize::from(motion), &mut cdfs.motion_mode[row]); + } else { + // A warp winner whose block the writer resolves to the 2-symbol + // alphabet would reconstruct as SIMPLE at the decoder: the same + // encoder-grid-drift rung the OBMC case above prints. + if motion == 2 && crate::envflags::env_flag!("EC_COMP_MISMATCH") { + eprintln!( + "EC_COMP_MISMATCH motion_mode enc=WARP wrote=SIMPLE mi=({mi_row},{mi_col}) wh=({write_w}x{write_h})" + ); + } + enc.symbol(usize::from(motion == 1), &mut cdfs.obmc[row]); + } let bucket = match write_w.min(write_h) { 32.. => 0, 16 => 1, _ => 2, }; - MOTION_MODE_HITS[usize::from(obmc) + 2 * bucket] + MOTION_MODE_HITS[usize::from(motion.min(2)) + 3 * bucket] .fetch_add(1, std::sync::atomic::Ordering::Relaxed); Ok(()) } @@ -1334,12 +1415,11 @@ pub struct BlockCoeffs { /// block. Only [`sb_coeff_inter_frame_tile`] codes `is_inter`; the key /// frame writers never read this field. pub inter: Option, - /// Whether this (single-reference inter) block's prediction was built - /// with OBMC -- spec `motion_mode == OBMC_CAUSAL`, written by - /// [`write_motion_mode`]. `false` (the [`Default`]) is - /// `SIMPLE_TRANSLATION`, the only motion mode this writer coded before - /// lane-av1obmc. - pub obmc: bool, + /// This (single-reference inter) block's spec `motion_mode`, written by + /// [`write_motion_mode`]: 0 `SIMPLE_TRANSLATION` (the [`Default`], and + /// the only mode this writer coded before lane-av1obmc), 1 `OBMC_CAUSAL`, + /// 2 `WARPED_CAUSAL` (lane-av1obmc2). + pub motion_mode: u8, /// The 8x8 leaves a straddling 16x16 block is split into (lane-av1-rect), /// each with its own 8x8 luma transform and 4x4 chroma transforms, in /// raster order among the leaves that are inside the true frame. `Some` @@ -5607,7 +5687,8 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( (8, 8), (BLOCK, BLOCK), (mi_cols as usize, mi_rows as usize), - block.obmc, + info.ref_frame, + block.motion_mode, )?; mode_for_tx = 0; } @@ -5841,7 +5922,8 @@ fn write_inter_frame_leaf( (SUB_MI as usize, SUB_MI as usize), (SUB, SUB), (mi_cols as usize, mi_rows as usize), - block.obmc, + info.ref_frame, + block.motion_mode, )?; mode_for_tx = 0; } @@ -6081,7 +6163,8 @@ fn write_inter_frame_leaf8( (2, 2), (8, 8), (mi_cols as usize, mi_rows as usize), - block.obmc, + info.ref_frame, + block.motion_mode, )?; mode_for_tx = 0; }