forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-t900' (89195e5c): refusal inventory closed, 35 of 35 proven by enumeration, census or negative gate; dead palette guards deleted; sb128 intrabc gap pinned with a waiting witness

Browse files at this commit

e5de66d58da2c9cc916b799b4fe1dcb5ab77413aAhmet Kaan GümüşParent: f5fdee3da8c1a6
crates/ec-av1/src/decode.rsmodified+0 -10
@@ -7088,11 +7088,6 @@ fn read_intra_mode_rect(
70887088 let use_palette_y =
70897089 mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
70907090 if use_palette_y {
7091- if palette.is_none() {
7092- return Err(unsupported(
7093- "a block that actually uses a palette (Y) -- reconstruction is out of scope",
7094- ));
7095- }
70967091 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
70977092 let colors = read_palette_colors_y(dec, n, cache, fctx);
70987093 palette_y_pending = Some((n, colors));
@@ -11166,11 +11161,6 @@ fn read_intra_mode(
1116611161 eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32);
1116711162 }
1116811163 if use_palette_y {
11169- if palette.is_none() {
11170- return Err(unsupported(
11171- "a block that actually uses a palette (Y) -- reconstruction is out of scope",
11172- ));
11173- }
1117411164 let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
1117511165 if trace {
1117611166 let (rng, _) = dec.debug_state();
crates/ec-av1/src/refusal_inventory.rsmodified+337 -4
@@ -50,10 +50,12 @@ const REFUSALS: &[&str] = &[
5050 // 8x8 LEAF inside an inter frame (this round, gate
5151 // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`),
5252 // which is why the (UV) string is gone from the decoder entirely -- the
53- // leaf was its only site. The (Y) one survives ONLY as the defensive
54- // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`;
55- // every caller now passes a real ctx/cache pair, so no stream reaches it.
56- "a block that actually uses a palette (Y) -- reconstruction is out of scope",
53+ // leaf was its only site. The (Y) one survived as the defensive
54+ // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`
55+ // until lane-t900 r33 DELETED both arms: all eight call sites hand the
56+ // reader a real ctx/cache pair, so no stream could reach either (audit
57+ // `every_read_intra_mode_call_site_hands_the_reader_a_palette_cache`,
58+ // which keeps that invariant now the refusal is gone).
5759 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
5860 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
5961 "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)] = &[
349351 // `real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact`
350352 // decodes both lifted shapes byte-exact vs ffmpeg, and the census now
351353 // asserts none of the three strings comes back.
354+ // lane-t900 r33, enumeration: the five callers of `decode_rect_split` pass
355+ // the ten rect footprints with `8 <= min` and `max <= 64`, and every one of
356+ // them has a chroma table and -- at every tx depth -- a luma arm. The two
357+ // shape classes that would miss one (a 128-sided half, a sub-8 strip) have
358+ // readers that are not among those callers.
359+ (
360+ "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
361+ "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table",
362+ ),
363+ (
364+ "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
365+ "every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table",
366+ ),
367+ // lane-t900 r33, enumeration: each of the four symbols this guard tests is
368+ // read under a size gate that no 128-pixel side passes (the call site's
369+ // literal `cfl=false`, `filter_intra_size_class_rect`'s table, and
370+ // `palette_bsize_ctx_wh`'s bound).
371+ (
372+ "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)",
373+ "no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol",
374+ ),
375+ // lane-t900 r33, WITNESS of a capability gap: the refusal is REACHED by
376+ // real `--tune-content=screen --enable-palette=1` streams, counted
377+ // (`palette_sb_strip_hits`) and hard-asserted non-zero by its gate, which
378+ // also decodes the arms that do not reach it pixel-exact. lane-pal8 r1
379+ // measured the lift and it mismatches whole-frame, so the string names a
380+ // real shape a real encoder writes -- an open capability, not a claim.
381+ (
382+ "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
383+ "a_real_aomenc_palette_stream_with_8x8_leaves_decodes_pixel_exact",
384+ ),
385+ // lane-t900 r33, CENSUS (reached -- a pinned capability gap): all four
386+ // `--sb-size=128` exact-repetition screen arms code
387+ // `use_128x128_superblock && allow_intrabc`, and every one of them reaches
388+ // this refusal by name. The lift is a decode.rs change (the block-vector
389+ // delay of `av1_is_dv_valid` is superblock-sized) with a waiting witness,
390+ // `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` (ignored).
391+ (
392+ "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)",
393+ "an_sb128_screen_census_measures_the_sb128_intrabc_refusal",
394+ ),
395+ // lane-t900 r33, CENSUS: the `use_intrabc` symbol IS read at the sub-8
396+ // reader for every sub-8x8 leaf of an `allow_intrabc` frame, and over the
397+ // `--min-partition-size=4` exact-repetition screen arms every such symbol
398+ // came back 0 while the frames decode pixel-exact.
399+ (
400+ "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
401+ "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal",
402+ ),
403+ // lane-t900 r33, CENSUS: four quantisers of the recipe that reaches the
404+ // intrabc var-tx tree at all read it for 5 blocks in total, every one of
405+ // which resolved to a UNIFORM leaf size, with the frames pixel-exact.
406+ (
407+ "an intrabc block whose var-tx tree resolved to mixed leaf transform sizes",
408+ "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal",
409+ ),
352410 (
353411 "a reference picture whose height does not match this frame's own true size",
354412 "an_inter_frame_shorter_than_its_reference_is_refused_by_name",
@@ -1045,6 +1103,281 @@ mod tests {
10451103 }
10461104 }
10471105
1106+ /// lane-t900 r33, ENUMERATION for the two [`decode_rect_split`] refusals
1107+ /// ("a coded HORZ/VERT strip whose chroma transform has no rect
1108+ /// coefficient tables here" and "a split intra strip whose transform unit
1109+ /// is {tx_w}x{tx_h}").
1110+ ///
1111+ /// Both guard shape lookups inside one function, so the proof is one
1112+ /// enumeration: the footprints that function is CALLED with, walked
1113+ /// through `depth_to_tx_wh` at every depth, against the two `match`
1114+ /// tables read out of `decode.rs` itself (class
1115+ /// `table-and-reader-move-together` -- a table edit invalidates this test
1116+ /// rather than sneaking past it).
1117+ ///
1118+ /// The footprint domain is the five callers' own: `decode_block_rect`
1119+ /// (32-level 2:1), `decode_block_rect4` (32-level 1:4), `decode_leaf_rect`
1120+ /// (16-level 2:1), `decode_block_rect64` (64-level 2:1 and 1:4) and
1121+ /// `decode_intra_rect_in_inter`, whose reachable shapes are the ten
1122+ /// rectangular census shapes with `8 <= min` and `max <= 64` (already
1123+ /// pinned by `every_intra_in_inter_shape_the_census_lists_has_a_size_group_row`).
1124+ /// The two shape classes that would MISS a table -- a 128-sided half
1125+ /// (chroma 64x32) and a sub-8 strip (16x4 -> chroma 8x2) -- are excluded
1126+ /// structurally: their readers, `decode_block_128rect` and
1127+ /// `decode_rect4_16_strip`, are not among the callers, which this test
1128+ /// asserts by locating every `decode_rect_split(` call in its enclosing
1129+ /// function.
1130+ #[test]
1131+ fn every_rect_strip_shape_the_split_path_codes_has_a_luma_and_chroma_table() {
1132+ let src = include_str!("decode.rs");
1133+
1134+ // (1) The caller set. Each call's enclosing function is the last
1135+ // top-level `fn` before it.
1136+ let fn_starts: Vec<(usize, String)> = src
1137+ .match_indices("\nfn ")
1138+ .map(|(i, _)| {
1139+ let rest = &src[i + 4..];
1140+ let name = rest[..rest.find('(').unwrap_or(0)].to_string();
1141+ (i, name)
1142+ })
1143+ .collect();
1144+ let mut callers: BTreeSet<String> = BTreeSet::new();
1145+ for (at, _) in src.match_indices("decode_rect_split(") {
1146+ let enclosing = fn_starts
1147+ .iter()
1148+ .filter(|(i, _)| *i < at)
1149+ .next_back()
1150+ .expect("a decode_rect_split call outside any function");
1151+ if enclosing.1 != "decode_rect_split" {
1152+ callers.insert(enclosing.1.clone());
1153+ }
1154+ }
1155+ let expected: BTreeSet<String> = [
1156+ "decode_block_rect",
1157+ "decode_block_rect4",
1158+ "decode_block_rect64",
1159+ "decode_intra_rect_in_inter",
1160+ "decode_leaf_rect",
1161+ ]
1162+ .iter()
1163+ .map(|s| s.to_string())
1164+ .collect();
1165+ assert_eq!(
1166+ callers, expected,
1167+ "the set of functions that call decode_rect_split changed -- re-derive the \
1168+ footprint domain below from the new caller (a 128-sided or sub-8 caller makes \
1169+ both refusals live)"
1170+ );
1171+
1172+ // (2) The walk, asserted against its own source before it is applied.
1173+ const WALK: &str = " let (mut w, mut h) = (bw.min(64), bh.min(64));\n \
1174+ for _ in 0..depth {\n match w.cmp(&h) {\n \
1175+ std::cmp::Ordering::Greater => w /= 2,\n \
1176+ std::cmp::Ordering::Less => h /= 2,\n \
1177+ std::cmp::Ordering::Equal => {\n w /= 2;\n \
1178+ h /= 2;\n }\n }\n }";
1179+ assert_eq!(
1180+ src.matches(WALK).count(),
1181+ 1,
1182+ "depth_to_tx_wh's walk is no longer spelled the way this enumeration mirrors it"
1183+ );
1184+ let depth_to_tx_wh = |bw: usize, bh: usize, depth: usize| {
1185+ let (mut w, mut h) = (bw.min(64), bh.min(64));
1186+ for _ in 0..depth {
1187+ match w.cmp(&h) {
1188+ std::cmp::Ordering::Greater => w /= 2,
1189+ std::cmp::Ordering::Less => h /= 2,
1190+ std::cmp::Ordering::Equal => {
1191+ w /= 2;
1192+ h /= 2;
1193+ }
1194+ }
1195+ }
1196+ (w, h)
1197+ };
1198+
1199+ // (3) The two tables, read out of decode_rect_split's own text: every
1200+ // `(w, h) =>` / `(w, h) |` match arm head between the table's `let`
1201+ // and the guard that follows it.
1202+ let body_at = src.find("fn decode_rect_split(").expect("decode_rect_split is gone");
1203+ let body = &src[body_at..];
1204+ let slice = |from: &str, to: &str| -> &str {
1205+ let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split"));
1206+ let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split"));
1207+ &body[a..a + b]
1208+ };
1209+ let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> {
1210+ let mut out = BTreeSet::new();
1211+ let bytes = text.as_bytes();
1212+ for (i, _) in text.match_indices('(') {
1213+ let mut j = i + 1;
1214+ let mut w = 0usize;
1215+ while j < bytes.len() && bytes[j].is_ascii_digit() {
1216+ w = w * 10 + usize::from(bytes[j] - b'0');
1217+ j += 1;
1218+ }
1219+ if j == i + 1 || !text[j..].starts_with(", ") {
1220+ continue;
1221+ }
1222+ j += 2;
1223+ let mut h = 0usize;
1224+ let start_h = j;
1225+ while j < bytes.len() && bytes[j].is_ascii_digit() {
1226+ h = h * 10 + usize::from(bytes[j] - b'0');
1227+ j += 1;
1228+ }
1229+ if j == start_h || !text[j..].starts_with(')') {
1230+ continue;
1231+ }
1232+ // Only an arm HEAD counts, never a `(32, 8)` inside prose.
1233+ let after = text[j + 1..].trim_start();
1234+ if after.starts_with("=>") || after.starts_with('|') {
1235+ out.insert((w, h));
1236+ }
1237+ }
1238+ out
1239+ };
1240+ let chroma = arm_shapes(slice("let chroma: Option<(TxbSet", "if !m.skip {"));
1241+ let luma = arm_shapes(slice("let luma_rect: Option<(TxbSet", "no luma \\"));
1242+ assert!(
1243+ chroma.len() >= 6 && luma.len() >= 6,
1244+ "the tables parsed to {} chroma / {} luma shapes -- the parse, not the decoder, \
1245+ is what this would be measuring",
1246+ chroma.len(),
1247+ luma.len()
1248+ );
1249+
1250+ // (4) The enumeration itself.
1251+ let mut checked = 0u32;
1252+ for wl in 3..=6u32 {
1253+ for hl in 3..=6u32 {
1254+ let (bw, bh) = (1usize << wl, 1usize << hl);
1255+ let ratio = bw.max(bh) / bw.min(bh);
1256+ if ratio != 2 && ratio != 4 {
1257+ continue;
1258+ }
1259+ assert!(
1260+ chroma.contains(&(bw / 2, bh / 2)),
1261+ "a {bw}x{bh} strip's {}x{} chroma transform has no rect table -- the \
1262+ chroma refusal is LIVE for a shape a caller codes",
1263+ bw / 2,
1264+ bh / 2
1265+ );
1266+ // Every depth: once the walk reaches a square it stays square,
1267+ // so this covers any tx_depth a header can code.
1268+ for depth in 1..=4 {
1269+ let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
1270+ assert!(
1271+ tx_w == tx_h || luma.contains(&(tx_w, tx_h)),
1272+ "a {bw}x{bh} strip at depth {depth} resolves to a {tx_w}x{tx_h} \
1273+ transform unit, which has no luma arm -- that refusal is LIVE"
1274+ );
1275+ checked += 1;
1276+ }
1277+ }
1278+ }
1279+ assert_eq!(checked, 40, "the strip domain is not the ten rect shapes x four depths");
1280+ }
1281+
1282+ /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a
1283+ /// 128-root HORZ/VERT intra block".
1284+ ///
1285+ /// The guard fires when any of four symbols came back `Some` from
1286+ /// `read_intra_mode_rect` on a 128x64/64x128 half. Each of the four is
1287+ /// read under a size gate, and none of those gates admits a 128-pixel
1288+ /// side:
1289+ ///
1290+ /// * `cfl_alpha` -- read only under the `cfl` PARAMETER, and the 128-root
1291+ /// call site passes the literal `false`;
1292+ /// * `use_filter_intra` -- read only when `filter_intra_size_class_rect`
1293+ /// is `Some`, whose table has no arm with a 128 side and whose square
1294+ /// fallback (`filter_intra_size_class`) caps at 32
1295+ /// (`av1_filter_intra_allowed_bsize`);
1296+ /// * `palette_y_mode` / `palette_uv_mode` -- both inside the
1297+ /// `palette_bsize_ctx_wh` block already enumerated by
1298+ /// [`no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax`].
1299+ #[test]
1300+ fn no_128_root_half_reads_a_cfl_filter_intra_or_palette_symbol() {
1301+ let src = include_str!("decode.rs");
1302+ // The 128-root call site's own `cfl` argument, with the comment that
1303+ // explains it -- the two lines are matched together so that reordering
1304+ // the arguments cannot leave this test pointing at another `false`.
1305+ const CFL_OFF_AT_128: &str = " // `is_cfl_allowed` caps CFL at 32x32: `uv_mode` comes off the\n \
1306+ // 13-symbol no-CFL CDF here, never the 14-symbol one.\n false,";
1307+ assert_eq!(
1308+ src.matches(CFL_OFF_AT_128).count(),
1309+ 1,
1310+ "the 128-root call site no longer passes cfl=false -- a CfL alpha can reach the \
1311+ guard, so this enumeration proves nothing"
1312+ );
1313+ // The filter-intra table: every arm head, plus the square fallback.
1314+ let fi_at = src
1315+ .find("fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> {")
1316+ .expect("filter_intra_size_class_rect is gone");
1317+ let fi_body = &src[fi_at..fi_at + src[fi_at..].find("\n}\n").expect("unterminated fn")];
1318+ assert!(
1319+ !fi_body.contains("128"),
1320+ "filter_intra_size_class_rect grew an arm naming a 128 side"
1321+ );
1322+ assert!(
1323+ fi_body.contains("_ if bw == bh => filter_intra_size_class(bw),")
1324+ && fi_body.contains("_ => None,"),
1325+ "filter_intra_size_class_rect's fallbacks changed shape"
1326+ );
1327+ let sq_at = src
1328+ .find("fn filter_intra_size_class(side: usize) -> Option<usize> {")
1329+ .expect("filter_intra_size_class is gone");
1330+ let sq_body = &src[sq_at..sq_at + src[sq_at..].find("\n}\n").expect("unterminated fn")];
1331+ assert!(
1332+ !sq_body.contains("128") && !sq_body.contains("64"),
1333+ "filter_intra_size_class admits a side above 32 -- av1_filter_intra_allowed_bsize \
1334+ does not, so re-derive this proof"
1335+ );
1336+ // And palette, at the two shapes the refusal names.
1337+ assert!(
1338+ src.contains("if bw > 64 || bh > 64 || bw * bh < 64 {"),
1339+ "palette_bsize_ctx_wh's bound moved -- see \
1340+ no_block_footprint_with_a_128_pixel_side_can_carry_palette_syntax"
1341+ );
1342+ for (bw, bh) in [(128usize, 64usize), (64, 128)] {
1343+ assert!(bw > 64 || bh > 64, "{bw}x{bh} is not a 128-root half");
1344+ }
1345+ }
1346+
1347+ /// lane-t900 r33, STRUCTURAL AUDIT behind the DELETION of "a block that
1348+ /// actually uses a palette (Y) -- reconstruction is out of scope".
1349+ ///
1350+ /// That refusal was the `palette.is_none()` arm of `read_intra_mode` and
1351+ /// `read_intra_mode_rect`: a stream reached it only if a CALLER read the
1352+ /// palette syntax without handing the reader a neighbour ctx/cache pair.
1353+ /// Every one of the eight call sites passes `Some((palette_ctx,
1354+ /// &palette_cache))`, so no stream could reach either arm and both are
1355+ /// gone from `decode.rs`. This test keeps the invariant the deletion rests
1356+ /// on: a future caller that passes `None` fails here rather than decoding
1357+ /// a palette off an empty colour cache.
1358+ #[test]
1359+ fn every_read_intra_mode_call_site_hands_the_reader_a_palette_cache() {
1360+ let src = include_str!("decode.rs");
1361+ let mut sites = 0u32;
1362+ for name in ["read_intra_mode(", "read_intra_mode_rect("] {
1363+ for (at, _) in src.match_indices(name) {
1364+ // The definition itself, not a call.
1365+ if src[..at].ends_with("fn ") {
1366+ continue;
1367+ }
1368+ sites += 1;
1369+ let window = &src[at..(at + 4096).min(src.len())];
1370+ let end = window.find("fctx,\n").unwrap_or(window.len());
1371+ assert!(
1372+ window[..end].contains("Some((palette_ctx, &palette_cache)),"),
1373+ "a {name} call site does not hand the reader a palette ctx/cache pair -- \
1374+ the deleted `palette.is_none()` refusal was its guard"
1375+ );
1376+ }
1377+ }
1378+ assert_eq!(sites, 8, "the call-site audit found {sites} sites, not the 8 it enumerated");
1379+ }
1380+
10481381 /// Every entry of [`PROVEN`] must still name a live refusal and a test
10491382 /// that exists, and the count it prints is the inventory's numerator.
10501383 #[test]
crates/ec-av1/src/stream.rsmodified+334 -0
@@ -4585,6 +4585,20 @@ mod tests {
45854585 /// and 1:4 partitions off so an intrabc block lands on a SQUARE block
45864586 /// instead of stopping on the rect-strip intrabc refusal first.
45874587 fn screen_intrabc_stream(src: &str, cq: &str, txs: &str, tiled: bool, square_only: bool) -> Vec<u8> {
4588+ screen_intrabc_stream_with(src, cq, txs, tiled, square_only, &[])
4589+ }
4590+
4591+ /// [`screen_intrabc_stream`] with per-arm flags appended AFTER the base
4592+ /// recipe -- aomenc keeps the LAST occurrence of a repeated flag, so an
4593+ /// arm can override `--sb-size` / `--min-partition-size` here.
4594+ fn screen_intrabc_stream_with(
4595+ src: &str,
4596+ cq: &str,
4597+ txs: &str,
4598+ tiled: bool,
4599+ square_only: bool,
4600+ extra: &[&str],
4601+ ) -> Vec<u8> {
45884602 let mut ff = Command::new("ffmpeg");
45894603 ff.args(["-v", "error", "-f", "lavfi", "-i", src, "-t", "0.2"]);
45904604 if tiled {
@@ -4626,6 +4640,7 @@ mod tests {
46264640 } else {
46274641 &[][..]
46284642 })
4643+ .args(extra)
46294644 .args(["--obu", "-o", "-", "-"])
46304645 .stdin(Stdio::piped())
46314646 .stdout(Stdio::piped())
@@ -4651,6 +4666,325 @@ mod tests {
46514666 enc.stdout
46524667 }
46534668
4669+ /// The sequence header's `use_128x128_superblock`, and how many frames of
4670+ /// `stream` keep `allow_intrabc` -- the two bits the refusal "intrabc
4671+ /// under a 128x128 superblock" is the conjunction of, read out of the
4672+ /// headers rather than assumed from the flags handed to the encoder.
4673+ fn sb128_and_intrabc_frames(stream: &[u8]) -> (bool, u32) {
4674+ let mut parser = Av1Parser::new();
4675+ let mut pos = 0usize;
4676+ let (mut sb128, mut intrabc) = (false, 0u32);
4677+ while pos < stream.len() {
4678+ let Ok(obu) = parser.parse_obu(&stream[pos..]) else {
4679+ break;
4680+ };
4681+ pos += obu.total_size.max(1);
4682+ if let Some(seq) = parser.sequence_header() {
4683+ sb128 = seq.use_128x128_superblock;
4684+ }
4685+ let header = match &obu.kind {
4686+ ObuKind::Frame(h, _) => Some(&**h),
4687+ ObuKind::FrameHeader(h) => Some(&**h),
4688+ _ => None,
4689+ };
4690+ if header.is_some_and(|h| h.allow_intrabc) {
4691+ intrabc += 1;
4692+ }
4693+ }
4694+ (sb128, intrabc)
4695+ }
4696+
4697+ /// lane-t900 r33, CENSUS for "intrabc under a 128x128 superblock".
4698+ ///
4699+ /// Unlike every other refusal in the inventory this one is decided in the
4700+ /// FRAME HEADER, before a single block symbol: `use_128x128_superblock &&
4701+ /// allow_intrabc`. So the census question is only whether a real encoder
4702+ /// writes that conjunction -- if it does, the refusal is a capability gap
4703+ /// (this decoder hardcodes the block-vector delay of `av1_is_dv_valid` to
4704+ /// a 64-px superblock) and the arm that reaches it is pinned here; if no
4705+ /// arm does, the string is measured against the domain instead of assumed.
4706+ ///
4707+ /// The four arms are the exact-repetition recipe that is the ONLY shape
4708+ /// known to keep `allow_intrabc` past libaom's own RD (lane-t900 r31: on
4709+ /// non-repeating content, `--enable-tx-size-search=1` makes RD drop
4710+ /// intrabc and libaom clears the bit again), with `--sb-size=128` and both
4711+ /// tx-size-search settings over two quantisers.
4712+ #[test]
4713+ fn an_sb128_screen_census_measures_the_sb128_intrabc_refusal() {
4714+ const NAME: &str = "an_sb128_screen_census_measures_the_sb128_intrabc_refusal";
4715+ if !have_ffmpeg() || !have_aomenc() {
4716+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
4717+ return;
4718+ }
4719+ let (width, height) = (256usize, 192usize);
4720+ let (mut premise_arms, mut reached, mut decoded_arms, mut frames_compared) =
4721+ (0u32, 0u32, 0u32, 0u32);
4722+ for txs in ["0", "1"] {
4723+ for cq in ["30", "45"] {
4724+ let arm = format!("sb128 txs={txs} cq={cq}");
4725+ let stream = screen_intrabc_stream_with(
4726+ "smptebars=size=128x96:rate=25",
4727+ cq,
4728+ txs,
4729+ true,
4730+ true,
4731+ &["--sb-size=128"],
4732+ );
4733+ let (sb128, intrabc_frames) = sb128_and_intrabc_frames(&stream);
4734+ assert!(sb128, "{NAME}: {arm}: aomenc ignored --sb-size=128");
4735+ if intrabc_frames > 0 {
4736+ premise_arms += 1;
4737+ }
4738+ match decode_stream(&stream) {
4739+ Ok(frames) => {
4740+ decoded_arms += 1;
4741+ let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len());
4742+ assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count");
4743+ for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() {
4744+ assert!(
4745+ ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v,
4746+ "{NAME}: {arm} frame {i} does not match ffmpeg"
4747+ );
4748+ frames_compared += 1;
4749+ }
4750+ eprintln!(
4751+ "{NAME}: {arm} sb128={sb128} intrabc_frames={intrabc_frames} \
4752+ DECODED {} frame(s) exact",
4753+ frames.len()
4754+ );
4755+ }
4756+ Err(e) => {
4757+ let msg = e.to_string();
4758+ assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}");
4759+ if msg.contains("intrabc under a 128x128 superblock") {
4760+ reached += 1;
4761+ }
4762+ eprintln!(
4763+ "{NAME}: {arm} sb128={sb128} intrabc_frames={intrabc_frames} \
4764+ REFUSED: {e}"
4765+ );
4766+ }
4767+ }
4768+ }
4769+ }
4770+ eprintln!(
4771+ "{NAME}: {premise_arms}/4 arm(s) code allow_intrabc under a 128x128 superblock, \
4772+ {reached} reach the refusal, {decoded_arms} arm(s) decoded \
4773+ ({frames_compared} frames exact)"
4774+ );
4775+ assert!(
4776+ premise_arms + decoded_arms > 0,
4777+ "{NAME}: census is vacuous -- no arm produced a decodable or premise-carrying stream"
4778+ );
4779+ assert_eq!(
4780+ reached, premise_arms,
4781+ "{NAME}: the refusal is the CONJUNCTION of the two header bits, so every arm \
4782+ carrying it must reach the refusal and no other arm may"
4783+ );
4784+ }
4785+
4786+ /// lane-t900 r33, the WAITING witness for the capability gap
4787+ /// [`an_sb128_screen_census_measures_the_sb128_intrabc_refusal`] pins:
4788+ /// FIRST BAD is `--sb-size=128 --tune-content=screen --enable-intrabc=1
4789+ /// --enable-tx-size-search=0 --cq-level=30` on a 2x2 tiling of a 128x96
4790+ /// bar pattern (256x192, 8-bit, `--cpu-used=0 --min-partition-size=8
4791+ /// --max-partition-size=32 --enable-rect-partitions=0
4792+ /// --enable-1to4-partitions=0`) -- all four arms of the census code
4793+ /// `use_128x128_superblock && allow_intrabc`, so the refusal names a
4794+ /// configuration real aomenc writes at its FIRST attempt, not a corner.
4795+ ///
4796+ /// Lifting it is a `decode.rs` change this lane is not allowed to make:
4797+ /// `av1_is_dv_valid` derives the block-vector delay (`sb_size` wide
4798+ /// `INTRABC_DELAY_PIXELS`, the wavefront the valid-DV region is offset
4799+ /// by) from the SUPERBLOCK SIZE, which this decoder hardcodes to 64, so
4800+ /// every DV bound and every intrabc source fetch under a 128 superblock
4801+ /// is computed against the wrong wavefront. Ignored until that lands.
4802+ #[test]
4803+ #[ignore = "capability gap: intrabc's block-vector delay is hardcoded to a 64-px superblock"]
4804+ fn an_sb128_screen_stream_with_intrabc_decodes_pixel_exact() {
4805+ const NAME: &str = "an_sb128_screen_stream_with_intrabc_decodes_pixel_exact";
4806+ if !have_ffmpeg() || !have_aomenc() {
4807+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
4808+ return;
4809+ }
4810+ let (width, height) = (256usize, 192usize);
4811+ let stream = screen_intrabc_stream_with(
4812+ "smptebars=size=128x96:rate=25",
4813+ "30",
4814+ "0",
4815+ true,
4816+ true,
4817+ &["--sb-size=128"],
4818+ );
4819+ let (sb128, intrabc_frames) = sb128_and_intrabc_frames(&stream);
4820+ assert!(sb128 && intrabc_frames > 0, "{NAME}: the first-bad recipe no longer codes it");
4821+ let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: {e}"));
4822+ let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len());
4823+ assert_eq!(frames.len(), theirs.len(), "{NAME}: frame count");
4824+ for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() {
4825+ assert!(
4826+ ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v,
4827+ "{NAME}: frame {i} does not match ffmpeg"
4828+ );
4829+ }
4830+ }
4831+
4832+ /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc".
4833+ ///
4834+ /// The `use_intrabc` symbol IS read at that reader for every sub-8x8 leaf
4835+ /// of an `allow_intrabc` frame, so arrival is provable rather than
4836+ /// assumed: the arms below force 4x4 leaves (`--min-partition-size=4`) on
4837+ /// the exact-repetition screen content that keeps `allow_intrabc`, and the
4838+ /// gate requires both counters -- `allow_intrabc` frames and decoded sub-8
4839+ /// leaves -- to be non-zero before it reads anything into the refusal
4840+ /// firing 0 times (class `gate-blind-to-feature`).
4841+ #[test]
4842+ fn a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal() {
4843+ const NAME: &str = "a_sub8_leaf_census_over_intrabc_screen_streams_measures_the_sub8_refusal";
4844+ if !have_ffmpeg() || !have_aomenc() {
4845+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
4846+ return;
4847+ }
4848+ let (width, height) = (256usize, 192usize);
4849+ let _guard = lock_gate_counters();
4850+ let (mut premise_arms, mut reached, mut sub8_total, mut frames_compared) =
4851+ (0u32, 0u32, 0usize, 0u32);
4852+ for cq in ["30", "45"] {
4853+ let arm = format!("sub8 cq={cq}");
4854+ let stream = screen_intrabc_stream_with(
4855+ "smptebars=size=128x96:rate=25",
4856+ cq,
4857+ "0",
4858+ true,
4859+ true,
4860+ &["--min-partition-size=4"],
4861+ );
4862+ let (_, intrabc_frames) = sb128_and_intrabc_frames(&stream);
4863+ if intrabc_frames > 0 {
4864+ premise_arms += 1;
4865+ }
4866+ // No reset for this counter, so measure the delta (the gate lock
4867+ // above keeps another gate's decode out of it).
4868+ let sub8_before = crate::decode::sub8_split_hits();
4869+ match decode_stream(&stream) {
4870+ Ok(frames) => {
4871+ let sub8 = crate::decode::sub8_split_hits() - sub8_before;
4872+ sub8_total += sub8;
4873+ let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len());
4874+ assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count");
4875+ for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() {
4876+ assert!(
4877+ ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v,
4878+ "{NAME}: {arm} frame {i} does not match ffmpeg"
4879+ );
4880+ frames_compared += 1;
4881+ }
4882+ eprintln!(
4883+ "{NAME}: {arm} intrabc_frames={intrabc_frames} sub8_leaves={sub8} \
4884+ DECODED {} frame(s) exact",
4885+ frames.len()
4886+ );
4887+ }
4888+ Err(e) => {
4889+ let msg = e.to_string();
4890+ assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}");
4891+ if msg.contains("a sub-8x8 leaf that uses intrabc") {
4892+ reached += 1;
4893+ }
4894+ sub8_total += crate::decode::sub8_split_hits() - sub8_before;
4895+ eprintln!(
4896+ "{NAME}: {arm} intrabc_frames={intrabc_frames} REFUSED: {e}"
4897+ );
4898+ }
4899+ }
4900+ }
4901+ eprintln!(
4902+ "{NAME}: {premise_arms}/2 arm(s) keep allow_intrabc, {sub8_total} sub-8 leaf/leaves \
4903+ decoded, {reached} reach the refusal, {frames_compared} frame(s) exact"
4904+ );
4905+ assert!(
4906+ premise_arms > 0,
4907+ "{NAME}: census is vacuous -- no arm kept allow_intrabc, so the refusal's own \
4908+ premise was never within reach"
4909+ );
4910+ assert!(
4911+ sub8_total > 0,
4912+ "{NAME}: census is vacuous -- no sub-8 leaf was decoded at all, so the \
4913+ `use_intrabc` symbol this refusal guards was never read"
4914+ );
4915+ }
4916+
4917+ /// lane-t900 r33, CENSUS for "an intrabc block whose var-tx tree resolved
4918+ /// to mixed leaf transform sizes" -- the residue lane-t900 r32 left when
4919+ /// it lifted the intrabc `TX_MODE_SELECT` refusal.
4920+ ///
4921+ /// The tree is read in full, but the luma reconstruct loop it feeds is a
4922+ /// UNIFORM grid of one square transform, so a tree that split unevenly
4923+ /// would be reconstructed at the wrong stride. This census sweeps the
4924+ /// quantiser across the exact-repetition recipe that reaches the tree at
4925+ /// all and requires the tree to actually be read (`intrabc_vartx_hits`)
4926+ /// before reading anything into the refusal firing 0 times.
4927+ #[test]
4928+ fn an_intrabc_vartx_census_measures_the_mixed_leaf_refusal() {
4929+ const NAME: &str = "an_intrabc_vartx_census_measures_the_mixed_leaf_refusal";
4930+ if !have_ffmpeg() || !have_aomenc() {
4931+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
4932+ return;
4933+ }
4934+ let (width, height) = (256usize, 192usize);
4935+ let _guard = lock_gate_counters();
4936+ let (mut vartx_total, mut reached, mut frames_compared) = (0usize, 0u32, 0u32);
4937+ for cq in ["20", "30", "45", "55"] {
4938+ let arm = format!("vartx cq={cq}");
4939+ let stream =
4940+ screen_intrabc_stream("smptebars=size=128x96:rate=25", cq, "1", true, true);
4941+ let (select, premise) = tx_select_and_intrabc_frames(&stream);
4942+ crate::decode::reset_intrabc_vartx_hits();
4943+ match decode_stream(&stream) {
4944+ Ok(frames) => {
4945+ let vartx = crate::decode::intrabc_vartx_hits();
4946+ vartx_total += vartx;
4947+ let theirs = ffmpeg_decode_sequence(&stream, width, height, frames.len());
4948+ assert_eq!(frames.len(), theirs.len(), "{NAME}: {arm} frame count");
4949+ for (i, (ours, ref_frame)) in frames.iter().zip(theirs.iter()).enumerate() {
4950+ assert!(
4951+ ours.y == ref_frame.y && ours.u == ref_frame.u && ours.v == ref_frame.v,
4952+ "{NAME}: {arm} frame {i} does not match ffmpeg"
4953+ );
4954+ frames_compared += 1;
4955+ }
4956+ eprintln!(
4957+ "{NAME}: {arm} select={select} premise={premise} vartx_blocks={vartx} \
4958+ DECODED {} frame(s) exact",
4959+ frames.len()
4960+ );
4961+ }
4962+ Err(e) => {
4963+ let msg = e.to_string();
4964+ assert!(msg.contains("unsupported"), "{NAME}: {arm} decode failed: {e}");
4965+ vartx_total += crate::decode::intrabc_vartx_hits();
4966+ if msg.contains("mixed leaf transform sizes") {
4967+ reached += 1;
4968+ }
4969+ eprintln!("{NAME}: {arm} select={select} premise={premise} REFUSED: {e}");
4970+ }
4971+ }
4972+ }
4973+ eprintln!(
4974+ "{NAME}: {vartx_total} intrabc block(s) read the var-tx tree, {reached} resolved to \
4975+ mixed leaves, {frames_compared} frame(s) exact"
4976+ );
4977+ assert!(
4978+ vartx_total > 0,
4979+ "{NAME}: census is vacuous -- no intrabc block read the var-tx tree at all"
4980+ );
4981+ assert_eq!(
4982+ reached, 0,
4983+ "{NAME}: an intrabc var-tx tree resolved to mixed leaves -- the refusal is a live \
4984+ capability gap and needs a pinned witness, not this census"
4985+ );
4986+ }
4987+
46544988 /// How many frames of `stream` carry `tx_mode == Select`, and how many of
46554989 /// those also keep `allow_intrabc` -- the frame-level premise of the
46564990 /// refusal "an intrabc block under TxMode::Select", read out of the