forge
Explore
Log in

Don't you dare go Hollow

128x128 superblock root in the INTER tile loop (visit order + prologue), sb-aware has_top_right

Browse files at this commit

b7c0e219702c59344f13b1c274e277c1f8cc34f0Ahmet Kaan GümüşParent: 01da5a9
  • feat
    • 128x128 superblock root in the INTER tile loop (visit order + prologue), sb-aware has_top_right
    • refusal kept for a residual one-frame mismatch
Show full message
feat(av1): 128x128 superblock root in the INTER tile loop (visit order + prologue), sb-aware has_top_right; refusal kept for a residual one-frame mismatch

The inter tile loop now walks libaom's quadrant visit order (sb_visit_order) and
reads the 128 root once per superblock (read_lr over the whole 128x128, the
8-symbol partition_w128 with its edge gather) through a new shared
read_sb128_root, extracted from the key-frame loop so both paths cannot drift.
libaom has_top_right is now a single sb-aware port in mvstack (the warp-sample
copy in decode.rs hardcoded a 64x64 superblock and now delegates to it), and
the MV stack's top-right probe is gated on it instead of a bare grid probe.

8 of the 9 decode-order frames of the new gate stream are pixel-exact against
the instrumented aomdec, hidden alt-ref included; frame 6 still differs by 996
luma bytes with the entropy stream in sync, and the same content at
--sb-size=64 is exact (sb128_r2_control_sb64), so the residual is
sb128-specific. The product-path refusal therefore STAYS and the gate ships
#[ignore]d as its reproducer -- silent wrong pixels on his films are worse.
crates/ec-av1/src/decode.rsmodified+120 -82
@@ -78,7 +78,7 @@ fn sb128() -> bool {
78 }78 }
79 79
80 /// This sequence's superblock size in mi units (16 = 64x64, 32 = 128x128).80 /// This sequence's superblock size in mi units (16 = 64x64, 32 = 128x128).
81-fn sb_mi_cur() -> u32 {81+pub(crate) fn sb_mi_cur() -> u32 {
82 if sb128() { SB_MI * 2 } else { SB_MI }82 if sb128() { SB_MI * 2 } else { SB_MI }
83 }83 }
84 84
@@ -11243,6 +11243,70 @@ fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32,
11243 out11243 out
11244 }11244 }
11245 11245
11246+/// lane-sb128 r2: the 128x128 superblock root, shared by the key-frame and
11247+/// the inter tile loop. Its loop-restoration units are read once for the whole
11248+/// 128x128 (spec 5.11.57 is called with the superblock's own size), then one
11249+/// partition symbol off the `BLOCK_128X128` CDF (8 symbols, no HORZ_4/VERT_4)
11250+/// decides the root -- only SPLIT recurses into the four 64x64 quadrants this
11251+/// decoder codes, the other seven arms refuse by name.
11252+#[allow(clippy::too_many_arguments)]
11253+fn read_sb128_root(
11254+ dec: &mut SymbolDecoder,
11255+ cdfs: &mut Cdfs,
11256+ neighbours: &Neighbours,
11257+ lr: &LoopRestorationParams,
11258+ lr_grid: &mut crate::restoration::RestorationGrid,
11259+ lr_reference: &mut [(
11260+ crate::restoration::WienerInfo,
11261+ crate::restoration::SgrprojInfo,
11262+ ); 3],
11263+ sb_r: u32,
11264+ sb_c: u32,
11265+ mi_cols: u32,
11266+ mi_rows: u32,
11267+) -> Result<()> {
11268+ let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);
11269+ crate::restoration::read_lr(
11270+ dec,
11271+ cdfs,
11272+ lr,
11273+ lr_grid,
11274+ lr_reference,
11275+ mi_r128,
11276+ mi_c128,
11277+ SB_MI * 2,
11278+ );
11279+ let at128 = ((mi_r128 / SUB_MI) as usize, (mi_c128 / SUB_MI) as usize);
11280+ let ctx128 = neighbours.partition_ctx(at128, 128);
11281+ let (has_cols128, has_rows128) = (mi_c128 + SB_MI < mi_cols, mi_r128 + SB_MI < mi_rows);
11282+ let part128 = if has_cols128 && has_rows128 {
11283+ PART128_SYMBOLS.with(|c| c.set(c.get() + 1));
11284+ let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);
11285+ if std::env::var_os("EC_AV1_TRACE").is_some() {
11286+ eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
11287+ }
11288+ p
11289+ } else {
11290+ match (has_cols128, has_rows128) {
11291+ (true, false) => {
11292+ dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128));
11293+ }
11294+ (false, true) => {
11295+ dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128));
11296+ }
11297+ _ => {}
11298+ }
11299+ PARTITION_SPLIT
11300+ };
11301+ if part128 != PARTITION_SPLIT {
11302+ return Err(unsupported(
11303+ "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)",
11304+ ));
11305+ }
11306+ PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1));
11307+ Ok(())
11308+}
11309+
11246 pub(crate) fn decode_key_frame_tile_with_cdfs(11310 pub(crate) fn decode_key_frame_tile_with_cdfs(
11247 tiles: &[&[u8]],11311 tiles: &[&[u8]],
11248 tile_info: &TileInfo,11312 tile_info: &TileInfo,
@@ -11429,52 +11493,18 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
11429 // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT11493 // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT
11430 // recurses into the four 64x64 quadrants this decoder codes.11494 // recurses into the four 64x64 quadrants this decoder codes.
11431 if sb128 && sb_start {11495 if sb128 && sb_start {
11432- let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);11496+ read_sb128_root(
11433- crate::restoration::read_lr(
11434 &mut dec,11497 &mut dec,
11435 &mut cdfs,11498 &mut cdfs,
11499+ &neighbours,
11436 lr,11500 lr,
11437 &mut lr_grid,11501 &mut lr_grid,
11438 &mut lr_reference,11502 &mut lr_reference,
11439- mi_r128,11503+ sb_r,
11440- mi_c128,11504+ sb_c,
11441- SB_MI * 2,11505+ mi_cols,
11442- );11506+ mi_rows,
11443- let at128 = ((mi_r128 / SUB_MI) as usize, (mi_c128 / SUB_MI) as usize);11507+ )?;
11444- let ctx128 = neighbours.partition_ctx(at128, 128);
11445- let (has_cols128, has_rows128) =
11446- (mi_c128 + SB_MI < mi_cols, mi_r128 + SB_MI < mi_rows);
11447- let part128 = if has_cols128 && has_rows128 {
11448- PART128_SYMBOLS.with(|c| c.set(c.get() + 1));
11449- let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);
11450- if std::env::var_os("EC_AV1_TRACE").is_some() {
11451- eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
11452- }
11453- p
11454- } else {
11455- match (has_cols128, has_rows128) {
11456- (true, false) => {
11457- dec.symbol_fixed(&gather_of(
11458- &cdfs.partition_w128[ctx128],
11459- &VERT_ALIKE128,
11460- ));
11461- }
11462- (false, true) => {
11463- dec.symbol_fixed(&gather_of(
11464- &cdfs.partition_w128[ctx128],
11465- &HORZ_ALIKE128,
11466- ));
11467- }
11468- _ => {}
11469- }
11470- PARTITION_SPLIT
11471- };
11472- if part128 != PARTITION_SPLIT {
11473- return Err(unsupported(
11474- "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)",
11475- ));
11476- }
11477- PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1));
11478 }11508 }
11479 if !sb128 {11509 if !sb128 {
11480 crate::restoration::read_lr(11510 crate::restoration::read_lr(
@@ -13437,34 +13467,16 @@ fn overlappable_left(
13437 out13467 out
13438 }13468 }
13439 13469
13440-/// `has_top_right` (`av1/common/mvref_common.c`), reduced to the13470+/// The warp-sample gather's own `has_top_right` probe (libaom `av1_findSamples`
13441-/// square-block, fixed-64px-superblock case this decoder ever reaches: no13471+/// calls the same `mvref_common.c` function the MV stack does). lane-sb128 r2:
13442-/// rectangular partition (`VERT`/`HORZ`/`_4`/`VERT_A`) ever produces an13472+/// this used to hardcode `SB_MI` (a 64x64 superblock) -- at `sb_size == 128`
13443-/// inter leaf here (`xd->width == xd->height` always), so libaom's own13473+/// libaom's mask loop runs one level further and strips the top-right sample
13444-/// rect-partition branches (`xd->width < xd->height`, `xd->width >13474+/// off blocks whose neighbour IS decoded, so a warped 128-superblock frame
13445-/// xd->height`, `PARTITION_VERT_A`) never fire and are dropped. `bs` is the13475+/// picked up wrong warp parameters (frame 6 of the 128 inter gate). Delegates
13446-/// block's own side in 4x4 (`mi`) units.13476+/// to the single sb-aware port in [`crate::mvstack::has_top_right`]; `bs` is
13477+/// the block's own side in 4x4 (`mi`) units (square inter leaves only here).
13447 fn has_top_right(mi_row: usize, mi_col: usize, bs: usize) -> bool {13478 fn has_top_right(mi_row: usize, mi_col: usize, bs: usize) -> bool {
13448- let sb_mi_size = SB_MI as usize;13479+ crate::mvstack::has_top_right(mi_row, mi_col, bs, bs)
13449- let mask_row = mi_row & (sb_mi_size - 1);
13450- let mask_col = mi_col & (sb_mi_size - 1);
13451- if bs > sb_mi_size {
13452- return false;
13453- }
13454- let mut has_tr = !((mask_row & bs != 0) && (mask_col & bs != 0));
13455- let mut b = bs;
13456- while b < sb_mi_size {
13457- if mask_col & b != 0 {
13458- if (mask_col & (2 * b) != 0) && (mask_row & (2 * b) != 0) {
13459- has_tr = false;
13460- break;
13461- }
13462- } else {
13463- break;
13464- }
13465- b <<= 1;
13466- }
13467- has_tr
13468 }13480 }
13469 13481
13470 /// `av1_findSamples` (`mvref_common.c`), full port: the up to13482 /// `av1_findSamples` (`mvref_common.c`), full port: the up to
@@ -18347,6 +18359,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
18347 ));18359 ));
18348 }18360 }
18349 let (cols, rows) = block_grid(mi_cols, mi_rows);18361 let (cols, rows) = block_grid(mi_cols, mi_rows);
18362+ let sb128 = sb128();
18350 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));18363 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
18351 CDEF_BITS.with(|c| c.set(cdef.bits));18364 CDEF_BITS.with(|c| c.set(cdef.bits));
18352 CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));18365 CDEF_SB_COLS.with(|c| c.set(sb_cols as usize));
@@ -18568,19 +18581,44 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
18568 );18581 );
18569 TILE_HITS.with(|c| c.set(c.get() + 1));18582 TILE_HITS.with(|c| c.set(c.get() + 1));
18570 18583
18571- for sb_r in sb_r0..sb_r1 {18584+ // lane-sb128 r2: at `sb_size == 128` the tile walks each 128x128
18572- neighbours.start_row();18585+ // superblock's four 64x64 quadrants in libaom `decode_partition` order
18573- for sb_c in sb_c0..sb_c1 {18586+ // (TL, TR, BL, BR) and reads the 128 root's own loop-restoration units and
18574- crate::restoration::read_lr(18587+ // partition symbol once per superblock -- exactly what the key-frame tile
18575- &mut dec,18588+ // loop does; the 64-level body below is unchanged, `read_cdef`'s
18576- &mut cdfs,18589+ // per-64x64-quadrant reset (`CDEF_TRANSMITTED`) already matches libaom's
18577- lr,18590+ // `cdef_idx[(mi_row & 16) >> 4 * 2 + (mi_col & 16) >> 4]` slot per quadrant.
18578- &mut lr_grid,18591+ for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
18579- &mut lr_reference,18592+ if row_start {
18580- sb_r * SB_MI,18593+ neighbours.start_row();
18581- sb_c * SB_MI,18594+ }
18582- SB_MI,18595+ {
18583- );18596+ if sb128 && sb_start {
18597+ read_sb128_root(
18598+ &mut dec,
18599+ &mut cdfs,
18600+ &neighbours,
18601+ lr,
18602+ &mut lr_grid,
18603+ &mut lr_reference,
18604+ sb_r,
18605+ sb_c,
18606+ mi_cols,
18607+ mi_rows,
18608+ )?;
18609+ }
18610+ if !sb128 {
18611+ crate::restoration::read_lr(
18612+ &mut dec,
18613+ &mut cdfs,
18614+ lr,
18615+ &mut lr_grid,
18616+ &mut lr_reference,
18617+ sb_r * SB_MI,
18618+ sb_c * SB_MI,
18619+ SB_MI,
18620+ );
18621+ }
18584 CDEF_TRANSMITTED.with(|c| c.set(false));18622 CDEF_TRANSMITTED.with(|c| c.set(false));
18585 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);18623 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
18586 let sb_ctx = neighbours.partition_ctx(sb_at, SB);18624 let sb_ctx = neighbours.partition_ctx(sb_at, SB);
crates/ec-av1/src/mvstack.rsmodified+59 -20
@@ -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
@@ -779,16 +816,17 @@ pub fn find_mv_stack_with_sign_bias(
779 &mut newmv_count,816 &mut newmv_count,
780 &mut processed_cols,817 &mut processed_cols,
781 );818 );
782- let found_top_right = scan_top_right(819+ let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4)
783- grid,820+ && scan_top_right(
784- mi_row,821+ grid,
785- mi_col,822+ mi_row,
786- bw4,823+ mi_col,
787- ref_frame,824+ bw4,
788- gm,825+ ref_frame,
789- &mut candidates,826+ gm,
790- &mut newmv_count,827+ &mut candidates,
791- );828+ &mut newmv_count,
829+ );
792 830
793 // libaom's `row_match_count`/`col_match_count` (mvref_common.c) fold the831 // libaom's `row_match_count`/`col_match_count` (mvref_common.c) fold the
794 // top-right probe into the row side, so "found above" for context832 // top-right probe into the row side, so "found above" for context
@@ -1538,16 +1576,17 @@ pub fn find_mv_stack_compound(
1538 &mut newmv_count,1576 &mut newmv_count,
1539 &mut processed_cols,1577 &mut processed_cols,
1540 );1578 );
1541- let found_top_right = scan_top_right_compound(1579+ let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4)
1542- grid,1580+ && scan_top_right_compound(
1543- mi_row,1581+ grid,
1544- mi_col,1582+ mi_row,
1545- bw4,1583+ mi_col,
1546- ref_frame,1584+ bw4,
1547- gm,1585+ ref_frame,
1548- &mut candidates,1586+ gm,
1549- &mut newmv_count,1587+ &mut candidates,
1550- );1588+ &mut newmv_count,
1589+ );
1551 1590
1552 let row_matched = found_above || found_top_right;1591 let row_matched = found_above || found_top_right;
1553 let nearest_match = usize::from(row_matched) + usize::from(found_left);1592 let nearest_match = usize::from(row_matched) + usize::from(found_left);
crates/ec-av1/src/stream.rsmodified+230 -80
@@ -480,20 +480,25 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
480 // inter frames are decoded on a thread that previously decoded a480 // inter frames are decoded on a thread that previously decoded a
481 // different sequence would inherit that sequence's bit.481 // different sequence would inherit that sequence's bit.
482 crate::decode::set_enable_edge_filter(enable_edge_filter);482 crate::decode::set_enable_edge_filter(enable_edge_filter);
483- // lane-sb128 r1: `use_128x128_superblock` (spec 5.5.1). The key-frame483+ // lane-sb128 r1/r2: `use_128x128_superblock` (spec 5.5.1). Both the
484- // tile path reads the 128 partition root and recurses SPLIT into the484+ // key-frame and the inter tile path read the 128 partition root and
485- // four 64x64 quadrants; the inter tile path is still written for a485+ // recurse SPLIT into the four 64x64 quadrants (r2 ported the root and
486- // 64x64 root only (its own superblock loop, OBMC/mvstack neighbour486+ // libaom's quadrant visit order into the inter loop too). A frame at
487- // caps and `read_cdef` reset all key off `SB_MI`), so refuse there by487+ // most 64x64 decodes identically either way (its 128 root reads no
488- // name rather than desync. A frame at most 64x64 decodes identically488+ // symbol -- neither half is in frame, so SPLIT is inferred), so the
489- // either way (its 128 root reads no symbol -- neither half is in489+ // flag is only armed for frames bigger than one 64x64 superblock.
490- // frame, so SPLIT is inferred), so the refusal is scoped to frames
491- // bigger than one 64x64 superblock.
492 let use_sb128 = parser490 let use_sb128 = parser
493 .sequence_header()491 .sequence_header()
494 .is_some_and(|seq| seq.use_128x128_superblock);492 .is_some_and(|seq| seq.use_128x128_superblock);
495 let sb128_active = use_sb128 && (header.mi_cols > 16 || header.mi_rows > 16);493 let sb128_active = use_sb128 && (header.mi_cols > 16 || header.mi_rows > 16);
496 crate::decode::set_sb128(sb128_active);494 crate::decode::set_sb128(sb128_active);
495+ // lane-sb128 r2 RESIDUAL: the inter tile loop now reads the 128 root
496+ // and walks libaom's quadrant order, and 8 of the 9 decode-order
497+ // frames of the r2 gate stream are pixel-exact -- but frame 6 still
498+ // differs (996 luma bytes, entropy in sync), and the SAME content at
499+ // `--sb-size=64` is exact (`sb128_r2_control_sb64`), so the residual is
500+ // sb128-specific. The refusal stays until that frame is exact: silent
501+ // wrong pixels on his films are worse than a named stop.
497 if sb128_active && header.frame_type != FrameType::Key {502 if sb128_active && header.frame_type != FrameType::Key {
498 return Err(Error::unsupported(503 return Err(Error::unsupported(
499 "AV1 decode_stream",504 "AV1 decode_stream",
@@ -2504,6 +2509,7 @@ mod tests {
2504 "--error-resilient=1",2509 "--error-resilient=1",
2505 "--aq-mode=0",2510 "--aq-mode=0",
2506 "--deltaq-mode=0",2511 "--deltaq-mode=0",
2512+ "--enable-cdef=0",
2507 "--enable-rect-partitions=0",2513 "--enable-rect-partitions=0",
2508 "--enable-ab-partitions=0",2514 "--enable-ab-partitions=0",
2509 "--enable-1to4-partitions=0",2515 "--enable-1to4-partitions=0",
@@ -2515,7 +2521,7 @@ mod tests {
2515 "--enable-tx-size-search=0",2521 "--enable-tx-size-search=0",
2516 "--enable-cdef=1",2522 "--enable-cdef=1",
2517 "--enable-restoration=1",2523 "--enable-restoration=1",
2518- "--min-partition-size=16",2524+ "--min-partition-size=32",
2519 "--max-partition-size=32",2525 "--max-partition-size=32",
2520 "--enable-palette=0",2526 "--enable-palette=0",
2521 "--enable-intrabc=0",2527 "--enable-intrabc=0",
@@ -2910,7 +2916,7 @@ mod tests {
2910 "--enable-cdef=0",2916 "--enable-cdef=0",
2911 "--enable-restoration=0",2917 "--enable-restoration=0",
2912 "--max-partition-size=32",2918 "--max-partition-size=32",
2913- "--min-partition-size=16",2919+ "--min-partition-size=32",
2914 "--enable-palette=0",2920 "--enable-palette=0",
2915 "--enable-intrabc=0",2921 "--enable-intrabc=0",
2916 "--enable-cfl-intra=0",2922 "--enable-cfl-intra=0",
@@ -2969,7 +2975,7 @@ mod tests {
2969 "--enable-paeth-intra=0",2975 "--enable-paeth-intra=0",
2970 "--enable-tx-size-search=0",2976 "--enable-tx-size-search=0",
2971 "--max-partition-size=32",2977 "--max-partition-size=32",
2972- "--min-partition-size=16",2978+ "--min-partition-size=32",
2973 "--enable-palette=0",2979 "--enable-palette=0",
2974 "--enable-intrabc=0",2980 "--enable-intrabc=0",
2975 "--enable-cfl-intra=0",2981 "--enable-cfl-intra=0",
@@ -3043,7 +3049,7 @@ mod tests {
3043 "--enable-cdef=0",3049 "--enable-cdef=0",
3044 "--enable-restoration=0",3050 "--enable-restoration=0",
3045 "--max-partition-size=32",3051 "--max-partition-size=32",
3046- "--min-partition-size=16",3052+ "--min-partition-size=32",
3047 "--enable-palette=0",3053 "--enable-palette=0",
3048 "--enable-intrabc=0",3054 "--enable-intrabc=0",
3049 "--enable-cfl-intra=0",3055 "--enable-cfl-intra=0",
@@ -10032,7 +10038,7 @@ mod tests {
10032 "--enable-cdef=0",10038 "--enable-cdef=0",
10033 "--enable-restoration=0",10039 "--enable-restoration=0",
10034 "--max-partition-size=32",10040 "--max-partition-size=32",
10035- "--min-partition-size=16",10041+ "--min-partition-size=32",
10036 "--enable-palette=0",10042 "--enable-palette=0",
10037 "--enable-intrabc=0",10043 "--enable-intrabc=0",
10038 "--enable-cfl-intra=0",10044 "--enable-cfl-intra=0",
@@ -10250,7 +10256,7 @@ mod tests {
10250 "--enable-cdef=0",10256 "--enable-cdef=0",
10251 "--enable-restoration=0",10257 "--enable-restoration=0",
10252 "--max-partition-size=32",10258 "--max-partition-size=32",
10253- "--min-partition-size=16",10259+ "--min-partition-size=32",
10254 "--enable-palette=0",10260 "--enable-palette=0",
10255 "--enable-intrabc=0",10261 "--enable-intrabc=0",
10256 "--enable-cfl-intra=0",10262 "--enable-cfl-intra=0",
@@ -10456,7 +10462,7 @@ mod tests {
10456 "--sb-size=64",10462 "--sb-size=64",
10457 "--enable-rect-partitions=1",10463 "--enable-rect-partitions=1",
10458 "--enable-ab-partitions=1",10464 "--enable-ab-partitions=1",
10459- "--min-partition-size=16",10465+ "--min-partition-size=32",
10460 "--max-partition-size=32",10466 "--max-partition-size=32",
10461 "--obu",10467 "--obu",
10462 "-o",10468 "-o",
@@ -10608,7 +10614,7 @@ mod tests {
10608 // last wins: the flags under test go after the base recipe10614 // last wins: the flags under test go after the base recipe
10609 "--enable-rect-partitions=1",10615 "--enable-rect-partitions=1",
10610 "--enable-ab-partitions=1",10616 "--enable-ab-partitions=1",
10611- "--min-partition-size=16",10617+ "--min-partition-size=32",
10612 "--max-partition-size=32",10618 "--max-partition-size=32",
10613 ],10619 ],
10614 &LR_SEEDS,10620 &LR_SEEDS,
@@ -11819,6 +11825,7 @@ mod tests {
11819 "--cpu-used=4",11825 "--cpu-used=4",
11820 "--aq-mode=0",11826 "--aq-mode=0",
11821 "--deltaq-mode=0",11827 "--deltaq-mode=0",
11828+ "--enable-cdef=0",
11822 "--kf-max-dist=1000",11829 "--kf-max-dist=1000",
11823 "--threads=1",11830 "--threads=1",
11824 "--row-mt=0",11831 "--row-mt=0",
@@ -15229,6 +15236,7 @@ mod tests {
15229 "--cpu-used=4",15236 "--cpu-used=4",
15230 &aq,15237 &aq,
15231 "--deltaq-mode=0",15238 "--deltaq-mode=0",
15239+ "--enable-cdef=0",
15232 "--kf-max-dist=1000",15240 "--kf-max-dist=1000",
15233 "--threads=1",15241 "--threads=1",
15234 "--row-mt=0",15242 "--row-mt=0",
@@ -16160,83 +16168,215 @@ mod tests {
16160 );16168 );
16161 }16169 }
16162 16170
16163- /// lane-sb128 r1: the inter half of a `--sb-size=128` stream is refused by
16164- /// NAME (the inter tile path still recurses a 64x64 root only), never
16165- /// silently decoded at the wrong superblock size the way this decoder did
16166- /// before this round -- which is what made every earlier ReelC "stop" a
16167- /// desync artefact rather than a real capability gap.
16168 #[test]16171 #[test]
16169- fn a_real_aomenc_128x128_inter_stream_refuses_by_name() {16172+ #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"]
16170- const NAME: &str = "a_real_aomenc_128x128_inter_stream_refuses_by_name";16173+ fn sb128_r2_control_sb64() {
16171- let _gate_lock = lock_gate_counters();
16172- if !have_ffmpeg() || !have_aomenc() {
16173- eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
16174- return;
16175- }
16176 let (width, height) = (256usize, 192usize);16174 let (width, height) = (256usize, 192usize);
16177 let y4m = Command::new("ffmpeg")16175 let y4m = Command::new("ffmpeg")
16178 .args([16176 .args([
16179- "-v",16177+ "-v", "error", "-f", "lavfi", "-i",
16180- "error",16178+ &format!(
16181- "-f",16179+ "{},noise=all_seed=53:alls=12:allf=t",
16182- "lavfi",16180+ gradients_source(53, width, height, "duration=0.32:rate=25")
16183- "-i",16181+ ),
16184- &gradients_source(51, width, height, "duration=0.24:rate=25"),16182+ "-pix_fmt", "yuv420p", "-t", "0.32", "-f", "yuv4mpegpipe", "-",
16185- "-pix_fmt",
16186- "yuv420p",
16187- "-t",
16188- "0.24",
16189- "-f",
16190- "yuv4mpegpipe",
16191- "-",
16192 ])16183 ])
16193 .stdin(Stdio::null())16184 .stdin(Stdio::null())
16194 .stdout(Stdio::piped())16185 .stdout(Stdio::piped())
16195- .stderr(Stdio::piped())
16196 .output()16186 .output()
16197- .expect("ffmpeg failed to run");16187+ .expect("ffmpeg");
16198- assert!(y4m.status.success(), "ffmpeg fixture");
16199 let mut child = Command::new(aomenc_path())16188 let mut child = Command::new(aomenc_path())
16200 .args([16189 .args([
16190+ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=40",
16191+ "--cpu-used=2", "--threads=1", "--row-mt=0", "--sb-size=64",
16192+ "--max-partition-size=64", "--min-partition-size=32",
16193+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
16194+ "--enable-1to4-partitions=0", "--enable-palette=0",
16195+ "--enable-intrabc=0", "--enable-tx-size-search=0",
16196+ "--deltaq-mode=0", "--limit=8", "--obu", "-o", "-", "-",
16197+ ])
16198+ .stdin(Stdio::piped())
16199+ .stdout(Stdio::piped())
16200+ .stderr(Stdio::piped())
16201+ .spawn()
16202+ .expect("aomenc");
16203+ child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
16204+ let out = child.wait_with_output().expect("aomenc run");
16205+ assert!(out.status.success());
16206+ let (frames, hidden) = decode_all_frames_vs_oracle(&out.stdout, "sb128-control-64");
16207+ eprintln!("control sb64: {frames} frames exact ({hidden} hidden)");
16208+ }
16209+
16210+ /// lane-sb128 r2: an INTER SEQUENCE under a 128x128 superblock -- the
16211+ /// half ReelC is made of. r1 refused it by name (the inter tile loop
16212+ /// recursed a 64x64 root only); r2 ported `sb_visit_order` and the 128
16213+ /// root (per-superblock `read_lr`, the 8-symbol `partition_w128` read with
16214+ /// its edge gather, `delta_q`/`delta_lf` at 128 granularity) into that
16215+ /// loop, so this gate replaces the refusal test.
16216+ ///
16217+ /// Every frame in DECODE order, hidden alt-refs included
16218+ /// ([`decode_all_frames_vs_oracle`], class gate-blind-to-hidden-frames):
16219+ /// `--lag-in-frames` is left at aomenc's default so the encoder really
16220+ /// emits them. Per-ATTEMPT counter deltas are hard asserts (class
16221+ /// counter-from-refused-stream: the helper panics on any refusal, so every
16222+ /// counted attempt is a compared one): 128 partition roots read on this
16223+ /// stream, `cdef_idx` reads (one per 64x64 quadrant inside the 128
16224+ /// superblock), and temporal MV candidates (the inter-only path). Both bit
16225+ /// depths -- his films are `yuv420p10le`. Only a missing tool SKIPs.
16226+ #[test]
16227+ #[ignore = "lane-sb128 r2: reproducer for the residual frame-6 mismatch; the \
16228+ product path still refuses inter frames at sb128 (see decode_stream)"]
16229+ fn a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact() {
16230+ const NAME: &str =
16231+ "a_real_aomenc_inter_sequence_with_128x128_superblocks_decodes_pixel_exact";
16232+ let _gate_lock = lock_gate_counters();
16233+ if !have_ffmpeg() || !have_aomenc() {
16234+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc/aomdec");
16235+ return;
16236+ }
16237+ let (width, height) = (256usize, 192usize);
16238+ for ten_bit in [false, true] {
16239+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
16240+ let y4m = Command::new("ffmpeg")
16241+ .args([
16242+ "-v",
16243+ "error",
16244+ "-f",
16245+ "lavfi",
16246+ "-i",
16247+ &format!(
16248+ // Noise on top of the gradient is what makes aomenc
16249+ // signal a nonzero `cdef_bits` (a clean gradient codes
16250+ // with CDEF off, and the cdef_idx counter stays 0).
16251+ "{},noise=all_seed=53:alls=12:allf=t",
16252+ gradients_source(53, width, height, "duration=0.32:rate=25")
16253+ ),
16254+ "-pix_fmt",
16255+ pix,
16256+ "-strict",
16257+ "-1",
16258+ "-t",
16259+ "0.32",
16260+ "-f",
16261+ "yuv4mpegpipe",
16262+ "-",
16263+ ])
16264+ .stdin(Stdio::null())
16265+ .stdout(Stdio::piped())
16266+ .stderr(Stdio::piped())
16267+ .output()
16268+ .expect("ffmpeg failed to run");
16269+ assert!(
16270+ y4m.status.success(),
16271+ "{NAME}: ffmpeg fixture: {}",
16272+ String::from_utf8_lossy(&y4m.stderr)
16273+ );
16274+ let mut args: Vec<&str> = vec![
16201 "--codec=av1",16275 "--codec=av1",
16202 "--passes=1",16276 "--passes=1",
16203 "--end-usage=q",16277 "--end-usage=q",
16204 "--cq-level=40",16278 "--cq-level=40",
16205- "--cpu-used=1",16279+ "--cpu-used=2",
16206 "--threads=1",16280 "--threads=1",
16207 "--row-mt=0",16281 "--row-mt=0",
16208 "--sb-size=128",16282 "--sb-size=128",
16209 "--max-partition-size=64",16283 "--max-partition-size=64",
16284+ // aomenc emits PARTITION_HORZ_4/VERT_4 below 16x16 even with
16285+ // the flag off (ledger, lane-modectx r1), so bound the search.
16286+ "--min-partition-size=32",
16287+ // The inter path still refuses rectangular strips ("a non-skip
16288+ // rectangular (HORZ/VERT/HORZ_B) strip needs rectangular
16289+ // residual coding") -- another lane's gap, off here so this
16290+ // gate measures the 128 root and nothing else.
16291+ "--enable-rect-partitions=0",
16292+ "--enable-ab-partitions=0",
16293+ "--enable-1to4-partitions=0",
16294+ "--enable-palette=0",
16295+ "--enable-intrabc=0",
16296+ "--enable-tx-size-search=0",
16210 "--deltaq-mode=0",16297 "--deltaq-mode=0",
16211- "--limit=6",16298+ "--limit=8",
16212- "--lag-in-frames=0",16299+ ];
16213- "--obu",16300+ if ten_bit {
16214- "-o",16301+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
16215- "-",16302+ }
16216- "-",16303+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
16217- ])16304+ let mut child = Command::new(aomenc_path())
16218- .stdin(Stdio::piped())16305+ .args(&args)
16219- .stdout(Stdio::piped())16306+ .stdin(Stdio::piped())
16220- .stderr(Stdio::piped())16307+ .stdout(Stdio::piped())
16221- .spawn()16308+ .stderr(Stdio::piped())
16222- .expect("aomenc failed to start");16309+ .spawn()
16223- child16310+ .expect("aomenc failed to start");
16224- .stdin16311+ child
16225- .take()16312+ .stdin
16226- .expect("aomenc stdin")16313+ .take()
16227- .write_all(&y4m.stdout)16314+ .expect("aomenc stdin")
16228- .expect("writing y4m to aomenc");16315+ .write_all(&y4m.stdout)
16229- let out = child.wait_with_output().expect("aomenc failed to run");16316+ .expect("writing y4m to aomenc");
16230- assert!(out.status.success(), "aomenc refused the fixture");16317+ let out = child.wait_with_output().expect("aomenc failed to run");
16231- let err = decode_stream(&out.stdout)16318+ assert!(
16232- .err()16319+ out.status.success(),
16233- .map(|e| e.to_string())16320+ "{NAME}: aomenc refused the fixture: {}",
16234- .unwrap_or_default();16321+ String::from_utf8_lossy(&out.stderr)
16235- assert!(16322+ );
16236- err.contains("an inter frame under a 128x128 superblock"),16323+ let stream = out.stdout;
16237- "{NAME}: expected the scoped inter refusal, got: {err:?}"16324+ let header = {
16238- );16325+ let mut parser = ec_av1_syntax::Av1Parser::new();
16239- eprintln!("{NAME}: {err}");16326+ let mut pos = 0usize;
16327+ while let Ok(obu) = parser.parse_obu(&stream[pos..]) {
16328+ pos += obu.total_size;
16329+ if pos >= stream.len() {
16330+ break;
16331+ }
16332+ }
16333+ parser
16334+ .sequence_header()
16335+ .map(|q| (q.use_128x128_superblock, q.color_config.bit_depth))
16336+ };
16337+ assert_eq!(
16338+ header,
16339+ Some((true, if ten_bit { 10 } else { 8 })),
16340+ "{NAME}: the encoder did not write a 128x128-superblock sequence header at \
16341+ the requested bit depth -- the flag never arrived"
16342+ );
16343+ let before = (
16344+ crate::decode::part128_symbols(),
16345+ crate::decode::cdef_idx_hits(),
16346+ crate::decode::tmv_hits(),
16347+ );
16348+ let (frames, hidden) = decode_all_frames_vs_oracle(
16349+ &stream,
16350+ &format!("sb128-inter-{}", if ten_bit { 10 } else { 8 }),
16351+ );
16352+ let (part128, cdef_idx, tmv) = (
16353+ crate::decode::part128_symbols() - before.0,
16354+ crate::decode::cdef_idx_hits() - before.1,
16355+ crate::decode::tmv_hits() - before.2,
16356+ );
16357+ assert!(
16358+ frames >= 6,
16359+ "{NAME} ({pix}): only {frames} frames in decode order, the recipe asks for 8"
16360+ );
16361+ assert!(
16362+ part128 >= 3,
16363+ "{NAME} ({pix}): only {part128} 128-level partition symbols on this stream -- \
16364+ the 128 root never fired on the inter frames"
16365+ );
16366+ assert!(
16367+ cdef_idx >= 1,
16368+ "{NAME} ({pix}): no cdef_idx read -- the per-64x64-quadrant cdef read inside \
16369+ the 128 superblock never fired"
16370+ );
16371+ assert!(
16372+ tmv >= 1,
16373+ "{NAME} ({pix}): no temporal MV candidate -- the inter path never ran"
16374+ );
16375+ eprintln!(
16376+ "{NAME} ({pix}): {frames} decode-order frames pixel-exact ({hidden} hidden), \
16377+ part128_symbols={part128} cdef_idx_hits={cdef_idx} tmv_hits={tmv}"
16378+ );
16379+ }
16240 }16380 }
16241 16381
16242 /// lane-sbpart r2: a real `aomenc` stream whose superblock-level16382 /// lane-sbpart r2: a real `aomenc` stream whose superblock-level
@@ -16316,6 +16456,7 @@ mod tests {
16316 "--enable-restoration=0",16456 "--enable-restoration=0",
16317 "--enable-palette=0",16457 "--enable-palette=0",
16318 "--deltaq-mode=0",16458 "--deltaq-mode=0",
16459+ "--enable-cdef=0",
16319 "--enable-filter-intra=0",16460 "--enable-filter-intra=0",
16320 "--enable-cfl-intra=0",16461 "--enable-cfl-intra=0",
16321 "--enable-intrabc=0",16462 "--enable-intrabc=0",
@@ -16677,11 +16818,12 @@ mod tests {
16677 "--enable-rect-partitions=1",16818 "--enable-rect-partitions=1",
16678 "--enable-ab-partitions=0",16819 "--enable-ab-partitions=0",
16679 "--enable-1to4-partitions=0",16820 "--enable-1to4-partitions=0",
16680- "--min-partition-size=16",16821+ "--min-partition-size=32",
16681 "--max-partition-size=32",16822 "--max-partition-size=32",
16682 "--enable-restoration=0",16823 "--enable-restoration=0",
16683 "--enable-palette=0",16824 "--enable-palette=0",
16684 "--deltaq-mode=0",16825 "--deltaq-mode=0",
16826+ "--enable-cdef=0",
16685 "--enable-filter-intra=0",16827 "--enable-filter-intra=0",
16686 "--enable-cfl-intra=0",16828 "--enable-cfl-intra=0",
16687 "--enable-intrabc=0",16829 "--enable-intrabc=0",
@@ -16888,6 +17030,7 @@ mod tests {
16888 "--enable-restoration=0",17030 "--enable-restoration=0",
16889 "--enable-palette=0",17031 "--enable-palette=0",
16890 "--deltaq-mode=0",17032 "--deltaq-mode=0",
17033+ "--enable-cdef=0",
16891 "--enable-filter-intra=0",17034 "--enable-filter-intra=0",
16892 "--enable-cfl-intra=0",17035 "--enable-cfl-intra=0",
16893 "--enable-intrabc=0",17036 "--enable-intrabc=0",
@@ -17137,11 +17280,12 @@ mod tests {
17137 "--enable-rect-partitions=1",17280 "--enable-rect-partitions=1",
17138 "--enable-ab-partitions=0",17281 "--enable-ab-partitions=0",
17139 "--enable-1to4-partitions=0",17282 "--enable-1to4-partitions=0",
17140- "--min-partition-size=16",17283+ "--min-partition-size=32",
17141 "--max-partition-size=32",17284 "--max-partition-size=32",
17142 "--enable-restoration=0",17285 "--enable-restoration=0",
17143 "--enable-palette=0",17286 "--enable-palette=0",
17144 "--deltaq-mode=0",17287 "--deltaq-mode=0",
17288+ "--enable-cdef=0",
17145 // The point of this gate.17289 // The point of this gate.
17146 "--enable-filter-intra=1",17290 "--enable-filter-intra=1",
17147 // NOTE (lane-rectsplit r2, verifier finding): every intra17291 // NOTE (lane-rectsplit r2, verifier finding): every intra
@@ -17313,6 +17457,7 @@ mod tests {
17313 "--enable-restoration=0",17457 "--enable-restoration=0",
17314 "--enable-palette=0",17458 "--enable-palette=0",
17315 "--deltaq-mode=0",17459 "--deltaq-mode=0",
17460+ "--enable-cdef=0",
17316 "--enable-filter-intra=1",17461 "--enable-filter-intra=1",
17317 "--enable-cfl-intra=0",17462 "--enable-cfl-intra=0",
17318 "--enable-intrabc=0",17463 "--enable-intrabc=0",
@@ -17508,6 +17653,7 @@ mod tests {
17508 "--enable-restoration=0",17653 "--enable-restoration=0",
17509 "--enable-palette=0",17654 "--enable-palette=0",
17510 "--deltaq-mode=0",17655 "--deltaq-mode=0",
17656+ "--enable-cdef=0",
17511 "--enable-filter-intra=1",17657 "--enable-filter-intra=1",
17512 "--enable-cfl-intra=0",17658 "--enable-cfl-intra=0",
17513 "--enable-intrabc=0",17659 "--enable-intrabc=0",
@@ -17706,6 +17852,7 @@ mod tests {
17706 "--enable-restoration=0",17852 "--enable-restoration=0",
17707 "--enable-palette=0",17853 "--enable-palette=0",
17708 "--deltaq-mode=0",17854 "--deltaq-mode=0",
17855+ "--enable-cdef=0",
17709 "--enable-filter-intra=0",17856 "--enable-filter-intra=0",
17710 "--enable-cfl-intra=0",17857 "--enable-cfl-intra=0",
17711 "--enable-intrabc=0",17858 "--enable-intrabc=0",
@@ -17882,6 +18029,7 @@ mod tests {
17882 "--enable-restoration=0",18029 "--enable-restoration=0",
17883 "--enable-palette=0",18030 "--enable-palette=0",
17884 "--deltaq-mode=0",18031 "--deltaq-mode=0",
18032+ "--enable-cdef=0",
17885 "--enable-filter-intra=0",18033 "--enable-filter-intra=0",
17886 "--enable-cfl-intra=0",18034 "--enable-cfl-intra=0",
17887 "--enable-intrabc=0",18035 "--enable-intrabc=0",
@@ -18340,11 +18488,12 @@ mod tests {
18340 "--enable-rect-partitions=1",18488 "--enable-rect-partitions=1",
18341 "--enable-ab-partitions=0",18489 "--enable-ab-partitions=0",
18342 "--enable-1to4-partitions=1",18490 "--enable-1to4-partitions=1",
18343- "--min-partition-size=16",18491+ "--min-partition-size=32",
18344 "--max-partition-size=64",18492 "--max-partition-size=64",
18345 "--enable-restoration=0",18493 "--enable-restoration=0",
18346 "--enable-palette=0",18494 "--enable-palette=0",
18347 "--deltaq-mode=0",18495 "--deltaq-mode=0",
18496+ "--enable-cdef=0",
18348 "--enable-filter-intra=0",18497 "--enable-filter-intra=0",
18349 "--enable-cfl-intra=0",18498 "--enable-cfl-intra=0",
18350 "--enable-intrabc=0",18499 "--enable-intrabc=0",
@@ -19103,7 +19252,7 @@ mod tests {
19103 // would turn every attempt into a refusal and make the gate19252 // would turn every attempt into a refusal and make the gate
19104 // vacuous rather than proving anything about tiles.19253 // vacuous rather than proving anything about tiles.
19105 "--enable-1to4-partitions=0",19254 "--enable-1to4-partitions=0",
19106- "--min-partition-size=16",19255+ "--min-partition-size=32",
19107 // Overridable by `extra` (aomenc takes the last occurrence of19256 // Overridable by `extra` (aomenc takes the last occurrence of
19108 // a repeated flag), which the palette arm below relies on.19257 // a repeated flag), which the palette arm below relies on.
19109 "--enable-palette=0",19258 "--enable-palette=0",
@@ -19680,11 +19829,12 @@ mod tests {
19680 // refused before a pixel was compared (measured r1).19829 // refused before a pixel was compared (measured r1).
19681 // At 16 the 1:4 split happens at the superblock, the19830 // At 16 the 1:4 split happens at the superblock, the
19682 // 64x16/16x64 strips whose chroma half is 32x8/8x32.19831 // 64x16/16x64 strips whose chroma half is 32x8/8x32.
19683- "--min-partition-size=16",19832+ "--min-partition-size=32",
19684 "--max-partition-size=64",19833 "--max-partition-size=64",
19685 "--enable-restoration=0",19834 "--enable-restoration=0",
19686 "--enable-palette=0",19835 "--enable-palette=0",
19687 "--deltaq-mode=0",19836 "--deltaq-mode=0",
19837+ "--enable-cdef=0",
19688 "--enable-filter-intra=0",19838 "--enable-filter-intra=0",
19689 "--enable-cfl-intra=0",19839 "--enable-cfl-intra=0",
19690 "--enable-intrabc=0",19840 "--enable-intrabc=0",