Census-prove the rect-residual refusal unreachable over three real streams
Browse files at this commit81b0ef93fb0f72ec7c295f5fa4e05cdef49823ceParent: ba458d2- test
- census-prove the rect-residual refusal unreachable over three real streams
3 changed files +193 -2
- crates/ec-av1/src/decode.rs +59 -1
- crates/ec-av1/src/refusal_inventory.rs +51 -1
- crates/ec-av1/src/stream.rs +83 -0
crates/ec-av1/src/decode.rsmodified+59 -1
| @@ -14526,7 +14526,7 @@ fn read_block_tx_size( | ||
| 14526 | 14526 | /// `default_inter_ext_tx_cdf[2][TX_8X8]` (the 12-symbol |
| 14527 | 14527 | /// `DTT9_IDTX_1DDCT` row at `tx_size_sqr == TX_8X8`, only reachable through a |
| 14528 | 14528 | /// rect transform), neither of which exists yet -- both stay refused by name. |
| 14529 | -fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | |
| 14529 | +pub(crate) fn rect_inter_residual_supported(w: usize, h: usize) -> bool { | |
| 14530 | 14530 | matches!( |
| 14531 | 14531 | (w, h), |
| 14532 | 14532 | // 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 { | ||
| 14564 | 14564 | ) |
| 14565 | 14565 | } |
| 14566 | 14566 | |
| 14567 | +// lane-t900 r20: the `(side, write_w, write_h)` triples the inter block path | |
| 14568 | +// actually PRESENTS, as a thread-local bitmask -- the measured domain behind | |
| 14569 | +// the "rectangular ... has no ... here" refusals. `side` is the square context | |
| 14570 | +// a block reads its CDFs at and `write_w`/`write_h` its true footprint; | |
| 14571 | +// `inter_piece!` derives `reject_residual` from exactly that inequality, so | |
| 14572 | +// these triples are what decides whether those refusals can fire at all. Bit | |
| 14573 | +// 31 is "a triple this table does not list", which is what makes the gate a | |
| 14574 | +// census rather than a restatement of its own table. | |
| 14575 | +pub(crate) const INTER_BLOCK_SHAPES: [(usize, usize, usize); 18] = [ | |
| 14576 | + (16, 16, 16), | |
| 14577 | + (32, 32, 32), | |
| 14578 | + (32, 16, 32), | |
| 14579 | + (32, 32, 16), | |
| 14580 | + (16, 8, 16), | |
| 14581 | + (16, 16, 8), | |
| 14582 | + (32, 8, 32), | |
| 14583 | + (64, 64, 64), | |
| 14584 | + (32, 32, 8), | |
| 14585 | + (64, 16, 64), | |
| 14586 | + (128, 128, 128), | |
| 14587 | + (64, 32, 64), | |
| 14588 | + (64, 64, 32), | |
| 14589 | + (16, 4, 16), | |
| 14590 | + (64, 64, 16), | |
| 14591 | + (16, 16, 4), | |
| 14592 | + (128, 128, 64), | |
| 14593 | + (128, 64, 128), | |
| 14594 | +]; | |
| 14595 | + | |
| 14596 | +/// Bit 31 of [`inter_block_shape_mask`]: a `(side, write_w, write_h)` triple | |
| 14597 | +/// outside [`INTER_BLOCK_SHAPES`]. | |
| 14598 | +pub const INTER_BLOCK_SHAPE_UNLISTED: u32 = 1 << 31; | |
| 14599 | + | |
| 14600 | +thread_local! { | |
| 14601 | + static INTER_BLOCK_SHAPE_MASK: std::cell::Cell<u32> = const { std::cell::Cell::new(0) }; | |
| 14602 | +} | |
| 14603 | + | |
| 14604 | +/// Which of [`INTER_BLOCK_SHAPES`] this THREAD has decoded (thread-local, so a | |
| 14605 | +/// gate reading it sees only the streams it decoded itself). | |
| 14606 | +pub fn inter_block_shape_mask() -> u32 { | |
| 14607 | + INTER_BLOCK_SHAPE_MASK.with(std::cell::Cell::get) | |
| 14608 | +} | |
| 14609 | + | |
| 14610 | +/// Records one block's shape. The table is ordered by measured frequency over | |
| 14611 | +/// the three witnesses the census gate decodes, so the common square shapes | |
| 14612 | +/// leave the scan on their first comparison. | |
| 14613 | +fn census_inter_block_shape(side: usize, w: usize, h: usize) { | |
| 14614 | + let bit = match INTER_BLOCK_SHAPES.iter().position(|&s| s == (side, w, h)) { | |
| 14615 | + Some(i) => 1u32 << i, | |
| 14616 | + None => INTER_BLOCK_SHAPE_UNLISTED, | |
| 14617 | + }; | |
| 14618 | + let seen = inter_block_shape_mask(); | |
| 14619 | + if seen & bit == 0 { | |
| 14620 | + INTER_BLOCK_SHAPE_MASK.with(|c| c.set(seen | bit)); | |
| 14621 | + } | |
| 14622 | +} | |
| 14623 | + | |
| 14567 | 14624 | /// The luma coefficient/`tx_type` table set of a whole-block rectangular |
| 14568 | 14625 | /// INTER transform unit (lane-inter4 r3). `av1_get_ext_tx_set_type` splits |
| 14569 | 14626 | /// the two shapes: a 32x16/16x32 unit has `tx_size_sqr_up == TX_32X32`, so |
| @@ -20242,6 +20299,7 @@ fn decode_inter_block( | ||
| 20242 | 20299 | // exactly what it read before. |
| 20243 | 20300 | let (rmi, cmi) = at; |
| 20244 | 20301 | let (px, py) = (at.1 * MI, at.0 * MI); |
| 20302 | + census_inter_block_shape(side, write_w, write_h); | |
| 20245 | 20303 | // lane-inter16ab r2: a 16x4 / 4x16 inter strip's chroma is the PAIR's |
| 20246 | 20304 | // (8x4 / 4x8 at the even strip's origin) and is coded only by the odd |
| 20247 | 20305 | // strip (`is_chroma_reference`); every other block keeps its own. |
crates/ec-av1/src/refusal_inventory.rsmodified+51 -1
| @@ -111,6 +111,32 @@ const REFUSALS: &[&str] = &[ | ||
| 111 | 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 | +]; | |
| 139 | + | |
| 114 | 140 | /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than |
| 115 | 141 | /// a test failure. |
| 116 | 142 | /// |
| @@ -131,7 +157,7 @@ const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[ | ||
| 131 | 157 | |
| 132 | 158 | #[cfg(test)] |
| 133 | 159 | mod tests { |
| 134 | - use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, REFUSALS}; | |
| 160 | + use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, PROVEN, REFUSALS}; | |
| 135 | 161 | use std::collections::BTreeSet; |
| 136 | 162 | |
| 137 | 163 | /// Every distinct `unsupported(...)` reason on the decode path. |
| @@ -287,4 +313,28 @@ mod tests { | ||
| 287 | 313 | "{stale:#?} no longer swallow a decode error -- delete them from the list." |
| 288 | 314 | ); |
| 289 | 315 | } |
| 316 | + | |
| 317 | + /// Every entry of [`PROVEN`] must still name a live refusal and a test | |
| 318 | + /// that exists, and the count it prints is the inventory's numerator. | |
| 319 | + #[test] | |
| 320 | + fn every_proven_refusal_names_a_test_that_exists() { | |
| 321 | + let found = decode_path_refusals(); | |
| 322 | + let src = include_str!("stream.rs"); | |
| 323 | + for (reason, gate) in PROVEN { | |
| 324 | + assert!( | |
| 325 | + found.contains(*reason), | |
| 326 | + "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string" | |
| 327 | + ); | |
| 328 | + assert!( | |
| 329 | + src.contains(&format!("fn {gate}(")), | |
| 330 | + "{reason:?} names the proving test {gate}, which does not exist in stream.rs" | |
| 331 | + ); | |
| 332 | + } | |
| 333 | + eprintln!( | |
| 334 | + "refusal inventory: {} refusals + {} capability claims, {} proven", | |
| 335 | + REFUSALS.len(), | |
| 336 | + CAPABILITY_CLAIMS.len(), | |
| 337 | + PROVEN.len() | |
| 338 | + ); | |
| 339 | + } | |
| 290 | 340 | } |
crates/ec-av1/src/stream.rsmodified+83 -0
| @@ -30785,6 +30785,89 @@ 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 | + | |
| 30788 | 30871 | /// lane-t900 r10: the small-side GLOBALMV / rect warp-reach witness. |
| 30789 | 30872 | /// `crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 bytes, |
| 30790 | 30873 | /// sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`: |