Coverage Report

Created: 2026-06-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/encoder/speed_features.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include <limits.h>
13
14
#include "av1/common/reconintra.h"
15
16
#include "av1/encoder/encoder.h"
17
#include "av1/encoder/speed_features.h"
18
#include "av1/encoder/rdopt.h"
19
20
#include "aom_dsp/aom_dsp_common.h"
21
22
#define MAX_MESH_SPEED 5  // Max speed setting for mesh motion method
23
// Max speed setting for tx domain evaluation
24
#define MAX_TX_DOMAIN_EVAL_SPEED 5
25
static const MESH_PATTERN
26
    good_quality_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
27
      { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
28
      { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
29
      { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
30
      { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
31
      { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
32
      { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
33
    };
34
35
// TODO(huisu@google.com): These settings are pretty relaxed, tune them for
36
// each speed setting
37
static const MESH_PATTERN
38
    intrabc_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
39
      { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
40
      { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
41
      { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
42
      { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
43
      { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
44
      { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
45
    };
46
47
// Threshold values to be used for pruning the txfm_domain_distortion
48
// based on block MSE
49
// Index 0: Default mode evaluation, Winner mode processing is not
50
// applicable (Eg : IntraBc). Index 1: Mode evaluation.
51
// Index 2: Winner mode evaluation. Index 1 and 2 are applicable when
52
// enable_winner_mode_for_use_tx_domain_dist speed feature is ON
53
// TODO(any): Experiment the threshold logic based on variance metric
54
static const unsigned int tx_domain_dist_thresholds[4][MODE_EVAL_TYPES] = {
55
  { UINT_MAX, UINT_MAX, UINT_MAX },
56
  { 22026, 22026, 22026 },
57
  { 1377, 1377, 1377 },
58
  { 0, 0, 0 }
59
};
60
61
// Number of different levels of aggressiveness in using transform domain
62
// distortion during the R-D evaluation based on the speed feature
63
// tx_domain_dist_level.
64
#define TX_DOMAIN_DIST_LEVELS 4
65
66
// Transform domain distortion type to be used for default, mode and winner mode
67
// evaluation Index 0: Default mode evaluation, Winner mode processing is not
68
// applicable (Eg : IntraBc). Index 1: Mode evaluation. Index 2: Winner mode
69
// evaluation. Index 1 and 2 are applicable when
70
// enable_winner_mode_for_use_tx_domain_dist speed feature is ON
71
static const unsigned int
72
    tx_domain_dist_types[TX_DOMAIN_DIST_LEVELS][MODE_EVAL_TYPES] = {
73
      { 0, 2, 0 }, { 1, 2, 0 }, { 2, 2, 0 }, { 2, 2, 2 }
74
    };
75
76
// Threshold values to be used for disabling coeff RD-optimization
77
// based on block MSE / qstep^2.
78
// TODO(any): Experiment the threshold logic based on variance metric.
79
// Table has satd and dist threshold value index 0 : dist,index 1: satd
80
// For each row, the indices are as follows.
81
// Index 0: Default mode evaluation, Winner mode processing is not applicable
82
// (Eg : IntraBc)
83
// Index 1: Mode evaluation.
84
// Index 2: Winner mode evaluation.
85
// Index 1 and 2 are applicable when enable_winner_mode_for_coeff_opt speed
86
// feature is ON
87
// There are 7 levels with increasing speed, mapping to vertical indices.
88
static const unsigned int coeff_opt_thresholds[9][MODE_EVAL_TYPES][2] = {
89
  { { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX } },
90
  { { 3200, UINT_MAX }, { 250, UINT_MAX }, { UINT_MAX, UINT_MAX } },
91
  { { 1728, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
92
  { { 864, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
93
  { { 432, UINT_MAX }, { 86, UINT_MAX }, { UINT_MAX, UINT_MAX } },
94
  { { 864, 97 }, { 142, 16 }, { UINT_MAX, UINT_MAX } },
95
  { { 432, 97 }, { 86, 16 }, { UINT_MAX, UINT_MAX } },
96
  { { 216, 25 }, { 86, 10 }, { UINT_MAX, UINT_MAX } },
97
  { { 216, 25 }, { 0, 10 }, { UINT_MAX, UINT_MAX } }
98
};
99
100
// Transform size to be used for default, mode and winner mode evaluation
101
// Index 0: Default mode evaluation, Winner mode processing is not applicable
102
// (Eg : IntraBc) Index 1: Mode evaluation. Index 2: Winner mode evaluation.
103
// Index 1 and 2 are applicable when enable_winner_mode_for_tx_size_srch speed
104
// feature is ON
105
static const TX_SIZE_SEARCH_METHOD
106
    tx_size_search_methods[4][MODE_EVAL_TYPES] = {
107
      { USE_FULL_RD, USE_LARGESTALL, USE_FULL_RD },
108
      { USE_FAST_RD, USE_LARGESTALL, USE_FULL_RD },
109
      { USE_LARGESTALL, USE_LARGESTALL, USE_FULL_RD },
110
      { USE_LARGESTALL, USE_LARGESTALL, USE_LARGESTALL }
111
    };
112
113
// Predict transform skip levels to be used for default, mode and winner mode
114
// evaluation. Index 0: Default mode evaluation, Winner mode processing is not
115
// applicable. Index 1: Mode evaluation, Index 2: Winner mode evaluation
116
// Values indicate the aggressiveness of skip flag prediction.
117
// 0 : no early skip prediction
118
// 1 : conservative early skip prediction using DCT_DCT
119
// 2 : early skip prediction based on SSE
120
static const unsigned int predict_skip_levels[3][MODE_EVAL_TYPES] = {
121
  { 0, 0, 0 }, { 1, 1, 1 }, { 1, 2, 1 }
122
};
123
124
// Predict skip or DC block level used during transform type search. It is
125
// indexed using the following:
126
// First index  : Speed feature 'dc_blk_pred_level' (0 to 3)
127
// Second index : Mode evaluation type (DEFAULT_EVAL, MODE_EVAL and
128
// WINNER_MODE_EVAL).
129
//
130
// The values of predict_dc_levels[][] indicate the aggressiveness of predicting
131
// a block as transform skip or DC only.
132
// Type 0 : No skip block or DC only block prediction
133
// Type 1 : Prediction of skip block based on residual mean and variance
134
// Type 2 : Prediction of skip block or DC only block based on residual mean and
135
// variance
136
static const unsigned int predict_dc_levels[4][MODE_EVAL_TYPES] = {
137
  { 0, 0, 0 }, { 1, 1, 0 }, { 2, 2, 0 }, { 2, 2, 2 }
138
};
139
140
#if !CONFIG_FPMT_TEST
141
// This table holds the maximum number of reference frames for global motion.
142
// The table is indexed as per the speed feature 'gm_search_type'.
143
// 0 : All reference frames are allowed.
144
// 1 : All reference frames except L2 and L3 are allowed.
145
// 2 : All reference frames except L2, L3 and ARF2 are allowed.
146
// 3 : No reference frame is allowed.
147
static const int gm_available_reference_frames[GM_DISABLE_SEARCH + 1] = {
148
  INTER_REFS_PER_FRAME, INTER_REFS_PER_FRAME - 2, INTER_REFS_PER_FRAME - 3, 0
149
};
150
#endif
151
152
// Intra only frames, golden frames (except alt ref overlays) and
153
// alt ref frames tend to be coded at a higher than ambient quality
154
0
static int frame_is_boosted(const AV1_COMP *cpi) {
155
0
  return frame_is_kf_gf_arf(cpi);
156
0
}
157
158
// Set transform rd gate level for all transform search cases.
159
static inline void set_txfm_rd_gate_level(
160
0
    int txfm_rd_gate_level[TX_SEARCH_CASES], int level) {
161
0
  assert(level <= MAX_TX_RD_GATE_LEVEL);
162
0
  for (int idx = 0; idx < TX_SEARCH_CASES; idx++)
163
0
    txfm_rd_gate_level[idx] = level;
164
0
}
165
166
static void set_allintra_speed_feature_framesize_dependent(
167
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
168
0
  const AV1_COMMON *const cm = &cpi->common;
169
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
170
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
171
0
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
172
0
  const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
173
0
  const bool use_hbd = cpi->oxcf.use_highbitdepth;
174
175
0
  if (is_480p_or_larger) {
176
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
177
0
    if (is_720p_or_larger)
178
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
179
0
    else
180
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
181
0
  } else {
182
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
183
0
    sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
184
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
185
0
  }
186
187
0
  if (is_4k_or_larger) {
188
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
189
0
  }
190
191
  // TODO(huisu@google.com): train models for 720P and above.
192
0
  if (!is_720p_or_larger) {
193
0
    sf->part_sf.ml_partition_search_breakout_thresh[0] = -1.0f;
194
0
    sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.993307f;
195
0
    sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.952574f;
196
0
    sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.924142f;
197
0
    sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.880797f;
198
0
    sf->part_sf.ml_early_term_after_part_split_level = 1;
199
0
  }
200
201
0
  sf->part_sf.ml_partition_search_breakout_model_index = 0;
202
203
0
  if (is_720p_or_larger) {
204
    // TODO(chiyotsai@google.com): make this speed feature adaptive based on
205
    // current block's vertical texture instead of hardcoded with resolution
206
0
    sf->mv_sf.use_downsampled_sad = 2;
207
0
  }
208
209
0
  if (speed >= 1) {
210
0
    sf->part_sf.ml_4_partition_search_level_index = 1;
211
0
    if (is_720p_or_larger) {
212
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
213
0
    } else if (is_480p_or_larger) {
214
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
215
0
    } else {
216
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
217
0
    }
218
219
0
    if (is_720p_or_larger) {
220
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 0.5f;
221
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.5042595622791082f;
222
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.5f;
223
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.8378425823517456f;
224
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.8047585616503903f;
225
0
      sf->part_sf.ml_partition_search_breakout_model_index = 1;
226
0
    } else {
227
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = -1.0f;
228
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.952574f;
229
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.952574f;
230
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.924142f;
231
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.880797f;
232
0
    }
233
0
    sf->part_sf.ml_early_term_after_part_split_level = 2;
234
0
  }
235
236
0
  if (speed >= 2) {
237
0
    sf->part_sf.ml_4_partition_search_level_index = 2;
238
0
    if (is_720p_or_larger) {
239
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
240
0
    } else {
241
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
242
0
    }
243
244
0
    if (is_720p_or_larger) {
245
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 0.5f;
246
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.5042595622791082f;
247
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.5f;
248
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.8378425823517456f;
249
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.8047585616503903f;
250
0
      sf->part_sf.ml_partition_search_breakout_model_index = 1;
251
0
    }
252
253
0
    if (is_720p_or_larger) {
254
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
255
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
256
0
    } else {
257
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
258
0
      sf->part_sf.partition_search_breakout_rate_thr = 100;
259
0
    }
260
261
0
    if (is_480p_or_larger) {
262
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
263
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
264
0
    } else {
265
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
266
0
    }
267
0
  }
268
269
0
  if (speed >= 3) {
270
0
    sf->part_sf.ml_early_term_after_part_split_level = 0;
271
0
    sf->part_sf.ml_4_partition_search_level_index = 3;
272
273
0
    if (is_720p_or_larger) {
274
0
      for (int i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
275
0
        sf->part_sf.ml_partition_search_breakout_thresh[i] =
276
0
            -1;  // -1 means not enabled.
277
0
      }
278
0
      sf->part_sf.ml_partition_search_breakout_model_index = 0;
279
0
    }
280
281
0
    if (is_720p_or_larger) {
282
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
283
0
      sf->part_sf.partition_search_breakout_rate_thr = 200;
284
0
    } else {
285
0
      sf->part_sf.max_intra_bsize = BLOCK_32X32;
286
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
287
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
288
0
    }
289
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
290
0
  }
291
292
0
  if (speed >= 4) {
293
0
    if (is_720p_or_larger) {
294
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
295
0
    } else {
296
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
297
0
    }
298
299
0
    if (is_480p_or_larger) {
300
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
301
0
    }
302
0
  }
303
304
0
  if (speed >= 6) {
305
0
    if (is_720p_or_larger) {
306
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
307
0
    } else if (is_480p_or_larger) {
308
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
309
0
    }
310
311
0
    if (is_1080p_or_larger) {
312
0
      sf->part_sf.default_min_partition_size = BLOCK_8X8;
313
0
    }
314
315
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
316
0
  }
317
318
0
  if (speed >= 7) {
319
    // TODO(kyslov): add more speed features to control speed/quality
320
0
  }
321
322
0
  if (speed >= 8) {
323
0
    if (!is_480p_or_larger) {
324
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 2;
325
0
    }
326
0
    if (is_720p_or_larger) {
327
0
      sf->rt_sf.force_large_partition_blocks_intra = 1;
328
0
    }
329
0
  }
330
331
0
  if (speed >= 9) {
332
    // TODO(kyslov): add more speed features to control speed/quality
333
0
    if (!is_4k_or_larger) {
334
      // In av1_select_sb_size(), superblock size is set to 64x64 only for
335
      // resolutions less than 4k in speed>=9, to improve the multithread
336
      // performance. If cost update levels are set to INTERNAL_COST_UPD_OFF
337
      // for resolutions >= 4k, the SB size setting can be modified for these
338
      // resolutions as well.
339
0
      sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_OFF;
340
0
      sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_OFF;
341
0
    }
342
0
  }
343
0
}
344
345
static void set_allintra_speed_features_framesize_independent(
346
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
347
0
  const AV1_COMMON *const cm = &cpi->common;
348
0
  const int allow_screen_content_tools =
349
0
      cm->features.allow_screen_content_tools;
350
0
  const int use_hbd = cpi->oxcf.use_highbitdepth;
351
352
0
  sf->part_sf.less_rectangular_check_level = 1;
353
0
  sf->part_sf.ml_prune_partition = 1;
354
0
  sf->part_sf.prune_ext_partition_types_search_level = 1;
355
0
  sf->part_sf.prune_part4_search = 2;
356
0
  sf->part_sf.simple_motion_search_prune_rect = 1;
357
0
  sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
358
0
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
359
0
  sf->part_sf.use_best_rd_for_pruning = 1;
360
361
0
  sf->intra_sf.intra_pruning_with_hog = 1;
362
0
  sf->intra_sf.prune_luma_palette_size_search_level = 1;
363
0
  sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
364
0
  sf->intra_sf.early_term_chroma_palette_size_search = 1;
365
366
0
  sf->tx_sf.adaptive_txb_search_level = 1;
367
0
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
368
0
  sf->tx_sf.model_based_prune_tx_search_level = 1;
369
0
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
370
0
  sf->tx_sf.use_chroma_trellis_rd_mult = 1;
371
372
0
  sf->rt_sf.use_nonrd_pick_mode = 0;
373
0
  sf->rt_sf.discount_color_cost = 0;
374
0
  sf->rt_sf.use_real_time_ref_set = 0;
375
376
0
  if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
377
0
      cpi->use_screen_content_tools) {
378
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
379
0
  } else {
380
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
381
0
  }
382
383
0
  sf->rd_sf.perform_coeff_opt = 1;
384
0
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
385
386
0
  if (speed >= 1) {
387
0
    sf->part_sf.intra_cnn_based_part_prune_level =
388
0
        allow_screen_content_tools ? 0 : 2;
389
0
    sf->part_sf.simple_motion_search_prune_agg =
390
0
        allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL1;
391
0
    sf->part_sf.simple_motion_search_early_term_none = 1;
392
    // TODO(Venkat): Clean-up frame type dependency for
393
    // simple_motion_search_split in partition search function and set the
394
    // speed feature accordingly
395
0
    sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
396
0
    sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
397
0
    sf->part_sf.reuse_best_prediction_for_part_ab = 1;
398
399
0
    sf->mv_sf.exhaustive_searches_thresh <<= 1;
400
0
    sf->mv_sf.prune_intrabc_candidate_block_hash_search = 1;
401
402
0
    sf->intra_sf.prune_palette_search_level = 1;
403
0
    sf->intra_sf.prune_luma_palette_size_search_level = 2;
404
0
    sf->intra_sf.top_intra_model_count_allowed = 3;
405
406
0
    sf->tx_sf.adaptive_txb_search_level = 2;
407
0
    sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
408
0
    sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
409
0
    sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
410
0
    sf->tx_sf.model_based_prune_tx_search_level = 0;
411
0
    sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
412
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
413
0
    sf->tx_sf.tx_type_search.skip_tx_search = 1;
414
415
0
    sf->rd_sf.perform_coeff_opt = 2;
416
0
    sf->rd_sf.tx_domain_dist_level = 1;
417
0
    sf->rd_sf.tx_domain_dist_thres_level = 1;
418
419
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
420
0
    sf->lpf_sf.dual_sgr_penalty_level = 1;
421
0
    sf->lpf_sf.enable_sgr_ep_pruning = 1;
422
0
  }
423
424
0
  if (speed >= 2) {
425
0
    sf->mv_sf.auto_mv_step_size = 1;
426
427
0
    sf->part_sf.simple_motion_search_prune_agg =
428
0
        allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL2;
429
0
    sf->intra_sf.disable_smooth_intra = 1;
430
0
    sf->intra_sf.intra_pruning_with_hog = 2;
431
0
    sf->intra_sf.prune_filter_intra_level = 1;
432
433
0
    sf->rd_sf.perform_coeff_opt = 3;
434
435
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 1;
436
0
    sf->lpf_sf.prune_sgr_based_on_wiener = 1;
437
0
  }
438
439
0
  if (speed >= 3) {
440
0
    sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
441
0
    sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
442
0
    sf->hl_sf.screen_detection_mode2_fast_detection = 1;
443
444
0
    sf->part_sf.less_rectangular_check_level = 2;
445
0
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL3;
446
0
    sf->part_sf.prune_ext_part_using_split_info = 1;
447
448
0
    sf->mv_sf.full_pixel_search_level = 1;
449
0
    sf->mv_sf.search_method = DIAMOND;
450
451
    // TODO(chiyotsai@google.com): the thresholds chosen for intra hog are
452
    // inherited directly from luma hog with some minor tweaking. Eventually we
453
    // should run this with a bayesian optimizer to find the Pareto frontier.
454
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 2;
455
0
    sf->intra_sf.intra_pruning_with_hog = 3;
456
0
    sf->intra_sf.prune_palette_search_level = 2;
457
458
0
    sf->tx_sf.adaptive_txb_search_level = 2;
459
0
    sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
460
0
    sf->tx_sf.use_rd_based_breakout_for_intra_tx_search = true;
461
462
    // TODO(any): evaluate if these lpf features can be moved to speed 2.
463
    // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
464
    // loss.
465
0
    sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
466
0
    sf->lpf_sf.disable_loop_restoration_chroma = 0;
467
0
    sf->lpf_sf.reduce_wiener_window_size = 1;
468
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 2;
469
0
  }
470
471
0
  if (speed >= 4) {
472
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
473
474
0
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL4;
475
0
    sf->part_sf.simple_motion_search_reduce_search_steps = 4;
476
0
    sf->part_sf.prune_ext_part_using_split_info = 2;
477
0
    sf->part_sf.early_term_after_none_split = 1;
478
0
    sf->part_sf.ml_predict_breakout_level = 3;
479
480
0
    sf->intra_sf.prune_chroma_modes_using_luma_winner = 1;
481
482
0
    sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
483
484
0
    sf->tpl_sf.prune_starting_mv = 2;
485
0
    sf->tpl_sf.subpel_force_stop = HALF_PEL;
486
0
    sf->tpl_sf.search_method = FAST_BIGDIA;
487
488
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
489
0
    sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 2;
490
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
491
0
    sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 1;
492
493
0
    sf->rd_sf.perform_coeff_opt = 5;
494
0
    sf->rd_sf.tx_domain_dist_thres_level = 3;
495
496
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
497
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
498
499
0
    sf->mv_sf.reduce_search_range = 1;
500
0
    sf->mv_sf.hash_max_8x8_intrabc_blocks = 1;
501
502
0
    sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
503
0
    sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
504
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_DEFAULT;
505
0
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
506
0
  }
507
508
0
  if (speed >= 5) {
509
0
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL5;
510
0
    sf->part_sf.ext_partition_eval_thresh =
511
0
        allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
512
0
    sf->part_sf.intra_cnn_based_part_prune_level =
513
0
        allow_screen_content_tools ? 1 : 2;
514
515
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 3;
516
517
0
    sf->lpf_sf.use_coarse_filter_level_search = 0;
518
    // Disable Wiener and Self-guided Loop restoration filters.
519
0
    sf->lpf_sf.disable_wiener_filter = true;
520
0
    sf->lpf_sf.disable_sgr_filter = true;
521
522
0
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
523
524
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_FAST;
525
0
  }
526
527
0
  if (speed >= 6) {
528
0
    sf->intra_sf.prune_smooth_intra_mode_for_chroma = 1;
529
0
    sf->intra_sf.prune_filter_intra_level = 2;
530
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 4;
531
0
    sf->intra_sf.intra_pruning_with_hog = 4;
532
0
    sf->intra_sf.cfl_search_range = 1;
533
0
    sf->intra_sf.top_intra_model_count_allowed = 2;
534
0
    sf->intra_sf.adapt_top_model_rd_count_using_neighbors = 1;
535
0
    sf->intra_sf.prune_luma_odd_delta_angles_in_intra = 1;
536
537
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
538
0
        allow_screen_content_tools ? 0 : 2;
539
0
    sf->part_sf.prune_rect_part_using_4x4_var_deviation = true;
540
0
    sf->part_sf.prune_rect_part_using_none_pred_mode = true;
541
0
    sf->part_sf.prune_sub_8x8_partition_level =
542
0
        allow_screen_content_tools ? 0 : 1;
543
0
    sf->part_sf.prune_part4_search = 3;
544
    // TODO(jingning): This might not be a good trade off if the
545
    // target image quality is very low.
546
0
    sf->part_sf.default_max_partition_size = BLOCK_32X32;
547
548
0
    sf->mv_sf.use_bsize_dependent_search_method = 3;
549
0
    sf->mv_sf.intrabc_search_level = 1;
550
551
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 3;
552
0
    sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 0;
553
0
    sf->tx_sf.prune_intra_tx_depths_using_nn = true;
554
555
0
    sf->rd_sf.perform_coeff_opt = 6;
556
0
    sf->rd_sf.tx_domain_dist_level = 3;
557
558
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
559
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
560
561
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
562
0
    sf->winner_mode_sf.prune_winner_mode_eval_level = 1;
563
0
    sf->winner_mode_sf.dc_blk_pred_level = 1;
564
0
  }
565
  // The following should make all-intra mode speed 7 approximately equal
566
  // to real-time speed 6,
567
  // all-intra speed 8 close to real-time speed 7, and all-intra speed 9
568
  // close to real-time speed 8
569
0
  if (speed >= 7) {
570
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
571
0
    sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
572
0
    sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
573
0
    sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
574
0
    sf->rt_sf.var_part_split_threshold_shift = 7;
575
0
  }
576
577
0
  if (speed >= 8) {
578
0
    sf->rt_sf.hybrid_intra_pickmode = 2;
579
0
    sf->rt_sf.use_nonrd_pick_mode = 1;
580
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 1;
581
0
    sf->rt_sf.var_part_split_threshold_shift = 8;
582
0
    sf->rt_sf.prune_palette_search_nonrd = 1;
583
    // Set mask for intra modes.
584
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
585
0
      if (i >= BLOCK_32X32)
586
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
587
0
      else
588
        // Use DC, H, V intra mode for block sizes < 32X32.
589
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
590
0
  }
591
592
0
  if (speed >= 9) {
593
0
    sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
594
0
    sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
595
596
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 0;
597
0
    sf->rt_sf.hybrid_intra_pickmode = 0;
598
    // Note that the threshold value below is intentionally lower than speed
599
    // 8's. This is due to the lack of hybrid intra pick mode, which causes
600
    // partitions to be bigger on average, causing noticeable ringing artifacts.
601
0
    sf->rt_sf.var_part_split_threshold_shift = 7;
602
0
    sf->rt_sf.vbp_prune_16x16_split_using_min_max_sub_blk_var = true;
603
0
    sf->rt_sf.prune_h_pred_using_best_mode_so_far = true;
604
0
    sf->rt_sf.enable_intra_mode_pruning_using_neighbors = true;
605
0
    sf->rt_sf.prune_intra_mode_using_best_sad_so_far = true;
606
0
  }
607
608
  // As the speed feature prune_chroma_modes_using_luma_winner already
609
  // constrains the number of chroma directional mode evaluations to a maximum
610
  // of 1, the HOG computation and the associated pruning logic does not seem to
611
  // help speed-up the chroma mode evaluations. Hence disable the speed feature
612
  // chroma_intra_pruning_with_hog when prune_chroma_modes_using_luma_winner is
613
  // enabled.
614
0
  if (sf->intra_sf.prune_chroma_modes_using_luma_winner)
615
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 0;
616
0
}
617
618
// Configures framesize dependent speed features for low complexity decoding.
619
static void set_good_speed_features_lc_dec_framesize_dependent(
620
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
621
0
  if (speed < 1 || speed > 3) return;
622
623
0
  const AV1_COMMON *const cm = &cpi->common;
624
0
  const bool is_between_608p_and_1080p = AOMMIN(cm->width, cm->height) >= 608 &&
625
0
                                         AOMMIN(cm->width, cm->height) <= 1080;
626
0
  const bool is_between_720p_and_1080p = AOMMIN(cm->width, cm->height) >= 720 &&
627
0
                                         AOMMIN(cm->width, cm->height) <= 1080;
628
0
  const bool is_vertical_video = cm->width < cm->height;
629
630
0
  const FRAME_UPDATE_TYPE update_type =
631
0
      get_frame_update_type(&cpi->ppi->gf_group, cpi->gf_frame_index);
632
0
  const int boosted = frame_is_boosted(cpi);
633
0
  const int is_key_frame = frame_is_intra_only(cm);
634
635
  // Need to study the decoder time impact.
636
0
  sf->interp_sf.use_more_sharp_interp = 0;
637
638
  // Speed features for vertical videos
639
0
  if (is_vertical_video && is_between_608p_and_1080p) {
640
0
    const int leaf_and_overlay_frames =
641
0
        (update_type == LF_UPDATE || update_type == OVERLAY_UPDATE ||
642
0
         update_type == INTNL_OVERLAY_UPDATE);
643
0
    if (leaf_and_overlay_frames) sf->gm_sf.gm_search_type = GM_DISABLE_SEARCH;
644
0
    sf->gm_sf.gm_erroradv_tr_level = 1;
645
646
0
    sf->hl_sf.ref_frame_mvs_lvl = 2;
647
648
0
    sf->lpf_sf.adaptive_cdef_mode = 1;
649
0
    sf->lpf_sf.dual_sgr_penalty_level = boosted ? 1 : 3;
650
0
    sf->lpf_sf.switchable_lr_with_bias_level = 1;
651
0
    sf->lpf_sf.skip_loop_filter_using_filt_error =
652
0
        (update_type != OVERLAY_UPDATE && update_type != INTNL_OVERLAY_UPDATE &&
653
0
         cm->current_frame.pyramid_level > 1)
654
0
            ? 1
655
0
            : 0;
656
657
0
    sf->inter_sf.bias_warp_mode_rd_scale_pct = 4;
658
0
    sf->inter_sf.bias_obmc_mode_rd_scale_pct = 1.5f;
659
660
0
    sf->part_sf.split_partition_penalty_level = is_key_frame ? 0 : 2;
661
662
0
    if (speed >= 2) {
663
0
      sf->part_sf.split_partition_penalty_level = is_key_frame ? 0 : 1;
664
0
    }
665
0
  }
666
667
  // Speed features for regular videos
668
0
  if (!is_vertical_video && is_between_720p_and_1080p) {
669
0
    sf->gm_sf.gm_erroradv_tr_level = 2;
670
671
0
    sf->hl_sf.ref_frame_mvs_lvl = 1;
672
673
0
    sf->lpf_sf.adaptive_cdef_mode = 1;
674
0
    sf->lpf_sf.dual_sgr_penalty_level = boosted ? 1 : 3;
675
0
    sf->lpf_sf.skip_loop_filter_using_filt_error =
676
0
        (update_type != OVERLAY_UPDATE && update_type != INTNL_OVERLAY_UPDATE &&
677
0
         cm->current_frame.pyramid_level > 1)
678
0
            ? 1
679
0
            : 0;
680
681
0
    sf->inter_sf.bias_warp_mode_rd_scale_pct = 4;
682
0
    sf->inter_sf.bias_obmc_mode_rd_scale_pct = 1.5f;
683
684
0
    sf->part_sf.split_partition_penalty_level = is_key_frame ? 0 : 2;
685
686
0
    if (speed >= 2) {
687
0
      sf->part_sf.split_partition_penalty_level = is_key_frame ? 0 : 1;
688
0
    }
689
0
  }
690
0
}
691
692
// Configures framesize independent speed features for low complexity decoding.
693
static void set_good_speed_features_lc_dec_framesize_independent(
694
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
695
0
  if (speed < 1 || speed > 3) return;
696
697
  // Need to study the decoder time impact.
698
0
  sf->interp_sf.use_more_sharp_interp = 0;
699
700
0
  const FRAME_UPDATE_TYPE update_type =
701
0
      get_frame_update_type(&cpi->ppi->gf_group, cpi->gf_frame_index);
702
703
0
  sf->lpf_sf.adaptive_luma_loop_filter_skip =
704
0
      (update_type != OVERLAY_UPDATE && update_type != INTNL_OVERLAY_UPDATE)
705
0
          ? 1
706
0
          : 0;
707
0
}
708
709
static void set_good_speed_feature_framesize_dependent(
710
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
711
0
  const AV1_COMMON *const cm = &cpi->common;
712
0
  const int is_480p_or_lesser = AOMMIN(cm->width, cm->height) <= 480;
713
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
714
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
715
0
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
716
0
  const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
717
0
  const bool use_hbd = cpi->oxcf.use_highbitdepth;
718
  // Speed features applicable for temporal filtering and tpl modules may be
719
  // changed based on frame type at places where the sf is applied (Example :
720
  // use_downsampled_sad). This is because temporal filtering and tpl modules
721
  // are called before this function (except for the first key frame).
722
  // TODO(deepa.kg@ittiam.com): For the speed features applicable to temporal
723
  // filtering and tpl modules, modify the sf initialization appropriately
724
  // before calling the modules.
725
0
  const int boosted = frame_is_boosted(cpi);
726
0
  const int is_boosted_arf2_bwd_type =
727
0
      boosted ||
728
0
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
729
0
  const int is_lf_frame =
730
0
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == LF_UPDATE;
731
0
  const int allow_screen_content_tools =
732
0
      cm->features.allow_screen_content_tools;
733
734
0
  if (is_480p_or_larger) {
735
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
736
0
    if (is_720p_or_larger)
737
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
738
0
    else
739
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
740
0
  } else {
741
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
742
0
    sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
743
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
744
0
  }
745
746
0
  if (is_4k_or_larger) {
747
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
748
0
  }
749
750
  // TODO(huisu@google.com): train models for 720P and above.
751
0
  if (!is_720p_or_larger) {
752
0
    sf->part_sf.ml_partition_search_breakout_thresh[0] = -1.0f;
753
0
    sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.993307f;
754
0
    sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.952574f;
755
0
    sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.924142f;
756
0
    sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.880797f;
757
0
    sf->part_sf.ml_early_term_after_part_split_level = 1;
758
0
  }
759
760
0
  sf->part_sf.ml_partition_search_breakout_model_index = 0;
761
762
0
  if (is_720p_or_larger) {
763
    // TODO(chiyotsai@google.com): make this speed feature adaptive based on
764
    // current block's vertical texture instead of hardcoded with resolution
765
0
    sf->mv_sf.use_downsampled_sad = 2;
766
0
  }
767
768
0
  if (!is_720p_or_larger) {
769
0
    const RateControlCfg *const rc_cfg = &cpi->oxcf.rc_cfg;
770
0
    const int rate_tolerance =
771
0
        AOMMIN(rc_cfg->under_shoot_pct, rc_cfg->over_shoot_pct);
772
0
    sf->hl_sf.recode_tolerance = 25 + (rate_tolerance >> 2);
773
0
  }
774
775
0
  if (speed >= 1) {
776
0
    sf->part_sf.ml_4_partition_search_level_index = 1;
777
0
    sf->inter_sf.skip_newmv_in_drl = 1;
778
779
0
    if (is_480p_or_lesser) {
780
0
      sf->inter_sf.skip_cmp_using_top_cmp_avg_est_rd_lvl = 1;
781
0
    } else {
782
0
      sf->inter_sf.skip_cmp_using_top_cmp_avg_est_rd_lvl = 2;
783
0
    }
784
785
0
    if (is_720p_or_larger) {
786
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
787
0
    } else if (is_480p_or_larger) {
788
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
789
0
    } else {
790
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
791
0
    }
792
793
0
    if (is_720p_or_larger) {
794
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 0.5f;
795
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.5042595622791082f;
796
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.5f;
797
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.8378425823517456f;
798
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.8047585616503903f;
799
0
      sf->part_sf.ml_partition_search_breakout_model_index = 1;
800
0
    } else {
801
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = -1.0f;
802
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.952574f;
803
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.952574f;
804
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.924142f;
805
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.880797f;
806
0
    }
807
0
    sf->part_sf.ml_early_term_after_part_split_level = 2;
808
809
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
810
0
  }
811
812
0
  if (speed >= 2) {
813
0
    sf->part_sf.ml_4_partition_search_level_index = 2;
814
0
    if (is_720p_or_larger) {
815
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
816
0
    } else {
817
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
818
0
    }
819
820
0
    if (is_720p_or_larger) {
821
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 0.5f;
822
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 0.5042595622791082f;
823
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 0.5f;
824
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 0.8378425823517456f;
825
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = 0.8047585616503903f;
826
0
      sf->part_sf.ml_partition_search_breakout_model_index = 1;
827
0
    }
828
829
0
    if (is_720p_or_larger) {
830
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
831
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
832
0
    } else {
833
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
834
0
      sf->part_sf.partition_search_breakout_rate_thr = 100;
835
0
    }
836
837
0
    if (is_720p_or_larger) {
838
0
      sf->inter_sf.prune_obmc_prob_thresh = 16;
839
0
    } else {
840
0
      sf->inter_sf.prune_obmc_prob_thresh = 8;
841
0
    }
842
843
0
    if (is_480p_or_larger) {
844
0
      sf->inter_sf.disable_interintra_wedge_var_thresh = 100;
845
0
    } else {
846
0
      sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
847
0
    }
848
849
0
    if (is_480p_or_lesser) sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
850
851
0
    if (is_720p_or_larger) {
852
0
      sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 1 : 0;
853
0
    } else {
854
0
      sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 2 : 0;
855
0
    }
856
857
0
    sf->inter_sf.skip_cmp_using_top_cmp_avg_est_rd_lvl = 3;
858
859
0
    if (is_480p_or_larger) {
860
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
861
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
862
0
    } else {
863
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
864
0
      sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = boosted ? 0 : 1;
865
0
      sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = boosted ? 0 : 1;
866
0
    }
867
868
0
    if (!is_720p_or_larger) {
869
0
      sf->mv_sf.disable_second_mv = 1;
870
0
      sf->mv_sf.auto_mv_step_size = 2;
871
0
    } else {
872
0
      sf->mv_sf.disable_second_mv = boosted ? 0 : 2;
873
0
      sf->mv_sf.auto_mv_step_size = 1;
874
0
    }
875
876
0
    if (!is_720p_or_larger) {
877
0
      sf->hl_sf.recode_tolerance = 50;
878
0
      sf->inter_sf.disable_interinter_wedge_newmv_search =
879
0
          is_boosted_arf2_bwd_type ? 0 : 1;
880
0
      sf->inter_sf.enable_fast_wedge_mask_search = 1;
881
0
    }
882
0
  }
883
884
0
  if (speed >= 3) {
885
0
    sf->inter_sf.enable_fast_wedge_mask_search = 1;
886
0
    sf->inter_sf.skip_newmv_in_drl = 2;
887
0
    sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
888
0
    sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 3 : 0;
889
0
    sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
890
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 1;
891
0
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch =
892
0
        frame_is_intra_only(&cpi->common) ? 0 : 1;
893
894
0
    sf->part_sf.ml_early_term_after_part_split_level = 0;
895
896
0
    if (is_720p_or_larger) {
897
0
      for (int i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
898
0
        sf->part_sf.ml_partition_search_breakout_thresh[i] =
899
0
            -1;  // -1 means not enabled.
900
0
      }
901
0
      sf->part_sf.ml_partition_search_breakout_model_index = 0;
902
0
    }
903
904
0
    sf->part_sf.ml_4_partition_search_level_index = 3;
905
906
0
    if (is_720p_or_larger) {
907
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
908
0
      sf->part_sf.partition_search_breakout_rate_thr = 200;
909
0
      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 2 : 0;
910
0
    } else {
911
0
      sf->part_sf.max_intra_bsize = BLOCK_32X32;
912
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
913
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
914
0
      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 1 : 0;
915
0
    }
916
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
917
918
0
    if (is_480p_or_larger) {
919
0
      sf->part_sf.early_term_after_none_split = 1;
920
0
    } else {
921
0
      sf->part_sf.early_term_after_none_split = 0;
922
0
    }
923
0
    if (is_720p_or_larger) {
924
0
      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 2;
925
0
    } else {
926
0
      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 3;
927
0
    }
928
929
0
    if (is_720p_or_larger) {
930
0
      sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
931
0
      sf->inter_sf.skip_interinter_wedge_search_based_on_mse = 1;
932
0
      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 1;
933
0
    } else {
934
0
      sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
935
0
      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
936
0
      sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL2;
937
0
    }
938
939
0
    if (is_480p_or_lesser) {
940
0
      sf->inter_sf.prune_comp_ref_frames = 0;
941
0
    } else {
942
0
      sf->inter_sf.prune_comp_ref_frames = 1;
943
0
    }
944
945
0
    sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
946
0
  }
947
948
0
  if (speed >= 4) {
949
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
950
0
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
951
0
    if (is_720p_or_larger) {
952
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
953
0
    } else {
954
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
955
0
    }
956
0
    sf->part_sf.early_term_after_none_split = 1;
957
958
0
    if (is_480p_or_larger) {
959
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
960
0
    } else {
961
0
      sf->mv_sf.skip_fullpel_search_using_startmv_refmv = boosted ? 0 : 1;
962
0
    }
963
964
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
965
0
    sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
966
0
    sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
967
0
    if (is_480p_or_lesser) sf->inter_sf.skip_newmv_in_drl = 3;
968
969
0
    if (is_720p_or_larger) {
970
0
      sf->inter_sf.prune_comp_ref_frames = 2;
971
0
    } else if (is_480p_or_larger) {
972
0
      sf->inter_sf.prune_comp_ref_frames = is_boosted_arf2_bwd_type ? 0 : 2;
973
0
    }
974
975
0
    if (is_720p_or_larger)
976
0
      sf->hl_sf.recode_tolerance = 32;
977
0
    else
978
0
      sf->hl_sf.recode_tolerance = 55;
979
980
0
    sf->intra_sf.skip_intra_in_interframe = 4;
981
982
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
983
0
  }
984
985
0
  if (speed >= 5) {
986
0
    if (is_720p_or_larger) {
987
0
      sf->inter_sf.prune_warped_prob_thresh = 16;
988
0
    } else if (is_480p_or_larger) {
989
0
      sf->inter_sf.prune_warped_prob_thresh = 8;
990
0
    }
991
0
    if (is_720p_or_larger) sf->hl_sf.recode_tolerance = 40;
992
993
0
    sf->inter_sf.skip_newmv_in_drl = 4;
994
0
    sf->inter_sf.prune_comp_ref_frames = 2;
995
0
    sf->mv_sf.skip_fullpel_search_using_startmv_refmv = boosted ? 0 : 1;
996
997
0
    if (!is_720p_or_larger) {
998
0
      sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW_SET;
999
0
      sf->inter_sf.prune_nearest_near_mv_using_refmv_weight =
1000
0
          (boosted || allow_screen_content_tools) ? 0 : 1;
1001
0
      sf->mv_sf.use_downsampled_sad = 1;
1002
0
    }
1003
1004
0
    if (!is_480p_or_larger) {
1005
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
1006
0
    }
1007
1008
0
    if (is_480p_or_lesser) {
1009
0
      sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL1;
1010
0
    } else {
1011
0
      sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL2;
1012
0
    }
1013
1014
0
    if (is_720p_or_larger) {
1015
0
      sf->part_sf.ext_part_eval_based_on_cur_best =
1016
0
          (allow_screen_content_tools || frame_is_intra_only(cm)) ? 0 : 1;
1017
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
1018
0
    }
1019
1020
0
    if (is_480p_or_larger) {
1021
0
      sf->tpl_sf.reduce_num_frames = 1;
1022
0
    }
1023
0
  }
1024
1025
0
  if (speed >= 6) {
1026
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
1027
0
    sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
1028
0
    sf->inter_sf.prune_comp_ref_frames = 3;
1029
0
    sf->inter_sf.prune_nearest_near_mv_using_refmv_weight =
1030
0
        (boosted || allow_screen_content_tools) ? 0 : 1;
1031
0
    sf->mv_sf.skip_fullpel_search_using_startmv_refmv = boosted ? 0 : 2;
1032
1033
0
    if (is_480p_or_larger && !is_720p_or_larger) {
1034
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
1035
0
    }
1036
1037
0
    if (is_480p_or_larger) {
1038
0
      sf->hl_sf.allow_sub_blk_me_in_tf = 1;
1039
0
    }
1040
1041
0
    if (is_1080p_or_larger) {
1042
0
      sf->part_sf.default_min_partition_size = BLOCK_8X8;
1043
0
    }
1044
1045
0
    if (is_720p_or_larger) {
1046
0
      sf->inter_sf.disable_masked_comp = 1;
1047
0
    }
1048
1049
0
    if (!is_720p_or_larger) {
1050
0
      sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1051
0
      sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1052
0
    }
1053
1054
0
    if (is_720p_or_larger) {
1055
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
1056
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 28);
1057
0
    } else {
1058
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
1059
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
1060
0
    }
1061
1062
0
    if (is_720p_or_larger) {
1063
0
      sf->inter_sf.prune_ref_mv_idx_search = 2;
1064
0
    } else {
1065
0
      sf->inter_sf.prune_ref_mv_idx_search = 1;
1066
0
    }
1067
1068
0
    if (is_720p_or_larger) {
1069
0
      sf->mv_sf.use_bsize_dependent_search_method = 1;
1070
0
    } else {
1071
0
      sf->mv_sf.use_bsize_dependent_search_method = 2;
1072
0
    }
1073
1074
0
    if (!is_720p_or_larger) {
1075
0
      sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
1076
0
          is_boosted_arf2_bwd_type ? 450 : 150;
1077
0
    }
1078
1079
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
1080
1081
0
    sf->hl_sf.recode_tolerance = 55;
1082
0
  }
1083
1084
0
  if (cpi->oxcf.enable_low_complexity_decode)
1085
0
    set_good_speed_features_lc_dec_framesize_dependent(cpi, sf, speed);
1086
1087
0
  if (cpi->oxcf.tune_cfg.tuning == AOM_TUNE_IQ ||
1088
0
      cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIMULACRA2) {
1089
0
    sf->intra_sf.skip_intra_in_interframe = 0;
1090
0
  }
1091
0
}
1092
1093
static void set_good_speed_features_framesize_independent(
1094
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
1095
0
  const AV1_COMMON *const cm = &cpi->common;
1096
0
  const GF_GROUP *const gf_group = &cpi->ppi->gf_group;
1097
0
  const int boosted = frame_is_boosted(cpi);
1098
0
  const int is_boosted_arf2_bwd_type =
1099
0
      boosted || gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
1100
0
  const int is_inter_frame =
1101
0
      gf_group->frame_type[cpi->gf_frame_index] == INTER_FRAME;
1102
0
  const int allow_screen_content_tools =
1103
0
      cm->features.allow_screen_content_tools;
1104
0
  const int use_hbd = cpi->oxcf.use_highbitdepth;
1105
0
  if (!cpi->oxcf.tile_cfg.enable_large_scale_tile) {
1106
0
    sf->hl_sf.high_precision_mv_usage = LAST_MV_DATA;
1107
0
  }
1108
1109
  // Speed 0 for all speed features that give neutral coding performance change.
1110
0
  sf->gm_sf.gm_search_type = boosted ? GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2
1111
0
                                     : GM_SEARCH_CLOSEST_REFS_ONLY;
1112
0
  sf->gm_sf.prune_ref_frame_for_gm_search = boosted ? 0 : 1;
1113
0
  sf->gm_sf.disable_gm_search_based_on_stats = 1;
1114
1115
0
  sf->part_sf.ml_prune_partition = 1;
1116
0
  sf->part_sf.prune_ext_partition_types_search_level = 1;
1117
0
  sf->part_sf.prune_part4_search = 2;
1118
0
  sf->part_sf.simple_motion_search_prune_rect = 1;
1119
0
  sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
1120
0
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
1121
0
  sf->part_sf.use_best_rd_for_pruning = 1;
1122
0
  sf->part_sf.simple_motion_search_prune_agg =
1123
0
      allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL0;
1124
1125
0
  sf->inter_sf.inter_mode_rd_model_estimation =
1126
0
      cpi->oxcf.algo_cfg.sharpness ? 0 : 1;
1127
0
  sf->inter_sf.model_based_post_interp_filter_breakout = 1;
1128
0
  sf->inter_sf.prune_compound_using_single_ref = 1;
1129
0
  sf->inter_sf.prune_mode_search_simple_translation = 1;
1130
0
  sf->inter_sf.prune_ref_frame_for_rect_partitions =
1131
0
      (boosted || (allow_screen_content_tools))
1132
0
          ? 0
1133
0
          : (is_boosted_arf2_bwd_type ? 1 : 2);
1134
0
  sf->inter_sf.reduce_inter_modes = boosted ? 1 : 2;
1135
0
  sf->inter_sf.selective_ref_frame = 1;
1136
0
  sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_SKIP_MV_SEARCH;
1137
0
  sf->inter_sf.enable_fast_compound_mode_search = 1;
1138
0
  sf->inter_sf.prune_inter_modes_based_on_tpl = 1;
1139
1140
0
  sf->interp_sf.use_fast_interpolation_filter_search = 1;
1141
0
  sf->interp_sf.disable_dual_filter = 1;
1142
0
  sf->interp_sf.use_more_sharp_interp = boosted ? 0 : 1;
1143
1144
0
  sf->intra_sf.intra_pruning_with_hog = 1;
1145
1146
0
  sf->tx_sf.adaptive_txb_search_level = 1;
1147
0
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
1148
0
  sf->tx_sf.model_based_prune_tx_search_level = 1;
1149
0
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
1150
1151
0
  sf->tpl_sf.search_method = NSTEP_8PT;
1152
1153
0
  sf->rt_sf.use_nonrd_pick_mode = 0;
1154
0
  sf->rt_sf.discount_color_cost = 0;
1155
0
  sf->rt_sf.use_real_time_ref_set = 0;
1156
1157
0
  if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
1158
0
      cpi->use_screen_content_tools) {
1159
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
1160
0
  } else {
1161
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
1162
0
  }
1163
0
  sf->mv_sf.disable_extensive_joint_motion_search = 1;
1164
1165
0
  sf->rd_sf.perform_coeff_opt = 1;
1166
0
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
1167
1168
0
  sf->lpf_sf.reduce_wiener_window_size = 1;
1169
1170
0
  if (speed >= 1) {
1171
0
    sf->hl_sf.adjust_num_frames_for_arf_filtering =
1172
0
        allow_screen_content_tools ? 0 : 1;
1173
1174
0
    sf->part_sf.intra_cnn_based_part_prune_level =
1175
0
        allow_screen_content_tools ? 0 : 2;
1176
1177
0
    sf->part_sf.simple_motion_search_prune_agg =
1178
0
        allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL1;
1179
0
    sf->part_sf.simple_motion_search_early_term_none = 1;
1180
    // TODO(Venkat): Clean-up frame type dependency for
1181
    // simple_motion_search_split in partition search function and set the
1182
    // speed feature accordingly
1183
0
    sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
1184
0
    sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
1185
0
    sf->part_sf.prune_h_or_v_4part_using_sms_info = boosted ? false : true;
1186
1187
0
    sf->mv_sf.exhaustive_searches_thresh <<= 1;
1188
0
    sf->mv_sf.obmc_full_pixel_search_level = 1;
1189
0
    sf->mv_sf.use_accurate_subpel_search = USE_4_TAPS;
1190
1191
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 2 : 1;
1192
0
    sf->inter_sf.prune_comp_type_by_comp_avg = 1;
1193
0
    sf->inter_sf.prune_comp_type_by_model_rd = boosted ? 0 : 1;
1194
0
    sf->inter_sf.prune_ref_frame_for_rect_partitions =
1195
0
        (frame_is_intra_only(&cpi->common) || (allow_screen_content_tools))
1196
0
            ? 0
1197
0
            : (boosted ? 1 : 2);
1198
0
    sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
1199
0
    sf->inter_sf.reuse_inter_intra_mode = 1;
1200
0
    sf->inter_sf.selective_ref_frame = 2;
1201
0
    sf->inter_sf.skip_arf_compound = 1;
1202
0
    sf->inter_sf.prune_comp_using_best_single_mode_ref = 2;
1203
0
    sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
1204
1205
0
    sf->interp_sf.use_interp_filter = 1;
1206
0
    sf->interp_sf.skip_model_rd_uv = 1;
1207
1208
0
    sf->intra_sf.prune_palette_search_level = 1;
1209
1210
0
    sf->tx_sf.adaptive_txb_search_level = 2;
1211
0
    sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
1212
0
    sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
1213
0
    sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
1214
0
    sf->tx_sf.model_based_prune_tx_search_level = 0;
1215
0
    sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
1216
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
1217
0
    sf->tx_sf.tx_type_search.skip_tx_search = 1;
1218
0
    sf->tx_sf.prune_inter_tx_split_rd_eval_lvl = 1;
1219
1220
0
    sf->rd_sf.perform_coeff_opt = boosted ? 2 : 3;
1221
0
    sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
1222
0
    sf->rd_sf.tx_domain_dist_thres_level = 1;
1223
1224
0
    sf->lpf_sf.dual_sgr_penalty_level = 1;
1225
0
    sf->lpf_sf.enable_sgr_ep_pruning = 1;
1226
1227
    // TODO(any, yunqing): move this feature to speed 0.
1228
0
    sf->tpl_sf.skip_alike_starting_mv = 1;
1229
0
  }
1230
1231
0
  if (speed >= 2) {
1232
0
    sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
1233
1234
0
    sf->part_sf.simple_motion_search_prune_agg =
1235
0
        allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL2;
1236
0
    sf->fp_sf.skip_motion_search_threshold = 25;
1237
1238
0
    sf->gm_sf.num_refinement_steps = 2;
1239
1240
0
    sf->part_sf.reuse_best_prediction_for_part_ab =
1241
0
        !frame_is_intra_only(&cpi->common);
1242
1243
0
    sf->mv_sf.simple_motion_subpel_force_stop = QUARTER_PEL;
1244
0
    sf->mv_sf.subpel_iters_per_step = 1;
1245
0
    sf->mv_sf.reduce_search_range = 1;
1246
1247
    // TODO(chiyotsai@google.com): We can get 10% speed up if we move
1248
    // adaptive_rd_thresh to speed 1. But currently it performs poorly on some
1249
    // clips (e.g. 5% loss on dinner_1080p). We need to examine the sequence a
1250
    // bit more closely to figure out why.
1251
0
    sf->inter_sf.adaptive_rd_thresh = 1;
1252
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
1253
0
    sf->inter_sf.fast_interintra_wedge_search = 1;
1254
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 1;
1255
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 1;
1256
0
    sf->inter_sf.prune_comp_type_by_comp_avg = 2;
1257
0
    sf->inter_sf.selective_ref_frame = 3;
1258
0
    sf->inter_sf.reuse_mask_search_results = 1;
1259
0
    set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level, boosted ? 0 : 1);
1260
0
    sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 1;
1261
0
    sf->inter_sf.alt_ref_search_fp = 1;
1262
0
    sf->inter_sf.prune_single_ref = boosted ? 1 : 2;
1263
1264
0
    sf->interp_sf.adaptive_interp_filter_search = 1;
1265
1266
0
    sf->intra_sf.intra_pruning_with_hog = 2;
1267
0
    sf->intra_sf.skip_intra_in_interframe = is_inter_frame ? 2 : 1;
1268
0
    sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1269
1270
0
    sf->tpl_sf.prune_starting_mv = 1;
1271
0
    sf->tpl_sf.search_method = DIAMOND;
1272
1273
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 3 : 4;
1274
0
    sf->rd_sf.use_mb_rd_hash = 1;
1275
1276
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 1;
1277
0
    sf->lpf_sf.prune_sgr_based_on_wiener = 1;
1278
0
    sf->lpf_sf.disable_loop_restoration_chroma = boosted ? 0 : 1;
1279
1280
    // TODO(any): Re-evaluate this feature set to 1 in speed 2.
1281
0
    sf->tpl_sf.allow_compound_pred = 0;
1282
0
    sf->tpl_sf.prune_ref_frames_in_tpl = 1;
1283
1284
0
    sf->tx_sf.prune_inter_tx_split_rd_eval_lvl = 2;
1285
0
  }
1286
1287
0
  if (speed >= 3) {
1288
0
    sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
1289
0
    sf->hl_sf.weight_calc_level_in_tf = 1;
1290
1291
0
    sf->gm_sf.prune_ref_frame_for_gm_search = 1;
1292
0
    sf->gm_sf.prune_zero_mv_with_sse = 1;
1293
0
    sf->gm_sf.num_refinement_steps = 0;
1294
1295
0
    sf->part_sf.simple_motion_search_prune_agg =
1296
0
        allow_screen_content_tools
1297
0
            ? SIMPLE_AGG_LVL0
1298
0
            : (boosted ? SIMPLE_AGG_LVL3 : QIDX_BASED_AGG_LVL1);
1299
0
    sf->part_sf.prune_ext_part_using_split_info = 1;
1300
0
    sf->part_sf.simple_motion_search_rect_split = 1;
1301
0
    sf->part_sf.prune_h_or_v_4part_using_sms_info = true;
1302
1303
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1304
0
    sf->mv_sf.search_method = DIAMOND;
1305
0
    sf->mv_sf.disable_second_mv = 2;
1306
0
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_1;
1307
0
    sf->mv_sf.use_intrabc = 0;
1308
1309
0
    sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
1310
0
    sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1311
0
    sf->inter_sf.disable_onesided_comp = 1;
1312
0
    sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1313
    // TODO(any): Experiment with the early exit mechanism for speeds 0, 1 and 2
1314
    // and clean-up the speed feature
1315
0
    sf->inter_sf.perform_best_rd_based_gating_for_chroma = 1;
1316
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 2;
1317
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 2;
1318
0
    sf->inter_sf.selective_ref_frame = 5;
1319
0
    sf->inter_sf.reuse_compound_type_decision = 1;
1320
0
    set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level,
1321
0
                           boosted ? 0 : (is_boosted_arf2_bwd_type ? 1 : 2));
1322
0
    sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 2;
1323
0
    sf->inter_sf.prune_single_ref = 2;
1324
1325
0
    sf->interp_sf.adaptive_interp_filter_search = 2;
1326
1327
    // TODO(chiyotsai@google.com): the thresholds chosen for intra hog are
1328
    // inherited directly from luma hog with some minor tweaking. Eventually we
1329
    // should run this with a bayesian optimizer to find the Pareto frontier.
1330
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 2;
1331
0
    sf->intra_sf.intra_pruning_with_hog = 3;
1332
0
    sf->intra_sf.prune_palette_search_level = 2;
1333
0
    sf->intra_sf.top_intra_model_count_allowed = 2;
1334
1335
0
    sf->tpl_sf.prune_starting_mv = 2;
1336
0
    sf->tpl_sf.skip_alike_starting_mv = 2;
1337
0
    sf->tpl_sf.prune_intra_modes = 1;
1338
0
    sf->tpl_sf.reduce_first_step_size = 6;
1339
0
    sf->tpl_sf.subpel_force_stop = QUARTER_PEL;
1340
1341
0
    sf->tx_sf.adaptive_txb_search_level = boosted ? 2 : 3;
1342
0
    sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
1343
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
1344
1345
    // TODO(any): Refactor the code related to following winner mode speed
1346
    // features
1347
0
    sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
1348
0
    sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
1349
0
    sf->winner_mode_sf.motion_mode_for_winner_cand =
1350
0
        boosted                                                          ? 0
1351
0
        : gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE ? 1
1352
0
                                                                         : 2;
1353
0
    sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 4;
1354
1355
    // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
1356
    // loss.
1357
0
    sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
1358
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 2;
1359
0
    sf->lpf_sf.use_coarse_filter_level_search =
1360
0
        frame_is_intra_only(&cpi->common) ? 0 : 1;
1361
0
    sf->lpf_sf.use_downsampled_wiener_stats = 1;
1362
0
  }
1363
1364
0
  if (speed >= 4) {
1365
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1366
1367
0
    sf->gm_sf.prune_zero_mv_with_sse = 2;
1368
0
    sf->gm_sf.downsample_level = 1;
1369
1370
0
    sf->part_sf.simple_motion_search_prune_agg =
1371
0
        allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL4;
1372
0
    sf->part_sf.simple_motion_search_reduce_search_steps = 4;
1373
0
    sf->part_sf.prune_ext_part_using_split_info = 2;
1374
0
    sf->part_sf.ml_predict_breakout_level = 3;
1375
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
1376
0
        (allow_screen_content_tools || frame_is_intra_only(&cpi->common)) ? 0
1377
0
                                                                          : 1;
1378
1379
0
    sf->inter_sf.alt_ref_search_fp = 2;
1380
0
    sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_DEFAULT] = boosted ? 0 : 3;
1381
0
    sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_MOTION_MODE] = boosted ? 0 : 5;
1382
0
    sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = boosted ? 0 : 3;
1383
1384
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 3;
1385
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 2;
1386
0
    sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
1387
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
1388
1389
0
    sf->interp_sf.cb_pred_filter_search = 1;
1390
0
    sf->interp_sf.skip_sharp_interp_filter_search = 1;
1391
0
    sf->interp_sf.use_interp_filter = 2;
1392
0
    sf->interp_sf.use_more_sharp_interp = 0;
1393
1394
0
    sf->intra_sf.intra_uv_mode_mask[TX_16X16] = UV_INTRA_DC_H_V_CFL;
1395
0
    sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC_H_V_CFL;
1396
0
    sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC_H_V_CFL;
1397
    // TODO(any): "intra_y_mode_mask" doesn't help much at speed 4.
1398
    // sf->intra_sf.intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
1399
    // sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
1400
    // sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC_H_V;
1401
0
    sf->intra_sf.skip_intra_in_interframe = 4;
1402
1403
0
    sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
1404
0
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
1405
1406
0
    sf->tpl_sf.subpel_force_stop = HALF_PEL;
1407
0
    sf->tpl_sf.search_method = FAST_BIGDIA;
1408
0
    sf->tpl_sf.use_sad_for_mode_decision = 1;
1409
1410
0
    sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
1411
1412
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 5 : 7;
1413
1414
    // TODO(any): Extend multi-winner mode processing support for inter frames
1415
0
    sf->winner_mode_sf.multi_winner_mode_type =
1416
0
        frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_DEFAULT
1417
0
                                          : MULTI_WINNER_MODE_OFF;
1418
0
    sf->winner_mode_sf.dc_blk_pred_level = boosted ? 0 : 2;
1419
1420
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
1421
0
  }
1422
1423
0
  if (speed >= 5) {
1424
0
    sf->hl_sf.adjust_num_frames_for_arf_filtering =
1425
0
        allow_screen_content_tools ? 0 : 2;
1426
1427
0
    sf->fp_sf.reduce_mv_step_param = 4;
1428
1429
0
    sf->part_sf.simple_motion_search_prune_agg =
1430
0
        allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL5;
1431
0
    sf->part_sf.ext_partition_eval_thresh =
1432
0
        allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
1433
0
    sf->part_sf.prune_sub_8x8_partition_level =
1434
0
        allow_screen_content_tools ? 1 : 2;
1435
1436
0
    sf->mv_sf.warp_search_method = WARP_SEARCH_DIAMOND;
1437
1438
0
    sf->inter_sf.prune_inter_modes_if_skippable = 1;
1439
0
    sf->inter_sf.prune_single_ref = is_boosted_arf2_bwd_type ? 0 : 3;
1440
0
    sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_DEFAULT] = boosted ? 0 : 4;
1441
0
    sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = boosted ? 0 : 5;
1442
0
    sf->inter_sf.enable_fast_compound_mode_search = 2;
1443
1444
0
    sf->interp_sf.skip_interp_filter_search = boosted ? 0 : 1;
1445
1446
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 3;
1447
0
    sf->intra_sf.disable_smooth_intra = 1;
1448
1449
    // TODO(any): Extend multi-winner mode processing support for inter frames
1450
0
    sf->winner_mode_sf.multi_winner_mode_type =
1451
0
        frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_FAST
1452
0
                                          : MULTI_WINNER_MODE_OFF;
1453
1454
    // Disable Self-guided Loop restoration filter.
1455
0
    sf->lpf_sf.enable_sgr_ep_pruning = 2;
1456
0
    sf->lpf_sf.disable_wiener_coeff_refine_search = true;
1457
1458
0
    sf->tpl_sf.prune_starting_mv = 3;
1459
0
    sf->tpl_sf.use_y_only_rate_distortion = 1;
1460
0
    sf->tpl_sf.subpel_force_stop = FULL_PEL;
1461
0
    sf->tpl_sf.gop_length_decision_method = 2;
1462
0
    sf->tpl_sf.use_sad_for_mode_decision = 2;
1463
1464
0
    sf->winner_mode_sf.dc_blk_pred_level = 2;
1465
1466
0
    sf->fp_sf.disable_recon = 1;
1467
0
  }
1468
1469
0
  if (speed >= 6) {
1470
0
    sf->hl_sf.disable_extra_sc_testing = 1;
1471
0
    sf->hl_sf.second_alt_ref_filtering = 0;
1472
1473
0
    sf->gm_sf.downsample_level = 2;
1474
1475
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 1 : 4;
1476
0
    sf->inter_sf.selective_ref_frame = 6;
1477
0
    sf->inter_sf.prune_single_ref = is_boosted_arf2_bwd_type ? 0 : 4;
1478
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 3;
1479
1480
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 4;
1481
0
    sf->intra_sf.intra_pruning_with_hog = 4;
1482
0
    sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC;
1483
0
    sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC;
1484
0
    sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC;
1485
0
    sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC;
1486
0
    sf->intra_sf.early_term_chroma_palette_size_search = 1;
1487
1488
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
1489
0
        boosted || allow_screen_content_tools ? 0 : 2;
1490
1491
0
    sf->part_sf.prune_part4_search = 3;
1492
1493
0
    sf->mv_sf.simple_motion_subpel_force_stop = FULL_PEL;
1494
1495
0
    sf->tpl_sf.gop_length_decision_method = 3;
1496
1497
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 6 : 8;
1498
1499
0
    sf->winner_mode_sf.dc_blk_pred_level = 3;
1500
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
1501
1502
0
    sf->fp_sf.skip_zeromv_motion_search = 1;
1503
0
  }
1504
1505
0
  if (cpi->oxcf.enable_low_complexity_decode)
1506
0
    set_good_speed_features_lc_dec_framesize_independent(cpi, sf, speed);
1507
1508
0
  if (cpi->oxcf.algo_cfg.sharpness == 3) {
1509
0
    sf->tx_sf.adaptive_txb_search_level = 0;
1510
0
    sf->tx_sf.tx_type_search.use_skip_flag_prediction = 0;
1511
0
  }
1512
1513
  // Set speed features for the IQ and SSIMULACRA2 tuning modes
1514
  // Layered image encoding has different requirements than regular video
1515
  // coding.
1516
  // Mainly, most of these speed features undo an implicit assumption that
1517
  // keyframes are encoded at a better quality than inter-coded frames.
1518
  // This means the encoder needs to be more thorough at considering and
1519
  // performing RDO on intra block candidates vs. inter block candidates for
1520
  // the best compression efficiency.
1521
  // Finally, enabling certain coding tools are beneficial for layered image
1522
  // encoding in general.
1523
0
  if (cpi->oxcf.tune_cfg.tuning == AOM_TUNE_IQ ||
1524
0
      cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIMULACRA2) {
1525
0
    sf->intra_sf.skip_intra_in_interframe = 0;
1526
0
    sf->inter_sf.inter_mode_rd_model_estimation = 0;
1527
0
    sf->mv_sf.use_intrabc = 1;
1528
1529
    // Don't prune intra candidates too aggressively, as it can cause more
1530
    // expensive inter candidates to be chosen instead
1531
0
    if (sf->intra_sf.intra_pruning_with_hog > 3) {
1532
0
      sf->intra_sf.intra_pruning_with_hog = 3;
1533
0
    }
1534
0
    if (sf->intra_sf.chroma_intra_pruning_with_hog > 3) {
1535
0
      sf->intra_sf.chroma_intra_pruning_with_hog = 3;
1536
0
    }
1537
0
  }
1538
0
}
1539
1540
static void set_rt_speed_feature_framesize_dependent(const AV1_COMP *const cpi,
1541
                                                     SPEED_FEATURES *const sf,
1542
0
                                                     int speed) {
1543
0
  const AV1_COMMON *const cm = &cpi->common;
1544
0
  const int boosted = frame_is_boosted(cpi);
1545
0
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
1546
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
1547
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
1548
0
  const int is_360p_or_larger = AOMMIN(cm->width, cm->height) >= 360;
1549
1550
0
  if (!is_360p_or_larger) {
1551
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 1;
1552
0
    sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
1553
0
    if (speed >= 6)
1554
0
      sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 2;
1555
0
    if (speed == 7) sf->rt_sf.prefer_large_partition_blocks = 2;
1556
0
    if (speed >= 7) {
1557
0
      sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1558
0
      sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
1559
0
      sf->rt_sf.use_rtc_tf = 2;
1560
0
    }
1561
0
    if (speed == 8) sf->rt_sf.prefer_large_partition_blocks = 1;
1562
0
    if (speed >= 8) {
1563
0
      sf->rt_sf.use_nonrd_filter_search = 1;
1564
0
      sf->rt_sf.tx_size_level_based_on_qstep = 1;
1565
0
    }
1566
0
    if (speed >= 9) {
1567
0
      sf->rt_sf.use_comp_ref_nonrd = 0;
1568
0
      sf->rt_sf.nonrd_aggressive_skip = 1;
1569
0
      sf->rt_sf.skip_intra_pred = 1;
1570
      // Only turn on enable_ref_short_signaling for low resolution when only
1571
      // LAST and GOLDEN ref frames are used.
1572
0
      sf->rt_sf.enable_ref_short_signaling =
1573
0
          (!sf->rt_sf.use_nonrd_altref_frame &&
1574
0
           (!sf->rt_sf.use_comp_ref_nonrd ||
1575
0
            (!sf->rt_sf.ref_frame_comp_nonrd[1] &&
1576
0
             !sf->rt_sf.ref_frame_comp_nonrd[2])));
1577
1578
// TODO(kyslov) Re-enable when AV1 models are trained
1579
#if 0
1580
#if CONFIG_RT_ML_PARTITIONING
1581
      if (!frame_is_intra_only(cm)) {
1582
        sf->part_sf.partition_search_type = ML_BASED_PARTITION;
1583
        sf->rt_sf.reuse_inter_pred_nonrd = 0;
1584
      }
1585
#endif
1586
#endif
1587
0
      sf->rt_sf.use_adaptive_subpel_search = false;
1588
0
    }
1589
0
    if (speed >= 10) {
1590
      // TODO(yunqingwang@google.com): To be conservative, disable
1591
      // sf->rt_sf.estimate_motion_for_var_based_partition = 3 for speed 10/qvga
1592
      // for now. May enable it in the future.
1593
0
      sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1594
0
      sf->rt_sf.skip_intra_pred = 2;
1595
0
      sf->rt_sf.hybrid_intra_pickmode = 3;
1596
0
      sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 1;
1597
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1598
0
      sf->rt_sf.use_nonrd_filter_search = 0;
1599
0
    }
1600
0
  } else {
1601
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 2;
1602
0
    sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1603
0
    if (speed <= 5) {
1604
0
      sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
1605
0
          boosted ? INT_MAX : 350;
1606
0
      sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 2;
1607
0
    }
1608
0
    if (speed == 6) sf->part_sf.disable_8x8_part_based_on_qidx = 1;
1609
0
    if (speed >= 6) sf->rt_sf.skip_newmv_mode_based_on_sse = 2;
1610
0
    if (speed == 7) {
1611
0
      sf->rt_sf.prefer_large_partition_blocks = 1;
1612
      // Enable this feature for [360p, 720p] resolution range initially.
1613
      // Only enable for low bitdepth to mitigate issue: b/303023614.
1614
0
      if (!cpi->rc.rtc_external_ratectrl &&
1615
0
          AOMMIN(cm->width, cm->height) <= 720 && !cpi->oxcf.use_highbitdepth)
1616
0
        sf->hl_sf.accurate_bit_estimate = cpi->oxcf.q_cfg.aq_mode == NO_AQ;
1617
0
    }
1618
0
    if (speed >= 7) {
1619
0
      sf->rt_sf.use_rtc_tf = 1;
1620
0
    }
1621
0
    if (speed == 8 && !cpi->ppi->use_svc) {
1622
0
      sf->rt_sf.short_circuit_low_temp_var = 0;
1623
0
      sf->rt_sf.use_nonrd_altref_frame = 1;
1624
0
    }
1625
0
    if (speed >= 8) sf->rt_sf.tx_size_level_based_on_qstep = 2;
1626
0
    if (speed >= 9) {
1627
0
      sf->rt_sf.gf_length_lvl = 1;
1628
0
      sf->rt_sf.skip_cdef_sb = 1;
1629
0
      sf->rt_sf.sad_based_adp_altref_lag = 2;
1630
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1631
0
      sf->rt_sf.use_adaptive_subpel_search = true;
1632
0
      sf->interp_sf.cb_pred_filter_search = 1;
1633
0
    }
1634
0
    if (speed >= 10) {
1635
0
      sf->rt_sf.hybrid_intra_pickmode = 2;
1636
0
      sf->rt_sf.sad_based_adp_altref_lag = 4;
1637
0
      sf->rt_sf.tx_size_level_based_on_qstep = 0;
1638
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1639
0
      sf->rt_sf.use_adaptive_subpel_search = false;
1640
0
      sf->interp_sf.cb_pred_filter_search = 2;
1641
0
    }
1642
0
  }
1643
0
  if (!is_480p_or_larger) {
1644
0
    if (speed == 7) {
1645
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 2;
1646
0
    }
1647
0
  }
1648
0
  if (!is_720p_or_larger) {
1649
0
    if (speed >= 9) {
1650
0
      sf->rt_sf.force_large_partition_blocks_intra = 1;
1651
0
    }
1652
0
  } else {
1653
0
    if (speed >= 6) sf->rt_sf.skip_newmv_mode_based_on_sse = 3;
1654
0
    if (speed == 7) sf->rt_sf.prefer_large_partition_blocks = 0;
1655
0
    if (speed >= 7) {
1656
0
      sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 2;
1657
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 1;
1658
0
    }
1659
0
    if (speed >= 9) {
1660
0
      sf->rt_sf.sad_based_adp_altref_lag = 1;
1661
0
      sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 0;
1662
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1663
0
    }
1664
0
    if (speed >= 10) {
1665
0
      sf->rt_sf.sad_based_adp_altref_lag = 3;
1666
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1667
0
    }
1668
0
  }
1669
  // TODO(Any): Check/Tune settings of other sfs for 1080p.
1670
0
  if (is_1080p_or_larger) {
1671
0
    if (speed >= 7) {
1672
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1673
0
      sf->rt_sf.use_adaptive_subpel_search = 0;
1674
0
    }
1675
0
    if (speed >= 9) sf->interp_sf.cb_pred_filter_search = 0;
1676
0
  } else {
1677
0
    if (speed >= 9) sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1678
0
    if (speed >= 10) sf->rt_sf.nonrd_aggressive_skip = 1;
1679
0
  }
1680
  // TODO(marpan): Tune settings for speed 11 video mode,
1681
0
  if (speed >= 11 && cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN) {
1682
0
    sf->rt_sf.skip_cdef_sb = 1;
1683
0
    sf->rt_sf.force_only_last_ref = 1;
1684
0
    sf->rt_sf.selective_cdf_update = 1;
1685
0
    sf->rt_sf.use_nonrd_filter_search = 0;
1686
0
    if (is_360p_or_larger) {
1687
0
      sf->part_sf.fixed_partition_size = BLOCK_32X32;
1688
0
      sf->rt_sf.use_fast_fixed_part = 1;
1689
0
      sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 2;
1690
0
    }
1691
0
    sf->rt_sf.increase_source_sad_thresh = 1;
1692
0
    sf->rt_sf.part_early_exit_zeromv = 2;
1693
0
    sf->rt_sf.set_zeromv_skip_based_on_source_sad = 2;
1694
0
    for (int i = 0; i < BLOCK_SIZES; ++i) {
1695
0
      sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1696
0
    }
1697
0
    sf->rt_sf.hybrid_intra_pickmode = 0;
1698
0
  }
1699
  // Setting for SVC, or when the ref_frame_config control is
1700
  // used to set the reference structure.
1701
0
  if (cpi->ppi->use_svc || cpi->ppi->rtc_ref.set_ref_frame_config) {
1702
0
    const RTC_REF *const rtc_ref = &cpi->ppi->rtc_ref;
1703
    // For SVC: for greater than 2 temporal layers, use better mv search on
1704
    // base temporal layers, and only on base spatial layer if highest
1705
    // resolution is above 640x360.
1706
0
    if (cpi->svc.number_temporal_layers >= 2 &&
1707
0
        cpi->svc.temporal_layer_id == 0 &&
1708
0
        (cpi->svc.spatial_layer_id == 0 ||
1709
0
         cpi->oxcf.frm_dim_cfg.width * cpi->oxcf.frm_dim_cfg.height <=
1710
0
             640 * 360)) {
1711
0
      sf->mv_sf.search_method = NSTEP;
1712
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1713
0
      sf->rt_sf.fullpel_search_step_param = 10;
1714
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1715
0
      if (cm->width * cm->height <= 352 * 288)
1716
0
        sf->rt_sf.nonrd_prune_ref_frame_search = 2;
1717
0
      sf->rt_sf.force_large_partition_blocks_intra = 0;
1718
0
    }
1719
0
    if (speed >= 8) {
1720
0
      if (cpi->svc.number_temporal_layers > 2)
1721
0
        sf->rt_sf.disable_cdf_update_non_reference_frame = true;
1722
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1723
0
      if (rtc_ref->non_reference_frame) {
1724
0
        sf->rt_sf.nonrd_aggressive_skip = 1;
1725
0
        sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1726
0
      }
1727
0
    }
1728
0
    if (speed <= 9 && cpi->svc.number_temporal_layers > 2 &&
1729
0
        cpi->svc.temporal_layer_id == 0)
1730
0
      sf->rt_sf.check_only_zero_zeromv_on_large_blocks = false;
1731
0
    else
1732
0
      sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
1733
0
    sf->rt_sf.frame_level_mode_cost_update = false;
1734
1735
    // Compound mode enabling.
1736
0
    if (rtc_ref->ref_frame_comp[0] || rtc_ref->ref_frame_comp[1] ||
1737
0
        rtc_ref->ref_frame_comp[2]) {
1738
0
      sf->rt_sf.use_comp_ref_nonrd = 1;
1739
0
      sf->rt_sf.ref_frame_comp_nonrd[0] =
1740
0
          rtc_ref->ref_frame_comp[0] && rtc_ref->reference[GOLDEN_FRAME - 1];
1741
0
      sf->rt_sf.ref_frame_comp_nonrd[1] =
1742
0
          rtc_ref->ref_frame_comp[1] && rtc_ref->reference[LAST2_FRAME - 1];
1743
0
      sf->rt_sf.ref_frame_comp_nonrd[2] =
1744
0
          rtc_ref->ref_frame_comp[2] && rtc_ref->reference[ALTREF_FRAME - 1];
1745
0
    } else {
1746
0
      sf->rt_sf.use_comp_ref_nonrd = 0;
1747
0
    }
1748
1749
0
    if (cpi->svc.number_spatial_layers > 1 ||
1750
0
        cpi->svc.number_temporal_layers > 1)
1751
0
      sf->hl_sf.accurate_bit_estimate = 0;
1752
1753
0
    sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1754
1755
    // For single layers RPS: bias/adjustment for recovery frame.
1756
0
    if (cpi->ppi->rtc_ref.bias_recovery_frame) {
1757
0
      sf->mv_sf.search_method = NSTEP;
1758
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE;
1759
0
      sf->rt_sf.fullpel_search_step_param = 8;
1760
0
      sf->rt_sf.nonrd_aggressive_skip = 0;
1761
0
    }
1762
0
  }
1763
  // Screen settings.
1764
0
  if (cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN) {
1765
    // TODO(marpan): Check settings for speed 7 and 8.
1766
0
    if (speed >= 7) {
1767
0
      sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1768
0
      sf->mv_sf.use_bsize_dependent_search_method = 0;
1769
0
      sf->rt_sf.skip_cdef_sb = 1;
1770
0
      sf->rt_sf.increase_color_thresh_palette = 1;
1771
0
      if (!frame_is_intra_only(cm)) sf->rt_sf.dct_only_palette_nonrd = 1;
1772
0
    }
1773
0
    if (speed >= 8) {
1774
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 3;
1775
0
      sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1776
0
      sf->rt_sf.use_nonrd_filter_search = 0;
1777
0
      sf->rt_sf.prune_hv_pred_modes_using_src_sad = false;
1778
0
    }
1779
0
    if (speed >= 9) {
1780
0
      sf->rt_sf.prune_idtx_nonrd = 1;
1781
0
      sf->rt_sf.part_early_exit_zeromv = 2;
1782
0
      sf->rt_sf.skip_lf_screen = 1;
1783
0
      sf->rt_sf.nonrd_prune_ref_frame_search = 3;
1784
0
      sf->rt_sf.var_part_split_threshold_shift = 10;
1785
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1786
0
      sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 1;
1787
0
      sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1788
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 0;
1789
0
      sf->interp_sf.cb_pred_filter_search = 0;
1790
0
    }
1791
0
    if (speed >= 10) {
1792
0
      if (cm->width * cm->height > 1920 * 1080)
1793
0
        sf->part_sf.disable_8x8_part_based_on_qidx = 1;
1794
0
      sf->rt_sf.screen_content_cdef_filter_qindex_thresh = 80;
1795
0
      sf->rt_sf.part_early_exit_zeromv = 1;
1796
0
      sf->rt_sf.nonrd_aggressive_skip = 1;
1797
0
      sf->rt_sf.thresh_active_maps_skip_lf_cdef = 90;
1798
0
      sf->rt_sf.hybrid_intra_pickmode = 0;
1799
0
      sf->rt_sf.dct_only_palette_nonrd = 1;
1800
0
      sf->rt_sf.prune_palette_search_nonrd = 1;
1801
0
      sf->rt_sf.prune_intra_mode_using_best_sad_so_far = true;
1802
0
      sf->rt_sf.rc_faster_convergence_static = 1;
1803
0
      sf->rt_sf.rc_compute_spatial_var_sc_kf = 1;
1804
0
    }
1805
0
    if (speed >= 11) {
1806
0
      sf->rt_sf.skip_lf_screen = 2;
1807
0
      sf->rt_sf.skip_cdef_sb = 2;
1808
0
      sf->rt_sf.prune_palette_search_nonrd = 2;
1809
0
      sf->rt_sf.increase_color_thresh_palette = 0;
1810
0
      sf->rt_sf.prune_h_pred_using_best_mode_so_far = true;
1811
0
      sf->rt_sf.enable_intra_mode_pruning_using_neighbors = true;
1812
0
    }
1813
0
    if (speed >= 12) {
1814
0
      if (cpi->rc.high_source_sad && cpi->rc.frame_source_sad > 40000 &&
1815
0
          cpi->rc.prev_avg_source_sad < 1000 &&
1816
0
          cpi->oxcf.frm_dim_cfg.width * cpi->oxcf.frm_dim_cfg.height >=
1817
0
              1280 * 720) {
1818
0
        sf->rt_sf.prune_palette_search_nonrd = 3;
1819
0
        sf->rt_sf.skip_newmv_mode_sad_screen = 1;
1820
0
      }
1821
0
    }
1822
0
    sf->rt_sf.skip_encoding_non_reference_slide_change =
1823
0
        cpi->oxcf.rc_cfg.drop_frames_water_mark > 0 ? 1 : 0;
1824
0
    sf->rt_sf.skip_newmv_flat_blocks_screen = 1;
1825
0
    sf->rt_sf.use_idtx_nonrd = 1;
1826
0
    sf->rt_sf.higher_thresh_scene_detection = 0;
1827
0
    sf->rt_sf.use_nonrd_altref_frame = 0;
1828
0
    sf->rt_sf.use_rtc_tf = 0;
1829
0
    sf->rt_sf.use_comp_ref_nonrd = 0;
1830
0
    sf->rt_sf.source_metrics_sb_nonrd = 1;
1831
0
    if (cpi->rc.high_source_sad == 1) {
1832
0
      sf->rt_sf.prefer_large_partition_blocks = 0;
1833
0
      sf->part_sf.max_intra_bsize = BLOCK_128X128;
1834
0
      for (int i = 0; i < BLOCK_SIZES; ++i) {
1835
0
        if (i > BLOCK_32X32)
1836
0
          sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1837
0
        else
1838
0
          sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
1839
0
      }
1840
0
    }
1841
0
    if (speed >= 11 && cpi->rc.high_motion_content_screen_rtc) {
1842
0
      sf->rt_sf.higher_thresh_scene_detection = 1;
1843
0
      sf->rt_sf.force_only_last_ref = 1;
1844
0
      sf->rt_sf.use_nonrd_filter_search = 0;
1845
0
      sf->part_sf.fixed_partition_size = BLOCK_32X32;
1846
0
      sf->rt_sf.use_fast_fixed_part = 1;
1847
0
      sf->rt_sf.increase_source_sad_thresh = 1;
1848
0
      sf->rt_sf.selective_cdf_update = 1;
1849
0
      sf->mv_sf.search_method = FAST_DIAMOND;
1850
0
    } else if (cpi->rc.max_block_source_sad > 20000 &&
1851
0
               cpi->rc.frame_source_sad > 100 && speed >= 6 &&
1852
0
               (cpi->rc.percent_blocks_with_motion > 1 ||
1853
0
                cpi->svc.last_layer_dropped[0])) {
1854
0
      sf->mv_sf.search_method = NSTEP;
1855
0
      sf->rt_sf.fullpel_search_step_param = 2;
1856
0
    }
1857
0
    if (cpi->rc.high_source_sad && cpi->ppi->rtc_ref.non_reference_frame) {
1858
0
      sf->rt_sf.use_idtx_nonrd = 0;
1859
0
      sf->rt_sf.prefer_large_partition_blocks = 1;
1860
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1861
0
      sf->rt_sf.fullpel_search_step_param = 10;
1862
0
    }
1863
0
    sf->rt_sf.partition_direct_merging = 0;
1864
0
    sf->hl_sf.accurate_bit_estimate = 0;
1865
    // This feature is for nonrd_pickmode.
1866
0
    if (sf->rt_sf.use_nonrd_pick_mode)
1867
0
      sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1868
0
    else
1869
0
      sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1870
0
  }
1871
0
  if (is_lossless_requested(&cpi->oxcf.rc_cfg)) {
1872
0
    sf->rt_sf.use_rtc_tf = 0;
1873
    // TODO(aomedia:3412): The setting accurate_bit_estimate = 0
1874
    // can be removed once it's fixed for lossless mode.
1875
0
    sf->hl_sf.accurate_bit_estimate = 0;
1876
0
  }
1877
0
  if (cpi->oxcf.use_highbitdepth) {
1878
    // Disable for use_highbitdepth = 1 to mitigate issue: b/303023614.
1879
0
    sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1880
0
  }
1881
0
  if (cpi->oxcf.superres_cfg.enable_superres) {
1882
0
    sf->rt_sf.use_rtc_tf = 0;
1883
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1884
0
  }
1885
  // rtc_tf feature allocates new source because of possible
1886
  // temporal filtering which may change the input source during encoding:
1887
  // this causes an issue on resized frames when psnr is calculated,
1888
  // so disable it here for frames that are resized (encoding width/height
1889
  // different from configured width/height). Also disable for spatial layers.
1890
  // Bug: 491358681
1891
0
  if ((is_psnr_calc_enabled(cpi) &&
1892
0
       (cpi->oxcf.frm_dim_cfg.width != cm->width ||
1893
0
        cpi->oxcf.frm_dim_cfg.height != cm->height)) ||
1894
0
      cpi->svc.number_spatial_layers > 1)
1895
0
    sf->rt_sf.use_rtc_tf = 0;
1896
1897
  // This speed feature is causing artifacts with active_maps enabled, so
1898
  // disable for now.
1899
0
  if (cpi->active_map.enabled)
1900
0
    sf->rt_sf.set_zeromv_skip_based_on_source_sad = 0;
1901
1902
0
  if (is_one_pass_rt_lag_params(cpi)) {
1903
0
    const RefreshFrameInfo *const refresh_frame = &cpi->refresh_frame;
1904
0
    if (refresh_frame->alt_ref_frame) {
1905
0
      sf->rt_sf.source_metrics_sb_nonrd = 0;
1906
0
      sf->rt_sf.var_part_based_on_qidx = 0;
1907
0
    }
1908
0
    sf->rt_sf.use_nonrd_altref_frame = 1;
1909
    // For non-zero lag: disable the 3 speed features below for now,
1910
    // until further testing.
1911
0
    sf->rt_sf.use_rtc_tf = 0;
1912
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 0;
1913
0
    sf->rt_sf.nonrd_check_partition_split = 0;
1914
    // These (nonrd) speed features that force zeromv-LAST early in partition
1915
    // are disabled since for src_frame_alt_ref frame the zeromv-ALTREF_FRAME
1916
    // mode is forced in the nonrd_pickmode.
1917
0
    if (cpi->rc.is_src_frame_alt_ref) {
1918
0
      sf->rt_sf.increase_source_sad_thresh = 0;
1919
0
      sf->rt_sf.part_early_exit_zeromv = 0;
1920
0
    }
1921
    // This feature is for CBR mode, turning if off means the gop interval
1922
    // will not be changed after encoding.
1923
0
    sf->rt_sf.gf_refresh_based_on_qp = 0;
1924
0
  }
1925
0
}
1926
1927
static void set_rt_speed_features_framesize_independent(AV1_COMP *cpi,
1928
                                                        SPEED_FEATURES *sf,
1929
0
                                                        int speed) {
1930
0
  AV1_COMMON *const cm = &cpi->common;
1931
0
  const int boosted = frame_is_boosted(cpi);
1932
1933
  // Currently, rt speed 0, 1, 2, 3, 4, 5 are the same.
1934
  // Following set of speed features are not impacting encoder's decisions as
1935
  // the relevant tools are disabled by default.
1936
0
  sf->gm_sf.gm_search_type = GM_DISABLE_SEARCH;
1937
0
  sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
1938
0
  sf->inter_sf.reuse_inter_intra_mode = 1;
1939
0
  sf->inter_sf.prune_compound_using_single_ref = 0;
1940
0
  sf->inter_sf.prune_comp_search_by_single_result = 2;
1941
0
  sf->inter_sf.prune_comp_type_by_comp_avg = 2;
1942
0
  sf->inter_sf.fast_wedge_sign_estimate = 1;
1943
0
  sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
1944
0
  sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1945
0
  sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
1946
0
  sf->interp_sf.cb_pred_filter_search = 0;
1947
0
  sf->interp_sf.skip_interp_filter_search = 1;
1948
0
  sf->part_sf.ml_prune_partition = 1;
1949
0
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
1950
0
  sf->part_sf.prune_ext_partition_types_search_level = 2;
1951
0
  sf->part_sf.less_rectangular_check_level = 2;
1952
0
  sf->mv_sf.obmc_full_pixel_search_level = 1;
1953
0
  sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
1954
0
  sf->tx_sf.model_based_prune_tx_search_level = 0;
1955
0
  sf->lpf_sf.dual_sgr_penalty_level = 1;
1956
  // Disable Wiener and Self-guided Loop restoration filters.
1957
0
  sf->lpf_sf.disable_wiener_filter = true;
1958
0
  sf->lpf_sf.disable_sgr_filter = true;
1959
0
  sf->intra_sf.prune_palette_search_level = 2;
1960
0
  sf->intra_sf.prune_luma_palette_size_search_level = 2;
1961
0
  sf->intra_sf.early_term_chroma_palette_size_search = 1;
1962
1963
  // End of set
1964
1965
  // TODO(any, yunqing): tune these features for real-time use cases.
1966
0
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_SOLO;
1967
0
  sf->hl_sf.frame_parameter_update = 0;
1968
1969
0
  sf->inter_sf.model_based_post_interp_filter_breakout = 1;
1970
  // TODO(any): As per the experiments, this speed feature is doing redundant
1971
  // computation since the model rd based pruning logic is similar to model rd
1972
  // based gating when inter_mode_rd_model_estimation = 2. Enable this SF if
1973
  // either of the condition becomes true.
1974
  //    (1) inter_mode_rd_model_estimation != 2
1975
  //    (2) skip_interp_filter_search == 0
1976
  //    (3) Motion mode or compound mode is enabled */
1977
0
  sf->inter_sf.prune_mode_search_simple_translation = 0;
1978
0
  sf->inter_sf.prune_ref_frame_for_rect_partitions = !boosted;
1979
0
  sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1980
0
  sf->inter_sf.selective_ref_frame = 4;
1981
0
  sf->inter_sf.alt_ref_search_fp = 2;
1982
0
  set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level, boosted ? 0 : 4);
1983
0
  sf->inter_sf.limit_txfm_eval_per_mode = 3;
1984
1985
0
  sf->inter_sf.adaptive_rd_thresh = 4;
1986
0
  sf->inter_sf.inter_mode_rd_model_estimation = 2;
1987
0
  sf->inter_sf.prune_inter_modes_if_skippable = 1;
1988
0
  sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
1989
0
  sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
1990
0
  sf->inter_sf.skip_newmv_in_drl = 4;
1991
1992
0
  sf->interp_sf.use_fast_interpolation_filter_search = 1;
1993
0
  sf->interp_sf.use_interp_filter = 1;
1994
0
  sf->interp_sf.adaptive_interp_filter_search = 1;
1995
0
  sf->interp_sf.disable_dual_filter = 1;
1996
1997
0
  sf->part_sf.default_max_partition_size = BLOCK_128X128;
1998
0
  sf->part_sf.default_min_partition_size = BLOCK_8X8;
1999
0
  sf->part_sf.use_best_rd_for_pruning = 1;
2000
0
  sf->part_sf.early_term_after_none_split = 1;
2001
0
  sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
2002
0
  sf->part_sf.max_intra_bsize = BLOCK_16X16;
2003
0
  sf->part_sf.partition_search_breakout_rate_thr = 500;
2004
0
  sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
2005
0
  sf->part_sf.adjust_var_based_rd_partitioning = 2;
2006
2007
0
  sf->mv_sf.full_pixel_search_level = 1;
2008
0
  sf->mv_sf.exhaustive_searches_thresh = INT_MAX;
2009
0
  sf->mv_sf.auto_mv_step_size = 1;
2010
0
  sf->mv_sf.subpel_iters_per_step = 1;
2011
0
  sf->mv_sf.use_accurate_subpel_search = USE_2_TAPS;
2012
0
  sf->mv_sf.search_method = FAST_DIAMOND;
2013
0
  sf->mv_sf.subpel_force_stop = EIGHTH_PEL;
2014
0
  sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
2015
2016
0
  for (int i = 0; i < TX_SIZES; ++i) {
2017
0
    sf->intra_sf.intra_y_mode_mask[i] = INTRA_DC;
2018
0
    sf->intra_sf.intra_uv_mode_mask[i] = UV_INTRA_DC_CFL;
2019
0
  }
2020
0
  sf->intra_sf.skip_intra_in_interframe = 5;
2021
0
  sf->intra_sf.disable_smooth_intra = 1;
2022
0
  sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
2023
2024
0
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
2025
0
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
2026
0
  sf->tx_sf.adaptive_txb_search_level = 2;
2027
0
  sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
2028
0
  sf->tx_sf.tx_size_search_lgr_block = 1;
2029
0
  sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
2030
0
  sf->tx_sf.tx_type_search.skip_tx_search = 1;
2031
0
  sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
2032
0
  sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
2033
0
  sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
2034
0
  sf->tx_sf.refine_fast_tx_search_results = 0;
2035
0
  sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 2;
2036
0
  sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
2037
0
  sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
2038
0
  sf->tx_sf.use_chroma_trellis_rd_mult = 1;
2039
2040
0
  sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
2041
0
  sf->rd_sf.simple_model_rd_from_var = 1;
2042
0
  sf->rd_sf.tx_domain_dist_level = 2;
2043
0
  sf->rd_sf.tx_domain_dist_thres_level = 2;
2044
2045
0
  sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
2046
0
  sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
2047
2048
0
  sf->winner_mode_sf.dc_blk_pred_level = frame_is_intra_only(cm) ? 0 : 3;
2049
0
  sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
2050
0
  sf->winner_mode_sf.tx_size_search_level = 1;
2051
0
  sf->winner_mode_sf.winner_mode_ifs = 1;
2052
2053
0
  sf->rt_sf.check_intra_pred_nonrd = 1;
2054
0
  sf->rt_sf.estimate_motion_for_var_based_partition = 2;
2055
0
  sf->rt_sf.hybrid_intra_pickmode = 1;
2056
0
  sf->rt_sf.use_comp_ref_nonrd = 0;
2057
0
  sf->rt_sf.ref_frame_comp_nonrd[0] = 0;
2058
0
  sf->rt_sf.ref_frame_comp_nonrd[1] = 0;
2059
0
  sf->rt_sf.ref_frame_comp_nonrd[2] = 0;
2060
0
  sf->rt_sf.use_nonrd_filter_search = 1;
2061
0
  sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
2062
0
  sf->rt_sf.num_inter_modes_for_tx_search = 5;
2063
0
  sf->rt_sf.prune_inter_modes_using_temp_var = 1;
2064
0
  sf->rt_sf.use_real_time_ref_set = is_one_pass_rt_lag_params(cpi) ? 0 : 1;
2065
0
  sf->rt_sf.use_simple_rd_model = 1;
2066
0
  sf->rt_sf.prune_inter_modes_with_golden_ref = boosted ? 0 : 1;
2067
  // TODO(any): This sf could be removed.
2068
0
  sf->rt_sf.short_circuit_low_temp_var = 1;
2069
0
  sf->rt_sf.check_scene_detection = 1;
2070
0
  if (cpi->rc.rtc_external_ratectrl) sf->rt_sf.check_scene_detection = 0;
2071
0
  if (cm->current_frame.frame_type != KEY_FRAME &&
2072
0
      cpi->oxcf.rc_cfg.mode == AOM_CBR)
2073
0
    sf->rt_sf.overshoot_detection_cbr = FAST_DETECTION_MAXQ;
2074
  // Enable noise estimation only for high resolutions for now.
2075
  //
2076
  // Since use_temporal_noise_estimate has no effect for all-intra frame
2077
  // encoding, it is disabled for this case.
2078
0
  if (cpi->oxcf.kf_cfg.key_freq_max != 0 && cm->width * cm->height > 640 * 480)
2079
0
    sf->rt_sf.use_temporal_noise_estimate = 1;
2080
0
  sf->rt_sf.skip_tx_no_split_var_based_partition = 1;
2081
0
  sf->rt_sf.skip_newmv_mode_based_on_sse = 1;
2082
0
  sf->rt_sf.mode_search_skip_flags =
2083
0
      (cm->current_frame.frame_type == KEY_FRAME)
2084
0
          ? 0
2085
0
          : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
2086
0
                FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR |
2087
0
                FLAG_EARLY_TERMINATE;
2088
0
  sf->rt_sf.var_part_split_threshold_shift = 5;
2089
0
  if (!frame_is_intra_only(&cpi->common)) sf->rt_sf.var_part_based_on_qidx = 1;
2090
0
  sf->rt_sf.use_fast_fixed_part = 0;
2091
0
  sf->rt_sf.increase_source_sad_thresh = 0;
2092
2093
0
  if (is_one_pass_rt_lag_params(cpi) && speed <= 6) {
2094
0
    sf->hl_sf.frame_parameter_update = 1;
2095
0
    sf->inter_sf.use_dist_wtd_comp_flag = 0;
2096
0
    sf->inter_sf.disable_masked_comp = 1;
2097
0
    sf->inter_sf.disable_onesided_comp = 1;
2098
0
  }
2099
2100
0
  if (speed >= 6) {
2101
0
    sf->mv_sf.use_fullpel_costlist = 1;
2102
2103
0
    sf->rd_sf.tx_domain_dist_thres_level = 3;
2104
2105
0
    sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh = 0;
2106
0
    sf->inter_sf.limit_inter_mode_cands = 4;
2107
0
    sf->inter_sf.prune_warped_prob_thresh = 8;
2108
0
    sf->inter_sf.extra_prune_warped = 1;
2109
2110
0
    sf->rt_sf.gf_refresh_based_on_qp = 1;
2111
0
    sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
2112
0
    sf->rt_sf.var_part_split_threshold_shift = 7;
2113
0
    if (!frame_is_intra_only(&cpi->common))
2114
0
      sf->rt_sf.var_part_based_on_qidx = 2;
2115
2116
0
    sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 3;
2117
0
  }
2118
2119
0
  if (speed >= 7) {
2120
0
    sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_1;
2121
0
    sf->rt_sf.use_comp_ref_nonrd = 1;
2122
0
    sf->rt_sf.ref_frame_comp_nonrd[2] = 1;  // LAST_ALTREF
2123
0
    sf->tx_sf.intra_tx_size_search_init_depth_sqr = 2;
2124
0
    sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
2125
0
    sf->part_sf.max_intra_bsize = BLOCK_32X32;
2126
2127
0
    sf->mv_sf.search_method = FAST_DIAMOND;
2128
0
    sf->mv_sf.subpel_force_stop = QUARTER_PEL;
2129
2130
0
    sf->inter_sf.inter_mode_rd_model_estimation = 2;
2131
    // This sf is not applicable in non-rd path.
2132
0
    sf->inter_sf.skip_newmv_in_drl = 0;
2133
2134
0
    sf->interp_sf.skip_interp_filter_search = 0;
2135
2136
    // Disable intra_y_mode_mask pruning since the performance at speed 7 isn't
2137
    // good. May need more study.
2138
0
    for (int i = 0; i < TX_SIZES; ++i) {
2139
0
      sf->intra_sf.intra_y_mode_mask[i] = INTRA_ALL;
2140
0
    }
2141
2142
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
2143
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL5;
2144
2145
0
    sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
2146
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 1;
2147
    // This is for rd path only.
2148
0
    sf->rt_sf.prune_inter_modes_using_temp_var = 0;
2149
0
    sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
2150
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 0;
2151
0
#if !CONFIG_REALTIME_ONLY
2152
0
    sf->rt_sf.reuse_inter_pred_nonrd =
2153
0
        (cpi->oxcf.motion_mode_cfg.enable_warped_motion == 0);
2154
#else
2155
    sf->rt_sf.reuse_inter_pred_nonrd = 1;
2156
#endif
2157
#if CONFIG_AV1_TEMPORAL_DENOISING
2158
    sf->rt_sf.reuse_inter_pred_nonrd = (cpi->oxcf.noise_sensitivity == 0);
2159
#endif
2160
0
    sf->rt_sf.short_circuit_low_temp_var = 0;
2161
    // For spatial layers, only LAST and GOLDEN are currently used in the SVC
2162
    // for nonrd. The flag use_nonrd_altref_frame can disable GOLDEN in the
2163
    // get_ref_frame_flags() for some patterns, so disable it here for
2164
    // spatial layers.
2165
0
    sf->rt_sf.use_nonrd_altref_frame =
2166
0
        (cpi->svc.number_spatial_layers > 1) ? 0 : 1;
2167
0
    sf->rt_sf.use_nonrd_pick_mode = 1;
2168
0
    sf->rt_sf.discount_color_cost = 1;
2169
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 3;
2170
0
    sf->rt_sf.skip_intra_pred = 1;
2171
0
    sf->rt_sf.source_metrics_sb_nonrd = 1;
2172
    // Set mask for intra modes.
2173
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
2174
0
      if (i >= BLOCK_32X32)
2175
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
2176
0
      else
2177
        // Use DC, H, V intra mode for block sizes < 32X32.
2178
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
2179
2180
0
    sf->winner_mode_sf.dc_blk_pred_level = 0;
2181
0
    sf->rt_sf.var_part_based_on_qidx = 3;
2182
0
    sf->rt_sf.prune_compoundmode_with_singlecompound_var = true;
2183
0
    sf->rt_sf.prune_compoundmode_with_singlemode_var = true;
2184
0
    sf->rt_sf.skip_compound_based_on_var = true;
2185
0
    sf->rt_sf.use_adaptive_subpel_search = true;
2186
0
  }
2187
2188
0
  if (speed >= 8) {
2189
0
    sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_2;
2190
0
    sf->intra_sf.intra_pruning_with_hog = 1;
2191
0
    sf->rt_sf.short_circuit_low_temp_var = 1;
2192
0
    sf->rt_sf.use_nonrd_altref_frame = 0;
2193
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 2;
2194
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 0;
2195
0
    sf->rt_sf.var_part_split_threshold_shift = 8;
2196
0
    sf->rt_sf.var_part_based_on_qidx = 4;
2197
0
    sf->rt_sf.partition_direct_merging = 1;
2198
0
    sf->rt_sf.prune_compoundmode_with_singlemode_var = false;
2199
0
    sf->mv_sf.use_bsize_dependent_search_method = 4;
2200
0
    sf->rt_sf.prune_hv_pred_modes_using_src_sad = true;
2201
0
  }
2202
0
  if (speed >= 9) {
2203
0
    sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_3;
2204
0
    sf->rt_sf.estimate_motion_for_var_based_partition = 3;
2205
0
    sf->rt_sf.prefer_large_partition_blocks = 3;
2206
0
    sf->rt_sf.skip_intra_pred = 2;
2207
0
    sf->rt_sf.var_part_split_threshold_shift = 9;
2208
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
2209
0
      sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
2210
0
    sf->rt_sf.var_part_based_on_qidx = 0;
2211
0
    sf->rt_sf.frame_level_mode_cost_update = true;
2212
0
    sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
2213
0
    sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
2214
0
    sf->rt_sf.use_adaptive_subpel_search = true;
2215
0
    sf->mv_sf.use_bsize_dependent_search_method = 0;
2216
0
  }
2217
0
  if (speed >= 10) {
2218
0
    sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_4;
2219
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 3;
2220
0
    sf->rt_sf.var_part_split_threshold_shift = 10;
2221
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
2222
0
  }
2223
0
  if (speed >= 11 && !frame_is_intra_only(cm) &&
2224
0
      cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN) {
2225
0
    sf->winner_mode_sf.dc_blk_pred_level = 3;
2226
0
  }
2227
2228
0
  if (cpi->oxcf.tune_cfg.tuning == AOM_TUNE_IQ ||
2229
0
      cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIMULACRA2) {
2230
0
    sf->intra_sf.skip_intra_in_interframe = 0;
2231
0
  }
2232
0
}
2233
2234
0
static inline void init_hl_sf(HIGH_LEVEL_SPEED_FEATURES *hl_sf) {
2235
  // best quality defaults
2236
0
  hl_sf->frame_parameter_update = 1;
2237
0
  hl_sf->recode_loop = ALLOW_RECODE;
2238
  // Recode loop tolerance %.
2239
0
  hl_sf->recode_tolerance = 25;
2240
0
  hl_sf->high_precision_mv_usage = CURRENT_Q;
2241
0
  hl_sf->superres_auto_search_type = SUPERRES_AUTO_ALL;
2242
0
  hl_sf->disable_extra_sc_testing = 0;
2243
0
  hl_sf->second_alt_ref_filtering = 1;
2244
0
  hl_sf->adjust_num_frames_for_arf_filtering = 0;
2245
0
  hl_sf->accurate_bit_estimate = 0;
2246
0
  hl_sf->weight_calc_level_in_tf = 0;
2247
0
  hl_sf->allow_sub_blk_me_in_tf = 0;
2248
0
  hl_sf->ref_frame_mvs_lvl = 0;
2249
0
  hl_sf->screen_detection_mode2_fast_detection = 0;
2250
0
}
2251
2252
0
static inline void init_fp_sf(FIRST_PASS_SPEED_FEATURES *fp_sf) {
2253
0
  fp_sf->reduce_mv_step_param = 3;
2254
0
  fp_sf->skip_motion_search_threshold = 0;
2255
0
  fp_sf->disable_recon = 0;
2256
0
  fp_sf->skip_zeromv_motion_search = 0;
2257
0
}
2258
2259
0
static inline void init_tpl_sf(TPL_SPEED_FEATURES *tpl_sf) {
2260
0
  tpl_sf->gop_length_decision_method = 1;
2261
0
  tpl_sf->prune_intra_modes = 0;
2262
0
  tpl_sf->prune_starting_mv = 0;
2263
0
  tpl_sf->reduce_first_step_size = 0;
2264
0
  tpl_sf->skip_alike_starting_mv = 0;
2265
0
  tpl_sf->subpel_force_stop = EIGHTH_PEL;
2266
0
  tpl_sf->search_method = NSTEP;
2267
0
  tpl_sf->prune_ref_frames_in_tpl = 0;
2268
0
  tpl_sf->allow_compound_pred = 1;
2269
0
  tpl_sf->use_y_only_rate_distortion = 0;
2270
0
  tpl_sf->use_sad_for_mode_decision = 0;
2271
0
  tpl_sf->reduce_num_frames = 0;
2272
0
}
2273
2274
0
static inline void init_gm_sf(GLOBAL_MOTION_SPEED_FEATURES *gm_sf) {
2275
0
  gm_sf->gm_search_type = GM_FULL_SEARCH;
2276
0
  gm_sf->prune_ref_frame_for_gm_search = 0;
2277
0
  gm_sf->prune_zero_mv_with_sse = 0;
2278
0
  gm_sf->disable_gm_search_based_on_stats = 0;
2279
0
  gm_sf->downsample_level = 0;
2280
0
  gm_sf->num_refinement_steps = GM_MAX_REFINEMENT_STEPS;
2281
0
  gm_sf->gm_erroradv_tr_level = 0;
2282
0
}
2283
2284
0
static inline void init_part_sf(PARTITION_SPEED_FEATURES *part_sf) {
2285
0
  part_sf->partition_search_type = SEARCH_PARTITION;
2286
0
  part_sf->less_rectangular_check_level = 0;
2287
0
  part_sf->use_square_partition_only_threshold = BLOCK_128X128;
2288
0
  part_sf->auto_max_partition_based_on_simple_motion = NOT_IN_USE;
2289
0
  part_sf->default_max_partition_size = BLOCK_LARGEST;
2290
0
  part_sf->default_min_partition_size = BLOCK_4X4;
2291
0
  part_sf->adjust_var_based_rd_partitioning = 0;
2292
0
  part_sf->max_intra_bsize = BLOCK_LARGEST;
2293
  // This setting only takes effect when partition_search_type is set
2294
  // to FIXED_PARTITION.
2295
0
  part_sf->fixed_partition_size = BLOCK_16X16;
2296
  // Recode loop tolerance %.
2297
0
  part_sf->partition_search_breakout_dist_thr = 0;
2298
0
  part_sf->partition_search_breakout_rate_thr = 0;
2299
0
  part_sf->prune_ext_partition_types_search_level = 0;
2300
0
  part_sf->prune_part4_search = 0;
2301
0
  part_sf->ml_prune_partition = 0;
2302
0
  part_sf->ml_early_term_after_part_split_level = 0;
2303
0
  for (int i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
2304
0
    part_sf->ml_partition_search_breakout_thresh[i] =
2305
0
        -1;  // -1 means not enabled.
2306
0
  }
2307
0
  part_sf->ml_partition_search_breakout_model_index = 0;
2308
0
  part_sf->ml_4_partition_search_level_index = 0;
2309
0
  part_sf->simple_motion_search_prune_agg = SIMPLE_AGG_LVL0;
2310
0
  part_sf->simple_motion_search_split = 0;
2311
0
  part_sf->simple_motion_search_prune_rect = 0;
2312
0
  part_sf->simple_motion_search_early_term_none = 0;
2313
0
  part_sf->simple_motion_search_reduce_search_steps = 0;
2314
0
  part_sf->intra_cnn_based_part_prune_level = 0;
2315
0
  part_sf->ext_partition_eval_thresh = BLOCK_8X8;
2316
0
  part_sf->rect_partition_eval_thresh = BLOCK_128X128;
2317
0
  part_sf->ext_part_eval_based_on_cur_best = 0;
2318
0
  part_sf->prune_ext_part_using_split_info = 0;
2319
0
  part_sf->prune_rectangular_split_based_on_qidx = 0;
2320
0
  part_sf->prune_rect_part_using_4x4_var_deviation = false;
2321
0
  part_sf->prune_rect_part_using_none_pred_mode = false;
2322
0
  part_sf->early_term_after_none_split = 0;
2323
0
  part_sf->ml_predict_breakout_level = 0;
2324
0
  part_sf->prune_sub_8x8_partition_level = 0;
2325
0
  part_sf->simple_motion_search_rect_split = 0;
2326
0
  part_sf->reuse_prev_rd_results_for_part_ab = 0;
2327
0
  part_sf->reuse_best_prediction_for_part_ab = 0;
2328
0
  part_sf->use_best_rd_for_pruning = 0;
2329
0
  part_sf->skip_non_sq_part_based_on_none = 0;
2330
0
  part_sf->disable_8x8_part_based_on_qidx = 0;
2331
0
  part_sf->split_partition_penalty_level = 0;
2332
0
  part_sf->prune_h_or_v_4part_using_sms_info = false;
2333
0
}
2334
2335
0
static inline void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
2336
0
  mv_sf->full_pixel_search_level = 0;
2337
0
  mv_sf->auto_mv_step_size = 0;
2338
0
  mv_sf->exhaustive_searches_thresh = 0;
2339
0
  mv_sf->obmc_full_pixel_search_level = 0;
2340
0
  mv_sf->prune_mesh_search = PRUNE_MESH_SEARCH_DISABLED;
2341
0
  mv_sf->reduce_search_range = 0;
2342
0
  mv_sf->search_method = NSTEP;
2343
0
  mv_sf->simple_motion_subpel_force_stop = EIGHTH_PEL;
2344
0
  mv_sf->subpel_force_stop = EIGHTH_PEL;
2345
0
  mv_sf->subpel_iters_per_step = 2;
2346
0
  mv_sf->subpel_search_method = SUBPEL_TREE;
2347
0
  mv_sf->use_accurate_subpel_search = USE_8_TAPS;
2348
0
  mv_sf->use_bsize_dependent_search_method = 0;
2349
0
  mv_sf->use_fullpel_costlist = 0;
2350
0
  mv_sf->use_downsampled_sad = 0;
2351
0
  mv_sf->disable_extensive_joint_motion_search = 0;
2352
0
  mv_sf->disable_second_mv = 0;
2353
0
  mv_sf->skip_fullpel_search_using_startmv_refmv = 0;
2354
0
  mv_sf->warp_search_method = WARP_SEARCH_SQUARE;
2355
0
  mv_sf->warp_search_iters = 8;
2356
0
  mv_sf->use_intrabc = 1;
2357
0
  mv_sf->prune_intrabc_candidate_block_hash_search = 0;
2358
0
  mv_sf->intrabc_search_level = 0;
2359
0
  mv_sf->hash_max_8x8_intrabc_blocks = 0;
2360
0
}
2361
2362
0
static inline void init_inter_sf(INTER_MODE_SPEED_FEATURES *inter_sf) {
2363
0
  inter_sf->adaptive_rd_thresh = 0;
2364
0
  inter_sf->model_based_post_interp_filter_breakout = 0;
2365
0
  inter_sf->reduce_inter_modes = 0;
2366
0
  inter_sf->alt_ref_search_fp = 0;
2367
0
  inter_sf->prune_single_ref = 0;
2368
0
  inter_sf->prune_comp_ref_frames = 0;
2369
0
  inter_sf->selective_ref_frame = 0;
2370
0
  inter_sf->prune_ref_frame_for_rect_partitions = 0;
2371
0
  inter_sf->fast_wedge_sign_estimate = 0;
2372
0
  inter_sf->use_dist_wtd_comp_flag = DIST_WTD_COMP_ENABLED;
2373
0
  inter_sf->reuse_inter_intra_mode = 0;
2374
0
  inter_sf->mv_cost_upd_level = INTERNAL_COST_UPD_SB;
2375
0
  inter_sf->coeff_cost_upd_level = INTERNAL_COST_UPD_SB;
2376
0
  inter_sf->mode_cost_upd_level = INTERNAL_COST_UPD_SB;
2377
0
  inter_sf->prune_inter_modes_based_on_tpl = 0;
2378
0
  inter_sf->prune_nearmv_using_neighbors = PRUNE_NEARMV_OFF;
2379
0
  inter_sf->prune_comp_search_by_single_result = 0;
2380
0
  inter_sf->skip_repeated_ref_mv = 0;
2381
0
  inter_sf->skip_newmv_in_drl = 0;
2382
0
  inter_sf->inter_mode_rd_model_estimation = 0;
2383
0
  inter_sf->prune_compound_using_single_ref = 0;
2384
0
  inter_sf->prune_ext_comp_using_neighbors = 0;
2385
0
  inter_sf->skip_ext_comp_nearmv_mode = 0;
2386
0
  inter_sf->prune_comp_using_best_single_mode_ref = 0;
2387
0
  inter_sf->prune_nearest_near_mv_using_refmv_weight = 0;
2388
0
  inter_sf->disable_onesided_comp = 0;
2389
0
  inter_sf->prune_mode_search_simple_translation = 0;
2390
0
  inter_sf->prune_comp_type_by_comp_avg = 0;
2391
0
  inter_sf->disable_interinter_wedge_newmv_search = 0;
2392
0
  inter_sf->fast_interintra_wedge_search = 0;
2393
0
  inter_sf->prune_comp_type_by_model_rd = 0;
2394
0
  inter_sf->perform_best_rd_based_gating_for_chroma = 0;
2395
0
  inter_sf->prune_obmc_prob_thresh = 0;
2396
0
  inter_sf->disable_interinter_wedge_var_thresh = 0;
2397
0
  inter_sf->disable_interintra_wedge_var_thresh = 0;
2398
0
  inter_sf->prune_ref_mv_idx_search = 0;
2399
0
  inter_sf->prune_warped_prob_thresh = 0;
2400
0
  inter_sf->reuse_compound_type_decision = 0;
2401
0
  inter_sf->prune_inter_modes_if_skippable = 0;
2402
0
  inter_sf->disable_masked_comp = 0;
2403
0
  inter_sf->enable_fast_compound_mode_search = 0;
2404
0
  inter_sf->reuse_mask_search_results = 0;
2405
0
  inter_sf->enable_fast_wedge_mask_search = 0;
2406
0
  inter_sf->inter_mode_txfm_breakout = 0;
2407
0
  inter_sf->limit_inter_mode_cands = 0;
2408
0
  inter_sf->limit_txfm_eval_per_mode = 0;
2409
0
  inter_sf->skip_arf_compound = 0;
2410
0
  inter_sf->bias_warp_mode_rd_scale_pct = 0;
2411
0
  inter_sf->bias_obmc_mode_rd_scale_pct = 0.0f;
2412
0
  inter_sf->skip_cmp_using_top_cmp_avg_est_rd_lvl = 0;
2413
0
  inter_sf->skip_interinter_wedge_search_based_on_mse = 0;
2414
0
  set_txfm_rd_gate_level(inter_sf->txfm_rd_gate_level, 0);
2415
0
}
2416
2417
0
static inline void init_interp_sf(INTERP_FILTER_SPEED_FEATURES *interp_sf) {
2418
0
  interp_sf->adaptive_interp_filter_search = 0;
2419
0
  interp_sf->cb_pred_filter_search = 0;
2420
0
  interp_sf->disable_dual_filter = 0;
2421
0
  interp_sf->skip_sharp_interp_filter_search = 0;
2422
0
  interp_sf->use_fast_interpolation_filter_search = 0;
2423
0
  interp_sf->use_interp_filter = 0;
2424
0
  interp_sf->skip_interp_filter_search = 0;
2425
0
  interp_sf->use_more_sharp_interp = 0;
2426
0
  interp_sf->skip_model_rd_uv = 0;
2427
0
}
2428
2429
0
static inline void init_intra_sf(INTRA_MODE_SPEED_FEATURES *intra_sf) {
2430
0
  intra_sf->dv_cost_upd_level = INTERNAL_COST_UPD_SB;
2431
0
  intra_sf->skip_intra_in_interframe = 1;
2432
0
  intra_sf->intra_pruning_with_hog = 0;
2433
0
  intra_sf->chroma_intra_pruning_with_hog = 0;
2434
0
  intra_sf->prune_palette_search_level = 0;
2435
0
  intra_sf->prune_luma_palette_size_search_level = 0;
2436
2437
0
  for (int i = 0; i < TX_SIZES; i++) {
2438
0
    intra_sf->intra_y_mode_mask[i] = INTRA_ALL;
2439
0
    intra_sf->intra_uv_mode_mask[i] = UV_INTRA_ALL;
2440
0
  }
2441
0
  intra_sf->disable_smooth_intra = 0;
2442
0
  intra_sf->prune_smooth_intra_mode_for_chroma = 0;
2443
0
  intra_sf->prune_filter_intra_level = 0;
2444
0
  intra_sf->prune_chroma_modes_using_luma_winner = 0;
2445
0
  intra_sf->cfl_search_range = 3;
2446
0
  intra_sf->top_intra_model_count_allowed = TOP_INTRA_MODEL_COUNT;
2447
0
  intra_sf->adapt_top_model_rd_count_using_neighbors = 0;
2448
0
  intra_sf->early_term_chroma_palette_size_search = 0;
2449
0
  intra_sf->skip_filter_intra_in_inter_frames = 0;
2450
0
  intra_sf->prune_luma_odd_delta_angles_in_intra = 0;
2451
0
}
2452
2453
0
static inline void init_tx_sf(TX_SPEED_FEATURES *tx_sf) {
2454
0
  tx_sf->inter_tx_size_search_init_depth_sqr = 0;
2455
0
  tx_sf->inter_tx_size_search_init_depth_rect = 0;
2456
0
  tx_sf->intra_tx_size_search_init_depth_rect = 0;
2457
0
  tx_sf->intra_tx_size_search_init_depth_sqr = 0;
2458
0
  tx_sf->tx_size_search_lgr_block = 0;
2459
0
  tx_sf->model_based_prune_tx_search_level = 0;
2460
0
  tx_sf->tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_1;
2461
0
  tx_sf->tx_type_search.ml_tx_split_thresh = 8500;
2462
0
  tx_sf->tx_type_search.use_skip_flag_prediction = 1;
2463
0
  tx_sf->tx_type_search.use_reduced_intra_txset = 0;
2464
0
  tx_sf->tx_type_search.fast_intra_tx_type_search = 0;
2465
0
  tx_sf->tx_type_search.fast_inter_tx_type_prob_thresh = INT_MAX;
2466
0
  tx_sf->tx_type_search.skip_tx_search = 0;
2467
0
  tx_sf->tx_type_search.prune_tx_type_using_stats = 0;
2468
0
  tx_sf->tx_type_search.prune_tx_type_est_rd = 0;
2469
0
  tx_sf->tx_type_search.winner_mode_tx_type_pruning = 0;
2470
0
  tx_sf->txb_split_cap = 1;
2471
0
  tx_sf->adaptive_txb_search_level = 0;
2472
0
  tx_sf->refine_fast_tx_search_results = 1;
2473
0
  tx_sf->prune_tx_size_level = 0;
2474
0
  tx_sf->prune_intra_tx_depths_using_nn = false;
2475
0
  tx_sf->use_rd_based_breakout_for_intra_tx_search = false;
2476
0
  tx_sf->prune_inter_tx_split_rd_eval_lvl = 0;
2477
0
  tx_sf->use_chroma_trellis_rd_mult = 0;
2478
0
}
2479
2480
static inline void init_rd_sf(RD_CALC_SPEED_FEATURES *rd_sf,
2481
0
                              const AV1EncoderConfig *oxcf) {
2482
0
  const int disable_trellis_quant = oxcf->algo_cfg.disable_trellis_quant;
2483
0
  if (disable_trellis_quant == 3) {
2484
0
    rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
2485
0
                                       ? NO_ESTIMATE_YRD_TRELLIS_OPT
2486
0
                                       : NO_TRELLIS_OPT;
2487
0
  } else if (disable_trellis_quant == 2) {
2488
0
    rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
2489
0
                                       ? FINAL_PASS_TRELLIS_OPT
2490
0
                                       : NO_TRELLIS_OPT;
2491
0
  } else if (disable_trellis_quant == 0) {
2492
0
    if (is_lossless_requested(&oxcf->rc_cfg)) {
2493
0
      rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
2494
0
    } else {
2495
0
      rd_sf->optimize_coefficients = FULL_TRELLIS_OPT;
2496
0
    }
2497
0
  } else if (disable_trellis_quant == 1) {
2498
0
    rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
2499
0
  } else {
2500
0
    assert(0 && "Invalid disable_trellis_quant value");
2501
0
  }
2502
0
  rd_sf->use_mb_rd_hash = 0;
2503
0
  rd_sf->simple_model_rd_from_var = 0;
2504
0
  rd_sf->tx_domain_dist_level = 0;
2505
0
  rd_sf->tx_domain_dist_thres_level = 0;
2506
0
  rd_sf->perform_coeff_opt = 0;
2507
0
}
2508
2509
static inline void init_winner_mode_sf(
2510
0
    WINNER_MODE_SPEED_FEATURES *winner_mode_sf) {
2511
0
  winner_mode_sf->motion_mode_for_winner_cand = 0;
2512
  // Set this at the appropriate speed levels
2513
0
  winner_mode_sf->tx_size_search_level = 0;
2514
0
  winner_mode_sf->enable_winner_mode_for_coeff_opt = 0;
2515
0
  winner_mode_sf->enable_winner_mode_for_tx_size_srch = 0;
2516
0
  winner_mode_sf->enable_winner_mode_for_use_tx_domain_dist = 0;
2517
0
  winner_mode_sf->multi_winner_mode_type = 0;
2518
0
  winner_mode_sf->dc_blk_pred_level = 0;
2519
0
  winner_mode_sf->winner_mode_ifs = 0;
2520
0
  winner_mode_sf->prune_winner_mode_eval_level = 0;
2521
0
}
2522
2523
0
static inline void init_lpf_sf(LOOP_FILTER_SPEED_FEATURES *lpf_sf) {
2524
0
  lpf_sf->disable_loop_restoration_chroma = 0;
2525
0
  lpf_sf->disable_loop_restoration_luma = 0;
2526
0
  lpf_sf->min_lr_unit_size = RESTORATION_PROC_UNIT_SIZE;
2527
0
  lpf_sf->max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2528
0
  lpf_sf->prune_wiener_based_on_src_var = 0;
2529
0
  lpf_sf->prune_sgr_based_on_wiener = 0;
2530
0
  lpf_sf->enable_sgr_ep_pruning = 0;
2531
0
  lpf_sf->reduce_wiener_window_size = 0;
2532
0
  lpf_sf->adaptive_luma_loop_filter_skip = 0;
2533
0
  lpf_sf->skip_loop_filter_using_filt_error = 0;
2534
0
  lpf_sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
2535
0
  lpf_sf->use_coarse_filter_level_search = 0;
2536
0
  lpf_sf->cdef_pick_method = CDEF_FULL_SEARCH;
2537
0
  lpf_sf->zero_low_cdef_strengths = 0;
2538
  // Set decoder side speed feature to use less dual sgr modes
2539
0
  lpf_sf->dual_sgr_penalty_level = 0;
2540
  // Enable Wiener and Self-guided Loop restoration filters by default.
2541
0
  lpf_sf->disable_wiener_filter = false;
2542
0
  lpf_sf->disable_sgr_filter = false;
2543
0
  lpf_sf->disable_wiener_coeff_refine_search = false;
2544
0
  lpf_sf->use_downsampled_wiener_stats = 0;
2545
0
  lpf_sf->switchable_lr_with_bias_level = 0;
2546
0
  lpf_sf->adaptive_cdef_mode = 0;
2547
0
}
2548
2549
0
static inline void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
2550
0
  rt_sf->check_intra_pred_nonrd = 0;
2551
0
  rt_sf->skip_intra_pred = 0;
2552
0
  rt_sf->estimate_motion_for_var_based_partition = 0;
2553
0
  rt_sf->nonrd_check_partition_merge_mode = 0;
2554
0
  rt_sf->nonrd_check_partition_split = 0;
2555
0
  rt_sf->mode_search_skip_flags = 0;
2556
0
  rt_sf->nonrd_prune_ref_frame_search = 0;
2557
0
  rt_sf->use_nonrd_pick_mode = 0;
2558
0
  rt_sf->discount_color_cost = 0;
2559
0
  rt_sf->use_nonrd_altref_frame = 0;
2560
0
  rt_sf->use_comp_ref_nonrd = 0;
2561
0
  rt_sf->use_real_time_ref_set = 0;
2562
0
  rt_sf->short_circuit_low_temp_var = 0;
2563
0
  rt_sf->reuse_inter_pred_nonrd = 0;
2564
0
  rt_sf->num_inter_modes_for_tx_search = INT_MAX;
2565
0
  rt_sf->use_nonrd_filter_search = 0;
2566
0
  rt_sf->use_simple_rd_model = 0;
2567
0
  rt_sf->hybrid_intra_pickmode = 0;
2568
0
  rt_sf->prune_palette_search_nonrd = 0;
2569
0
  rt_sf->source_metrics_sb_nonrd = 0;
2570
0
  rt_sf->overshoot_detection_cbr = NO_DETECTION;
2571
0
  rt_sf->check_scene_detection = 0;
2572
0
  rt_sf->rc_adjust_keyframe = 0;
2573
0
  rt_sf->rc_compute_spatial_var_sc_kf = 0;
2574
0
  rt_sf->prefer_large_partition_blocks = 0;
2575
0
  rt_sf->use_temporal_noise_estimate = 0;
2576
0
  rt_sf->fullpel_search_step_param = 0;
2577
0
  for (int i = 0; i < BLOCK_SIZES; ++i)
2578
0
    rt_sf->intra_y_mode_bsize_mask_nrd[i] = INTRA_ALL;
2579
0
  rt_sf->prune_hv_pred_modes_using_src_sad = false;
2580
0
  rt_sf->nonrd_aggressive_skip = 0;
2581
0
  rt_sf->skip_cdef_sb = 0;
2582
0
  rt_sf->force_large_partition_blocks_intra = 0;
2583
0
  rt_sf->skip_tx_no_split_var_based_partition = 0;
2584
0
  rt_sf->skip_newmv_mode_based_on_sse = 0;
2585
0
  rt_sf->gf_length_lvl = 0;
2586
0
  rt_sf->prune_inter_modes_with_golden_ref = 0;
2587
0
  rt_sf->prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
2588
0
  rt_sf->prune_inter_modes_using_temp_var = 0;
2589
0
  rt_sf->reduce_mv_pel_precision_highmotion = 0;
2590
0
  rt_sf->reduce_mv_pel_precision_lowcomplex = 0;
2591
0
  rt_sf->prune_intra_mode_based_on_mv_range = 0;
2592
0
  rt_sf->var_part_split_threshold_shift = 7;
2593
0
  rt_sf->gf_refresh_based_on_qp = 0;
2594
0
  rt_sf->use_rtc_tf = 0;
2595
0
  rt_sf->use_idtx_nonrd = 0;
2596
0
  rt_sf->prune_idtx_nonrd = 0;
2597
0
  rt_sf->dct_only_palette_nonrd = 0;
2598
0
  rt_sf->part_early_exit_zeromv = 0;
2599
0
  rt_sf->sse_early_term_inter_search = EARLY_TERM_DISABLED;
2600
0
  rt_sf->skip_lf_screen = 0;
2601
0
  rt_sf->thresh_active_maps_skip_lf_cdef = 100;
2602
0
  rt_sf->sad_based_adp_altref_lag = 0;
2603
0
  rt_sf->partition_direct_merging = 0;
2604
0
  rt_sf->var_part_based_on_qidx = 0;
2605
0
  rt_sf->tx_size_level_based_on_qstep = 0;
2606
0
  rt_sf->vbp_prune_16x16_split_using_min_max_sub_blk_var = false;
2607
0
  rt_sf->prune_compoundmode_with_singlecompound_var = false;
2608
0
  rt_sf->frame_level_mode_cost_update = false;
2609
0
  rt_sf->prune_h_pred_using_best_mode_so_far = false;
2610
0
  rt_sf->enable_intra_mode_pruning_using_neighbors = false;
2611
0
  rt_sf->prune_intra_mode_using_best_sad_so_far = false;
2612
0
  rt_sf->check_only_zero_zeromv_on_large_blocks = false;
2613
0
  rt_sf->disable_cdf_update_non_reference_frame = false;
2614
0
  rt_sf->prune_compoundmode_with_singlemode_var = false;
2615
0
  rt_sf->skip_compound_based_on_var = false;
2616
0
  rt_sf->set_zeromv_skip_based_on_source_sad = 1;
2617
0
  rt_sf->use_adaptive_subpel_search = false;
2618
0
  rt_sf->screen_content_cdef_filter_qindex_thresh = 0;
2619
0
  rt_sf->enable_ref_short_signaling = false;
2620
0
  rt_sf->check_globalmv_on_single_ref = true;
2621
0
  rt_sf->increase_color_thresh_palette = false;
2622
0
  rt_sf->selective_cdf_update = 0;
2623
0
  rt_sf->force_only_last_ref = 0;
2624
0
  rt_sf->higher_thresh_scene_detection = 1;
2625
0
  rt_sf->skip_newmv_flat_blocks_screen = 0;
2626
0
  rt_sf->skip_encoding_non_reference_slide_change = 0;
2627
0
  rt_sf->rc_faster_convergence_static = 0;
2628
0
  rt_sf->skip_newmv_mode_sad_screen = 0;
2629
0
}
2630
2631
static fractional_mv_step_fp
2632
    *const fractional_mv_search[SUBPEL_SEARCH_METHODS] = {
2633
      av1_find_best_sub_pixel_tree,             // SUBPEL_TREE = 0
2634
      av1_find_best_sub_pixel_tree_pruned,      // SUBPEL_TREE_PRUNED = 1
2635
      av1_find_best_sub_pixel_tree_pruned_more  // SUBPEL_TREE_PRUNED_MORE = 2
2636
    };
2637
2638
// Populate appropriate sub-pel search method based on speed feature and user
2639
// specified settings
2640
static void set_subpel_search_method(
2641
    MotionVectorSearchParams *mv_search_params,
2642
    unsigned int motion_vector_unit_test,
2643
0
    SUBPEL_SEARCH_METHOD subpel_search_method) {
2644
0
  assert(subpel_search_method <= SUBPEL_TREE_PRUNED_MORE);
2645
0
  mv_search_params->find_fractional_mv_step =
2646
0
      fractional_mv_search[subpel_search_method];
2647
2648
  // This is only used in motion vector unit test.
2649
0
  if (motion_vector_unit_test == 1)
2650
0
    mv_search_params->find_fractional_mv_step = av1_return_max_sub_pixel_mv;
2651
0
  else if (motion_vector_unit_test == 2)
2652
0
    mv_search_params->find_fractional_mv_step = av1_return_min_sub_pixel_mv;
2653
0
}
2654
2655
0
void av1_set_speed_features_framesize_dependent(AV1_COMP *cpi, int speed) {
2656
0
  SPEED_FEATURES *const sf = &cpi->sf;
2657
0
  const AV1EncoderConfig *const oxcf = &cpi->oxcf;
2658
2659
0
  switch (oxcf->mode) {
2660
0
    case GOOD:
2661
0
      set_good_speed_feature_framesize_dependent(cpi, sf, speed);
2662
0
      break;
2663
0
    case ALLINTRA:
2664
0
      set_allintra_speed_feature_framesize_dependent(cpi, sf, speed);
2665
0
      break;
2666
0
    case REALTIME:
2667
0
      set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
2668
0
      break;
2669
0
  }
2670
2671
0
  if (!cpi->ppi->seq_params_locked) {
2672
0
    cpi->common.seq_params->enable_masked_compound &=
2673
0
        !sf->inter_sf.disable_masked_comp;
2674
0
    cpi->common.seq_params->enable_interintra_compound &=
2675
0
        (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
2676
0
  }
2677
2678
0
  set_subpel_search_method(&cpi->mv_search_params,
2679
0
                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
2680
0
                           sf->mv_sf.subpel_search_method);
2681
2682
  // For multi-thread use case with row_mt enabled, cost update for a set of
2683
  // SB rows is not desirable. Hence, the sf mv_cost_upd_level is set to
2684
  // INTERNAL_COST_UPD_SBROW in such cases.
2685
0
  if ((cpi->oxcf.row_mt == 1) && (cpi->mt_info.num_workers > 1)) {
2686
0
    if (sf->inter_sf.mv_cost_upd_level == INTERNAL_COST_UPD_SBROW_SET) {
2687
      // Set mv_cost_upd_level to use row level update.
2688
0
      sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
2689
0
    }
2690
0
  }
2691
0
}
2692
2693
0
void av1_set_speed_features_framesize_independent(AV1_COMP *cpi, int speed) {
2694
0
  SPEED_FEATURES *const sf = &cpi->sf;
2695
0
  WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
2696
0
  const AV1EncoderConfig *const oxcf = &cpi->oxcf;
2697
0
  int i;
2698
2699
0
  init_hl_sf(&sf->hl_sf);
2700
0
  init_fp_sf(&sf->fp_sf);
2701
0
  init_tpl_sf(&sf->tpl_sf);
2702
0
  init_gm_sf(&sf->gm_sf);
2703
0
  init_part_sf(&sf->part_sf);
2704
0
  init_mv_sf(&sf->mv_sf);
2705
0
  init_inter_sf(&sf->inter_sf);
2706
0
  init_interp_sf(&sf->interp_sf);
2707
0
  init_intra_sf(&sf->intra_sf);
2708
0
  init_tx_sf(&sf->tx_sf);
2709
0
  init_rd_sf(&sf->rd_sf, oxcf);
2710
0
  init_winner_mode_sf(&sf->winner_mode_sf);
2711
0
  init_lpf_sf(&sf->lpf_sf);
2712
0
  init_rt_sf(&sf->rt_sf);
2713
2714
0
  switch (oxcf->mode) {
2715
0
    case GOOD:
2716
0
      set_good_speed_features_framesize_independent(cpi, sf, speed);
2717
0
      break;
2718
0
    case ALLINTRA:
2719
0
      set_allintra_speed_features_framesize_independent(cpi, sf, speed);
2720
0
      break;
2721
0
    case REALTIME:
2722
0
      set_rt_speed_features_framesize_independent(cpi, sf, speed);
2723
0
      break;
2724
0
  }
2725
2726
  // Note: when use_nonrd_pick_mode is true, the transform size is the
2727
  // minimum of 16x16 and the largest possible size of the current block,
2728
  // which conflicts with the speed feature "enable_tx_size_search".
2729
0
  if (!oxcf->txfm_cfg.enable_tx_size_search &&
2730
0
      sf->rt_sf.use_nonrd_pick_mode == 0) {
2731
0
    sf->winner_mode_sf.tx_size_search_level = 3;
2732
0
  }
2733
2734
0
  if (cpi->mt_info.num_workers > 1) {
2735
    // Loop restoration stage is conditionally disabled for speed 5, 6 when
2736
    // num_workers > 1. Since av1_pick_filter_restoration() is not
2737
    // multi-threaded, enabling the Loop restoration stage will cause an
2738
    // increase in encode time (3% to 7% increase depends on frame
2739
    // resolution).
2740
    // TODO(aomedia:3446): Implement multi-threading of
2741
    // av1_pick_filter_restoration() and enable Wiener filter for speed 5, 6
2742
    // similar to single thread encoding path.
2743
0
    if (speed >= 5) {
2744
0
      sf->lpf_sf.disable_sgr_filter = true;
2745
0
      sf->lpf_sf.disable_wiener_filter = true;
2746
0
    }
2747
0
  }
2748
2749
0
  if (!cpi->ppi->seq_params_locked) {
2750
0
    cpi->common.seq_params->order_hint_info.enable_dist_wtd_comp &=
2751
0
        (sf->inter_sf.use_dist_wtd_comp_flag != DIST_WTD_COMP_DISABLED);
2752
0
    cpi->common.seq_params->enable_dual_filter &=
2753
0
        !sf->interp_sf.disable_dual_filter;
2754
    // Set the flag 'enable_restoration', if one the Loop restoration filters
2755
    // (i.e., Wiener or Self-guided) is enabled.
2756
0
    cpi->common.seq_params->enable_restoration &=
2757
0
        (!sf->lpf_sf.disable_wiener_filter || !sf->lpf_sf.disable_sgr_filter);
2758
2759
0
    cpi->common.seq_params->enable_interintra_compound &=
2760
0
        (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
2761
0
  }
2762
2763
0
  const int mesh_speed = AOMMIN(speed, MAX_MESH_SPEED);
2764
0
  for (i = 0; i < MAX_MESH_STEP; ++i) {
2765
0
    sf->mv_sf.mesh_patterns[i].range =
2766
0
        good_quality_mesh_patterns[mesh_speed][i].range;
2767
0
    sf->mv_sf.mesh_patterns[i].interval =
2768
0
        good_quality_mesh_patterns[mesh_speed][i].interval;
2769
0
  }
2770
2771
  // Update the mesh pattern of exhaustive motion search for intraBC
2772
  // Though intraBC mesh pattern is populated for all frame types, it is used
2773
  // only for intra frames of screen contents
2774
0
  for (i = 0; i < MAX_MESH_STEP; ++i) {
2775
0
    sf->mv_sf.intrabc_mesh_patterns[i].range =
2776
0
        intrabc_mesh_patterns[mesh_speed][i].range;
2777
0
    sf->mv_sf.intrabc_mesh_patterns[i].interval =
2778
0
        intrabc_mesh_patterns[mesh_speed][i].interval;
2779
0
  }
2780
2781
  // Slow quant, dct and trellis not worthwhile for first pass
2782
  // so make sure they are always turned off.
2783
0
  if (is_stat_generation_stage(cpi))
2784
0
    sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
2785
2786
  // No recode for 1 pass.
2787
0
  if (oxcf->pass == AOM_RC_ONE_PASS && has_no_stats_stage(cpi))
2788
0
    sf->hl_sf.recode_loop = DISALLOW_RECODE;
2789
2790
0
  set_subpel_search_method(&cpi->mv_search_params,
2791
0
                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
2792
0
                           sf->mv_sf.subpel_search_method);
2793
2794
  // assert ensures that tx_domain_dist_level is accessed correctly
2795
0
  assert(cpi->sf.rd_sf.tx_domain_dist_thres_level >= 0 &&
2796
0
         cpi->sf.rd_sf.tx_domain_dist_thres_level < 4);
2797
0
  memcpy(winner_mode_params->tx_domain_dist_threshold,
2798
0
         tx_domain_dist_thresholds[cpi->sf.rd_sf.tx_domain_dist_thres_level],
2799
0
         sizeof(winner_mode_params->tx_domain_dist_threshold));
2800
2801
0
  assert(cpi->sf.rd_sf.tx_domain_dist_level >= 0 &&
2802
0
         cpi->sf.rd_sf.tx_domain_dist_level < TX_DOMAIN_DIST_LEVELS);
2803
0
  memcpy(winner_mode_params->use_transform_domain_distortion,
2804
0
         tx_domain_dist_types[cpi->sf.rd_sf.tx_domain_dist_level],
2805
0
         sizeof(winner_mode_params->use_transform_domain_distortion));
2806
2807
  // assert ensures that coeff_opt_thresholds is accessed correctly
2808
0
  assert(cpi->sf.rd_sf.perform_coeff_opt >= 0 &&
2809
0
         cpi->sf.rd_sf.perform_coeff_opt < 9);
2810
0
  memcpy(winner_mode_params->coeff_opt_thresholds,
2811
0
         &coeff_opt_thresholds[cpi->sf.rd_sf.perform_coeff_opt],
2812
0
         sizeof(winner_mode_params->coeff_opt_thresholds));
2813
2814
  // assert ensures that predict_skip_levels is accessed correctly
2815
0
  assert(cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction >= 0 &&
2816
0
         cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction < 3);
2817
0
  memcpy(winner_mode_params->skip_txfm_level,
2818
0
         predict_skip_levels[cpi->sf.tx_sf.tx_type_search
2819
0
                                 .use_skip_flag_prediction],
2820
0
         sizeof(winner_mode_params->skip_txfm_level));
2821
2822
  // assert ensures that tx_size_search_level is accessed correctly
2823
0
  assert(cpi->sf.winner_mode_sf.tx_size_search_level >= 0 &&
2824
0
         cpi->sf.winner_mode_sf.tx_size_search_level <= 3);
2825
0
  memcpy(winner_mode_params->tx_size_search_methods,
2826
0
         tx_size_search_methods[cpi->sf.winner_mode_sf.tx_size_search_level],
2827
0
         sizeof(winner_mode_params->tx_size_search_methods));
2828
0
  memcpy(winner_mode_params->predict_dc_level,
2829
0
         predict_dc_levels[cpi->sf.winner_mode_sf.dc_blk_pred_level],
2830
0
         sizeof(winner_mode_params->predict_dc_level));
2831
2832
0
  if (cpi->oxcf.row_mt == 1 && (cpi->mt_info.num_workers > 1)) {
2833
0
    if (sf->inter_sf.inter_mode_rd_model_estimation == 1) {
2834
      // Revert to type 2
2835
0
      sf->inter_sf.inter_mode_rd_model_estimation = 2;
2836
0
    }
2837
2838
0
#if !CONFIG_FPMT_TEST
2839
    // Disable the speed feature 'prune_ref_frame_for_gm_search' to achieve
2840
    // better parallelism when number of threads available are greater than or
2841
    // equal to maximum number of reference frames allowed for global motion.
2842
0
    if (sf->gm_sf.gm_search_type != GM_DISABLE_SEARCH &&
2843
0
        (cpi->mt_info.num_workers >=
2844
0
         gm_available_reference_frames[sf->gm_sf.gm_search_type]))
2845
0
      sf->gm_sf.prune_ref_frame_for_gm_search = 0;
2846
0
#endif
2847
0
  }
2848
2849
  // This only applies to the real time mode. Adaptive gf refresh is disabled if
2850
  // gf_cbr_boost_pct that is set by the user is larger than 0.
2851
0
  if (cpi->oxcf.rc_cfg.gf_cbr_boost_pct > 0)
2852
0
    sf->rt_sf.gf_refresh_based_on_qp = 0;
2853
0
}
2854
2855
// Override some speed features for low complexity decode based on qindex.
2856
static void set_good_speed_features_lc_dec_qindex_dependent(
2857
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
2858
0
  if (speed < 1 || speed > 3) return;
2859
2860
0
  const AV1_COMMON *const cm = &cpi->common;
2861
0
  const bool is_between_608p_and_1080p = AOMMIN(cm->width, cm->height) >= 608 &&
2862
0
                                         AOMMIN(cm->width, cm->height) <= 1080;
2863
0
  const bool is_vertical_video = cm->width < cm->height;
2864
2865
  // Need to study the decoder time impact.
2866
0
  sf->interp_sf.use_more_sharp_interp = 0;
2867
2868
  // Speed features for vertical videos
2869
0
  if (is_vertical_video && is_between_608p_and_1080p) {
2870
0
    sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
2871
0
    sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
2872
0
  }
2873
0
}
2874
2875
// Override some speed features based on qindex
2876
0
void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
2877
0
  AV1_COMMON *const cm = &cpi->common;
2878
0
  SPEED_FEATURES *const sf = &cpi->sf;
2879
0
  WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
2880
0
  const int boosted = frame_is_boosted(cpi);
2881
0
  const int is_480p_or_lesser = AOMMIN(cm->width, cm->height) <= 480;
2882
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
2883
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
2884
0
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
2885
0
  const int is_1440p_or_larger = AOMMIN(cm->width, cm->height) >= 1440;
2886
0
  const int is_arf2_bwd_type =
2887
0
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
2888
2889
0
  if (cpi->oxcf.mode == ALLINTRA || cpi->oxcf.tune_cfg.tuning == AOM_TUNE_IQ ||
2890
0
      cpi->oxcf.tune_cfg.tuning == AOM_TUNE_SSIMULACRA2) {
2891
0
    if (cm->quant_params.base_qindex <= 140) {
2892
0
      sf->lpf_sf.zero_low_cdef_strengths = 1;
2893
0
    }
2894
0
  }
2895
2896
0
  if (cpi->oxcf.mode == REALTIME) {
2897
0
    if (speed >= 6) {
2898
0
      const int qindex_thresh = boosted ? 190 : (is_720p_or_larger ? 120 : 150);
2899
0
      sf->part_sf.adjust_var_based_rd_partitioning =
2900
0
          frame_is_intra_only(cm)
2901
0
              ? 0
2902
0
              : cm->quant_params.base_qindex > qindex_thresh;
2903
0
    }
2904
0
    return;
2905
0
  }
2906
2907
0
  if (speed == 0) {
2908
    // qindex_thresh for resolution < 720p
2909
0
    const int qindex_thresh = boosted ? 70 : (is_arf2_bwd_type ? 110 : 140);
2910
0
    if (!is_720p_or_larger && cm->quant_params.base_qindex <= qindex_thresh) {
2911
0
      sf->part_sf.simple_motion_search_split =
2912
0
          cm->features.allow_screen_content_tools ? 1 : 2;
2913
0
      sf->part_sf.simple_motion_search_early_term_none = 1;
2914
0
      sf->tx_sf.model_based_prune_tx_search_level = 0;
2915
0
    }
2916
2917
0
    if (is_720p_or_larger && cm->quant_params.base_qindex <= 128) {
2918
0
      sf->rd_sf.perform_coeff_opt = 2 + is_1080p_or_larger;
2919
0
      memcpy(winner_mode_params->coeff_opt_thresholds,
2920
0
             &coeff_opt_thresholds[sf->rd_sf.perform_coeff_opt],
2921
0
             sizeof(winner_mode_params->coeff_opt_thresholds));
2922
0
      sf->part_sf.simple_motion_search_split =
2923
0
          cm->features.allow_screen_content_tools ? 1 : 2;
2924
0
      sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
2925
0
      sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
2926
0
      sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
2927
0
      sf->tx_sf.model_based_prune_tx_search_level = 0;
2928
2929
0
      if (is_1080p_or_larger && cm->quant_params.base_qindex <= 108) {
2930
0
        sf->inter_sf.selective_ref_frame = 2;
2931
0
        sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
2932
0
        sf->rd_sf.tx_domain_dist_thres_level = 1;
2933
0
        sf->part_sf.simple_motion_search_early_term_none = 1;
2934
0
        sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
2935
0
        sf->interp_sf.cb_pred_filter_search = 0;
2936
0
        sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
2937
0
        sf->tx_sf.tx_type_search.skip_tx_search = 1;
2938
0
      }
2939
0
    }
2940
0
  }
2941
2942
0
  if (speed >= 2) {
2943
    // Disable extended partitions for lower quantizers
2944
0
    const int aggr = AOMMIN(4, speed - 2);
2945
0
    const int qindex_thresh1[4] = { 50, 50, 80, 100 };
2946
0
    const int qindex_thresh2[4] = { 80, 100, 120, 160 };
2947
0
    int qindex_thresh;
2948
0
    if (aggr <= 1) {
2949
0
      const int qthresh2 =
2950
0
          (!aggr && !is_480p_or_larger) ? 70 : qindex_thresh2[aggr];
2951
0
      qindex_thresh = cm->features.allow_screen_content_tools
2952
0
                          ? qindex_thresh1[aggr]
2953
0
                          : qthresh2;
2954
0
      if (cm->quant_params.base_qindex <= qindex_thresh && !boosted)
2955
0
        sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2956
0
    } else if (aggr <= 2) {
2957
0
      qindex_thresh = boosted ? qindex_thresh1[aggr] : qindex_thresh2[aggr];
2958
0
      if (cm->quant_params.base_qindex <= qindex_thresh &&
2959
0
          !frame_is_intra_only(cm))
2960
0
        sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2961
0
    } else if (aggr <= 3) {
2962
0
      if (!is_480p_or_larger) {
2963
0
        sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2964
0
      } else if (!is_720p_or_larger && !frame_is_intra_only(cm) &&
2965
0
                 !cm->features.allow_screen_content_tools) {
2966
0
        sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2967
0
      } else {
2968
0
        qindex_thresh = boosted ? qindex_thresh1[aggr] : qindex_thresh2[aggr];
2969
0
        if (cm->quant_params.base_qindex <= qindex_thresh &&
2970
0
            !frame_is_intra_only(cm))
2971
0
          sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2972
0
      }
2973
0
    } else {
2974
0
      sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2975
0
    }
2976
0
  }
2977
2978
0
  if (speed >= 3) {
2979
    // Disable rectangular partitions for lower quantizers
2980
0
    const int aggr = (speed <= 4) ? 0 : 1;
2981
0
    const int qindex_thresh[2] = { 65, 80 };
2982
0
    int disable_rect_part;
2983
0
    disable_rect_part = !boosted;
2984
0
    if (cm->quant_params.base_qindex <= qindex_thresh[aggr] &&
2985
0
        disable_rect_part && is_480p_or_larger) {
2986
0
      sf->part_sf.rect_partition_eval_thresh = BLOCK_8X8;
2987
0
    }
2988
0
  }
2989
2990
0
  if (speed <= 2) {
2991
0
    if (!is_stat_generation_stage(cpi)) {
2992
      // Use faster full-pel motion search for high quantizers.
2993
      // Also use reduced total search range for low resolutions at high
2994
      // quantizers.
2995
0
      const int aggr = speed;
2996
2997
      // For < 720p resolutions:
2998
0
      if (!is_720p_or_larger) {
2999
        // For < 720p resolutions:
3000
0
        const int ms_qindex_thresh[3][2] = { { 200, 70 },
3001
0
                                             { 170, 50 },
3002
0
                                             { 170, 40 } };
3003
0
        const int qindex_thresh1 = ms_qindex_thresh[aggr][0];
3004
0
        const int qindex_thresh2 = ms_qindex_thresh[aggr][1];
3005
0
        if (cm->quant_params.base_qindex > qindex_thresh1) {
3006
0
          sf->mv_sf.search_method = CLAMPED_DIAMOND;
3007
0
          sf->tpl_sf.search_method = CLAMPED_DIAMOND;
3008
0
        } else if (cm->quant_params.base_qindex > qindex_thresh2) {
3009
0
          sf->mv_sf.search_method = NSTEP_8PT;
3010
0
        }
3011
0
      } else {
3012
        // For >= 720p resolutions:
3013
0
        const int ms_qindex_thresh[3][2] = { { MAXQ, 200 },
3014
0
                                             { MAXQ, -1 },
3015
0
                                             { 200, -1 } };
3016
0
        const SEARCH_METHODS motion_search_method[3][2] = {
3017
0
          { NSTEP_8PT, NSTEP_8PT },
3018
0
          { NSTEP_8PT, DIAMOND },
3019
0
          { NSTEP_8PT, DIAMOND }
3020
0
        };
3021
0
        const int qindex_thresh1 = ms_qindex_thresh[aggr][0];
3022
0
        const int qindex_thresh2 = ms_qindex_thresh[aggr][1];
3023
0
        if (cm->quant_params.base_qindex > qindex_thresh1) {
3024
0
          sf->mv_sf.search_method = DIAMOND;
3025
0
          sf->tpl_sf.search_method = DIAMOND;
3026
0
        } else if (cm->quant_params.base_qindex > qindex_thresh2) {
3027
0
          sf->mv_sf.search_method = motion_search_method[aggr][0];
3028
0
          sf->tpl_sf.search_method = motion_search_method[aggr][1];
3029
0
        }
3030
0
      }
3031
0
    }
3032
0
    sf->part_sf.less_rectangular_check_level = 1;
3033
0
  }
3034
3035
0
  if (speed == 3)
3036
0
    sf->part_sf.less_rectangular_check_level =
3037
0
        (cm->quant_params.base_qindex >= 170) ? 1 : 2;
3038
3039
0
  if (speed >= 4) {
3040
    // Disable LR search at low and high quantizers and enable only for
3041
    // mid-quantizer range.
3042
0
    if (!boosted && !is_arf2_bwd_type) {
3043
0
      const int qindex_low[2] = { 100, 60 };
3044
0
      const int qindex_high[2] = { 180, 160 };
3045
0
      if (cm->quant_params.base_qindex <= qindex_low[is_720p_or_larger] ||
3046
0
          cm->quant_params.base_qindex > qindex_high[is_720p_or_larger]) {
3047
0
        sf->lpf_sf.disable_sgr_filter = true;
3048
0
        sf->lpf_sf.disable_wiener_coeff_refine_search = true;
3049
0
      }
3050
0
    }
3051
0
    sf->part_sf.less_rectangular_check_level = 2;
3052
0
  }
3053
3054
0
  if (speed == 1) {
3055
    // Reuse interinter wedge mask search from first search for non-boosted
3056
    // non-internal-arf frames, except at very high quantizers.
3057
0
    if (cm->quant_params.base_qindex <= 200) {
3058
0
      if (!boosted && !is_arf2_bwd_type)
3059
0
        sf->inter_sf.reuse_mask_search_results = 1;
3060
0
    }
3061
0
  }
3062
3063
0
  if (speed == 5) {
3064
0
    if (!(frame_is_intra_only(&cpi->common) ||
3065
0
          cm->features.allow_screen_content_tools)) {
3066
0
      const int qindex[2] = { 256, 128 };
3067
      // Set the sf value as 3 for low resolution and
3068
      // for higher resolutions with low quantizers.
3069
0
      if (cm->quant_params.base_qindex < qindex[is_480p_or_larger])
3070
0
        sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 3;
3071
0
    }
3072
0
  }
3073
3074
0
  if (speed >= 5) {
3075
    // Disable the sf for low quantizers in case of low resolution screen
3076
    // contents.
3077
0
    if (cm->features.allow_screen_content_tools &&
3078
0
        cm->quant_params.base_qindex < 128 && is_480p_or_lesser) {
3079
0
      sf->part_sf.prune_sub_8x8_partition_level = 0;
3080
0
    }
3081
0
  }
3082
3083
  // Loop restoration size search
3084
  // At speed 0, always search all available sizes for the maximum possible gain
3085
0
  sf->lpf_sf.min_lr_unit_size = RESTORATION_PROC_UNIT_SIZE;
3086
0
  sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
3087
3088
0
  if (speed >= 1) {
3089
    // For large frames, small restoration units are almost never useful,
3090
    // so prune them away
3091
0
    if (is_1440p_or_larger) {
3092
0
      sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX;
3093
0
    } else if (is_720p_or_larger) {
3094
0
      sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
3095
0
    }
3096
0
  }
3097
3098
0
  if (speed >= 3 || (cpi->oxcf.mode == ALLINTRA && speed >= 1)) {
3099
    // At this speed, a full search is too expensive. Instead, pick a single
3100
    // size based on size and qindex. Note that, in general, higher quantizers
3101
    // (== lower quality) and larger frames generally want to use larger
3102
    // restoration units.
3103
0
    int qindex_thresh = 96;
3104
0
    if (cm->quant_params.base_qindex <= qindex_thresh && !is_1440p_or_larger) {
3105
0
      sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
3106
0
      sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
3107
0
    } else {
3108
0
      sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX;
3109
0
      sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
3110
0
    }
3111
0
  }
3112
3113
0
  set_subpel_search_method(&cpi->mv_search_params,
3114
0
                           cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
3115
0
                           sf->mv_sf.subpel_search_method);
3116
3117
0
  if (cpi->oxcf.enable_low_complexity_decode && cpi->oxcf.mode == GOOD)
3118
0
    set_good_speed_features_lc_dec_qindex_dependent(cpi, sf, speed);
3119
0
}