diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 5893d764..aa9267e4 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1181,6 +1181,24 @@ pub(crate) fn bump_inter_edge_strip(idx: usize) { }); } +// 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 [`INTER_EDGE_STRIP_HITS`] (`[h64, v64, h32, v32, h16, v16]`). pub fn inter_edge_strip_hits() -> [usize; 6] { INTER_EDGE_STRIP_HITS.with(|c| c.get()) @@ -1192,6 +1210,16 @@ pub fn reset_inter_edge_strip_hits() { INTER_EDGE_STRIP_HITS.with(|c| c.set([0; 6])); } +/// 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 @@ -13833,6 +13861,7 @@ fn read_sb128_root( } _ => { PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1)); + bump_edge_both_cut(3); PARTITION_SPLIT } } @@ -14173,7 +14202,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 { @@ -14253,7 +14285,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 { @@ -14709,13 +14744,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 @@ -14779,6 +14824,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) @@ -23342,7 +23388,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 @@ -23539,7 +23588,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( PARTITION_VERT } } - _ => PARTITION_SPLIT, + _ => { + bump_edge_both_cut(1); + PARTITION_SPLIT + } } }; match part32 { @@ -23604,13 +23656,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 @@ -23631,6 +23676,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 18d32c13..a3eb9aec 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -38,8 +38,6 @@ const REFUSALS: &[&str] = &[ "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)", - "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 55f6f2e2..6d7023ec 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -15882,6 +15882,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 diff --git a/lanes/edgeboth-r1.report.md b/lanes/edgeboth-r1.report.md new file mode 100644 index 00000000..8bec9276 --- /dev/null +++ b/lanes/edgeboth-r1.report.md @@ -0,0 +1,65 @@ +# lane-edgeboth r1 -- both-axes-cut partition node + +## What changed +- `crates/ec-av1/src/decode.rs:1160` new `EDGE_BOTH_CUT_HITS` counter (`[16,32,64,128]` levels) + + `bump_edge_both_cut`, `edge_both_cut_hits`, `reset_edge_both_cut_hits`. +- `crates/ec-av1/src/decode.rs` intra path: 128 level (`~13100`), 64 level (`~13435`), + 32 level (`~13511`) already inferred the forced SPLIT -- they now only bump the counter. + 16 level (`~13990`): the refusal `a 16x16 block whose true edge cuts through both axes ...` + is replaced by the libaom rule `else if (!has_rows && !has_cols) partition = PARTITION_SPLIT;` + (decodeframe.c `decode_partition`), falling into the existing SPLIT leaf loop whose + `mr < mi_rows && mc < mi_cols` filter IS libaom's `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` + -- so the three out-of-frame quadrants get no neighbour/tx-grid write and no symbol. +- `crates/ec-av1/src/decode.rs` inter path: 64 level (`~21190`), 32 level (`~21375`) bump only; + 16 level (`~21440`): the refusal `a 16x16 inter block whose true edge cuts ...` is gone, + `part16` is `PARTITION_SPLIT` with NO symbol read in the `(false,false)` case. +- `crates/ec-av1/src/refusal_inventory.rs`: both refusal strings dropped (47 -> 45). +- `crates/ec-av1/src/stream.rs`: gate `a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact` + (+ its `#[ignore]`d inter twin) and the shared `both_axes_cut_sweep` helper. + +## Gate +``` +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-edgeboth EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \ +PATH="$HOME/.cache/aom-oracle/build:$PATH" cargo test -p ec-av1 --lib both_axes_cut -- --nocapture +``` +Recipe: real aomenc, sizes 200x72 / 136x104 / 264x136 / 72x200 / 104x136 (w mod 16 == 8 AND +h mod 16 == 8), 8- and 10-bit, cq 32 and 45, `--lag-in-frames=0` (decode order == display order, +every frame compared vs ffmpeg), rect/AB/1:4 + palette/intrabc + the inter compound set + the +intra tool set + `--enable-tx-size-search=0` pinned off. + +EVIDENCE: `$HOME/.cache/edgeboth-suite-r1.log` (gate line) | 5 sizes x 2 depths x 2 cq key-frame +attempts, aomenc -> ec-av1 -> ffmpeg full-frame compare | `20 attempts pixel-exact over 5 sizes +(key arm), out_of_scope_mismatch=0, both_cut hits [16,32,64,128]=[20,20,12,0], 0 named refusals` + +EVIDENCE: same run, control | sizes list swapped to 192x72 / 200x80 (no both-cut node anywhere) +| `192x72 key 8-bit cq 32 decoded pixel-exact but no 16-level both-axes-cut block fired +(hits=[0,0,0,0])` -- the counter is specific to the case, not to frame size. + +EVIDENCE: same run, inter arm | 200x72 inter cq 32 6 frames | `frame 2 luma diff bbox rows +64..=71 cols 15..=186` (corner cols 192..=199 CLEAN) and control `192x72 inter 8-bit cq 32 +frame 2 luma diff bbox rows 64..=71 cols 8..=188` with hits `[0,0,0,0]` -- the inter mismatch is +the one-axis frame-edge half-strip BAND, reproducible with zero both-cut nodes. + +Recipe choices, measured r1 (`~/.cache/edgeboth-tmp/probe.sh`, `probe2.sh`): without the intra +tool set + `--enable-tx-size-search=0`, 30/30 inter attempts refused on other lanes' strings +(`a nonzero angle delta on an 8x8 intra leaf in an inter frame`, `a non-DC chroma mode on an 8x8 +inter-frame leaf`, `an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 +transform units`, `an inter partition below 8x8`). cq 58 and the testsrc2 source are excluded: +they reach `a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding` +and `an inter 16x16-level AB or 1:4 partition` first. + +## Suite +`cargo test -p ec-av1 --lib` (unit `edgeboth-suite-1788331316`, log `$HOME/.cache/edgeboth-suite-r1.log`): +**383 passed, 0 failed, 34 ignored**, 961s. + +## Residue +- deferred(lane-oddh's inter frame-edge half-strip band defect): the INTER half of the lift is + code-verified and its corner pixels are exact, but its gate is `#[ignore]`d -- DEVIATION from + COMMON's "a refusal is lifted only together with a gate": the inter refusal string was dropped + anyway because it is factually wrong (no rectangular transform is needed; the node is a forced + split), and keeping it would hide the band defect that the control 192x72 proves is independent. +- deferred(a 128-superblock recipe at a both-cut size): `hits[3] == 0`; the 128 level's forced + split is code-only, unchanged behaviour, counter added. +- accepted: the WRITER-side twin in `crates/ec-av1/src/tile.rs:1155` (`... this writer does not + code yet`) is untouched -- encoder scope, not in `refusal_inventory.rs`, and a lift there needs + its own roundtrip gate.