From 7b4f91d155e0c9b999bb3cc8ca2fe376e67b20b5 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 09:41:09 +0300 Subject: [PATCH] feat(av1): the 64x64 root ships at every speed preset; re-pin With the early-out clamped at 0.125 the preset-6 regression lane-b64 measured is gone -- every row of the native gate is better on both columns with the root on (film A +55.1/+24.8 -> +51.0/+21.7, film B +91.5/+53.4 -> +77.9/+44.3, screen +57.7/-11.7 -> +40.3/-20.0, bars +88.9/+54.8 -> +79.5/+47.2 and +91.6/+49.8 -> +72.6/+35.1) at 28.1s vs 30.8s, 31.3s vs 28.0s, 14.3s vs 15.2s. Pins re-taken for the residual arm, ON THIS LANE'S BASE (456295e9, whose pins are 7291/27466 -- main has since moved to 8446/28548 under the 8:-32:16 pyramid, and those get re-taken at merge): 7291 -> 7355 at q=150, 27466 -> 27573 at q=60. EC_AV1_B64=0 still gives lane-b64's pre-root 8076 / 27585, verified on this base. Also drops the stale claim in B64_ROOT's doc that transform.rs has no forward TX_64X64. --- crates/ec-av1/src/encode.rs | 22 +++++++++++++++----- crates/ec-av1/src/speed.rs | 40 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 5b51eb7c..55cb2802 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -386,10 +386,16 @@ fn split_inter_blocks() -> bool { /// 32x32 or smaller, which put our mode+mv+partition+tx_size spend at 162,669 /// bits against rav1e's 61,988, about 46% of the film B gap. /// -/// SKIP-only: a 64x64 residual needs a forward TX_64X64 the encoder does not -/// have (`transform.rs` tops out at 32x32), and the writer refuses any other -/// shape (`crate::tile::Quadrant::Whole64`). Switched off by `EC_AV1_B64=0` -/// in any build. +/// lane-tx64: no longer skip-only. The root also prices a REAL residual -- +/// one TX_64X64 luma transform (`transform.rs`'s forward network has always +/// reached 64 points; what was missing was the block coder and the writer +/// around it) and one TX_32X32 per chroma plane -- see [`b64_residual`], +/// which carries that arm's own gate table. Still refused at the 64 root: +/// compound references, a depth-1 4x32x32 var-tx tree, intra, and a +/// superblock the true frame edge cuts through. +/// +/// Switched off by `EC_AV1_B64=0` in any build; `EC_AV1_B64RES=0` keeps the +/// root and restores the skip-only shape lane-b64 shipped. pub(crate) const B64_ROOT: bool = true; /// How many superblocks took the 64x64 root since the last @@ -13495,8 +13501,14 @@ mod tests { // one mode/mv chain and no residual where four quadrants used to -- // 8076 -> 7291 at q=150 and 27585 -> 27466 at q=60. `EC_AV1_B64=0` // restores these. + // Re-taken on lane-tx64: that 64x64 root can code a REAL residual now + // (one TX_64X64 luma transform and two TX_32X32 chroma ones), so a + // superblock whose skip arm was too coarse codes coefficients where + // it used to fall back to four quadrants -- 7291 -> 7355 at q=150 and + // 27466 -> 27573 at q=60. `EC_AV1_B64RES=0` restores these; + // `EC_AV1_B64=0` still gives lane-b64's own pre-root 8076 / 27585. let pins: [(u8, usize, u64); 2] = - [(150, 7291, 0xa411_97e8_8a80_2a1b), (60, 27466, 0xdc87_26a3_c625_46ce)]; + [(150, 7355, 0xd074_3dc7_a231_8a20), (60, 27573, 0xd9fb_3c84_57cc_b86f)]; for (q, bytes, hash) in pins { let encoded = encode_sequence(&source, q, 0.5).unwrap(); assert_eq!( diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index 001211d6..a050840c 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -149,27 +149,25 @@ pub(crate) fn at(table: &[T; 11]) -> T { /// film B +70.5/+35.2 -> +64.7/+34.0, screen +48.2/-16.4 -> +33.4/-23.8) at /// -4% to -20% wall on four of the five rows. /// -/// MEASURED OFF from preset 4 up (lane-b64, native gate at `EC_AV1_SPEED=6`, -/// two arms side by side): ON costs film A +55.1/+24.8 -> +64.5/+37.5 and -/// film B +91.5/+53.4 -> +114.6/+71.5 for -16%/-36% wall. The cause is the -/// trial's own early-out, which rides [`SPLIT_RD`]: at 0.5 (preset 6) a -/// superblock is taken whole without its quadrants ever being searched, and -/// film B's q150 point loses 1.2 dB. Presets 1..=3 keep it because they keep -/// `SPLIT_RD` at 0.125, i.e. the early-out they get is the measured one; -/// 4 and up switch it off with `SPLIT_RD`'s first step. -pub(crate) const B64_ROOT: [bool; 11] = [ - crate::encode::B64_ROOT, - true, - true, - true, - false, - false, - false, - false, - false, - false, - false, -]; +/// lane-b64 MEASURED it off from preset 4 up: at `EC_AV1_SPEED=6` ON cost +/// film A +55.1/+24.8 -> +64.5/+37.5 and film B +91.5/+53.4 -> +114.6/+71.5. +/// The cause was named there and FIXED in lane-tx64: the trial's early-out +/// rode [`SPLIT_RD`], so at 0.5 (preset 6) a superblock was taken whole with +/// its quadrants never searched. `encode::b64_breakout_threshold` clamps that +/// early-out at the shipped 0.125 whatever the preset, and the same gate at +/// `EC_AV1_SPEED=6` now reads, every row better on both columns: +/// +/// | row | B64 off | B64 on, clamped | +/// |---|---|---| +/// | bars 1080p | +88.9 / +54.8 | +79.5 / +47.2 | +/// | bars 2160p | +91.6 / +49.8 | +72.6 / +35.1 | +/// | film A | +55.1 / +24.8 | +51.0 / +21.7 | +/// | film B | +91.5 / +53.4 | +77.9 / +44.3 | +/// | screen | +57.7 / -11.7 | +40.3 / -20.0 | +/// +/// at 28.1s vs 30.8s (film A), 31.3s vs 28.0s (film B), 14.3s vs 15.2s +/// (screen). So it is on at every preset. +pub(crate) const B64_ROOT: [bool; 11] = [crate::encode::B64_ROOT; 11]; /// `encode::SPLIT_RD_THRESHOLD`: how cheap a block has to be before its split /// trial is withheld. The single biggest wall lever in the tile search.