forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-refs' (904af5ee): the frame interpolation filter is a real knob (mc::predict had hard-wired REGULAR), default byte-identical; the LAST2 census

Browse files at this commit

f1b38e0bad38e23aef33d4f77dcad18786903b60Ahmet Kaan GümüşParent: 15ab38bd381213
SMOOTH/SHARP refuted as frame defaults. A second past reference would
remove 7-10% of prediction SAD on both films at both levels (LAST2/LAST3
alias LAST's DPB slot today; slot 7 is free) -- built as its own lane.
crates/ec-av1/src/decode.rsmodified+10 -0
@@ -69,6 +69,14 @@ pub(crate) struct FrameCtx {
69 pub(crate) capture_stages: std::cell::Cell<bool>,69 pub(crate) capture_stages: std::cell::Cell<bool>,
70 pub(crate) stages: std::cell::RefCell<Option<FilterStages>>,70 pub(crate) stages: std::cell::RefCell<Option<FilterStages>>,
71 pub(crate) sb128_flag: std::cell::Cell<bool>,71 pub(crate) sb128_flag: std::cell::Cell<bool>,
72+ /// lane-refs: the frame-level `interpolation_filter` (spec 6.8.9) every
73+ /// motion compensation of THIS frame runs, already resolved to a kernel.
74+ /// `mc::predict` used to hardwire `Regular`, so the encoder's search,
75+ /// trial and recon could only ever build a REGULAR prediction whatever
76+ /// the frame header said; it lives here (and is copied by
77+ /// [`filter_ctx_copy`]) so a tile-search worker thread reads the same
78+ /// kernel the frame header wrote instead of the default.
79+ pub(crate) interp_filter: std::cell::Cell<crate::mc::InterpFilterKind>,
72 /// lane-lossless: this frame's `CodedLossless` (spec 5.9.12) -- every80 /// lane-lossless: this frame's `CodedLossless` (spec 5.9.12) -- every
73 /// segment at `qindex == 0` with zero plane deltas. It forces TX_4X4 with81 /// segment at `qindex == 0` with zero plane deltas. It forces TX_4X4 with
74 /// the Walsh-Hadamard transform on every plane, drops the `tx_type`82 /// the Walsh-Hadamard transform on every plane, drops the `tx_type`
@@ -163,6 +171,7 @@ impl FrameCtx {
163 // (`set_sb128`, stream.rs). The encoder's own contexts start at171 // (`set_sb128`, stream.rs). The encoder's own contexts start at
164 // the size this process encodes -- see [`FrameCtx::for_encoder`].172 // the size this process encodes -- see [`FrameCtx::for_encoder`].
165 sb128_flag: std::cell::Cell::new(false),173 sb128_flag: std::cell::Cell::new(false),
174+ interp_filter: std::cell::Cell::new(crate::mc::InterpFilterKind::Regular),
166 lossless_flag: std::cell::Cell::new(false),175 lossless_flag: std::cell::Cell::new(false),
167 cdef_bits: std::cell::Cell::new(0),176 cdef_bits: std::cell::Cell::new(0),
168 bit_depth: std::cell::Cell::new(8),177 bit_depth: std::cell::Cell::new(8),
@@ -260,6 +269,7 @@ impl<T: ?Sized> WithRef for T {}
260 pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {269 pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {
261 let out = FrameCtx::new();270 let out = FrameCtx::new();
262 out.bit_depth.set(fctx.bit_depth.get());271 out.bit_depth.set(fctx.bit_depth.get());
272+ out.interp_filter.set(fctx.interp_filter.get());
263 out.grain_bit_depth.set(fctx.grain_bit_depth.get());273 out.grain_bit_depth.set(fctx.grain_bit_depth.get());
264 out.superres.set(fctx.superres.get());274 out.superres.set(fctx.superres.get());
265 out.seg_mi_dims.set(fctx.seg_mi_dims.get());275 out.seg_mi_dims.set(fctx.seg_mi_dims.get());
crates/ec-av1/src/encode.rsmodified+215 -6
@@ -1967,6 +1967,49 @@ pub(crate) fn key_frame_headers_colour(
1967 /// 1 still holds the key frame however long the GOP runs.1967 /// 1 still holds the key frame however long the GOP runs.
1968 pub const GOLDEN_SLOT: u8 = 1;1968 pub const GOLDEN_SLOT: u8 = 1;
1969 1969
1970+/// lane-refs: the frame-level `interpolation_filter` (spec 6.8.9) every inter
1971+/// frame this encoder writes carries. `EC_AV1_INTERP=smooth|sharp` codes the
1972+/// EIGHTTAP_SMOOTH / EIGHTTAP_SHARP kernel instead of the default REGULAR --
1973+/// one filter for the whole frame, which is what libaom does on this content
1974+/// too (`lanes/obmc3.report.md` read `switchable_interp 0/0` out of its own
1975+/// stream, so a per-BLOCK filter search has no bits to win). The kernel
1976+/// reaches the search, the trials and the recon through
1977+/// `FrameCtx::interp_filter`, so the stream a decoder reads and the
1978+/// prediction the search priced are the same one.
1979+/// A PROCESS-GLOBAL [`frame_interp_filter`] override that wins over the
1980+/// environment (`u8::MAX` = unset), the shape [`set_inter_tx_search`] has:
1981+/// the witness that has to see a non-REGULAR kernel coded and decoded turns
1982+/// it on through this while holding [`crate::speed::knob_write`].
1983+static INTERP_OVERRIDE: std::sync::atomic::AtomicU8 =
1984+ std::sync::atomic::AtomicU8::new(u8::MAX);
1985+
1986+/// Sets [`INTERP_OVERRIDE`]; `None` clears it.
1987+#[allow(dead_code)] // set only from the `#[cfg(test)]` gates
1988+pub(crate) fn set_frame_interp(filter: Option<ec_av1_syntax::InterpolationFilter>) {
1989+ INTERP_OVERRIDE.store(
1990+ filter.map_or(u8::MAX, |f| f as u8),
1991+ std::sync::atomic::Ordering::Relaxed,
1992+ );
1993+}
1994+
1995+fn frame_interp_filter() -> ec_av1_syntax::InterpolationFilter {
1996+ use ec_av1_syntax::InterpolationFilter as F;
1997+ match INTERP_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) {
1998+ 0 => return F::Eighttap,
1999+ 1 => return F::EighttapSmooth,
2000+ 2 => return F::EighttapSharp,
2001+ _ => {}
2002+ }
2003+ static ENV: std::sync::LazyLock<Option<F>> = std::sync::LazyLock::new(|| {
2004+ crate::envflags::var("EC_AV1_INTERP").ok().map(|v| match v.as_str() {
2005+ "smooth" => F::EighttapSmooth,
2006+ "sharp" => F::EighttapSharp,
2007+ _ => F::Eighttap,
2008+ })
2009+ });
2010+ ENV.unwrap_or(F::Eighttap)
2011+}
2012+
1970 /// The frame header for a shown inter frame that predicts from the single2013 /// The frame header for a shown inter frame that predicts from the single
1971 /// slot `last_slot` (every `ref_frame_idx` entry names it) and refreshes that2014 /// slot `last_slot` (every `ref_frame_idx` entry names it) and refreshes that
1972 /// same slot with itself once coded. The sequence header is [`key_frame_headers`]'s,2015 /// same slot with itself once coded. The sequence header is [`key_frame_headers`]'s,
@@ -5819,7 +5862,7 @@ fn obmc_prediction(
5819 x / 2,5862 x / 2,
5820 y / 2,5863 y / 2,
5821 &refpix,5864 &refpix,
5822- Some(mc::InterpFilterKind::Regular),5865+ Some(fctx.interp_filter.get()),
5823 frame_width,5866 frame_width,
5824 )5867 )
5825 .ok()?;5868 .ok()?;
@@ -7251,6 +7294,10 @@ pub(crate) fn encode_key_frame_inner(
7251 render: (usize, usize),7294 render: (usize, usize),
7252 color_config: ColorConfig, fctx: &crate::decode::FrameCtx,7295 color_config: ColorConfig, fctx: &crate::decode::FrameCtx,
7253 ) -> Result<Encoded> {7296 ) -> Result<Encoded> {
7297+ // lane-refs: an intra frame runs no motion compensation, and the
7298+ // context is shared across the sequence -- put the kernel back to the
7299+ // default so nothing reads the previous inter frame's.
7300+ fctx.interp_filter.set(mc::InterpFilterKind::Regular);
7254 picture.check()?;7301 picture.check()?;
7255 if modes.is_empty() {7302 if modes.is_empty() {
7256 return Err(Error::unsupported(7303 return Err(Error::unsupported(
@@ -8542,8 +8589,8 @@ fn mc_trial_compound_typed(
8542 mc::REF_NO_SCALE,8589 mc::REF_NO_SCALE,
8543 side,8590 side,
8544 side,8591 side,
8545- mc::InterpFilterKind::Regular,8592+ fctx.interp_filter.get(),
8546- mc::InterpFilterKind::Regular,8593+ fctx.interp_filter.get(),
8547 dst,8594 dst,
8548 );8595 );
8549 }8596 }
@@ -8635,8 +8682,8 @@ fn predict_compound_u8(
8635 mc::REF_NO_SCALE,8682 mc::REF_NO_SCALE,
8636 side,8683 side,
8637 side,8684 side,
8638- mc::InterpFilterKind::Regular,8685+ fctx.interp_filter.get(),
8639- mc::InterpFilterKind::Regular,8686+ fctx.interp_filter.get(),
8640 dst,8687 dst,
8641 );8688 );
8642 }8689 }
@@ -10618,6 +10665,12 @@ pub(crate) fn encode_inter_frame(
10618 )?;10665 )?;
10619 header.render_width = render.0 as u32;10666 header.render_width = render.0 as u32;
10620 header.render_height = render.1 as u32;10667 header.render_height = render.1 as u32;
10668+ // lane-refs: this frame's motion-compensation kernel, written into the
10669+ // header AND armed on the context every prediction reads, in one place so
10670+ // the two cannot disagree (a header saying SMOOTH over a REGULAR-searched
10671+ // tile decodes to different pixels than the encoder scored).
10672+ header.interpolation_filter = frame_interp_filter();
10673+ fctx.interp_filter.set(mc::InterpFilterKind::from_header(header.interpolation_filter));
10621 let sign_bias = pyramid.map_or(crate::mvstack::NO_SIGN_BIAS, |p| p.sign_bias);10674 let sign_bias = pyramid.map_or(crate::mvstack::NO_SIGN_BIAS, |p| p.sign_bias);
10622 // The order hint behind each `ref_frame_idx` entry. The flat path's own10675 // The order hint behind each `ref_frame_idx` entry. The flat path's own
10623 // slot plan (`inter_frame_headers_slots`) is: every reference but10676 // slot plan (`inter_frame_headers_slots`) is: every reference but
@@ -11680,7 +11733,7 @@ pub(crate) fn encode_inter_frame(
11680 lf,11733 lf,
11681 h.allow_high_precision_mv,11734 h.allow_high_precision_mv,
11682 h.force_integer_mv,11735 h.force_integer_mv,
11683- Some(mc::InterpFilterKind::Regular),11736+ Some(fctx.interp_filter.get()),
11684 seq.enable_dual_filter,11737 seq.enable_dual_filter,
11685 h.reference_select,11738 h.reference_select,
11686 // lane-txi: this frame's own bit, not the hardcoded `true`11739 // lane-txi: this frame's own bit, not the hardcoded `true`
@@ -17083,4 +17136,160 @@ mod tests {
17083 eprintln!("PARITY q={q} bytes={} fnv1a={hash:016x} speed={} pyramid {:?} effective {:?}",17136 eprintln!("PARITY q={q} bytes={} fnv1a={hash:016x} speed={} pyramid {:?} effective {:?}",
17084 e.stream.len(), crate::speed::speed(), crate::encoder::Pyramid::from_env(), last_sequence_pyramid());17137 e.stream.len(), crate::speed::speed(), crate::encoder::Pyramid::from_env(), last_sequence_pyramid());
17085 }17138 }
17139+ /// lane-refs: IS A SECOND PAST REFERENCE WORTH RETAINING? `encoder.rs`'s
17140+ /// `ref_frame_idx` maps `LAST2`/`LAST3` onto `LAST`'s own DPB slot, so no
17141+ /// block can predict from the picture before `LAST` -- while rav1e's ARFs
17142+ /// read LAST@-4 plus LAST2@-8 and libaom holds up to seven distinct
17143+ /// pictures. Building that (a second retained slot, the search offering
17144+ /// it, a witness, a second motion search per block) is a week of wall on
17145+ /// the stage that already owns most of the encode, so this census prices
17146+ /// the lever FIRST (class `gate-blind-to-feature`, "count how often the
17147+ /// feature would fire before building the machine").
17148+ ///
17149+ /// The measurement is on the gate's own window and loader (`gate_crop`,
17150+ /// 12 pictures) of the two real films: every 16x16 luma block of every
17151+ /// picture gets one full-pel diamond search against the NEAR reference
17152+ /// and the same search against the FAR one, at the two lags the pyramid
17153+ /// actually offers -- (1, 2) for the leaf chain and (4, 8) for the ARF
17154+ /// level, rav1e's own pair. Reported per lag: the share of blocks the far
17155+ /// reference wins at all and by more than 10%, and -- the number the
17156+ /// decision is taken on -- the total SAD of best-of-{near, far} against
17157+ /// the total SAD of near alone, which is the prediction energy a second
17158+ /// reference could remove before any rate is paid for naming it.
17159+ ///
17160+ /// cargo test -p ec-av1 --release --lib -- --ignored last2_census --nocapture
17161+ #[test]
17162+ #[ignore = "reads the real films"]
17163+ fn last2_census() {
17164+ if !have_ffmpeg() {
17165+ eprintln!("SKIP last2_census: no ffmpeg");
17166+ return;
17167+ }
17168+ const SIDE: usize = 16;
17169+ // SAD of one 16x16 block against `r` at full-pel `(dy, dx)`, or
17170+ // `None` when the displaced block leaves the picture.
17171+ let sad = |cur: &Picture, r: &Picture, bx: usize, by: usize, mv: (isize, isize)| {
17172+ let (sy, sx) = (by as isize + mv.0, bx as isize + mv.1);
17173+ if sy < 0 || sx < 0 {
17174+ return None;
17175+ }
17176+ let (sy, sx) = (sy as usize, sx as usize);
17177+ if sy + SIDE > r.height || sx + SIDE > r.width {
17178+ return None;
17179+ }
17180+ let mut acc = 0u64;
17181+ for row in 0..SIDE {
17182+ let c = &cur.y[(by + row) * cur.width + bx..][..SIDE];
17183+ let p = &r.y[(sy + row) * r.width + sx..][..SIDE];
17184+ acc += c.iter().zip(p).map(|(&a, &b)| u64::from(a.abs_diff(b))).sum::<u64>();
17185+ }
17186+ Some(acc)
17187+ };
17188+ // A log-step diamond from the zero motion vector: the cheapest search
17189+ // that still finds real pans. Both references get exactly this one,
17190+ // so the comparison is search-fair.
17191+ let search = |cur: &Picture, r: &Picture, bx: usize, by: usize| -> u64 {
17192+ let mut best = (sad(cur, r, bx, by, (0, 0)).unwrap_or(u64::MAX), (0isize, 0isize));
17193+ let mut step = 16isize;
17194+ while step >= 1 {
17195+ let centre = best.1;
17196+ for (dy, dx) in [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] {
17197+ let mv = (centre.0 + dy * step, centre.1 + dx * step);
17198+ if let Some(s) = sad(cur, r, bx, by, mv) {
17199+ if s < best.0 {
17200+ best = (s, mv);
17201+ }
17202+ }
17203+ }
17204+ step /= 2;
17205+ }
17206+ best.0
17207+ };
17208+ println!("| clip | level (near/far lag) | blocks | far wins | far wins >10% | SAD near | SAD best-of | energy removed |");
17209+ println!("|---|---|---|---|---|---|---|---|");
17210+ for (name, path, seek) in native_gate_clips() {
17211+ if !name.starts_with("film ") {
17212+ continue;
17213+ }
17214+ let (vf, cw, ch) = crate::probe::gate_crop(&path);
17215+ let pictures = clip_frames_vf(&path, &seek, &vf, cw, ch, 12);
17216+ for (near, far, level) in [(1usize, 2usize, "leaf"), (4usize, 8usize, "ARF")] {
17217+ let (mut blocks, mut wins, mut big) = (0u64, 0u64, 0u64);
17218+ let (mut near_sad, mut best_sad) = (0u64, 0u64);
17219+ for i in far..pictures.len() {
17220+ let cur = &pictures[i];
17221+ let (rn, rf) = (&pictures[i - near], &pictures[i - far]);
17222+ for by in (0..ch.saturating_sub(SIDE - 1)).step_by(SIDE) {
17223+ for bx in (0..cw.saturating_sub(SIDE - 1)).step_by(SIDE) {
17224+ let (n, f) = (search(cur, rn, bx, by), search(cur, rf, bx, by));
17225+ blocks += 1;
17226+ wins += u64::from(f < n);
17227+ big += u64::from(f as f64 * 1.1 < n as f64);
17228+ near_sad += n;
17229+ best_sad += n.min(f);
17230+ }
17231+ }
17232+ }
17233+ let pct = |a: u64| 100.0 * a as f64 / blocks.max(1) as f64;
17234+ println!(
17235+ "| {name} | {level} ({near}/{far}) | {blocks} | {:.1}% | {:.1}% | {near_sad} | {best_sad} | {:.2}% |",
17236+ pct(wins),
17237+ pct(big),
17238+ 100.0 * (near_sad - best_sad) as f64 / near_sad.max(1) as f64,
17239+ );
17240+ }
17241+ }
17242+ }
17243+
17244+ /// lane-refs: THE FRAME FILTER REACHES THE PIXELS. `mc::predict` used to
17245+ /// hardwire the REGULAR kernel, so the encoder could not have coded a
17246+ /// SMOOTH or SHARP frame even if the header had said so -- the search,
17247+ /// the trials, the recon and the frame header now all read
17248+ /// `FrameCtx::interp_filter`. Each of the three kernels codes its own
17249+ /// distinct stream (a filter that never reached the prediction would code
17250+ /// the same bytes as REGULAR, class `symbol consumption gap`), and ffmpeg
17251+ /// reconstructs every frame of each of them exactly, which is what proves
17252+ /// the header and the prediction agree.
17253+ #[test]
17254+ fn each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly() {
17255+ let _knobs = crate::speed::knob_write();
17256+ if !have_ffmpeg() {
17257+ eprintln!("SKIP each_frame_interpolation_filter_codes_its_own_stream: no ffmpeg");
17258+ return;
17259+ }
17260+ let (width, height) = (256usize, 128usize);
17261+ // A HALF-PEL pan: an integer-pel one reads no filter tap at all, so
17262+ // all three kernels would code the same bytes and the test would pass
17263+ // on a wiring that does nothing (class `fixture proves the symbol, not
17264+ // the signal`). `panned_test_card` shifts by whole pixels, so the
17265+ // search finds the sub-pel positions off the reconstruction instead:
17266+ // three frames of a slow diagonal pan.
17267+ let pictures: Vec<Picture> = (0..3).map(|i| panned_test_card(width, height, i * 3)).collect();
17268+ let mut streams = Vec::new();
17269+ for filter in [
17270+ ec_av1_syntax::InterpolationFilter::Eighttap,
17271+ ec_av1_syntax::InterpolationFilter::EighttapSmooth,
17272+ ec_av1_syntax::InterpolationFilter::EighttapSharp,
17273+ ] {
17274+ set_frame_interp(Some(filter));
17275+ let fctx = &crate::decode::FrameCtx::for_encoder();
17276+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
17277+ .unwrap_or_else(|e| panic!("{filter:?}: {e}"));
17278+ let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);
17279+ assert_eq!(decoded.len(), 3, "{filter:?}: decoded frame count");
17280+ for (i, (frame, decoded)) in encoded.frames.iter().zip(&decoded).enumerate() {
17281+ assert_eq!(decoded.y, frame.reconstruction.y, "{filter:?} frame {i}: luma");
17282+ assert_eq!(decoded.u, frame.reconstruction.u, "{filter:?} frame {i}: U");
17283+ assert_eq!(decoded.v, frame.reconstruction.v, "{filter:?} frame {i}: V");
17284+ }
17285+ streams.push((filter, encoded.stream));
17286+ }
17287+ set_frame_interp(None);
17288+ for (i, (fa, a)) in streams.iter().enumerate() {
17289+ for (fb, b) in &streams[i + 1..] {
17290+ assert_ne!(a, b, "{fa:?} and {fb:?} coded the same bytes");
17291+ }
17292+ }
17293+ }
17294+
17086 }17295 }
crates/ec-av1/src/mc.rsmodified+6 -1
@@ -1048,7 +1048,12 @@ pub(crate) fn predict(
1048 y_q4,1048 y_q4,
1049 block_w,1049 block_w,
1050 block_h,1050 block_h,
1051- InterpFilterKind::Regular,1051+ // lane-refs: the FRAME's kernel (spec 6.8.9), not a hardwired
1052+ // `Regular` -- `FrameCtx::interp_filter` is what the encoder set from
1053+ // the header it is about to write, and every decode leaves it at
1054+ // `Regular` (the decoder's own inter path calls
1055+ // `predict_with_filters` with the kernels it parsed).
1056+ fctx.interp_filter.get(),
1052 dst, fctx,1057 dst, fctx,
1053 );1058 );
1054 }1059 }
lanes/refs.report.mdadded+142 -0
@@ -0,0 +1,142 @@
1+# lane-refs — the reference set (LAST2) and the frame interpolation filter
2+
3+Worktree `edith_codecs-refs`, branch `lane-refs` off main 68e96c56. Every gate
4+arm is the prebuilt release lib-test binary running `bd_rate_screen_native`
5+(12 pictures, `gop 12`, four quantizers, native `gate_crop` window); every row
6+is read off that log's own header line, never off the argument order.
7+
8+## 0. The controls reproduce
9+
10+| clip | control (vs libaom / vs rav1e) | charter |
11+|---|---|---|
12+| film A, 12 frames | +21.7 / -4.4 | +21.7 / -4.4 |
13+| film B, 12 frames | +26.9 / -0.6 | +26.9 / -0.6 |
14+| screen capture, 12 frames | +20.1 / -30.4 | +20.1 / -30.4 |
15+
16+All three land to the digit.
17+
18+## 1. LAST2 — the census, before the machinery
19+
20+`encoder.rs`'s `ref_frame_idx` maps LAST2/LAST3 onto LAST's own DPB slot, so
21+the picture before LAST is not merely unoffered to the search, it is not
22+retained at all. Building it out is not a small diff (a second retained slot
23+per level, `ref_frame_idx` / `refresh_frame_flags` / `ref_frame_sign_bias` /
24+order hints for it, a per-reference mv stack, the writer's `single_ref` tree,
25+`record_mi`, and — the expensive part — a SECOND motion search per block, on
26+the stage that already owns most of the encode wall: `search_inter_block`'s
27+existing extra references are priced search-FREE for exactly that reason).
28+So the lever was PRICED first (`last2_census`, `--ignored`, 3.3 s):
29+
30+every 16x16 luma block of the gate's own 12-picture window of both real films
31+gets one full-pel diamond search against the NEAR reference and the same
32+search against the FAR one, at the two lags the pyramid offers — (1, 2) for
33+the leaf chain, (4, 8) for the ARF level, which is rav1e's own pair.
34+
35+| clip | level (near/far lag) | blocks | far wins | far wins >10% | SAD near | SAD best-of | prediction energy removed |
36+|---|---|---|---|---|---|---|---|
37+| film A | leaf (1/2) | 57600 | 38.7% | 19.0% | 20974762 | 19509622 | **6.99%** |
38+| film A | ARF (4/8) | 23040 | 37.8% | 21.0% | 12015492 | 10776319 | **10.31%** |
39+| film B | leaf (1/2) | 76800 | 38.1% | 21.2% | 18946199 | 17572121 | **7.25%** |
40+| film B | ARF (4/8) | 30720 | 44.3% | 22.5% | 8539904 | 7824079 | **8.38%** |
41+
42+READ IT AS: a second past reference is chosen by ~4 blocks in 10 and by more
43+than 10% of SAD by ~1 in 5; best-of-two removes 7-10% of the total residual
44+ENERGY before any rate is paid for naming the reference or for the second
45+search. That is the largest un-taken prediction lever measured on this content
46+so far (the anchors' non-skip area is the standing film B gap), and the ARF
47+level — where the census is strongest — is exactly the level libaom and rav1e
48+spend their extra slots on.
49+
50+**Decision: the lever is worth building, and it does not fit this lane.** The
51+census is the charter's own first step ("before wiring the full search"), and
52+the build is chartered as its own lane below.
53+
54+## 2. The frame interpolation filter — WIRED, MEASURED, REJECTED as a default
55+
56+The premise held: `mc::predict` hardwired `InterpFilterKind::Regular`, so the
57+encoder could not have coded a SMOOTH or SHARP frame whatever the header said.
58+The kernel now travels on `FrameCtx::interp_filter` (copied into every
59+tile-search worker by `filter_ctx_copy`, so a threaded search reads the same
60+kernel), and `encode_inter_frame` writes that one kernel into the header —
61+one place, so header and prediction cannot disagree. `EC_AV1_INTERP=
62+smooth|sharp` (or `set_frame_interp`) selects it; the default is unchanged
63+REGULAR and byte-identical.
64+
65+| arm | film A | film B | keep rule |
66+|---|---|---|---|
67+| REGULAR (control) | +21.7 / -4.4 | +26.9 / -0.6 | — |
68+| SMOOTH | **+40.9 / +10.2** | +26.3 / -0.4 | film A loses 19.2 / 14.6 |
69+| SHARP | +24.0 / -2.9 | +28.4 / +0.6 | both rows worse on both columns |
70+
71+SMOOTH is a catastrophe on film A (19 BD points) for 0.6 of a point on film B's
72+libaom column while its rav1e column goes 0.2 the wrong way; SHARP is worse
73+everywhere. The keep rule (both films down on both columns) is nowhere near
74+met, so **REGULAR stays the default at every preset** and the per-frame
75+CHOOSER was not built: its ceiling is film B's +0.6/-0.2 mixed-sign move, and
76+its downside when a proxy mispicks is film A's 19 points (ladder rung 1 — it
77+does not need to exist). The wiring stays because it is what makes the
78+measurement possible at all and because it removes the hardwired-kernel
79+ceiling; it is proved by a witness rather than left as a claim.
80+
81+## 3. Invariants
82+
83+* `each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly`
84+ (new, NOT ignored): each of the three kernels codes a DISTINCT stream (a
85+ kernel that never reached the prediction would code REGULAR's bytes — class
86+ `symbol consumption gap`) and ffmpeg reconstructs every frame of each of them
87+ exactly against our own reconstruction. Green.
88+* `cargo test -p ec-av1 --release --lib`: see §4.
89+* `cargo check --workspace --all-targets`: see §4.
90+
91+## 4. Suite and check
92+
93+`timeout 900 cargo check --workspace --all-targets -j4`: **0 errors, 0 ec-av1
94+warnings** (the 22 warnings are ec-opus' missing struct-field docs and
95+ec-vorbis' unused `decode_capture`, both pre-existing on main).
96+
97+THE LIB SUITE DOES NOT FIT A 900 s CAP ON THIS BOX. Two whole-suite arms died
98+`RC=124` -- the second one alone on the prebuilt binary, 168 of 253
99+`stream::` tests in, no failure anywhere -- so the suite was SPLIT into three
100+disjoint-by-filter arms, each under the cap:
101+
102+| arm | filter | result |
103+|---|---|---|
104+| A | `--skip stream::` | 333 passed, 0 failed, 30 ignored (661 s) |
105+| B | `stream:: --skip 10bit` | 197 passed, 0 failed, 15 ignored (822 s) |
106+| C | `10bit` | 42 passed, 0 failed, 1 ignored (99 s) |
107+
108+Arms A and C overlap on exactly 2 tests (the two `10bit` names outside
109+`stream::`, counted from `--list`), and the binary holds 616 tests, so the
110+UNION is **570 passed / 46 ignored / 0 failed**, which accounts for every test
111+in the binary (570 + 46 = 616) and includes this lane's two: the filter
112+witness (passed) and `last2_census` (ignored).
113+
114+Invariants, all green, all on the prebuilt release binary:
115+
116+| invariant | run | result |
117+|---|---|---|
118+| every preset decodes sample-exact through both decoders | `--include-ignored`, `EC_COMP_MISMATCH=1` | 1 passed |
119+| tile / filter-stage bytes do not depend on the thread count | `--include-ignored` | 2 passed |
120+| facade identity + `predicted_coeff_bits_track_the_tile_the_writer_wrote` | default | 2 passed |
121+| pins 8562 / 33357 | `the_encoders_own_streams_are_byte_identical_to_their_pins`, in arm A | passed, UNCHANGED -- every lever ships off, so nothing was re-pinned |
122+| the filter witness | `each_frame_interpolation_filter_codes_its_own_stream_ffmpeg_decodes_exactly` | passed (landed in f6a107ff) |
123+
124+## 5. Deferred
125+
126+* **LAST2 / a real second past reference — deferred, chartered.** What it
127+ needs: DPB slot 7 is free (the key's copy, never read back), so the leaf
128+ chain can alternate its refresh between slots 0 and 7 and name the older of
129+ the two as LAST2 while the ARF levels take theirs from the anchor pair;
130+ `ref_frame_idx[1]`, `refresh_frame_flags`, `ref_frame_sign_bias`, the order
131+ hints and a per-reference mv stack follow; the cheapest first arm offers
132+ LAST2 through the EXISTING search-free `extra` path (NEARESTMV/GLOBALMV
133+ only, as GOLDEN is offered today) so the second motion search — and its wall,
134+ which is the user's stated priority — is a second arm, not a prerequisite.
135+ Witness: a clip where the picture before LAST is the better reference, N
136+ blocks coded off LAST2, exact through ffmpeg and `decode_stream`, hidden
137+ frame display order intact. Unblocked by: a lane of its own with the wall
138+ budget for the desync hunt.
139+* **The per-frame interpolation-filter chooser — dropped, not deferred**: §2's
140+ table is its refutation, not a gap.
141+* The long-GOP gate was not run: nothing from this lane changes a default, so
142+ there is nothing for it to confirm.