Enumerate the motion_mode CDF row map over every shape that reads one
Browse files at this commitff81ea85bf5fcf3f12e739aeb57af22f7c7bcbd6Parent: 3f6ede5- test
- enumerate the motion_mode CDF row map over every shape that reads one
2 changed files +115 -24
crates/ec-av1/src/decode.rsmodified+107 -24
| @@ -7734,6 +7734,110 @@ fn every_intra_in_inter_shape_the_census_lists_has_a_size_group_row() { | |||
| 7734 | ); | 7734 | ); |
| 7735 | } | 7735 | } |
| 7736 | 7736 | ||
| 7737 | +/// The `motion_mode` / `obmc` CDF row for a block footprint: libaom's | ||
| 7738 | +/// `motion_mode_cdf[mbmi->bsize]`, in this crate's packed row order (which | ||
| 7739 | +/// `cdf::MOTION_MODE` documents -- the 128-px rows come last, so they are | ||
| 7740 | +/// matched before the square arm's `log2` shortcut). | ||
| 7741 | +/// | ||
| 7742 | +/// `None` is the refusal "a motion_mode symbol for a block shape with no CDF | ||
| 7743 | +/// row here"; the enumeration below is what proves no conformant block can | ||
| 7744 | +/// reach it. | ||
| 7745 | +pub(crate) fn motion_mode_cdf_row(write_w: usize, write_h: usize) -> Option<usize> { | ||
| 7746 | + Some(match (write_w, write_h) { | ||
| 7747 | + // lane-sb128c r5: the 128 root's own rows come FIRST -- the square arm | ||
| 7748 | + // below maps 128 to row 4 (BLOCK_16X32). | ||
| 7749 | + (64, 128) => 14, | ||
| 7750 | + (128, 64) => 15, | ||
| 7751 | + (128, 128) => 16, | ||
| 7752 | + (w, h) if w == h => (w.trailing_zeros() - 3) as usize, | ||
| 7753 | + (16, 32) => 4, | ||
| 7754 | + (32, 16) => 5, | ||
| 7755 | + (32, 64) => 6, | ||
| 7756 | + (64, 32) => 7, | ||
| 7757 | + (8, 32) => 8, | ||
| 7758 | + (32, 8) => 9, | ||
| 7759 | + (16, 64) => 10, | ||
| 7760 | + (64, 16) => 11, | ||
| 7761 | + // lane-inter4 r3: the 16x16-level rect inter leaves. | ||
| 7762 | + (8, 16) => 12, | ||
| 7763 | + (16, 8) => 13, | ||
| 7764 | + _ => return None, | ||
| 7765 | + }) | ||
| 7766 | +} | ||
| 7767 | + | ||
| 7768 | +/// Every `BLOCK_SIZES_ALL` footprint, as `(width, height)` in pixels: the six | ||
| 7769 | +/// squares, the ten 2:1 shapes and the six 1:4 ones (libaom `common_data.h`, | ||
| 7770 | +/// `block_size_wide`/`block_size_high`). | ||
| 7771 | +#[cfg(test)] | ||
| 7772 | +const BLOCK_SIZES_ALL_WH: [(usize, usize); 22] = [ | ||
| 7773 | + (4, 4), | ||
| 7774 | + (4, 8), | ||
| 7775 | + (8, 4), | ||
| 7776 | + (8, 8), | ||
| 7777 | + (8, 16), | ||
| 7778 | + (16, 8), | ||
| 7779 | + (16, 16), | ||
| 7780 | + (16, 32), | ||
| 7781 | + (32, 16), | ||
| 7782 | + (32, 32), | ||
| 7783 | + (32, 64), | ||
| 7784 | + (64, 32), | ||
| 7785 | + (64, 64), | ||
| 7786 | + (64, 128), | ||
| 7787 | + (128, 64), | ||
| 7788 | + (128, 128), | ||
| 7789 | + (4, 16), | ||
| 7790 | + (16, 4), | ||
| 7791 | + (8, 32), | ||
| 7792 | + (32, 8), | ||
| 7793 | + (16, 64), | ||
| 7794 | + (64, 16), | ||
| 7795 | +]; | ||
| 7796 | + | ||
| 7797 | +/// lane-t900 r25, enumeration: the refusal "a motion_mode symbol for a block | ||
| 7798 | +/// shape with no CDF row here" names a shape no conformant stream can present. | ||
| 7799 | +/// | ||
| 7800 | +/// A `motion_mode`/`obmc` symbol is read only under `motion_mode_eligible`, | ||
| 7801 | +/// whose `write_w.min(write_h) >= 8` clause is libaom's | ||
| 7802 | +/// `is_motion_variation_allowed_bsize` (`blockd.h:1455`). So the reachable | ||
| 7803 | +/// domain of [`motion_mode_cdf_row`] is exactly the `BLOCK_SIZES_ALL` | ||
| 7804 | +/// footprints with `min(bw, bh) >= 8` -- 17 of the 22 -- and each of those | ||
| 7805 | +/// must map to a distinct row of the 17-row `Cdfs::motion_mode` table. The | ||
| 7806 | +/// five it excludes (4x4, 4x8, 8x4, 4x16, 16x4) are the ones the eligibility | ||
| 7807 | +/// clause rejects before the lookup. | ||
| 7808 | +#[test] | ||
| 7809 | +fn every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row() { | ||
| 7810 | + let mut rows = std::collections::BTreeSet::new(); | ||
| 7811 | + let mut excluded = 0; | ||
| 7812 | + for (w, h) in BLOCK_SIZES_ALL_WH { | ||
| 7813 | + if w.min(h) < 8 { | ||
| 7814 | + excluded += 1; | ||
| 7815 | + assert!( | ||
| 7816 | + w == 4 || h == 4, | ||
| 7817 | + "{w}x{h} is not one of the sub-8 shapes is_motion_variation_allowed_bsize rejects" | ||
| 7818 | + ); | ||
| 7819 | + continue; | ||
| 7820 | + } | ||
| 7821 | + let row = motion_mode_cdf_row(w, h).unwrap_or_else(|| { | ||
| 7822 | + panic!( | ||
| 7823 | + "a {w}x{h} block passes is_motion_variation_allowed_bsize and reads a motion_mode \ | ||
| 7824 | + symbol, but has no CDF row -- the refusal is a real gap, not a dead arm" | ||
| 7825 | + ) | ||
| 7826 | + }); | ||
| 7827 | + assert!( | ||
| 7828 | + row < 17, | ||
| 7829 | + "{w}x{h} maps to motion_mode row {row}, outside the 17-row table" | ||
| 7830 | + ); | ||
| 7831 | + assert!(rows.insert(row), "{w}x{h} shares motion_mode row {row}"); | ||
| 7832 | + } | ||
| 7833 | + assert_eq!(excluded, 5, "the sub-8 footprint set changed"); | ||
| 7834 | + assert_eq!( | ||
| 7835 | + rows.len(), | ||
| 7836 | + 17, | ||
| 7837 | + "17 eligible footprints must fill all 17 rows of the motion_mode table" | ||
| 7838 | + ); | ||
| 7839 | +} | ||
| 7840 | + | ||
| 7737 | fn decode_intra_rect_in_inter( | 7841 | fn decode_intra_rect_in_inter( |
| 7738 | dec: &mut SymbolDecoder, | 7842 | dec: &mut SymbolDecoder, |
| 7739 | cdfs: &mut Cdfs, | 7843 | cdfs: &mut Cdfs, |
| @@ -22342,30 +22446,9 @@ fn decode_inter_block( | |||
| 22342 | // documented on `cdf::MOTION_MODE`); a wrong row is a wrong | 22446 | // documented on `cdf::MOTION_MODE`); a wrong row is a wrong |
| 22343 | // interval narrowing, not a wrong value (class | 22447 | // interval narrowing, not a wrong value (class |
| 22344 | // wrong-alphabet-same-value). | 22448 | // wrong-alphabet-same-value). |
| 22345 | - let bsize_idx = match (write_w, write_h) { | 22449 | + let bsize_idx = motion_mode_cdf_row(write_w, write_h).ok_or_else(|| { |
| 22346 | - // lane-sb128c r5: the 128 root's own rows come FIRST -- | 22450 | + unsupported("a motion_mode symbol for a block shape with no CDF row here") |
| 22347 | - // the square arm below maps 128 to row 4 (BLOCK_16X32). | 22451 | + })?; |
| 22348 | - (64, 128) => 14, | ||
| 22349 | - (128, 64) => 15, | ||
| 22350 | - (128, 128) => 16, | ||
| 22351 | - (w, h) if w == h => (w.trailing_zeros() - 3) as usize, | ||
| 22352 | - (16, 32) => 4, | ||
| 22353 | - (32, 16) => 5, | ||
| 22354 | - (32, 64) => 6, | ||
| 22355 | - (64, 32) => 7, | ||
| 22356 | - (8, 32) => 8, | ||
| 22357 | - (32, 8) => 9, | ||
| 22358 | - (16, 64) => 10, | ||
| 22359 | - (64, 16) => 11, | ||
| 22360 | - // lane-inter4 r3: the 16x16-level rect inter leaves. | ||
| 22361 | - (8, 16) => 12, | ||
| 22362 | - (16, 8) => 13, | ||
| 22363 | - _ => { | ||
| 22364 | - return Err(unsupported( | ||
| 22365 | - "a motion_mode symbol for a block shape with no CDF row here", | ||
| 22366 | - )); | ||
| 22367 | - } | ||
| 22368 | - }; | ||
| 22369 | // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` | 22452 | // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` |
| 22370 | // instead of the 2-symbol `obmc_cdf` exactly when | 22453 | // instead of the 2-symbol `obmc_cdf` exactly when |
| 22371 | // `num_proj_ref >= 1` under `allow_warped_motion`. | 22454 | // `num_proj_ref >= 1` under `allow_warped_motion`. |
crates/ec-av1/src/refusal_inventory.rsmodified+8 -0
| @@ -262,6 +262,14 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 262 | "a Golomb tail longer than this decoder reads", | 262 | "a Golomb tail longer than this decoder reads", |
| 263 | "read_golomb_reads_every_value_a_conformant_stream_can_carry", | 263 | "read_golomb_reads_every_value_a_conformant_stream_can_carry", |
| 264 | ), | 264 | ), |
| 265 | + // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under | ||
| 266 | + // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17 | ||
| 267 | + // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of | ||
| 268 | + // the 17-row table. | ||
| 269 | + ( | ||
| 270 | + "a motion_mode symbol for a block shape with no CDF row here", | ||
| 271 | + "every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row", | ||
| 272 | + ), | ||
| 265 | ( | 273 | ( |
| 266 | "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)", | 274 | "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)", |
| 267 | "a_twelve_bit_sequence_header_is_refused_by_name", | 275 | "a_twelve_bit_sequence_header_is_refused_by_name", |