From bcfe7e8d261b134840438ac12fa8fc179029fd61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 05:40:14 +0300 Subject: [PATCH] feat(av1): EC_AV1_LAST2_NEW -- the search-free LAST2 arm; native gate prints the reference census --- crates/ec-av1/src/encode.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 0c1f0386..80afabb6 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -8299,6 +8299,17 @@ fn mv_component_bits(diff: i32) -> Option { Some(bits) } +/// Whether `LAST2_FRAME` gets a `NEWMV` search of its own beside the +/// neighbour-derived modes ([`extra_ref_new_mv`]'s per-reference switch, +/// `EC_AV1_LAST2_NEW=0`): the charter's "free arm", i.e. the reference's +/// value without the second motion search's wall. +fn last2_new_mv() -> bool { + match std::env::var("EC_AV1_LAST2_NEW").ok() { + Some(v) => v != "0", + None => true, + } +} + /// Whether an extra reference (GOLDEN/ALTREF) is offered a `NEWMV` of its /// own -- a second motion search per block against that reference's picture, /// priced off that reference's own stack. `EC_AV1_MV_EXTRA_NEW=0` turns it @@ -9410,8 +9421,15 @@ fn search_inter_block( // prices out `margin` times better than LAST's best vector does -- // one candidate evaluation (`motion::cost_at`) standing in for a // whole search of ~50. + // lane-last2: the SEARCH-FREE arm for the second past leaf picture + // (`EC_AV1_LAST2_NEW=0`) -- LAST2 is then coded only at a vector some + // neighbour already found, which is how GOLDEN/ALTREF were offered + // before `EXTRA_REF_NEW_MV`, and it is what separates the reference's + // own value from the second motion search's wall. + let searched = extra_ref_new_mv() + && (ref_frame != crate::mvstack::LAST2_FRAME || last2_new_mv()); let margin = extra_new_skip_margin(); - let skip_search = extra_ref_new_mv() + let skip_search = searched && margin > 0.0 && motion::cost_at( &g.y, @@ -9429,7 +9447,7 @@ fn search_inter_block( fctx, ) * margin <= found.cost; - if extra_ref_new_mv() && !skip_search { + if searched && !skip_search { let (gseeds, gn) = mv_seeds(gstack); #[cfg(test)] let t = stage_start();