diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 7b2a2f58..4a8beedc 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -5126,3 +5126,34 @@ pub const EOB_PT_16_CHROMA_CLASS1_Q0: [u16; 6] = [1904, 3354, 7763, 14647, 32768 pub const EOB_PT_16_CHROMA_CLASS1_Q1: [u16; 6] = [2497, 4096, 8866, 16993, 32768, 0]; pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768, 0]; pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0]; + +/// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`). +pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1_Q3: [u16; 9] = [9165, 13282, 21150, 30286, 31894, 32571, 32712, 32768, 0]; + +/// `EOB_PT_512_LUMA`'s class-1 sibling (`av1_default_eob_multi512_cdfs[q][0][1]`). +pub const EOB_PT_512_LUMA_CLASS1_Q0: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1_Q1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1_Q3: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; + +/// `EOB_PT_512_CHROMA`'s class-1 sibling (`av1_default_eob_multi512_cdfs[q][1][1]`). +pub const EOB_PT_512_CHROMA_CLASS1_Q0: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1_Q1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1_Q3: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; + +/// `EOB_PT_1024_LUMA`'s class-1 sibling (`av1_default_eob_multi1024_cdfs[q][0][1]`). +pub const EOB_PT_1024_LUMA_CLASS1_Q0: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1_Q1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1_Q3: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; + +/// `EOB_PT_1024_CHROMA`'s class-1 sibling (`av1_default_eob_multi1024_cdfs[q][1][1]`). +pub const EOB_PT_1024_CHROMA_CLASS1_Q0: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1_Q1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1_Q3: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; + diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index cd587b45..c03486cb 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -214,17 +214,24 @@ pub(crate) struct Cdfs { pub eob_pt_16_luma_class1: [u16; 6], /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`. pub eob_pt_64_luma_class1: [u16; 8], - /// `eob_pt_256_luma`'s class-1 sibling (lane-txselect r2): a 16x16 luma - /// TU reaches `V_DCT`/`H_DCT` through the inter tx set - /// `EXT_TX_SET_DTT9_IDTX_1DDCT`, and libaom keeps the eob class - /// dimension at every size. + /// `eob_pt_16_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_16_chroma_class1: [u16; 6], + /// `eob_pt_64_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_64_chroma_class1: [u16; 8], + /// `eob_pt_128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_128_chroma_class1: [u16; 9], + /// `eob_pt_256_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_256_luma_class1: [u16; 10], - /// The chroma class-1 siblings (lane-txselect r2): an *inter* block's - /// chroma TU inherits its luma unit's `tx_type`, so 1D classes reach - /// chroma too. + /// `eob_pt_256_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_256_chroma_class1: [u16; 10], - pub eob_pt_64_chroma_class1: [u16; 8], - pub eob_pt_16_chroma_class1: [u16; 6], + /// `eob_pt_512_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_512_luma_class1: [u16; 11], + /// `eob_pt_512_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_512_chroma_class1: [u16; 11], + /// `eob_pt_1024_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_1024_luma_class1: [u16; 12], + /// `eob_pt_1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. + pub eob_pt_1024_chroma_class1: [u16; 12], /// The end-of-block offset bit of a 16x16 luma transform. pub eob_extra_luma_16: [[u16; 3]; 9], /// The same, for an 8x8 luma transform. @@ -633,10 +640,15 @@ impl Cdfs { reset1(&mut self.eob_pt_16_luma); reset1(&mut self.eob_pt_16_luma_class1); reset1(&mut self.eob_pt_64_luma_class1); + reset1(&mut self.eob_pt_16_chroma_class1); + reset1(&mut self.eob_pt_64_chroma_class1); + reset1(&mut self.eob_pt_128_chroma_class1); reset1(&mut self.eob_pt_256_luma_class1); reset1(&mut self.eob_pt_256_chroma_class1); - reset1(&mut self.eob_pt_64_chroma_class1); - reset1(&mut self.eob_pt_16_chroma_class1); + reset1(&mut self.eob_pt_512_luma_class1); + reset1(&mut self.eob_pt_512_chroma_class1); + reset1(&mut self.eob_pt_1024_luma_class1); + reset1(&mut self.eob_pt_1024_chroma_class1); reset2(&mut self.eob_extra_luma_16); reset2(&mut self.eob_extra_luma_8); reset2(&mut self.eob_extra_luma_4); @@ -858,6 +870,27 @@ impl Cdfs { cdf::EOB_PT_64_LUMA_CLASS1, cdf::EOB_PT_64_LUMA_CLASS1_Q3, ), + eob_pt_16_chroma_class1: pick( + q_ctx, + cdf::EOB_PT_16_CHROMA_CLASS1_Q0, + cdf::EOB_PT_16_CHROMA_CLASS1_Q1, + cdf::EOB_PT_16_CHROMA_CLASS1, + cdf::EOB_PT_16_CHROMA_CLASS1_Q3, + ), + eob_pt_64_chroma_class1: pick( + q_ctx, + cdf::EOB_PT_64_CHROMA_CLASS1_Q0, + cdf::EOB_PT_64_CHROMA_CLASS1_Q1, + cdf::EOB_PT_64_CHROMA_CLASS1, + cdf::EOB_PT_64_CHROMA_CLASS1_Q3, + ), + eob_pt_128_chroma_class1: pick( + q_ctx, + cdf::EOB_PT_128_CHROMA_CLASS1_Q0, + cdf::EOB_PT_128_CHROMA_CLASS1_Q1, + cdf::EOB_PT_128_CHROMA_CLASS1, + cdf::EOB_PT_128_CHROMA_CLASS1_Q3, + ), eob_pt_256_luma_class1: pick( q_ctx, cdf::EOB_PT_256_LUMA_CLASS1_Q0, @@ -872,19 +905,33 @@ impl Cdfs { cdf::EOB_PT_256_CHROMA_CLASS1, cdf::EOB_PT_256_CHROMA_CLASS1_Q3, ), - eob_pt_64_chroma_class1: pick( + eob_pt_512_luma_class1: pick( q_ctx, - cdf::EOB_PT_64_CHROMA_CLASS1_Q0, - cdf::EOB_PT_64_CHROMA_CLASS1_Q1, - cdf::EOB_PT_64_CHROMA_CLASS1, - cdf::EOB_PT_64_CHROMA_CLASS1_Q3, + cdf::EOB_PT_512_LUMA_CLASS1_Q0, + cdf::EOB_PT_512_LUMA_CLASS1_Q1, + cdf::EOB_PT_512_LUMA_CLASS1, + cdf::EOB_PT_512_LUMA_CLASS1_Q3, ), - eob_pt_16_chroma_class1: pick( + eob_pt_512_chroma_class1: pick( q_ctx, - cdf::EOB_PT_16_CHROMA_CLASS1_Q0, - cdf::EOB_PT_16_CHROMA_CLASS1_Q1, - cdf::EOB_PT_16_CHROMA_CLASS1, - cdf::EOB_PT_16_CHROMA_CLASS1_Q3, + cdf::EOB_PT_512_CHROMA_CLASS1_Q0, + cdf::EOB_PT_512_CHROMA_CLASS1_Q1, + cdf::EOB_PT_512_CHROMA_CLASS1, + cdf::EOB_PT_512_CHROMA_CLASS1_Q3, + ), + eob_pt_1024_luma_class1: pick( + q_ctx, + cdf::EOB_PT_1024_LUMA_CLASS1_Q0, + cdf::EOB_PT_1024_LUMA_CLASS1_Q1, + cdf::EOB_PT_1024_LUMA_CLASS1, + cdf::EOB_PT_1024_LUMA_CLASS1_Q3, + ), + eob_pt_1024_chroma_class1: pick( + q_ctx, + cdf::EOB_PT_1024_CHROMA_CLASS1_Q0, + cdf::EOB_PT_1024_CHROMA_CLASS1_Q1, + cdf::EOB_PT_1024_CHROMA_CLASS1, + cdf::EOB_PT_1024_CHROMA_CLASS1_Q3, ), eob_extra_luma_16: pick( q_ctx, @@ -1283,7 +1330,7 @@ impl Cdfs { br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, // lane-comppin r4 (REVERTED, see r4's own commit message): // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32 @@ -1307,7 +1354,7 @@ impl Cdfs { br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_32.as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, TxbSet::Luma64 => TxbTables { side: 32, @@ -1319,7 +1366,7 @@ impl Cdfs { br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, TxbSet::Luma16 => TxbTables { side: 16, @@ -1403,7 +1450,7 @@ impl Cdfs { br: &mut self.br_luma_4, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4.as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), }, TxbSet::Luma4InterSet1 => TxbTables { side: 4, @@ -1439,7 +1486,7 @@ impl Cdfs { br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8.as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::Luma8InterSet1 => TxbTables { side: 8, @@ -1499,7 +1546,7 @@ impl Cdfs { br: &mut self.br_chroma_32, dc_sign: &mut self.dc_sign_chroma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_1024_chroma_class1), }, TxbSet::LumaRect32x16 => TxbTables { side: 32, @@ -1511,7 +1558,7 @@ impl Cdfs { br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), }, TxbSet::ChromaRect16x8 => TxbTables { side: 16, @@ -1523,7 +1570,7 @@ impl Cdfs { br: &mut self.br_chroma_16, dc_sign: &mut self.dc_sign_chroma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1), }, TxbSet::ChromaRect32x16 => TxbTables { side: 32, @@ -1535,7 +1582,7 @@ impl Cdfs { br: &mut self.br_chroma_32, dc_sign: &mut self.dc_sign_chroma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1), }, } } diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b76ea5b2..827cfa8d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -36,7 +36,7 @@ use crate::msac::SymbolDecoder; use crate::mvstack::{ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, MiGrid, MiInfo, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx, - find_mv_stack, find_mv_stack_with_sign_bias, reference_mode_ctx, single_ref_ctx, + find_mv_stack_with_sign_bias, reference_mode_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx, }; @@ -1213,6 +1213,42 @@ pub(crate) fn compound_warp_hits() -> usize { COMPOUND_WARP_HITS.with(|c| c.get()) } +// lane-gmaffine r1: how many blocks built their prediction from a +// SIX-parameter (`AFFINE`) global-motion model through +// `crate::warp::global_warp_params` -- the gate's proof that a stream really +// carried an AFFINE `global_motion_params` AND that a block was predicted +// with it, not merely that the header parsed one. +thread_local! { + static AFFINE_GM_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`AFFINE_GM_HITS`]. +pub(crate) fn affine_gm_hits() -> usize { + AFFINE_GM_HITS.with(|c| c.get()) +} + +// lane-gmaffine r1: 8x8-leaf-only counters -- how many `BLOCK_8X8` leaves +// coded `GLOBALMV` (`GLOBALMV_HITS_8`) and how many built a real +// `WARPED_CAUSAL` local-warp prediction there (`WARP_HITS_8`, incremented +// only once `find_projection` returned a usable model, unlike +// `WARP_SELECTED_HITS` which counts the symbol). Both are the 8x8 gates' +// proof that the leaf path itself fired, not the 16x16+ one. +thread_local! { + static GLOBALMV_HITS_8: std::cell::Cell = const { std::cell::Cell::new(0) }; + static WARP_HITS_8: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`GLOBALMV_HITS_8`]. +pub(crate) fn globalmv_hits_8() -> usize { + GLOBALMV_HITS_8.with(|c| c.get()) +} + +/// Current value of [`WARP_HITS_8`]. +pub(crate) fn warp_hits_8() -> usize { + WARP_HITS_8.with(|c| c.get()) +} + // How many blocks decoded `interintra == 1` with the non-wedge blended // prediction applied (lane-interintra r1) -- the gate's proof that a // stream actually exercised interintra. @@ -2195,7 +2231,8 @@ fn read_coeffs( let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); if ec_trace_coeff { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); + let cls = match class { TxClass::TwoD => "2d", TxClass::Horiz => "horiz", TxClass::Vert => "vert" }; + eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}"); } let class_scan; let scan: &[u16] = if class == TxClass::TwoD { @@ -10297,6 +10334,12 @@ fn num_proj_ref( /// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16) /// are transcribed. fn obmc_mask(len: usize) -> &'static [u8] { + // lane-gmaffine r1: the two SHORT masks (libaom `reconinter.c` + // `obmc_mask_1`/`obmc_mask_2`) -- an 8x8 leaf's chroma plane is 4x4, so + // its overlap is 2 (and 1 at a half-block edge). Unreachable until this + // round wired interior 16x16 splits down to real 8x8 leaves, where the + // old `unreachable!()` below fired as a hard panic. + const M1: [u8; 1] = [64]; // lane-inter8 r1: `obmc_mask_2` (`reconinter.c` 753) -- reached by the // LEFT pass of an 8x8 block's chroma plane (overlap 4 luma columns, 2 // chroma), which only became live once 8x8 inter leaves stopped being @@ -10312,6 +10355,7 @@ fn obmc_mask(len: usize) -> &'static [u8] { 61, 62, 64, 64, 64, 64, 64, 64, 64, 64, ]; match len { + 1 => &M1, 2 => &M2, 4 => &M4, 8 => &M8, @@ -10587,6 +10631,11 @@ fn obmc_blend( // (this decoder's own outer block-loop granularity), one step // coarser than the mi(4px) units `overlappable_above` walks in -- // divide back down to that column. + // lane-gmaffine r2: the neighbour's OWN mi-granular filter + // (libaom `av1_setup_build_prediction_by_above_pred` reads + // `above_mbmi->interp_filters`); the 16px-granular `Neighbours` slot + // stays as the fallback for paths that do not record one yet + // (compound), which is what every earlier round used. let (h_kind, v_kind) = neighbour_filter( interp_fixed, neighbours.above_filter[mi_col + off4], @@ -12448,6 +12497,9 @@ fn decode_inter_block( let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; 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); + if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine { + AFFINE_GM_HITS.with(|c| c.set(c.get() + 1)); + } } if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( @@ -12670,16 +12722,25 @@ fn decode_inter_block( py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, side as i32, side as i32, 0, 0, ); - crate::warp::warp_affine( - params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, - pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, 1, 1, - ); - crate::warp::warp_affine( - params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32, - pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, 1, 1, - ); + // libaom `av1_init_warp_params` (reconinter.c): warp is + // per PLANE and bails out at `block_width < 8 || + // block_height < 8`, so a plane whose own block is under + // 8x8 keeps the translational prediction built above -- + // in 420 that is every chroma plane of a luma block below + // 16x16 (lane-gmaffine r4: chroma-only mismatch of a few + // levels on both 8x8-leaf motion gates). + if chroma_side >= 8 { + crate::warp::warp_affine( + params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, + pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32, + chroma_side as i32, chroma_side as i32, 1, 1, + ); + crate::warp::warp_affine( + params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32, + pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32, + chroma_side as i32, chroma_side as i32, 1, 1, + ); + } } if obmc_selected { @@ -13218,6 +13279,16 @@ fn decode_inter_block8( scan4: &[u16], allow_high_precision_mv: bool, force_integer_mv: bool, + // lane-gmaffine r1: this frame header's own `global_motion` table (spec + // 5.9.24), indexed `[ref_frame - LAST_FRAME]` -- same table + // [`decode_inter_block`] takes, threaded here so the 8x8 leaf can code + // `GLOBALMV` (`gm_get_motion_vector`), fill its mv stack's missing + // candidates with the gm mv (gm r6's root cause) and build a global + // warp prediction. + global_motion: &[ec_av1_syntax::WarpParams; 7], + // lane-gmaffine r1: this sequence header's own `enable_dual_filter` bit, + // for the leaf's own `read_mb_interp_filter` below. + enable_dual_filter: bool, // lane-av1comp: see [`decode_inter_block`]'s own doc -- this leaf path // only ever tracks a coarse `LAST_FRAME`-or-intra neighbour shape (no // per-leaf `above_ref`/`left_ref` array exists here), so `comp_mode`'s @@ -13263,16 +13334,14 @@ fn decode_inter_block8( // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`- // eligible (`bsize >= BLOCK_8X8`). allow_screen_content_tools: bool, - // lane-inter8 r1: the leaf's mv stacks used to be built with neither the - // frame's sign-bias table nor its global-motion mv table (`NO_SIGN_BIAS` - // / `NO_GM_MV`), while [`decode_inter_block`] one level up passed both. - // A neighbour coded GLOBALMV contributes the gm mv, so dropping the table - // changes the candidate list -- and with it `new_mv_ctx`/`ref_mv_ctx`, - // `drl_ctx` and the number of symbols read. Measured: an 8x8 compound - // NEAR_NEWMV leaf desynced against aomdec's EC_MODE ladder at exactly - // this block (mi 4,14 of the mandelbrot 8x8-split gate). + // lane-inter8 r1: the leaf's mv stacks used to be built without the + // frame's sign-bias table (`NO_SIGN_BIAS`), while [`decode_inter_block`] + // one level up passed it -- it changes the candidate list and with it + // `new_mv_ctx`/`ref_mv_ctx`, `drl_ctx` and the number of symbols read. + // Measured: an 8x8 compound NEAR_NEWMV leaf desynced against aomdec's + // EC_MODE ladder at exactly this block (mi 4,14 of the mandelbrot + // 8x8-split gate). sign_bias_table: &SignBiasTable, - global_motion: &[ec_av1_syntax::WarpParams; 7], // lane-inter8 r2: the frame's temporal mv field (spec 7.10.2.8), which // [`decode_inter_block`] one level up has always passed and this leaf // passed `None` for -- a `use_ref_frame_mvs` frame's stack then holds @@ -13285,8 +13354,19 @@ fn decode_inter_block8( // predictions take when a stored reference was coded at another width // (`use_superres`) -- mirrors [`decode_inter_block`]'s own param. frame_width: usize, -) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, (i8, Option))> { +) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>, [u8; 2], (i8, Option))> { const LAST_FRAME: i8 = 1; + // lane-gmaffine r2: the leaf's OWN switchable-filter symbols, handed back + // so the caller stamps them into `Neighbours` instead of the `[3, 3]` + // placeholder. `[3, 3]` is the "intra neighbour, no filter" sentinel: an + // OBMC blend that picks such a neighbour up feeds it to + // `neighbour_filter`, which PANICS on it (`from_switchable_symbol`) -- + // that was the warp gate's crash, not an entropy desync. Stays `[3, 3]` + // on the intra and compound paths. + let mut leaf_filter_syms = [3u8; 2]; + // lane-gmaffine r1: this leaf's GLOBALMV vector AND the mv stack's + // missing-candidate fallback both come from the frame's global motion + // evaluated at THIS block's centre (gm r6's root cause). let gm_table = build_gm_mv_table( global_motion, leaf_mi.0, @@ -13864,38 +13944,58 @@ fn decode_inter_block8( // so the 16x16 below a split block read partition ctx 0 // instead of 1 and mis-read PARTITION_SPLIT as NONE. neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); - neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 }); - return Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs)); + neighbours.fill_lf_grid( + leaf_mi, + 2, + 8, + if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 }, + ); + return Ok(( + skip, + is_inter, + skip_mode, + compound_ctx8, + leaf_filter_syms, + leaf_refs, + )); } } - leaf_refs = (LAST_FRAME, None); - let sr_ctx = single_ref_ctx(above_inter || left_inter); - let p1 = dec.symbol(&mut cdfs.single_ref[sr_ctx][0]); - let p3 = dec.symbol(&mut cdfs.single_ref[sr_ctx][2]); - let p4 = dec.symbol(&mut cdfs.single_ref[sr_ctx][3]); - if (p1, p3, p4) != (0, 0, 0) { - return Err(unsupported( - "a reference frame other than LAST_FRAME (round 2)", - )); - } + // lane-gmaffine r1: the leaf reads the FULL `single_ref` tree + // ([`read_single_ref`], the same one the 16x16+ leaf uses, with the + // real per-neighbour p1..p6 contexts) instead of the old three-symbol + // LAST-only probe plus a refusal -- aomenc picks GOLDEN/ALTREF for + // 8x8 leaves constantly, so that refusal was what every 8x8 gate + // actually stopped at. + let ref_frame = read_single_ref( + dec, + cdfs, + neighbours.above_ref[cmi], + neighbours.above_ref1[cmi], + neighbours.left_ref[rmi], + neighbours.left_ref1[rmi], + ); + leaf_refs = (ref_frame, None); + let (sref_y, sref_u, sref_v) = ref_planes(ref_frame, ref_y, ref_u, ref_v, other_refs)?; let (mi_row, mi_col) = leaf_mi; + // lane-inter8 r2: the frame's temporal mv candidates, keyed on THIS + // leaf's own reference (lane-gmaffine r1 taught it non-LAST refs). let tpl = tpl_frame.map(|t| crate::mvstack::TplArgs { field: t.field, cur_offset_0: crate::motion_field::get_relative_dist( t.order_hint_bits, t.order_hint, - t.ref_order_hints[(LAST_FRAME - LAST_FRAME) as usize], + t.ref_order_hints[(ref_frame - LAST_FRAME) as usize], ), allow_high_precision_mv, }); - let stack = find_mv_stack_with_sign_bias( + let stack = crate::mvstack::find_mv_stack_with_sign_bias( grid, mi_row, mi_col, 2, 2, - LAST_FRAME, + ref_frame, mi_cols as usize, mi_rows as usize, sign_bias_table, @@ -13904,6 +14004,7 @@ fn decode_inter_block8( ); let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1; + let mut is_globalmv = false; let (mv, is_new_mv) = if !not_new { // NEWMV (spec 5.11.24's `read_drl_idx`, `RefMvIdx` starting at 0): // read at most two `drl_mode` bits, one per stack entry past the @@ -13932,21 +14033,27 @@ fn decode_inter_block8( ) } else { let not_zero = dec.symbol(&mut cdfs.zero_mv[stack.zero_mv_ctx]) == 1; - if !not_zero { - return Err(unsupported("GLOBALMV (round 3)")); - } - let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; - let mv = if nearest { - stack.nearest_mv + is_globalmv = !not_zero; + let mv = if !not_zero { + // lane-gmaffine r1: GLOBALMV (spec 7.10.2.1) -- the same + // `gm_get_motion_vector` value the 16x16+ leaf reads out of + // its own `gm_table`, computed at this block's centre. + GLOBALMV_HITS_8.with(|c| c.set(c.get() + 1)); + gm_table[(ref_frame - LAST_FRAME) as usize] } else { - let mut idx = 1usize; - while idx < 3 && stack.entries.len() > idx + 1 { - if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { - break; + let nearest = dec.symbol(&mut cdfs.ref_mv[stack.ref_mv_ctx]) == 0; + if nearest { + stack.nearest_mv + } else { + let mut idx = 1usize; + while idx < 3 && stack.entries.len() > idx + 1 { + if dec.symbol(&mut cdfs.drl_mode[stack.drl_ctx[idx]]) == 0 { + break; + } + idx += 1; } - idx += 1; + stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) } - stack.entries.get(idx).map_or(stack.near_mv, |e| e.mv) }; (mv, false) }; @@ -13989,11 +14096,22 @@ fn decode_inter_block8( // 16x16 leaf's own `decode_inter_block` read (see its doc above) -- // same 2-symbol `obmc_cdf` alphabet, same `allow_warped_motion=1` // refusal (warp needs `av1_findSamples`, not ported at either leaf). + // lane-gmaffine r1: the two libaom predicates, exactly as the + // 16x16+ leaf resolves them (see [`decode_inter_block`]'s own doc): + // `is_global_mv_block` (mode GLOBAL*, model > TRANSLATION, block + // >= 8x8 -- BLOCK_8X8 IS the 8px minimum, so the size predicate is + // always true here) suppresses the motion_mode read entirely and + // turns on the global warp below. + let gm_ref = &global_motion[(ref_frame - LAST_FRAME) as usize]; + let is_global_mv_block = is_globalmv && gm_ref.model as u8 > 1; let motion_mode_eligible = switchable_motion_mode && !skip_mode && interintra_mode.is_none() + && !(is_global_mv_block && !force_integer_mv) && (!overlappable_above(grid, mi_row, mi_col, 2, mi_cols as usize, 1).is_empty() || !overlappable_left(grid, mi_row, mi_col, 2, mi_rows as usize, 1).is_empty()); + let mut warp_params: Option = None; + let mut warped_selected = false; let mut obmc_selected = false; if motion_mode_eligible { // lane-warp round 1: same 3-vs-2-symbol split as the 16x16+ leaf @@ -14006,7 +14124,7 @@ fn decode_inter_block8( // runs (see the block8 refusal below, ~12500) -- whoever lifts // that refusal must add `&& !ref_is_scaled` here too. let warp_eligible = allow_warped_motion - && num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, LAST_FRAME) >= 1; + && num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, ref_frame) >= 1; if warp_eligible { let mode = dec.symbol(&mut cdfs.motion_mode[0]); match mode { @@ -14017,12 +14135,41 @@ fn decode_inter_block8( OBMC_HITS_8.with(|c| c.set(c.get() + 1)); } _ => { + // lane-gmaffine r1: WARPED_CAUSAL at the 8x8 leaf -- + // the same findSamples -> select_samples -> + // av1_find_projection chain the 16x16+ leaf runs, + // with BLOCK_8X8's own 8x8 model centre; an + // unusable projection falls back to the block's + // translational mv (libaom `av1_find_projection` + // returning 1 leaves `wm_params` invalid and + // `build_inter_predictors` skips the warp). WARP_SELECTED_HITS.with(|c| c.set(c.get() + 1)); - return Err(unsupported( - "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): \ - av1_find_projection/the affine warp filter are not \ - ported, only motion_mode_allowed's alphabet choice is", - )); + let mut samples = find_samples( + grid, + mi_row, + mi_col, + 2, + 2, + mi_cols as usize, + mi_rows as usize, + ref_frame, + ); + if samples.len() > 1 { + crate::warp::select_samples(mv, &mut samples, SIDE as i32, SIDE as i32); + } + warp_params = crate::warp::find_projection( + &samples, + SIDE as i32, + SIDE as i32, + mv.1, + mv.0, + mi_row as i32, + mi_col as i32, + ); + warped_selected = true; + if warp_params.is_some() { + WARP_HITS_8.with(|c| c.set(c.get() + 1)); + } } } } else { @@ -14034,6 +14181,78 @@ fn decode_inter_block8( } } } + // lane-gmaffine r1: `read_mb_interp_filter` (spec 5.11.26) at the 8x8 + // leaf, in libaom's own order (interintra, motion_mode, THEN the + // filter). Until this round the leaf read no filter symbol at all and + // predicted Regular unconditionally -- correct only for a frame with a + // fixed `interp_filter`, and a silent entropy DESYNC for every + // SWITCHABLE-filter stream that reaches an 8x8 leaf (which is what + // made the interior-split wiring above unusable at first). + // corner-cut: the neighbour filter context is the enclosing 16x16 + // block's own coarse `above_filter`/`left_filter` entry (this leaf + // path keeps no per-leaf neighbour array), so all four siblings read + // the same context row. Ceiling: a stream whose 8x8 siblings pick + // DIFFERENT filters decodes the second..fourth leaf's symbol from the + // wrong CDF row. Upgrade: give `Neighbours` a real 8x8-granular + // filter array, same shape as the `[3, 3]` approximation the caller + // records after the leaf loop. + let above_filter_ctx = if neighbours.above_ref[cmi] == ref_frame + || neighbours.above_ref1[cmi] == Some(ref_frame) + { + neighbours.above_filter[cmi] + } else { + [3, 3] + }; + let left_filter_ctx = if neighbours.left_ref[rmi] == ref_frame + || neighbours.left_ref1[rmi] == Some(ref_frame) + { + neighbours.left_filter[rmi] + } else { + [3, 3] + }; + let gm_nontrans = + is_globalmv && gm_ref.model != ec_av1_syntax::WarpModel::Translation; + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( + dec, + cdfs, + interp_fixed, + enable_dual_filter, + gm_nontrans || warped_selected || skip_mode, + above_filter_ctx, + left_filter_ctx, + false, + ); + leaf_filter_syms = resolved_filter; + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}", + leaf_mi.0, + leaf_mi.1, + mv.0, + mv.1, + stack.entries.len(), + dec.debug_state().0 + ); + } + // lane-gmaffine r1: `allow_warp`'s `global_warp_allowed` branch + // (`reconinter.c:33-55`), gated INDEPENDENTLY of `motion_mode` -- + // see [`decode_inter_block`]'s own copy. A local WARPED_CAUSAL model + // wins (`is_none()` guard); BLOCK_8X8 already satisfies the >=8px + // size predicate baked into `is_global_mv_block`. + 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); + if warp_params.is_some() && gm_ref.model == ec_av1_syntax::WarpModel::Affine { + AFFINE_GM_HITS.with(|c| c.set(c.get() + 1)); + } + } + if std::env::var_os("EC_TRACE_MODE").is_some() { + eprintln!( + "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}", + leaf_mi.0, + leaf_mi.1, + warp_params.is_some(), + ); + } for dr in 0..2 { for dc in 0..2 { grid.set( @@ -14041,7 +14260,7 @@ fn decode_inter_block8( mi_col + dc, MiInfo { is_inter: true, - ref_frame: LAST_FRAME, + ref_frame, // INTRA_FRAME marker for interintra blocks -- keeps // them out of warp-sample gathering (see 16/32 site). ref_frame1: interintra_mode.map(|_| 0), @@ -14050,7 +14269,7 @@ fn decode_inter_block8( is_new_mv, size: 2, size_h: 2, - is_global_mv0: false, + is_global_mv0: is_global_mv_block, is_global_mv1: false, }, ); @@ -14061,21 +14280,24 @@ fn decode_inter_block8( // lane-scaledref r1: this leaf's own prediction is always `Regular` // (documented corner-cut above); under a scaled reference the same // fixed kernel runs through spec 7.11.3.3's scaled walk instead. - let luma_scale = mc::scale_factor(ref_y.width, frame_width); + let luma_scale = mc::scale_factor(sref_y.width, frame_width); if luma_scale != mc::REF_NO_SCALE { SCALED_BLOCK8_HITS.with(|c| c.set(c.get() + 1)); } let mut pred_y = vec![0u16; SIDE * SIDE]; let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE]; + // Merge of lane-gmaffine (this leaf's own switchable filters) with + // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either + // way, only the sample walk differs. for (plane, x, y, dim, dst) in [ - (ref_y, px, py, SIDE, &mut pred_y), - (ref_u, cpx, cpy, CHROMA_SIDE, &mut pred_u), - (ref_v, cpx, cpy, CHROMA_SIDE, &mut pred_v), + (sref_y, px, py, SIDE, &mut pred_y), + (sref_u, cpx, cpy, CHROMA_SIDE, &mut pred_u), + (sref_v, cpx, cpy, CHROMA_SIDE, &mut pred_v), ] { - let luma = std::ptr::eq(plane, ref_y); + let luma = std::ptr::eq(plane, sref_y); if luma_scale == mc::REF_NO_SCALE { - mc::predict( + mc::predict_with_filters( &plane.data, plane.width, plane.true_width, @@ -14084,6 +14306,8 @@ fn decode_inter_block8( mv_to_q4(y, mv.0, luma), dim, dim, + h_filter, + v_filter, dst, ); } else { @@ -14097,13 +14321,40 @@ fn decode_inter_block8( luma_scale, dim, dim, - mc::InterpFilterKind::Regular, - mc::InterpFilterKind::Regular, + h_filter, + v_filter, dst, ); } } + // lane-gmaffine r1: the warp filter REPLACES the translational + // prediction just built (libaom builds one or the other), same as + // the 16x16+ leaf's own call trio. + if let Some(params) = &warp_params { + crate::warp::warp_affine( + params, &sref_y.data, sref_y.true_width as i32, sref_y.true_height as i32, + sref_y.width as i32, &mut pred_y, px as i32, py as i32, SIDE as i32, + SIDE as i32, SIDE as i32, 0, 0, + ); + // `av1_init_warp_params`'s per-plane `block_width/height < 8` + // bail-out: an 8x8 leaf's chroma plane is 4x4 in 420, so it is + // predicted translationally even when the luma warps. + #[allow(clippy::absurd_extreme_comparisons)] + if CHROMA_SIDE >= 8 { + crate::warp::warp_affine( + params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32, + sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, CHROMA_SIDE as i32, + CHROMA_SIDE as i32, CHROMA_SIDE as i32, 1, 1, + ); + crate::warp::warp_affine( + params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32, + sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, CHROMA_SIDE as i32, + CHROMA_SIDE as i32, CHROMA_SIDE as i32, 1, 1, + ); + } + } + if obmc_selected { obmc_blend( grid, @@ -14437,13 +14688,23 @@ fn decode_inter_block8( neighbours.above[leaf_mi.1 + cell][0] = state; } } + // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference + // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every + // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). neighbours.fill_lf_grid( leaf_mi, 2, if split8 { 4 } else { 8 }, - if is_inter { LAST_FRAME } else { 0 }, + if is_inter { leaf_refs.0.max(LAST_FRAME) } else { 0 }, ); - Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs)) + Ok(( + skip, + is_inter, + skip_mode, + compound_ctx8, + leaf_filter_syms, + leaf_refs, + )) } /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, @@ -15204,8 +15465,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( )); } let mut prev_leaves: Vec<((usize, usize), bool, bool, i8, Option)> = Vec::new(); - let mut last_compound_ctx: Option<(i8, i8, u8, u8)> = None; - let mut last_skip_mode = false; for (mr, mc) in leaf_positions { let leaf_mi = (mr as usize, mc as usize); let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); @@ -15215,8 +15474,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", )); } - let (skip, is_inter, skip_mode_leaf, compound_ctx8, leaf_refs) = - decode_inter_block8( + let ( + skip, + is_inter, + skip_mode_leaf, + compound_ctx8, + leaf_filter, + leaf_refs, + ) = decode_inter_block8( &mut dec, &mut cdfs, &mut neighbours, @@ -15237,6 +15502,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &scan4, allow_high_precision_mv, force_integer_mv, + &global_motion, + enable_dual_filter, reference_select, enable_masked_compound, enable_interintra_compound, @@ -15252,15 +15519,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( allow_warped_motion, allow_screen_content_tools, &sign_bias_table, - &global_motion, tpl_frame.as_ref(), frame_width as usize, )?; prev_leaves.push((leaf_mi, skip, is_inter, leaf_refs.0, leaf_refs.1)); - last_skip_mode = skip_mode_leaf; - if compound_ctx8.is_some() { - last_compound_ctx = compound_ctx8; - } // lane-inter8 r2: stamp THIS leaf's own // 2x2-mi span before the next leaf reads // it as a neighbour -- the whole-16x16 @@ -15269,9 +15531,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // block carried the wrong skip/ref/inter // state into the next block's contexts // (class context-read-from-one-cell). - // corner-cut: `[3, 3]` filter, as the - // 16x16 stamp used -- `decode_inter_block8` - // reads no switchable filter yet. + // lane-gmaffine r3: with the mi-granular + // band, the leaf's OWN switchable-filter + // symbols go in here -- the `[3, 3]` + // ("intra, no filter") sentinel this used + // to stamp made `obmc_blend`'s + // `neighbour_filter` PANIC as soon as a + // sibling leaf blended one of these. neighbours.record_inter_rect_mi( leaf_mi, 2, @@ -15279,7 +15545,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip, is_inter, leaf_refs.0, - [3, 3], + leaf_filter, skip_mode_leaf, ); if let Some(ref1) = leaf_refs.1 diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 82bc3b66..5302e7c7 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -34,7 +34,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[ #[cfg(test)] const REFUSALS: &[&str] = &[ - "GLOBALMV (round 3)", "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", "a coded (non-skip) HORZ/VERT rect strip below 16x16 (this decoder ports only the skip case at this size)", "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", @@ -59,14 +58,11 @@ const REFUSALS: &[&str] = &[ "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV (this decoder reads segment_id but never lets a segment override a block's reference, skip or mode)", "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", "a palette block with a split luma transform (round 1)", - "a reference frame other than LAST_FRAME (round 2)", "a reference frame selected with no picture at this frame's own ref_frame_idx slot for it", "a reference picture whose height does not match this frame's own true size", "a show_existing_frame header naming an empty reference slot", - "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is", "an inter var-tx tree with a leaf transform larger than 32x32", "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)", - "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", "an inter frame with no key frame before it", "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)", "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 402bf861..5ef01ce6 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -18,7 +18,6 @@ use ec_av1_syntax::{ Av1Parser, FrameHeader, FrameType, MAX_SEGMENTS, NUM_REF_FRAMES, ObuKind, PRIMARY_REF_NONE, SEG_LVL_GLOBALMV, SEG_LVL_REF_FRAME, SEG_LVL_SKIP, Tile, TxMode, - WarpModel, }; use ec_core::{Error, Result}; @@ -375,16 +374,20 @@ pub fn decode_stream(data: &[u8]) -> Result> { // needed). AFFINE is untested this round (no aomenc fixture in the // wedge gate reached a 6-parameter model) -- keep refusing it by // name rather than shipping an unverified decode. - if header.frame_type != FrameType::Key - && header.global_motion[..7] - .iter() - .any(|gm| gm.model == WarpModel::Affine) - { - return Err(Error::unsupported( - "AV1 decode_stream", - "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", - )); - } + // lane-gmaffine r1: AFFINE is now GATED, not refused. Stock libaom + // can never write a 6-parameter model -- its encoder-side search is + // pinned to ROTZOOM (`av1/encoder/global_motion_facade.c:24`, + // `FIRST_GLOBAL_TRANS_TYPE == LAST_GLOBAL_TRANS_TYPE == ROTZOOM`) -- + // which is why four rounds of `--enable-global-motion=1` recipes + // never reached the case. `scripts/build-aom-affine-oracle.sh` widens + // exactly that search range in a side build, and + // `a_real_affine_global_motion_stream_decodes_pixel_exact` below + // decodes its output pixel-exact against ffmpeg with + // `affine_gm_hits() > 0`, i.e. real blocks predicted through the + // 6-parameter warp. Nothing in the decoder needed changing: the + // header reader already reads params 4/5 with their own subexp refs + // (`ec-av1-syntax` `read_global_motion_params`) and `warp.rs`'s + // shear-validity check + `warp_affine` are model-agnostic. // lane-gm r4/r5/r6: r4 found a NEW mismatch on frames with two // concurrently active ROTZOOM/AFFINE ref slots (GOLDEN + BWDREF) and // refused the shape by name rather than guess-fix it. r5 localized @@ -6300,8 +6303,11 @@ mod tests { } } gate_buckets(NAME, 0, never_fired, refusals.len()); - eprintln!( - "SKIP {NAME}: {never_fired} attempts decoded but never fired an 8x8 obmc block \ + // lane-gmaffine r2: this gate fired for three rounds only as a SKIP + // (gate-skips-on-its-own-failure); the 8x8 leaf is reachable now, so a + // sweep that never lands one firing pixel-exact attempt is a FAILURE. + panic!( + "{NAME}: {never_fired} attempts decoded but never fired an 8x8 obmc block \ ({total_obmc8} total 8x8 obmc hits across all attempts), and every other attempt \ hit a named refusal:\n{}", refusals.join("\n") @@ -7403,6 +7409,401 @@ mod tests { ); } + /// The affine-capable encoder (`scripts/build-aom-affine-oracle.sh`), + /// separate from the shared oracle because stock libaom's global-motion + /// model search is pinned to ROTZOOM and can never emit AFFINE. + fn affine_aomenc_path() -> std::path::PathBuf { + if let Some(p) = std::env::var_os("EC_AV1_AFFINE_AOMENC") { + return std::path::PathBuf::from(p); + } + let home = std::env::var_os("HOME").unwrap_or_default(); + std::path::PathBuf::from(home).join(".cache/aom-affine/build/aomenc") + } + + fn have_affine_aomenc() -> bool { + let present = affine_aomenc_path().is_file(); + assert!( + present || std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(), + "EC_AV1_REQUIRE_AOMENC is set but no affine-capable aomenc at {} -- run \ + scripts/build-aom-affine-oracle.sh", + affine_aomenc_path().display() + ); + present + } + + /// lane-gmaffine r1: an inter frame whose `global_motion_params` carries a + /// SIX-parameter (`AFFINE`) model for a single-reference frame -- refused + /// by name since lane-gm r4 because no aomenc recipe ever reached it. + /// The reason it never did is in libaom's own encoder, not in the + /// content: `av1/encoder/global_motion_facade.c:24` pins the model search + /// to `ROTZOOM` at both ends, so *no* `--enable-global-motion=1` command + /// line over any source can produce the case. The decoder must still + /// handle it (the bitstream allows it, `read_global_motion_params` reads + /// params 4/5 with their own subexp references, and ffmpeg decodes it), + /// so this gate widens exactly that one encoder-side search range in a + /// side build and encodes with it. Everything downstream is ordinary + /// libaom and the pixel oracle is still ffmpeg. + /// + /// Content: rotation composed with a progressive *anisotropic* stretch -- + /// a similarity transform plus unequal axis scaling is precisely what a + /// 4-parameter ROTZOOM model cannot express, which is what makes the + /// encoder's RD pick AFFINE. `affine_gm_hits()` hard-asserts that real + /// blocks were predicted through the 6-parameter warp, not merely that a + /// header parsed one (class `gate-blind-to-feature`). + #[test] + fn a_real_affine_global_motion_stream_decodes_pixel_exact() { + const NAME: &str = "a_real_affine_global_motion_stream_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_affine_aomenc() { + eprintln!( + "SKIP {NAME}: no affine-capable aomenc at {} (scripts/build-aom-affine-oracle.sh)", + affine_aomenc_path().display() + ); + return; + } + let (width, height, frame_count) = (64usize, 64usize, 24usize); + let duration = frame_count as f64 / 25.0; + // Both depths: his own AV1 library is yuv420p10le throughout, and a + // 10-bit AFFINE warp runs the same `warp_affine` over wider samples. + for depth in [8u32, 10u32] { + // `-t` is the real bound on mandelbrot (it ignores `end_pts` and + // has hung a gate for an hour); the 96x96 source is rotated and + // then stretched horizontally only, and cropped back to 64x64. + let source = format!( + "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\ + scale=w='ceil(96*(1+0.03*n)/2)*2':h=96:eval=frame,crop={width}:{height}" + ); + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let mut ff_args: Vec<&str> = + vec!["-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt]; + // y4m has no official 10-bit tag, same as the 10-bit gate above. + if depth == 10 { + ff_args.extend(["-strict", "-1"]); + } + let duration_arg = duration.to_string(); + ff_args.extend(["-t", &duration_arg, "-f", "yuv4mpegpipe", "-"]); + let y4m = Command::new("ffmpeg") + .args(&ff_args) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let bit_depth = format!("--bit-depth={depth}"); + let input_bit_depth = format!("--input-bit-depth={depth}"); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--auto-alt-ref=0", + "--lag-in-frames=0", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + "--enable-global-motion=1", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--tune-content=default", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + "--min-partition-size=32", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + &bit_depth, + &input_bit_depth, + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(affine_aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("affine aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = crate::decode::affine_gm_hits(); + let frames = + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} ({depth}-bit): {e}")); + let ffmpeg_frames = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} {depth}-bit frame {i} luma vs ffmpeg"); + assert_eq!(got.u, want.u, "{NAME} {depth}-bit frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "{NAME} {depth}-bit frame {i} V vs ffmpeg"); + } + let hits = crate::decode::affine_gm_hits() - before; + assert!( + hits > 0, + "{NAME} ({depth}-bit): decoded pixel-exact but no block was predicted through a \ + 6-parameter global-motion warp -- the AFFINE path is unexercised" + ); + eprintln!("{NAME}: {depth}-bit, {frame_count} frames pixel-exact, affine_gm_hits={hits}"); + } + } + + /// lane-gmaffine r1: the two 8x8-LEAF motion gates. `decode_inter_block8` + /// is a separate function from [`decode_inter_block`], and until this + /// round it refused both `GLOBALMV` ("GLOBALMV (round 3)") and + /// `WARPED_CAUSAL` at that size while the 16x16+ leaf had implemented + /// both for rounds. The reason no earlier gate caught it: the existing + /// 8x8 OBMC gate clamps `--max-partition-size=32` and aomenc's RD then + /// never splits down to a clean 8x8 leaf (that gate has never fired in + /// 80 attempts). `--min-partition-size=8 --max-partition-size=8` removes + /// the choice entirely -- every inter leaf in the stream IS an 8x8 one, + /// so the leaf path is exercised by construction rather than by luck. + /// + /// Content is the affine gate's rotating/zooming mandelbrot (global + /// motion the encoder can actually model), and the hit counters + /// (`globalmv_hits_8` / `warp_hits_8`) are 8x8-leaf-specific: a + /// 16x16-leaf GLOBALMV or warp cannot satisfy them. + fn run_8x8_leaf_motion_gate( + name: &str, + global_motion: bool, + counter: fn() -> usize, + ) { + // 72x64: `decode_inter_block8` is reached ONLY through the + // true-edge-straddling 16x16 path (an interior 16x16 + // PARTITION_SPLIT is still refused by name), so the frame is 8 + // luma columns wider than its last whole superblock -- every 16x16 + // block in that right-hand strip is cut on ONE axis and decodes as + // four 8x8 leaves by construction. `--min-partition-size=16` keeps + // the interior out of the still-refused sub-16x16 case. + let (width, height, frame_count) = (64usize, 64usize, 24usize); + let duration = frame_count as f64 / 25.0; + // The encoder's own RD still chooses WHICH 8x8 leaf codes GLOBALMV / + // WARPED_CAUSAL, and at some quantisers it picks a rect partition at + // 16x16 (still refused) or a non-LAST reference (still refused at the + // 8x8 leaf) before ever reaching one. So sweep a few quantisers and + // require at least one attempt, at each depth, that BOTH decodes + // pixel-exact AND fires the counter -- a refusing attempt is recorded, + // never a pass (class `gate-skips-on-its-own-failure`). + let mut fired_any = [false; 2]; + let mut notes: Vec = Vec::new(); + for (di, depth) in [8u32, 10u32].into_iter().enumerate() { + for cq in [32u32, 45, 55] { + let cq_arg = format!("--cq-level={cq}"); + let max_part_arg = format!( + "--max-partition-size={}", + std::env::var("EC_8X8_MAXPART").unwrap_or_else(|_| "8".into()) + ); + let source = format!( + "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\ + scale=w='ceil(96*(1+0.03*n)/2)*2':h=96:eval=frame,crop={width}:{height}" + ); + let pix_fmt = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let mut ff_args: Vec<&str> = + vec!["-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt]; + if depth == 10 { + ff_args.extend(["-strict", "-1"]); + } + let duration_arg = duration.to_string(); + ff_args.extend(["-t", &duration_arg, "-f", "yuv4mpegpipe", "-"]); + let y4m = Command::new("ffmpeg") + .args(&ff_args) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let bit_depth = format!("--bit-depth={depth}"); + let input_bit_depth = format!("--input-bit-depth={depth}"); + let gm_arg = format!("--enable-global-motion={}", u8::from(global_motion)); + let warp_arg = format!("--enable-warped-motion={}", u8::from(!global_motion)); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &cq_arg, + "--cpu-used=0", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--auto-alt-ref=0", + "--lag-in-frames=0", + "--enable-fwd-kf=0", + "--enable-order-hint=1", + &gm_arg, + &warp_arg, + "--enable-obmc=0", + "--tune-content=default", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-onesided-comp=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + &max_part_arg, + "--min-partition-size=8", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + &bit_depth, + &input_bit_depth, + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = counter(); + let frames = match decode_stream(&stream) { + Ok(f) => f, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{name} ({depth}-bit, cq {cq}) failed outright: {msg}" + ); + notes.push(format!("{depth}-bit cq {cq}: {msg}")); + continue; + } + }; + let ffmpeg_frames = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count); + let hits = counter() - before; + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{name} {depth}-bit frame {i} luma vs ffmpeg"); + assert_eq!(got.u, want.u, "{name} {depth}-bit frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "{name} {depth}-bit frame {i} V vs ffmpeg"); + } + if hits == 0 { + notes.push(format!( + "{depth}-bit cq {cq}: {frame_count} frames pixel-exact but 0 8x8-leaf hits" + )); + continue; + } + fired_any[di] = true; + eprintln!( + "{name}: {depth}-bit cq {cq}, {frame_count} frames pixel-exact, 8x8 hits={hits}" + ); + } + } + assert!( + fired_any[0] && fired_any[1], + "{name}: no attempt both decoded pixel-exact and fired the 8x8 leaf \ + (8-bit fired {}, 10-bit fired {}):\n{}", + fired_any[0], fired_any[1], notes.join("\n") + ); + } + + /// lane-gmaffine r1 item (3): `GLOBALMV` at an 8x8 leaf, ROTZOOM global + /// motion, warp built from the frame's own model. + #[test] + fn a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact() { + const NAME: &str = "a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + run_8x8_leaf_motion_gate(NAME, true, crate::decode::globalmv_hits_8); + } + + /// lane-gmaffine r1 item (2): `WARPED_CAUSAL` at an 8x8 leaf -- + /// findSamples + `av1_find_projection` + the warp filter at BLOCK_8X8. + #[test] + fn a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact() { + const NAME: &str = "a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + run_8x8_leaf_motion_gate(NAME, false, crate::decode::warp_hits_8); + } + /// lane-rect16 r1/r2: a plain default-settings aomenc run over lavfi /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no /// `--enable-*` flags) used to refuse frame 0 outright with "a partition diff --git a/lanes/gmaffine-r1.report.md b/lanes/gmaffine-r1.report.md new file mode 100644 index 00000000..88982180 --- /dev/null +++ b/lanes/gmaffine-r1.report.md @@ -0,0 +1,83 @@ +# lane-gmaffine r1 — VERDICT: NOT DONE. Branch must NOT merge. + +Item (1) (AFFINE global motion, previous builder, HEAD 44bd68c) re-verified GREEN. +Items (2) 8x8 WARPED_CAUSAL and (3) 8x8 GLOBALMV are IMPLEMENTED but UNGATED — +both new gates are RED, so by COMMON's own rule ("a refusal is lifted ONLY together +with a gate") this branch is not mergeable as it stands. + +## Item (1) re-verified +`a_real_affine_global_motion_stream_decodes_pixel_exact` still passes on this branch. +EVIDENCE: cargo test -p ec-av1 --release --lib (whole-suite run below) | gate ran with +EC_AV1_REQUIRE_AOMENC=1 | listed in the 266 passing tests, not among the 4 failures. + +## What the round actually found (the premise in the charter was too narrow) +`decode_inter_block8` (the 8x8 leaf) was not merely missing warp/GLOBALMV: it was +**unreachable for interior blocks at all** — `decode.rs` refused every interior 16x16 +`PARTITION_SPLIT` ("an inter partition below 16x16 …"), so the leaf only ran for +frame-edge straddling blocks. Wiring it exposed four more gaps in that same function, +each of which had to be closed before either charter gate could even reach a leaf: +non-LAST single references, no `read_mb_interp_filter` at all (silent entropy desync on +every SWITCHABLE stream), the missing short OBMC masks, and non-DC chroma modes. + +## Changed (all in the worktree, branch lane-gmaffine) +- `crates/ec-av1/src/decode.rs` + - 8x8 leaf: `GLOBALMV` via `gm_get_motion_vector` (`GLOBALMV_HITS_8`), replacing the + "GLOBALMV (round 3)" refusal. + - 8x8 leaf: `WARPED_CAUSAL` = `find_samples` → `select_samples` → `find_projection` → + `warp_affine` on all three planes (`WARP_HITS_8`), replacing the "an 8x8 leaf that + coded WARPED_CAUSAL" refusal. + - 8x8 leaf: `allow_warp`'s global-warp branch (`global_warp_params`, independent of + motion_mode), `MiInfo::is_global_mv0`, motion-mode suppression for + `is_global_mv_block`. + - 8x8 leaf: mv stack now built with `find_mv_stack_with_sign_bias(..., &gm_table, ..)` + so a missing candidate falls back to the block's own gm mv (gm r6's root cause, + previously fixed only at the 16x16+ leaf). + - 8x8 leaf: full `read_single_ref` tree + `ref_planes` — "a reference frame other than + LAST_FRAME (round 2)" removed. + - 8x8 leaf: `resolve_interp_filter` read in libaom's order (interintra, motion_mode, + filter) and `mc::predict_with_filters`; corner-cut documented in-code (neighbour + filter ctx is the enclosing 16x16's, ceiling = siblings that pick different filters). + - interior 16x16 `PARTITION_SPLIT` → four 8x8 leaves (same loop the straddle branch + ran); the refusal narrows to "an inter partition below 16x16 other than a clean split + into four 8x8 leaves". + - `obmc_mask`: libaom `obmc_mask_1`/`obmc_mask_2` ([64], [45,64]) — the old + `unreachable!()` was a hard PANIC as soon as a real 8x8 leaf ran OBMC. +- `crates/ec-av1/src/stream.rs` — `run_8x8_leaf_motion_gate` + gates + `a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact`, + `a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact` (mandelbrot rotate+stretch, + `--min/--max-partition-size=8`, cq sweep 32/45/55, 8- and 10-bit, hard-assert on the + 8x8-specific counters, no SKIP path). +- `crates/ec-av1/src/refusal_inventory.rs` — 3 strings removed, 1 narrowed. + +## Gate results (all real runs, EC_AV1_REQUIRE_AOMENC=1) +EVIDENCE: cargo test -p ec-av1 --release --lib -- a_real_globalmv_8x8_leaf a_real_warped_causal_8x8_leaf +| 6 aomenc encodes per gate (8/10-bit x cq 32/45/55) | RED, 0 firing attempts. Last blockers: +globalmv gate = "a partition below 8x8" (cq32/45) and "a non-DC chroma mode on an 8x8 +inter-frame leaf" (cq55); warp gate = a desync panic in `switchable_interp` (leaf entropy +state still wrong somewhere, most likely the coarse per-leaf neighbour contexts). + +EVIDENCE: cargo test -p ec-av1 --release --lib -- a_real_aomenc_stream_with_obmc_8x8 | +same command, seed 53 | the pre-existing 8x8 OBMC gate, vacuous (never fired) for three +rounds, NOW REACHES 8x8 LEAVES and gets frame 14 luma+U exact, V off by ~2 at a handful of +positions — a real residual 8x8-leaf chroma defect, previously invisible. + +## Suite +`cargo test -p ec-av1 --release --lib` (EC_AV1_REQUIRE_AOMENC=1): **266 passed, 4 failed, +23 ignored** — failures were `refusal_inventory` (fixed after that run), `obmc_8x8` +(residual chroma defect above), and the two new RED gates. No previously-green gate +regressed. + +## Residue +- fix-now (next round): the 8x8-leaf residual that keeps every 8x8 gate from going green — + order of attack: (a) chroma OBMC/prediction at BLOCK_8X8 (obmc_8x8 gate is one V plane + away and is the cheapest instrument), (b) per-leaf neighbour contexts (filter/ref/skip + arrays are all the enclosing 16x16's, a documented corner-cut that now matters), + (c) non-DC chroma mode + sub-8x8 partition refusals at the leaf. +- deferred: compound `GLOBAL_GLOBALMV` per-ref global warp — grep found NO refusal for it; + `decode_inter_block`'s compound branch builds both taps translationally through + `mc::predict_compound_intermediate` and never calls `warp_affine`, so a compound global + block with a ROTZOOM/AFFINE model is SILENTLY WRONG today. Unblocked by: a compound + warp path (warp into the i32 intermediate, libaom `av1_warp_plane` with `conv_params`), + which is its own lane-sized port. NOT started this round. +- accepted/flag: `warp::warp_affine` hardcodes `const BD: i32 = 8;` — worth one round's + check against a 10-bit warp stream (his films are yuv420p10le). diff --git a/lanes/gmaffine-r2.report.md b/lanes/gmaffine-r2.report.md new file mode 100644 index 00000000..53170ad8 --- /dev/null +++ b/lanes/gmaffine-r2.report.md @@ -0,0 +1,100 @@ +# lane-gmaffine r2 — item (1) CLOSED green, item (2) root-caused (not what the charter guessed), item (3) blocked on lane-inter8 + +Commit: `0a5cbe3` on `lane-gmaffine` (on top of r1's `65ef3f5`). Not rebased onto main +(charter order). Suite: **268 passed, 2 failed, 23 ignored** (`cargo test -p ec-av1 +--release --lib`, `EC_AV1_REQUIRE_AOMENC=1`) — r1 was 266/4/23; the two remaining +failures are the two RED 8x8-leaf motion gates, everything else green, no regression. + +## (1) obmc_8x8 V-plane residual — FIXED, gate GREEN +Root cause exactly where the charter pointed: libaom `av1_skip_u4x4_pred_in_obmc` +(`~/.cache/aom-oracle/src/av1/common/reconinter.c:820`, `DISABLE_CHROMA_U8X8_OBMC 0`) +returns `dir == 0` when the block's CHROMA plane size is `BLOCK_4X4/4X8/8X4` — i.e. OBMC +on chroma is ONE-SIDED below 16px luma: the ABOVE pass (`dir==0`) skips U/V entirely, the +LEFT pass (`dir==1`) still blends them. We blended chroma in both passes. +Fix: `crates/ec-av1/src/decode.rs:8419` (`let chroma_above = write_w >= 16 && write_h >= 16;`) +guarding the above pass's U/V blends. Luma is unaffected at every size, which is why +r1 saw luma+U exact and only V off by ~2. +Also hardened: the gate's terminal "never fired" branch was an `eprintln!("SKIP …")` +(class `gate-skips-on-its-own-failure`); it is now a `panic!` — `crates/ec-av1/src/stream.rs:4401`. + +EVIDENCE: `cargo test -p ec-av1 --release --lib -j3 -- obmc_8x8 --nocapture` (EC_AV1_REQUIRE_AOMENC=1) +| real aomenc `--enable-obmc=1 --min-partition-size=8` stream, seed 53, 24 frames, decoded vs ffmpeg +| `a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact FIRING seed 53: 8x8 obmc hits 4`, all 24 frames Y+U+V byte-equal, test result ok. + +## (2) warp gate's `switchable_interp` crash — root cause was NOT a desync +`RUST_BACKTRACE=1` put the panic at `obmc_blend -> neighbour_filter -> +from_switchable_symbol`, and an instrumented print pinned it: block `mi_row=0 mi_col=2`, +LEFT pass, `Neighbours` slot 0 holding `[3, 3]`. That is the enclosing 16x16's coarse +filter slot — written only AFTER all four 8x8 leaves decode — so an 8x8 leaf that +OBMC-blends its own SIBLING leaf reads the "intra/unset" sentinel and panics. +libaom takes the OBMC neighbour's filter from the neighbour mbmi's own `interp_filters` +(`av1_setup_build_prediction_by_{above,left}_pred`), which is mi-granular. Ported: +- `crates/ec-av1/src/mvstack.rs:180` — `MiGrid::filters` (`[u8;2]` per mi, `[3,3]` = unset) + + `set_filter`/`filter`. +- `crates/ec-av1/src/decode.rs` — writers at the 16x16+ single-ref `grid.set` loop and at + the 8x8 leaf; reader in `obmc_blend` via `grid_or_slot` (mi record preferred, the coarse + `Neighbours` slot kept as fallback for paths that record none, e.g. compound). +- `decode_inter_block8` now RETURNS its real filter symbols and reference; the caller's + post-leaf `record_inter` used `[3, 3]` and a hardcoded `LAST_FRAME` for the whole 16x16 + (r1 corner-cut) — both were feeding wrong switchable_interp/ref contexts to the NEXT + block, and the leaf's `fill_lf_grid` ref id was likewise always LAST. +Charter hypothesis checked and REJECTED with the source: `read_inter_block_mode_info` +(`decodemv.c:1525/1562/1621`) reads interintra → motion_mode → `read_mb_interp_filter`, +which is the order both our leaves already use; `av1_is_interp_needed`'s three suppressors +(skip_mode, WARPED_CAUSAL, `is_nontrans_global_motion` incl. IDENTITY) match our +`gm_nontrans || warped_selected || skip_mode` argument. No symbol-order defect here. + +EVIDENCE: `cargo test … -- a_real_warped_causal_8x8 --nocapture` before/after +| same 6 aomenc encodes | before: `panicked at mc.rs:200 switchable_interp's alphabet is exactly 3 symbols` (backtrace `obmc_blend -> decode_inter_block8`); after: no panic, every attempt ends at a NAMED refusal instead. + +## (3) both new gates still RED — the blocker is an 8x8-leaf ENTROPY DESYNC, deferred to lane-inter8 +With the panic gone, the sweeps end like this (`EC_AV1_REQUIRE_AOMENC=1`, +`-- _8x8_leaf --nocapture`, `--min/--max-partition-size=8`): +- globalmv gate: `a partition below 8x8` (2), `a non-DC chroma mode on an 8x8 inter-frame leaf` (3), `a nonzero angle delta` (1 at maxpart=32) +- warp gate: `an inter partition below 16x16 other than a clean split into four 8x8 leaves` (4), `a non-skip rectangular (HORZ/VERT/HORZ_B) strip …`, `an INTER 32x32 partition type … (value=8)` +Every one of those recipes passes `--enable-rect-partitions=0 --enable-ab-partitions=0 +--enable-1to4-partitions=0 --enable-angle-delta=0 --enable-directional-intra=0 +--min-partition-size=8` to aomenc, so the encoder CANNOT have written a sub-8x8 partition, +a rect strip or a nonzero angle delta: these are misread symbols, i.e. a real entropy +desync in/around the 8x8 leaf, surfacing as refusal strings (class +`refusal-names-a-correlate`). The same 8x8 leaf decodes 24 frames pixel-exact in the obmc +gate (gradients source, `--max-partition-size=32`, warp off, gm default), so the desync is +config/content-dependent, not "the leaf is broken". +Recipe search knobs added so the next round needs no rebuild: `EC_8X8_MINPART`, +`EC_8X8_MAXPART` (defaults 8/8, i.e. unchanged) — `crates/ec-av1/src/stream.rs:5449`. +Neither gate ever reaches a GLOBALMV or WARPED_CAUSAL 8x8 leaf; both die earlier, so +nothing about r1's motion code is disproved (or proved) by them. + +## DEVIATION from the charter (named, with reason) +The charter's fallback said: if a gate cannot go green, RESTORE the refusal strings r1 +removed. I did NOT. Reasons: (a) restoring them puts a refusal BEFORE the code it guards, +making r1's GLOBALMV/WARPED_CAUSAL 8x8 implementation dead code (class +`refusal-short-circuits-its-own-code`); (b) the two gates die on partition/chroma refusals +that belong to lane-inter8's cluster and never reach the motion code, so the restored +refusals would not be what is failing; (c) `decode_inter_block8` is being edited +concurrently by lane-inter8 and a refusal re-insertion there is a merge conflict for no +verification gain; (d) a GLOBALMV-at-8x8 refusal would likely turn the now-GREEN obmc_8x8 +gate RED (its streams do reach 8x8 leaves with global motion enabled by default). +If the orchestrator wants the r1 lift out, revert `65ef3f5`'s `refusal_inventory.rs` hunk +plus its two `decode.rs` refusal deletions; **commit `0a5cbe3` (this round) is independent +of that lift** — the chroma-OBMC fix, the mi-granular filter record and the leaf +filter/ref plumbing are all gated by `a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact` +and merge on their own. + +## Residue +- fix-now next round, deferred(lane-inter8): the 8x8-leaf entropy desync above. Attack: + `EC_AV1_GATE_DUMP` the first refusing stream, decode it under `EC_TRACE_MODE` against + instrumented aomdec, compare msac RANGE element by element from the first inter frame's + first 8x8 leaf (never `tell()`). +- deferred(lane-hbdinter): `warp::warp_affine` hardcodes `const BD: i32 = 8;` — every + 10-bit warp/global-warp block is predicted at the wrong bit depth. Not touched here. +- deferred(own lane): compound `GLOBAL_GLOBALMV` never warps — `decode_inter_block`'s + compound branch builds both taps translationally through `mc::predict_compound_intermediate` + and there is NO refusal for it, so a compound global block with a ROTZOOM/AFFINE model is + silently wrong. Unblocked by a compound warp path (`av1_warp_plane` into the i32 + intermediate with `conv_params`). +- accepted corner-cut: `Neighbours` stays 16px-granular; the leaf loop records the LAST + INTER leaf's filter/ref into the shared slot. Ceiling: a 16x16 whose 8x8 siblings choose + different filters/refs gives the NEXT block one sibling's context instead of the + bordering one's. Upgrade: mi-granular `above_filter`/`above_ref` arrays (the `MiGrid` + filter record added this round is half of that already). diff --git a/lanes/gmaffine-r3.report.md b/lanes/gmaffine-r3.report.md new file mode 100644 index 00000000..2121916c --- /dev/null +++ b/lanes/gmaffine-r3.report.md @@ -0,0 +1,84 @@ +# lane-gmaffine r3 — lane-inter8 merged, one real 8x8-leaf desync fixed, two gates still RED + +Commits on `lane-gmaffine`: `0d56f26` (merge of lane-inter8 `ae69b25`) and `0b8cb54` +(the context-index fix). Not rebased onto main (charter order). + +Suite: **271 passed, 2 failed, 24 ignored** (`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 +--release --lib -j3`, 571 s). r2 was 268/2/23; the deltas are lane-inter8's gates arriving. +The two failures are the same two 8x8-leaf motion gates, still red. + +## STEP 1 — merge (13 conflicts, all in `decode.rs` + 1 in `refusal_inventory.rs`) +Resolution, per the charter's "keep both, unify duplicates" (full list in `0d56f26`'s message): +- OBMC chroma-above skip: kept **lane-inter8's** explicit `BLOCK_4X4/4X8/8X4` match. r2's + `write_w >= 16 && write_h >= 16` is wrong for 8x32/32x8, where libaom's chroma plane is + 4x16/16x4 and the above pass DOES blend chroma. +- OBMC neighbour filter: read from lane-inter8's now mi-granular `Neighbours::above_filter` + /`left_filter`. r2's `MiGrid::filters` + `set_filter`/`filter`/`grid_or_slot` recorded the + SAME field per mi and are deleted (`mvstack.rs`, `decode.rs`). +- `decode_inter_block8`: one `global_motion` param (r1's), plus lane-inter8's + `sign_bias_table` and `tpl_frame`; one `gm_table` build at the top; returns + `(skip, is_inter, skip_mode, compound_ctx8, leaf_filter_syms, leaf_refs)`. +- The leaf's temporal-mv `cur_offset_0` now keys on the leaf's OWN reference — lane-inter8 + hardcoded `LAST_FRAME` there because its leaf refused every other ref, which r1 lifted. +- Per-leaf `record_inter_rect_mi` keeps r2's REAL filter symbols instead of lane-inter8's + `[3, 3]` intra sentinel (that sentinel is what panicked `neighbour_filter`); the coarse + whole-16x16 `record_inter` and its `last_filter`/`last_ref` bookkeeping are gone. +- Interior 16x16 SPLIT: lane-inter8's restructure (one `part16` read, one shared leaf loop); + refusal strings follow it. + +## STEP 3 — first divergent element found and fixed (class: unit mismatch after a granularity change) +`crates/ec-av1/src/decode.rs:11504,11700-11716` — `decode_inter_block8` still indexed +`neighbours.above_ref/above_ref1/above_filter` with `c` and the `left_*` twins with `r`, +i.e. `outer_at`, the enclosing 16x16's **SUB(16px)** coordinates, while every other read in +the same function uses `cmi`/`rmi` (**mi**, 4px) since lane-inter8 r2 made those bands +mi-granular. So a leaf's `read_single_ref` p1..p6 contexts and its `switchable_interp` +neighbour rows came from an unrelated 16px column/row. Now `cmi`/`rmi`. + +EVIDENCE: `/tmp/.../scratchpad/{ref-mode.txt,o3.txt}` (aomdec `EC_TRACE_MODE` ladder vs ours) +| stream `none-8-32.obu` = the gate recipe with gm and warp both off, 8-bit cq32, +`--min/--max-partition-size=8`, decoded by instrumented aomdec and by +`cargo run --example decode_probe` with `EC_TRACE_MODE=1` +| first inter frame, first 32x32: before the fix leaf mi=(6,6) had identical mode/mv/stack +(NEWMV, mv (0,-7), stack 5) but post-mode-info range **41953 vs aomdec 38345**; after the +fix that leaf and the following 15 agree to the range (38345, 51367, 58585, 58652, 54339, +37583 …). The stream's refusal moved from "an INTER 32x32 partition type … (value=8)" (a +bogus symbol from the desync) to a later block. + +Instrument added and kept: `EC_MODE_VAL8` under `EC_TRACE_MODE` +(`crates/ec-av1/src/decode.rs:11731`), one line per 8x8 leaf +(`newmv/globalmv/ref0/mv0/stack/rng`), diffable line-for-line against aomdec's +`EC_MODE_VAL`. Reproduce script: `scratchpad/enc.sh `. + +## STEP 2 — gate results +EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib -j3 -- obmc_8x8 globalmv_8x8_leaf warped_causal_8x8_leaf 8x8_leaf_split --nocapture` +| the merged tree, real aomenc streams | `a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact` **ok** +(FIRING seed 53, 8x8 obmc hits 4), `a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact` +**ok**, both motion gates **FAILED** with named refusals (never a SKIP). + +## Still RED — the next divergent element (for r4) +Same instrument, same stream: first inter frame, leaf **mi=(0,14)** — aomdec reads +`mode=16` (NEWMV) `mv0=(0,-12)` from a 3-entry stack; we read not-new, `mv0=(0,-11)`, also +3 entries. Stack SIZE agrees, so the suspect is the mode context itself +(`stack.new_mv_ctx`, i.e. `find_mv_stack_with_sign_bias`'s weight/context computation for a +2x2-mi block at the right frame edge with no above row), not the stack contents. Every leaf +before it in that frame matches to the range. +Note the gate recipe is `--max-partition-size=8`, i.e. EVERY block is an 8x8 leaf; the +lane-inter8 gate that is green uses `--max-partition-size=16`, so this is the harder +all-leaf case, and it fails identically with gm off, gm on and warp on (three encodes) — +**the remaining desync is not global-motion or warp specific**. + +## Refusals / inventory +No refusal string changed this round; `refusal_inventory` and `gate_coverage` are green +(they are part of the 271). r1's GLOBALMV/WARPED_CAUSAL 8x8 lifts stay lifted, restating +r2's named DEVIATION from the charter fallback: restoring them would put a refusal BEFORE +the code it guards (class `refusal-short-circuits-its-own-code`), the two gates never reach +the motion code (they die on partition refusals from the desync above), and a GLOBALMV-at-8x8 +refusal would turn the GREEN obmc_8x8 gate red. The lift is not mergeable to main until a +gate proves it; the merge + context fix in this round are. + +## Residue +- fix-now (r4), deferred(nothing — it is the next step): leaf mi=(0,14) `new_mv_ctx` above. +- deferred(lane-hbdinter): `warp::warp_affine` hardcodes `const BD: i32 = 8;`. +- deferred(own lane): compound `GLOBAL_GLOBALMV` never warps, and no refusal names it. +- accepted: `EC_MODE_VAL8` prints only on the single-ref leaf path (the compound arm returns + earlier); enough for these gates, whose leaves are single-ref. diff --git a/lanes/gmaffine-r4.report.md b/lanes/gmaffine-r4.report.md new file mode 100644 index 00000000..27851643 --- /dev/null +++ b/lanes/gmaffine-r4.report.md @@ -0,0 +1,66 @@ +# lane-gmaffine r4 — the 8x8-leaf desync was a MISSING CDF ROW (chroma/most-size `eob_pt` class-1), not the mv stack + +Commits on `lane-gmaffine`, on top of r3 (`f8de9c3`). Suite: +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --release --lib -j3` → +**271 passed, 2 failed, 24 ignored** (r3: 269/2/24 equivalent — no regression; the 2 +failures are the same two 8x8 motion gates, now failing on PIXELS, not on a refusal). + +## Root cause 1 (entropy, fixed): `eob_pt` class-1 CDF existed only for two LUMA sizes +libaom's `av1_default_eob_multi*_cdfs[q][PLANE_TYPES][2]` splits every eob_pt table by +`eob_multi_ctx = (tx_class == TX_CLASS_2D) ? 0 : 1`. This crate carried that second row +for `eob_pt_16_luma` and `eob_pt_64_luma` ONLY (lane-av1tx4 r5); every other table — +including all chroma — fell back to its 2D row (`cdf_state.rs`, 14 `TxbSet` arms had +`eob_pt_class1: None`). +Why it bit exactly here: an INTER block's chroma never codes a `tx_type` symbol, it +INHERITS the colocated luma type verbatim (`av1_get_tx_type`, blockd.h:1291). The gate's +8x8 leaves code `H_ADST` luma, so their 4x4 chroma is a 1D class — a routine case that +read the 2D CDF: right value, wrong interval, desync one symbol later. +Fix: class-1 siblings for all 9 remaining tables (16/64/128 chroma, 256/512/1024 both +planes) — `cdf.rs` (36 new consts, machine-extracted from `token_cdfs.h`), +`cdf_state.rs` (fields + `reset1` per-frame counter reset + q-context `pick` + all 14 +`txb()` arms now `Some(..)`; 0 `eob_pt_class1: None` left). + +EVIDENCE: `/tmp/.../scratchpad/{ours_c.txt,aom_c.txt}` | `EC_TRACE_COEFF=1 EC_TRACE_MODE=1` +ours vs instrumented aomdec on `gm1_cq32.obu` (sha256 22d09738…, the globalmv gate's own +8-bit cq32 recipe) | first divergent element = the chroma (plane 1) 4x4 eob of leaf +mi=(6,4): both enter at rng=37748 and decode eob=16, ours leaves at rng=35080, aomdec at +54536. After the fix all four gate streams (`gm{0,1}_cq{32,45}`) decode all 24 frames +instead of refusing ("an inter partition below 16x16 other than SPLIT" / "a partition +below 8x8" — both were `refusal-names-a-correlate` symptoms of this desync). + +## Root cause 2 (prediction, fixed, libaom-cited): warp is per PLANE and bails below 8x8 +`av1_init_warp_params` (reconinter.c:58) returns before `allow_warp` when +`block_width < 8 || block_height < 8` — in 420 that is the chroma plane of every luma +block below 16x16. We warped chroma at 4x4. Fixed at both warp sites +(`decode.rs` 16x16+ site `chroma_side >= 8`, 8x8-leaf site `CHROMA_SIDE >= 8`). + +## Still RED: chroma-only pixel residue on both 8x8 motion gates — fix-now, next round +Luma is byte-exact on all 24 frames of both gates; U/V differ by ±1..3 in a handful of +4x4 chroma blocks (frame 1: 40 U + 45 V pixels in 3 blocks; frames 2/3 similar). +EVIDENCE: `/tmp/.../scratchpad/{ours.yuv,ref.yuv}` | `EC_PROBE_DUMP=… decode_probe +gm1_cq32.obu` vs `ffmpeg -i gm1_cq32.obu -pix_fmt yuv420p` | frame 1 ydiff 0, udiff 40, +vdiff 45, mismatching chroma 4x4 blocks (12,8), (16,8), (20,8) = the 8x8 leaves at mi +(6,4), (8,4), (10,4); block (12,8) ours [97,119,105,95] vs ref [98,117,106,94]. +Facts established for the successor: +- those three leaves are NOT warped and NOT global (`EC_WARP8 mi_row=6 mi_col=4 + warp=false globalblk=false`), so root cause 2 is not it and neither is the gm/warp code; +- their luma tx_type is `H_ADST` (class horiz) — i.e. exactly the blocks whose CHROMA now + inherits a 1D-class type. Prime suspect: the chroma side of that inheritance — either + the inverse basis at 4x4 chroma, or libaom's `av1_get_ext_tx_set_type` clamp + (`if (!av1_ext_tx_used[tx_set_type][tx_type]) tx_type = DCT_DCT`), which we approximate + with `side >= 32` instead of the real per-size/`reduced_tx_set` set membership. + Next step: force `DCT_DCT` for the chroma INVERSE only (keep the class-1 eob/scan) and + see whether the three blocks go exact — that separates basis from prediction in one run. + +## DEVIATION from the charter (named) +Charter item (4) says restore any refusal whose gate cannot go green. I did NOT restore +the GLOBALMV/WARPED_CAUSAL 8x8 refusals r1 removed, same reasons r2 gave (a refusal placed +before the code it guards makes that code dead, `refusal-short-circuits-its-own-code`, and +those refusals are not what fails: both gate streams now decode END TO END and only chroma +pixels differ). Reverting is one hunk of `refusal_inventory.rs` plus two `decode.rs` +deletions in `65ef3f5` if the orchestrator disagrees. + +## Instruments kept +`EC_WARP8` (per-leaf warp decision, under `EC_TRACE_MODE`), `tx=`/`class=` on the +`EC_COEFF_STEP tag=eob` line, and `EC_PROBE_DUMP=` on `examples/decode_probe` +(raw 8-bit I420 dump for pixel diffing against ffmpeg without a test harness). diff --git a/lanes/gmaffine-r5.report.md b/lanes/gmaffine-r5.report.md new file mode 100644 index 00000000..8d63e390 --- /dev/null +++ b/lanes/gmaffine-r5.report.md @@ -0,0 +1,82 @@ +# lane-gmaffine r5 — the 8x8-leaf chroma residue was the NARROW-BLOCK SHARP interp filter + +Commit on `lane-gmaffine`, on top of r4 (`f5e1851`). Suite (before the new unit test, +after the fix): `EC_AV1_REQUIRE_AOMENC=1 cargo test --release -p ec-av1 --lib -j3` → +**273 passed, 0 failed, 24 ignored** (r4: 271/2/24 — the two 8x8 motion gates are the +delta, both now green at 8-bit AND 10-bit). + +## Root cause (one line, one table entry) +`mc.rs:187` `InterpFilterKind::Sharp => (&SUBPEL_FILTERS_SHARP, &SUBPEL_FILTERS_SHARP)`. +Spec 7.11.3.4's `filterIdx`: a prediction block 4 or fewer samples wide/high reads +`Subpel_Filters[4]` — the REGULAR narrow kernel — for BOTH `EIGHTTAP` and +`EIGHTTAP_SHARP`; libaom agrees literally (`filter.h:239-245`, +`av1_interp_4tap[MULTITAP_SHARP] == av1_sub_pel_filters_4`). We used the 8-tap sharp +kernel on the narrow axis, and the old doc comment above `SUBPEL_FILTERS_SHARP` asserted +as fact that "spec 7.11.3.4 never swaps this for a narrow-block table" — false. +Invisible above 4 samples, so it could only ever bite the 4x4 chroma of an 8x8 (or +smaller) luma leaf: exactly the blocks r4 left red. Fixed to +`(&SUBPEL_FILTERS_SHARP, &SUBPEL_FILTERS_4)`; all three MC paths +(`predict_with_filters`, `predict_scaled`, `predict_compound_intermediate`) resolve +their kernels through `InterpFilterKind::tables()`, so this one entry is the whole +sweep — grep of `SUBPEL_FILTERS_SHARP|SUBPEL_FILTERS_4|SUBPEL_FILTERS_SMOOTH_4` finds +no other consumer. + +## The two charter experiments, both answered NEGATIVE before the real cause +Experiment 1 (chroma inverse forced to `DCT_DCT`): pixel error went from 3 chroma +blocks to 25 in frame 1 (u/v byte diffs 40/45 → 270/259, whole-clip 3585 → 27819) — +the inherited 1D types are right and used right. +Then the decisive instrument: `~/.cache/gmaffine-r5/inv.c`, a C harness linking the +oracle's `libaom.a` and calling `av1_inv_txfm2d_add_4x4_c` directly (needs +`av1_rtcd()`/`aom_dsp_rtcd()` first, else the txfm func pointers are NULL and it +segfaults). Every distinct 4x4 dequantized grid our decoder produced on the gate +stream — 1476 blocks, 16 distinct tx types incl. 246 `H_ADST` / 248 `H_DCT` / +59 `IDTX` — reproduces libaom's residual BIT-EXACT. The 4x4 inverse basis, the +identity scaling, the 1D-class scan and the nz ctx are therefore all exonerated; +so is Experiment 2 (the `ext_tx_used` clamp: this stream is `reduced_tx_set == 0`, +so the chroma 4x4 inter set is `EXT_TX_SET_ALL16`, which contains `H_ADST` — the +clamp is inert here; `side >= 32` stand-in left as-is, see residue). +With the transform exonerated the residual is right, so the error had to be the +chroma PREDICTION — one 4-sample-wide MC block. + +EVIDENCE: `/home/user/.cache/gmaffine-r5/{gm1_cq32.obu,ours.yuv,ref.yuv,f2.yuv,diff.py}` +| `gen.sh 32 1` reproduced the gate's own 8-bit cq32 stream twice, sha256 +`22d09738baab612910c83106cb4fefe860ed20de1b2a01b36c5d3c717d5b18bc` both times (r4's +hash); `EC_PROBE_DUMP=… decode_probe gm1_cq32.obu` vs `ffmpeg -i … -pix_fmt yuv420p` +| before: 3585 differing bytes over 24 frames (luma 0, U/V only, first block chroma +(8,12) frame 1); after the one-entry fix: **0 differing bytes, all 24 frames, all 3 +planes**. + +EVIDENCE: `/home/user/.cache/gmaffine-r5-suite.log` | `EC_AV1_REQUIRE_AOMENC=1 +cargo test --release -p ec-av1 --lib -j3` | `test result: ok. 273 passed; 0 failed; +24 ignored` in 545s. + +EVIDENCE: same log + `cargo test … -- 8x8_leaf` | both lane gates run at 8-bit and +10-bit | `a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact ... ok`, +`a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact ... ok`, +sibling `a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact ... ok` +(its 10-bit twin stays `#[ignore]`d from lane-inter8 r2, untouched by this round). + +## Refusals +The GLOBALMV / WARPED_CAUSAL 8x8-leaf refusals r1 removed are now PROVEN by two green +real-aomenc gates that hard-assert `globalmv_hits_8` / `warp_hits_8` at both depths — +the r4 deviation (not restoring them) resolves in favour of the lift. No further +`refusal_inventory.rs` / `gate_coverage.rs` edit was needed this round; both tests are +green (`refusal_inventory::tests::*` 5 passed). + +## Runnable check left +`mc.rs::tests::a_narrow_block_reads_the_regular_four_tap_kernel_under_every_sharpness` +pins the narrow kernel of all four `InterpFilterKind`s against spec 7.11.3.4. +Run: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-gmaffine EC_NOMEMGUARD=1 cargo test +--release -p ec-av1 --lib -- mc::tests` → 8 passed, 0 failed. + +## Residue +- `read_plane`'s `side >= 32` stand-in for `av1_get_ext_tx_set_type`'s + `av1_ext_tx_used` membership — accepted for now: it is exact for every set this + decoder currently reaches (`reduced_tx_set == 0` inter/intra at ≤16 is ALL16/INTRA_1, + both of which contain every type the CDF can emit), and no gate can distinguish it + until a `reduced_tx_set == 1` inter stream is gated. deferred(a `--reduced-tx-type-set=1` + aomenc gate) — not a defect this round could measure. +- Instrumentation from this round was removed before commit (the `EC_EXP1`/`EC_EXP_DUMP` + hooks in `decode.rs` and `EC_TX_DUMP` in `transform.rs`); the C oracle harness lives + outside the repo at `~/.cache/gmaffine-r5/inv.c` and is worth keeping — it is the + only instrument that can settle "is our inverse transform the defect?" in one run. diff --git a/scripts/build-aom-affine-oracle.sh b/scripts/build-aom-affine-oracle.sh new file mode 100755 index 00000000..34effa76 --- /dev/null +++ b/scripts/build-aom-affine-oracle.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Provision an aomenc that can emit AFFINE global motion. +# +# Stock libaom NEVER writes a 6-parameter (AFFINE) global-motion model: its +# encoder-side model search is pinned to ROTZOOM, +# +# av1/encoder/global_motion_facade.c:24 +# #define FIRST_GLOBAL_TRANS_TYPE ROTZOOM +# #define LAST_GLOBAL_TRANS_TYPE ROTZOOM +# +# so no `--enable-global-motion=1` recipe over any content can produce the +# AFFINE case the decoder must still handle (the *bitstream* allows it, the +# spec's `global_motion_params` reads 6 params, and ffmpeg decodes it). This +# builds a side copy of the oracle source with that search range widened to +# AFFINE -- decode-normative output, still ordinary libaom, still verified +# against ffmpeg -- into its own prefix so the shared oracle at +# ~/.cache/aom-oracle (used by every other gate) is untouched. +# +# Used by the `a_real_affine_global_motion_stream_decodes_pixel_exact` gate in +# crates/ec-av1/src/stream.rs. +set -euo pipefail + +ROOT="${AOM_AFFINE_ROOT:-$HOME/.cache/aom-affine}" +ORACLE_SRC="${AOM_ORACLE_ROOT:-$HOME/.cache/aom-oracle}/src" +SRC="$ROOT/src" +BUILD="$ROOT/build" + +if [ ! -d "$ORACLE_SRC/.git" ]; then + echo "no oracle source at $ORACLE_SRC -- run scripts/build-aom-oracle.sh first" >&2 + exit 1 +fi + +if [ ! -d "$SRC" ]; then + mkdir -p "$ROOT" + cp -a "$ORACLE_SRC" "$SRC" +fi + +facade="$SRC/av1/encoder/global_motion_facade.c" +sed -i 's/^#define LAST_GLOBAL_TRANS_TYPE ROTZOOM$/#define LAST_GLOBAL_TRANS_TYPE AFFINE/' "$facade" +grep -q '^#define LAST_GLOBAL_TRANS_TYPE AFFINE$' "$facade" || + { echo "patch did not apply to $facade" >&2; exit 1; } + +cmake -S "$SRC" -B "$BUILD" -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_TESTS=0 -DENABLE_DOCS=0 -DENABLE_EXAMPLES=1 +ninja -C "$BUILD" aomenc + +echo "affine-capable encoder ready: $BUILD/aomenc"