diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 237e7d99..dd402ca8 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -11964,12 +11964,13 @@ pub(crate) struct PyramidFrame { /// one's (film A 5.9%) with the two past neighbours at strength 30, and the /// filtered picture is 50.1 dB from the source it replaces -- 4 dB above the /// quality the ARF is coded at, so the substitution itself costs little. +// lane-lookahead: the CALLER sizes `window` (`ARF_TF_WIN` past neighbours and +// `ARF_TF_WIN_FUT` future ones); this takes every picture in it. pub(crate) fn arf_temporal_filter(src: &Picture, window: &[Picture], strength: f64) -> Picture { const SIDE: usize = 16; let neighbours: Vec<&Picture> = window .iter() .filter(|p| p.width == src.width && p.height == src.height) - .take(crate::encoder::arf_tf_window()) .collect(); if neighbours.is_empty() || strength <= 0.0 { return src.clone(); diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index e320148c..4dbd0138 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -1238,6 +1238,58 @@ pub(crate) fn arf_tf_window() -> usize { .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_WIN)) } +/// lane-lookahead: how many DISPLAY-FUTURE neighbours the top ARF's filter +/// takes out of the buffered next group ([`crate::speed::ARF_TF_WIN_FUT`], +/// `EC_AV1_ARF_TF_WIN_FUT=`). Inert without [`lookahead`]. +pub(crate) fn arf_tf_window_future() -> usize { + match ARF_TF_FUT_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) { + usize::MAX => {} + n => return n, + } + std::env::var("EC_AV1_ARF_TF_WIN_FUT") + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| crate::speed::at(&crate::speed::ARF_TF_WIN_FUT)) +} + +/// PROCESS-GLOBAL overrides of the two lane-lookahead knobs, the shape +/// [`set_last2`] has (this crate's tests never call `set_var`); `u8::MAX` / +/// `usize::MAX` is unset, and a witness holds [`crate::speed::knob_write`] +/// while it uses them. +static LOOKAHEAD_OVERRIDE: std::sync::atomic::AtomicU8 = + std::sync::atomic::AtomicU8::new(u8::MAX); +static ARF_TF_FUT_OVERRIDE: std::sync::atomic::AtomicUsize = + std::sync::atomic::AtomicUsize::new(usize::MAX); + +/// Sets [`LOOKAHEAD_OVERRIDE`]; `None` clears it. +#[allow(dead_code)] // set only from the `#[cfg(test)]` witness +pub(crate) fn set_lookahead(on: Option) { + LOOKAHEAD_OVERRIDE.store( + on.map_or(u8::MAX, u8::from), + std::sync::atomic::Ordering::Relaxed, + ); +} + +/// Sets [`ARF_TF_FUT_OVERRIDE`]; `None` clears it. +#[allow(dead_code)] // set only from the `#[cfg(test)]` witness +pub(crate) fn set_arf_tf_future(n: Option) { + ARF_TF_FUT_OVERRIDE.store(n.unwrap_or(usize::MAX), std::sync::atomic::Ordering::Relaxed); +} + +/// lane-lookahead: whether the pyramid path holds one group of lookahead +/// ([`crate::speed::LOOKAHEAD`], `EC_AV1_LOOKAHEAD=0|1`). +fn lookahead() -> bool { + match LOOKAHEAD_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) { + 0 => return false, + 1 => return true, + _ => {} + } + match std::env::var("EC_AV1_LOOKAHEAD").ok() { + Some(v) => v != "0", + None => crate::speed::LOOKAHEAD, + } +} + fn tpl_pyramid() -> bool { match std::env::var("EC_AV1_TPL_PYRAMID").ok() { Some(v) => v != "0", @@ -1315,6 +1367,11 @@ pub struct Av1Encoder { dpb: [Option; 8], /// Pictures held back waiting for their mini-GOP's hidden frame. pending: Vec<(u64, Picture)>, + /// lane-lookahead: the CLOSED group waiting for the next group's sources + /// before it is coded, so its top ARF -- the group's last picture in + /// display order -- has display-future neighbours available. Always empty + /// with [`lookahead`] off. + ready: Vec<(u64, Picture)>, /// The flat path's delay queue: pictures whose packets later calls /// return, each coded with the ones behind it as its lookahead window /// (lane-av1facade, deepened to [`crate::encode::tpl_depth`] - 1 on @@ -1415,6 +1472,7 @@ impl Av1Encoder { pyramid: None, dpb: [const { None }; 8], pending: Vec::new(), + ready: Vec::new(), held: std::collections::VecDeque::new(), anchor: 0, leaf_hist: Vec::new(), @@ -1618,7 +1676,7 @@ impl Av1Encoder { // A key frame closes whatever group is open (there is nothing for // its leaves to point forward at across the boundary) and then // restarts the pyramid from the key itself. - let mut packets = self.drain_pending()?; + let mut packets = self.drain_all(Some(picture))?; packets.push(self.encode_key(order, picture)?); return Ok(packets); } @@ -1655,7 +1713,7 @@ impl Av1Encoder { } return Ok(packets); } - self.drain_pending() + self.drain_all(None) } /// The flat path: one picture and its lookahead (the next source picture, @@ -1885,6 +1943,11 @@ impl Av1Encoder { // from, already padded (lane-arfcen). Empty codes the frame at one // lambda, which is what the whole pyramid path used to do. lookahead: &[Picture], + // lane-lookahead: DISPLAY-FUTURE pictures for the SOURCE temporal + // filter only (the top ARF's, out of the buffered next group), never + // for the temporal lambda map -- keeping the filter's window and the + // tpl window separate levers. Empty everywhere else. + future: &[Picture], ) -> Result { let render = (self.config.width, self.config.height); let order_hint = (order & 0x7f) as u32; @@ -1973,7 +2036,18 @@ impl Av1Encoder { false => 0.0, }; let source = match tf > 0.0 { - true => crate::encode::arf_temporal_filter(&source, lookahead, tf), + true => { + // lane-lookahead: the filter's window is sized HERE -- up to + // `ARF_TF_WIN` display-past neighbours (nearest first) and + // then the display-future ones the caller buffered. + let window: Vec = lookahead + .iter() + .take(arf_tf_window()) + .chain(future.iter()) + .cloned() + .collect(); + crate::encode::arf_temporal_filter(&source, &window, tf) + } false => source, }; let encoded = || -> Result { encode_inter_frame( @@ -2029,14 +2103,52 @@ impl Av1Encoder { Ok(self.packet(cropped.stream, false, order, level)) } - /// Codes the open mini-GOP: its hidden frame first, then its leaves, then - /// the `show_existing_frame` header that puts the hidden frame back in - /// display order. + /// Closes the open mini-GOP. With the lookahead off that codes it + /// straight away, which is byte for byte what this encoder did before + /// lane-lookahead; with it on the open group takes the `ready` slot and + /// the group ALREADY there is coded, with the open one's sources as its + /// display-future window. fn drain_pending(&mut self) -> Result> { - if self.pending.is_empty() { + if !lookahead() { + let group = std::mem::take(&mut self.pending); + return self.code_group(group, &[]); + } + let group = std::mem::take(&mut self.ready); + let next = std::mem::take(&mut self.pending); + let packets = self.code_group(group, &next); + self.ready = next; + packets + } + + /// Codes every group still buffered, in coding order -- what a key frame + /// (`next` is the key picture, the last buffered group's own + /// display-future) and the end of stream (`None`) both need. The tail + /// group can be any length, down to the single picture `code_group` + /// codes as one shown leaf. + fn drain_all(&mut self, next: Option<&Picture>) -> Result> { + let tail: Vec<(u64, Picture)> = next + .filter(|_| lookahead()) + .map(|p| vec![(self.next_index, p.clone())]) + .unwrap_or_default(); + let ready = std::mem::take(&mut self.ready); + let pending = std::mem::take(&mut self.pending); + let mut packets = self.code_group(ready, &pending)?; + packets.extend(self.code_group(pending, &tail)?); + Ok(packets) + } + + /// Codes one mini-GOP: its hidden frame first, then its leaves, then + /// the `show_existing_frame` header that puts the hidden frame back in + /// display order. `future` is the display-future sources the caller has + /// buffered past this group (lane-lookahead), empty without a lookahead. + fn code_group( + &mut self, + group: Vec<(u64, Picture)>, + future: &[(u64, Picture)], + ) -> Result> { + if group.is_empty() { return Ok(Vec::new()); } - let group: Vec<(u64, Picture)> = std::mem::take(&mut self.pending); let mut packets = Vec::with_capacity(group.len() + 1); // The lookahead window of the group's picture at index `pos`: the // display-order successors inside this group, or -- for the group's @@ -2080,10 +2192,21 @@ impl Av1Encoder { Level::Leaf, pyramid.leaf_q_offset, &tpl_window(0, false), + &[], )?); self.anchor = 1 - self.anchor; return Ok(packets); } + // lane-lookahead: the display-future half of the top ARF's temporal + // filter window, padded like the frame itself. Empty when the + // lookahead is off (`future` is then always empty) or when the filter + // asks for no future neighbours, which is what keeps the default + // stream byte-identical. + let arf_future: Vec = future + .iter() + .take(arf_tf_window_future()) + .map(|(_, p)| p.padded_to(SUPERBLOCK)) + .collect(); // The group's top level: the last picture, hidden, off the anchor. packets.push(self.encode_pyramid_inter( arf_order, @@ -2106,6 +2229,10 @@ impl Av1Encoder { Level::Arf, pyramid.arf_q_offset, &tpl_window(group.len() - 1, true), + // lane-lookahead: the group's top ARF is its LAST picture in + // display order, so every picture of the next group is a + // display-future neighbour of it -- nearest first. + &arf_future, )?); let leaves = group.len() - 1; // THE THIRD LEVEL: a second hidden frame at the middle of the leaf @@ -2140,6 +2267,7 @@ impl Av1Encoder { Level::Arf, offset, &tpl_window(at, false), + &[], )?); } // THE FOURTH LEVEL: one hidden frame at the middle of each half of @@ -2177,6 +2305,7 @@ impl Av1Encoder { Level::Arf, offset, &tpl_window(pos, false), + &[], )?); } } @@ -2253,6 +2382,7 @@ impl Av1Encoder { Level::Leaf, pyramid.leaf_q_offset, &tpl_window(i, false), + &[], )?); } let packet = show_existing(self, next_anchor_slot, arf_order)?; @@ -3515,6 +3645,149 @@ mod tests { assert_eq!(shown, arfs, "one show_existing_frame per hidden frame"); } + /// A picture whose content is a static gradient plus a per-picture + /// pseudo-random +-2 of noise: motion search matches the neighbours + /// almost exactly, so the ARF temporal filter's weights are near 1 and + /// the filter actually changes the source (a moving test card gives every + /// neighbour a large MSE, weight ~0, and the filter is a no-op that would + /// make the future-window witness below pass blind). + fn noisy_card(width: usize, height: usize, t: usize) -> Picture { + let mut picture = Picture::grey(width, height); + let mut seed = (t as u64 + 1).wrapping_mul(0x9e37_79b9_7f4a_7c15); + for y in 0..height { + for x in 0..width { + seed = seed.wrapping_mul(6_364_136_223_846_793_005).wrapping_add(1); + let noise = ((seed >> 33) % 5) as i32 - 2; + let base = 40 + (x + y) as i32 / 2; + picture.y[y * width + x] = base.saturating_add(noise).clamp(0, 255) as u16; + } + } + for i in 0..(width / 2) * (height / 2) { + picture.u[i] = 110; + picture.v[i] = 140; + } + picture + } + + /// lane-lookahead's correctness witness. One group of lookahead + /// (`Av1Encoder::drain_pending` hands the closed group to `ready` and + /// codes the group before it) must not change WHAT is coded: + /// + /// * with the future half of the filter window empty the stream is byte + /// for byte the one the encoder coded without a lookahead, at every + /// run length -- 1 picture (no hidden frame at all), 7 (a short group), + /// 8 (exactly `mini_gop`), 9 (a group plus a tail) and 17 -- and at a + /// GOP short enough (8) that key frames drain the buffer mid-run; + /// * every run decodes to exactly its picture count through OUR decoder + /// and through ffmpeg, sample-exact between the two, so the flush and + /// the `show_existing_frame` order survive the delay; + /// * and with ONE future neighbour the top ARF's source filter actually + /// reads it -- the stream MOVES (class gate-blind-to-feature: a + /// buffered picture nothing consumes would pass every check above). + #[test] + fn the_lookahead_holds_one_group_and_still_codes_every_picture() { + let _knobs = crate::speed::knob_write(); + // The preset is PROCESS-GLOBAL and another test may have left it + // anywhere: at a high one every block of this fixture codes as skip + // (17 pictures in 493 bytes) and the source filter cannot change a + // byte, which failed the future-half assertion below in the suite and + // passed it standalone (class process-global-knob-races-tests). + let was = crate::speed::speed(); + crate::speed::set_speed(0); + crate::encode::force_screen(Some(false)); + let (width, height) = (128usize, 128usize); + let run = |n: usize, gop: usize, on: bool, fut: usize| -> (Vec, Vec) { + set_lookahead(Some(on)); + set_arf_tf_future(Some(fut)); + let config = EncoderConfig { + // FINE (not the 120 the other facade tests use): at a coarse + // quantizer this fixture's ARF codes almost pure skip (17 + // pictures in 493 bytes) and a filtered source quantizes back + // to the same bytes, which made the future-half assertion + // below depend on where the suite's other tests had left the + // process-global preset. At q=60 the anchor carries real + // coefficients and the filter must move them. + base_q_idx: 60, + width, + height, + gop, + colour: Colour::Bt709Limited, + tile_cols_log2: 0, + tile_rows_log2: 0, + }; + let mut enc = Av1Encoder::with_pyramid(config, Pyramid::default()).unwrap(); + let sources: Vec = (0..n).map(|t| noisy_card(width, height, t)).collect(); + let packets = encode_all(&mut enc, &sources); + // The content gate is process-global and so is the preset: if + // either has been flipped under this test the pyramid is gone and + // there is no ARF to filter, which is a different failure from + // "the future neighbour changed nothing" (the suite reported the + // second when it meant the first). + assert!( + enc.pyramid().is_some(), + "{n} pictures at gop {gop}: the content gate dropped the pyramid, so no ARF was coded (speed {})", + crate::speed::speed(), + ); + (concat(&packets), packets) + }; + for gop in [32usize, 8] { + for n in [1usize, 7, 8, 9, 17] { + let (flat, flat_packets) = run(n, gop, false, 0); + let (held, packets) = run(n, gop, true, 0); + assert_eq!( + flat.len(), + held.len(), + "{n} pictures at gop {gop}: the lookahead changed the stream LENGTH" + ); + assert!(flat == held, "{n} pictures at gop {gop}: the stream is not byte-identical"); + assert_eq!( + packets.iter().map(|p| (p.order, p.key, p.level)).collect::>(), + flat_packets.iter().map(|p| (p.order, p.key, p.level)).collect::>(), + "{n} pictures at gop {gop}: coding order/levels moved" + ); + let ours = crate::stream::decode_stream(&held).expect("our decoder"); + assert_eq!(ours.len(), n, "{n} pictures at gop {gop}: our decoder's count"); + if !have_ffmpeg() { + continue; + } + let theirs = ffmpeg_decode_luma(&held, width, height); + assert_eq!(theirs.len(), n, "{n} pictures at gop {gop}: ffmpeg's count"); + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { + let got: Vec = a.y.iter().map(|&v| v as u8).collect(); + assert!( + got == *b, + "{n} pictures at gop {gop}, display frame {i}: ours differs from ffmpeg" + ); + } + } + } + // The future half REACHES the filter, and what it produces still + // decodes exactly. + let (base, _) = run(17, 32, true, 0); + let (symmetric, _) = run(17, 32, true, 1); + set_lookahead(None); + set_arf_tf_future(None); + assert!( + base != symmetric, + "one display-future neighbour left the top ARF's filter unchanged \ + ({} B vs {} B, preset {})", + base.len(), + symmetric.len(), + crate::speed::speed() + ); + let ours = crate::stream::decode_stream(&symmetric).expect("our decoder"); + assert_eq!(ours.len(), 17, "the symmetric arm's display-order count"); + if have_ffmpeg() { + let theirs = ffmpeg_decode_luma(&symmetric, width, height); + assert_eq!(theirs.len(), 17, "the symmetric arm's ffmpeg count"); + for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() { + let got: Vec = a.y.iter().map(|&v| v as u8).collect(); + assert!(got == *b, "symmetric arm, display frame {i}: ours differs from ffmpeg"); + } + } + crate::speed::set_speed(was); + } + fn pyramid_round_trip(pyramid: Pyramid, hidden: usize) { let (width, height) = (128usize, 128usize); let config = EncoderConfig { diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 300d9444..701f3b5c 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -433,7 +433,47 @@ pub(crate) const ARF_TF_MID: [f64; 11] = [0.0; 11]; /// measured with two neighbours on EACH side; four pictures of one-sided /// past is a different (and worse) window, and the anchor drifts away from /// the leaves it has to predict. -pub(crate) const ARF_TF_WIN: [usize; 11] = [2; 11]; +/// +/// lane-lookahead gave the encoder the future half ([`LOOKAHEAD`]) and swept +/// the SYMMETRIC window (this many past neighbours and [`ARF_TF_WIN_FUT`] +/// future ones) on the long-GOP gate at strength 2: +/// +/// | window | film A | film B | +/// |---|---|---| +/// | +-0 (2 past, the control) | +22.0/-8.4 | +76.5/+1.2 | +/// | +-1 | +21.4/-8.8 | +74.3/+0.3 | +/// | +-2 | +21.2/-8.8 | +72.3/-0.9 | +/// | **+-3 (ships)** | **+21.2/-8.8** | **+72.1/-1.2** | +/// | +-4 | +21.5/-8.7 | +72.5/-1.0 | +/// +/// Bracketed on both sides and down on all four columns against the control +/// (film A -0.8/-0.4, film B -4.4/-2.4). The census's shape is confirmed: +/// what a wider window cost past-only, it buys symmetric. +pub(crate) const ARF_TF_WIN: [usize; 11] = [3; 11]; + +/// lane-lookahead: how many DISPLAY-FUTURE neighbours the top ARF's temporal +/// filter averages in, on top of [`ARF_TF_WIN`] past ones. Non-zero needs +/// [`LOOKAHEAD`] -- the future pictures are the next group's sources, which +/// the encoder buffers only with the lookahead on. +/// `EC_AV1_ARF_TF_WIN_FUT=` overrides it. The sweep is [`ARF_TF_WIN`]'s +/// table (the two move together, +-n); strength 3 at +-2 loses to strength 2 +/// (film A +21.5/-8.7, film B +73.1/-0.7 against +21.2/-8.8 and +72.3/-0.9), +/// so [`ARF_TF`] stays where lane-arftf put it. +pub(crate) const ARF_TF_WIN_FUT: [usize; 11] = [3; 11]; + +/// lane-lookahead: whether [`crate::encoder::Av1Encoder`] holds one whole +/// mini-GOP of lookahead -- the next group's sources are buffered before the +/// current group's top ARF is coded, so that ARF has display-FUTURE pictures +/// available. Costs one group of latency (`mini_gop` pictures, 8 by default) +/// and one group of source buffer -- [`crate::encode::Picture`] holds u16 +/// samples, so a 3840x2160 4:2:0 picture is 24.9 MB and the group is 199 MB +/// on top of the group the encoder already buffered -- and nothing else: with +/// [`ARF_TF_WIN_FUT`] at 0 nothing reads the future half and the streams are +/// byte-identical. `EC_AV1_LOOKAHEAD=0|1` overrides it. What it BUYS is +/// [`ARF_TF_WIN_FUT`]: the symmetric filter window is the long-GOP gate's +/// film A -0.8/-0.4 and film B -4.4/-2.4, and the buffer is also what a +/// two-pass-like allocation would need. +pub(crate) const LOOKAHEAD: bool = true; /// lane-arfpred: the qindex below which the ARF temporal filter is OFF -- /// libaom scales `arnr` strength with the quantizer and stops filtering at diff --git a/lanes/lookahead.report.md b/lanes/lookahead.report.md new file mode 100644 index 00000000..50fc1ab5 --- /dev/null +++ b/lanes/lookahead.report.md @@ -0,0 +1,147 @@ +# lane-lookahead — one mini-GOP of lookahead, and the ARF filter's future half + +Worktree `edith_codecs-lookahead`, branch `lane-lookahead` off main `eb2af4ee`. +Deciding gate `encode::tests::bd_rate_film_long_gop` (48 pictures, both film +rows, BD vs libaom `cpu-used 6` / rav1e `speed 6`, lower is better). +**Control RUN, not quoted: film A +22.0 / −8.4, film B +76.5 / +1.2** — the +charter's +22.2/−8.2 and +77.5/+1.7 to within the gate's own noise. + +## 1. The machinery — one group held back + +`Av1Encoder::drain_pending` used to code the group it had just closed. It now +hands that group to a new `ready` slot and codes the group ALREADY there, +passing the just-closed group's sources as its display-FUTURE window; the +group's top ARF is its last picture in display order, so every picture of the +next group is a future neighbour of it. `code_group` (the old `drain_pending` +body) takes the group and that future slice as arguments, and `drain_all` +codes both buffered groups in coding order — what a key frame (the key +picture itself is then the last group's future) and `flush` (nothing behind +it) both need. + +* **Latency**: one `mini_gop`, 8 pictures at the default pyramid, on top of + the group the encoder already buffered. +* **Memory**: `Picture` holds u16 samples, so a 3840x2160 4:2:0 source is + 24.9 MB and the extra group is **199 MB at 4K** (56 MB at 1080p). Nothing + else is retained: `ready` holds sources, not reconstructions. +* Output picture order, timestamps and the `show_existing_frame` headers are + untouched — the packets are the same packets, emitted one group later. + +`speed::LOOKAHEAD` (`EC_AV1_LOOKAHEAD=0|1`) switches it off: the open group is +then coded straight away, which is byte for byte the old encoder. + +### The witness — `encoder::tests::the_lookahead_holds_one_group_and_still_codes_every_picture` + +At 1, 7, 8, 9 and 17 pictures, at GOP 32 (one key) and GOP 8 (keys drain the +buffer mid-run), with a gradient-plus-noise fixture: + +* the stream is **byte-identical** to the same run with the lookahead off, and + the packet (order, key, level) list is identical — the delay changes nothing + about WHAT is coded while the future window is empty; +* every run decodes to **exactly its picture count** through `decode_stream` + AND through ffmpeg, **sample-exact between the two**, so the flush, the + short final group (1 picture = one shown leaf, no hidden frame) and the + display order all survive the delay; +* with ONE future neighbour the stream **MOVES** — the buffered picture is + really consumed ([[gate-blind-to-feature]]: everything above would pass over + a lookahead nothing reads) — and still decodes sample-exact. + +RED first, twice, and both reds were the FIXTURE, not the encoder. In the +split suite (never standalone) the future-half assertion failed with "493 B +both": at the q=120 the other facade tests use, this fixture's ARF codes +almost pure skip, and a filtered source quantizes back to the same bytes — +whether it does depends on where the suite's other tests left the +process-global preset, which is why it passed alone and failed in company +(class `process-global-knob-races-tests`). Pinning `set_speed(0)` under +`knob_write` (the byte pins' shape) did NOT fix it — the added assertion that +`enc.pyramid()` survived the content gate ruled the second suspect out — and +what fixed it is coding the witness at **q=60**, where the anchor carries real +coefficients and a filtered source must move them. Both guards ship. + +The gate is a second witness: `native_bd_arm` asserts our decoder's +display-order count and ffmpeg sample-exactness for every one of its 48-picture +streams, and all six long-GOP arms below ran RC=0. + +## 2. The symmetric filter window — it pays, and it is bracketed + +`speed::ARF_TF_WIN` is the PAST neighbour count, new `speed::ARF_TF_WIN_FUT` +(`EC_AV1_ARF_TF_WIN_FUT=`) the FUTURE one; the caller now sizes the window +and `encode::arf_temporal_filter` takes all of it. The tpl lookahead window is +a separate argument (`encode_pyramid_inter`'s new `future` reaches the source +filter only), so this arm is the filter's window and nothing else. + +Long-GOP gate, strength 2 (lane-arftf's shipped point): + +| window | film A | film B | +|---|---|---| +| ±0 = 2 past (control) | +22.0 / −8.4 | +76.5 / +1.2 | +| ±1 | +21.4 / −8.8 | +74.3 / +0.3 | +| ±2 | +21.2 / −8.8 | +72.3 / −0.9 | +| **±3 (ships)** | **+21.2 / −8.8** | **+72.1 / −1.2** | +| ±4 | +21.5 / −8.7 | +72.5 / −1.0 | + +**Down on all four columns against the control** (film A −0.8/−0.4, film B +−4.4/−2.4), which clears the keep rule outright, and BRACKETED on both sides — +±4 is worse than ±3 on all four, so this is not a result at its own search +edge. `arf_pred_census`'s reading is confirmed: what a wider window cost +past-only (lane-arftf refuted 4 past at +22.8/−7.8, +78.9/+2.8) it buys +symmetric. + +Deviation from the charter, named: ±3 and ±4 were run on top of the chartered +±1/±2 because ±2 was the best point of a range with nothing above it. + +Strength re-swept at ±2, as chartered: + +| arm | film A | film B | +|---|---|---| +| ±2, strength 2 | +21.2 / −8.8 | +72.3 / −0.9 | +| ±2, strength 3 | +21.5 / −8.7 | +73.1 / −0.7 | + +Worse on three columns, so `ARF_TF` stays at 2. + +## 3. Guard rows — `bd_rate_screen_native`, 12 pictures, all five rows + +| clip | control | shipped (lookahead + ±3) | Δ | +|---|---|---|---| +| bars 1080p | −3.5 / −19.0 | −3.4 / −19.0 | +0.1 / 0.0 | +| bars 2160p | +8.6 / −13.7 | +8.6 / −13.7 | 0.0 / 0.0 | +| film A | +17.9 / −6.4 | +17.9 / −6.3 | 0.0 / +0.1 | +| film B | +22.9 / −3.6 | +22.8 / −3.6 | −0.1 / 0.0 | +| screen capture | +14.4 / −33.2 | +14.4 / −33.2 | byte-identical | + +Nothing moves by more than 0.1. Measured fact worth keeping: at 12 pictures +`group_target` absorbs the tail into ONE group of 11, so there is no next +group to buffer and **the 12-frame gate cannot see this lever at all** — a +±2 arm run at that length was byte-identical to its control on every row. The +rows above move only through the wider PAST window (2 → 3). + +## 4. Invariants + +* **Byte pins UNCHANGED**, green at the default and at `EC_AV1_SPEED=6`: + `(150, 8290, 0x92cb11033d1f5813)`, `(60, 33227, 0x57ee6b1f8eacd881)`. Not a + miss — the pin fixture is four pictures through `encode_sequence`, one + truncated group whose ARF has two past neighbours and no next group at all, + so neither the lookahead nor a 3-wide window can reach it. +* `encoder::tests::bitrate_target_lands_within_5_percent_over_48_frames` + green and NOT near its bound any more: pyramid arms −0.1% (768 kbps), +0.0% + (1536 kbps), +0.0% (2 Mbps); flat arms −2.5% / −2.8% / −1.8%. +* Split suite at the shipped default: `--skip stream::` **346 passed / 0 + failed**, `stream:: --skip 10bit` **202 passed / 0 failed**, `10bit` **42 + passed / 0 failed** (590 in all). +* `--ignored --exact + encoder::tests::every_speed_preset_decodes_sample_exact_through_both_decoders` + 1 passed. +* `cargo check --workspace --all-targets -j4`: 0 errors, 0 `ec-av1` warnings. + +## 5. What this lane did NOT do + +* `deferred: the tpl window at the ARF (the charter's task 3) — the buffered + future pictures reach the SOURCE filter only; encode_pyramid_inter still + gets tpl_window(pos, true), the display-past leaves, for its temporal + lambda map — unblocked by a lane with long-GOP arms to spend, and it is now + a one-argument change (pass the same future slice as lookahead).` +* `deferred: two-pass-like allocation over the buffered group (the rate loop + still plans per level from gop_shape, blind to the group it holds) — out of + this charter's scope; the buffer it needs now exists.` +* `deferred: per-block weight refinement in arf_temporal_filter (libaom + weights each 16x16 block against each neighbour separately) — untouched + since lane-arftf.`