Merge 8c6065e into lane-uv8
Browse files at this commit3 changed files +281 -6
- crates/ec-av1/src/decode.rs +70 -6
- crates/ec-av1/src/stream.rs +145 -0
- lanes/cdef-r1.handoff.md +66 -0
crates/ec-av1/src/decode.rsmodified+70 -6
| @@ -2660,6 +2660,28 @@ pub fn sub8_inter_rect_hits() -> (usize, usize) { | |||
| 2660 | }) | 2660 | }) |
| 2661 | } | 2661 | } |
| 2662 | 2662 | ||
| 2663 | +// lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all | ||
| 2664 | +// four of their mi cells are `skip_txfm` (libaom `cdef.c:29-38` | ||
| 2665 | +// `is_8x8_block_skip` / `av1_cdef_compute_sb_list`'s dlist test), and (b) how | ||
| 2666 | +// many 8x8 inter leaves (`decode_inter_block8`) wrote that skip band at all. | ||
| 2667 | +// (b) was 0 for every stream before this round -- the leaf path never touched | ||
| 2668 | +// the band, so an all-skip 8x8 group kept the PREVIOUS frame's flags and got | ||
| 2669 | +// filtered where libaom skips it. A gate asserts both are non-zero. | ||
| 2670 | +thread_local! { | ||
| 2671 | + static CDEF_SKIPPED_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2672 | + static INTER8_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2673 | +} | ||
| 2674 | + | ||
| 2675 | +/// Current value of `CDEF_SKIPPED_UNITS`. | ||
| 2676 | +pub(crate) fn cdef_skipped_units() -> usize { | ||
| 2677 | + CDEF_SKIPPED_UNITS.with(|c| c.get()) | ||
| 2678 | +} | ||
| 2679 | + | ||
| 2680 | +/// Current value of `INTER8_SKIP_BAND_HITS`. | ||
| 2681 | +pub(crate) fn inter8_skip_band_hits() -> usize { | ||
| 2682 | + INTER8_SKIP_BAND_HITS.with(|c| c.get()) | ||
| 2683 | +} | ||
| 2684 | + | ||
| 2663 | /// Current value of [`SUB8_SPLIT_HITS`]. | 2685 | /// Current value of [`SUB8_SPLIT_HITS`]. |
| 2664 | pub(crate) fn sub8_split_hits() -> usize { | 2686 | pub(crate) fn sub8_split_hits() -> usize { |
| 2665 | SUB8_SPLIT_HITS.with(|c| c.get()) | 2687 | SUB8_SPLIT_HITS.with(|c| c.get()) |
| @@ -8944,7 +8966,7 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 { | |||
| 8944 | fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { | 8966 | fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, fh: usize) { |
| 8945 | use std::io::Write; | 8967 | use std::io::Write; |
| 8946 | if let Ok(path) = std::env::var(var) | 8968 | if let Ok(path) = std::env::var(var) |
| 8947 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 8969 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) |
| 8948 | { | 8970 | { |
| 8949 | 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))] { | 8971 | 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))] { |
| 8950 | for row in 0..h { | 8972 | for row in 0..h { |
| @@ -8958,10 +8980,25 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, | |||
| 8958 | } | 8980 | } |
| 8959 | } | 8981 | } |
| 8960 | 8982 | ||
| 8983 | +/// Decode-order index of the next [`dump_stage`]/[`dump_stage16`] file for a | ||
| 8984 | +/// given env var -- lane-cdef r1: both used to write `.f0` unconditionally, so | ||
| 8985 | +/// every frame overwrote the previous one and only the LAST frame survived, | ||
| 8986 | +/// which silently defeats any per-frame filter-stage bisection. | ||
| 8987 | +fn dump_stage_idx(var: &str) -> usize { | ||
| 8988 | + use std::collections::HashMap; | ||
| 8989 | + use std::sync::{Mutex, OnceLock}; | ||
| 8990 | + static IDX: OnceLock<Mutex<HashMap<String, usize>>> = OnceLock::new(); | ||
| 8991 | + let mut m = IDX.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); | ||
| 8992 | + let e = m.entry(var.to_string()).or_insert(0); | ||
| 8993 | + let i = *e; | ||
| 8994 | + *e += 1; | ||
| 8995 | + i | ||
| 8996 | +} | ||
| 8997 | + | ||
| 8961 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | 8998 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { |
| 8962 | use std::io::Write; | 8999 | use std::io::Write; |
| 8963 | if let Ok(path) = std::env::var(var) | 9000 | if let Ok(path) = std::env::var(var) |
| 8964 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 9001 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) |
| 8965 | { | 9002 | { |
| 8966 | for p in [y, u, v] { | 9003 | for p in [y, u, v] { |
| 8967 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); | 9004 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); |
| @@ -10474,6 +10511,7 @@ fn decode_leaf8( | |||
| 10474 | neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); | 10511 | neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10475 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); | 10512 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10476 | } | 10513 | } |
| 10514 | + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10477 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 10515 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10478 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); | 10516 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); |
| 10479 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | 10517 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| @@ -12829,6 +12867,9 @@ fn apply_cdef( | |||
| 12829 | while mi_r < skip_grid.mi_rows { | 12867 | while mi_r < skip_grid.mi_rows { |
| 12830 | let mut mi_c = 0usize; | 12868 | let mut mi_c = 0usize; |
| 12831 | while mi_c < skip_grid.mi_cols { | 12869 | while mi_c < skip_grid.mi_cols { |
| 12870 | + if skip_grid.is_skip_txfm(mi_r, mi_c) { | ||
| 12871 | + CDEF_SKIPPED_UNITS.with(|c| c.set(c.get() + 1)); | ||
| 12872 | + } | ||
| 12832 | if !skip_grid.is_skip_txfm(mi_r, mi_c) { | 12873 | if !skip_grid.is_skip_txfm(mi_r, mi_c) { |
| 12833 | let sidx = strength_idx(mi_r, mi_c); | 12874 | let sidx = strength_idx(mi_r, mi_c); |
| 12834 | let (ox, oy) = (mi_c * 4, mi_r * 4); | 12875 | let (ox, oy) = (mi_c * 4, mi_r * 4); |
| @@ -12841,10 +12882,15 @@ fn apply_cdef( | |||
| 12841 | i32::from(src_y[ny as usize * y_stride + nx as usize]) | 12882 | i32::from(src_y[ny as usize * y_stride + nx as usize]) |
| 12842 | } | 12883 | } |
| 12843 | }; | 12884 | }; |
| 12844 | - let (dir, var) = cdef_find_dir(coeff_shift, |r, c| { | 12885 | + // lane-cdef r1: the direction search reads the SAME padded |
| 12845 | - let (ny, nx) = ((oy + r).min(y_true_h - 1), (ox + c).min(y_true_w - 1)); | 12886 | + // block the taps do -- libaom runs `cdef_find_dir` on the |
| 12846 | - i32::from(src_y[ny * y_stride + nx]) | 12887 | + // prepared filter block (`cdef_block.c:296-320` over |
| 12847 | - }); | 12888 | + // `cdef_prepare_fb`'s buffer, `cdef.c:249-256`), whose columns |
| 12889 | + // and rows past the mi-rounded frame extent are CDEF_VERY_LARGE. | ||
| 12890 | + // Clamping to the last real sample instead made every straddling | ||
| 12891 | + // edge 8x8 (odd `mi_cols`/`mi_rows`) pick a different var, hence | ||
| 12892 | + // a different `adjust_strength`, hence a +-1 band at the crop edge. | ||
| 12893 | + let (dir, var) = cdef_find_dir(coeff_shift, |r, c| sample_y(r as i32, c as i32)); | ||
| 12848 | 12894 | ||
| 12849 | // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` | 12895 | // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` |
| 12850 | // -- each plane zeroes the shared direction when *its own* | 12896 | // -- each plane zeroes the shared direction when *its own* |
| @@ -12854,6 +12900,12 @@ fn apply_cdef( | |||
| 12854 | let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; | 12900 | let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; |
| 12855 | let y_dir = if y_pri_strength != 0 { dir } else { 0 }; | 12901 | let y_dir = if y_pri_strength != 0 { dir } else { 0 }; |
| 12856 | let t = cdef_adjust_strength(y_pri_strength, var); | 12902 | let t = cdef_adjust_strength(y_pri_strength, var); |
| 12903 | + // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit. | ||
| 12904 | + if std::env::var_os("EC_AV1_CDEF_DBG").is_some() { | ||
| 12905 | + eprintln!( | ||
| 12906 | + "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}" | ||
| 12907 | + ); | ||
| 12908 | + } | ||
| 12857 | let enable_primary = t != 0; | 12909 | let enable_primary = t != 0; |
| 12858 | let enable_secondary = y_sec_strength != 0; | 12910 | let enable_secondary = y_sec_strength != 0; |
| 12859 | if enable_primary || enable_secondary { | 12911 | if enable_primary || enable_secondary { |
| @@ -21125,6 +21177,14 @@ fn decode_inter_block8( | |||
| 21125 | // so the 16x16 below a split block read partition ctx 0 | 21177 | // so the 16x16 below a split block read partition ctx 0 |
| 21126 | // instead of 1 and mis-read PARTITION_SPLIT as NONE. | 21178 | // instead of 1 and mis-read PARTITION_SPLIT as NONE. |
| 21127 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 21179 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 21180 | + // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s | ||
| 21181 | + // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi | ||
| 21182 | + // cells of the 8x8; this leaf wrote none of them, so a 64x64 | ||
| 21183 | + // whose bottom-right 16x16 is an all-skip 8x8-leaf group kept | ||
| 21184 | + // the PREVIOUS frame's flags and got filtered where libaom's | ||
| 21185 | + // dlist excludes it (3 luma samples on a 192x128 inter frame). | ||
| 21186 | + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); | ||
| 21187 | + neighbours.fill_skip_grid(leaf_mi, 2, skip); | ||
| 21128 | neighbours.fill_lf_grid( | 21188 | neighbours.fill_lf_grid( |
| 21129 | leaf_mi, | 21189 | leaf_mi, |
| 21130 | 2, | 21190 | 2, |
| @@ -21999,6 +22059,10 @@ fn decode_inter_block8( | |||
| 21999 | // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference | 22059 | // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference |
| 22000 | // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every | 22060 | // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every |
| 22001 | // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). | 22061 | // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). |
| 22062 | + // lane-cdef r1: the fall-through twin of the compound arm's skip-band | ||
| 22063 | + // write above -- `skip` is one flag for the whole 8x8 leaf (read at | ||
| 22064 | + // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform. | ||
| 22065 | + neighbours.fill_skip_grid(leaf_mi, 2, skip); | ||
| 22002 | neighbours.fill_lf_grid( | 22066 | neighbours.fill_lf_grid( |
| 22003 | leaf_mi, | 22067 | leaf_mi, |
| 22004 | 2, | 22068 | 2, |
crates/ec-av1/src/stream.rsmodified+145 -0
| @@ -16240,6 +16240,151 @@ mod tests { | |||
| 16240 | ); | 16240 | ); |
| 16241 | } | 16241 | } |
| 16242 | 16242 | ||
| 16243 | + /// lane-cdef r1: CDEF's per-8x8 skip band under sub-16x16 inter leaves. | ||
| 16244 | + /// | ||
| 16245 | + /// `apply_cdef` excludes an 8x8 luma unit whose four mi cells are all | ||
| 16246 | + /// `skip_txfm` (libaom `cdef.c:29-38 is_8x8_block_skip`, called from | ||
| 16247 | + /// `av1_cdef_compute_sb_list`'s dlist loop). `decode_inter_block8` -- the | ||
| 16248 | + /// leaf path `--min-partition-size=4` makes aomenc pick for a 16x16 group | ||
| 16249 | + /// -- wrote the loop-filter grid but never that skip band, so an all-skip | ||
| 16250 | + /// group kept the PREVIOUS frame's flags and got filtered where libaom | ||
| 16251 | + /// skips it (3 luma samples, decode-order frames 3 and 4 of the 192x128 | ||
| 16252 | + /// cq-8 stream below, at the frame's last 8x8 column). | ||
| 16253 | + /// | ||
| 16254 | + /// Both counters are hard asserts per compared attempt: `cdef_skipped_units` | ||
| 16255 | + /// proves the all-skip dlist exclusion was actually reached, and | ||
| 16256 | + /// `inter8_skip_band_hits` proves the 8x8 leaf path (the writer that used | ||
| 16257 | + /// to be missing) ran on the same stream. | ||
| 16258 | + #[test] | ||
| 16259 | + fn a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact() { | ||
| 16260 | + if !have_aomenc() { | ||
| 16261 | + return; | ||
| 16262 | + } | ||
| 16263 | + let (width, height, frames) = (192usize, 128usize, 6usize); | ||
| 16264 | + let mut refusals: Vec<String> = Vec::new(); | ||
| 16265 | + let mut fired = 0u32; | ||
| 16266 | + for (depth, cq, sp) in [(8u32, 8u32, 3u32), (8, 10, 3), (8, 12, 6), (10, 8, 3), (10, 12, 6)] { | ||
| 16267 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 16268 | + let src = format!( | ||
| 16269 | + "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ | ||
| 16270 | + geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p" | ||
| 16271 | + ); | ||
| 16272 | + let y4m = Command::new("ffmpeg") | ||
| 16273 | + .args([ | ||
| 16274 | + "-v", "error", "-f", "lavfi", "-i", &src, "-t", "0.24", "-pix_fmt", pix, | ||
| 16275 | + "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 16276 | + ]) | ||
| 16277 | + .stdin(Stdio::null()) | ||
| 16278 | + .stdout(Stdio::piped()) | ||
| 16279 | + .stderr(Stdio::piped()) | ||
| 16280 | + .output() | ||
| 16281 | + .expect("ffmpeg failed to run"); | ||
| 16282 | + assert!( | ||
| 16283 | + y4m.status.success(), | ||
| 16284 | + "ffmpeg fixture: {}", | ||
| 16285 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 16286 | + ); | ||
| 16287 | + let mut child = Command::new(aomenc_path()) | ||
| 16288 | + .args([ | ||
| 16289 | + "--codec=av1", | ||
| 16290 | + "--passes=1", | ||
| 16291 | + "--end-usage=q", | ||
| 16292 | + &format!("--cq-level={cq}"), | ||
| 16293 | + "--cpu-used=0", | ||
| 16294 | + "--threads=1", | ||
| 16295 | + "--row-mt=0", | ||
| 16296 | + "--sb-size=64", | ||
| 16297 | + &format!("--bit-depth={depth}"), | ||
| 16298 | + &format!("--input-bit-depth={depth}"), | ||
| 16299 | + "--enable-restoration=0", | ||
| 16300 | + "--enable-palette=0", | ||
| 16301 | + "--deltaq-mode=0", | ||
| 16302 | + "--enable-filter-intra=0", | ||
| 16303 | + "--enable-cfl-intra=0", | ||
| 16304 | + "--enable-intrabc=0", | ||
| 16305 | + "--lag-in-frames=0", | ||
| 16306 | + "--enable-obmc=0", | ||
| 16307 | + "--enable-tx-size-search=1", | ||
| 16308 | + "--enable-rect-partitions=0", | ||
| 16309 | + "--enable-ab-partitions=0", | ||
| 16310 | + "--enable-1to4-partitions=0", | ||
| 16311 | + "--min-partition-size=4", | ||
| 16312 | + "--max-partition-size=16", | ||
| 16313 | + // Last occurrence of a repeated --enable-* flag wins | ||
| 16314 | + // (aomenc-last-flag-wins): CDEF stays ON, and the two | ||
| 16315 | + // counters below prove the filter really ran. | ||
| 16316 | + "--enable-cdef=1", | ||
| 16317 | + "--obu", | ||
| 16318 | + "-o", | ||
| 16319 | + "-", | ||
| 16320 | + "-", | ||
| 16321 | + ]) | ||
| 16322 | + .stdin(Stdio::piped()) | ||
| 16323 | + .stdout(Stdio::piped()) | ||
| 16324 | + .stderr(Stdio::piped()) | ||
| 16325 | + .spawn() | ||
| 16326 | + .expect("aomenc failed to start"); | ||
| 16327 | + child | ||
| 16328 | + .stdin | ||
| 16329 | + .take() | ||
| 16330 | + .expect("aomenc stdin") | ||
| 16331 | + .write_all(&y4m.stdout) | ||
| 16332 | + .expect("writing y4m to aomenc"); | ||
| 16333 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 16334 | + assert!( | ||
| 16335 | + out.status.success(), | ||
| 16336 | + "aomenc refused the fixture (depth={depth} cq={cq})" | ||
| 16337 | + ); | ||
| 16338 | + let stream = out.stdout; | ||
| 16339 | + let skipped_before = decode::cdef_skipped_units(); | ||
| 16340 | + let leaves_before = decode::inter8_skip_band_hits(); | ||
| 16341 | + let decoded = match decode_stream(&stream) { | ||
| 16342 | + Ok(f) => f, | ||
| 16343 | + Err(e) => { | ||
| 16344 | + let msg = e.to_string(); | ||
| 16345 | + assert!( | ||
| 16346 | + msg.starts_with("unsupported: "), | ||
| 16347 | + "decode error that is not a named refusal \ | ||
| 16348 | + (depth={depth} cq={cq}): {msg}" | ||
| 16349 | + ); | ||
| 16350 | + refusals.push(format!("depth={depth} cq={cq}: {msg}")); | ||
| 16351 | + continue; | ||
| 16352 | + } | ||
| 16353 | + }; | ||
| 16354 | + assert_eq!(decoded.len(), frames, "frame count (depth={depth} cq={cq})"); | ||
| 16355 | + assert!( | ||
| 16356 | + decode::cdef_skipped_units() > skipped_before, | ||
| 16357 | + "no 8x8 CDEF unit was excluded by the all-skip rule \ | ||
| 16358 | + (depth={depth} cq={cq})" | ||
| 16359 | + ); | ||
| 16360 | + assert!( | ||
| 16361 | + decode::inter8_skip_band_hits() > leaves_before, | ||
| 16362 | + "no sub-16x16 inter leaf wrote the CDEF skip band \ | ||
| 16363 | + (depth={depth} cq={cq})" | ||
| 16364 | + ); | ||
| 16365 | + let reference = if depth == 10 { | ||
| 16366 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames) | ||
| 16367 | + } else { | ||
| 16368 | + ffmpeg_decode_sequence(&stream, width, height, frames) | ||
| 16369 | + }; | ||
| 16370 | + for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() { | ||
| 16371 | + assert_eq!(ours.y, theirs.y, "luma frame {i} (depth={depth} cq={cq})"); | ||
| 16372 | + assert_eq!(ours.u, theirs.u, "U frame {i} (depth={depth} cq={cq})"); | ||
| 16373 | + assert_eq!(ours.v, theirs.v, "V frame {i} (depth={depth} cq={cq})"); | ||
| 16374 | + } | ||
| 16375 | + fired += 1; | ||
| 16376 | + } | ||
| 16377 | + // Three of the five arms land on OTHER open refusals (a non-DC chroma | ||
| 16378 | + // mode on an 8x8 inter leaf; inter partitions below 8x8) -- the two | ||
| 16379 | + // 8-bit cq 8/10 arms ARE the streams the defect was found on, and each | ||
| 16380 | + // hard-asserts both counters plus all six frames on all three planes. | ||
| 16381 | + assert!( | ||
| 16382 | + fired >= 2, | ||
| 16383 | + "fewer than 2 firing+pixel-exact attempts:\n{}", | ||
| 16384 | + refusals.join("\n") | ||
| 16385 | + ); | ||
| 16386 | + } | ||
| 16387 | + | ||
| 16243 | /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients | 16388 | /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients |
| 16244 | /// at low cq reliably makes aomenc split an 8x8 block all the way to | 16389 | /// at low cq reliably makes aomenc split an 8x8 block all the way to |
| 16245 | /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec | 16390 | /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec |
lanes/cdef-r1.handoff.mdadded+66 -0
| @@ -0,0 +1,66 @@ | |||
| 1 | +# lane-cdef r1 -- HANDOFF (2 CDEF defects rooted, both fixed, gate GREEN; one residue open) | ||
| 2 | + | ||
| 3 | +Base: main 48b35ab. Suite unit `cdef-suite-1788330834.service` -> `$HOME/.cache/cdef-suite-r1.log` | ||
| 4 | +(started at the turn cap; FIRST THING NEXT ROUND: `grep -E "^test result|FAILED" $HOME/.cache/cdef-suite-r1.log`). | ||
| 5 | + | ||
| 6 | +## Defect A -- per-8x8 CDEF skip band never written by the 8x8 inter leaf (charter hypothesis (a), variant) | ||
| 7 | + | ||
| 8 | +* Stream: `~/.cache/cdef-tmp/a0_8.obu`, sha256 `aa40f17f6e49eca2bb8c9d9ab99a175312134bdcf45c39b8a76b6757d8536751` | ||
| 9 | + (hashed twice, identical), `~/.cache/cdef-tmp/gen.sh 8 3 8 a0_8.obu` = lane-intersub8's recipe, | ||
| 10 | + 192x128, 6 frames, `--min-partition-size=4`, cq 8, 8-bit. | ||
| 11 | +* Stage attribution: reconstruction and post-deblock are EXACT (`EC_AV1_POSTDEBLOCK_DUMP` ours vs | ||
| 12 | + the instrumented aomdec: 0/24576 luma on decode-order frame 3); the 3 samples enter at CDEF. | ||
| 13 | + NOTE: aomdec's `EC_AV1_PREFILT_DUMP` is ALREADY POST-DEBLOCK on this build (r_pre.fN == r_pd.fN | ||
| 14 | + for 5 of 6 frames) -- ours is genuinely pre-deblock, so the two rungs are NOT the same stage. | ||
| 15 | +* Root cause: `decode_inter_block8` (decode.rs, the leaf path `--min-partition-size=4` picks for a | ||
| 16 | + 16x16 group) wrote `record_mi` + `fill_lf_grid` at both exits but NEVER `fill_skip_grid`. The | ||
| 17 | + bottom-right 16x16 of decode-order frame 3 was therefore judged by the PREVIOUS frame's flags: | ||
| 18 | + our 8x8 units at mi(28,46)/(30,46) read skip=false and were filtered, while libaom's | ||
| 19 | + `is_8x8_block_skip` (cdef.c:29-38, called from `av1_cdef_compute_sb_list` cdef.c:40-71) excludes | ||
| 20 | + an all-skip 8x8 from the dlist. Proof: a python model of `cdef_block.c` reproduces the reference | ||
| 21 | + for all 16 units of the last column at (sec=1,damp=3) EXCEPT those two, where only "unfiltered" | ||
| 22 | + matches; frame-3 fill log showed 0 of 95 skip fills covering mi(28,44)+16x16. | ||
| 23 | +* Fix: `neighbours.fill_skip_grid(leaf_mi, 2, skip)` at both `decode_inter_block8` exits (compound | ||
| 24 | + early return + fall-through), each bumping `INTER8_SKIP_BAND_HITS`. | ||
| 25 | +* Before/after on the pinned stream: frames 3 and 4 had 3 luma samples |d|=1 each | ||
| 26 | + ((189,116/120/124) and (186,116/120/124)); after, all 6 frames pixel-exact on Y/U/V. | ||
| 27 | + | ||
| 28 | +## Defect B -- CDEF direction search clamped at the crop edge instead of reading CDEF_VERY_LARGE | ||
| 29 | + | ||
| 30 | +* Stream: `~/.cache/golomb-tmp/s68.obu` (68x192, 5 frames, 8-bit, cq 35) -- lane-golomb r9's | ||
| 31 | + deferred "straddle band". | ||
| 32 | +* Root cause: `apply_cdef`'s `cdef_find_dir` closure clamped to `true_w-1`/`true_h-1`, but libaom | ||
| 33 | + runs `cdef_find_dir` over `cdef_prepare_fb`'s buffer (cdef.c:249-256 `frame_boundary[RIGHT]` | ||
| 34 | + fill, cdef_block.c:296-320), whose columns/rows past the mi-rounded extent are CDEF_VERY_LARGE. | ||
| 35 | + With odd `mi_cols` (68 px -> 17 mi) the last 8x8 straddles, so var/`adjust_strength` differed. | ||
| 36 | +* Fix: the direction search now reads the SAME padded `sample_y` the taps use (one line). | ||
| 37 | +* Before/after: frame 1 luma 145 diffs -> **0**; all 5 frames luma exact. | ||
| 38 | +* RESIDUE (open, NOT fixed): the same stream still differs in CHROMA from frame 1 on | ||
| 39 | + (U/V 194/401/466/551 samples, |d| up to 6, spread over ~37 chroma 4x4 units, frame 0 exact). | ||
| 40 | + Not attributable yet: `EC_AV1_DEBUG_SKIP_CDEF=1` cannot bisect inter frames (it also breaks the | ||
| 41 | + reference frames), so the postdeblock rung is only valid for frame 0 here. Next step: dump | ||
| 42 | + per-4x4 chroma CDEF params (uv pri/sec, damping-1, shared luma dir) for frame 1's first | ||
| 43 | + differing unit and model it against `cdef_block.c` the way defect A was modelled | ||
| 44 | + (`~/.cache/cdef-tmp/model.py` is a complete python port of cdef_block.c + find_dir + adjust). | ||
| 45 | + | ||
| 46 | +## Gate | ||
| 47 | +`stream.rs::a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact` -- real | ||
| 48 | +aomenc, `--min-partition-size=4 --enable-cdef=1` (last flag wins), 5 arms (8-bit cq 8/10/12, | ||
| 49 | +10-bit cq 8/12), every decode-order frame compared on Y/U/V, hard asserts | ||
| 50 | +`decode::cdef_skipped_units()` (an 8x8 unit really excluded by the all-skip rule) and | ||
| 51 | +`decode::inter8_skip_band_hits()` (the leaf that used to write nothing) both grew per compared | ||
| 52 | +attempt. 2 of 5 arms fire; the other 3 hit UNRELATED open refusals (non-DC chroma mode on an 8x8 | ||
| 53 | +inter leaf; inter partition below 8x8) -- widening to 10-bit needs those lifted first. | ||
| 54 | +`cargo test -p ec-av1 --lib cdef_and_sub16` -> ok, 1 passed / 0 failed. | ||
| 55 | + | ||
| 56 | +## Other | ||
| 57 | +* `dump_stage`/`dump_stage16` wrote `.f0` for EVERY frame (each overwrote the last), so | ||
| 58 | + `EC_AV1_POSTDEBLOCK_DUMP`/`POSTCDEF_DUMP` were unusable for per-frame bisection. Now indexed | ||
| 59 | + per env var (`dump_stage_idx`), matching aomdec's own `.fN`. | ||
| 60 | +* New rung `EC_AV1_CDEF_DBG=1`: one line per filtered 8x8 luma unit | ||
| 61 | + (`EC_CDEF mi_r= mi_c= x= y= sidx= dir= var= t= pri= sec= damp=`). | ||
| 62 | +* Class sweep for "per-8x8 map read at the top-left mi only under sub-8x8 partitions": the skip | ||
| 63 | + grid is written by every OTHER leaf path (grep `fill_skip_grid`), `decode_inter_block8` was the | ||
| 64 | + only writer missing; `is_skip_txfm` already gathers all four cells; the deblock/tx grid has a | ||
| 65 | + `fill_lf_grid` at every one of those sites including both `decode_inter_block8` exits. | ||
| 66 | +* Not done: `--tile-columns=1` arm on the new gate (COMMON neighbour-map rule) -- deferred. | ||