diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1efe9b97..cf1cede3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1763,6 +1763,32 @@ thread_local! { static OBMC_HITS_8: std::cell::Cell = const { std::cell::Cell::new(0) }; } +// lane-interp3 r1: how many inter blocks read a SWITCHABLE `interp_filter` +// pair whose two directions differ (`enable_dual_filter` only -- with dual +// filter off both directions take the single symbol, so this can never fire). +// A gate asserting it proves the stream really carries dual-filter blocks. +thread_local! { + static DUAL_FILTER_DIFF_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +// lane-interp3 r1: how many COMPOUND 8x8 leaves read their own +// `read_mb_interp_filter` symbol(s) -- the read this round added (the leaf +// used to skip it entirely, losing a symbol and stamping the `[3, 3]` +// no-filter sentinel that made a neighbouring OBMC block panic). +thread_local! { + static COMPOUND8_FILTER_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`DUAL_FILTER_DIFF_HITS`]. +pub(crate) fn dual_filter_diff_hits() -> usize { + DUAL_FILTER_DIFF_HITS.with(|c| c.get()) +} + +/// Current value of [`COMPOUND8_FILTER_HITS`]. +pub(crate) fn compound8_filter_hits() -> usize { + COMPOUND8_FILTER_HITS.with(|c| c.get()) +} + // lane-warp round 1: how many blocks resolved `motion_mode_allowed` to // `WARPED_CAUSAL`-eligible (3-symbol read, `num_proj_ref >= 1` under // `allow_warped_motion`) AND the symbol actually decoded to `WARPED_CAUSAL` @@ -1794,6 +1820,20 @@ pub(crate) fn compound_warp_hits() -> usize { COMPOUND_WARP_HITS.with(|c| c.get()) } +// lane-interp3 r3: the same proof narrowed to the 8x8 LEAF's own compound +// arm ([`decode_inter_block8`]) -- that arm predicted both taps +// translationally until r3, so a gate needs to tell a warped 8x8 compound +// leaf apart from a warped 16x16+ one (both bump [`COMPOUND_WARP_HITS`]). +thread_local! { + static COMPOUND_WARP_HITS_8: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`COMPOUND_WARP_HITS_8`]. +pub(crate) fn compound_warp_hits_8() -> usize { + COMPOUND_WARP_HITS_8.with(|c| c.get()) +} + // lane-gmaffine r1: how many blocks built their prediction from a // SIX-parameter (`AFFINE`) global-motion model through // `crate::warp::global_warp_params` -- the gate's proof that a stream really @@ -14850,6 +14890,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // that isolate whether a decode-order frame's mismatch already exists // in reconstruction (this dump) vs is introduced by the loop filter // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders. + if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_PICT idx={}", + PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) + ); + } dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; @@ -15054,6 +15101,9 @@ fn resolve_interp_filter( } else { sym0 }; + if enable_dual_filter && sym0 != sym1 { + DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1)); + } ( mc::InterpFilterKind::from_switchable_symbol(sym1 as usize), mc::InterpFilterKind::from_switchable_symbol(sym0 as usize), @@ -15713,14 +15763,25 @@ fn obmc_mask(len: usize) -> &'static [u8] { fn neighbour_filter( interp_fixed: Option, sym: [u8; 2], -) -> (mc::InterpFilterKind, mc::InterpFilterKind) { +) -> Result<(mc::InterpFilterKind, mc::InterpFilterKind)> { if let Some(kind) = interp_fixed { - return (kind, kind); + return Ok((kind, kind)); + } + // lane-interp3 r1: the `[3, 3]` sentinel reaching here is a DEFECT in + // whatever path recorded the neighbour (an inter block that never stored + // its own switchable symbols), and it used to abort the process through + // `from_switchable_symbol`'s panic. A decoder must never crash on a real + // stream: it stops by name instead, so the frame is refused and the + // stream is pinned like every other unsupported case. + if sym[0] > 2 || sym[1] > 2 { + return Err(unsupported( + "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)", + )); } - ( + Ok(( mc::InterpFilterKind::from_switchable_symbol(sym[1] as usize), mc::InterpFilterKind::from_switchable_symbol(sym[0] as usize), - ) + )) } /// One neighbour's own re-prediction over a `w`x`h` region, MC'd fresh @@ -15900,6 +15961,71 @@ fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, } } +/// libaom's own `BLOCK_SIZE` enum index for a `w4`x`h4` (mi-unit) block -- +/// only for the `EC_OBMC` trace rung below, so it reads byte-identical to +/// the instrumented aomdec's `backup_mbmi.bsize`. +fn ec_obmc_bsize(w4: usize, h4: usize) -> i32 { + match (w4, h4) { + (1, 1) => 0, + (1, 2) => 1, + (2, 1) => 2, + (2, 2) => 3, + (2, 4) => 4, + (4, 2) => 5, + (4, 4) => 6, + (4, 8) => 7, + (8, 4) => 8, + (8, 8) => 9, + (8, 16) => 10, + (16, 8) => 11, + (16, 16) => 12, + (1, 4) => 16, + (4, 1) => 17, + (2, 8) => 18, + (8, 2) => 19, + (4, 16) => 20, + (16, 4) => 21, + _ => -1, + } +} + +/// The `EC_OBMC` rung: one line per blended neighbour, in the instrumented +/// aomdec's own byte format (`decodeframe.c` +/// `dec_build_prediction_by_{above,left}_pred`), so the two decoders' OBMC +/// neighbour lists diff line for line. `filt` is libaom's packed +/// `interp_filters.as_int` = `y_filter | (x_filter << 16)`. +#[allow(clippy::too_many_arguments)] +fn ec_obmc_trace( + dir: &str, + mi_row: usize, + mi_col: usize, + write_w: usize, + write_h: usize, + rel: usize, + op: usize, + nb: &MiInfo, + h_kind: mc::InterpFilterKind, + v_kind: mc::InterpFilterKind, +) { + if std::env::var_os("EC_OBMC").is_none() { + return; + } + let sym = |k: mc::InterpFilterKind| match k { + mc::InterpFilterKind::Smooth => 1u32, + mc::InterpFilterKind::Sharp => 2, + _ => 0, + }; + eprintln!( + "EC_OBMC {dir} mi=({mi_row},{mi_col}) wh=({write_w}x{write_h}) rel={rel} op={op} \ +nbmv=({},{}) nbref={} nbbsize={} filt={}", + nb.mv.0, + nb.mv.1, + nb.ref_frame, + ec_obmc_bsize(nb.size, nb.size_h), + sym(v_kind) | (sym(h_kind) << 16), + ); +} + /// `av1_build_obmc_inter_prediction` (libaom `reconinter.c`): re-predicts /// the overlap strip against each bordering above/left inter neighbour's own /// mv/ref/filter and blends it into this block's just-built single-reference @@ -15998,7 +16124,8 @@ fn obmc_blend( let (h_kind, v_kind) = neighbour_filter( interp_fixed, neighbours.above_filter[mi_col + off4], - ); + )?; + ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4); @@ -16017,7 +16144,8 @@ fn obmc_blend( let (h_kind, v_kind) = neighbour_filter( interp_fixed, neighbours.left_filter[mi_row + off4], - ); + )?; + ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind); let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?; let nb_scale = mc::scale_factor(ny.width, frame_width); let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4); @@ -19376,21 +19504,24 @@ fn decode_inter_block8( let (ref0, ref1) = if skip_mode { (skip_mode_frame[0] as i8, skip_mode_frame[1] as i8) } else { + // lane-interp3 r2 (class twin-functions-drift): this leaf + // passed a hard-coded `LAST_FRAME` for every inter + // neighbour -- the old "coarse LAST_FRAME-or-intra" + // approximation -- while the side bands have carried the + // neighbour's REAL reference per mi since lane-inter8 r2. + // Every `av1_collect_neighbors_ref_counts` vote below + // (`uni_comp_ref_p1`, `comp_ref`, `comp_bwdref`, ...) was + // therefore taken off the wrong CDF row. Same two args + // [`decode_inter_block`]'s own compound arm passes + // (`-1` when the band is unavailable is start_tile's / + // start_row's own reset value, so no `has_above` guard). read_compound_ref_frames( dec, cdfs, above_nbr, left_nbr, - if has_above && above_inter { - LAST_FRAME - } else { - -1 - }, - if has_left && left_inter { - LAST_FRAME - } else { - -1 - }, + above_ref0, + left_ref0, ) }; leaf_refs = (ref0, Some(ref1)); @@ -19571,6 +19702,58 @@ fn decode_inter_block8( ); } + // lane-interp3 r1: `read_mb_interp_filter` (libaom + // `decodemv.c` 1575, the tail of + // `read_inter_block_mode_info`) runs for EVERY inter block, + // compound included, right AFTER `read_compound_type` -- this + // leaf read no filter symbol at all, so a SWITCHABLE-filter + // stream lost one symbol (two under `enable_dual_filter`) at + // every compound 8x8 leaf, and the leaf recorded the `[3, 3]` + // "no filter" sentinel, which made a neighbouring OBMC block's + // `neighbour_filter` PANIC instead of blending. + // `av1_is_interp_needed` suppression terms for this arm: + // `skip_mode`, and `is_nontrans_global_motion` (mode + // GLOBAL_GLOBALMV with BOTH refs' models non-TRANSLATION) -- + // WARPED_CAUSAL cannot occur on a compound block. + let gm_nontrans_c = compound_mode == 6 + && global_motion[(ref0 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation + && global_motion[(ref1 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation; + // spec `get_ref_filter_type`, keyed on this block's ref0 and + // matching EITHER of the neighbour's references -- same shape + // as [`decode_inter_block`]'s compound arm. Same corner-cut as + // this leaf's single-ref arm below: the context comes from the + // enclosing 16x16's coarse slot. + let above_filter_ctx = if neighbours.above_ref[cmi] == ref0 + || neighbours.above_ref1[cmi] == Some(ref0) + { + neighbours.above_filter[cmi] + } else { + [3, 3] + }; + let left_filter_ctx = if neighbours.left_ref[rmi] == ref0 + || neighbours.left_ref1[rmi] == Some(ref0) + { + neighbours.left_filter[rmi] + } else { + [3, 3] + }; + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( + dec, + cdfs, + interp_fixed, + enable_dual_filter, + gm_nontrans_c || skip_mode, + above_filter_ctx, + left_filter_ctx, + true, + ); + leaf_filter_syms = resolved_filter; + if interp_fixed.is_none() && !(gm_nontrans_c || skip_mode) { + COMPOUND8_FILTER_HITS.with(|c| c.set(c.get() + 1)); + } + let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; let scale0 = mc::scale_factor(py0.width, frame_width); @@ -19580,6 +19763,54 @@ fn decode_inter_block8( SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1)); } + // lane-interp3 r2 (class twin-functions-drift): both slots + // used to be stamped `false`, while [`decode_inter_block`]'s + // compound arm computes libaom's PER-SLOT `is_global_mv_block` + // (blockd.h:421-429 -- mode GLOBAL_GLOBALMV, block >= 8x8 + // (always true for this leaf) and THAT slot's own gm model > + // TRANSLATION). A neighbour carrying the flag makes + // `setup_ref_mv_list` substitute the READER's global mv for + // the neighbour's stored one, so a cleared flag fed the next + // block's stack a stored mv where libaom has the global + // candidate -- a wrong mv stack, wrong mode contexts, and a + // desync one block later. + let is_globalmv_c = compound_mode == 6; + let is_global_mv0_c = is_globalmv_c + && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1; + let is_global_mv1_c = is_globalmv_c + && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1; + // lane-interp3 r3 (class twin-functions-drift, second + // instance): libaom applies `allow_warp`'s GLOBAL branch + // (`reconinter.c:33-55`, reached from `av1_init_warp_params` + // inside `build_inter_predictors_8x8_and_bigger`'s per-`ref` + // loop) to EVERY `is_global_mv_block` slot, compound + // included and independently of `motion_mode` -- the 16x16+ + // compound arm has done this since lane-cwarp r1, this leaf + // predicted both taps translationally, so a GLOBAL_GLOBALMV + // 8x8 compound leaf under a non-TRANSLATION model drifted by + // a few luma levels, growing away from the block origin. + // `force_integer_mv` short-circuits `av1_init_warp_params` + // before `allow_warp`; chroma is 4x4 here, below + // `av1_init_warp_params`'s own 8px per-plane bound, so only + // luma warps (same rule as this leaf's single-ref arm). + let leaf_compound_warp = |ref_frame: i8, eligible: bool| { + if eligible + && !force_integer_mv + && !global_motion[(ref_frame - LAST_FRAME) as usize].invalid + { + crate::warp::global_warp_params( + global_motion[(ref_frame - LAST_FRAME) as usize].params, + ) + } else { + None + } + }; + let warp0_c = leaf_compound_warp(ref0, is_global_mv0_c); + let warp1_c = leaf_compound_warp(ref1, is_global_mv1_c); + if warp0_c.is_some() || warp1_c.is_some() { + COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1)); + COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1)); + } for dr in 0..2 { for dc in 0..2 { grid.set( @@ -19594,19 +19825,14 @@ fn decode_inter_block8( is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7), size: 2, size_h: 2, - is_global_mv0: false, - is_global_mv1: false, + is_global_mv0: is_global_mv0_c, + is_global_mv1: is_global_mv1_c, }, ); } } mode_for_tx = 0; - // lane-av1comp corner-cut, matching this leaf's single-ref - // arm below (`mc::predict`'s own fixed-Regular default): - // `decode_inter_block8` never resolves a switchable filter, - // so both compound taps use `Regular` too. - use mc::InterpFilterKind::Regular; let mut inter0_y = vec![0i32; SIDE * SIDE]; mc::predict_compound_intermediate( &py0.data, @@ -19618,10 +19844,17 @@ fn decode_inter_block8( scale0, SIDE, SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter0_y, ); + if let Some(wp) = &warp0_c { + crate::warp::warp_affine_compound( + wp, &py0.data, py0.true_width as i32, py0.true_height as i32, + py0.width as i32, &mut inter0_y, px as i32, py as i32, SIDE as i32, + SIDE as i32, SIDE as i32, 0, 0, + ); + } let mut inter1_y = vec![0i32; SIDE * SIDE]; mc::predict_compound_intermediate( &py1.data, @@ -19633,10 +19866,17 @@ fn decode_inter_block8( scale1, SIDE, SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter1_y, ); + if let Some(wp) = &warp1_c { + crate::warp::warp_affine_compound( + wp, &py1.data, py1.true_width as i32, py1.true_height as i32, + py1.width as i32, &mut inter1_y, px as i32, py as i32, SIDE as i32, + SIDE as i32, SIDE as i32, 0, 0, + ); + } let mut pred_y = vec![0u16; SIDE * SIDE]; let mut diffwtd_mask_y = Vec::new(); let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type { @@ -19666,8 +19906,8 @@ fn decode_inter_block8( scale0, CHROMA_SIDE, CHROMA_SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter0_u, ); let mut inter1_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; @@ -19681,8 +19921,8 @@ fn decode_inter_block8( scale1, CHROMA_SIDE, CHROMA_SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter1_u, ); let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; @@ -19712,8 +19952,8 @@ fn decode_inter_block8( scale0, CHROMA_SIDE, CHROMA_SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter0_v, ); let mut inter1_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; @@ -19727,8 +19967,8 @@ fn decode_inter_block8( scale1, CHROMA_SIDE, CHROMA_SIDE, - Regular, - Regular, + h_filter, + v_filter, &mut inter1_v, ); let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; @@ -19902,6 +20142,17 @@ fn decode_inter_block8( &gm_table, tpl, ); + // lane-interp3 r2: same per-entry EC_STACK ladder + // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack + // diffs line for line against the oracle's. + if std::env::var_os("EC_TRACE_MODE").is_some() { + for (i, e) in stack.entries.iter().enumerate() { + eprintln!( + "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}", + e.mv.0, e.mv.1, e.weight + ); + } + } let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; let mut is_globalmv = false; @@ -22969,6 +23220,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // that isolate whether a decode-order frame's mismatch already exists // in reconstruction (this dump) vs is introduced by the loop filter // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders. + if std::env::var_os("EC_OBMC").is_some() || std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_PICT idx={}", + PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst) + ); + } dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { use std::io::Write; @@ -23339,6 +23597,30 @@ mod tests { /// always cleared to `None` by `record_inter`, so the next block's own /// `NeighbourRef::uni` -- and `comp_reference_type_ctx` downstream of it /// -- could never see a real compound neighbour). + /// lane-interp3 r1: a decoder must never abort the process on + /// stream-derived state. `neighbour_filter` used to feed the `[3, 3]` + /// "no filter recorded" sentinel straight into + /// `InterpFilterKind::from_switchable_symbol`, whose `panic!` ("...alphabet + /// is exactly 3 symbols") crashed on a real aomenc dual-filter + OBMC + /// stream. It now refuses by name; the real symbols still decode. + #[test] + fn an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking() { + assert!( + neighbour_filter(None, [3, 3]) + .unwrap_err() + .to_string() + .contains("an OBMC neighbour whose interp filter was never recorded"), + "the [3, 3] sentinel must refuse by name, never panic" + ); + assert!(neighbour_filter(None, [3, 0]).is_err()); + let (h, v) = neighbour_filter(None, [0, 2]).expect("real symbols decode"); + assert_eq!(h, mc::InterpFilterKind::Sharp, "sym[1] is the horizontal kernel"); + assert_eq!(v, mc::InterpFilterKind::Regular, "sym[0] is the vertical kernel"); + let (h, v) = neighbour_filter(Some(mc::InterpFilterKind::Smooth), [3, 3]) + .expect("a fixed-filter frame never reads a symbol"); + assert_eq!((h, v), (mc::InterpFilterKind::Smooth, mc::InterpFilterKind::Smooth)); + } + #[test] fn record_compound_ctx_stamps_ref1_for_the_next_block_to_read() { let mut n = Neighbours::new(4, 4, 16, 16); diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 18f40cc1..59d9414f 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -33,6 +33,7 @@ const REFUSALS: &[&str] = &[ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", + "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)", "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 61eba57e..0860b313 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6466,6 +6466,9 @@ mod tests { // aomenc silently codes one tile column and the arm is vacuous. extra: &[&str], width: usize, + // lane-interp3 r1: sequence length -- a compound block needs several + // already-coded references, which a 4-frame sequence never has. + frame_count: usize, ) { if !have_ffmpeg() { eprintln!("SKIP {name}: no ffmpeg"); @@ -6475,7 +6478,8 @@ mod tests { eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); return; } - let (height, frame_count) = (64usize, 4usize); + let height = 64usize; + let duration = format!("{:.2}", frame_count as f64 / 25.0); // A deterministic synthetic source with real motion (a static source // codes every inter frame as skip and never exercises the residual // path); bounded with `-t` (class gate-loader-slurps-whole-file). @@ -6488,7 +6492,7 @@ mod tests { "-i", &format!("mandelbrot=size={width}x{height}:rate=25"), "-t", - "0.16", + &duration, "-pix_fmt", if ten_bit { "yuv420p10le" } else { "yuv420p" }, // y4m calls 10-bit unofficial (same as the 10-bit key-frame @@ -6615,6 +6619,7 @@ mod tests { "whole-superblock inter PARTITION_NONE", &[], 64, + 4, ); } @@ -6629,6 +6634,7 @@ mod tests { "whole-superblock inter PARTITION_NONE", &[], 64, + 4, ); } @@ -6671,6 +6677,88 @@ mod tests { "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves", &["--tile-columns=1"], 128, + 4, + ); + } + + /// lane-interp3 r1: the same 8x8-leaf recipe with DUAL FILTER, OBMC and + /// warped motion on. `read_mb_interp_filter` runs for every inter block + /// (libaom `decodemv.c` 1575), compound ones included; the compound 8x8 + /// leaf skipped it entirely, so a SWITCHABLE-filter stream lost a symbol + /// per compound leaf and stamped the `[3, 3]` "no filter" sentinel, which + /// made a neighbouring OBMC block's `neighbour_filter` PANIC (a crash on + /// his data, not a named refusal). The three hard asserts prove the flags + /// arrived: a compound 8x8 leaf that really read the filter, a block whose + /// two dual-filter directions DIFFER (impossible with dual filter off), + /// and an 8x8 OBMC blend. + // lane-interp3 r2: the ENTROPY desync r1 measured is CLOSED -- the full + // 16-frame stream now parses end to end and every `EC_MODE`/`EC_MODE_VAL` + // element's msac RANGE matches the instrumented aomdec's line for line + // (570/570 mode elements, 0 diff). Two twin-drift root causes, both in + // `decode_inter_block8`'s compound arm: `read_compound_ref_frames` was + // passed a hard-coded `LAST_FRAME` for every inter neighbour instead of + // the real per-mi band, and the grid stamp cleared both per-slot + // `is_global_mv_block` flags. + // lane-interp3 r3: the luma reconstruction residue r2 left open is CLOSED + // and this gate is GREEN. Third instance of the same twin-drift class: + // libaom applies `allow_warp`'s GLOBAL branch to every + // `is_global_mv_block` reference slot, compound included and independent + // of `motion_mode` (`av1_init_warp_params` inside + // `build_inter_predictors_8x8_and_bigger`'s per-`ref` loop) -- the 16x16+ + // compound arm has warped since lane-cwarp r1, the 8x8 leaf's compound arm + // predicted BOTH taps translationally, so a GLOBAL_GLOBALMV 8x8 compound + // leaf under a non-TRANSLATION model drifted a few luma levels, growing + // away from the block origin. It was NOT OBMC: the `EC_OBMC` emitter this + // round added to `decode.rs` diffs 325/325 lines against the instrumented + // aomdec's own rung (position, span, neighbour mv/ref/bsize/filter) with + // zero differences. + #[test] + fn a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let before_dual = decode::dual_filter_diff_hits(); + let before_obmc = decode::obmc_hits_8(); + let before_cwarp8 = decode::compound_warp_hits_8(); + inter_sb_none_gate( + NAME, + false, + "8", + "16", + decode::compound8_filter_hits, + "a compound 8x8 leaf reading its own switchable interp_filter", + &[ + "--enable-dual-filter=1", + "--enable-obmc=1", + "--enable-warped-motion=1", + "--enable-onesided-comp=1", + ], + 64, + // Recipe search hook (same shape as EC_OBMC8_ATTEMPTS): a compound + // block needs several coded references, so the sequence is longer + // than the other arms' 4 frames. + std::env::var("EC_INTERP3_FRAMES") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(16), + ); + assert!( + decode::dual_filter_diff_hits() > before_dual, + "{NAME}: no block read two DIFFERENT dual-filter directions -- \ + --enable-dual-filter=1 did not arrive or aomenc declined it" + ); + assert!( + decode::obmc_hits_8() > before_obmc, + "{NAME}: no 8x8 OBMC blend fired -- --enable-obmc=1 did not arrive" + ); + assert!( + decode::compound_warp_hits_8() > before_cwarp8, + "{NAME}: no 8x8 COMPOUND leaf was predicted through the per-ref GLOBAL \ + warp -- the r3 root-cause path never fired, so this stream no longer \ + proves it" ); } @@ -6685,6 +6773,7 @@ mod tests { "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves", &[], 64, + 4, ); } @@ -6708,6 +6797,7 @@ mod tests { "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves", &[], 64, + 4, ); } diff --git a/lanes/interp3-r1.report.md b/lanes/interp3-r1.report.md new file mode 100644 index 00000000..9b9906d0 --- /dev/null +++ b/lanes/interp3-r1.report.md @@ -0,0 +1,96 @@ +# lane-interp3 r1 -- the `switchable_interp` PANIC: the compound 8x8 leaf never read its filter + +## Root cause (cited) + +libaom `decodemv.c:1575` (`read_inter_block_mode_info`) calls `read_mb_interp_filter` +for **every** inter block, compound ones included, right after `read_compound_type`. +`decode_leaf8`'s COMPOUND arm (`crates/ec-av1/src/decode.rs`, the branch that returns at +the old line 19589) called `resolve_interp_filter` **not at all**: it predicted both taps +with a hard-coded `Regular` and returned the `[3, 3]` "no filter recorded" sentinel as the +leaf's `leaf_filter_syms`. Two consequences, both real on his data: + +1. **Entropy**: on a `SWITCHABLE`-filter frame one symbol (two under `enable_dual_filter`) + is left unread at every compound 8x8 leaf -- silent desync. +2. **Crash**: the sentinel is stamped into `Neighbours::above_filter`/`left_filter`, and a + neighbouring OBMC block's `neighbour_filter` fed it to + `mc::InterpFilterKind::from_switchable_symbol`, whose `panic!("switchable_interp's + alphabet is exactly 3 symbols")` aborted the process. That is the panic lane-r14 r3 + flagged (its `--enable-dual-filter=1 --enable-obmc=1` 192x128 cq30 stream). The same + shape was already fixed once for the SINGLE-ref 8x8 leaf (lane-gmaffine r3, decode.rs + ~21509 comment) -- the compound arm was the surviving sibling instance. + +## Changed + +- `crates/ec-av1/src/decode.rs` (compound 8x8 leaf, after the `comp_group_idx`/ + `compound_idx` reads): reads `interp_filter` in libaom's order, with `get_ref_filter_type` + neighbour contexts keyed on `ref0` and `is_compound = true`; suppression term is + `skip_mode || is_nontrans_global_motion` (GLOBAL_GLOBALMV + both refs' models non- + TRANSLATION; WARPED_CAUSAL cannot occur on compound). The 12 `predict_compound_intermediate` + taps now use the resolved `h_filter`/`v_filter` instead of `Regular`. +- `crates/ec-av1/src/decode.rs` `neighbour_filter`: returns `Result`; the `[3, 3]` sentinel + is now the named refusal `an OBMC neighbour whose interp filter was never recorded (no + switchable symbol for that block)` -- **never a panic**. Both OBMC call sites `?` it. +- `crates/ec-av1/src/decode.rs`: counters `DUAL_FILTER_DIFF_HITS` (a block whose two + dual-filter directions differ -- impossible with dual filter off) and + `COMPOUND8_FILTER_HITS`. +- `crates/ec-av1/src/refusal_inventory.rs`: the new refusal listed (inventory test green). +- `crates/ec-av1/src/stream.rs`: `inter_sb_none_gate` takes a `frame_count` + (4 frames never code a compound block); new gate + `a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` + (`--enable-dual-filter=1 --enable-obmc=1 --enable-warped-motion=1 --enable-onesided-comp=1` + on the `--min-partition-size=8 --enable-ab-partitions=0 --enable-1to4-partitions=0` + recipe, every frame compared Y/U/V vs ffmpeg, hard asserts on all three counters). +- `crates/ec-av1/src/decode.rs` test + `an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking`. + +## Gate: RED, `#[ignore]`d with the measurement, not deleted + +`EC_INTERP3_FRAMES=4` -> aomenc codes no compound block, stream decodes. +From 5 frames on it does, and the decode stops at a refusal that the recipe makes +impossible: `an inter 16x16-level AB or 1:4 partition` WITH this round's filter read, and +`an inter partition below 8x8` WITHOUT it (measured by ablating the read behind a temporary +env switch, since removed). `--enable-ab-partitions=0 --enable-1to4-partitions=0 +--min-partition-size=8` cannot emit either -- so both are our own desync +(class `refusal-from-own-desync`): the compound 8x8 leaf carries at least one more +missing/misplaced symbol beyond the interp filter. The fix is therefore **necessary but not +sufficient** and is not claimed as pixel-proven. + +EVIDENCE: $HOME/.cache/interp3-suite-r1.log | `cargo test -p ec-av1 --lib -j3` under a +systemd user unit, MemoryMax=10G | totals below +EVIDENCE: gate run `EC_INTERP3_FRAMES=5..16 cargo test -p ec-av1 --lib a_real_aomenc_dual_filter_obmc_8x8` with and without the new read | 6 encodes x 2 arms | refusal string differs per arm (AB/1:4 vs below-8x8), 0 frames compared either way -- gate RED, ignored +EVIDENCE: `cargo test -p ec-av1 --lib an_obmc_neighbour_with_no_recorded` | direct call with the `[3, 3]` sentinel | 1 passed: refuses by name, no panic + +## Panic sweep of the decode path (charter clause) + +`neighbour_filter` was the only `panic!` reachable from a *stream-derived value* on the OBMC +path; converted. The rest of `decode.rs`'s 57 `panic!/unreachable!/unwrap/expect` sites, +inspected: `2733, 11268, 11617, 11636, 11683, 11996, 12015, 12052, 13820, 13998, 15225, +15533` are `unreachable!` on values a CDF alphabet or an earlier refusal already bounds +(cannot fire on any stream); `5238, 5282, 6043, 6110, 7310, 7311, 7777, 7778, 10479, 10535, +10679, 10888` are `unwrap/expect` on this decoder's own just-built state; everything above +line 22700 is inside `#[cfg(test)]`. Two remain flagged, not converted (they need a `Result` +in a counter/table helper and no stream is known to reach them): +`decode.rs:2486` `panic!("ref_hits: no per-reference counter for ref_frame {other}")` and +`decode.rs:3247` `panic!("intra mode {other} has no Intra_Mode_To_Tx_Type entry")`. +`mc.rs:203`/`:220` stay as documented invariants -- both callers now check first. + +## Residue + +- fix-now(next round): the remaining compound-8x8 desync. Method: `EC_TRACE=1` aomdec range + ladder against ours on the FIRST compound leaf of frame 5 of the gate's stream, comparing + msac RANGE element by element (never `tell()`). +- deferred(needs that fix): the 10-bit arm of the new gate, and the counter-proving + pixel-exact claim. + +## Suite + +`systemd-run --user --unit=interp3-suite-r1 -p MemoryMax=10G --same-dir bash -lc 'EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-interp3 nice -n 10 cargo test -p ec-av1 --lib -j3 > $HOME/.cache/interp3-suite-r1.log 2>&1'` + +**372 passed; 0 failed; 33 ignored; 1208.18s** (main's 371/0/32 plus this round's +`an_obmc_neighbour_with_no_recorded_filter_refuses_instead_of_panicking`, plus the new +gate ignored). Every OBMC/compound sibling gate green on this tip, including +`a_real_aomenc_stream_with_obmc_decodes_pixel_exact`, +`a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact`, +`a_real_aomenc_stream_with_compound_references_decodes_pixel_exact`, +`a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact` +and both `..._8x8_leaf_split_...` arms -- the entropy change did not move any of them. diff --git a/lanes/interp3-r2.handoff.md b/lanes/interp3-r2.handoff.md new file mode 100644 index 00000000..85064061 --- /dev/null +++ b/lanes/interp3-r2.handoff.md @@ -0,0 +1,48 @@ +# lane-interp3 r2 HANDOFF (turn cap) + +Tip: see `git log -1` on branch `lane-interp3` (r2 fix commit + report commit). +Base: r1 b702853 + `git merge main` (4eff3a1, lane-mvtwin mvstack fixes). Merge touched +only mvstack.rs / stream.rs / lanes/mvtwin-r1.report.md; cdf.rs untouched both sides. + +## Phase table + divergences: see lanes/interp3-r2.report.md (complete, 17 rows) +Two divergences found in `decode_inter_block8`'s compound arm, both FIXED: +1. decode.rs:19151 `read_compound_ref_frames` got a hard-coded `LAST_FRAME` (or -1) + for the above/left neighbour reference instead of the real per-mi bands + (`above_ref0`/`left_ref0`, what `decode_inter_block` passes) -> every + `av1_collect_neighbors_ref_counts` vote off the wrong CDF row. +2. decode.rs:19410 the leaf's grid stamp cleared BOTH per-slot `is_global_mv_block` + flags; now computed as libaom blockd.h:421-429 (mode GLOBAL_GLOBALMV + that slot's + gm model > TRANSLATION). +Also added: decode.rs:19726 per-entry `EC_STACK` print in the leaf's SINGLE-ref arm. + +## Ladder (EC_TRACE_MODE=1, ours vs instrumented aomdec, RANGE never tell) +- Before fix 1, frames=5 stream: first divergence at compound leaf mi (10,2) -- + both enter the mode info at rng=61097; aomdec reads refs (LAST,GOLDEN) mode + NEAREST_NEARESTMV -> rng 49516; ours read (LAST,LAST2) NEW_NEWMV -> rng 50496. +- Before fix 2, frames=16 stream: first divergence at single-ref 8x8 leaf mi (8,8), + entry rng=43099 both; aomdec stack = [(-1,-1) w648, (0,0) w644] (2 entries), + ours = [(0,0) w644, (2,-4) w644, (-1,-1) w4] (3) -- the extra (2,-4) is the + neighbour's stored mv1 where libaom substitutes the reader's global mv. +- AFTER both fixes: 570 vs 570 mode elements, `diff` EMPTY, no refusal. + +## Gate state +`a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` still +`#[ignore]`d (ignore text updated with this measurement). Now RED on RECONSTRUCTION, +not entropy: luma-only, frames 0-6 byte-exact, frame 7 = 36 Y wrong (max |d| 5, first +(42,15), the 8x8 leaf at mi (10,4), 1-px spill across its left/bottom deblock edges), +propagating to 222 Y + 4 U + 1 V at frame 15. +Artifacts: scratchpad .../{pin.obu (5 frames), pin16.obu==mm.obu (16), aom16.trace, +ours16e.trace, mm.aom.yuv, mm.ours.yuv, aom.obmc}. + +## Suite +Unit `interp3-suite-r2-1788327820.service`, log `$HOME/.cache/interp3-suite-r2.log`. +Armed at the r2 fix commit; still running at the cap -- read the log's `test result:` +line, do not re-run blindly. + +## EXACT NEXT STEP +Build an `EC_OBMC` emitter in decode.rs (both OBMC call sites) printing the oracle's +own byte format -- `EC_OBMC above|left mi=(r,c) wh=(WxH) rel=%d op=%d nbmv=(y,x) +nbref=%d nbbsize=%d filt=%d` -- then diff it against the 325 lines of +`EC_OBMC=1 aomdec --rawvideo -o /dev/null mm.obu`, starting at `mi=(10,4)`. The leaf +now records a REAL filter pair where it used to record the [3,3] sentinel, so an OBMC +blend over a compound neighbour is the first suspect for the residue. diff --git a/lanes/interp3-r2.report.md b/lanes/interp3-r2.report.md new file mode 100644 index 00000000..9e5333bc --- /dev/null +++ b/lanes/interp3-r2.report.md @@ -0,0 +1,88 @@ +# lane-interp3 r2 -- the compound 8x8 leaf's ENTROPY desync is closed (two twin drifts); gate now RED on a small luma reconstruction residue + +Base: b702853 (r1) + `git merge main` (4eff3a1, brings lane-mvtwin's mvstack fixes). +Merge diffstat: `crates/ec-av1/src/mvstack.rs`, `crates/ec-av1/src/stream.rs`, +`lanes/mvtwin-r1.report.md` only -- `cdf.rs` untouched by either side (byte-compare +trivially clean), no fixtures churn, no conflicts. + +## Phase table -- libaom `read_inter_block_mode_info` (decodemv.c ~1400-1600) + +`IB` = `decode_inter_block` compound arm, `L8` = `decode_inter_block8` compound arm +(both in `crates/ec-av1/src/decode.rs`; line numbers are this commit's). + +| # | phase (libaom) | IB | L8 | verdict | +|---|---|---|---|---| +| 1 | `skip_mode` (ctx = above+left skip_mode) | 16363 | 19087 | matches | +| 2 | `skip` | 16375 | 19093 | matches | +| 3 | cdef / delta_q / delta_lf | 16377-16382 | (16x16 slot's, per this fn's doc) | matches (leaf never a delta root) | +| 4 | `is_inter` (`intra_inter_ctx`) | 16389 | 19105 | matches | +| 5 | `comp_mode` (`read_comp_mode`, ref-count ctx) | 16475 | 19147 | matches (`skip_mode \|\| (reference_select && ...)` vs `reference_select \|\| skip_mode` then `skip_mode \|\| ...` -- same predicate) | +| 6 | `read_ref_frames`: `comp_ref_type`, uni/bi trees | 16480 | 19151 | **DIFFERENT -> FIXED**: L8 passed a hard-coded `LAST_FRAME` (or `-1`) as the above/left reference; IB passes the real `neighbours.above_ref[cmi]`/`left_ref[rmi]` | +| 7 | `av1_find_mv_refs` (`find_mv_stack_compound`, sign bias + gm table + tpl) | 16519 | 19195 | matches (L8's doc comment claiming "no sign-bias table nor tpl_frame" is stale -- both are passed) | +| 8 | `compound_mode` CDF (`COMPOUND_MODE_CTX_MAP`) | 16532 | 19205 | matches | +| 9 | drl + `read_mv` per ref (`assign_compound_mv`, has_nearmv/have_newmv rules) | 16537 | 19226 | matches (one shared fn) | +| 10 | `interintra` | n/a compound | n/a | matches (never read on compound -- correct) | +| 11 | `read_motion_mode` | n/a compound | n/a | matches (`has_second_ref` -> SIMPLE_TRANSLATION) | +| 12 | `comp_group_idx` (neighbour ctx) | 16675 | 19263 | matches | +| 13 | `compound_type` -> wedge idx+sign / diffwtd `mask_type` | 16710 | 19279 | matches | +| 14 | `compound_idx` (distance-weight ctx) | 16936 | 19310 | matches | +| 15 | `read_mb_interp_filter` (after `read_compound_type`; suppressed by `skip_mode` / `is_nontrans_global_motion`; `get_ref_filter_type` on ref0 matching EITHER neighbour ref) | 16980 | 19383 | matches (landed r1) | +| 16 | tail: grid `MiInfo` stamp -- per-slot `is_global_mv_block` | 16577+16660 | 19424 | **DIFFERENT -> FIXED**: L8 stamped `is_global_mv0/1 = false` unconditionally | +| 17 | tail: `record_inter_rect_mi` + `record_compound_ctx_rect_mi` (skip/skip_mode/inter/ref/ref1/filter/comp_group_idx/compound_idx bands) | 18870 | via `compound_ctx8` + caller, 19000 | matches -- verified by the range ladder staying exact for the whole stream | + +Root causes 6 and 16 are the round's fix. Both are the same class the charter named +(twin functions drift), and both are invisible to any value-only check: (6) changes a +CDF ROW, (16) changes a LATER block's mv-stack composition. + +## Changed (path:line) + +- `crates/ec-av1/src/decode.rs:19151` -- `read_compound_ref_frames` now gets + `above_ref0`/`left_ref0` (the per-mi bands the leaf already reads at 19078-19081) + instead of `LAST_FRAME`/`-1`. `-1` on an unavailable band is `start_tile`'s / + `start_row`'s own reset value, so no `has_above` guard is needed (IB has none either). +- `crates/ec-av1/src/decode.rs:19410` -- the leaf's grid stamp computes libaom's + per-slot `is_global_mv_block` (mode `GLOBAL_GLOBALMV`, that slot's gm model > + TRANSLATION; the >= 8x8 size predicate is always true for this leaf). +- `crates/ec-av1/src/decode.rs:19726` -- the leaf's SINGLE-ref arm prints the same + per-entry `EC_STACK` ladder `decode_inter_block`'s single-ref arm prints (this is + the instrument that isolated cause 16). +- `crates/ec-av1/src/stream.rs:6315` -- the gate's ignore reason + comment replaced + with this round's measurement (entropy closed, pixel residue open). + +## Gate: still RED, still `#[ignore]`d -- but on a different, much smaller failure + +`a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` +(`--enable-dual-filter=1 --enable-obmc=1 --enable-warped-motion=1 +--enable-onesided-comp=1`, `--min-partition-size=8 --enable-ab-partitions=0 +--enable-1to4-partitions=0`, 16 frames, 64x64). + +- r1: decode STOPPED at a bogus refusal at frame 5 (0 frames ever compared). +- r2: the whole 16-frame stream parses; the failure is now + `frame 7 mismatch vs ffmpeg` -- a reconstruction residue, luma-only, + |delta| <= 8, first sample (42,15) inside/around the 8x8 leaf at mi (10,4), + spilling 1 px across that leaf's left and bottom deblock edges. It grows by pure + propagation to 222 Y + 4 U + 1 V samples at frame 15 (chroma stays exact until + frame 14). + +EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/b6d8a07f-96a4-4bbb-b378-af9ae25cf7c9/scratchpad/{aom16.trace,ours16e.trace} | `EC_TRACE_MODE=1 aomdec --rawvideo` and `EC_TRACE_MODE=1 decode_probe` on the pinned 16-frame stream, `diff` of every `EC_MODE`/`EC_MODE_VAL` line (mi + msac RANGE, never tell) | 570 vs 570 elements, diff EMPTY, no refusal (before the fix: ours stopped at 347 elements, first RANGE divergence at the 8x8 leaf mi (8,8), stack 3 entries vs libaom's 2) +EVIDENCE: same dir, `pin.obu` (EC_INTERP3_FRAMES=5) | ladder before fix 1 | ours read refs (LAST,LAST2) + NEW_NEWMV at leaf mi (10,2) where aomdec reads (LAST,GOLDEN) + NEAREST_NEARESTMV -- the two differ only in a CDF row of `uni_comp_ref` +EVIDENCE: same dir, `mm.{aom,ours}.yuv` | `aomdec --rawvideo` vs `decode_probe` on the pinned mismatch stream, per-frame per-plane sample compare | frames 0-6 byte-exact; frame 7: 36 Y / 0 U / 0 V wrong, max |delta| 5; frame 15: 222 Y / 4 U / 1 V, max |delta| 8 + +## Refusals + +None lifted this round (the r1 refusal `an OBMC neighbour whose interp filter was +never recorded` stays; `refusal_inventory` unchanged). Two refusals this stream used +to hit -- `an inter 16x16-level AB or 1:4 partition` and `an inter partition below +8x8` -- were our own desync (class refusal-from-own-desync) and no longer fire on it. + +## Residue + +- fix-now(next round): the luma reconstruction residue above. First suspect is the + OBMC blend over a COMPOUND neighbour -- the leaf now records a real filter pair + where it used to record the `[3,3]` sentinel, and the oracle's `EC_OBMC` rung + prints `nbmv`/`nbref`/`nbbsize`/`filt` per neighbour while THIS decoder has no + `EC_OBMC` emitter at all. Build that emitter first (instrument-before-excuse), then + diff the 325 oracle `EC_OBMC` lines of `mm.obu` against ours. +- deferred(needs that fix): the gate's counter asserts (compound-8x8 filter reads, + dual-filter differing directions, 8x8 OBMC blends) are never reached while the + pixel compare fails first; the 10-bit arm; a `--tile-columns=1` arm. diff --git a/lanes/interp3-r3.handoff.md b/lanes/interp3-r3.handoff.md new file mode 100644 index 00000000..0c238b81 --- /dev/null +++ b/lanes/interp3-r3.handoff.md @@ -0,0 +1,88 @@ +# lane-interp3 r3 HANDOFF (turn cap) -- root cause FOUND and FIXED, suite still running + +Tip: `f36be26` on branch `lane-interp3` (fix) + this handoff/report commit. + +## Suite state +- r2 suite (unit `interp3-suite-r2-1788327820.service`, log `$HOME/.cache/interp3-suite-r2.log`), + armed at the r2 commit, FINISHED: + `test result: ok. 378 passed; 0 failed; 34 ignored; 0 measured; 0 filtered out; finished in 742.50s` +- r3 suite FINISHED GREEN at f36be26 (unit `interp3-suite-r3-1788328778.service`): + `test result: ok. 379 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1031.33s` + (old text below is superseded) +- r3 suite armed at f36be26: unit `interp3-suite-r3-1788328778.service`, + log `$HOME/.cache/interp3-suite-r3.log`. At the cap it had 258 `... ok`, ZERO + `FAILED`/`panicked`, no `test result:` line yet. READ THAT LINE, do not re-run + blindly, then paste it into `lanes/interp3-r3.report.md` where + `EVIDENCE: SUITE_LINE_PLACEHOLDER` sits. + +## Stage attribution of the frame-7 residue (done FIRST, as chartered) +`EC_AV1_PREFILT_DUMP` on both decoders over the pinned 16-frame stream +(`.../scratchpad/mm.obu`), byte compare per decode-order frame: +frames 0-6 identical, frame 7 = 35 differing luma bytes, 8..15 grow to 224. +=> PRE-FILTER, i.e. prediction/reconstruction, never the loop filter/CDEF/LR. +All 35 sit in luma rows 42-47, cols 16-23, i.e. the block at mi (10,4); +rows 40-41 of that same block are EXACT and the error grows downward. + +## What the OBMC comparison actually said (emitter built, class swept, CLEAN) +Before writing the emitter, the hand comparison against libaom found NO mismatch: +`overlappable_above`/`overlappable_left` stepping and `max_neighbor_obmc` +(`{0,1,2,3,4,4}`, 8x8 -> 1 per pass) match `obmc.h:20-55`; overlap sizes +(4 luma rows above / 4 luma cols left at 8x8, chroma 2) match +`build_obmc_inter_pred_{above,left}`; `av1_skip_u4x4_pred_in_obmc` chroma-above +skip matches; `obmc_mask_1/2/4/8/16/32` are byte-identical to +`reconinter.c:752-765`; OBMC never warps (`if (!build_for_obmc) av1_init_warp_params`). +One real divergence candidate was left un-ported and is still a documented +corner-cut, not a defect on this content: `obmc.h`'s `mi_step == 1` 4-wide pair +merge, and libaom's `op_mi_size = AOMMIN(xd->width, mi_step)` which can exceed +the remaining span while ours clips with `.min(end_col - col)` (only reachable +for a 2nd neighbour with a wide step). + +Emitter: `decode.rs:15806` `ec_obmc_bsize()` + `decode.rs:15828` `ec_obmc_trace()`, +called at both passes in `obmc_blend`. Format is aomdec's own bytes: +`EC_OBMC above|left mi=(r,c) wh=(WxH) rel=N op=N nbmv=(y,x) nbref=N nbbsize=N filt=N` +(`filt` = packed `interp_filters.as_int` = `y | (x << 16)`). +`diff` of the 325 oracle lines vs our 325: EMPTY. OBMC is exonerated. + +Also added `decode.rs:14682` + `:22658` `EC_PICT idx=` (decode-order frame +marker under `EC_OBMC`/`EC_TRACE_MODE`). REQUIRED: the marker prints AFTER the +frame's own trace lines, so `awk` must count markers seen, not read the value on +the preceding line -- attributing by the preceding `EC_PICT` value is off by one +and cost part of this round. + +## Hypotheses ruled out (each by measurement) +- OBMC neighbour fields / masks / overlap: 325/325 identical lines (above). +- Frame 7 has NO OBMC block at mi (10,4) at all -- it is COMPOUND + (SIMPLE_TRANSLATION), so the r2 handoff's "OBMC over a compound neighbour" + suspect could not have been it. +- Residual/entropy: r2's range ladder is exact end to end; `EC_MCDUMP` (a + temporary rung, removed before commit) showed aom_recon - our_residual + reproduces our PREDICTION in rows 40-41 and diverges below => prediction. +- Wrong dual-filter x/y assignment: a swap would err in every row, not only the + lower ones. + +## Root cause (FIXED, gate GREEN) +`decode_inter_block8`'s COMPOUND arm predicted BOTH taps translationally. +libaom applies `allow_warp`'s GLOBAL branch to every `is_global_mv_block` +reference slot -- compound included, independent of `motion_mode` +(`av1_init_warp_params` inside `build_inter_predictors_8x8_and_bigger`'s per-`ref` +loop; `reconinter.c:33-55`). `decode_inter_block`'s compound arm has done this +since lane-cwarp r1 (`decode.rs:16691`). Third twin-functions-drift instance in +this lane. Frame 7 mi (10,4): GLOBAL_GLOBALMV, ref0=GOLDEN mv (0,0), +ref1=ALTREF mv (-3,4), comp_group_idx=1. +Fix: `decode.rs:19513` (`leaf_compound_warp`, `warp0_c`/`warp1_c`), +`decode.rs:19596`/`:19618` (`warp_affine_compound` per luma tap; chroma is 4x4, +below `av1_init_warp_params`'s 8px per-plane bound, so it stays translational). +Counter `COMPOUND_WARP_HITS_8` / `compound_warp_hits_8()` at `decode.rs:1786`. +After the fix ALL 16 decode-order frames are byte-identical pre-filter. + +## Gate +`a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` +(`stream.rs:6332`) is UN-IGNORED and GREEN with four hard asserts (compound-8x8 +filter read, differing dual-filter directions, 8x8 OBMC blend, 8x8 compound +GLOBAL warp). `$HOME/.cache/interp3-gate-r3.log`: `1 passed; 0 failed`. + +## EXACT NEXT STEP +1. DONE (suite green, report filled). Nothing owed here. +2. Then the lane's open residue is only the two deferrals in the report + (10-bit arm blocked by lane-inter8's 10-bit 8x8-leaf desync; `--tile-columns=1` + arm blocked by the SB-level rect-partition refusal). diff --git a/lanes/interp3-r3.report.md b/lanes/interp3-r3.report.md new file mode 100644 index 00000000..05fac697 --- /dev/null +++ b/lanes/interp3-r3.report.md @@ -0,0 +1,106 @@ +# lane-interp3 r3 -- the 8x8 COMPOUND leaf never applied the per-ref GLOBAL warp; gate is GREEN and un-ignored + +Base: d06d93f (r2 handoff, already merged with main). + +## Root cause (one line) + +`decode_inter_block8`'s COMPOUND arm predicted **both** reference taps +translationally, while libaom applies `allow_warp`'s GLOBAL branch to every +`is_global_mv_block` reference slot -- compound included and independently of +`motion_mode` (`av1_init_warp_params` is called inside +`build_inter_predictors_8x8_and_bigger`'s per-`ref` loop, `reconinter.c:33-55` +for `allow_warp` itself). The 16x16+ compound arm has done this since +lane-cwarp r1 (`decode.rs:16691`); the 8x8 leaf is its twin and drifted. +Third instance in this lane of the class **twin functions drift**. + +Effect on the pinned stream: the GLOBAL_GLOBALMV compound 8x8 leaf at +mi (10,4) of decode-order frame 7 (ref0=GOLDEN mv (0,0), ref1=ALTREF mv +(-3,4), `comp_group_idx=1` masked compound) was predicted with a pure +translation, so its prediction error was 0 at the block's top rows and grew +downward to |delta| 5 -- then propagated through every later frame. + +## It was NOT the OBMC blend (the r2 handoff's first suspect, disproved) + +An `EC_OBMC` emitter was added to both OBMC passes in `decode.rs`, printing the +instrumented aomdec's own byte format +(`EC_OBMC above|left mi=() wh=() rel= op= nbmv=() nbref= nbbsize= filt=`, +`decodeframe.c` `dec_build_prediction_by_{above,left}_pred`). The two decoders +emit **325 identical lines** on the pinned 16-frame stream -- neighbour +position, span, mv, reference, bsize and packed dual-filter pair all agree at +every OBMC call. The class sweep the charter asked for (neighbour-side fields +used by OBMC: filter, ref, mv, scale) is therefore CLEAN by measurement, not by +inspection; `obmc_mask_1/2/4/8/16/32` were also byte-compared against +`reconinter.c:752-765` and match. + +Frame 7 has no OBMC block at mi (10,4) at all: it is a compound block, and +compound blocks take SIMPLE_TRANSLATION. + +## Changed (path:line, this commit) + +- `crates/ec-av1/src/decode.rs:19513` -- `leaf_compound_warp` + + `warp0_c`/`warp1_c`, the leaf's per-slot copy of `decode_inter_block`'s + `compound_warp` (`force_integer_mv` short-circuit, `gm.invalid` guard). +- `crates/ec-av1/src/decode.rs:19596,19618` -- `warp::warp_affine_compound` + replaces each luma tap's translational intermediate, exactly as the 16x16+ + arm does at 17130/17155. Chroma is 4x4 at an 8x8 leaf, below + `av1_init_warp_params`'s own per-plane 8px bound, so chroma stays + translational (same rule the leaf's single-ref arm already applied). +- `crates/ec-av1/src/decode.rs:1786` -- `COMPOUND_WARP_HITS_8` + + `compound_warp_hits_8()`: the gate's proof that the warp fired at an 8x8 + LEAF specifically (`COMPOUND_WARP_HITS` alone cannot tell it from a 16x16+). +- `crates/ec-av1/src/decode.rs:15806` (`ec_obmc_bsize`) and `15828` + (`ec_obmc_trace`) + the two call sites in `obmc_blend` -- the `EC_OBMC` rung. +- `crates/ec-av1/src/decode.rs:14682,22658` -- `EC_PICT idx=` decode-order + frame marker (printed under `EC_OBMC`/`EC_TRACE_MODE`), so a trace line can be + attributed to the frame whose `EC_AV1_PREFILT_DUMP` file mismatched. Without + it the r2 hunt mis-attributed every trace line by one frame. +- `crates/ec-av1/src/stream.rs:6332` -- the gate's `#[ignore]` removed, doc + comment carries this round's measurement, and a third hard assert + (`compound_warp_hits_8() > before`) added. + +## Class sweep + +Both inter block decoders are the only prediction sites +(`decode_inter_block` 16309, `decode_inter_block8` 19032); all 12 +`predict_compound_intermediate` calls were audited. Warp coverage is now: +16x16+ single-ref (18235-18253), 16x16+ compound y/u/v x 2 refs +(17130-17300), 8x8 leaf single-ref (20238-20253), 8x8 leaf compound luma x 2 +refs (19596/19618, chroma correctly excluded). No third twin exists. + +## Gate: GREEN, un-ignored + +`a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` +(`--enable-dual-filter=1 --enable-obmc=1 --enable-warped-motion=1 +--enable-onesided-comp=1`, `--min-partition-size=8 --enable-ab-partitions=0 +--enable-1to4-partitions=0`, 64x64, 16 frames). Four hard asserts now: +compound 8x8 leaf reading its own switchable filter, a block whose two +dual-filter directions DIFFER, an 8x8 OBMC blend, and an 8x8 compound leaf +predicted through the per-ref GLOBAL warp. + +Command: +`EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-interp3 cargo test -p ec-av1 --lib a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact` +Result: `test result: ok. 1 passed; 0 failed` (log `$HOME/.cache/interp3-gate-r3.log`). + +## Refusals + +None lifted. The r1 refusal `an OBMC neighbour whose interp filter was never +recorded` stays (it does not fire on this stream); `refusal_inventory.rs` and +`gate_coverage.rs` unchanged. + +## EVIDENCE + +EVIDENCE: /tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/b6d8a07f-96a4-4bbb-b378-af9ae25cf7c9/scratchpad/{aom.obmc,ours.obmc} | `EC_OBMC=1 aomdec --rawvideo -o /dev/null mm.obu` vs `EC_OBMC=1 decode_probe mm.obu`, `diff` of every EC_OBMC line | 325 vs 325 lines, diff EMPTY -- OBMC neighbour selection/mv/ref/bsize/filter exonerated +EVIDENCE: same dir, pf_a/f.f0..15 vs pf_o/f.f0..15 | `EC_AV1_PREFILT_DUMP` on both decoders, byte compare per decode-order frame BEFORE the fix | frames 0-6 identical, frame 7 35 bytes differ (all inside luma rows 42-47, cols 16-23 = the 8x8 leaf at mi (10,4)), growing to 224 at frame 15 +EVIDENCE: same dir, pf_a vs pf_o2 | identical command AFTER the fix | all 16 decode-order frames byte-identical pre-filter (0 differing bytes) +EVIDENCE: $HOME/.cache/interp3-gate-r3.log | `cargo test -p ec-av1 --lib a_real_aomenc_dual_filter_obmc_8x8_inter_sequence_decodes_pixel_exact -- --nocapture` | `test result: ok. 1 passed; 0 failed` with all four counter asserts live (the run would panic if `compound_warp_hits_8` had not moved) +EVIDENCE: $HOME/.cache/interp3-suite-r3.log | `EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-interp3 cargo test -p ec-av1 --lib -j3` under systemd unit `interp3-suite-r3-1788328778.service`, armed at f36be26 | `test result: ok. 379 passed; 0 failed; 33 ignored; 0 measured; 0 filtered out; finished in 1031.33s` (r2 baseline was 378 passed / 34 ignored -- the delta is exactly this gate leaving `#[ignore]`) + +## Residue + +- deferred(lane-inter8's 10-bit 8x8-leaf desync) -- a 10-bit twin of this gate. + Its sibling `a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_...` + is still `#[ignore]`d on an unrelated 10-bit desync (lane-inter8 r2), so a + 10-bit arm of this recipe would go RED on that, not on interp3's own path. +- deferred(needs a multi-tile recipe that reaches an 8x8 leaf) -- a + `--tile-columns=1` arm. lane-inter8 r3 measured that the 128x64 multi-tile + recipe stops at the SB-level rect-partition refusal before any 8x8 leaf.