From ff81ea85bf5fcf3f12e739aeb57af22f7c7bcbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 14:26:09 +0300 Subject: [PATCH] test(av1): enumerate the motion_mode CDF row map over every shape that reads one `is_motion_variation_allowed_bsize` (libaom blockd.h:1455, mirrored by `motion_mode_eligible`'s `min(write_w, write_h) >= 8` clause) is the only gate in front of the motion_mode/obmc row lookup, so the reachable domain of that lookup is exactly the 17 `BLOCK_SIZES_ALL` footprints with a min side of 8 or more. Each maps to a distinct row of the 17-row table, so the refusal "a motion_mode symbol for a block shape with no CDF row here" names a shape no conformant block can present -- no gap, nothing to witness. The inline `match` is now `motion_mode_cdf_row`, which is what the enumeration can call; the refusal stays at its own site. --- crates/ec-av1/src/decode.rs | 131 ++++++++++++++++++++----- crates/ec-av1/src/refusal_inventory.rs | 8 ++ 2 files changed, 115 insertions(+), 24 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 471d4fb8..1e132312 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -7734,6 +7734,110 @@ fn every_intra_in_inter_shape_the_census_lists_has_a_size_group_row() { ); } +/// The `motion_mode` / `obmc` CDF row for a block footprint: libaom's +/// `motion_mode_cdf[mbmi->bsize]`, in this crate's packed row order (which +/// `cdf::MOTION_MODE` documents -- the 128-px rows come last, so they are +/// matched before the square arm's `log2` shortcut). +/// +/// `None` is the refusal "a motion_mode symbol for a block shape with no CDF +/// row here"; the enumeration below is what proves no conformant block can +/// reach it. +pub(crate) fn motion_mode_cdf_row(write_w: usize, write_h: usize) -> Option { + Some(match (write_w, write_h) { + // lane-sb128c r5: the 128 root's own rows come FIRST -- the square arm + // below maps 128 to row 4 (BLOCK_16X32). + (64, 128) => 14, + (128, 64) => 15, + (128, 128) => 16, + (w, h) if w == h => (w.trailing_zeros() - 3) as usize, + (16, 32) => 4, + (32, 16) => 5, + (32, 64) => 6, + (64, 32) => 7, + (8, 32) => 8, + (32, 8) => 9, + (16, 64) => 10, + (64, 16) => 11, + // lane-inter4 r3: the 16x16-level rect inter leaves. + (8, 16) => 12, + (16, 8) => 13, + _ => return None, + }) +} + +/// Every `BLOCK_SIZES_ALL` footprint, as `(width, height)` in pixels: the six +/// squares, the ten 2:1 shapes and the six 1:4 ones (libaom `common_data.h`, +/// `block_size_wide`/`block_size_high`). +#[cfg(test)] +const BLOCK_SIZES_ALL_WH: [(usize, usize); 22] = [ + (4, 4), + (4, 8), + (8, 4), + (8, 8), + (8, 16), + (16, 8), + (16, 16), + (16, 32), + (32, 16), + (32, 32), + (32, 64), + (64, 32), + (64, 64), + (64, 128), + (128, 64), + (128, 128), + (4, 16), + (16, 4), + (8, 32), + (32, 8), + (16, 64), + (64, 16), +]; + +/// lane-t900 r25, enumeration: the refusal "a motion_mode symbol for a block +/// shape with no CDF row here" names a shape no conformant stream can present. +/// +/// A `motion_mode`/`obmc` symbol is read only under `motion_mode_eligible`, +/// whose `write_w.min(write_h) >= 8` clause is libaom's +/// `is_motion_variation_allowed_bsize` (`blockd.h:1455`). So the reachable +/// domain of [`motion_mode_cdf_row`] is exactly the `BLOCK_SIZES_ALL` +/// footprints with `min(bw, bh) >= 8` -- 17 of the 22 -- and each of those +/// must map to a distinct row of the 17-row `Cdfs::motion_mode` table. The +/// five it excludes (4x4, 4x8, 8x4, 4x16, 16x4) are the ones the eligibility +/// clause rejects before the lookup. +#[test] +fn every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row() { + let mut rows = std::collections::BTreeSet::new(); + let mut excluded = 0; + for (w, h) in BLOCK_SIZES_ALL_WH { + if w.min(h) < 8 { + excluded += 1; + assert!( + w == 4 || h == 4, + "{w}x{h} is not one of the sub-8 shapes is_motion_variation_allowed_bsize rejects" + ); + continue; + } + let row = motion_mode_cdf_row(w, h).unwrap_or_else(|| { + panic!( + "a {w}x{h} block passes is_motion_variation_allowed_bsize and reads a motion_mode \ + symbol, but has no CDF row -- the refusal is a real gap, not a dead arm" + ) + }); + assert!( + row < 17, + "{w}x{h} maps to motion_mode row {row}, outside the 17-row table" + ); + assert!(rows.insert(row), "{w}x{h} shares motion_mode row {row}"); + } + assert_eq!(excluded, 5, "the sub-8 footprint set changed"); + assert_eq!( + rows.len(), + 17, + "17 eligible footprints must fill all 17 rows of the motion_mode table" + ); +} + fn decode_intra_rect_in_inter( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -22342,30 +22446,9 @@ fn decode_inter_block( // documented on `cdf::MOTION_MODE`); a wrong row is a wrong // interval narrowing, not a wrong value (class // wrong-alphabet-same-value). - let bsize_idx = match (write_w, write_h) { - // lane-sb128c r5: the 128 root's own rows come FIRST -- - // the square arm below maps 128 to row 4 (BLOCK_16X32). - (64, 128) => 14, - (128, 64) => 15, - (128, 128) => 16, - (w, h) if w == h => (w.trailing_zeros() - 3) as usize, - (16, 32) => 4, - (32, 16) => 5, - (32, 64) => 6, - (64, 32) => 7, - (8, 32) => 8, - (32, 8) => 9, - (16, 64) => 10, - (64, 16) => 11, - // lane-inter4 r3: the 16x16-level rect inter leaves. - (8, 16) => 12, - (16, 8) => 13, - _ => { - return Err(unsupported( - "a motion_mode symbol for a block shape with no CDF row here", - )); - } - }; + let bsize_idx = motion_mode_cdf_row(write_w, write_h).ok_or_else(|| { + unsupported("a motion_mode symbol for a block shape with no CDF row here") + })?; // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` // instead of the 2-symbol `obmc_cdf` exactly when // `num_proj_ref >= 1` under `allow_warped_motion`. diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 4811fad3..32b7802f 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -262,6 +262,14 @@ const PROVEN: &[(&str, &str)] = &[ "a Golomb tail longer than this decoder reads", "read_golomb_reads_every_value_a_conformant_stream_can_carry", ), + // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under + // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17 + // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of + // the 17-row table. + ( + "a motion_mode symbol for a block shape with no CDF row here", + "every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row", + ), ( "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)", "a_twelve_bit_sequence_header_is_refused_by_name",