From 6aa3e57f58674d47af78cc49336c34e3c79fe267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 17:59:07 +0300 Subject: [PATCH] feat(av1): a group's top ARF names the ARF two groups back as its second anchor The ARF-vs-ARF census found our first top ARF naming the SAME picture as LAST and GOLDEN (refs LAST@-8 GOLDEN@-8), where rav1e's ARFs read two distinct anchors of their own chain. The slot the ARF is about to refresh still holds the anchor from two groups back while this frame is coded, so naming it as ALTREF costs no DPB slot and no extra encode. Long-GOP gate on top of the pyramid tpl window: film A +42.8/+4.5 -> +40.9/+3.1, film B +127.3/+32.9 -> +125.6/+32.0 -- both films down on both columns. Pins re-taken: 9853 at q=150, 35866 at q=60; EC_AV1_ARF_ALTREF=0 restores 9859 / 35904. --- crates/ec-av1/src/encode.rs | 7 ++++++- crates/ec-av1/src/encoder.rs | 7 +++++-- lanes/arfcen.report.md | 21 +++++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index f6911c2c..1c6b027c 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -13636,8 +13636,13 @@ mod tests { // 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, 9859, 0x4409_f8db_e152_9fe7), (60, 35904, 0xc408_f126_2877_0ffb)]; + [(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 cac80fca..9467745e 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -918,8 +918,11 @@ fn arf_altref() -> bool { } } -/// [`arf_altref`]'s default. -const ARF_ALTREF: bool = false; +/// [`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 diff --git a/lanes/arfcen.report.md b/lanes/arfcen.report.md index 0477ad12..f74f9a88 100644 --- a/lanes/arfcen.report.md +++ b/lanes/arfcen.report.md @@ -133,8 +133,25 @@ recorded defaults to the digit: | 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%** | -Both film rows improve on both columns: the keep rule passes, so arm 1 ships -on by default. +| **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: