diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 7d79a414..6b3be148 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -45,6 +45,7 @@ fn main() { println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits()); println!("gm_nontrans_small_side: {}", ec_av1::decode::gm_nontrans_small_side_hits()); + println!("tr_reach_longer_side: {}", ec_av1::decode::tr_reach_longer_side_hits()); let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); let si = ec_av1::stream::sub8_intra_rect_hits(); diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 4be0fd24..7278fcfc 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2134,6 +2134,19 @@ pub(crate) fn affine_gm_hits() -> usize { AFFINE_GM_HITS.with(|c| c.get()) } +// lane-t900 r9: rect blocks whose warp-sample top-right probe answers +// differently at the block's WIDTH than at libaom's +// `AOMMAX(xd->width, xd->height)` -- each one is a `num_proj_ref` that could +// pick the wrong motion_mode alphabet. +thread_local! { + static TR_REACH_LONGER_SIDE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`TR_REACH_LONGER_SIDE_HITS`]. +pub fn tr_reach_longer_side_hits() -> usize { + TR_REACH_LONGER_SIDE_HITS.with(std::cell::Cell::get) +} + // lane-t900 r9: libaom `is_nontrans_global_motion` (mvref_common.h) returns 0 // for `AOMMIN(mi_size_wide[bsize], mi_size_high[bsize]) < 2`, i.e. any block // with a 4-px side is NEVER "non-translational global" and therefore ALWAYS @@ -18859,7 +18872,22 @@ fn find_samples( let up_available = mi_row > 0; let left_available = mi_col > 0; let mut samples = Vec::with_capacity(MAX); - let single_ref_match = |info: &MiInfo| info.ref_frame == ref_frame && info.ref_frame1.is_none(); + // lane-t900 r9: `EC_PROJ_MI=,` lists this block's warp + // sample candidates in libaom's own order (above, left, top-left, + // top-right) -- `num_proj_ref >= 1` is what picks the 3-symbol + // motion_mode alphabet over the 2-symbol obmc one. + let proj_dbg = std::env::var("EC_PROJ_MI") + .is_ok_and(|v| v == format!("{mi_row},{mi_col}")); + let single_ref_match = |info: &MiInfo| { + let m = info.ref_frame == ref_frame && info.ref_frame1.is_none(); + if proj_dbg { + eprintln!( + "EC_PROJ cand ref={} ref1={:?} size={} size_h={} is_inter={} want={ref_frame} match={m}", + info.ref_frame, info.ref_frame1, info.size, info.size_h, info.is_inter + ); + } + m + }; let mut do_tl = true; let mut do_tr = true; let rec = |info: &MiInfo, row_offset: i32, sign_r: i32, col_offset: i32, sign_c: i32| { @@ -18956,7 +18984,18 @@ fn find_samples( } } - if do_tr && has_top_right(mi_row, mi_col, bw4) { + // lane-t900 r9: libaom passes `AOMMAX(xd->width, xd->height)` here + // (`mvref_common.c:1235`), NOT the block's width -- a rect block's + // top-right reach is probed at its LONGER side. With `bw4` a 64x128 + // block found a top-right sample libaom never sees, so + // `num_proj_ref >= 1` picked the 3-symbol `motion_mode_cdf` where + // libaom reads the 2-symbol `obmc_cdf` (class + // wrong-alphabet-same-value). + let tr_reach = has_top_right(mi_row, mi_col, bw4.max(bh4)); + if do_tr && bw4 != bh4 && tr_reach != has_top_right(mi_row, mi_col, bw4) { + TR_REACH_LONGER_SIDE_HITS.with(|c| c.set(c.get() + 1)); + } + if do_tr && tr_reach { let tr_col = mi_col + bw4; if mi_row > 0 && tr_col < mi_cols { if let Some(info) = grid.get(mi_row - 1, tr_col) { @@ -21652,6 +21691,24 @@ fn decode_inter_block( // mv reads no motion_mode/obmc symbol at all -- implicit // SIMPLE_TRANSLATION. && !(is_global_mv_block && !force_integer_mv); + // lane-t900 r9: the eligibility terms themselves, on the same rung + // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility + // mismatch is otherwise invisible (a skipped symbol prints + // nothing). + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \ + ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}", + motion_mode_eligible as u8, + overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).len(), + overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1).len(), + switchable_motion_mode as u8, + skip_mode as u8, + interintra_mode.is_some() as u8, + is_global_mv_block as u8, + dec.debug_state().0, + ); + } let mut obmc_selected = false; // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL // *and* the local warp estimate is valid (`!wm_params.invalid`, @@ -21811,6 +21868,22 @@ fn decode_inter_block( OBMC_HITS.with(|c| c.set(c.get() + 1)); } } + // lane-t900 r9: which ALPHABET this block read (3-symbol + // motion_mode vs 2-symbol obmc) and the range after -- the + // two give the same value with a different narrowing (class + // wrong-alphabet-same-value). + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { + eprintln!( + "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \ + scaled={} fimv={} obmc={} warped={} rng={}", + warp_eligible as u8, + ref_is_scaled as u8, + force_integer_mv as u8, + obmc_selected as u8, + warped_selected as u8, + dec.debug_state().0, + ); + } } // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index cd9fe14b..9f0384ab 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -690,6 +690,33 @@ pub fn decode_stream(data: &[u8]) -> Result> { let started_from = initial_cdfs.clone(); // lane-frame80: narrow the EC_TRACE_COEFF rungs to one DECODE-order frame. decode::set_coeff_trace_frame(pictures_decoded); + // lane-t900 r9: one line per DECODE-order frame naming the header + // fields a desync cliff is usually keyed on (frame type, base q, + // primary_ref, the 7 ref slots, refresh mask, order hints). + if std::env::var_os("EC_PROBE_HDR").is_some() { + eprintln!( + "EC_HDR decode_idx={pictures_decoded} type={:?} show={} show_existing={} base_q={} primary_ref={} ref_idx={:?} refresh=0x{:02x} order_hint={} tiles={}x{} txmode={:?} interp={:?} reduced_tx={} allow_warp={} switchable_mo={} ref_mvs={} skip_mode={} cdef={:?} lr={:?}", + header.frame_type, + header.show_frame, + header.show_existing_frame, + header.quantization.base_q_idx, + header.primary_ref_frame, + header.ref_frame_idx, + header.refresh_frame_flags, + header.order_hint, + header.tile_info.cols, + header.tile_info.rows, + header.tx_mode, + header.interpolation_filter, + header.reduced_tx_set, + header.allow_warped_motion, + header.is_motion_mode_switchable, + header.use_ref_frame_mvs, + header.skip_mode_present, + header.cdef.bits, + header.loop_restoration.frame_restoration_type, + ); + } let order_hint_bits = parser .sequence_header()