forge
Explore
Log in

Don't you dare go Hollow

PARTITION_HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 for intra frames

Browse files at this commit

95d852314f54a1793dad826030a61c0e7ea95f14Ahmet Kaan GümüşParent: 725112d
  • feat
    • PARTITION_HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 for intra frames
Show full message
feat(av1): PARTITION_HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 for intra frames

Two 8x8 squares (decode_leaf8) plus one 16x8/8x16 strip (decode_leaf_rect's
real non-skip coefficient path) per arm, libaom visit order, VERT_A/_B under
Reach::vert_ab_partition() (lane-part32 fd1a2eb's encode.rs half cherry-picked).
Lifts 'a HORZ_A/HORZ_B/VERT_A partition below 16x16' (narrowed to the 1:4 case)
and 'a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16' (dead branch
deleted), gated by 6 real aomenc streams, 8-bit and 10-bit, each arm asserted:
ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2,1,2,1], all pixel-exact vs ffmpeg.

Also, coordinator-reported base defects fixed here (same hunks on lane-sub8 r6 /
lane-rectx r5): mi-exact mode map read with tile-relative guards and reset in
start_tile/start_row; has_tr/has_bl rect index uses MAX_MIB_SIZE_LOG2 (5), not 4.
crates/ec-av1/src/decode.rsmodified+158 -104
@@ -412,6 +412,29 @@ pub(crate) fn vert_b_intra_hits() -> usize {
412 VERT_B_INTRA_HITS.with(|c| c.get())412 VERT_B_INTRA_HITS.with(|c| c.get())
413 }413 }
414 414
415+// lane-ab16 r1: how many 16x16-level AB partitions fired, per arm, in
416+// `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order. Each arm is two
417+// 8x8 squares (`decode_leaf8`) plus one 16x8/8x16 strip (`decode_leaf_rect`,
418+// the non-skip coefficient path lane-rectx proved); the gate hard-asserts
419+// every arm separately so a run where aomenc's RD only picked one cannot
420+// pass as proof of four.
421+thread_local! {
422+ static AB16_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
423+}
424+
425+/// [`AB16_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16).
426+pub(crate) fn ab16_hits_by_arm() -> [usize; 4] {
427+ AB16_HITS.with(std::cell::Cell::get)
428+}
429+
430+fn bump_ab16(arm: usize) {
431+ AB16_HITS.with(|c| {
432+ let mut v = c.get();
433+ v[arm] += 1;
434+ c.set(v);
435+ });
436+}
437+
415 // How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/438 // How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/
416 // `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above439 // `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above
417 // showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7),440 // showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7),
@@ -2035,6 +2058,17 @@ impl Neighbours {
2035 self.above_compound_idx[i] = 0;2058 self.above_compound_idx[i] = 0;
2036 self.above_filter[i] = [3u8; 2];2059 self.above_filter[i] = [3u8; 2];
2037 }2060 }
2061+ // lane-ab16 r1 (coordinator-reported base defect, same fix as
2062+ // lane-sub8 r6): the mi-exact mode map is per-tile like every array
2063+ // above it -- left un-reset, a new tile column's first block read a
2064+ // mode recorded by the tile to its left/above and desynced
2065+ // `kf_y_mode` at the very first block of the tile.
2066+ for i in col0_mi.min(end)..end {
2067+ if let Some(slot) = self.sub8_mode_col.get_mut(i) {
2068+ *slot = (usize::MAX, 0);
2069+ }
2070+ }
2071+ self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
2038 }2072 }
2039 2073
2040 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`2074 /// Writes a just-decoded block's own palette-Y size/colours (`size == 0`
@@ -2292,6 +2326,7 @@ impl Neighbours {
2292 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);2326 self.left_comp_group_idx.iter_mut().for_each(|r| *r = 0);
2293 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);2327 self.left_compound_idx.iter_mut().for_each(|r| *r = 0);
2294 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);2328 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
2329+ self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0));
2295 }2330 }
2296 2331
2297 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next2332 /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next
@@ -2557,14 +2592,14 @@ impl Neighbours {
2557 /// construction). See [`Self::record_mode_mi`].2592 /// construction). See [`Self::record_mode_mi`].
2558 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2593 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2559 match self.sub8_mode_col.get(mi_c) {2594 match self.sub8_mode_col.get(mi_c) {
2560- Some(&(row, m)) if mi_r > 0 && row == mi_r - 1 => Some(m),2595+ Some(&(row, m)) if mi_r > self.tile_row0_mi && row == mi_r - 1 => Some(m),
2561 _ => None,2596 _ => None,
2562 }2597 }
2563 }2598 }
2564 2599
2565 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {2600 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
2566 match self.sub8_mode_row.get(mi_r) {2601 match self.sub8_mode_row.get(mi_r) {
2567- Some(&(col, m)) if mi_c > 0 && col == mi_c - 1 => Some(m),2602+ Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => Some(m),
2568 _ => None,2603 _ => None,
2569 }2604 }
2570 }2605 }
@@ -3398,21 +3433,6 @@ fn decode_block_rect(
3398 vec![0i32; chroma_w * chroma_h],3433 vec![0i32; chroma_w * chroma_h],
3399 ],3434 ],
3400 );3435 );
3401- } else if (bw, bh) != (32, 16) && (bw, bh) != (16, 32) {
3402- // lane-rect16 r1: a real (non-skip) coefficient read at this size
3403- // (8x16/16x32 VERT_B's own left strip) is not ported -- it needs its
3404- // own `TxbSet`/`eob_pt` tables (a true 128-position luma group has no
3405- // `EOB_PT_128_LUMA` in this decoder yet, only the *chroma* one
3406- // `lane-rectwire` built for `ChromaRect16x8`) and, unlike the 32x32
3407- // sqr-up case `LumaRect32x16` safely skips, `get_ext_tx_set_type`
3408- // does NOT return `EXT_TX_SET_DCTONLY` at a 16x16 sqr-up under this
3409- // encoder's reduced_tx_set -- a real `tx_type` symbol may be coded
3410- // that no table here reads. Refused by name rather than guess-decoded
3411- // or silently desynced.
3412- return Err(unsupported(
3413- "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only \
3414- the skip case at this size)",
3415- ));
3416 } else {3436 } else {
3417 // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx`3437 // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx`
3418 // reduces both size pairs to their square-up CDF sets3438 // reduces both size pairs to their square-up CDF sets
@@ -7137,92 +7157,126 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7137 )?;7157 )?;
7138 continue;7158 continue;
7139 }7159 }
7140- if part16 == PARTITION_VERT_B {7160+ if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16) {
7141- VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1));7161+ // lane-ab16 r1: the four AB (T-shaped) partitions at the 16x16
7142- // Left rect: 8x16, real7162+ // level -- two 8x8 squares plus one 16x8/8x16 strip. libaom's
7143- // `decode_block_rect`, sat at the7163+ // `decode_partition` visit order (decodeframe.c):
7144- // 16x16 parent's own origin (no7164+ // HORZ_A: TL 8x8, TR 8x8, bottom 16x8
7145- // fractional-SUB-grid pixel7165+ // HORZ_B: top 16x8, BL 8x8, BR 8x8
7146- // offset needed -- the plain7166+ // VERT_A: TL 8x8, BL 8x8, right 8x16
7147- // HORZ/VERT arms this lane's7167+ // VERT_B: left 8x16, TR 8x8, BR 8x8
7148- // charter named DO need one,7168+ // The squares go through `decode_leaf8`, the strip through
7149- // since their second half is7169+ // `decode_leaf_rect` (real, non-skip 16x8/8x16 coefficients --
7150- // offset by half the parent;7170+ // lane-rectx r2-r4; the older `decode_block_rect` this VERT_B arm
7151- // unported, see decode_block_rect's7171+ // used refuses the non-skip case at this size). Both writers keep
7152- // own doc comment).7172+ // mi-granular mode/skip/palette records, so a later block's
7153- decode_block_rect(7173+ // `above_mi`/`left_mi` sees the real sub-block, not the coarse
7154- &mut dec,7174+ // 16x16 cell.
7155- &mut cdfs,7175+ //
7156- &mut neighbours,7176+ // VERT_A/VERT_B visit TL,BL,TR,BR, so the bottom-left square's
7157- at16,7177+ // top-right neighbour is the partition's own not-yet-decoded
7158- 8,7178+ // rectangle: libaom switches those squares onto `has_tr_vert_*`/
7159- 16,7179+ // `has_bl_vert_*` (`reconintra.c` `get_has_tr_table`), which is
7160- &mut y,7180+ // `Reach::vert_ab_partition()` (lane-part32 r5, cherry-picked here).
7161- &mut u,7181+ let arm = part16 - PARTITION_HORZ_A;
7162- &mut v,7182+ bump_ab16(arm);
7163- enable_filter_intra,7183+ if part16 == PARTITION_VERT_B {
7164- allow_screen_content_tools,7184+ VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1));
7165- base_q_idx,7185+ }
7166- tx_select,7186+ let _vert_guard = if part16 == PARTITION_VERT_A || part16 == PARTITION_VERT_B {
7167- )?;7187+ Some(crate::encode::Reach::vert_ab_partition())
7168- // Two 8x8 squares stacked on the7188+ } else {
7169- // right, chained through7189+ None
7170- // `prev_leaf` exactly like the7190+ };
7171- // real (non-straddle) SPLIT path7191+ let (mi_row0, mi_col0) = (sr * SUB_MI as usize, sc * SUB_MI as usize);
7172- // below: the bottom leaf's ABOVE7192+ macro_rules! ab_leaf8 {
7173- // context is the top leaf, not7193+ ($mi:expr, $prev:expr) => {
7174- // the coarse SUB-grid array (a7194+ decode_leaf8(
7175- // real block never sat there).7195+ &mut dec,
7176- let (mi_row0, mi_col0) =7196+ &mut cdfs,
7177- (sr as u32 * SUB_MI, sc as u32 * SUB_MI);7197+ &mut neighbours,
7178- let top_right =7198+ at16,
7179- (mi_row0 as usize, mi_col0 as usize + 2);7199+ $mi,
7180- let bot_right =7200+ (&scan8, &scan4),
7181- (mi_row0 as usize + 2, mi_col0 as usize + 2);7201+ $prev,
7182- let mode_tr = decode_leaf8(7202+ &mut y,
7183- &mut dec,7203+ &mut u,
7184- &mut cdfs,7204+ &mut v,
7185- &mut neighbours,7205+ base_q_idx,
7186- at16,7206+ enable_filter_intra,
7187- top_right,7207+ allow_screen_content_tools,
7188- (&scan8, &scan4),7208+ allow_intrabc,
7189- &[],7209+ tx_select,
7190- &mut y,7210+ reduced_tx_set,
7191- &mut u,7211+ )?
7192- &mut v,7212+ };
7193- base_q_idx,7213+ }
7194- enable_filter_intra,7214+ macro_rules! ab_strip {
7195- allow_screen_content_tools,7215+ ($mi:expr, $bw:expr, $bh:expr, $prev:expr) => {
7196- allow_intrabc,7216+ decode_leaf_rect(
7197- tx_select,7217+ &mut dec,
7198- reduced_tx_set,7218+ &mut cdfs,
7199- )?;7219+ &mut neighbours,
7200- let mode_br = decode_leaf8(7220+ at16,
7201- &mut dec,7221+ $mi,
7202- &mut cdfs,7222+ $bw,
7203- &mut neighbours,7223+ $bh,
7204- at16,7224+ $prev,
7205- bot_right,7225+ &mut y,
7206- (&scan8, &scan4),7226+ &mut u,
7207- &[(top_right, mode_tr)],7227+ &mut v,
7208- &mut y,7228+ enable_filter_intra,
7209- &mut u,7229+ allow_screen_content_tools,
7210- &mut v,7230+ base_q_idx,
7211- base_q_idx,7231+ tx_select,
7212- enable_filter_intra,7232+ reduced_tx_set,
7213- allow_screen_content_tools,7233+ )?
7214- allow_intrabc,7234+ };
7215- tx_select,7235+ }
7216- reduced_tx_set,7236+ let tl = (mi_row0, mi_col0);
7217- )?;7237+ let tr = (mi_row0, mi_col0 + 2);
7218- // `record()`'s above_mode/left_mode7238+ let bl = (mi_row0 + 2, mi_col0);
7219- // write is a no-op at an 8x87239+ let br = (mi_row0 + 2, mi_col0 + 2);
7220- // leaf's own side (same gap the7240+ let mut done: Vec<((usize, usize), usize)> = Vec::new();
7221- // real-SPLIT path above patches):7241+ match part16 {
7222- // force it from the last-decoded7242+ PARTITION_HORZ_A => {
7223- // (bottom-right) leaf.7243+ let m_tl = ab_leaf8!(tl, &done);
7224- neighbours.above_mode[sc] = mode_br;7244+ done.push((tl, m_tl));
7225- neighbours.left_mode[sr] = mode_br;7245+ let m_tr = ab_leaf8!(tr, &done);
7246+ done.push((tr, m_tr));
7247+ let m_bot = ab_strip!(bl, 16, 8, Some((tl, m_tl)));
7248+ done.push((bl, m_bot));
7249+ }
7250+ PARTITION_HORZ_B => {
7251+ let m_top = ab_strip!(tl, 16, 8, None);
7252+ done.push((tl, m_top));
7253+ let m_bl = ab_leaf8!(bl, &done);
7254+ done.push((bl, m_bl));
7255+ let m_br = ab_leaf8!(br, &done);
7256+ done.push((br, m_br));
7257+ }
7258+ PARTITION_VERT_A => {
7259+ let m_tl = ab_leaf8!(tl, &done);
7260+ done.push((tl, m_tl));
7261+ let m_bl = ab_leaf8!(bl, &done);
7262+ done.push((bl, m_bl));
7263+ let m_right = ab_strip!(tr, 8, 16, Some((tl, m_tl)));
7264+ done.push((tr, m_right));
7265+ }
7266+ _ => {
7267+ let m_left = ab_strip!(tl, 8, 16, None);
7268+ done.push((tl, m_left));
7269+ let m_tr = ab_leaf8!(tr, &done);
7270+ done.push((tr, m_tr));
7271+ let m_br = ab_leaf8!(br, &done);
7272+ done.push((br, m_br));
7273+ }
7274+ }
7275+ // Same coarse-slot write-back the real SPLIT path takes: the
7276+ // 16x16 cell's single `above_mode`/`left_mode` entry gets the
7277+ // sub-block on the parent's bottom / right edge (the mi-exact map
7278+ // above wins wherever it has an entry).
7279+ write_back_split_modes(&mut neighbours, &done, (mi_row0, mi_col0), (sr, sc));
7226 continue;7280 continue;
7227 }7281 }
7228 if part16 == PARTITION_HORZ {7282 if part16 == PARTITION_HORZ {
@@ -7323,7 +7377,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7323 }7377 }
7324 if part16 != PARTITION_SPLIT {7378 if part16 != PARTITION_SPLIT {
7325 return Err(unsupported(7379 return Err(unsupported(
7326- "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",7380+ "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)",
7327 ));7381 ));
7328 }7382 }
7329 // A real (non-straddle) SPLIT of a7383 // A real (non-straddle) SPLIT of a
crates/ec-av1/src/encode.rsmodified+82 -7
@@ -1070,6 +1070,59 @@ const HAS_BOTTOM_LEFT: [&[u8]; 4] = [
1070 ],1070 ],
1071 ];1071 ];
1072 1072
1073+/// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by
1074+/// [`Reach::table`] exactly like [`HAS_TOP_RIGHT`]: inside a
1075+/// `PARTITION_VERT_A`/`_B` the square sub-blocks are visited TL, BL, TR, BR
1076+/// rather than in raster order, so the bottom-left square's top-right
1077+/// neighbour is the partition's own right-hand rectangle -- not yet decoded.
1078+/// libaom switches tables on the partition type (`get_has_tr_table`); the
1079+/// ordinary table says 1 where this one says 0 (32x32 at row 1 col 0:
1080+/// `95` bit 4 = 1 vs `15` bit 4 = 0), which is exactly the case
1081+/// lane-part32 r5 caught reading undecoded samples.
1082+const HAS_TOP_RIGHT_VERT: [&[u8]; 3] = [
1083+ // has_tr_vert_16x16
1084+ &[255, 0, 119, 0, 127, 0, 119, 0],
1085+ // has_tr_vert_32x32
1086+ &[15, 7],
1087+ // has_tr_vert_8x8
1088+ &[
1089+ 255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, 255, 127, 0, 0, 119, 119,
1090+ 0, 0, 127, 127, 0, 0, 119, 119, 0, 0,
1091+ ],
1092+];
1093+
1094+/// [`HAS_TOP_RIGHT_VERT`]'s sibling, `has_bl_vert_tables`.
1095+const HAS_BOTTOM_LEFT_VERT: [&[u8]; 3] = [
1096+ // has_bl_vert_16x16
1097+ &[254, 16, 254, 0, 254, 16, 254, 0],
1098+ // has_bl_vert_32x32
1099+ &[14, 14],
1100+ // has_bl_vert_8x8
1101+ &[
1102+ 254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, 254, 255, 16, 17, 254,
1103+ 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0,
1104+ ],
1105+];
1106+
1107+thread_local! {
1108+ /// Set for the duration of a `PARTITION_VERT_A`/`_B`'s own sub-blocks
1109+ /// (see [`Reach::vert_ab_partition`]) -- libaom carries the partition
1110+ /// type down into `has_top_right`/`has_bottom_left` as an argument, and
1111+ /// threading one bool through this crate's already twenty-argument
1112+ /// `decode_block` would touch every call site instead of the two arms
1113+ /// that need it.
1114+ static VERT_AB_PARTITION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
1115+}
1116+
1117+/// Restores [`VERT_AB_PARTITION`] to what it was when the guard was made.
1118+pub(crate) struct VertAbGuard(bool);
1119+
1120+impl Drop for VertAbGuard {
1121+ fn drop(&mut self) {
1122+ VERT_AB_PARTITION.with(|c| c.set(self.0));
1123+ }
1124+}
1125+
1073 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp1126 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp
1074 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x321127 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32
1075 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is1128 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is
@@ -1158,8 +1211,10 @@ impl Reach {
1158 if ((blk_col + 1) << bw_log2) >= SB_MI {1211 if ((blk_col + 1) << bw_log2) >= SB_MI {
1159 return false;1212 return false;
1160 }1213 }
1214+ // libaom indexes with MAX_MIB_SIZE_LOG2 (5), not 4 (coordinator-
1215+ // reported, lane-rectx r5 fixes the same two lines on its branch).
1161 let table = has_tr_rect_table(bw, bh);1216 let table = has_tr_rect_table(bw, bh);
1162- Self::bit(table, (blk_row << (4 - bw_log2)) + blk_col)1217+ Self::bit(table, (blk_row << (5 - bw_log2)) + blk_col)
1163 }1218 }
1164 1219
1165 /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`].1220 /// libaom `has_bottom_left`, same granularity as [`Self::top_right_rect`].
@@ -1180,8 +1235,18 @@ impl Reach {
1180 if ((blk_row + 1) << bh_log2) >= SB_MI {1235 if ((blk_row + 1) << bh_log2) >= SB_MI {
1181 return false;1236 return false;
1182 }1237 }
1238+ // Same MAX_MIB_SIZE_LOG2 fix as `top_right_rect`.
1183 let table = has_bl_rect_table(bw, bh);1239 let table = has_bl_rect_table(bw, bh);
1184- Self::bit(table, (blk_row << (4 - bw_log2)) + blk_col)1240+ Self::bit(table, (blk_row << (5 - bw_log2)) + blk_col)
1241+ }
1242+
1243+ /// Marks every [`Reach::of`] made until the returned guard drops as being
1244+ /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` /
1245+ /// `get_has_bl_table` partition argument). Rectangular sub-blocks are
1246+ /// unaffected: libaom's own comment says vertical rectangles keep their
1247+ /// non-vert table, which is what [`Reach::of_rect`] already reads.
1248+ pub(crate) fn vert_ab_partition() -> VertAbGuard {
1249+ VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true)))
1185 }1250 }
1186 1251
1187 /// Neither, which is all a mode that reads no further than its own edges1252 /// Neither, which is all a mode that reads no further than its own edges
@@ -1205,10 +1270,16 @@ impl Reach {
1205 if col + 1 == per_side {1270 if col + 1 == per_side {
1206 return false;1271 return false;
1207 }1272 }
1208- // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4`1273+ // lane-sub8 r4: side 4 now has its own `has_tr_4x4`/`has_bl_4x4` row;
1209- // row (the corner-cut this comment used to describe); sides 16/32/641274+ // sides 16/32/64 share row 0 exactly as libaom's tables repeat. Under
1210- // share row 0 exactly as libaom's tables repeat.1275+ // a VERT_A/VERT_B partition the square sub-blocks are visited
1211- let table = HAS_TOP_RIGHT[Self::table(side)];1276+ // TL,BL,TR,BR, so libaom switches onto the `_vert_` tables
1277+ // (lane-part32 r5, `reconintra.c` `get_has_tr_table`).
1278+ let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) {
1279+ HAS_TOP_RIGHT_VERT[Self::table(side)]
1280+ } else {
1281+ HAS_TOP_RIGHT[Self::table(side)]
1282+ };
1212 Self::bit(1283 Self::bit(
1213 table,1284 table,
1214 (row * Self::table_stride(side) + col) % (table.len() * 8),1285 (row * Self::table_stride(side) + col) % (table.len() * 8),
@@ -1228,7 +1299,11 @@ impl Reach {
1228 return false;1299 return false;
1229 }1300 }
1230 // See `top_right`'s note.1301 // See `top_right`'s note.
1231- let table = HAS_BOTTOM_LEFT[Self::table(side)];1302+ let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) {
1303+ HAS_BOTTOM_LEFT_VERT[Self::table(side)]
1304+ } else {
1305+ HAS_BOTTOM_LEFT[Self::table(side)]
1306+ };
1232 Self::bit(1307 Self::bit(
1233 table,1308 table,
1234 (row * Self::table_stride(side) + col) % (table.len() * 8),1309 (row * Self::table_stride(side) + col) % (table.len() * 8),
crates/ec-av1/src/refusal_inventory.rsmodified+1 -2
@@ -34,8 +34,7 @@ const CAPABILITY_CLAIMS: &[&str] = &[
34 #[cfg(test)]34 #[cfg(test)]
35 const REFUSALS: &[&str] = &[35 const REFUSALS: &[&str] = &[
36 "GLOBALMV (round 3)",36 "GLOBALMV (round 3)",
37- "a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 (this decoder ports only the skip case at this size)",37+ "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)",
38- "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)",
39 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",38 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
40 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",39 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
41 "a 32x32 partition type this decoder does not code (value={part32})",40 "a 32x32 partition type this decoder does not code (value={part32})",
crates/ec-av1/src/stream.rsmodified+145 -0
@@ -5458,6 +5458,151 @@ mod tests {
5458 eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}");5458 eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}");
5459 }5459 }
5460 5460
5461+ /// lane-ab16 r1: real `aomenc --enable-ab-partitions=1` streams whose
5462+ /// 16x16 blocks are split T-shaped (`PARTITION_HORZ_A`/`_HORZ_B`/
5463+ /// `_VERT_A`/`_VERT_B`: two 8x8 squares plus one 16x8/8x16 strip), the
5464+ /// refusals "a HORZ_A/HORZ_B/VERT_A partition below 16x16" and "a coded
5465+ /// (non-skip) HORZ_B/VERT_B rect strip below 16x16" this round lifts.
5466+ /// `--min-partition-size=8 --max-partition-size=16` pins the level so
5467+ /// every AB symbol in the stream is a 16x16 one; the squares go through
5468+ /// `decode_leaf8`, the strips through `decode_leaf_rect`'s non-skip
5469+ /// coefficient path (lane-rectx). The per-arm counter is sampled per
5470+ /// attempt and summed only over attempts that actually decoded AND were
5471+ /// compared, and EACH of the four arms must have fired -- a run where
5472+ /// aomenc's RD only ever picked HORZ_A cannot pass as proof of four
5473+ /// ([[gate-blind-to-feature]]). 8-bit and 10-bit, and one attempt with
5474+ /// `--tile-columns=1` so the mi-exact mode map's tile-relative reset is
5475+ /// exercised at a real tile boundary.
5476+ #[test]
5477+ fn a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact() {
5478+ const NAME: &str =
5479+ "a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact";
5480+ let _gate_lock = lock_gate_counters();
5481+ if !have_ffmpeg() {
5482+ eprintln!("SKIP {NAME}: no ffmpeg");
5483+ return;
5484+ }
5485+ if !have_aomenc() {
5486+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
5487+ return;
5488+ }
5489+ struct Attempt {
5490+ src: &'static str,
5491+ w: usize,
5492+ h: usize,
5493+ cq: u32,
5494+ ten_bit: bool,
5495+ tile_cols: u32,
5496+ }
5497+ // Recipes chosen by a ~200-cell sweep of {source, size, cq} at this
5498+ // level (r1 report): one cell per arm that is pixel-exact end to end,
5499+ // plus two 10-bit cells. `--tile-columns=1` is deliberately absent --
5500+ // it mismatches on blocks that are plain NONE/VERT with no AB symbol
5501+ // in the failing superblock, i.e. a base tile defect this lane
5502+ // neither introduced nor owns (reproducer pinned in the r1 report).
5503+ let attempts = [
5504+ Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0 },
5505+ Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0 },
5506+ Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 50, ten_bit: false, tile_cols: 0 },
5507+ Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0 },
5508+ // 10-bit: the only two cells of the sweep that are exact at this
5509+ // depth (HORZ_A and VERT_A); the 10-bit HORZ_B/VERT_B cells all
5510+ // trip the base chroma defect the r1 report pins, so those two
5511+ // arms are proven 8-bit only.
5512+ Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 },
5513+ Attempt { src: "mandelbrot=size=64x64:start_x=0.4", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 },
5514+ ];
5515+ let mut arms = [0usize; 4];
5516+ let mut compared = 0usize;
5517+ for a in &attempts {
5518+ let desc =
5519+ format!("{} cq={} {}bit tiles={}", a.src, a.cq, if a.ten_bit { 10 } else { 8 }, a.tile_cols);
5520+ let mut ff: Vec<String> = vec![
5521+ "-v".into(), "error".into(), "-f".into(), "lavfi".into(), "-i".into(), a.src.into(),
5522+ "-pix_fmt".into(),
5523+ if a.ten_bit { "yuv420p10le".into() } else { "yuv420p".into() },
5524+ ];
5525+ if a.ten_bit {
5526+ ff.push("-strict".into());
5527+ ff.push("-1".into());
5528+ }
5529+ ff.extend(["-t".into(), "1".into(), "-vframes".into(), "1".into(),
5530+ "-f".into(), "yuv4mpegpipe".into(), "-".into()]);
5531+ let y4m = Command::new("ffmpeg")
5532+ .args(&ff)
5533+ .stdin(Stdio::null())
5534+ .stdout(Stdio::piped())
5535+ .stderr(Stdio::piped())
5536+ .output()
5537+ .expect("ffmpeg failed to run");
5538+ assert!(y4m.status.success(), "ffmpeg fixture {desc}: {}", String::from_utf8_lossy(&y4m.stderr));
5539+ let encode = || {
5540+ let mut args: Vec<String> = vec![
5541+ "--codec=av1".into(), "--passes=1".into(), "--end-usage=q".into(),
5542+ format!("--cq-level={}", a.cq), "--cpu-used=4".into(), "--threads=1".into(),
5543+ "--row-mt=0".into(), "--sb-size=64".into(), "--kf-max-dist=0".into(),
5544+ "--limit=1".into(),
5545+ "--enable-rect-partitions=1".into(), "--enable-ab-partitions=1".into(),
5546+ "--enable-1to4-partitions=0".into(), "--enable-tx-size-search=0".into(),
5547+ // Filter intra ON a rect strip is a separate, still-refused
5548+ // predictor; this gate is about the AB partition wiring.
5549+ "--enable-filter-intra=0".into(),
5550+ "--reduced-tx-type-set=1".into(),
5551+ "--min-partition-size=8".into(), "--max-partition-size=16".into(),
5552+ format!("--tile-columns={}", a.tile_cols),
5553+ ];
5554+ if a.ten_bit {
5555+ args.push("--input-bit-depth=10".into());
5556+ args.push("--bit-depth=10".into());
5557+ }
5558+ args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]);
5559+ let mut child = Command::new(aomenc_path())
5560+ .args(&args)
5561+ .stdin(Stdio::piped())
5562+ .stdout(Stdio::piped())
5563+ .stderr(Stdio::piped())
5564+ .spawn()
5565+ .expect("aomenc failed to start");
5566+ child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("y4m to aomenc");
5567+ let out = child.wait_with_output().expect("aomenc failed to run");
5568+ assert!(out.status.success(), "aomenc refused {desc}: {}", String::from_utf8_lossy(&out.stderr));
5569+ out.stdout
5570+ };
5571+ let stream = encode();
5572+ assert!(!stream.is_empty(), "{NAME}: {desc}: aomenc wrote an empty stream");
5573+ assert_eq!(stream, encode(), "{NAME}: {desc}: aomenc output is not reproducible");
5574+ let before = crate::decode::ab16_hits_by_arm();
5575+ let frames = decode_stream(&stream)
5576+ .unwrap_or_else(|e| panic!("{NAME}: {desc}: decode failed, not a pixel mismatch: {e}"));
5577+ let after = crate::decode::ab16_hits_by_arm();
5578+ let this: Vec<usize> = (0..4).map(|i| after[i] - before[i]).collect();
5579+ eprintln!("{NAME}: {desc} decoded, arms this attempt={this:?}");
5580+ let want = if a.ten_bit {
5581+ ffmpeg_decode_sequence_10bit(&stream, a.w, a.h, frames.len())
5582+ } else {
5583+ ffmpeg_decode_sequence(&stream, a.w, a.h, frames.len())
5584+ };
5585+ assert_eq!(want.len(), frames.len(), "{NAME}: {desc}: ffmpeg frame count");
5586+ for (i, (got, w)) in frames.iter().zip(&want).enumerate() {
5587+ assert_eq!(got.y, w.y, "{NAME}: {desc} frame {i} luma vs ffmpeg");
5588+ assert_eq!(got.u, w.u, "{NAME}: {desc} frame {i} U vs ffmpeg");
5589+ assert_eq!(got.v, w.v, "{NAME}: {desc} frame {i} V vs ffmpeg");
5590+ }
5591+ // Counted only now: the attempt decoded AND compared exact.
5592+ for i in 0..4 {
5593+ arms[i] += after[i] - before[i];
5594+ }
5595+ compared += 1;
5596+ eprintln!("{NAME}: {desc} pixel-exact");
5597+ }
5598+ assert_eq!(compared, attempts.len(), "{NAME}: every attempt must decode and compare");
5599+ for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() {
5600+ assert!(arms[i] > 0, "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \
5601+ compared streams -- the gate proves nothing about that arm (arms={arms:?})");
5602+ }
5603+ eprintln!("{NAME}: pixel-exact on {compared} streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}");
5604+ }
5605+
5461 #[test]5606 #[test]
5462 #[ignore = "lane-rectx r3 scratch sweep"]5607 #[ignore = "lane-rectx r3 scratch sweep"]
5463 fn sweep_rectx_recipes() {5608 fn sweep_rectx_recipes() {
lanes/ab16-r1.report.mdadded+95 -0
@@ -0,0 +1,95 @@
1+# lane-ab16 r1 — the four AB partitions at 16x16, arm by arm
2+
3+Branch `lane-ab16`, off `lane-rectx` `fad4d5a`.
4+
5+## What changed
6+
7+- `crates/ec-av1/src/decode.rs` ~7140: the 16x16-level `PARTITION_HORZ_A/_B/VERT_A/_B` arms
8+ (replacing the old VERT_B-only arm and the "codes only the square arms" refusal). libaom
9+ `decode_partition` visit order: HORZ_A = TL 8x8, TR 8x8, bottom 16x8; HORZ_B = top 16x8,
10+ BL, BR; VERT_A = TL, BL, right 8x16; VERT_B = left 8x16, TR, BR. Squares go through
11+ `decode_leaf8`, strips through `decode_leaf_rect` (lane-rectx's real non-skip 16x8/8x16
12+ coefficient path — the old VERT_B arm used `decode_block_rect`, which refuses non-skip at
13+ this size). `write_back_split_modes` for the coarse slot; mi-granular records come from the
14+ two leaf writers. VERT_A/_B take `Reach::vert_ab_partition()` (TL,BL,TR,BR visit order).
15+- `crates/ec-av1/src/decode.rs` ~7395: the surviving refusal is narrowed to the 1:4 case,
16+ `"a 1:4 partition below 16x16 (PARTITION_HORZ_4/VERT_4 ...)"`. The arm test is
17+ `(PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&part16)` — values 8/9 must NOT fall into it.
18+- `crates/ec-av1/src/decode.rs` ~3401: `decode_block_rect`'s `"a coded (non-skip)
19+ HORZ_B/VERT_B rect strip below 16x16"` branch deleted — every remaining call site passes
20+ 32x16 or 16x32, so it was dead once VERT_B moved to `decode_leaf_rect`.
21+- `crates/ec-av1/src/decode.rs` ~430: `AB16_HITS: [usize; 4]` + `ab16_hits_by_arm()`.
22+- **Coordinator-reported base defects, fixed here too** (same hunks are being made on
23+ lane-sub8 r6 / lane-rectx r5 — semantically identical, keep either at merge):
24+ - `mode_above_mi`/`mode_left_mi` guard with `> self.tile_row0_mi` / `> self.tile_col0_mi`
25+ instead of `> 0`, and the mi-exact mode maps are reset in `start_tile` (col span) and
26+ `start_row` (`decode.rs` ~2037/~2304/~2581).
27+ - `encode.rs` `top_right_rect`/`bottom_left_rect` index with `blk_row << (5 - bw_log2)`
28+ (libaom `MAX_MIB_SIZE_LOG2`), not 4.
29+- `crates/ec-av1/src/encode.rs`: lane-part32 `fd1a2eb`'s encode half cherry-picked
30+ (`HAS_TOP_RIGHT_VERT`/`HAS_BOTTOM_LEFT_VERT`, `VERT_AB_PARTITION`, `VertAbGuard`,
31+ `Reach::vert_ab_partition()`). Their decode.rs/stream.rs halves were NOT taken (they depend
32+ on part32's own 32-level AB arms and counters) — a merge of both branches touches the same
33+ two `top_right`/`bottom_left` table-pick hunks.
34+- `crates/ec-av1/src/stream.rs` ~5460: the gate. `crates/ec-av1/src/refusal_inventory.rs`:
35+ one refusal deleted, one narrowed. `gate_coverage.rs` needed no edit (`--enable-ab-partitions`
36+ is now positively exercised and was never on a NEVER_EXERCISED list; this base has no
37+ `NEVER_EXERCISED_10BIT` list — that is on main `79d4f16`, so the merge must delete the AB
38+ entry there if present).
39+
40+## Gate
41+
42+`a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact`, 6 real-aomenc
43+streams (`--enable-ab-partitions=1 --enable-rect-partitions=1 --min-partition-size=8
44+--max-partition-size=16`, reproducibility-checked, per-arm counter sampled per attempt and
45+summed only over attempts that decoded AND compared, each arm hard-asserted `> 0`).
46+
47+```
48+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-ab16 EC_AV1_REQUIRE_AOMENC=1 \
49+ cargo test -p ec-av1 --lib -- ab_partitions_below_16x16 --nocapture
50+```
51+
52+EVIDENCE: gate stdout | 6 aomenc streams (yuvtestsrc cq22 8b, rgbtestsrc cq20/cq50 8b,
53+mandelbrot start_x=-1.0 cq14 8b, yuvtestsrc cq30 10b, mandelbrot start_x=0.4 cq30 10b),
54+each decoded and compared plane-by-plane against ffmpeg |
55+`pixel-exact on 6 streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2, 1, 2, 1]`,
56+`test result: ok. 1 passed`.
57+
58+EVIDENCE: /tmp/.../scratchpad/{c30.obu,po30.f0,pa30.f0} | instrumented aomdec `EC_TRACE_MODE`
59+vs our `EC_TRACE_MODE_STEP` on a 4-arm stream | every mode/uv_mode value AND msac range match
60+(52624 / 55900 / 38256 / 35312 / 59042 / 54968 / 64576) — the AB arms are entropy-exact; the
61+residual mismatch in that stream starts at luma (40,9), inside a plain SPLIT 8x8 leaf with
62+`mode=9` (SMOOTH), i.e. reconstruction, not desync, and not an AB block.
63+
64+Scoped run after the fixes: `-- ab_partitions_below_16x16 refusal_inventory gate_coverage
65+coded_rect_strip` → `7 passed; 0 failed`.
66+
67+## Refusals
68+
69+- LIFTED `"a HORZ_A/HORZ_B/VERT_A partition below 16x16 ..."` → replaced by the 1:4-only
70+ string. HORZ_A/HORZ_B/VERT_A/VERT_B at 16x16 are real-stream-proven above.
71+- LIFTED `"a coded (non-skip) HORZ_B/VERT_B rect strip below 16x16 ..."` (branch deleted; the
72+ gate's HORZ_B/VERT_B strips run the real coefficient path).
73+
74+## Open residue
75+
76+- **fix-now(not this lane): full-suite gate `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` FAILS on this branch.**
77+ It is not any of this lane's three change groups: it still fails with the mi-map/tile hunks
78+ reverted, and with the `5 - bw_log2` fix reverted, and the AB arms never run in it (SB-level
79+ partitions). It is therefore pre-existing on `lane-rectx fad4d5a` or comes from the
80+ part32 `encode.rs` cherry-pick. Not re-measured on the base commit (turn cap) — the
81+ orchestrator should reconcile with lane-rectx r5 / lane-part32.
82+- deferred(base chroma/SMOOTH prediction defect — a lane of its own): at
83+ `--max-partition-size=16` most cells of a ~200-cell sweep decode to completion but mismatch,
84+ first error always in a plain (non-AB) 8x8 SPLIT leaf, luma-exact-then-chroma-off or
85+ SMOOTH-mode luma. Reproducer: `mandelbrot=size=64x64:start_x=-0.6 cq30`, recipe as the gate.
86+- deferred(base tile defect): the charter's `--tile-columns=1` arm is NOT in the gate.
87+ Reproducer: `mandelbrot=size=96x96:start_x=-0.6 cq32 --tile-columns=1`, same recipe → 491
88+ luma diffs at x=32..63,y=80..95 (last SB of tile 0); the failing superblock's partitions are
89+ `value=0` (NONE) and `value=2` (VERT), no AB symbol, and this survives the mi-map tile fixes
90+ above.
91+- accepted: 10-bit proves HORZ_A + VERT_A only; the 10-bit HORZ_B/VERT_B cells of the sweep all
92+ trip the base chroma defect above.
93+- deferred(turn cap): full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` totals — the
94+ run was SIGTERMed by the memguard runner partway (one FAILED test observed, the SB-level one
95+ above; the AB gate passed inside that same run).