From 123515aacdd89bc83fbe577f7d19015b2189da56 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 07:42:35 +0300 Subject: [PATCH] fix(av1): compound MV stack was missing libaom's three tpl_sample_pos extension samples `find_mv_stack_compound` ported the temporal (`add_tpl_ref_mv`) row/col scan but dropped the three EXTENSION samples the single-ref twin already carries (mvref_common.c:590-600, `allow_extension` + `check_sb_border`). On the 192x80 cq59 frame-edge stream that cost one weight-2 candidate at mi(16,32) picture 2: our stack came out 2 deep where libaom's is 3, so the NEAR_NEARMV block never read its `drl_mode` symbol -- one bit short, and every later symbol in the tile read from the wrong place (a 32-level edge bit then resolved HORZ where libaom split, 130 wrong pixels). Range ladder after the fix is exact through the block: post-refs stack 3 == 3 with identical entries/weights, post-mv rng 39839 == libaom EC_MODE_MV 39839, next block entry 62618 == 62618, and all 48 of our EC_MODE block-entry ranges on the cq35 stream match aomdec's. Same hunk as lane-sb128 d6cca7d (independent lane, same root cause). --- crates/ec-av1/src/mvstack.rs | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 8c0fd438..5fe3ad33 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -1623,6 +1623,47 @@ pub fn find_mv_stack_compound( } blk_row += step_h; } + // lane-sb128 r3: libaom's three `tpl_sample_pos` EXTENSION samples + // (mvref_common.c:591), which the single-ref twin already ports and + // this compound path dropped. `check_sb_border`'s mask is libaom's + // hardcoded `mi_size_wide[BLOCK_64X64]` (16), NOT the sequence's + // superblock size. Missing them cost one weight-2 vote on a + // candidate, which reordered the stack and gave a NEW_NEWMV block a + // different predictor -- 957 wrong pixels on one 32x32 block of one + // frame with the entropy stream in sync. + let allow_extension = (2..16).contains(&bh4) && (2..16).contains(&bw4); + if allow_extension { + let (voffset, hoffset) = (bh4.max(2) as isize, bw4.max(2) as isize); + let sb_mask = 16isize; + for (row_off, col_off) in [ + (voffset, -2isize), + (voffset, hoffset), + (voffset - 2, hoffset), + ] { + let row = (mi_row as isize & (sb_mask - 1)) + row_off; + let col = (mi_col as isize & (sb_mask - 1)) + col_off; + if row < 0 || row >= sb_mask || col < 0 || col >= sb_mask { + continue; + } + let cand0 = crate::motion_field::add_tpl_ref_mv( + field, mi_row, mi_col, row_off, col_off, cur_offset_0, + allow_high_precision_mv, + ); + let cand1 = crate::motion_field::add_tpl_ref_mv( + field, mi_row, mi_col, row_off, col_off, cur_offset_1, + allow_high_precision_mv, + ); + if cand0.is_some() || cand1.is_some() { + any_hit = true; + add_compound_candidate( + &mut candidates, + cand0.map_or((0, 0), |c| c.mv), + cand1.map_or((0, 0), |c| c.mv), + 2, + ); + } + } + } if any_hit { TMV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); }