diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e94489a1..ca8a5c6d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1162,6 +1162,34 @@ pub(crate) fn edge_rect_strip_hits() -> usize { EDGE_RECT_STRIP_HITS.with(|c| c.get()) } +// lane-edgeboth r1: how many partition nodes were coded as the BOTH-AXES-CUT +// forced split -- libaom `decode_partition` (decodeframe.c): +// `else if (!has_rows && !has_cols) partition = PARTITION_SPLIT;`, the one +// straddle case that reads NO symbol at all. Indexed by level: +// 0 = 16x16, 1 = 32x32, 2 = 64x64, 3 = 128x128; intra and inter share it. +thread_local! { + static EDGE_BOTH_CUT_HITS: std::cell::Cell<[usize; 4]> = + const { std::cell::Cell::new([0; 4]) }; +} + +fn bump_edge_both_cut(level: usize) { + EDGE_BOTH_CUT_HITS.with(|c| { + let mut v = c.get(); + v[level] += 1; + c.set(v); + }); +} + +/// Current value of [`EDGE_BOTH_CUT_HITS`] (`[16, 32, 64, 128]` levels). +pub(crate) fn edge_both_cut_hits() -> [usize; 4] { + EDGE_BOTH_CUT_HITS.with(|c| c.get()) +} + +/// Zeroes [`EDGE_BOTH_CUT_HITS`] so a gate can measure a per-attempt delta. +pub(crate) fn reset_edge_both_cut_hits() { + EDGE_BOTH_CUT_HITS.with(|c| c.set([0; 4])); +} + // How many HORZ/VERT intra strips resolved a SPLIT luma transform // (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) -- // the case every rect path here refused by name before, and the first @@ -13095,6 +13123,7 @@ fn read_sb128_root( } _ => { PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1)); + bump_edge_both_cut(3); PARTITION_SPLIT } } @@ -13431,7 +13460,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( bump_edge_part(b.min(1) as usize); if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } } - _ => PARTITION_SPLIT, + _ => { + bump_edge_both_cut(2); + PARTITION_SPLIT + } } }; match part { @@ -13507,7 +13539,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( bump_edge_part(2 + b.min(1) as usize); if b == 1 { PARTITION_SPLIT } else { PARTITION_VERT } } - _ => PARTITION_SPLIT, + _ => { + bump_edge_both_cut(1); + PARTITION_SPLIT + } } }; match part32 { @@ -13963,13 +13998,23 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // leaf never itself straddles, so the // block splits cleanly along whichever // axis is short. + // lane-edgeboth r1: when the true frame + // edge cuts BOTH axes libaom's + // `decode_partition` takes + // `else if (!has_rows && !has_cols) + // partition = PARTITION_SPLIT;` -- no + // symbol of any kind is read, and the four + // 8x8 children are then visited by the + // same loop below, whose + // `mr < mi_rows && mc < mi_cols` filter IS + // libaom's own + // `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` + // early return, so the three out-of-frame + // quadrants get no neighbour or tx-grid + // write. if !has_cols16 && !has_rows16 { - return Err(unsupported( - "a 16x16 block whose true edge cuts through both \ - axes needs a rectangular transform this decoder \ - does not code yet", - )); - } + bump_edge_both_cut(0); + } else { // lane-golomb r1 (class // `parsed-then-discarded`): the gathered // bit IS the partition -- 0 names @@ -14032,6 +14077,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( neighbours.left_mode[sr] = mode; continue; } + } let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); let leaf_positions: Vec<(u32, u32)> = (0..4) @@ -21180,7 +21226,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( PARTITION_VERT } } - (false, false) => PARTITION_SPLIT, + (false, false) => { + bump_edge_both_cut(2); + PARTITION_SPLIT + } }; if part64 == PARTITION_NONE { // lane-inter8 r1: the whole superblock as one 64x64 inter @@ -21365,7 +21414,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( PARTITION_VERT } } - _ => PARTITION_SPLIT, + _ => { + bump_edge_both_cut(1); + PARTITION_SPLIT + } } }; match part32 { @@ -21430,13 +21482,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), ); - if !has_cols16 && !has_rows16 { - return Err(unsupported( - "a 16x16 inter block whose true edge cuts through both \ - axes needs a rectangular transform this decoder does \ - not code yet", - )); - } let at16 = (sr, sc); let ctx16 = neighbours.partition_ctx(at16, SUB); // lane-inter8 r1: a straddling 16x16 cannot name a @@ -21456,6 +21501,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); } p + } else if !has_cols16 && !has_rows16 { + // lane-edgeboth r1: both axes cut by the true + // frame edge -- libaom `decode_partition` + // forces PARTITION_SPLIT and reads NO symbol; + // the leaf loop below already drops the + // out-of-frame quadrants. + bump_edge_both_cut(0); + PARTITION_SPLIT } else { if has_cols16 { // lane-golomb r1 (class `parsed-then-discarded`): the gathered diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index bd4793af..750aa833 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -35,8 +35,6 @@ const REFUSALS: &[&str] = &[ "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", - "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", - "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", "a Golomb tail longer than this decoder reads", "a tx_type symbol outside its CDF's own set: {t}", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index f93f98e2..1f881cf5 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -14274,6 +14274,268 @@ mod tests { crate::decode::cdef_idx_hits() ); } + /// lane-edgeboth r1 GATE: frame sizes whose width AND height are both + /// 8 mod 16, so the bottom-right corner of the frame is a partition node + /// with `has_rows == false && has_cols == false` at every level it + /// reaches -- libaom `decode_partition` forces PARTITION_SPLIT there and + /// reads NO symbol (`else if (!has_rows && !has_cols) partition = + /// PARTITION_SPLIT;`), then drops the out-of-frame children on its + /// `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` early return. + /// The 64 and 32 levels already inferred that split; the 16 level refused + /// by name until r1, on both the intra (key) and the inter path -- so both + /// arms are swept here. Every compared attempt must show a 16-level + /// both-cut hit, and the sweep must show 32- and 64-level hits too (200x72 + /// puts all three levels in that state: mi_cols 50, mi_rows 18, so the + /// nodes at mi (16,48) of size 64, 32 and 16 are all cut on both axes). + #[test] + fn a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact() { + both_axes_cut_sweep( + "a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact", + ("key", 1, "--kf-max-dist=0", "--limit=1"), + ); + } + + /// lane-edgeboth r1, INTER half of the same lift. `#[ignore]`d, and the + /// reason is MEASURED, not assumed: the inter path's both-cut corner block + /// itself decodes exactly (200x72 inter cq 32, luma diff bounding box rows + /// 64..=71 cols 15..=186 -- the corner at cols 192..=199 is clean), but the + /// bottom 8-row frame-edge BAND of an inter frame is wrong, and the + /// control 192x72 (width a multiple of 16, so zero both-cut nodes: hits + /// [0,0,0,0]) fails identically at rows 64..=71 cols 8..=188. That band is + /// the forced one-axis HORZ half strip on the inter path -- lane-oddh's + /// own inter gate is `#[ignore]`d for the same arm -- so this gate turns + /// green with that defect, not with anything this lane changed. + #[test] + #[ignore = "2026-09-02 lane-edgeboth r1: blocked by the pre-existing inter frame-edge half-strip band defect, not by the both-cut corner -- control 192x72 (zero both-cut hits) mismatches identically at rows 64..=71"] + fn a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact() { + both_axes_cut_sweep( + "a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact", + ("inter", 6, "--kf-max-dist=9999", "--limit=6"), + ); + } + + fn both_axes_cut_sweep( + name: &'static str, + (arm, frames, kf_arg, limit_arg): (&str, usize, &str, &str), + ) { + // Kept upper-case so every message string below reads the same as in + // the sibling gates. + #[allow(non_snake_case)] + let NAME = name; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() || !have_aomenc() { + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); + return; + } + let sizes: &[(usize, usize)] = &[(200, 72), (136, 104), (264, 136), (72, 200), (104, 136)]; + let mut compared = 0u32; + let mut refusals: Vec = Vec::new(); + let mut totals = [0usize; 4]; + for &(width, height) in sizes { + let mut size_compared = 0u32; + { + for bit_depth in [8u32, 10u32] { + // cq 58 is left out on purpose: measured r1, it is where + // libaom starts answering the frame-edge gathered symbol + // with a rect strip and other lanes' refusals fire first + // ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs + // rectangular residual coding"). + for cq in [32u32, 45] { + let source = format!("mandelbrot=size={width}x{height}:rate=25"); + // Feed exactly `frames` frames: --limit=1 makes + // aomenc stop reading after the first one and the + // y4m write then dies on a broken pipe. + let dur = format!("{}", frames as f64 / 25.0); + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-t", &dur, + "-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(), + "{NAME}: ffmpeg refused the {width}x{height} {bit_depth}-bit \ + fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let depth_arg = format!("--bit-depth={bit_depth}"); + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); + let cq_arg = format!("--cq-level={cq}"); + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, + // cpu-used >= 1 keeps libaom on 64x64 + // superblocks at these sizes + // (`av1_select_sb_size`). + "--cpu-used=4", "--threads=1", "--row-mt=0", + // --lag-in-frames=0: no hidden alt-ref, so + // decode order == display order and the + // compare below covers every frame the stream + // carries (class gate-blind-to-hidden-frames). + kf_arg, limit_arg, "--lag-in-frames=0", + &depth_arg, &input_depth_arg, + // Other lanes' named refusals this recipe must + // not trip. The both-cut corner is FORCED down + // to 8x8 leaves, which is exactly where the + // 8x8-intra-leaf-in-an-inter-frame gaps live, + // so the intra tool set and tx-size search are + // pinned off: without them 30/30 inter + // attempts refused (measured r1) on "a nonzero + // angle delta on an 8x8 intra leaf in an inter + // frame", "a non-DC chroma mode on an 8x8 + // inter-frame leaf" and "an 8x8 intra leaf in + // an inter frame whose tx_depth splits it into + // 4x4 transform units". + "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=8", "--max-partition-size=64", + "--enable-palette=0", "--enable-intrabc=0", + "--enable-warped-motion=0", "--enable-obmc=0", + "--enable-masked-comp=0", "--enable-interintra-comp=0", + "--enable-onesided-comp=0", "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0", + "--enable-angle-delta=0", "--enable-cfl-intra=0", + "--enable-directional-intra=0", "--enable-smooth-intra=0", + "--enable-paeth-intra=0", "--enable-filter-intra=0", + "--enable-tx-size-search=0", + "--obu", "-o", "-", "-", + ]) + .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("write y4m"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + + // Reset, never a delta across attempts: a refused + // attempt's hits must not count (class + // counter-from-refused-stream). + crate::decode::reset_edge_both_cut_hits(); + let decoded = match decode_stream(&stream) { + Ok(f) => f, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ + failed outright, not a named refusal: {msg}" + ); + eprintln!( + " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ + REFUSED {msg}" + ); + refusals.push(msg); + continue; + } + }; + let hits = crate::decode::edge_both_cut_hits(); + let reference = if bit_depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frames) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames) + }; + assert_eq!( + decoded.len(), + frames, + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded {} \ + frames, expected {frames}", + decoded.len() + ); + assert_eq!( + reference.len(), + frames, + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} reference \ + frame count" + ); + for (i, (ours, theirs)) in decoded.iter().zip(&reference).enumerate() { + let nd = + |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count(); + // Where a mismatch lands is the whole diagnosis + // here (corner block vs elsewhere), so print the + // luma bounding box before the assert kills the run. + if nd(&ours.y, &theirs.y) > 0 { + let (mut r0, mut c0, mut r1, mut c1) = + (usize::MAX, usize::MAX, 0usize, 0usize); + for row in 0..height { + for col in 0..width { + if ours.y[row * width + col] != theirs.y[row * width + col] { + r0 = r0.min(row); + c0 = c0.min(col); + r1 = r1.max(row); + c1 = c1.max(col); + } + } + } + eprintln!( + " {NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} \ + frame {i} luma diff bbox rows {r0}..={r1} cols {c0}..={c1}" + ); + } + assert_eq!( + ( + nd(&ours.y, &theirs.y), + nd(&ours.u, &theirs.u), + nd(&ours.v, &theirs.v) + ), + (0, 0, 0), + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} frame \ + {i} differs from ffmpeg" + ); + } + // Every compared attempt must carry the case, so no + // compared attempt is out of scope and + // out_of_scope_mismatch is 0 by construction. + assert!( + hits[0] > 0, + "{NAME}: {width}x{height} {arm} {bit_depth}-bit cq {cq} decoded \ + pixel-exact but no 16-level both-axes-cut block fired \ + (hits={hits:?}) -- the recipe no longer reaches the lifted arm" + ); + for l in 0..4 { + totals[l] += hits[l]; + } + compared += 1; + size_compared += 1; + } + } + } + assert!( + size_compared > 0, + "{NAME}: every {width}x{height} attempt refused -- that size proved nothing" + ); + } + assert!( + totals[1] > 0 && totals[2] > 0, + "{NAME}: no 32-level ({}) or 64-level ({}) both-axes-cut node fired -- 200x72 puts \ + both in that state, so the sweep stopped reaching them", + totals[1], + totals[2] + ); + eprintln!( + "{NAME}: {compared} attempts pixel-exact over {} sizes ({arm} arm), \ + out_of_scope_mismatch=0, both_cut hits [16,32,64,128]={totals:?}, {} named refusals", + sizes.len(), + refusals.len() + ); + } + /// lane-tiny r4 GATE (was r1's `#[ignore]`d probe): every tiny key-frame /// size real aomenc will encode, decoded pixel-exact against ffmpeg. /// Tiny frames are where every edge/partial-superblock corner case is