forge
Explore
Log in

Don't you dare go Hollow

Decode the LUMA half of a 128x128 PARTITION_NONE root

Browse files at this commit

3d9370c90ae804b912666804f7c250acc647cef6Ahmet Kaan GümüşParent: 9852037
  • feat
    • decode the LUMA half of a 128x128 PARTITION_NONE root
    • refuse its chroma by name
Show full message
feat(av1): decode the LUMA half of a 128x128 PARTITION_NONE root; refuse its chroma by name

lane-sb128b r1. `read_sb128_root` now returns the root partition instead of
refusing everything but SPLIT, and the key-frame tile loop decodes a
`PARTITION_NONE` 128 root as one 128x128 intra block (the other three visits
of that superblock code nothing).

Generalised, all measured against libaom rather than assumed:
- `read_tx_size`: `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64, so a
  128 block reads BLOCK_64X64's own depth category and resolves against 64,
  never against its own side.
- `decode_block`: the single-transform-unit arm was `!tx_select || logical_tx
  == side`; without `tx_select` `logical_tx` IS `side` at every size <= 64, so
  the first half was redundant -- and wrong at 128, where the block is four
  TX_64X64 units either way. The TU loop now passes the unit's own COEFFICIENT
  side (32 at TX_64X64), not its transform side.
- `delta_q`/`delta_lf`: "this leaf IS the superblock" now compares against the
  sequence's superblock size instead of a hardcoded 64 (a NONE 128 root is the
  whole superblock).
- the 128 block's single `cdef_idx` read is copied to all four 64x64 CDEF
  units, which is what libaom's shared `MB_MODE_INFO` does.

RESIDUAL, and why the arm still refuses in the product path:
`av1_get_max_uv_txsize` runs `av1_get_adjusted_tx_size` over the 64x64 uv plane
block, so a 128 block's chroma is FOUR TX_32X32 units per plane, not one
TX_64X64 unit -- `decode_block` codes one whole-plane chroma unit and desyncs
there. New gate
`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact`
(real aomenc --sb-size=128, no --max-partition-size, smooth gradients at cq
55/63, 384x384 + 256x256, 8- and 10-bit) is the reproducer, #[ignore]d until
the chroma loop lands.

refusal_inventory: the one "partition other than SPLIT" string splits into the
HORZ/VERT/AB arm, the inter NONE arm, and the chroma residual above.
crates/ec-av1/src/decode.rsmodified+155 -25
@@ -281,10 +281,12 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_
281 if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {281 if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {
282 return;282 return;
283 }283 }
284- // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which284+ // `is_whole_sb` is the caller's "this leaf IS the superblock" flag,
285- // it computes against the 64x64 root; under a 128 superblock no leaf this285+ // computed against the sequence's own superblock size (lane-sb128b r1:
286- // decoder codes can be the whole superblock (the root is always SPLIT).286+ // it used to be hardcoded against 64 and disabled under `sb128`, which a
287- if is_whole_sb && !sb128() && skip {287+ // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes
288+ // wrong).
289+ if is_whole_sb && skip {
288 return;290 return;
289 }291 }
290 let mut abs = dec.symbol(&mut cdfs.delta_q) as i32;292 let mut abs = dec.symbol(&mut cdfs.delta_q) as i32;
@@ -340,10 +342,12 @@ fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi
340 if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {342 if mi_r % sb_mi != 0 || mi_c % sb_mi != 0 {
341 return;343 return;
342 }344 }
343- // `is_whole_sb` is the caller's "this leaf IS the superblock" flag, which345+ // `is_whole_sb` is the caller's "this leaf IS the superblock" flag,
344- // it computes against the 64x64 root; under a 128 superblock no leaf this346+ // computed against the sequence's own superblock size (lane-sb128b r1:
345- // decoder codes can be the whole superblock (the root is always SPLIT).347+ // it used to be hardcoded against 64 and disabled under `sb128`, which a
346- if is_whole_sb && !sb128() && skip {348+ // `PARTITION_NONE` 128x128 root -- itself the whole superblock -- makes
349+ // wrong).
350+ if is_whole_sb && skip {
347 return;351 return;
348 }352 }
349 let multi = DELTA_LF_MULTI.with(|c| c.get());353 let multi = DELTA_LF_MULTI.with(|c| c.get());
@@ -7414,8 +7418,12 @@ fn read_intra_mode(
7414 // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here.7418 // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here.
7415 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);7419 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
7416 istep!("cdef", 0);7420 istep!("cdef", 0);
7417- maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip);7421+ // lane-sb128b r1: "this leaf IS the superblock" is `side == sb_size`, not
7418- maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip);7422+ // a hardcoded 64 -- a `PARTITION_NONE` 128x128 root is the whole
7423+ // superblock and skips `delta_q` exactly like a 64 one under a 64 root.
7424+ let whole_sb = side == sb_mi_cur() as usize * 4;
7425+ maybe_read_delta_q(dec, cdfs, mi_r, mi_c, whole_sb, skip);
7426+ maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, whole_sb, skip);
7419 istep!("dq", 0);7427 istep!("dq", 0);
7420 // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at7428 // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at
7421 // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before7429 // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before
@@ -8252,7 +8260,11 @@ fn decode_block(
8252 let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None);8260 let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None);
8253 (resolved, if resolved == 64 { 32 } else { resolved })8261 (resolved, if resolved == 64 { 32 } else { resolved })
8254 } else {8262 } else {
8255- (side, luma_tx)8263+ // lane-sb128b r1: `max_txsize_rect_lookup[BLOCK_128X128]` is
8264+ // TX_64X64, so a 128x128 block is always FOUR luma transform units
8265+ // even with `tx_select` off -- the TU loop below, never the
8266+ // single-unit path.
8267+ (side.min(64), luma_tx)
8256 };8268 };
8257 if tx_select && logical_tx < side && uv_mode != DC_PRED {8269 if tx_select && logical_tx < side && uv_mode != DC_PRED {
8258 SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1));8270 SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1));
@@ -8393,7 +8405,12 @@ fn decode_block(
8393 let u_grid = vec![0i32; chroma_side * chroma_side];8405 let u_grid = vec![0i32; chroma_side * chroma_side];
8394 let v_grid = vec![0i32; chroma_side * chroma_side];8406 let v_grid = vec![0i32; chroma_side * chroma_side];
8395 neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);8407 neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
8396- } else if !tx_select || logical_tx == side {8408+ } else if logical_tx == side {
8409+ // lane-sb128b r1: the test used to be `!tx_select || logical_tx == side`.
8410+ // Without `tx_select` `logical_tx` IS `side` at every size <= 64, so
8411+ // that arm was redundant -- and wrong at 128, where
8412+ // `max_txsize_rect_lookup` caps the block's transform at 64 and the
8413+ // block is four units whether or not `tx_select` is on.
8397 // A single luma transform unit -- the old path, unchanged (including8414 // A single luma transform unit -- the old path, unchanged (including
8398 // the 64x64 corner case, `logical_tx == side == 64` with8415 // the 64x64 corner case, `logical_tx == side == 64` with
8399 // `coeff_tx_side == 32`).8416 // `coeff_tx_side == 32`).
@@ -8542,7 +8559,11 @@ fn decode_block(
8542 tu_px,8559 tu_px,
8543 tu_py,8560 tu_py,
8544 logical_tx,8561 logical_tx,
8545- logical_tx,8562+ // The unit's own COEFFICIENT grid, half its side at
8563+ // TX_64X64 (a 64-point transform codes nothing past 32);
8564+ // identical to `logical_tx` at every smaller size
8565+ // (lane-sb128b r1).
8566+ coeff_tx_side,
8546 base_q_idx,8567 base_q_idx,
8547 None,8568 None,
8548 filter_intra,8569 filter_intra,
@@ -9978,8 +9999,14 @@ fn read_tx_size(
9978 // key-frame path's own deblock-grid approximation.9999 // key-frame path's own deblock-grid approximation.
9979 ctx_override: Option<usize>,10000 ctx_override: Option<usize>,
9980 ) -> usize {10001 ) -> usize {
9981- let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side));10002+ // `max_txsize_rect_lookup[bsize]` (libaom `read_selected_tx_size` /
9982- let depth = match side {10003+ // `get_tx_size_context`): a block wider than 64 still tops out at
10004+ // TX_64X64, so BLOCK_128X128 reads BLOCK_64X64's own category (its depth
10005+ // chain 64->32->16->8->4 is the same four steps) and resolves against 64,
10006+ // never against its own 128 side (lane-sb128b r1).
10007+ let max_tx = side.min(64);
10008+ let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, max_tx));
10009+ let depth = match max_tx {
9983 8 => {10010 8 => {
9984 dec.symbol(&mut cdfs.tx_size_cat0[ctx])10011 dec.symbol(&mut cdfs.tx_size_cat0[ctx])
9985 }10012 }
@@ -9992,7 +10019,7 @@ fn read_tx_size(
9992 64 => {10019 64 => {
9993 dec.symbol(&mut cdfs.tx_size_cat3[ctx])10020 dec.symbol(&mut cdfs.tx_size_cat3[ctx])
9994 }10021 }
9995- _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"),10022+ _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"),
9996 };10023 };
9997 if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {10024 if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
9998 let (rng, _) = dec.debug_state();10025 let (rng, _) = dec.debug_state();
@@ -10004,7 +10031,7 @@ fn read_tx_size(
10004 if depth != 0 {10031 if depth != 0 {
10005 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));10032 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
10006 }10033 }
10007- side >> depth10034+ max_tx >> depth
10008 }10035 }
10009 10036
10010 /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's10037 /// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's
@@ -11250,6 +11277,17 @@ fn sb_visit_order(r0: u32, r1: u32, c0: u32, c1: u32, sb128: bool) -> Vec<(u32,
11250 /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this11277 /// decides the root -- only SPLIT recurses into the four 64x64 quadrants this
11251 /// decoder codes, the other seven arms refuse by name.11278 /// decoder codes, the other seven arms refuse by name.
11252 #[allow(clippy::too_many_arguments)]11279 #[allow(clippy::too_many_arguments)]
11280+thread_local! {
11281+ /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one
11282+ /// whole 128x128 block (lane-sb128b r1's gate counter).
11283+ pub(crate) static PART128_NONE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
11284+}
11285+
11286+/// [`PART128_NONE_HITS`], for a gate's own before/after delta.
11287+pub(crate) fn part128_none_hits() -> usize {
11288+ PART128_NONE_HITS.with(std::cell::Cell::get)
11289+}
11290+
11253 fn read_sb128_root(11291 fn read_sb128_root(
11254 dec: &mut SymbolDecoder,11292 dec: &mut SymbolDecoder,
11255 cdfs: &mut Cdfs,11293 cdfs: &mut Cdfs,
@@ -11264,7 +11302,7 @@ fn read_sb128_root(
11264 sb_c: u32,11302 sb_c: u32,
11265 mi_cols: u32,11303 mi_cols: u32,
11266 mi_rows: u32,11304 mi_rows: u32,
11267-) -> Result<()> {11305+) -> Result<usize> {
11268 let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);11306 let (mi_r128, mi_c128) = ((sb_r & !1) * SB_MI, (sb_c & !1) * SB_MI);
11269 crate::restoration::read_lr(11307 crate::restoration::read_lr(
11270 dec,11308 dec,
@@ -11298,13 +11336,31 @@ fn read_sb128_root(
11298 }11336 }
11299 PARTITION_SPLIT11337 PARTITION_SPLIT
11300 };11338 };
11301- if part128 != PARTITION_SPLIT {11339+ // lane-sb128b r1: `PARTITION_NONE` -- one 128x128 block -- is decoded by
11340+ // the key-frame caller below. The six remaining arms (HORZ/VERT and the
11341+ // four AB shapes) still need the rect/AB machinery at this size.
11342+ if part128 != PARTITION_SPLIT && part128 != PARTITION_NONE {
11302 return Err(unsupported(11343 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)",11344+ "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)",
11304 ));11345 ));
11305 }11346 }
11306- PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1));11347+ if part128 == PARTITION_SPLIT {
11307- Ok(())11348+ PART128_SPLIT_HITS.with(|c| c.set(c.get() + 1));
11349+ } else {
11350+ PART128_NONE_HITS.with(|c| c.set(c.get() + 1));
11351+ // lane-sb128b r1 RESIDUAL: the luma half of a 128x128 `PARTITION_NONE`
11352+ // block is coded below (four TX_64X64 units), but its CHROMA is not:
11353+ // `av1_get_max_uv_txsize` runs `av1_get_adjusted_tx_size` over the
11354+ // 64x64 uv plane block, so the uv transform is TX_32X32 and each
11355+ // plane is FOUR units -- `decode_block` codes exactly one whole-plane
11356+ // chroma unit, which desyncs the tile at the first such block (gate
11357+ // `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact`,
11358+ // 384x384 cq63: decoded, small deltas over 94% of the luma plane).
11359+ return Err(unsupported(
11360+ "a 128x128 PARTITION_NONE block's chroma (its 64x64 uv plane block is four TX_32X32 units, and this decoder codes one whole-plane chroma unit per block)",
11361+ ));
11362+ }
11363+ Ok(part128)
11308 }11364 }
11309 11365
11310 pub(crate) fn decode_key_frame_tile_with_cdfs(11366 pub(crate) fn decode_key_frame_tile_with_cdfs(
@@ -11482,10 +11538,20 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
11482 );11538 );
11483 TILE_HITS.with(|c| c.set(c.get() + 1));11539 TILE_HITS.with(|c| c.set(c.get() + 1));
11484 11540
11541+ // lane-sb128b r1: set when the 128 root resolved to `PARTITION_NONE` --
11542+ // its one block covers all four 64x64 quadrants, so the remaining three
11543+ // visits of this superblock code nothing at all.
11544+ let mut sb128_none = false;
11485 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {11545 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
11486 if row_start {11546 if row_start {
11487 neighbours.start_row();11547 neighbours.start_row();
11488 }11548 }
11549+ if sb_start {
11550+ sb128_none = false;
11551+ }
11552+ if sb128_none {
11553+ continue;
11554+ }
11489 {11555 {
11490 // lane-sb128 r1: the 128 root. Its loop-restoration units are read11556 // lane-sb128 r1: the 128 root. Its loop-restoration units are read
11491 // once for the whole 128x128 (spec 5.11.57 is called with the11557 // once for the whole 128x128 (spec 5.11.57 is called with the
@@ -11493,7 +11559,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
11493 // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT11559 // `BLOCK_128X128` CDF (8 symbols) decides the root -- only SPLIT
11494 // recurses into the four 64x64 quadrants this decoder codes.11560 // recurses into the four 64x64 quadrants this decoder codes.
11495 if sb128 && sb_start {11561 if sb128 && sb_start {
11496- read_sb128_root(11562+ let part128 = read_sb128_root(
11497 &mut dec,11563 &mut dec,
11498 &mut cdfs,11564 &mut cdfs,
11499 &neighbours,11565 &neighbours,
@@ -11505,6 +11571,62 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
11505 mi_cols,11571 mi_cols,
11506 mi_rows,11572 mi_rows,
11507 )?;11573 )?;
11574+ if part128 == PARTITION_NONE {
11575+ // One 128x128 intra block: four TX_64X64 luma units and a
11576+ // single 64x64 chroma unit per plane (`av1_get_max_uv_txsize`
11577+ // of a 128x128 block is TX_64X64 over its 64x64 uv plane
11578+ // block). No CfL, no filter intra, no palette at this size --
11579+ // [`read_intra_mode`]'s own size gates already say so.
11580+ sb128_none = true;
11581+ CDEF_TRANSMITTED.with(|c| c.set(false));
11582+ let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4);
11583+ decode_block(
11584+ &mut dec,
11585+ &mut cdfs,
11586+ &mut neighbours,
11587+ at128,
11588+ SB * 2,
11589+ TxbSet::Luma64,
11590+ TxbSet::Chroma32,
11591+ TX32,
11592+ TX32,
11593+ (&scan32, &scan32),
11594+ false,
11595+ &mut y,
11596+ &mut u,
11597+ &mut v,
11598+ base_q_idx,
11599+ enable_filter_intra,
11600+ allow_screen_content_tools,
11601+ allow_intrabc,
11602+ &scan32,
11603+ &scan16,
11604+ &scan8,
11605+ &scan4,
11606+ tx_select,
11607+ reduced_tx_set,
11608+ )?;
11609+ // libaom writes one `cdef_strength` into the block's own
11610+ // `MB_MODE_INFO`, which every mi cell of the block --
11611+ // hence all four 64x64 CDEF units -- points at; our grid
11612+ // is per-unit, so the read (which only ever lands in the
11613+ // top-left unit, `read_cdef`'s index 0) is copied across.
11614+ let (q_r, q_c) = ((sb_r & !1) as usize, (sb_c & !1) as usize);
11615+ CDEF_IDX_GRID.with(|g| {
11616+ let mut g = g.borrow_mut();
11617+ let cols = CDEF_SB_COLS.with(|c| c.get());
11618+ if cols > 0 && q_r * cols + q_c < g.len() {
11619+ let idx = g[q_r * cols + q_c];
11620+ for (dr, dc) in [(0, 1), (1, 0), (1, 1)] {
11621+ let i = (q_r + dr) * cols + q_c + dc;
11622+ if q_c + dc < cols && i < g.len() {
11623+ g[i] = idx;
11624+ }
11625+ }
11626+ }
11627+ });
11628+ continue;
11629+ }
11508 }11630 }
11509 if !sb128 {11631 if !sb128 {
11510 crate::restoration::read_lr(11632 crate::restoration::read_lr(
@@ -18594,7 +18716,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
18594 }18716 }
18595 {18717 {
18596 if sb128 && sb_start {18718 if sb128 && sb_start {
18597- read_sb128_root(18719+ if read_sb128_root(
18598 &mut dec,18720 &mut dec,
18599 &mut cdfs,18721 &mut cdfs,
18600 &neighbours,18722 &neighbours,
@@ -18605,7 +18727,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
18605 sb_c,18727 sb_c,
18606 mi_cols,18728 mi_cols,
18607 mi_rows,18729 mi_rows,
18608- )?;18730+ )? != PARTITION_SPLIT
18731+ {
18732+ // lane-sb128b r1 decodes a `PARTITION_NONE` 128 root on
18733+ // KEY frames only; an inter 128x128 leaf needs whole-block
18734+ // MC, OBMC and compound at a size this path has never run.
18735+ return Err(unsupported(
18736+ "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)",
18737+ ));
18738+ }
18609 }18739 }
18610 if !sb128 {18740 if !sb128 {
18611 crate::restoration::read_lr(18741 crate::restoration::read_lr(
crates/ec-av1/src/refusal_inventory.rsmodified+3 -1
@@ -43,7 +43,9 @@ const REFUSALS: &[&str] = &[
43 "a tx_type symbol outside its CDF's own set: {t}",43 "a tx_type symbol outside its CDF's own set: {t}",
44 "an INTER 32x32 partition type this decoder does not code (value={part32})",44 "an INTER 32x32 partition type this decoder does not code (value={part32})",
45 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",45 "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4",
46- "a 128x128 superblock partition other than SPLIT (NONE/HORZ/VERT and the four AB arms at the 128 root are not decoded)",46+ "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)",
47+ "a 128x128 superblock PARTITION_NONE root on an inter frame (only the key-frame path codes a whole 128x128 block)",
48+ "a 128x128 PARTITION_NONE block's chroma (its 64x64 uv plane block is four TX_32X32 units, and this decoder codes one whole-plane chroma unit per block)",
47 "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)",49 "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)",
48 "an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 superblock root only)",50 "an inter frame under a 128x128 superblock (this decoder's inter tile path recurses a 64x64 superblock root only)",
49 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",51 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",
crates/ec-av1/src/stream.rsmodified+146 -0
@@ -16168,6 +16168,152 @@ mod tests {
16168 );16168 );
16169 }16169 }
16170 16170
16171+ /// lane-sb128b r1 gate: a real `aomenc --sb-size=128` KEY frame whose 128
16172+ /// roots resolve to `PARTITION_NONE` -- one whole 128x128 intra block,
16173+ /// four TX_64X64 luma transform units and ONE TX_64X64 chroma unit per
16174+ /// plane (`av1_get_max_uv_txsize(BLOCK_128X128)` over its 64x64 uv plane
16175+ /// block), a coefficient set (`TxbSet::Chroma64`) no block at 64 or below
16176+ /// can reach. The r1 gate above pins `--max-partition-size=64`, which
16177+ /// makes every 128 root a forced SPLIT and leaves this arm unexercised.
16178+ /// Smooth gradients at a high `--cq-level` are what make the RD search
16179+ /// keep a whole 128x128 block; `part128_none_hits` HARD-asserts it did.
16180+ #[test]
16181+ #[ignore = "lane-sb128b r1 reproducer: the 128 NONE luma path decodes, its \
16182+ chroma (four TX_32X32 units, not one) is not coded yet, so the \
16183+ product path refuses the arm by name"]
16184+ fn a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact() {
16185+ const NAME: &str =
16186+ "a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact";
16187+ let _gate_lock = lock_gate_counters();
16188+ if !have_ffmpeg() {
16189+ eprintln!("SKIP {NAME}: no ffmpeg");
16190+ return;
16191+ }
16192+ if !have_aomenc() {
16193+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
16194+ return;
16195+ }
16196+ let render = |seed: u32, width: usize, height: usize, ten_bit: bool| -> Vec<u8> {
16197+ let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" };
16198+ let out = Command::new("ffmpeg")
16199+ .args([
16200+ "-v", "error", "-f", "lavfi", "-i",
16201+ &gradients_source(seed, width, height, "duration=0.04:rate=25"),
16202+ "-pix_fmt", pix, "-strict", "-1", "-t", "0.04",
16203+ "-f", "yuv4mpegpipe", "-",
16204+ ])
16205+ .stdin(Stdio::null())
16206+ .stdout(Stdio::piped())
16207+ .stderr(Stdio::piped())
16208+ .output()
16209+ .expect("ffmpeg failed to run");
16210+ assert!(
16211+ out.status.success(),
16212+ "ffmpeg fixture: {}",
16213+ String::from_utf8_lossy(&out.stderr)
16214+ );
16215+ out.stdout
16216+ };
16217+ let mut matched = 0u32;
16218+ let mut named_refusals = 0u32;
16219+ let mut none_arms = 0u32;
16220+ // (seed, cq, width, height, 10-bit). 384x384 is a 3x3 grid of whole
16221+ // 128 superblocks; 256x256 a 2x2.
16222+ let arms: Vec<(u32, &str, usize, usize, bool)> = vec![
16223+ (42, "--cq-level=63", 384, 384, false),
16224+ (43, "--cq-level=55", 384, 384, false),
16225+ (44, "--cq-level=63", 256, 256, false),
16226+ (45, "--cq-level=63", 384, 384, true),
16227+ ];
16228+ for (seed, cq, width, height, ten_bit) in arms {
16229+ let y4m = render(seed, width, height, ten_bit);
16230+ let mut args: Vec<&str> = vec![
16231+ "--codec=av1", "--passes=1", "--end-usage=q", cq,
16232+ "--cpu-used=0", "--threads=1", "--row-mt=0",
16233+ "--sb-size=128",
16234+ "--enable-rect-partitions=0",
16235+ "--enable-ab-partitions=0",
16236+ "--enable-1to4-partitions=0",
16237+ "--min-partition-size=16",
16238+ "--enable-restoration=1",
16239+ "--enable-palette=0",
16240+ "--deltaq-mode=0",
16241+ "--enable-intrabc=0",
16242+ "--enable-tx-size-search=0",
16243+ "--limit=1",
16244+ ];
16245+ if ten_bit {
16246+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
16247+ }
16248+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
16249+ let mut child = Command::new(aomenc_path())
16250+ .args(&args)
16251+ .stdin(Stdio::piped())
16252+ .stdout(Stdio::piped())
16253+ .stderr(Stdio::piped())
16254+ .spawn()
16255+ .expect("aomenc failed to start");
16256+ child
16257+ .stdin
16258+ .take()
16259+ .expect("aomenc stdin")
16260+ .write_all(&y4m)
16261+ .expect("writing y4m to aomenc");
16262+ let out = child.wait_with_output().expect("aomenc failed to run");
16263+ assert!(
16264+ out.status.success(),
16265+ "aomenc refused the fixture: {}",
16266+ String::from_utf8_lossy(&out.stderr)
16267+ );
16268+ let stream = out.stdout;
16269+ let before = crate::decode::part128_none_hits();
16270+ let frames = match decode_stream(&stream) {
16271+ Err(e) => {
16272+ let msg = e.to_string();
16273+ assert!(
16274+ msg.contains("unsupported"),
16275+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
16276+ );
16277+ named_refusals += 1;
16278+ eprintln!("seed {seed} refusal: {msg}");
16279+ continue;
16280+ }
16281+ Ok(frames) => frames,
16282+ };
16283+ let want = if ten_bit {
16284+ ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
16285+ } else {
16286+ ffmpeg_decode_sequence(&stream, width, height, 1)
16287+ };
16288+ assert_eq!(frames.len(), 1);
16289+ for (i, (got, want)) in frames.iter().zip(&want).enumerate() {
16290+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
16291+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
16292+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
16293+ }
16294+ let hits = crate::decode::part128_none_hits() - before;
16295+ eprintln!("seed {seed} cq {cq} {width}x{height}: part128_none_hits +{hits}");
16296+ if hits > 0 {
16297+ none_arms += 1;
16298+ }
16299+ matched += 1;
16300+ }
16301+ assert!(
16302+ matched > 0,
16303+ "{NAME}: every attempt refused; the gate never decoded a stream"
16304+ );
16305+ assert!(
16306+ none_arms > 0,
16307+ "{NAME}: {matched} stream(s) decoded pixel-exact but NOT ONE 128 root was \
16308+ PARTITION_NONE -- the arm this gate exists for never fired"
16309+ );
16310+ eprintln!(
16311+ "{NAME}: {matched} pixel-exact ({none_arms} with a 128 NONE root), \
16312+ {named_refusals} named refusals, part128_none_hits={}",
16313+ crate::decode::part128_none_hits()
16314+ );
16315+ }
16316+
16171 #[test]16317 #[test]
16172 #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"]16318 #[ignore = "lane-sb128 r2 diagnostic: is the frame-6 mismatch sb128-specific?"]
16173 fn sb128_r2_control_sb64() {16319 fn sb128_r2_control_sb64() {