From 43e5d8c984a48c1be0035791d50c554444db542a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 09:40:21 +0300 Subject: [PATCH] fix(av1): mv-stack single-ref predictor falls back to global motion, not zero Root cause of lane-gm r4/r5's "more than one concurrently active ROTZOOM/AFFINE ref slot" refusal, found by range-laddering the r5 pin against a new aomdec EC_TRACE_MODE instrument: libaom's setup_ref_mv_list fills any mv_ref_list slot the neighbour scan left short with gm_get_motion_vector for that block's own ref, not zero. Our find_mv_stack_with_sign_bias used (0, 0) -- invisible whenever the live ref's global motion is itself identity/translation, wrong the moment it's a real ROTZOOM/AFFINE and a block's own stack (e.g. the very first block of a frame, no neighbours) comes up short. Symbol consumption was already bit-exact (rng matched aomdec before/after mode info); only the predictor value was wrong. Fixed at the fallback (nearest_mv/near_mv now default to gm_mv(gm, ref_frame)); the r5/r6 pin decodes all 24 frames byte-exact through the unmodified decode_stream. The multi-slot refusal that was masking this is lifted (AFFINE-on-single-ref refusal stays). Wedge gate: 10/40 matches -> 33/40 (7 remaining refusals are all an unrelated screen-content-tools capability gap). Full ec-av1 --lib suite: 230/231 green (1 filter_intra gate flake, confirmed non-regression by standalone rerun -- ok). --- crates/ec-av1/src/mvstack.rs | 27 ++++++++++++++++------ crates/ec-av1/src/stream.rs | 45 +++++++++++++++++------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 2ac8f6e2..8aa29d96 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -1000,13 +1000,26 @@ pub fn find_mv_stack_with_sign_bias( for e in candidates.iter_mut() { e.mv = clamp(e.mv); } - let nearest_mv = candidates.first().map_or((0, 0), |e| clamp(e.mv)); - let near_mv = candidates.get(1).map_or((0, 0), |e| clamp(e.mv)); - let pred_mv = if candidates.is_empty() { - (0, 0) - } else { - nearest_mv - }; + // libaom `setup_ref_mv_list`'s single-reference-extension tail + // (mvref_common.c ~778-780): once the real scan/extension passes are + // done, every `mv_ref_list` slot still empty (`idx >= refmv_count`, up + // to `MAX_MV_REF_CANDIDATES`=2) is filled with `gm_mv_candidates[0]` -- + // this query block's OWN global motion vector for `ref_frame`, not a + // zero fallback -- and that fill is UNclamped (only the real + // `ref_mv_stack` entries go through `clamp_mv_ref` above). r6: this was + // `(0, 0)` here, invisible whenever a live ref's global motion is + // itself translation/identity (an unclamped gm mv of exactly (0,0)), + // and wrong the moment a ref carries a real ROTZOOM/AFFINE model and a + // query block's stack comes up short -- e.g. the very first block of a + // frame (mi=(0,0), no neighbours at all, `nearest_match`/`ref_match_count` + // both 0) coded NEWMV against a ROTZOOM-global ref: range-ladder against + // aomdec's `EC_TRACE_MODE` confirmed identical symbol consumption (same + // `rng` before/after mode info) with a different final mv purely from + // this predictor gap. + let gm_fallback = gm_mv(gm, ref_frame); + let nearest_mv = candidates.first().map_or(gm_fallback, |e| clamp(e.mv)); + let near_mv = candidates.get(1).map_or(gm_fallback, |e| clamp(e.mv)); + let pred_mv = nearest_mv; // Exact port of the `mode_context[ref_frame]` switch (mvref_common.c // ~line 619-643). `new_mv_ctx` depends on `nearest_match` and the real diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 57a2d289..13873ea9 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -259,30 +259,27 @@ pub fn decode_stream(data: &[u8]) -> Result> { "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", )); } - // lane-gm r4: a NEW mismatch, distinct from the one this round - // fixed and NOT explained by `reference_select`/compound (traced - // live: the mismatched frame of the seed-43 pin has - // `reference_select == false`) -- localized instead to the one - // property that DOES distinguish it from every frame that already - // matches: TWO different ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`) - // carry a non-translation model AT THE SAME TIME. The pin-verified - // fix (frame 1) only ever exercised a single active non-identity - // slot (`LAST_FRAME` alone). Root cause not yet found within this - // round's budget (do not guess-fix): refuse the untested shape by - // name -- more than one concurrently active ROTZOOM/AFFINE ref -- - // rather than ship it silently wrong. - if header.frame_type != FrameType::Key - && header.global_motion[..7] - .iter() - .filter(|gm| gm.model != WarpModel::Identity && gm.model != WarpModel::Translation) - .count() - > 1 - { - return Err(Error::unsupported( - "AV1 decode_stream", - "an inter frame with more than one concurrently active ROTZOOM/AFFINE global-motion ref slot (single-active-slot ROTZOOM is pin-verified; this shape is not)", - )); - } + // lane-gm r4/r5/r6: r4 found a NEW mismatch on frames with two + // concurrently active ROTZOOM/AFFINE ref slots (GOLDEN + BWDREF) and + // refused the shape by name rather than guess-fix it. r5 localized + // the mismatch to an ordinary NEWMV/GOLDEN block, not the new + // global-warp branch at all -- proving "two active slots" was a + // correlated symptom, not the cause. r6 range-laddered that block + // against aomdec's `EC_TRACE_MODE` (identical `rng` before/after + // mode info -- symbol consumption bit-exact) and found the real + // defect in `mvstack.rs`'s single-reference predictor fallback: + // libaom's `setup_ref_mv_list` fills any `mv_ref_list` slot the real + // neighbour scan left short with this block's OWN global motion + // vector for its ref (`gm_get_motion_vector`), not zero -- invisible + // whenever the live ref's global motion is itself + // identity/translation, wrong the moment it's a real ROTZOOM/AFFINE + // and the querying block's own stack comes up short (frame 14's + // mi=(0,0), the very first block decoded, has no neighbours at + // all). Fixed at the predictor fallback; the refusal above (single + // untested shape: AFFINE on a single-ref frame) stays, but the + // *multi-slot* refusal this comment used to guard is lifted -- the + // r5/r6 pin (seed-43 wedge-gate mismatch) now decodes all 24 frames + // byte-exact with it gone. // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read // `comp_mode` per block whenever this frame's own `reference_select` // header bit is set (spec 5.11.25), and refuse by name the blocks