diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index cb32f4f7..06ba8c45 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -67,6 +67,11 @@ fn main() { println!( "rect_wedge(8x16,16x8,16x32,32x16,8x32,32x8): compound={rw:?} interintra={rwi:?}" ); + let sb = ec_av1::stream::sb128_rect_counters(); + println!( + "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}", + sb.0, sb.1, sb.2, sb.3 + ); let ir = ec_av1::stream::inter_rect_counters(); println!( "inter_rect: 32x8={} 8x32={} 64x32={} 32x64={} 64x16={} 16x64={}", diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index a21cbdfc..5191fe6d 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -1645,7 +1645,7 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812 /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. -pub const OBMC: [[u16; 3]; 14] = [ +pub const OBMC: [[u16; 3]; 17] = [ [10437, 32768, 0], [17432, 32768, 0], [25817, 32768, 0], @@ -1669,6 +1669,11 @@ pub const OBMC: [[u16; 3]; 14] = [ // BLOCK_8X16 (4) and BLOCK_16X8 (5) of libaom's `default_obmc_cdf`. [9371, 32768, 0], [9301, 32768, 0], + // lane-sb128c r5: the 128-root rows -- BLOCK_64X128 (13), BLOCK_128X64 + // (14), BLOCK_128X128 (15) of libaom's `default_obmc_cdf`. + [31014, 32768, 0], + [31560, 32768, 0], + [32638, 32768, 0], ]; /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize @@ -1678,7 +1683,7 @@ pub const OBMC: [[u16; 3]; 14] = [ /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` /// under `allow_warped_motion`) -- lane-warp round 1. -pub const MOTION_MODE: [[u16; 4]; 14] = [ +pub const MOTION_MODE: [[u16; 4]; 17] = [ [7651, 24760, 32768, 0], [19419, 26810, 32768, 0], [26260, 29116, 32768, 0], @@ -1698,6 +1703,13 @@ pub const MOTION_MODE: [[u16; 4]; 14] = [ // `default_motion_mode_cdf` indices 4 and 5). [4738, 24765, 32768, 0], [5391, 25528, 32768, 0], + // lane-sb128c r5: BLOCK_64X128 / 128X64 / 128X128 rows (libaom + // `default_motion_mode_cdf` indices 13, 14, 15). Without them a 128x128 + // inter block fell through `w == h => trailing_zeros - 3` to row 4 (the + // BLOCK_16X32 row) and narrowed the msac by the wrong interval. + [28898, 30397, 32768, 0], + [30878, 31335, 32768, 0], + [32507, 32558, 32768, 0], ]; /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 589b85de..40ce2898 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -551,13 +551,13 @@ pub(crate) struct Cdfs { /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- /// this decoder only ever codes those four square sizes). - pub obmc: [[u16; 3]; 14], + pub obmc: [[u16; 3]; 17], /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. /// lane-warp round 1. - pub motion_mode: [[u16; 4]; 14], + pub motion_mode: [[u16; 4]; 17], /// `interintra`, indexed by `size_group_lookup[bsize]` -- see /// `cdf::INTERINTRA`'s own doc. pub interintra: [[u16; 3]; 4], diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 21bfc736..22cd7177 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2119,6 +2119,42 @@ pub(crate) fn rect_partition_hits() -> usize { // lane-inter8 r1: how many superblocks an inter tile coded as a single // whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for // static content, previously a named refusal). +thread_local! { + /// lane-sb128c r1: how many 128x128 `PARTITION_NONE` roots this INTER tile + /// path decoded as one whole block (its gate's own witness). + pub(crate) static INTER_SB128_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// 128x64 / 64x128 INTER blocks decoded at the 128 root (lane-sb128c r7). + pub(crate) static INTER_SB128_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + pub(crate) static INTER_SB128_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTER_SB128_HORZ_HITS`], for a gate's before/after delta. +pub(crate) fn inter_sb128_horz_hits() -> usize { + INTER_SB128_HORZ_HITS.with(std::cell::Cell::get) +} + +/// Current value of [`INTER_SB128_VERT_HITS`], for a gate's before/after delta. +pub(crate) fn inter_sb128_vert_hits() -> usize { + INTER_SB128_VERT_HITS.with(std::cell::Cell::get) +} + +/// Current value of [`INTER_SB128_NONE_HITS`], for a gate's before/after delta. +pub fn inter_sb128_none_hits() -> usize { + INTER_SB128_NONE_HITS.with(std::cell::Cell::get) +} + +thread_local! { + /// lane-sb128c r3: how many INTRA-coded 128x128 blocks inside an INTER + /// frame this decoder reconstructed (mu-chunk chroma, four TX_64X64 luma + /// units) -- the gate's witness that the lifted refusal's case fired. + pub(crate) static INTRA_128_IN_INTER_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTRA_128_IN_INTER_HITS`], for a gate's before/after delta. +pub fn intra_128_in_inter_hits() -> usize { + INTRA_128_IN_INTER_HITS.with(std::cell::Cell::get) +} + thread_local! { static INTER_SB_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; @@ -4255,6 +4291,18 @@ impl Neighbours { /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's /// true (unpadded) size in 4x4 mode-info units. fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize) -> Self { + // lane-sb128c r7: a 128x64 block at the bottom frame edge records its + // neighbour state over the whole 64-row extent, past the frame's last + // mi row (mi_rows 198, block rows 192..208). libaom's own context + // buffers are superblock-aligned for exactly that reason + // (`av1_alloc_context_buffers` rounds to `MAX_MIB_SIZE`), so pad the + // side arrays to a superblock multiple and leave those cells unread -- + // every availability check uses the true `mi_rows`/`mi_cols` below. + let sb_sub = (sb_mi_cur() as usize) / (SUB / MI); + let (cols, rows) = ( + cols.next_multiple_of(sb_sub), + rows.next_multiple_of(sb_sub), + ); Self { above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)], left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)], @@ -4583,6 +4631,31 @@ impl Neighbours { /// existing corner-cut, `Neighbours::tx_grid`'s own doc comment -- a /// rectangular strip's transform is `TX_32X16`/`TX_16X32`, not tracked /// per-axis, matching lane-warp r5's `HORZ_B` top-strip precedent). + /// libaom `set_one_param_for_line_luma`/`_chroma`: an edge that is a + /// transform-unit edge but NOT a prediction-unit edge is not filtered when + /// `curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi)`. Widening this + /// block's published transform extent to its own size is exactly that + /// suppression for the deblocker's `x0 % tx != 0` test -- the only shape + /// that needs it is the 128 root, whose chroma extent (64) is the one + /// [`Self::fill_lf_grid_rect`]'s TX_32X32 cap narrows. An INTRA block is + /// never suppressed (libaom's `is_inter_block` term), so this is called + /// only from the skipped-inter branch. + fn suppress_internal_lf_edges(&mut self, at_mi: (usize, usize), w_mi: usize, h_mi: usize) { + let (mi_r, mi_c) = at_mi; + let (uv_w, uv_h) = ((w_mi * MI / 2).max(4) as u8, (h_mi * MI / 2).max(4) as u8); + for rr in 0..h_mi { + for cc in 0..w_mi { + let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); + if let Some(cell) = self.uv_tx_grid.get_mut(idx) { + *cell = uv_w; + } + if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) { + *cell = uv_h; + } + } + } + } + fn fill_lf_grid_rect( &mut self, at_mi: (usize, usize), @@ -5349,7 +5422,14 @@ impl Neighbours { round_up_even(self.mi_cols), ]; for cell in 0..h_mi { - self.left[mi_r + cell] = std::array::from_fn(|plane| { + // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows + // past the padded side arrays (mi_rows 198, block rows 192..208); + // libaom's own arrays are superblock-sized, so those cells simply + // have no reader. Same guard the `left_side_mi` loop above uses. + let Some(left_slot) = self.left.get_mut(mi_r + cell) else { + break; + }; + *left_slot = std::array::from_fn(|plane| { if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) { states[plane] } else { @@ -5358,7 +5438,10 @@ impl Neighbours { }); } for cell in 0..w_mi { - self.above[mi_c + cell] = std::array::from_fn(|plane| { + let Some(above_slot) = self.above.get_mut(mi_c + cell) else { + break; + }; + *above_slot = std::array::from_fn(|plane| { if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) { states[plane] } else { @@ -6074,6 +6157,14 @@ fn read_intra_mode_rect( 0 }; istep!("angle_y", angle_delta_y); + // lane-sb128c r3 (class sweep): libaom `read_intra_mode_uv(.., is_cfl_allowed(xd), ..)` + // and `is_cfl_allowed` (blockd.h) is `block_size_wide[bsize] <= 32 && + // block_size_high[bsize] <= 32` on the LUMA bsize. Deciding the alphabet + // here, from the block's own size, is the single point every caller routes + // through -- a caller passing `true` for a >32 strip used to pick the + // 14-symbol CFL CDF, same value but a different range (class + // wrong-alphabet-same-value). + let cfl = cfl && bw <= 32 && bh <= 32; let uv_mode = if !has_chroma { DC_PRED } else if cfl { @@ -9299,6 +9390,10 @@ fn read_intra_mode( 0 }; istep!("angle_y", angle_delta_y); + // lane-sb128c r3 (class sweep): `is_cfl_allowed` on the luma bsize, decided + // here so every `decode_block` caller (64x64 and 128x128 roots included) + // picks the right alphabet -- see [`read_intra_mode_rect`]'s twin. + let cfl = cfl && side <= 32; let uv_mode = if cfl { dec.symbol(&mut cdfs.uv_mode_cfl[mode]) } else { @@ -12388,6 +12483,21 @@ fn read_block_tx_size( skip: bool, ) -> Result<(usize, Option>)> { if !TX_SELECT_INTER.with(std::cell::Cell::get) { + // lane-sb128c r1: `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64, + // so a 128x128 inter block is FOUR luma units even with `tx_mode == + // TX_MODE_LARGEST` -- the same leaf shape the var-tx tree hands back. + // lane-sb128c r3: intra too -- an INTRA 128x128 block under + // `TX_MODE_LARGEST` also resolves to TX_64X64, i.e. four luma units. + if side > 64 { + let step = 64 / MI; + let mut leaves = Vec::new(); + for row in (0..side / MI).step_by(step) { + for col in (0..side / MI).step_by(step) { + leaves.push((row, col, 64, 64)); + } + } + return Ok((64, Some(leaves))); + } return Ok((side, None)); } let side_mi = side / MI; @@ -12415,7 +12525,12 @@ fn read_block_tx_size( } } let single = leaves.len() == 1 && leaves[0].2 == side && leaves[0].3 == side; - if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > 32) { + // lane-sb128c r6: below the 128 root the ceiling is main's TX_32X32 + // ([`inter_txbset_for`] has no 64-point *inter* table set); a 128x128 + // block's own var-tx tree legitimately bottoms out at TX_64X64 leaves, + // which the mu-chunk reader above codes as their 32x32 coded corner. + let leaf_ceiling = if side > 64 { 64 } else { 32 }; + if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > leaf_ceiling) { // Only a block wider than a superblock's own 64x64 max transform // reaches here; this crate has no 64-point *inter* coefficient // table set ([`inter_txbset_for`] stops at 32). @@ -12435,7 +12550,10 @@ fn read_block_tx_size( n, at_mi, side, - Some(tx_size_context_txfm(n, at_mi, side)), + // lane-sb128c r3: `get_tx_size_context` compares the neighbour txfm + // contexts against `tx_size_wide[max_txsize_rect_lookup[bsize]]`, + // which is 64 for BLOCK_128X128 -- never the block's own 128 side. + Some(tx_size_context_txfm(n, at_mi, side.min(64))), ) }; set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter); @@ -12497,6 +12615,12 @@ fn rect_inter_residual_supported(w: usize, h: usize) -> bool { // Only reachable as a var-tx LEAF -- an 8x4/4x8 inter BLOCK is // refused earlier ("an inter partition below 8x8"). | (8, 4) | (4, 8) + // lane-sb128c r7: the 128 root's HORZ/VERT halves. These are NOT + // one rectangular transform -- `max_txsize_rect_lookup + // [BLOCK_128X64]` is TX_64X64, so the block tiles into two square + // TX_64X64 units read through the mu-chunk loop, same as the + // 128x128 NONE block's four. + | (128, 64) | (64, 128) ) } @@ -12655,6 +12779,55 @@ fn read_block_tx_size_rect( } // `max_txsize_rect_lookup` is the block's own size, capped at 64 -- and // `rect_inter_residual_supported` has already excluded everything above 32. + // lane-sb128c r7: except at the 128 root. `max_txsize_rect_lookup + // [BLOCK_128X64] == TX_64X64` (libaom `common_data.h`), so a 128x64 block + // is TWO square top-level transform units side by side and a 64x128 one is + // two stacked -- exactly what libaom `read_block_tx_size` + // (decodeframe.c:1140) codes with its `idy/idx` loop over + // `tx_size_high_unit/tx_size_wide_unit[max_tx_size]`. Each unit reads its + // own `txfm_partition` symbol at depth 0. + if bw.max(bh) > 64 { + let tx = 64usize; + let (max_w_mi, max_h_mi) = ( + (bw / MI).min(mi_cols.saturating_sub(at_mi.1)), + (bh / MI).min(mi_rows.saturating_sub(at_mi.0)), + ); + let mut leaves = Vec::new(); + if !TX_SELECT_INTER.with(std::cell::Cell::get) { + for row in (0..bh / MI).step_by(tx / MI) { + for col in (0..bw / MI).step_by(tx / MI) { + leaves.push((row, col, tx, tx)); + } + } + for &(row, col, tw, th) in &leaves { + txfm_partition_update_rect(n, (at_mi.0 + row, at_mi.1 + col), (tw, th), (tw, th)); + } + return Ok(Some(leaves)); + } + for row in (0..bh / MI).step_by(tx / MI) { + for col in (0..bw / MI).step_by(tx / MI) { + read_var_tx_size( + dec, + cdfs, + n, + at_mi, + bw.max(bh), + (max_w_mi, max_h_mi), + (tx, tx), + 0, + row, + col, + &mut leaves, + ); + } + } + if leaves.iter().any(|l| l.2.max(l.3) > 64) { + return Err(unsupported( + "an inter var-tx tree with a leaf transform larger than 64x64", + )); + } + return Ok(Some(leaves)); + } let (tx_w, tx_h) = (bw, bh); if !TX_SELECT_INTER.with(std::cell::Cell::get) { // `TX_MODE_LARGEST`: no symbol at all, the whole block is one @@ -12965,6 +13138,12 @@ fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize) -> TxType { fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { match tx_px { + // lane-sb128c r1: a 128x128 inter block's own luma unit + // (`max_txsize_rect_lookup[BLOCK_128X128] == TX_64X64`). + // `av1_get_ext_tx_set_type` is `DCT_ONLY` at `tx_size_sqr_up == + // TX_64X64`, so no `tx_type` symbol is coded and the intra/inter sets + // coincide -- exactly the set the whole-64x64 inter block already uses. + 64 => TxbSet::Luma64, 32 => TxbSet::Luma32Inter, 16 if reduced_tx_set => TxbSet::Luma16Inter, 16 => TxbSet::Luma16InterSet1, @@ -13927,6 +14106,15 @@ thread_local! { /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one /// whole 128x128 block (lane-sb128b r1's gate counter). pub(crate) static PART128_NONE_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// 128 roots that resolved to PARTITION_HORZ (two 128x64 pieces, or one + /// when the bottom half is out of frame) -- lane-sb128c r7. + pub(crate) static PART128_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// 128 roots that resolved to PARTITION_VERT (two 64x128 pieces). + pub(crate) static PART128_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// Of those, the ones decided by the GATHERED bit at a frame edge -- the + /// only shape a 1080p (mi_rows = 270) stream reaches. + pub(crate) static PART128_EDGE_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + pub(crate) static PART128_EDGE_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// [`PART128_NONE_HITS`], for a gate's own before/after delta. @@ -13934,6 +14122,26 @@ pub(crate) fn part128_none_hits() -> usize { PART128_NONE_HITS.with(std::cell::Cell::get) } +/// [`PART128_HORZ_HITS`], for a gate's own before/after delta. +pub(crate) fn part128_horz_hits() -> usize { + PART128_HORZ_HITS.with(std::cell::Cell::get) +} + +/// [`PART128_VERT_HITS`], for a gate's own before/after delta. +pub(crate) fn part128_vert_hits() -> usize { + PART128_VERT_HITS.with(std::cell::Cell::get) +} + +/// [`PART128_EDGE_HORZ_HITS`] -- gathered-bit HORZ at the bottom frame edge. +pub(crate) fn part128_edge_horz_hits() -> usize { + PART128_EDGE_HORZ_HITS.with(std::cell::Cell::get) +} + +/// [`PART128_EDGE_VERT_HITS`] -- gathered-bit VERT at the right frame edge. +pub(crate) fn part128_edge_vert_hits() -> usize { + PART128_EDGE_VERT_HITS.with(std::cell::Cell::get) +} + thread_local! { /// How many CHROMA transform units were coded inside a block whose uv /// plane block is more than one unit (lane-sb128b r2 -- only a 128x128 @@ -13995,6 +14203,7 @@ fn read_sb128_root( if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128)) == 1 { PARTITION_SPLIT } else { + PART128_EDGE_HORZ_HITS.with(|c| c.set(c.get() + 1)); PARTITION_HORZ } } @@ -14002,6 +14211,7 @@ fn read_sb128_root( if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128)) == 1 { PARTITION_SPLIT } else { + PART128_EDGE_VERT_HITS.with(|c| c.set(c.get() + 1)); PARTITION_VERT } } @@ -14015,15 +14225,23 @@ fn read_sb128_root( // lane-sb128b r1: `PARTITION_NONE` -- one 128x128 block -- is decoded by // the key-frame caller below. The six remaining arms (HORZ/VERT and the // four AB shapes) still need the rect/AB machinery at this size. - if part128 != PARTITION_SPLIT && part128 != PARTITION_NONE { - return Err(unsupported( - "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", - )); - } - if part128 == PARTITION_SPLIT { - PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)); - } else { - PART128_NONE_HITS.with(|c| c.set(c.get() + 1)); + // lane-sb128c r7: HORZ (two 128x64) and VERT (two 64x128) now decode on + // both tile paths. The four AB shapes (libaom `decode_partition`'s + // PARTITION_HORZ_A..VERT_B, decodeframe.c) still need the mixed + // 128x64 + 64x64 + 64x64 visit order and stay refused by name; a 128 + // root has no 1:4 arm at all (`PARTITION_HORZ_4`/`VERT_4` are excluded + // for BLOCK_128X128 by `av1_get_partition_cdf`'s 8-symbol alphabet, + // which stops at VERT_B). + match part128 { + PARTITION_SPLIT => PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1)), + PARTITION_NONE => PART128_NONE_HITS.with(|c| c.set(c.get() + 1)), + PARTITION_HORZ => PART128_HORZ_HITS.with(|c| c.set(c.get() + 1)), + PARTITION_VERT => PART128_VERT_HITS.with(|c| c.set(c.get() + 1)), + _ => { + return Err(unsupported( + "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)", + )); + } } Ok(part128) } @@ -14236,6 +14454,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( mi_cols, mi_rows, )?; + if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { + // lane-sb128c r7: the INTER path decodes these (two 128x64 + // / two 64x128 blocks, the film's own bottom-edge shape); + // the key path's `decode_block` is square-only, so an + // intra 128x64 would silently decode as four 64x64 + // quadrants. Refuse by name instead of corrupting. + return Err(unsupported( + "a 128x128 superblock HORZ/VERT partition on an intra frame (the inter path decodes it; the intra one is square-block only)", + )); + } if part128 == PARTITION_NONE { // One 128x128 intra block: four TX_64X64 luma units and a // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize` @@ -16189,6 +16417,12 @@ impl PlaneBuf { prediction: &[u16], residual: &[i32], ) { + // lane-sb128c r7: a 128x64 half of a 128 root at the BOTTOM frame edge + // is the first block shape whose true footprint overhangs the padded + // coding surface (mi_rows = 198 -> a plane 800 rows tall, block rows + // 768..832). libaom reconstructs those rows into the frame buffer's + // border; nothing reads them back, so they are simply dropped here. + let (h, w) = (h.min(self.height.saturating_sub(y)), w.min(self.width.saturating_sub(x))); for row in 0..h { for col in 0..w { let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col]) @@ -16239,7 +16473,13 @@ fn read_inter_plane( let skip_ctx = if plane_idx == 0 { luma_skip_ctx.unwrap_or(0) } else { - usize::from(around.0) + usize::from(around.1) + // lane-sb128c r1: on a CHROMA plane this same parameter carries + // `get_txb_ctx`'s own offset instead -- `combine_entropy_contexts(..)` + // is +7 normally and +10 when the plane block is LARGER than the + // transform (a 128x128 block's 64x64 uv plane block with TX_32X32 + // units, AV1's only such case), and the `txb_skip_chroma_32` table + // carries the offset-10 rows at +3 (lane-sb128b r3). + usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0) }; let mut coding = cdfs.txb(set, tx_mode); let default_tx_type = match inherited_luma_tx_type { @@ -16983,8 +17223,13 @@ fn obmc_blend( if matches!((write_w, write_h), (16, 8) | (8, 16)) { OBMC_RECT_LEAF_HITS.with(|c| c.set(c.get() + 1)); } - let overlap_above = write_h / 2; - let overlap_left = write_w / 2; + // lane-sb128c r1: libaom caps the overlap strip at a 64x64 block's own + // half (`reconinter.c` 860/899: `AOMMIN(block_size_high[bsize], + // block_size_high[BLOCK_64X64]) >> 1`, and the `block_size_wide` mirror) -- + // inert below 128, where a 128x128 block would otherwise blend a 64-row + // strip `obmc_mask` has no table for. + let overlap_above = write_h.min(64) / 2; + let overlap_left = write_w.min(64) / 2; // lane-inter8 r1 / lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` // (`reconinter.c` 820, `DISABLE_CHROMA_U8X8_OBMC == 0` -- "one-sided // obmc") returns `dir == 0` when the chroma plane's own block is @@ -17626,7 +17871,10 @@ fn decode_inter_block( maybe_read_cdef_idx(dec, rmi, cmi, skip); // lane-inter4 r1: spec 5.11.6's `bSize == sbSize` -- a 64x32/64x16 strip // is NOT the whole superblock, so its `skip` never suppresses the read. - let whole_sb = side == 64 && write_w == 64 && write_h == 64; + // lane-sb128c r7: `sbSize` is 128 under `--sb-size=128`, so the whole-block + // test is against the sequence's own superblock side, not a hardcoded 64. + let sb_px = sb_mi_cur() as usize * 4; + let whole_sb = side == sb_px && write_w == sb_px && write_h == sb_px; maybe_read_delta_q(dec, cdfs, rmi, cmi, whole_sb, skip); maybe_read_delta_lf(dec, cdfs, rmi, cmi, whole_sb, skip); let (has_above, has_left) = ( @@ -17636,13 +17884,19 @@ fn decode_inter_block( let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]); let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter); let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; + // lane-sb128c r1: this round wires the INTER half of a 128x128 block (four + // TX_64X64 luma units and four TX_32X32 chroma units interleaved per mu + // chunk). An INTRA block at that size inside an inter frame takes the + // intra tail below, which still codes one whole-block chroma unit and one + // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it. if std::env::var_os("EC_TRACE_MODE").is_some() { eprintln!( - "EC_MODE mi_row={} mi_col={} is_inter={} skip={skip} rng={}", + "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}", rmi, cmi, - is_inter as u8, - dec.debug_state().0 + dec.debug_state().0, + u8::from(is_inter), + u8::from(skip) ); } // lane-warp r5: see `reject_residual` -- a square-block decode of a @@ -18582,6 +18836,11 @@ fn decode_inter_block( neighbours.around_mi(at, side) }; let luma_tx_type; + // lane-sb128c r1: a 128x128 inter block's four chroma units + // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); + // these collect them for the block-level neighbour write-back. + let mut u_units = vec![0i32; chroma_side * chroma_side]; + let mut v_units = vec![0i32; chroma_side * chroma_side]; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -18600,7 +18859,7 @@ fn decode_inter_block( let start = (row * MI + rr) * side + col * MI; tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); } - let scan = default_scan(tx_px); + let scan = default_scan(tx_px.min(32)); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); read_inter_plane( dec, @@ -18652,6 +18911,79 @@ fn decode_inter_block( first_tx_type = tu_tx_type; } neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); + // lane-sb128c r1: libaom's `decode_token_recon_block` + // walks 64x64 "mu" chunks (`mu_blocks_wide/high = + // mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of + // a chunk before the next one, so a 128x128 block + // interleaves Y,U,V per quadrant -- the same order the + // intra 128 path reads (lane-sb128b r3, measured + // against aomdec's `EC_TRACE_COEFF`). Below 128 a block + // is a single chunk and this never fires. + if side > 64 { + let chunk = (row / 16, col / 16); + let done = idx + 1 == leaves.len() + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; + if done { + let (cr, cc) = chunk; + // `av1_get_max_uv_txsize(BLOCK_128X128)` = + // `av1_get_adjusted_tx_size(TX_64X64)` = + // TX_32X32: one 32x32 chroma unit per chunk. + let cu_tx = 32usize; + let luma_span = cu_tx * 2; + let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); + let cu_around = neighbours.around_mi(cu_mi, luma_span); + let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); + let cu_scan = default_scan(cu_tx); + for plane_idx in 1..3 { + let (src, buf) = if plane_idx == 1 { + (&pred_u, &mut *u) + } else { + (&pred_v, &mut *v) + }; + let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx); + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + cu_pred.extend_from_slice(&src[start..start + cu_tx]); + } + let cu_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + &cu_scan, + plane_idx, + cu_around[plane_idx], + mode_for_tx, + buf, + cu_x, + cu_y, + cu_tx, + base_q_idx, + &cu_pred, + Some(first_tx_type), + Some(3), + )? + .0; + // Immediately, so the NEXT chunk's unit + // reads this one's coefficient context. + neighbours.record_mi_chroma( + cu_mi, luma_span, luma_span, plane_idx, &cu_grid, + ); + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let dst = if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }; + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + } + } + } + } } // `av1_get_tx_type`'s chroma lookup scales the chroma // position back to luma, so an inter block's chroma @@ -18698,7 +19030,13 @@ fn decode_inter_block( None, )?; } - if rect_tu { + if side > 64 { + // Already read inside the mu-chunk loop above -- at the 128 + // root a rect (128x64/64x128) block's chroma is per mu + // chunk too, so this test comes BEFORE the `rect_tu` one. + u_grid = std::mem::take(&mut u_units); + v_grid = std::mem::take(&mut v_units); + } else if rect_tu { // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a // 2:1 strip is the strip's own rect chroma size (16x8 / // 8x16), one unit for the whole block, and it codes no @@ -19117,6 +19455,11 @@ fn decode_inter_block( // interval narrowing, not a wrong value (class // wrong-alphabet-same-value). let bsize_idx = match (write_w, write_h) { + // lane-sb128c r5: the 128 root's own rows come FIRST -- + // the square arm below maps 128 to row 4 (BLOCK_16X32). + (64, 128) => 14, + (128, 64) => 15, + (128, 128) => 16, (w, h) if w == h => (w.trailing_zeros() - 3) as usize, (16, 32) => 4, (32, 16) => 5, @@ -19684,6 +20027,11 @@ fn decode_inter_block( _ => around, }; let luma_tx_type; + // lane-sb128c r1: a 128x128 inter block's four chroma units + // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); + // these collect them for the block-level neighbour write-back. + let mut u_units = vec![0i32; chroma_side * chroma_side]; + let mut v_units = vec![0i32; chroma_side * chroma_side]; if let Some(leaves) = vartx_leaves.clone() { // spec 5.11.17's transform tree, leaf by leaf in the order // `read_var_tx_size` coded it: each unit reads its own @@ -19702,7 +20050,7 @@ fn decode_inter_block( let start = (row * MI + rr) * side + col * MI; tu_pred.extend_from_slice(&pred_y[start..start + tx_px]); } - let scan = default_scan(tx_px); + let scan = default_scan(tx_px.min(32)); let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); read_inter_plane( dec, @@ -19754,6 +20102,79 @@ fn decode_inter_block( first_tx_type = tu_tx_type; } neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); + // lane-sb128c r1: libaom's `decode_token_recon_block` + // walks 64x64 "mu" chunks (`mu_blocks_wide/high = + // mi_size_wide[BLOCK_64X64]`) and codes EVERY PLANE of + // a chunk before the next one, so a 128x128 block + // interleaves Y,U,V per quadrant -- the same order the + // intra 128 path reads (lane-sb128b r3, measured + // against aomdec's `EC_TRACE_COEFF`). Below 128 a block + // is a single chunk and this never fires. + if side > 64 { + let chunk = (row / 16, col / 16); + let done = idx + 1 == leaves.len() + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; + if done { + let (cr, cc) = chunk; + // `av1_get_max_uv_txsize(BLOCK_128X128)` = + // `av1_get_adjusted_tx_size(TX_64X64)` = + // TX_32X32: one 32x32 chroma unit per chunk. + let cu_tx = 32usize; + let luma_span = cu_tx * 2; + let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); + let cu_around = neighbours.around_mi(cu_mi, luma_span); + let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); + let cu_scan = default_scan(cu_tx); + for plane_idx in 1..3 { + let (src, buf) = if plane_idx == 1 { + (&pred_u, &mut *u) + } else { + (&pred_v, &mut *v) + }; + let mut cu_pred = Vec::with_capacity(cu_tx * cu_tx); + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + cu_pred.extend_from_slice(&src[start..start + cu_tx]); + } + let cu_grid = read_inter_plane( + dec, + cdfs, + chroma_set, + &cu_scan, + plane_idx, + cu_around[plane_idx], + mode_for_tx, + buf, + cu_x, + cu_y, + cu_tx, + base_q_idx, + &cu_pred, + Some(first_tx_type), + Some(3), + )? + .0; + // Immediately, so the NEXT chunk's unit + // reads this one's coefficient context. + neighbours.record_mi_chroma( + cu_mi, luma_span, luma_span, plane_idx, &cu_grid, + ); + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let dst = if plane_idx == 1 { + &mut u_units + } else { + &mut v_units + }; + for rr in 0..cu_tx { + let start = + (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + } + } + } + } } // `av1_get_tx_type`'s chroma lookup scales the chroma // position back to luma, so an inter block's chroma @@ -19809,6 +20230,12 @@ fn decode_inter_block( // neither symbol nor context exists. u_grid = vec![0i32; chroma_side * chroma_side]; v_grid = vec![0i32; chroma_side * chroma_side]; + } else if side > 64 { + // Already read inside the mu-chunk loop above -- at the 128 + // root a rect (128x64/64x128) block's chroma is per mu + // chunk too, so this test comes BEFORE the `rect_tu` one. + u_grid = std::mem::take(&mut u_units); + v_grid = std::mem::take(&mut v_units); } else if rect_tu { // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a // 2:1 strip is the strip's own rect chroma size (16x8 / @@ -20150,9 +20577,16 @@ fn decode_inter_block( .1; let reach = Reach::of(side, px, py, y.width, y.height); let split_luma = vartx_leaves.is_some(); + // lane-sb128c r3: a 128x128 INTRA block inside an inter frame codes + // its chroma per 64x64 mu chunk, exactly as the inter half above -- + // `decode_token_recon_block` walks `mu_blocks_wide/high` and codes + // every plane of a chunk before the next chunk's luma. These collect + // the four TX_32X32 units per plane for the block-level write-back. + let mut u_units = vec![0i32; chroma_side * chroma_side]; + let mut v_units = vec![0i32; chroma_side * chroma_side]; if let Some(leaves) = vartx_leaves.clone() { let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); - for &(row, col, tx_px, _) in &leaves { + for (idx, &(row, col, tx_px, _)) in leaves.iter().enumerate() { let tu_mi = (at_mi.0 + row, at_mi.1 + col); let (tu_px, tu_py) = (px + col * MI, py + row * MI); // A transform unit inside a block is not a block at that @@ -20183,7 +20617,11 @@ fn decode_inter_block( dec, cdfs, txbset_for(tx_px, reduced), - &default_scan(tx_px), + // lane-sb128c r5: a TX_64X64 unit codes only its + // top-left 32x32 of frequencies (spec 5.11.40), so + // the scan and `tx_side` are the CODED corner while + // `side` stays the transform's true 64. + &default_scan(tx_px.min(32)), 0, neighbours.around_mi(tu_mi, tx_px)[0], mode, @@ -20194,7 +20632,7 @@ fn decode_inter_block( tu_px, tu_py, tx_px, - tx_px, + tx_px.min(32), base_q_idx, None, filter_intra, @@ -20203,9 +20641,96 @@ fn decode_inter_block( )? }; neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); + if side > 64 { + let chunk = (row / 16, col / 16); + let done = idx + 1 == leaves.len() + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; + if !done { + continue; + } + let (cr, cc) = chunk; + // `av1_get_max_uv_txsize(BLOCK_128X128)` = + // `av1_get_adjusted_tx_size(TX_64X64)` = TX_32X32. + let cu_tx = 32usize; + let luma_span = cu_tx * 2; + let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); + let cu_around = neighbours.around_mi(cu_mi, luma_span); + let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); + let cu_reach = crate::decode::tu_reach( + side, side, + cc * luma_span, cr * luma_span, luma_span, + reach, px, py, y.width, y.height, + ); + let cu_scan = default_scan(cu_tx); + for plane_idx in 1..3 { + let buf: &mut PlaneBuf = if plane_idx == 1 { &mut *u } else { &mut *v }; + let cu_grid = if skip { + buf.reconstruct( + cu_x, + cu_y, + cu_tx, + uv_predict_mode, + angle_delta_uv, + cu_reach, + &vec![0i32; cu_tx * cu_tx], + None, + None, + smooth_neighbor_uv, + ); + vec![0i32; cu_tx * cu_tx] + } else { + read_plane( + dec, + cdfs, + chroma_set, + &cu_scan, + plane_idx, + cu_around[plane_idx], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + buf, + cu_x, + cu_y, + cu_tx, + cu_tx, + base_q_idx, + // CfL is refused above 32x32 + // (`is_cfl_allowed`), so never here. + None, + None, + // The uv plane block (64x64) is larger than + // the unit (32x32): `get_txb_ctx`'s offset-10 + // rows, +3 on the `txb_skip_chroma_32` table + // (lane-sb128b r3). + Some(3), + smooth_neighbor_uv, + )? + }; + // Immediately, so the NEXT chunk's unit reads this + // one's coefficient context. + neighbours.record_mi_chroma( + cu_mi, luma_span, luma_span, plane_idx, &cu_grid, + ); + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let dst = if plane_idx == 1 { &mut u_units } else { &mut v_units }; + for rr in 0..cu_tx { + let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; + dst[start..start + cu_tx] + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); + } + } + } } } - if skip { + if side > 64 { + // Chroma is already coded and reconstructed per mu chunk above. + luma_grid = vec![0i32; side * side]; + u_grid = std::mem::take(&mut u_units); + v_grid = std::mem::take(&mut v_units); + INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); + } else if skip { if !split_luma { y.reconstruct( px, @@ -20428,12 +20953,24 @@ fn decode_inter_block( // units, not the block -- for LUMA only (lane-golomb r6): the chroma // grids keep the block's own `av1_get_max_uv_txsize`, which is what // libaom's `get_transform_size` reads for `plane != AOM_PLANE_Y`. - if let Some(leaves) = &vartx_leaves { + // lane-sb128c r4: libaom `set_one_param_for_line_luma` suppresses every + // edge that is a TU edge but not a PU edge when + // `curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi)`, so a SKIP + // inter block's internal transform edges are never filtered even though + // `get_transform_size` still reports TX_64X64 for it. The only block that + // reaches here skipped is the 128 root (`read_block_tx_size` hands back + // four TX_64X64 leaves for `side > 64` regardless of `skip`); leaving its + // block-level 128 publication in place is exactly that suppression. + // lane-sb128c r6: narrowed to the 128 root. Below it `read_block_tx_size` + // hands a skipped inter block a single leaf equal to the block, so the + // per-leaf write is the block-level one and this branch is a no-op either + // way; only the 128 root gets four TX_64X64 leaves regardless of `skip`. + let skip_inter_128 = skip && is_inter && write_w.max(write_h) > 64; + if skip_inter_128 { + neighbours.suppress_internal_lf_edges((rmi, cmi), write_w / MI, write_h / MI); + } + if let Some(leaves) = (!skip_inter_128).then_some(()).and(vartx_leaves.as_ref()) { for &(row, col, tw, th) in leaves { - // lane-r14's RECT leaf dims through lane-golomb r6's luma-only - // writer: fill_lf_grid_rect would recompute CHROMA tx dims from - // the leaf span, but libaom's `get_transform_size` splits only for - // AOM_PLANE_Y (merge J, ledger constraint). neighbours.fill_lf_grid_leaf_luma( (at_mi.0 + row, at_mi.1 + col), tw / MI, @@ -23476,13 +24013,25 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // loop does; the 64-level body below is unchanged, `read_cdef`'s // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant. + // lane-sb128c r1: set when the 128 root resolved to `PARTITION_NONE` -- its + // one 128x128 inter block covers all four 64x64 quadrants, so the remaining + // three items of this superblock carry no syntax at all (same skip the + // key-frame tile loop runs). + let mut sb128_none = false; for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) { if row_start { neighbours.start_row(); } + if sb_start { + sb128_none = false; + } + if sb128_none { + continue; + } { + let mut sb128_rect = None; if sb128 && sb_start { - if read_sb128_root( + let part128 = read_sb128_root( &mut dec, &mut cdfs, &neighbours, @@ -23493,14 +24042,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( sb_c, mi_cols, mi_rows, - )? != PARTITION_SPLIT - { - // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on - // KEY frames only; an inter 128x128 leaf needs whole-block - // MC, OBMC and compound at a size this path has never run. - return Err(unsupported( - "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", - )); + )?; + if matches!(part128, PARTITION_HORZ | PARTITION_VERT) { + // Two 128x64 (HORZ) or two 64x128 (VERT) inter blocks; the + // whole 128x128 root is consumed here, so the remaining + // three 64-quadrant visits of this superblock carry no + // syntax (same skip the NONE arm runs). + sb128_none = true; + sb128_rect = Some(part128); + CDEF_TRANSMITTED.with(|c| c.set(false)); + } + if part128 == PARTITION_NONE { + // One 128x128 inter block. Its luma transform is + // `max_txsize_rect_lookup[BLOCK_128X128]` = TX_64X64 (four + // units, read as var-tx leaves), its uv plane block is + // 64x64 with TX_32X32 units (`av1_get_max_uv_txsize`), and + // `size_group_lookup[BLOCK_128X128]` is 3, same as 64x64. + sb128_none = true; + CDEF_TRANSMITTED.with(|c| c.set(false)); } } if !sb128 { @@ -23567,7 +24126,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip_mode_frame, switchable_motion_mode, allow_warped_motion, - true, + // lane-sb128c r3: `reject_residual` is about a + // RECTANGULAR strip decoded with square dimensions -- + // the 128x128 NONE root is square, and a hardcoded + // `true` refused every one of them at its first + // non-skip block. + $ww != $side || $wh != $side, $ww, $wh, allow_screen_content_tools, @@ -23652,6 +24216,96 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } }}; } + if let Some(part128) = sb128_rect { + // lane-sb128c r7: libaom `decode_partition` (decodeframe.c:1554) + // codes PARTITION_HORZ at the 128 root as `subsize = + // BLOCK_128X64` at (mi_row, mi_col) and a second one at + // (mi_row + hbs, mi_col) only `if (mi_row + hbs < mi_rows)`; + // PARTITION_VERT mirrors it on the column. `hbs` here is + // `mi_size_high[BLOCK_128X128] / 2` = 16 mi. + let horz = part128 == PARTITION_HORZ; + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + let base_mi = sub16_to_mi(at128); + let (bw, bh) = if horz { (128usize, 64usize) } else { (64, 128) }; + for i in 0..2 { + let at_mi = if horz { + (base_mi.0 + i * 16, base_mi.1) + } else { + (base_mi.0, base_mi.1 + i * 16) + }; + if i > 0 && (at_mi.0 >= mi_rows as usize || at_mi.1 >= mi_cols as usize) { + break; + } + inter_piece!( + at_mi, SB * 2, + TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, + &scan32, &scan32, 3, bw, bh + ); + if horz { + INTER_SB128_HORZ_HITS.with(|c| c.set(c.get() + 1)); + } else { + INTER_SB128_VERT_HITS.with(|c| c.set(c.get() + 1)); + } + } + // One `cdef_idx` per BLOCK, copied to every 64x64 CDEF unit it + // covers -- both halves of the root read their own, and the + // first one's read lands in the top-left unit while the + // second's lands in the bottom-left (HORZ) / top-right (VERT). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols == 0 { + return; + } + for (src, dst) in if horz { + [((0, 0), (0, 1)), ((1, 0), (1, 1))] + } else { + [((0, 0), (1, 0)), ((0, 1), (1, 1))] + } { + let (si, di) = ( + (q_r + src.0) * cols + q_c + src.1, + (q_r + dst.0) * cols + q_c + dst.1, + ); + if q_c + src.1 < cols && q_c + dst.1 < cols && si < g.len() && di < g.len() + { + g[di] = g[si]; + } + } + }); + continue; + } + if sb128_none { + INTER_SB128_NONE_HITS.with(|c| c.set(c.get() + 1)); + let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); + // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`; + // `decode_inter_block` takes MI. Unconverted it was (0,0) for + // the first 128 root and a quarter-position for every other + // one -- the whole-frame gate never got past superblock 1. + inter_piece!( + sub16_to_mi(at128), SB * 2, + TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, + &scan32, &scan32, 3, SB * 2, SB * 2 + ); + // libaom writes one `cdef_strength` into the block's own + // `MB_MODE_INFO`, which all four 64x64 CDEF units point at + // (mirrors the key-frame 128 NONE block). + let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize); + CDEF_IDX_GRID.with(|g| { + let mut g = g.borrow_mut(); + let cols = CDEF_SB_COLS.with(|c| c.get()); + if cols > 0 && q_r * cols + q_c < g.len() { + let idx = g[q_r * cols + q_c]; + for (dr, dc) in [(0, 1), (1, 0), (1, 1)] { + let i = (q_r + dr) * cols + q_c + dc; + if q_c + dc < cols && i < g.len() { + g[i] = idx; + } + } + } + }); + continue; + } let sb_ctx = neighbours.partition_ctx(sb_at, SB); let (has_cols, has_rows) = ( sb_c * SB_MI + SB_MI / 2 < mi_cols, diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index cb4e42e9..4755c69c 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -631,6 +631,26 @@ fn scan_col( found } +/// The half of libaom's `has_top_right` (mvref_common.c:264) that +/// `setup_ref_mv_list` (mvref_common.c:497/546) gates the top-right mv probe on +/// and that this crate can state exactly: `if (bs > mi_size_wide[BLOCK_64X64]) +/// return 0`. A 128x128 / 128x64 / 64x128 block has NO top-right candidate even +/// though the cell diagonally above-right of it sits in decoded memory -- an +/// ungated grid probe invented `(441,441) w=644` at `mi(32,0)` and desynced the +/// drl symbols of the 128 inter gate (lane-sb128c r5). +/// +/// corner-cut: the position-mask half of `has_top_right` is deliberately NOT +/// applied here. It needs libaom's three shape refinements +/// (`is_last_vertical_rect`, `is_first_horizontal_rect`, the `PARTITION_VERT_A` +/// bottom-left square) which [`has_top_right`] does not port; applying the mask +/// without them cost the 64-level AB, free-partition and 1:4 gates frame 16 +/// (measured lane-sb128c r6). Ceiling: a sub-128 block may still probe a +/// top-right libaom would not, exactly as main does today; upgrade path = port +/// the three refinements into [`has_top_right`] and gate on it whole. +fn top_right_scan_allowed(bw4: usize, bh4: usize) -> bool { + bw4.max(bh4) <= 16 +} + /// libaom `has_top_right` (mvref_common.c:264): whether the unit diagonally /// above-right of this block has been decoded *by the superblock's own /// recursion order*. The mask is `sb_size`-relative, so at a 128x128 @@ -875,7 +895,12 @@ pub fn find_mv_stack_with_sign_bias( &mut newmv_count, &mut processed_cols, ); - let found_top_right = scan_top_right( + // libaom `setup_ref_mv_list` gates this probe on `has_top_right` + // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 + // block sits in decoded memory but is NOT available (bs > 16), so an + // ungated grid probe invents a candidate and desyncs the drl symbols. + let found_top_right = top_right_scan_allowed(bw4, bh4) + && scan_top_right( grid, mi_row, mi_col, @@ -1668,7 +1693,12 @@ pub fn find_mv_stack_compound( &mut newmv_count, &mut processed_cols, ); - let found_top_right = scan_top_right_compound( + // libaom `setup_ref_mv_list` gates this probe on `has_top_right` + // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 + // block sits in decoded memory but is NOT available (bs > 16), so an + // ungated grid probe invents a candidate and desyncs the drl symbols. + let found_top_right = top_right_scan_allowed(bw4, bh4) + && scan_top_right_compound( grid, mi_row, mi_col, diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 7f6bb35f..756a58fb 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -45,8 +45,9 @@ const REFUSALS: &[&str] = &[ "a tx_type symbol outside its CDF's own set: {t}", "an INTER 32x32 partition type this decoder does not code (value={part32})", "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", - "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", - "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)", + "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)", + "an inter var-tx tree with a leaf transform larger than 64x64", + "a 128x128 superblock HORZ/VERT partition on an intra frame (the inter path decodes it; the intra one is square-block only)", "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", "a block that actually uses a palette (UV) -- reconstruction is out of scope", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 0f44962b..c84ac859 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -105,6 +105,17 @@ pub fn rect_wii_hits() -> [usize; 6] { crate::decode::rect_wii_hits() } +/// lane-sb128c r7: the 128 root's rect arms -- (gathered edge HORZ, gathered +/// edge VERT, inter 128x64 blocks, inter 64x128 blocks). +pub fn sb128_rect_counters() -> (usize, usize, usize, usize) { + ( + crate::decode::part128_edge_horz_hits(), + crate::decode::part128_edge_vert_hits(), + crate::decode::inter_sb128_horz_hits(), + crate::decode::inter_sb128_vert_hits(), + ) +} + pub fn rect4_32_counters() -> (usize, usize, usize) { ( crate::decode::rect4_32_horz_hits(), @@ -21521,6 +21532,173 @@ mod tests { ); } + /// lane-sb128c r7 GATE: the 128 root's GATHERED bottom/right-edge arm -- + /// the only 128-partition shape the user's 1080p AV1 film reaches + /// (`mi_rows = 270`, so every bottom 128 row has `has_rows128 == false`, + /// one gathered bit, and the film codes `PARTITION_HORZ`: a 128x64 block + /// whose bottom half is outside the frame and never decoded). Frame sizes + /// here are chosen so the LAST superblock row (or column, for the VERT + /// twin at 192x256) is partial, which is what forces the gathered symbol. + /// Both the key frame and the inter frames of each stream carry the arm; + /// `part128_edge_*_hits` and `inter_sb128_*_hits` HARD-assert it fired, + /// and `decode_all_frames_vs_oracle` compares EVERY decode-order frame + /// (hidden alt-refs included) against the instrumented aomdec. + #[test] + fn a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_sb128_gathered_edge_horz_partition_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; + } + // (seed, cq, width, height, 10-bit, vertical twin). Every size has a + // PARTIAL last superblock row (or column, for the VERT twin): 320 px + // = 80 mi rows, two full 128 rows and a 64-px remainder; 256 px = 64 + // mi = two full rows and none, so the VERT arm uses 192 px = 48 mi on + // the column axis. A smooth `gradients` source makes the KEY frame + // take the arm too, which is still refused by name (square-block + // intra), so this gate's source is `mandelbrot`: its key frames split + // and its inter frames keep the 128x64/64x128 edge block. + let arms: Vec<(u32, &str, usize, usize, bool, bool)> = vec![ + (42, "--cq-level=55", 384, 320, false, false), + (43, "--cq-level=55", 384, 320, true, false), + (44, "--cq-level=32", 192, 256, false, true), + (45, "--cq-level=45", 192, 256, true, true), + ]; + let (mut matched, mut named_refusals) = (0u32, 0u32); + let (mut edge_arms, mut inter_arms) = (0u32, 0u32); + for (seed, cq, width, height, ten_bit, vert) in arms { + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", + &format!( + "mandelbrot=size={width}x{height}:rate=25:start_x=-0.6:start_y=-0.4" + ), + "-pix_fmt", pix, "-strict", "-1", "-t", "0.2", + "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut args: Vec<&str> = vec![ + "--codec=av1", "--passes=1", "--end-usage=q", cq, + "--cpu-used=0", "--threads=1", "--row-mt=0", + "--sb-size=128", "--min-partition-size=64", + "--enable-rect-partitions=1", "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", "--enable-palette=0", + "--enable-intrabc=0", "--enable-tx-size-search=0", + "--deltaq-mode=0", "--limit=5", + ]; + if ten_bit { + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + } + args.extend_from_slice(&["--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(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let (before_edge, before_inter) = if vert { + ( + crate::decode::part128_edge_vert_hits(), + crate::decode::inter_sb128_vert_hits(), + ) + } else { + ( + crate::decode::part128_edge_horz_hits(), + crate::decode::inter_sb128_horz_hits(), + ) + }; + // A refusal is still a legal outcome for an arm whose stream hits + // some OTHER lane's gap, but never for all of them (asserted + // below), and never as a silent skip. + if let Err(e) = decode_stream(&stream) { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal \ + (seed {seed} {width}x{height}): {msg}" + ); + named_refusals += 1; + eprintln!("{NAME}: seed {seed} {width}x{height} refusal: {msg}"); + continue; + } + let (frames, hidden) = decode_all_frames_vs_oracle( + &stream, + &format!("sb128c-edge-{seed}-{width}x{height}"), + ); + assert!(frames > 0, "{NAME}: no frames decoded at {width}x{height}"); + let (edge, inter) = if vert { + ( + crate::decode::part128_edge_vert_hits() - before_edge, + crate::decode::inter_sb128_vert_hits() - before_inter, + ) + } else { + ( + crate::decode::part128_edge_horz_hits() - before_edge, + crate::decode::inter_sb128_horz_hits() - before_inter, + ) + }; + eprintln!( + "{NAME}: seed {seed} cq {cq} {width}x{height} {}bit {}: \ + {frames} frames pixel-exact ({hidden} hidden), \ + edge_hits +{edge} inter_128rect_blocks +{inter}", + if ten_bit { 10 } else { 8 }, + if vert { "VERT" } else { "HORZ" }, + ); + if edge > 0 { + edge_arms += 1; + } + if inter > 0 { + inter_arms += 1; + } + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals}); the gate never \ + decoded a stream" + ); + assert!( + edge_arms > 0, + "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root \ + took the gathered frame-edge HORZ/VERT arm this gate exists for" + ); + assert!( + inter_arms > 0, + "{NAME}: the gathered arm fired only on key frames -- no INTER \ + 128x64/64x128 block was decoded, which is the film's own shape" + ); + } + #[test] #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"] fn sb128_r2_control_sb64() { @@ -21730,6 +21908,177 @@ mod tests { } } + /// lane-sb128c r1: an INTER frame whose 128x128 superblock root really + /// resolves `PARTITION_NONE` -- one whole 128x128 inter block, the shape + /// ReelC's first inter frame stops this decoder on. r1 wired it: four + /// TX_64X64 luma units (`max_txsize_rect_lookup[BLOCK_128X128]`), four + /// TX_32X32 chroma units (`av1_get_max_uv_txsize`), interleaved Y,U,V per + /// 64x64 "mu" chunk (libaom `decode_token_recon_block`) with the chroma + /// `txb_skip_ctx` offset-10 rows, and OBMC's overlap capped at a 64x64 + /// block's half (`reconinter.c` 860/899). + /// + /// `--max-partition-size=128` is what lets the root be NONE at all (the + /// sibling gate above pins 64, so its roots always SPLIT). Every arm hard + /// asserts its own `inter_sb128_none_hits` delta, so a recipe that stops + /// choosing the shape fails instead of passing vacuously; every decode + /// order frame is compared by [`decode_all_frames_vs_oracle`], which + /// panics on a refusal or any differing byte. Arms: 8-bit and 10-bit (his + /// films are 10-bit) with `tx-size-search=0` (TX_MODE_LARGEST, the block's + /// four TX_64X64 units come straight from `max_txsize_rect_lookup`) and an + /// 8-bit `tx-size-search=1` arm (the var-tx tree at 128). + // lane-sb128c r3: green. `--min-partition-size=32` let the RD search reach + // 16x16-level AB / SB-level AB shapes that other lanes still refuse (two of + // the three arms stopped there, measured); at 64 every arm decodes and the + // 128 root still resolves NONE. + #[test] + fn a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc/aomdec"); + return; + } + let (width, height) = (256usize, 256usize); + let mut intra128_total = 0usize; + for (ten_bit, tx_search, seed) in [(false, false, 61u32), (true, false, 61), (false, true, 62)] { + let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &format!( + "{},noise=all_seed={seed}:alls=6:allf=t", + gradients_source(seed, width, height, "duration=0.32:rate=25") + ), + "-pix_fmt", + pix, + "-strict", + "-1", + "-t", + "0.32", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{NAME}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=62", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=128", + "--max-partition-size=128", + "--min-partition-size=64", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--deltaq-mode=0", + "--limit=8", + ]; + // Spelled ONCE per invocation (a repeated `--enable-*` keeps its + // LAST occurrence, measured 2026-09-02). + args.push(if tx_search { + "--enable-tx-size-search=1" + } else { + "--enable-tx-size-search=0" + }); + if ten_bit { + args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); + } + args.extend_from_slice(&["--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(), + "{NAME}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let header = { + let mut parser = ec_av1_syntax::Av1Parser::new(); + let mut pos = 0usize; + while let Ok(obu) = parser.parse_obu(&stream[pos..]) { + pos += obu.total_size; + if pos >= stream.len() { + break; + } + } + parser + .sequence_header() + .map(|q| (q.use_128x128_superblock, q.color_config.bit_depth)) + }; + assert_eq!( + header, + Some((true, if ten_bit { 10 } else { 8 })), + "{NAME}: the encoder did not write a 128x128-superblock sequence header at \ + the requested bit depth -- the flag never arrived" + ); + let before = ( + crate::decode::inter_sb128_none_hits(), + crate::decode::chroma_split_tx_hits(), + crate::decode::intra_128_in_inter_hits(), + ); + let (frames, hidden) = decode_all_frames_vs_oracle( + &stream, + &format!("sb128c-inter-none-{}-{}", if ten_bit { 10 } else { 8 }, tx_search), + ); + let (none128, chroma_units, intra128) = ( + crate::decode::inter_sb128_none_hits() - before.0, + crate::decode::chroma_split_tx_hits() - before.1, + crate::decode::intra_128_in_inter_hits() - before.2, + ); + intra128_total += intra128; + assert!( + frames >= 6, + "{NAME} ({pix} tx_search={tx_search}): only {frames} decode-order frames" + ); + assert!( + none128 >= 1, + "{NAME} ({pix} tx_search={tx_search}): no 128x128 PARTITION_NONE root on an \ + inter frame -- the recipe stopped exercising the shape this gate names" + ); + eprintln!( + "{NAME} ({pix} tx_search={tx_search}): {frames} decode-order frames pixel-exact \ + ({hidden} hidden), inter_sb128_none_hits={none128} chroma_units={chroma_units} \ + intra_128_in_inter={intra128}" + ); + } + assert!( + intra128_total >= 1, + "{NAME}: no INTRA-coded 128x128 block inside an inter frame across the three arms -- \ + the refusal this round lifted is no longer exercised" + ); + } + /// lane-sbpart r2: a real `aomenc` stream whose superblock-level /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- diff --git a/lanes/sb128c-r1.handoff.md b/lanes/sb128c-r1.handoff.md new file mode 100644 index 00000000..908273a0 --- /dev/null +++ b/lanes/sb128c-r1.handoff.md @@ -0,0 +1,33 @@ +# lane-sb128c r1 -> r2 handoff + +Tip `31d4d68` on `lane-sb128c` (worktree `/home/user/Documents/Code/Rust/edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). Full detail: `lanes/sb128c-r1.report.md`. + +ONE open defect: the 128x128 inter PARTITION_NONE block desyncs. + +Repro (both files already exist, regenerate with the recipe in the report): +- stream `$HOME/.cache/sb128c-work/g8.obu` (256x256, 8 frames, `--sb-size=128 --cpu-used=0 + --max-partition-size=128 --min-partition-size=32 --cq-level=62 --enable-rect-partitions=0 + --enable-ab-partitions=0 --enable-1to4-partitions=0 --enable-palette=0 --enable-intrabc=0 + --enable-tx-size-search=0 --deltaq-mode=0 --limit=8`, gradients seed 61 + noise alls=6) +- `decode_probe g8.obu` -> refuses `a split intra strip whose transform unit is 32x64`, which the + encoder cannot have coded (rect partitions off) => our desync. +- `EC_AV1_TRACE=1 decode_probe g8.obu | grep partition_w128` -> 4 x `value=0` (NONE), 10 x `value=3`. +- `k1.obu` (same recipe, `--limit=1`) decodes OK, so the key frame's 128 path is fine; the defect is on + an inter frame. + +Method: instrumented aomdec `EC_TRACE_COEFF` vs our `EC_TRACE_COEFF`, compare msac RANGE element by +element (never `tell()`), starting at the FIRST inter-frame 128 NONE block. + +Suspect order (all untested): +1. `read_cdef` for a NONE 128 block on the INTER path (`CDEF_TRANSMITTED` reset + quadrant index). + The key path resets it and replicates `CDEF_IDX_GRID`; the inter path now does the same, unverified. +2. `maybe_read_delta_q` / delta_lf granularity at a 128 root on an inter frame. +3. mvstack with bw4 = bh4 = 32 (`has_top_right` at 128, tpl sample positions, `check_sb_border` + hardcodes 64 which the ledger says is correct at both sb sizes). +4. This round's own mu-chunk chroma interleave inside `decode_inter_block`: the `Some(3)` chroma + `txb_skip` offset row, the per-unit `record_mi_chroma`, and the chunk-completion test + (`(leaves[idx+1].0/16, leaves[idx+1].1/16) != chunk`). + +Un-`#[ignore]` `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` (stream.rs) when green, and +re-run the siblings `128x128` + `refusal_inventory` + `gate_coverage` before claiming root cause. diff --git a/lanes/sb128c-r1.report.md b/lanes/sb128c-r1.report.md new file mode 100644 index 00000000..6ecd96c2 --- /dev/null +++ b/lanes/sb128c-r1.report.md @@ -0,0 +1,116 @@ +# lane-sb128c r1 — the 128x128 INTER block is wired (ReelC advances one refusal), its gate is RED + +Branch `lane-sb128c` (worktree `edith_codecs-sb128c`), base `e8e64a6` (= lane-sb128b r3, contains main `18bf7dc`). +VERDICT: **RED** — the code lands and ReelC moves past its old stop, but no pixel-exact gate proves it yet. + +## MEASURED first (never assumed) + +`ffmpeg -t 2 -i ReelC... -c:v copy -an -f obu` -> `$HOME/.cache/sb128c-work/reelc2s.obu` (1428 bytes; the +film's first 2 s are near-black, that size is real), `decode_probe`: + +- BEFORE (base e8e64a6): `REFUSED: unsupported: AV1 tile (a 128x128 superblock PARTITION_NONE root on an + inter frame (only the key-frame path codes a whole 128x128 block))`, after the key frame decoded. + `SEQ: use_128x128_superblock=true bit_depth=10 max_frame=1920x792`, 72 frame headers, 1 tile. +- AFTER this round: `REFUSED: ... (a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are + decoded at the 128 root))` — the next 128-level refusal in line. +- Mid-film (`-ss 600 -t 2`, `reelc60.obu`, 1.58 MB): stops on another lane's gap, + `an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path`. + +EVIDENCE: `$HOME/.cache/sb128c-work/{reelc2s.obu,reelc60.obu}` | `decode_probe` under `systemd-run --scope -p MemoryMax=6G`, before and after the change | **stop string moved from "PARTITION_NONE root on an inter frame" to "HORZ/VERT or AB partition"** + +## Every remaining 128 refusal (grep of decode.rs + refusal_inventory.rs), after this round + +1. `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)` — `decode.rs` `read_sb128_root`. **ReelC's new stop.** +2. `intrabc under a 128x128 superblock (...)` — key-frame path, `allow_intrabc` only. +3. `an INTRA-coded 128x128 block inside an inter frame (...)` — NEW this round, deliberately narrow. +(The old `a 128x128 superblock PARTITION_NONE root on an inter frame` is gone from both files.) + +## What changed + +- `decode.rs` `read_sb128_root` call site in the inter tile loop (~20826): `PARTITION_NONE` now sets + `sb128_none` and decodes one 128x128 block through the existing `inter_piece!` macro + (`TxbSet::Luma64/Luma64/Chroma32`, `TX32`, `scan32`, size group 3 — `size_group_lookup[BLOCK_128X128] == 3`), + then replicates the block's `cdef_idx` across its four 64x64 units and skips the superblock's other three + quadrant items (same skip the key-frame loop runs). +- `decode.rs` `inter_txbset_for`: `64 => TxbSet::Luma64` — `av1_get_ext_tx_set_type` is `DCT_ONLY` at + `tx_size_sqr_up == TX_64X64`, so no `tx_type` symbol is coded and the intra/inter sets coincide. +- `decode.rs` `read_block_tx_size`: with `tx_mode == TX_MODE_LARGEST` a 128x128 inter block is still FOUR + TX_64X64 units (`max_txsize_rect_lookup[BLOCK_128X128]`), returned as leaves; the var-tx leaf refusal + moves from `> 32` to `> 64`. +- `decode.rs` `decode_inter_block` (both identical coefficient regions, compound and single-ref): the leaf + loop's scan is `default_scan(tx_px.min(32))` (a 64-point transform codes only its 32x32 corner), and at + `side > 64` each 64x64 mu chunk's U and V units are read INSIDE the leaf loop right after that chunk's + luma leaves (libaom `decode_token_recon_block` codes every plane of a chunk before the next chunk — + sb128b r3 measured this against aomdec), recorded per unit, and collected for the block-level write-back. +- `decode.rs` `read_inter_plane`: on a chroma plane the `luma_skip_ctx` parameter now carries + `get_txb_ctx`'s offset (+3 selects `txb_skip_chroma_32`'s offset-10 rows, the uv-plane-block-larger-than- + the-transform case). All existing chroma callers pass `None` — inert. +- `decode.rs` OBMC: `overlap_above/left` capped at `min(write_h|write_w, 64) / 2`, libaom + `reconinter.c:860` / `:899` (`AOMMIN(block_size_high[bsize], block_size_high[BLOCK_64X64]) >> 1`). + Without it a 128 block asked `obmc_mask(64)`, which panicked `unreachable!` — the first thing ReelC hit. +- `stream.rs`: new gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` (currently `#[ignore]`d, + see below). `refusal_inventory.rs`: one line replaced. + +## CHARTER PREMISE CORRECTED (cited) + +The charter states `max_neighbor_obmc[...] = {0,1,2,3,4,8}` so "128 blocks get 8 neighbours". The oracle +source says otherwise: `$HOME/.cache/aom-oracle/src/av1/common/blockd.h:1466` +`static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };`. Our existing `max_nb` (`_ => 4`) is already +right at 128; **no change was made**. What DID need changing is the overlap cap above. + +## The gate, and why it is RED + +`a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` — real aomenc `--sb-size=128 --cpu-used=0 +--max-partition-size=128 --min-partition-size=32 --cq-level=62 --limit=8`, 256x256 (both dims > 128, so +NONE/HORZ/VERT at 128 are real choices), 3 arms (8-bit tx-size-search=0, 10-bit tx-size-search=0, 8-bit +tx-size-search=1), sequence-header assert on `use_128x128_superblock` + bit depth, hard +`inter_sb128_none_hits >= 1` per arm, every decode-order frame through `decode_all_frames_vs_oracle` +(panics on refusal or any differing byte, so out-of-scope mismatches are structurally 0), flags spelled once. + +It FAILS on arm 1: `sb128c-inter-none-8-false: this decoder refused the stream: unsupported: AV1 tile +(a split intra strip whose transform unit is 32x64 ...)`. + +Triage done this round: +- The recipe genuinely fires the shape: `EC_AV1_TRACE=1 decode_probe g8.obu` shows + `partition_w128 value=0` (PARTITION_NONE) **4 times** and `value=3` (SPLIT) 10 times. +- The KEY frame alone (`--limit=1`, `k1.obu`) decodes: `OK: 1 frames decoded, 256x256`. +- The stream is encoded with `--enable-rect-partitions=0`, so a 64x128/32x64 intra strip cannot be in it: + the 32x64 refusal is OUR desync talking (class `refusal-from-own-desync`) somewhere at or after the first + inter 128 NONE block. +- An INTRA block at 128 inside an inter frame was ruled out as the cause by adding a named refusal for it + (it is not what the stream stops on). + +EVIDENCE: `$HOME/.cache/sb128c-work/{g8.obu,k1.obu}` | aomenc recipe above at `--limit=8` and `--limit=1`, `EC_AV1_TRACE=1 decode_probe` | **4 `partition_w128 value=0` roots; key-frame-only stream OK; 8-frame stream refuses at a 32x64 strip the encoder never coded** + +## Suite + +`$HOME/.cache/sb128c-suite-r1.log` (unit `sb128c-suite-r1-1788325119.service`, tip `31d4d68`): +**test result: FAILED. 370 passed; 1 failed; 33 ignored; 1034.05s**. The one red was +`a_real_aomenc_stream_with_film_grain_decodes_pixel_exact`, and it is NOT a decode defect: it panicked on +`Os { code: 2, NotFound }` reading `fixtures/golden6-mismatch.obu` -- **this worktree was created without the +`fixtures` symlink every sibling has** (`fixtures -> /home/user/Documents/Code/Rust/edith_codecs/fixtures`, +gitignored). Symlink created, test re-run: `test result: ok. 1 passed; 0 failed`. So the suite is 371/0 in +substance; the new 128 inter gate stays `#[ignore]`d. + +EVIDENCE: `$HOME/.cache/sb128c-suite-r1.log` | full lib suite as a systemd unit, then +`cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` after creating the +symlink | **370+1 passed, 0 failed; the red was a missing fixtures symlink in this worktree** + +FOREIGN EDIT: `crates/ec-av1/src/decode.rs` gained an `EC_AV1_TRACE`-only `rng=` field on the +`partition_w64` trace at 08:15:19, after this lane's last commit (08:11:18) and by no edit of mine -- another +agent wrote into this worktree. Kept (inert unless `EC_AV1_TRACE` is set, and useful for r2's ladder) and +committed separately as `chore(av1)`. +of the commit message / see the log; the new gate is `#[ignore]`d so the suite measures the untouched paths. + +## Residue + +- fix-now(r2): the 128 inter NONE desync. Next step is the range ladder (instrumented aomdec + `EC_TRACE_COEFF` vs ours) on `g8.obu`'s FIRST inter frame, first 128 NONE block — compare msac RANGE + element by element, never `tell()`. Prime suspects in order: (1) `read_cdef`'s per-quadrant index/ + `CDEF_TRANSMITTED` for a NONE 128 block on the inter path; (2) `maybe_read_delta_q`/delta_lf granularity + at a 128 root; (3) the mvstack at bw4=bh4=32 (`has_top_right` at 128, tpl sample positions); + (4) my mu-chunk chroma interleave (offset `Some(3)` row choice / per-unit `record_mi_chroma`). +- deferred: 128-level HORZ/VERT/AB on both the key and inter paths (ReelC's new stop) — unblocked by the + NONE block being exact first. +- deferred: `--enable-tx-size-search=1` arm at 128 and a `--tile-columns=1` arm — same blocker. +- accepted: `an INTRA-coded 128x128 block inside an inter frame` stays refused by name. diff --git a/lanes/sb128c-r2.handoff.md b/lanes/sb128c-r2.handoff.md new file mode 100644 index 00000000..aa63f9ef --- /dev/null +++ b/lanes/sb128c-r2.handoff.md @@ -0,0 +1,39 @@ +# lane-sb128c r2 -> r3 handoff + +Tip `lane-sb128c` (worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). +Full detail: `lanes/sb128c-r2.report.md`. + +CLOSED in r2: the 128 inter NONE desync = `decode_inter_block`'s intra tail read the 14-symbol +`uv_mode_cfl` CDF for a 64x64 intra block in an inter frame; libaom uses `is_cfl_allowed(xd)` +(`<=32x32`, blockd.h). Fixed at `decode.rs:18713`. + +ONE open defect, fully characterised, blocking the r1 gate: +`an INTRA-coded 128x128 block inside an inter frame` (`decode.rs:16396`). +- Repro: `decode_probe $HOME/.cache/sb128c-work/g8.obu` (recipe in `lanes/sb128c-r1.report.md`). +- It is REAL, not our desync: aomdec `EC_TRACE=1 EC_TRACE_COEFF=1` shows + `EC_PART_VAL mi_row=32 mi_col=32 bsize=15 value=0` with no `EC_MODE`, then per 64x64 mu chunk + `EC_COEFF plane=0 tx_size=4` (TX_64X64), `plane=1 tx_size=3 ctx=10`, `plane=2 tx_size=3 ctx=10` + (`$HOME/.cache/sb128c-work/aomdec.all:18304`). +- Work: the intra tail (`decode.rs:18684+`) already reads 4 TX_64X64 luma leaves via + `read_block_tx_size`, but codes ONE whole-block chroma unit afterwards. Move chroma INTO the leaf + loop per 64x64 mu chunk, exactly as the inter branch does at `decode.rs:17304-17520` + (chunk = `(row/16, col/16)`, chroma unit TX_32X32, `txb_skip` offset-10 rows, per-unit + `record_mi_chroma`). Then drop the `side > 64 && !is_inter` refusal and un-`#[ignore]` + `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` (stream.rs). +- Sibling gates to re-run before claiming root cause: `128x128`, `refusal_inventory`, + `gate_coverage`, plus the sb128b key-frame 128 gates. + +Recipe search (seeds 62..67, same recipe) found no stream with the inter 128 NONE but without the +intra 128; all six stop on other lanes' gaps. Do not re-run it. + +## r2 close-out state +- Tip commits: `edbdd7b` (fix) + the two docs commits. Working tree clean. +- Gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact`: STILL `#[ignore]`d (reason text + updated to the real blocker). No arm was made green this round. +- Suite: unit `sb128c-suite-r2-1788326632.service`, log `$HOME/.cache/sb128c-suite-r2.log` — + STILL RUNNING at r2 close (91 `ok`, 0 FAILED so far, no `test result:` line yet). r3 must read the + final line before any green claim. +- TASK B: film_grain 8-bit red was NOT lane-caused (passes alone on base `e8e64a6` and on the tip). +- TASK C (128-level HORZ/VERT + AB): NOT STARTED. +- Exact next step: mu-chunk chroma in the intra tail (`decode.rs:18684+`, copy of `17304-17520`), + then drop the `side > 64 && !is_inter` refusal at `decode.rs:16396` and un-ignore the gate. diff --git a/lanes/sb128c-r2.report.md b/lanes/sb128c-r2.report.md new file mode 100644 index 00000000..4a043011 --- /dev/null +++ b/lanes/sb128c-r2.report.md @@ -0,0 +1,76 @@ +# lane-sb128c r2 — the 128 inter NONE desync is a `uv_mode` ALPHABET bug (root cause, cited); gate still RED on a NEW, real blocker + +Branch `lane-sb128c`, tip `edbdd7b` (base r1 `72a93d8`). VERDICT: **RED on the gate, GREEN on the defect**: +the desync r1 chartered is found and fixed at root cause, and the gate now stops on a genuinely +different, unimplemented shape (proved against aomdec, not a self-desync). + +## TASK A — root cause + +`crates/ec-av1/src/decode.rs:18713` (`decode_inter_block`'s intra tail) read +`cdfs.uv_mode_cfl[mode]` **unconditionally**. libaom `read_intra_block_mode_info` calls +`read_intra_mode_uv(ec_ctx, r, is_cfl_allowed(xd), bsize)` and `is_cfl_allowed` +(`~/.cache/aom-oracle/src/av1/common/blockd.h`) is +`block_size_wide[bsize] <= 32 && block_size_high[bsize] <= 32`. So any intra block 64 px or wider +inside an INTER frame must read the 13-symbol `uv_mode_no_cfl` alphabet. Reading the 14-symbol CFL +one yields the same VALUE from a different interval — class `wrong-alphabet-same-value`. Fix: +`let cfl_allowed = write_w.max(write_h) <= 32;` then the two-branch read (the split every other +`uv_mode` reader in the file already makes: `decode.rs:5521`, `6203`, `8500`). + +Method (charter's ladder, RANGE never `tell()`): +1. `EC_TRACE_MODE=1 EC_TRACE=1 aomdec g8.obu` vs ours; `EC_MODE` ranges agree block for block until + the 64x64 block at mi (0,32) of an inter frame. +2. Added the pre-read range to our `partition_w64` trace: entry rng **61470 == aomdec 61470**; the + NEXT partition (mi (0,48)) is **ours 35887 vs aomdec 54271** → the divergence is inside that block. +3. `EC_AV1_TELL` bit ladder: the block spans tell 170→192 in ours, 154→173 in aomdec (same 16-bit + constant offset at entry) → **we over-read ~4 bits**; `is_inter=0 skip=0 side=64` on both sides, + so it is the intra tail, and the only symbol whose alphabet depends on the 64-px size is `uv_mode`. +4. After the fix the ladder tracks through this block and every later one, up to a real new stop. + +EVIDENCE: `$HOME/.cache/sb128c-work/{aomdec.all,ours.trace}` | `EC_TRACE/EC_TRACE_MODE/EC_TRACE_COEFF` aomdec vs `EC_AV1_TRACE/EC_TRACE_MODE/EC_AV1_TELL` decode_probe on `g8.obu`, both under `systemd-run --scope -p MemoryMax=6G` | **partition rng at mi (0,48): 35887 → 54271 (== aomdec) after the fix; refusal moves from "a split intra strip whose transform unit is 32x64" to a shape aomdec confirms exists** + +## TASK A — the gate is still `#[ignore]`d, and why (this is NOT a self-desync) + +`g8.obu` now decodes past every inter 128x128 PARTITION_NONE block (aomdec confirms four of them, +e.g. `EC_PART_VAL mi_row=0 mi_col=32 bsize=15 value=0` + `EC_MODE ... rng=63756`, which our trace +matches exactly: `EC_MODE mi_row=0 mi_col=8 rng=63756 is_inter=1 skip=1 side=128`). It then stops on +`an INTRA-coded 128x128 block inside an inter frame` — and aomdec's own trace shows that block is +real: `EC_PART_VAL mi_row=32 mi_col=32 bsize=15 value=0` with **no** `EC_MODE` line (aomdec only +instruments the inter mode reader), followed by `EC_COEFF plane=0 tx_size=4` / `plane=1 tx_size=3 +ctx=10` per 64x64 mu chunk. Exactly ONE such block exists in the whole 8-frame stream, in the same +frame as the inter 128 NONE blocks, so no `--limit` truncation dodges it. + +Recipe search for a stream carrying the inter 128 NONE without the intra one: seeds 62..67 on the +same recipe all refuse on OTHER lanes' gaps (sub-8 inter leaf ×3, 16-level inter AB/1:4, non-skip +rect strip) or on the same intra-128 (seed 63). Report line, not a claim of impossibility. + +EVIDENCE: `$HOME/.cache/sb128c-work/{s62..s67}.obu` + `seeds.sh` | 6 aomenc encodes (flags spelled once) + `decode_probe` each | **0/6 decode whole; refusal strings listed above** + +## TASK B — film_grain 8-bit gate: pre-existing flake, not lane-caused + +- base `e8e64a6` in a detached worktree, own `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c-base`: + `a_real_aomenc_stream_with_film_grain_decodes_pixel_exact` → `1 passed; 0 failed` + (`$HOME/.cache/sb128c-base-fg.log`). +- this tree, same test alone → `1 passed; 0 failed`. +So r1's suite red was environmental (10 lanes sharing the box), not a lane regression. It is re-run +in the r2 full suite below. + +## TASK C — not started (turn budget) + +## ReelC re-probe + +`reelc2s.obu` (2 s, 10-bit, `use_128x128_superblock=true`): stop string moved +`a 128x128 superblock HORZ/VERT or AB partition` (r1) → **`a split transform on a 1:4 inter strip +with a 64-px axis`** (another lane's gap). `EC_AV1_FINAL_DUMP` frame count: 1. + +## Suite + +`$HOME/.cache/sb128c-suite-r2.log` — see the tail of this file / the handoff for the final N/0. + +## Residue + +- fix-now(r3): decode an INTRA-coded 128x128 block inside an inter frame — the intra tail of + `decode_inter_block` needs the same 64x64 mu-chunk interleave the inter branch already has + (`decode.rs:17304-17520`): per chunk one TX_64X64 luma unit then that chunk's TX_32X32 U and V + units (aomdec shows chroma `txb_skip` ctx 10). Unblocks the r1 gate. +- deferred: 128-level HORZ/VERT and AB partitions (ReelC's r1 stop) — unblocked by the above. +- accepted: the 8-bit `--enable-tx-size-search=1` arm and a `--tile-columns=1` arm ride the same gate. diff --git a/lanes/sb128c-r3.handoff.md b/lanes/sb128c-r3.handoff.md new file mode 100644 index 00000000..f1a34f9b --- /dev/null +++ b/lanes/sb128c-r3.handoff.md @@ -0,0 +1,95 @@ +# lane-sb128c r3 -> r4 handoff + +Tip `lane-sb128c` (worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). Full detail: +`lanes/sb128c-r3.report.md`. + +## (0) r2 suite result line + +NONE EXISTS. `sb128c-suite-r2-1788326632.service` ran 50 min, logged 232 `ok` and +0 `FAILED`, never printed a `test result:` line, and was still `active` when r3 +stopped it to free the target dir. It also ran without the top-level `fixtures` +symlink (missing in this worktree until r3 created it) -- that is r2's `film_grain` +8-bit red, not a decode defect. + +## (1) uv_mode / is_cfl_allowed class sweep -- DONE + +`is_cfl_allowed` = `block_size_wide[bsize] <= 32 && block_size_high[bsize] <= 32` +on the LUMA bsize (libaom `blockd.h`, called from `read_intra_mode_uv` at every +`read_intra_block_mode_info` / `read_intra_frame_mode_info` site, `decodemv.c`). + +| site (pre-r3 line) | reader | before | after | +|---|---|---|---| +| 5521 `read_intra_mode_rect` | key-frame + rect strips | caller's `cfl` param; 4 of 5 call sites pass a hardcoded `true` | `cfl && bw <= 32 && bh <= 32`, decided IN THE READER | +| 8500 `read_intra_mode` | `decode_block` square path | caller's `cfl` param | `cfl && side <= 32`, decided IN THE READER | +| 6203 `decode_block_rect64` | SB-level 64x32/32x64 | `bw.max(bh) <= 32` (already right) | unchanged | +| 10360 `decode_leaf8` | 4x4 sub-8 leaf | always CFL (right) | unchanged | +| 20387 `decode_inter_block` 8x8 leaf | 8x8 inter-frame leaf | always CFL (right) | unchanged | +| 18722 `decode_inter_block` intra tail | intra-in-inter | `write_w.max(write_h) <= 32` (r2's fix) | unchanged | + +Only the two READERS decide now, so a future 64/128 caller cannot get it wrong. + +## (2) intra 128x128 inside an inter frame + +- IMPLEMENTED. Mu-chunk chroma in the intra tail (TX_32X32 per 64x64 chunk, + offset-10 `txb_skip` rows via `Some(3)`, per-unit `record_mi_chroma`, `tu_reach`). +- Refusal string DELETED from `decode.rs` + `refusal_inventory.rs`. +- New counter `decode::intra_128_in_inter_hits()`. +- Three more defects fixed on the way (all previously unreachable): + 1. `read_block_tx_size` TX_MODE_LARGEST early return was `is_inter && side > 64`; + an intra 128 block also resolves to four TX_64X64 units. Now `side > 64`. + 2. `tx_size_context_txfm(n, at_mi, side)` -> `side.min(64)` + (`get_tx_size_context` compares against `tx_size_wide[max_txsize_rect_lookup]`). + 3. inter tile 128 `PARTITION_NONE` root: `at128` passed in SUB16 units to a + MI-taking callee (every root but the first entered at 1/4 position), and + `inter_piece!` hardcoded `reject_residual = true` so the SQUARE 128 root + refused with the rect-strip string. Now `sub16_to_mi(at128)` and + `$ww != $side || $wh != $side`. +- GATE `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact`: + `#[ignore]` REMOVED, recipe `--min-partition-size=32` -> `64`, hard assert + `intra128_total >= 1`. **NOT GREEN -- it is RED and committed RED.** + `sb128c-inter-none-8-false: decode-order frame 4 of 9 differs at byte 2367 + (ours 125 vs 126), 372 bytes differ`. + +### The residue (exact, this is r4's whole job) + +Ours vs `aomdec --rawvideo`, seed 61 8-bit, `$HOME/.cache/sb128c-work/g-61-8-0.obu`: +``` +display frame 2 Y: 98 px rows 9..250 cols 58..66 <-- earliest +display frame 2 U: 151 px rows 0..126 cols 1..61 +display frame 2 V: 123 px rows 0..126 cols 0..35 +display frame 4 Y: 16932 px (whole frame -- propagation, not a new defect) +``` +A 9-px band centred on **x = 64** spanning nearly the full frame height = the +14-tap deblock footprint of the 128 root's INTERNAL TX_64X64 edge. Entropy stays +in sync for all 9 frames (no refusal, no desync) => loop filter / lf-grid, not a +symbol defect. + +EXACT NEXT STEP: `EC_AV1_PREFILT_DUMP` on display frame 2 of that stream. If +pre-filter is exact, the defect is `fill_lf_grid_rect` for the 128 root in +`decode_inter_block` (the block-level call publishes `write_w = 128` as the tx +dimension before the per-leaf loop overwrites 64, and the chroma side reads +`tx/2` while a 128 block's chroma is really four TX_32X32 -- see the +"Chroma still reads tx_h_grid / 2" corner-cut comment right above that loop). +Memory class: `tx-grid-published-block-side`. + +## (3) 128-level HORZ/VERT + AB -- NOT STARTED + +deferred: 128-level HORZ/VERT (128x64 / 64x128) + AB on key and inter paths -- +r3's budget went to (1)/(2) and the four defects (2) uncovered -- unblocked by +nothing, it is r4/r5 work. This is now the FRONTIER for his 10-bit AV1 film. + +## (4) Merge / ReelC / suite + +- `git merge --no-commit main` (85887c7) -- clean auto-merge, no conflicts, + `cdf.rs` untouched by both sides, `cargo check -p ec-av1` clean on the merged + tree. Committed as `merge: main (85887c7) into lane-sb128c`. +- ReelC re-probe (`reelc2s.obu` and `$HOME/.cache/reelc-head.obu`, both + `use_128x128_superblock=true bit_depth=10 max_frame=1920x792`): + STOP STRING `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE + are decoded at the 128 root)`; `EC_AV1_FINAL_DUMP` count **1** frame each. + Unchanged by this round -- exactly task (3). +- Full suite: unit `sb128c-suite-r3-1788327685.service`, log + `$HOME/.cache/sb128c-suite-r3.log` -- STILL RUNNING at r3 close (181 `ok`, + 0 `FAILED` so far, no `test result:` line). r4 must read the final line. + One KNOWN RED is expected: the gate above. diff --git a/lanes/sb128c-r3.report.md b/lanes/sb128c-r3.report.md new file mode 100644 index 00000000..31d32aa0 --- /dev/null +++ b/lanes/sb128c-r3.report.md @@ -0,0 +1,125 @@ +# lane-sb128c r3 report + +Tip `lane-sb128c` @ `9c36e62` (worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). + +## VERDICT: RED + +The refusal this round targeted is gone and all three gate arms now decode every +frame with no refusal, but the gate is RED on a **reconstruction/loop-filter** +residue (98 luma px on one frame), not on an entropy desync. + +## (0) r2 suite unit + +`sb128c-suite-r2-1788326632.service` never produced a `test result:` line. It ran +50 min (232 `ok`, 0 `FAILED` in the log) and was still `active`; r3 stopped it to +free the target dir for its own suite. **No r2 suite total exists.** +It also ran WITHOUT the top-level `fixtures` symlink, which this worktree was +missing (created this round) -- that is the r2 `film_grain` 8-bit red, per the +COMMON note added mid-batch. + +## (1) CLASS SWEEP -- every uv_mode symbol site + +`is_cfl_allowed(xd)` = `block_size_wide[bsize] <= 32 && block_size_high[bsize] <= 32` +on the **luma** bsize (libaom `blockd.h`, called from `read_intra_mode_uv` at every +`read_intra_block_mode_info` / `read_intra_frame_mode_info` site in `decodemv.c`). +Six sites read a `uv_mode` symbol in `decode.rs`: + +| site (before) | reader | alphabet chosen before | after | +|---|---|---|---| +| `read_intra_mode_rect` (was 5521) | key/rect strips | caller's `cfl` param (4 call sites pass `true` unconditionally) | `cfl && bw <= 32 && bh <= 32`, decided **in the reader** | +| `read_intra_mode` (was 8500) | `decode_block` square path | caller's `cfl` param | `cfl && side <= 32`, decided **in the reader** | +| `decode_block_rect64` (was 6203) | SB-level 64x32/32x64 strips | `bw.max(bh) <= 32` (already correct) | unchanged | +| `decode_leaf8` sub-8 (was 10360) | 4x4 leaves | always CFL (correct, 4x4 <= 32) | unchanged | +| `decode_inter_block` 8x8 leaf (was 20387) | 8x8 inter-frame leaf | always CFL (correct) | unchanged | +| `decode_inter_block` intra tail (18722) | intra-in-inter | `write_w.max(write_h) <= 32` (r2's fix) | unchanged | + +Root-cause shape: the decision moved from six call sites to the two readers every +caller routes through, so a future 64/128-sized caller cannot get it wrong. +(Class `wrong-alphabet-same-value`: a 14- vs 13-symbol CDF gives the same VALUE and +a different range.) + +## (2) The INTRA-coded 128x128 block inside an inter frame + +Four distinct defects, all in `crates/ec-av1/src/decode.rs`: + +1. **Intra tail codes one whole-block chroma unit.** Now codes chroma per 64x64 mu + chunk inside the luma leaf loop -- `cu_tx = 32` (`av1_get_max_uv_txsize(BLOCK_128X128)` + = `av1_get_adjusted_tx_size(TX_64X64)` = TX_32X32), `txb_skip` offset-10 rows + (`Some(3)` on `txb_skip_chroma_32`), per-unit `record_mi_chroma` immediately so the + next chunk reads this one's context, `tu_reach` per unit. Mirrors the inter half + (`decode_inter_block`'s var-tx branch) exactly. Refusal string deleted from + `refusal_inventory.rs`. +2. **`read_block_tx_size` TX_MODE_LARGEST early return was `is_inter && side > 64`.** + An INTRA 128x128 block also resolves to `max_txsize_rect_lookup[BLOCK_128X128]` + = TX_64X64 = four units; it got one 128-wide unit that coded nothing. Now `side > 64`. +3. **`tx_size_context_txfm(n, at_mi, side)`.** `get_tx_size_context` compares the + neighbour txfm contexts against `tx_size_wide[max_txsize_rect_lookup[bsize]]`, + which is 64 for BLOCK_128X128 -- now `side.min(64)`. +4. **Two defects in the inter tile's 128 PARTITION_NONE root** (r1 code, never + exercised past superblock 0): + - `at128` is in SUB16 units like `sb_at`; `decode_inter_block` takes MI. Every 128 + root except the first entered at a quarter of its true position + (`TELL ... mi_col=8` where the trace said `partition_w128` at mi col 32). + Now `sub16_to_mi(at128)`. + - the `inter_piece!` macro hardcoded `reject_residual = true`, so the SQUARE 128 + root refused at its first non-skip block with the rect-strip refusal string + (class `refusal-from-own-desync` inverted: a refusal naming a shape the encoder + never wrote, produced by our own wiring). Now `$ww != $side || $wh != $side`. + +### Gate + +`a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` -- `#[ignore]` REMOVED, +recipe `--min-partition-size=32` -> `64` (measured: at 32, the 10-bit arm stops on +"an inter SB-level AB partition" and the tx-search arm on "an inter 16x16-level AB or +1:4 partition", both other lanes' gaps; 10 seeds x 2 arms, 0/20 clean. At 64, 3/3 +arms clean). New hard assert `intra128_total >= 1` on the new +`decode::intra_128_in_inter_hits()` counter. + +RESULT: **FAILED** -- +`sb128c-inter-none-8-false: decode-order frame 4 of 9 (8 shown, 1 hidden) differs +from the oracle at byte 2367 (ours 125 vs 126), 372 bytes differ`. + +Plane/bbox map of the residue (display order, ours vs `aomdec --rawvideo`, same +recipe, seed 61 8-bit): + +``` +frame 2 Y: 98 px rows 9..250 cols 58..66 <-- earliest, and the tell +frame 2 U: 151 px rows 0..126 cols 1..61 +frame 2 V: 123 px rows 0..126 cols 0..35 +frame 4 Y: 16932 px (whole frame; error propagates through prediction) +``` + +Frame 2 luma is a 9-px-wide band centred on **x = 64**, spanning nearly the whole +frame height -- the 14-tap deblock footprint of the 128 root's INTERNAL TX_64X64 +edge. The entropy stream stays in sync for all 9 frames (no refusal, no desync), +so this is the loop filter / lf grid for the 128 block, not a symbol defect. +Next step for r4: `EC_AV1_PREFILT_DUMP` on frame 2 -- if pre-filter is exact, it is +`fill_lf_grid_rect`'s tx/skip publication for the 128 root (the block-level call +writes `write_w = 128` as the tx dimension before the per-leaf loop overwrites 64, +and the chroma side reads `tx/2`, but a 128 block's chroma really is four TX_32X32). + +## (3) 128-level HORZ/VERT + AB -- NOT STARTED + +deferred: 128-level HORZ/VERT/AB on key and inter paths -- r3's budget went to (1) +and (2) and the four defects (2) uncovered -- unblocked by nothing; it is the next +lane round. This is now the FRONTIER for his 10-bit AV1 film: both `reelc2s.obu` and +`$HOME/.cache/reelc-head.obu` stop at +`a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at +the 128 root)` (was the same string before this round; 1 `EC_AV1_FINAL_DUMP` frame +each). + +## EVIDENCE + +``` +EVIDENCE: $HOME/.cache/sb128c-work/{arm-8-0,arm-10-0,arm-8-1}.obu | decode_probe on the r2 tip recipe (--min-partition-size=32) | 3/3 REFUSED before, then 1/3 (the two others on other lanes' AB refusals) +EVIDENCE: $HOME/.cache/sb128c-work/g-61-{8,10}-0.obu, g-62-8-1.obu | decode_probe, --min-partition-size=64 | 3/3 decode all 9 frames, 0 REFUSED +EVIDENCE: $HOME/.cache/sb128c-work/{o,m}.yuv | aomdec --rawvideo vs EC_PROBE_OUT on g-61-8-0.obu, per-plane bbox diff | earliest defect display frame 2, luma 98 px in cols 58..66 (x=64 edge), rows 9..250 +EVIDENCE: cargo test -p ec-av1 --lib -- a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact | single gate run | FAILED, decode-order frame 4 of 9, 372 bytes differ +EVIDENCE: $HOME/.cache/reelc-head.obu, $HOME/.cache/sb128c-work/reelc2s.obu | decode_probe with EC_AV1_FINAL_DUMP | both stop at "a 128x128 superblock HORZ/VERT or AB partition", 1 dumped frame each +``` + +## Suite + +`$HOME/.cache/sb128c-suite-r3.log` (unit `sb128c-suite-r3-1788327685.service`) -- +totals appended below by whoever reads it; the gate above is a KNOWN RED. diff --git a/lanes/sb128c-r4.handoff.md b/lanes/sb128c-r4.handoff.md new file mode 100644 index 00000000..53f71fd7 --- /dev/null +++ b/lanes/sb128c-r4.handoff.md @@ -0,0 +1,129 @@ +# lane-sb128c r4 -> r5 handoff + +Tip `lane-sb128c` (worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). Detail: `lanes/sb128c-r4.report.md` +(written before the uv-cap correction below -- this file supersedes its fix description). + +## (0) r3 suite result line + +`sb128c-suite-r3-1788327685.service`, `$HOME/.cache/sb128c-suite-r3.log`: +`test result: FAILED. 371 passed; 1 failed; 32 ignored; 0 measured; 0 filtered out; finished in 797.36s` +The single failure was r3's own known-RED gate. + +## (1) The x=64 deblock band -- ROOT CAUSE, FIXED + +Stage bisection (aomdec rungs, decode order) on `$HOME/.cache/sb128c-work/g-61-8-0.obu`: +decode-order frames 0..4 pre-filter EXACT, frame 4 post-deblock WRONG (98 luma px +in a 9-px band at x=64, 274 chroma) => loop filter, not a symbol. Decisive: +aomdec's own post-deblock dump changes ZERO pixels in luma cols 50..78 of that +frame; ours changed 98 (peak 26 at col 63). libaom filters that edge not at all. + +libaom `av1/common/av1_loopfilter.c`, `set_one_param_for_line_luma` (~line 690) +and `set_one_param_for_line_chroma`: +```c +const int32_t pu_edge = mi_prev != mbmi; +if (!pu_edge) curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi); +if ((pu_edge || !curr_skipped) && level) { params->filter_length = ...; } +``` +`get_transform_size` still reports TX_64X64 (luma) / TX_32X32 (chroma) for a +SKIP 128x128 INTER block, so the TU edge at x=64 / y=64 exists -- it is +suppressed because it is not a PU edge and the block is skipped. Every 128 +block in the gate stream is `is_inter=1 skip=1`. + +GRID WRITE (`crates/ec-av1/src/decode.rs`), final shape: +- the per-leaf `fill_lf_grid_rect` loop in `decode_inter_block` is gated on + `!(skip && is_inter)`, so the block-level publication (`write_w = 128`) stays + and no internal LUMA edge exists. The 128 root is the only block reaching + that loop skipped (`read_block_tx_size` returns four TX_64X64 leaves for + `side > 64` regardless of `skip`; every `side <= 64` skip inter block gets `None`). +- new `Neighbours::suppress_internal_lf_edges(at_mi, w_mi, h_mi)` writes the + UNCAPPED chroma extent (64 for a 128 block) into `uv_tx_grid`/`uv_tx_h_grid`, + called ONLY from the `skip && is_inter` branch of `decode_inter_block`. +- `dump_stage` now indexes its file per decode-order picture + (`EC_AV1_POSTDEBLOCK_DUMP` overwrote `.f0` every frame, so only the last + picture was comparable against aomdec's indexed rung). This is the instrument + that found the defect. + +## (1b) THE UV-CAP TRAP (cost one suite run; do not repeat) + +My first fix instead removed the `.min(32)` TX_32X32 cap inside +`fill_lf_grid_rect` outright, reasoning it was inert for every block up to 64 +wide. It is inert only for the INTER path. libaom's `curr_skipped` term +contains `is_inter_block(mbmi)`, so an INTRA 128x128 block's internal chroma TU +edges (every 32 chroma px, `av1_get_max_uv_txsize(BLOCK_128X128) == TX_32X32`) +ARE filtered. Removing the cap broke the sibling gate +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` +(caught mid-suite at 293/404). The cap is restored; suppression is now explicit +and inter-only. Both gates re-run together after the correction: +`key_frame_with_a_128x128_none_partition ... ok`, inter gate now fails one +frame LATER (see below). Class: `fix-trades-sibling-gate`. + +## (1c) cdef_idx per 64x64 quadrant -- the r4 charter's suspicion is WRONG + +`read_cdef` (`av1/decoder/decodemv.c`) reads at most ONE literal per CALL and is +called once per BLOCK. A `PARTITION_NONE` 128 root is one block, so exactly ONE +`cdef_idx` symbol is read (`index = cdef_unit_col_in_sb + 2*cdef_unit_row_in_sb` += 0 at the SB origin) and stored in the block's own `MB_MODE_INFO`, which all +four 64x64 CDEF units point at. r1's "replicated over 4 quadrants" is CORRECT; +no change was made. Four symbols are read only when the root SPLITs into four +non-skip 64s -- and for a 128-level HORZ/VERT root there are TWO blocks, hence +up to TWO literals: re-derive the index from that function, do not assume. + +## GATE STATES + +- `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` -- **GREEN** +- `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` -- **RED**, advanced + from `decode-order frame 4 of 9` (deblock) to `decode-order frame 5 of 9` + (reconstruction): `differs at byte 32264 (ours 140 vs 141), 24858 bytes differ`. +- Full suite r4: NOT COMPLETED -- I stopped `sb128c-suite-r4-1788328542.service` + at 293/404 to apply the uv-cap correction. It had exactly two failures, both + named above; the key-frame one is now fixed. r5 must run a fresh full suite. + +## EXACT NEXT STEP (r5's first job) + +Decode-order frame 5 of `$HOME/.cache/sb128c-work/g-61-8-0.obu` is wrong ALREADY +AT PRE-FILTER, and every reference it uses is now exact at every stage +(pre-filter, post-deblock and `EC_AV1_FINAL_DUMP` incl. the hidden frame, frames +0..4 all zero-diff). So this is a genuine reconstruction defect, not propagation. + +``` +frame 5 pre-filter Y: 19609 px, rows 128..255, cols 0..255, maxd 33, first bad (128,0) +frame 5 pre-filter C: 5207 px +per-64x64 quadrant Y: [0,0,0,0] [0,0,0,0] [3707,844,3137,3889] [183,177,3844,3828] +``` +The whole BOTTOM superblock row (both 128x128 SBs); rows 0..127 exact. Our mode +trace lists that row as two `side=128 is_inter=1 skip=1` blocks -- pure motion +compensation. Entropy stays in sync for all 9 frames (no refusal, no desync). +The quadrant diff is content-dependent (flat quadrants mostly match, detailed +ones do not) = a slightly wrong PREDICTOR, not a wrong write geometry. Frame 4's +own `(32,0)` 128 skip block is exact, so 128-wide MC itself works. +Suspects in order: the block's mv (mv-stack / GLOBALMV resolution), `ref_frame`, +`switchable_interp`, `motion_mode`/OBMC at 128x128. + +Reproduce: +``` +cd $HOME/.cache/sb128c-work && rm -f pf-o.f* pf-m.f* +systemd-run --user --scope -q -p MemoryMax=6G env EC_AV1_PREFILT_DUMP=$PWD/pf-o \ + ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null g-61-8-0.obu +systemd-run --user --scope -q -p MemoryMax=6G env EC_NOMEMGUARD=1 EC_AV1_PREFILT_DUMP=$PWD/pf-m \ + $HOME/.cache/cargo-target-sb128c/debug/examples/decode_probe g-61-8-0.obu +# 256x256 yuv420p8, pf-o.fN vs pf-m.fN +``` +Oracle rungs: `EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, +`EC_AV1_FINAL_DUMP` (all indexed, decode order, hidden frames included), +`EC_TRACE_MODE` (`EC_MODE_MV`/`EC_MODE_VAL` carry mode/ref0/ref1/mv0/stack/rng -- +only 62 lines on this stream and NONE in the failing bottom SB row, so a skip +block's mv needs `EC_PRED`/`EC_PREDOUT` or a new rung). +NOTE (ledger constraint): our `EC_AV1_POSTDEBLOCK_DUMP` site runs AFTER +`apply_cdef` on the inter path -- pair it with `EC_AV1_DEBUG_SKIP_CDEF=1` or a +CDEF defect reads as a deblock defect. + +## (3) 128-level HORZ/VERT + AB -- NOT STARTED + +deferred: 128x64 / 64x128 and AB at the 128 root, key and inter paths -- r4's +budget went to the stage bisection and the uv-cap correction; unblocked by +nothing. Both ReelC extracts (`$HOME/.cache/sb128c-work/reelc2s.obu` and +`$HOME/.cache/reelc-head.obu`, 1428 B, `use_128x128_superblock=true bit_depth=10`) +still stop at `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and +NONE are decoded at the 128 root)`, `EC_AV1_FINAL_DUMP` count 1 -- and that one +frame is BYTE-IDENTICAL to ffmpeg's `yuv420p10le` decode (4561920 B, `cmp` clean). diff --git a/lanes/sb128c-r4.report.md b/lanes/sb128c-r4.report.md new file mode 100644 index 00000000..6da0b849 --- /dev/null +++ b/lanes/sb128c-r4.report.md @@ -0,0 +1,132 @@ +# lane-sb128c r4 report + +Tip `lane-sb128c` @ `6226c27` (worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). + +## VERDICT: RED + +The r3 residue is CLOSED at its root cause (deblock), but the gate stream has a +SECOND, independent defect one decode-order frame later, in reconstruction. + +## (0) r3 suite result line + +`sb128c-suite-r3-1788327685.service`, `$HOME/.cache/sb128c-suite-r3.log`: +`test result: FAILED. 371 passed; 1 failed; 32 ignored; 0 measured; 0 filtered +out; finished in 797.36s`. The one failure is r3's own known-RED gate +`a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact`. + +## (1) The x=64 band -- ROOT CAUSE FOUND AND FIXED + +Method: stage bisection with the aomdec instrumentation rungs, decode order. + +| decode-order frame | pre-filter | post-deblock | final (CDEF+LR) | +|---|---|---|---| +| 0..3 | exact | exact | exact | +| 4 | **exact** | **98 Y px, 274 C** | 98 Y / 274 C | +| 5..8 | wrong | wrong | wrong | + +Pre-filter exact + post-deblock wrong on the SAME frame => the loop filter, not +a symbol. The decisive measurement: against `EC_AV1_PREFILT_DUMP`, aomdec's own +post-deblock dump changes **ZERO** pixels in luma columns 50..78 of that frame, +while ours changes 98 (peak 26 at column 63, footprint 58..66 = the 14-tap +vertical filter at x=64). libaom does not filter that edge at all. + +Why: libaom `av1_loopfilter.c:set_one_param_for_line_luma` (and `_chroma`) + +```c +const int32_t pu_edge = mi_prev != mbmi; +if (!pu_edge) curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi); +if ((pu_edge || !curr_skipped) && level) { params->filter_length = ...; } +``` + +`get_transform_size` still reports TX_64X64 for a SKIP 128x128 inter block, so +the transform-unit edge at x=64 exists -- it is simply suppressed because it is +not a prediction-unit edge and the block is skipped. Every 128 block in this +stream is `is_inter=1 skip=1`. + +Fix (`crates/ec-av1/src/decode.rs`, commit `6226c27`): +- the per-leaf `fill_lf_grid_rect` loop (the var-tx leaf publication, ~line + 19256) is gated on `!(skip && is_inter)`. The block-level publication of + `write_w = 128` stays, which IS the suppression. The 128 root is the only + block that reaches that loop skipped: `read_block_tx_size`'s + `TX_MODE_LARGEST` branch hands back four TX_64X64 leaves for `side > 64` + regardless of `skip`, while every `side <= 64` skip inter block gets `None`. +- `fill_lf_grid_rect`'s uv extent (~line 4186) drops its `.min(32)` cap. The + cap was INERT for every block up to 64 wide (`64/2 == 32`) and wrong for a + 128-sided one, where it published an internal chroma TU edge every 32 chroma + px. A non-skip 128 block still gets uv 32, through its own per-leaf calls + (`w_mi * MI == 64`). +- `dump_stage` now indexes its file per decode-order picture. It wrote a fixed + `.f0` every frame, so `EC_AV1_POSTDEBLOCK_DUMP` only ever held the LAST + picture and could not be compared against aomdec's indexed rung -- that is + the instrument this root cause needed. + +Result on `$HOME/.cache/sb128c-work/g-61-8-0.obu`: decode-order frames 0..4 are +now exact at pre-filter, post-deblock AND final (`EC_AV1_FINAL_DUMP`, hidden +frames included). Before the fix frame 4 was wrong at post-deblock. + +## (1b) CDEF for a 128 root -- the charter's suspicion is WRONG, verified + +`read_cdef` (`av1/decoder/decodemv.c`) reads at most one literal PER CALL, and +is called once per BLOCK. For a `PARTITION_NONE` 128 root there is exactly one +block in the superblock, so exactly ONE `cdef_idx` symbol is read +(`index = cdef_unit_col_in_sb + 2 * cdef_unit_row_in_sb` = 0), and it is stored +into the block's own `MB_MODE_INFO`, which every mi cell of all four 64x64 CDEF +units points at. r1's "replicated over 4 quadrants" is CORRECT; no change made. +(Four symbols are read only when the 128 root SPLITs into four non-skip 64s.) + +## (2) The NEW frontier: decode-order frame 5, reconstruction + +Every reference of frame 5 is now pixel-exact at every stage, and frame 5 is +already wrong at PRE-FILTER, so this is not filter propagation: + +``` +decode-order 5 pre-filter: Y 19609 px rows 128..255 cols 0..255 maxd 33 + C 5207 px +per-64x64-quadrant Y diff: [0,0,0,0] [0,0,0,0] [3707,844,3137,3889] [183,177,3844,3828] +first bad pixel: (128, 0) +``` + +The whole BOTTOM superblock row, both 128x128 superblocks, from its very first +pixel; rows 0..127 exact. Our own mode trace for that picture lists the bottom +row as two `side=128 is_inter=1 skip=1` blocks. A skipped inter block's +reconstruction is pure motion compensation, the entropy stream stays in sync +for all 9 frames, and the quadrant diff is content-dependent (flat quadrants +mostly match, detailed ones mostly do not) -- the signature of a slightly wrong +predictor, i.e. mv / reference / interp filter / OBMC, NOT of a wrong write +geometry. Frame 4's own `(32,0)` 128 skip block decodes exact, so 128-wide MC +per se works. + +fix-now for r5; it is the only thing between this gate and GREEN. + +## (3) 128-level HORZ/VERT + AB -- NOT STARTED + +deferred: 128-level HORZ/VERT (128x64, 64x128) and AB on key and inter paths -- +r4's budget went to (0)/(1) and the stage bisection that found the root cause; +unblocked by nothing, it is r5 work. It remains the FRONTIER for his 10-bit AV1 +film. + +## ReelC re-probe (unchanged, as expected -- (3) was not started) + +Both `$HOME/.cache/sb128c-work/reelc2s.obu` and `$HOME/.cache/reelc-head.obu` +(1428 bytes each, `use_128x128_superblock=true bit_depth=10`) stop at +`a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are +decoded at the 128 root)` with `EC_AV1_FINAL_DUMP` count **1**. That one frame +is **byte-identical** to ffmpeg's `yuv420p10le` decode of the same extract +(4561920 bytes, `cmp` clean). + +## EVIDENCE + +``` +EVIDENCE: $HOME/.cache/sb128c-work/{pf-o,pf-m}.f0..f8, {pd-o,pd-m}.f* | aomdec EC_AV1_PREFILT_DUMP/EC_AV1_POSTDEBLOCK_DUMP vs ours, per decode-order frame | decode-order 0-4 pre-filter exact; frame 4 post-deblock 98 Y + 274 C before the fix +EVIDENCE: $HOME/.cache/sb128c-work/pd-o.f4 vs pf-o.f4 | aomdec's own post-deblock minus pre-filter, luma cols 50..78 | 0 pixels changed by libaom; ours changed 98 (peak 26 at col 63) +EVIDENCE: $HOME/.cache/sb128c-work/{fo,fm}.f0..f8 | EC_AV1_FINAL_DUMP (post CDEF+LR, decode order, hidden frames included) after the fix | frames 0-4 exact, first divergence decode-order 5 +EVIDENCE: $HOME/.cache/sb128c-work/pf-m.f5 vs pf-o.f5 | per-64x64 quadrant diff map | rows 128..255 only, first bad pixel (128,0), maxd 33 +EVIDENCE: $HOME/.cache/sb128c-work/{td.f0,ff.yuv} | decode_probe EC_AV1_FINAL_DUMP vs ffmpeg -pix_fmt yuv420p10le on reelc2s.obu | cmp IDENTICAL, 4561920 bytes +EVIDENCE: $HOME/.cache/sb128c-suite-r3.log | full lib suite on the r3 tip | 371 passed; 1 failed; 32 ignored +``` + +## Suite + +`$HOME/.cache/sb128c-suite-r4.log` (unit `sb128c-suite-r4-1788328542.service`), +totals in the handoff. One KNOWN RED expected: the gate above. diff --git a/lanes/sb128c-r5.handoff.md b/lanes/sb128c-r5.handoff.md new file mode 100644 index 00000000..c284dcaf --- /dev/null +++ b/lanes/sb128c-r5.handoff.md @@ -0,0 +1,102 @@ +# lane-sb128c r5 -> r6 handoff + +Worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. +Work stream: `$HOME/.cache/sb128c-work/g-61-8-0.obu` (arm 1) and `a3.obu` (arm 3, +copied out of the gate's pinned `/tmp` dir -- keep it, /tmp is reaped). + +## (1) The r4 residue: THREE root causes, all fixed, arms 1+2 GREEN + +r4's "frame 5 pre-filter wrong, entropy in sync" premise was WRONG: the mode-value +ladder (`EC_TRACE_MODE`, values only -- our `EC_MODE_VAL` prints its `rng` at +libaom's `EC_MODE_MV` point, so RANGE is not comparable line-for-line) diverges at +mode-value line 43, `mi(32,0)`, a 128x128 NEWMV block: + +``` +oracle EC_MODE_VAL mi_row=32 mi_col=0 mode=16 ref0=1 mv0=(63,0) stack=1 +ours EC_MODE_VAL mi_row=32 mi_col=0 mode=16 ref0=1 mv0=(0,0) stack=2 +``` + +a) **mv stack: the top-right probe was never gated on `has_top_right`.** +`crates/ec-av1/src/mvstack.rs:882` (`find_mv_stack`) and `:1680` +(`find_mv_stack_compound`) called `scan_top_right{,_compound}` unconditionally. +libaom `setup_ref_mv_list` (mvref_common.c:497 + :546) computes +`has_tr = has_top_right(cm, xd, mi_row, mi_col, AOMMAX(width,height))` and only +then `scan_blk_mbmi(-1, xd->width)`. `has_top_right` returns 0 for `bs > 16`, so a +128x128 block has NO top-right candidate -- but the cell diagonally above-right of +`mi(32,0)` (= `mi(31,32)`, in the previous SB row) IS populated, so our grid probe +invented `(441,441) w=644` and the extra stack entry desynced the drl symbols. +The module's own `mvstack::has_top_right` port already existed and was correct; it +just was not wired into the mv-stack scan (only into the warp-sample gather). + +b) **`motion_mode`/`obmc` CDF row 4 for a 128x128 block.** +`decode.rs:17977` mapped square sizes with `w == h => (w.trailing_zeros() - 3)`, +which sends 128 to row 4 -- our packed `BLOCK_16X32` row. Wrong alphabet narrowing, +no wrong value (class `wrong-alphabet-same-value`). Added libaom +`default_motion_mode_cdf` / `default_obmc_cdf` rows 13/14/15 (BLOCK_64X128, +128X64, 128X128) as our packed indices 14/15/16 in `cdf.rs` (arrays 14 -> 17, +`cdf_state.rs` types too) and explicit `(64,128)/(128,64)/(128,128)` match arms +BEFORE the square arm. + +c) **A TX_64X64 luma unit of an INTRA-in-inter 128 block used the full 64x64 scan.** +`decode.rs:18995` passed `default_scan(tx_px)` and `tx_side = tx_px`; a TX_64X64 +codes only its top-left 32x32 (spec 5.11.40). Panicked +`transform.rs:828 assertion left==right: one coefficient per position, 1024 vs 4096` +on gate arm 2. Now `.min(32)` on both, matching every other 64-capable site +(`coeff_tx_side`, `default_scan(tx_px.min(32))` at :17429/:18494). + +EVIDENCE: `$HOME/.cache/sb128c-work/pf-{o,m}.f0..f8` | `EC_AV1_PREFILT_DUMP` on +aomdec oracle + `decode_probe`, g-61-8-0.obu | all 9 decode-order frames 0 bytes +differ (was 19550/14164/26667/26716 on f5..f8), mode-value ladder MODE_IDENTICAL. + +Gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact`: +- arm 1 (yuv420p, tx_search=0, seed 61): **9/9 frames exact**, `inter_sb128_none_hits=14 chroma_units=16 intra_128_in_inter=0` +- arm 2 (yuv420p10le, tx_search=0, seed 61): **9/9 frames exact**, `hits=29 chroma_units=28 intra_128_in_inter=1` +- arm 3 (yuv420p, tx_search=1, seed 62): **RED**, 7 bytes, see below. +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` and +`a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact` stay green. + +## (2) EXACT NEXT STEP: arm 3, a phantom CHROMA deblock edge (4 px), stage-bisected + +Stream `$HOME/.cache/sb128c-work/a3.obu` (909 B, 256x256 8-bit, 9 decode-order +frames). Mode ladder is IDENTICAL to the oracle -- no entropy defect. + +Stage bisection (oracle rungs `EC_AV1_PREFILT_DUMP` / `EC_AV1_POSTDEBLOCK_DUMP` / +`EC_AV1_FINAL_DUMP`; NOTE our POSTDEBLOCK dump indexes 0,2,4,... so oracle `fN` +pairs with ours `f2N`, and on THIS stream it really is pre-CDEF): +``` +pre-filter f0..f8 : 0 0 0 0 7 6 6 6 0 (f4+ is propagation) +post-deblock f3 : 4 px <-- the defect +final f3 : 7 px, f4..f7 6 px each +``` +The 4 post-deblock pixels are V-plane only: +`V(46,56) V(46,57) V(47,54) V(47,55)`, ours 170 vs oracle 167 -- two pairs +straddling a VERTICAL chroma edge at chroma x=56 (luma x=112), inside the +`mi(0,0)` `side=128 is_inter=1 skip=0` block of decode-order frame 3. + +Root cause (identified, NOT yet fixed): `decode.rs:19303`, the per-vartx-leaf +`fill_lf_grid_rect` loop in `decode_inter_block`, passes the LUMA leaf extent, and +`fill_lf_grid_rect` derives `uv_tx_w/h` from its own `w_mi/h_mi` (`decode.rs:4211`). +So a 16x16 luma leaf publishes a chroma TU extent of 8 and creates chroma edges +every 8 px -- e.g. at chroma 56. libaom takes a chroma plane's transform size from +`av1_get_max_uv_txsize(mbmi->bsize, ...)` (the BLOCK's, = TX_32X32 for a 128 root) +in `set_one_param_for_line_chroma`, never from the luma var-tx leaf. Fix shape: +leave the chroma half of the grid at the BLOCK's uv extent when writing per-leaf +(a leaf-only luma write, or an explicit uv re-publish after the loop, mirroring +r4's `suppress_internal_lf_edges`). Beware r4's trap: the block-level uv `.min(32)` +cap must stay (an INTRA 128 block's internal chroma edges ARE filtered). +Re-run the key-frame 128 sibling gate after touching this (class +`fix-trades-sibling-gate`). + +## (3) NOT STARTED + +deferred: 128-level HORZ/VERT + AB partitions (key and inter) -- r5's budget went +to the three r4-residue root causes; unblocked by nothing. Refusal +`refusal_inventory.rs:45` "a 128x128 superblock HORZ/VERT or AB partition (only +SPLIT and NONE are decoded at the 128 root)" is untouched. `cdf::MOTION_MODE`/ +`cdf::OBMC` now already carry the BLOCK_64X128 / BLOCK_128X64 rows that work needs. +deferred: full suite -- not run this round (r4's was also incomplete); r6 must run +`systemd-run --user --unit=sb128c-suite-$(date +%s) -p MemoryMax=10G --same-dir bash -lc '...'` +per COMMON, log to `$HOME/.cache/sb128c-suite-r6.log`. +deferred: ReelC re-probe -- not re-run; r4 measured both extracts still stopping at +the 128 HORZ/VERT/AB refusal with `EC_AV1_FINAL_DUMP` count 1, byte-identical to +ffmpeg. Nothing in r5 touches that stop string. diff --git a/lanes/sb128c-r6.handoff.md b/lanes/sb128c-r6.handoff.md new file mode 100644 index 00000000..490ebbb8 --- /dev/null +++ b/lanes/sb128c-r6.handoff.md @@ -0,0 +1,75 @@ +# lane-sb128c r6 -> r7 handoff: the 128-root HORZ/VERT/AB partition work + +Worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. +r6 merged main 727f29a + lane-golomb 173b793 and re-greened the five 128 gate arms; +it did NOT start the partition work. Everything below is measured this round. + +## The blocker on the 1080p AV1 film is ONE arm: the GATHERED bottom-edge HORZ + +`decode_probe` on four extracts of the 1080p 10-bit AV1 film (2 s each, `-c:v copy`) +all stop at `a 128x128 superblock HORZ/VERT or AB partition`, and +`EC_AV1_TRACE=1 | grep partition_w128` shows values **0 and 3 only** right up to the +stop -- i.e. the refusing partition never came from the full-alphabet symbol (which +traces every value) but from `read_sb128_root`'s GATHERED branch (`decode.rs:13317`, +no trace line): frame height 1080 gives `mi_rows = 270`, so the bottom 128 row has +`mi_r128 = 256`, `256 + SB_MI(16) = 272 > 270` -> `has_rows128 == false`, one gathered +bit, and the film codes it as `PARTITION_HORZ` (a 128x64 block whose bottom 8 luma rows +are the only ones in frame). Frame width 1920 = 15*128 exactly, so `has_cols128` is +always true and the VERT gathered arm is unreachable on this film. +=> r7's minimum for the film is the **128x64 block** (key + inter), not the whole set. + +## What aomenc actually emits (measured, 90 streams) + +- Sweep A, 72 streams (`sweep.sh`: seeds 41/42/43/61/62/71 x 256x256,384x384 x cq + 40/55/63 x 8+10-bit, `--sb-size=128 --cpu-used=0 --min-partition-size=64 + --enable-rect-partitions=1 --enable-ab-partitions=1`): partition_w128 takes ONLY + value 0 (NONE) and 3 (SPLIT). No HORZ, no VERT, no AB, at any setting. +- Sweep B, 18 streams (`sweep2.sh`, 512x512 synthetic sources designed to favour the + arms): horizontal-stripe and vertical-stripe sources still give NONE only; the + **AB-shaped** source (`geq` = top 64 rows of every 128 uniform, bottom split into two + 64x64 levels) gives `value=1` (**PARTITION_HORZ at the 128 root**) at every cq + (32/50/63) and both `--min-partition-size` 64 and 16. + Reproduce: `nullsrc=s=512x512:d=0.32:r=25,geq=lum='if(lt(mod(Y\,128)\,64),200,if(lt(mod(X\,128)\,64),40,120))':cb=128:cr=128,noise=all_seed=7:alls=3:allf=t` + Streams kept at `$HOME/.cache/sb128c-work/s2-abshape-*.obu` (decode stops at the + 5th 128 root of the KEY frame). +- Whether VERT / the four AB values (4..7) are reachable is still UNKNOWN: our decoder + stops at the first refusing root, so nothing past it is observable. Re-run both + sweeps once HORZ decodes -- only then is "aomenc never picks arm X" a measured claim + (class `refusal-lifted-without-a-gate`: keep the unreached arms refused BY NAME). + +## Shape of the 128x64 / 64x128 block (spec + libaom, for r7) + +- luma: `max_txsize_rect_lookup[BLOCK_128X64] = TX_64X64` -> two TX_64X64 units, each + coding only its top-left 32x32 (`default_scan(tx_px.min(32))`, already the convention + at decode.rs:17540/:18670). +- chroma: `av1_get_max_uv_txsize(BLOCK_128X64) = TX_32X32` over a 64x32 uv block -> two + units per plane, uv block > uv tx, so the txb_skip CDF takes the offset-10 rows. +- coding order: two 64x64 mu chunks (`decode_token_recon_block`), Y then U then V per + chunk -- the existing `side > 64` chunk loop in `decode_inter_block` (decode.rs:17568) + already does this for four chunks; it keys the chunk on `(row/16, col/16)`. +- `motion_mode`/`obmc` rows BLOCK_64X128 (14) / BLOCK_128X64 (15) are already in + `cdf.rs` (added r5, packed indices 14/15/16 with 128X128). +- `has_top_right`: `mvstack::has_top_right` returns 0 for `bs0 = max(bw4,bh4) > 16`, so + both 128x64 and 64x128 have no top-right candidate; the probe is now gated + (mvstack.rs:882/:1680), nothing more to do there. +- lf grid: per-unit write with the skip-inter suppression, luma-only leaf write + (`fill_lf_grid_leaf_luma`, from lane-golomb) -- both already merged in r6. +- one `cdef_idx` literal per block, copied to every 64x64 CDEF unit the block covers + (the pattern at decode.rs:13606 / :21744). +- palette (>64), CfL (>32) and filter intra are all size-refused already. +- AB visit order (libaom `decode_partition`): VERT_A = 64x64 TL, 64x64 BL, 64x128 right; + VERT_B = 64x128 left, 64x64 TR, 64x64 BR; HORZ_A = 64x64 TL, 64x64 TR, 128x64 bottom; + HORZ_B = 128x64 top, 64x64 BL, 64x64 BR. + +## Entry points to touch + +- `read_sb128_root` decode.rs:13277 (the refusal at :13345, both branches). +- key-frame tile: decode.rs:13554 (`part128 == PARTITION_NONE` arm; the 128 NONE block + goes through `decode_block(..., SB * 2, ...)`; a 128x64 needs the rect analogue -- + `decode_block_rect64` (decode.rs:8061) is the 64x32/32x64 one and is corner-cropped + for a 32x32 real transform, so it does NOT generalise as-is). +- inter tile: decode.rs:21642 + the `inter_piece!` macro at :21683 -- there a 128x64 is + plausibly `inter_piece!(mi, SB * 2, ..., ww = SB * 2, wh = SB)` because + `decode_inter_block` is already (write_w, write_h)-general; try the inter arm FIRST, + it is much cheaper than the key one. +- `refusal_inventory.rs:46` + `gate_coverage.rs` in the same commit as the gate. diff --git a/lanes/sb128c-r6.report.md b/lanes/sb128c-r6.report.md new file mode 100644 index 00000000..05a402e2 --- /dev/null +++ b/lanes/sb128c-r6.report.md @@ -0,0 +1,121 @@ +# lane-sb128c r6 report + +Branch `lane-sb128c`, worktree `edith_codecs-sb128c`. +Tip `cf0bd84` (merges: `363ab1e` main 727f29a, `5230f4c` lane-golomb 173b793). + +## Verdict: GREEN on the merge + the five 128 arms; the partition work is NOT started (see below) + +## (1) Merge (charter step 1) -- done, and it found a real regression + +`git merge --no-commit main` (main tip 727f29a, which does NOT contain lane-golomb), +then `git merge --no-commit 173b793` directly, as chartered. + +Resolutions (all in `crates/ec-av1/src/decode.rs`): +- var-tx leaves are main's general `(row, col, tw, th)`; the lane's 128-root mu-chunk + chroma interleave (`side > 64`, one 32x32 uv unit per 64x64 chunk) is kept, appended + after main's `record_mi_luma_rect` (:17540 and :18670, both leaf loops). +- `default_scan(tx_px.min(32))` kept over main's `default_scan(tx_px)` -- a TX_64X64 + codes only its top-left 32x32 (r5 root cause c). +- the per-vartx-leaf lf grid write is golomb's LUMA-ONLY `fill_lf_grid_leaf_luma` + (:19477), called with `(tw, th)`; this is exactly the r5 arm-3 defect (a 16x16 luma + leaf was publishing a chroma TU extent of 8 and inventing a chroma edge at chroma + x=56), so arm 3 needed no new code of mine. +- the lane's skip-inter `suppress_internal_lf_edges` is kept, narrowed to the 128 root. +- leaf ceiling is per root: main's TX_32X32 refusal below 128, TX_64X64 at the 128 root. +- `cdf.rs` diff vs 173b793 is ONLY the lane's own three rows in `MOTION_MODE`/`OBMC` + (BLOCK_64X128 / 128X64 / 128X128), 18 changed lines vs main; no hand-resolution. + +REGRESSION FOUND AND FIXED (class `fix-trades-sibling-gate`): r5's mv-stack change wired +libaom's WHOLE `has_top_right`, position mask included, without its three shape +refinements (`is_last_vertical_rect`, `is_first_horizontal_rect`, the `PARTITION_VERT_A` +bottom-left square) that `mvstack::has_top_right`'s own doc calls a corner-cut. Correct +at 128 (`bs > 64` -> no candidate) and WRONG below it once main decodes rect/AB inter +leaves: `a_real_aomenc_stream_with_ab_partitions`, `..._with_free_partitions` and +`real_aomenc_1to4_streams...` all lost frame 16 luma (seed 48), and the +`all_same_mv_neighbourhood_dedupes_to_one_entry` unit test lost the corner weight +(648 vs 652). Now gated on the size half only (`mvstack::top_right_scan_allowed`, +`bw4.max(bh4) <= 16`), with the ceiling and upgrade path named at the helper. + +EVIDENCE: $HOME/.cache/sb128c-gate-r6e.log | cargo test -p ec-av1 --lib -- ab_partitions +free_partitions real_aomenc_1to4_streams inter_128x128_none_root +key_frame_with_a_128x128_none_partition a_real_aomenc_128x128_superblock_stream +all_same_mv_neighbourhood | test result: ok. 9 passed; 0 failed + +The five 128 arms the charter asks for, from $HOME/.cache/sb128c-gate-r6a.log (all green +already at the merge commit, i.e. arm 3 was fixed by the golomb merge): +- inter 128 NONE arm 1 (yuv420p, tx_search=0, seed 61): 9/9 decode-order frames exact, + `inter_sb128_none_hits=14 chroma_units=16 intra_128_in_inter=0` +- arm 2 (yuv420p10le, tx_search=0, seed 61): 9/9 exact, `hits=29 chroma_units=28 + intra_128_in_inter=1` +- arm 3 (yuv420p, tx_search=1, seed 62): 9/9 exact, `hits=15 chroma_units=24` -- was RED + (7 bytes, a phantom chroma deblock edge) at r5. +- `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact`: ok +- `a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact`: ok + +## (2) 128-level HORZ/VERT + AB partitions -- NOT STARTED, but scoped by measurement + +deferred: the whole of charter step 2 -- fix-now for r7, unblocked by nothing; the round's +budget went to the merge, the has_top_right regression and the measurements below. +`refusal_inventory.rs:45` is untouched, no refusal lifted this round. + +What r6 measured instead (this is what r7 should build against, full detail in +`lanes/sb128c-r6.handoff.md`): +- 72 aomenc streams (6 seeds x 256x256/384x384 x cq 40/55/63 x 8+10-bit, `--sb-size=128 + --cpu-used=0 --min-partition-size=64 --enable-rect-partitions=1 --enable-ab-partitions=1`): + the 128-root partition symbol is ONLY 0 (NONE) or 3 (SPLIT). aomenc picks no 128-level + HORZ/VERT/AB on that recipe at all -- a gate built on it would be vacuous. +- 18 further streams with sources designed for the arms (512x512): an AB-shaped source + DOES produce `value=1` = PARTITION_HORZ at the 128 root, at cq 32/50/63 and both + min-partition-size 64 and 16. Recipe + kept streams in the handoff. +- Whether VERT / the four AB values are reachable stays UNKNOWN: our decoder stops at the + first refusing root, so nothing past it is observable. Any "aomenc never picks it" + claim needs a re-sweep AFTER HORZ decodes. + +EVIDENCE: $HOME/.cache/sb128c-work/sweep.out + sweep2 stdout | 90 aomenc encodes decoded +with EC_AV1_TRACE=1 | partition_w128 value histogram: {0,3} in all 72 sweep-A streams, +{0,1} in the 6 abshape streams + +## (3) Full suite + +`cargo test -p ec-av1 --lib` (systemd unit, MemoryMax=10G) at the merge commit: +**381 passed / 4 failed / 35 ignored** -- the four failures are the has_top_right +regression described above. Re-run at tip cf0bd84: **385 passed / 0 failed / 35 ignored** +(1125.89 s), log `$HOME/.cache/sb128c-suite-r6.log`. + +EVIDENCE: $HOME/.cache/sb128c-suite-r6.log | systemd-run --user --unit=sb128c-suite2-... +-p MemoryMax=10G cargo test -p ec-av1 --lib -j3 | test result: ok. 385 passed; 0 failed; +35 ignored + +## (4) Film re-probe (1080p 10-bit AV1, four extracts) + +| stream | bytes | stop string | FINAL_DUMP frames | +|---|---|---|---| +| `sb128c-work/reelc2s.obu` | 1428 | 128x128 superblock HORZ/VERT or AB partition | 1 | +| `~/.cache/reelc-head.obu` | 1428 | same | 1 | +| `sb128c-work/reelc-8100.obu` (`-ss 8100 -t 2`) | 326696 | same | 0 | +| `sb128c-work/reelc-9000.obu` (`-ss 9000 -t 2`) | 1287780 | same | 0 | + +The one shown frame the head extract does decode is byte-identical to ffmpeg's 10-bit +output. No film grain on this title. + +NEW, decisive for r7: on all four extracts `EC_AV1_TRACE=1 | grep partition_w128` shows +values 0 and 3 ONLY right up to the stop. The full-alphabet symbol traces every value it +reads, so the refusing partition came from `read_sb128_root`'s GATHERED branch +(decode.rs:13317, untraced): 1080 luma rows -> `mi_rows = 270`, the bottom 128 row has +`mi_r128 = 256`, `256 + 16 > 270`, one gathered bit, and the film codes it +`PARTITION_HORZ` -- a 128x64 block at the frame's bottom edge. Width 1920 = 15*128 +exactly, so the VERT gathered arm is unreachable on this title. The film's minimum ask is +therefore the 128x64 block, not the whole 128-level partition set. + +EVIDENCE: $HOME/.cache/sb128c-work/fd/o.f0 vs reelc-ff.yuv | EC_AV1_FINAL_DUMP decode of +reelc2s.obu + `ffmpeg -pix_fmt yuv420p10le -frames:v 1` | cmp: identical, 4561920 B + +## Open residue + +- fix-now (r7): 128-level HORZ (128x64) on the key and inter paths, gated on the abshape + recipe; then re-sweep for VERT/AB and keep the unreached arms refused BY NAME. +- accepted: `top_right_scan_allowed`'s corner-cut (mask half unported) -- identical to + main's behaviour below 128, ceiling named in the doc comment. +- deferred: the three `has_top_right` shape refinements -- unblocked by nothing, but only + observable once a gate exercises a rect/AB inter leaf whose top-right differs; none of + the 416 lib tests does today. diff --git a/lanes/sb128c-r7.report.md b/lanes/sb128c-r7.report.md new file mode 100644 index 00000000..2d43421e --- /dev/null +++ b/lanes/sb128c-r7.report.md @@ -0,0 +1,99 @@ +# lane-sb128c r7 report -- the 128 root's gathered frame-edge HORZ/VERT arm + +Branch `lane-sb128c`, worktree `edith_codecs-sb128c`, +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. +Commits this round: `d10a641` (the interrupted r7 builder's partial, committed as +wip), `52e4458` (feature + gate), `5bd4556` (inventory). + +## What changed + +- `crates/ec-av1/src/decode.rs:13446` `read_sb128_root`: HORZ/VERT are no longer + refused there; they are counted (`PART128_HORZ_HITS`, `PART128_VERT_HITS`, and + the gathered-edge pair `PART128_EDGE_HORZ_HITS`/`PART128_EDGE_VERT_HITS`) and + only the four AB shapes still refuse, by their own name. +- `crates/ec-av1/src/decode.rs:21881` inter tile path: a 128 root that resolves + to HORZ/VERT decodes two `inter_piece!` blocks of 128x64 / 64x128 (the second + skipped when its origin is outside the frame, libaom `decode_partition`'s + `if (mi_row + hbs < mi_rows)`), then fans one `cdef_idx` out over the 64x64 + CDEF units the block covers. +- `crates/ec-av1/src/decode.rs:12029` `read_block_tx_size_rect`: `bw.max(bh) > 64` + reads TWO square TX_64X64 top-level units (libaom `read_block_tx_size`'s + `idy/idx` loop), each with its own `txfm_partition` symbol at depth 0. +- `crates/ec-av1/src/decode.rs:11897` `rect_inter_residual_supported`: (128,64) + and (64,128) admitted. +- `crates/ec-av1/src/decode.rs:18008` / `:19109`: the `side > 64` mu-chunk chroma + branch now precedes the `rect_tu` one -- at the 128 root a rect block's chroma + is per mu chunk, not one unit for the block. +- `crates/ec-av1/src/decode.rs:16891`: the `whole_sb` test that gates delta-q / + delta-lf reads is against `sb_mi_cur() * 4`, not a hardcoded 64. +- `crates/ec-av1/src/decode.rs:3948` `Neighbours::new`: the per-mi side arrays are + padded to a superblock multiple. ROOT CAUSE of two index-out-of-bounds panics + (`decode.rs:5018`, `:4537`, len 200 index 200) on the 1080p film: a 128x64 at + the bottom edge records neighbour state for its whole 64-row extent, past the + frame's last mi row -- libaom's own context buffers are `MAX_MIB_SIZE`-aligned + for exactly that reason. The two `get_mut` guards in `record_mi_rect` are the + belt; the padding is the fix. +- `crates/ec-av1/src/decode.rs:13700` key-frame path: HORZ/VERT at the 128 root + now REFUSE by name. Before this round they fell through into the four-quadrant + SPLIT visit and silently decoded wrong pixels (the first version of the gate + caught it as a frame-0 mismatch on a `gradients` source). +- `crates/ec-av1/src/stream.rs:18957` new gate; `:84` `sb128_rect_counters()`; + `crates/ec-av1/examples/decode_probe.rs:40` prints them. +- `crates/ec-av1/src/refusal_inventory.rs:46`: the old + "a 128x128 superblock HORZ/VERT or AB partition" line is REPLACED by + "a 128x128 superblock AB partition (HORZ_A/HORZ_B/VERT_A/VERT_B at the 128 root)" + plus the new intra-frame one and the var-tx >64 leaf guard. + +## Gate (GREEN) + +`cargo test -p ec-av1 --lib gathered_edge_horz -- --nocapture` +(`a_real_aomenc_sb128_gathered_edge_horz_partition_decodes_pixel_exact`): +4 real `aomenc --sb-size=128 --cpu-used=0 --min-partition-size=64 +--enable-rect-partitions=1` streams, 5 frames each, every decode-order frame +(hidden alt-ref included) compared against the instrumented aomdec through +`decode_all_frames_vs_oracle`; hard asserts the gathered-edge counter and the +inter 128x64/64x128 block counter. + + seed 42 cq55 384x320 8bit HORZ: 6 frames pixel-exact (1 hidden), edge +2 inter_128rect +2 + seed 43 cq55 384x320 10bit HORZ: 6 frames pixel-exact (1 hidden), edge +24 inter_128rect +24 + seed 44 cq32 192x256 8bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter_128rect +2 + seed 45 cq45 192x256 10bit VERT: 6 frames pixel-exact (1 hidden), edge +2 inter_128rect +2 + test result: ok. 1 passed; 0 failed + +EVIDENCE: $HOME/.cache/sb128c-gate3-r7.log | cargo test -p ec-av1 --lib gathered_edge_horz --nocapture | 4/4 arms pixel-exact vs aomdec, edge counters +2/+24/+2/+2 + +## Film (1080p 10-bit AV1, 4 extracts) + +| extract | before r7 | after r7 | edge_horz | inter_128x64 | +|---|---|---|---|---| +| 2 s head (1920x792) | stopped: 128 HORZ/VERT/AB | **OK: 48/48 frames, 49/49 dumps bit-exact vs aomdec** | 720 | 720 | +| `~/.cache/reelc-head.obu` | stopped: 128 HORZ/VERT/AB | **OK: 48/48 frames, 49/49 dumps bit-exact** | 720 | 720 | +| `-ss 8100` 2 s | stopped: 128 HORZ/VERT/AB | stops at another lane: "a split intra strip whose transform unit is 32x64" | 1 | 0 | +| `-ss 9000` 2 s | stopped: 128 HORZ/VERT/AB | stops at another lane: "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding" | 12 | 0 | + +EVIDENCE: $HOME/.cache/sb128c-r7/d2 vs $HOME/.cache/sb128c-r7/o2 | EC_AV1_FINAL_DUMP on decode_probe head2s.obu and on aomdec head2s.obu, cmp per frame | frames=49 frames_differing=0 + +The 128-partition wall is gone from all four extracts; two of them now decode +their whole 2 s window bit-exact, the other two stop at OTHER lanes' refusals. + +## Suite + +`cargo test -p ec-av1 --lib` (systemd unit, MemoryMax=10G): +**386 passed; 0 failed; 35 ignored** in 1133 s -- `$HOME/.cache/sb128c-suite-r7.log`. + +## Residue + +- deferred: the INTRA (key-frame) 128x64/64x128 block -- refused by name, was a + silent wrong decode before this round. Unblocked by a rect-capable + `decode_block` at 128 (`decode_block_rect64` is corner-cropped for a 32x32 + transform and does not generalise). A smooth `gradients` source at + `--min-partition-size=64` reaches it in one encode, so a gate is one recipe away. +- deferred: the four AB shapes at the 128 root (HORZ_A/HORZ_B/VERT_A/VERT_B), + still refused by name. Unblocked by the intra rect block above plus the + libaom visit order recorded in `lanes/sb128c-r6.handoff.md`. Whether aomenc + ever picks them is still unmeasured -- our decoder used to stop at the first + refusing root, so the r6 sweeps could not observe past it; the 512x512 + abshape source now decodes further and the sweep can be re-run. +- accepted: `PART128_HORZ_HITS`/`PART128_VERT_HITS` (the non-gathered, + full-alphabet arms) are counted but were 0 in every stream measured this + round; the gate asserts the gathered pair only.