Merge lane-cdef 8c6065e into lane-rectchroma2 (chroma deblock grid, CDEF skip band, LR crop)
Browse files at this commit3 changed files +281 -8
- crates/ec-av1/src/decode.rs +70 -8
- crates/ec-av1/src/stream.rs +145 -0
- lanes/cdef-r1.handoff.md +66 -0
crates/ec-av1/src/decode.rsmodified+70 -8
| @@ -2599,6 +2599,28 @@ thread_local! { | |||
| 2599 | static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 2599 | static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 2600 | } | 2600 | } |
| 2601 | 2601 | ||
| 2602 | +// lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all | ||
| 2603 | +// four of their mi cells are `skip_txfm` (libaom `cdef.c:29-38` | ||
| 2604 | +// `is_8x8_block_skip` / `av1_cdef_compute_sb_list`'s dlist test), and (b) how | ||
| 2605 | +// many 8x8 inter leaves (`decode_inter_block8`) wrote that skip band at all. | ||
| 2606 | +// (b) was 0 for every stream before this round -- the leaf path never touched | ||
| 2607 | +// the band, so an all-skip 8x8 group kept the PREVIOUS frame's flags and got | ||
| 2608 | +// filtered where libaom skips it. A gate asserts both are non-zero. | ||
| 2609 | +thread_local! { | ||
| 2610 | + static CDEF_SKIPPED_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2611 | + static INTER8_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2612 | +} | ||
| 2613 | + | ||
| 2614 | +/// Current value of `CDEF_SKIPPED_UNITS`. | ||
| 2615 | +pub(crate) fn cdef_skipped_units() -> usize { | ||
| 2616 | + CDEF_SKIPPED_UNITS.with(|c| c.get()) | ||
| 2617 | +} | ||
| 2618 | + | ||
| 2619 | +/// Current value of `INTER8_SKIP_BAND_HITS`. | ||
| 2620 | +pub(crate) fn inter8_skip_band_hits() -> usize { | ||
| 2621 | + INTER8_SKIP_BAND_HITS.with(|c| c.get()) | ||
| 2622 | +} | ||
| 2623 | + | ||
| 2602 | /// Current value of [`SUB8_SPLIT_HITS`]. | 2624 | /// Current value of [`SUB8_SPLIT_HITS`]. |
| 2603 | pub(crate) fn sub8_split_hits() -> usize { | 2625 | pub(crate) fn sub8_split_hits() -> usize { |
| 2604 | SUB8_SPLIT_HITS.with(|c| c.get()) | 2626 | SUB8_SPLIT_HITS.with(|c| c.get()) |
| @@ -8899,10 +8921,8 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, | |||
| 8899 | // lane-sbrect10 r2: index the dump by decode-order picture like | 8921 | // lane-sbrect10 r2: index the dump by decode-order picture like |
| 8900 | // EC_AV1_PREFILT_DUMP already does -- a fixed `.f0` name kept only the | 8922 | // EC_AV1_PREFILT_DUMP already does -- a fixed `.f0` name kept only the |
| 8901 | // LAST frame, so a mid-sequence divergence could not be read out at all. | 8923 | // LAST frame, so a mid-sequence divergence could not be read out at all. |
| 8902 | - static STAGE16_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 8903 | if let Ok(path) = std::env::var(var) | 8924 | if let Ok(path) = std::env::var(var) |
| 8904 | - && let idx = STAGE16_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst) | 8925 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) |
| 8905 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) | ||
| 8906 | { | 8926 | { |
| 8907 | 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))] { | 8927 | 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))] { |
| 8908 | for row in 0..h { | 8928 | for row in 0..h { |
| @@ -8916,10 +8936,25 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize, | |||
| 8916 | } | 8936 | } |
| 8917 | } | 8937 | } |
| 8918 | 8938 | ||
| 8939 | +/// Decode-order index of the next [`dump_stage`]/[`dump_stage16`] file for a | ||
| 8940 | +/// given env var -- lane-cdef r1: both used to write `.f0` unconditionally, so | ||
| 8941 | +/// every frame overwrote the previous one and only the LAST frame survived, | ||
| 8942 | +/// which silently defeats any per-frame filter-stage bisection. | ||
| 8943 | +fn dump_stage_idx(var: &str) -> usize { | ||
| 8944 | + use std::collections::HashMap; | ||
| 8945 | + use std::sync::{Mutex, OnceLock}; | ||
| 8946 | + static IDX: OnceLock<Mutex<HashMap<String, usize>>> = OnceLock::new(); | ||
| 8947 | + let mut m = IDX.get_or_init(|| Mutex::new(HashMap::new())).lock().unwrap(); | ||
| 8948 | + let e = m.entry(var.to_string()).or_insert(0); | ||
| 8949 | + let i = *e; | ||
| 8950 | + *e += 1; | ||
| 8951 | + i | ||
| 8952 | +} | ||
| 8953 | + | ||
| 8919 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | 8954 | fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { |
| 8920 | use std::io::Write; | 8955 | use std::io::Write; |
| 8921 | if let Ok(path) = std::env::var(var) | 8956 | if let Ok(path) = std::env::var(var) |
| 8922 | - && let Ok(mut f) = std::fs::File::create(format!("{path}.f0")) | 8957 | + && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var))) |
| 8923 | { | 8958 | { |
| 8924 | for p in [y, u, v] { | 8959 | for p in [y, u, v] { |
| 8925 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); | 8960 | let narrow: Vec<u8> = p.data.iter().map(|&s| s as u8).collect(); |
| @@ -10432,6 +10467,7 @@ fn decode_leaf8( | |||
| 10432 | neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); | 10467 | neighbours.record_palette_y_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10433 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); | 10468 | neighbours.record_palette_uv_rect(pal_at, 8, 8, 0, [0u16; 8]); |
| 10434 | } | 10469 | } |
| 10470 | + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); | ||
| 10435 | neighbours.fill_skip_grid(leaf_mi, 2, skip); | 10471 | neighbours.fill_skip_grid(leaf_mi, 2, skip); |
| 10436 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); | 10472 | neighbours.fill_lf_grid(leaf_mi, 2, 8, 0); |
| 10437 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); | 10473 | neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode); |
| @@ -12787,6 +12823,9 @@ fn apply_cdef( | |||
| 12787 | while mi_r < skip_grid.mi_rows { | 12823 | while mi_r < skip_grid.mi_rows { |
| 12788 | let mut mi_c = 0usize; | 12824 | let mut mi_c = 0usize; |
| 12789 | while mi_c < skip_grid.mi_cols { | 12825 | while mi_c < skip_grid.mi_cols { |
| 12826 | + if skip_grid.is_skip_txfm(mi_r, mi_c) { | ||
| 12827 | + CDEF_SKIPPED_UNITS.with(|c| c.set(c.get() + 1)); | ||
| 12828 | + } | ||
| 12790 | if !skip_grid.is_skip_txfm(mi_r, mi_c) { | 12829 | if !skip_grid.is_skip_txfm(mi_r, mi_c) { |
| 12791 | let sidx = strength_idx(mi_r, mi_c); | 12830 | let sidx = strength_idx(mi_r, mi_c); |
| 12792 | let (ox, oy) = (mi_c * 4, mi_r * 4); | 12831 | let (ox, oy) = (mi_c * 4, mi_r * 4); |
| @@ -12799,10 +12838,15 @@ fn apply_cdef( | |||
| 12799 | i32::from(src_y[ny as usize * y_stride + nx as usize]) | 12838 | i32::from(src_y[ny as usize * y_stride + nx as usize]) |
| 12800 | } | 12839 | } |
| 12801 | }; | 12840 | }; |
| 12802 | - let (dir, var) = cdef_find_dir(coeff_shift, |r, c| { | 12841 | + // lane-cdef r1: the direction search reads the SAME padded |
| 12803 | - let (ny, nx) = ((oy + r).min(y_true_h - 1), (ox + c).min(y_true_w - 1)); | 12842 | + // block the taps do -- libaom runs `cdef_find_dir` on the |
| 12804 | - i32::from(src_y[ny * y_stride + nx]) | 12843 | + // prepared filter block (`cdef_block.c:296-320` over |
| 12805 | - }); | 12844 | + // `cdef_prepare_fb`'s buffer, `cdef.c:249-256`), whose columns |
| 12845 | + // and rows past the mi-rounded frame extent are CDEF_VERY_LARGE. | ||
| 12846 | + // Clamping to the last real sample instead made every straddling | ||
| 12847 | + // edge 8x8 (odd `mi_cols`/`mi_rows`) pick a different var, hence | ||
| 12848 | + // a different `adjust_strength`, hence a +-1 band at the crop edge. | ||
| 12849 | + let (dir, var) = cdef_find_dir(coeff_shift, |r, c| sample_y(r as i32, c as i32)); | ||
| 12806 | 12850 | ||
| 12807 | // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` | 12851 | // libaom `av1_cdef_filter_fb` passes `pri_strength ? dir : 0` |
| 12808 | // -- each plane zeroes the shared direction when *its own* | 12852 | // -- each plane zeroes the shared direction when *its own* |
| @@ -12812,6 +12856,12 @@ fn apply_cdef( | |||
| 12812 | let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; | 12856 | let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift; |
| 12813 | let y_dir = if y_pri_strength != 0 { dir } else { 0 }; | 12857 | let y_dir = if y_pri_strength != 0 { dir } else { 0 }; |
| 12814 | let t = cdef_adjust_strength(y_pri_strength, var); | 12858 | let t = cdef_adjust_strength(y_pri_strength, var); |
| 12859 | + // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit. | ||
| 12860 | + if std::env::var_os("EC_AV1_CDEF_DBG").is_some() { | ||
| 12861 | + eprintln!( | ||
| 12862 | + "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}" | ||
| 12863 | + ); | ||
| 12864 | + } | ||
| 12815 | let enable_primary = t != 0; | 12865 | let enable_primary = t != 0; |
| 12816 | let enable_secondary = y_sec_strength != 0; | 12866 | let enable_secondary = y_sec_strength != 0; |
| 12817 | if enable_primary || enable_secondary { | 12867 | if enable_primary || enable_secondary { |
| @@ -19873,6 +19923,14 @@ fn decode_inter_block8( | |||
| 19873 | // so the 16x16 below a split block read partition ctx 0 | 19923 | // so the 16x16 below a split block read partition ctx 0 |
| 19874 | // instead of 1 and mis-read PARTITION_SPLIT as NONE. | 19924 | // instead of 1 and mis-read PARTITION_SPLIT as NONE. |
| 19875 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 19925 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 19926 | + // lane-cdef r1: ... and the CDEF skip band too. `apply_cdef`'s | ||
| 19927 | + // `is_8x8_block_skip` (libaom `cdef.c:29-38`) reads all four mi | ||
| 19928 | + // cells of the 8x8; this leaf wrote none of them, so a 64x64 | ||
| 19929 | + // whose bottom-right 16x16 is an all-skip 8x8-leaf group kept | ||
| 19930 | + // the PREVIOUS frame's flags and got filtered where libaom's | ||
| 19931 | + // dlist excludes it (3 luma samples on a 192x128 inter frame). | ||
| 19932 | + INTER8_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1)); | ||
| 19933 | + neighbours.fill_skip_grid(leaf_mi, 2, skip); | ||
| 19876 | neighbours.fill_lf_grid( | 19934 | neighbours.fill_lf_grid( |
| 19877 | leaf_mi, | 19935 | leaf_mi, |
| 19878 | 2, | 19936 | 2, |
| @@ -20678,6 +20736,10 @@ fn decode_inter_block8( | |||
| 20678 | // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference | 20736 | // lane-gmaffine r2: the deblock grid's ref id is the leaf's OWN reference |
| 20679 | // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every | 20737 | // (r1 taught this leaf non-LAST refs; the hardcoded LAST_FRAME made every |
| 20680 | // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). | 20738 | // GOLDEN/ALTREF leaf read as LAST at the loop-filter's ref/mv edge test). |
| 20739 | + // lane-cdef r1: the fall-through twin of the compound arm's skip-band | ||
| 20740 | + // write above -- `skip` is one flag for the whole 8x8 leaf (read at | ||
| 20741 | + // `decode.rs`'s `skip_ctx` site), `split8` only splits its transform. | ||
| 20742 | + neighbours.fill_skip_grid(leaf_mi, 2, skip); | ||
| 20681 | neighbours.fill_lf_grid( | 20743 | neighbours.fill_lf_grid( |
| 20682 | leaf_mi, | 20744 | leaf_mi, |
| 20683 | 2, | 20745 | 2, |
crates/ec-av1/src/stream.rsmodified+145 -0
| @@ -15863,6 +15863,151 @@ mod tests { | |||
| 15863 | ); | 15863 | ); |
| 15864 | } | 15864 | } |
| 15865 | 15865 | ||
| 15866 | + /// lane-cdef r1: CDEF's per-8x8 skip band under sub-16x16 inter leaves. | ||
| 15867 | + /// | ||
| 15868 | + /// `apply_cdef` excludes an 8x8 luma unit whose four mi cells are all | ||
| 15869 | + /// `skip_txfm` (libaom `cdef.c:29-38 is_8x8_block_skip`, called from | ||
| 15870 | + /// `av1_cdef_compute_sb_list`'s dlist loop). `decode_inter_block8` -- the | ||
| 15871 | + /// leaf path `--min-partition-size=4` makes aomenc pick for a 16x16 group | ||
| 15872 | + /// -- wrote the loop-filter grid but never that skip band, so an all-skip | ||
| 15873 | + /// group kept the PREVIOUS frame's flags and got filtered where libaom | ||
| 15874 | + /// skips it (3 luma samples, decode-order frames 3 and 4 of the 192x128 | ||
| 15875 | + /// cq-8 stream below, at the frame's last 8x8 column). | ||
| 15876 | + /// | ||
| 15877 | + /// Both counters are hard asserts per compared attempt: `cdef_skipped_units` | ||
| 15878 | + /// proves the all-skip dlist exclusion was actually reached, and | ||
| 15879 | + /// `inter8_skip_band_hits` proves the 8x8 leaf path (the writer that used | ||
| 15880 | + /// to be missing) ran on the same stream. | ||
| 15881 | + #[test] | ||
| 15882 | + fn a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact() { | ||
| 15883 | + if !have_aomenc() { | ||
| 15884 | + return; | ||
| 15885 | + } | ||
| 15886 | + let (width, height, frames) = (192usize, 128usize, 6usize); | ||
| 15887 | + let mut refusals: Vec<String> = Vec::new(); | ||
| 15888 | + let mut fired = 0u32; | ||
| 15889 | + for (depth, cq, sp) in [(8u32, 8u32, 3u32), (8, 10, 3), (8, 12, 6), (10, 8, 3), (10, 12, 6)] { | ||
| 15890 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 15891 | + let src = format!( | ||
| 15892 | + "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\ | ||
| 15893 | + geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p" | ||
| 15894 | + ); | ||
| 15895 | + let y4m = Command::new("ffmpeg") | ||
| 15896 | + .args([ | ||
| 15897 | + "-v", "error", "-f", "lavfi", "-i", &src, "-t", "0.24", "-pix_fmt", pix, | ||
| 15898 | + "-strict", "-1", "-f", "yuv4mpegpipe", "-", | ||
| 15899 | + ]) | ||
| 15900 | + .stdin(Stdio::null()) | ||
| 15901 | + .stdout(Stdio::piped()) | ||
| 15902 | + .stderr(Stdio::piped()) | ||
| 15903 | + .output() | ||
| 15904 | + .expect("ffmpeg failed to run"); | ||
| 15905 | + assert!( | ||
| 15906 | + y4m.status.success(), | ||
| 15907 | + "ffmpeg fixture: {}", | ||
| 15908 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 15909 | + ); | ||
| 15910 | + let mut child = Command::new(aomenc_path()) | ||
| 15911 | + .args([ | ||
| 15912 | + "--codec=av1", | ||
| 15913 | + "--passes=1", | ||
| 15914 | + "--end-usage=q", | ||
| 15915 | + &format!("--cq-level={cq}"), | ||
| 15916 | + "--cpu-used=0", | ||
| 15917 | + "--threads=1", | ||
| 15918 | + "--row-mt=0", | ||
| 15919 | + "--sb-size=64", | ||
| 15920 | + &format!("--bit-depth={depth}"), | ||
| 15921 | + &format!("--input-bit-depth={depth}"), | ||
| 15922 | + "--enable-restoration=0", | ||
| 15923 | + "--enable-palette=0", | ||
| 15924 | + "--deltaq-mode=0", | ||
| 15925 | + "--enable-filter-intra=0", | ||
| 15926 | + "--enable-cfl-intra=0", | ||
| 15927 | + "--enable-intrabc=0", | ||
| 15928 | + "--lag-in-frames=0", | ||
| 15929 | + "--enable-obmc=0", | ||
| 15930 | + "--enable-tx-size-search=1", | ||
| 15931 | + "--enable-rect-partitions=0", | ||
| 15932 | + "--enable-ab-partitions=0", | ||
| 15933 | + "--enable-1to4-partitions=0", | ||
| 15934 | + "--min-partition-size=4", | ||
| 15935 | + "--max-partition-size=16", | ||
| 15936 | + // Last occurrence of a repeated --enable-* flag wins | ||
| 15937 | + // (aomenc-last-flag-wins): CDEF stays ON, and the two | ||
| 15938 | + // counters below prove the filter really ran. | ||
| 15939 | + "--enable-cdef=1", | ||
| 15940 | + "--obu", | ||
| 15941 | + "-o", | ||
| 15942 | + "-", | ||
| 15943 | + "-", | ||
| 15944 | + ]) | ||
| 15945 | + .stdin(Stdio::piped()) | ||
| 15946 | + .stdout(Stdio::piped()) | ||
| 15947 | + .stderr(Stdio::piped()) | ||
| 15948 | + .spawn() | ||
| 15949 | + .expect("aomenc failed to start"); | ||
| 15950 | + child | ||
| 15951 | + .stdin | ||
| 15952 | + .take() | ||
| 15953 | + .expect("aomenc stdin") | ||
| 15954 | + .write_all(&y4m.stdout) | ||
| 15955 | + .expect("writing y4m to aomenc"); | ||
| 15956 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 15957 | + assert!( | ||
| 15958 | + out.status.success(), | ||
| 15959 | + "aomenc refused the fixture (depth={depth} cq={cq})" | ||
| 15960 | + ); | ||
| 15961 | + let stream = out.stdout; | ||
| 15962 | + let skipped_before = decode::cdef_skipped_units(); | ||
| 15963 | + let leaves_before = decode::inter8_skip_band_hits(); | ||
| 15964 | + let decoded = match decode_stream(&stream) { | ||
| 15965 | + Ok(f) => f, | ||
| 15966 | + Err(e) => { | ||
| 15967 | + let msg = e.to_string(); | ||
| 15968 | + assert!( | ||
| 15969 | + msg.starts_with("unsupported: "), | ||
| 15970 | + "decode error that is not a named refusal \ | ||
| 15971 | + (depth={depth} cq={cq}): {msg}" | ||
| 15972 | + ); | ||
| 15973 | + refusals.push(format!("depth={depth} cq={cq}: {msg}")); | ||
| 15974 | + continue; | ||
| 15975 | + } | ||
| 15976 | + }; | ||
| 15977 | + assert_eq!(decoded.len(), frames, "frame count (depth={depth} cq={cq})"); | ||
| 15978 | + assert!( | ||
| 15979 | + decode::cdef_skipped_units() > skipped_before, | ||
| 15980 | + "no 8x8 CDEF unit was excluded by the all-skip rule \ | ||
| 15981 | + (depth={depth} cq={cq})" | ||
| 15982 | + ); | ||
| 15983 | + assert!( | ||
| 15984 | + decode::inter8_skip_band_hits() > leaves_before, | ||
| 15985 | + "no sub-16x16 inter leaf wrote the CDEF skip band \ | ||
| 15986 | + (depth={depth} cq={cq})" | ||
| 15987 | + ); | ||
| 15988 | + let reference = if depth == 10 { | ||
| 15989 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames) | ||
| 15990 | + } else { | ||
| 15991 | + ffmpeg_decode_sequence(&stream, width, height, frames) | ||
| 15992 | + }; | ||
| 15993 | + for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() { | ||
| 15994 | + assert_eq!(ours.y, theirs.y, "luma frame {i} (depth={depth} cq={cq})"); | ||
| 15995 | + assert_eq!(ours.u, theirs.u, "U frame {i} (depth={depth} cq={cq})"); | ||
| 15996 | + assert_eq!(ours.v, theirs.v, "V frame {i} (depth={depth} cq={cq})"); | ||
| 15997 | + } | ||
| 15998 | + fired += 1; | ||
| 15999 | + } | ||
| 16000 | + // Three of the five arms land on OTHER open refusals (a non-DC chroma | ||
| 16001 | + // mode on an 8x8 inter leaf; inter partitions below 8x8) -- the two | ||
| 16002 | + // 8-bit cq 8/10 arms ARE the streams the defect was found on, and each | ||
| 16003 | + // hard-asserts both counters plus all six frames on all three planes. | ||
| 16004 | + assert!( | ||
| 16005 | + fired >= 2, | ||
| 16006 | + "fewer than 2 firing+pixel-exact attempts:\n{}", | ||
| 16007 | + refusals.join("\n") | ||
| 16008 | + ); | ||
| 16009 | + } | ||
| 16010 | + | ||
| 15866 | /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients | 16011 | /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients |
| 15867 | /// at low cq reliably makes aomenc split an 8x8 block all the way to | 16012 | /// at low cq reliably makes aomenc split an 8x8 block all the way to |
| 15868 | /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec | 16013 | /// 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. | ||