diff --git a/crates/ec-av1/examples/syntax_census.rs b/crates/ec-av1/examples/syntax_census.rs index e578c73a..5b6c2bd7 100644 --- a/crates/ec-av1/examples/syntax_census.rs +++ b/crates/ec-av1/examples/syntax_census.rs @@ -116,6 +116,9 @@ fn pct(n: u64, total: u64) -> String { format!("{:.1}%", 100.0 * n as f64 / total.max(1) as f64) } +const REFS: [&str; 8] = + ["INTRA", "LAST", "LAST2", "LAST3", "GOLDEN", "BWDREF", "ALTREF2", "ALTREF"]; + fn report(label: &str, f: &Frame, frames: usize) { let area = f.area.iter().sum::().max(1); println!("\n== {label} ({frames} frames, {} bytes) ==", f.bytes); @@ -126,8 +129,6 @@ fn report(label: &str, f: &Frame, frames: usize) { pct(f.area[2], area), pct(f.skip_area, area), ); - const REFS: [&str; 8] = - ["INTRA", "LAST", "LAST2", "LAST3", "GOLDEN", "BWDREF", "ALTREF2", "ALTREF"]; println!( " refs (area): {}", REFS.iter() @@ -252,6 +253,7 @@ fn main() { // the frames above are coded in (a pyramid codes a hidden ARF ahead of the // leaves that predict from it, and re-outputs it later with // `show_existing_frame`) -- so it is its own table rather than a column. + let mut psnrs: Vec = Vec::new(); if let Some(src) = args.get(1).map(|p| std::fs::read(p).expect("source")) { let mut sum = 0.0; let mut rows = Vec::new(); @@ -261,6 +263,7 @@ fn main() { let Some(b) = src.get(i * frame_len..(i + 1) * frame_len) else { break }; let want: Vec = b[..luma].iter().map(|&v| u16::from(v)).collect(); let p = psnr(&pic.y, &want); + psnrs.push(p); sum += p; rows.push(format!("{i}:{p:.2}")); } @@ -273,6 +276,36 @@ fn main() { ); } + // lane-arfcen: one full report PER CODED FRAME, so an ARF of ours can be + // put next to the reference encoder's ARF at the same display position. + if std::env::var("EC_CENSUS_PERFRAME").as_deref() == Ok("1") { + for f in &frames { + let p = psnrs.get(f.order_hint as usize).copied().unwrap_or(f64::NAN); + let refs: Vec = (0..7) + .filter(|i| f.refs[i + 1] > 0) + .map(|i| { + format!( + "{}@{:+}", + REFS[i + 1], + i64::from(f.ref_hints[i]) - i64::from(f.order_hint), + ) + }) + .collect(); + report( + &format!( + "frame {} {} hint {} q {} PSNR-Y {p:.2} dB refs [{}]", + f.idx, + f.kind, + f.order_hint, + f.qindex, + refs.join(" "), + ), + f, + 1, + ); + } + } + for kind in ["key", "arf", "leaf"] { let set: Vec<&Frame> = frames.iter().filter(|f| f.kind == kind).collect(); if !set.is_empty() { diff --git a/crates/ec-av1/src/census.rs b/crates/ec-av1/src/census.rs index d5afe15f..e771d7b4 100644 --- a/crates/ec-av1/src/census.rs +++ b/crates/ec-av1/src/census.rs @@ -50,6 +50,11 @@ pub struct Frame { pub kind: &'static str, /// `base_q_idx`. pub qindex: u8, + /// `OrderHint` of this frame, i.e. its display position (lane-arfcen). + pub order_hint: u32, + /// `OrderHints[LAST..=ALTREF]`, so a row can name its references' display + /// distance rather than only which slot it read (lane-arfcen). + pub ref_hints: [u32; 7], /// Tile payload bytes of this frame. pub bytes: usize, /// `delta_q_present`. @@ -132,6 +137,8 @@ pub(crate) fn frame_start(header: &ec_av1_syntax::FrameHeader, bytes: usize, idx idx, kind, qindex: header.quantization.base_q_idx, + order_hint: header.order_hint, + ref_hints: header.order_hints, bytes, delta_q: header.delta.q_present, segmentation: header.segmentation.enabled, diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index d55c563b..1c6b027c 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -137,6 +137,26 @@ fn reach_sb_px(fctx: &crate::decode::FrameCtx) -> usize { /// defaults below are on: +50.1 / -15.4). It spends ~5% more encode wall. const LAMBDA_SCALE: f64 = 0.0275; +/// The rate weight a HIDDEN frame (a pyramid ARF, coded but not shown) codes +/// under, as a multiple of [`LAMBDA_SCALE`] (lane-arfcen). +/// +/// The ARF-vs-ARF census says our top ARF codes residual over HALF its area +/// (rav1e's, at the same display position, over 26-30%) and comes out 1.4-2.5x +/// its bytes at the same PSNR, while every leaf that predicts from it is +/// still 0.4 dB behind rav1e's -- i.e. the ARF's extra fidelity is bought at +/// a rate weight fitted on shown frames and does not propagate. This is the +/// one knob that prices a hidden frame's rate differently from its q, which +/// the pyramid's q offsets cannot do (they move lambda and step together). +const HIDDEN_LAMBDA_FACTOR: f64 = 1.0; + +/// [`HIDDEN_LAMBDA_FACTOR`], swept by `EC_AV1_LAMBDA_HIDDEN` in any build. +fn hidden_lambda_factor() -> f64 { + match std::env::var("EC_AV1_LAMBDA_HIDDEN").ok().and_then(|v| v.parse().ok()) { + Some(f) => f, + None => HIDDEN_LAMBDA_FACTOR, + } +} + /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that /// picks it is the thing running. A release build has no such knob. fn lambda_scale() -> f64 { @@ -9040,7 +9060,13 @@ pub(crate) fn encode_inter_frame( let search = Search { base_q_idx, deadzone, - lambda: lambda_scale() * step * step, + lambda: lambda_scale() + * match pyramid { + Some(p) if !p.show_frame => hidden_lambda_factor(), + _ => 1.0, + } + * step + * step, modes: &KEY_FRAME_MODES, top_k: prune_top_k_inter(), screen, @@ -13604,8 +13630,19 @@ mod tests { // base now, not 16 ([`crate::encoder::Pyramid::leaf_q_offset`]) -- 9778 // -> 9835 at q=150 and 35450 -> 35798 at q=60. // `EC_AV1_PYRAMID=8:-32:16:-8:-48` restores these. + // Re-taken on lane-arfcen: the pyramid path hands every frame the + // lookahead window its temporal lambda map needs + // (`crate::encoder::tpl_pyramid`), which it never had, so every + // superblock of these four pictures is priced at its own lambda -- + // 9835 -> 9859 at q=150 and 35798 -> 35904 at q=60. + // `EC_AV1_TPL_PYRAMID=0` restores these. + // Re-taken again on lane-arfcen: a group's top ARF names the ARF from + // two groups back as its own `ALTREF_FRAME` + // (`crate::encoder::arf_altref`) instead of the key frame it already + // reads as `GOLDEN` -- 9859 -> 9853 at q=150 and 35904 -> 35866 at + // q=60. `EC_AV1_ARF_ALTREF=0` restores these. let pins: [(u8, usize, u64); 2] = - [(150, 9835, 0xfdac_0219_4a6e_111e), (60, 35798, 0xe57e_aa3f_8b48_d206)]; + [(150, 9853, 0x0f6d_bbc8_b72c_ceb3), (60, 35866, 0xbd00_f4ed_e283_3ce4)]; for (q, bytes, hash) in pins { let encoded = encode_sequence(&source, q, 0.5).unwrap(); assert_eq!( diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 376c7088..87efc064 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -1016,6 +1016,44 @@ const MID_DEFAULT: Option = Some(-8); /// is gated off). const KEY_DEFAULT: i16 = -48; +/// Whether the pyramid path hands each frame a lookahead window, i.e. +/// whether the temporal lambda map (`encode::tpl_lambda_factors`) runs on +/// the DEFAULT stream at all. It did not until lane-arfcen: the pyramid +/// reorders pictures, so this path passed `&[]` and the map -- measured and +/// shipped on the flat path -- was inert on every frame of every pyramid +/// stream, including the ARFs that carry 54% of a long-GOP stream's bytes +/// (class `tool disabled in every gate recipe`). +fn tpl_pyramid() -> bool { + match std::env::var("EC_AV1_TPL_PYRAMID").ok() { + Some(v) => v != "0", + None => TPL_PYRAMID, + } +} + +/// [`tpl_pyramid`]'s default. +const TPL_PYRAMID: bool = true; + +/// Whether a group's TOP ARF names the ARF from TWO groups back as its own +/// `ALTREF_FRAME` (lane-arfcen). It has always named `GOLDEN_SLOT` there, +/// which for a top ARF is the key frame it already reads as `GOLDEN`, i.e. +/// its second reference is the same picture as its first for the first group +/// and adds nothing after: the ARF-vs-ARF census reads +/// `LAST@-8 GOLDEN@-8` on our first ARF where rav1e's reads two DISTINCT +/// anchors. The slot the ARF is about to refresh still holds that older +/// anchor while this frame is coded, so naming it costs no extra DPB slot. +fn arf_altref() -> bool { + match std::env::var("EC_AV1_ARF_ALTREF").ok() { + Some(v) => v != "0", + None => ARF_ALTREF, + } +} + +/// [`arf_altref`]'s default. ON since its long-GOP arm: film A +/// +42.8%/+4.5% -> +40.9%/+3.1% and film B +127.3%/+32.9% -> +125.6%/+32.0% +/// (BD vs libaom cpu-used 6 / vs rav1e speed 6), i.e. both films down on both +/// columns. +const ARF_ALTREF: bool = true; + /// The AV1 software encoder: [`EncoderConfig`] in, one [`Packet`] out per /// [`Av1Encoder::encode`] call — or, with a [`Pyramid`] configured, a /// coding-order burst of them per [`Av1Encoder::encode_frames`] call plus a @@ -1595,6 +1633,10 @@ impl Av1Encoder { // ARF and the mid one) at different offsets, and they share the // rate-control slot but not the offset. offset: i16, + // The lookahead window this frame's temporal lambda map is built + // from, already padded (lane-arfcen). Empty codes the frame at one + // lambda, which is what the whole pyramid path used to do. + lookahead: &[Picture], ) -> Result { let render = (self.config.width, self.config.height); let order_hint = (order & 0x7f) as u32; @@ -1660,10 +1702,10 @@ impl Av1Encoder { show_frame, sign_bias, }), - // The pyramid path reorders pictures, so its own buffer is not - // a lookahead window: the temporal lambda weighting is off on - // this path (lane-av1tpl). - &[], + // lane-arfcen: the group's own sources ARE this frame's window + // (`tpl_window`); it was `&[]` here, which switched the temporal + // lambda map off on every frame the default stream codes. + lookahead, ) }(); // Name the pyramid position in any failure: an error out of the tile // writer or the filter search is otherwise indistinguishable between @@ -1699,6 +1741,23 @@ impl Av1Encoder { } 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 + // top ARF, the last picture, whose successors are not buffered yet -- + // the leaves BEHIND it in reverse display order, which are exactly + // the pictures that predict backward from it. Padded like the frame + // itself, as `encode_inter_frame` wants it. + let tpl_window = |pos: usize, back: bool| -> Vec { + let depth = crate::encode::tpl_depth(); + if !tpl_pyramid() || depth < 2 { + return Vec::new(); + } + let window: Vec<&Picture> = match back { + false => group[pos + 1..].iter().map(|(_, p)| p).collect(), + true => group[..pos].iter().rev().map(|(_, p)| p).collect(), + }; + window.into_iter().take(depth - 1).map(|p| p.padded_to(SUPERBLOCK)).collect() + }; let anchor_slot = ANCHOR_SLOTS[self.anchor]; let next_anchor_slot = ANCHOR_SLOTS[1 - self.anchor]; let (arf_order, arf_picture) = group.last().cloned().expect("non-empty"); @@ -1715,6 +1774,7 @@ impl Av1Encoder { true, Level::Leaf, pyramid.leaf_q_offset, + &tpl_window(0, false), )?); self.anchor = 1 - self.anchor; return Ok(packets); @@ -1725,10 +1785,18 @@ impl Av1Encoder { &arf_picture, anchor_slot, next_anchor_slot, - GOLDEN_SLOT, + // lane-arfcen: the slot this ARF refreshes still holds the ARF + // from two groups back, so naming it here gives the frame a + // SECOND, distinct past anchor instead of the key it already + // reads as GOLDEN. + match arf_altref() { + true => next_anchor_slot, + false => GOLDEN_SLOT, + }, false, Level::Arf, pyramid.arf_q_offset, + &tpl_window(group.len() - 1, true), )?); let leaves = group.len() - 1; // THE THIRD LEVEL: a second hidden frame at the middle of the leaf @@ -1761,6 +1829,7 @@ impl Av1Encoder { false, Level::Arf, offset, + &tpl_window(at, false), )?); } // THE FOURTH LEVEL: one hidden frame at the middle of each half of @@ -1796,6 +1865,7 @@ impl Av1Encoder { false, Level::Arf, offset, + &tpl_window(pos, false), )?); } } @@ -1852,6 +1922,7 @@ impl Av1Encoder { true, Level::Leaf, pyramid.leaf_q_offset, + &tpl_window(i, false), )?); } let packet = show_existing(self, next_anchor_slot, arf_order)?; diff --git a/crates/ec-av1/src/motion.rs b/crates/ec-av1/src/motion.rs index d352856a..c55c994c 100644 --- a/crates/ec-av1/src/motion.rs +++ b/crates/ec-av1/src/motion.rs @@ -340,17 +340,26 @@ pub(crate) fn search( fn dist_initial_step(dist: u32) -> i32 { let base = if seeded() { seeded_step() } else { SEARCH_INITIAL_STEP_PEL }; static K: std::sync::OnceLock = std::sync::OnceLock::new(); + // lane-arfcen: readable in ANY build, like the encoder's other search + // margins -- the constant below was swept when the deepest reference in + // the GOP sat at distance 4, and the arm that re-sweeps it at the + // shipped mini-GOP of 8 runs through the release `enc_probe`. let k = *K.get_or_init(|| match std::env::var("EC_AV1_MV_DIST_SCALE").ok() { - Some(v) if cfg!(test) => v.parse().unwrap_or(MV_DIST_SCALE), - _ => MV_DIST_SCALE, + Some(v) => v.parse().unwrap_or(MV_DIST_SCALE), + None => MV_DIST_SCALE, }); if dist <= 1 || k <= 0.0 { return base; } let scaled = f64::from(base) * k.mul_add(f64::from(dist - 1), 1.0); - // Past 4x the base the log stage spends its rounds on vectors no - // reference in this encoder's GOP reaches. - scaled.round().clamp(f64::from(base), f64::from(base * 4)) as i32 + // The ceiling on that widening. `MV_DIST_CAP` x the base; swept by + // `EC_AV1_MV_DIST_CAP`. + static CAP: std::sync::OnceLock = std::sync::OnceLock::new(); + let cap = *CAP.get_or_init(|| match std::env::var("EC_AV1_MV_DIST_CAP").ok() { + Some(v) => v.parse().unwrap_or(MV_DIST_CAP), + None => MV_DIST_CAP, + }); + scaled.round().clamp(f64::from(base), f64::from(base * cap)) as i32 } /// The distance scale [`dist_initial_step`] ships with. Swept on the BD gate @@ -362,6 +371,14 @@ fn dist_initial_step(dist: u32) -> i32 { /// is near-tie churn, not a gradient. const MV_DIST_SCALE: f64 = 0.5; +/// How many times the base step [`dist_initial_step`] may widen to. Written +/// as 4 when the deepest reference in the GOP sat at distance 4 ("past 4x the +/// base the log stage spends its rounds on vectors no reference in this +/// encoder's GOP reaches"), which the shipped mini-GOP of 8 falsified: the +/// top ARF predicts at distance 8 and its own widened step (36 at +/// [`MV_DIST_SCALE`] 0.5) was being clamped back to 32. +const MV_DIST_CAP: i32 = 4; + /// [`search`], plus the running best cost after every round any of its three /// stages ran — what `cost_is_monotone_non_increasing_over_the_search` below /// checks. diff --git a/lanes/arfcen.report.md b/lanes/arfcen.report.md new file mode 100644 index 00000000..d0569cea --- /dev/null +++ b/lanes/arfcen.report.md @@ -0,0 +1,184 @@ +# lane-arfcen — why a hidden ARF of ours costs what it costs + +Instrument: `census::Frame` now carries `order_hint` + `ref_hints`, and +`examples/syntax_census` prints ONE FULL REPORT PER CODED FRAME under +`EC_CENSUS_PERFRAME=1` (display-order PSNR joined to the coded frame through +its own order hint, references named by display DISTANCE). Both streams are +read by the same decoder, so every number below is comparable. + +Arming (film B, 48 frames, the long-GOP gate's own window and seek): + + EC_ENC_SS=00:40:00 EC_ENC_OUT= enc_probe gate 0 48 150 + -> 90674 B, byte-exact with bd_rate_film_long_gop's q=150 point + ffmpeg ... -g 48 -c:v librav1e -rav1e-params speed=6:quantizer=Q:... + EC_AV1_BITCENSUS=1 EC_CENSUS_PERFRAME=1 syntax_census source.yuv + +rav1e's PSNR-matched point is **quantizer 110** (45.751 dB / 75452 B), not the +125 the charter assumed (44.990 dB / 51680 B): ours reads 45.473 dB / 90674 B. +Interpolated to our PSNR rav1e needs ~65.6 kB, i.e. **we are +38% at matched +quality**. + +## 1. Level census, same 48 display pictures + +| | frames | qindex | bytes | share | B/frame | PSNR-Y | +|---|---|---|---|---|---|---| +| ours key | 1 | 102 | 19321 | 21.6% | 19321 | 47.67 | +| ours top ARF (dist 8) | 6 | 118 | 48126 | 53.8% | 8021 | 46.01 | +| ours mid ARF (dist 4) | 6 | 142 | 10331 | 11.5% | 1722 | 45.79 | +| ours leaf | 35 | 162 | 11736 | 13.1% | 335 | 45.26 | +| rav1e key | 1 | 80 | 20763 | 28.0% | 20763 | 47.95 | +| rav1e top ARF (dist 4) | 11 | 104 | 42590 | 57.5% | 3872 | 45.97 | +| rav1e 2nd ARF (dist 2) | 12 | 122 | 6446 | 8.7% | 537 | 45.48 | +| rav1e leaf | 24 | 139 | 4290 | 5.8% | 179 | 45.69 | + +## 2. ARF vs ARF at the SAME display position + +| display | ours B/q/PSNR | intra% | comp% | skip% | NEW% | rav1e B/q/PSNR | intra% | comp% | skip% | +|---|---|---|---|---|---|---|---|---|---| +| 8 | 8449 / 118 / 46.13 | 10.3 | 4.2 | 50.3 | 35.8 | 5945 / 104 / 45.99 | 1.8 | 0.0 | 73.7 | +| 16 | 8889 / 118 / 46.18 | 8.8 | 6.2 | 47.7 | 34.5 | 4869 / 104 / 45.92 | 0.3 | 0.0 | 72.8 | +| 24 | 9897 / 118 / 45.61 | 8.3 | 13.4 | 47.7 | 31.2 | 5911 / 104 / 45.28 | 0.4 | 0.0 | 73.8 | +| 32 | 4941 / 118 / 46.62 | 1.9 | 6.6 | 51.9 | 41.5 | 2087 / 104 / 46.15 | 0.0 | 0.0 | 90.0 | +| 40 | 7023 / 118 / 46.04 | 3.3 | 2.8 | 47.7 | 38.5 | 2854 / 104 / 45.53 | 0.1 | 0.0 | 85.4 | +| 47/44 | 8927 / 118 / 45.50 | 4.9 | 6.9 | 48.1 | 39.1 | 3151 / 104 / 45.37 | 0.0 | 0.0 | 86.0 | + +Reference sets: ours `LAST@-8 GOLDEN@-8` (the first ARF names the SAME picture +twice) then `LAST@-8 GOLDEN@-16/-24`; rav1e `LAST@-4 LAST2@-4/-8`. Coded mv +magnitude, our top ARF: 47.1% in 2-16 px, 40.0% in 16-64 px, 0.0% over 64 px; +rav1e's: 76.5% / 8.3% / 0.0%. + +## 3. Do our expensive ARFs buy cheaper leaves? No. + +Per display picture, the six positions our encoder codes as top ARFs against +the same six positions in rav1e's stream, and everything else: + +| | our bytes | rav1e bytes | delta | +|---|---|---|---| +| key (1 picture) | 19321 | 20763 | -1442 | +| our 6 ARF positions | 48126 | 24817 | **+23309** | +| the other 41 pictures | 22067 | 28509 | -6442 | + +So the WHOLE +15.4 kB gap (and 6 kB more) sits in the six pictures we code at +prediction distance 8; our non-anchor pictures are already 23% CHEAPER than +rav1e's -- though 0.3-0.4 dB worse (leaves 45.26 vs 45.69 dB). + +## 4. Ranked mechanisms, and what each one measured + +Every arm below is `enc_probe`'s q=150 and q=90 points on film B (48 frames, +the gate's window), read against the control's own rate/quality slope +(3.46 dB per decade of bytes between its two points), so "better" means +fewer bytes AT the arm's own PSNR. + +| # | mechanism | bytes at stake | verdict | +|---|---|---|---| +| 1 | anchor density (rav1e anchors every 2 pictures, ours every 4) | 22.1 kB of leaf+mid | **REFUTED** | +| 2 | hidden-frame rate weight (ARF codes residual on 50% of area, rav1e 26-30%) | 48.1 kB of ARF | **REFUTED** | +| 3 | motion search widening at distance 8 (`MV_DIST_SCALE`, its 4x cap) | 48.1 kB of ARF | **INERT** | +| 4 | the temporal lambda map never ran on the pyramid path | the whole stream | **KEPT, small** | +| 5 | ARF q offset / key allocation | — | already swept (lane-arfq, lane-keyq) | + +1. `EC_AV1_PYRAMID` density arms: `4:-32:12:-8:-48` 108567 B/45.809 dB and + 613170 B/48.283 (3.8% better at q150, 3.8% WORSE at q90), `4:-24:12:-8:-48` + 92200/45.504 and 535188/48.102 (0.4% better, 2.7% worse), `2:-32:12:-8:-48` + 127348/45.982 and 778014/48.492 (tie, 15% worse). Denser anchors pay only + at the low-rate end and lose at the rates the gate is scored on -- the same + verdict lane-pyr6 got for a fourth level, now with the mini-GOP-4 shape + (rav1e's exact structure) measured too. +2. `EC_AV1_LAMBDA_HIDDEN` (a rate weight for hidden frames only, on top of + the q-derived lambda -- the one knob the q offsets cannot express): + 1.5 -> 84513/45.297 (4.8% WORSE), 2.0 -> 81454/45.160, 3.0 -> 75372/44.910, + 0.5 -> 106859/45.733 (0.9% better at q150, 5.5% worse at q90). 1.0 is the + optimum; our ARF's operating point is not mispriced. +3. `EC_AV1_MV_DIST_SCALE` x `EC_AV1_MV_DIST_CAP`: (0.5,8) 90534/45.471, + (1.0,8) 90531/45.481, (2.0,8) 90526/45.473, (1.0,16) 90650/45.474 against + the control's 90674/45.473 -- +-0.2% bytes, +-0.01 dB. The distance-8 ARF + is NOT search-range-bound (and its coded mv histogram, 0.0% over 64 px, is + the content, not a clamp). + +## 5. The lever: the temporal lambda map was inert on every default stream + +`Av1Encoder::encode_pyramid_inter` passed `&[]` as the lookahead window with +the comment "the pyramid path reorders pictures, so its own buffer is not a +lookahead window: the temporal lambda weighting is off on this path". The +pyramid has been the DEFAULT since lane-av1pyrdef, so the propagating tpl map +lane-av1tpl2/3 measured and shipped (`TPL_DEPTH` 8, `TPL_STRENGTH` 0.5) has +been running on nothing but the flat A/B arm ever since -- class +`tool disabled in every gate recipe`. + +The fix is the window the group already holds: for a frame inside the leaf +run, its display-order successors in `pending`; for the group's top ARF (the +last picture of the group, whose successors are not buffered yet) the group's +own leaves in REVERSE display order, which are exactly the pictures that +predict backward from it. `EC_AV1_TPL_PYRAMID=0` restores the old behaviour. + +Probe arms on film B (control = the old `&[]`): + +| arm | q150 | q90 | vs control at equal PSNR | +|---|---|---|---| +| off (control) | 90674 B / 45.473 dB | 479686 B / 47.978 dB | — | +| on, depth 8 | 91206 / 45.511 | 482161 / 47.989 | -1.9% / -0.2% | +| on, depth 4 | 91453 / 45.506 | 481555 / 47.991 | -1.4% / -0.3% | +| on, depth 2 | 91328 / 45.489 | 481497 / 47.990 | -0.6% / -0.3% | + +Wall is unchanged (101.5 s vs 101.2 s for the two-point ladder). + +## 6. Gate tables + +Long-GOP arm (`bd_rate_film_long_gop`, 48 frames, BD vs libaom cpu-used 6 / +vs rav1e speed 6). The control arm was RUN, not quoted, and lands on the +recorded defaults to the digit: + +| arm | film A | film B | +|---|---|---| +| control (`EC_AV1_TPL_PYRAMID=0`) | +43.1% / +4.6% | +129.0% / +34.3% | +| **arm 1: tpl on the pyramid path** | **+42.8% / +4.5%** | **+127.3% / +32.9%** | + +| **arm 2: + a second past anchor on the top ARF** | **+40.9% / +3.1%** | **+125.6% / +32.0%** | + +Both arms pass the keep rule on their own control (every film row down on +both columns), so both ship on by default. Together: film A +43.1/+4.6 -> ++40.9/+3.1 and film B +129.0/+34.3 -> +125.6/+32.0, i.e. -2.2/-1.5 and +-3.4/-2.3 points. + +### Arm 2: what it is + +The census read `refs [LAST@-8 GOLDEN@-8]` on our first top ARF -- one +picture named twice -- and `LAST@-8 GOLDEN@-16/-24` after, against rav1e's +`LAST@-4 LAST2@-8` (two distinct anchors of its own chain). Our top ARF's +`ALTREF` slot was pinned to `GOLDEN_SLOT`, the key frame it already reads. +The slot the ARF is ABOUT to refresh still holds the ARF from two groups back +while the frame is coded, so naming that slot gives the frame a second, +distinct past anchor for no extra DPB slot and no extra encode: +`crate::encoder::arf_altref`, `EC_AV1_ARF_ALTREF=0` restores the old wiring. +Probe arms on film B: 91262 B/45.518 dB and 479578 B/47.996 dB against arm +1's 91206/45.511 and 482161/47.989 (0.4% and 0.6% better at equal PSNR). + +12-frame arm (`bd_rate_screen_native`), control re-run the same way: + +| arm | bars 1080p | bars 2160p | film A | film B | +|---|---|---|---|---| +| control | +1.7 / -14.5 | +12.2 / -10.2 | +37.5 / +7.6 | +54.1 / +23.9 | +| arm 1 | +2.0 / -14.2 | +12.6 / -9.9 | +37.2 / +7.3 | +53.2 / +23.1 | +| arm 1 + arm 2 (ships) | +2.2 / -14.0 | +12.7 / -9.8 | **+37.1 / +7.3** | **+52.5 / +22.3** | + +Both REAL film rows improve on both columns here too; the two "bars" rows are +ffmpeg `testsrc2` colour bars (recorded, never a decision) and read 0.3-0.4 +points up. + +Invariants at the SHIPPED configuration (both arms on): `encoder::` scoped +33 passed / 0 failed (release binary, 780 s, the bitrate test included), +`the_facade_codes_the_same_bytes_as_encode_sequence` 1 passed, +`tile_bytes_do_not_depend_on_the_thread_count --include-ignored` 1 passed, +`EC_COMP_MISMATCH=1` over the 48-frame film B encode 0 lines, ec-av1 lib +suite 558 passed / 0 failed / 44 ignored (745 s), +`cargo check --workspace --all-targets -j4` 0 errors and 0 ec-av1 warnings. +Pins: 9835 -> 9859 (tpl window) -> **9853** at q=150, 35798 -> 35904 -> +**35866** at q=60. + +Arm 1's own invariant run (tpl window only, before arm 2): `encoder::` scoped 33 passed / 0 failed +(release binary, 868 s, includes the bitrate test), +`the_facade_codes_the_same_bytes_as_encode_sequence` + +`tile_bytes_do_not_depend_on_the_thread_count --include-ignored` 2 passed, +`EC_COMP_MISMATCH=1` over the 48-frame film B encode: 0 lines. +Pins re-taken (the stream moves by construction): 9835 -> **9859** at q=150 +and 35798 -> **35904** at q=60; `EC_AV1_TPL_PYRAMID=0` restores the old pair.