From defe73ab89e261c05485605a743be091e8ceaed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 23:16:59 +0300 Subject: [PATCH] fix(av1): a GLOBALMV block with a 4-px side must still read its interp filter libaom `is_nontrans_global_motion` (mvref_common.h) returns 0 at `AOMMIN(mi_size_wide[bsize], mi_size_high[bsize]) < 2` BEFORE it looks at any global-motion model, so no block with a 4-px side is ever "non-translational global" and `av1_is_interp_needed` never suppresses its interp-filter symbol. Our two sub-8x8 readers (quad-4x4 and the 4x8/8x4 rect pair) and the compound arm of decode_inter_block computed `gm_nontrans` from the model alone and skipped that symbol -- a one-symbol entropy desync at the block, before any coefficient. The single-ref arm of decode_inter_block already carried the guard; the 8x8-leaf reader cannot hit it (min side 2). Counter `gm_nontrans_small_side_hits()` counts only the blocks where the guard flips our answer (printed by decode_probe). Measured on the 10-bit 3840x1608 head cut (170 decode frames), coefficient ladder vs aomdec (tags all_zero/eob/after_bases + rng): decode frame 99 was DIFF at element 11933 (we read txfm_split where aomdec read interp: our rng 60039 vs 46640 at block mi(40,637), the second 4x8 of a vertical sub-8x8 group, GLOBALMV ref0=5); it is now element-exact over all 69065 elements. Counter fires 109 times on that cut. --- crates/ec-av1/examples/decode_probe.rs | 1 + crates/ec-av1/src/decode.rs | 43 ++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index bdee65a7..7d79a414 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -44,6 +44,7 @@ fn main() { println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}"); 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()); 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 a016066f..4be0fd24 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2134,6 +2134,22 @@ pub(crate) fn affine_gm_hits() -> usize { AFFINE_GM_HITS.with(|c| c.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 +// reads its interp-filter symbol. Counts the blocks where that guard flips +// our answer -- a GLOBALMV/GLOBAL_GLOBALMV block with a non-TRANSLATION model +// and a 4-px side, which we used to suppress the interp read on (a pre-mode +// entropy desync one symbol wide). +thread_local! { + static GM_NONTRANS_SMALL_SIDE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`GM_NONTRANS_SMALL_SIDE_HITS`]. +pub fn gm_nontrans_small_side_hits() -> usize { + GM_NONTRANS_SMALL_SIDE_HITS.with(std::cell::Cell::get) +} + // lane-gmaffine r1: 8x8-leaf-only counters -- how many `BLOCK_8X8` leaves // coded `GLOBALMV` (`GLOBALMV_HITS_8`) and how many built a real // `WARPED_CAUSAL` local-warp prediction there (`WARP_HITS_8`, incremented @@ -20276,9 +20292,16 @@ fn decode_inter_block( // spec `is_nontrans_global_motion`: ALL active refs' models must // be non-TRANSLATION (IDENTITY counts) for the compound block's // interp-filter read to be suppressed. - let gm_nontrans = is_globalmv + let gm_nontrans_models = is_globalmv && 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; + // lane-t900 r9: `is_nontrans_global_motion` bails at + // `AOMMIN(mi_size_wide, mi_size_high) < 2` before it looks at any + // model, so a 4-px-sided block still reads its interp filter. + let gm_nontrans = gm_nontrans_models && bw4.min(bh4) >= 2; + if gm_nontrans_models && !gm_nontrans { + GM_NONTRANS_SMALL_SIDE_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)?; // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is @@ -23645,7 +23668,14 @@ fn decode_inter_sub8_split4( neighbours.left_filter[rmi], ); } - let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + // lane-t900 r9: this reader's sub-blocks have a 4-px side, and libaom + // `is_nontrans_global_motion` returns 0 for + // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model -- + // so a GLOBALMV sub-block here always reads its interp filter. + if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation { + GM_NONTRANS_SMALL_SIDE_HITS.with(|c| c.set(c.get() + 1)); + } + let gm_nontrans = false; let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( dec, cdfs, @@ -24571,7 +24601,14 @@ fn decode_inter_sub8_rect2( } else { [3, 3] }; - let gm_nontrans = is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + // lane-t900 r9: this reader's sub-blocks have a 4-px side, and libaom + // `is_nontrans_global_motion` returns 0 for + // `AOMMIN(mi_size_wide, mi_size_high) < 2` BEFORE testing any model -- + // so a GLOBALMV sub-block here always reads its interp filter. + if is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation { + GM_NONTRANS_SMALL_SIDE_HITS.with(|c| c.set(c.get() + 1)); + } + let gm_nontrans = false; let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( dec, cdfs,