Commit 9300ad63ce for aom

commit 9300ad63ce1165f3119e0fc680a12c0daf072ede
Author: Deepa K G <deepa.kg@ittiam.com>
Date:   Tue Mar 10 08:54:20 2026 +0530

    Fix sf 'reuse_compound_type_decision'

    The speed feature 'reuse_compound_type_decision'
    reuses the compound type RD decision when the
    reference frames and motion vectors match. When
    match is found, RD cost is calculated using the
    stored stats. However, for COMPOUND_AVERAGE, rate
    and distortion are not backed up resulting in
    early termination of the matched mode.

    The sf 'prune_comp_type_by_model_rd' is supposed to
    prune approximate RD evaluation of COMPOUND_DIFFWTD
    based on modelled RD of COMPOUND_AVERAGE. However, as
    modelled RD is not calculated for COMPOUND_AVERAGE,
    the sf 'prune_comp_type_by_model_rd' does not prune
    approximate RD evaluation of COMPOUND_DIFFWTD.

    This patch adds backup of rate and distortion and
    calculates the modelled RD for COMPOUND_AVERAGE and
    thus fixes the above issues.

    STATS_CHANGED for speed>=1

    Change-Id: I8adf28ec5f78cd74cd52cb985a1c1d56133aa480

diff --git a/av1/encoder/compound_type.c b/av1/encoder/compound_type.c
index 778c3f1cf6..f8364f1cf9 100644
--- a/av1/encoder/compound_type.c
+++ b/av1/encoder/compound_type.c
@@ -1374,12 +1374,26 @@ int av1_compound_type_rd(const AV1_COMP *const cpi, MACROBLOCK *x,

         int eval_txfm = prune_mode_by_skip_rd(cpi, x, xd, bsize, ref_skip_rd,
                                               rs2 + *rate_mv);
+        int64_t est_rd = INT64_MAX;
+        RD_STATS est_rd_stats;
         if (eval_txfm) {
-          RD_STATS est_rd_stats;
-          estimate_yrd_for_sb(cpi, bsize, x, INT64_MAX, &est_rd_stats);
-
+          est_rd = estimate_yrd_for_sb(cpi, bsize, x, INT64_MAX, &est_rd_stats);
+        }
+        if (est_rd != INT64_MAX) {
           best_rd_cur = RDCOST(x->rdmult, rs2 + tmp_rate_mv + est_rd_stats.rate,
                                est_rd_stats.dist);
+          int rate_sum;
+          uint8_t tmp_skip_txfm_sb;
+          int64_t dist_sum, tmp_skip_sse_sb;
+          model_rd_sb_fn[MODELRD_TYPE_MASKED_COMPOUND](
+              cpi, bsize, x, xd, 0, 0, &rate_sum, &dist_sum, &tmp_skip_txfm_sb,
+              &tmp_skip_sse_sb, NULL, NULL, NULL);
+          comp_model_rd_cur =
+              RDCOST(x->rdmult, rs2 + tmp_rate_mv + rate_sum, dist_sum);
+          // Backup rate and distortion for future reuse
+          backup_stats(cur_type, comp_rate, comp_dist, comp_model_rate,
+                       comp_model_dist, rate_sum, dist_sum, &est_rd_stats,
+                       comp_rs2, rs2);
         }
       }