diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index c0c366bb..a0667b0b 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -32,6 +32,42 @@ fn main() { let (h, v, c) = ec_av1::stream::rect4_32_counters(); println!("rect4_32: horz={h} vert={v} coded={c}"); }; + // 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/decode.rs b/crates/ec-av1/src/decode.rs index cc88ffac..6b0c84fe 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1046,6 +1046,19 @@ pub(crate) fn palette_hits() -> usize { PALETTE_HITS.with(|c| c.get()) } +// lane-tiles r12: of those, how many sat at their own TILE's left column -- +// exactly the blocks whose palette cache/ctx must NOT see the previous tile's +// colours (`av1_get_palette_cache`'s `xd->left_mbmi == NULL`). A multi-tile +// palette gate that never hits one proves nothing about the tile guard. +thread_local! { + static PALETTE_TILE_LEFT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of [`PALETTE_TILE_LEFT_HITS`]. +pub(crate) fn palette_tile_left_hits() -> usize { + PALETTE_TILE_LEFT_HITS.with(|c| c.get()) +} + // lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma // palette use -- proves a stream actually reconstructed UV palette pixels, // not just read and refused the `palette_uv_mode` symbol. @@ -3279,7 +3292,13 @@ impl Neighbours { } else { (0, [0u16; 8]) }; - let (left_n, left_colors) = if self.left_palette_size[r] > 0 { + // lane-tiles r11: `av1_get_palette_cache` takes `xd->left_mbmi`, which + // is NULL whenever the block sits at its TILE's own left column + // (`left_available`), not the frame's -- without this guard a second + // tile column reads the previous tile's palette colours into its cache + // and its `palette_y_mode` ctx. + let left_ok = c > self.tile_col0_mi / (SUB / MI); + let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 { (self.left_palette_size[r], self.left_palette_colors[r]) } else { (0, [0u16; 8]) @@ -3344,7 +3363,9 @@ impl Neighbours { } else { (0, [0u16; 8]) }; - let (left_n, left_colors) = if self.left_palette_uv_size[r] > 0 { + // Same tile-relative left availability as the luma cache above. + let left_ok = c > self.tile_col0_mi / (SUB / MI); + let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 { (self.left_palette_uv_size[r], self.left_palette_uv_colors[r]) } else { (0, [0u16; 8]) @@ -3518,6 +3539,14 @@ impl Neighbours { // context (a tile/SB-row boundary has no left neighbour). self.sub8_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); self.uv_mode_row.iter_mut().for_each(|s| *s = (usize::MAX, 0)); + // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands + // are per-mi maps like every other one here, so they reset with the + // row too -- the left guard above is what actually stops a cross-tile + // read, this keeps a stale colour out of the arrays at all. + self.left_palette_size.iter_mut().for_each(|s| *s = 0); + self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]); + self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0); + self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]); } /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next @@ -6439,8 +6468,15 @@ fn read_intra_mode( // matched bit-exact, then `eob_pt` read 5 instead of 6, because this // symbol's bits were never consumed). let mut filter_intra = None; + // lane-tiles r12: `av1_filter_intra_allowed` (blockd.h) also requires + // `mbmi->palette_mode_info.palette_size[0] == 0` -- libaom writes NO + // `use_filter_intra` symbol for a Y-palette block, and reading one here + // desynced every screen-content stream from the first palette block on + // (it surfaced as a bogus "partition below 8x8" refusal further down the + // tile). if mode == DC_PRED && enable_filter_intra + && palette_y_pending.is_none() && let Some(class) = filter_intra_size_class(side) { let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; @@ -7032,6 +7068,7 @@ fn decode_block( let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c); + let at_tile_left = c == neighbours.tile_col0_mi / (SUB / MI); let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = read_intra_mode( dec, @@ -7049,6 +7086,9 @@ fn decode_block( r * (SUB / MI), c * (SUB / MI), )?; + if at_tile_left && palette_y.is_some() { + PALETTE_TILE_LEFT_HITS.with(|c| c.set(c.get() + 1)); + } let intrabc_dv = INTRABC_DV.with(|c| c.take()); // libaom `parse_decode_block`: an intrabc block is `inter_block_tx`, so // under `TX_MODE_SELECT` its transform size comes from the inter var-tx diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 42a08351..b6805291 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. /// @@ -182,7 +191,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. lane-hbdgates r1 closed six of the seven diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index d9073e39..94be1b01 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -16369,4 +16369,395 @@ mod tests { ); } } + + /// 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], + // lane-tiles r12: the palette arm's own override proof. `true` asserts, + // per attempt, that the arm's `--tune-content=screen --enable-palette=1` + // really reached the encoder (frame header `allow_screen_content_tools`) + // AND that a palette block fired at a TILE's left column -- the exact + // block whose colour cache must not see the previous tile's colours. + require_tile_left_palette: bool, + // `None` = the shared `gradients_source`. The palette arm overrides it + // with `smptebars`, the flat few-colour source the existing palette + // gates use -- gradients never make aomenc pick a palette block. + source_override: Option<&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 = match source_override { + Some(src) => format!("{src}=size={width}x{height}:duration={duration}:rate=25"), + None => 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", + // Overridable by `extra` (aomenc takes the last occurrence of + // a repeated flag), which the palette arm below relies on. + "--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, + // lane-tiles r12: prove the base recipe's tools-on + // flags arrived (a repeated aomenc `--enable-*` keeps + // the LAST occurrence -- measured, see the report -- + // so a per-arm override must not silently vanish). + ObuKind::SequenceHeader(seq) => { + assert!( + seq.enable_cdef && seq.enable_restoration, + "{name}: --enable-cdef=1 --enable-restoration=1 did not reach \ + aomenc (seq enable_cdef={} enable_restoration={}, seed {seed})", + seq.enable_cdef, + seq.enable_restoration + ); + continue; + } + _ => 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; + } + if require_tile_left_palette { + assert!( + header.allow_screen_content_tools, + "{name}: --tune-content=screen/--enable-palette=1 did not reach \ + aomenc -- allow_screen_content_tools is 0 (seed {seed})" + ); + } + 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 pal_before = crate::decode::palette_tile_left_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})"); + } + if require_tile_left_palette { + let pal = crate::decode::palette_tile_left_hits() - pal_before; + assert!( + pal >= 1, + "{name}: this attempt decoded and matched but fired {pal} palette blocks at \ + a tile's left column -- the tile-relative palette cache guard is untested \ + (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, + &[], + false, + None, + ); + } + + #[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, + &[], + false, + None, + ); + } + + /// 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"], + false, + None, + ); + } + + /// lane-tiles r11, the defect this arm exists for: `palette_ctx_and_cache` + /// / `palette_uv_cache` (`decode.rs`) read the LEFT palette neighbour with + /// no availability guard at all, where libaom's `av1_get_palette_cache` + /// takes `xd->left_mbmi`, which is NULL at the block's own TILE left + /// column. A second tile column therefore inherited the previous tile's + /// palette colours and `palette_y_mode` ctx. Screen content is what makes + /// aomenc pick palette at all, so this arm drives `--tune-content=screen + /// --enable-palette=1` over a 2-column grid and asserts a real palette + /// block actually fired. + /// `#[ignore]`d at r11 and NOT yet proof of the fix: with the broad tool + /// set every seed refuses before a palette block reconstructs + /// ("a HORZ_A/HORZ_B/VERT_A partition below 16x16"), and the per-arm + /// `extra` overrides do not switch the base recipe's tools off -- aomenc + /// keeps the FIRST occurrence of a repeated `--enable-*` flag (measured: + /// appending `--enable-rect-partitions=0` after the base `=1` changed the + /// refusal not at all). Next round: put `extra` BEFORE the base list in + /// `run_multi_tile_gate`'s args, then this arm should reach a palette + /// block on smptebars with rect/ab off. + #[test] + fn a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact"; + let before = crate::decode::palette_hits(); + run_multi_tile_gate( + NAME, + 1, + 0, + 8, + 1, + &["--enable-palette=1", "--tune-content=screen", "--cq-level=30", "--enable-tx-size-search=0", "--max-partition-size=32", + // Screen content + rect strips is a separate, pre-existing + // refusal ("palette syntax is consumed for square blocks + // only"); this arm owns the palette CACHE at a tile edge, so + // it takes the square-only path the other palette gates take. + "--enable-rect-partitions=0", "--enable-ab-partitions=0"], + true, + Some("smptebars"), + ); + if have_ffmpeg() && have_aomenc() { + assert!( + crate::decode::palette_hits() > before, + "{NAME}: no palette block fired -- the gate proves nothing about the palette \ + cache at a tile edge" + ); + } + } + + #[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"], + false, + None, + ); + } } diff --git a/lanes/tiles-r11.report.md b/lanes/tiles-r11.report.md new file mode 100644 index 00000000..2d229e6c --- /dev/null +++ b/lanes/tiles-r11.report.md @@ -0,0 +1,132 @@ +# lane-tiles r11 — multi-tile gates with the tools ON; the films are single-tile + +## Charter premises, re-measured first (both stale) +1. **"all 45 real-aomenc gates are single-tile"** — false at main 9c35ecc. This lane + already ran 10 rounds, all merged; `crates/ec-av1/src/stream.rs` carries 9 multi-tile + gates (2/4 tile columns, 2/4 tile rows, an inter one, several tile-group OBUs, + non-uniform spacing). The branch was already identical to main at start + (`git log main..HEAD` empty). +2. **"round 1"** — this is r11. + +What was genuinely missing: every one of those 9 gates turns the coding tools OFF +(`--enable-rect-partitions=0 --enable-ab-partitions=0 --enable-cdef=0 +--enable-restoration=0`, some `--loopfilter-control=0`, `--min/--max-partition-size=32`). +That is the [[tool-disabled-in-every-gate]] shape: a tile-edge defect inside any of those +tools was invisible to all nine. + +## HIS FILMS' REAL TILING (the charter's decision input) +Both films are **one tile**: `cols=1 rows=1 uniform_spacing=1 context_update_tile_id=0`, +constant over 181 parsed frame headers each. Cross-checked with a foreign parser +(ffmpeg `trace_headers` bsf): `tile_cols_log2 = 0`, `tile_rows_log2 = 0`, +`uniform_tile_spacing_flag = 1` on every frame. **Multi-tile is not on the critical path +for his library**; it stays a conformance obligation, not a film blocker. + +EVIDENCE: /tmp/.../scratchpad/reelcB.obu, reelbB.obu (120 frames each, `-ss 300 -c:v copy -f obu`) | `cargo run -p ec-av1 --example decode_probe -- ` + `ffmpeg -v trace -bsf:v trace_headers` | ours: 181 headers, one distinct tiling (1x1); ffmpeg: tile_cols_log2=0 tile_rows_log2=0 on every frame; ReelC 1920x792, ReelB 3840x1608 + +## New gate family (`crates/ec-av1/src/stream.rs`, `run_multi_tile_gate` + 4 arms) +256x128 (four 64x64 SBs wide, two tall), through `decode_stream` — the same entry point a +caller decoding a file uses, not the tile function the older gates call directly. +Recipe: `--enable-rect-partitions=1 --enable-ab-partitions=1 --enable-cdef=1 +--enable-restoration=1`, deblocking left at its default so it filters across tile +boundaries, `--sb-size=64`, `--threads=1 --row-mt=0`, 6 seeds. +Hard asserts: parsed `tile_info.cols*rows == expected` on every non-`show_existing_frame` +header, and `tile_hits` delta `>= tiles * frames` (a header claiming 4 tiles cannot pass on +one decoded tile). + +| arm | grid | depth | frames | result | +|---|---|---|---|---| +| `a_real_aomenc_multi_tile_intra_stream_decodes_pixel_exact` | 2x2 | 8 | 1 | 5/6 exact, 1 named refusal | +| `a_real_aomenc_multi_tile_intra_10bit_stream_decodes_pixel_exact` | 4 cols | 10 | 1 | 5/6 exact, 1 named refusal | +| `a_real_aomenc_multi_tile_inter_10bit_stream_decodes_pixel_exact` | 4 cols | 10 | 16 | 3/6 exact, 3 named refusals | +| `a_real_aomenc_multi_tile_inter_stream_decodes_pixel_exact` | 2x2 | 8 | 16 | **`#[ignore]`d — open defect, below** | + +The two inter arms additionally pass `--max-partition-size=32 --enable-tx-size-search=0`: +without them every attempt refuses on two *pre-existing, non-tile* limits (the inter path +only recurses a superblock as SPLIT; it reads no `tx_depth` under `TxMode::Select`), so the +gate would compare no tile edge at all. Stated here rather than silently folded in. + +EVIDENCE: cargo test output | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib multi_tile -- --nocapture --test-threads=1` | 3 arms pass with tools on, 4th ignored + +## OPEN DEFECT (fix-now was not reached; deferred) +Seed 42, 2 tile rows: one 32x32 luma block at **x[224..255] y[32..63]** (tile row 0, frame +right edge) mismatches ffmpeg from **frame 4**, propagating through inter prediction to +12 of 16 frames. Localisation and ablations: +- bbox with deblocking on: x[221..255] y[30..69] — crosses the tile row boundary (y=64), so + deblock only *spreads* it; with `--loopfilter-control=0` it collapses to the single 32x32 + block above. +- NOT removed by `--enable-restoration=0`, `--enable-cdef=0`, `--loopfilter-control=0`. +- Reproduces with 2 tile rows *and* with the 2x2 grid; seeds 47 and 48 decode 16/16 exact + with two tile rows, so it is content-dependent, not a systematic tile-row defect. +- **Tile attribution is UNPROVEN**: the same-content single-tile control re-encodes to + different partitions and refuses ("an inter SB-level partition type other than SPLIT"), so + no one-tile comparison of this content exists ([[gate-recipe-confound]]). Calling it a + tile-edge defect would be a guess. +Reproducer: `EC_AV1_GATE_DUMP=/tmp/mt.obu cargo test -p ec-av1 --lib a_real_aomenc_multi_tile_inter_stream -- --ignored`. +Disposition: **deferred(a decodable single-tile control of the same content — unblocked by +either the inter SB-level non-SPLIT partition capability or an aomenc recipe that keeps +partitions identical across tile settings)**. + +EVIDENCE: /tmp/.../scratchpad/{c11,c01,norest,nocdef,nolf}.obu + cmp.py bboxes | encode seeds 42..48 x tile-rows 0/1 x {restoration,cdef,deblock} off, decode via decode_probe, per-pixel diff vs `ffmpeg -f rawvideo` | seed42 rows=1: 12/16 frames mismatch, nolf bbox x[224..255] y[32..63]; seed47 rows=1 and seed48 rows=0/1: 0/16 mismatch + +## Neighbour-map sweep (COMMON's NEIGHBOUR MAPS paragraph) +`grep -n "> 0" `-swept the per-mi availability guards: `decode.rs` uses +`tile_row0_mi`/`tile_col0_mi` (fields at decode.rs:2420-2421, reset in +`Neighbours::start_tile`, called per tile at decode.rs:5549 and 10512) and `PlaneBuf`'s +reach clamps use `tile_x0/tile_y0`; no `> 0` availability guard remained on a per-mi side +band. Nothing to fix — recorded so the next lane does not re-sweep it. + +## gate_coverage (charter item 3) +- Tiling **cannot** join the derivation and needs no entry: the check keys on + `--enable-=0/1`, and a `--tile-columns=` presence check would read `=0` (one tile) + as coverage. Noted in `gate_coverage.rs` with the gates that do spell it. +- Deleted 5 stale `NEVER_EXERCISED_10BIT` entries. Two of them + (`enable-global-motion`, `enable-dist-wtd-comp`) were closed by lane-cwarp's 10-bit + compound-warp gate without updating this list, **so `never_exercised_10bit_matches_the_gate_recipes` + was already failing at main 9c35ecc** — a pre-existing red, fixed here. The other three + (`enable-ab-partitions`, `enable-rect-partitions`, `enable-restoration`) are closed by the + new 10-bit arms. +- Also fixed the same body-split shape in my own helper: `gate_coverage` splits gate bodies + on `\n #[`, so a bare helper `fn` is glued onto the preceding gate's recipe. + `run_multi_tile_gate` carries `#[track_caller]` so it owns its body. + +## Test totals +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --test-threads=2`: +**282 passed, 0 failed, 26 ignored** (1211 s). `cargo check -p ec-av1 --tests`: clean. +(A first run at default test-threads was SIGTERMed by `scripts/memguard-runner.sh` under +10 concurrent lanes; `--test-threads=2` is the working setting, not a result.) + +## Files changed +- `crates/ec-av1/src/stream.rs` — `run_multi_tile_gate` + 4 arms. +- `crates/ec-av1/src/gate_coverage.rs` — 5 stale 10-bit entries deleted, tiling note. +- `crates/ec-av1/examples/decode_probe.rs` — prints every frame header's tiling. + +## Commit +- 2e73186 on `lane-tiles`. Never pushed, never merged, main untouched. + +## Coordinator items received mid-round (after the r11 commit) +1. **Palette left neighbour has no tile guard — CONFIRMED and FIXED.** + `decode.rs` `palette_ctx_and_cache` and `palette_uv_cache` read + `left_palette_size[r]` / `left_palette_uv_size[r]` with **no availability guard at + all**, where libaom's `av1_get_palette_cache` takes `xd->left_mbmi`, NULL at the + block's own tile left column. Fixed with `let left_ok = c > self.tile_col0_mi / (SUB / MI);` + on both (`at` is in SUB units, so the mi-unit tile origin is divided the same way + `start_tile` divides `col0_mi` for `above_mode`). `start_row` also never cleared + `left_palette_*`/`left_palette_uv_*`; it does now (COMMON's NEIGHBOUR MAPS rule 2). + Status: **code-verified** — 54 tile tests + gate_coverage green, no gate yet proves it. +2. **Palette + screen-content multi-tile arm — written, `#[ignore]`d, NOT yet proof.** + `a_real_aomenc_multi_tile_palette_stream_decodes_pixel_exact` (smptebars, 2 tile + columns, `--tune-content=screen --enable-palette=1`, asserts `palette_hits` rose). + It currently refuses on every seed before a palette block reconstructs, because the + per-arm `extra` flags do NOT override the base recipe: **aomenc keeps the FIRST + occurrence of a repeated `--enable-*` flag** (measured — appending + `--enable-rect-partitions=0` after the base `=1` changed the refusal not at all). + Fix next round: move `args.extend(extra)` to precede the base list in + `run_multi_tile_gate`. Disposition: **deferred(one edit — extra before base)**. +3. **lane-ab16's `--tile-columns=1` mismatch (mandelbrot 96x96, x=32..63 y=80..95)** — + NOT reproduced this round. Disposition: **deferred(tool-call cap)**. +4. **Frame-relative `mi_row > 0` / `mi_col > 0` guards at decode.rs ~8547-8548 and + mvstack.rs ~727,733,742,756,1486,1492,1501,1515** — NOT swept. mvstack has no tile + origin plumbed in at all, so this is a signature change plus a call-site sweep, and + it needs a multi-tile INTER gate to show — the arm that is `#[ignore]`d above for an + unrelated open defect. Disposition: **deferred(next round; needs tile bounds threaded + into mvstack, then the inter multi-tile arm re-enabled to measure)**. diff --git a/lanes/tiles-r12.report.md b/lanes/tiles-r12.report.md new file mode 100644 index 00000000..38b4ac71 --- /dev/null +++ b/lanes/tiles-r12.report.md @@ -0,0 +1,106 @@ +# lane-tiles r12 — the palette gate is live; the refusal it hit was a filter-intra desync + +## Charter item 1: REJECTED, with the measurement (do NOT move `extend(extra)`) +The charter (and r11, and a ledger `constraint|` line) states "aomenc keeps the FIRST +occurrence of a repeated flag". **Measured false.** Same input, one frame, 2 tile columns: + +| args | md5 | size | +|---|---|---| +| `--enable-palette=0 --enable-palette=1` | 34b7fe63… | 299 | +| `--enable-palette=1` alone | 34b7fe63… | 299 | +| `--enable-palette=1 --enable-palette=0` | f8339ae1… | 334 | +| `--enable-palette=0` alone | f8339ae1… | 334 | + +The LAST occurrence wins (libaom `aomenc.c` updates the existing entry in +`config->arg_ctrls` in place). The current order — base list, then `extra` — is already +correct; moving `extra` first would silently disable every per-arm override. Not done, and +the ledger line is corrected below. + +EVIDENCE: /tmp/.../scratchpad/p01.obu,p10.obu,p0.obu,p1.obu | aomenc same y4m, 4 flag orders | md5(p01)==md5(p1), md5(p10)==md5(p0) + +## Root cause of the palette arm's refusal: `use_filter_intra` read after a palette block +With the overrides proven to arrive, the palette arm still refused — and the refusal was a +**correlate, not the defect** ("a HORZ_A/… partition below 16x16" with rect/ab OFF is +impossible; the stream had desynced). Isolation, single tile, identical recipe: +`--enable-palette=0` → `OK: 1 frames decoded`; `--enable-palette=1` → refusal. + +Range ladder (instrumented aomdec `EC_TRACE_MODE_STEP` vs ours) diverges inside the first +16x16 palette block, mi(0,8): both sides agree through `angle_uv` (rng=38738); ours then +reads `use_filter_intra=1` (rng→61700) while libaom reads no such symbol. +`av1_filter_intra_allowed` (blockd.h) requires +`mbmi->palette_mode_info.palette_size[0] == 0` — **libaom writes no `use_filter_intra` +symbol for a Y-palette block**, and we consumed one, desyncing the rest of every +screen-content tile from its first palette block on. + +Fix: `crates/ec-av1/src/decode.rs:5120` — `&& palette_y_pending.is_none()` on the +`use_filter_intra` read. + +Class sweep (`filter_intra_size_class*` call sites): the only other reader is +`read_intra_mode_rect` (decode.rs:3661), which refuses screen content wholesale before any +palette syntax, so no palette block can reach it; the two inter-frame intra sites +(decode.rs:12009, 13109) return `unsupported` the moment palette fires. One site, fixed. + +EVIDENCE: /tmp/.../scratchpad/{w0,w1}.obu + ref2.txt/our2.txt | aomenc palette=0/1, same recipe; EC_TRACE_MODE_STEP ladder both decoders | w0 OK / w1 refused before; both OK after; first divergence mi(0,8) rng 38738: oracle no symbol, ours use_filter_intra=1 + +## Charter item 2: `a_real_aomenc_multi_tile_palette_stream…` un-ignored and GREEN +- `#[ignore]` removed; **6/6 attempts pixel-exact vs ffmpeg, 0 refusals**. +- Per-attempt proof added: new counter `palette_tile_left_hits()` (decode.rs:916, bumped at + decode.rs:5715) counts palette-Y blocks at their own tile's left column; the gate asserts + the delta `>= 1` on every attempt that decoded **and** compared. All 6 attempts pass it. +- Override proof (charter item 1's real intent): every arm now asserts the sequence header's + `enable_cdef && enable_restoration` (the base tools-on recipe arrived), and the palette arm + additionally asserts `allow_screen_content_tools` on every frame header (its own + `--tune-content=screen --enable-palette=1` arrived). + +Mutation test on a scratch copy of decode.rs (restored after each run): +- revert **`left_ok`** alone (`c > 0`) → gate still passes: the tile-left guard is + belt-and-braces, because `start_row` wipes the left palette bands before a tile's first row. +- revert **`left_ok` + `start_row`'s palette clear** → gate FAILS (panic at stream.rs:11465). + So the gate does bind the r11 palette-band fix, and the load-bearing half is the + `start_row` clear, not the `left_ok` guard. Stated rather than claimed the other way. + +EVIDENCE: cargo test output | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib multi_tile -- --test-threads=1`; two mutations of decode.rs re-run | palette arm 6/6 exact; mutation(left_ok) passes, mutation(left_ok+start_row) fails + +## Charter item 3: override-shape sweep of stream.rs +`grep -n "extend(\|\.chain("` near aomenc/ffmpeg arg vectors → 3 sites: +- stream.rs:11234 `run_multi_tile_gate` — extras after base: **correct** (last wins). +- stream.rs:9266 — appends `rate_args`/`depth_args`, no flag repeated with the base list. +- stream.rs:1323 — ffmpeg (`libaom-av1` private options), where a repeated option also takes + the last value (`av_dict_set` overwrite). +Nothing to fix; the shape is safe under last-wins, which is the measured behaviour. + +## Charter item 4: the `#[ignore]`d multi-tile inter arm +Left ignored, with its reproducer. It already carries `--max-partition-size=32 +--enable-tx-size-search=0` (r11), so the charter's suggested flags are the ones it runs with; +the open defect is the seed-42 32x32 block at x[224..255] y[32..63], tile attribution still +unproven. Disposition: **deferred(a decodable single-tile control of the same content)** — +unchanged from r11, no budget spent on it this round. + +## Test totals +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --test-threads=2`: +**283 passed, 0 failed, 26 ignored** (1860.6 s), log `$HOME/.cache/tiles-suite.log`. +Includes `refusal_inventory` (3 tests) and `gate_coverage` (5 tests) green, and all four +live multi-tile arms (`intra`, `intra_10bit`, `inter_10bit`, `palette`) ok; the 8-bit +`multi_tile_inter` arm stays `ignored` with its open-defect reason in the ignore string. + +EVIDENCE: $HOME/.cache/tiles-suite.log | `EC_AV1_REQUIRE_AOMENC=1 nice -n 10 cargo test -p ec-av1 --lib -j3 -- --test-threads=2` | `test result: ok. 283 passed; 0 failed; 26 ignored ... 1860.64s` + +## Charter premise re-measured: main does NOT already carry this fix +The charter said lane-palette2 had fixed "no `use_filter_intra` read on palette-Y blocks" +on main since 3808cf8. **False at main df5d630**: `git show main:crates/ec-av1/src/decode.rs` +has no palette condition on EITHER `use_filter_intra` read (square site ~5367, rect site +~3903) — the branch's `&& palette_y_pending.is_none()` is not a duplicate and main still +needs it. The rect site is unreachable for palette content (it refuses +`allow_screen_content_tools` wholesale at decode.rs:3596), so one guarded site is the whole +class, as the r12 sweep said. + +## r12 restart (the first r12 agent was killed mid-report) +Its commit 99f0091 was complete and the tree was clean; this round finished the suite run, +the main-duplication check above, and one cosmetic fix: the two new override asserts had a +missing `\` line continuation, so their panic messages carried 30 spaces mid-sentence +(`stream.rs:11284`, `stream.rs:11304`). + +## Files changed +- `crates/ec-av1/src/decode.rs` — filter-intra/palette gating fix; `PALETTE_TILE_LEFT_HITS`. +- `crates/ec-av1/src/stream.rs` — palette arm un-ignored; per-attempt tile-left palette + assert; sequence-header + screen-tools override proofs on every arm.