forge
Explore
Log in

Don't you dare go Hollow

Compound MV stack was missing libaom's three tpl_sample_pos extension samples

Browse files at this commit

123515aacdd89bc83fbe577f7d19015b2189da56Ahmet Kaan GümüşParent: 6f3b424
  • fix
    • compound MV stack was missing libaom's three tpl_sample_pos extension samples
Show full message
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.rsmodified+41 -0
@@ -1623,6 +1623,47 @@ pub fn find_mv_stack_compound(
16231623 }
16241624 blk_row += step_h;
16251625 }
1626+ // lane-sb128 r3: libaom's three `tpl_sample_pos` EXTENSION samples
1627+ // (mvref_common.c:591), which the single-ref twin already ports and
1628+ // this compound path dropped. `check_sb_border`'s mask is libaom's
1629+ // hardcoded `mi_size_wide[BLOCK_64X64]` (16), NOT the sequence's
1630+ // superblock size. Missing them cost one weight-2 vote on a
1631+ // candidate, which reordered the stack and gave a NEW_NEWMV block a
1632+ // different predictor -- 957 wrong pixels on one 32x32 block of one
1633+ // frame with the entropy stream in sync.
1634+ let allow_extension = (2..16).contains(&bh4) && (2..16).contains(&bw4);
1635+ if allow_extension {
1636+ let (voffset, hoffset) = (bh4.max(2) as isize, bw4.max(2) as isize);
1637+ let sb_mask = 16isize;
1638+ for (row_off, col_off) in [
1639+ (voffset, -2isize),
1640+ (voffset, hoffset),
1641+ (voffset - 2, hoffset),
1642+ ] {
1643+ let row = (mi_row as isize & (sb_mask - 1)) + row_off;
1644+ let col = (mi_col as isize & (sb_mask - 1)) + col_off;
1645+ if row < 0 || row >= sb_mask || col < 0 || col >= sb_mask {
1646+ continue;
1647+ }
1648+ let cand0 = crate::motion_field::add_tpl_ref_mv(
1649+ field, mi_row, mi_col, row_off, col_off, cur_offset_0,
1650+ allow_high_precision_mv,
1651+ );
1652+ let cand1 = crate::motion_field::add_tpl_ref_mv(
1653+ field, mi_row, mi_col, row_off, col_off, cur_offset_1,
1654+ allow_high_precision_mv,
1655+ );
1656+ if cand0.is_some() || cand1.is_some() {
1657+ any_hit = true;
1658+ add_compound_candidate(
1659+ &mut candidates,
1660+ cand0.map_or((0, 0), |c| c.mv),
1661+ cand1.map_or((0, 0), |c| c.mv),
1662+ 2,
1663+ );
1664+ }
1665+ }
1666+ }
16261667 if any_hit {
16271668 TMV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
16281669 }