Commit 6c7f40b404 for aom

commit 6c7f40b404fba7ff34eeb0a9709411d300120db2
Author: Deepa K G <deepa.kg@ittiam.com>
Date:   Tue Apr 14 17:56:35 2026 +0530

    Disable superblock level qp offsets for INTNL_ARF_UPDATE frames

    For INTNL_ARF_UPDATE frames, superblock-level QP offset is disabled.
    However, coding block-level RD multiplier modulation is enabled for
    all frames except LF_UPDATE frames.

        Instruction Count                BD-Rate Loss(%)
    cpu    Reduction(%)   avg.psnr  ovr.psnr  ssim     vmaf   vmaf_neg
     1        0.7          -0.3453  -0.3349  -0.4416  -0.4601  -0.3960
     2        0.2          -0.3422  -0.3220  -0.4258  -0.4177  -0.3530
     3        0.2          -0.3431  -0.3428  -0.4282  -0.4404  -0.4057
     4        0.1          -0.3760  -0.3680  -0.4344  -0.4011  -0.3728
     5       -0.1          -0.2544  -0.2322  -0.2695  -0.2197  -0.1997
     6       -0.0          -0.2677  -0.2534  -0.2281  -0.2499  -0.2002

    STATS_CHANGED

    Change-Id: I68a0cdafcf16024f80a11cefa2982d6c49e3ab11

diff --git a/av1/encoder/av1_quantize.c b/av1/encoder/av1_quantize.c
index aeda245241..49acf3332b 100644
--- a/av1/encoder/av1_quantize.c
+++ b/av1/encoder/av1_quantize.c
@@ -818,7 +818,14 @@ void av1_init_plane_quantizers(const AV1_COMP *cpi, MACROBLOCK *x,
               0, QINDEX_RANGE - 1);
     qindex_rd = av1_get_qindex(&cm->seg, segment_id, current_rd_qindex);
   } else {
-    qindex_rd = qindex;
+    if (cpi->cb_delta_rdmult_enabled) {
+      const int current_rd_qindex =
+          clamp(quant_params->base_qindex + x->rdmult_delta_qindex, 0,
+                QINDEX_RANGE - 1);
+      qindex_rd = av1_get_qindex(&cm->seg, segment_id, current_rd_qindex);
+    } else {
+      qindex_rd = qindex;
+    }
   }

   const int qindex_rdmult = qindex_rd + quant_params->y_dc_delta_q;
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 816ae20995..c089674223 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1345,6 +1345,8 @@ int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
   // Allocation of mi buffers.
   alloc_mb_mode_info_buffers(cpi);

+  cpi->cb_delta_rdmult_enabled = 0;
+
   cpi->skip_tpl_setup_stats = 0;
 #if !CONFIG_REALTIME_ONLY
   if (oxcf->pass != AOM_RC_FIRST_PASS) {
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index f1d9f88a92..b4bc0148f2 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -301,7 +301,6 @@ static inline void setup_delta_q(AV1_COMP *const cpi, ThreadData *td,
   AV1_COMMON *const cm = &cpi->common;
   const CommonModeInfoParams *const mi_params = &cm->mi_params;
   const DeltaQInfo *const delta_q_info = &cm->delta_q_info;
-  assert(delta_q_info->delta_q_present_flag);

   const BLOCK_SIZE sb_size = cm->seq_params->sb_size;
   av1_setup_src_planes(x, cpi->source, mi_row, mi_col, num_planes, sb_size);
@@ -364,17 +363,22 @@ static inline void setup_delta_q(AV1_COMP *const cpi, ThreadData *td,
   }
   current_qindex = adjusted_qindex;

-  x->delta_qindex = current_qindex - cm->quant_params.base_qindex;
-  x->rdmult_delta_qindex = x->delta_qindex;
+  x->delta_qindex = cm->delta_q_info.delta_q_present_flag
+                        ? current_qindex - cm->quant_params.base_qindex
+                        : 0;
+  x->rdmult_delta_qindex = current_qindex - cm->quant_params.base_qindex;

   av1_set_offsets(cpi, tile_info, x, mi_row, mi_col, sb_size);
-  xd->mi[0]->current_qindex = current_qindex;
+  xd->mi[0]->current_qindex = cm->delta_q_info.delta_q_present_flag
+                                  ? current_qindex
+                                  : cm->quant_params.base_qindex;
   av1_init_plane_quantizers(cpi, x, xd->mi[0]->segment_id, 0);

   // keep track of any non-zero delta-q used
   td->deltaq_used |= (x->delta_qindex != 0);

-  if (cpi->oxcf.tool_cfg.enable_deltalf_mode) {
+  if (cpi->oxcf.tool_cfg.enable_deltalf_mode &&
+      cm->delta_q_info.delta_q_present_flag) {
     const int delta_lf_res = delta_q_info->delta_lf_res;
     const int lfmask = ~(delta_lf_res - 1);
     const int delta_lf_from_base =
@@ -691,7 +695,7 @@ static inline void init_encode_rd_sb(AV1_COMP *cpi, ThreadData *td,
     x->sb_energy_level = 0;
     x->part_search_info.cnn_output_valid = 0;
     if (gather_tpl_data) {
-      if (cm->delta_q_info.delta_q_present_flag) {
+      if (cpi->cb_delta_rdmult_enabled) {
         const int num_planes = av1_num_planes(cm);
         const BLOCK_SIZE sb_size = cm->seq_params->sb_size;
         setup_delta_q(cpi, td, x, tile_info, mi_row, mi_col, num_planes);
@@ -1231,7 +1235,7 @@ static inline void encode_sb_row(AV1_COMP *cpi, ThreadData *td,

   // Reset delta for quantizer and loof filters at the beginning of every tile
   if (mi_row == tile_info->mi_row_start || row_mt_enabled) {
-    if (cm->delta_q_info.delta_q_present_flag)
+    if (cpi->cb_delta_rdmult_enabled)
       xd->current_base_qindex = cm->quant_params.base_qindex;
     if (cm->delta_q_info.delta_lf_present_flag) {
       av1_reset_loop_filter_delta(xd, av1_num_planes(cm));
@@ -1872,6 +1876,33 @@ static int allow_deltaq_mode(AV1_COMP *cpi) {
 #endif  // !CONFIG_REALTIME_ONLY
 }

+static inline int disable_deltaq_for_intl_arfs(const AV1_COMP *cpi) {
+  if (cpi->oxcf.mode == GOOD && is_stat_consumption_stage_twopass(cpi) &&
+      cpi->oxcf.q_cfg.deltaq_mode == DELTA_Q_OBJECTIVE &&
+      cpi->oxcf.algo_cfg.enable_tpl_model && cpi->oxcf.q_cfg.aq_mode == NO_AQ &&
+      !cpi->common.seg.enabled && !cpi->roi.enabled && !cpi->oxcf.sb_qp_sweep &&
+      !cpi->use_ducky_encode) {
+    return 1;
+  }
+  return 0;
+}
+
+static inline int enable_delta_rdmult(const AV1_COMP *cpi) {
+  if (!disable_deltaq_for_intl_arfs(cpi))
+    return cpi->common.delta_q_info.delta_q_present_flag;
+
+  const GF_GROUP *gf_group = &cpi->ppi->gf_group;
+  return gf_group->update_type[cpi->gf_frame_index] != LF_UPDATE;
+}
+
+static inline int enable_delta_q(const AV1_COMP *cpi) {
+  const GF_GROUP *gf_group = &cpi->ppi->gf_group;
+  if (!disable_deltaq_for_intl_arfs(cpi))
+    return gf_group->update_type[cpi->gf_frame_index] != LF_UPDATE;
+
+  return cpi->common.current_frame.pyramid_level <= 1;
+}
+
 #define FORCE_ZMV_SKIP_128X128_BLK_DIFF 10000
 #define FORCE_ZMV_SKIP_MAX_PER_PIXEL_DIFF 4

@@ -2303,10 +2334,8 @@ static inline void encode_frame_internal(AV1_COMP *cpi) {
     // is used for ineligible frames. That effectively will turn off row_mt
     // usage. Note objective delta_q and tpl eligible frames are only altref
     // frames currently.
-    const GF_GROUP *gf_group = &cpi->ppi->gf_group;
     if (cm->delta_q_info.delta_q_present_flag) {
-      if (deltaq_mode == DELTA_Q_OBJECTIVE &&
-          gf_group->update_type[cpi->gf_frame_index] == LF_UPDATE)
+      if (deltaq_mode == DELTA_Q_OBJECTIVE && !enable_delta_q(cpi))
         cm->delta_q_info.delta_q_present_flag = 0;

       if (deltaq_mode == DELTA_Q_OBJECTIVE &&
@@ -2333,6 +2362,7 @@ static inline void encode_frame_internal(AV1_COMP *cpi) {
     cpi->cyclic_refresh->actual_num_seg2_blocks = 0;
   }
   cpi->rc.cnt_zeromv = 0;
+  cpi->cb_delta_rdmult_enabled = enable_delta_rdmult(cpi);

   av1_frame_init_quantizer(cpi);
   init_encode_frame_mb_context(cpi);
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 36510f05b4..5978f22284 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -3004,6 +3004,11 @@ typedef struct AV1_COMP {
    */
   int skip_tpl_setup_stats;

+  /*!
+   * Flag to indicate if RD multiplier modulation is enabled.
+   */
+  int cb_delta_rdmult_enabled;
+
   /*!
    * Scaling factors used in the RD multiplier modulation.
    * TODO(sdeng): consider merge the following arrays.
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c
index 9455b4bc51..2feb14fd3f 100644
--- a/av1/encoder/partition_search.c
+++ b/av1/encoder/partition_search.c
@@ -618,8 +618,7 @@ static void setup_block_rdmult(const AV1_COMP *const cpi, MACROBLOCK *const x,
   }

 #if !CONFIG_REALTIME_ONLY
-  if (cpi->common.delta_q_info.delta_q_present_flag &&
-      !cpi->sf.rt_sf.use_nonrd_pick_mode) {
+  if (cpi->cb_delta_rdmult_enabled && !cpi->sf.rt_sf.use_nonrd_pick_mode) {
     x->rdmult = av1_get_cb_rdmult(cpi, x, bsize, mi_row, mi_col);
   }
 #endif  // !CONFIG_REALTIME_ONLY