diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a9dbb46c..ab9c2b71 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -7088,11 +7088,6 @@ fn read_intra_mode_rect( let use_palette_y = mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0; if use_palette_y { - if palette.is_none() { - return Err(unsupported( - "a block that actually uses a palette (Y) -- reconstruction is out of scope", - )); - } let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); let colors = read_palette_colors_y(dec, n, cache, fctx); palette_y_pending = Some((n, colors)); @@ -11166,11 +11161,6 @@ fn read_intra_mode( eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32); } if use_palette_y { - if palette.is_none() { - return Err(unsupported( - "a block that actually uses a palette (Y) -- reconstruction is out of scope", - )); - } let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); if trace { let (rng, _) = dec.debug_state(); diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 056dd777..8156abb1 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -50,10 +50,12 @@ const REFUSALS: &[&str] = &[ // 8x8 LEAF inside an inter frame (this round, gate // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`), // which is why the (UV) string is gone from the decoder entirely -- the - // leaf was its only site. The (Y) one survives ONLY as the defensive - // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`; - // every caller now passes a real ctx/cache pair, so no stream reaches it. - "a block that actually uses a palette (Y) -- reconstruction is out of scope", + // leaf was its only site. The (Y) one survived as the defensive + // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect` + // until lane-t900 r33 DELETED both arms: all eight call sites hand the + // reader a real ctx/cache pair, so no stream could reach either (audit + // `every_read_intra_mode_call_site_hands_the_reader_a_palette_cache`, + // which keeps that invariant now the refusal is gone). "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", "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)", @@ -349,6 +351,62 @@ const PROVEN: &[(&str, &str)] = &[ // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact` // decodes both lifted shapes byte-exact vs ffmpeg, and the census now // asserts none of the three strings comes back. + // lane-t900 r33, enumeration: the five callers of `decode_rect_split` pass + // the ten rect footprints with `8 <= min` and `max <= 64`, and every one of + // them has a chroma table and -- at every tx depth -- a luma arm. The two + // shape classes that would miss one (a 128-sided half, a sub-8 strip) have + // readers that are not among those callers. + ( + "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", + "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table", + ), + ( + "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", + "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table", + ), + // lane-t900 r33, enumeration: each of the four symbols this guard tests is + // read under a size gate that no 128-pixel side passes (the call site's + // literal `cfl=false`, `filter_intra_size_class_rect`'s table, and + // `palette_bsize_ctx_wh`'s bound). + ( + "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", + "no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol", + ), + // lane-t900 r33, WITNESS of a capability gap: the refusal is REACHED by + // real `--tune-content=screen --enable-palette=1` streams, counted + // (`palette_sb_strip_hits`) and hard-asserted non-zero by its gate, which + // also decodes the arms that do not reach it pixel-exact. lane-pal8 r1 + // measured the lift and it mismatches whole-frame, so the string names a + // real shape a real encoder writes -- an open capability, not a claim. + ( + "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", + "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact", + ), + // lane-t900 r33, CENSUS (reached -- a pinned capability gap): all four + // `--sb-size=128` exact-repetition screen arms code + // `use_128x128_superblock && allow_intrabc`, and every one of them reaches + // this refusal by name. The lift is a decode.rs change (the block-vector + // delay of `av1_is_dv_valid` is superblock-sized) with a waiting witness, + // `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` (ignored). + ( + "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", + "an_sb128_screen_census_measures_the_sb128_intrabc_refusal", + ), + // lane-t900 r33, CENSUS: the `use_intrabc` symbol IS read at the sub-8 + // reader for every sub-8x8 leaf of an `allow_intrabc` frame, and over the + // `--min-partition-size=4` exact-repetition screen arms every such symbol + // came back 0 while the frames decode pixel-exact. + ( + "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", + "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal", + ), + // lane-t900 r33, CENSUS: four quantisers of the recipe that reaches the + // intrabc var-tx tree at all read it for 5 blocks in total, every one of + // which resolved to a UNIFORM leaf size, with the frames pixel-exact. + ( + "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes", + "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal", + ), ( "a reference picture whose height does not match this frame's own true size", "an_inter_frame_shorter_than_its_reference_is_refused_by_name", @@ -1045,6 +1103,281 @@ mod tests { } } + /// lane-t900 r33, ENUMERATION for the two [`decode_rect_split`] refusals + /// ("a coded HORZ/VERT strip whose chroma transform has no rect + /// coefficient tables here" and "a split intra strip whose transform unit + /// is {tx_w}x{tx_h}"). + /// + /// Both guard shape lookups inside one function, so the proof is one + /// enumeration: the footprints that function is CALLED with, walked + /// through `depth_to_tx_wh` at every depth, against the two `match` + /// tables read out of `decode.rs` itself (class + /// `table-and-reader-move-together` -- a table edit invalidates this test + /// rather than sneaking past it). + /// + /// The footprint domain is the five callers' own: `decode_block_rect` + /// (32-level 2:1), `decode_block_rect4` (32-level 1:4), `decode_leaf_rect` + /// (16-level 2:1), `decode_block_rect64` (64-level 2:1 and 1:4) and + /// `decode_intra_rect_in_inter`, whose reachable shapes are the ten + /// rectangular census shapes with `8 <= min` and `max <= 64` (already + /// pinned by `every_intra_in_inter_shape_the_census_lists_has_a_size_group_row`). + /// The two shape classes that would MISS a table -- a 128-sided half + /// (chroma 64x32) and a sub-8 strip (16x4 -> chroma 8x2) -- are excluded + /// structurally: their readers, `decode_block_128rect` and + /// `decode_rect4_16_strip`, are not among the callers, which this test + /// asserts by locating every `decode_rect_split(` call in its enclosing + /// function. + #[test] + fn every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table() { + let src = include_str!("decode.rs"); + + // (1) The caller set. Each call's enclosing function is the last + // top-level `fn` before it. + let fn_starts: Vec<(usize, String)> = src + .match_indices("\nfn ") + .map(|(i, _)| { + let rest = &src[i + 4..]; + let name = rest[..rest.find('(').unwrap_or(0)].to_string(); + (i, name) + }) + .collect(); + let mut callers: BTreeSet = BTreeSet::new(); + for (at, _) in src.match_indices("decode_rect_split(") { + let enclosing = fn_starts + .iter() + .filter(|(i, _)| *i < at) + .next_back() + .expect("a decode_rect_split call outside any function"); + if enclosing.1 != "decode_rect_split" { + callers.insert(enclosing.1.clone()); + } + } + let expected: BTreeSet = [ + "decode_block_rect", + "decode_block_rect4", + "decode_block_rect64", + "decode_intra_rect_in_inter", + "decode_leaf_rect", + ] + .iter() + .map(|s| s.to_string()) + .collect(); + assert_eq!( + callers, expected, + "the set of functions that call decode_rect_split changed -- re-derive the \ + footprint domain below from the new caller (a 128-sided or sub-8 caller makes \ + both refusals live)" + ); + + // (2) The walk, asserted against its own source before it is applied. + const WALK: &str = " let (mut w, mut h) = (bw.min(64), bh.min(64));\n \ + for _ in 0..depth {\n match w.cmp(&h) {\n \ + std::cmp::Ordering::Greater => w /= 2,\n \ + std::cmp::Ordering::Less => h /= 2,\n \ + std::cmp::Ordering::Equal => {\n w /= 2;\n \ + h /= 2;\n }\n }\n }"; + assert_eq!( + src.matches(WALK).count(), + 1, + "depth_to_tx_wh's walk is no longer spelled the way this enumeration mirrors it" + ); + let depth_to_tx_wh = |bw: usize, bh: usize, depth: usize| { + let (mut w, mut h) = (bw.min(64), bh.min(64)); + for _ in 0..depth { + match w.cmp(&h) { + std::cmp::Ordering::Greater => w /= 2, + std::cmp::Ordering::Less => h /= 2, + std::cmp::Ordering::Equal => { + w /= 2; + h /= 2; + } + } + } + (w, h) + }; + + // (3) The two tables, read out of decode_rect_split's own text: every + // `(w, h) =>` / `(w, h) |` match arm head between the table's `let` + // and the guard that follows it. + let body_at = src.find("fn decode_rect_split(").expect("decode_rect_split is gone"); + let body = &src[body_at..]; + let slice = |from: &str, to: &str| -> &str { + let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split")); + let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split")); + &body[a..a + b] + }; + let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> { + let mut out = BTreeSet::new(); + let bytes = text.as_bytes(); + for (i, _) in text.match_indices('(') { + let mut j = i + 1; + let mut w = 0usize; + while j < bytes.len() && bytes[j].is_ascii_digit() { + w = w * 10 + usize::from(bytes[j] - b'0'); + j += 1; + } + if j == i + 1 || !text[j..].starts_with(", ") { + continue; + } + j += 2; + let mut h = 0usize; + let start_h = j; + while j < bytes.len() && bytes[j].is_ascii_digit() { + h = h * 10 + usize::from(bytes[j] - b'0'); + j += 1; + } + if j == start_h || !text[j..].starts_with(')') { + continue; + } + // Only an arm HEAD counts, never a `(32, 8)` inside prose. + let after = text[j + 1..].trim_start(); + if after.starts_with("=>") || after.starts_with('|') { + out.insert((w, h)); + } + } + out + }; + let chroma = arm_shapes(slice("let chroma: Option<(TxbSet", "if !m.skip {")); + let luma = arm_shapes(slice("let luma_rect: Option<(TxbSet", "no luma \\")); + assert!( + chroma.len() >= 6 && luma.len() >= 6, + "the tables parsed to {} chroma / {} luma shapes -- the parse, not the decoder, \ + is what this would be measuring", + chroma.len(), + luma.len() + ); + + // (4) The enumeration itself. + let mut checked = 0u32; + for wl in 3..=6u32 { + for hl in 3..=6u32 { + let (bw, bh) = (1usize << wl, 1usize << hl); + let ratio = bw.max(bh) / bw.min(bh); + if ratio != 2 && ratio != 4 { + continue; + } + assert!( + chroma.contains(&(bw / 2, bh / 2)), + "a {bw}x{bh} strip's {}x{} chroma transform has no rect table -- the \ + chroma refusal is LIVE for a shape a caller codes", + bw / 2, + bh / 2 + ); + // Every depth: once the walk reaches a square it stays square, + // so this covers any tx_depth a header can code. + for depth in 1..=4 { + let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth); + assert!( + tx_w == tx_h || luma.contains(&(tx_w, tx_h)), + "a {bw}x{bh} strip at depth {depth} resolves to a {tx_w}x{tx_h} \ + transform unit, which has no luma arm -- that refusal is LIVE" + ); + checked += 1; + } + } + } + assert_eq!(checked, 40, "the strip domain is not the ten rect shapes x four depths"); + } + + /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a + /// 128-root HORZ/VERT intra block". + /// + /// The guard fires when any of four symbols came back `Some` from + /// `read_intra_mode_rect` on a 128x64/64x128 half. Each of the four is + /// read under a size gate, and none of those gates admits a 128-pixel + /// side: + /// + /// * `cfl_alpha` -- read only under the `cfl` PARAMETER, and the 128-root + /// call site passes the literal `false`; + /// * `use_filter_intra` -- read only when `filter_intra_size_class_rect` + /// is `Some`, whose table has no arm with a 128 side and whose square + /// fallback (`filter_intra_size_class`) caps at 32 + /// (`av1_filter_intra_allowed_bsize`); + /// * `palette_y_mode` / `palette_uv_mode` -- both inside the + /// `palette_bsize_ctx_wh` block already enumerated by + /// [`no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax`]. + #[test] + fn no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol() { + let src = include_str!("decode.rs"); + // The 128-root call site's own `cfl` argument, with the comment that + // explains it -- the two lines are matched together so that reordering + // the arguments cannot leave this test pointing at another `false`. + const CFL_OFF_AT_128: &str = " // `is_cfl_allowed` caps CFL at 32x32: `uv_mode` comes off the\n \ + // 13-symbol no-CFL CDF here, never the 14-symbol one.\n false,"; + assert_eq!( + src.matches(CFL_OFF_AT_128).count(), + 1, + "the 128-root call site no longer passes cfl=false -- a CfL alpha can reach the \ + guard, so this enumeration proves nothing" + ); + // The filter-intra table: every arm head, plus the square fallback. + let fi_at = src + .find("fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option {") + .expect("filter_intra_size_class_rect is gone"); + let fi_body = &src[fi_at..fi_at + src[fi_at..].find("\n}\n").expect("unterminated fn")]; + assert!( + !fi_body.contains("128"), + "filter_intra_size_class_rect grew an arm naming a 128 side" + ); + assert!( + fi_body.contains("_ if bw == bh => filter_intra_size_class(bw),") + && fi_body.contains("_ => None,"), + "filter_intra_size_class_rect's fallbacks changed shape" + ); + let sq_at = src + .find("fn filter_intra_size_class(side: usize) -> Option {") + .expect("filter_intra_size_class is gone"); + let sq_body = &src[sq_at..sq_at + src[sq_at..].find("\n}\n").expect("unterminated fn")]; + assert!( + !sq_body.contains("128") && !sq_body.contains("64"), + "filter_intra_size_class admits a side above 32 -- av1_filter_intra_allowed_bsize \ + does not, so re-derive this proof" + ); + // And palette, at the two shapes the refusal names. + assert!( + src.contains("if bw > 64 || bh > 64 || bw * bh < 64 {"), + "palette_bsize_ctx_wh's bound moved -- see \ + no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax" + ); + for (bw, bh) in [(128usize, 64usize), (64, 128)] { + assert!(bw > 64 || bh > 64, "{bw}x{bh} is not a 128-root half"); + } + } + + /// lane-t900 r33, STRUCTURAL AUDIT behind the DELETION of "a block that + /// actually uses a palette (Y) -- reconstruction is out of scope". + /// + /// That refusal was the `palette.is_none()` arm of `read_intra_mode` and + /// `read_intra_mode_rect`: a stream reached it only if a CALLER read the + /// palette syntax without handing the reader a neighbour ctx/cache pair. + /// Every one of the eight call sites passes `Some((palette_ctx, + /// &palette_cache))`, so no stream could reach either arm and both are + /// gone from `decode.rs`. This test keeps the invariant the deletion rests + /// on: a future caller that passes `None` fails here rather than decoding + /// a palette off an empty colour cache. + #[test] + fn every_read_intra_mode_call_site_hands_the_reader_a_palette_cache() { + let src = include_str!("decode.rs"); + let mut sites = 0u32; + for name in ["read_intra_mode(", "read_intra_mode_rect("] { + for (at, _) in src.match_indices(name) { + // The definition itself, not a call. + if src[..at].ends_with("fn ") { + continue; + } + sites += 1; + let window = &src[at..(at + 4096).min(src.len())]; + let end = window.find("fctx,\n").unwrap_or(window.len()); + assert!( + window[..end].contains("Some((palette_ctx, &palette_cache)),"), + "a {name} call site does not hand the reader a palette ctx/cache pair -- \ + the deleted `palette.is_none()` refusal was its guard" + ); + } + } + assert_eq!(sites, 8, "the call-site audit found {sites} sites, not the 8 it enumerated"); + } + /// 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] diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index b2fe4b86..3c4ee7b5 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4585,6 +4585,20 @@ mod tests { /// and 1:4 partitions off so an intrabc block lands on a SQUARE block /// instead of stopping on the rect-strip intrabc refusal first. fn screen_intrabc_stream(src: &str, cq: &str, txs: &str, tiled: bool, square_only: bool) -> Vec { + screen_intrabc_stream_with(src, cq, txs, tiled, square_only, &[]) + } + + /// [`screen_intrabc_stream`] with per-arm flags appended AFTER the base + /// recipe -- aomenc keeps the LAST occurrence of a repeated flag, so an + /// arm can override `--sb-size` / `--min-partition-size` here. + fn screen_intrabc_stream_with( + src: &str, + cq: &str, + txs: &str, + tiled: bool, + square_only: bool, + extra: &[&str], + ) -> Vec { let mut ff = Command::new("ffmpeg"); ff.args(["-v", "error", "-f", "lavfi", "-i", src, "-t", "0.2"]); if tiled { @@ -4626,6 +4640,7 @@ mod tests { } else { &[][..] }) + .args(extra) .args(["--obu", "-o", "-", "-"]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -4651,6 +4666,325 @@ mod tests { enc.stdout } + /// The sequence header's `use_128x128_superblock`, and how many frames of + /// `stream` keep `allow_intrabc` -- the two bits the refusal "intrabc + /// under a 128x128 superblock" is the conjunction of, read out of the + /// headers rather than assumed from the flags handed to the encoder. + fn sb128_and_intrabc_frames(stream: &[u8]) -> (bool, u32) { + let mut parser = Av1Parser::new(); + let mut pos = 0usize; + let (mut sb128, mut intrabc) = (false, 0u32); + while pos < stream.len() { + let Ok(obu) = parser.parse_obu(&stream[pos..]) else { + break; + }; + pos += obu.total_size.max(1); + if let Some(seq) = parser.sequence_header() { + sb128 = seq.use_128x128_superblock; + } + let header = match &obu.kind { + ObuKind::Frame(h, _) => Some(&**h), + ObuKind::FrameHeader(h) => Some(&**h), + _ => None, + }; + if header.is_some_and(|h| h.allow_intrabc) { + intrabc += 1; + } + } + (sb128, intrabc) + } + + /// lane-t900 r33, CENSUS for "intrabc under a 128x128 superblock". + /// + /// Unlike every other refusal in the inventory this one is decided in the + /// FRAME HEADER, before a single block symbol: `use_128x128_superblock && + /// allow_intrabc`. So the census question is only whether a real encoder + /// writes that conjunction -- if it does, the refusal is a capability gap + /// (this decoder hardcodes the block-vector delay of `av1_is_dv_valid` to + /// a 64-px superblock) and the arm that reaches it is pinned here; if no + /// arm does, the string is measured against the domain instead of assumed. + /// + /// The four arms are the exact-repetition recipe that is the ONLY shape + /// known to keep `allow_intrabc` past libaom's own RD (lane-t900 r31: on + /// non-repeating content, `--enable-tx-size-search=1` makes RD drop + /// intrabc and libaom clears the bit again), with `--sb-size=128` and both + /// tx-size-search settings over two quantisers. + #[test] + fn an_sb128_screen_census_measures_the_sb128_intrabc_refusal() { + const NAME: &str = "an_sb128_screen_census_measures_the_sb128_intrabc_refusal"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let (width, height) = (256usize, 192usize); + let (mut premise_arms, mut reached, mut decoded_arms, mut frames_compared) = + (0u32, 0u32, 0u32, 0u32); + for txs in ["0", "1"] { + for cq in ["30", "45"] { + let arm = format!("sb128 txs={txs} cq={cq}"); + let stream = screen_intrabc_stream_with( + "smptebars=size=128x96:rate=25", + cq, + txs, + true, + true, + &["--sb-size=128"], + ); + let (sb128, intrabc_frames) = sb128_and_intrabc_frames(&stream); + assert!(sb128, "{NAME}: {arm}: aomenc ignored --sb-size=128"); + if intrabc_frames > 0 { + premise_arms += 1; + } + match decode_stream(&stream) { + Ok(frames) => { + decoded_arms += 1; + let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { + assert!( + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, + "{NAME}: {arm} frame {i} does not match ffmpeg" + ); + frames_compared += 1; + } + eprintln!( + "{NAME}: {arm} sb128={sb128} intrabc_frames={intrabc_frames} \ + DECODED {} frame(s) exact", + frames.len() + ); + } + Err(e) => { + let msg = e.to_string(); + assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + if msg.contains("intrabc under a 128x128 superblock") { + reached += 1; + } + eprintln!( + "{NAME}: {arm} sb128={sb128} intrabc_frames={intrabc_frames} \ + REFUSED: {e}" + ); + } + } + } + } + eprintln!( + "{NAME}: {premise_arms}/4 arm(s) code allow_intrabc under a 128x128 superblock, \ + {reached} reach the refusal, {decoded_arms} arm(s) decoded \ + ({frames_compared} frames exact)" + ); + assert!( + premise_arms + decoded_arms > 0, + "{NAME}: census is vacuous -- no arm produced a decodable or premise-carrying stream" + ); + assert_eq!( + reached, premise_arms, + "{NAME}: the refusal is the CONJUNCTION of the two header bits, so every arm \ + carrying it must reach the refusal and no other arm may" + ); + } + + /// lane-t900 r33, the WAITING witness for the capability gap + /// [`an_sb128_screen_census_measures_the_sb128_intrabc_refusal`] pins: + /// FIRST BAD is `--sb-size=128 --tune-content=screen --enable-intrabc=1 + /// --enable-tx-size-search=0 --cq-level=30` on a 2x2 tiling of a 128x96 + /// bar pattern (256x192, 8-bit, `--cpu-used=0 --min-partition-size=8 + /// --max-partition-size=32 --enable-rect-partitions=0 + /// --enable-1to4-partitions=0`) -- all four arms of the census code + /// `use_128x128_superblock && allow_intrabc`, so the refusal names a + /// configuration real aomenc writes at its FIRST attempt, not a corner. + /// + /// Lifting it is a `decode.rs` change this lane is not allowed to make: + /// `av1_is_dv_valid` derives the block-vector delay (`sb_size` wide + /// `INTRABC_DELAY_PIXELS`, the wavefront the valid-DV region is offset + /// by) from the SUPERBLOCK SIZE, which this decoder hardcodes to 64, so + /// every DV bound and every intrabc source fetch under a 128 superblock + /// is computed against the wrong wavefront. Ignored until that lands. + #[test] + #[ignore = "capability gap: intrabc's block-vector delay is hardcoded to a 64-px superblock"] + fn an_sb128_screen_stream_with_intrabc_decodes_pixel_exact() { + const NAME: &str = "an_sb128_screen_stream_with_intrabc_decodes_pixel_exact"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let (width, height) = (256usize, 192usize); + let stream = screen_intrabc_stream_with( + "smptebars=size=128x96:rate=25", + "30", + "0", + true, + true, + &["--sb-size=128"], + ); + let (sb128, intrabc_frames) = sb128_and_intrabc_frames(&stream); + assert!(sb128 && intrabc_frames > 0, "{NAME}: the first-bad recipe no longer codes it"); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: {e}")); + let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count"); + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { + assert!( + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, + "{NAME}: frame {i} does not match ffmpeg" + ); + } + } + + /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc". + /// + /// The `use_intrabc` symbol IS read at that reader for every sub-8x8 leaf + /// of an `allow_intrabc` frame, so arrival is provable rather than + /// assumed: the arms below force 4x4 leaves (`--min-partition-size=4`) on + /// the exact-repetition screen content that keeps `allow_intrabc`, and the + /// gate requires both counters -- `allow_intrabc` frames and decoded sub-8 + /// leaves -- to be non-zero before it reads anything into the refusal + /// firing 0 times (class `gate-blind-to-feature`). + #[test] + fn a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal() { + const NAME: &str = "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let (width, height) = (256usize, 192usize); + let _guard = lock_gate_counters(); + let (mut premise_arms, mut reached, mut sub8_total, mut frames_compared) = + (0u32, 0u32, 0usize, 0u32); + for cq in ["30", "45"] { + let arm = format!("sub8 cq={cq}"); + let stream = screen_intrabc_stream_with( + "smptebars=size=128x96:rate=25", + cq, + "0", + true, + true, + &["--min-partition-size=4"], + ); + let (_, intrabc_frames) = sb128_and_intrabc_frames(&stream); + if intrabc_frames > 0 { + premise_arms += 1; + } + // No reset for this counter, so measure the delta (the gate lock + // above keeps another gate's decode out of it). + let sub8_before = crate::decode::sub8_split_hits(); + match decode_stream(&stream) { + Ok(frames) => { + let sub8 = crate::decode::sub8_split_hits() - sub8_before; + sub8_total += sub8; + let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { + assert!( + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, + "{NAME}: {arm} frame {i} does not match ffmpeg" + ); + frames_compared += 1; + } + eprintln!( + "{NAME}: {arm} intrabc_frames={intrabc_frames} sub8_leaves={sub8} \ + DECODED {} frame(s) exact", + frames.len() + ); + } + Err(e) => { + let msg = e.to_string(); + assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + if msg.contains("a sub-8x8 leaf that uses intrabc") { + reached += 1; + } + sub8_total += crate::decode::sub8_split_hits() - sub8_before; + eprintln!( + "{NAME}: {arm} intrabc_frames={intrabc_frames} REFUSED: {e}" + ); + } + } + } + eprintln!( + "{NAME}: {premise_arms}/2 arm(s) keep allow_intrabc, {sub8_total} sub-8 leaf/leaves \ + decoded, {reached} reach the refusal, {frames_compared} frame(s) exact" + ); + assert!( + premise_arms > 0, + "{NAME}: census is vacuous -- no arm kept allow_intrabc, so the refusal's own \ + premise was never within reach" + ); + assert!( + sub8_total > 0, + "{NAME}: census is vacuous -- no sub-8 leaf was decoded at all, so the \ + `use_intrabc` symbol this refusal guards was never read" + ); + } + + /// lane-t900 r33, CENSUS for "an intrabc block whose var-tx tree resolved + /// to mixed leaf transform sizes" -- the residue lane-t900 r32 left when + /// it lifted the intrabc `TX_MODE_SELECT` refusal. + /// + /// The tree is read in full, but the luma reconstruct loop it feeds is a + /// UNIFORM grid of one square transform, so a tree that split unevenly + /// would be reconstructed at the wrong stride. This census sweeps the + /// quantiser across the exact-repetition recipe that reaches the tree at + /// all and requires the tree to actually be read (`intrabc_vartx_hits`) + /// before reading anything into the refusal firing 0 times. + #[test] + fn an_intrabc_vartx_census_measures_the_mixed_leaf_refusal() { + const NAME: &str = "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal"; + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let (width, height) = (256usize, 192usize); + let _guard = lock_gate_counters(); + let (mut vartx_total, mut reached, mut frames_compared) = (0usize, 0u32, 0u32); + for cq in ["20", "30", "45", "55"] { + let arm = format!("vartx cq={cq}"); + let stream = + screen_intrabc_stream("smptebars=size=128x96:rate=25", cq, "1", true, true); + let (select, premise) = tx_select_and_intrabc_frames(&stream); + crate::decode::reset_intrabc_vartx_hits(); + match decode_stream(&stream) { + Ok(frames) => { + let vartx = crate::decode::intrabc_vartx_hits(); + vartx_total += vartx; + let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count"); + for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() { + assert!( + ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v, + "{NAME}: {arm} frame {i} does not match ffmpeg" + ); + frames_compared += 1; + } + eprintln!( + "{NAME}: {arm} select={select} premise={premise} vartx_blocks={vartx} \ + DECODED {} frame(s) exact", + frames.len() + ); + } + Err(e) => { + let msg = e.to_string(); + assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}"); + vartx_total += crate::decode::intrabc_vartx_hits(); + if msg.contains("mixed leaf transform sizes") { + reached += 1; + } + eprintln!("{NAME}: {arm} select={select} premise={premise} REFUSED: {e}"); + } + } + } + eprintln!( + "{NAME}: {vartx_total} intrabc block(s) read the var-tx tree, {reached} resolved to \ + mixed leaves, {frames_compared} frame(s) exact" + ); + assert!( + vartx_total > 0, + "{NAME}: census is vacuous -- no intrabc block read the var-tx tree at all" + ); + assert_eq!( + reached, 0, + "{NAME}: an intrabc var-tx tree resolved to mixed leaves -- the refusal is a live \ + capability gap and needs a pinned witness, not this census" + ); + } + /// How many frames of `stream` carry `tx_mode == Select`, and how many of /// those also keep `allow_intrabc` -- the frame-level premise of the /// refusal "an intrabc block under TxMode::Select", read out of the