From 71acae1e958707d6837a91a76d93dd919a4dec8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 12 Sep 2026 20:33:28 +0300 Subject: [PATCH] =?UTF-8?q?ec-vp8=20M3:=20census=20merge=20fix=20=E2=80=94?= =?UTF-8?q?=20above-left=20third-candidate=20merge=20is=20ALIVE=20in=20lib?= =?UTF-8?q?vpx,=20mode=20records=20now=20agree=20read-for-read=20for=20all?= =?UTF-8?q?=2060=20MBs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The predecessor's 'dead in libvpx too' note about the cnt[CNT_SPLITMV] merge was a misread: when the above-left pushes a THIRD distinct candidate, cntx reaches slot 3 and its count lands in cnt[CNT_SPLITMV], so decodemv.c:366's merge check sees it non-zero and absorbs the candidate into NEAREST when it equals the nearest. Rust's find_near_mvs already implemented this correctly (the ported guard is live); the model lacked the merge entirely. Model fixed (plus a closure-scope idx/ix bug it exposed) — CNT and SP streams now zero-diff across all 60 MBs of gop frame 1, and the B streams agree through the entire mode-record phase (first divergence moved into frame 1's token phase at MB(0,1)'s Y2, prob 131 vs 202 — next suspect: the frame-0 refresh_entropy revert path feeding frame 1's coef prob tables). --- crates/ec-vp8/src/modes.rs | 8 +++++--- scripts/vp8ref_model.py | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ec-vp8/src/modes.rs b/crates/ec-vp8/src/modes.rs index aceadaff..e69fe3b7 100644 --- a/crates/ec-vp8/src/modes.rs +++ b/crates/ec-vp8/src/modes.rs @@ -462,9 +462,11 @@ pub fn find_near_mvs( } } - // libvpx checks `cnt[CNT_SPLITMV]` BEFORE computing it (the write - // happens later in the same branch), so the above-left merge is - // effectively dead there; ported as-is with the same dead guard. + // Above-left merge (libvpx decodemv.c:366): when the above-left + // pushed a THIRD distinct candidate, its count landed in + // cnt[CNT_SPLITMV] (cntx reached slot 3), and if that candidate + // equals the nearest candidate, NEAREST absorbs it. The split count + // is then overwritten with the SPLITMV-neighbour census below. if cnt[CNT_SPLITMV] != 0 && mvs[idx] == mvs[CNT_NEAREST] { cnt[CNT_NEAREST] += 1; } diff --git a/scripts/vp8ref_model.py b/scripts/vp8ref_model.py index ea9788b2..a22b787b 100755 --- a/scripts/vp8ref_model.py +++ b/scripts/vp8ref_model.py @@ -342,6 +342,12 @@ def main(): cnt[cx] += wgt else: cnt[0] += wgt + # libvpx decodemv.c:366 — when the above-left pushed a THIRD + # distinct candidate it counted into cnt[CNT_SPLITMV] (cntx + # reached slot 3), and if that candidate equals the nearest, + # NEAREST absorbs it. Alive, not dead. + if cnt[3] != 0 and mvs[ix] == mvs[1]: + cnt[1] += 1 cnt[3] = (above["split"] * 2) + (left["split"] * 2) + aboveleft["split"] if cnt[2] > cnt[1]: cnt[1], cnt[2] = cnt[2], cnt[1] @@ -525,7 +531,7 @@ def main(): import traceback; traceback.print_exc() print(f"EXC at r={r} c={c}: {e}") raise SystemExit(1) - mvref_print = 4 if mbsplit[r][c] else {-1: 3, -2: 1, -3: 2, -4: 3}.get( + mvref_print = 4 if mbsplit[r][c] else {-1: 0, -2: 1, -3: 2, -4: 3}.get( mbmode[r][c], 0 ) print(