forge
Explore
Log in

Don't you dare go Hollow

Multi-tile gates with the coding tools ON, and the films' real tiling measured

Browse files at this commit

9c8c2142f00291e2681276c0f4433ddaefd815b3Ahmet Kaan GümüşParent: 1a194e3
  • test
    • multi-tile gates with the coding tools ON, and the films' real tiling measured
Show full message
test(av1): multi-tile gates with the coding tools ON, and the films' real tiling measured

Every existing tile gate turns rect/ab partitions, tx-size search, cdef and
restoration OFF to isolate the per-tile loop -- the tool-disabled-in-every-gate
shape, under which a tile-edge defect in any of those tools is invisible.

- stream.rs: `run_multi_tile_gate` + 4 arms (2x2 grid and 4 columns, 8- and
  10-bit, intra and inter) through `decode_stream`, rect+ab partitions, default
  cdef and loop restoration on, deblocking left crossing tile boundaries. The
  parsed `tile_info` is asserted to carry the grid asked for (skipping
  `show_existing_frame` headers, which code no tile info) and `tile_hits` is
  asserted >= tiles*frames so a header claiming 4 tiles cannot pass on one
  decoded tile.
- The 8-bit 2x2 inter arm is `#[ignore]`d with an open defect documented in
  place: seed 42 mismatches in one 32x32 block at x[224..255] y[32..63] from
  frame 4 on; not cdef, not restoration, not deblocking; seeds 47/48 are exact;
  tile attribution unproven because the single-tile control refuses.
- decode_probe: prints the tiling of every frame header before decoding. Both
  of his AV1 films measure cols=1 rows=1 uniform over 181 headers each,
  confirmed independently by ffmpeg's trace_headers (tile_cols_log2=0,
  tile_rows_log2=0) -- multi-tile is NOT on the critical path for them.
- gate_coverage: 5 stale 10-bit entries deleted (global-motion and
  dist-wtd-comp were already closed by lane-cwarp and left this test red at
  main 9c35ecc; ab-partitions, rect-partitions and restoration are closed by
  the new 10-bit arms), plus a note on why tiling cannot join the
  `--enable-*` derivation.
crates/ec-av1/examples/decode_probe.rsmodified+36 -0
@@ -28,6 +28,42 @@ fn main() {
2828 std::process::exit(2);
2929 }
3030 };
31+ // lane-tiles: the tiling a real stream actually uses is a decision input
32+ // (every gate in `stream.rs` picks its own `--tile-columns`), so report it
33+ // from the frame headers before saying anything about pixels.
34+ let mut parser = ec_av1_syntax::Av1Parser::new();
35+ let mut seen: Vec<(u32, u32, bool, u32)> = Vec::new();
36+ let mut pos = 0usize;
37+ let mut frames_seen = 0usize;
38+ // OBU at a time, so one unparseable OBU late in the stream still leaves
39+ // every earlier frame header's tiling reported.
40+ while pos < data.len() {
41+ let Ok(obu) = parser.parse_obu(&data[pos..]) else {
42+ break;
43+ };
44+ pos += obu.total_size.max(1);
45+ let header = match &obu.kind {
46+ ec_av1_syntax::ObuKind::FrameHeader(h) => h,
47+ ec_av1_syntax::ObuKind::Frame(h, _) => h,
48+ _ => continue,
49+ };
50+ frames_seen += 1;
51+ let t = &header.tile_info;
52+ let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id);
53+ if !seen.contains(&entry) {
54+ seen.push(entry);
55+ }
56+ }
57+ println!("TILING: {frames_seen} frame headers parsed");
58+ for (cols, rows, uniform, ctx_id) in &seen {
59+ println!(
60+ "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}"
61+ );
62+ }
63+ if seen.is_empty() {
64+ println!("TILING: no frame header parsed");
65+ }
66+
3167 match ec_av1::stream::decode_stream(&data) {
3268 Ok(frames) if frames.is_empty() => {
3369 println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
crates/ec-av1/src/gate_coverage.rsmodified+16 -21
@@ -18,6 +18,15 @@
1818 //! feature's gate, which shrinks the derived set and fails this test until the
1919 //! list is updated -- the point being that the shrink is noticed.
2020
21+// TILING is deliberately NOT in this derivation (lane-tiles r11): the check
22+// keys on `--enable-<tool>=0/1`, and `--tile-columns=<log2>` has no such
23+// shape -- a `--tile-columns=` presence check would also read `=0` (one tile)
24+// as coverage, which is the opposite of what it would claim. It needs no
25+// entry either: 13 gates spell `--tile-columns`/`--tile-rows` with a nonzero
26+// log2 and assert the parsed `tile_info` really carries the grid, and
27+// `run_multi_tile_gate` covers a 2D grid with the coding tools ON at both
28+// bit depths.
29+
2130 /// aomenc coding tools that no real-`aomenc` gate is proven to exercise:
2231 /// switched off in every gate that names them, and on in none.
2332 ///
@@ -144,7 +153,13 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
144153 ];
145154
146155 #[cfg(test)]
147-const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
156+const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit compound-global-warp gate closed `enable-global-motion`
157+ // and `enable-dist-wtd-comp` at 10 bits without deleting their entries here,
158+ // so this list was already stale (and this test already red) at main 9c35ecc;
159+ // lane-tiles r11's multi-tile 10-bit gates then closed `enable-ab-partitions`,
160+ // `enable-rect-partitions` and `enable-restoration` at 10 bits. All five
161+ // deleted together.
162+
148163 // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the
149164 // pixel filters and the intra tool set off. Every entry the 8-bit list
150165 // carries is a hole here too; the seven extra ones below are tools an
@@ -154,10 +169,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
154169 "enable-1to4-partitions",
155170 "hole at both depths, see the 8-bit list",
156171 ),
157- (
158- "enable-ab-partitions",
159- "8-bit only: no 10-bit gate enables AB partitions",
160- ),
161172 (
162173 "enable-angle-delta",
163174 "hole at both depths, see the 8-bit list",
@@ -166,10 +177,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
166177 "enable-cfl-intra",
167178 "hole at both depths, see the 8-bit list",
168179 ),
169- (
170- "enable-dist-wtd-comp",
171- "hole at both depths, see the 8-bit list",
172- ),
173180 (
174181 "enable-dual-filter",
175182 "hole at both depths, see the 8-bit list",
@@ -182,10 +189,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
182189 "enable-flip-idtx",
183190 "hole at both depths, see the 8-bit list",
184191 ),
185- (
186- "enable-global-motion",
187- "hole at both depths, see the 8-bit list",
188- ),
189192 (
190193 "enable-intra-edge-filter",
191194 "8-bit only: the 10-bit intra path never runs the edge filter",
@@ -195,19 +198,11 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
195198 "enable-paeth-intra",
196199 "8-bit only: no 10-bit gate enables Paeth",
197200 ),
198- (
199- "enable-rect-partitions",
200- "8-bit only: no 10-bit gate enables rect partitions",
201- ),
202201 ("enable-rect-tx", "hole at both depths, see the 8-bit list"),
203202 (
204203 "enable-ref-frame-mvs",
205204 "hole at both depths, see the 8-bit list",
206205 ),
207- (
208- "enable-restoration",
209- "8-bit only -- THE instance this split was built for: every 10-bit gate passed `--enable-restoration=0`, so the SGR box sums and the Wiener clamp were never run at 10 bits and both were wrong (lane-hbdinter, 2026-09-01)",
210- ),
211206 (
212207 "enable-smooth-intra",
213208 "8-bit only: no 10-bit gate enables smooth intra",
crates/ec-av1/src/stream.rsmodified+291 -0
@@ -11116,4 +11116,295 @@ mod tests {
1111611116 assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned sbpart)");
1111711117 }
1111811118 }
11119+
11120+ /// lane-tiles r11: every tile gate before this one turns the coding tools
11121+ /// OFF (rect/ab partitions, tx-size search, cdef, restoration all `=0`)
11122+ /// to isolate the per-tile loop, which is exactly the
11123+ /// [[tool-disabled-in-every-gate]] shape -- a tile-edge defect in any of
11124+ /// those tools is invisible to all of them. This one runs the BROAD tool
11125+ /// set (rect + ab partitions, default tx search, cdef and loop
11126+ /// restoration both on, deblocking left at its default so it filters
11127+ /// across tile boundaries as the spec requires) over a real 2D tile grid,
11128+ /// through `decode_stream` rather than the tile entry point, so it is the
11129+ /// same path a caller decoding a file takes.
11130+ ///
11131+ /// 256x128 is four 64x64 superblocks wide and two tall, so
11132+ /// `--tile-columns=1 --tile-rows=1` really yields a 2x2 grid and
11133+ /// `--tile-columns=2` really yields 4 columns; both are asserted from the
11134+ /// parsed `tile_info` rather than assumed, and the decoded-tile counter
11135+ /// (`tile_hits`) is asserted at >= 4 per decoded frame so a stream whose
11136+ /// header claims 4 tiles but whose decode only walked one cannot pass.
11137+ // `#[track_caller]` so a failing assert names the calling arm's line, and
11138+ // so `gate_coverage`'s body split (on `\n #[`) treats this helper's
11139+ // recipe as its own gate rather than gluing it onto the preceding one.
11140+ #[track_caller]
11141+ fn run_multi_tile_gate(
11142+ name: &str,
11143+ tile_cols_log2: u32,
11144+ tile_rows_log2: u32,
11145+ bit_depth: usize,
11146+ frame_count: usize,
11147+ extra: &[&str],
11148+ ) {
11149+ let _gate_lock = lock_gate_counters();
11150+ if !have_ffmpeg() {
11151+ eprintln!("SKIP {name}: no ffmpeg");
11152+ return;
11153+ }
11154+ if !have_aomenc() {
11155+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
11156+ return;
11157+ }
11158+ let (width, height) = (256usize, 128usize);
11159+ let expected_tiles = (1usize << tile_cols_log2) * (1usize << tile_rows_log2);
11160+ let mut matched = 0u32;
11161+ let mut named_refusals = 0u32;
11162+ let n_attempts: u32 = std::env::var("EC_TILES_GATE_ATTEMPTS")
11163+ .ok()
11164+ .and_then(|s| s.parse().ok())
11165+ .unwrap_or(6);
11166+ for attempt in 0..n_attempts {
11167+ let seed = 42 + attempt;
11168+ let duration = frame_count as f64 / 25.0;
11169+ let source = gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
11170+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
11171+ let y4m = Command::new("ffmpeg")
11172+ .args([
11173+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt, "-strict",
11174+ "-1", "-f", "yuv4mpegpipe", "-",
11175+ ])
11176+ .stdin(Stdio::null())
11177+ .stdout(Stdio::piped())
11178+ .stderr(Stdio::piped())
11179+ .output()
11180+ .expect("ffmpeg failed to run");
11181+ assert!(
11182+ y4m.status.success(),
11183+ "ffmpeg fixture: {}",
11184+ String::from_utf8_lossy(&y4m.stderr)
11185+ );
11186+ let cols = format!("--tile-columns={tile_cols_log2}");
11187+ let rows = format!("--tile-rows={tile_rows_log2}");
11188+ let limit = format!("--limit={frame_count}");
11189+ let depth_args: Vec<String> = if bit_depth == 10 {
11190+ vec!["--input-bit-depth=10".to_owned(), "--bit-depth=10".to_owned()]
11191+ } else {
11192+ Vec::new()
11193+ };
11194+ let mut args: Vec<&str> = vec![
11195+ "--codec=av1",
11196+ "--passes=1",
11197+ "--end-usage=q",
11198+ "--cq-level=40",
11199+ "--cpu-used=4",
11200+ &limit,
11201+ "--kf-max-dist=1000",
11202+ "--threads=1",
11203+ "--row-mt=0",
11204+ // This decoder is 64x64-superblock only, and `--tile-columns`
11205+ // splits on superblock boundaries, so 128x128 superblocks
11206+ // would leave 256px only two tiles' worth of columns.
11207+ "--sb-size=64",
11208+ &cols,
11209+ &rows,
11210+ // The point of this gate: tools ON across tile edges.
11211+ "--enable-rect-partitions=1",
11212+ "--enable-ab-partitions=1",
11213+ "--enable-cdef=1",
11214+ "--enable-restoration=1",
11215+ // Still off: capabilities this decoder refuses outright, which
11216+ // would turn every attempt into a refusal and make the gate
11217+ // vacuous rather than proving anything about tiles.
11218+ "--enable-1to4-partitions=0",
11219+ "--min-partition-size=16",
11220+ "--enable-palette=0",
11221+ "--enable-intrabc=0",
11222+ "--enable-ref-frame-mvs=0",
11223+ "--enable-global-motion=0",
11224+ ];
11225+ args.extend(extra.iter().copied());
11226+ args.extend(depth_args.iter().map(String::as_str));
11227+ args.extend(["--obu", "-o", "-", "-"]);
11228+ let mut child = Command::new(aomenc_path())
11229+ .args(&args)
11230+ .stdin(Stdio::piped())
11231+ .stdout(Stdio::piped())
11232+ .stderr(Stdio::piped())
11233+ .spawn()
11234+ .expect("aomenc failed to start");
11235+ child
11236+ .stdin
11237+ .take()
11238+ .expect("aomenc stdin")
11239+ .write_all(&y4m.stdout)
11240+ .expect("writing y4m to aomenc");
11241+ let out = child.wait_with_output().expect("aomenc failed to run");
11242+ assert!(
11243+ out.status.success(),
11244+ "aomenc refused the fixture: {}",
11245+ String::from_utf8_lossy(&out.stderr)
11246+ );
11247+ let stream = out.stdout;
11248+
11249+ // The stream must really carry the tile grid asked for, or the
11250+ // gate proves nothing (aomenc silently clamps tile counts that do
11251+ // not fit the frame's superblock grid).
11252+ {
11253+ let mut probe = Av1Parser::new();
11254+ let mut pos = 0usize;
11255+ let mut checked = false;
11256+ while pos < stream.len() {
11257+ let obu = probe.parse_obu(&stream[pos..]).expect("parsing the gate stream");
11258+ pos += obu.total_size;
11259+ let header = match &obu.kind {
11260+ ObuKind::Frame(h, _) => h,
11261+ ObuKind::FrameHeader(h) => h,
11262+ _ => continue,
11263+ };
11264+ // A `show_existing_frame` header codes no tile info at all
11265+ // (spec 5.9.2 returns before `tile_info()`), so its
11266+ // `TileInfo` is the parser's 1x1 default -- checking it
11267+ // here would fail every inter stream for a header that
11268+ // carries no tiling.
11269+ if header.show_existing_frame {
11270+ continue;
11271+ }
11272+ assert_eq!(
11273+ (header.tile_info.cols * header.tile_info.rows) as usize,
11274+ expected_tiles,
11275+ "{name}: aomenc wrote {}x{} tiles, not the {expected_tiles} asked for \
11276+ (seed {seed})",
11277+ header.tile_info.cols,
11278+ header.tile_info.rows
11279+ );
11280+ checked = true;
11281+ }
11282+ assert!(checked, "{name}: no frame header in the stream (seed {seed})");
11283+ }
11284+
11285+ let before = crate::decode::tile_hits();
11286+ let frames = match decode_stream(&stream) {
11287+ Err(e) => {
11288+ let msg = e.to_string();
11289+ assert!(
11290+ msg.contains("unsupported"),
11291+ "{name} failed outright, not a named refusal (seed {seed}): {msg}"
11292+ );
11293+ named_refusals += 1;
11294+ eprintln!("seed {seed} refusal: {msg}");
11295+ continue;
11296+ }
11297+ Ok(frames) => frames,
11298+ };
11299+ let hits = crate::decode::tile_hits() - before;
11300+ assert!(
11301+ hits >= expected_tiles * frames.len(),
11302+ "{name}: tile_hits delta was {hits}, expected >= {} -- every tile of every \
11303+ frame must actually decode (seed {seed})",
11304+ expected_tiles * frames.len()
11305+ );
11306+ let ffmpeg_frames = if bit_depth == 10 {
11307+ ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
11308+ } else {
11309+ ffmpeg_decode_sequence(&stream, width, height, frames.len())
11310+ };
11311+ let mismatched = frames
11312+ .iter()
11313+ .zip(&ffmpeg_frames)
11314+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
11315+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
11316+ std::fs::write(&path, &stream).expect("writing pinned stream");
11317+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
11318+ }
11319+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
11320+ assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (seed {seed})");
11321+ assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})");
11322+ assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})");
11323+ }
11324+ matched += 1;
11325+ }
11326+ assert!(
11327+ matched > 0,
11328+ "{name}: every attempt refused ({named_refusals}); the gate never decoded a \
11329+ multi-tile stream with the coding tools on"
11330+ );
11331+ eprintln!("{name}: {matched} pixel-exact matches, {named_refusals} named refusals");
11332+ }
11333+
11334+ #[test]
11335+ fn a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact() {
11336+ run_multi_tile_gate(
11337+ "a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact",
11338+ 1,
11339+ 1,
11340+ 8,
11341+ 1,
11342+ &[],
11343+ );
11344+ }
11345+
11346+ #[test]
11347+ fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() {
11348+ run_multi_tile_gate(
11349+ "a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact",
11350+ 2,
11351+ 0,
11352+ 10,
11353+ 1,
11354+ &[],
11355+ );
11356+ }
11357+
11358+ /// OPEN DEFECT (lane-tiles r11), which is why this arm is `#[ignore]`d
11359+ /// rather than deleted or quietly reseeded: at seed 42 this recipe
11360+ /// mismatches ffmpeg from frame 4 on, in one 32x32 block at
11361+ /// x[224..255] y[32..63] (measured with `--loopfilter-control=0`, which
11362+ /// removes the deblock spreading; with deblocking on the region grows to
11363+ /// x[221..255] y[30..69] and crosses the tile row boundary at y=64), and
11364+ /// the error then propagates through inter prediction to 12 of 16 frames.
11365+ /// Ablations that did NOT remove it: `--enable-restoration=0`,
11366+ /// `--enable-cdef=0`, `--loopfilter-control=0`. It is seed-specific
11367+ /// (seeds 47 and 48 decode 16/16 exact with two tile rows) and its
11368+ /// tile attribution is UNPROVEN: the single-tile control at seed 42
11369+ /// re-encodes to different partitions and refuses on
11370+ /// "an inter SB-level partition type other than SPLIT", so no
11371+ /// same-content one-tile comparison exists. Reproducer:
11372+ /// `EC_AV1_GATE_DUMP=<path> cargo test -p ec-av1 --lib
11373+ /// a_real_aomenc_multi_tile_inter_stream -- --ignored`.
11374+ #[test]
11375+ #[ignore = "open defect: seed-42 32x32 block at x[224..255] y[32..63] mismatches; tile attribution unproven"]
11376+ fn a_real_aomenc_multi_tile_inter_stream_decodes_pixel_exact() {
11377+ run_multi_tile_gate(
11378+ "a_real_aomenc_multi_tile_inter_stream_decodes_pixel_exact",
11379+ 1,
11380+ 1,
11381+ 8,
11382+ 16,
11383+ // Pre-existing, non-tile decoder limits this lane does not own:
11384+ // the inter path only recurses a superblock as SPLIT (so the SB
11385+ // level must be forced to split) and never reads a `tx_depth`
11386+ // symbol under `TxMode::Select`. Both are named refusals in
11387+ // `refusal_inventory.rs`; without these two flags every inter
11388+ // attempt refuses before a single tile edge is compared.
11389+ &["--max-partition-size=32", "--enable-tx-size-search=0"],
11390+ );
11391+ }
11392+
11393+ #[test]
11394+ fn a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact() {
11395+ run_multi_tile_gate(
11396+ "a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact",
11397+ 2,
11398+ 0,
11399+ 10,
11400+ 16,
11401+ // Pre-existing, non-tile decoder limits this lane does not own:
11402+ // the inter path only recurses a superblock as SPLIT (so the SB
11403+ // level must be forced to split) and never reads a `tx_depth`
11404+ // symbol under `TxMode::Select`. Both are named refusals in
11405+ // `refusal_inventory.rs`; without these two flags every inter
11406+ // attempt refuses before a single tile edge is compared.
11407+ &["--max-partition-size=32", "--enable-tx-size-search=0"],
11408+ );
11409+ }
1111911410 }