diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index bd1e82ca..a6d27f5a 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -13310,25 +13310,31 @@ mod tests { // 25 dB garbage while this gate stayed green) and the crf-5 key // frame desync. A failure names the encoder, the point's flags and // the first differing frame/plane/sample. + // lane-dpm1: a failing reference point is COLLECTED, not panicked + // on, so one run still prints the whole BD table and names every + // bad point instead of stopping at the first. The collection is + // asserted empty by [`assert_ladder_decodes`] at the end of each + // gate. match crate::stream::decode_stream(&stream) { + Ok(ours) if ours.len() != decoded.len() => note_ladder_failure(format!( + "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}", + ours.len(), + decoded.len(), + )), Ok(ours) => { - assert_eq!( - ours.len(), - decoded.len(), - "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}", - ours.len(), - decoded.len(), - ); for (f, (o, d)) in ours.iter().zip(&decoded).enumerate() { if let Some((plane, s, got, want)) = first_plane_mismatch(o, d) { - panic!( + note_ladder_failure(format!( "{encoder} {params:?} frame {f} plane {plane} sample {s}: our \ decoder decoded {got}, ffmpeg {want}" - ); + )); + break; } } } - Err(e) => panic!("{encoder} {params:?}: our decoder refused the stream ({e})"), + Err(e) => note_ladder_failure(format!( + "{encoder} {params:?}: our decoder refused the stream ({e})" + )), } let mean: f64 = decoded .iter() @@ -13344,6 +13350,28 @@ mod tests { (ladder, wall) } + /// Every reference ladder point that did not decode sample-exactly + /// through our own decoder, collected across a whole gate run so the BD + /// table still prints and EVERY bad point is named + /// (`encoder params frame plane sample`) instead of only the first. + static LADDER_FAILURES: std::sync::Mutex> = std::sync::Mutex::new(Vec::new()); + + fn note_ladder_failure(msg: String) { + eprintln!("LADDER DECODE FAILURE: {msg}"); + LADDER_FAILURES.lock().expect("ladder failures").push(msg); + } + + /// Fail the gate at its END on everything [`external_ladder`] collected. + fn assert_ladder_decodes() { + let failures = std::mem::take(&mut *LADDER_FAILURES.lock().expect("ladder failures")); + assert!( + failures.is_empty(), + "{} reference ladder point(s) did not decode exactly through our decoder:\n{}", + failures.len(), + failures.join("\n"), + ); + } + /// First differing sample between two pictures, as /// `(plane, index, left, right)` -- so a gate failure names the plane and /// the sample instead of just "differs". A length difference counts as a @@ -14446,6 +14474,7 @@ mod tests { .join(", "), ); } + assert_ladder_decodes(); } /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2, /// split by block class in lane-av1txdepth): depth 0 is one transform over @@ -14846,6 +14875,7 @@ mod tests { bd_rate(&rav1e, &ours) * 100.0, ); } + assert_ladder_decodes(); } /// lane-av1tpl3 step 1: the SHAPE of the propagating map's denominator diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index c30c81f2..784abd6e 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3771,14 +3771,22 @@ pub(crate) mod tests { /// the desync surfaced blocks later as "a Golomb tail longer than this /// decoder reads". /// - /// The source is SYNTHETIC (no film sample lives in `fixtures`): a - /// near-flat dark background at the film-B crop size, 1920x1024, with one - /// textured patch stepping 9 px every SECOND frame, so half the frames are - /// exact duplicates of their predecessor (the `C == T` trigger) while the - /// motion field still holds non-zero MVs whose projections are not - /// multiples of 8. The gate asserts both halves: at least one INTER frame - /// really carries `force_integer_mv` (class `gate-blind-to-feature`), and - /// every shown frame decodes sample-exact against ffmpeg's own decode. + /// The source is SYNTHETIC (no film sample lives in `fixtures`): the + /// near-flat dark pattern libaom's own screen-content detector counts as + /// screen content, at the film-B crop size 1920x1024, SCROLLING globally + /// 5 px per frame and frozen on frame 8 -- an exact duplicate of frame 7 + /// (the `C == T` trigger) whose twin is not among its own references, so + /// its blocks still code real motion under `force_integer_mv`. + /// + /// lane-dpm1 made this gate SENSITIVE: with the `force_integer_mv` branch + /// of [`crate::motion_field::lower_mv_precision`] stubbed out (`if false + /// &&`) the stream decodes WRONG -- frame 8, luma sample 25695, 20 against + /// ffmpeg's 19 -- where the previous patch-in-a-static-background recipe + /// (and two others tried) still decoded byte-exact: there the used mv-stack + /// slots came from agreeing spatial neighbours and the rounded temporal + /// entries never won one. The gate asserts both halves: at least one INTER + /// frame really carries `force_integer_mv` (class `gate-blind-to-feature`), + /// and every shown frame decodes sample-exact against ffmpeg's own decode. #[test] fn a_libaom_force_integer_mv_stream_decodes_exact() { const NAME: &str = "a_libaom_force_integer_mv_stream_decodes_exact"; @@ -3786,23 +3794,30 @@ pub(crate) mod tests { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - let (w, h, frames) = (1920usize, 1024usize, 12usize); + let (w, h, frames) = (1920usize, 1024usize, 16usize); let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); + let mut off = 0usize; for f in 0..frames { + // lane-dpm1: the WHOLE picture scrolls 5 px per frame and freezes + // on frame 8, so (a) every block of the frozen frame -- including + // mi(0,0), which has no spatial neighbour at all -- still codes + // real motion against the references that are not its twin, and + // (b) 40 eighth-pels projected over the pyramid's distances lands + // on non-multiples of 8 (40/2 = 20 -> 16). A patch moving inside a + // static background was NOT sensitive: there the used stack slots + // came from spatial neighbours that agreed, and the rounded + // temporal entries never won one. + if f > 0 && f != 8 { + off = (off + 5) % h; + } let mut y = vec![0u8; w * h]; for row in 0..h { + let src = (row + off) % h; for col in 0..w { // 2..=4 distinct values per 16x16 block, all dark: the // screen-content detector's own counting rule. y[row * w + col] = - 16 + ((col / 32 + row / 32) % 5) as u8 + ((col / 4 + row / 4) % 3) as u8; - } - } - let x0 = 200 + 9 * (f / 2); - for row in 300..428 { - for col in x0..x0 + 192 { - y[row * w + col] = - ((((col - x0) / 3) * 7 + ((row - 300) / 5) * 13) % 200 + 30) as u8; + 16 + ((col / 32 + src / 32) % 5) as u8 + ((col / 4 + src / 4) % 3) as u8; } } raw.extend_from_slice(&y); @@ -3815,7 +3830,7 @@ pub(crate) mod tests { .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) .arg(&src) - .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) + .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"]) .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) .stdin(Stdio::null()) .stdout(Stdio::piped()) diff --git a/lanes/dpm1.report.md b/lanes/dpm1.report.md new file mode 100644 index 00000000..d0f3928c --- /dev/null +++ b/lanes/dpm1.report.md @@ -0,0 +1,38 @@ +# lane-dpm1 — the native gate's decode assertion, all reference points + +## (0) The assertion now COLLECTS (encode.rs) +`external_ladder` no longer panics on the first bad reference point: every +failure is printed at once (`LADDER DECODE FAILURE: ...`) and pushed onto +`LADDER_FAILURES`; each gate calls `assert_ladder_decodes()` after its loop, so +the whole BD table still prints and every bad point is named. First run already +paid for itself: it found a SECOND failure (screen capture, crf 5) the +panic-at-first version hid, and it showed the bars failure is the 2160p clip, +not the 1080p one. + +## (1) bars ±1 — the charter's premise was mis-attributed +`bars 1080p` libaom crf 45 decodes EXACT (reproduced standalone: crop +1920x1024+0+28, 12 frames, -g 12, cpu-used 6, crf 45 -> our decode == ffmpeg, +byte for byte). The real failing row is **bars 2160p** (same crf 45, frame 1, +Y sample 66, ours 146 / ffmpeg 145). Status below. + +## (2) film B crf 5 — STALE premise, already closed +Regenerated from the manifest (film B, 00:40:00, crop 1920x1024+960+292): +`-cpu-used 6 -crf 5 -g 48` and `-g 12` both decode **sample-exact** vs ffmpeg +at this head (48 and 12 frames). No Golomb refusal. The lane-dkey/dgolomb +reports' "4th inter frame refuses" is pre-merge state. + +## (3) force_integer_mv fixture — now SENSITIVE +`stream.rs a_libaom_force_integer_mv_stream_decodes_exact`: source replaced by a +GLOBAL 5 px/frame vertical scroll of the screen-detector pattern, frozen on +frame 8, 16 frames, -g 16. With the fix stubbed (`if false && force_integer_mv`) +it now decodes WRONG at frame 8 luma sample 25695 (20 vs ffmpeg 19); with the +fix it is exact. Blind recipes tried: patch-in-static-background (the old one), +3 patches at 3 speeds with freezes at {5,9} / {4,8,12} / {8}, 3 px scroll. +Instrumented finding: a +64 perturbation of rounded candidates DID change the +output on those streams, so the rounded candidates were consumed but only in +slots whose ±4 eighth-pel difference never reached a coded block's mv. + +## OPEN +* bars 2160p libaom crf 45 frame 1 Y sample 66 (+-1 reconstruction). +* screen capture (OBS .mkv row) libaom crf 5 frame 0 (KEY) Y sample 0: 126 vs + 33 — a key-frame desync at the first sample.