aom: rtc: Refactor speed features for prune palette

From 86d1aeba446f6b3a14c438136d2b1fbd6b1e7ae9 Mon Sep 17 00:00:00 2001
From: Marco Paniconi <[EMAIL REDACTED]>
Date: Wed, 15 May 2024 05:59:35 +0000
Subject: [PATCH] rtc: Refactor speed features for prune palette

Two speed features sharing the similar name and
function, so combine into one.

Change-Id: Ie36a1e96a4e43358ce50c654363c852b3e14ba6a
---
 av1/encoder/nonrd_pickmode.c |  8 +++++---
 av1/encoder/speed_features.c |  7 +++----
 av1/encoder/speed_features.h | 12 ++++++------
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 7b204c78a..45d81aa9d 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -1649,7 +1649,8 @@ void av1_nonrd_pick_intra_mode(AV1_COMP *cpi, MACROBLOCK *x, RD_STATS *rd_cost,
     }
   }
 
-  const unsigned int thresh_sad = cpi->sf.rt_sf.prune_palette_nonrd ? 100 : 20;
+  const unsigned int thresh_sad =
+      cpi->sf.rt_sf.prune_palette_search_nonrd > 1 ? 100 : 20;
   const unsigned int best_sad_norm =
       args.best_sad >>
       (b_width_log2_lookup[bsize] + b_height_log2_lookup[bsize]);
@@ -1659,7 +1660,7 @@ void av1_nonrd_pick_intra_mode(AV1_COMP *cpi, MACROBLOCK *x, RD_STATS *rd_cost,
       cpi->oxcf.tool_cfg.enable_palette &&
       av1_allow_palette(cpi->common.features.allow_screen_content_tools,
                         mi->bsize);
-  if (cpi->sf.rt_sf.prune_screen_palette_search) {
+  if (cpi->sf.rt_sf.prune_palette_search_nonrd > 0) {
     bool prune =
         (!args.prune_mode_based_on_sad || best_sad_norm > thresh_sad) &&
         bsize <= BLOCK_16X16 && x->source_variance > 200;
@@ -3477,7 +3478,8 @@ void av1_nonrd_pick_inter_mode_sb(AV1_COMP *cpi, TileDataEnc *tile_data,
       x->source_variance > 0 && !x->force_zeromv_skip_for_blk &&
       (cpi->rc.high_source_sad || x->source_variance > 300);
 
-  if (rt_sf->prune_palette_nonrd && bsize > BLOCK_16X16) try_palette = 0;
+  if (rt_sf->prune_palette_search_nonrd > 1 && bsize > BLOCK_16X16)
+    try_palette = 0;
 
   // Perform screen content mode evaluation for non-rd
   handle_screen_content_mode_nonrd(
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 73836276f..a788af811 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1580,14 +1580,14 @@ static void set_rt_speed_feature_framesize_dependent(const AV1_COMP *const cpi,
       sf->rt_sf.thresh_active_maps_skip_lf_cdef = 90;
       sf->rt_sf.hybrid_intra_pickmode = 0;
       sf->rt_sf.dct_only_palette_nonrd = 1;
-      sf->rt_sf.prune_screen_palette_search = true;
+      sf->rt_sf.prune_palette_search_nonrd = 1;
       sf->rt_sf.prune_intra_mode_using_best_sad_so_far = true;
     }
     if (speed >= 11) {
       sf->rt_sf.skip_lf_screen = 2;
       sf->rt_sf.skip_cdef_sb = 2;
       sf->rt_sf.part_early_exit_zeromv = 2;
-      sf->rt_sf.prune_palette_nonrd = 1;
+      sf->rt_sf.prune_palette_search_nonrd = 2;
       sf->rt_sf.increase_color_thresh_palette = 0;
       sf->rt_sf.prune_h_pred_using_best_mode_so_far = true;
       sf->rt_sf.enable_intra_mode_pruning_using_neighbors = true;
@@ -2255,7 +2255,7 @@ static AOM_INLINE void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
   rt_sf->use_nonrd_filter_search = 0;
   rt_sf->use_simple_rd_model = 0;
   rt_sf->hybrid_intra_pickmode = 0;
-  rt_sf->prune_screen_palette_search = false;
+  rt_sf->prune_palette_search_nonrd = 0;
   rt_sf->source_metrics_sb_nonrd = 0;
   rt_sf->overshoot_detection_cbr = NO_DETECTION;
   rt_sf->check_scene_detection = 0;
@@ -2282,7 +2282,6 @@ static AOM_INLINE void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
   rt_sf->use_rtc_tf = 0;
   rt_sf->use_idtx_nonrd = 0;
   rt_sf->prune_idtx_nonrd = 0;
-  rt_sf->prune_palette_nonrd = 0;
   rt_sf->dct_only_palette_nonrd = 0;
   rt_sf->part_early_exit_zeromv = 0;
   rt_sf->sse_early_term_inter_search = EARLY_TERM_DISABLED;
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index 300d7e190..77e66228a 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -1631,9 +1631,12 @@ typedef struct REAL_TIME_SPEED_FEATURES {
 
   // Filter blocks by certain criteria such as SAD, source variance, such that
   // fewer blocks will go through the palette search.
-  // For screen content types, enable this feature reduces key frame encoding
-  // time. Disabling it leads to better compression efficiency.
-  bool prune_screen_palette_search;
+  // For nonrd encoding path, enable this feature reduces encoding time when
+  // palette mode is used. Disabling it leads to better compression efficiency.
+  // 0: off
+  // 1: less aggressive pruning mode
+  // 2: more aggressive pruning mode
+  int prune_palette_search_nonrd;
 
   // Compute variance/sse on source difference, prior to encoding superblock.
   int source_metrics_sb_nonrd;
@@ -1768,9 +1771,6 @@ typedef struct REAL_TIME_SPEED_FEATURES {
   // is not already set.
   int prune_idtx_nonrd;
 
-  // Prune the use of paletter mode in nonrd pickmode.
-  int prune_palette_nonrd;
-
   // Force to only use dct for palette search in nonrd pickmode.
   int dct_only_palette_nonrd;