diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index f7ca80b9..b2131d88 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2673,6 +2673,41 @@ thread_local! { static SUB8_SPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; } +// lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all +// four of their mi cells are `skip_txfm` (libaom `cdef.c:29-38` +// `is_8x8_block_skip` / `av1_cdef_compute_sb_list`'s dlist test), and (b) how +// many 8x8 inter leaves (`decode_inter_block8`) wrote that skip band at all. +// (b) was 0 for every stream before this round -- the leaf path never touched +// the band, so an all-skip 8x8 group kept the PREVIOUS frame's flags and got +// filtered where libaom skips it. A gate asserts both are non-zero. +thread_local! { + static CDEF_SKIPPED_UNITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static INTER8_SKIP_BAND_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + // lane-cdef r2: (c) 8x8 CDEF units that are FILTERED and whose extent + // crosses the cropped frame edge -- the only units for which "clamp at + // the crop" and "pad past the mi-rounded extent with CDEF_VERY_LARGE" + // (libaom `cdef.c:249-256`, `cdef_prepare_fb`'s hsize/vsize are + // `nhb << mi_wide_l2` off the MI grid, not the crop) differ. A frame + // whose width or height is not a multiple of 8 is the only shape that + // produces one; the straddling-band gate arms assert it grew. + static CDEF_STRADDLE_UNITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of `CDEF_SKIPPED_UNITS`. +pub(crate) fn cdef_skipped_units() -> usize { + CDEF_SKIPPED_UNITS.with(|c| c.get()) +} + +/// Current value of `INTER8_SKIP_BAND_HITS`. +pub(crate) fn inter8_skip_band_hits() -> usize { + INTER8_SKIP_BAND_HITS.with(|c| c.get()) +} + +/// Current value of `CDEF_STRADDLE_UNITS`. +pub(crate) fn cdef_straddle_units() -> usize { + CDEF_STRADDLE_UNITS.with(|c| c.get()) +} + /// Current value of [`SUB8_SPLIT_HITS`]. pub(crate) fn sub8_split_hits() -> usize { SUB8_SPLIT_HITS.with(|c| c.get()) @@ -9304,13 +9339,12 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { /// matches aomdec's own `ec_dump16` rung byte for byte (crop dims, u16 LE). fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { use std::io::Write; - // lane-sbrect10 r2: index the dump by decode-order picture like - // EC_AV1_PREFILT_DUMP already does -- a fixed `.f0` name kept only the - // LAST frame, so a mid-sequence divergence could not be read out at all. - static STAGE16_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by + // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed + // `.f0` name kept only the LAST frame, so a mid-sequence divergence could + // not be read out at all. if let Ok(path) = std::env::var(var) - && let idx = STAGE16_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst) - && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) { for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] { for row in 0..h { @@ -9324,24 +9358,25 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, } } +/// Decode-order index of the next [`dump_stage`]/[`dump_stage16`] file for a +/// given env var -- lane-cdef r1: both used to write `.f0` unconditionally, so +/// every frame overwrote the previous one and only the LAST frame survived, +/// which silently defeats any per-frame filter-stage bisection. +fn dump_stage_idx(var: &str) -> usize { + use std::collections::HashMap; + use std::sync::{Mutex, OnceLock}; + static IDX: OnceLock>> = OnceLock::new(); + let mut m = IDX.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); + let e = m.entry(var.to_string()).or_insert(0); + let i = *e; + *e += 1; + i +} + fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { use std::io::Write; - // lane-golomb r6: one file per DECODE-order picture, like aomdec's own - // `ec_dump16` static index -- a single `.f0` overwritten every frame made - // the post-deblock stage uncomparable across a sequence. - thread_local! { - static STAGE_IDX: std::cell::RefCell> = - std::cell::RefCell::new(std::collections::HashMap::new()); - } - let idx = STAGE_IDX.with(|m| { - let mut m = m.borrow_mut(); - let e = m.entry(var.to_string()).or_insert(0); - let i = *e; - *e += 1; - i - }); if let Ok(path) = std::env::var(var) - && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) { for p in [y, u, v] { let narrow: Vec = p.data.iter().map(|&s| s as u8).collect(); @@ -10854,6 +10889,7 @@ fn decode_leaf8( neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); } + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); neighbours.fill_skip_grid(leaf_mi, 2, skip); // lane-kf900 r1: the leaf's own RESOLVED transform size, never the literal // block side. libaom calls `set_txfm_ctxs(mbmi->tx_size, ..., skip_txfm && @@ -13236,6 +13272,9 @@ fn apply_cdef( v: &mut PlaneBuf, cdef: &CdefParams, skip_grid: &Neighbours, + // This frame header's own CROPPED luma size, for the straddling-unit + // counter only -- CDEF itself walks the mi-rounded plane. + (frame_w, frame_h): (usize, usize), ) { // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling. if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() { @@ -13279,6 +13318,9 @@ fn apply_cdef( while mi_r < skip_grid.mi_rows { let mut mi_c = 0usize; while mi_c < skip_grid.mi_cols { + if skip_grid.is_skip_txfm(mi_r, mi_c) { + CDEF_SKIPPED_UNITS.with(|c| c.set(c.get() + 1)); + } if !skip_grid.is_skip_txfm(mi_r, mi_c) { let sidx = strength_idx(mi_r, mi_c); let (ox, oy) = (mi_c * 4, mi_r * 4); @@ -13291,10 +13333,15 @@ fn apply_cdef( i32::from(src_y[ny as usize * y_stride + nx as usize]) } }; - let (dir, var) = cdef_find_dir(coeff_shift, |r, c| { - let (ny, nx) = ((oy + r).min(y_true_h - 1), (ox + c).min(y_true_w - 1)); - i32::from(src_y[ny * y_stride + nx]) - }); + // lane-cdef r1: the direction search reads the SAME padded + // block the taps do -- libaom runs `cdef_find_dir` on the + // prepared filter block (`cdef_block.c:296-320` over + // `cdef_prepare_fb`'s buffer, `cdef.c:249-256`), whose columns + // and rows past the mi-rounded frame extent are CDEF_VERY_LARGE. + // Clamping to the last real sample instead made every straddling + // edge 8x8 (odd `mi_cols`/`mi_rows`) pick a different var, hence + // a different `adjust_strength`, hence a +-1 band at the crop edge. + let (dir, var) = cdef_find_dir(coeff_shift, |r, c| sample_y(r as i32, c as i32)); // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` // -- each plane zeroes the shared direction when *its own* @@ -13304,8 +13351,22 @@ fn apply_cdef( let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; let y_dir = if y_pri_strength != 0 { dir } else { 0 }; let t = cdef_adjust_strength(y_pri_strength, var); + // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit. + if std::env::var_os("EC_AV1_CDEF_DBG").is_some() { + eprintln!( + "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}" + ); + } let enable_primary = t != 0; let enable_secondary = y_sec_strength != 0; + if (ox + 8 > frame_w || oy + 8 > frame_h) + && (enable_primary + || enable_secondary + || cdef.uv_pri_strength[sidx] != 0 + || cdef.uv_sec_strength[sidx] != 0) + { + CDEF_STRADDLE_UNITS.with(|c| c.set(c.get() + 1)); + } if enable_primary || enable_secondary { cdef_filter_block( sample_y, @@ -15444,7 +15505,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); - apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); + apply_cdef( + &mut y, + &mut u, + &mut v, + cdef, + &neighbours, + (frame_width as usize, frame_height as usize), + ); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_loop_restoration( @@ -20423,6 +20491,14 @@ fn decode_inter_block8( // so the 16x16 below a split block read partition ctx 0 // instead of 1 and mis-read PARTITION_SPLIT as NONE. neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); + // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s + // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi + // cells of the 8x8; this leaf wrote none of them, so a 64x64 + // whose bottom-right 16x16 is an all-skip 8x8-leaf group kept + // the PREVIOUS frame's flags and got filtered where libaom's + // dlist excludes it (3 luma samples on a 192x128 inter frame). + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); + neighbours.fill_skip_grid(leaf_mi, 2, skip); neighbours.fill_lf_grid( leaf_mi, 2, @@ -21228,6 +21304,10 @@ fn decode_inter_block8( // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). + // lane-cdef r1: the fall-through twin of the compound arm's skip-band + // write above -- `skip` is one flag for the whole 8x8 leaf (read at + // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform. + neighbours.fill_skip_grid(leaf_mi, 2, skip); neighbours.fill_lf_grid( leaf_mi, 2, @@ -23560,7 +23640,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // dump above these bisect WHICH filter stage introduced a mismatch. dump_stage("EC_AV1_POSTDEBLOCK_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTDEBLOCK_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); - apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); + apply_cdef( + &mut y, + &mut u, + &mut v, + cdef, + &neighbours, + (frame_width as usize, frame_height as usize), + ); dump_stage("EC_AV1_POSTCDEF_DUMP", &y, &u, &v); dump_stage16("EC_AV1_POSTCDEF_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize); apply_loop_restoration( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index e8656a70..39951086 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -16655,6 +16655,151 @@ mod tests { ); } + /// lane-cdef r1: CDEF's per-8x8 skip band under sub-16x16 inter leaves. + /// + /// `apply_cdef` excludes an 8x8 luma unit whose four mi cells are all + /// `skip_txfm` (libaom `cdef.c:29-38 is_8x8_block_skip`, called from + /// `av1_cdef_compute_sb_list`'s dlist loop). `decode_inter_block8` -- the + /// leaf path `--min-partition-size=4` makes aomenc pick for a 16x16 group + /// -- wrote the loop-filter grid but never that skip band, so an all-skip + /// group kept the PREVIOUS frame's flags and got filtered where libaom + /// skips it (3 luma samples, decode-order frames 3 and 4 of the 192x128 + /// cq-8 stream below, at the frame's last 8x8 column). + /// + /// Both counters are hard asserts per compared attempt: `cdef_skipped_units` + /// proves the all-skip dlist exclusion was actually reached, and + /// `inter8_skip_band_hits` proves the 8x8 leaf path (the writer that used + /// to be missing) ran on the same stream. + #[test] + fn a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact() { + if !have_aomenc() { + return; + } + let (width, height, frames) = (192usize, 128usize, 6usize); + let mut refusals: Vec = Vec::new(); + let mut fired = 0u32; + for (depth, cq, sp) in [(8u32, 8u32, 3u32), (8, 10, 3), (8, 12, 6), (10, 8, 3), (10, 12, 6)] { + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; + let src = format!( + "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ + geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p" + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &src, "-t", "0.24", "-pix_fmt", pix, + "-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 mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + &format!("--cq-level={cq}"), + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + &format!("--bit-depth={depth}"), + &format!("--input-bit-depth={depth}"), + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--lag-in-frames=0", + "--enable-obmc=0", + "--enable-tx-size-search=1", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=4", + "--max-partition-size=16", + // Last occurrence of a repeated --enable-* flag wins + // (aomenc-last-flag-wins): CDEF stays ON, and the two + // counters below prove the filter really ran. + "--enable-cdef=1", + "--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("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture (depth={depth} cq={cq})" + ); + let stream = out.stdout; + let skipped_before = decode::cdef_skipped_units(); + let leaves_before = decode::inter8_skip_band_hits(); + let decoded = match decode_stream(&stream) { + Ok(f) => f, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.starts_with("unsupported: "), + "decode error that is not a named refusal \ + (depth={depth} cq={cq}): {msg}" + ); + refusals.push(format!("depth={depth} cq={cq}: {msg}")); + continue; + } + }; + assert_eq!(decoded.len(), frames, "frame count (depth={depth} cq={cq})"); + assert!( + decode::cdef_skipped_units() > skipped_before, + "no 8x8 CDEF unit was excluded by the all-skip rule \ + (depth={depth} cq={cq})" + ); + assert!( + decode::inter8_skip_band_hits() > leaves_before, + "no sub-16x16 inter leaf wrote the CDEF skip band \ + (depth={depth} cq={cq})" + ); + let reference = if depth == 10 { + ffmpeg_decode_sequence_10bit(&stream, width, height, frames) + } else { + ffmpeg_decode_sequence(&stream, width, height, frames) + }; + for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() { + assert_eq!(ours.y, theirs.y, "luma frame {i} (depth={depth} cq={cq})"); + assert_eq!(ours.u, theirs.u, "U frame {i} (depth={depth} cq={cq})"); + assert_eq!(ours.v, theirs.v, "V frame {i} (depth={depth} cq={cq})"); + } + fired += 1; + } + // Three of the five arms land on OTHER open refusals (a non-DC chroma + // mode on an 8x8 inter leaf; inter partitions below 8x8) -- the two + // 8-bit cq 8/10 arms ARE the streams the defect was found on, and each + // hard-asserts both counters plus all six frames on all three planes. + assert!( + fired >= 2, + "fewer than 2 firing+pixel-exact attempts:\n{}", + refusals.join("\n") + ); + } + /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients /// at low cq reliably makes aomenc split an 8x8 block all the way to /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec @@ -20578,10 +20723,36 @@ mod tests { /// `frame_width` clip, is correct. /// * The divergence therefore enters in CDEF, at the last 8x8 CDEF block /// column/row, which is the one that straddles the crop edge. - /// `#[ignore]` so the suite stays green; run it with - /// `cargo test -p ec-av1 --lib -- --ignored a_frame_edge_straddling_band`. + /// lane-cdef r2: CLOSED, and un-ignored. r1 rooted the luma half in + /// `apply_cdef`'s direction search, which clamped at the CROPPED frame + /// edge while libaom runs `cdef_find_dir` over `cdef_prepare_fb`'s buffer + /// -- whose columns/rows past the MI-ROUNDED extent (`hsize = nhb << + /// mi_wide_l2`, `cdef.c:164-167`, and the `frame_boundary[RIGHT]` + /// CDEF_VERY_LARGE fill at `cdef.c:249-256`) are CDEF_VERY_LARGE, not the + /// last real sample. The chroma half was lane-golomb r8's loop-restoration + /// plane size (LR is the one post-decode filter sized by the CROP, not the + /// mi grid) plus its reference-size fix; merging both branches takes all + /// four arms to 0 differing pixels on Y, U and V. + /// + /// Arms: 192x68 and 68x192 (a 4-px straddling band on one axis), 5 frames, + /// 8-bit and 10-bit, plus a `--tile-columns=1` twin of each (COMMON's + /// neighbour-map rule -- the skip band CDEF reads is a per-mi side band). + /// MEASURED 2026-09-02: all 32 multi-tile attempts refuse BY NAME today, + /// so that half of the gate compares nothing yet (class + /// `counter-from-refused-stream`); the census is 10x "an inter SB-level AB + /// partition", 6x "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs + /// rectangular residual coding", 6x "an 8x8 intra leaf in an inter frame + /// whose tx_depth splits it into 4x4 transform units", 5x "an inter + /// partition below 8x8", 3x "an inter 16x16-level AB or 1:4 partition", + /// 1x "a split intra strip whose transform unit is 32x64", 1x "an + /// intra-coded 1:4 (or other non-2:1) rect strip on the inter block path". + /// The arms stay so the coverage appears the day those lift; every assert + /// below is carried by the single-tile arms. + /// Hard-asserts `decode::cdef_straddle_units()` grew: a FILTERED 8x8 CDEF + /// unit whose extent crosses the crop edge is the only shape for which + /// clamping and padding differ, so a zero delta would make these arms + /// vacuous for this defect. #[test] - #[ignore = "open r9 defect: CDEF at the last straddling 8x8 block column/row"] fn a_frame_edge_straddling_band_decodes_pixel_exact() { edge32_gate( "a_frame_edge_straddling_band_decodes_pixel_exact", @@ -20600,15 +20771,15 @@ mod tests { eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); return; } - // (width, height, frames, ten_bit) - let mut arms: Vec<(usize, usize, usize, bool)> = Vec::new(); + // (width, height, frames, ten_bit, tile_columns_log2) + let mut arms: Vec<(usize, usize, usize, bool, u32)> = Vec::new(); for &(w, h) in &[(192usize, 80usize), (80usize, 192usize)] { - arms.push((w, h, 1, false)); - arms.push((w, h, 1, true)); + arms.push((w, h, 1, false, 0)); + arms.push((w, h, 1, true, 0)); } // The inter arm: >= 4 frames so the 32-level edge path in the INTER // tile walk is exercised too. - arms.push((192, 80, 5, false)); + arms.push((192, 80, 5, false, 0)); // lane-golomb r9: the straddling-band arms, only under the ignored // `a_frame_edge_straddling_band_decodes_pixel_exact` name (they are // RED -- see that test's own comment for the stage bisection). Naming @@ -20616,10 +20787,12 @@ mod tests { // recipe, the counters and the refusal handling identical. if name == "a_frame_edge_straddling_band_decodes_pixel_exact" { arms.clear(); - arms.push((192, 68, 5, false)); - arms.push((192, 68, 5, true)); - arms.push((68, 192, 5, false)); - arms.push((68, 192, 5, true)); + for &tile_cols in &[0u32, 1] { + arms.push((192, 68, 5, false, tile_cols)); + arms.push((192, 68, 5, true, tile_cols)); + arms.push((68, 192, 5, false, tile_cols)); + arms.push((68, 192, 5, true, tile_cols)); + } } // lane-golomb r8 MEASURED, arm STILL NOT added (every cq level is // vacuous, panicking or red -- each measured this round with @@ -20660,7 +20833,9 @@ mod tests { let mut totals = [0usize; 8]; let mut compared = 0usize; let mut refusals: Vec = Vec::new(); - for &(width, height, frame_count, ten_bit) in &arms { + let straddle = name == "a_frame_edge_straddling_band_decodes_pixel_exact"; + let mut straddle_units = 0usize; + for &(width, height, frame_count, ten_bit, tile_cols) in &arms { for &cq in &cqs { let duration = frame_count as f64 / 25.0; // `noise` (explicit seed) both defeats aomenc's @@ -20735,6 +20910,10 @@ mod tests { if ten_bit { args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]); } + let tile_arg = format!("--tile-columns={tile_cols}"); + if tile_cols > 0 { + args.push(&tile_arg); + } args.extend_from_slice(&["--obu", "-o", "-", "-"]); let mut child = Command::new(aomenc_path()) .args(&args) @@ -20763,8 +20942,12 @@ mod tests { "{NAME}: aomenc did not write a 10-bit sequence header" ); } - let tag = format!("{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit}"); + let tag = format!( + "{width}x{height} cq{cq} frames={frame_count} 10bit={ten_bit} \ + tile_cols={tile_cols}" + ); let before = crate::decode::edge32_hits(); + let straddle_before = crate::decode::cdef_straddle_units(); // lane-golomb r8: name the attempt BEFORE decoding it -- a // desync surfaces as a panic deep in mc.rs with no arm in the // message, and r8 spent a run bisecting arms by hand. @@ -20826,6 +21009,7 @@ mod tests { } } compared += 1; + straddle_units += crate::decode::cdef_straddle_units() - straddle_before; for i in 0..8 { totals[i] += delta[i]; } @@ -20836,6 +21020,11 @@ mod tests { "{NAME}: every attempt hit a named refusal:\n{}", refusals.join("\n") ); + assert!( + !straddle || straddle_units > 0, + "{NAME}: no FILTERED 8x8 CDEF unit crossed the cropped frame edge over \ + {compared} compared attempts -- the straddling arms proved nothing" + ); assert!( totals[0] + totals[1] + totals[4] + totals[5] > 0, "{NAME}: no frame-edge partition bit was read at all over \ @@ -20861,7 +21050,8 @@ mod tests { eprintln!( "{NAME}: {compared} pixel-exact attempts, 32-level edge bits \ [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, 64-level edge bits \ - [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, {} named refusals", + [horz_or_vert={} split={}] bottom-HORZ={} right-VERT={}, \ + {straddle_units} straddling CDEF units, {} named refusals", totals[0], totals[1], totals[2], diff --git a/lanes/cdef-r1.handoff.md b/lanes/cdef-r1.handoff.md new file mode 100644 index 00000000..a6479dec --- /dev/null +++ b/lanes/cdef-r1.handoff.md @@ -0,0 +1,66 @@ +# lane-cdef r1 -- HANDOFF (2 CDEF defects rooted, both fixed, gate GREEN; one residue open) + +Base: main 48b35ab. Suite unit `cdef-suite-1788330834.service` -> `$HOME/.cache/cdef-suite-r1.log` +(started at the turn cap; FIRST THING NEXT ROUND: `grep -E "^test result|FAILED" $HOME/.cache/cdef-suite-r1.log`). + +## Defect A -- per-8x8 CDEF skip band never written by the 8x8 inter leaf (charter hypothesis (a), variant) + +* Stream: `~/.cache/cdef-tmp/a0_8.obu`, sha256 `aa40f17f6e49eca2bb8c9d9ab99a175312134bdcf45c39b8a76b6757d8536751` + (hashed twice, identical), `~/.cache/cdef-tmp/gen.sh 8 3 8 a0_8.obu` = lane-intersub8's recipe, + 192x128, 6 frames, `--min-partition-size=4`, cq 8, 8-bit. +* Stage attribution: reconstruction and post-deblock are EXACT (`EC_AV1_POSTDEBLOCK_DUMP` ours vs + the instrumented aomdec: 0/24576 luma on decode-order frame 3); the 3 samples enter at CDEF. + NOTE: aomdec's `EC_AV1_PREFILT_DUMP` is ALREADY POST-DEBLOCK on this build (r_pre.fN == r_pd.fN + for 5 of 6 frames) -- ours is genuinely pre-deblock, so the two rungs are NOT the same stage. +* Root cause: `decode_inter_block8` (decode.rs, the leaf path `--min-partition-size=4` picks for a + 16x16 group) wrote `record_mi` + `fill_lf_grid` at both exits but NEVER `fill_skip_grid`. The + bottom-right 16x16 of decode-order frame 3 was therefore judged by the PREVIOUS frame's flags: + our 8x8 units at mi(28,46)/(30,46) read skip=false and were filtered, while libaom's + `is_8x8_block_skip` (cdef.c:29-38, called from `av1_cdef_compute_sb_list` cdef.c:40-71) excludes + an all-skip 8x8 from the dlist. Proof: a python model of `cdef_block.c` reproduces the reference + for all 16 units of the last column at (sec=1,damp=3) EXCEPT those two, where only "unfiltered" + matches; frame-3 fill log showed 0 of 95 skip fills covering mi(28,44)+16x16. +* Fix: `neighbours.fill_skip_grid(leaf_mi, 2, skip)` at both `decode_inter_block8` exits (compound + early return + fall-through), each bumping `INTER8_SKIP_BAND_HITS`. +* Before/after on the pinned stream: frames 3 and 4 had 3 luma samples |d|=1 each + ((189,116/120/124) and (186,116/120/124)); after, all 6 frames pixel-exact on Y/U/V. + +## Defect B -- CDEF direction search clamped at the crop edge instead of reading CDEF_VERY_LARGE + +* Stream: `~/.cache/golomb-tmp/s68.obu` (68x192, 5 frames, 8-bit, cq 35) -- lane-golomb r9's + deferred "straddle band". +* Root cause: `apply_cdef`'s `cdef_find_dir` closure clamped to `true_w-1`/`true_h-1`, but libaom + runs `cdef_find_dir` over `cdef_prepare_fb`'s buffer (cdef.c:249-256 `frame_boundary[RIGHT]` + fill, cdef_block.c:296-320), whose columns/rows past the mi-rounded extent are CDEF_VERY_LARGE. + With odd `mi_cols` (68 px -> 17 mi) the last 8x8 straddles, so var/`adjust_strength` differed. +* Fix: the direction search now reads the SAME padded `sample_y` the taps use (one line). +* Before/after: frame 1 luma 145 diffs -> **0**; all 5 frames luma exact. +* RESIDUE (open, NOT fixed): the same stream still differs in CHROMA from frame 1 on + (U/V 194/401/466/551 samples, |d| up to 6, spread over ~37 chroma 4x4 units, frame 0 exact). + Not attributable yet: `EC_AV1_DEBUG_SKIP_CDEF=1` cannot bisect inter frames (it also breaks the + reference frames), so the postdeblock rung is only valid for frame 0 here. Next step: dump + per-4x4 chroma CDEF params (uv pri/sec, damping-1, shared luma dir) for frame 1's first + differing unit and model it against `cdef_block.c` the way defect A was modelled + (`~/.cache/cdef-tmp/model.py` is a complete python port of cdef_block.c + find_dir + adjust). + +## Gate +`stream.rs::a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact` -- real +aomenc, `--min-partition-size=4 --enable-cdef=1` (last flag wins), 5 arms (8-bit cq 8/10/12, +10-bit cq 8/12), every decode-order frame compared on Y/U/V, hard asserts +`decode::cdef_skipped_units()` (an 8x8 unit really excluded by the all-skip rule) and +`decode::inter8_skip_band_hits()` (the leaf that used to write nothing) both grew per compared +attempt. 2 of 5 arms fire; the other 3 hit UNRELATED open refusals (non-DC chroma mode on an 8x8 +inter leaf; inter partition below 8x8) -- widening to 10-bit needs those lifted first. +`cargo test -p ec-av1 --lib cdef_and_sub16` -> ok, 1 passed / 0 failed. + +## Other +* `dump_stage`/`dump_stage16` wrote `.f0` for EVERY frame (each overwrote the last), so + `EC_AV1_POSTDEBLOCK_DUMP`/`POSTCDEF_DUMP` were unusable for per-frame bisection. Now indexed + per env var (`dump_stage_idx`), matching aomdec's own `.fN`. +* New rung `EC_AV1_CDEF_DBG=1`: one line per filtered 8x8 luma unit + (`EC_CDEF mi_r= mi_c= x= y= sidx= dir= var= t= pri= sec= damp=`). +* Class sweep for "per-8x8 map read at the top-left mi only under sub-8x8 partitions": the skip + grid is written by every OTHER leaf path (grep `fill_skip_grid`), `decode_inter_block8` was the + only writer missing; `is_skip_txfm` already gathers all four cells; the deblock/tx grid has a + `fill_lf_grid` at every one of those sites including both `decode_inter_block8` exits. +* Not done: `--tile-columns=1` arm on the new gate (COMMON neighbour-map rule) -- deferred. diff --git a/lanes/cdef-r2.report.md b/lanes/cdef-r2.report.md new file mode 100644 index 00000000..faf6f710 --- /dev/null +++ b/lanes/cdef-r2.report.md @@ -0,0 +1,83 @@ +# lane-cdef r2 report -- merge, the 68x192 chroma residue CLOSED, gate un-ignored + +Branch `lane-cdef`, base main `727f29a`. Commits this round: +* `32a467a` Merge main 727f29a (lane-r14, lane-kf1200, lane-reelckf) -- no conflicts. +* `0e6c5c9` Merge lane-golomb 173b793 -- 2 conflicts in `decode.rs`, both resolved (below). +* `26b971a` straddling-band gate un-ignored + `CDEF_STRADDLE_UNITS` counter + multi-tile arms. + +`cdf.rs` is byte-identical across `main`, `lane-golomb` and this tree +(`sha256 655f9a45ccedf7e37adab8b46703cf7ec4c9cc395978a1e6179157741def5844`, all four). + +## r1's leftover suite unit +`cdef-suite-1788330834.service` was still RUNNING at the start of this round; it had reached +**184 tests ok, 0 FAILED / 0 panics** with no `test result` line yet. Stopped (its target dir is +this lane's) and superseded by the r2 run below. + +## Merge conflicts (decode.rs), resolved +1. `dump_stage`'s per-decode-order-frame index: both lanes added one. Kept this lane's shared + `dump_stage_idx()` helper (`dump_stage16` uses it too), dropped lane-golomb's duplicate + `thread_local` counter. +2. The var-tx leaf loop (`decode.rs:19323`): took **main's** general `(row, col, tw, th)` rect + leaves and **lane-golomb's** `fill_lf_grid_leaf_luma` writer. Routing a rect leaf through + `fill_lf_grid_rect` would recompute the CHROMA tx dims from the leaf span; libaom's + `get_transform_size` (`av1/common/av1_loopfilter.c:207`) applies the split override only for + `plane == AOM_PLANE_Y`. Class `table-and-reader-move-together`: table (leaf tuple) from main, + writer from golomb, both re-gated below. + +## Charter item (2) -- the 68x192 CHROMA residue: CLOSED, and it was NOT a chroma-CDEF defect +The charter's hypotheses (chroma `hsize >> xdec` fill, `damping - 1`, `uv_pri/uv_sec`, shared luma +`dir`, `coeff_shift`, the 8x8 skip band) were each checked against the oracle source and all six +were **already correct** in `apply_cdef`: +* right/bottom pad bound: `sample_uv` bounds at `plane.true_width/true_height`, which is + `mi_cols * 4 / 2` (`decode.rs:13388`) = 36 for a 68-px axis -- exactly libaom's + `hsize = nhb << mi_wide_l2` with `mi_wide_l2 = MI_SIZE_LOG2 - subsampling_x` + (`cdef.c:164-167`), the fill starting there being `cdef.c:249-256`. +* `damping += coeff_shift - (pli != AOM_PLANE_Y)` (`cdef_block.c:337`) == our `damping_uv`. +* chroma `t = pri_strength`, NOT `adjust_strength` (`cdef_block.c:387`) == ours. +* `pri_strength ? dir[by][bx] : 0` per plane (`cdef_block.c:392`) == ours; the `conv422/conv440` + direction remap is `if (pli == 1 && xdec != ydec)` (`cdef_block.c:361-369`), i.e. never in 4:2:0. +* `level`/`sec_strength` from `cdef_uv_strengths[mbmi_cdef_strength]` with the `== 3` bump + (`cdef.c:325-333`) == ours; block size `8 >> xdec` by `8 >> ydec` == our 4x4. + +The residue was the **loop restoration plane size**, fixed on lane-golomb r8 and merged this +round: LR is the one post-decode filter sized by the CROP (`av1_get_upsampled_plane_size`, +`restoration.c:47`, asserted against the crop at `restoration.c:1106`), while deblock and CDEF walk +the mi grid. With both branches' fixes in one tree all four straddling arms are exact on Y, U and V. + +EVIDENCE: /home/user/.cache/cdef-strad-r2.log | merged tree, `cargo test -p ec-av1 --lib -- --ignored --nocapture a_frame_edge_straddling_band` (192x68 + 68x192, 5 frames, 8+10-bit, cq 35..61) | 14 pixel-exact attempts (Y, U and V, every shown frame), 0 differing pixels, 18 named refusals, test result ok 1 passed / 0 failed + +## Charter item (3) -- `--tile-columns=1` arms: added, and VACUOUS today +Each straddling arm gained a `--tile-columns=1` twin (8 arms x 8 cq = 64 attempts). All 32 +multi-tile attempts refuse **by name**; census (in the test's doc comment): +10x "an inter SB-level AB partition", 6x "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs +rectangular residual coding", 6x "an 8x8 intra leaf in an inter frame whose tx_depth splits it into +4x4 transform units", 5x "an inter partition below 8x8", 3x "an inter 16x16-level AB or 1:4 +partition", 1x "a split intra strip whose transform unit is 32x64", 1x "an intra-coded 1:4 rect +strip on the inter block path". Class `counter-from-refused-stream`: that half of the gate compares +nothing yet and every assert is carried by the single-tile arms. Arms kept so the coverage appears +the day those refusals lift. + +## Gate +`stream.rs::a_frame_edge_straddling_band_decodes_pixel_exact` -- **un-ignored** (was +`#[ignore] "open r9 defect"`). Hard-asserts the new `decode::cdef_straddle_units()` grew: a FILTERED +8x8 CDEF unit whose extent crosses the cropped frame edge is the only shape for which "clamp at the +crop" and "pad with CDEF_VERY_LARGE past the mi-rounded extent" differ, so a zero delta would make +these arms vacuous for this defect. + +EVIDENCE: /home/user/.cache/cdef-strad2-r2.log | `cargo test -p ec-av1 --lib -- --nocapture a_frame_edge_straddling_band` on the final tree | 14 pixel-exact attempts, **337 straddling CDEF units**, 50 named refusals, ok 1 passed / 0 failed in 33.99s + +Sibling gate (same tables/paths -- `apply_cdef`, the skip band, `fill_skip_grid`): +EVIDENCE: /home/user/.cache/cdef-sib-r2.log | `cargo test -p ec-av1 --lib -- --nocapture cdef_and_sub16` | a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact ok, 1 passed / 0 failed + +## Suite +EVIDENCE: /home/user/.cache/cdef-suite-r2.log | `systemd-run --user --unit=cdef-suite-r2-... -p MemoryMax=10G ... cargo test -p ec-av1 --lib -j3` on `646f2d3`'s tree | **386 passed, 0 failed, 34 ignored** in 1009.29s (r1's tree had 385/0/35 -- one test moved out of `ignored` and into `passed`: this round's un-ignored straddling gate) + +## Refusals +None lifted this round, so `refusal_inventory.rs` is unchanged. `gate_coverage.rs` needs no entry +either: its derivation deliberately excludes `--tile-columns` (see its header comment) and this +round adds no `--enable-*` flag. + +## Residue +* deferred(the 7 refusals in the census above) -- the multi-tile half of the straddling gate. +* accepted -- the gate compares SHOWN frames (`ffmpeg_decode_sequence`); no-show alt-ref frames are + not compared here, same as every sibling gate (class `gate-blind-to-hidden-frames`).