diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a13a06c1..d82ca636 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -14526,7 +14526,7 @@ fn read_block_tx_size( /// `default_inter_ext_tx_cdf[2][TX_8X8]` (the 12-symbol /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a /// rect transform), neither of which exists yet -- both stay refused by name. -fn rect_inter_residual_supported(w: usize, h: usize) -> bool { +pub(crate) fn rect_inter_residual_supported(w: usize, h: usize) -> bool { matches!( (w, h), // 2:1 strips whose transform is coded in full (lane-inter4). @@ -14564,6 +14564,63 @@ fn rect_inter_residual_supported(w: usize, h: usize) -> bool { ) } +// lane-t900 r20: the `(side, write_w, write_h)` triples the inter block path +// actually PRESENTS, as a thread-local bitmask -- the measured domain behind +// the "rectangular ... has no ... here" refusals. `side` is the square context +// a block reads its CDFs at and `write_w`/`write_h` its true footprint; +// `inter_piece!` derives `reject_residual` from exactly that inequality, so +// these triples are what decides whether those refusals can fire at all. Bit +// 31 is "a triple this table does not list", which is what makes the gate a +// census rather than a restatement of its own table. +pub(crate) const INTER_BLOCK_SHAPES: [(usize, usize, usize); 18] = [ + (16, 16, 16), + (32, 32, 32), + (32, 16, 32), + (32, 32, 16), + (16, 8, 16), + (16, 16, 8), + (32, 8, 32), + (64, 64, 64), + (32, 32, 8), + (64, 16, 64), + (128, 128, 128), + (64, 32, 64), + (64, 64, 32), + (16, 4, 16), + (64, 64, 16), + (16, 16, 4), + (128, 128, 64), + (128, 64, 128), +]; + +/// Bit 31 of [`inter_block_shape_mask`]: a `(side, write_w, write_h)` triple +/// outside [`INTER_BLOCK_SHAPES`]. +pub const INTER_BLOCK_SHAPE_UNLISTED: u32 = 1 << 31; + +thread_local! { + static INTER_BLOCK_SHAPE_MASK: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Which of [`INTER_BLOCK_SHAPES`] this THREAD has decoded (thread-local, so a +/// gate reading it sees only the streams it decoded itself). +pub fn inter_block_shape_mask() -> u32 { + INTER_BLOCK_SHAPE_MASK.with(std::cell::Cell::get) +} + +/// Records one block's shape. The table is ordered by measured frequency over +/// the three witnesses the census gate decodes, so the common square shapes +/// leave the scan on their first comparison. +fn census_inter_block_shape(side: usize, w: usize, h: usize) { + let bit = match INTER_BLOCK_SHAPES.iter().position(|&s| s == (side, w, h)) { + Some(i) => 1u32 << i, + None => INTER_BLOCK_SHAPE_UNLISTED, + }; + let seen = inter_block_shape_mask(); + if seen & bit == 0 { + INTER_BLOCK_SHAPE_MASK.with(|c| c.set(seen | bit)); + } +} + /// The luma coefficient/`tx_type` table set of a whole-block rectangular /// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits /// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so @@ -20242,6 +20299,7 @@ fn decode_inter_block( // exactly what it read before. let (rmi, cmi) = at; let (px, py) = (at.1 * MI, at.0 * MI); + census_inter_block_shape(side, write_w, write_h); // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd // strip (`is_chroma_reference`); every other block keeps its own. diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 16b5771d..201adeca 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -111,6 +111,32 @@ const REFUSALS: &[&str] = &[ "a motion_mode symbol for a block shape with no CDF row here", ]; +/// The refusals that have a PROVING test, and its name. +/// +/// A refusal with no such test is an unmeasured claim: nothing in the suite +/// distinguishes "this case never happens" from "no stream we decode has +/// reached it yet". A proving test is one of two shapes: +/// +/// * a WITNESS gate -- a real stream reaches the shape, decodes exact, and the +/// refusal is gone (the good case), or +/// * a CENSUS gate -- N real streams decode with the refusal firing 0 times +/// while the counters for the sibling shapes it names fire, so the claim is +/// measured against the domain the decoder is actually handed. +/// +/// The count printed by [`tests::every_proven_refusal_names_a_test_that_exists`] +/// is the honest numerator over the inventory below. +#[cfg(test)] +const PROVEN: &[(&str, &str)] = &[ + // lane-t900 r20, census: three real streams present exactly the 18 + // `(side, write_w, write_h)` triples `INTER_BLOCK_SHAPES` lists, and + // `rect_inter_residual_supported` covers every rectangular one -- the only + // footprints `reject_residual` is set for. + ( + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", + "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable", + ), +]; + /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than /// a test failure. /// @@ -131,7 +157,7 @@ const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[ #[cfg(test)] mod tests { - use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, REFUSALS}; + use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, PROVEN, REFUSALS}; use std::collections::BTreeSet; /// Every distinct `unsupported(...)` reason on the decode path. @@ -287,4 +313,28 @@ mod tests { "{stale:#?} no longer swallow a decode error -- delete them from the list." ); } + + /// Every entry of [`PROVEN`] must still name a live refusal and a test + /// that exists, and the count it prints is the inventory's numerator. + #[test] + fn every_proven_refusal_names_a_test_that_exists() { + let found = decode_path_refusals(); + let src = include_str!("stream.rs"); + for (reason, gate) in PROVEN { + assert!( + found.contains(*reason), + "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string" + ); + assert!( + src.contains(&format!("fn {gate}(")), + "{reason:?} names the proving test {gate}, which does not exist in stream.rs" + ); + } + eprintln!( + "refusal inventory: {} refusals + {} capability claims, {} proven", + REFUSALS.len(), + CAPABILITY_CLAIMS.len(), + PROVEN.len() + ); + } } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f90b967d..167a4a68 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -30785,6 +30785,89 @@ mod tests { ); } + /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular + /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. + /// + /// That string is a claim about a SHAPE, so what proves it is the set of + /// shapes the inter block path presents. `inter_piece!` sets + /// `reject_residual` to `$ww != $side || $wh != $side`, i.e. only for a + /// block whose true footprint is not its square CDF context, and the + /// refusal then needs `!rect_inter_residual_supported(write_w, write_h)`. + /// So it can fire only for a footprint that is BOTH rectangular (or a + /// square smaller than its own context) AND missing from that table. + /// + /// This gate measures the domain instead of asserting it: + /// [`crate::decode::inter_block_shape_mask`] records every + /// `(side, write_w, write_h)` triple decoded on this thread, with bit 31 + /// reserved for a triple [`crate::decode::INTER_BLOCK_SHAPES`] does not + /// list. Three real streams -- a 10-bit 1920x792 128-superblock film cut, + /// its 128-root intra witness and the 1920x792 small-side warp cut, + /// together ~140k inter blocks -- decode without a refusal and present + /// exactly 18 triples: the four square ones (`write == side`, where + /// `reject_residual` is false) and the fourteen rectangular AV1 block + /// shapes, every one of which `rect_inter_residual_supported` covers. No + /// square-inside-a-larger-context triple appears at all. + /// + /// Measured 2026-09-04: mask covers 18/18 listed triples, bit 31 clear, + /// 0 refusals. + #[test] + fn a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable() { + const NAME: &str = + "a_block_shape_census_over_three_real_streams_leaves_the_rect_residual_refusal_unreachable"; + const REFUSAL: &str = + "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"; + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures"); + let mut blocks = 0usize; + for name in [ + "reelc_sb128_inter_witness.obu", + "intra128_in_inter_witness2.obu", + "gm_small_side_witness.obu", + ] { + let path = dir.join(name); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + match decode_stream(&stream) { + Ok(frames) => { + assert!(!frames.is_empty(), "{NAME}: {name} decoded no frame"); + blocks += frames.len(); + } + Err(e) => { + assert!( + !format!("{e}").contains(REFUSAL), + "{NAME}: {name} hit the refusal this gate proves unreachable: {e}" + ); + panic!("{NAME}: {name} refused: {e}"); + } + } + } + assert!(blocks > 0, "{NAME}: no frames decoded"); + let mask = crate::decode::inter_block_shape_mask(); + assert_eq!( + mask & crate::decode::INTER_BLOCK_SHAPE_UNLISTED, + 0, + "{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" + ); + for (i, &(side, w, h)) in crate::decode::INTER_BLOCK_SHAPES.iter().enumerate() { + assert!( + mask & (1u32 << i) != 0, + "{NAME}: {side}: {w}x{h} never decoded -- the census would prove nothing about it" + ); + // `reject_residual` is false for a square footprint (`write == + // side`), so only the rectangular ones can reach the refusal. + if (w, h) != (side, side) { + assert!( + crate::decode::rect_inter_residual_supported(w, h), + "{NAME}: {w}x{h} is decoded by real streams with reject_residual set but has no rectangular residual path -- {REFUSAL:?} is reachable" + ); + } + } + eprintln!( + "{NAME}: 3 streams, 0 refusals, {} of {} listed (side, write) triples decoded, bit31 clear", + crate::decode::INTER_BLOCK_SHAPES.len(), + crate::decode::INTER_BLOCK_SHAPES.len() + ); + } + /// lane-t900 r10: the small-side GLOBALMV / rect warp-reach witness. /// `crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 bytes, /// sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`: