forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-gm': non-IDENTITY global motion decodes through the warp path

Browse files at this commit

384a874588620ae48c881953f95ee6e952cf6003Ahmet Kaan GümüşParent: f4ec6feda24637
Four rounds. The first three ported the syntax correctly -- gm_get_motion_vector,
the mvstack neighbour substitution, the is_global_mv_block vs
is_nontrans_global_motion split -- and the wedge gate still mismatched, because
every check that compared mv VALUES passed. A range ladder settled it: our msac
range and the instrumented aomdec's were both 38664 at the offending block, so
entropy was in sync and the defect was prediction-side. libaom's allow_warp has
a global_warp_allowed branch that predicts every is_global_mv_block block with
the full per-pixel affine warp, independent of motion_mode; this decoder only
ever warped for local WARPED_CAUSAL and fell back to translational MC on the
block-centre mv -- a centre-point approximation whose error grows with distance
from the centre, which is exactly the error shape that was observed.

r4 implements that path, reusing the existing warp_affine and shear machinery
rather than writing a second one. The seed-43 pin's frame 1 luma, the divergence
r3 root-caused, now matches, as do frames 0-13. The blanket "any non-IDENTITY
global motion" refusal is replaced by two named ones: AFFINE models, and more
than one concurrently active ROTZOOM/AFFINE ref slot -- the latter is a real
residue r4 localized but did not root-cause, and refusing it beats guessing.

Also fixed en route: gm_get_motion_vector was missing the -1 on both block-centre
offsets that libaom's block_center_x/y apply.

Full lib suite 231 passed / 0 failed. The wedge gate's match count is 11-16 of 40
across runs -- it selects a different aomenc attempt each run, so single-run
counts from any one round are not comparable.
crates/ec-av1/src/decode.rsmodified+158 -9
@@ -5580,6 +5580,9 @@ fn assign_compound_mv(
5580 mode: u8,5580 mode: u8,
5581 allow_high_precision_mv: bool,5581 allow_high_precision_mv: bool,
5582 force_integer_mv: bool,5582 force_integer_mv: bool,
5583+ // lane-gm r2: `gm_get_motion_vector(ref0)`/`(ref1)` at this block's own
5584+ // position, spec 7.10.2.10's `GLOBAL_GLOBALMV` assignment.
5585+ global_mv: ((i32, i32), (i32, i32)),
5583 ) -> ((i32, i32), (i32, i32)) {5586 ) -> ((i32, i32), (i32, i32)) {
5584 const NEAREST_NEARESTMV: u8 = 0;5587 const NEAREST_NEARESTMV: u8 = 0;
5585 const NEAR_NEARMV: u8 = 1;5588 const NEAR_NEARMV: u8 = 1;
@@ -5643,7 +5646,7 @@ fn assign_compound_mv(
5643 NEW_NEARESTMV => (read_new(dec, cdfs, new_pred.0), comp_stack.nearest_mv.1),5646 NEW_NEARESTMV => (read_new(dec, cdfs, new_pred.0), comp_stack.nearest_mv.1),
5644 NEAR_NEWMV => (near.0, read_new(dec, cdfs, new_pred.1)),5647 NEAR_NEWMV => (near.0, read_new(dec, cdfs, new_pred.1)),
5645 NEW_NEARMV => (read_new(dec, cdfs, new_pred.0), near.1),5648 NEW_NEARMV => (read_new(dec, cdfs, new_pred.0), near.1),
5646- GLOBAL_GLOBALMV => ((0, 0), (0, 0)),5649+ GLOBAL_GLOBALMV => global_mv,
5647 _ => (5650 _ => (
5648 read_new(dec, cdfs, new_pred.0),5651 read_new(dec, cdfs, new_pred.0),
5649 read_new(dec, cdfs, new_pred.1),5652 read_new(dec, cdfs, new_pred.1),
@@ -5651,6 +5654,35 @@ fn assign_compound_mv(
5651 }5654 }
5652 }5655 }
5653 5656
5657+/// Derives this query block's own [`crate::mvstack::GmMvTable`] -- one
5658+/// `gm_get_motion_vector` (spec 7.10.2.1) result per reference frame, at
5659+/// THIS block's own `(mi_row, mi_col, bw4, bh4)` (mvstack.rs's own doc: the
5660+/// table is always computed at the *querying* block's position, never a
5661+/// donating neighbour's).
5662+fn build_gm_mv_table(
5663+ global_motion: &[ec_av1_syntax::WarpParams; 7],
5664+ mi_row: usize,
5665+ mi_col: usize,
5666+ bw4: usize,
5667+ bh4: usize,
5668+ allow_high_precision_mv: bool,
5669+ force_integer_mv: bool,
5670+) -> crate::mvstack::GmMvTable {
5671+ std::array::from_fn(|i| {
5672+ let gm = &global_motion[i];
5673+ crate::warp::gm_get_motion_vector(
5674+ gm.model,
5675+ &gm.params,
5676+ mi_row,
5677+ mi_col,
5678+ bw4,
5679+ bh4,
5680+ allow_high_precision_mv,
5681+ force_integer_mv,
5682+ )
5683+ })
5684+}
5685+
5654 /// Decodes one square inter-frame block (32x32 whole or 16x16 leaf): skip,5686 /// Decodes one square inter-frame block (32x32 whole or 16x16 leaf): skip,
5655 /// `is_inter`, then either the single-reference/MV-stack/motion-vector chain5687 /// `is_inter`, then either the single-reference/MV-stack/motion-vector chain
5656 /// and motion-compensated reconstruction, or the inter frame's own intra5688 /// and motion-compensated reconstruction, or the inter frame's own intra
@@ -5690,6 +5722,11 @@ fn decode_inter_block(
5690 // GOP), matching `GOLDEN_FRAME`'s existing empty-slot refusal below.5722 // GOP), matching `GOLDEN_FRAME`'s existing empty-slot refusal below.
5691 other_refs: &RefSlots,5723 other_refs: &RefSlots,
5692 sign_bias_table: &SignBiasTable,5724 sign_bias_table: &SignBiasTable,
5725+ // lane-gm r2: this frame header's own `global_motion` table (spec
5726+ // 5.9.24), indexed `[ref_frame - LAST_FRAME]` same as `sign_bias_table`
5727+ // -- feeds `warp::gm_get_motion_vector` for `GLOBALMV`/`GLOBAL_GLOBALMV`
5728+ // assignment and the mv-stack's neighbour substitution.
5729+ global_motion: &[ec_av1_syntax::WarpParams; 7],
5693 base_q_idx: u8,5730 base_q_idx: u8,
5694 luma_set_intra: TxbSet,5731 luma_set_intra: TxbSet,
5695 luma_set_inter: TxbSet,5732 luma_set_inter: TxbSet,
@@ -5891,6 +5928,15 @@ fn decode_inter_block(
5891 ),5928 ),
5892 allow_high_precision_mv,5929 allow_high_precision_mv,
5893 });5930 });
5931+ let gm_table = build_gm_mv_table(
5932+ global_motion,
5933+ mi_row,
5934+ mi_col,
5935+ bw4,
5936+ bh4,
5937+ allow_high_precision_mv,
5938+ force_integer_mv,
5939+ );
5894 let comp_stack = crate::mvstack::find_mv_stack_compound(5940 let comp_stack = crate::mvstack::find_mv_stack_compound(
5895 grid,5941 grid,
5896 mi_row,5942 mi_row,
@@ -5901,6 +5947,7 @@ fn decode_inter_block(
5901 mi_cols as usize,5947 mi_cols as usize,
5902 mi_rows as usize,5948 mi_rows as usize,
5903 sign_bias_table,5949 sign_bias_table,
5950+ &gm_table,
5904 comp_tpl,5951 comp_tpl,
5905 );5952 );
5906 let compound_mode = if skip_mode {5953 let compound_mode = if skip_mode {
@@ -5915,8 +5962,15 @@ fn decode_inter_block(
5915 compound_mode,5962 compound_mode,
5916 allow_high_precision_mv,5963 allow_high_precision_mv,
5917 force_integer_mv,5964 force_integer_mv,
5965+ (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),
5918 );5966 );
5919 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV5967 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV
5968+ // spec `is_nontrans_global_motion`: ALL active refs' models must
5969+ // be non-TRANSLATION (IDENTITY counts) for the compound block's
5970+ // interp-filter read to be suppressed.
5971+ let gm_nontrans = is_globalmv
5972+ && global_motion[(ref0 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation
5973+ && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation;
5920 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;5974 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;
5921 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;5975 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;
5922 // spec `get_ref_filter_type`: matches when EITHER of the5976 // spec `get_ref_filter_type`: matches when EITHER of the
@@ -5963,6 +6017,17 @@ fn decode_inter_block(
5963 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),6017 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
5964 size: bw4,6018 size: bw4,
5965 size_h: bh4,6019 size_h: bh4,
6020+ // libaom `is_global_mv_block`: per-ref-slot, mode
6021+ // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's
6022+ // own gm model > TRANSLATION (IDENTITY excluded
6023+ // too -- the two-predicate trap, distinct from
6024+ // `gm_nontrans` above which allows IDENTITY).
6025+ is_global_mv0: is_globalmv
6026+ && bw4.min(bh4) >= 2
6027+ && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1,
6028+ is_global_mv1: is_globalmv
6029+ && bw4.min(bh4) >= 2
6030+ && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1,
5966 },6031 },
5967 );6032 );
5968 }6033 }
@@ -6274,7 +6339,7 @@ fn decode_inter_block(
6274 cdfs,6339 cdfs,
6275 interp_fixed,6340 interp_fixed,
6276 enable_dual_filter,6341 enable_dual_filter,
6277- is_globalmv || skip_mode,6342+ gm_nontrans || skip_mode,
6278 above_filter_ctx,6343 above_filter_ctx,
6279 left_filter_ctx,6344 left_filter_ctx,
6280 true,6345 true,
@@ -6566,6 +6631,15 @@ fn decode_inter_block(
6566 ),6631 ),
6567 allow_high_precision_mv,6632 allow_high_precision_mv,
6568 });6633 });
6634+ let gm_table = build_gm_mv_table(
6635+ global_motion,
6636+ mi_row,
6637+ mi_col,
6638+ bw4,
6639+ bh4,
6640+ allow_high_precision_mv,
6641+ force_integer_mv,
6642+ );
6569 let stack = find_mv_stack_with_sign_bias(6643 let stack = find_mv_stack_with_sign_bias(
6570 grid,6644 grid,
6571 mi_row,6645 mi_row,
@@ -6576,6 +6650,7 @@ fn decode_inter_block(
6576 mi_cols as usize,6650 mi_cols as usize,
6577 mi_rows as usize,6651 mi_rows as usize,
6578 sign_bias_table,6652 sign_bias_table,
6653+ &gm_table,
6579 tpl,6654 tpl,
6580 );6655 );
6581 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;6656 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
@@ -6610,11 +6685,9 @@ fn decode_inter_block(
6610 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;6685 let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1;
6611 is_globalmv = !not_zero;6686 is_globalmv = !not_zero;
6612 let mv = if !not_zero {6687 let mv = if !not_zero {
6613- // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1) under the6688+ // GLOBALMV: `gm_get_motion_vector` (spec 7.10.2.1), already
6614- // `GmType::IDENTITY` this crate's `decode_stream` requires of6689+ // computed at this block's own position in `gm_table`.
6615- // every inter frame's `LAST_FRAME` entry (any other warp6690+ gm_table[(ref_frame - LAST_FRAME) as usize]
6616- // model is refused before the tile decoder is ever called).
6617- (0, 0)
6618 } else {6691 } else {
6619 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;6692 let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0;
6620 if nearest {6693 if nearest {
@@ -6638,6 +6711,18 @@ fn decode_inter_block(
6638 };6711 };
6639 (mv, false)6712 (mv, false)
6640 };6713 };
6714+ // lane-gm r2: the two libaom predicates single-ref GLOBALMV
6715+ // blocks need -- `is_global_mv_block` (blockd.h:421-429, mode
6716+ // GLOBAL* AND model > TRANSLATION AND min(bw,bh) >= 8px, gating
6717+ // `motion_mode_eligible`/`MiInfo::is_global_mv0` below) and
6718+ // `is_nontrans_global_motion` (reconinter.h:420-425, model !=
6719+ // TRANSLATION -- IDENTITY counts here -- gating the interp
6720+ // filter suppress below). Do NOT unify these.
6721+ let gm_model = global_motion[(ref_frame - LAST_FRAME) as usize].model;
6722+ let min_bw_bh4 = bw4.min(bh4);
6723+ let is_global_mv_block = is_globalmv && gm_model as u8 > 1 && min_bw_bh4 >= 2;
6724+ let gm_nontrans =
6725+ is_globalmv && gm_model != ec_av1_syntax::WarpModel::Translation && min_bw_bh4 >= 2;
6641 if std::env::var_os("EC_AV1_TELL").is_some() {6726 if std::env::var_os("EC_AV1_TELL").is_some() {
6642 eprintln!(6727 eprintln!(
6643 "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",6728 "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",
@@ -6722,7 +6807,12 @@ fn decode_inter_block(
6722 && interintra_mode.is_none()6807 && interintra_mode.is_none()
6723 && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()6808 && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()
6724 || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1)6809 || !overlappable_left(grid, mi_row, mi_col, bh4, mi_rows as usize, 1)
6725- .is_empty());6810+ .is_empty())
6811+ // libaom `motion_mode_allowed`: a GLOBALMV block whose model
6812+ // is non-IDENTITY-non-TRANSLATION under free (non-integer)
6813+ // mv reads no motion_mode/obmc symbol at all -- implicit
6814+ // SIMPLE_TRANSLATION.
6815+ && !(is_global_mv_block && !force_integer_mv);
6726 let mut obmc_selected = false;6816 let mut obmc_selected = false;
6727 // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL6817 // lane-warp round 2: `Some` when motion_mode == WARPED_CAUSAL
6728 // *and* the local warp estimate is valid (`!wm_params.invalid`,6818 // *and* the local warp estimate is valid (`!wm_params.invalid`,
@@ -6823,6 +6913,26 @@ fn decode_inter_block(
6823 }6913 }
6824 }6914 }
6825 }6915 }
6916+ // lane-gm r4: `allow_warp`'s `global_warp_allowed` branch
6917+ // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` --
6918+ // libaom's `av1_init_warp_params` runs for every inter
6919+ // predictor build, not just a `WARPED_CAUSAL`-selected one. Only
6920+ // reachable when `warp_params` is still `None` here: a block
6921+ // that read (and got) local `WARPED_CAUSAL` above already has
6922+ // `local_warp_allowed && !wm_params.invalid`, which `allow_warp`
6923+ // checks FIRST and short-circuits on -- the global branch is an
6924+ // `else if`, never layered on top. `is_global_mv_block` already
6925+ // encodes `allow_warp`'s size bound (`min(bw4,bh4) >= 2`, i.e.
6926+ // >=8px both dims, matching `av1_init_warp_params`'s
6927+ // `block_height < 8 || block_width < 8` early return) and, via
6928+ // `motion_mode_eligible`'s own suppression above, the
6929+ // `force_integer_mv` case never reads a motion_mode symbol at
6930+ // all -- checked again here directly since this branch fires
6931+ // independent of `motion_mode_eligible`.
6932+ let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize];
6933+ if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid {
6934+ warp_params = crate::warp::global_warp_params(gm_ref.params);
6935+ }
6826 if std::env::var_os("EC_AV1_TELL").is_some() {6936 if std::env::var_os("EC_AV1_TELL").is_some() {
6827 eprintln!(6937 eprintln!(
6828 "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",6938 "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",
@@ -6859,7 +6969,7 @@ fn decode_inter_block(
6859 cdfs,6969 cdfs,
6860 interp_fixed,6970 interp_fixed,
6861 enable_dual_filter,6971 enable_dual_filter,
6862- is_globalmv || warped_selected,6972+ gm_nontrans || warped_selected,
6863 above_filter_ctx,6973 above_filter_ctx,
6864 left_filter_ctx,6974 left_filter_ctx,
6865 false,6975 false,
@@ -6901,6 +7011,8 @@ fn decode_inter_block(
6901 is_new_mv,7011 is_new_mv,
6902 size: bw4,7012 size: bw4,
6903 size_h: bh4,7013 size_h: bh4,
7014+ is_global_mv0: is_global_mv_block,
7015+ is_global_mv1: false,
6904 },7016 },
6905 );7017 );
6906 }7018 }
@@ -7147,6 +7259,8 @@ fn decode_inter_block(
7147 is_new_mv: false,7259 is_new_mv: false,
7148 size: side / 4,7260 size: side / 4,
7149 size_h: side / 4,7261 size_h: side / 4,
7262+ is_global_mv0: false,
7263+ is_global_mv1: false,
7150 },7264 },
7151 );7265 );
7152 }7266 }
@@ -7482,6 +7596,7 @@ fn decode_inter_block8(
7482 mi_cols as usize,7596 mi_cols as usize,
7483 mi_rows as usize,7597 mi_rows as usize,
7484 &NO_SIGN_BIAS,7598 &NO_SIGN_BIAS,
7599+ &crate::mvstack::NO_GM_MV,
7485 None,7600 None,
7486 );7601 );
7487 let compound_mode = if skip_mode {7602 let compound_mode = if skip_mode {
@@ -7501,6 +7616,9 @@ fn decode_inter_block8(
7501 compound_mode,7616 compound_mode,
7502 allow_high_precision_mv,7617 allow_high_precision_mv,
7503 force_integer_mv,7618 force_integer_mv,
7619+ // leaf8 stays gm-inert (sanctioned partial landing, see
7620+ // this fn's own GLOBALMV refusal below).
7621+ ((0, 0), (0, 0)),
7504 );7622 );
7505 7623
7506 // spec 5.11.25: same gating [`decode_inter_block`]'s own7624 // spec 5.11.25: same gating [`decode_inter_block`]'s own
@@ -7608,6 +7726,8 @@ fn decode_inter_block8(
7608 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),7726 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
7609 size: 2,7727 size: 2,
7610 size_h: 2,7728 size_h: 2,
7729+ is_global_mv0: false,
7730+ is_global_mv1: false,
7611 },7731 },
7612 );7732 );
7613 }7733 }
@@ -7995,6 +8115,8 @@ fn decode_inter_block8(
7995 is_new_mv,8115 is_new_mv,
7996 size: 2,8116 size: 2,
7997 size_h: 2,8117 size_h: 2,
8118+ is_global_mv0: false,
8119+ is_global_mv1: false,
7998 },8120 },
7999 );8121 );
8000 }8122 }
@@ -8189,6 +8311,8 @@ fn decode_inter_block8(
8189 is_new_mv: false,8311 is_new_mv: false,
8190 size: 2,8312 size: 2,
8191 size_h: 2,8313 size_h: 2,
8314+ is_global_mv0: false,
8315+ is_global_mv1: false,
8192 },8316 },
8193 );8317 );
8194 }8318 }
@@ -8349,6 +8473,7 @@ pub fn decode_inter_frame_tile(
8349 allow_high_precision_mv,8473 allow_high_precision_mv,
8350 force_integer_mv,8474 force_integer_mv,
8351 NO_SIGN_BIAS,8475 NO_SIGN_BIAS,
8476+ [ec_av1_syntax::WarpParams::default(); 7],
8352 interp_fixed,8477 interp_fixed,
8353 enable_dual_filter,8478 enable_dual_filter,
8354 0,8479 0,
@@ -8388,6 +8513,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8388 allow_high_precision_mv: bool,8513 allow_high_precision_mv: bool,
8389 force_integer_mv: bool,8514 force_integer_mv: bool,
8390 sign_bias_table: SignBiasTable,8515 sign_bias_table: SignBiasTable,
8516+ // lane-gm r2: this frame header's own `global_motion` table (spec
8517+ // 5.9.24), threaded to every `decode_inter_block` call below.
8518+ global_motion: [ec_av1_syntax::WarpParams; 7],
8391 interp_fixed: Option<mc::InterpFilterKind>,8519 interp_fixed: Option<mc::InterpFilterKind>,
8392 enable_dual_filter: bool,8520 enable_dual_filter: bool,
8393 // lane-av1tmvp: `order_hint`/`order_hint_bits`/`ref_order_hints` are8521 // lane-av1tmvp: `order_hint`/`order_hint_bits`/`ref_order_hints` are
@@ -8641,6 +8769,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8641 &ref_v,8769 &ref_v,
8642 &ref_slots,8770 &ref_slots,
8643 &sign_bias_table,8771 &sign_bias_table,
8772+ &global_motion,
8644 base_q_idx,8773 base_q_idx,
8645 TxbSet::Luma32,8774 TxbSet::Luma32,
8646 TxbSet::Luma32Inter,8775 TxbSet::Luma32Inter,
@@ -8714,6 +8843,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8714 &ref_v,8843 &ref_v,
8715 &ref_slots,8844 &ref_slots,
8716 &sign_bias_table,8845 &sign_bias_table,
8846+ &global_motion,
8717 base_q_idx,8847 base_q_idx,
8718 TxbSet::Luma16,8848 TxbSet::Luma16,
8719 if reduced_tx_set {8849 if reduced_tx_set {
@@ -8890,6 +9020,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8890 &ref_v,9020 &ref_v,
8891 &ref_slots,9021 &ref_slots,
8892 &sign_bias_table,9022 &sign_bias_table,
9023+ &global_motion,
8893 base_q_idx,9024 base_q_idx,
8894 TxbSet::Luma32,9025 TxbSet::Luma32,
8895 TxbSet::Luma32Inter,9026 TxbSet::Luma32Inter,
@@ -8940,6 +9071,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8940 &ref_v,9071 &ref_v,
8941 &ref_slots,9072 &ref_slots,
8942 &sign_bias_table,9073 &sign_bias_table,
9074+ &global_motion,
8943 base_q_idx,9075 base_q_idx,
8944 TxbSet::Luma16,9076 TxbSet::Luma16,
8945 if reduced_tx_set {9077 if reduced_tx_set {
@@ -8991,6 +9123,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8991 &ref_v,9123 &ref_v,
8992 &ref_slots,9124 &ref_slots,
8993 &sign_bias_table,9125 &sign_bias_table,
9126+ &global_motion,
8994 base_q_idx,9127 base_q_idx,
8995 TxbSet::Luma16,9128 TxbSet::Luma16,
8996 if reduced_tx_set {9129 if reduced_tx_set {
@@ -9052,6 +9185,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9052 &ref_v,9185 &ref_v,
9053 &ref_slots,9186 &ref_slots,
9054 &sign_bias_table,9187 &sign_bias_table,
9188+ &global_motion,
9055 base_q_idx,9189 base_q_idx,
9056 TxbSet::Luma32,9190 TxbSet::Luma32,
9057 TxbSet::Luma32Inter,9191 TxbSet::Luma32Inter,
@@ -9098,6 +9232,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9098 &ref_v,9232 &ref_v,
9099 &ref_slots,9233 &ref_slots,
9100 &sign_bias_table,9234 &sign_bias_table,
9235+ &global_motion,
9101 base_q_idx,9236 base_q_idx,
9102 TxbSet::Luma32,9237 TxbSet::Luma32,
9103 TxbSet::Luma32Inter,9238 TxbSet::Luma32Inter,
@@ -9149,6 +9284,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9149 &ref_v,9284 &ref_v,
9150 &ref_slots,9285 &ref_slots,
9151 &sign_bias_table,9286 &sign_bias_table,
9287+ &global_motion,
9152 base_q_idx,9288 base_q_idx,
9153 TxbSet::Luma32,9289 TxbSet::Luma32,
9154 TxbSet::Luma32Inter,9290 TxbSet::Luma32Inter,
@@ -9195,6 +9331,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9195 &ref_v,9331 &ref_v,
9196 &ref_slots,9332 &ref_slots,
9197 &sign_bias_table,9333 &sign_bias_table,
9334+ &global_motion,
9198 base_q_idx,9335 base_q_idx,
9199 TxbSet::Luma32,9336 TxbSet::Luma32,
9200 TxbSet::Luma32Inter,9337 TxbSet::Luma32Inter,
@@ -9247,6 +9384,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9247 &ref_v,9384 &ref_v,
9248 &ref_slots,9385 &ref_slots,
9249 &sign_bias_table,9386 &sign_bias_table,
9387+ &global_motion,
9250 base_q_idx,9388 base_q_idx,
9251 TxbSet::Luma16,9389 TxbSet::Luma16,
9252 if reduced_tx_set {9390 if reduced_tx_set {
@@ -9297,6 +9435,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9297 &ref_v,9435 &ref_v,
9298 &ref_slots,9436 &ref_slots,
9299 &sign_bias_table,9437 &sign_bias_table,
9438+ &global_motion,
9300 base_q_idx,9439 base_q_idx,
9301 TxbSet::Luma16,9440 TxbSet::Luma16,
9302 if reduced_tx_set {9441 if reduced_tx_set {
@@ -9347,6 +9486,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9347 &ref_v,9486 &ref_v,
9348 &ref_slots,9487 &ref_slots,
9349 &sign_bias_table,9488 &sign_bias_table,
9489+ &global_motion,
9350 base_q_idx,9490 base_q_idx,
9351 TxbSet::Luma32,9491 TxbSet::Luma32,
9352 TxbSet::Luma32Inter,9492 TxbSet::Luma32Inter,
@@ -9398,6 +9538,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9398 &ref_v,9538 &ref_v,
9399 &ref_slots,9539 &ref_slots,
9400 &sign_bias_table,9540 &sign_bias_table,
9541+ &global_motion,
9401 base_q_idx,9542 base_q_idx,
9402 TxbSet::Luma16,9543 TxbSet::Luma16,
9403 if reduced_tx_set {9544 if reduced_tx_set {
@@ -9448,6 +9589,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9448 &ref_v,9589 &ref_v,
9449 &ref_slots,9590 &ref_slots,
9450 &sign_bias_table,9591 &sign_bias_table,
9592+ &global_motion,
9451 base_q_idx,9593 base_q_idx,
9452 TxbSet::Luma16,9594 TxbSet::Luma16,
9453 if reduced_tx_set {9595 if reduced_tx_set {
@@ -9498,6 +9640,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9498 &ref_v,9640 &ref_v,
9499 &ref_slots,9641 &ref_slots,
9500 &sign_bias_table,9642 &sign_bias_table,
9643+ &global_motion,
9501 base_q_idx,9644 base_q_idx,
9502 TxbSet::Luma32,9645 TxbSet::Luma32,
9503 TxbSet::Luma32Inter,9646 TxbSet::Luma32Inter,
@@ -9550,6 +9693,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9550 &ref_v,9693 &ref_v,
9551 &ref_slots,9694 &ref_slots,
9552 &sign_bias_table,9695 &sign_bias_table,
9696+ &global_motion,
9553 base_q_idx,9697 base_q_idx,
9554 TxbSet::Luma32,9698 TxbSet::Luma32,
9555 TxbSet::Luma32Inter,9699 TxbSet::Luma32Inter,
@@ -9596,6 +9740,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9596 &ref_v,9740 &ref_v,
9597 &ref_slots,9741 &ref_slots,
9598 &sign_bias_table,9742 &sign_bias_table,
9743+ &global_motion,
9599 base_q_idx,9744 base_q_idx,
9600 TxbSet::Luma16,9745 TxbSet::Luma16,
9601 if reduced_tx_set {9746 if reduced_tx_set {
@@ -9646,6 +9791,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9646 &ref_v,9791 &ref_v,
9647 &ref_slots,9792 &ref_slots,
9648 &sign_bias_table,9793 &sign_bias_table,
9794+ &global_motion,
9649 base_q_idx,9795 base_q_idx,
9650 TxbSet::Luma16,9796 TxbSet::Luma16,
9651 if reduced_tx_set {9797 if reduced_tx_set {
@@ -10316,6 +10462,8 @@ mod tests {
10316 is_new_mv: false,10462 is_new_mv: false,
10317 size: 1,10463 size: 1,
10318 size_h: 1,10464 size_h: 1,
10465+ is_global_mv0: false,
10466+ is_global_mv1: false,
10319 };10467 };
10320 for col in mi_col..mi_col + bw4 {10468 for col in mi_col..mi_col + bw4 {
10321 grid.set(mi_row - 1, col, neighbour(above_mv));10469 grid.set(mi_row - 1, col, neighbour(above_mv));
@@ -10424,6 +10572,7 @@ mod tests {
10424 &ref_v,10572 &ref_v,
10425 &[None; 8],10573 &[None; 8],
10426 &NO_SIGN_BIAS,10574 &NO_SIGN_BIAS,
10575+ &[ec_av1_syntax::WarpParams::default(); 7],
10427 100,10576 100,
10428 TxbSet::Luma16,10577 TxbSet::Luma16,
10429 TxbSet::Luma16Inter,10578 TxbSet::Luma16Inter,
crates/ec-av1/src/encode.rsmodified+12 -0
@@ -2681,6 +2681,8 @@ pub(crate) fn encode_inter_frame(
2681 is_new_mv: matches!(info.mode, InterMode::NewMv),2681 is_new_mv: matches!(info.mode, InterMode::NewMv),
2682 size: 8,2682 size: 8,
2683 size_h: 8,2683 size_h: 8,
2684+ is_global_mv0: false,
2685+ is_global_mv1: false,
2684 },2686 },
2685 // Intra: no vote, but still a coded cell2687 // Intra: no vote, but still a coded cell
2686 // -- mvstack's extended-scan coverage2688 // -- mvstack's extended-scan coverage
@@ -2695,6 +2697,8 @@ pub(crate) fn encode_inter_frame(
2695 is_new_mv: false,2697 is_new_mv: false,
2696 size: 8,2698 size: 8,
2697 size_h: 8,2699 size_h: 8,
2700+ is_global_mv0: false,
2701+ is_global_mv1: false,
2698 },2702 },
2699 },2703 },
2700 );2704 );
@@ -2775,6 +2779,8 @@ pub(crate) fn encode_inter_frame(
2775 is_new_mv: matches!(info.mode, InterMode::NewMv),2779 is_new_mv: matches!(info.mode, InterMode::NewMv),
2776 size: 4,2780 size: 4,
2777 size_h: 4,2781 size_h: 4,
2782+ is_global_mv0: false,
2783+ is_global_mv1: false,
2778 },2784 },
2779 None => MiInfo {2785 None => MiInfo {
2780 is_inter: false,2786 is_inter: false,
@@ -2785,6 +2791,8 @@ pub(crate) fn encode_inter_frame(
2785 is_new_mv: false,2791 is_new_mv: false,
2786 size: 4,2792 size: 4,
2787 size_h: 4,2793 size_h: 4,
2794+ is_global_mv0: false,
2795+ is_global_mv1: false,
2788 },2796 },
2789 },2797 },
2790 );2798 );
@@ -2834,6 +2842,8 @@ pub(crate) fn encode_inter_frame(
2834 ),2842 ),
2835 size: 2,2843 size: 2,
2836 size_h: 2,2844 size_h: 2,
2845+ is_global_mv0: false,
2846+ is_global_mv1: false,
2837 },2847 },
2838 None => MiInfo {2848 None => MiInfo {
2839 is_inter: false,2849 is_inter: false,
@@ -2844,6 +2854,8 @@ pub(crate) fn encode_inter_frame(
2844 is_new_mv: false,2854 is_new_mv: false,
2845 size: 2,2855 size: 2,
2846 size_h: 2,2856 size_h: 2,
2857+ is_global_mv0: false,
2858+ is_global_mv1: false,
2847 },2859 },
2848 },2860 },
2849 );2861 );
crates/ec-av1/src/mvstack.rsmodified+115 -24
@@ -141,6 +141,16 @@ pub struct MiInfo {
141 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a141 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a
142 /// neighbour's own coded-with-NEWMV state, not this block's.142 /// neighbour's own coded-with-NEWMV state, not this block's.
143 pub is_new_mv: bool,143 pub is_new_mv: bool,
144+ /// Whether this unit's own coded mode was `GLOBALMV`/`GLOBAL_GLOBALMV`
145+ /// *and* the frame's global-motion model for its `ref_frame` is more
146+ /// than `TRANSLATION` (libaom's `is_global_mv_block`, checked per
147+ /// reference slot at donation time, mvref_common.c:88-92): when true,
148+ /// a scan that matches this unit on its first ref slot donates the
149+ /// *querying* block's own `gm_mv` there, not `mv`.
150+ pub is_global_mv0: bool,
151+ /// `is_global_mv0`, for the second ref slot (`ref_frame1`/`mv1`,
152+ /// mvref_common.c:116-117).
153+ pub is_global_mv1: bool,
144 /// The side, in 4x4 units, of the square block this unit belongs to (8154 /// The side, in 4x4 units, of the square block this unit belongs to (8
145 /// for a whole 32x32 block, 4 for a 16x16 leaf -- every block this crate155 /// for a whole 32x32 block, 4 for a 16x16 leaf -- every block this crate
146 /// ever codes is square, so one dimension is enough). Feeds the extended156 /// ever codes is square, so one dimension is enough). Feeds the extended
@@ -302,6 +312,26 @@ pub type SignBiasTable = [bool; 7];
302 /// hardcoded `sign_bias` stub.312 /// hardcoded `sign_bias` stub.
303 pub const NO_SIGN_BIAS: SignBiasTable = [false; 7];313 pub const NO_SIGN_BIAS: SignBiasTable = [false; 7];
304 314
315+/// One derived global-motion `(row, col)` mv per reference frame
316+/// (`table[ref_frame - LAST_FRAME]`, same shape/indexing as
317+/// [`SignBiasTable`]), all computed at the *querying* block's own position
318+/// -- lane-gm: a neighbour donating a candidate under `MiInfo::is_global_mv0`/
319+/// `MiInfo::is_global_mv1` contributes this table's entry for the matched
320+/// ref frame, not its own stored `mv`/`mv1` (mvref_common.c:88-92/116-117).
321+pub type GmMvTable = [(i32, i32); 7];
322+
323+/// The all-zero table every IDENTITY/no-gm caller passes: exact whenever no
324+/// unit in the grid is ever `is_global_mv0`/`is_global_mv1` (the 14-pin
325+/// list's own streams), since a substitution that never triggers reads as
326+/// this reduction's old hardcoded-zero behaviour.
327+pub const NO_GM_MV: GmMvTable = [(0, 0); 7];
328+
329+/// `table[ref_frame - LAST_FRAME]`, [`sign_bias`]'s shape for a
330+/// [`GmMvTable`].
331+fn gm_mv(table: &GmMvTable, ref_frame: i8) -> (i32, i32) {
332+ table[(ref_frame - LAST_FRAME) as usize]
333+}
334+
305 /// libaom's `process_single_ref_mv_candidate` (mvref_common.c): folds one335 /// libaom's `process_single_ref_mv_candidate` (mvref_common.c): folds one
306 /// already-coded neighbour into the stack as a low-weight (`2`, unboosted)336 /// already-coded neighbour into the stack as a low-weight (`2`, unboosted)
307 /// filler entry, used only by the single-reference extension pass below.337 /// filler entry, used only by the single-reference extension pass below.
@@ -326,6 +356,10 @@ fn process_single_ref_mv_candidate(
326 if !candidate.is_inter {356 if !candidate.is_inter {
327 return;357 return;
328 }358 }
359+ // libaom's `process_single_ref_mv_candidate` (mvref_common.c ~440-475)
360+ // reads `candidate->mv[rf_idx]` unconditionally here -- unlike
361+ // `add_ref_mv_candidate`'s row/col/corner scans, this extension pass
362+ // never checks `is_global_mv_block`/substitutes `gm_mv_candidates`.
329 let mut slots = [(candidate.ref_frame, candidate.mv); 2];363 let mut slots = [(candidate.ref_frame, candidate.mv); 2];
330 let mut n_slots = 1;364 let mut n_slots = 1;
331 if let (Some(rf1), Some(mv1)) = (candidate.ref_frame1, candidate.mv1) {365 if let (Some(rf1), Some(mv1)) = (candidate.ref_frame1, candidate.mv1) {
@@ -386,6 +420,7 @@ fn scan_row(
386 row_offset: isize,420 row_offset: isize,
387 max_row_offset: isize,421 max_row_offset: isize,
388 ref_frame: i8,422 ref_frame: i8,
423+ gm: &GmMvTable,
389 candidates: &mut Vec<StackEntry>,424 candidates: &mut Vec<StackEntry>,
390 newmv_count: &mut u32,425 newmv_count: &mut u32,
391 processed_rows: &mut usize,426 processed_rows: &mut usize,
@@ -416,7 +451,7 @@ fn scan_row(
416 weight = weight.max(inc as u32);451 weight = weight.max(inc as u32);
417 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;452 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
418 }453 }
419- if let Some(mv) = single_ref_match(info, ref_frame) {454+ if let Some(mv) = single_ref_match(info, ref_frame, gm) {
420 found = true;455 found = true;
421 add_candidate(candidates, mv, len as u32 * weight);456 add_candidate(candidates, mv, len as u32 * weight);
422 *newmv_count += u32::from(info.is_new_mv);457 *newmv_count += u32::from(info.is_new_mv);
@@ -435,14 +470,22 @@ fn scan_row(
435 /// compound neighbour's vote whenever the match sat in its *second* slot470 /// compound neighbour's vote whenever the match sat in its *second* slot
436 /// (the class this crate's own compound-stack scan already had to close for471 /// (the class this crate's own compound-stack scan already had to close for
437 /// [`find_mv_stack_compound`] -- see the module doc).472 /// [`find_mv_stack_compound`] -- see the module doc).
438-fn single_ref_match(info: &MiInfo, ref_frame: i8) -> Option<(i32, i32)> {473+fn single_ref_match(info: &MiInfo, ref_frame: i8, gm: &GmMvTable) -> Option<(i32, i32)> {
439 if !info.is_inter {474 if !info.is_inter {
440 return None;475 return None;
441 }476 }
442 if info.ref_frame == ref_frame {477 if info.ref_frame == ref_frame {
443- Some(info.mv)478+ Some(if info.is_global_mv0 {
479+ gm_mv(gm, ref_frame)
480+ } else {
481+ info.mv
482+ })
444 } else if info.ref_frame1 == Some(ref_frame) {483 } else if info.ref_frame1 == Some(ref_frame) {
445- info.mv1484+ if info.is_global_mv1 {
485+ Some(gm_mv(gm, ref_frame))
486+ } else {
487+ info.mv1
488+ }
446 } else {489 } else {
447 None490 None
448 }491 }
@@ -459,6 +502,7 @@ fn scan_col(
459 col_offset: isize,502 col_offset: isize,
460 max_col_offset: isize,503 max_col_offset: isize,
461 ref_frame: i8,504 ref_frame: i8,
505+ gm: &GmMvTable,
462 candidates: &mut Vec<StackEntry>,506 candidates: &mut Vec<StackEntry>,
463 newmv_count: &mut u32,507 newmv_count: &mut u32,
464 processed_cols: &mut usize,508 processed_cols: &mut usize,
@@ -489,7 +533,7 @@ fn scan_col(
489 weight = weight.max(inc as u32);533 weight = weight.max(inc as u32);
490 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;534 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
491 }535 }
492- if let Some(mv) = single_ref_match(info, ref_frame) {536+ if let Some(mv) = single_ref_match(info, ref_frame, gm) {
493 found = true;537 found = true;
494 add_candidate(candidates, mv, len as u32 * weight);538 add_candidate(candidates, mv, len as u32 * weight);
495 *newmv_count += u32::from(info.is_new_mv);539 *newmv_count += u32::from(info.is_new_mv);
@@ -511,6 +555,7 @@ fn scan_top_right(
511 mi_col: usize,555 mi_col: usize,
512 bw4: usize,556 bw4: usize,
513 ref_frame: i8,557 ref_frame: i8,
558+ gm: &GmMvTable,
514 candidates: &mut Vec<StackEntry>,559 candidates: &mut Vec<StackEntry>,
515 newmv_count: &mut u32,560 newmv_count: &mut u32,
516 ) -> bool {561 ) -> bool {
@@ -519,7 +564,7 @@ fn scan_top_right(
519 };564 };
520 let col = mi_col + bw4;565 let col = mi_col + bw4;
521 if let Some(info) = grid.get(row, col)566 if let Some(info) = grid.get(row, col)
522- && let Some(mv) = single_ref_match(info, ref_frame)567+ && let Some(mv) = single_ref_match(info, ref_frame, gm)
523 {568 {
524 add_candidate(candidates, mv, CORNER_WEIGHT);569 add_candidate(candidates, mv, CORNER_WEIGHT);
525 *newmv_count += u32::from(info.is_new_mv);570 *newmv_count += u32::from(info.is_new_mv);
@@ -539,6 +584,7 @@ fn scan_corner(
539 mi_row: usize,584 mi_row: usize,
540 mi_col: usize,585 mi_col: usize,
541 ref_frame: i8,586 ref_frame: i8,
587+ gm: &GmMvTable,
542 candidates: &mut Vec<StackEntry>,588 candidates: &mut Vec<StackEntry>,
543 newmv_count: &mut u32,589 newmv_count: &mut u32,
544 ) -> bool {590 ) -> bool {
@@ -546,7 +592,7 @@ fn scan_corner(
546 return false;592 return false;
547 };593 };
548 if let Some(info) = grid.get(row, col)594 if let Some(info) = grid.get(row, col)
549- && let Some(mv) = single_ref_match(info, ref_frame)595+ && let Some(mv) = single_ref_match(info, ref_frame, gm)
550 {596 {
551 add_candidate(candidates, mv, CORNER_WEIGHT);597 add_candidate(candidates, mv, CORNER_WEIGHT);
552 *newmv_count += u32::from(info.is_new_mv);598 *newmv_count += u32::from(info.is_new_mv);
@@ -613,6 +659,7 @@ pub fn find_mv_stack(
613 mi_cols,659 mi_cols,
614 mi_rows,660 mi_rows,
615 &NO_SIGN_BIAS,661 &NO_SIGN_BIAS,
662+ &NO_GM_MV,
616 None,663 None,
617 )664 )
618 }665 }
@@ -633,6 +680,7 @@ pub fn find_mv_stack_with_sign_bias(
633 mi_cols: usize,680 mi_cols: usize,
634 mi_rows: usize,681 mi_rows: usize,
635 sign_bias_table: &SignBiasTable,682 sign_bias_table: &SignBiasTable,
683+ gm: &GmMvTable,
636 tpl: Option<TplArgs>,684 tpl: Option<TplArgs>,
637 ) -> MvStack {685 ) -> MvStack {
638 let mut candidates = Vec::new();686 let mut candidates = Vec::new();
@@ -670,6 +718,7 @@ pub fn find_mv_stack_with_sign_bias(
670 -1,718 -1,
671 max_row_offset,719 max_row_offset,
672 ref_frame,720 ref_frame,
721+ gm,
673 &mut candidates,722 &mut candidates,
674 &mut newmv_count,723 &mut newmv_count,
675 &mut processed_rows,724 &mut processed_rows,
@@ -683,6 +732,7 @@ pub fn find_mv_stack_with_sign_bias(
683 -1,732 -1,
684 max_col_offset,733 max_col_offset,
685 ref_frame,734 ref_frame,
735+ gm,
686 &mut candidates,736 &mut candidates,
687 &mut newmv_count,737 &mut newmv_count,
688 &mut processed_cols,738 &mut processed_cols,
@@ -693,6 +743,7 @@ pub fn find_mv_stack_with_sign_bias(
693 mi_col,743 mi_col,
694 bw4,744 bw4,
695 ref_frame,745 ref_frame,
746+ gm,
696 &mut candidates,747 &mut candidates,
697 &mut newmv_count,748 &mut newmv_count,
698 );749 );
@@ -756,7 +807,9 @@ pub fn find_mv_stack_with_sign_bias(
756 any_hit = true;807 any_hit = true;
757 if blk_row == 0 && blk_col == 0 {808 if blk_row == 0 && blk_col == 0 {
758 first_sample_missing = false;809 first_sample_missing = false;
759- first_sample_far = cand.mv.0.abs() >= 16 || cand.mv.1.abs() >= 16;810+ let this_gm_mv = gm_mv(gm, ref_frame);
811+ first_sample_far = (cand.mv.0 - this_gm_mv.0).abs() >= 16
812+ || (cand.mv.1 - this_gm_mv.1).abs() >= 16;
760 }813 }
761 add_candidate(&mut candidates, cand.mv, 2);814 add_candidate(&mut candidates, cand.mv, 2);
762 }815 }
@@ -811,6 +864,7 @@ pub fn find_mv_stack_with_sign_bias(
811 mi_row,864 mi_row,
812 mi_col,865 mi_col,
813 ref_frame,866 ref_frame,
867+ gm,
814 &mut candidates,868 &mut candidates,
815 &mut dummy_newmv_count,869 &mut dummy_newmv_count,
816 );870 );
@@ -841,6 +895,7 @@ pub fn find_mv_stack_with_sign_bias(
841 row_offset,895 row_offset,
842 max_row_offset,896 max_row_offset,
843 ref_frame,897 ref_frame,
898+ gm,
844 &mut candidates,899 &mut candidates,
845 &mut dummy_newmv_count,900 &mut dummy_newmv_count,
846 &mut processed_rows,901 &mut processed_rows,
@@ -858,6 +913,7 @@ pub fn find_mv_stack_with_sign_bias(
858 col_offset,913 col_offset,
859 max_col_offset,914 max_col_offset,
860 ref_frame,915 ref_frame,
916+ gm,
861 &mut candidates,917 &mut candidates,
862 &mut dummy_newmv_count,918 &mut dummy_newmv_count,
863 &mut processed_cols,919 &mut processed_cols,
@@ -1101,6 +1157,7 @@ fn scan_row_compound(
1101 row_offset: isize,1157 row_offset: isize,
1102 max_row_offset: isize,1158 max_row_offset: isize,
1103 ref_frame: (i8, i8),1159 ref_frame: (i8, i8),
1160+ gm: &GmMvTable,
1104 candidates: &mut Vec<CompoundStackEntry>,1161 candidates: &mut Vec<CompoundStackEntry>,
1105 newmv_count: &mut u32,1162 newmv_count: &mut u32,
1106 processed_rows: &mut usize,1163 processed_rows: &mut usize,
@@ -1135,8 +1192,8 @@ fn scan_row_compound(
1135 found = true;1192 found = true;
1136 add_compound_candidate(1193 add_compound_candidate(
1137 candidates,1194 candidates,
1138- info.mv,1195+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1139- info.mv1.unwrap_or((0, 0)),1196+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1140 len as u32 * weight,1197 len as u32 * weight,
1141 );1198 );
1142 *newmv_count += u32::from(info.is_new_mv);1199 *newmv_count += u32::from(info.is_new_mv);
@@ -1157,6 +1214,7 @@ fn scan_col_compound(
1157 col_offset: isize,1214 col_offset: isize,
1158 max_col_offset: isize,1215 max_col_offset: isize,
1159 ref_frame: (i8, i8),1216 ref_frame: (i8, i8),
1217+ gm: &GmMvTable,
1160 candidates: &mut Vec<CompoundStackEntry>,1218 candidates: &mut Vec<CompoundStackEntry>,
1161 newmv_count: &mut u32,1219 newmv_count: &mut u32,
1162 processed_cols: &mut usize,1220 processed_cols: &mut usize,
@@ -1191,8 +1249,8 @@ fn scan_col_compound(
1191 found = true;1249 found = true;
1192 add_compound_candidate(1250 add_compound_candidate(
1193 candidates,1251 candidates,
1194- info.mv,1252+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1195- info.mv1.unwrap_or((0, 0)),1253+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1196 len as u32 * weight,1254 len as u32 * weight,
1197 );1255 );
1198 *newmv_count += u32::from(info.is_new_mv);1256 *newmv_count += u32::from(info.is_new_mv);
@@ -1203,12 +1261,14 @@ fn scan_col_compound(
1203 }1261 }
1204 1262
1205 /// The compound top-right probe ([`scan_top_right`]'s pair-matched twin).1263 /// The compound top-right probe ([`scan_top_right`]'s pair-matched twin).
1264+#[allow(clippy::too_many_arguments)]
1206 fn scan_top_right_compound(1265 fn scan_top_right_compound(
1207 grid: &MiGrid,1266 grid: &MiGrid,
1208 mi_row: usize,1267 mi_row: usize,
1209 mi_col: usize,1268 mi_col: usize,
1210 bw4: usize,1269 bw4: usize,
1211 ref_frame: (i8, i8),1270 ref_frame: (i8, i8),
1271+ gm: &GmMvTable,
1212 candidates: &mut Vec<CompoundStackEntry>,1272 candidates: &mut Vec<CompoundStackEntry>,
1213 newmv_count: &mut u32,1273 newmv_count: &mut u32,
1214 ) -> bool {1274 ) -> bool {
@@ -1223,8 +1283,8 @@ fn scan_top_right_compound(
1223 {1283 {
1224 add_compound_candidate(1284 add_compound_candidate(
1225 candidates,1285 candidates,
1226- info.mv,1286+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1227- info.mv1.unwrap_or((0, 0)),1287+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1228 CORNER_WEIGHT,1288 CORNER_WEIGHT,
1229 );1289 );
1230 *newmv_count += u32::from(info.is_new_mv);1290 *newmv_count += u32::from(info.is_new_mv);
@@ -1239,6 +1299,7 @@ fn scan_corner_compound(
1239 mi_row: usize,1299 mi_row: usize,
1240 mi_col: usize,1300 mi_col: usize,
1241 ref_frame: (i8, i8),1301 ref_frame: (i8, i8),
1302+ gm: &GmMvTable,
1242 candidates: &mut Vec<CompoundStackEntry>,1303 candidates: &mut Vec<CompoundStackEntry>,
1243 newmv_count: &mut u32,1304 newmv_count: &mut u32,
1244 ) -> bool {1305 ) -> bool {
@@ -1252,8 +1313,8 @@ fn scan_corner_compound(
1252 {1313 {
1253 add_compound_candidate(1314 add_compound_candidate(
1254 candidates,1315 candidates,
1255- info.mv,1316+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1256- info.mv1.unwrap_or((0, 0)),1317+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1257 CORNER_WEIGHT,1318 CORNER_WEIGHT,
1258 );1319 );
1259 *newmv_count += u32::from(info.is_new_mv);1320 *newmv_count += u32::from(info.is_new_mv);
@@ -1360,6 +1421,7 @@ fn combine_compound_candidates(lists: &CompoundRefLists) -> [((i32, i32), (i32,
1360 /// ports of libaom's real behaviour as of r5 — see the inline comments at1421 /// ports of libaom's real behaviour as of r5 — see the inline comments at
1361 /// each site.1422 /// each site.
1362 #[allow(clippy::too_many_arguments)]1423 #[allow(clippy::too_many_arguments)]
1424+#[allow(clippy::too_many_arguments)]
1363 pub fn find_mv_stack_compound(1425 pub fn find_mv_stack_compound(
1364 grid: &MiGrid,1426 grid: &MiGrid,
1365 mi_row: usize,1427 mi_row: usize,
@@ -1370,6 +1432,7 @@ pub fn find_mv_stack_compound(
1370 mi_cols: usize,1432 mi_cols: usize,
1371 mi_rows: usize,1433 mi_rows: usize,
1372 sign_bias_table: &SignBiasTable,1434 sign_bias_table: &SignBiasTable,
1435+ gm: &GmMvTable,
1373 tpl: Option<CompoundTplArgs>,1436 tpl: Option<CompoundTplArgs>,
1374 ) -> CompoundMvStack {1437 ) -> CompoundMvStack {
1375 let mut candidates: Vec<CompoundStackEntry> = Vec::new();1438 let mut candidates: Vec<CompoundStackEntry> = Vec::new();
@@ -1401,6 +1464,7 @@ pub fn find_mv_stack_compound(
1401 -1,1464 -1,
1402 max_row_offset,1465 max_row_offset,
1403 ref_frame,1466 ref_frame,
1467+ gm,
1404 &mut candidates,1468 &mut candidates,
1405 &mut newmv_count,1469 &mut newmv_count,
1406 &mut processed_rows,1470 &mut processed_rows,
@@ -1414,6 +1478,7 @@ pub fn find_mv_stack_compound(
1414 -1,1478 -1,
1415 max_col_offset,1479 max_col_offset,
1416 ref_frame,1480 ref_frame,
1481+ gm,
1417 &mut candidates,1482 &mut candidates,
1418 &mut newmv_count,1483 &mut newmv_count,
1419 &mut processed_cols,1484 &mut processed_cols,
@@ -1424,6 +1489,7 @@ pub fn find_mv_stack_compound(
1424 mi_col,1489 mi_col,
1425 bw4,1490 bw4,
1426 ref_frame,1491 ref_frame,
1492+ gm,
1427 &mut candidates,1493 &mut candidates,
1428 &mut newmv_count,1494 &mut newmv_count,
1429 );1495 );
@@ -1489,10 +1555,12 @@ pub fn find_mv_stack_compound(
1489 let mv1 = cand1.map_or((0, 0), |c| c.mv);1555 let mv1 = cand1.map_or((0, 0), |c| c.mv);
1490 if blk_row == 0 && blk_col == 0 {1556 if blk_row == 0 && blk_col == 0 {
1491 first_sample_missing = false;1557 first_sample_missing = false;
1492- first_sample_far = mv0.0.abs() >= 161558+ let this_gm0 = gm_mv(gm, ref_frame.0);
1493- || mv0.1.abs() >= 161559+ let this_gm1 = gm_mv(gm, ref_frame.1);
1494- || mv1.0.abs() >= 161560+ first_sample_far = (mv0.0 - this_gm0.0).abs() >= 16
1495- || mv1.1.abs() >= 16;1561+ || (mv0.1 - this_gm0.1).abs() >= 16
1562+ || (mv1.0 - this_gm1.0).abs() >= 16
1563+ || (mv1.1 - this_gm1.1).abs() >= 16;
1496 }1564 }
1497 add_compound_candidate(&mut candidates, mv0, mv1, 2);1565 add_compound_candidate(&mut candidates, mv0, mv1, 2);
1498 }1566 }
@@ -1512,6 +1580,7 @@ pub fn find_mv_stack_compound(
1512 mi_row,1580 mi_row,
1513 mi_col,1581 mi_col,
1514 ref_frame,1582 ref_frame,
1583+ gm,
1515 &mut candidates,1584 &mut candidates,
1516 &mut dummy_newmv_count,1585 &mut dummy_newmv_count,
1517 );1586 );
@@ -1530,6 +1599,7 @@ pub fn find_mv_stack_compound(
1530 row_offset,1599 row_offset,
1531 max_row_offset,1600 max_row_offset,
1532 ref_frame,1601 ref_frame,
1602+ gm,
1533 &mut candidates,1603 &mut candidates,
1534 &mut dummy_newmv_count,1604 &mut dummy_newmv_count,
1535 &mut processed_rows,1605 &mut processed_rows,
@@ -1547,6 +1617,7 @@ pub fn find_mv_stack_compound(
1547 col_offset,1617 col_offset,
1548 max_col_offset,1618 max_col_offset,
1549 ref_frame,1619 ref_frame,
1620+ gm,
1550 &mut candidates,1621 &mut candidates,
1551 &mut dummy_newmv_count,1622 &mut dummy_newmv_count,
1552 &mut processed_cols,1623 &mut processed_cols,
@@ -1983,6 +2054,8 @@ mod tests {
1983 // tests only exercise the immediate/corner/top-right scans.2054 // tests only exercise the immediate/corner/top-right scans.
1984 size: 1,2055 size: 1,
1985 size_h: 1,2056 size_h: 1,
2057+ is_global_mv0: false,
2058+ is_global_mv1: false,
1986 }2059 }
1987 }2060 }
1988 2061
@@ -2137,6 +2210,8 @@ mod tests {
2137 is_new_mv: true,2210 is_new_mv: true,
2138 size: 1,2211 size: 1,
2139 size_h: 1,2212 size_h: 1,
2213+ is_global_mv0: false,
2214+ is_global_mv1: false,
2140 },2215 },
2141 );2216 );
2142 // Only the row matches (nearest_match == 1): newmv_count > 0 picks2217 // Only the row matches (nearest_match == 1): newmv_count > 0 picks
@@ -2218,6 +2293,8 @@ mod tests {
2218 is_new_mv: false,2293 is_new_mv: false,
2219 size: 8,2294 size: 8,
2220 size_h: 8,2295 size_h: 8,
2296+ is_global_mv0: false,
2297+ is_global_mv1: false,
2221 },2298 },
2222 );2299 );
2223 2300
@@ -2248,6 +2325,8 @@ mod tests {
2248 is_new_mv: false,2325 is_new_mv: false,
2249 size: 8,2326 size: 8,
2250 size_h: 8,2327 size_h: 8,
2328+ is_global_mv0: false,
2329+ is_global_mv1: false,
2251 }2330 }
2252 }2331 }
2253 2332
@@ -2265,6 +2344,8 @@ mod tests {
2265 is_new_mv: false,2344 is_new_mv: false,
2266 size: 8,2345 size: 8,
2267 size_h: 8,2346 size_h: 8,
2347+ is_global_mv0: false,
2348+ is_global_mv1: false,
2268 }2349 }
2269 }2350 }
2270 2351
@@ -2503,6 +2584,8 @@ mod tests {
2503 is_new_mv: false,2584 is_new_mv: false,
2504 size: 1,2585 size: 1,
2505 size_h: 1,2586 size_h: 1,
2587+ is_global_mv0: false,
2588+ is_global_mv1: false,
2506 }2589 }
2507 }2590 }
2508 2591
@@ -2524,13 +2607,15 @@ mod tests {
2524 is_new_mv: false,2607 is_new_mv: false,
2525 size: 1,2608 size: 1,
2526 size_h: 1,2609 size_h: 1,
2610+ is_global_mv0: false,
2611+ is_global_mv1: false,
2527 },2612 },
2528 );2613 );
2529 // Exact pair match.2614 // Exact pair match.
2530 let (mv0, mv1) = ((2, 2), (-6, 3));2615 let (mv0, mv1) = ((2, 2), (-6, 3));
2531 grid.set(2, 1, comp_inter(mv0, mv1));2616 grid.set(2, 1, comp_inter(mv0, mv1));
2532 2617
2533- let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, None);2618+ let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None);
2534 2619
2535 // The exact-pair immediate scan lands one boosted entry; the2620 // The exact-pair immediate scan lands one boosted entry; the
2536 // compound extension pass (short stack, len < MAX_MV_REF_CANDIDATES)2621 // compound extension pass (short stack, len < MAX_MV_REF_CANDIDATES)
@@ -2554,7 +2639,7 @@ mod tests {
2554 grid.set(2, 1, comp_inter(mv0, mv1));2639 grid.set(2, 1, comp_inter(mv0, mv1));
2555 grid.set(3, 1, comp_inter(mv0, mv1));2640 grid.set(3, 1, comp_inter(mv0, mv1));
2556 2641
2557- let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, None);2642+ let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None);
2558 2643
2559 // Exact libaom `is_dup` port: with exactly one entry already in the2644 // Exact libaom `is_dup` port: with exactly one entry already in the
2560 // stack (the four identical-pair neighbours deduped by the2645 // stack (the four identical-pair neighbours deduped by the
@@ -2586,7 +2671,7 @@ mod tests {
2586 grid.set(4, 2, comp_inter(left.0, left.1));2671 grid.set(4, 2, comp_inter(left.0, left.1));
2587 grid.set(5, 2, comp_inter(left.0, left.1));2672 grid.set(5, 2, comp_inter(left.0, left.1));
2588 2673
2589- let stack = find_mv_stack_compound(&grid, 3, 3, 2, 3, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, None);2674+ let stack = find_mv_stack_compound(&grid, 3, 3, 2, 3, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None);
2590 2675
2591 assert_eq!(stack.entries.len(), 2);2676 assert_eq!(stack.entries.len(), 2);
2592 assert_eq!(stack.entries[0].mv0, left.0);2677 assert_eq!(stack.entries[0].mv0, left.0);
@@ -2625,6 +2710,8 @@ mod tests {
2625 is_new_mv: false,2710 is_new_mv: false,
2626 size: 1,2711 size: 1,
2627 size_h: 1,2712 size_h: 1,
2713+ is_global_mv0: false,
2714+ is_global_mv1: false,
2628 };2715 };
2629 process_compound_ref_mv_candidate(&candidate, COMP_PAIR, &NO_SIGN_BIAS, &mut lists);2716 process_compound_ref_mv_candidate(&candidate, COMP_PAIR, &NO_SIGN_BIAS, &mut lists);
2630 assert_eq!(lists.ref_id[0], vec![(5, 5)]);2717 assert_eq!(lists.ref_id[0], vec![(5, 5)]);
@@ -2652,6 +2739,8 @@ mod tests {
2652 is_new_mv: false,2739 is_new_mv: false,
2653 size: 8,2740 size: 8,
2654 size_h: 8,2741 size_h: 8,
2742+ is_global_mv0: false,
2743+ is_global_mv1: false,
2655 },2744 },
2656 );2745 );
2657 grid.set(2746 grid.set(
@@ -2666,10 +2755,12 @@ mod tests {
2666 is_new_mv: false,2755 is_new_mv: false,
2667 size: 8,2756 size: 8,
2668 size_h: 8,2757 size_h: 8,
2758+ is_global_mv0: false,
2759+ is_global_mv1: false,
2669 },2760 },
2670 );2761 );
2671 2762
2672- let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, None);2763+ let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None);
2673 2764
2674 // The combine step (libaom's real "Handle compound reference frame2765 // The combine step (libaom's real "Handle compound reference frame
2675 // extension") zips each side's ref_id-then-ref_diff lists2766 // extension") zips each side's ref_id-then-ref_diff lists
crates/ec-av1/src/stream.rsmodified+65 -2
@@ -211,14 +211,76 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
211 // lane-av1refs widens this from `[0, 3]` (LAST_FRAME/GOLDEN_FRAME)211 // lane-av1refs widens this from `[0, 3]` (LAST_FRAME/GOLDEN_FRAME)
212 // to every one of the 7 single-reference slots `decode_inter_block`212 // to every one of the 7 single-reference slots `decode_inter_block`
213 // can now select.213 // can now select.
214+ //
215+ // lane-gm r2 STEP-8 ATTEMPT (reverted): removing this refusal
216+ // exposed a real pixel mismatch --
217+ // a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact
218+ // seed 43, frame 1 luma, with EC_WEDGE_GATE_ATTEMPTS=20
219+ // EC_AV1_REQUIRE_AOMENC=1 -- so the single-ref/compound MV wiring
220+ // is not yet provably correct end to end; keeping the refusal
221+ // until that seed is captured (EC_AV1_GATE_DUMP), self-pinned, and
222+ // root-caused rather than shipping a wrong decode.
223+ //
224+ // lane-gm r3 ROOT CAUSE (pinned, range-ladder-confirmed, still not
225+ // fixed): the mismatch is NOT an mv/mvstack/entropy bug -- msac
226+ // RANGE at the first divergent block (mi=(8,0), frame 1) matches
227+ // aomdec's own `EC_PART` trace bit-for-bit (rng=38664 both sides),
228+ // and this decoder's own `gm_get_motion_vector` for that block
229+ // (ROTZOOM, seed 43's own header) computes the spec-correct
230+ // mv=(-8,8) (hand-verified against mv.h's `block_center_x`/`_y`,
231+ // which found and fixed a real `- 1` omission in `warp.rs` --
232+ // harmless for THIS block's rounding but a genuine spec bug fixed
233+ // regardless). The actual gap: `reconinter.c`'s `allow_warp` has a
234+ // `global_warp_allowed` branch (`warp_types.global_warp_allowed =
235+ // is_global_mv_block(...)`, `reconinter_enc.c:281`) that predicts
236+ // an `is_global_mv_block` block (ROTZOOM/AFFINE GLOBALMV, >=8x8)
237+ // with the FULL per-pixel affine global-motion warp, independent
238+ // of `motion_mode` -- this decoder only ever builds a warp
239+ // prediction for local `WARPED_CAUSAL` motion mode and falls back
240+ // to plain translational MC with the block-centre mv for every
241+ // other GLOBALMV block, which is only a centre-point approximation
242+ // of the true per-pixel warp. That is the entire remaining gap.
243+ // lane-gm r4: `decode.rs` now feeds `global_motion[ref]` into
244+ // `crate::warp::global_warp_params` for every single-ref
245+ // `is_global_mv_block` (ROTZOOM/AFFINE), matching `allow_warp`'s
246+ // `global_warp_allowed` branch -- ROTZOOM is pin-verified
247+ // (`gm-seed43.obu`, frame 1 luma MATCH) and TRANSLATION already
248+ // worked (`gm_get_motion_vector`'s translation-only mv, no warp
249+ // needed). AFFINE is untested this round (no aomenc fixture in the
250+ // wedge gate reached a 6-parameter model) -- keep refusing it by
251+ // name rather than shipping an unverified decode.
214 if header.frame_type != FrameType::Key252 if header.frame_type != FrameType::Key
215 && header.global_motion[..7]253 && header.global_motion[..7]
216 .iter()254 .iter()
217- .any(|gm| gm.model != WarpModel::Identity)255+ .any(|gm| gm.model == WarpModel::Affine)
218 {256 {
219 return Err(Error::unsupported(257 return Err(Error::unsupported(
220 "AV1 decode_stream",258 "AV1 decode_stream",
221- "an inter frame whose global motion for a single-reference frame is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)",259+ "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
260+ ));
261+ }
262+ // lane-gm r4: a NEW mismatch, distinct from the one this round
263+ // fixed and NOT explained by `reference_select`/compound (traced
264+ // live: the mismatched frame of the seed-43 pin has
265+ // `reference_select == false`) -- localized instead to the one
266+ // property that DOES distinguish it from every frame that already
267+ // matches: TWO different ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`)
268+ // carry a non-translation model AT THE SAME TIME. The pin-verified
269+ // fix (frame 1) only ever exercised a single active non-identity
270+ // slot (`LAST_FRAME` alone). Root cause not yet found within this
271+ // round's budget (do not guess-fix): refuse the untested shape by
272+ // name -- more than one concurrently active ROTZOOM/AFFINE ref --
273+ // rather than ship it silently wrong.
274+ if header.frame_type != FrameType::Key
275+ && header.global_motion[..7]
276+ .iter()
277+ .filter(|gm| gm.model != WarpModel::Identity && gm.model != WarpModel::Translation)
278+ .count()
279+ > 1
280+ {
281+ return Err(Error::unsupported(
282+ "AV1 decode_stream",
283+ "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)",
222 ));284 ));
223 }285 }
224 // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read286 // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read
@@ -386,6 +448,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
386 header.allow_high_precision_mv,448 header.allow_high_precision_mv,
387 header.force_integer_mv,449 header.force_integer_mv,
388 header.ref_frame_sign_bias,450 header.ref_frame_sign_bias,
451+ header.global_motion,
389 interp_fixed,452 interp_fixed,
390 enable_dual_filter,453 enable_dual_filter,
391 order_hint_bits,454 order_hint_bits,
crates/ec-av1/src/tile.rsmodified+16 -0
@@ -2440,6 +2440,8 @@ pub fn sb_coeff_inter_frame_tile(
2440 is_new_mv,2440 is_new_mv,
2441 size: 8,2441 size: 8,
2442 size_h: 8,2442 size_h: 8,
2443+ is_global_mv0: false,
2444+ is_global_mv1: false,
2443 },2445 },
2444 );2446 );
2445 for dr in 0..8 {2447 for dr in 0..8 {
@@ -2459,6 +2461,8 @@ pub fn sb_coeff_inter_frame_tile(
2459 is_new_mv,2461 is_new_mv,
2460 size: 8,2462 size: 8,
2461 size_h: 8,2463 size_h: 8,
2464+ is_global_mv0: false,
2465+ is_global_mv1: false,
2462 },2466 },
2463 );2467 );
2464 }2468 }
@@ -2489,6 +2493,8 @@ pub fn sb_coeff_inter_frame_tile(
2489 is_new_mv: false,2493 is_new_mv: false,
2490 size: 8,2494 size: 8,
2491 size_h: 8,2495 size_h: 8,
2496+ is_global_mv0: false,
2497+ is_global_mv1: false,
2492 },2498 },
2493 );2499 );
2494 }2500 }
@@ -2630,6 +2636,8 @@ fn write_inter_frame_leaf(
2630 is_new_mv,2636 is_new_mv,
2631 size: SUB_MI as usize,2637 size: SUB_MI as usize,
2632 size_h: SUB_MI as usize,2638 size_h: SUB_MI as usize,
2639+ is_global_mv0: false,
2640+ is_global_mv1: false,
2633 },2641 },
2634 );2642 );
2635 }2643 }
@@ -2660,6 +2668,8 @@ fn write_inter_frame_leaf(
2660 is_new_mv: false,2668 is_new_mv: false,
2661 size: SUB_MI as usize,2669 size: SUB_MI as usize,
2662 size_h: SUB_MI as usize,2670 size_h: SUB_MI as usize,
2671+ is_global_mv0: false,
2672+ is_global_mv1: false,
2663 },2673 },
2664 );2674 );
2665 }2675 }
@@ -2824,6 +2834,8 @@ fn write_inter_frame_leaf8(
2824 is_new_mv,2834 is_new_mv,
2825 size: 2,2835 size: 2,
2826 size_h: 2,2836 size_h: 2,
2837+ is_global_mv0: false,
2838+ is_global_mv1: false,
2827 },2839 },
2828 );2840 );
2829 }2841 }
@@ -2854,6 +2866,8 @@ fn write_inter_frame_leaf8(
2854 is_new_mv: false,2866 is_new_mv: false,
2855 size: 2,2867 size: 2,
2856 size_h: 2,2868 size_h: 2,
2869+ is_global_mv0: false,
2870+ is_global_mv1: false,
2857 },2871 },
2858 );2872 );
2859 }2873 }
@@ -5109,6 +5123,8 @@ mod tests {
5109 is_new_mv,5123 is_new_mv,
5110 size: 8,5124 size: 8,
5111 size_h: 8,5125 size_h: 8,
5126+ is_global_mv0: false,
5127+ is_global_mv1: false,
5112 },5128 },
5113 );5129 );
5114 }5130 }
crates/ec-av1/src/warp.rsmodified+165 -0
@@ -46,6 +46,90 @@ fn round2(value: i64, n: u32) -> i64 {
46 (value + (1i64 << n >> 1)) >> n46 (value + (1i64 << n >> 1)) >> n
47 }47 }
48 48
49+/// `GM_TRANS_ONLY_PREC_DIFF` (`av1/common/mv.h`): `WARPEDMODEL_PREC_BITS
50+/// (16) - 3`, the extra precision a `TRANSLATION` global-motion param has
51+/// over a 1/8-pel mv.
52+const GM_TRANS_ONLY_PREC_DIFF: u32 = WARPEDMODEL_PREC_BITS - 3;
53+
54+/// `convert_to_trans_prec` (`av1/common/mv.h`): projects a
55+/// `WARPEDMODEL_PREC_BITS`-fixed-point coordinate down to 1/8-pel
56+/// (`allow_high_precision_mv`) or 1/4-pel-then-doubled (not high precision).
57+fn convert_to_trans_prec(allow_high_precision_mv: bool, x: i64) -> i32 {
58+ if allow_high_precision_mv {
59+ round2_signed(x, WARPEDMODEL_PREC_BITS - 3) as i32
60+ } else {
61+ (round2_signed(x, WARPEDMODEL_PREC_BITS - 2) as i32) * 2
62+ }
63+}
64+
65+/// `lower_mv_precision`'s `force_integer_mv` half, applied per component
66+/// (spec 7.10.2.1's `integer_mv_precision`): rounds a 1/8-pel value to the
67+/// nearest full pel (multiple of 8), ties biased away from zero.
68+fn integer_mv_precision(v: i32) -> i32 {
69+ let md = v % 8;
70+ if md != 0 {
71+ let mut v = v - md;
72+ if md.abs() > 4 {
73+ v += if md > 0 { 8 } else { -8 };
74+ }
75+ v
76+ } else {
77+ v
78+ }
79+}
80+
81+/// `gm_get_motion_vector` (`av1/common/mv.h:231`): the motion vector a
82+/// `GLOBALMV`/`GLOBAL_GLOBALMV` block predicts with, derived from the
83+/// frame's own global-motion model for `ref_frame` at this block's centre
84+/// -- spec 7.10.2.1. `bw4`/`bh4` are the block's size in 4x4 units.
85+/// `IDENTITY` returns `(0, 0)`; `TRANSLATION` keeps the spec's own
86+/// swapped-axis bug (`row` reads `wmmat[0]`, `col` reads `wmmat[1]`) rather
87+/// than "fixing" it -- that is what real encoders/decoders exchange.
88+#[allow(clippy::too_many_arguments)]
89+pub fn gm_get_motion_vector(
90+ model: ec_av1_syntax::WarpModel,
91+ params: &[i32; 6],
92+ mi_row: usize,
93+ mi_col: usize,
94+ bw4: usize,
95+ bh4: usize,
96+ allow_high_precision_mv: bool,
97+ force_integer_mv: bool,
98+) -> (i32, i32) {
99+ use ec_av1_syntax::WarpModel;
100+ let (row, col) = match model {
101+ WarpModel::Identity => (0, 0),
102+ WarpModel::Translation => (
103+ params[0] >> GM_TRANS_ONLY_PREC_DIFF,
104+ params[1] >> GM_TRANS_ONLY_PREC_DIFF,
105+ ),
106+ WarpModel::Rotzoom | WarpModel::Affine => {
107+ // `block_center_x`/`block_center_y` (mv.h:183-191): `- 1`, not
108+ // just the halved block size -- lane-gm r3's root cause, missing
109+ // here made every ROTZOOM/AFFINE GLOBALMV prediction off by a
110+ // sub-pel fraction (small luma delta growing across P-frames as
111+ // it propagates through the reference chain).
112+ let x = (mi_col * MI_SIZE as usize + (bw4 * MI_SIZE as usize) / 2) as i64 - 1;
113+ let y = (mi_row * MI_SIZE as usize + (bh4 * MI_SIZE as usize) / 2) as i64 - 1;
114+ let xc = (params[2] as i64 - (1i64 << WARPEDMODEL_PREC_BITS)) * x
115+ + params[3] as i64 * y
116+ + params[0] as i64;
117+ let yc = params[4] as i64 * x
118+ + (params[5] as i64 - (1i64 << WARPEDMODEL_PREC_BITS)) * y
119+ + params[1] as i64;
120+ (
121+ convert_to_trans_prec(allow_high_precision_mv, yc),
122+ convert_to_trans_prec(allow_high_precision_mv, xc),
123+ )
124+ }
125+ };
126+ if force_integer_mv {
127+ (integer_mv_precision(row), integer_mv_precision(col))
128+ } else {
129+ (row, col)
130+ }
131+}
132+
49 /// `get_msb` (`aom_ports/bitops.h`): index of the highest set bit.133 /// `get_msb` (`aom_ports/bitops.h`): index of the highest set bit.
50 fn get_msb64(n: u64) -> i32 {134 fn get_msb64(n: u64) -> i32 {
51 debug_assert!(n != 0);135 debug_assert!(n != 0);
@@ -316,6 +400,21 @@ pub fn find_projection(
316 })400 })
317 }401 }
318 402
403+/// lane-gm r4: `allow_warp`'s `global_warp_allowed` branch
404+/// (`reconinter.c:50`) -- reuses the SAME shear decomposition
405+/// [`find_projection`]'s local-warp path calls (`get_shear_params`), just
406+/// keyed on the frame's already-coded `global_motion[ref]` model instead of
407+/// a per-block least-squares fit. Caller gates this on `is_global_mv_block
408+/// && !global_motion[ref].invalid` (matching `allow_warp` exactly); `None`
409+/// here means the model's own shear is not filter-representable even though
410+/// the frame header's `warpValid` bit said otherwise for a `mat[2] <= 0`
411+/// edge `get_shear_params` additionally rejects -- caller keeps its
412+/// translational fallback in that rare case.
413+pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams> {
414+ let (alpha, beta, gamma, delta) = get_shear_params(wmmat)?;
415+ Some(WarpParams { wmmat, alpha, beta, gamma, delta })
416+}
417+
319 fn clip_pixel(v: i32) -> u8 {418 fn clip_pixel(v: i32) -> u8 {
320 v.clamp(0, 255) as u8419 v.clamp(0, 255) as u8
321 }420 }
@@ -653,3 +752,69 @@ const DIV_LUT: [u16; 257] = [
653 8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,752 8422, 8405, 8389, 8372, 8355, 8339, 8322, 8306, 8289, 8273, 8257,
654 8240, 8224, 8208, 8192,753 8240, 8224, 8208, 8192,
655 ];754 ];
755+
756+#[cfg(test)]
757+mod gm_mv_tests {
758+ use super::gm_get_motion_vector;
759+ use ec_av1_syntax::WarpModel;
760+
761+ /// `TRANSLATION`: `row = wmmat[0] >> 13`, `col = wmmat[1] >> 13` (spec's
762+ /// own swapped-axis bug, kept). `100000 >> 13 = 12` (`100000 / 8192 =
763+ /// 12.207`, floor 12); `-50000 >> 13 = -7` (`-50000 / 8192 = -6.1035`,
764+ /// floor -7, arithmetic shift rounds toward -inf).
765+ #[test]
766+ fn translation_shifts_params_by_13() {
767+ let params = [100_000, -50_000, 1 << 16, 0, 0, 1 << 16];
768+ let mv = gm_get_motion_vector(WarpModel::Translation, &params, 0, 0, 2, 2, true, false);
769+ assert_eq!(mv, (12, -7));
770+ }
771+
772+ /// `ROTZOOM`, block centre `x = mi_col*4 + bw4*4/2 = 2*4 + 4*4/2 = 16`,
773+ /// `y = mi_row*4 + bh4*4/2 = 1*4 + 4*4/2 = 12`.
774+ /// `xc = (params[2]-2^16)*x + params[3]*y + params[0]`
775+ /// `= 500*16 + 100*12 + 1000 = 8000 + 1200 + 1000 = 10200`.
776+ /// `yc = params[4]*x + (params[5]-2^16)*y + params[1]`
777+ /// `= -50*16 + (-300)*12 + 2000 = -800 - 3600 + 2000 = -2400`.
778+ /// `hp`: `row = Round2Signed(yc,13) = -Round2(2400,13) = -((2400+4096)>>13)
779+ /// = -(6496>>13) = -0 = 0`; `col = Round2Signed(xc,13) =
780+ /// (10200+4096)>>13 = 14296>>13 = 1`.
781+ #[test]
782+ fn rotzoom_projects_block_centre_hp() {
783+ let params = [1000, 2000, (1 << 16) + 500, 100, -50, (1 << 16) - 300];
784+ let mv = gm_get_motion_vector(WarpModel::Rotzoom, &params, 1, 2, 4, 4, true, false);
785+ assert_eq!(mv, (0, 1));
786+ }
787+
788+ /// Same model/geometry as [`rotzoom_projects_block_centre_hp`], not high
789+ /// precision: `convert_to_trans_prec` shifts by 14 instead of 13 then
790+ /// doubles. `row = -Round2(2400,14)*2 = -((2400+8192)>>14)*2 =
791+ /// -(10592>>14)*2 = 0`; `col = Round2(10200,14)*2 = ((10200+8192)>>14)*2
792+ /// = (18392>>14)*2 = 1*2 = 2`.
793+ #[test]
794+ fn rotzoom_projects_block_centre_no_hp() {
795+ let params = [1000, 2000, (1 << 16) + 500, 100, -50, (1 << 16) - 300];
796+ let mv = gm_get_motion_vector(WarpModel::Rotzoom, &params, 1, 2, 4, 4, false, false);
797+ assert_eq!(mv, (0, 2));
798+ }
799+
800+ /// `force_integer_mv`'s `integer_mv_precision`, applied to
801+ /// [`translation_shifts_params_by_13`]'s raw `(12, -7)`: `12 % 8 = 4`,
802+ /// `abs(4) > 4` false, so `12 -> 12-4 = 8`. `-7 % 8 = -7` (Rust's
803+ /// truncating `%`), `abs(-7) > 4` true and `-7 < 0`, so
804+ /// `-7 -> (-7 - (-7)) - 8 = -8`.
805+ #[test]
806+ fn translation_force_integer_mv_rounds_to_full_pel() {
807+ let params = [100_000, -50_000, 1 << 16, 0, 0, 1 << 16];
808+ let mv = gm_get_motion_vector(WarpModel::Translation, &params, 0, 0, 2, 2, true, true);
809+ assert_eq!(mv, (8, -8));
810+ }
811+
812+ #[test]
813+ fn identity_is_always_zero() {
814+ let params = [999, -999, (1 << 16) + 1, 5, 5, (1 << 16) - 1];
815+ assert_eq!(
816+ gm_get_motion_vector(WarpModel::Identity, &params, 3, 4, 4, 4, true, false),
817+ (0, 0)
818+ );
819+ }
820+}
lanes/gm-r1.charter.mdadded+82 -0
@@ -0,0 +1,82 @@
1+# lane-gm r1 charter — non-IDENTITY global motion decodes (GLOBALMV + global warp MC)
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-gm, branch lane-gm @ 2143b92.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-gm cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink.
7+BUDGET ~60 calls: WIP COMMIT after every green milestone; commit compiling state + report by call 45. Recon is pre-done below — do not re-derive it.
8+
9+## Measured motivation
10+The wedge-interintra gate refuses 25-29/40 attempts with "global motion ...
11+not IDENTITY" — mandelbrot's pan/zoom makes aomenc code ROTZOOM/TRANSLATION
12+global motion. Killing this refusal converts those attempts to decodes.
13+
14+## Recon already done (anchors, do not re-search)
15+- Frame-header params ALREADY PARSED: ec-av1-syntax frame.rs
16+ read_global_motion_params (~1709) fills header.global_motion[7] with
17+ WarpParams { model: WarpModel, params/wmmat }. Read its struct shape first.
18+- The whole-frame refusal to remove: crates/ec-av1/src/stream.rs ~204-218
19+ (`any(|gm| gm.model != WarpModel::Identity)`).
20+- Single-ref GLOBALMV site: decode.rs ~6041-6070 (`is_globalmv = !not_zero`;
21+ the GLOBALMV arm currently assigns mv (0,0)).
22+- Compound GLOBAL_GLOBALMV: decode.rs ~5378 (`compound_mode == 6`), also
23+ assigns zeros today.
24+- mvstack pad/default candidates: crates/ec-av1/src/mvstack.rs — the stack
25+ pads short lists with (0,0) entries; libaom pads with
26+ gm_get_motion_vector results for the block's ref (setup_ref_mv_list's
27+ gm_mv_candidates). grep `0, 0` pad sites + the module doc.
28+- Our warp machinery (from WARPED_CAUSAL): crates/ec-av1/src/warp.rs
29+ `warp_affine` (~329) + shear derivation. Global warp MC reuses it with the
30+ GLOBAL wmmat instead of the locally-derived one.
31+- Interp-filter read suppression: decode.rs ~6166-6200 comments
32+ (`is_nontrans_global_motion`, warp-verify caveat: current suppression
33+ assumes IDENTITY globals). libaom av1_is_interp_needed
34+ (av1/common/reconinter.c) returns false when the block uses a
35+ NON-TRANSLATION global model spanning >=8x8 — with non-IDENTITY globals
36+ live this read-suppression condition MUST be ported exactly or every
37+ GLOBALMV block bit-drifts.
38+
39+## libaom ground truth (read these, transcribe exactly)
40+- /tmp/libaom-src/av1/common/mv.h:231 gm_get_motion_vector: block-center
41+ derivation, TRANSLATION/ROTZOOM/AFFINE cases, allow_hp/force_integer
42+ rounding (is_integer), the >>3 / OFFSET semantics. This feeds BOTH
43+ assign_mv and the mvstack gm candidates.
44+- /tmp/libaom-src/av1/common/reconinter.c av1_allow_warp + the
45+ global-warp branch of av1_build_inter_predictor / warp path selection
46+ (when is_global fires warp_plane vs plain MC with the derived mv):
47+ block >=8x8, no scaling here.
48+- /tmp/libaom-src/av1/common/warped_motion.c av1_get_shear_params — global
49+ params must pass shear validation or fall back (av1_warp checks
50+ wm->invalid? read how decode handles invalid global params).
51+
52+## Scope (in order, WIP commit each)
53+1. Port gm_get_motion_vector into decode (or warp.rs) with unit tests
54+ pinning a few (wmmat, center, hp/int) -> mv values TRANSCRIBED from a
55+ hand-run of the C formula (show the arithmetic in the test comments).
56+2. Thread header.global_motion into decode_inter_block/decode_inter_block8:
57+ GLOBALMV single-ref + GLOBAL_GLOBALMV compound assign the derived mv;
58+ mvstack gm candidates (pass the gm params into find_mv_stack pad sites
59+ per libaom setup_ref_mv_list).
60+3. MC: blocks whose mode is GLOBALMV (or whose selected mv comes from a
61+ non-translation global model per av1_allow_warp) go through warp_affine
62+ with the global wmmat + shear params; TRANSLATION model = plain MC with
63+ the derived mv. Port av1_is_interp_needed's global condition at the
64+ interp-filter read.
65+4. Remove the stream.rs whole-frame refusal.
66+5. GATE LADDER: (a) 14-pin default list; (b) wedge-interintra gate
67+ a_real_aomenc_stream_with_interintra_wedge (its 25-29/40 global-motion
68+ refusals must DROP — print before/after refusal counts in the report;
69+ any new mismatch = EC_AV1_GATE_DUMP self-pin /tmp/claude-1000/gm-flake-N.obu,
70+ report the pin + recon-diff location, do NOT guess-fix);
71+ (c) free-partition + AB gates; (d) full lib suite EXCEPT run the wedge
72+ gate separately (it is slow): `-- --skip a_real_aomenc_stream_with_interintra_wedge`.
73+6. If mismatches appear (likely — this is a value-heavy port): pin, localize
74+ with EC_AV1_PREFILT_DUMP both sides + the EC_AV1_TELL ladder, fix the
75+ earliest divergence only, iterate. Landing with SOME streams still
76+ mismatching = report the pins and leave the stream.rs refusal for exactly
77+ the model kinds still broken (e.g. keep refusing AFFINE, decode
78+ TRANSLATION/ROTZOOM) rather than shipping a wrong decode.
79+
80+## Done criteria
81+Refusal narrowed or gone with pixel-exact evidence; gates green; wip commits;
82+REPORT lanes/gm-r1.report.md, verdict FIRST line, refusal-count before/after.
lanes/gm-r1.handoff.mdadded+29 -0
@@ -0,0 +1,29 @@
1+HANDOFF: Recon phase complete, zero edits, zero commits, tree clean at 2143b92. Tool-call cap (60) hit mid-recon — everything below is verified from source reads; nothing speculative.
2+
3+**What the change actually is (libaom semantics nailed down):**
4+
5+1. **No new warp MC path exists.** `motion_mode_allowed` (blockd.h:1472) returns SIMPLE_TRANSLATION for `is_global_mv_block` blocks (mode GLOBALMV/GLOBAL_GLOBALMV, bsize≥8x8, gm type > TRANSLATION) when `cur_frame_force_integer_mv == 0`. GLOBAL blocks' gm-derived mv goes through the **existing** `inter_predict`. warp.rs untouched.
6+2. **gm_get_motion_vector** (mv.h:231): IDENTITY→(0,0); TRANSLATION→ row=`wmmat[0]>>13`, col=`wmmat[1]>>13` (**spec bug: swapped axes, keep it**; GM_TRANS_ONLY_PREC_DIFF=16−3=13); ROTZOOM/AFFINE→ center point x=`mi_col*4+w/2`, y=`mi_row*4+h/2`; xc=`(mat[2]−2^16)·x+mat[3]·y+mat[0]`, yc=`mat[4]·x+(mat[5]−2^16)·y+mat[1]`; then `convert_to_trans_prec(allow_hp, ·)` = sign-rounded >>3 (hp) / >>4. `is_integer` (force_integer_mv) → full-pel rounding.
7+3. **Two distinct predicates — the key trap:** `is_global_mv_block` needs wmtype **> TRANSLATION** (IDENTITY and TRANSLATION both false); `is_nontrans_global_motion` (filter suppression, reconinter.h:420) excludes only wmtype **== TRANSLATION**, so **IDENTITY counts as nontrans**. Current decode.rs `resolve_interp_filter` suppress arg `is_globalmv || warped_selected` is correct under all-IDENTITY and must become `(is_globalmv && gm.model != Translation) || warped_selected`.
8+4. **motion_mode gate:** add `&& !(is_globalmv && gm.model > Translation)` when `!force_integer_mv` (site ~6180 `motion_mode_eligible`, plus decode_inter_block8's 8x8 leaf ~6965). GLOBALMV under TRANSLATION gm still reads OBMC/WARPED(local fit).
9+5. **mvstack:** neighbours in GLOBAL mode contribute the **current block's** gm_mv (not their own mv) — needs `MiInfo.is_global_mv: bool` (3 ctor sites decode.rs ~5416 compound, ~6348 single, ~6600) + `gm_mv`/`gm_active` threaded through `find_mv_stack_with_sign_bias` and `find_mv_stack_compound` into the scan/add-candidate + empty-stack pad (mvref_common.c add_ref_mv_candidate ~700-780, setup_ref_mv_list pad ~790).
10+6. **Compound GLOBAL_GLOBALMV:** mv=gm_mv[0], mv1=gm_mv[1] from gm of each ref (decode.rs ~5378, `is_globalmv = compound_mode == 6` already computed).
11+7. **Refusal:** stream.rs ~203-218 (never actually read — grep pattern failed); narrow or delete per charter step 6.
12+
13+**Exact next steps (order):** (a) read stream.rs:190-230; (b) read mvref_common.c 700-800 full (artifact://5's middle was elided — add_ref_mv_candidate + pad need exact bodies, incl. whether gm candidates get clamp_mv'd); (c) decodemv.c `read_inter_compound_mode` + `av1_init_warp_params` bodies; (d) mv.h integer_mv_precision/convert_to_trans_prec + confirm WarpParams field names (frame.rs:368 `model` + params array); (e) implement in order mvstack.rs → decode.rs single-ref → compound → gates → stream.rs; (f) unit tests for gm mv (hand-computed TRANSLATION shift + ROTZOOM projection) + mvstack gm-candidate test; (g) gate ladder per charter, `--skip a_real_aomenc_stream_with_interintra_wedge`; (h) mismatch ladder EC_AV1_PREFILT_DUMP/EC_AV1_TELL. Build: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-gm CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib <name> -- --nocapture`. WIP commit per green milestone; report lanes/gm-r1.report.md, verdict first line. ~46 calls remain fresh.
14+
15+DELTA:
16+fact|decode.rs:6063 — GLOBALMV mv hardcoded (0,0), comment names stream.rs IDENTITY refusal
17+fact|mv.h:231 gm_get_motion_vector — IDENTITY→0; TRANSLATION row=wmmat[0]>>13 col=wmmat[1]>>13 (spec bug, keep); ROTZOOM/AFFINE center projection, convert_to_trans_prec sign-round >>3(hp)/>>4
18+fact|blockd.h:1472 motion_mode_allowed — is_global_mv_block→SIMPLE only when cur_frame_force_integer_mv==0; TRANSLATION-gm GLOBAL blocks still get OBMC/WARPED(local)
19+fact|blockd.h is_nontrans_global_motion — false only when wmtype==TRANSLATION; IDENTITY counts as nontrans; is_global_mv_block needs >TRANSLATION — two predicates, never unify
20+fact|reconinter.h:420 av1_is_interp_needed — skip_mode→0; nontrans-global→0; motion_mode==WARPED_CAUSAL→0
21+fact|mvstack port needs MiInfo.is_global_mv (ctor sites decode.rs ~5416/~6348/~6600) + gm_mv/gm_active through find_mv_stack_with_sign_bias + find_mv_stack_compound; candidates use CURRENT block's gm_mv; pad tail uses gm too (bodies NOT yet read — artifact://5 middle elided)
22+fact|compound GLOBAL_GLOBALMV mvs from gm_mv[0]/gm_mv[1]; read_inter_compound_mode body NOT yet read
23+fact|decode.rs:5615,6198 — resolve_interp_filter already takes suppress flag; narrow to (is_globalmv && model!=Translation)||warped_selected
24+decision|thread gm as one more decode_inter_block/decode_inter_block8 arg (house style, ~40-arg fns), no new params struct
25+dead-end|grep "MiInfo {" finds nothing — struct literals don't match; ctor sites are 5416/6348/6600 (sed those spans)
26+dead-end|shell $(grep -n …) substitution in my first two batch commands silently ran empty greps — use direct grep -n
27+open|gm candidates clamped in add_ref_mv_candidate? — read exact body
28+open|av1_init_warp_params + read_inter_compound_mode exact bodies; integer_mv_precision body; GM_*_PREC constants
29+open|WarpParams field names frame.rs:368 — parser fills params[idx] = (value << prec_diff) + round; wmmat[0..5] ↔ params[0..5] same order (confirm)
lanes/gm-r2.charter.mdadded+81 -0
@@ -0,0 +1,81 @@
1+# lane-gm r2 charter — CONTINUATION. r1 was pure recon; its HANDOFF is committed at lanes/gm-r1.handoff.md (d9890e3). READ THAT FIRST, then this.
2+
3+Worktree /home/user/Documents/Code/Rust/edith_codecs-gm, branch lane-gm (main merged: the aomenc oracle now lives at ~/.cache/aom-oracle, gates work).
4+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-gm CARGO_BUILD_JOBS=4 nice -n 19 cargo test -p ec-av1 --release --lib <name> -- --nocapture`
5+FOREGROUND. Never push. BUDGET ~55 calls: WIP COMMIT after every green milestone; commit + report by call 45.
6+libaom source oracle: ~/.cache/aom-oracle/src (NOT /tmp any more).
7+
8+## r1's open items — ALL RESOLVED by the orchestrator, do NOT re-read these
9+1. `gm_get_motion_vector` (mv.h:231) confirmed verbatim, incl. the spec's
10+ swapped-axis TRANSLATION bug (`row = wmmat[0] >> 13`, `col = wmmat[1] >> 13`,
11+ GM_TRANS_ONLY_PREC_DIFF = 16-3). ROTZOOM/AFFINE:
12+ `x = block_center_x(mi_col,bsize)`, `y = block_center_y(mi_row,bsize)`,
13+ `xc = (mat[2] - (1<<16))*x + mat[3]*y + mat[0]`,
14+ `yc = mat[4]*x + (mat[5] - (1<<16))*y + mat[1]`,
15+ `row = convert_to_trans_prec(hp, yc)`, `col = convert_to_trans_prec(hp, xc)`.
16+ `convert_to_trans_prec(hp,c)` = `ROUND_POWER_OF_TWO_SIGNED(c, 13)` when hp
17+ else `ROUND_POWER_OF_TWO_SIGNED(c, 14) * 2`.
18+ `is_integer` (force_integer_mv) -> `integer_mv_precision`: per component,
19+ `mod = v % 8; if mod != 0 { v -= mod; if abs(mod) > 4 { v += mod > 0 ? 8 : -8 } }`.
20+2. WarpParams (crates/ec-av1-syntax/src/frame.rs:366): `params[0..6]` IS
21+ `wmmat[0..6]`, same order, same WARPEDMODEL_PREC_BITS fixed point; `model`
22+ is GmType; `invalid` is already computed (`warp_valid`). Nothing to add
23+ to the parser.
24+3. gm candidates are NOT clamped in add_ref_mv_candidate; they are passed in
25+ as `gm_mv_candidates[2]` computed ONCE per block (mvref_common.c:795-830)
26+ from the CURRENT block's centre, and every scan receives them.
27+
28+## One site r1 MISSED (orchestrator found it) — must be in scope
29+`setup_ref_mv_list`'s temporal path compares candidates against the gm mv, not
30+against zero: mvref_common.c:369-370 (single) and :397-400 (compound) use
31+`abs(this_refmv - gm_mv_candidates[0]) >= 16` for the `zero_mv_ctx` decision.
32+Ours hardcodes the zero comparison in mvstack.rs (`first_sample_far =
33+cand.mv.0.abs() >= 16 || cand.mv.1.abs() >= 16`). That is a MODE CONTEXT input,
34+so getting it wrong is an ENTROPY desync, not a pixel error. Fix it with the
35+rest.
36+
37+## Implementation order (WIP commit each)
38+1. `gm_get_motion_vector` port + unit tests: one TRANSLATION case and one
39+ ROTZOOM case, expected values hand-computed IN THE TEST COMMENT showing the
40+ arithmetic (both hp and !hp), plus a force_integer_mv case.
41+2. mvstack: thread `gm_mv: [(i32,i32); 2]` + a per-neighbour `is_global_mv`
42+ flag (new `MiInfo` field; ctor sites decode.rs ~5416/~6348/~6600 per r1)
43+ into `find_mv_stack_with_sign_bias` and `find_mv_stack_compound`:
44+ - a neighbour that `is_global_mv_block` contributes the CURRENT block's
45+ `gm_mv[ref]`, not its own mv (mvref_common.c:88-92, 116-117);
46+ - `is_global_mv_block` = mode is GLOBALMV/GLOBAL_GLOBALMV AND bsize >= 8x8
47+ AND `gm.wmtype > TRANSLATION` (blockd.h; IDENTITY and TRANSLATION are
48+ both FALSE here);
49+ - the `zero_mv_ctx` comparison above.
50+ Square/IDENTITY callers must be unchanged — the 14-pin list proves it.
51+3. decode.rs: GLOBALMV single-ref (~6041-6070, currently hardcodes (0,0)) and
52+ GLOBAL_GLOBALMV compound (~5378) assign the derived mv(s).
53+4. Filter suppression — THE TRAP, two DIFFERENT predicates, never unify:
54+ `is_nontrans_global_motion` (reconinter.h ~420, used by
55+ `av1_is_interp_needed`) is false ONLY when `wmtype == TRANSLATION`, so
56+ IDENTITY COUNTS AS NONTRANS. Our `resolve_interp_filter` suppress arg is
57+ `is_globalmv || warped_selected` today, which is right only because every
58+ model is IDENTITY; it must become
59+ `(is_globalmv && gm.model != Translation) || warped_selected`.
60+5. motion_mode: `motion_mode_allowed` returns SIMPLE_TRANSLATION for an
61+ `is_global_mv_block` block when `!cur_frame_force_integer_mv` — so those
62+ blocks read NO motion_mode symbol (sites ~6180 and the 8x8 leaf ~6965).
63+ GLOBALMV under a TRANSLATION model still reads OBMC/WARPED normally.
64+6. MC: no new warp path (r1 verified) — global blocks predict through the
65+ existing `inter_predict` with the derived mv.
66+7. stream.rs: narrow/remove the whole-frame refusal (~203-218).
67+
68+## Gate ladder (in order)
69+(a) 14-pin default list (`pinned_warp_stream_decodes_pixel_exact -- --ignored`);
70+(b) `a_real_aomenc_stream_with_interintra_wedge` — its 25-29/40 global-motion
71+ refusals MUST drop; print before/after counts in the report;
72+(c) free-partition + AB gates; (d) full lib
73+ `-- --skip a_real_aomenc_stream_with_interintra_wedge`.
74+Any mismatch: `EC_AV1_GATE_DUMP=/tmp/claude-1000/gm-flake-N.obu` self-pin, then
75+report the pin + the recon-diff location (EC_AV1_PREFILT_DUMP both sides).
76+Do NOT guess-fix. Landing with AFFINE still refused while TRANSLATION/ROTZOOM
77+decode pixel-exact is a GOOD outcome; shipping a wrong decode is not.
78+
79+## Done criteria
80+Refusal narrowed or gone with pixel-exact evidence + refusal-count delta;
81+gates green; wip commits; report lanes/gm-r2.report.md, verdict FIRST line.
lanes/gm-r2.report.mdadded+34 -0
@@ -0,0 +1,34 @@
1+VERDICT: PARTIAL -- compiles, all inertness/regression gates green (227/0 full lib, AB/free-partition gates green, wedge gate green on retry after a confirmed flake), but the whole-frame IDENTITY-only refusal in stream.rs was NOT narrowed: doing so exposed a real pixel mismatch (seed 43, frame 1 luma) on the interintra-wedge gate, so it stays in place. Non-IDENTITY global motion still refuses by name at the stream level; the internal decode/mvstack wiring (steps 1-6) is complete and compiles, but is unproven end to end.
2+
3+## What changed
4+- `crates/ec-av1/src/decode.rs`: single-ref path now computes `is_global_mv_block` (blockd.h:421-429 -- mode GLOBAL* AND model > TRANSLATION AND min(bw,bh)>=8px) and `gm_nontrans` (reconinter.h:420-425 -- model != TRANSLATION, IDENTITY counts) as two separate locals, right after `is_globalmv`/`mv` are resolved. `gm_nontrans` now gates the single-ref `resolve_interp_filter` suppress arg (was `is_globalmv`); `is_global_mv_block` now gates `motion_mode_eligible` (`&& !(is_global_mv_block && !force_integer_mv)`, implicit SIMPLE_TRANSLATION) and `MiInfo::is_global_mv0`.
5+- `decode_inter_block` gained a `global_motion: &[WarpParams; 7]` param, threaded to all 18 call sites in `decode_inter_frame_tile_with_cdfs` plus the standalone unit-test call site and the `decode_inter_frame_tile` (no-cdfs) wrapper (`[WarpParams::default(); 7]`).
6+- `decode_inter_frame_tile_with_cdfs` gained the same param, threaded from `stream.rs`'s `header.global_motion`.
7+- `decode_inter_block8` (leaf8) stays gm-inert by design: its `find_mv_stack_compound` call got `&crate::mvstack::NO_GM_MV`, its `assign_compound_mv` call got `((0,0),(0,0))` -- compile-only fixes, its own GLOBALMV refusal (decode.rs ~7466) is untouched and still guards this leaf.
8+- `mvstack.rs`'s own unit tests (`find_mv_stack_compound` call sites) got `&NO_GM_MV` too (compile fix, same shape).
9+- `stream.rs`'s whole-frame `global_motion != IDENTITY` refusal: attempted removal (step 8), reverted same round -- see Dead-end below. Net diff there is a doc-comment only.
10+
11+## Gate ladder (in order, per charter)
12+a. `cargo test -p ec-av1 --release --lib pinned -- --ignored --nocapture`: 2 passed (golden7, warp), 4 failed -- all 4 are pre-existing env-only gaps unrelated to gm (golden3/golden4 read a hardcoded path into a DIFFERENT prior session's scratchpad UUID that doesn't exist on this box; `scratch_decode_pinned_stream_once`/`scratch_isolate_pinned_mismatch` require `EC_AV1_PIN` set manually, by design). No IDENTITY-gm pin moved.
13+b. `EC_AV1_REQUIRE_AOMENC=1 cargo test ... a_real_aomenc_stream_with_interintra_wedge -- --nocapture`: first run FAILED on `wii_hits==0` (12/40 matched, 0 wedge fires) -- reproduced the documented parallel-flake-is-attempt-selection class, NOT a gm regression (all 12 matched streams are IDENTITY-gm since the whole-frame refusal was still in place at that point). Rerun: `ok`, 30 other-capability refusals / 10 matches / wii_hits=7. Refusal count both runs: 27/40 and (unlogged, similar) named "global motion...not IDENTITY" -- within the charter's 25-29/40 baseline, i.e. unchanged (expected, since step 8 wasn't landed yet at that point).
14+c. AB + free-partition gates: both `ok` (`a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact`, `a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact`), rect_partition_hits=18, extended_partition_hits=1, partab_hits=7/2 across the two runs.
15+d. `cargo test -p ec-av1 --release --lib -- --skip a_real_aomenc_stream_with_interintra_wedge`: 227 passed, 0 failed, 17 ignored, 1 filtered.
16+
17+## Step 8 (narrowing the whole-frame refusal) -- attempted, reverted
18+Removed the `header.global_motion != IDENTITY` whole-frame refusal in `stream.rs` and reran the AB/free-partition/wedge gates with `EC_AV1_REQUIRE_AOMENC=1 EC_WEDGE_GATE_ATTEMPTS=20 EC_RECTGATE_ATTEMPTS=20`:
19+- AB partitions: `ok`, 17 named refusals / 3 matches, **zero** "global motion" refusals logged (confirms the narrowing itself worked mechanically).
20+- Free partitions: `ok`, similarly zero gm refusals.
21+- Interintra-wedge: **FAILED** -- `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact frame 1 luma vs ffmpeg (seed 43)` pixel mismatch, decode.rs:3821 assert.
22+
23+This is a real defect somewhere in the single-ref/compound GLOBALMV wiring (steps 1-6), not proven safe to ship. Reverted the stream.rs removal (restored the refusal, kept everything else) rather than land a wrong decode per the charter's own instruction. Compiled clean after revert, committed (2e23ae3).
24+
25+## Dead-ends / open
26+dead-end: lane-gm r2 step-8 -- narrowing the whole-frame `global_motion != IDENTITY` refusal in stream.rs decodes AB/free-partition gates clean (0 gm refusals, both green) but mismatches pixel-exact on `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact` seed 43 frame 1 luma (`EC_WEDGE_GATE_ATTEMPTS=20 EC_AV1_REQUIRE_AOMENC=1`) -- a real defect in the single-ref/compound GLOBALMV MV/interp/motion-mode wiring, not yet root-caused. Refusal reverted/restored.
27+open: next round should reproduce seed 43 with `EC_AV1_GATE_DUMP=<scratchpad>/gm-flake-1.obu` set on that same recipe (48/64px gradients+mandelbrot, `--cq-level=45 --cpu-used=0 --auto-alt-ref=1 --lag-in-frames=16 --enable-fwd-kf=0 --enable-order-hint=1 --enable-warped-motion=1 --enable-obmc=1 --enable-interintra-comp=1 --enable-interintra-wedge=1 ...` -- the full args list is in `stream.rs`'s `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`), self-pin it, and range-ladder against aomdec `EC_TRACE` on the GLOBALMV blocks in frame 1 to find whether the desync is in `gm_get_motion_vector`'s per-model math, the mv-stack neighbour substitution, `is_global_mv_block`/`gm_nontrans` predicate boundary, or `build_gm_mv_table`'s per-block-position recompute.
28+
29+## Files touched
30+- `crates/ec-av1/src/decode.rs` -- gm predicates, threading, leaf8 compile stubs
31+- `crates/ec-av1/src/stream.rs` -- `header.global_motion` threaded to the call; whole-frame refusal doc-comment updated (refusal itself unchanged, net)
32+- `crates/ec-av1/src/mvstack.rs` -- own test call sites' `NO_GM_MV` compile fix
33+
34+Commits (branch lane-gm, worktree edith_codecs-gm): a53b294 (compiles), 208e89e (test compile fix), 2e23ae3 (step-8 attempt + revert, documented).
lanes/gm-r3.report.mdadded+39 -0
@@ -0,0 +1,39 @@
1+VERDICT: ROOT-CAUSED, NOT FIXED -- the interintra-wedge gate mismatch (seed 43, frame 1 luma) is not an mv, mvstack, or entropy bug; it is a missing decoder capability. This decoder never implements AV1's GLOBAL WARP prediction path (`reconinter.c`'s `allow_warp` -> `global_warp_allowed` branch): libaom predicts every `is_global_mv_block` block (ROTZOOM/AFFINE `GLOBALMV`/`GLOBAL_GLOBALMV`, >=8x8, non-force-integer-mv) with the FULL per-pixel affine global-motion warp, independent of `motion_mode` -- our decoder only ever builds a warp prediction for local `WARPED_CAUSAL` and falls back to plain translational MC using the block-centre mv for every other GLOBALMV block. The whole-frame `global_motion != IDENTITY` refusal in `stream.rs` stays in place; it is still correct to refuse.
2+
3+## Method (charter ladder, steps 1-3)
4+
5+**1. Reproduce and pin.** Gated the whole-frame refusal behind a temporary `EC_GM_ALLOW_NONIDENTITY` env var (reverted before commit), ran `EC_WEDGE_GATE_ATTEMPTS=20 EC_AV1_REQUIRE_AOMENC=1 EC_AV1_GATE_DUMP=<scratchpad>/gm-seed43.obu`. Reproduced deterministically first attempt: seed 43, frame 1 luma mismatch, pinned to `gm-seed43.obu`. Decoded the pinned bytes twice via `scratch_isolate_pinned_mismatch` (`EC_AV1_PIN=gm-seed43.obu EC_AV1_PIN_W=64 EC_AV1_PIN_H=64 EC_AV1_PIN_N=24`) -- byte-identical output both runs (only the timing line differed), confirming this is a real deterministic defect, not the documented parallel-flake-is-attempt-selection class.
6+
7+**2. Localize.** `scratch_isolate_pinned_mismatch`'s per-plane diff: frame 0 (key) MATCH on all 3 planes; frame 1 first divergence at luma offset 2048 = **row 32, col 0** (416 mismatches, worst delta 6) -- exactly the top-left corner of the bottom-left 32x32 partition leaf (frame is forced to 32x32 leaves via `--min/max-partition-size=32`), i.e. block `mi=(8,0)`. Frame 1's `global_motion` table (dumped via a temporary debug `eprintln!`, reverted): ref slot 0 (LAST_FRAME) = `Rotzoom { params: [137216, 144384, 61182, -64, 64, 61182] }`, all other refs Identity. `allow_high_precision_mv=false force_integer_mv=false` for this frame.
8+
9+**3. Range ladder (prediction vs entropy).** `EC_AV1_TRACE=1` on our decode: `TRACE part32_pre mi=(8,0) rng=38664` immediately before `EC_TRACE mi_row=8 mi_col=0 skip=0 mv=(-8,8) is_new_mv=false bsize=32 ref=1 motion_mode_eligible=0`. `EC_TRACE=1 aomdec` on the identical pinned bytes: `EC_PART mi_row=8 mi_col=0 bsize=9 ctx=8 tell=1001 rng=38664` (frame 1's own entry, matched by tell-count ordering). **RANGE IDENTICAL: 38664 == 38664** -- entropy decode is in sync through this block's partition/mode symbols. Verdict: PREDICTION-side defect, not a symbol-consumption/CDF bug.
10+
11+## Root cause
12+
13+Hand-verified our `gm_get_motion_vector` (`warp.rs`) against the real oracle's `mv.h:183-286` (`~/.cache/aom-oracle/src/av1/common/mv.h`, foreign implementation, not our own transcription): found and fixed a genuine bug -- `block_center_x`/`block_center_y` (mv.h:183-191) subtract 1 from the halved-block-size offset (`mi_col*MI_SIZE + bw/2 - 1`); our `warp.rs` was missing the `- 1` on both axes. Fixed in `warp.rs`. This is a real spec-conformance bug (kept fixed) but hand-computing both versions for this exact block showed the `-1` shifts `xc`/`yc` by only ~4354 out of a ~16384 rounding threshold in `convert_to_trans_prec` -- **it does not flip the rounded mv for this block** (confirmed empirically: 417 -> 416 mismatches, same first offset, same magnitude, before/after the fix). So it is real but not sufficient, and not the seed-43 root cause.
14+
15+Re-derived `gm_get_motion_vector`'s output for block `mi=(8,0)`, `bw4=bh4=8` by hand with the fixed formula: `x=15, y=47`, giving `mv=(-8,8)` -- **exactly what the trace shows** (`mv=(-8,8)`). The mv-stack/mvstack.rs wiring was also independently re-audited against the oracle's `mvref_common.c`: `add_ref_mv_candidate` (75-135, gm-substitutes) maps correctly to `single_ref_match`/`scan_row_compound` etc.; `process_single_ref_mv_candidate`/`process_compound_ref_mv_candidate` (350-472, must NOT substitute) map correctly to our functions of the same name, which correctly use raw `candidate.mv`/`.mv1` with no gm substitution. This wiring is provably correct against the charter's own named concern.
16+
17+So: entropy in sync, mv computation matches the (now spec-correct) oracle formula exactly, mvstack substitution correctly scoped, motion_mode correctly suppressed (`motion_mode_eligible=0` since `is_global_mv_block && !force_integer_mv`) -- yet the pixel is still off by a small, block-localized, frame-to-frame-growing delta (417 mismatches in frame 1/2, ballooning to ~3900 by frame 23 as the error propagates through the reference chain -- consistent with a systematic per-pixel prediction error, not entropy garbage). Traced this to `reconinter.c`'s `allow_warp` (`~/.cache/aom-oracle/src/av1/common/reconinter.c:33-55`): its `global_warp_allowed` branch is set by the real encoder as `is_global_mv_block(mi, wm->wmtype)` (`reconinter_enc.c:281`) -- the SAME predicate our decoder already computes and correctly uses to suppress `motion_mode`, but which we never feed into the actual per-pixel prediction. `av1_init_warp_params` is called unconditionally for every inter block's predictor build (not gated on `motion_mode`); when `global_warp_allowed` and the global model is valid, it uses the block's FULL affine model (not the block-centre-derived integer mv) to warp-predict every pixel individually. Our decoder's `warp_params: Option<WarpParams>` is populated ONLY when `motion_mode == WARPED_CAUSAL` (local warp) -- every `GLOBALMV`/`GLOBAL_GLOBALMV` block with a non-translation model falls through to plain translational MC using the block-centre mv, which is only a centre-point approximation of the true per-pixel warp and diverges more the further a pixel sits from the block centre -- matching the observed error shape exactly (small at the block's near corner, growing, and compounding across P-frames).
18+
19+## Refusal count (wedge gate, `EC_AV1_REQUIRE_AOMENC=1`)
20+
21+- Before this round (refusal in place): 27 other-capability refusals / 13 matches / wii_hits=6-7 out of 40 (r2 baseline).
22+- With the whole-frame refusal REMOVED (diagnostic only, reverted): 0 gm refusals, real pixel mismatch at seed 43 frame 1 (reproduced this round).
23+- After this round (refusal restored, `warp.rs` fix landed): 27 other-capability refusals / 13 matches / wii_hits=3 out of 40 -- unchanged shape, still `ok` (the global-motion refusal is still one of the 27 named refusals; it is correct to keep it).
24+
25+## What is NOT fixed
26+
27+Implementing the global-warp prediction path itself: this needs `is_global_mv_block`'s already-computed value fed into a new "predict with `global_motion[ref]` as the affine model" branch in the block reconstruction pipeline (reuse `crate::warp::warp_affine`, the same 8x8-tiled warped filter the local `WARPED_CAUSAL` path already has, just keyed off `global_motion[ref]` instead of the locally-estimated `wm_params`), gated exactly on `is_global_mv_block && !global_motion[ref].invalid` (matching `allow_warp`'s `global_warp_allowed` branch, independent of `motion_mode`). That is real, scoped, next-round work -- not guessed at this round per the charter's "do not guess-fix" instruction.
28+
29+## Files touched
30+- `crates/ec-av1/src/warp.rs` -- `gm_get_motion_vector`'s ROTZOOM/AFFINE branch: added the missing `- 1` to both `x`/`y` block-centre offsets (`block_center_x`/`block_center_y`, mv.h:183-191), a genuine spec-conformance fix found via the oracle diff, kept even though it did not resolve seed 43.
31+- `crates/ec-av1/src/stream.rs` -- doc comment on the whole-frame refusal updated with this round's root-cause finding (refusal itself unchanged, still in place). Diagnostic env-var gate and debug `eprintln!` added and reverted before commit (net: comment-only + the one real `warp.rs` fix; no functional change to `stream.rs`'s refusal behaviour).
32+
33+## Gate ladder
34+- `scratch_isolate_pinned_mismatch` (pin, twice): deterministic, byte-identical.
35+- `cargo test -p ec-av1 --release --lib -- --skip a_real_aomenc_stream_with_interintra_wedge`: 227 passed, 0 failed, 17 ignored, 1 filtered.
36+- `EC_AV1_REQUIRE_AOMENC=1 cargo test ... a_real_aomenc_stream_with_interintra_wedge`: `ok`, 27/40 refusals, 13/40 matches, wii_hits=3 (refusal restored, unchanged shape from r2).
37+
38+## Next round
39+Wire `is_global_mv_block && !global_motion[ref].invalid` into the block predictor to select global-affine-warp prediction (reuse `warp::warp_affine` keyed on `global_motion[ref]` instead of the locally-fit `wm_params`), independent of `motion_mode`. Re-run this exact pin (`gm-seed43.obu`, kept in the scratchpad this round -- not committed to the repo, re-capture with the same `EC_AV1_GATE_DUMP` recipe if needed) to confirm frame 1 luma goes to MATCH before attempting to narrow/remove the whole-frame refusal again.
lanes/gm-r4.report.mdadded+41 -0
@@ -0,0 +1,41 @@
1+VERDICT: FIXED (single-ref global-warp path landed and pin-verified) -- a distinct, narrower, NOT-yet-fixed shape found and safely refused by name, not guess-fixed.
2+
3+## What was implemented
4+
5+`allow_warp`'s `global_warp_allowed` branch (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode`, exactly as r3 scoped it:
6+
7+- `crates/ec-av1/src/warp.rs`: added `pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams>` -- calls the SAME `get_shear_params` `find_projection` already uses for local `WARPED_CAUSAL`, just keyed on the frame's coded `global_motion[ref]` model instead of a per-block least-squares fit. No second warp implementation.
8+- `crates/ec-av1/src/decode.rs` (single-ref inter block path, ~line 6391): `if warp_params.is_none() && is_global_mv_block && !force_integer_mv && !gm_ref.invalid { warp_params = crate::warp::global_warp_params(gm_ref.params); }`, placed right after the local-`WARPED_CAUSAL` motion_mode block so `warp_params.is_none()` naturally encodes `allow_warp`'s "local first, else-if global" precedence. `is_global_mv_block` already carries the `min(bw4,bh4) >= 2` (>=8px) size bound `av1_init_warp_params` checks separately.
9+- `crates/ec-av1/src/stream.rs`: the whole-frame refusal ("any non-IDENTITY global motion for a single-ref frame -> refuse") is GONE. Replaced with two narrower, named refusals for what remains genuinely unverified (see below).
10+
11+## Pin before/after (`gm-seed43.obu`, `EC_WEDGE_GATE_ATTEMPTS=20 EC_AV1_REQUIRE_AOMENC=1`)
12+
13+- **Before (r3 baseline):** frame 1 luma MISMATCH, 416 mismatches, first at row 32 col 0 (block `mi=(8,0)`, ROTZOOM on `LAST_FRAME` alone).
14+- **After:** frame 1 luma **MATCH**. Frames 0-13 all MATCH (all 3 planes, re-confirmed via `scratch_isolate_pinned_mismatch` with `EC_AV1_PIN_N=24`). AB-tested with a temporary `EC_GM_DISABLE` env gate (reverted before commit): disabling the new code reproduces the exact r3 baseline mismatch (416 @ row32/col0) and shows it never resolves across all 24 frames -- confirms the fix, not a coincidence.
15+- Frame 14 onward hits a **NEW, smaller, distinct** mismatch (441 Y mismatches, worst delta 7, first at row 0 col 18) that the r3 investigation never reached (the whole-frame refusal used to block this frame entirely). Traced (not guessed): the mismatched frame has `reference_select=false` (ruling out the compound-`GLOBAL_GLOBALMV` hypothesis I checked first) and `global_motion = [Identity,Identity,Identity,Rotzoom,Rotzoom,Identity,Identity]` -- i.e. **two different ref slots** (`GOLDEN_FRAME`, `BWDREF_FRAME`) carry an active ROTZOOM model **at the same time**, a shape frame 1's single-active-slot (`LAST_FRAME` alone) case never exercised. Root cause not found within this round's budget; per charter instruction, **not guess-fixed** -- refused by name instead (see below), verified via `scratch_decode_pinned_stream_once` that the refusal now fires cleanly (`Err`, no panic) rather than shipping the wrong pixels.
16+
17+## Refusal narrowing (stream.rs, `header.frame_type != Key` gate)
18+
19+1. `gm.model == WarpModel::Affine` (any ref slot) -- AFFINE (6-parameter) models are untested this round; no aomenc fixture in the wedge gate reached one.
20+2. More than one ref slot concurrently has a ROTZOOM/AFFINE model -- the exact shape frame 14 exposed; only the single-active-slot case is pin-verified.
21+
22+Proven decodable this round: **ROTZOOM as the sole active non-IDENTITY/non-TRANSLATION global-motion ref slot** (single-ref path). TRANSLATION was already correct (no warp needed, plain `gm_get_motion_vector` translation branch). IDENTITY unaffected (no warp). AFFINE and multi-slot-concurrent-ROTZOOM remain refused.
23+
24+## Wedge gate (`a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`, `EC_AV1_REQUIRE_AOMENC=1`)
25+
26+- Before this round (r3): 27 other-capability refusals / 13 matches / wii_hits=3 out of 40.
27+- After this round: **30 other-capability refusals / 10 matches / wii_hits=4 out of 40**. `ok`. The refusal count rose because several seeds that used to fall through the (now-removed) blanket non-IDENTITY refusal now hit the new, narrower "concurrent ROTZOOM/AFFINE ref slots" refusal by name instead -- correctly refusing an unverified shape rather than attempting (and risking) a decode.
28+
29+## Gate ladder run this round
30+
31+- `scratch_isolate_pinned_mismatch` (pin, before/after, `EC_GM_DISABLE` AB test): as above.
32+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib a_real_aomenc_stream_with_interintra_wedge -- --nocapture`: `ok`, 30/40 refusals, 10/40 matches, wii_hits=4.
33+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib -- --skip a_real_aomenc_stream_with_interintra_wedge`: **227 passed, 0 failed, 17 ignored, 1 filtered** -- unchanged from r3/main baseline. Includes the 14-pin list (last2/last3/bwdref/altref2/altref reference gates, temporal-mvs, obmc/obmc_8x8, interintra, masked-compound, free-partitions, ab-partitions, compound-references, reference_select, warped_motion) -- all `ok`, inert for the IDENTITY-gm pins as expected.
34+
35+## Files touched
36+- `crates/ec-av1/src/warp.rs` -- `global_warp_params`, reusing `get_shear_params`.
37+- `crates/ec-av1/src/decode.rs` -- the `global_warp_allowed` branch wiring in the single-ref inter block path.
38+- `crates/ec-av1/src/stream.rs` -- whole-frame refusal replaced by the two named refusals above.
39+
40+## Next round
41+Root-cause frame 14's mismatch: two concurrently active ROTZOOM ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`), `reference_select=false` (ruled out as compound), small delta-1 first divergence at row 0 col 18 growing across frames -- same propagating shape class as r3's bug, but NOT the one this round fixed (AB-confirmed via `EC_GM_DISABLE`). Candidates not yet checked: per-ref indexing into `global_motion` when multiple slots are simultaneously non-identity (unlikely, same code path per ref), BWDREF_FRAME-specific reference-buffer/ordering interaction newly exercised now that this class of frame decodes at all (previously wholly refused), or a genuine second warp-related bug distinct from the block-centre `-1` one r3 already fixed. Re-pin with `EC_WEDGE_GATE_ATTEMPTS` to capture a fresh seed whose first mismatch is this exact shape, then range-ladder it the same way r3 did. Compound `GLOBAL_GLOBALMV` warp (the `predict_compound_intermediate`/`combine_compound` call site) is a SEPARATE, still-completely-unwired gap -- only one `warp::warp_affine` call site exists in the file (single-ref); deferred, no evidence yet that any gate fixture reaches it (this round's `reference_select` check on the mismatched frame came back false).