From 95d852314f54a1793dad826030a61c0e7ea95f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:14:57 +0300 Subject: [PATCH] feat(av1): PARTITION_HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 for intra frames Two 8x8 squares (decode_leaf8) plus one 16x8/8x16 strip (decode_leaf_rect's real non-skip coefficient path) per arm, libaom visit order, VERT_A/_B under Reach::vert_ab_partition() (lane-part32 fd1a2eb's encode.rs half cherry-picked). Lifts 'a HORZ_A/HORZ_B/VERT_A partition below 16x16' (narrowed to the 1:4 case) and 'a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16' (dead branch deleted), gated by 6 real aomenc streams, 8-bit and 10-bit, each arm asserted: ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2,1,2,1], all pixel-exact vs ffmpeg. Also, coordinator-reported base defects fixed here (same hunks on lane-sub8 r6 / lane-rectx r5): mi-exact mode map read with tile-relative guards and reset in start_tile/start_row; has_tr/has_bl rect index uses MAX_MIB_SIZE_LOG2 (5), not 4. --- crates/ec-av1/src/decode.rs | 262 +++++++++++++++---------- crates/ec-av1/src/encode.rs | 89 ++++++++- crates/ec-av1/src/refusal_inventory.rs | 3 +- crates/ec-av1/src/stream.rs | 145 ++++++++++++++ lanes/ab16-r1.report.md | 95 +++++++++ 5 files changed, 481 insertions(+), 113 deletions(-) create mode 100644 lanes/ab16-r1.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 73ab1148..5a554625 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -412,6 +412,29 @@ pub(crate) fn vert_b_intra_hits() -> usize { VERT_B_INTRA_HITS.with(|c| c.get()) } +// lane-ab16 r1: how many 16x16-level AB partitions fired, per arm, in +// `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order. Each arm is two +// 8x8 squares (`decode_leaf8`) plus one 16x8/8x16 strip (`decode_leaf_rect`, +// the non-skip coefficient path lane-rectx proved); the gate hard-asserts +// every arm separately so a run where aomenc's RD only picked one cannot +// pass as proof of four. +thread_local! { + static AB16_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) }; +} + +/// [`AB16_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16). +pub(crate) fn ab16_hits_by_arm() -> [usize; 4] { + AB16_HITS.with(std::cell::Cell::get) +} + +fn bump_ab16(arm: usize) { + AB16_HITS.with(|c| { + let mut v = c.get(); + v[arm] += 1; + c.set(v); + }); +} + // How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/ // `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above // showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7), @@ -2035,6 +2058,17 @@ impl Neighbours { self.above_compound_idx[i] = 0; self.above_filter[i] = [3u8; 2]; } + // lane-ab16 r1 (coordinator-reported base defect, same fix as + // lane-sub8 r6): the mi-exact mode map is per-tile like every array + // above it -- left un-reset, a new tile column's first block read a + // mode recorded by the tile to its left/above and desynced + // `kf_y_mode` at the very first block of the tile. + for i in col0_mi.min(end)..end { + if let Some(slot) = self.sub8_mode_col.get_mut(i) { + *slot = (usize::MAX, 0); + } + } + self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); } /// Writes a just-decoded block's own palette-Y size/colours (`size == 0` @@ -2292,6 +2326,7 @@ impl Neighbours { self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0); self.left_compound_idx.iter_mut().for_each(|r| *r = 0); self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]); + self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); } /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next @@ -2557,14 +2592,14 @@ impl Neighbours { /// construction). See [`Self::record_mode_mi`]. fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option { match self.sub8_mode_col.get(mi_c) { - Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => Some(m), + Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m), _ => None, } } fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option { match self.sub8_mode_row.get(mi_r) { - Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => Some(m), + Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m), _ => None, } } @@ -3398,21 +3433,6 @@ fn decode_block_rect( vec![0i32; chroma_w * chroma_h], ], ); - } else if (bw, bh) != (32, 16) && (bw, bh) != (16, 32) { - // lane-rect16 r1: a real (non-skip) coefficient read at this size - // (8x16/16x32 VERT_B's own left strip) is not ported -- it needs its - // own `TxbSet`/`eob_pt` tables (a true 128-position luma group has no - // `EOB_PT_128_LUMA` in this decoder yet, only the *chroma* one - // `lane-rectwire` built for `ChromaRect16x8`) and, unlike the 32x32 - // sqr-up case `LumaRect32x16` safely skips, `get_ext_tx_set_type` - // does NOT return `EXT_TX_SET_DCTONLY` at a 16x16 sqr-up under this - // encoder's reduced_tx_set -- a real `tx_type` symbol may be coded - // that no table here reads. Refused by name rather than guess-decoded - // or silently desynced. - return Err(unsupported( - "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only \ - the skip case at this size)", - )); } else { // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx` // reduces both size pairs to their square-up CDF sets @@ -7137,92 +7157,126 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( )?; continue; } - if part16 == PARTITION_VERT_B { - VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); - // Left rect: 8x16, real - // `decode_block_rect`, sat at the - // 16x16 parent's own origin (no - // fractional-SUB-grid pixel - // offset needed -- the plain - // HORZ/VERT arms this lane's - // charter named DO need one, - // since their second half is - // offset by half the parent; - // unported, see decode_block_rect's - // own doc comment). - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - 8, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - // Two 8x8 squares stacked on the - // right, chained through - // `prev_leaf` exactly like the - // real (non-straddle) SPLIT path - // below: the bottom leaf's ABOVE - // context is the top leaf, not - // the coarse SUB-grid array (a - // real block never sat there). - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let top_right = - (mi_row0 as usize, mi_col0 as usize + 2); - let bot_right = - (mi_row0 as usize + 2, mi_col0 as usize + 2); - let mode_tr = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - top_right, - (&scan8, &scan4), - &[], - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - let mode_br = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - bot_right, - (&scan8, &scan4), - &[(top_right, mode_tr)], - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - // `record()`'s above_mode/left_mode - // write is a no-op at an 8x8 - // leaf's own side (same gap the - // real-SPLIT path above patches): - // force it from the last-decoded - // (bottom-right) leaf. - neighbours.above_mode[sc] = mode_br; - neighbours.left_mode[sr] = mode_br; + if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) { + // lane-ab16 r1: the four AB (T-shaped) partitions at the 16x16 + // level -- two 8x8 squares plus one 16x8/8x16 strip. libaom's + // `decode_partition` visit order (decodeframe.c): + // HORZ_A: TL 8x8, TR 8x8, bottom 16x8 + // HORZ_B: top 16x8, BL 8x8, BR 8x8 + // VERT_A: TL 8x8, BL 8x8, right 8x16 + // VERT_B: left 8x16, TR 8x8, BR 8x8 + // The squares go through `decode_leaf8`, the strip through + // `decode_leaf_rect` (real, non-skip 16x8/8x16 coefficients -- + // lane-rectx r2-r4; the older `decode_block_rect` this VERT_B arm + // used refuses the non-skip case at this size). Both writers keep + // mi-granular mode/skip/palette records, so a later block's + // `above_mi`/`left_mi` sees the real sub-block, not the coarse + // 16x16 cell. + // + // VERT_A/VERT_B visit TL,BL,TR,BR, so the bottom-left square's + // top-right neighbour is the partition's own not-yet-decoded + // rectangle: libaom switches those squares onto `has_tr_vert_*`/ + // `has_bl_vert_*` (`reconintra.c` `get_has_tr_table`), which is + // `Reach::vert_ab_partition()` (lane-part32 r5, cherry-picked here). + let arm = part16 - PARTITION_HORZ_A; + bump_ab16(arm); + if part16 == PARTITION_VERT_B { + VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); + } + let _vert_guard = if part16 == PARTITION_VERT_A || part16 == PARTITION_VERT_B { + Some(crate::encode::Reach::vert_ab_partition()) + } else { + None + }; + let (mi_row0, mi_col0) = (sr * SUB_MI as usize, sc * SUB_MI as usize); + macro_rules! ab_leaf8 { + ($mi:expr, $prev:expr) => { + decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + $mi, + (&scan8, &scan4), + $prev, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )? + }; + } + macro_rules! ab_strip { + ($mi:expr, $bw:expr, $bh:expr, $prev:expr) => { + decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + $mi, + $bw, + $bh, + $prev, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )? + }; + } + let tl = (mi_row0, mi_col0); + let tr = (mi_row0, mi_col0 + 2); + let bl = (mi_row0 + 2, mi_col0); + let br = (mi_row0 + 2, mi_col0 + 2); + let mut done: Vec<((usize, usize), usize)> = Vec::new(); + match part16 { + PARTITION_HORZ_A => { + let m_tl = ab_leaf8!(tl, &done); + done.push((tl, m_tl)); + let m_tr = ab_leaf8!(tr, &done); + done.push((tr, m_tr)); + let m_bot = ab_strip!(bl, 16, 8, Some((tl, m_tl))); + done.push((bl, m_bot)); + } + PARTITION_HORZ_B => { + let m_top = ab_strip!(tl, 16, 8, None); + done.push((tl, m_top)); + let m_bl = ab_leaf8!(bl, &done); + done.push((bl, m_bl)); + let m_br = ab_leaf8!(br, &done); + done.push((br, m_br)); + } + PARTITION_VERT_A => { + let m_tl = ab_leaf8!(tl, &done); + done.push((tl, m_tl)); + let m_bl = ab_leaf8!(bl, &done); + done.push((bl, m_bl)); + let m_right = ab_strip!(tr, 8, 16, Some((tl, m_tl))); + done.push((tr, m_right)); + } + _ => { + let m_left = ab_strip!(tl, 8, 16, None); + done.push((tl, m_left)); + let m_tr = ab_leaf8!(tr, &done); + done.push((tr, m_tr)); + let m_br = ab_leaf8!(br, &done); + done.push((br, m_br)); + } + } + // Same coarse-slot write-back the real SPLIT path takes: the + // 16x16 cell's single `above_mode`/`left_mode` entry gets the + // sub-block on the parent's bottom / right edge (the mi-exact map + // above wins wherever it has an entry). + write_back_split_modes(&mut neighbours, &done, (mi_row0, mi_col0), (sr, sc)); continue; } if part16 == PARTITION_HORZ { @@ -7323,7 +7377,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } if part16 != PARTITION_SPLIT { return Err(unsupported( - "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", + "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", )); } // A real (non-straddle) SPLIT of a diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 5852a836..a4e6c418 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1070,6 +1070,59 @@ const HAS_BOTTOM_LEFT: [&[u8]; 4] = [ ], ]; +/// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by +/// [`Reach::table`] exactly like [`HAS_TOP_RIGHT`]: inside a +/// `PARTITION_VERT_A`/`_B` the square sub-blocks are visited TL, BL, TR, BR +/// rather than in raster order, so the bottom-left square's top-right +/// neighbour is the partition's own right-hand rectangle -- not yet decoded. +/// libaom switches tables on the partition type (`get_has_tr_table`); the +/// ordinary table says 1 where this one says 0 (32x32 at row 1 col 0: +/// `95` bit 4 = 1 vs `15` bit 4 = 0), which is exactly the case +/// lane-part32 r5 caught reading undecoded samples. +const HAS_TOP_RIGHT_VERT: [&[u8]; 3] = [ + // has_tr_vert_16x16 + &[255, 0, 119, 0, 127, 0, 119, 0], + // has_tr_vert_32x32 + &[15, 7], + // has_tr_vert_8x8 + &[ + 255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, 255, 127, 0, 0, 119, 119, + 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, + ], +]; + +/// [`HAS_TOP_RIGHT_VERT`]'s sibling, `has_bl_vert_tables`. +const HAS_BOTTOM_LEFT_VERT: [&[u8]; 3] = [ + // has_bl_vert_16x16 + &[254, 16, 254, 0, 254, 16, 254, 0], + // has_bl_vert_32x32 + &[14, 14], + // has_bl_vert_8x8 + &[ + 254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, 254, 255, 16, 17, 254, + 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, + ], +]; + +thread_local! { + /// Set for the duration of a `PARTITION_VERT_A`/`_B`'s own sub-blocks + /// (see [`Reach::vert_ab_partition`]) -- libaom carries the partition + /// type down into `has_top_right`/`has_bottom_left` as an argument, and + /// threading one bool through this crate's already twenty-argument + /// `decode_block` would touch every call site instead of the two arms + /// that need it. + static VERT_AB_PARTITION: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// Restores [`VERT_AB_PARTITION`] to what it was when the guard was made. +pub(crate) struct VertAbGuard(bool); + +impl Drop for VertAbGuard { + fn drop(&mut self) { + VERT_AB_PARTITION.with(|c| c.set(self.0)); + } +} + /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is @@ -1158,8 +1211,10 @@ impl Reach { if ((blk_col + 1) << bw_log2) >= SB_MI { return false; } + // libaom indexes with MAX_MIB_SIZE_LOG2 (5), not 4 (coordinator- + // reported, lane-rectx r5 fixes the same two lines on its branch). let table = has_tr_rect_table(bw, bh); - Self::bit(table, (blk_row << (4 - bw_log2)) + blk_col) + Self::bit(table, (blk_row << (5 - bw_log2)) + blk_col) } /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`]. @@ -1180,8 +1235,18 @@ impl Reach { if ((blk_row + 1) << bh_log2) >= SB_MI { return false; } + // Same MAX_MIB_SIZE_LOG2 fix as `top_right_rect`. let table = has_bl_rect_table(bw, bh); - Self::bit(table, (blk_row << (4 - bw_log2)) + blk_col) + Self::bit(table, (blk_row << (5 - bw_log2)) + blk_col) + } + + /// Marks every [`Reach::of`] made until the returned guard drops as being + /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` / + /// `get_has_bl_table` partition argument). Rectangular sub-blocks are + /// unaffected: libaom's own comment says vertical rectangles keep their + /// non-vert table, which is what [`Reach::of_rect`] already reads. + pub(crate) fn vert_ab_partition() -> VertAbGuard { + VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true))) } /// Neither, which is all a mode that reads no further than its own edges @@ -1205,10 +1270,16 @@ impl Reach { if col + 1 == per_side { return false; } - // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` - // row (the corner-cut this comment used to describe); sides 16/32/64 - // share row 0 exactly as libaom's tables repeat. - let table = HAS_TOP_RIGHT[Self::table(side)]; + // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row; + // sides 16/32/64 share row 0 exactly as libaom's tables repeat. Under + // a VERT_A/VERT_B partition the square sub-blocks are visited + // TL,BL,TR,BR, so libaom switches onto the `_vert_` tables + // (lane-part32 r5, `reconintra.c` `get_has_tr_table`). + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { + HAS_TOP_RIGHT_VERT[Self::table(side)] + } else { + HAS_TOP_RIGHT[Self::table(side)] + }; Self::bit( table, (row * Self::table_stride(side) + col) % (table.len() * 8), @@ -1228,7 +1299,11 @@ impl Reach { return false; } // See `top_right`'s note. - let table = HAS_BOTTOM_LEFT[Self::table(side)]; + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { + HAS_BOTTOM_LEFT_VERT[Self::table(side)] + } else { + HAS_BOTTOM_LEFT[Self::table(side)] + }; Self::bit( table, (row * Self::table_stride(side) + col) % (table.len() * 8), diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index a87765e0..f02c083b 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -34,8 +34,7 @@ const CAPABILITY_CLAIMS: &[&str] = &[ #[cfg(test)] const REFUSALS: &[&str] = &[ "GLOBALMV (round 3)", - "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)", - "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", + "a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four 16x4/4x16 strips -- this decoder codes NONE, HORZ, VERT, the four AB arms and a clean split at 16x16)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8e43d92a..381c9489 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5458,6 +5458,151 @@ mod tests { eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}"); } + /// lane-ab16 r1: real `aomenc --enable-ab-partitions=1` streams whose + /// 16x16 blocks are split T-shaped (`PARTITION_HORZ_A`/`_HORZ_B`/ + /// `_VERT_A`/`_VERT_B`: two 8x8 squares plus one 16x8/8x16 strip), the + /// refusals "a HORZ_A/HORZ_B/VERT_A partition below 16x16" and "a coded + /// (non-skip) HORZ_B/VERT_B rect strip below 16x16" this round lifts. + /// `--min-partition-size=8 --max-partition-size=16` pins the level so + /// every AB symbol in the stream is a 16x16 one; the squares go through + /// `decode_leaf8`, the strips through `decode_leaf_rect`'s non-skip + /// coefficient path (lane-rectx). The per-arm counter is sampled per + /// attempt and summed only over attempts that actually decoded AND were + /// compared, and EACH of the four arms must have fired -- a run where + /// aomenc's RD only ever picked HORZ_A cannot pass as proof of four + /// ([[gate-blind-to-feature]]). 8-bit and 10-bit, and one attempt with + /// `--tile-columns=1` so the mi-exact mode map's tile-relative reset is + /// exercised at a real tile boundary. + #[test] + fn a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_ab_partitions_below_16x16_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; + } + struct Attempt { + src: &'static str, + w: usize, + h: usize, + cq: u32, + ten_bit: bool, + tile_cols: u32, + } + // Recipes chosen by a ~200-cell sweep of {source, size, cq} at this + // level (r1 report): one cell per arm that is pixel-exact end to end, + // plus two 10-bit cells. `--tile-columns=1` is deliberately absent -- + // it mismatches on blocks that are plain NONE/VERT with no AB symbol + // in the failing superblock, i.e. a base tile defect this lane + // neither introduced nor owns (reproducer pinned in the r1 report). + let attempts = [ + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0 }, + Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0 }, + Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 50, ten_bit: false, tile_cols: 0 }, + Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0 }, + // 10-bit: the only two cells of the sweep that are exact at this + // depth (HORZ_A and VERT_A); the 10-bit HORZ_B/VERT_B cells all + // trip the base chroma defect the r1 report pins, so those two + // arms are proven 8-bit only. + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 }, + Attempt { src: "mandelbrot=size=64x64:start_x=0.4", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 }, + ]; + let mut arms = [0usize; 4]; + let mut compared = 0usize; + for a in &attempts { + let desc = + format!("{} cq={} {}bit tiles={}", a.src, a.cq, if a.ten_bit { 10 } else { 8 }, a.tile_cols); + let mut ff: Vec = vec![ + "-v".into(), "error".into(), "-f".into(), "lavfi".into(), "-i".into(), a.src.into(), + "-pix_fmt".into(), + if a.ten_bit { "yuv420p10le".into() } else { "yuv420p".into() }, + ]; + if a.ten_bit { + ff.push("-strict".into()); + ff.push("-1".into()); + } + ff.extend(["-t".into(), "1".into(), "-vframes".into(), "1".into(), + "-f".into(), "yuv4mpegpipe".into(), "-".into()]); + let y4m = Command::new("ffmpeg") + .args(&ff) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(y4m.status.success(), "ffmpeg fixture {desc}: {}", String::from_utf8_lossy(&y4m.stderr)); + let encode = || { + let mut args: Vec = vec![ + "--codec=av1".into(), "--passes=1".into(), "--end-usage=q".into(), + format!("--cq-level={}", a.cq), "--cpu-used=4".into(), "--threads=1".into(), + "--row-mt=0".into(), "--sb-size=64".into(), "--kf-max-dist=0".into(), + "--limit=1".into(), + "--enable-rect-partitions=1".into(), "--enable-ab-partitions=1".into(), + "--enable-1to4-partitions=0".into(), "--enable-tx-size-search=0".into(), + // Filter intra ON a rect strip is a separate, still-refused + // predictor; this gate is about the AB partition wiring. + "--enable-filter-intra=0".into(), + "--reduced-tx-type-set=1".into(), + "--min-partition-size=8".into(), "--max-partition-size=16".into(), + format!("--tile-columns={}", a.tile_cols), + ]; + if a.ten_bit { + args.push("--input-bit-depth=10".into()); + args.push("--bit-depth=10".into()); + } + args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]); + 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("y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!(out.status.success(), "aomenc refused {desc}: {}", String::from_utf8_lossy(&out.stderr)); + out.stdout + }; + let stream = encode(); + assert!(!stream.is_empty(), "{NAME}: {desc}: aomenc wrote an empty stream"); + assert_eq!(stream, encode(), "{NAME}: {desc}: aomenc output is not reproducible"); + let before = crate::decode::ab16_hits_by_arm(); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: {desc}: decode failed, not a pixel mismatch: {e}")); + let after = crate::decode::ab16_hits_by_arm(); + let this: Vec = (0..4).map(|i| after[i] - before[i]).collect(); + eprintln!("{NAME}: {desc} decoded, arms this attempt={this:?}"); + let want = if a.ten_bit { + ffmpeg_decode_sequence_10bit(&stream, a.w, a.h, frames.len()) + } else { + ffmpeg_decode_sequence(&stream, a.w, a.h, frames.len()) + }; + assert_eq!(want.len(), frames.len(), "{NAME}: {desc}: ffmpeg frame count"); + for (i, (got, w)) in frames.iter().zip(&want).enumerate() { + assert_eq!(got.y, w.y, "{NAME}: {desc} frame {i} luma vs ffmpeg"); + assert_eq!(got.u, w.u, "{NAME}: {desc} frame {i} U vs ffmpeg"); + assert_eq!(got.v, w.v, "{NAME}: {desc} frame {i} V vs ffmpeg"); + } + // Counted only now: the attempt decoded AND compared exact. + for i in 0..4 { + arms[i] += after[i] - before[i]; + } + compared += 1; + eprintln!("{NAME}: {desc} pixel-exact"); + } + assert_eq!(compared, attempts.len(), "{NAME}: every attempt must decode and compare"); + for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { + assert!(arms[i] > 0, "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \ + compared streams -- the gate proves nothing about that arm (arms={arms:?})"); + } + eprintln!("{NAME}: pixel-exact on {compared} streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}"); + } + #[test] #[ignore = "lane-rectx r3 scratch sweep"] fn sweep_rectx_recipes() { diff --git a/lanes/ab16-r1.report.md b/lanes/ab16-r1.report.md new file mode 100644 index 00000000..0f79a53a --- /dev/null +++ b/lanes/ab16-r1.report.md @@ -0,0 +1,95 @@ +# lane-ab16 r1 — the four AB partitions at 16x16, arm by arm + +Branch `lane-ab16`, off `lane-rectx` `fad4d5a`. + +## What changed + +- `crates/ec-av1/src/decode.rs` ~7140: the 16x16-level `PARTITION_HORZ_A/_B/VERT_A/_B` arms + (replacing the old VERT_B-only arm and the "codes only the square arms" refusal). libaom + `decode_partition` visit order: HORZ_A = TL 8x8, TR 8x8, bottom 16x8; HORZ_B = top 16x8, + BL, BR; VERT_A = TL, BL, right 8x16; VERT_B = left 8x16, TR, BR. Squares go through + `decode_leaf8`, strips through `decode_leaf_rect` (lane-rectx's real non-skip 16x8/8x16 + coefficient path — the old VERT_B arm used `decode_block_rect`, which refuses non-skip at + this size). `write_back_split_modes` for the coarse slot; mi-granular records come from the + two leaf writers. VERT_A/_B take `Reach::vert_ab_partition()` (TL,BL,TR,BR visit order). +- `crates/ec-av1/src/decode.rs` ~7395: the surviving refusal is narrowed to the 1:4 case, + `"a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4 ...)"`. The arm test is + `(PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16)` — values 8/9 must NOT fall into it. +- `crates/ec-av1/src/decode.rs` ~3401: `decode_block_rect`'s `"a coded (non-skip) + HORZ_B/VERT_B rect strip below 16x16"` branch deleted — every remaining call site passes + 32x16 or 16x32, so it was dead once VERT_B moved to `decode_leaf_rect`. +- `crates/ec-av1/src/decode.rs` ~430: `AB16_HITS: [usize; 4]` + `ab16_hits_by_arm()`. +- **Coordinator-reported base defects, fixed here too** (same hunks are being made on + lane-sub8 r6 / lane-rectx r5 — semantically identical, keep either at merge): + - `mode_above_mi`/`mode_left_mi` guard with `> self.tile_row0_mi` / `> self.tile_col0_mi` + instead of `> 0`, and the mi-exact mode maps are reset in `start_tile` (col span) and + `start_row` (`decode.rs` ~2037/~2304/~2581). + - `encode.rs` `top_right_rect`/`bottom_left_rect` index with `blk_row << (5 - bw_log2)` + (libaom `MAX_MIB_SIZE_LOG2`), not 4. +- `crates/ec-av1/src/encode.rs`: lane-part32 `fd1a2eb`'s encode half cherry-picked + (`HAS_TOP_RIGHT_VERT`/`HAS_BOTTOM_LEFT_VERT`, `VERT_AB_PARTITION`, `VertAbGuard`, + `Reach::vert_ab_partition()`). Their decode.rs/stream.rs halves were NOT taken (they depend + on part32's own 32-level AB arms and counters) — a merge of both branches touches the same + two `top_right`/`bottom_left` table-pick hunks. +- `crates/ec-av1/src/stream.rs` ~5460: the gate. `crates/ec-av1/src/refusal_inventory.rs`: + one refusal deleted, one narrowed. `gate_coverage.rs` needed no edit (`--enable-ab-partitions` + is now positively exercised and was never on a NEVER_EXERCISED list; this base has no + `NEVER_EXERCISED_10BIT` list — that is on main `79d4f16`, so the merge must delete the AB + entry there if present). + +## Gate + +`a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact`, 6 real-aomenc +streams (`--enable-ab-partitions=1 --enable-rect-partitions=1 --min-partition-size=8 +--max-partition-size=16`, reproducibility-checked, per-arm counter sampled per attempt and +summed only over attempts that decoded AND compared, each arm hard-asserted `> 0`). + +``` +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-ab16 EC_AV1_REQUIRE_AOMENC=1 \ + cargo test -p ec-av1 --lib -- ab_partitions_below_16x16 --nocapture +``` + +EVIDENCE: gate stdout | 6 aomenc streams (yuvtestsrc cq22 8b, rgbtestsrc cq20/cq50 8b, +mandelbrot start_x=-1.0 cq14 8b, yuvtestsrc cq30 10b, mandelbrot start_x=0.4 cq30 10b), +each decoded and compared plane-by-plane against ffmpeg | +`pixel-exact on 6 streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2, 1, 2, 1]`, +`test result: ok. 1 passed`. + +EVIDENCE: /tmp/.../scratchpad/{c30.obu,po30.f0,pa30.f0} | instrumented aomdec `EC_TRACE_MODE` +vs our `EC_TRACE_MODE_STEP` on a 4-arm stream | every mode/uv_mode value AND msac range match +(52624 / 55900 / 38256 / 35312 / 59042 / 54968 / 64576) — the AB arms are entropy-exact; the +residual mismatch in that stream starts at luma (40,9), inside a plain SPLIT 8x8 leaf with +`mode=9` (SMOOTH), i.e. reconstruction, not desync, and not an AB block. + +Scoped run after the fixes: `-- ab_partitions_below_16x16 refusal_inventory gate_coverage +coded_rect_strip` → `7 passed; 0 failed`. + +## Refusals + +- LIFTED `"a HORZ_A/HORZ_B/VERT_A partition below 16x16 ..."` → replaced by the 1:4-only + string. HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 are real-stream-proven above. +- LIFTED `"a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 ..."` (branch deleted; the + gate's HORZ_B/VERT_B strips run the real coefficient path). + +## Open residue + +- **fix-now(not this lane): full-suite gate `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` FAILS on this branch.** + It is not any of this lane's three change groups: it still fails with the mi-map/tile hunks + reverted, and with the `5 - bw_log2` fix reverted, and the AB arms never run in it (SB-level + partitions). It is therefore pre-existing on `lane-rectx fad4d5a` or comes from the + part32 `encode.rs` cherry-pick. Not re-measured on the base commit (turn cap) — the + orchestrator should reconcile with lane-rectx r5 / lane-part32. +- deferred(base chroma/SMOOTH prediction defect — a lane of its own): at + `--max-partition-size=16` most cells of a ~200-cell sweep decode to completion but mismatch, + first error always in a plain (non-AB) 8x8 SPLIT leaf, luma-exact-then-chroma-off or + SMOOTH-mode luma. Reproducer: `mandelbrot=size=64x64:start_x=-0.6 cq30`, recipe as the gate. +- deferred(base tile defect): the charter's `--tile-columns=1` arm is NOT in the gate. + Reproducer: `mandelbrot=size=96x96:start_x=-0.6 cq32 --tile-columns=1`, same recipe → 491 + luma diffs at x=32..63,y=80..95 (last SB of tile 0); the failing superblock's partitions are + `value=0` (NONE) and `value=2` (VERT), no AB symbol, and this survives the mi-map tile fixes + above. +- accepted: 10-bit proves HORZ_A + VERT_A only; the 10-bit HORZ_B/VERT_B cells of the sweep all + trip the base chroma defect above. +- deferred(turn cap): full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` totals — the + run was SIGTERMed by the memguard runner partway (one FAILED test observed, the SB-level one + above; the AB gate passed inside that same run).