The warp-sample top-right probe uses the block's LONGER side, plus EC_MM/EC_MM2/EC_PROJ/EC_PROBE_HDR rungs
Browse files at this commit864b5c62807d02a7a7fcacc625f6b4dd45e32a44Parent: defe73a- fix
- the warp-sample top-right probe uses the block's LONGER side, plus EC_MM/EC_MM2/EC_PROJ/EC_PROBE_HDR rungs
3 changed files +103 -2
- crates/ec-av1/examples/decode_probe.rs +1 -0
- crates/ec-av1/src/decode.rs +75 -2
- crates/ec-av1/src/stream.rs +27 -0
crates/ec-av1/examples/decode_probe.rsmodified+1 -0
| @@ -45,6 +45,7 @@ fn main() { | ||
| 45 | 45 | println!("sub8_inter_split: groups={}", ec_av1::decode::sub8_inter_split_hits()); |
| 46 | 46 | println!("interintra_rect: {}", ec_av1::decode::interintra_rect_hits()); |
| 47 | 47 | println!("gm_nontrans_small_side: {}", ec_av1::decode::gm_nontrans_small_side_hits()); |
| 48 | + println!("tr_reach_longer_side: {}", ec_av1::decode::tr_reach_longer_side_hits()); | |
| 48 | 49 | let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits(); |
| 49 | 50 | println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}"); |
| 50 | 51 | let si = ec_av1::stream::sub8_intra_rect_hits(); |
crates/ec-av1/src/decode.rsmodified+75 -2
| @@ -2134,6 +2134,19 @@ pub(crate) fn affine_gm_hits() -> usize { | ||
| 2134 | 2134 | AFFINE_GM_HITS.with(|c| c.get()) |
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | +// lane-t900 r9: rect blocks whose warp-sample top-right probe answers | |
| 2138 | +// differently at the block's WIDTH than at libaom's | |
| 2139 | +// `AOMMAX(xd->width, xd->height)` -- each one is a `num_proj_ref` that could | |
| 2140 | +// pick the wrong motion_mode alphabet. | |
| 2141 | +thread_local! { | |
| 2142 | + static TR_REACH_LONGER_SIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 2143 | +} | |
| 2144 | + | |
| 2145 | +/// Current value of [`TR_REACH_LONGER_SIDE_HITS`]. | |
| 2146 | +pub fn tr_reach_longer_side_hits() -> usize { | |
| 2147 | + TR_REACH_LONGER_SIDE_HITS.with(std::cell::Cell::get) | |
| 2148 | +} | |
| 2149 | + | |
| 2137 | 2150 | // lane-t900 r9: libaom `is_nontrans_global_motion` (mvref_common.h) returns 0 |
| 2138 | 2151 | // for `AOMMIN(mi_size_wide[bsize], mi_size_high[bsize]) < 2`, i.e. any block |
| 2139 | 2152 | // with a 4-px side is NEVER "non-translational global" and therefore ALWAYS |
| @@ -18859,7 +18872,22 @@ fn find_samples( | ||
| 18859 | 18872 | let up_available = mi_row > 0; |
| 18860 | 18873 | let left_available = mi_col > 0; |
| 18861 | 18874 | let mut samples = Vec::with_capacity(MAX); |
| 18862 | - let single_ref_match = |info: &MiInfo| info.ref_frame == ref_frame && info.ref_frame1.is_none(); | |
| 18875 | + // lane-t900 r9: `EC_PROJ_MI=<mi_row>,<mi_col>` lists this block's warp | |
| 18876 | + // sample candidates in libaom's own order (above, left, top-left, | |
| 18877 | + // top-right) -- `num_proj_ref >= 1` is what picks the 3-symbol | |
| 18878 | + // motion_mode alphabet over the 2-symbol obmc one. | |
| 18879 | + let proj_dbg = std::env::var("EC_PROJ_MI") | |
| 18880 | + .is_ok_and(|v| v == format!("{mi_row},{mi_col}")); | |
| 18881 | + let single_ref_match = |info: &MiInfo| { | |
| 18882 | + let m = info.ref_frame == ref_frame && info.ref_frame1.is_none(); | |
| 18883 | + if proj_dbg { | |
| 18884 | + eprintln!( | |
| 18885 | + "EC_PROJ cand ref={} ref1={:?} size={} size_h={} is_inter={} want={ref_frame} match={m}", | |
| 18886 | + info.ref_frame, info.ref_frame1, info.size, info.size_h, info.is_inter | |
| 18887 | + ); | |
| 18888 | + } | |
| 18889 | + m | |
| 18890 | + }; | |
| 18863 | 18891 | let mut do_tl = true; |
| 18864 | 18892 | let mut do_tr = true; |
| 18865 | 18893 | let rec = |info: &MiInfo, row_offset: i32, sign_r: i32, col_offset: i32, sign_c: i32| { |
| @@ -18956,7 +18984,18 @@ fn find_samples( | ||
| 18956 | 18984 | } |
| 18957 | 18985 | } |
| 18958 | 18986 | |
| 18959 | - if do_tr && has_top_right(mi_row, mi_col, bw4) { | |
| 18987 | + // lane-t900 r9: libaom passes `AOMMAX(xd->width, xd->height)` here | |
| 18988 | + // (`mvref_common.c:1235`), NOT the block's width -- a rect block's | |
| 18989 | + // top-right reach is probed at its LONGER side. With `bw4` a 64x128 | |
| 18990 | + // block found a top-right sample libaom never sees, so | |
| 18991 | + // `num_proj_ref >= 1` picked the 3-symbol `motion_mode_cdf` where | |
| 18992 | + // libaom reads the 2-symbol `obmc_cdf` (class | |
| 18993 | + // wrong-alphabet-same-value). | |
| 18994 | + let tr_reach = has_top_right(mi_row, mi_col, bw4.max(bh4)); | |
| 18995 | + if do_tr && bw4 != bh4 && tr_reach != has_top_right(mi_row, mi_col, bw4) { | |
| 18996 | + TR_REACH_LONGER_SIDE_HITS.with(|c| c.set(c.get() + 1)); | |
| 18997 | + } | |
| 18998 | + if do_tr && tr_reach { | |
| 18960 | 18999 | let tr_col = mi_col + bw4; |
| 18961 | 19000 | if mi_row > 0 && tr_col < mi_cols { |
| 18962 | 19001 | if let Some(info) = grid.get(mi_row - 1, tr_col) { |
| @@ -21652,6 +21691,24 @@ fn decode_inter_block( | ||
| 21652 | 21691 | // mv reads no motion_mode/obmc symbol at all -- implicit |
| 21653 | 21692 | // SIMPLE_TRANSLATION. |
| 21654 | 21693 | && !(is_global_mv_block && !force_integer_mv); |
| 21694 | + // lane-t900 r9: the eligibility terms themselves, on the same rung | |
| 21695 | + // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility | |
| 21696 | + // mismatch is otherwise invisible (a skipped symbol prints | |
| 21697 | + // nothing). | |
| 21698 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | |
| 21699 | + eprintln!( | |
| 21700 | + "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \ | |
| 21701 | + ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}", | |
| 21702 | + motion_mode_eligible as u8, | |
| 21703 | + overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).len(), | |
| 21704 | + overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1).len(), | |
| 21705 | + switchable_motion_mode as u8, | |
| 21706 | + skip_mode as u8, | |
| 21707 | + interintra_mode.is_some() as u8, | |
| 21708 | + is_global_mv_block as u8, | |
| 21709 | + dec.debug_state().0, | |
| 21710 | + ); | |
| 21711 | + } | |
| 21655 | 21712 | let mut obmc_selected = false; |
| 21656 | 21713 | // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL |
| 21657 | 21714 | // *and* the local warp estimate is valid (`!wm_params.invalid`, |
| @@ -21811,6 +21868,22 @@ fn decode_inter_block( | ||
| 21811 | 21868 | OBMC_HITS.with(|c| c.set(c.get() + 1)); |
| 21812 | 21869 | } |
| 21813 | 21870 | } |
| 21871 | + // lane-t900 r9: which ALPHABET this block read (3-symbol | |
| 21872 | + // motion_mode vs 2-symbol obmc) and the range after -- the | |
| 21873 | + // two give the same value with a different narrowing (class | |
| 21874 | + // wrong-alphabet-same-value). | |
| 21875 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | |
| 21876 | + eprintln!( | |
| 21877 | + "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \ | |
| 21878 | + scaled={} fimv={} obmc={} warped={} rng={}", | |
| 21879 | + warp_eligible as u8, | |
| 21880 | + ref_is_scaled as u8, | |
| 21881 | + force_integer_mv as u8, | |
| 21882 | + obmc_selected as u8, | |
| 21883 | + warped_selected as u8, | |
| 21884 | + dec.debug_state().0, | |
| 21885 | + ); | |
| 21886 | + } | |
| 21814 | 21887 | } |
| 21815 | 21888 | // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch |
| 21816 | 21889 | // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- |
crates/ec-av1/src/stream.rsmodified+27 -0
| @@ -690,6 +690,33 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 690 | 690 | let started_from = initial_cdfs.clone(); |
| 691 | 691 | // lane-frame80: narrow the EC_TRACE_COEFF rungs to one DECODE-order frame. |
| 692 | 692 | decode::set_coeff_trace_frame(pictures_decoded); |
| 693 | + // lane-t900 r9: one line per DECODE-order frame naming the header | |
| 694 | + // fields a desync cliff is usually keyed on (frame type, base q, | |
| 695 | + // primary_ref, the 7 ref slots, refresh mask, order hints). | |
| 696 | + if std::env::var_os("EC_PROBE_HDR").is_some() { | |
| 697 | + eprintln!( | |
| 698 | + "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={:?}", | |
| 699 | + header.frame_type, | |
| 700 | + header.show_frame, | |
| 701 | + header.show_existing_frame, | |
| 702 | + header.quantization.base_q_idx, | |
| 703 | + header.primary_ref_frame, | |
| 704 | + header.ref_frame_idx, | |
| 705 | + header.refresh_frame_flags, | |
| 706 | + header.order_hint, | |
| 707 | + header.tile_info.cols, | |
| 708 | + header.tile_info.rows, | |
| 709 | + header.tx_mode, | |
| 710 | + header.interpolation_filter, | |
| 711 | + header.reduced_tx_set, | |
| 712 | + header.allow_warped_motion, | |
| 713 | + header.is_motion_mode_switchable, | |
| 714 | + header.use_ref_frame_mvs, | |
| 715 | + header.skip_mode_present, | |
| 716 | + header.cdef.bits, | |
| 717 | + header.loop_restoration.frame_restoration_type, | |
| 718 | + ); | |
| 719 | + } | |
| 693 | 720 | |
| 694 | 721 | let order_hint_bits = parser |
| 695 | 722 | .sequence_header() |