Commit 3c18637ca0 for aom

commit 3c18637ca00c98de3dd88ca3480f365485fe1400
Author: Apurve Kumar Pandey <apurve.pandey@ittiam.com>
Date:   Fri Feb 6 19:44:47 2026 +0530

    Prune evaluation of inter modes w.r.t LAST2_FRAME

    This patch introduces a new level to the sf
    'prune_inter_modes_based_on_tpl' which uses tpl stage inter
    cost to prune inter modes w.r.t. LAST2 reference frame.

    Encoder performance results averaged over all resolutions
    are as follows:

          Instruction Count           BD-Rate Loss(%)
    cpu     Reduction(%)      avg.psnr  ovr.psnr   ssim      vmaf   vmaf_neg
     2         3.585           0.0352    0.0357   0.0180   -0.0021   0.0047
     3        -0.003          -0.0051   -0.0147   0.0022    0.0123   0.0147
     4         0.035           0.0011    0.0048   0.0039    0.0206   0.0198
     5        -0.026          -0.0015    0.0010   0.0038    0.0087   0.0047
     6        -0.029          -0.0020   -0.0019  -0.0015   -0.0016  -0.0012

    STATS_CHANGED for speed >= 2

    Change-Id: Idf351a7e797cd099a1f85d5b391dbad3f268022d

diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index a9e0f8f9b4..76490359d5 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -2556,28 +2556,17 @@ static inline void get_block_level_tpl_stats(
 static inline int prune_modes_based_on_tpl_stats(
     PruneInfoFromTpl *inter_cost_info_from_tpl, const int *refs, int ref_mv_idx,
     const PREDICTION_MODE this_mode, int prune_mode_level) {
+  const int is_ref_last2 = refs[0] == LAST2_FRAME || refs[1] == LAST2_FRAME;
+  if (prune_mode_level == 1 && !is_ref_last2) return 0;
+
   const int have_newmv = have_newmv_in_inter_mode(this_mode);
-  if ((prune_mode_level < 2) && have_newmv) return 0;
+  if ((prune_mode_level == 2) && have_newmv) return 0;

   const int64_t best_inter_cost = inter_cost_info_from_tpl->best_inter_cost;
   if (best_inter_cost == INT64_MAX) return 0;

-  const int prune_level = prune_mode_level - 1;
   int64_t cur_inter_cost;

-  const int is_globalmv =
-      (this_mode == GLOBALMV) || (this_mode == GLOBAL_GLOBALMV);
-  const int prune_index = is_globalmv ? MAX_REF_MV_SEARCH : ref_mv_idx;
-
-  // Thresholds used for pruning:
-  // Lower value indicates aggressive pruning and higher value indicates
-  // conservative pruning which is set based on ref_mv_idx and speed feature.
-  // 'prune_index' 0, 1, 2 corresponds to ref_mv indices 0, 1 and 2. prune_index
-  // 3 corresponds to GLOBALMV/GLOBAL_GLOBALMV
-  static const int tpl_inter_mode_prune_mul_factor[3][MAX_REF_MV_SEARCH + 1] = {
-    { 6, 6, 6, 4 }, { 6, 4, 4, 4 }, { 5, 4, 4, 4 }
-  };
-
   const int is_comp_pred = (refs[1] > INTRA_FRAME);
   if (!is_comp_pred) {
     cur_inter_cost = inter_cost_info_from_tpl->ref_inter_cost[refs[0] - 1];
@@ -2591,6 +2580,22 @@ static inline int prune_modes_based_on_tpl_stats(
     cur_inter_cost = AOMMAX(inter_cost_ref0, inter_cost_ref1);
   }

+  if (is_ref_last2) return (cur_inter_cost > best_inter_cost);
+
+  const int is_globalmv =
+      (this_mode == GLOBALMV) || (this_mode == GLOBAL_GLOBALMV);
+  const int prune_index = is_globalmv ? MAX_REF_MV_SEARCH : ref_mv_idx;
+  const int prune_level = prune_mode_level - 2;
+
+  // Thresholds used for pruning:
+  // Lower value indicates aggressive pruning and higher value indicates
+  // conservative pruning which is set based on ref_mv_idx and speed feature.
+  // 'prune_index' 0, 1, 2 corresponds to ref_mv indices 0, 1 and 2.
+  // prune_index 3 corresponds to GLOBALMV/GLOBAL_GLOBALMV
+  static const int tpl_inter_mode_prune_mul_factor[3][MAX_REF_MV_SEARCH + 1] = {
+    { 6, 6, 6, 4 }, { 6, 4, 4, 4 }, { 5, 4, 4, 4 }
+  };
+
   // Prune the mode if cur_inter_cost is greater than threshold times
   // best_inter_cost
   if (cur_inter_cost >
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index b62cb64f99..20cb20dbd7 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1235,6 +1235,7 @@ static void set_good_speed_features_framesize_independent(
     set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level, boosted ? 0 : 1);
     sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 1;
     sf->inter_sf.alt_ref_search_fp = 1;
+    sf->inter_sf.prune_inter_modes_based_on_tpl = 1;

     sf->interp_sf.adaptive_interp_filter_search = 1;

@@ -1285,7 +1286,7 @@ static void set_good_speed_features_framesize_independent(
     // TODO(any): Experiment with the early exit mechanism for speeds 0, 1 and 2
     // and clean-up the speed feature
     sf->inter_sf.perform_best_rd_based_gating_for_chroma = 1;
-    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 1;
+    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 2;
     sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 2;
     sf->inter_sf.selective_ref_frame = 5;
     sf->inter_sf.reuse_compound_type_decision = 1;
@@ -1355,7 +1356,7 @@ static void set_good_speed_features_framesize_independent(
     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_MOTION_MODE] = boosted ? 0 : 5;
     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = boosted ? 0 : 3;

-    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 2;
+    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 3;
     sf->inter_sf.prune_ext_comp_using_neighbors = 2;
     sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
     sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
@@ -1445,7 +1446,7 @@ static void set_good_speed_features_framesize_independent(

     sf->gm_sf.downsample_level = 2;

-    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 3;
+    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 4;
     sf->inter_sf.selective_ref_frame = 6;
     sf->inter_sf.prune_single_ref = is_boosted_arf2_bwd_type ? 0 : 2;
     sf->inter_sf.prune_ext_comp_using_neighbors = 3;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index ad7f7e4fb7..7b87f3cd67 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -1159,7 +1159,9 @@ typedef struct INTER_MODE_SPEED_FEATURES {

   // Prune inter modes based on tpl stats
   // 0 : no pruning
-  // 1 - 3 indicate increasing aggressiveness in order.
+  // 1 : Allow pruning of LAST2 frame
+  // 2 - 4: Allow pruning of all reference frames with increased aggressiveness
+  // of pruning in order
   int prune_inter_modes_based_on_tpl;

   // Skip NEARMV and NEAR_NEARMV modes using ref frames of above and left