forge
Explore
Log in

Don't you dare go Hollow

An OBMC candidate for the 32x32 single-reference winner, measured and defaulted off

Browse files at this commit

84a1ea3cad68fe410752be08c2df838cb345ad50Ahmet Kaan GümüşParent: ba4398c
  • feat
    • an OBMC candidate for the 32x32 single-reference winner, measured and defaulted off
Show full message
feat(av1): an OBMC candidate for the 32x32 single-reference winner, measured and defaulted off

The encoder now offers the 32x32 single-reference winner an OBMC_CAUSAL
candidate built by the DECODER's own plan and blend (decode::obmc_plan /
obmc_run, libaom av1_build_obmc_inter_prediction) off the committed
neighbours' mvs the search grid already carries, prices the motion_mode
symbol against the default obmc CDF, and the tile writer codes whichever
value won. obmc_plan lost its Neighbours parameter for the two filter bands
themselves so an encoder with a fixed interpolation filter can call it; no
second implementation of the blend exists.

MEASURED and NOT KEPT ON: native crop BD with it on is +18.2/+0.9,
+47.3/+19.2, +59.1/-10.0 against +18.0/+0.7, +47.3/+19.2, +59.4/-10.0 off
-- one row down, one flat, one up, short of the two-down-one-flat rule. It
is behind EC_AV1_OBMC=1 with the numbers at the decision site; the default
path is byte-identical to the SIMPLE-only commit before it. Only the 32x32
winner is offered OBMC and the price is the static-CDF estimate: the leaves
and a real-CDF price are the upgrade path.

Byte-exact either way: EC_COMP_MISMATCH=1 prints nothing with OBMC on, and
every decode round trip (our own decoder and ffmpeg) is sample-exact.
crates/ec-av1/src/decode.rsmodified+18 -7
@@ -24772,9 +24772,18 @@ nbmv=({},{}) nbref={} nbbsize={} filt={}",
2477224772 /// how many bordering blocks actually get blended, separate from the
2477324773 /// eligibility scan's own unbounded ("any at all") walk.
2477424774 #[allow(clippy::too_many_arguments)]
24775-fn obmc_plan(
24775+pub(crate) fn obmc_plan(
2477624776 grid: &MiGrid,
24777- neighbours: &Neighbours,
24777+ // The two switchable-filter bands (`Neighbours::above_filter`/
24778+ // `left_filter`), read only when `interp_fixed` is `None`. The ENCODER
24779+ // (`encode.rs`'s OBMC candidate) codes a fixed interpolation filter and
24780+ // has no `Neighbours` of its own, so it passes both empty; the reads
24781+ // below fall back to the `[3, 3]` never-recorded sentinel, which
24782+ // `neighbour_filter` never reaches under a fixed filter.
24783+ // corner-cut: ceiling is a switchable-filter ENCODER -- it must build and
24784+ // pass the real bands here, exactly as the decoder does.
24785+ above_filter: &[[u8; 2]],
24786+ left_filter: &[[u8; 2]],
2477824787 mi_row: usize,
2477924788 mi_col: usize,
2478024789 bw4: usize,
@@ -24841,7 +24850,7 @@ fn obmc_plan(
2484124850 // neighbour's OWN mi-granular filter (libaom
2484224851 // `av1_setup_build_prediction_by_above_pred` reads
2484324852 // `above_mbmi->interp_filters`).
24844- let above_syms = neighbours.above_filter[mi_col + src4];
24853+ let above_syms = above_filter.get(mi_col + src4).copied().unwrap_or([3; 2]);
2484524854 obmcrec_probe(
2484624855 "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms,
2484724856 grid.get(mi_row - 1, mi_col + src4), interp_fixed.is_some(),
@@ -24865,7 +24874,7 @@ fn obmc_plan(
2486524874 let mut left = Vec::new();
2486624875 for (off4, span4, nb, src4) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4))
2486724876 {
24868- let left_syms = neighbours.left_filter[mi_row + src4];
24877+ let left_syms = left_filter.get(mi_row + src4).copied().unwrap_or([3; 2]);
2486924878 obmcrec_probe(
2487024879 "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms,
2487124880 grid.get(mi_row + src4, mi_col - 1), interp_fixed.is_some(),
@@ -24940,7 +24949,7 @@ pub(crate) struct ObmcPlan {
2494024949 /// (libaom `av1_build_obmc_inter_prediction`). Reads nothing but reference
2494124950 /// pixels and the plan, so it runs wherever the block's prediction is built
2494224951 /// -- on a recon worker when that prediction is deferred (lane-defer8).
24943-fn obmc_run(
24952+pub(crate) fn obmc_run(
2494424953 plan: &ObmcPlan,
2494524954 refpix: &RefPix<'_>,
2494624955 pred_y: &mut [u16],
@@ -27622,7 +27631,8 @@ fn decode_inter_block(
2762227631 let obmc = if obmc_selected {
2762327632 Some(obmc_plan(
2762427633 grid,
27625- neighbours,
27634+ &neighbours.above_filter,
27635+ &neighbours.left_filter,
2762627636 mi_row,
2762727637 mi_col,
2762827638 bw4,
@@ -32209,7 +32219,8 @@ fn decode_inter_block8(
3220932219 let obmc = if obmc_selected {
3221032220 Some(obmc_plan(
3221132221 grid,
32212- neighbours,
32222+ &neighbours.above_filter,
32223+ &neighbours.left_filter,
3221332224 mi_row,
3221432225 mi_col,
3221532226 2,
crates/ec-av1/src/encode.rsmodified+186 -3
@@ -2237,6 +2237,16 @@ impl Reach {
22372237 }
22382238
22392239 /// What one symbol costs against a CDF, in bits.
2240+/// What the `motion_mode`/`obmc` symbol costs (spec 5.11.24), off the default
2241+/// table rather than the tile's adapted one -- the same static-CDF estimate
2242+/// every other symbol in this search is priced with.
2243+fn obmc_bits(write_w: usize, write_h: usize, obmc: bool) -> f64 {
2244+ let Some(row) = crate::decode::motion_mode_cdf_row(write_w, write_h) else {
2245+ return 0.0;
2246+ };
2247+ symbol_bits(&cdf::OBMC[row], usize::from(obmc))
2248+}
2249+
22402250 pub(crate) fn symbol_bits(cdf: &[u16], symbol: usize) -> f64 {
22412251 let low = if symbol == 0 { 0 } else { cdf[symbol - 1] };
22422252 let width = cdf[symbol] - low;
@@ -5614,7 +5624,15 @@ fn search_inter_block(
56145624 // The COMPOUND stack of each `LAST_FRAME` + extra-reference pair, built by
56155625 // the caller off the same MI grid the tile writer will (empty unless the
56165626 // frame carries `reference_select`).
5617- compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)], fctx: &crate::decode::FrameCtx,
5627+ compound: &[(i8, &Picture, crate::mvstack::CompoundMvStack)],
5628+ // lane-av1obmc: the mi grid this search's neighbours were published into
5629+ // (`record_mi`) and this block's own place in it -- what the OBMC
5630+ // candidate's eligibility walk and neighbour plan read, the same state
5631+ // the tile writer will read when it codes the `motion_mode` symbol.
5632+ grid: &MiGrid,
5633+ (mi_row, mi_col): (usize, usize),
5634+ (mi_rows, mi_cols): (usize, usize),
5635+ fctx: &crate::decode::FrameCtx,
56185636 ) -> (BlockCoeffs, f64) {
56195637 // `luma_set` is the INTRA candidates' table; the two inter candidates
56205638 // below price their coefficients through `TxbSet::Luma32Inter`, which is
@@ -5647,6 +5665,10 @@ fn search_inter_block(
56475665 mode: u8,
56485666 skip: bool,
56495667 inter: Option<InterInfo>,
5668+ /// The mode/mv syntax this candidate pays for, apart from its
5669+ /// residual -- what the OBMC candidate below has to re-pay when it
5670+ /// re-prices the winner's prediction.
5671+ mode_bits: f64,
56505672 }
56515673 let mut best: Option<Candidate> = None;
56525674 let mut consider = |candidate: Candidate| {
@@ -5741,6 +5763,7 @@ fn search_inter_block(
57415763 mode,
57425764 skip: false,
57435765 inter: None,
5766+ mode_bits: mode_bits[usize::from(mode)],
57445767 });
57455768 }
57465769
@@ -6152,6 +6175,7 @@ fn search_inter_block(
61526175 v,
61536176 mode: DC_PRED,
61546177 skip,
6178+ mode_bits: bits,
61556179 inter: Some(info),
61566180 });
61576181 }
@@ -6249,12 +6273,150 @@ fn search_inter_block(
62496273 v,
62506274 mode: DC_PRED,
62516275 skip,
6276+ mode_bits: mode_bits_inter,
62526277 inter: Some(info),
62536278 });
62546279 }
62556280 }
62566281
62576282 let best = best.expect("the search offers at least the intra modes");
6283+ // lane-av1obmc: the OBMC candidate (spec `motion_mode == OBMC_CAUSAL`),
6284+ // offered to the SINGLE-REFERENCE winner only -- libaom's
6285+ // `motion_mode_allowed` fails `is_motion_variation_allowed_compound` on a
6286+ // compound block, so the writer codes no symbol for one. The prediction
6287+ // is built by the DECODER's own plan and blend
6288+ // ([`crate::decode::obmc_plan`]/[`crate::decode::obmc_run`],
6289+ // `av1_build_obmc_inter_prediction`) off the committed neighbours' mvs
6290+ // this search's `grid` already carries, so what is priced here is what a
6291+ // decoder reconstructs -- never a second implementation of the blend.
6292+ //
6293+ // MEASURED 2026-09-06 and NOT KEPT ON BY DEFAULT (`EC_AV1_OBMC=1` turns it
6294+ // on). Native crop BD, the standing recipe, with it on against the same
6295+ // build with it off: film 1080p +18.2/+0.9 against +18.0/+0.7, film 2160p
6296+ // +47.3/+19.2 against +47.3/+19.2, screen +59.1/-10.0 against
6297+ // +59.4/-10.0. That is one row down (screen -0.3 vs libaom), one flat and
6298+ // one UP -- the keep rule wants two down and one flat, so it stays off.
6299+ // The 640x384 gate reads the same shape louder: +79.7/+95.5/+54.2 and
6300+ // +37.2/+56.8/+0.8 against +78.8/+95.1/+54.5 and +36.1/+56.4/+1.1. Two
6301+ // things bound it and are the upgrade path: only the 32x32 winner is
6302+ // offered OBMC (the 16x16/8x8 leaves in `code_square_inter` are not, and
6303+ // that is where libaom cashes most of its OBMC gain), and the symbol/
6304+ // residual price here is the static-CDF estimate.
6305+ let mut best = best;
6306+ let mut obmc_won = false;
6307+ if let Some(info) = best.inter.filter(|i| i.ref1.is_none()) {
6308+ if crate::envflags::env_flag!("EC_AV1_OBMC")
6309+ && crate::decode::has_overlappable_neighbour(grid, mi_row, mi_col, 8, 8, mi_cols, mi_rows)
6310+ {
6311+ let mut refs: [Option<&Picture>; 8] = [None; 8];
6312+ refs[LAST_FRAME as usize] = Some(reference);
6313+ for &(r, p, _) in extra {
6314+ refs[r as usize] = Some(p);
6315+ }
6316+ let refpix = crate::decode::RefPix::ready(refs);
6317+ let plan = crate::decode::obmc_plan(
6318+ grid,
6319+ &[],
6320+ &[],
6321+ mi_row,
6322+ mi_col,
6323+ 8,
6324+ 8,
6325+ mi_rows,
6326+ mi_cols,
6327+ BLOCK,
6328+ BLOCK,
6329+ BLOCK,
6330+ BLOCK / 2,
6331+ x,
6332+ y,
6333+ x / 2,
6334+ y / 2,
6335+ &refpix,
6336+ Some(mc::InterpFilterKind::Regular),
6337+ reference.width,
6338+ );
6339+ if let Ok(plan) = plan {
6340+ let (ref_luma, ref_u, ref_v) = match extra
6341+ .iter()
6342+ .find(|(r, _, _)| *r == info.ref_frame)
6343+ {
6344+ Some(&(_, g, _)) => (
6345+ (&g.y, g.width, luma.true_width, luma.true_height),
6346+ (&g.u, g.width / 2, chroma[0].true_width, chroma[0].true_height),
6347+ (&g.v, g.width / 2, chroma[1].true_width, chroma[1].true_height),
6348+ ),
6349+ None => (ref_luma, ref_u, ref_v),
6350+ };
6351+ let mv = info.mv;
6352+ let mut pred = [
6353+ vec![0u16; BLOCK * BLOCK],
6354+ vec![0u16; BLOCK * BLOCK / 4],
6355+ vec![0u16; BLOCK * BLOCK / 4],
6356+ ];
6357+ for (i, (r, luma_plane)) in
6358+ [(ref_luma, true), (ref_u, false), (ref_v, false)].into_iter().enumerate()
6359+ {
6360+ let (px, py) = if luma_plane { (x, y) } else { (x / 2, y / 2) };
6361+ let side = if luma_plane { BLOCK } else { BLOCK / 2 };
6362+ mc::predict(
6363+ r.0,
6364+ r.1,
6365+ r.2,
6366+ r.3,
6367+ mv_to_q4(px, mv.1, luma_plane),
6368+ mv_to_q4(py, mv.0, luma_plane),
6369+ side,
6370+ side,
6371+ &mut pred[i],
6372+ fctx,
6373+ );
6374+ }
6375+ let [mut py_buf, mut pu_buf, mut pv_buf] = pred;
6376+ crate::decode::obmc_run(
6377+ &plan, &refpix, &mut py_buf, &mut pu_buf, &mut pv_buf, fctx,
6378+ );
6379+ let u8s = |b: &[u16]| b.iter().map(|&v| v as u8).collect::<Vec<u8>>();
6380+ let luma_trial = luma.code_from_prediction(
6381+ x, y, BLOCK, &u8s(&py_buf), false, search.base_q_idx, search.deadzone,
6382+ TxbSet::Luma32Inter,
6383+ );
6384+ let u = chroma[0].code_from_prediction(
6385+ x / 2, y / 2, BLOCK / 2, &u8s(&pu_buf), false, search.base_q_idx,
6386+ search.deadzone, chroma_set,
6387+ );
6388+ let v = chroma[1].code_from_prediction(
6389+ x / 2, y / 2, BLOCK / 2, &u8s(&pv_buf), false, search.base_q_idx,
6390+ search.deadzone, chroma_set,
6391+ );
6392+ let skip = luma_trial.levels.iter().all(|&l| l == 0)
6393+ && u.levels.iter().all(|&l| l == 0)
6394+ && v.levels.iter().all(|&l| l == 0);
6395+ let cost = luma_trial.sse
6396+ + u.sse
6397+ + v.sse
6398+ + search.lambda
6399+ * (skip_bits(skip)
6400+ + intra_inter_bits(true)
6401+ + best.mode_bits
6402+ + obmc_bits(BLOCK, BLOCK, true)
6403+ + if skip { 0.0 } else { luma_trial.bits + u.bits + v.bits });
6404+ if cost < best.cost + search.lambda * obmc_bits(BLOCK, BLOCK, false) {
6405+ obmc_won = true;
6406+ best = Candidate {
6407+ cost,
6408+ luma: luma_trial,
6409+ u,
6410+ v,
6411+ mode: DC_PRED,
6412+ skip,
6413+ mode_bits: best.mode_bits,
6414+ inter: best.inter,
6415+ };
6416+ }
6417+ }
6418+ }
6419+ }
62586420 // lane-av1txbits BUILT the transform-depth search this path lacks -- a
62596421 // 32x32 single-reference winner offered `commit_inter_luma`'s four 16x16
62606422 // units against its flat trial, exactly as a 16x16 winner is -- and
@@ -6276,7 +6438,7 @@ fn search_inter_block(
62766438 uv_mode: DC_PRED,
62776439 skip: best.skip,
62786440 inter: best.inter,
6279- obmc: false,
6441+ obmc: obmc_won,
62806442 eight: None,
62816443 dv: None,
62826444 palette: None,
@@ -6656,7 +6818,11 @@ pub(crate) fn encode_inter_frame(
66566818 reference,
66576819 &stack,
66586820 &extra,
6659- &compound, fctx,
6821+ &compound,
6822+ &grid,
6823+ (mi_row, mi_col),
6824+ (mi_rows, mi_cols),
6825+ fctx,
66606826 );
66616827 cost_whole += search.lambda * partition_bits(BLOCK, false);
66626828 let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);
@@ -9518,6 +9684,11 @@ mod tests {
95189684 // remaining gap is the syntax the coefficient sum leaves out. That is
95199685 // the default on a non-screen frame since lane-av1price2 (this
95209686 // fixture is one), and it reads +32.6% here.
9687+ // lane-av1obmc: every eligible single-reference inter block now also
9688+ // carries a `motion_mode` symbol the coefficient sum never counts,
9689+ // and an OBMC block carries the more expensive of the two values --
9690+ // re-measured at +35.0% here with `EC_AV1_OBMC=1`; the default path
9691+ // (OBMC off, SIMPLE symbols only) reads +33.x.
95219692 assert!(
95229693 worst_under <= 0.34,
95239694 "the writer spent {:.2}% more than the search priced -- more than \
@@ -11042,6 +11213,18 @@ mod tests {
1104211213 .collect::<Vec<_>>()
1104311214 .join(" ")
1104411215 );
11216+ // lane-av1obmc: how many blocks actually CODED a motion_mode
11217+ // symbol and which value they took, by footprint -- "OBMC is on"
11218+ // as a measurement rather than a claim (class
11219+ // `gate-blind-to-feature`).
11220+ let mm = crate::tile::take_motion_mode_hits();
11221+ eprintln!(
11222+ "{name}: motion_mode 32x32 SIMPLE={} OBMC={} | 16x16 SIMPLE={} OBMC={} | \
11223+ 8x8 SIMPLE={} OBMC={} ({:.1}% OBMC of {} eligible)",
11224+ mm[0], mm[1], mm[2], mm[3], mm[4], mm[5],
11225+ 100.0 * (mm[1] + mm[3] + mm[5]) as f64 / mm.iter().sum::<usize>().max(1) as f64,
11226+ mm.iter().sum::<usize>(),
11227+ );
1104511228 let (aom, aom_wall) =
1104611229 external_ladder(&source, width, height, "libaom-av1", &aom_points);
1104711230 let (rav1e, rav1e_wall) =