forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1-interdesync': corner-only matches raise new_mv_ctx

Browse files at this commit

c47074ad3e4e8d3ccfbe57603d5a27980431a1ccAhmet Kaan GümüşParent: af95500d5bf53b
Closes the I8 verifier's CLASS B real-content inter desync at aligned sizes.
crates/ec-av1/src/mvstack.rsmodified+46 -15
@@ -13,23 +13,29 @@
13 //! clamping (7.10.2.14, libaom's `clamp_mv_ref`).13 //! clamping (7.10.2.14, libaom's `clamp_mv_ref`).
14 //!14 //!
15 //! This module's immediate row/col/top-right scan alone is *not* enough to15 //! This module's immediate row/col/top-right scan alone is *not* enough to
16-//! get `RefMvContext` (`ref_mv_ctx`) right, even though it *is* enough for16+//! get `RefMvContext` (`ref_mv_ctx`) right, *nor* `NewMvContext` at
17-//! `NewMvContext`/`ZeroMvContext`. Ported straight from libaom's17+//! `nearest_match == 0` (see below). Ported straight from libaom's
18 //! `av1_find_mv_stack` (`av1/common/mvref_common.c`, `setup_ref_mv_list`,18 //! `av1_find_mv_stack` (`av1/common/mvref_common.c`, `setup_ref_mv_list`,
19 //! ~line 480 on): after the immediate row (-1), col (-1) and top-right19 //! ~line 480 on): after the immediate row (-1), col (-1) and top-right
20 //! probes settle `nearest_match` (and `mode_context`'s `new_mv` bits, which20 //! probes settle `nearest_match` (and `mode_context`'s `new_mv` bits, which
21-//! depend on `nearest_match` alone), libaom runs one more probe *before*21+//! for `nearest_match >= 1` depend on `nearest_match` alone), libaom runs one
22-//! computing `ref_match_count` — `scan_blk_mbmi` at the diagonal top-left22+//! more probe *before* computing `ref_match_count` — `scan_blk_mbmi` at the
23-//! corner `(-1, -1)` — whose match folds into `row_match_count` (and hence23+//! diagonal top-left corner `(-1, -1)` — whose match folds into
24-//! can flip `ref_match_count`'s row term true) without ever touching the24+//! `row_match_count` (and hence can flip `ref_match_count`'s row term true)
25-//! already-captured `nearest_match`. So `ref_match_count >= nearest_match`25+//! without ever touching the already-captured `nearest_match`. So
26-//! always, sometimes strictly greater, and `ref_mv_ctx` (the `REFMV_OFFSET`26+//! `ref_match_count >= nearest_match` always, sometimes strictly greater, and
27-//! half of libaom's `mode_context` switch, mvref_common.c ~line 619-643)27+//! `ref_mv_ctx` (the `REFMV_OFFSET` half of libaom's `mode_context` switch,
28-//! genuinely depends on both counts, not `nearest_match` alone — that28+//! mvref_common.c ~line 619-643) genuinely depends on both counts, not
29-//! collapse was the bug this module shipped with for several rounds (see29+//! `nearest_match` alone — that collapse was the bug this module shipped
30-//! the crate report). [`find_mv_stack`] now runs that corner probe and30+//! with for several rounds (see the crate report). The `case 0` arm of that
31-//! computes `ref_mv_ctx` from the true `(nearest_match, ref_match_count)`31+//! same switch *also* sets `new_mv_ctx`'s own bit from `ref_match_count`
32-//! pair.32+//! (`mode_context[ref_frame] |= 1` when `ref_match_count >= 1`) — a second
33+//! corner-probe dependency this module missed for several more rounds after
34+//! the first fix, until real-content inter streams (I8 CLASS B) caught it:
35+//! synthetic fixtures never produced a block with `nearest_match == 0` and a
36+//! genuine corner match. [`find_mv_stack`] now runs that corner probe and
37+//! computes both `ref_mv_ctx` and `new_mv_ctx` from the true
38+//! `(nearest_match, ref_match_count)` pair.
33 //!39 //!
34 //! The corner probe's own candidate is added to the stack too (matching40 //! The corner probe's own candidate is added to the stack too (matching
35 //! libaom: a genuinely new MV there becomes a real, if low-weight, entry),41 //! libaom: a genuinely new MV there becomes a real, if low-weight, entry),
@@ -434,7 +440,12 @@ pub fn find_mv_stack(
434 // `newmv_count` alone — libaom's switch never reads `ref_match_count`440 // `newmv_count` alone — libaom's switch never reads `ref_match_count`
435 // for those bits, so this half was already exact before this round.441 // for those bits, so this half was already exact before this round.
436 let new_mv_ctx = match nearest_match {442 let new_mv_ctx = match nearest_match {
437- 0 => 0,443+ // libaom's `case 0` also sets this bit from `ref_match_count`
444+ // (`mode_context[ref_frame] |= 1` when `ref_match_count >= 1`,
445+ // mvref_common.c ~line 621) — the corner-probe-derived count, not
446+ // `nearest_match` alone, despite this module's doc comment above
447+ // having claimed the opposite for several rounds.
448+ 0 => usize::from(ref_match_count >= 1),
438 1 => {449 1 => {
439 if newmv_count > 0 {450 if newmv_count > 0 {
440 2451 2
@@ -706,6 +717,26 @@ mod tests {
706 assert_eq!(stack.drl_ctx, vec![1]);717 assert_eq!(stack.drl_ctx, vec![1]);
707 }718 }
708 719
720+ #[test]
721+ fn a_corner_only_match_raises_new_mv_ctx_even_when_nearest_match_is_zero() {
722+ // Block at (2, 2), 1x1 mi unit: row above (1, 2), col left (2, 1)
723+ // and top-right (1, 3) all empty — nearest_match == 0 — but the
724+ // diagonal top-left corner (1, 1) matches. libaom's `case 0` arm
725+ // (mvref_common.c ~line 621) sets `new_mv_ctx`'s own bit from
726+ // `ref_match_count` here, not just `ref_mv_ctx`'s: this is I8 CLASS
727+ // B's real-content bitstream desync (real clips hit blocks whose
728+ // *only* neighbour match is diagonal; the repo's synthetic tests
729+ // never had one until this case).
730+ let mut grid = MiGrid::new(8, 8);
731+ grid.set(1, 1, inter((4, 4)));
732+
733+ let stack = find_mv_stack(&grid, 2, 2, 1, 1, 1, 8, 8);
734+
735+ assert_eq!(stack.entries.len(), 1);
736+ assert_eq!(stack.new_mv_ctx, 1); // ref_match_count == 1, not the old hard-0
737+ assert_eq!(stack.ref_mv_ctx, 1); // nearest_match=0, ref_match_count=1
738+ }
739+
709 #[test]740 #[test]
710 fn single_ref_ctx_matches_libaoms_collapsed_forward_only_case() {741 fn single_ref_ctx_matches_libaoms_collapsed_forward_only_case() {
711 assert_eq!(single_ref_ctx(false), 1);742 assert_eq!(single_ref_ctx(false), 1);