diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index a7edca41..c1ea6eee 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -32,7 +32,21 @@ fn main() { Ok(frames) if frames.is_empty() => { println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?"); } - Ok(frames) => println!("OK: {} frames decoded", frames.len()), + Ok(frames) => { + // lane-gmaffine r4: `EC_PROBE_DUMP=` writes the decoded + // planes as raw 8-bit I420 so a pixel diff against ffmpeg can + // name the mismatching block without a test harness. + if let Ok(dump) = std::env::var("EC_PROBE_DUMP") { + let mut out = Vec::new(); + for f in &frames { + for p in [&f.y, &f.u, &f.v] { + out.extend(p.iter().map(|&v| v as u8)); + } + } + std::fs::write(&dump, out).expect("writing EC_PROBE_DUMP"); + } + println!("OK: {} frames decoded", frames.len()) + } Err(e) => println!("REFUSED: {e}"), } } diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index a097ea79..539166fa 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -4996,3 +4996,64 @@ pub const INTRA_TX_TYPE_SET1_4: [[u16; 8]; 13] = [ [277, 4369, 5255, 8905, 16465, 22271, 32768, 0], [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0], ]; + +// lane-gmaffine r4: the `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`eob_multi_ctx == 1`) +// half of libaom's `av1_default_eob_multi*_cdfs[q][plane][2]` for every eob_pt +// table that carried only its 2D row -- an inter block's chroma inherits the +// colocated luma `tx_type` verbatim, so a 1D-class chroma TU is routine and +// used to read the 2D CDF (right value, wrong interval). + +/// `EOB_PT_16_CHROMA`'s class-1 sibling (`av1_default_eob_multi16_cdfs[q][1][1]`). +pub const EOB_PT_16_CHROMA_CLASS1_Q0: [u16; 6] = [1904, 3354, 7763, 14647, 32768, 0]; +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_64_CHROMA`'s class-1 sibling (`av1_default_eob_multi64_cdfs[q][1][1]`). +pub const EOB_PT_64_CHROMA_CLASS1_Q0: [u16; 8] = [1563, 2700, 4876, 10911, 14706, 22480, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1_Q1: [u16; 8] = [1923, 3127, 5867, 9703, 14277, 27100, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1: [u16; 8] = [4034, 6290, 10235, 14982, 21214, 28491, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1_Q3: [u16; 8] = [8726, 12378, 19409, 26450, 30038, 32462, 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_256_LUMA`'s class-1 sibling (`av1_default_eob_multi256_cdfs[q][0][1]`). +pub const EOB_PT_256_LUMA_CLASS1_Q0: [u16; 10] = [998, 1850, 2998, 5604, 17341, 19888, 22899, 25583, 32768, 0]; +pub const EOB_PT_256_LUMA_CLASS1_Q1: [u16; 10] = [399, 1019, 1749, 3038, 10444, 15546, 22739, 27294, 32768, 0]; +pub const EOB_PT_256_LUMA_CLASS1: [u16; 10] = [1084, 2358, 3488, 5122, 11483, 18103, 26023, 29799, 32768, 0]; +pub const EOB_PT_256_LUMA_CLASS1_Q3: [u16; 10] = [2453, 4474, 6307, 8777, 16474, 22975, 29000, 31547, 32768, 0]; + +/// `EOB_PT_256_CHROMA`'s class-1 sibling (`av1_default_eob_multi256_cdfs[q][1][1]`). +pub const EOB_PT_256_CHROMA_CLASS1_Q0: [u16; 10] = [2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1_Q1: [u16; 10] = [1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1: [u16; 10] = [6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1_Q3: [u16; 10] = [9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695, 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 330dcad8..f078a52e 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -200,6 +200,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_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], + /// `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], + /// `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. @@ -592,6 +610,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_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); @@ -805,6 +832,69 @@ 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, + cdf::EOB_PT_256_LUMA_CLASS1_Q1, + cdf::EOB_PT_256_LUMA_CLASS1, + cdf::EOB_PT_256_LUMA_CLASS1_Q3, + ), + eob_pt_256_chroma_class1: pick( + q_ctx, + cdf::EOB_PT_256_CHROMA_CLASS1_Q0, + cdf::EOB_PT_256_CHROMA_CLASS1_Q1, + cdf::EOB_PT_256_CHROMA_CLASS1, + cdf::EOB_PT_256_CHROMA_CLASS1_Q3, + ), + eob_pt_512_luma_class1: pick( + q_ctx, + 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_512_chroma_class1: pick( + q_ctx, + 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, cdf::EOB_EXTRA_LUMA_16_Q0, @@ -1191,7 +1281,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 @@ -1215,7 +1305,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, @@ -1227,7 +1317,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, @@ -1239,7 +1329,7 @@ impl Cdfs { br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma16Inter => TxbTables { side: 16, @@ -1251,7 +1341,7 @@ impl Cdfs { br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_16.as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma16InterSet1 => TxbTables { side: 16, @@ -1263,7 +1353,7 @@ impl Cdfs { br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()), - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma8 => TxbTables { side: 8, @@ -1323,7 +1413,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, @@ -1347,7 +1437,7 @@ impl Cdfs { br: &mut self.br_chroma_8, dc_sign: &mut self.dc_sign_chroma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1), }, TxbSet::Chroma4 => TxbTables { side: 4, @@ -1359,7 +1449,7 @@ impl Cdfs { br: &mut self.br_chroma_4, dc_sign: &mut self.dc_sign_chroma, tx_type: None, - eob_pt_class1: None, + eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1), }, TxbSet::Chroma16 => TxbTables { side: 16, @@ -1371,7 +1461,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_256_chroma_class1), }, TxbSet::Chroma32 => TxbTables { side: 32, @@ -1383,7 +1473,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, @@ -1395,7 +1485,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, @@ -1407,7 +1497,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, @@ -1419,7 +1509,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 62685504..bb8b65d9 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1562,7 +1562,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 { @@ -10393,16 +10394,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 { @@ -11750,6 +11760,14 @@ fn decode_inter_block8( 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( @@ -11826,16 +11844,22 @@ fn decode_inter_block8( 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, ); - 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, - ); + // `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 { 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).