From 9c8c2142f00291e2681276c0f4433ddaefd815b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:22:48 +0300 Subject: [PATCH] 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.rs | 36 +++ crates/ec-av1/src/gate_coverage.rs | 37 ++-- crates/ec-av1/src/stream.rs | 291 +++++++++++++++++++++++++ 3 files changed, 343 insertions(+), 21 deletions(-) diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 8b0452a7..834e058f 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -28,6 +28,42 @@ fn main() { std::process::exit(2); } }; + // lane-tiles: the tiling a real stream actually uses is a decision input + // (every gate in `stream.rs` picks its own `--tile-columns`), so report it + // from the frame headers before saying anything about pixels. + let mut parser = ec_av1_syntax::Av1Parser::new(); + let mut seen: Vec<(u32, u32, bool, u32)> = Vec::new(); + let mut pos = 0usize; + let mut frames_seen = 0usize; + // OBU at a time, so one unparseable OBU late in the stream still leaves + // every earlier frame header's tiling reported. + while pos < data.len() { + let Ok(obu) = parser.parse_obu(&data[pos..]) else { + break; + }; + pos += obu.total_size.max(1); + let header = match &obu.kind { + ec_av1_syntax::ObuKind::FrameHeader(h) => h, + ec_av1_syntax::ObuKind::Frame(h, _) => h, + _ => continue, + }; + frames_seen += 1; + let t = &header.tile_info; + let entry = (t.cols, t.rows, t.uniform_spacing, t.context_update_tile_id); + if !seen.contains(&entry) { + seen.push(entry); + } + } + println!("TILING: {frames_seen} frame headers parsed"); + for (cols, rows, uniform, ctx_id) in &seen { + println!( + "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}" + ); + } + if seen.is_empty() { + println!("TILING: no frame header parsed"); + } + match ec_av1::stream::decode_stream(&data) { Ok(frames) if frames.is_empty() => { println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?"); diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 727088f6..381ebaba 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -18,6 +18,15 @@ //! feature's gate, which shrinks the derived set and fails this test until the //! list is updated -- the point being that the shrink is noticed. +// TILING is deliberately NOT in this derivation (lane-tiles r11): the check +// keys on `--enable-=0/1`, and `--tile-columns=` has no such +// shape -- a `--tile-columns=` presence check would also read `=0` (one tile) +// as coverage, which is the opposite of what it would claim. It needs no +// entry either: 13 gates spell `--tile-columns`/`--tile-rows` with a nonzero +// log2 and assert the parsed `tile_info` really carries the grid, and +// `run_multi_tile_gate` covers a 2D grid with the coding tools ON at both +// bit depths. + /// aomenc coding tools that no real-`aomenc` gate is proven to exercise: /// switched off in every gate that names them, and on in none. /// @@ -144,7 +153,13 @@ const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[ ]; #[cfg(test)] -const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ +const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ // lane-cwarp's 10-bit compound-global-warp gate closed `enable-global-motion` + // and `enable-dist-wtd-comp` at 10 bits without deleting their entries here, + // so this list was already stale (and this test already red) at main 9c35ecc; + // lane-tiles r11's multi-tile 10-bit gates then closed `enable-ab-partitions`, + // `enable-rect-partitions` and `enable-restoration` at 10 bits. All five + // deleted together. + // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the // pixel filters and the intra tool set off. Every entry the 8-bit list // carries is a hole here too; the seven extra ones below are tools an @@ -154,10 +169,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ "enable-1to4-partitions", "hole at both depths, see the 8-bit list", ), - ( - "enable-ab-partitions", - "8-bit only: no 10-bit gate enables AB partitions", - ), ( "enable-angle-delta", "hole at both depths, see the 8-bit list", @@ -166,10 +177,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ "enable-cfl-intra", "hole at both depths, see the 8-bit list", ), - ( - "enable-dist-wtd-comp", - "hole at both depths, see the 8-bit list", - ), ( "enable-dual-filter", "hole at both depths, see the 8-bit list", @@ -182,10 +189,6 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ "enable-flip-idtx", "hole at both depths, see the 8-bit list", ), - ( - "enable-global-motion", - "hole at both depths, see the 8-bit list", - ), ( "enable-intra-edge-filter", "8-bit only: the 10-bit intra path never runs the edge filter", @@ -195,19 +198,11 @@ const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[ "enable-paeth-intra", "8-bit only: no 10-bit gate enables Paeth", ), - ( - "enable-rect-partitions", - "8-bit only: no 10-bit gate enables rect partitions", - ), ("enable-rect-tx", "hole at both depths, see the 8-bit list"), ( "enable-ref-frame-mvs", "hole at both depths, see the 8-bit list", ), - ( - "enable-restoration", - "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)", - ), ( "enable-smooth-intra", "8-bit only: no 10-bit gate enables smooth intra", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a40ef2cb..9e53333f 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -11116,4 +11116,295 @@ mod tests { assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned sbpart)"); } } + + /// lane-tiles r11: every tile gate before this one turns the coding tools + /// OFF (rect/ab partitions, tx-size search, cdef, restoration all `=0`) + /// to isolate the per-tile loop, which is exactly the + /// [[tool-disabled-in-every-gate]] shape -- a tile-edge defect in any of + /// those tools is invisible to all of them. This one runs the BROAD tool + /// set (rect + ab partitions, default tx search, cdef and loop + /// restoration both on, deblocking left at its default so it filters + /// across tile boundaries as the spec requires) over a real 2D tile grid, + /// through `decode_stream` rather than the tile entry point, so it is the + /// same path a caller decoding a file takes. + /// + /// 256x128 is four 64x64 superblocks wide and two tall, so + /// `--tile-columns=1 --tile-rows=1` really yields a 2x2 grid and + /// `--tile-columns=2` really yields 4 columns; both are asserted from the + /// parsed `tile_info` rather than assumed, and the decoded-tile counter + /// (`tile_hits`) is asserted at >= 4 per decoded frame so a stream whose + /// header claims 4 tiles but whose decode only walked one cannot pass. + // `#[track_caller]` so a failing assert names the calling arm's line, and + // so `gate_coverage`'s body split (on `\n #[`) treats this helper's + // recipe as its own gate rather than gluing it onto the preceding one. + #[track_caller] + fn run_multi_tile_gate( + name: &str, + tile_cols_log2: u32, + tile_rows_log2: u32, + bit_depth: usize, + frame_count: usize, + extra: &[&str], + ) { + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {name}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height) = (256usize, 128usize); + let expected_tiles = (1usize << tile_cols_log2) * (1usize << tile_rows_log2); + let mut matched = 0u32; + let mut named_refusals = 0u32; + let n_attempts: u32 = std::env::var("EC_TILES_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(6); + for attempt in 0..n_attempts { + let seed = 42 + attempt; + let duration = frame_count as f64 / 25.0; + let source = gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt, "-strict", + "-1", "-f", "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let cols = format!("--tile-columns={tile_cols_log2}"); + let rows = format!("--tile-rows={tile_rows_log2}"); + let limit = format!("--limit={frame_count}"); + let depth_args: Vec = if bit_depth == 10 { + vec!["--input-bit-depth=10".to_owned(), "--bit-depth=10".to_owned()] + } else { + Vec::new() + }; + let mut args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=40", + "--cpu-used=4", + &limit, + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + // This decoder is 64x64-superblock only, and `--tile-columns` + // splits on superblock boundaries, so 128x128 superblocks + // would leave 256px only two tiles' worth of columns. + "--sb-size=64", + &cols, + &rows, + // The point of this gate: tools ON across tile edges. + "--enable-rect-partitions=1", + "--enable-ab-partitions=1", + "--enable-cdef=1", + "--enable-restoration=1", + // Still off: capabilities this decoder refuses outright, which + // would turn every attempt into a refusal and make the gate + // vacuous rather than proving anything about tiles. + "--enable-1to4-partitions=0", + "--min-partition-size=16", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-ref-frame-mvs=0", + "--enable-global-motion=0", + ]; + args.extend(extra.iter().copied()); + args.extend(depth_args.iter().map(String::as_str)); + args.extend(["--obu", "-o", "-", "-"]); + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + + // The stream must really carry the tile grid asked for, or the + // gate proves nothing (aomenc silently clamps tile counts that do + // not fit the frame's superblock grid). + { + let mut probe = Av1Parser::new(); + let mut pos = 0usize; + let mut checked = false; + while pos < stream.len() { + let obu = probe.parse_obu(&stream[pos..]).expect("parsing the gate stream"); + pos += obu.total_size; + let header = match &obu.kind { + ObuKind::Frame(h, _) => h, + ObuKind::FrameHeader(h) => h, + _ => continue, + }; + // A `show_existing_frame` header codes no tile info at all + // (spec 5.9.2 returns before `tile_info()`), so its + // `TileInfo` is the parser's 1x1 default -- checking it + // here would fail every inter stream for a header that + // carries no tiling. + if header.show_existing_frame { + continue; + } + assert_eq!( + (header.tile_info.cols * header.tile_info.rows) as usize, + expected_tiles, + "{name}: aomenc wrote {}x{} tiles, not the {expected_tiles} asked for \ + (seed {seed})", + header.tile_info.cols, + header.tile_info.rows + ); + checked = true; + } + assert!(checked, "{name}: no frame header in the stream (seed {seed})"); + } + + let before = crate::decode::tile_hits(); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{name} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + eprintln!("seed {seed} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let hits = crate::decode::tile_hits() - before; + assert!( + hits >= expected_tiles * frames.len(), + "{name}: tile_hits delta was {hits}, expected >= {} -- every tile of every \ + frame must actually decode (seed {seed})", + expected_tiles * frames.len() + ); + let ffmpeg_frames = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames.len()) + }; + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { + std::fs::write(&path, &stream).expect("writing pinned stream"); + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (seed {seed})"); + } + matched += 1; + } + assert!( + matched > 0, + "{name}: every attempt refused ({named_refusals}); the gate never decoded a \ + multi-tile stream with the coding tools on" + ); + eprintln!("{name}: {matched} pixel-exact matches, {named_refusals} named refusals"); + } + + #[test] + fn a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact() { + run_multi_tile_gate( + "a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact", + 1, + 1, + 8, + 1, + &[], + ); + } + + #[test] + fn a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact() { + run_multi_tile_gate( + "a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact", + 2, + 0, + 10, + 1, + &[], + ); + } + + /// OPEN DEFECT (lane-tiles r11), which is why this arm is `#[ignore]`d + /// rather than deleted or quietly reseeded: at seed 42 this recipe + /// mismatches ffmpeg from frame 4 on, in one 32x32 block at + /// x[224..255] y[32..63] (measured with `--loopfilter-control=0`, which + /// removes the deblock spreading; with deblocking on the region grows to + /// x[221..255] y[30..69] and crosses the tile row boundary at y=64), and + /// the error then propagates through inter prediction to 12 of 16 frames. + /// Ablations that did NOT remove it: `--enable-restoration=0`, + /// `--enable-cdef=0`, `--loopfilter-control=0`. It is seed-specific + /// (seeds 47 and 48 decode 16/16 exact with two tile rows) and its + /// tile attribution is UNPROVEN: the single-tile control at seed 42 + /// re-encodes to different partitions and refuses on + /// "an inter SB-level partition type other than SPLIT", so no + /// same-content one-tile comparison exists. Reproducer: + /// `EC_AV1_GATE_DUMP= cargo test -p ec-av1 --lib + /// a_real_aomenc_multi_tile_inter_stream -- --ignored`. + #[test] + #[ignore = "open defect: seed-42 32x32 block at x[224..255] y[32..63] mismatches; tile attribution unproven"] + fn a_real_aomenc_multi_tile_inter_stream_decodes_pixel_exact() { + run_multi_tile_gate( + "a_real_aomenc_multi_tile_inter_stream_decodes_pixel_exact", + 1, + 1, + 8, + 16, + // Pre-existing, non-tile decoder limits this lane does not own: + // the inter path only recurses a superblock as SPLIT (so the SB + // level must be forced to split) and never reads a `tx_depth` + // symbol under `TxMode::Select`. Both are named refusals in + // `refusal_inventory.rs`; without these two flags every inter + // attempt refuses before a single tile edge is compared. + &["--max-partition-size=32", "--enable-tx-size-search=0"], + ); + } + + #[test] + fn a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact() { + run_multi_tile_gate( + "a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact", + 2, + 0, + 10, + 16, + // Pre-existing, non-tile decoder limits this lane does not own: + // the inter path only recurses a superblock as SPLIT (so the SB + // level must be forced to split) and never reads a `tx_depth` + // symbol under `TxMode::Select`. Both are named refusals in + // `refusal_inventory.rs`; without these two flags every inter + // attempt refuses before a single tile edge is compared. + &["--max-partition-size=32", "--enable-tx-size-search=0"], + ); + } }