diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 8bb41995..bab9ae81 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -171,6 +171,26 @@ pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize { INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get()) } +// lane-uv8 r1: the three non-DC chroma mode classes an INTRA 8x8 leaf inside +// an INTER frame ([`decode_inter_block8`]'s intra arm) can carry -- the arm +// read `uv_mode` and then refused everything but `DC_PRED`. Counted here and +// nowhere else so the gate's assert cannot be satisfied by a >=16x16 block. +thread_local! { + static INTRA_IN_INTER8_UV_DIR_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTRA_IN_INTER8_UV_SMOOTH_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTRA_IN_INTER8_UV_CFL_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// `(directional, smooth/paeth, CfL)` chroma modes coded by an intra 8x8 leaf +/// inside an inter frame -- see [`INTRA_IN_INTER8_UV_DIR_HITS`]. +pub(crate) fn intra_in_inter8_uv_hits() -> (usize, usize, usize) { + ( + INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.get()), + INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.get()), + INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.get()), + ) +} + // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a // frame-level flag through the recursive block decode -- `0` (the default) @@ -1779,6 +1799,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` @@ -1810,6 +1856,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 @@ -15613,6 +15673,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; @@ -15827,6 +15894,9 @@ fn resolve_interp_filter( } else { sym0 }; + if enable_dual_filter && sym0 != sym1 { + DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1)); + } if std::env::var_os("EC_TRACE_MODE").is_some() { eprintln!( "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}", @@ -16495,15 +16565,15 @@ fn neighbour_filter( if let Some(kind) = interp_fixed { return Ok((kind, kind)); } - // lane-golomb r9: this used to hand the sentinel straight to - // `from_switchable_symbol`, which PANICS on any value above 2 -- a crash - // on stream data (measured on a real 192x68 cq40 aomenc stream, where an - // inter leaf below 8x8 desyncs upstream and leaves an unrecorded filter - // behind). A decoder must refuse such a stream by name, never abort the - // process; the desync that produces the sentinel belongs to lane-intersub8. + // 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 switchable interp filter was never recorded", + "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)", )); } Ok(( @@ -16689,6 +16759,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 @@ -16788,6 +16923,7 @@ fn obmc_blend( 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); @@ -16807,6 +16943,7 @@ fn obmc_blend( 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); @@ -21113,7 +21250,6 @@ fn decode_inter_block8( const CHROMA_SIDE: usize = 4; let (r, c) = outer_at; - let _ = (r, c); // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the // left column of a 16x16's second leaf ROW is the previous 16x16 block's @@ -21168,6 +21304,10 @@ fn decode_inter_block8( } let mode_for_tx; + // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the + // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf + // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. + let mut uv_predict_mode = DC_PRED; let (luma_grid, u_grid, v_grid); let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; // lane-inter8 r1: this leaf's own resolved references, handed back so the @@ -21200,21 +21340,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)); @@ -21395,6 +21538,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); @@ -21404,6 +21599,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( @@ -21418,51 +21661,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-intersub8 r2: the compound 8x8 leaf used to hard-code - // `Regular` and leave `leaf_filter_syms` at the `[3, 3]` - // "no filter" sentinel. libaom reads `read_mb_interp_filter` - // here for EVERY inter block (`decodemv.c` - // `read_inter_block_mode_info`, right after - // `read_compound_type`), and when `av1_is_interp_needed` is 0 - // -- `skip_mode`, or a non-translational GLOBALMV -- - // `set_default_interp_filters` stores EIGHTTAP_REGULAR (0), - // NOT a sentinel. A later block whose ref matches this one - // then reads `av1_get_pred_context_switchable_interp` off - // that stored 0, so recording `[3, 3]` shifted its - // `switchable_interp` context and desynced the tile. - 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, - skip_mode, - above_filter_ctx, - left_filter_ctx, - true, - ); - leaf_filter_syms = resolved_filter; let mut inter0_y = vec![0i32; SIDE * SIDE]; mc::predict_compound_intermediate( &py0.data, @@ -21478,6 +21684,13 @@ fn decode_inter_block8( 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, @@ -21493,6 +21706,13 @@ fn decode_inter_block8( 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 { @@ -21766,6 +21986,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; @@ -22287,12 +22518,62 @@ fn decode_inter_block8( this leaf with one; the >=16x16 arm decodes deltas)", )); } + // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a + // directional luma mode is already legal on this leaf -- the arm + // passed a hardcoded `false` where [`decode_leaf8`] reads the + // mi-exact neighbour modes (`get_intra_edge_filter_type`, spec + // 7.11.2). + let (above_mode, left_mode) = + neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, neighbours.modes_above_left(r, c)); + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); + // lane-uv8 r1: libaom `read_intra_block_mode_info` (decodemv.c:1198-1207) + // -- `uv_mode` over the CFL-allowed alphabet (`is_cfl_allowed`: a + // BLOCK_8X8 leaf is inside the 32x32 bound), then `read_cfl_alphas` + // for `UV_CFL_PRED`, then `angle_delta_uv` off the MAPPED uv mode's + // row (`get_uv_mode`, identity over `V_PRED..=D67_PRED`). Every value + // but `DC_PRED` was refused here, which is what blocked the low-cq + // CDEF arms and the 10-bit gates. let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); - if uv_mode != DC_PRED { - return Err(unsupported( - "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", - )); + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}", + leaf_mi.0, + leaf_mi.1, + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), + dec.debug_state().0 + ); } + if (9..=12).contains(&uv_mode) { + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.set(c.get() + 1)); + } + let alpha = if uv_mode == UV_CFL_PRED { + INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.set(c.get() + 1)); + Some(read_cfl_alphas(dec, cdfs)) + } else { + None + }; + let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.set(c.get() + 1)); + read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) + } else { + 0 + }; + if angle_delta_uv != 0 { + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.set(c.get() + 1)); + } + // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED`. + uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; + // The CHROMA neighbour's own `uv_mode` decides the chroma edge filter + // strength (`get_intra_edge_filter_type`, reconintra.c:974), never the + // luma one -- same read [`decode_leaf8`] does. + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/ // `uv_mode` are both effectively `DC_PRED`-gated already on this // leaf (a nonzero `mode` still passes, but `uv_mode` is forced @@ -22304,7 +22585,10 @@ fn decode_inter_block8( "a block that actually uses a palette (Y) -- reconstruction is out of scope", )); } - if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { + // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only + // when `uv_mode == UV_DC_PRED` (decodemv.c) -- unconditional here + // while every non-DC uv_mode was refused a few lines above. + if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { return Err(unsupported( "a block that actually uses a palette (UV) -- reconstruction is out of scope", )); @@ -22319,14 +22603,39 @@ fn decode_inter_block8( // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: // a real palette-Y block already returned above. let mut filter_intra = None; + // lane-uv8 r2: the oracle's `EC_ISTEP` ladder (`EC_TRACE_MODE_STEP`) + // prints `use_filter_intra` for an intra block inside an INTER frame + // and nothing else, so this leaf needs the same two lines for a + // range-ladder diff against it. + let ec_istep8 = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); if mode == DC_PRED && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) && let Some(class) = filter_intra_size_class(SIDE) - && dec.symbol(&mut cdfs.filter_intra[class]) != 0 { - FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); - INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); - filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); + let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0; + if ec_istep8 { + eprintln!( + "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={} rng={}", + leaf_mi.0, + leaf_mi.1, + u8::from(use_fi), + dec.debug_state().0 + ); + } + if use_fi { + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); + let fi = dec.symbol(&mut cdfs.filter_intra_mode); + if ec_istep8 { + eprintln!( + "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}", + leaf_mi.0, + leaf_mi.1, + dec.debug_state().0 + ); + } + filter_intra = Some(fi); + } } mode_for_tx = mode; let (mi_row, mi_col) = leaf_mi; @@ -22385,31 +22694,34 @@ fn decode_inter_block8( &vec![0i32; SIDE * SIDE], None, filter_intra, - false, + smooth_neighbor, ); + // CfL's AC contribution is the luma this leaf just reconstructed, + // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5). + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); u.reconstruct( cpx, cpy, CHROMA_SIDE, - DC_PRED, - 0, + uv_predict_mode, + angle_delta_uv, reach, &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, - None, - false, + smooth_neighbor_uv, ); v.reconstruct( cpx, cpy, CHROMA_SIDE, - DC_PRED, - 0, + uv_predict_mode, + angle_delta_uv, reach, &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, - None, - false, + smooth_neighbor_uv, ); luma_grid = vec![0i32; SIDE * SIDE]; u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; @@ -22419,7 +22731,15 @@ fn decode_inter_block8( luma_grid = read_plane( dec, cdfs, - TxbSet::Luma8, + // lane-uv8 r3: an intra leaf inside an inter frame is + // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8 + // luma reads the INTRA set -- seven-type + // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`, + // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding + // the reduced set read the wrong ALPHABET (class + // [[wrong-alphabet-same-value]]) and desynced at the leaf's + // first `tx_type`. + txbset_for(8, reduced_tx_set), scan8, 0, around[0], @@ -22436,8 +22756,9 @@ fn decode_inter_block8( None, filter_intra, None, - false, + smooth_neighbor, )?; + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); u_grid = read_plane( dec, cdfs, @@ -22446,8 +22767,8 @@ fn decode_inter_block8( 1, around[1], mode, - DC_PRED, - 0, + uv_predict_mode, + angle_delta_uv, reach, u, cpx, @@ -22455,10 +22776,10 @@ fn decode_inter_block8( CHROMA_SIDE, TX4, base_q_idx, + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, None, - None, - false, + smooth_neighbor_uv, )?; v_grid = read_plane( dec, @@ -22468,8 +22789,8 @@ fn decode_inter_block8( 2, around[2], mode, - DC_PRED, - 0, + uv_predict_mode, + angle_delta_uv, reach, v, cpx, @@ -22477,10 +22798,10 @@ fn decode_inter_block8( CHROMA_SIDE, TX4, base_q_idx, + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, None, - None, - false, + smooth_neighbor_uv, )?; } } @@ -22502,6 +22823,16 @@ fn decode_inter_block8( ) }); neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + // lane-uv8 r1: this leaf never stamped a mode band at all, so the block + // below/right of it read whatever block last wrote the coarse [`SUB`] + // slot -- now that an intra leaf here can code a smooth/directional + // `uv_mode`, its chroma neighbours must see it (and an inter leaf must + // stamp `DC_PRED`, what libaom stores for a non-intra block). Same pair + // [`decode_leaf8`] writes, plus the coarse fallback slots. + neighbours.above_uv_mode[c] = uv_predict_mode; + neighbours.left_uv_mode[r] = uv_predict_mode; + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode_for_tx); + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); if let Some((left, above)) = saved_luma_ctx { for (cell, state) in left.into_iter().enumerate() { neighbours.left[leaf_mi.0 + cell][0] = state; @@ -24901,6 +25232,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; @@ -25311,6 +25649,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 fcc82e7e..7db27494 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -25,7 +25,6 @@ #[cfg(test)] const CAPABILITY_CLAIMS: &[&str] = &[ "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", - "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", ]; #[cfg(test)] @@ -33,7 +32,7 @@ const REFUSALS: &[&str] = &[ "a nonzero angle delta on an 8x8 intra leaf in an inter frame (no gate reaches this leaf with one; the >=16x16 arm decodes deltas)", "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 OBMC neighbour whose switchable interp filter was never recorded", + "an OBMC neighbour whose interp filter was never recorded (no switchable symbol for that block)", "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index c7e86431..9c9a5dce 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6657,6 +6657,283 @@ mod tests { ); } + /// lane-uv8 r1 (classes [[refusal-strings-are-claims]] + + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with + /// 8x8 partitions and full chroma intra tooling + /// (`--enable-cfl-intra=1 --enable-smooth-intra=1 --enable-paeth-intra=1 + /// --enable-directional-intra=1`), in which the RD gives an INTRA 8x8 + /// leaf inside an inter frame a NON-DC `uv_mode`. That leaf + /// ([`decode::decode_inter_block8`]'s intra arm) read the `uv_mode` + /// symbol and refused every value but `DC_PRED` -- "this encoder never + /// writes one" was a claim, and this gate is what contradicts it. Hard- + /// asserts `decode::intra_in_inter8_uv_hits` (directional, smooth/paeth, + /// CfL, counted on THIS leaf only); an attempt that never produced one + /// proves nothing, and exhausting every attempt is a FAILURE, not a SKIP. + #[test] + fn a_real_aomenc_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { + uv_mode_in_inter8_gate(8, 1); + } + + /// The 10-bit arm (both of the user's films are `yuv420p10le`). + #[test] + fn a_real_aomenc_10bit_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { + uv_mode_in_inter8_gate(10, 1); + } + + /// The multi-tile arm (class [[new-map-ignores-tile-edge]]): this round + /// stamps a new `uv_mode` band from the 8x8 leaf, whose availability must + /// be tile-relative. + #[test] + fn a_real_aomenc_two_tile_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() + { + uv_mode_in_inter8_gate(8, 2); + } + + fn uv_mode_in_inter8_gate(bit_depth: u32, tile_columns: u32) { + let name = format!("uv_mode_in_inter8_gate({bit_depth}, tiles={tile_columns})"); + if !have_ffmpeg() { + eprintln!("SKIP {name}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 8usize); + let mut refusals = Vec::new(); + let mut uncounted_exact = 0u32; + let mut totals = (0usize, 0usize, 0usize); + for attempt in 0..30u32 { + let seed = 42 + attempt; + // A zooming fractal with a hard CUT at frame 4 (`overlay` + // switching a second, unrelated fractal on): after the cut a block + // is unpredictable from the reference, which is what makes aomenc + // code INTRA blocks inside an inter frame. Chroma is NOT + // desaturated here (every sibling inter gate passes `hue=s=0`) -- + // real chroma detail is exactly what pushes the chroma RD off + // DC_PRED. `noise` carries its own explicit seed (lavfi + // `gradients` ignores its seed; class [[seeded-fixture-not-reproducible]]). + let source = format!( + "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ + mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ + [a][b]overlay=enable='gte(n,4)',noise=alls=12:allf=t+u:all_seed={seed}", + 5.0 - f64::from(attempt) * 0.06, + 0.9 + f64::from(attempt) * 0.11 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, + "-strict", + "-1", + "-t", + "0.32", + "-f", + "yuv4mpegpipe", + "-strict", + "-1", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + // A coarser quantiser is what pushes the chroma RD to a cheap + // non-DC mode on a small block; sweep 12..40 (the low end is what + // lane-cdef's cq12 arm needs). + let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7); + let depth_args: &[&str] = if bit_depth == 10 { + &["-b", "10", "--input-bit-depth=10"] + } else { + &[] + }; + let tiles = format!("--tile-columns={}", tile_columns - 1); + // The y4m goes through a FILE, not aomenc's stdin: this gate's + // stream is ~100 KB, bigger than a pipe buffer, so an aomenc that + // is still being fed on stdin blocks writing its stdout and the + // test blocks writing its stdin -- a hard deadlock (measured + // here, 3 min into attempt 0, class [[gate-loader-slurps-whole-file]]). + // The path is PID-keyed (class [[pid-keyed-temp-path]]). + let y4m_path = std::env::temp_dir().join(format!( + "ec-av1-uv8-{}-{bit_depth}-{tile_columns}-{seed}.y4m", + std::process::id() + )); + std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture"); + let child = Command::new(aomenc_path()) + .args(depth_args) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq, + "--cpu-used=0", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-max-dist=9999", + "--kf-min-dist=9999", + "--threads=1", + "--row-mt=0", + &tiles, + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-ref-frame-mvs=0", + // Per-arm overrides go LAST (aomenc keeps the LAST + // occurrence of a repeated --enable-* flag). The three + // chroma intra tools this gate is about, plus the fences + // that keep the leaf's SIBLING refusals (its TX_4X4 + // split, a nonzero angle delta, sub-16 rect inter leaves) + // out of the way. + "--enable-cfl-intra=1", + "--enable-smooth-intra=1", + "--enable-paeth-intra=1", + "--enable-directional-intra=1", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-rect-partitions=0", + "--min-partition-size=8", + "--max-partition-size=32", + "--obu", + "-o", + "-", + ]) + .arg(&y4m_path) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + let out = child.wait_with_output().expect("aomenc failed to run"); + let _ = std::fs::remove_file(&y4m_path); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::intra_in_inter8_uv_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{name} decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed}: {msg}")); + continue; + } + }; + let now = decode::intra_in_inter8_uv_hits(); + // class [[counter-from-refused-stream]]: per-attempt deltas, and + // only for an attempt that decoded to the end and is pixel- + // compared below. + let fired = (now.0 - before.0, now.1 - before.1, now.2 - before.2); + totals = ( + totals.0 + fired.0, + totals.1 + fired.1, + totals.2 + fired.2, + ); + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded + // is ALWAYS pixel-compared; the counter only decides whether the + // attempt counts as firing. + // lane-uv8 r3: every one of the three chroma classes this gate + // exists for (directional, smooth/paeth, CfL) must fire on the + // SAME pixel-compared attempt -- a sum-nonzero predicate would + // pass on an attempt that only ever hit DC-adjacent CfL. + let counted = fired.0 > 0 && fired.1 > 0 && fired.2 > 0; + if !counted { + uncounted_exact += 1; + refusals.push(format!( + "seed {seed}: decoded and pixel-compared, but no 8x8 intra leaf in an inter \ + frame carried a non-DC uv_mode" + )); + } + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + eprintln!( + "{name} seed={seed} {cq}: 8x8 intra-in-inter leaves with a non-DC uv_mode -- \ + directional {}, smooth/paeth {}, CfL {}", + fired.0, fired.1, fired.2 + ); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + for (plane, (g, w)) in [ + ("Y", (&got.y, &want.y)), + ("U", (&got.u, &want.u)), + ("V", (&got.v, &want.v)), + ] { + let stride = if plane == "Y" { width } else { width / 2 }; + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { + eprintln!( + "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ + want {} ({} samples differ)", + at % stride, + at / stride, + g[at], + w[at], + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), + ); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); + } + if counted { + gate_buckets( + &name, + 1, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + return; + } + } + gate_buckets( + &name, + 0, + uncounted_exact, + refusals.len() - uncounted_exact as usize, + ); + panic!( + "{name} never observed a non-DC uv_mode on an 8x8 intra leaf in an inter frame \ + (totals dir/smooth/cfl {totals:?}):\n{}", + refusals.join("\n") + ); + } + + /// lane-chroma r2 stage 1: a real aomenc key frame with /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- @@ -7165,6 +7442,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"); @@ -7174,7 +7454,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). @@ -7187,7 +7468,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 @@ -7314,6 +7595,7 @@ mod tests { "whole-superblock inter PARTITION_NONE", &[], 64, + 4, ); } @@ -7328,6 +7610,7 @@ mod tests { "whole-superblock inter PARTITION_NONE", &[], 64, + 4, ); } @@ -7370,6 +7653,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" ); } @@ -7384,6 +7749,7 @@ mod tests { "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves", &[], 64, + 4, ); } @@ -7407,6 +7773,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. diff --git a/lanes/uv8-r1.handoff.md b/lanes/uv8-r1.handoff.md new file mode 100644 index 00000000..62b181fc --- /dev/null +++ b/lanes/uv8-r1.handoff.md @@ -0,0 +1,64 @@ +# lane-uv8 r1 — HANDOFF (RED: implemented, NOT gated) + +## What is implemented (`crates/ec-av1/src/decode.rs`, `decode_inter_block8`'s intra arm) +Mirrors libaom `read_intra_block_mode_info` (`av1/decoder/decodemv.c:1178-1220`, read from +`~/.cache/aom-oracle/src`) for an INTRA 8x8 leaf inside an INTER frame: + +- `uv_mode` over the CFL-allowed alphabet (`cdfs.uv_mode_cfl[mode]`; BLOCK_8X8 is inside + `is_cfl_allowed`'s 32x32 bound), then `read_cfl_alphas` when `UV_CFL_PRED`, then + `angle_delta_uv` off `angle_delta[uv_mode - V_PRED]` (`get_uv_mode` is the identity over + `V_PRED..=D67_PRED`) — the exact order libaom reads them in. +- `uv_predict_mode = get_uv_mode(uv_mode)`; chroma prediction, chroma `default_tx_type` + (`read_plane`'s `predict_mode` arg → `default_intra_tx_type`, DCT for CfL) and the CfL AC + (`cfl_ac_q3(y, px, py, 8)` over the leaf's 4x4 chroma) all take it. +- `smooth_neighbor_uv` from `Neighbours::smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c)` + (chroma edge filter reads the CHROMA neighbour's uv_mode — reconintra.c:974), and the leaf's + LUMA `smooth_neighbor` from `modes_above_left_mi` (it passed a hardcoded `false` before). +- `palette_uv_mode` is now read only when `uv_mode == DC_PRED` (`read_palette_mode_info`); + it was read unconditionally, harmless only because every non-DC uv_mode was refused. +- Tail: the leaf now stamps its mode bands (`above_uv_mode[c]`/`left_uv_mode[r]`, + `record_mode_mi`, `record_uv_mode_mi`, 2x2 mi) — it stamped none at all, so a neighbour read + a stale coarse SUB slot. An inter leaf stamps `DC_PRED`, what libaom stores. +- New per-leaf counters `decode::intra_in_inter8_uv_hits() -> (dir, smooth/paeth, cfl)`. + +## Refusal state +`"a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)"` is REMOVED +from decode.rs and from `refusal_inventory.rs::CAPABILITY_CLAIMS`. **This lift is NOT gated** — +see below. If the next round cannot gate it, restoring both lines is the honest move. + +## Gate (written, never observed a firing attempt) +`stream.rs::uv_mode_in_inter8_gate(bit_depth, tile_columns)` + 3 tests (8-bit, 10-bit, 2-tile): +192x128, 8 frames, mandelbrot zoom + hard cut at frame 4 + seeded `noise`, chroma NOT +desaturated, 30 attempts, cq 12..40, `--min-partition-size=8 --max-partition-size=32 +--sb-size=64 --enable-cfl-intra=1 --enable-smooth-intra=1 --enable-paeth-intra=1 +--enable-directional-intra=1`, per-attempt counter deltas, every decode-order frame compared, +no SKIP on decode error. The y4m goes through a temp FILE: feeding aomenc on stdin while its +~100 KB OBU fills the stdout pipe DEADLOCKS (measured, 3 min into attempt 0). + +RESULT: 8-bit arm ran, 30/30 attempts REFUSED, 0 compared → the gate fails as designed. + +## The blocker (pre-existing, NOT this round's change) +Every `--min-partition-size=8` inter stream refuses. `--min-partition-size=16` on the same +recipe decodes 8/8 frames. The refusals name tools the encoder was explicitly told to disable: +`--enable-rect-partitions=0 --enable-ab-partitions=0 --enable-1to4-partitions=0` yet we refuse +"an inter 16x16-level AB or 1:4 partition" / "a non-skip rectangular strip"; and +`--enable-angle-delta=0` yet we refuse "a nonzero angle delta on an 8x8 intra leaf". Class +[[refusal-from-own-desync]]: those are our own desync, not encoder output. +Ablation: the same refusals appear with `--enable-cfl-intra=0 --enable-smooth-intra=0 +--enable-paeth-intra=0 --enable-directional-intra=0`, where this round's code is inert → +the desync is INDEPENDENT of this round. +The KEY frame of the same recipe (`--limit=1`, min8) decodes PIXEL-EXACT vs aomdec +(md5 860b50e830271fa57fb60e4a76eb83ec both) — so the 8x8 leaf's key-frame path is fine and the +divergence is in an INTER frame. + +## Exact next step +Bisect the first inter-frame divergence with the oracle mode ladder. Note the trace semantics +(cost this round an hour): oracle `EC_IMODE` = KEY-frame blocks only, oracle `EC_MODE` = +INTER blocks only (an intra block inside an inter frame prints NEITHER), while ours prints +`EC_MODE` for EVERY block of an inter frame. So the oracle's `EC_MODE` (mi_row, mi_col) +sequence must be an ordered SUBSEQUENCE of ours; the first ref entry that ours never produces +is the first structurally divergent block. On `~/.cache/uv8-tmp/o.obu` (recipe above, cq 26, +cpu-used 0) that subsequence match stops after 79 of the ref's frame-1 entries, with ref next +at mi (12,8) — start there with a range ladder (compare RANGE, never tell()). +Scripts: `~/.cache/uv8-tmp/{in.y4m,sweep.sh,sweep2.sh,sweep3.sh}`; probe +`$HOME/.cache/cargo-target-uv8/debug/examples/decode_probe [out.yuv]`. diff --git a/lanes/uv8-r2.handoff.md b/lanes/uv8-r2.handoff.md new file mode 100644 index 00000000..5743e12a --- /dev/null +++ b/lanes/uv8-r2.handoff.md @@ -0,0 +1,65 @@ +# lane-uv8 r2 — HANDOFF (merge done, root cause NARROWED to one block, gate still RED) + +## Merged into lane-uv8 (tip f5c8dbf) +- `a9b4468` main aa83400 (clean). +- `5dc9707` lane-interp3 `10b801a` (clean). +- `c3ead8c`/prev `af47324` lane-intersub8 — CONFLICTS resolved: + * `decode_inter_block8` compound-leaf interp read: kept **interp3's** copy (it adds the + `gm_nontrans_c || skip_mode` suppression and the COMPOUND8_FILTER_HITS counter); dropped + intersub8's duplicate read (two reads = one extra symbol). + * `resolve_interp_filter` tail: kept BOTH (interp3's DUAL_FILTER_DIFF_HITS + intersub8's EC_IF trace). + * `refusal_inventory.rs`: union of both lists, then deleted + "an inter partition below 8x8 (...lane-sub8 scoped to intra)" — intersub8 landed that capability + (the `the_decode_path_refuses_exactly_the_listed_cases` test named it). +- `6561ec4` lane-cdef `8c6065e` (clean). +- `c3ead8c` lane-sqdrift `7d498c0` — stream.rs conflict was two whole appended test fns interleaved; + resolved by `git checkout --ours stream.rs` + `patch -p1` of `git diff 85887c7 7d498c0 -- stream.rs` + (both new tests present: `..._reads_the_no_cfl_uv_alphabet`, `..._square_only_inter_sequence...`). +- `crates/ec-av1/src/cdf.rs` byte-identical to main (`git diff --stat main -- cdf.rs` empty). +- `f5c8dbf` adds EC_TRACE_MODE_STEP ladder prints in the 8x8 intra-in-inter arm + (`EC_ISTEP ... name=use_filter_intra` in the oracle's exact format, plus `EC_ISTEP8 name=modes`). + +## Gate result on the merged tree (RED, same shape as r1) +`uv8-gate-r2.log` (unit uv8-gate-r2-1788332583, before the trace commit): all three arms +30/30 named refusals, counted-exact=0, uncounted-exact=0. Re-armed after the merge as unit +**uv8-gate-r2b** → `$HOME/.cache/uv8-gate-r2.log`, then the full suite in the SAME unit → +`$HOME/.cache/uv8-suite-r2.log`. +Refusal histogram over the 90 attempts: 31x inter 16x16-level 1:4, 21x nonzero angle delta on an +8x8 intra leaf, 13x inter 8x8 HORZ, 10x non-skip rect strip, 5x intra 1:4 rect strip, 3x inter SB AB, +3x 128x128 SB HORZ/VERT/AB, 2x intra 4x4 in sub-8x8 split, 1x 32x64 split TU, 1x intra 8x4/4x8. +All still class [[refusal-from-own-desync]] — proven below. + +## ROOT CAUSE LOCALISED (this is the round's real result) +Stream `~/.cache/uv8-tmp/a0.obu` (regenerate: `~/.cache/uv8-tmp/g2.sh 42 12 a0.obu`, exact gate +recipe, 8-bit, seed 42, cq 12; note it is a **128x128 superblock** stream — the gate recipe has no +`--sb-size=64`). +1. `EC_TRACE=1 aomdec` partition histogram (`ref_part.txt`): the reference codes **only** NONE and + SPLIT (bsize 15/12/9 value=3, bsize 6 value 0|3, bsize 3 value 0). There is no rect/AB/1:4 + partition anywhere in the stream → every refusal above is our own desync. +2. Partition range ladder (ours `EC_TRACE_PART=1` vs ref, ignoring the ctx print convention: + ref prints `4*bsl + ctx`): decode-order frame 1 matches 138/138; frame 2 first range divergence + at element 119 — ref `(0,36,bsize=6,rng=48648)` vs ours `rng=38664`. The previous element, + the 8x8 partition at **mi (2,34)**, still matches (rng 44040). +3. `EC_MODE` subsequence: ref's entries are consumed in order up to `(2,32)`; ours' next block + `(0,36)` starts at rng 57984 vs ref 32884. Ref prints no EC_MODE for `(2,34)` → that block is an + **INTRA 8x8 leaf inside inter frame 2**. +4. `EC_TRACE_MODE_STEP` ladder at that block: ours reads `use_filter_intra val=1 rng=64248` and + `filter_intra_mode val=0 rng=43964` — **bit-identical to the oracle**. Our decoded modes there are + `y=DC_PRED, uv=13 (UV_CFL_PRED)` (`EC_ISTEP8` line). + => the whole mode-info half of this leaf, including the new non-DC/CfL uv path, is IN SYNC. + The desync is in what follows: `read_block_tx_size` or the leaf's COEFFICIENTS. + +## EXACT NEXT STEP +Both coefficient traces are already dumped: `~/.cache/uv8-tmp/ref_co.txt` (761992 lines) and +`ours_co.txt` (260655). Formats: ref `EC_COEFF plane=.. row=.. col=.. tx_size=.. rng=..` + +`EC_COEFF_STEP tag=all_zero|tx_type|base|br ...`; ours prints the STEP lines only (no EC_COEFF +header with plane/row/col). Align the two `EC_COEFF_STEP` streams and find the first `rng` +divergence — it must be inside the block at mi (2,34) of decode-order frame 2, i.e. the FIRST +filter-intra + CfL 8x8 intra leaf of an inter frame. Prime suspects, in order: + (a) the CfL AC / chroma `TxbSet::Chroma4` txb ctx on a leaf whose luma is filter-intra; + (b) `read_block_tx_size` for an intra block in an inter frame at 8x8 (`--enable-tx-size-search=0` + here, so check whether a symbol should be read at all); + (c) the luma `intra_ext_tx` row: `read_plane` gets `filter_intra` and applies `fi_tx_row`, but the + CHROMA calls pass `mode` (raw luma mode) as the tx-row arg with `filter_intra=None` — verify + against libaom `av1_read_tx_type` (chroma tx type is inferred, so this should be inert; prove it). +Do NOT re-do steps 1-4; they are pinned above with their artifacts. diff --git a/lanes/uv8-r3.handoff.md b/lanes/uv8-r3.handoff.md new file mode 100644 index 00000000..4cc92107 --- /dev/null +++ b/lanes/uv8-r3.handoff.md @@ -0,0 +1,54 @@ +# lane-uv8 r3 — HANDOFF (GREEN gate; suite still running at the turn cap) + +## ROOT CAUSE (fixed, committed) +`decode_inter_block8`'s INTRA arm passed a hardcoded `TxbSet::Luma8` to `read_plane` for the +8x8 leaf's LUMA transform. `TxbSet::Luma8` is the `reduced_tx_set == 1` alphabet +(`EXT_TX_SET_DTT4_IDTX`, FIVE types). libaom `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) +returns `EXT_TX_SET_DTT4_IDTX_1DDCT` (SEVEN types, `TxbSet::Luma8Set1`) for `is_inter == 0`, +`tx_size_sqr == TX_8X8`, `use_reduced_set == 0` — and an INTRA leaf inside an INTER frame is +`is_inter == 0`. Same symbol value, different narrowing (class [[wrong-alphabet-same-value]]); +the msac range diverged at the leaf's first `tx_type` and desynced the rest of the tile, which +manufactured the 30/30 "named refusals" of r1/r2 (class [[refusal-from-own-desync]]). +FIX: `crates/ec-av1/src/decode.rs:22057` -> `txbset_for(8, reduced_tx_set)` (the parameter was +already in scope). Charter suspects (1) `fimode_to_intradir` and (2) `tx_depth` were BOTH already +correct: `fi_tx_row` is applied at every luma txb call site, `fimode_to_intradir[0] == DC_PRED` +equals this block's y_mode anyway, and `read_block_tx_size` returns depth 0 here. + +## GATE AFTER THE FIX — GREEN (unit uv8-gate-r3, log $HOME/.cache/uv8-gate-r3.log) +`cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture non_dc_chroma_8x8_intra_leaf` +-> 3 passed / 0 failed, 5.53s. Every arm exact on ATTEMPT 0 with all three chroma classes +firing (directional / smooth-paeth / CfL): + 8-bit 1-tile seed42 cq12: 159 / 172 / 211 + 10-bit 1-tile seed42 cq12: 112 / 126 / 120 + 8-bit 2-tile seed42 cq12: 83 / 66 / 80 +buckets on each arm: counted-exact=1 uncounted-exact=0 named-refusals=0 (attempts 1). +All 8 frames of each stream pixel-compared vs ffmpeg (Y/U/V), no mismatch. +`stream.rs:5897` tightened: `counted` now requires ALL THREE classes on the same compared +attempt (was sum-nonzero) — this stricter predicate is what the green run above satisfies. + +## REFUSAL STATE +The lifted non-DC-uv_mode refusal STAYS LIFTED (gate green). Still refused by name and NOT part +of this lane: "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform +units" (decode.rs ~21996) and "a nonzero angle delta on an 8x8 intra leaf in an inter frame". + +## SWEEP (class: hardcoded reduced-set TxbSet) +`grep -n 'TxbSet::Luma\(4\|8\|16\|32\),' crates/ec-av1/src/decode.rs` — after the fix there are +ZERO reduced-sensitive hardcodes outside `txbset_for`/`txbset_for_inter`; every remaining +`Luma16`/`Luma32` literal is alphabet-invariant to `reduced_tx_set`. The rect-strip and >=16 +square intra-in-inter arms already route through `txbset_for` (decode.rs 6053, 7167, 7777, +7857, 9594, 11075). + +## SUITE — RUNNING, NOT VERIFIED +Unit `uv8-gate-r3.service` (still active at the turn cap) is now in its suite phase: +log `$HOME/.cache/uv8-suite-r3.log`. At hand-off: 233 tests `ok`, 0 FAILED, 0 `failures:` lines +(of ~425). NO green suite claim. + +## EXACT NEXT STEP +1. `grep -E "^test result|FAILED|^failures:" $HOME/.cache/uv8-suite-r3.log` once the unit goes + inactive; expect N/0. If a gate reddens, it is a SIBLING of this alphabet fix — re-run it + before touching the fix. +2. Then the lane is mergeable at its tip. + +## EVIDENCE +EVIDENCE: ~/.cache/uv8-tmp/ref.tu + ours3.tu | instrumented aomdec EC_TRACE_COEFF vs our EC_TRACE_COEFF on ~/.cache/uv8-tmp/a0.obu, per-TU (all_zero,eob) msac RANGE ladder | before: first divergence at TU-line 3392 (ref eob rng=32776 vs ours 34568; the preceding tx_type read ref rng=33532 vs ours 35240 at plane=0 tx_size=1, the mi(2,34) filter-intra leaf of decode-order frame 2) — after: 13986/13986 identical over the whole stream, decode_probe rc=0, no refusal +EVIDENCE: $HOME/.cache/uv8-gate-r3.log | the three-arm gate command above | 3 passed / 0 failed, counted-exact=1 named-refusals=0 per arm, counts as listed diff --git a/lanes/uv8-r3.report.md b/lanes/uv8-r3.report.md new file mode 100644 index 00000000..d8b3fc41 --- /dev/null +++ b/lanes/uv8-r3.report.md @@ -0,0 +1,42 @@ +# lane-uv8 r3 — GREEN (root cause: wrong tx_type ALPHABET on the 8x8 intra-in-inter leaf) + +## Root cause +`decode_inter_block8`'s INTRA arm passed a hardcoded `TxbSet::Luma8` to `read_plane` for the +leaf's 8x8 luma transform. `TxbSet::Luma8` is the `reduced_tx_set == 1` set +(`EXT_TX_SET_DTT4_IDTX`, FIVE types); with `reduced_tx_set == 0` libaom's +`av1_get_ext_tx_set_type` (`av1/common/blockd.h`) returns, for `is_inter == 0` and +`tx_size_sqr == TX_8X8`, `EXT_TX_SET_DTT4_IDTX_1DDCT` — SEVEN types +(`TxbSet::Luma8Set1`). Same symbol, different alphabet: the CDF narrowing differed, so the +msac range diverged at the leaf's first `tx_type` and every following block desynced. The +desync manufactured the 30/30 "named refusals" the r1/r2 gate logs showed +(class [[refusal-from-own-desync]] + [[wrong-alphabet-same-value]]). + +Charter suspect (1) (the `fimode_to_intradir` row) was already correct: `fi_tx_row` is applied +at every luma `txb` call site including this one, and `fimode_to_intradir[0] == DC_PRED` +equals this block's `y_mode` anyway, so that row was inert here. + +## Change +- `crates/ec-av1/src/decode.rs:22057` — `TxbSet::Luma8` -> `txbset_for(8, reduced_tx_set)` + (`reduced_tx_set` was already a parameter of `decode_inter_block8`). +- `crates/ec-av1/src/stream.rs:5897` — gate `counted` predicate tightened from + "sum nonzero" to "all three uv classes fired on the same pixel-compared attempt". + +## Sweep (class: hardcoded reduced-set TxbSet) +`grep -n 'TxbSet::Luma\(4\|8\|16\|32\),' decode.rs` — the only reduced-sensitive hardcodes are +sizes 8 and 4; after this fix there are ZERO outside `txbset_for`/`txbset_for_inter`. Every +`Luma16`/`Luma32` literal is alphabet-invariant to `reduced_tx_set` (`txbset_for` maps 16 and +32 identically for both values). The rect-strip and >=16 square intra-in-inter arms already go +through `txbset_for`/`txbset_for_inter` (decode.rs:6053, 7167, 7777, 7857, 9594, 11075). + +## EVIDENCE +EVIDENCE: ~/.cache/uv8-tmp/ref.tu + ours3.tu | aomdec EC_TRACE_COEFF vs our EC_TRACE_COEFF on ~/.cache/uv8-tmp/a0.obu, per-TU (all_zero,eob) msac range ladder | before: first divergence at TU-line 3392 (ref eob rng=32776, ours 34568; the preceding tx_type read was ref rng=33532 vs ours 35240 at plane=0 tx_size=1, the mi(2,34) filter-intra leaf of decode-order frame 2) — after: 13986/13986 lines identical, whole stream, decode_probe rc=0 with no refusal +EVIDENCE: $HOME/.cache/uv8-gate-r3.log | `cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture non_dc_chroma_8x8_intra_leaf` | 3 passed / 0 failed; every arm exact on attempt 0 with all three classes firing — 8bit/1tile dir 159 smooth-paeth 172 cfl 211; 10bit/1tile 112/126/120; 8bit/2tile 83/66/80; buckets counted-exact=1 uncounted-exact=0 named-refusals=0 on each + +## Residue +- deferred: the 8x8 intra-in-inter leaf whose `tx_depth` splits to four TX_4X4 units is still + refused by name (decode.rs ~21996). Unblocked by an arm with `--enable-tx-size-search=1` + plus a 4x4-TU prediction loop in this leaf path — out of this lane's charter, which fixed the + depth-0 alphabet. Its refusal string stays in refusal_inventory.rs. +- accepted: `frames` from `decode_stream` is decode order; the gate recipe has + `--lag-in-frames=0 --auto-alt-ref=0`, so decode order == display order and all 8 frames are + compared (class [[gate-blind-to-hidden-frames]] does not apply).