Merge branch 'lane-t900' (b80c4577): four shape-keyed refusals proven by block-shape census + table enumeration; refusal inventory gains PROVEN registry
Browse files at this commit3 changed files +450 -30
- crates/ec-av1/src/decode.rs +204 -29
- crates/ec-av1/src/refusal_inventory.rs +83 -1
- crates/ec-av1/src/stream.rs +163 -0
crates/ec-av1/src/decode.rsmodified+204 -29
| @@ -7601,6 +7601,62 @@ fn decode_rect_split( | |||
| 7601 | /// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the | 7601 | /// grid, deblock grid) are [`decode_rect_split`]'s; the caller adds the |
| 7602 | /// inter-side bands and the mi map. | 7602 | /// inter-side bands and the mi map. |
| 7603 | #[allow(clippy::too_many_arguments)] | 7603 | #[allow(clippy::too_many_arguments)] |
| 7604 | +/// The `(size_group_lookup, bsize_to_tx_size_cat)` row an INTRA block coded | ||
| 7605 | +/// inside an inter frame reads its `y_mode` and `tx_depth` symbols from, for | ||
| 7606 | +/// the rect footprints [`decode_intra_rect_in_inter`] resolves itself (the | ||
| 7607 | +/// 128-root halves and the 16x4/4x16 strips of a 1:4 partition take their own | ||
| 7608 | +/// branches before this). libaom `common_data.h:61` / `blockd.h:1347`: the 2:1 | ||
| 7609 | +/// strips keep the group/category diagonal (BLOCK_16X8 -> 1/1, BLOCK_32X16 -> | ||
| 7610 | +/// 2/2, BLOCK_64X32 -> 3/3), the 1:4 ones break it (BLOCK_32X8 is group 1 but | ||
| 7611 | +/// category 2, BLOCK_64X16 group 2 and category 3), which is why the row is a | ||
| 7612 | +/// table here rather than a shift of `bw.min(bh)`. | ||
| 7613 | +fn intra_in_inter_size_row(bw: usize, bh: usize) -> Option<(usize, usize)> { | ||
| 7614 | + Some(match (bw.min(bh), bw.max(bh)) { | ||
| 7615 | + (8, 16) => (1usize, 1usize), | ||
| 7616 | + (16, 32) => (2, 2), | ||
| 7617 | + (32, 64) => (3, 3), | ||
| 7618 | + (8, 32) => (1, 2), | ||
| 7619 | + (16, 64) => (2, 3), | ||
| 7620 | + _ => return None, | ||
| 7621 | + }) | ||
| 7622 | +} | ||
| 7623 | + | ||
| 7624 | +/// lane-t900 r20, refusal B ("an intra-coded {bw}x{bh} block on the inter | ||
| 7625 | +/// block path"): the shapes that can reach that arm, enumerated against the | ||
| 7626 | +/// MEASURED domain of the inter block path | ||
| 7627 | +/// ([`INTER_BLOCK_SHAPES`], the census the gate | ||
| 7628 | +/// `a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable` | ||
| 7629 | +/// fills from three real streams). | ||
| 7630 | +/// | ||
| 7631 | +/// [`decode_intra_rect_in_inter`] is called from one site, under | ||
| 7632 | +/// `write_w != side || write_h != side`, and only after two earlier arms have | ||
| 7633 | +/// taken their shapes: a footprint with a side below 8 is either a 16x4/4x16 | ||
| 7634 | +/// strip WITH a chroma-pair record (the `strip16` branch) or refused by name, | ||
| 7635 | +/// and a 128-px footprint returns from the `bw.max(bh) == 128` branch. What is | ||
| 7636 | +/// left is every rectangular census shape with `8 <= min` and `max <= 64` -- | ||
| 7637 | +/// and each of those has a row, so the refusal names a shape no measured | ||
| 7638 | +/// stream can present. | ||
| 7639 | +#[test] | ||
| 7640 | +fn every_intra_in_inter_shape_the_census_lists_has_a_size_group_row() { | ||
| 7641 | + let mut checked = 0; | ||
| 7642 | + for &(side, w, h) in &INTER_BLOCK_SHAPES { | ||
| 7643 | + if (w, h) == (side, side) || w.min(h) < 8 || w.max(h) > 64 { | ||
| 7644 | + continue; | ||
| 7645 | + } | ||
| 7646 | + assert!( | ||
| 7647 | + intra_in_inter_size_row(w, h).is_some(), | ||
| 7648 | + "the inter path decodes {w}x{h} blocks, and an INTRA one of that shape would hit \ | ||
| 7649 | + the \"no size-group/tx-category row\" refusal" | ||
| 7650 | + ); | ||
| 7651 | + checked += 1; | ||
| 7652 | + } | ||
| 7653 | + assert_eq!( | ||
| 7654 | + checked, 10, | ||
| 7655 | + "the block-shape census changed: {checked} rect shapes reach the intra-in-inter row \ | ||
| 7656 | + lookup, not the 10 this claim was measured over" | ||
| 7657 | + ); | ||
| 7658 | +} | ||
| 7659 | + | ||
| 7604 | fn decode_intra_rect_in_inter( | 7660 | fn decode_intra_rect_in_inter( |
| 7605 | dec: &mut SymbolDecoder, | 7661 | dec: &mut SymbolDecoder, |
| 7606 | cdfs: &mut Cdfs, | 7662 | cdfs: &mut Cdfs, |
| @@ -7779,35 +7835,22 @@ fn decode_intra_rect_in_inter( | |||
| 7779 | INTRA_IN_INTER_MODE.with(|c| c.set(None)); | 7835 | INTRA_IN_INTER_MODE.with(|c| c.set(None)); |
| 7780 | return res; | 7836 | return res; |
| 7781 | } | 7837 | } |
| 7782 | - let (size_group, tx_cat) = match (bw.min(bh), bw.max(bh)) { | 7838 | + let Some((size_group, tx_cat)) = intra_in_inter_size_row(bw, bh) else { |
| 7783 | - (8, 16) => (1usize, 1usize), | 7839 | + if crate::envflags::env_flag!("EC_OBMCREC") { |
| 7784 | - (16, 32) => (2, 2), | 7840 | + eprintln!( |
| 7785 | - (32, 64) => (3, 3), | 7841 | + "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}" |
| 7786 | - // lane-intra14 r1: the 1:4 strips, read off libaom's own tables -- | 7842 | + ); |
| 7787 | - // `size_group_lookup` (common_data.h:61) gives BLOCK_8X32/32X8 group | ||
| 7788 | - // 1 and BLOCK_16X64/64X16 group 2, while | ||
| 7789 | - // `bsize_to_tx_size_depth_table` (blockd.h:1347) gives them depth | ||
| 7790 | - // 3 and 4, i.e. tx categories 2 and 3 -- the diagonal a 2:1 strip | ||
| 7791 | - // keeps is genuinely broken here, which is why the shape was refused | ||
| 7792 | - // rather than read from the 2:1 row. | ||
| 7793 | - (8, 32) => (1, 2), | ||
| 7794 | - (16, 64) => (2, 3), | ||
| 7795 | - _ => { | ||
| 7796 | - if crate::envflags::env_flag!("EC_OBMCREC") { | ||
| 7797 | - eprintln!( | ||
| 7798 | - "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}" | ||
| 7799 | - ); | ||
| 7800 | - } | ||
| 7801 | - // lane-obmcrec r1: the message used to name a 16x4/4x16 strip | ||
| 7802 | - // (class refusal-names-a-correlate). Measured with `EC_OBMCREC=1` | ||
| 7803 | - // on three 2 s cuts of the 10-bit 1920x792 128-superblock stream: | ||
| 7804 | - // every arrival here is a 128x64 block -- a PARTITION_HORZ half of | ||
| 7805 | - // a 128 superblock coded INTRA inside an inter frame, at mi | ||
| 7806 | - // (128,416) / (192,0) / (192,0) -- not a strip at all. | ||
| 7807 | - return Err(unsupported(format!( | ||
| 7808 | - "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)" | ||
| 7809 | - ))); | ||
| 7810 | } | 7843 | } |
| 7844 | + // lane-obmcrec r1: the message used to name a 16x4/4x16 strip | ||
| 7845 | + // (class refusal-names-a-correlate). lane-t900 r20: the shapes that | ||
| 7846 | + // can arrive here are enumerated against the measured block-shape | ||
| 7847 | + // census ([`INTER_BLOCK_SHAPES`]) by | ||
| 7848 | + // [`every_intra_in_inter_shape_the_census_lists_has_a_size_group_row`] | ||
| 7849 | + // -- every one of them has a row, so this arm names a shape no stream | ||
| 7850 | + // has been able to present. | ||
| 7851 | + return Err(unsupported(format!( | ||
| 7852 | + "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)" | ||
| 7853 | + ))); | ||
| 7811 | }; | 7854 | }; |
| 7812 | // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is | 7855 | // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is |
| 7813 | // consumed for square blocks only, so a strip in a screen-content frame | 7856 | // consumed for square blocks only, so a strip in a screen-content frame |
| @@ -14526,7 +14569,7 @@ fn read_block_tx_size( | |||
| 14526 | /// `default_inter_ext_tx_cdf[2][TX_8X8]` (the 12-symbol | 14569 | /// `default_inter_ext_tx_cdf[2][TX_8X8]` (the 12-symbol |
| 14527 | /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a | 14570 | /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a |
| 14528 | /// rect transform), neither of which exists yet -- both stay refused by name. | 14571 | /// rect transform), neither of which exists yet -- both stay refused by name. |
| 14529 | -fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | 14572 | +pub(crate) fn rect_inter_residual_supported(w: usize, h: usize) -> bool { |
| 14530 | matches!( | 14573 | matches!( |
| 14531 | (w, h), | 14574 | (w, h), |
| 14532 | // 2:1 strips whose transform is coded in full (lane-inter4). | 14575 | // 2:1 strips whose transform is coded in full (lane-inter4). |
| @@ -14564,6 +14607,63 @@ fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | |||
| 14564 | ) | 14607 | ) |
| 14565 | } | 14608 | } |
| 14566 | 14609 | ||
| 14610 | +// lane-t900 r20: the `(side, write_w, write_h)` triples the inter block path | ||
| 14611 | +// actually PRESENTS, as a thread-local bitmask -- the measured domain behind | ||
| 14612 | +// the "rectangular ... has no ... here" refusals. `side` is the square context | ||
| 14613 | +// a block reads its CDFs at and `write_w`/`write_h` its true footprint; | ||
| 14614 | +// `inter_piece!` derives `reject_residual` from exactly that inequality, so | ||
| 14615 | +// these triples are what decides whether those refusals can fire at all. Bit | ||
| 14616 | +// 31 is "a triple this table does not list", which is what makes the gate a | ||
| 14617 | +// census rather than a restatement of its own table. | ||
| 14618 | +pub(crate) const INTER_BLOCK_SHAPES: [(usize, usize, usize); 18] = [ | ||
| 14619 | + (16, 16, 16), | ||
| 14620 | + (32, 32, 32), | ||
| 14621 | + (32, 16, 32), | ||
| 14622 | + (32, 32, 16), | ||
| 14623 | + (16, 8, 16), | ||
| 14624 | + (16, 16, 8), | ||
| 14625 | + (32, 8, 32), | ||
| 14626 | + (64, 64, 64), | ||
| 14627 | + (32, 32, 8), | ||
| 14628 | + (64, 16, 64), | ||
| 14629 | + (128, 128, 128), | ||
| 14630 | + (64, 32, 64), | ||
| 14631 | + (64, 64, 32), | ||
| 14632 | + (16, 4, 16), | ||
| 14633 | + (64, 64, 16), | ||
| 14634 | + (16, 16, 4), | ||
| 14635 | + (128, 128, 64), | ||
| 14636 | + (128, 64, 128), | ||
| 14637 | +]; | ||
| 14638 | + | ||
| 14639 | +/// Bit 31 of [`inter_block_shape_mask`]: a `(side, write_w, write_h)` triple | ||
| 14640 | +/// outside [`INTER_BLOCK_SHAPES`]. | ||
| 14641 | +pub const INTER_BLOCK_SHAPE_UNLISTED: u32 = 1 << 31; | ||
| 14642 | + | ||
| 14643 | +thread_local! { | ||
| 14644 | + static INTER_BLOCK_SHAPE_MASK: std::cell::Cell<u32> = const { std::cell::Cell::new(0) }; | ||
| 14645 | +} | ||
| 14646 | + | ||
| 14647 | +/// Which of [`INTER_BLOCK_SHAPES`] this THREAD has decoded (thread-local, so a | ||
| 14648 | +/// gate reading it sees only the streams it decoded itself). | ||
| 14649 | +pub fn inter_block_shape_mask() -> u32 { | ||
| 14650 | + INTER_BLOCK_SHAPE_MASK.with(std::cell::Cell::get) | ||
| 14651 | +} | ||
| 14652 | + | ||
| 14653 | +/// Records one block's shape. The table is ordered by measured frequency over | ||
| 14654 | +/// the three witnesses the census gate decodes, so the common square shapes | ||
| 14655 | +/// leave the scan on their first comparison. | ||
| 14656 | +fn census_inter_block_shape(side: usize, w: usize, h: usize) { | ||
| 14657 | + let bit = match INTER_BLOCK_SHAPES.iter().position(|&s| s == (side, w, h)) { | ||
| 14658 | + Some(i) => 1u32 << i, | ||
| 14659 | + None => INTER_BLOCK_SHAPE_UNLISTED, | ||
| 14660 | + }; | ||
| 14661 | + let seen = inter_block_shape_mask(); | ||
| 14662 | + if seen & bit == 0 { | ||
| 14663 | + INTER_BLOCK_SHAPE_MASK.with(|c| c.set(seen | bit)); | ||
| 14664 | + } | ||
| 14665 | +} | ||
| 14666 | + | ||
| 14567 | /// The luma coefficient/`tx_type` table set of a whole-block rectangular | 14667 | /// The luma coefficient/`tx_type` table set of a whole-block rectangular |
| 14568 | /// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits | 14668 | /// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits |
| 14569 | /// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so | 14669 | /// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so |
| @@ -14700,6 +14800,80 @@ fn rect_scan(w: usize, h: usize) -> Result<&'static [u16]> { | |||
| 14700 | }) | 14800 | }) |
| 14701 | } | 14801 | } |
| 14702 | 14802 | ||
| 14803 | +/// lane-t900 r20, refusal D -- the three "a rectangular inter luma/chroma | ||
| 14804 | +/// transform unit whose shape has no coefficient table set here" / "a | ||
| 14805 | +/// rectangular transform unit whose shape has no coefficient scan table here" | ||
| 14806 | +/// arms, enumerated against the MEASURED domain of the inter block path | ||
| 14807 | +/// ([`INTER_BLOCK_SHAPES`], filled from three real streams by the gate | ||
| 14808 | +/// `a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable`). | ||
| 14809 | +/// | ||
| 14810 | +/// What each helper is actually handed: | ||
| 14811 | +/// | ||
| 14812 | +/// * [`rect_inter_luma_set`] -- the block's own footprint (call sites at the | ||
| 14813 | +/// whole-block residual), and a var-tx LEAF shape. `sub_tx_size_map` is | ||
| 14814 | +/// square for every rect transform except TX_16X4/TX_4X16, whose leaves are | ||
| 14815 | +/// TX_8X4/TX_4X8, so the leaf domain adds exactly 8x4 and 4x8. | ||
| 14816 | +/// * [`rect_inter_chroma_set`] -- `(write_w / 2, write_h / 2)` for a 4:2:0 | ||
| 14817 | +/// block, except a 16x4/4x16 strip, whose chroma is the PAIR's 8x4 / 4x8. | ||
| 14818 | +/// * [`rect_scan`] -- the `min(w, 32) x min(h, 32)` coded corner of a rect | ||
| 14819 | +/// unit, and only when that corner is not 32x32 (a square corner goes | ||
| 14820 | +/// through the square reader with `rect_shape = Some((w, h))`). | ||
| 14821 | +/// | ||
| 14822 | +/// The 128-px halves take neither: `max_txsize_rect_lookup[BLOCK_128X64]` is | ||
| 14823 | +/// TX_64X64, so they tile into SQUARE 64x64 luma units through the mu-chunk | ||
| 14824 | +/// loop, which is why they are skipped below. | ||
| 14825 | +#[test] | ||
| 14826 | +fn every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan() { | ||
| 14827 | + let corner_scan = |w: usize, h: usize| { | ||
| 14828 | + let (cw, ch) = (w.min(32), h.min(32)); | ||
| 14829 | + if (cw, ch) == (32, 32) { | ||
| 14830 | + return; // the square coefficient reader, not `rect_scan` | ||
| 14831 | + } | ||
| 14832 | + assert!( | ||
| 14833 | + rect_scan(cw, ch).is_ok(), | ||
| 14834 | + "a {w}x{h} rect transform codes its {cw}x{ch} corner, which has no scan table" | ||
| 14835 | + ); | ||
| 14836 | + }; | ||
| 14837 | + let mut checked = 0; | ||
| 14838 | + for &(side, w, h) in &INTER_BLOCK_SHAPES { | ||
| 14839 | + if (w, h) == (side, side) || w.max(h) > 64 { | ||
| 14840 | + continue; | ||
| 14841 | + } | ||
| 14842 | + assert!( | ||
| 14843 | + rect_inter_luma_set(w, h).is_ok(), | ||
| 14844 | + "the inter path decodes {w}x{h} blocks but has no luma coefficient table set for one" | ||
| 14845 | + ); | ||
| 14846 | + corner_scan(w, h); | ||
| 14847 | + // 4:2:0 chroma: the pair's 8x4 / 4x8 for a 1:4 strip, the halved | ||
| 14848 | + // footprint for every other shape. | ||
| 14849 | + let (cw, ch) = match (w, h) { | ||
| 14850 | + (16, 4) => (8, 4), | ||
| 14851 | + (4, 16) => (4, 8), | ||
| 14852 | + _ => (w / 2, h / 2), | ||
| 14853 | + }; | ||
| 14854 | + assert!( | ||
| 14855 | + rect_inter_chroma_set(cw, ch).is_ok(), | ||
| 14856 | + "a {w}x{h} block's {cw}x{ch} chroma unit has no coefficient table set" | ||
| 14857 | + ); | ||
| 14858 | + corner_scan(cw, ch); | ||
| 14859 | + checked += 1; | ||
| 14860 | + } | ||
| 14861 | + assert_eq!( | ||
| 14862 | + checked, 12, | ||
| 14863 | + "the block-shape census changed: {checked} rect shapes reach the rect transform \ | ||
| 14864 | + tables, not the 12 this claim was measured over" | ||
| 14865 | + ); | ||
| 14866 | + // `sub_tx_size_map[TX_16X4] == TX_8X4` -- the only RECTANGULAR var-tx leaf | ||
| 14867 | + // shapes, which reach `rect_inter_luma_set` as `(tw, th)`. | ||
| 14868 | + for (w, h) in [(8usize, 4usize), (4, 8)] { | ||
| 14869 | + assert!( | ||
| 14870 | + rect_inter_luma_set(w, h).is_ok(), | ||
| 14871 | + "the {w}x{h} split leaf of a 16x4/4x16 strip has no luma coefficient table set" | ||
| 14872 | + ); | ||
| 14873 | + corner_scan(w, h); | ||
| 14874 | + } | ||
| 14875 | +} | ||
| 14876 | + | ||
| 14703 | /// [`read_block_tx_size`] for a rectangular inter block (lane-inter4 r2): | 14877 | /// [`read_block_tx_size`] for a rectangular inter block (lane-inter4 r2): |
| 14704 | /// spec 5.11.17 / libaom `read_tx_size_vartx` starting from the block's own | 14878 | /// spec 5.11.17 / libaom `read_tx_size_vartx` starting from the block's own |
| 14705 | /// `max_txsize_rect_lookup` entry, which for a 2:1 strip IS rectangular. The | 14879 | /// `max_txsize_rect_lookup` entry, which for a 2:1 strip IS rectangular. The |
| @@ -20242,6 +20416,7 @@ fn decode_inter_block( | |||
| 20242 | // exactly what it read before. | 20416 | // exactly what it read before. |
| 20243 | let (rmi, cmi) = at; | 20417 | let (rmi, cmi) = at; |
| 20244 | let (px, py) = (at.1 * MI, at.0 * MI); | 20418 | let (px, py) = (at.1 * MI, at.0 * MI); |
| 20419 | + census_inter_block_shape(side, write_w, write_h); | ||
| 20245 | // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's | 20420 | // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's |
| 20246 | // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd | 20421 | // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd |
| 20247 | // strip (`is_chroma_reference`); every other block keeps its own. | 20422 | // strip (`is_chroma_reference`); every other block keeps its own. |
crates/ec-av1/src/refusal_inventory.rsmodified+83 -1
| @@ -111,6 +111,63 @@ const REFUSALS: &[&str] = &[ | |||
| 111 | "a motion_mode symbol for a block shape with no CDF row here", | 111 | "a motion_mode symbol for a block shape with no CDF row here", |
| 112 | ]; | 112 | ]; |
| 113 | 113 | ||
| 114 | +/// The refusals that have a PROVING test, and its name. | ||
| 115 | +/// | ||
| 116 | +/// A refusal with no such test is an unmeasured claim: nothing in the suite | ||
| 117 | +/// distinguishes "this case never happens" from "no stream we decode has | ||
| 118 | +/// reached it yet". A proving test is one of two shapes: | ||
| 119 | +/// | ||
| 120 | +/// * a WITNESS gate -- a real stream reaches the shape, decodes exact, and the | ||
| 121 | +/// refusal is gone (the good case), or | ||
| 122 | +/// * a CENSUS gate -- N real streams decode with the refusal firing 0 times | ||
| 123 | +/// while the counters for the sibling shapes it names fire, so the claim is | ||
| 124 | +/// measured against the domain the decoder is actually handed. | ||
| 125 | +/// | ||
| 126 | +/// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`] | ||
| 127 | +/// is the honest numerator over the inventory below. | ||
| 128 | +#[cfg(test)] | ||
| 129 | +const PROVEN: &[(&str, &str)] = &[ | ||
| 130 | + // lane-t900 r20, census: three real streams present exactly the 18 | ||
| 131 | + // `(side, write_w, write_h)` triples `INTER_BLOCK_SHAPES` lists, and | ||
| 132 | + // `rect_inter_residual_supported` covers every rectangular one -- the only | ||
| 133 | + // footprints `reject_residual` is set for. | ||
| 134 | + ( | ||
| 135 | + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", | ||
| 136 | + "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable", | ||
| 137 | + ), | ||
| 138 | + // lane-t900 r20, census: the shapes that can reach `decode_intra_rect_in_inter`'s | ||
| 139 | + // size-group/tx-category lookup are the ten rectangular census shapes with | ||
| 140 | + // `8 <= min` and `max <= 64` (a sub-8 footprint and a 128-px one take | ||
| 141 | + // earlier branches), and every one of them has a row. | ||
| 142 | + ( | ||
| 143 | + "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)", | ||
| 144 | + "every_intra_in_inter_shape_the_census_lists_has_a_size_group_row", | ||
| 145 | + ), | ||
| 146 | + // lane-t900 r20, census: the only sub-8 footprints three real streams | ||
| 147 | + // present are the 16x4/4x16 strips of a 16x16-level 1:4 partition, whose | ||
| 148 | + // caller records the chroma pair for every strip, while the supported path | ||
| 149 | + // fires on both orientations inside streams that decode with no refusal. | ||
| 150 | + ( | ||
| 151 | + "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once for two strips; only the inter path implements that pairing)", | ||
| 152 | + "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable", | ||
| 153 | + ), | ||
| 154 | + // lane-t900 r20, census: the rect transform tables and scans, enumerated | ||
| 155 | + // over the shapes the measured block-shape domain hands each helper (block | ||
| 156 | + // footprint, 4:2:0 chroma unit, rect var-tx leaf, clamped coded corner). | ||
| 157 | + ( | ||
| 158 | + "a rectangular inter luma transform unit whose shape has no coefficient table set here", | ||
| 159 | + "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 160 | + ), | ||
| 161 | + ( | ||
| 162 | + "a rectangular inter chroma transform unit whose shape has no coefficient table set here", | ||
| 163 | + "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 164 | + ), | ||
| 165 | + ( | ||
| 166 | + "a rectangular transform unit whose shape has no coefficient scan table here", | ||
| 167 | + "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan", | ||
| 168 | + ), | ||
| 169 | +]; | ||
| 170 | + | ||
| 114 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than | 171 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than |
| 115 | /// a test failure. | 172 | /// a test failure. |
| 116 | /// | 173 | /// |
| @@ -131,7 +188,7 @@ const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[ | |||
| 131 | 188 | ||
| 132 | #[cfg(test)] | 189 | #[cfg(test)] |
| 133 | mod tests { | 190 | mod tests { |
| 134 | - use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, REFUSALS}; | 191 | + use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, PROVEN, REFUSALS}; |
| 135 | use std::collections::BTreeSet; | 192 | use std::collections::BTreeSet; |
| 136 | 193 | ||
| 137 | /// Every distinct `unsupported(...)` reason on the decode path. | 194 | /// Every distinct `unsupported(...)` reason on the decode path. |
| @@ -287,4 +344,29 @@ mod tests { | |||
| 287 | "{stale:#?} no longer swallow a decode error -- delete them from the list." | 344 | "{stale:#?} no longer swallow a decode error -- delete them from the list." |
| 288 | ); | 345 | ); |
| 289 | } | 346 | } |
| 347 | + | ||
| 348 | + /// Every entry of [`PROVEN`] must still name a live refusal and a test | ||
| 349 | + /// that exists, and the count it prints is the inventory's numerator. | ||
| 350 | + #[test] | ||
| 351 | + fn every_proven_refusal_names_a_test_that_exists() { | ||
| 352 | + let found = decode_path_refusals(); | ||
| 353 | + let sources = [include_str!("stream.rs"), include_str!("decode.rs")]; | ||
| 354 | + for (reason, gate) in PROVEN { | ||
| 355 | + assert!( | ||
| 356 | + found.contains(*reason), | ||
| 357 | + "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string" | ||
| 358 | + ); | ||
| 359 | + assert!( | ||
| 360 | + sources.iter().any(|src| src.contains(&format!("fn {gate}("))), | ||
| 361 | + "{reason:?} names the proving test {gate}, which exists in neither stream.rs \ | ||
| 362 | + nor decode.rs" | ||
| 363 | + ); | ||
| 364 | + } | ||
| 365 | + eprintln!( | ||
| 366 | + "refusal inventory: {} refusals + {} capability claims, {} proven", | ||
| 367 | + REFUSALS.len(), | ||
| 368 | + CAPABILITY_CLAIMS.len(), | ||
| 369 | + PROVEN.len() | ||
| 370 | + ); | ||
| 371 | + } | ||
| 290 | } | 372 | } |
crates/ec-av1/src/stream.rsmodified+163 -0
| @@ -30785,6 +30785,169 @@ mod tests { | |||
| 30785 | ); | 30785 | ); |
| 30786 | } | 30786 | } |
| 30787 | 30787 | ||
| 30788 | + /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular | ||
| 30789 | + /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. | ||
| 30790 | + /// | ||
| 30791 | + /// That string is a claim about a SHAPE, so what proves it is the set of | ||
| 30792 | + /// shapes the inter block path presents. `inter_piece!` sets | ||
| 30793 | + /// `reject_residual` to `$ww != $side || $wh != $side`, i.e. only for a | ||
| 30794 | + /// block whose true footprint is not its square CDF context, and the | ||
| 30795 | + /// refusal then needs `!rect_inter_residual_supported(write_w, write_h)`. | ||
| 30796 | + /// So it can fire only for a footprint that is BOTH rectangular (or a | ||
| 30797 | + /// square smaller than its own context) AND missing from that table. | ||
| 30798 | + /// | ||
| 30799 | + /// This gate measures the domain instead of asserting it: | ||
| 30800 | + /// [`crate::decode::inter_block_shape_mask`] records every | ||
| 30801 | + /// `(side, write_w, write_h)` triple decoded on this thread, with bit 31 | ||
| 30802 | + /// reserved for a triple [`crate::decode::INTER_BLOCK_SHAPES`] does not | ||
| 30803 | + /// list. Three real streams -- a 10-bit 1920x792 128-superblock film cut, | ||
| 30804 | + /// its 128-root intra witness and the 1920x792 small-side warp cut, | ||
| 30805 | + /// together ~140k inter blocks -- decode without a refusal and present | ||
| 30806 | + /// exactly 18 triples: the four square ones (`write == side`, where | ||
| 30807 | + /// `reject_residual` is false) and the fourteen rectangular AV1 block | ||
| 30808 | + /// shapes, every one of which `rect_inter_residual_supported` covers. No | ||
| 30809 | + /// square-inside-a-larger-context triple appears at all. | ||
| 30810 | + /// | ||
| 30811 | + /// Measured 2026-09-04: mask covers 18/18 listed triples, bit 31 clear, | ||
| 30812 | + /// 0 refusals. | ||
| 30813 | + #[test] | ||
| 30814 | + fn a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable() { | ||
| 30815 | + const NAME: &str = | ||
| 30816 | + "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable"; | ||
| 30817 | + const REFUSAL: &str = | ||
| 30818 | + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"; | ||
| 30819 | + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures"); | ||
| 30820 | + let mut blocks = 0usize; | ||
| 30821 | + for name in [ | ||
| 30822 | + "reelc_sb128_inter_witness.obu", | ||
| 30823 | + "intra128_in_inter_witness2.obu", | ||
| 30824 | + "gm_small_side_witness.obu", | ||
| 30825 | + ] { | ||
| 30826 | + let path = dir.join(name); | ||
| 30827 | + let stream = std::fs::read(&path) | ||
| 30828 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 30829 | + match decode_stream(&stream) { | ||
| 30830 | + Ok(frames) => { | ||
| 30831 | + assert!(!frames.is_empty(), "{NAME}: {name} decoded no frame"); | ||
| 30832 | + blocks += frames.len(); | ||
| 30833 | + } | ||
| 30834 | + Err(e) => { | ||
| 30835 | + assert!( | ||
| 30836 | + !format!("{e}").contains(REFUSAL), | ||
| 30837 | + "{NAME}: {name} hit the refusal this gate proves unreachable: {e}" | ||
| 30838 | + ); | ||
| 30839 | + panic!("{NAME}: {name} refused: {e}"); | ||
| 30840 | + } | ||
| 30841 | + } | ||
| 30842 | + } | ||
| 30843 | + assert!(blocks > 0, "{NAME}: no frames decoded"); | ||
| 30844 | + let mask = crate::decode::inter_block_shape_mask(); | ||
| 30845 | + assert_eq!( | ||
| 30846 | + mask & crate::decode::INTER_BLOCK_SHAPE_UNLISTED, | ||
| 30847 | + 0, | ||
| 30848 | + "{NAME}: a (side, write_w, write_h) triple outside INTER_BLOCK_SHAPES was decoded -- the census no longer describes the inter path's domain, so {REFUSAL:?} is not proven by it" | ||
| 30849 | + ); | ||
| 30850 | + for (i, &(side, w, h)) in crate::decode::INTER_BLOCK_SHAPES.iter().enumerate() { | ||
| 30851 | + assert!( | ||
| 30852 | + mask & (1u32 << i) != 0, | ||
| 30853 | + "{NAME}: {side}: {w}x{h} never decoded -- the census would prove nothing about it" | ||
| 30854 | + ); | ||
| 30855 | + // `reject_residual` is false for a square footprint (`write == | ||
| 30856 | + // side`), so only the rectangular ones can reach the refusal. | ||
| 30857 | + if (w, h) != (side, side) { | ||
| 30858 | + assert!( | ||
| 30859 | + crate::decode::rect_inter_residual_supported(w, h), | ||
| 30860 | + "{NAME}: {w}x{h} is decoded by real streams with reject_residual set but has no rectangular residual path -- {REFUSAL:?} is reachable" | ||
| 30861 | + ); | ||
| 30862 | + } | ||
| 30863 | + } | ||
| 30864 | + eprintln!( | ||
| 30865 | + "{NAME}: 3 streams, 0 refusals, {} of {} listed (side, write) triples decoded, bit31 clear", | ||
| 30866 | + crate::decode::INTER_BLOCK_SHAPES.len(), | ||
| 30867 | + crate::decode::INTER_BLOCK_SHAPES.len() | ||
| 30868 | + ); | ||
| 30869 | + } | ||
| 30870 | + | ||
| 30871 | + /// lane-t900 r20 GATE, refusal C -- `"an intra 16x4/4x16 strip inside an | ||
| 30872 | + /// inter 16x16-level 1:4 partition (its 4:2:0 chroma pair is coded once | ||
| 30873 | + /// for two strips; only the inter path implements that pairing)"`. | ||
| 30874 | + /// | ||
| 30875 | + /// The arm fires for an INTRA footprint with a side below 8 that carries | ||
| 30876 | + /// no chroma-pair record (`strip16`). Two measurements make that a claim | ||
| 30877 | + /// rather than a hope: | ||
| 30878 | + /// | ||
| 30879 | + /// * the block-shape census: the ONLY sub-8 footprints three real streams | ||
| 30880 | + /// present are 16x4 and 4x16 at a 16-px context, i.e. the strips of a | ||
| 30881 | + /// 16x16-level 1:4 partition -- and that caller sets | ||
| 30882 | + /// `INTER_STRIP_CHROMA` for every one of its four strips before the | ||
| 30883 | + /// block is decoded, so the record is never missing there; | ||
| 30884 | + /// * the sibling counter: the SUPPORTED path | ||
| 30885 | + /// ([`crate::decode::intra16x4_in_inter_hits`]) fires on both | ||
| 30886 | + /// orientations, chroma-paired, inside streams that decode with no | ||
| 30887 | + /// refusal at all. | ||
| 30888 | + /// | ||
| 30889 | + /// Measured 2026-09-04: 3 streams, 0 refusals, 78 16x4 + 149 4x16 (108 | ||
| 30890 | + /// chroma-paired), and 2 of 2 sub-8 census triples are the 1:4 strips. | ||
| 30891 | + #[test] | ||
| 30892 | + fn a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable() | ||
| 30893 | + { | ||
| 30894 | + const NAME: &str = | ||
| 30895 | + "a_sub8_footprint_census_over_real_streams_leaves_the_intra_16x4_pairing_refusal_unreachable"; | ||
| 30896 | + const REFUSAL: &str = "an intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition"; | ||
| 30897 | + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures"); | ||
| 30898 | + let before = crate::decode::intra16x4_in_inter_hits(); | ||
| 30899 | + for name in [ | ||
| 30900 | + "reelc_sb128_inter_witness.obu", | ||
| 30901 | + "intra128_in_inter_witness2.obu", | ||
| 30902 | + "gm_small_side_witness.obu", | ||
| 30903 | + ] { | ||
| 30904 | + let path = dir.join(name); | ||
| 30905 | + let stream = std::fs::read(&path) | ||
| 30906 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 30907 | + if let Err(e) = decode_stream(&stream) { | ||
| 30908 | + assert!( | ||
| 30909 | + !format!("{e}").contains(REFUSAL), | ||
| 30910 | + "{NAME}: {name} hit the refusal this gate proves unreachable: {e}" | ||
| 30911 | + ); | ||
| 30912 | + panic!("{NAME}: {name} refused: {e}"); | ||
| 30913 | + } | ||
| 30914 | + } | ||
| 30915 | + let after = crate::decode::intra16x4_in_inter_hits(); | ||
| 30916 | + let fired = (after.0 - before.0, after.1 - before.1, after.2 - before.2); | ||
| 30917 | + assert!( | ||
| 30918 | + fired.0 > 0 && fired.1 > 0 && fired.2 > 0, | ||
| 30919 | + "{NAME}: the SUPPORTED intra 16x4/4x16-in-inter path fired {fired:?} \ | ||
| 30920 | + (16x4, 4x16, chroma-paired) -- with a sibling at zero the refusal's claim is \ | ||
| 30921 | + untested from the other side" | ||
| 30922 | + ); | ||
| 30923 | + let sub8: Vec<(usize, usize, usize)> = crate::decode::INTER_BLOCK_SHAPES | ||
| 30924 | + .iter() | ||
| 30925 | + .copied() | ||
| 30926 | + .filter(|&(_, w, h)| w.min(h) < 8) | ||
| 30927 | + .collect(); | ||
| 30928 | + assert_eq!( | ||
| 30929 | + sub8, | ||
| 30930 | + vec![(16, 4, 16), (16, 16, 4)], | ||
| 30931 | + "{NAME}: the sub-8 footprints the inter path presents are no longer just the \ | ||
| 30932 | + 16x16-level 1:4 strips, whose caller always records the chroma pair -- the \ | ||
| 30933 | + refusal's domain changed" | ||
| 30934 | + ); | ||
| 30935 | + let mask = crate::decode::inter_block_shape_mask(); | ||
| 30936 | + for (i, &(side, w, h)) in crate::decode::INTER_BLOCK_SHAPES.iter().enumerate() { | ||
| 30937 | + if w.min(h) < 8 { | ||
| 30938 | + assert!( | ||
| 30939 | + mask & (1u32 << i) != 0, | ||
| 30940 | + "{NAME}: {side}: {w}x{h} never decoded -- the sub-8 census is vacuous" | ||
| 30941 | + ); | ||
| 30942 | + } | ||
| 30943 | + } | ||
| 30944 | + eprintln!( | ||
| 30945 | + "{NAME}: 3 streams, 0 refusals, intra16x4_in_inter 16x4={} 4x16={} chroma_ref={}, \ | ||
| 30946 | + sub-8 census triples {sub8:?}", | ||
| 30947 | + fired.0, fired.1, fired.2 | ||
| 30948 | + ); | ||
| 30949 | + } | ||
| 30950 | + | ||
| 30788 | /// lane-t900 r10: the small-side GLOBALMV / rect warp-reach witness. | 30951 | /// lane-t900 r10: the small-side GLOBALMV / rect warp-reach witness. |
| 30789 | /// `crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 bytes, | 30952 | /// `crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 bytes, |
| 30790 | /// sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`: | 30953 | /// sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`: |