forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' (18bf7dc) into lane-sbrect10: sb128 128x128 superblocks + r14 1:4 partitions

Browse files at this commit

d03e23e79dd7792100e8ef261695152c84745604Ahmet Kaan GümüşParent: a603d45c6f22ad

12 changed files +1353 -108

crates/ec-av1/examples/decode_probe.rsmodified+12 -0
@@ -66,6 +66,18 @@ fn main() {
66 }66 }
67 }67 }
68 println!("TILING: {frames_seen} frame headers parsed");68 println!("TILING: {frames_seen} frame headers parsed");
69+ // lane-sb128 r4: the superblock size decides the whole partition tree, so
70+ // report it next to the tiling -- it is the first thing a film blocker
71+ // triage needs.
72+ if let Some(seq) = parser.sequence_header() {
73+ println!(
74+ "SEQ: use_128x128_superblock={} bit_depth={} max_frame={}x{}",
75+ seq.use_128x128_superblock,
76+ seq.color_config.bit_depth,
77+ seq.max_frame_width,
78+ seq.max_frame_height
79+ );
80+ }
69 for (cols, rows, uniform, ctx_id) in &seen {81 for (cols, rows, uniform, ctx_id) in &seen {
70 println!(82 println!(
71 "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}"83 "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}"
crates/ec-av1/src/cdf.rsmodified+11 -0
@@ -8,6 +8,17 @@
8 8
9 /// `Default_Partition_W64_Cdf` (spec 9.4): the ten partition types of a9 /// `Default_Partition_W64_Cdf` (spec 9.4): the ten partition types of a
10 /// 64x64 block, indexed by the context the blocks above and left give.10 /// 64x64 block, indexed by the context the blocks above and left give.
11+/// `default_partition_cdf`'s last four contexts (entropymode.c:154, the
12+/// `AOM_CDF8` rows): the `BLOCK_128X128` root's alphabet is
13+/// `EXT_PARTITION_TYPES - 2 = 8` -- `PARTITION_HORZ_4`/`_VERT_4` do not exist
14+/// at 128 (spec `partition_cdf_length`).
15+pub const PARTITION_W128: [[u16; 9]; 4] = [
16+ [27899, 28219, 28529, 32484, 32539, 32619, 32639, 32768, 0],
17+ [6607, 6990, 8268, 32060, 32219, 32338, 32371, 32768, 0],
18+ [5429, 6676, 7122, 32027, 32227, 32531, 32582, 32768, 0],
19+ [711, 966, 1172, 32448, 32538, 32617, 32664, 32768, 0],
20+];
21+
11 pub const PARTITION_W64: [[u16; 11]; 4] = [22 pub const PARTITION_W64: [[u16; 11]; 4] = [
12 [23 [
13 20137, 21547, 23078, 29566, 29837, 30261, 30524, 30892, 31724, 32768, 0,24 20137, 21547, 23078, 29566, 29837, 30261, 30524, 30892, 31724, 32768, 0,
crates/ec-av1/src/cdf_state.rsmodified+4 -0
@@ -267,6 +267,8 @@ pub(crate) struct TxbTables<'a> {
267 #[derive(Clone)]267 #[derive(Clone)]
268 pub(crate) struct Cdfs {268 pub(crate) struct Cdfs {
269 /// The partition symbol of a 64x64 superblock.269 /// The partition symbol of a 64x64 superblock.
270+ /// `partition_cdf`'s `BLOCK_128X128` rows (8 symbols).
271+ pub partition_w128: [[u16; 9]; 4],
270 pub partition_w64: [[u16; 11]; 4],272 pub partition_w64: [[u16; 11]; 4],
271 /// The partition symbol of a 32x32 block.273 /// The partition symbol of a 32x32 block.
272 pub partition_w32: [[u16; 11]; 4],274 pub partition_w32: [[u16; 11]; 4],
@@ -737,6 +739,7 @@ impl Cdfs {
737 /// into a reference slot for cross-frame forwarding; never on a table739 /// into a reference slot for cross-frame forwarding; never on a table
738 /// still being read within the same tile.740 /// still being read within the same tile.
739 pub(crate) fn reset_counts(&mut self) {741 pub(crate) fn reset_counts(&mut self) {
742+ reset2(&mut self.partition_w128);
740 reset2(&mut self.partition_w64);743 reset2(&mut self.partition_w64);
741 reset2(&mut self.partition_w32);744 reset2(&mut self.partition_w32);
742 reset2(&mut self.txfm_partition);745 reset2(&mut self.txfm_partition);
@@ -902,6 +905,7 @@ impl Cdfs {
902 /// quantizer, so they are the same for every `q_ctx`.905 /// quantizer, so they are the same for every `q_ctx`.
903 pub fn new(q_ctx: usize) -> Cdfs {906 pub fn new(q_ctx: usize) -> Cdfs {
904 Cdfs {907 Cdfs {
908+ partition_w128: cdf::PARTITION_W128,
905 partition_w64: cdf::PARTITION_W64,909 partition_w64: cdf::PARTITION_W64,
906 partition_w32: cdf::PARTITION_W32,910 partition_w32: cdf::PARTITION_W32,
907 skip: cdf::SKIP,911 skip: cdf::SKIP,
crates/ec-av1/src/decode.rsmodified+306 -43
@@ -56,6 +56,71 @@ const PARTITION_VERT_4: usize = 9;
56 const SB_MI: u32 = 16;56 const SB_MI: u32 = 16;
57 const BLOCK_MI: u32 = 8;57 const BLOCK_MI: u32 = 8;
58 58
59+// lane-sb128 r1: this sequence's `use_128x128_superblock` (spec 5.5.1).
60+// Every superblock-granular rule below (`delta_q`/`delta_lf`'s "is this the
61+// superblock's own top-left mi?", the loop-restoration read's unit span, the
62+// partition tree's own root level) keys off it; `SB_MI` stays the 64x64
63+// *quadrant* size a 128 superblock is decoded in, which is also what the CDEF
64+// grid is indexed by (libaom `read_cdef` reads one `cdef_idx` per 64x64
65+// inside a 128 superblock).
66+thread_local! {
67+ static SB128: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
68+}
69+
70+/// Sets [`SB128`] for this thread (called once per frame from `stream.rs`).
71+pub(crate) fn set_sb128(v: bool) {
72+ SB128.with(|c| c.set(v));
73+ crate::encode::set_reach_superblock_px(if v { 128 } else { 64 });
74+}
75+
76+fn sb128() -> bool {
77+ SB128.with(|c| c.get())
78+}
79+
80+/// This sequence's superblock size in mi units (16 = 64x64, 32 = 128x128).
81+pub(crate) fn sb_mi_cur() -> u32 {
82+ if sb128() { SB_MI * 2 } else { SB_MI }
83+}
84+
85+/// How many real 128-level partition symbols this decoder has read, and how
86+/// many superblocks resolved to `PARTITION_SPLIT` (coded or forced) -- the
87+/// gate's proof a `--sb-size=128` stream exercised the 128 partition root.
88+thread_local! {
89+ static PART128_SYMBOLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
90+ static PART128_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
91+ static PART128_GATHERED_SYMBOLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
92+}
93+
94+/// Current value of `PART128_GATHERED_SYMBOLS`: 128 roots that read the
95+/// half-out-of-frame gathered split_or_horz/split_or_vert symbol (spec
96+/// 5.11.4), which this decoder used to read and throw away.
97+pub(crate) fn part128_gathered_symbols() -> usize {
98+ PART128_GATHERED_SYMBOLS.with(|c| c.get())
99+}
100+
101+/// Current value of [`PART128_SYMBOLS`].
102+pub(crate) fn part128_symbols() -> usize {
103+ PART128_SYMBOLS.with(|c| c.get())
104+}
105+
106+/// Current value of [`PART128_SPLIT_HITS`].
107+pub(crate) fn part128_split_hits() -> usize {
108+ PART128_SPLIT_HITS.with(|c| c.get())
109+}
110+
111+/// [`gather`] over an alphabet of any length -- the 128-level partition CDF
112+/// has 8 symbols (no `PARTITION_HORZ_4`/`_VERT_4` at `BLOCK_128X128`, spec
113+/// `partition_cdf_length`), so its forced-split gather sums 5 elements where
114+/// the 64/32 levels sum 6.
115+fn gather_of(cdf: &[u16], elements: &[usize]) -> [u16; 3] {
116+ let split: u16 = elements.iter().map(|&e| element_prob(cdf, e)).sum();
117+ [32768 - split, 32768, 0]
118+}
119+
120+/// [`VERT_ALIKE`]/[`HORZ_ALIKE`] without the 1:4 arms, for the 128 root.
121+const VERT_ALIKE128: [usize; 5] = [2, PARTITION_SPLIT, 4, 6, 7];
122+const HORZ_ALIKE128: [usize; 5] = [1, PARTITION_SPLIT, 4, 5, 6];
123+
59 // How many `use_filter_intra` symbols this decoder has read as `1`, across124 // How many `use_filter_intra` symbols this decoder has read as `1`, across
60 // every call on the current thread -- the cheap counter [`filter_intra_hits`] gate125 // every call on the current thread -- the cheap counter [`filter_intra_hits`] gate
61 // tests read (before/after, not the absolute value) to prove a stream126 // tests read (before/after, not the absolute value) to prove a stream
@@ -241,10 +306,14 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_
241 if !DELTA_Q_PRESENT.with(|c| c.get()) {306 if !DELTA_Q_PRESENT.with(|c| c.get()) {
242 return;307 return;
243 }308 }
244- if mi_r % SB_MI as usize != 0 || mi_c % SB_MI as usize != 0 {309+ let sb_mi = sb_mi_cur() as usize;
310+ if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {
245 return;311 return;
246 }312 }
247- if is_whole_sb && skip {313+ // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which
314+ // it computes against the 64x64 root; under a 128 superblock no leaf this
315+ // decoder codes can be the whole superblock (the root is always SPLIT).
316+ if is_whole_sb && !sb128() && skip {
248 return;317 return;
249 }318 }
250 let mut abs = dec.symbol(&mut cdfs.delta_q) as i32;319 let mut abs = dec.symbol(&mut cdfs.delta_q) as i32;
@@ -296,10 +365,14 @@ fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi
296 if !DELTA_LF_PRESENT.with(|c| c.get()) {365 if !DELTA_LF_PRESENT.with(|c| c.get()) {
297 return;366 return;
298 }367 }
299- if mi_r % SB_MI as usize != 0 || mi_c % SB_MI as usize != 0 {368+ let sb_mi = sb_mi_cur() as usize;
369+ if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {
300 return;370 return;
301 }371 }
302- if is_whole_sb && skip {372+ // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which
373+ // it computes against the 64x64 root; under a 128 superblock no leaf this
374+ // decoder codes can be the whole superblock (the root is always SPLIT).
375+ if is_whole_sb && !sb128() && skip {
303 return;376 return;
304 }377 }
305 let multi = DELTA_LF_MULTI.with(|c| c.get());378 let multi = DELTA_LF_MULTI.with(|c| c.get());
@@ -2522,6 +2595,18 @@ fn note_chroma_class1(plane_idx: usize, tx_type: TxType) {
2522 const SUB_MI: u32 = 4;2595 const SUB_MI: u32 = 4;
2523 const MI: usize = 4;2596 const MI: usize = 4;
2524 const SB: usize = 64;2597 const SB: usize = 64;
2598+/// The `above_side`/`left_side` value a cell with no decoded neighbour holds
2599+/// (tile start, superblock-row start).
2600+///
2601+/// [`Neighbours::partition_ctx_mi`] reads it as libaom's
2602+/// `av1_get_partition_plane_context` reads its own zero-initialised
2603+/// `above_partition_context` byte: bit `bsl` clear, i.e. "the neighbour is at
2604+/// least as wide as this block". lane-sb128 r1: the old sentinel was `SB`
2605+/// (64), which reads identically at every level up to 64x64 but sets the bit
2606+/// at the `BLOCK_128X128` root (64 * 2 <= 128) -- the 128-level partition
2607+/// symbol was read off CDF row 3 where libaom uses row 0 (aomdec
2608+/// `EC_PART mi_row=0 mi_col=0 bsize=15 ctx=16`, i.e. `bsl*4 + 0`).
2609+const NO_NEIGHBOUR_SIDE: usize = 128;
2525 const BLOCK: usize = 32;2610 const BLOCK: usize = 32;
2526 const SUB: usize = 16;2611 const SUB: usize = 16;
2527 const TX32: usize = 32;2612 const TX32: usize = 32;
@@ -3749,10 +3834,10 @@ impl Neighbours {
3749 left_mode: vec![DC_PRED; rows],3834 left_mode: vec![DC_PRED; rows],
3750 above_uv_mode: vec![DC_PRED; cols],3835 above_uv_mode: vec![DC_PRED; cols],
3751 left_uv_mode: vec![DC_PRED; rows],3836 left_uv_mode: vec![DC_PRED; rows],
3752- above_side: vec![SB; cols],3837+ above_side: vec![NO_NEIGHBOUR_SIDE; cols],
3753- left_side: vec![SB; rows],3838+ left_side: vec![NO_NEIGHBOUR_SIDE; rows],
3754- above_side_mi: vec![SB; cols * (SUB / MI)],3839+ above_side_mi: vec![NO_NEIGHBOUR_SIDE; cols * (SUB / MI)],
3755- left_side_mi: vec![SB; rows * (SUB / MI)],3840+ left_side_mi: vec![NO_NEIGHBOUR_SIDE; rows * (SUB / MI)],
3756 sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],3841 sub8_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
3757 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],3842 sub8_mode_row: vec![(usize::MAX, 0); rows * (SUB / MI)],
3758 uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],3843 uv_mode_col: vec![(usize::MAX, 0); cols * (SUB / MI)],
@@ -3817,7 +3902,7 @@ impl Neighbours {
3817 let end = col1_mi.min(self.above.len());3902 let end = col1_mi.min(self.above.len());
3818 for i in col0_mi.min(end)..end {3903 for i in col0_mi.min(end)..end {
3819 self.above[i] = Default::default();3904 self.above[i] = Default::default();
3820- self.above_side_mi[i] = SB;3905+ self.above_side_mi[i] = NO_NEIGHBOUR_SIDE;
3821 }3906 }
3822 let (sc0, sc1) = (3907 let (sc0, sc1) = (
3823 col0_mi / (SUB / MI),3908 col0_mi / (SUB / MI),
@@ -3825,7 +3910,7 @@ impl Neighbours {
3825 );3910 );
3826 for i in sc0.min(sc1)..sc1 {3911 for i in sc0.min(sc1)..sc1 {
3827 self.above_mode[i] = DC_PRED;3912 self.above_mode[i] = DC_PRED;
3828- self.above_side[i] = SB;3913+ self.above_side[i] = NO_NEIGHBOUR_SIDE;
3829 }3914 }
3830 // lane-inter8 r2: the inter bands are mi-granular, so they reset over3915 // lane-inter8 r2: the inter bands are mi-granular, so they reset over
3831 // the tile's own mi column span directly.3916 // the tile's own mi column span directly.
@@ -4164,8 +4249,8 @@ impl Neighbours {
4164 self.left.iter_mut().for_each(|l| *l = Default::default());4249 self.left.iter_mut().for_each(|l| *l = Default::default());
4165 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);4250 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
4166 self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);4251 self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);
4167- self.left_side.iter_mut().for_each(|s| *s = SB);4252+ self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
4168- self.left_side_mi.iter_mut().for_each(|s| *s = SB);4253+ self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
4169 self.left_skip.iter_mut().for_each(|s| *s = false);4254 self.left_skip.iter_mut().for_each(|s| *s = false);
4170 self.left_skip_mode.iter_mut().for_each(|s| *s = false);4255 self.left_skip_mode.iter_mut().for_each(|s| *s = false);
4171 self.left_inter.iter_mut().for_each(|i| *i = false);4256 self.left_inter.iter_mut().for_each(|i| *i = false);
@@ -12633,6 +12718,131 @@ pub(crate) fn take_last_frame_wide_margin() -> Option<Picture> {
12633 /// PRIMARY_REF_NONE`). Returns the tile's own end-of-tile adapted table12718 /// PRIMARY_REF_NONE`). Returns the tile's own end-of-tile adapted table
12634 /// alongside the picture, for the caller to save into whichever reference12719 /// alongside the picture, for the caller to save into whichever reference
12635 /// slots this frame's `refresh_frame_flags` names.12720 /// slots this frame's `refresh_frame_flags` names.
12721+/// The order the 64x64 superblock quadrants of a tile are decoded in.
12722+///
12723+/// At `sb_size == 64` this is plain raster order over the tile's own
12724+/// superblock grid. At `sb_size == 128` libaom's `decode_partition` recurses
12725+/// each 128x128 superblock in raster order and visits its four 64x64
12726+/// quadrants (TL, TR, BL, BR) before moving to the next superblock, so the
12727+/// 64-level bodies must run in that nested order. `row_start` marks the first
12728+/// item of each *superblock* row (where the left neighbour context resets),
12729+/// `sb_start` the first item of each superblock (where the 128 root's own
12730+/// loop-restoration units and partition symbol are read).
12731+fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32, u32, bool, bool)> {
12732+ let mut out = Vec::new();
12733+ if !sb128 {
12734+ for r in r0..r1 {
12735+ for c in c0..c1 {
12736+ out.push((r, c, c == c0, true));
12737+ }
12738+ }
12739+ return out;
12740+ }
12741+ let mut r = r0;
12742+ while r < r1 {
12743+ let mut first_in_row = true;
12744+ let mut c = c0;
12745+ while c < c1 {
12746+ let mut first_in_sb = true;
12747+ for qr in 0..2 {
12748+ for qc in 0..2 {
12749+ let (rr, cc) = (r + qr, c + qc);
12750+ if rr >= r1 || cc >= c1 {
12751+ continue;
12752+ }
12753+ out.push((rr, cc, first_in_row, first_in_sb));
12754+ first_in_row = false;
12755+ first_in_sb = false;
12756+ }
12757+ }
12758+ c += 2;
12759+ }
12760+ r += 2;
12761+ }
12762+ out
12763+}
12764+
12765+/// lane-sb128 r2: the 128x128 superblock root, shared by the key-frame and
12766+/// the inter tile loop. Its loop-restoration units are read once for the whole
12767+/// 128x128 (spec 5.11.57 is called with the superblock's own size), then one
12768+/// partition symbol off the `BLOCK_128X128` CDF (8 symbols, no HORZ_4/VERT_4)
12769+/// decides the root -- only SPLIT recurses into the four 64x64 quadrants this
12770+/// decoder codes, the other seven arms refuse by name.
12771+#[allow(clippy::too_many_arguments)]
12772+fn read_sb128_root(
12773+ dec: &mut SymbolDecoder,
12774+ cdfs: &mut Cdfs,
12775+ neighbours: &Neighbours,
12776+ lr: &LoopRestorationParams,
12777+ lr_grid: &mut crate::restoration::RestorationGrid,
12778+ lr_reference: &mut [(
12779+ crate::restoration::WienerInfo,
12780+ crate::restoration::SgrprojInfo,
12781+ ); 3],
12782+ sb_r: u32,
12783+ sb_c: u32,
12784+ mi_cols: u32,
12785+ mi_rows: u32,
12786+) -> Result<()> {
12787+ let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);
12788+ crate::restoration::read_lr(
12789+ dec,
12790+ cdfs,
12791+ lr,
12792+ lr_grid,
12793+ lr_reference,
12794+ mi_r128,
12795+ mi_c128,
12796+ SB_MI * 2,
12797+ );
12798+ let at128 = ((mi_r128 / SUB_MI) as usize, (mi_c128 / SUB_MI) as usize);
12799+ let ctx128 = neighbours.partition_ctx(at128, 128);
12800+ let (has_cols128, has_rows128) = (mi_c128 + SB_MI < mi_cols, mi_r128 + SB_MI < mi_rows);
12801+ let part128 = if has_cols128 && has_rows128 {
12802+ PART128_SYMBOLS.with(|c| c.set(c.get() + 1));
12803+ let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);
12804+ if std::env::var_os("EC_AV1_TRACE").is_some() {
12805+ eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
12806+ }
12807+ p
12808+ } else {
12809+ // lane-sb128 r4: the gathered half-out-of-frame reads DECIDE the
12810+ // partition, they are not a forced split -- exactly the discarded-bit
12811+ // defect the 64 root carries a comment about at `partition_w64`'s
12812+ // gathered arm. Value 1 is SPLIT; 0 is HORZ (rows out of frame) or
12813+ // VERT (cols out of frame), which the refusal below then names
12814+ // instead of silently reconstructing a split.
12815+ PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() + 1));
12816+ match (has_cols128, has_rows128) {
12817+ (true, false) => {
12818+ if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128)) == 1 {
12819+ PARTITION_SPLIT
12820+ } else {
12821+ PARTITION_HORZ
12822+ }
12823+ }
12824+ (false, true) => {
12825+ if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128)) == 1 {
12826+ PARTITION_SPLIT
12827+ } else {
12828+ PARTITION_VERT
12829+ }
12830+ }
12831+ _ => {
12832+ PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1));
12833+ PARTITION_SPLIT
12834+ }
12835+ }
12836+ };
12837+ if part128 != PARTITION_SPLIT {
12838+ return Err(unsupported(
12839+ "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)",
12840+ ));
12841+ }
12842+ PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1));
12843+ Ok(())
12844+}
12845+
12636 pub(crate) fn decode_key_frame_tile_with_cdfs(12846 pub(crate) fn decode_key_frame_tile_with_cdfs(
12637 tiles: &[&[u8]],12847 tiles: &[&[u8]],
12638 tile_info: &TileInfo,12848 tile_info: &TileInfo,
@@ -12665,6 +12875,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
12665 return Err(unsupported("a frame with no mode-info grid"));12875 return Err(unsupported("a frame with no mode-info grid"));
12666 }12876 }
12667 ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter));12877 ENABLE_EDGE_FILTER.with(|f| f.set(enable_edge_filter));
12878+ let sb128 = sb128();
12879+ if sb128 && allow_intrabc {
12880+ return Err(unsupported(
12881+ "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)",
12882+ ));
12883+ }
12668 let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI));12884 let (sb_cols, sb_rows) = (mi_cols.div_ceil(SB_MI), mi_rows.div_ceil(SB_MI));
12669 INTRABC_MI_GRID.with(|g| {12885 INTRABC_MI_GRID.with(|g| {
12670 *g.borrow_mut() = allow_intrabc.then(|| {12886 *g.borrow_mut() = allow_intrabc.then(|| {
@@ -12802,9 +13018,31 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
12802 );13018 );
12803 TILE_HITS.with(|c| c.set(c.get() + 1));13019 TILE_HITS.with(|c| c.set(c.get() + 1));
12804 13020
12805- for sb_r in sb_r0..sb_r1 {13021+ for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
13022+ if row_start {
12806 neighbours.start_row();13023 neighbours.start_row();
12807- for sb_c in sb_c0..sb_c1 {13024+ }
13025+ {
13026+ // lane-sb128 r1: the 128 root. Its loop-restoration units are read
13027+ // once for the whole 128x128 (spec 5.11.57 is called with the
13028+ // superblock's own size), then one partition symbol off the
13029+ // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT
13030+ // recurses into the four 64x64 quadrants this decoder codes.
13031+ if sb128 && sb_start {
13032+ read_sb128_root(
13033+ &mut dec,
13034+ &mut cdfs,
13035+ &neighbours,
13036+ lr,
13037+ &mut lr_grid,
13038+ &mut lr_reference,
13039+ sb_r,
13040+ sb_c,
13041+ mi_cols,
13042+ mi_rows,
13043+ )?;
13044+ }
13045+ if !sb128 {
12808 crate::restoration::read_lr(13046 crate::restoration::read_lr(
12809 &mut dec,13047 &mut dec,
12810 &mut cdfs,13048 &mut cdfs,
@@ -12815,6 +13053,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
12815 sb_c * SB_MI,13053 sb_c * SB_MI,
12816 SB_MI,13054 SB_MI,
12817 );13055 );
13056+ }
12818 CDEF_TRANSMITTED.with(|c| c.set(false));13057 CDEF_TRANSMITTED.with(|c| c.set(false));
12819 let at = (sb_r as usize * 4, sb_c as usize * 4);13058 let at = (sb_r as usize * 4, sb_c as usize * 4);
12820 let ctx = neighbours.partition_ctx(at, SB);13059 let ctx = neighbours.partition_ctx(at, SB);
@@ -14877,34 +15116,16 @@ fn overlappable_left(
14877 out15116 out
14878 }15117 }
14879 15118
14880-/// `has_top_right` (`av1/common/mvref_common.c`), reduced to the15119+/// The warp-sample gather's own `has_top_right` probe (libaom `av1_findSamples`
14881-/// square-block, fixed-64px-superblock case this decoder ever reaches: no15120+/// calls the same `mvref_common.c` function the MV stack does). lane-sb128 r2:
14882-/// rectangular partition (`VERT`/`HORZ`/`_4`/`VERT_A`) ever produces an15121+/// this used to hardcode `SB_MI` (a 64x64 superblock) -- at `sb_size == 128`
14883-/// inter leaf here (`xd->width == xd->height` always), so libaom's own15122+/// libaom's mask loop runs one level further and strips the top-right sample
14884-/// rect-partition branches (`xd->width < xd->height`, `xd->width >15123+/// off blocks whose neighbour IS decoded, so a warped 128-superblock frame
14885-/// xd->height`, `PARTITION_VERT_A`) never fire and are dropped. `bs` is the15124+/// picked up wrong warp parameters (frame 6 of the 128 inter gate). Delegates
14886-/// block's own side in 4x4 (`mi`) units.15125+/// to the single sb-aware port in [`crate::mvstack::has_top_right`]; `bs` is
15126+/// the block's own side in 4x4 (`mi`) units (square inter leaves only here).
14887 fn has_top_right(mi_row: usize, mi_col: usize, bs: usize) -> bool {15127 fn has_top_right(mi_row: usize, mi_col: usize, bs: usize) -> bool {
14888- let sb_mi_size = SB_MI as usize;15128+ crate::mvstack::has_top_right(mi_row, mi_col, bs, bs)
14889- let mask_row = mi_row & (sb_mi_size - 1);
14890- let mask_col = mi_col & (sb_mi_size - 1);
14891- if bs > sb_mi_size {
14892- return false;
14893- }
14894- let mut has_tr = !((mask_row & bs != 0) && (mask_col & bs != 0));
14895- let mut b = bs;
14896- while b < sb_mi_size {
14897- if mask_col & b != 0 {
14898- if (mask_col & (2 * b) != 0) && (mask_row & (2 * b) != 0) {
14899- has_tr = false;
14900- break;
14901- }
14902- } else {
14903- break;
14904- }
14905- b <<= 1;
14906- }
14907- has_tr
14908 }15129 }
14909 15130
14910 /// `av1_findSamples` (`mvref_common.c`), full port: the up to15131 /// `av1_findSamples` (`mvref_common.c`), full port: the up to
@@ -16096,6 +16317,22 @@ fn decode_inter_block(
16096 force_integer_mv,16317 force_integer_mv,
16097 (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),16318 (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),
16098 );16319 );
16320+ if std::env::var_os("EC_TRACE_MODE").is_some() {
16321+ eprintln!(
16322+ "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}",
16323+ compound_mode + 17,
16324+ mv0.0,
16325+ mv0.1,
16326+ comp_stack.entries.len(),
16327+ dec.debug_state().0
16328+ );
16329+ for (i, e) in comp_stack.entries.iter().enumerate() {
16330+ eprintln!(
16331+ "EC_STACK mi_row={mi_row} mi_col={mi_col} i={i} this=({},{}) comp=({},{}) w={}",
16332+ e.mv0.0, e.mv0.1, e.mv1.0, e.mv1.1, e.weight
16333+ );
16334+ }
16335+ }
16099 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV16336 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV
16100 // spec `is_nontrans_global_motion`: ALL active refs' models must16337 // spec `is_nontrans_global_motion`: ALL active refs' models must
16101 // be non-TRANSLATION (IDENTITY counts) for the compound block's16338 // be non-TRANSLATION (IDENTITY counts) for the compound block's
@@ -20179,6 +20416,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20179 ));20416 ));
20180 }20417 }
20181 let (cols, rows) = block_grid(mi_cols, mi_rows);20418 let (cols, rows) = block_grid(mi_cols, mi_rows);
20419+ let sb128 = sb128();
20182 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));20420 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
20183 CDEF_BITS.with(|c| c.set(cdef.bits));20421 CDEF_BITS.with(|c| c.set(cdef.bits));
20184 CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));20422 CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));
@@ -20400,9 +20638,33 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20400 );20638 );
20401 TILE_HITS.with(|c| c.set(c.get() + 1));20639 TILE_HITS.with(|c| c.set(c.get() + 1));
20402 20640
20403- for sb_r in sb_r0..sb_r1 {20641+ // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128
20642+ // superblock's four 64x64 quadrants in libaom `decode_partition` order
20643+ // (TL, TR, BL, BR) and reads the 128 root's own loop-restoration units and
20644+ // partition symbol once per superblock -- exactly what the key-frame tile
20645+ // loop does; the 64-level body below is unchanged, `read_cdef`'s
20646+ // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's
20647+ // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant.
20648+ for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
20649+ if row_start {
20404 neighbours.start_row();20650 neighbours.start_row();
20405- for sb_c in sb_c0..sb_c1 {20651+ }
20652+ {
20653+ if sb128 && sb_start {
20654+ read_sb128_root(
20655+ &mut dec,
20656+ &mut cdfs,
20657+ &neighbours,
20658+ lr,
20659+ &mut lr_grid,
20660+ &mut lr_reference,
20661+ sb_r,
20662+ sb_c,
20663+ mi_cols,
20664+ mi_rows,
20665+ )?;
20666+ }
20667+ if !sb128 {
20406 crate::restoration::read_lr(20668 crate::restoration::read_lr(
20407 &mut dec,20669 &mut dec,
20408 &mut cdfs,20670 &mut cdfs,
@@ -20413,6 +20675,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
20413 sb_c * SB_MI,20675 sb_c * SB_MI,
20414 SB_MI,20676 SB_MI,
20415 );20677 );
20678+ }
20416 CDEF_TRANSMITTED.with(|c| c.set(false));20679 CDEF_TRANSMITTED.with(|c| c.set(false));
20417 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);20680 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
20418 // lane-inter4 r1: every rect inter piece below is the same20681 // lane-inter4 r1: every rect inter piece below is the same
crates/ec-av1/src/encode.rsmodified+32 -15
@@ -47,6 +47,26 @@ const SUB: usize = 16;
47 /// The side of a superblock, which is what the partition tree starts from.47 /// The side of a superblock, which is what the partition tree starts from.
48 pub(crate) const SUPERBLOCK: usize = 64;48 pub(crate) const SUPERBLOCK: usize = 64;
49 49
50+// lane-sb128 r1: the superblock size in samples the intra-reach rules
51+// (`has_top_right`/`has_bottom_left`) are answered against. libaom masks the
52+// block's mi position with `mi_size_wide[cm->seq_params->sb_size] - 1` and
53+// tests the "top row"/"rightmost column" of THAT superblock, so a 128x128
54+// superblock changes every answer inside it (the tables themselves are
55+// already laid out 128-relative -- see `Reach::table_stride`). [`SUPERBLOCK`]
56+// stays the encoder's own fixed 64.
57+thread_local! {
58+ static REACH_SB_PX: std::cell::Cell<usize> = const { std::cell::Cell::new(SUPERBLOCK) };
59+}
60+
61+/// Sets the superblock size [`Reach`] answers against (64 or 128).
62+pub(crate) fn set_reach_superblock_px(px: usize) {
63+ REACH_SB_PX.with(|c| c.set(px));
64+}
65+
66+fn reach_sb_px() -> usize {
67+ REACH_SB_PX.with(|c| c.get())
68+}
69+
50 /// How heavily the mode search weighs rate against squared error, in units of70 /// How heavily the mode search weighs rate against squared error, in units of
51 /// the quantizer's reconstruction step squared per bit.71 /// the quantizer's reconstruction step squared per bit.
52 ///72 ///
@@ -1300,19 +1320,19 @@ impl Reach {
1300 /// the transform covering the whole block, luma): everything before the1320 /// the transform covering the whole block, luma): everything before the
1301 /// table lookup is that function's own early-exit ladder.1321 /// table lookup is that function's own early-exit ladder.
1302 fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {1322 fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {
1303- const SB_MI: usize = SUPERBLOCK / 4;1323+ let sb_mi: usize = reach_sb_px() / 4;
1304 let (mi_row, mi_col) = (y / 4, x / 4);1324 let (mi_row, mi_col) = (y / 4, x / 4);
1305 let bw_log2 = (bw / 4).trailing_zeros() as usize;1325 let bw_log2 = (bw / 4).trailing_zeros() as usize;
1306 let bh_log2 = (bh / 4).trailing_zeros() as usize;1326 let bh_log2 = (bh / 4).trailing_zeros() as usize;
1307- let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2;1327+ let blk_row = (mi_row & (sb_mi - 1)) >> bh_log2;
1308- let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2;1328+ let blk_col = (mi_col & (sb_mi - 1)) >> bw_log2;
1309 // Top row of the superblock: the top-right pixels are in the (already1329 // Top row of the superblock: the top-right pixels are in the (already
1310 // decoded) superblock above.1330 // decoded) superblock above.
1311 if blk_row == 0 {1331 if blk_row == 0 {
1312 return true;1332 return true;
1313 }1333 }
1314 // Rightmost column: they fall in the superblock to the right.1334 // Rightmost column: they fall in the superblock to the right.
1315- if ((blk_col + 1) << bw_log2) >= SB_MI {1335+ if ((blk_col + 1) << bw_log2) >= sb_mi {
1316 return false;1336 return false;
1317 }1337 }
1318 let table = rect_reach_tables(bw, bh).0;1338 let table = rect_reach_tables(bw, bh).0;
@@ -1333,20 +1353,20 @@ impl Reach {
1333 1353
1334 /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`].1354 /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`].
1335 fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {1355 fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool {
1336- const SB_MI: usize = SUPERBLOCK / 4;1356+ let sb_mi: usize = reach_sb_px() / 4;
1337 let (mi_row, mi_col) = (y / 4, x / 4);1357 let (mi_row, mi_col) = (y / 4, x / 4);
1338 let bw_log2 = (bw / 4).trailing_zeros() as usize;1358 let bw_log2 = (bw / 4).trailing_zeros() as usize;
1339 let bh_log2 = (bh / 4).trailing_zeros() as usize;1359 let bh_log2 = (bh / 4).trailing_zeros() as usize;
1340- let blk_row = (mi_row & (SB_MI - 1)) >> bh_log2;1360+ let blk_row = (mi_row & (sb_mi - 1)) >> bh_log2;
1341- let blk_col = (mi_col & (SB_MI - 1)) >> bw_log2;1361+ let blk_col = (mi_col & (sb_mi - 1)) >> bw_log2;
1342 // Leftmost column of the superblock: the bottom-left pixels are in1362 // Leftmost column of the superblock: the bottom-left pixels are in
1343 // the left superblock iff they stay inside its height.1363 // the left superblock iff they stay inside its height.
1344 if blk_col == 0 {1364 if blk_col == 0 {
1345- return (blk_row << bh_log2) + (bh / 4) < SB_MI;1365+ return (blk_row << bh_log2) + (bh / 4) < sb_mi;
1346 }1366 }
1347 // Bottom row (and not the leftmost column): they fall in the1367 // Bottom row (and not the leftmost column): they fall in the
1348 // superblock below, which is not decoded yet.1368 // superblock below, which is not decoded yet.
1349- if ((blk_row + 1) << bh_log2) >= SB_MI {1369+ if ((blk_row + 1) << bh_log2) >= sb_mi {
1350 return false;1370 return false;
1351 }1371 }
1352 let table = rect_reach_tables(bw, bh).1;1372 let table = rect_reach_tables(bw, bh).1;
@@ -1420,7 +1440,7 @@ impl Reach {
1420 fn bottom_left(side: usize, x: usize, y: usize) -> bool {1440 fn bottom_left(side: usize, x: usize, y: usize) -> bool {
1421 let (row, col, per_side) = Self::position(side, x, y);1441 let (row, col, per_side) = Self::position(side, x, y);
1422 if col == 0 {1442 if col == 0 {
1423- return row * side + side < SUPERBLOCK;1443+ return row * side + side < reach_sb_px();
1424 }1444 }
1425 if row + 1 == per_side {1445 if row + 1 == per_side {
1426 return false;1446 return false;
@@ -1451,11 +1471,8 @@ impl Reach {
1451 /// Where a block sits inside its superblock, in blocks of its own size,1471 /// Where a block sits inside its superblock, in blocks of its own size,
1452 /// and how many of them a superblock is across.1472 /// and how many of them a superblock is across.
1453 fn position(side: usize, x: usize, y: usize) -> (usize, usize, usize) {1473 fn position(side: usize, x: usize, y: usize) -> (usize, usize, usize) {
1454- (1474+ let sb = reach_sb_px();
1455- (y % SUPERBLOCK) / side,1475+ ((y % sb) / side, (x % sb) / side, sb / side)
1456- (x % SUPERBLOCK) / side,
1457- SUPERBLOCK / side,
1458- )
1459 }1476 }
1460 1477
1461 /// The row stride `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` index by: libaom pins1478 /// The row stride `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` index by: libaom pins
crates/ec-av1/src/mvstack.rsmodified+78 -0
@@ -585,6 +585,43 @@ fn scan_col(
585 found585 found
586 }586 }
587 587
588+/// libaom `has_top_right` (mvref_common.c:264): whether the unit diagonally
589+/// above-right of this block has been decoded *by the superblock's own
590+/// recursion order*. The mask is `sb_size`-relative, so at a 128x128
591+/// superblock the `while` loop runs one level further than at 64x64 and
592+/// strips the top-right neighbour off blocks that DO sit in already-decoded
593+/// memory -- an availability rule a plain "is the grid cell populated" probe
594+/// (what this module did before lane-sb128 r2) cannot see. It cost frame 6 of
595+/// the 128 inter gate 380 wrong luma bytes with the entropy stream in sync.
596+///
597+/// corner-cut: libaom's three shape refinements (`is_last_vertical_rect`,
598+/// `is_first_horizontal_rect`, the `PARTITION_VERT_A` bottom-left square) are
599+/// not ported -- the ceiling is rectangular and AB-partitioned INTER leaves,
600+/// which this decoder refuses by name today; port them with the rect inter
601+/// leaf.
602+pub(crate) fn has_top_right(mi_row: usize, mi_col: usize, bw4: usize, bh4: usize) -> bool {
603+ let sb_mi_size = crate::decode::sb_mi_cur() as usize;
604+ let bs0 = bw4.max(bh4);
605+ if bs0 > 16 {
606+ return false;
607+ }
608+ let (mask_row, mask_col) = (mi_row & (sb_mi_size - 1), mi_col & (sb_mi_size - 1));
609+ let mut has_tr = !(mask_row & bs0 != 0 && mask_col & bs0 != 0);
610+ let mut bs = bs0;
611+ while bs < sb_mi_size {
612+ if mask_col & bs != 0 {
613+ if mask_col & (2 * bs) != 0 && mask_row & (2 * bs) != 0 {
614+ has_tr = false;
615+ break;
616+ }
617+ } else {
618+ break;
619+ }
620+ bs <<= 1;
621+ }
622+ has_tr
623+}
624+
588 /// The single top-right probe this reduction keeps of spec 7.10.2.4's extra625 /// The single top-right probe this reduction keeps of spec 7.10.2.4's extra
589 /// scan positions, at the unit diagonally above-right of the block. Its626 /// scan positions, at the unit diagonally above-right of the block. Its
590 /// vote is folded into the row scan's candidates (it sits on the same row627 /// vote is folded into the row scan's candidates (it sits on the same row
@@ -1623,6 +1660,47 @@ pub fn find_mv_stack_compound(
1623 }1660 }
1624 blk_row += step_h;1661 blk_row += step_h;
1625 }1662 }
1663+ // lane-sb128 r3: libaom's three `tpl_sample_pos` EXTENSION samples
1664+ // (mvref_common.c:591), which the single-ref twin already ports and
1665+ // this compound path dropped. `check_sb_border`'s mask is libaom's
1666+ // hardcoded `mi_size_wide[BLOCK_64X64]` (16), NOT the sequence's
1667+ // superblock size. Missing them cost one weight-2 vote on a
1668+ // candidate, which reordered the stack and gave a NEW_NEWMV block a
1669+ // different predictor -- 957 wrong pixels on one 32x32 block of one
1670+ // frame with the entropy stream in sync.
1671+ let allow_extension = (2..16).contains(&bh4) && (2..16).contains(&bw4);
1672+ if allow_extension {
1673+ let (voffset, hoffset) = (bh4.max(2) as isize, bw4.max(2) as isize);
1674+ let sb_mask = 16isize;
1675+ for (row_off, col_off) in [
1676+ (voffset, -2isize),
1677+ (voffset, hoffset),
1678+ (voffset - 2, hoffset),
1679+ ] {
1680+ let row = (mi_row as isize & (sb_mask - 1)) + row_off;
1681+ let col = (mi_col as isize & (sb_mask - 1)) + col_off;
1682+ if row < 0 || row >= sb_mask || col < 0 || col >= sb_mask {
1683+ continue;
1684+ }
1685+ let cand0 = crate::motion_field::add_tpl_ref_mv(
1686+ field, mi_row, mi_col, row_off, col_off, cur_offset_0,
1687+ allow_high_precision_mv,
1688+ );
1689+ let cand1 = crate::motion_field::add_tpl_ref_mv(
1690+ field, mi_row, mi_col, row_off, col_off, cur_offset_1,
1691+ allow_high_precision_mv,
1692+ );
1693+ if cand0.is_some() || cand1.is_some() {
1694+ any_hit = true;
1695+ add_compound_candidate(
1696+ &mut candidates,
1697+ cand0.map_or((0, 0), |c| c.mv),
1698+ cand1.map_or((0, 0), |c| c.mv),
1699+ 2,
1700+ );
1701+ }
1702+ }
1703+ }
1626 if any_hit {1704 if any_hit {
1627 TMV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1705 TMV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1628 }1706 }
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -42,6 +42,8 @@ const REFUSALS: &[&str] = &[
42 "a tx_type symbol outside its CDF's own set: {t}",42 "a tx_type symbol outside its CDF's own set: {t}",
43 "an INTER 32x32 partition type this decoder does not code (value={part32})",43 "an INTER 32x32 partition type this decoder does not code (value={part32})",
44 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",44 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
45+ "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)",
46+ "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)",
45 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",47 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",
46 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",48 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
47 "a block that actually uses a palette (UV) -- reconstruction is out of scope",49 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
@@ -49,7 +51,6 @@ const REFUSALS: &[&str] = &[
49 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",51 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
50 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",52 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
51 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",53 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
52- "a sequence using 128x128 superblocks on a frame larger than 64x64 (this decoder's whole partition/CDEF/LR grid is 64x64-superblock only; aomenc picks 128x128 at --cpu-used=0)",
53 "a frame OBU with no tile group",54 "a frame OBU with no tile group",
54 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",55 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
55 "a frame with no mode-info grid",56 "a frame with no mode-info grid",
crates/ec-av1/src/stream.rsmodified+467 -49
@@ -510,6 +510,18 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
510 // inter frames are decoded on a thread that previously decoded a510 // inter frames are decoded on a thread that previously decoded a
511 // different sequence would inherit that sequence's bit.511 // different sequence would inherit that sequence's bit.
512 crate::decode::set_enable_edge_filter(enable_edge_filter);512 crate::decode::set_enable_edge_filter(enable_edge_filter);
513+ // lane-sb128 r1/r2: `use_128x128_superblock` (spec 5.5.1). Both the
514+ // key-frame and the inter tile path read the 128 partition root and
515+ // recurse SPLIT into the four 64x64 quadrants (r2 ported the root and
516+ // libaom's quadrant visit order into the inter loop too). A frame at
517+ // most 64x64 decodes identically either way (its 128 root reads no
518+ // symbol -- neither half is in frame, so SPLIT is inferred), so the
519+ // flag is only armed for frames bigger than one 64x64 superblock.
520+ let use_sb128 = parser
521+ .sequence_header()
522+ .is_some_and(|seq| seq.use_128x128_superblock);
523+ let sb128_active = use_sb128 && (header.mi_cols > 16 || header.mi_rows > 16);
524+ crate::decode::set_sb128(sb128_active);
513 // lane-hbd r5: `BIT_DEPTH` (decode.rs) drives `crate::decode::sample_max`,525 // lane-hbd r5: `BIT_DEPTH` (decode.rs) drives `crate::decode::sample_max`,
514 // which every dequant/inverse-transform clamp reads -- set per frame,526 // which every dequant/inverse-transform clamp reads -- set per frame,
515 // not once per process, for the same cross-sequence-on-one-thread527 // not once per process, for the same cross-sequence-on-one-thread
@@ -531,37 +543,6 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
531 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",543 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
532 ));544 ));
533 }545 }
534- // lane-oddh r2: `use_128x128_superblock` reaches every level of the
535- // decode -- the partition tree starts at BLOCK_128X128, `SB_MI` is 32
536- // mi units, and the CDEF/LR/deblock grids are per-128 -- and this
537- // decoder is written for 64x64 superblocks throughout (`SB_MI = 16`,
538- // no BLOCK_128X128 partition read at all). Until r1 that was SILENT:
539- // a 64x72 aomenc key frame at `--cpu-used=0` (libaom picks 128x128
540- // whenever speed is 0, `av1_select_sb_size`) desynced at the very
541- // first symbol -- aomdec reads a gathered 2-symbol
542- // BLOCK_128X128 partition (has_cols false at mi_cols=16,
543- // has_rows true at mi_rows=18) where we read a 10-symbol
544- // BLOCK_64X64 one from the same byte, giving PARTITION_VERT_4 (9)
545- // against SPLIT (3). Refuse by name rather than decode wrong pixels.
546- //
547- // Scoped, not blanket (measured: a blanket refusal red-lined 29
548- // previously pixel-exact gates): on a frame of at most 64x64 a
549- // 128x128 superblock decodes IDENTICALLY to a 64x64 one -- mi (0,0)
550- // has neither `has_rows` nor `has_cols`, so BLOCK_128X128 is a forced
551- // SPLIT that reads no symbol, and only one of its four 64x64 children
552- // is inside the frame. Every sibling inter gate at 64x64 and
553- // `--cpu-used=0` is exactly that case. The divergence starts the
554- // moment a superblock has a second child in frame.
555- if parser
556- .sequence_header()
557- .is_some_and(|seq| seq.use_128x128_superblock)
558- && (header.mi_cols > 16 || header.mi_rows > 16)
559- {
560- return Err(Error::unsupported(
561- "AV1 decode_stream",
562- "a sequence using 128x128 superblocks on a frame larger than 64x64 (this decoder's whole partition/CDEF/LR grid is 64x64-superblock only; aomenc picks 128x128 at --cpu-used=0)",
563- ));
564- }
565 crate::decode::set_bit_depth(bit_depth);546 crate::decode::set_bit_depth(bit_depth);
566 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.547 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.
567 let enable_masked_compound = parser548 let enable_masked_compound = parser
@@ -1103,22 +1084,18 @@ mod tests {
1103 eprintln!("{NAME}: {compared} attempts pixel-exact, edge_rect_strip_hits={strip_hits}, {refused} refusals");1084 eprintln!("{NAME}: {compared} attempts pixel-exact, edge_rect_strip_hits={strip_hits}, {refused} refusals");
1104 }1085 }
1105 1086
1106- /// lane-oddh r2 GATE: a REAL aomenc stream that uses 128x128 superblocks1087+ /// lane-sb128 r4 GATE (was lane-oddh r2's refusal gate): the SAME real
1107- /// is refused by name, not silently mis-decoded. This is the root cause of1088+ /// aomenc 64x72 `--cpu-used=0 --sb-size=128` stream that once desynced at
1108- /// r1's pinned 64x72 first-symbol desync: libaom's `av1_select_sb_size`1089+ /// the very first symbol now decodes PIXEL-EXACT against aomdec. mi_rows
1109- /// returns BLOCK_128X128 whenever speed is 0, so a tiny frame encoded at1090+ /// = 18 > 16, so the BLOCK_128X128 root reads a real gathered partition
1110- /// `--cpu-used=0` carries 128x128 superblocks, and this 64x64-only1091+ /// symbol (2 symbols: has_cols false, has_rows true) -- exactly the case
1111- /// decoder read a 10-symbol BLOCK_64X64 partition (value 9, VERT_4) where1092+ /// r1 mis-read as a 10-symbol BLOCK_64X64 partition.
1112- /// aomdec read a gathered 2-symbol BLOCK_128X128 one (value 3, SPLIT) from
1113- /// the same byte -- the uncompressed header parse was byte-identical
1114- /// (49 bits, tile data at file offset 20; hand-verified against spec
1115- /// 5.9.2 field by field).
1116 ///1093 ///
1117 /// The `use_128x128_superblock` assert is the "knob reached the tool"1094 /// The `use_128x128_superblock` assert is the "knob reached the tool"
1118- /// half: without it, an aomenc that ignored `--sb-size=128` would leave1095+ /// half: without it an aomenc that ignored `--sb-size=128` would leave
1119- /// the gate asserting a refusal that never fires.1096+ /// the gate proving nothing about 128 superblocks.
1120 #[test]1097 #[test]
1121- fn a_real_aomenc_128x128_superblock_stream_is_refused_by_name() {1098+ fn a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact() {
1122 if !have_ffmpeg() || !have_aomenc() {1099 if !have_ffmpeg() || !have_aomenc() {
1123 eprintln!("SKIP: no ffmpeg/aomenc");1100 eprintln!("SKIP: no ffmpeg/aomenc");
1124 return;1101 return;
@@ -1139,7 +1116,8 @@ mod tests {
1139 let mut child = Command::new(aomenc_path())1116 let mut child = Command::new(aomenc_path())
1140 .args([1117 .args([
1141 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",1118 "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
1142- "--cpu-used=0", "--sb-size=128", "--kf-max-dist=0", "--limit=1",1119+ "--cpu-used=0", "--sb-size=128", "--min-partition-size=16",
1120+ "--kf-max-dist=0", "--limit=1",
1143 "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-",1121 "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-",
1144 ])1122 ])
1145 .stdin(Stdio::piped())1123 .stdin(Stdio::piped())
@@ -1169,10 +1147,26 @@ mod tests {
1169 }1147 }
1170 assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock");1148 assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock");
1171 1149
1172- let err = decode_stream(&stream).unwrap_err().to_string();1150+ let _guard = lock_gate_counters();
1173- assert!(1151+ let before = crate::decode::part128_symbols()
1174- err.contains("a sequence using 128x128 superblocks"),1152+ + crate::decode::part128_gathered_symbols();
1175- "expected the 128x128-superblock refusal for {width}x{height}, got: {err}"1153+ let (frames, hidden) =
1154+ decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72");
1155+ assert!(frames > 0, "no frames decoded for {width}x{height}");
1156+ // The 128 root actually READ a partition symbol here: at mi_rows=18
1157+ // `has_rows` is true, so BLOCK_128X128 is not a forced split.
1158+ let part128 = crate::decode::part128_symbols()
1159+ + crate::decode::part128_gathered_symbols()
1160+ - before;
1161+ assert!(
1162+ part128 > 0,
1163+ "{width}x{height} decoded without reading a single BLOCK_128X128 \
1164+ partition symbol -- the gate proves nothing about the 128 root"
1165+ );
1166+ eprintln!(
1167+ "a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact: \
1168+ {frames} frames pixel-exact ({hidden} hidden) at {width}x{height}, \
1169+ part128_symbols={part128}"
1176 );1170 );
1177 }1171 }
1178 1172
@@ -2755,6 +2749,7 @@ mod tests {
2755 "--error-resilient=1",2749 "--error-resilient=1",
2756 "--aq-mode=0",2750 "--aq-mode=0",
2757 "--deltaq-mode=0",2751 "--deltaq-mode=0",
2752+ "--enable-cdef=0",
2758 "--enable-rect-partitions=0",2753 "--enable-rect-partitions=0",
2759 "--enable-ab-partitions=0",2754 "--enable-ab-partitions=0",
2760 "--enable-1to4-partitions=0",2755 "--enable-1to4-partitions=0",
@@ -13799,6 +13794,7 @@ mod tests {
13799 "--cpu-used=4",13794 "--cpu-used=4",
13800 "--aq-mode=0",13795 "--aq-mode=0",
13801 "--deltaq-mode=0",13796 "--deltaq-mode=0",
13797+ "--enable-cdef=0",
13802 "--kf-max-dist=1000",13798 "--kf-max-dist=1000",
13803 "--threads=1",13799 "--threads=1",
13804 "--row-mt=0",13800 "--row-mt=0",
@@ -17227,6 +17223,7 @@ mod tests {
17227 "--cpu-used=4",17223 "--cpu-used=4",
17228 &aq,17224 &aq,
17229 "--deltaq-mode=0",17225 "--deltaq-mode=0",
17226+ "--enable-cdef=0",
17230 "--kf-max-dist=1000",17227 "--kf-max-dist=1000",
17231 "--threads=1",17228 "--threads=1",
17232 "--row-mt=0",17229 "--row-mt=0",
@@ -17956,6 +17953,417 @@ mod tests {
17956 );17953 );
17957 }17954 }
17958 17955
17956+ /// lane-sb128 r1 gate: a real `aomenc --sb-size=128` stream (the size his
17957+ /// ReelC encode uses -- `EC_TRACE=1 aomdec reelc-head.obu` prints
17958+ /// `EC_PART mi_row=0 mi_col=0 bsize=15` = `BLOCK_128X128`) must decode
17959+ /// pixel-exact. `--max-partition-size=64` keeps the RD search from ever
17960+ /// choosing a 128-level NONE/HORZ/VERT/AB arm, so every 128 root here is
17961+ /// genuinely `PARTITION_SPLIT` -- the one arm
17962+ /// `decode_key_frame_tile_with_cdfs` codes; the other seven refuse by
17963+ /// name (`PART128_NON_SPLIT_REFUSAL`) and stay refused after this round.
17964+ ///
17965+ /// What the 128 root actually changes, and what this gate therefore
17966+ /// proves: the 8-symbol `partition_w128` CDF and its forced-split gather
17967+ /// at the frame edge, the quadrant VISIT ORDER (TL, TR, BL, BR inside one
17968+ /// superblock, not raster over 64x64 superblocks), one loop-restoration
17969+ /// read per 128x128 instead of per 64x64, `delta_q`/`delta_lf` once per
17970+ /// 128x128, and the per-64x64 `cdef_idx` read inside the 128 superblock.
17971+ /// 256x192 gives a 2x2 grid of 128 superblocks whose bottom row is a
17972+ /// partial superblock (the gathered forced-split read); 384x384 gives a
17973+ /// 3x3 grid of whole ones. 8-bit sweep plus one 10-bit stream (his films
17974+ /// are `yuv420p10le`). Only a missing tool SKIPs.
17975+ #[test]
17976+ fn a_real_aomenc_stream_with_128x128_superblocks_decodes_pixel_exact() {
17977+ const NAME: &str = "a_real_aomenc_stream_with_128x128_superblocks_decodes_pixel_exact";
17978+ let _gate_lock = lock_gate_counters();
17979+ if !have_ffmpeg() {
17980+ eprintln!("SKIP {NAME}: no ffmpeg");
17981+ return;
17982+ }
17983+ if !have_aomenc() {
17984+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
17985+ return;
17986+ }
17987+ let base: Vec<&str> = vec![
17988+ "--codec=av1",
17989+ "--passes=1",
17990+ "--end-usage=q",
17991+ "--cq-level=40",
17992+ "--cpu-used=0",
17993+ "--threads=1",
17994+ "--row-mt=0",
17995+ "--sb-size=128",
17996+ "--max-partition-size=64",
17997+ "--enable-rect-partitions=1",
17998+ "--enable-ab-partitions=0",
17999+ "--enable-1to4-partitions=0",
18000+ // aomenc emits PARTITION_HORZ_4/VERT_4 below 16x16 even with the
18001+ // flag off (ledger, lane-modectx r1), so bound the search instead.
18002+ "--min-partition-size=16",
18003+ "--enable-restoration=1",
18004+ "--enable-palette=0",
18005+ "--deltaq-mode=0",
18006+ "--enable-intrabc=0",
18007+ "--enable-tx-size-search=0",
18008+ "--limit=1",
18009+ ];
18010+ let encode = |y4m: &[u8], extra: &[&str]| -> Vec<u8> {
18011+ let mut args = base.clone();
18012+ args.extend_from_slice(extra);
18013+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
18014+ let mut child = Command::new(aomenc_path())
18015+ .args(&args)
18016+ .stdin(Stdio::piped())
18017+ .stdout(Stdio::piped())
18018+ .stderr(Stdio::piped())
18019+ .spawn()
18020+ .expect("aomenc failed to start");
18021+ child
18022+ .stdin
18023+ .take()
18024+ .expect("aomenc stdin")
18025+ .write_all(y4m)
18026+ .expect("writing y4m to aomenc");
18027+ let out = child.wait_with_output().expect("aomenc failed to run");
18028+ assert!(
18029+ out.status.success(),
18030+ "aomenc refused the fixture: {}",
18031+ String::from_utf8_lossy(&out.stderr)
18032+ );
18033+ out.stdout
18034+ };
18035+ let render = |seed: u32, width: usize, height: usize, ten_bit: bool| -> Vec<u8> {
18036+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
18037+ let out = Command::new("ffmpeg")
18038+ .args([
18039+ "-v",
18040+ "error",
18041+ "-f",
18042+ "lavfi",
18043+ "-i",
18044+ &gradients_source(seed, width, height, "duration=0.04:rate=25"),
18045+ "-pix_fmt",
18046+ pix,
18047+ "-strict",
18048+ "-1",
18049+ "-t",
18050+ "0.04",
18051+ "-f",
18052+ "yuv4mpegpipe",
18053+ "-",
18054+ ])
18055+ .stdin(Stdio::null())
18056+ .stdout(Stdio::piped())
18057+ .stderr(Stdio::piped())
18058+ .output()
18059+ .expect("ffmpeg failed to run");
18060+ assert!(
18061+ out.status.success(),
18062+ "ffmpeg fixture: {}",
18063+ String::from_utf8_lossy(&out.stderr)
18064+ );
18065+ out.stdout
18066+ };
18067+ let mut matched = 0u32;
18068+ let mut named_refusals = 0u32;
18069+ // (seed, width, height, 10-bit): 256x192 = 2x2 superblocks with a
18070+ // partial bottom row; 384x384 = 3x3 whole ones.
18071+ let arms: Vec<(u32, usize, usize, bool)> = vec![
18072+ (42, 256, 192, false),
18073+ (43, 256, 192, false),
18074+ (44, 256, 192, false),
18075+ (45, 384, 384, false),
18076+ (46, 256, 192, true),
18077+ (47, 384, 384, true),
18078+ ];
18079+ for (seed, width, height, ten_bit) in arms {
18080+ let y4m = render(seed, width, height, ten_bit);
18081+ let extra: Vec<&str> = if ten_bit {
18082+ vec!["--input-bit-depth=10", "--bit-depth=10"]
18083+ } else {
18084+ vec![]
18085+ };
18086+ let stream = encode(&y4m, &extra);
18087+ let parsed = {
18088+ let mut parser = ec_av1_syntax::Av1Parser::new();
18089+ let mut pos = 0usize;
18090+ while let Ok(obu) = parser.parse_obu(&stream[pos..]) {
18091+ pos += obu.total_size;
18092+ if pos >= stream.len() {
18093+ break;
18094+ }
18095+ }
18096+ parser
18097+ .sequence_header()
18098+ .map(|q| (q.use_128x128_superblock, q.color_config.bit_depth))
18099+ };
18100+ assert_eq!(
18101+ parsed,
18102+ Some((true, if ten_bit { 10 } else { 8 })),
18103+ "{NAME} (seed {seed}): the encoder did not write a 128x128-superblock \
18104+ sequence header at the requested bit depth -- the flag never arrived"
18105+ );
18106+ let frames = match decode_stream(&stream) {
18107+ Err(e) => {
18108+ let msg = e.to_string();
18109+ assert!(
18110+ msg.contains("unsupported"),
18111+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
18112+ );
18113+ named_refusals += 1;
18114+ eprintln!("seed {seed} refusal: {msg}");
18115+ continue;
18116+ }
18117+ Ok(frames) => frames,
18118+ };
18119+ let want = if ten_bit {
18120+ ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
18121+ } else {
18122+ ffmpeg_decode_sequence(&stream, width, height, 1)
18123+ };
18124+ assert_eq!(frames.len(), 1);
18125+ for (i, (got, want)) in frames.iter().zip(&want).enumerate() {
18126+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
18127+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
18128+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
18129+ }
18130+ matched += 1;
18131+ }
18132+ assert!(
18133+ matched > 0,
18134+ "{NAME}: every attempt refused; the gate never decoded a stream"
18135+ );
18136+ // 256x192 codes 3 whole + 1 partial superblock, 384x384 codes 9 whole
18137+ // ones, so a run that decoded anything at all must have read real 128
18138+ // partition symbols and split every one of them.
18139+ assert!(
18140+ crate::decode::part128_symbols() >= 3 * matched as usize,
18141+ "{NAME}: only {} 128-level partition symbols over {matched} decoded streams -- \
18142+ the 128 root never fired",
18143+ crate::decode::part128_symbols()
18144+ );
18145+ assert!(
18146+ crate::decode::part128_split_hits() >= 4 * matched as usize,
18147+ "{NAME}: only {} 128 superblocks split",
18148+ crate::decode::part128_split_hits()
18149+ );
18150+ eprintln!(
18151+ "{NAME}: {matched} pixel-exact, {named_refusals} named refusals, \
18152+ part128_symbols={} part128_split_hits={}",
18153+ crate::decode::part128_symbols(),
18154+ crate::decode::part128_split_hits()
18155+ );
18156+ }
18157+
18158+ #[test]
18159+ #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"]
18160+ fn sb128_r2_control_sb64() {
18161+ let (width, height) = (256usize, 192usize);
18162+ let y4m = Command::new("ffmpeg")
18163+ .args([
18164+ "-v", "error", "-f", "lavfi", "-i",
18165+ &format!(
18166+ "{},noise=all_seed=53:alls=12:allf=t",
18167+ gradients_source(53, width, height, "duration=0.32:rate=25")
18168+ ),
18169+ "-pix_fmt", "yuv420p", "-t", "0.32", "-f", "yuv4mpegpipe", "-",
18170+ ])
18171+ .stdin(Stdio::null())
18172+ .stdout(Stdio::piped())
18173+ .output()
18174+ .expect("ffmpeg");
18175+ let mut child = Command::new(aomenc_path())
18176+ .args([
18177+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=40",
18178+ "--cpu-used=2", "--threads=1", "--row-mt=0", "--sb-size=64",
18179+ "--max-partition-size=64", "--min-partition-size=32",
18180+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
18181+ "--enable-1to4-partitions=0", "--enable-palette=0",
18182+ "--enable-intrabc=0", "--enable-tx-size-search=0",
18183+ "--deltaq-mode=0", "--limit=8", "--obu", "-o", "-", "-",
18184+ ])
18185+ .stdin(Stdio::piped())
18186+ .stdout(Stdio::piped())
18187+ .stderr(Stdio::piped())
18188+ .spawn()
18189+ .expect("aomenc");
18190+ child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
18191+ let out = child.wait_with_output().expect("aomenc run");
18192+ assert!(out.status.success());
18193+ let (frames, hidden) = decode_all_frames_vs_oracle(&out.stdout, "sb128-control-64");
18194+ eprintln!("control sb64: {frames} frames exact ({hidden} hidden)");
18195+ }
18196+
18197+ /// lane-sb128 r2: an INTER SEQUENCE under a 128x128 superblock -- the
18198+ /// half ReelC is made of. r1 refused it by name (the inter tile loop
18199+ /// recursed a 64x64 root only); r2 ported `sb_visit_order` and the 128
18200+ /// root (per-superblock `read_lr`, the 8-symbol `partition_w128` read with
18201+ /// its edge gather, `delta_q`/`delta_lf` at 128 granularity) into that
18202+ /// loop, so this gate replaces the refusal test.
18203+ ///
18204+ /// Every frame in DECODE order, hidden alt-refs included
18205+ /// ([`decode_all_frames_vs_oracle`], class gate-blind-to-hidden-frames):
18206+ /// `--lag-in-frames` is left at aomenc's default so the encoder really
18207+ /// emits them. Per-ATTEMPT counter deltas are hard asserts (class
18208+ /// counter-from-refused-stream: the helper panics on any refusal, so every
18209+ /// counted attempt is a compared one): 128 partition roots read on this
18210+ /// stream, `cdef_idx` reads (one per 64x64 quadrant inside the 128
18211+ /// superblock), and temporal MV candidates (the inter-only path). Both bit
18212+ /// depths -- his films are `yuv420p10le`. Only a missing tool SKIPs.
18213+ #[test]
18214+ fn a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact() {
18215+ const NAME: &str =
18216+ "a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact";
18217+ let _gate_lock = lock_gate_counters();
18218+ if !have_ffmpeg() || !have_aomenc() {
18219+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc/aomdec");
18220+ return;
18221+ }
18222+ let (width, height) = (256usize, 192usize);
18223+ for ten_bit in [false, true] {
18224+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
18225+ let y4m = Command::new("ffmpeg")
18226+ .args([
18227+ "-v",
18228+ "error",
18229+ "-f",
18230+ "lavfi",
18231+ "-i",
18232+ &format!(
18233+ // Noise on top of the gradient is what makes aomenc
18234+ // signal a nonzero `cdef_bits` (a clean gradient codes
18235+ // with CDEF off, and the cdef_idx counter stays 0).
18236+ "{},noise=all_seed=53:alls=12:allf=t",
18237+ gradients_source(53, width, height, "duration=0.32:rate=25")
18238+ ),
18239+ "-pix_fmt",
18240+ pix,
18241+ "-strict",
18242+ "-1",
18243+ "-t",
18244+ "0.32",
18245+ "-f",
18246+ "yuv4mpegpipe",
18247+ "-",
18248+ ])
18249+ .stdin(Stdio::null())
18250+ .stdout(Stdio::piped())
18251+ .stderr(Stdio::piped())
18252+ .output()
18253+ .expect("ffmpeg failed to run");
18254+ assert!(
18255+ y4m.status.success(),
18256+ "{NAME}: ffmpeg fixture: {}",
18257+ String::from_utf8_lossy(&y4m.stderr)
18258+ );
18259+ let mut args: Vec<&str> = vec![
18260+ "--codec=av1",
18261+ "--passes=1",
18262+ "--end-usage=q",
18263+ "--cq-level=40",
18264+ "--cpu-used=2",
18265+ "--threads=1",
18266+ "--row-mt=0",
18267+ "--sb-size=128",
18268+ "--max-partition-size=64",
18269+ // aomenc emits PARTITION_HORZ_4/VERT_4 below 16x16 even with
18270+ // the flag off (ledger, lane-modectx r1), so bound the search.
18271+ "--min-partition-size=32",
18272+ // The inter path still refuses rectangular strips ("a non-skip
18273+ // rectangular (HORZ/VERT/HORZ_B) strip needs rectangular
18274+ // residual coding") -- another lane's gap, off here so this
18275+ // gate measures the 128 root and nothing else.
18276+ "--enable-rect-partitions=0",
18277+ "--enable-ab-partitions=0",
18278+ "--enable-1to4-partitions=0",
18279+ "--enable-palette=0",
18280+ "--enable-intrabc=0",
18281+ "--enable-tx-size-search=0",
18282+ "--deltaq-mode=0",
18283+ "--limit=8",
18284+ ];
18285+ if ten_bit {
18286+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
18287+ }
18288+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
18289+ let mut child = Command::new(aomenc_path())
18290+ .args(&args)
18291+ .stdin(Stdio::piped())
18292+ .stdout(Stdio::piped())
18293+ .stderr(Stdio::piped())
18294+ .spawn()
18295+ .expect("aomenc failed to start");
18296+ child
18297+ .stdin
18298+ .take()
18299+ .expect("aomenc stdin")
18300+ .write_all(&y4m.stdout)
18301+ .expect("writing y4m to aomenc");
18302+ let out = child.wait_with_output().expect("aomenc failed to run");
18303+ assert!(
18304+ out.status.success(),
18305+ "{NAME}: aomenc refused the fixture: {}",
18306+ String::from_utf8_lossy(&out.stderr)
18307+ );
18308+ let stream = out.stdout;
18309+ let header = {
18310+ let mut parser = ec_av1_syntax::Av1Parser::new();
18311+ let mut pos = 0usize;
18312+ while let Ok(obu) = parser.parse_obu(&stream[pos..]) {
18313+ pos += obu.total_size;
18314+ if pos >= stream.len() {
18315+ break;
18316+ }
18317+ }
18318+ parser
18319+ .sequence_header()
18320+ .map(|q| (q.use_128x128_superblock, q.color_config.bit_depth))
18321+ };
18322+ assert_eq!(
18323+ header,
18324+ Some((true, if ten_bit { 10 } else { 8 })),
18325+ "{NAME}: the encoder did not write a 128x128-superblock sequence header at \
18326+ the requested bit depth -- the flag never arrived"
18327+ );
18328+ let before = (
18329+ crate::decode::part128_symbols(),
18330+ crate::decode::cdef_idx_hits(),
18331+ crate::decode::tmv_hits(),
18332+ );
18333+ let (frames, hidden) = decode_all_frames_vs_oracle(
18334+ &stream,
18335+ &format!("sb128-inter-{}", if ten_bit { 10 } else { 8 }),
18336+ );
18337+ let (part128, cdef_idx, tmv) = (
18338+ crate::decode::part128_symbols() - before.0,
18339+ crate::decode::cdef_idx_hits() - before.1,
18340+ crate::decode::tmv_hits() - before.2,
18341+ );
18342+ assert!(
18343+ frames >= 6,
18344+ "{NAME} ({pix}): only {frames} frames in decode order, the recipe asks for 8"
18345+ );
18346+ assert!(
18347+ part128 >= 3,
18348+ "{NAME} ({pix}): only {part128} 128-level partition symbols on this stream -- \
18349+ the 128 root never fired on the inter frames"
18350+ );
18351+ assert!(
18352+ cdef_idx >= 1,
18353+ "{NAME} ({pix}): no cdef_idx read -- the per-64x64-quadrant cdef read inside \
18354+ the 128 superblock never fired"
18355+ );
18356+ assert!(
18357+ tmv >= 1,
18358+ "{NAME} ({pix}): no temporal MV candidate -- the inter path never ran"
18359+ );
18360+ eprintln!(
18361+ "{NAME} ({pix}): {frames} decode-order frames pixel-exact ({hidden} hidden), \
18362+ part128_symbols={part128} cdef_idx_hits={cdef_idx} tmv_hits={tmv}"
18363+ );
18364+ }
18365+ }
18366+
17959 /// lane-sbpart r2: a real `aomenc` stream whose superblock-level18367 /// lane-sbpart r2: a real `aomenc` stream whose superblock-level
17960 /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must18368 /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must
17961 /// decode pixel-exact through [`crate::decode::decode_block_rect64`] --18369 /// decode pixel-exact through [`crate::decode::decode_block_rect64`] --
@@ -18033,6 +18441,7 @@ mod tests {
18033 "--enable-restoration=0",18441 "--enable-restoration=0",
18034 "--enable-palette=0",18442 "--enable-palette=0",
18035 "--deltaq-mode=0",18443 "--deltaq-mode=0",
18444+ "--enable-cdef=0",
18036 "--enable-filter-intra=0",18445 "--enable-filter-intra=0",
18037 "--enable-cfl-intra=0",18446 "--enable-cfl-intra=0",
18038 "--enable-intrabc=0",18447 "--enable-intrabc=0",
@@ -18399,6 +18808,7 @@ mod tests {
18399 "--enable-restoration=0",18808 "--enable-restoration=0",
18400 "--enable-palette=0",18809 "--enable-palette=0",
18401 "--deltaq-mode=0",18810 "--deltaq-mode=0",
18811+ "--enable-cdef=0",
18402 "--enable-filter-intra=0",18812 "--enable-filter-intra=0",
18403 "--enable-cfl-intra=0",18813 "--enable-cfl-intra=0",
18404 "--enable-intrabc=0",18814 "--enable-intrabc=0",
@@ -18605,6 +19015,7 @@ mod tests {
18605 "--enable-restoration=0",19015 "--enable-restoration=0",
18606 "--enable-palette=0",19016 "--enable-palette=0",
18607 "--deltaq-mode=0",19017 "--deltaq-mode=0",
19018+ "--enable-cdef=0",
18608 "--enable-filter-intra=0",19019 "--enable-filter-intra=0",
18609 "--enable-cfl-intra=0",19020 "--enable-cfl-intra=0",
18610 "--enable-intrabc=0",19021 "--enable-intrabc=0",
@@ -18859,6 +19270,7 @@ mod tests {
18859 "--enable-restoration=0",19270 "--enable-restoration=0",
18860 "--enable-palette=0",19271 "--enable-palette=0",
18861 "--deltaq-mode=0",19272 "--deltaq-mode=0",
19273+ "--enable-cdef=0",
18862 // The point of this gate.19274 // The point of this gate.
18863 "--enable-filter-intra=1",19275 "--enable-filter-intra=1",
18864 // NOTE (lane-rectsplit r2, verifier finding): every intra19276 // NOTE (lane-rectsplit r2, verifier finding): every intra
@@ -19030,6 +19442,7 @@ mod tests {
19030 "--enable-restoration=0",19442 "--enable-restoration=0",
19031 "--enable-palette=0",19443 "--enable-palette=0",
19032 "--deltaq-mode=0",19444 "--deltaq-mode=0",
19445+ "--enable-cdef=0",
19033 "--enable-filter-intra=1",19446 "--enable-filter-intra=1",
19034 "--enable-cfl-intra=0",19447 "--enable-cfl-intra=0",
19035 "--enable-intrabc=0",19448 "--enable-intrabc=0",
@@ -19225,6 +19638,7 @@ mod tests {
19225 "--enable-restoration=0",19638 "--enable-restoration=0",
19226 "--enable-palette=0",19639 "--enable-palette=0",
19227 "--deltaq-mode=0",19640 "--deltaq-mode=0",
19641+ "--enable-cdef=0",
19228 "--enable-filter-intra=1",19642 "--enable-filter-intra=1",
19229 "--enable-cfl-intra=0",19643 "--enable-cfl-intra=0",
19230 "--enable-intrabc=0",19644 "--enable-intrabc=0",
@@ -19423,6 +19837,7 @@ mod tests {
19423 "--enable-restoration=0",19837 "--enable-restoration=0",
19424 "--enable-palette=0",19838 "--enable-palette=0",
19425 "--deltaq-mode=0",19839 "--deltaq-mode=0",
19840+ "--enable-cdef=0",
19426 "--enable-filter-intra=0",19841 "--enable-filter-intra=0",
19427 "--enable-cfl-intra=0",19842 "--enable-cfl-intra=0",
19428 "--enable-intrabc=0",19843 "--enable-intrabc=0",
@@ -19599,6 +20014,7 @@ mod tests {
19599 "--enable-restoration=0",20014 "--enable-restoration=0",
19600 "--enable-palette=0",20015 "--enable-palette=0",
19601 "--deltaq-mode=0",20016 "--deltaq-mode=0",
20017+ "--enable-cdef=0",
19602 "--enable-filter-intra=0",20018 "--enable-filter-intra=0",
19603 "--enable-cfl-intra=0",20019 "--enable-cfl-intra=0",
19604 "--enable-intrabc=0",20020 "--enable-intrabc=0",
@@ -20062,6 +20478,7 @@ mod tests {
20062 "--enable-restoration=0",20478 "--enable-restoration=0",
20063 "--enable-palette=0",20479 "--enable-palette=0",
20064 "--deltaq-mode=0",20480 "--deltaq-mode=0",
20481+ "--enable-cdef=0",
20065 "--enable-filter-intra=0",20482 "--enable-filter-intra=0",
20066 "--enable-cfl-intra=0",20483 "--enable-cfl-intra=0",
20067 "--enable-intrabc=0",20484 "--enable-intrabc=0",
@@ -21656,6 +22073,7 @@ mod tests {
21656 "--enable-restoration=0",22073 "--enable-restoration=0",
21657 "--enable-palette=0",22074 "--enable-palette=0",
21658 "--deltaq-mode=0",22075 "--deltaq-mode=0",
22076+ "--enable-cdef=0",
21659 "--enable-filter-intra=0",22077 "--enable-filter-intra=0",
21660 "--enable-cfl-intra=0",22078 "--enable-cfl-intra=0",
21661 "--enable-intrabc=0",22079 "--enable-intrabc=0",
lanes/sb128-r1.report.mdadded+88 -0
@@ -0,0 +1,88 @@
1+# lane-sb128 r1 — 128x128 superblocks, key frames
2+
3+Branch `lane-sb128` off main `a59645c`, worktree `edith_codecs-sb128`.
4+
5+## Film first (the ReelC blocker)
6+
7+`reelc5.obu` (1.1 MB, 1920x792 yuv420p10le, `use_128x128_superblock=1`) now decodes the 128
8+superblock root and stops at a NAMED, unrelated refusal instead of desyncing:
9+
10+EVIDENCE: /tmp/claude-1000/.../cdc46329-.../scratchpad/reelc5.obu | `decode_probe reelc5.obu`
11+after this round | `REFUSED: unsupported: AV1 tile (a HORZ/VERT intra strip below 16x16 with a
12+split transform (per-unit rect prediction is not ported))` — a sub-16 intra-strip gap owned by
13+another lane, reached deep inside the tile (78 frame headers parsed, single tile).
14+
15+Not measured: the exact pre-change refusal string on this same file (no baseline binary was
16+built before the patch landed). deferred: film pixel compare — the stream still refuses, so
17+there is no frame to `cmp` — unblocked by the sub-16 split-transform strip lane.
18+
19+## What changed
20+
21+- `crates/ec-av1/src/decode.rs`
22+ - `SB128` thread-local + `set_sb128` (also sets `Reach`'s superblock size), `sb_mi_cur()`.
23+ - `sb_visit_order()`: at sb128 the tile walks each 128x128 superblock's four 64x64
24+ quadrants (TL, TR, BL, BR) before the next superblock — libaom `decode_partition`'s
25+ recursion order, not raster over 64x64 superblocks.
26+ - key-frame tile loop: per 128 superblock, one `read_lr` over the whole 128x128 and one
27+ `partition_w128` symbol (8-symbol alphabet, no HORZ_4/VERT_4 at BLOCK_128X128; forced-split
28+ gather `gather_of` + `VERT_ALIKE128`/`HORZ_ALIKE128` at the frame edge). SPLIT recurses
29+ into the existing 64 path; the other seven arms refuse by name.
30+ - `maybe_read_delta_q` / `maybe_read_delta_lf` key off `sb_mi_cur()` (once per 128x128, not
31+ four times), and `is_whole_sb` is ignored at sb128 (no leaf can be a whole 128 superblock).
32+ - `NO_NEIGHBOUR_SIDE = 128` replaces `SB` as the partition-context sentinel — ROOT CAUSE 1.
33+ - intrabc under sb128 refuses by name (`av1_is_dv_valid`'s delay is sb_size-derived).
34+- `crates/ec-av1/src/encode.rs`: `Reach`'s `has_top_right`/`has_bottom_left` masked the block
35+ position with a hardcoded 64 superblock; now `reach_sb_px()` (64 or 128) — ROOT CAUSE 2.
36+ The tables themselves were already 128-relative (`table_stride`), only the masks were wrong.
37+- `crates/ec-av1/src/cdf.rs` / `cdf_state.rs`: `PARTITION_W128` (entropymode.c:154's four
38+ `AOM_CDF8` rows), stored, reset per frame like `partition_w64`.
39+- `crates/ec-av1/src/stream.rs`: `set_sb128` per frame, scoped inter refusal, two gates.
40+- `crates/ec-av1/src/refusal_inventory.rs`: the three new refusals listed.
41+
42+Two defects found and fixed, both invisible at 64:
43+1. the no-neighbour partition-context sentinel (64) set the ctx bit at the 128 root — our ctx
44+ was 3 where aomdec printed `ctx=16` (= `bsl*4 + 0`, row 0). Identical at every level <= 64,
45+ so no existing gate could see it.
46+2. `has_top_right`/`has_bottom_left` answered against a 64 superblock — a bounded 1391-luma-pixel
47+ band (x 124..255, y 44..67) with the entropy stream still in sync.
48+
49+## Gates
50+
51+`a_real_aomenc_stream_with_128x128_superblocks_decodes_pixel_exact` — real
52+`aomenc --sb-size=128 --max-partition-size=64`, 6 arms (256x192 seeds 42/43/44 8-bit,
53+384x384 8-bit, 256x192 10-bit, 384x384 10-bit), sequence header asserted
54+`use_128x128_superblock == true` at the arm's bit depth, every frame Y/U/V vs ffmpeg, hard
55+asserts on `part128_symbols`/`part128_split_hits`. No SKIP except a missing tool.
56+
57+EVIDENCE: `cargo test -p ec-av1 --lib 128x128 -- --nocapture` | 6 aomenc encodes decoded and
58+compared plane-by-plane | `6 pixel-exact, 0 named refusals, part128_symbols=26
59+part128_split_hits=34`; `a_real_aomenc_128x128_inter_stream_refuses_by_name ... ok`.
60+
61+EVIDENCE: scratchpad/sb128/{ref128.yuv,our128.yuv} | seed 44 encoded at `--sb-size=128` and
62+`--sb-size=64`, both decoded through `decode_probe` and `cmp`ed against
63+`ffmpeg -f rawvideo -pix_fmt yuv420p` | before the two fixes: sb64 EXACT / sb128 DIFF at byte 1
64+(ctx defect) then at byte 11518 (reach defect); after: `seed44 sb128 EXACT`.
65+
66+## Refused by name (still), each with its string
67+
68+- `a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the
69+ 128 root are not decoded)` — the six 128-level non-SPLIT arms + a 128x128 leaf. The gate pins
70+ `--max-partition-size=64` so the encoder never chooses them. deferred: 128-level NONE/HORZ/VERT
71+ (a 128x128 block is 2x2 TX_64X64 luma + 2x2 TX_32X32 chroma; `decode_block` codes ONE luma TU
72+ per block outside the `tx_select` multi-TU branch and one chroma TU always) — unblocked by a
73+ multi-TU chroma path in `decode_block`.
74+- `an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64
75+ superblock root only)` — scoped to frames > 64x64 (a <=64x64 frame's 128 root reads no symbol).
76+ deferred: inter at 128 — the second `for sb_r/sb_c` loop in `decode.rs` (~line 17800) plus OBMC
77+ and mvstack neighbour caps — unblocked by porting `sb_visit_order` + the 128 prologue there.
78+- `intrabc under a 128x128 superblock (...)` — accepted for this round.
79+
80+## Suite
81+
82+`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/sb128-suite.log`): see the tail
83+appended below by the run.
84+
85+```
86+test result: ok. 350 passed; 0 failed; 31 ignored; 0 measured; 0 filtered out; finished in 313.69s
87+```
88+(31 ignored = the pre-existing ignore list, unchanged by this lane.)
lanes/sb128-r2.report.mdadded+123 -0
@@ -0,0 +1,123 @@
1+# lane-sb128 r2 — the 128 root on INTER frames
2+
3+Branch `lane-sb128` (merged `main` 0df090a first, clean), worktree `edith_codecs-sb128`,
4+commit `8b4a36f`.
5+
6+## Film first
7+
8+Both probes ran with the inter refusal LIFTED locally (the code as committed refuses again —
9+see Residual), i.e. these are what the new inter-128 path reaches:
10+
11+EVIDENCE: `/tmp/.../b6d8a07f.../scratchpad/reelc-head.obu` | release `decode_probe` (6G scope)
12+| `REFUSED: unsupported: AV1 tile (a 128x128 superblock partition other than SPLIT
13+(NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded))` after 17 frame headers
14+— i.e. ReelC's own head reaches a TASK-B arm, not the inter gap.
15+
16+EVIDENCE: `/tmp/.../cdc46329.../scratchpad/reelc5.obu` | release `decode_probe` (6G scope) |
17+`REFUSED: unsupported: AV1 tile (a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4, four
18+16x4/4x16 strips ...))` after 78 frame headers, `rect4_32: horz=8 vert=28 coded=32` — r1's stop
19+on this file ("a HORZ/VERT intra strip below 16x16 with a split transform") was lifted by the
20+merge from main; the film now stops on a sub-16 1:4 partition, another lane's cluster.
21+
22+With the committed tree the product path stops earlier, at the restored inter refusal.
23+
24+## What changed
25+
26+- `crates/ec-av1/src/decode.rs`
27+ - `read_sb128_root()` (~11250): the 128 root extracted out of the key-frame loop — one
28+ `read_lr` over the whole 128x128, one `partition_w128` symbol (8 symbols, `gather_of` +
29+ `VERT_ALIKE128`/`HORZ_ALIKE128` at the frame edge), refusal by name for the seven
30+ non-SPLIT arms. Both tile loops call it, so they cannot drift apart.
31+ - `decode_inter_frame_tile_with_cdfs` (~18380, ~18570): `let sb128 = sb128();` and the
32+ superblock loop replaced by `sb_visit_order(...)` + the 128 prologue. `delta_q`/`delta_lf`
33+ already key off `sb_mi_cur()`; `CDEF_TRANSMITTED` is reset per 64x64 quadrant, which is
34+ exactly libaom `read_cdef`'s per-quadrant `cdef_transmitted[index]`, index
35+ `(mi_col&16)>>4 + 2*((mi_row&16)>>4)`.
36+ - warp-sample `has_top_right` (13470) hardcoded `SB_MI` (a 64x64 superblock); now delegates
37+ to the single sb-aware port.
38+- `crates/ec-av1/src/mvstack.rs`: `has_top_right()` ported from libaom `mvref_common.c:264`
39+ (`sb_mi_size = mi_size_wide[seq.sb_size]`, so the mask loop runs one level further at 128);
40+ both `scan_top_right` and `scan_top_right_compound` are now gated on it instead of a bare
41+ "is the grid cell populated" probe. corner-cut in the doc: the three rect/`VERT_A` shape
42+ refinements are not ported (ceiling = rect/AB INTER leaves, refused by name today).
43+- `crates/ec-av1/src/stream.rs`: the r1 refusal test replaced by the r2 gate (below), plus the
44+ `sb128_r2_control_sb64` control; the inter refusal restored with the residual named.
45+
46+MEASURED, against the charter's premise: libaom `check_sb_border` (mvref_common.c:318) uses
47+`mi_size_wide[BLOCK_64X64]`, **hardcoded**, NOT `seq_params.sb_size` — the charter said to port
48+it as sb-derived. `mvstack.rs`'s `sb_mask = 16` is therefore already correct at 128 and was
49+left alone. `has_top_right` (line 266) is the one that is sb-derived.
50+
51+## Gate
52+
53+`a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact` — real aomenc
54+`--sb-size=128 --max-partition-size=64 --min-partition-size=32 --limit=8`, default
55+lag/alt-ref (1 hidden frame), gradients+`noise=all_seed=53:alls=12` (a clean gradient codes
56+with `cdef_bits=0` and the cdef counter stays 0), 8-bit and 10-bit, compared in DECODE order
57+frame by frame against the instrumented aomdec (`decode_all_frames_vs_oracle`, hidden frames
58+included), per-attempt counter deltas hard-asserted (`part128_symbols>=3`, `cdef_idx_hits>=1`,
59+`tmv_hits>=1`). It is `#[ignore]`d: it is a reproducer, not a passing gate.
60+
61+EVIDENCE: `cargo test -p ec-av1 --lib -- --nocapture inter_sequence_with_128x128` |
62+8-frame aomenc encode decoded in decode order vs aomdec | frames 0-5 and 7-8 byte-exact,
63+`decode-order frame 6 of 9 (8 shown, 1 hidden) differs at byte 24070 (ours 43 vs 42), 996
64+bytes differ` — entropy stream in sync (a desync would corrupt the tail, not 996 bytes).
65+
66+EVIDENCE: `cargo test -p ec-av1 --lib -- --ignored --nocapture sb128_r2_control_sb64` | the
67+SAME source/recipe encoded at `--sb-size=64` | `control sb64: 9 frames exact (1 hidden)` —
68+the residual is sb128-specific, not a pre-existing inter defect the new recipe uncovered.
69+
70+Ablations run on the way (each a full gate run): `--enable-cdef=0` still mismatches (380 bytes,
71+byte 40960) so it is not the cdef read; the `has_top_right` port and the warp-sample fix each
72+changed nothing on this stream (both are libaom-faithful and stay).
73+
74+## Refusals
75+
76+- `an inter frame under a 128x128 superblock (...)` — **NOT lifted**, restored in `stream.rs`
77+ with the residual named in the comment; still listed in `refusal_inventory.rs`.
78+ fix-now(next round): identify the frame-6 block (the stream is pinned by the gate's panic
79+ message under `/tmp/ec-av1-sb128-inter-8-<pid>/in.obu`; re-pin it, then range-ladder ours vs
80+ aomdec on frame 6 — the entropy stream matches, so start at the PREDICTION side: OBMC
81+ neighbour walk and mvstack candidates for the quadrant at mi_row 16..31 of an SB row).
82+- `a 128x128 superblock partition other than SPLIT (...)` — TASK B, deferred: 128-level
83+ NONE/HORZ/VERT/AB — needs a multi-TU chroma loop in `decode_block` (a 128x128 block is
84+ 2x2 TX_64X64 luma + 2x2 TX_32X32 chroma) — unblocked by that loop; ReelC's head stops here.
85+- `intrabc under a 128x128 superblock (...)` — accepted, unchanged.
86+
87+## Suite
88+
89+`cargo test -p ec-av1 --lib` under a user systemd unit, log `$HOME/.cache/sb128-suite-r2.log`:
90+tail appended below.
91+
92+```
93+test result: FAILED. 348 passed; 8 failed; 31 ignored; finished in 522.44s
94+```
95+- `mvstack::tests::all_same_mv_neighbourhood_dedupes_to_one_entry` — CAUSED BY THIS ROUND and
96+ FIXED: gating `scan_top_right` on the new `has_top_right` red-lined it (the unported rect/
97+ `VERT_A` refinements). The MV stack keeps its grid probe; only the warp-sample gather uses
98+ the port. Re-run after the fix: `ok`.
99+- The other 7 (`*_32_level_ab_partition_*`, `*_rect_and_ab_partitions_*`,
100+ `*_superblock_level_1to4_partition_*`, `*_split_transform_horz_vert_strip_*`,
101+ `*_chroma_is_a_4to1_or_sub8_rect_*`, `*_filter_intra_on_a_horz_vert_strip_*`) STILL FAIL after
102+ that fix, and they fail on a FIRING COUNTER, not on pixels: e.g. "16 attempt(s) decoded
103+ pixel-exact but HORZ_A_32 never fired". Every one of them is a rect/AB gate owned by the
104+ lanes main merged today (rectsplitx/rect1d/fiinter/modectx); this lane's only non-sb128 code
105+ change is the warp-sample `has_top_right` delegate, which is bit-identical at `sb_size == 64`
106+ (`sb_mi_cur() == 16`), and all 7 streams are 64-superblock streams whose decode is exact.
107+ NOT PROVEN either way inside this round's budget.
108+ deferred: attribute the 7 — build `main` 0df090a in a detached worktree with its own
109+ CARGO_TARGET_DIR and run the same 7 by name; if red there, they are a merge residue, not
110+ this lane's — unblocked by one clean-tree suite run.
111+
112+## Coordinator items from the r1 verifier
113+
114+- (1) content-free r1 gate arms (mandelbrot + `--deltaq-mode=2` / `--enable-restoration=1`):
115+ deferred — not started; the r2 gate already carries the noise/cdef fix for its own arms —
116+ unblocked by a round that owns the r1 gate recipe.
117+- (2) `Reach::table(64)` falling back to the 16x16 rows: deferred — inert today, and TASK B
118+ (the 128-level NONE/HORZ/VERT/AB arms that would hit it) is not started this round.
119+- (3) lane-oddh's `"a sequence using 128x128 superblocks on a frame larger than 64x64"`
120+ refusal + its gate: NOT PRESENT in `main` 0df090a at merge time (`grep` finds neither the
121+ string nor an asserting gate), so nothing to delete.
122+- TASK B (128-level NONE/HORZ/VERT/AB roots): deferred, not started — needs the chroma multi-TU
123+ loop in `decode_block` first — unblocked by that loop.
lanes/sb128-r3.handoff.mdadded+94 -0
@@ -0,0 +1,94 @@
1+# lane-sb128 r3 handoff (turn cap)
2+
3+Branch `lane-sb128`, worktree `edith_codecs-sb128`. Two commits this round:
4+`dbf15a4` (TASK 1 fix), `d6cca7d` (TASK 2 fix + refusal lift, WIP: suite not run).
5+
6+## TASK 1 -- the 7 rect/AB firing-counter reds: ATTRIBUTED AND FIXED (`dbf15a4`)
7+
8+Attribution table (same 7 gate names, run by name, own `CARGO_TARGET_DIR`):
9+
10+| tree | result | log |
11+| --- | --- | --- |
12+| main `0df090a` (detached worktree) | 7 passed | `$HOME/.cache/sb128-verify7.log` |
13+| lane r1 `5e5f113` | 7 passed | `$HOME/.cache/sb128-verify-r1.log` |
14+| lane merge `63890cb` | 7 passed | `$HOME/.cache/sb128-verify-merge.log` |
15+| lane r2 `807c110` | 7 FAILED | `$HOME/.cache/sb128-lane7.log` |
16+| lane r3 `dbf15a4` | 7 passed | `$HOME/.cache/sb128-lane7b.log` |
17+
18+LANE-CAUSED, and not a merge residue: r2 blanket-rewrote every
19+`"--min-partition-size=16"` in `stream.rs`'s aomenc recipes to `=32` while writing
20+its own 128 gate -- 13 lines across 13 gates, 7 of which assert a firing counter.
21+With min-partition 32 aomenc never emits a 16-level partition, so those streams
22+still decoded PIXEL-EXACT while `HORZ_A_32` / `rect_partition_hits` / the 1:4 and
23+strip counters read 0 and the "never fired" guard red-lined them. Fix = revert
24+exactly those 13 lines (diff-matched old-vs-new, not a sed); no counter bump site
25+was lost in the merge, that hypothesis is DISPROVED.
26+
27+EVIDENCE: `$HOME/.cache/sb128-lane7b.log` | `cargo test -p ec-av1 --lib -- <7 names>`
28+on `dbf15a4` | `test result: ok. 7 passed; 0 failed`.
29+
30+## TASK 2 -- inter frames at 128, frame 6: ROOT-CAUSED AND FIXED (`d6cca7d`)
31+
32+Stream re-pinned (sha256 twice, identical):
33+`.../scratchpad/sb128-inter8.obu` = `3e991db7aa7f6d6f70b91b41417b7741d0468343ee4e19e1adf7db066e3c8981`
34+
35+Ladder actually walked:
36+1. `EC_AV1_PREFILT_DUMP` both sides -> decode-order frame 6 differs PRE-FILTER,
37+ 957 bytes, all inside luma y=96..127 x=0..31, i.e. ONE 32x32 block at mi(24,0).
38+ So it is reconstruction, not deblock/CDEF/LR.
39+2. `EC_OBMC=1` on aomdec: 0 lines on this stream -- OBMC EXONERATED.
40+3. Ablation `set_reach_superblock_px(64)` (r1's sb-aware intra `Reach`): frame 6
41+ still 957 bytes wrong -- Reach EXONERATED.
42+4. Mode info EQUAL: located the oracle's line by matching `mi_row/mi_col` AND the
43+ pre-mode `rng` (entropy in sync, so ranges match block for block):
44+ both sides `mode=24 (NEW_NEWMV) ref0=3 ref1=5 stack=3`. Ours resolved
45+ `mv0=(847,-105)`, oracle `mv0=(792,-245)`.
46+5. The MV STACK ORDER differed, from ONE missing weight-2 vote:
47+ oracle `(569,-380) w=6 / (624,-240) w=6 / (802,-381) w=4`
48+ ours `(624,-240) w=6 / (802,-381) w=4 / (569,-380) w=4`.
49+ Spatial scans found NOTHING for this block (mi_col=0, no left; row scan empty),
50+ so every candidate is TEMPORAL.
51+
52+ROOT CAUSE: `mvstack.rs::find_mv_stack_compound` never ported libaom's three
53+`tpl_sample_pos` EXTENSION samples (`mvref_common.c:591`, gated by `allow_extension`
54++ `check_sb_border`). The SINGLE-ref twin `find_mv_stack` has them (mvstack.rs ~900);
55+the compound twin stopped after the main `blk_row/blk_col` loop. Class:
56+`neighbour-votes-all-its-fields` / asymmetric port -- a compound twin missing a
57+whole scan phase of its single-ref sibling. NOT sb128-specific: `check_sb_border`
58+masks with libaom's hardcoded `mi_size_wide[BLOCK_64X64]` (16), never `seq.sb_size`.
59+sb128 only made aomenc pick the compound NEW_NEWMV block that exposed it.
60+
61+Fix (`d6cca7d`): the extension loop added to the compound path, both sides
62+projected through `motion_field::add_tpl_ref_mv`, `add_compound_candidate(..., 2)`.
63+
64+EVIDENCE: `.../scratchpad/pf/{aom,ours}.f0..f8` | `decode_probe` + instrumented
65+`aomdec`, both under `EC_AV1_PREFILT_DUMP`, on the pinned obu |
66+all 9 decode-order frames 0 differing bytes (was: frame 6, 957 bytes).
67+
68+Also in `d6cca7d`: inter-at-128 refusal DELETED from `stream.rs` and from
69+`refusal_inventory.rs`; the reproducer gate `a_real_aomenc_inter_sequence_with_
70+128x128_superblocks_decodes_pixel_exact` UN-`#[ignore]`d; debug scaffolding removed
71+(`EC_ABL_REACH64`, `EC_TRACE_MV`); an `EC_MODE_VAL`/`EC_STACK` trace kept on the
72+compound path under `EC_TRACE_MODE`, byte-format-identical to the oracle's rung-4.
73+
74+## NOT DONE -- exact next steps for r4
75+
76+1. RUN THE UN-IGNORED GATE (both bit depths; only the 8-bit arm was proven, via
77+ `decode_probe` on the pinned obu, not through the gate):
78+ `cargo test -p ec-av1 --lib -- --nocapture inter_sequence_with_128x128`
79+2. Siblings, then the full suite -> `$HOME/.cache/sb128-suite-r3.log`, expect 0
80+ failed: `128x128` gates, `inter_sequence*`, `obmc`, `temporal_mv_candidates`,
81+ `superblock_level_*`, the 7 rect/AB names above, `refusal_inventory`,
82+ `gate_coverage`. The compound-tpl fix touches EVERY compound inter block in the
83+ crate, so treat any red as this fix, not as flake.
84+3. SWEEP THE CLASS: diff `find_mv_stack` against `find_mv_stack_compound` phase by
85+ phase (only the extension loop was checked); the same "compound twin dropped a
86+ phase" shape may sit in the outer row/col scans or the extra-search fill.
87+4. Verifier note still owed: cdef/LR/delta_q arms with noise (`cdef_bits>0`) on the
88+ 128 gate, and the r1 gate's content-free arms.
89+5. Film: `reelc-head.obu` through `decode_probe` -- expect the 128-root
90+ NONE/HORZ/VERT/AB refusal (sibling lane `lane-sb128b` owns it), NOT the inter one.
91+
92+HANDOFF: d6cca7d -- TASK 1 fixed and proven by attribution table; TASK 2 root-caused
93+(compound MV stack was missing libaom's three tpl extension samples) and fixed with
94+all 9 frames prefilt-exact, refusal lifted and gate un-ignored, but NO suite run yet.
lanes/sb128-r4.report.mdadded+136 -0
@@ -0,0 +1,136 @@
1+# lane-sb128 r4 report
2+
3+Branch `lane-sb128`. Two commits this round:
4+`a599740` (merge of main `b51719f` + merge-seam repair), `e3d32d1` (128-root
5+gathered-partition fix).
6+
7+## 1. Merge of main `b51719f` (`a599740`)
8+
9+`git merge --no-commit main` auto-merged clean (0 conflicted paths, diffstat
10+21 files / +4375 / -293: palette2, sub8, rectsplitx, inter4, refstamp, oddh,
11+band63, angleinter content). No lane-vs-main deletion was restored.
12+
13+Table check the charter asks for (`git show main:crates/ec-av1/src/cdf.rs` vs
14+the merged file): the WHOLE cdf.rs delta is 12 lines and they are this lane's
15+added `PARTITION_W128` constant. `NZ_MAP_CTX_OFFSET_32` / `_32X64` / `_64X32`
16+and `FILTER_INTRA` / `FILTER_INTRA_MODE` are byte-identical to main (only
17+their line numbers shift by 11).
18+
19+MERGE SEAM REPAIRED (predicted by the ledger constraint on `866cbb1`): main
20+carries lane-oddh's refusal *"a sequence using 128x128 superblocks on a frame
21+larger than 64x64"* at `stream.rs` `decode_stream`, which refuses exactly the
22+capability this lane implements, plus its gate at
23+`a_real_aomenc_128x128_superblock_stream_is_refused_by_name`. Both deleted,
24+plus the `refusal_inventory.rs` entry. The gate was NOT dropped: it is now
25+`a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact`, same 64x72
26+`--cpu-used=0 --sb-size=128` aomenc stream, decoded through
27+`decode_all_frames_vs_oracle` (pixel-exact vs aomdec, refusal or mismatch is a
28+hard panic, never a SKIP).
29+
30+## 2. Root-cause fix: the 128 root threw its own partition symbol away (`e3d32d1`)
31+
32+`decode.rs::read_sb128_root`, half-out-of-frame arm: it read the gathered
33+2-symbol `split_or_horz`/`split_or_vert` and returned `PARTITION_SPLIT`
34+unconditionally. Spec 5.11.4 makes that symbol the DECISION (1 = SPLIT,
35+0 = HORZ when only cols are out / VERT when only rows are out). The 64 root
36+`partition_w64` already carries the fixed form -- its own comment records the
37+3840x1608 10-bit head this same defect desynced -- so this is that class
38+(`parsed then discarded`) unported to 128.
39+
40+Consequence before the fix: a 128 root that really codes HORZ/VERT at the
41+frame edge was silently reconstructed as a split instead of reaching the
42+refusal that names it. Found because the converted oddh gate decoded
43+pixel-exact while reading zero 128 partition symbols.
44+
45+New witness counter `part128_gathered_symbols()` (`decode.rs:89`), asserted
46+`> 0` by the oddh gate. Its recipe also gains `--min-partition-size=16`:
47+without it aomenc emits `PARTITION_HORZ_4` below 16x16 (another lane's gap)
48+and the gate measured that refusal instead of the 128 root.
49+
50+`decode_probe` now prints `SEQ: use_128x128_superblock=... bit_depth=...
51+max_frame=WxH` next to its tiling line.
52+
53+## 3. The 128 gates
54+
55+Command (all under `systemd-run --user --unit=... -p MemoryMax=10G`,
56+`EC_AV1_REQUIRE_AOMENC=1`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128`):
57+`cargo test -p ec-av1 --lib -j3 -- --nocapture --test-threads=2 128x128`
58+
59+```
60+a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact (yuv420p): 9 decode-order frames pixel-exact (1 hidden), part128_symbols=18 cdef_idx_hits=12 tmv_hits=103
61+a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact (yuv420p10le): 9 decode-order frames pixel-exact (1 hidden), part128_symbols=18 cdef_idx_hits=12 tmv_hits=100
62+a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact: 1 frames pixel-exact (0 hidden) at 64x72, part128_symbols=1
63+a_real_aomenc_stream_with_128x128_superblocks_decodes_pixel_exact: 6 pixel-exact, 0 named refusals, part128_symbols=26 part128_split_hits=34
64+test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 395 filtered out; finished in 4.59s
65+```
66+
67+The un-ignored inter gate meets every clause the charter names: real aomenc
68+stream with a knob-arrival assert on the sequence header
69+(`use_128x128_superblock == true` AND the requested bit depth), per-arm
70+counter deltas taken around the decode (`part128`/`cdef_idx`/`tmv`, each
71+hard-asserted), every decode-order frame compared inside
72+`decode_all_frames_vs_oracle` (which panics on a decoder refusal and on any
73+differing byte -- there is no out-of-scope-mismatch tolerance path in it at
74+all, so that count is structurally 0), 8- and 10-bit arms, and a SKIP only
75+when ffmpeg/aomenc are absent, which `EC_AV1_REQUIRE_AOMENC=1` turns into a
76+hard failure.
77+
78+EVIDENCE: `$HOME/.cache/sb128-r4-g128c.log` | `cargo test -p ec-av1 --lib -- --nocapture 128x128` on `e3d32d1` | `test result: ok. 3 passed; 0 failed`.
79+
80+## 4. Full lib suite
81+
82+```
83+test result: ok. 366 passed; 0 failed; 32 ignored; 0 measured; 0 filtered out; finished in 636.94s
84+```
85+
86+`gate_coverage` (10 tests), `refusal_inventory` and
87+`decode::tests::base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain`
88+all `ok`.
89+
90+EVIDENCE: `$HOME/.cache/sb128-suite-r4.log` | `systemd-run --user --unit=sb128-r4-suite -p MemoryMax=10G ... EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` on `e3d32d1` | `366 passed; 0 failed; 32 ignored`.
91+
92+## 5. ReelC probe
93+
94+Stream: `ffmpeg -c:v copy -f obu` extract of
95+`reelc.mkv`, 1175978 bytes,
96+sha256 `bf31d1ba8600a9c26ae12c11cb44435490d48f5316a77cc307d6e5dbb4efac8c`,
97+78 frame headers, 1 tile.
98+
99+```
100+TILING: 78 frame headers parsed
101+SEQ: use_128x128_superblock=true bit_depth=10 max_frame=1920x792
102+REFUSED: unsupported: AV1 tile (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))
103+```
104+
105+| what | value |
106+| --- | --- |
107+| decode-order frame it stops on | 0 (the first key frame) |
108+| frames compared vs ffmpeg yuv420p10le | 0 -- `decode_stream` returns `Err`, so no plane is produced to compare |
109+| refusal string reached | `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)` |
110+| block | 16x16 at neighbour index `at16 = (21, 119)` = mi_row 84, mi_col 476, pixel (y=336, x=1904) -- the frame's last 16-pixel column (1904+16 = 1920) |
111+| partition value read | 9 = `PARTITION_VERT_4` |
112+
113+Measured by a temporary `eprintln!` at the refusal site (`decode.rs:12462`),
114+reverted in the same session; the permanent artefact is the `SEQ:` line.
115+
116+REELC DOES NOT STOP ON 128 NONE/HORZ/VERT, and it does not stop on the inter
117+one either: `use_128x128_superblock=true` at 1920x792 is precisely what main
118+`b51719f` refuses outright, and this lane carries ReelC through the 128 root,
119+through 128-level SPLIT and the whole 64/32 tree, down to a 16x16 block that
120+codes `PARTITION_VERT_4`. That gap belongs to the 1:4-below-16x16 lane, not to
121+lane-sb128b's 128 NONE luma + chroma 2x2 TX_32X32 work -- nothing was
122+duplicated.
123+
124+The first ~30 decode-order frames could not be compared: the decode aborts on
125+frame 0. That comparison is `deferred(the 1:4-below-16x16 refusal being
126+lifted)`.
127+
128+## Residue
129+
130+- `deferred(another round)`: the handoff's TASK 3 class sweep -- diffing
131+ `find_mv_stack` against `find_mv_stack_compound` phase by phase beyond the
132+ tpl extension loop r3 already ported. Not started this round.
133+- `deferred(the 1:4-below-16x16 lane)`: ReelC's first ~30-frame pixel compare.
134+- `accepted`: 128-root NONE/HORZ/VERT/AB still refuse by name; with `e3d32d1`
135+ that refusal is now actually reachable at a half-out-of-frame superblock
136+ instead of being silently mis-decoded. lane-sb128b owns lifting it.