From 7ea51337a66ba545d25a2d0b8faeced518d87c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 13 Sep 2026 05:41:11 +0300 Subject: [PATCH] perf(av1): the ARFMODE intra arm cuts the top ARF's whole-32 candidates too -- the probe falsified the leaf-only scope (film A arm 1 byte-identical to the control at q150 AND q90: the ARF's 15% intra area lives in search_inter_block's whole-32 intra loop, not in the leaves), so the scene-cut hatch as chartered was a hatch nothing else was using; per-block engagement counter moved to the whole-32 site, docs updated, witness and pins re-green --- crates/ec-av1/src/encode.rs | 97 +++++++++++++++++++++---------------- crates/ec-av1/src/speed.rs | 17 ++++--- 2 files changed, 64 insertions(+), 50 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 8845496d..7bdedba2 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -7779,13 +7779,17 @@ struct Search<'a> { /// `intra_pruning_with_hog` -- never prunes it away). `None` runs every /// mode through full RD, unchanged from before this lever. top_k: Option, - /// lane-arfmode: the top ARF's leaf offer set ([`crate::speed::ARFMODE`]) - /// -- `false` cuts the named candidate group from the 16x16/8x8 LEAF - /// search ([`code_square_inter`]) and the 8x8 split offer at the top ARF + /// lane-arfmode: the top ARF's offer set ([`crate::speed::ARFMODE`]) + /// -- `false` cuts the named candidate group from the whole-32 search + /// ([`search_inter_block`]), the 16x16/8x8 leaf search + /// ([`code_square_inter`]) and the 8x8 split offer, at the top ARF /// ([`DqLevel::TopArf`] frames only). `true` everywhere else, which is - /// the pre-lane behaviour: the key frame never reaches - /// [`code_square_inter`], the 32x32 whole keeps its full set, and the + /// the pre-lane behaviour: the mid and quarter hidden frames, the shown + /// leaves and the flat path keep intra and compound, and the /// straddling-edge 8x8s are only mode-gated, never partition-gated. + /// The probe's correction: with the leaf gate ALONE the film A stream + /// was byte-identical to the control -- the ARF's intra area lives at + /// the whole-32 level, so the intra arm must cut it there too. arf_leaf_intra: bool, arf_leaf8: bool, arf_leaf_compound: bool, @@ -11018,43 +11022,52 @@ fn search_inter_block( _ => search.modes.to_vec(), }; census_add(5, 1); - census_add(6, intra_modes.len()); - for &mode in &intra_modes { - let luma_trial = luma.trial( - At { - x, - y, - side: BLOCK, - reach, - set: luma_set, - }, - mode, - 0, - search.base_q_idx, - search.deadzone, fctx, - ); - let u = u_trial.clone(); - let v = v_trial.clone(); - let cost = luma_trial.sse - + u.sse - + v.sse - + search.lambda - * (luma_trial.bits - + u.bits - + v.bits - + mode_bits[usize::from(mode)] - + skip_bits(false) - + intra_inter_bits(false)); - consider(Candidate { - cost, - luma: luma_trial, - u, - v, - mode, - skip: false, - inter: None, - mode_bits: mode_bits[usize::from(mode)], - }); + census_add(6, if search.arf_leaf_intra { intra_modes.len() } else { 0 }); + // lane-arfmode: arm 1 drops the whole-32 block's intra candidates at the + // top ARF too -- the probe proved the ARF's intra AREA lives HERE, not at + // the leaves (film A arm 1 vs control byte-identical with the leaf gate + // alone), so "the 32x32 whole keeps intra as the scene-cut hatch" was a + // hatch nothing else was using. Counted once per block. + if search.arf_leaf_intra { + for &mode in &intra_modes { + let luma_trial = luma.trial( + At { + x, + y, + side: BLOCK, + reach, + set: luma_set, + }, + mode, + 0, + search.base_q_idx, + search.deadzone, fctx, + ); + let u = u_trial.clone(); + let v = v_trial.clone(); + let cost = luma_trial.sse + + u.sse + + v.sse + + search.lambda + * (luma_trial.bits + + u.bits + + v.bits + + mode_bits[usize::from(mode)] + + skip_bits(false) + + intra_inter_bits(false)); + consider(Candidate { + cost, + luma: luma_trial, + u, + v, + mode, + skip: false, + inter: None, + mode_bits: mode_bits[usize::from(mode)], + }); + } + } else { + arfmode_hit(0); } // The reference frame buffer a spec decoder holds is exactly the true diff --git a/crates/ec-av1/src/speed.rs b/crates/ec-av1/src/speed.rs index e609502d..abd5b212 100644 --- a/crates/ec-av1/src/speed.rs +++ b/crates/ec-av1/src/speed.rs @@ -460,14 +460,15 @@ pub(crate) const ARF_TF_WIN: [usize; 11] = [3; 11]; /// so [`ARF_TF`] stays where lane-arftf put it. pub(crate) const ARF_TF_WIN_FUT: [usize; 11] = [3; 11]; -/// lane-arfmode: the top ARF's LEAF offer set, as a bitmask -- `1` the 16x16 -/// and 8x8 leaves of the group's own anchor ([`crate::encode::DqLevel:: -/// TopArf`]) offer no INTRA candidate, `2` a 16x16 leaf under it is not -/// offered the 8x8 split, `4` the leaves offer no compound candidates; -/// combinations OR, `0` (the default) is bit-exact with the pre-lane -/// encoder. `EC_AV1_ARFMODE=` overrides it. The 32x32 whole keeps its -/// full offer set (the scene-cut hatch), and the spec-forced 8x8s at -/// straddling edges are untouched -- only RD-optional offers are cut. +/// lane-arfmode: the top ARF's offer set, as a bitmask -- `1` the group's +/// own anchor ([`crate::encode::DqLevel::TopArf`]) offers no INTRA +/// candidate at any block size (the whole-32 search and the 16x16/8x8 +/// leaves), `2` a 16x16 leaf under it is not offered the 8x8 split, `4` the +/// leaves offer no compound candidates; combinations OR, `0` (the default) +/// is bit-exact with the pre-lane encoder. `EC_AV1_ARFMODE=` overrides +/// it. The spec-forced 8x8s at straddling edges are untouched -- only +/// RD-optional offers are cut; the mid and quarter hidden frames and every +/// shown leaf keep the full set. /// /// The census it answers to (lanes/arfmode.charter.md, at 0d81d6c5): the top /// ARF's syntax gap against rav1e's own ARF at the same position is