Coverage Report

Created: 2022-08-24 06:15

/src/aom/av1/encoder/speed_features.c
Line
Count
Source (jump to first uncovered line)
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 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 MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
38
  { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
39
  { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
40
  { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
41
  { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
42
  { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
43
  { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
44
};
45
46
// Threshold values to be used for pruning the txfm_domain_distortion
47
// based on block MSE
48
// Index 0: Default mode evaluation, Winner mode processing is not
49
// applicable (Eg : IntraBc). Index 1: Mode evaluation.
50
// Index 2: Winner mode evaluation. Index 1 and 2 are applicable when
51
// enable_winner_mode_for_use_tx_domain_dist speed feature is ON
52
// TODO(any): Experiment the threshold logic based on variance metric
53
static unsigned int tx_domain_dist_thresholds[4][MODE_EVAL_TYPES] = {
54
  { UINT_MAX, UINT_MAX, UINT_MAX },
55
  { 22026, 22026, 22026 },
56
  { 1377, 1377, 1377 },
57
  { 0, 0, 0 }
58
};
59
60
// Transform domain distortion type to be used for default, mode and winner mode
61
// evaluation Index 0: Default mode evaluation, Winner mode processing is not
62
// applicable (Eg : IntraBc). Index 1: Mode evaluation. Index 2: Winner mode
63
// evaluation. Index 1 and 2 are applicable when
64
// enable_winner_mode_for_use_tx_domain_dist speed feature is ON
65
static unsigned int tx_domain_dist_types[3][MODE_EVAL_TYPES] = { { 0, 2, 0 },
66
                                                                 { 1, 2, 0 },
67
                                                                 { 2, 2, 0 } };
68
69
// Threshold values to be used for disabling coeff RD-optimization
70
// based on block MSE / qstep^2.
71
// TODO(any): Experiment the threshold logic based on variance metric.
72
// Table has satd and dist threshold value index 0 : dist,index 1: satd
73
// For each row, the indices are as follows.
74
// Index 0: Default mode evaluation, Winner mode processing is not applicable
75
// (Eg : IntraBc)
76
// Index 1: Mode evaluation.
77
// Index 2: Winner mode evaluation.
78
// Index 1 and 2 are applicable when enable_winner_mode_for_coeff_opt speed
79
// feature is ON
80
// There are 7 levels with increasing speed, mapping to vertical indices.
81
static unsigned int coeff_opt_thresholds[9][MODE_EVAL_TYPES][2] = {
82
  { { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX } },
83
  { { 3200, UINT_MAX }, { 250, UINT_MAX }, { UINT_MAX, UINT_MAX } },
84
  { { 1728, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
85
  { { 864, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
86
  { { 432, UINT_MAX }, { 86, UINT_MAX }, { UINT_MAX, UINT_MAX } },
87
  { { 864, 97 }, { 142, 16 }, { UINT_MAX, UINT_MAX } },
88
  { { 432, 97 }, { 86, 16 }, { UINT_MAX, UINT_MAX } },
89
  { { 216, 25 }, { 86, 10 }, { UINT_MAX, UINT_MAX } },
90
  { { 216, 25 }, { 0, 10 }, { UINT_MAX, UINT_MAX } }
91
};
92
93
// Transform size to be used for default, mode and winner mode evaluation
94
// Index 0: Default mode evaluation, Winner mode processing is not applicable
95
// (Eg : IntraBc) Index 1: Mode evaluation. Index 2: Winner mode evaluation.
96
// Index 1 and 2 are applicable when enable_winner_mode_for_tx_size_srch speed
97
// feature is ON
98
static TX_SIZE_SEARCH_METHOD tx_size_search_methods[4][MODE_EVAL_TYPES] = {
99
  { USE_FULL_RD, USE_LARGESTALL, USE_FULL_RD },
100
  { USE_FAST_RD, USE_LARGESTALL, USE_FULL_RD },
101
  { USE_LARGESTALL, USE_LARGESTALL, USE_FULL_RD },
102
  { USE_LARGESTALL, USE_LARGESTALL, USE_LARGESTALL }
103
};
104
105
// Predict transform skip levels to be used for default, mode and winner mode
106
// evaluation. Index 0: Default mode evaluation, Winner mode processing is not
107
// applicable. Index 1: Mode evaluation, Index 2: Winner mode evaluation
108
// Values indicate the aggressiveness of skip flag prediction.
109
// 0 : no early skip prediction
110
// 1 : conservative early skip prediction using DCT_DCT
111
// 2 : early skip prediction based on SSE
112
static unsigned int predict_skip_levels[3][MODE_EVAL_TYPES] = { { 0, 0, 0 },
113
                                                                { 1, 1, 1 },
114
                                                                { 1, 2, 1 } };
115
116
// Predict DC block levels to be used for default, mode and winner mode
117
// evaluation. Index 0: Default mode evaluation, Winner mode processing is not
118
// applicable. Index 1: Mode evaluation, Index 2: Winner mode evaluation
119
// Values indicate the aggressiveness of skip flag prediction.
120
// 0 : no early DC block prediction
121
// 1 : Early DC block prediction based on error variance
122
static unsigned int predict_dc_levels[3][MODE_EVAL_TYPES] = { { 0, 0, 0 },
123
                                                              { 1, 1, 0 },
124
                                                              { 1, 1, 1 } };
125
126
#if !CONFIG_FRAME_PARALLEL_ENCODE || \
127
    (CONFIG_FRAME_PARALLEL_ENCODE && !CONFIG_FPMT_TEST)
128
// This table holds the maximum number of reference frames for global motion.
129
// The table is indexed as per the speed feature 'gm_search_type'.
130
// 0 : All reference frames are allowed.
131
// 1 : All reference frames except L2 and L3 are allowed.
132
// 2 : All reference frames except L2, L3 and ARF2 are allowed.
133
// 3 : No reference frame is allowed.
134
static int gm_available_reference_frames[GM_DISABLE_SEARCH + 1] = {
135
  INTER_REFS_PER_FRAME, INTER_REFS_PER_FRAME - 2, INTER_REFS_PER_FRAME - 3, 0
136
};
137
#endif
138
139
// Qindex threshold levels used for selecting full-pel motion search.
140
// ms_qthresh[i][j][k] indicates the qindex boundary value for 'k'th qindex band
141
// for resolution index 'j' for aggressiveness level 'i'.
142
// Aggressiveness increases from i = 0 to 2.
143
// j = 0: lower than 720p resolution, j = 1: 720p or larger resolution.
144
// Currently invoked only for speed 0, 1 and 2.
145
static int ms_qindex_thresh[3][2][2] = { { { 200, 70 }, { MAXQ, 200 } },
146
                                         { { 170, 50 }, { MAXQ, 200 } },
147
                                         { { 170, 40 }, { 200, 40 } } };
148
149
// Full-pel search methods for aggressive search based on qindex.
150
// Index 0 is for resolutions lower than 720p, index 1 for 720p or larger
151
// resolutions. Currently invoked only for speed 1 and 2.
152
static SEARCH_METHODS motion_search_method[2] = { CLAMPED_DIAMOND, DIAMOND };
153
154
// Intra only frames, golden frames (except alt ref overlays) and
155
// alt ref frames tend to be coded at a higher than ambient quality
156
1.26k
static int frame_is_boosted(const AV1_COMP *cpi) {
157
1.26k
  return frame_is_kf_gf_arf(cpi);
158
1.26k
}
159
160
static void set_allintra_speed_feature_framesize_dependent(
161
3.78k
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
162
3.78k
  const AV1_COMMON *const cm = &cpi->common;
163
3.78k
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
164
3.78k
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
165
3.78k
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
166
3.78k
  const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
167
3.78k
  const bool use_hbd = cpi->oxcf.use_highbitdepth;
168
169
3.78k
  if (is_480p_or_larger) {
170
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
171
0
    if (is_720p_or_larger)
172
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
173
0
    else
174
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
175
3.78k
  } else {
176
3.78k
    sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
177
3.78k
    sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
178
3.78k
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
179
3.78k
  }
180
181
3.78k
  if (is_4k_or_larger) {
182
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
183
0
  }
184
185
  // TODO(huisu@google.com): train models for 720P and above.
186
3.78k
  if (!is_720p_or_larger) {
187
3.78k
    sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
188
3.78k
    sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
189
3.78k
    sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
190
3.78k
    sf->part_sf.ml_partition_search_breakout_thresh[3] = 500;  // BLOCK_64X64
191
3.78k
    sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;   // BLOCK_128X128
192
3.78k
    sf->part_sf.ml_early_term_after_part_split_level = 1;
193
3.78k
  }
194
195
3.78k
  if (is_720p_or_larger) {
196
    // TODO(chiyotsai@google.com): make this speed feature adaptive based on
197
    // current block's vertical texture instead of hardcoded with resolution
198
0
    sf->mv_sf.use_downsampled_sad = 1;
199
0
  }
200
201
3.78k
  if (speed >= 1) {
202
2.52k
    if (is_720p_or_larger) {
203
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
204
2.52k
    } else if (is_480p_or_larger) {
205
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
206
2.52k
    } else {
207
2.52k
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
208
2.52k
    }
209
210
2.52k
    if (!is_720p_or_larger) {
211
2.52k
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
212
2.52k
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
213
2.52k
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
214
2.52k
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 300;  // BLOCK_64X64
215
2.52k
      sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;  // BLOCK_128X128
216
2.52k
    }
217
2.52k
    sf->part_sf.ml_early_term_after_part_split_level = 2;
218
2.52k
  }
219
220
3.78k
  if (speed >= 2) {
221
2.52k
    if (is_720p_or_larger) {
222
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
223
2.52k
    } else if (is_480p_or_larger) {
224
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
225
2.52k
    } else {
226
2.52k
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
227
2.52k
    }
228
229
2.52k
    if (is_720p_or_larger) {
230
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
231
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
232
2.52k
    } else {
233
2.52k
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
234
2.52k
      sf->part_sf.partition_search_breakout_rate_thr = 100;
235
2.52k
    }
236
237
2.52k
    if (is_480p_or_larger) {
238
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
239
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
240
2.52k
    } else {
241
2.52k
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
242
2.52k
    }
243
2.52k
  }
244
245
3.78k
  if (speed >= 3) {
246
2.52k
    sf->part_sf.ml_early_term_after_part_split_level = 0;
247
248
2.52k
    if (is_720p_or_larger) {
249
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
250
0
      sf->part_sf.partition_search_breakout_rate_thr = 200;
251
2.52k
    } else {
252
2.52k
      sf->part_sf.max_intra_bsize = BLOCK_32X32;
253
2.52k
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
254
2.52k
      sf->part_sf.partition_search_breakout_rate_thr = 120;
255
2.52k
    }
256
2.52k
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
257
2.52k
  }
258
259
3.78k
  if (speed >= 4) {
260
2.52k
    if (is_720p_or_larger) {
261
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
262
2.52k
    } else {
263
2.52k
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
264
2.52k
    }
265
266
2.52k
    if (is_480p_or_larger) {
267
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
268
0
    }
269
2.52k
  }
270
271
3.78k
  if (speed >= 6) {
272
0
    if (is_720p_or_larger) {
273
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
274
0
    } else if (is_480p_or_larger) {
275
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
276
0
    }
277
278
0
    if (is_1080p_or_larger) {
279
0
      sf->part_sf.default_min_partition_size = BLOCK_8X8;
280
0
    }
281
282
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
283
0
  }
284
285
3.78k
  if (speed >= 7) {
286
    // TODO(kyslov): add more speed features to control speed/quality
287
0
  }
288
289
3.78k
  if (speed >= 8) {
290
0
    if (!is_480p_or_larger) {
291
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 2;
292
0
    }
293
0
    if (is_720p_or_larger) {
294
0
      sf->rt_sf.force_large_partition_blocks_intra = 1;
295
0
    }
296
0
  }
297
298
3.78k
  if (speed >= 9) {
299
    // TODO(kyslov): add more speed features to control speed/quality
300
0
    if (!is_4k_or_larger) {
301
0
      sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_OFF;
302
0
      sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_OFF;
303
0
    }
304
0
  }
305
3.78k
}
306
307
static void set_allintra_speed_features_framesize_independent(
308
3.78k
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
309
3.78k
  const AV1_COMMON *const cm = &cpi->common;
310
3.78k
  const int allow_screen_content_tools =
311
3.78k
      cm->features.allow_screen_content_tools;
312
3.78k
  const int use_hbd = cpi->oxcf.use_highbitdepth;
313
314
3.78k
  sf->part_sf.less_rectangular_check_level = 1;
315
3.78k
  sf->part_sf.ml_prune_partition = 1;
316
3.78k
  sf->part_sf.prune_ext_partition_types_search_level = 1;
317
3.78k
  sf->part_sf.prune_part4_search = 2;
318
3.78k
  sf->part_sf.simple_motion_search_prune_rect = 1;
319
3.78k
  sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
320
3.78k
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
321
3.78k
  sf->part_sf.use_best_rd_for_pruning = 1;
322
323
3.78k
  sf->intra_sf.intra_pruning_with_hog = 1;
324
3.78k
  sf->intra_sf.prune_luma_palette_size_search_level = 1;
325
3.78k
  sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
326
3.78k
  sf->intra_sf.early_term_chroma_palette_size_search = 1;
327
328
3.78k
  sf->tx_sf.adaptive_txb_search_level = 1;
329
3.78k
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
330
3.78k
  sf->tx_sf.model_based_prune_tx_search_level = 1;
331
3.78k
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
332
333
3.78k
  sf->rt_sf.use_nonrd_pick_mode = 0;
334
3.78k
  sf->rt_sf.use_real_time_ref_set = 0;
335
336
3.78k
  if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
337
3.78k
      cpi->use_screen_content_tools) {
338
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
339
3.78k
  } else {
340
3.78k
    sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
341
3.78k
  }
342
343
3.78k
  sf->rd_sf.perform_coeff_opt = 1;
344
3.78k
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
345
346
3.78k
  if (speed >= 1) {
347
2.52k
    sf->part_sf.intra_cnn_based_part_prune_level =
348
2.52k
        allow_screen_content_tools ? 0 : 2;
349
2.52k
    sf->part_sf.simple_motion_search_early_term_none = 1;
350
    // TODO(Venkat): Clean-up frame type dependency for
351
    // simple_motion_search_split in partition search function and set the
352
    // speed feature accordingly
353
2.52k
    sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
354
2.52k
    sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
355
2.52k
    sf->part_sf.reuse_best_prediction_for_part_ab = 1;
356
357
2.52k
    sf->mv_sf.exhaustive_searches_thresh <<= 1;
358
359
2.52k
    sf->intra_sf.prune_palette_search_level = 1;
360
2.52k
    sf->intra_sf.prune_luma_palette_size_search_level = 2;
361
2.52k
    sf->intra_sf.top_intra_model_count_allowed = 3;
362
363
2.52k
    sf->tx_sf.adaptive_txb_search_level = 2;
364
2.52k
    sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
365
2.52k
    sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
366
2.52k
    sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
367
2.52k
    sf->tx_sf.model_based_prune_tx_search_level = 0;
368
2.52k
    sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
369
2.52k
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
370
2.52k
    sf->tx_sf.tx_type_search.skip_tx_search = 1;
371
372
2.52k
    sf->rd_sf.perform_coeff_opt = 2;
373
2.52k
    sf->rd_sf.tx_domain_dist_level = 1;
374
2.52k
    sf->rd_sf.tx_domain_dist_thres_level = 1;
375
376
2.52k
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
377
2.52k
    sf->lpf_sf.dual_sgr_penalty_level = 1;
378
2.52k
    sf->lpf_sf.enable_sgr_ep_pruning = 1;
379
2.52k
  }
380
381
3.78k
  if (speed >= 2) {
382
2.52k
    sf->mv_sf.auto_mv_step_size = 1;
383
384
2.52k
    sf->intra_sf.disable_smooth_intra = 1;
385
2.52k
    sf->intra_sf.intra_pruning_with_hog = 2;
386
2.52k
    sf->intra_sf.prune_filter_intra_level = 1;
387
388
2.52k
    sf->rd_sf.perform_coeff_opt = 3;
389
390
2.52k
    sf->lpf_sf.prune_wiener_based_on_src_var = 1;
391
2.52k
    sf->lpf_sf.prune_sgr_based_on_wiener = 1;
392
2.52k
  }
393
394
3.78k
  if (speed >= 3) {
395
2.52k
    sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
396
2.52k
    sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
397
398
2.52k
    sf->part_sf.less_rectangular_check_level = 2;
399
2.52k
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL1;
400
2.52k
    sf->part_sf.prune_ext_part_using_split_info = 1;
401
402
2.52k
    sf->mv_sf.full_pixel_search_level = 1;
403
2.52k
    sf->mv_sf.search_method = DIAMOND;
404
405
    // TODO(chiyotsai@google.com): the thresholds chosen for intra hog are
406
    // inherited directly from luma hog with some minor tweaking. Eventually we
407
    // should run this with a bayesian optimizer to find the Pareto frontier.
408
2.52k
    sf->intra_sf.chroma_intra_pruning_with_hog = 2;
409
2.52k
    sf->intra_sf.intra_pruning_with_hog = 3;
410
2.52k
    sf->intra_sf.prune_palette_search_level = 2;
411
412
2.52k
    sf->tx_sf.adaptive_txb_search_level = 2;
413
2.52k
    sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
414
415
    // TODO(any): evaluate if these lpf features can be moved to speed 2.
416
    // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
417
    // loss.
418
2.52k
    sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
419
2.52k
    sf->lpf_sf.disable_loop_restoration_chroma = 0;
420
2.52k
    sf->lpf_sf.reduce_wiener_window_size = 1;
421
2.52k
    sf->lpf_sf.prune_wiener_based_on_src_var = 2;
422
2.52k
  }
423
424
3.78k
  if (speed >= 4) {
425
2.52k
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
426
427
2.52k
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL2;
428
2.52k
    sf->part_sf.simple_motion_search_reduce_search_steps = 4;
429
2.52k
    sf->part_sf.prune_ext_part_using_split_info = 2;
430
2.52k
    sf->part_sf.early_term_after_none_split = 1;
431
2.52k
    sf->part_sf.ml_predict_breakout_level = 3;
432
433
2.52k
    sf->intra_sf.prune_chroma_modes_using_luma_winner = 1;
434
435
2.52k
    sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
436
437
2.52k
    sf->tpl_sf.prune_starting_mv = 2;
438
2.52k
    sf->tpl_sf.subpel_force_stop = HALF_PEL;
439
2.52k
    sf->tpl_sf.search_method = FAST_BIGDIA;
440
441
2.52k
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
442
2.52k
    sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
443
2.52k
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
444
2.52k
    sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 1;
445
446
2.52k
    sf->rd_sf.perform_coeff_opt = 5;
447
2.52k
    sf->rd_sf.tx_domain_dist_thres_level = 3;
448
449
2.52k
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
450
2.52k
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
451
452
2.52k
    sf->mv_sf.reduce_search_range = 1;
453
454
2.52k
    sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
455
2.52k
    sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
456
2.52k
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_DEFAULT;
457
2.52k
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
458
2.52k
  }
459
460
3.78k
  if (speed >= 5) {
461
2.52k
    sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL3;
462
2.52k
    sf->part_sf.ext_partition_eval_thresh =
463
2.52k
        allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
464
2.52k
    sf->part_sf.intra_cnn_based_part_prune_level =
465
2.52k
        allow_screen_content_tools ? 1 : 2;
466
467
2.52k
    sf->intra_sf.chroma_intra_pruning_with_hog = 3;
468
469
2.52k
    sf->lpf_sf.use_coarse_filter_level_search = 0;
470
2.52k
    sf->lpf_sf.disable_lr_filter = 1;
471
472
2.52k
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
473
474
2.52k
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_FAST;
475
2.52k
  }
476
477
3.78k
  if (speed >= 6) {
478
0
    sf->intra_sf.prune_filter_intra_level = 2;
479
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 4;
480
0
    sf->intra_sf.intra_pruning_with_hog = 4;
481
0
    sf->intra_sf.cfl_search_range = 1;
482
0
    sf->intra_sf.top_intra_model_count_allowed = 2;
483
0
    sf->intra_sf.adapt_top_model_rd_count_using_neighbors = 1;
484
485
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
486
0
        allow_screen_content_tools ? 0 : 2;
487
0
    sf->part_sf.prune_sub_8x8_partition_level =
488
0
        allow_screen_content_tools ? 0 : 1;
489
0
    sf->part_sf.prune_part4_search = 3;
490
    // TODO(jingning): This might not be a good trade off if the
491
    // target image quality is very low.
492
0
    sf->part_sf.default_max_partition_size = BLOCK_32X32;
493
494
0
    sf->mv_sf.use_bsize_dependent_search_method = 1;
495
496
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 3;
497
0
    sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 0;
498
499
0
    sf->rd_sf.perform_coeff_opt = 6;
500
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
501
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
502
503
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
504
0
    sf->winner_mode_sf.prune_winner_mode_processing_using_src_var = 1;
505
0
  }
506
  // The following should make all-intra mode speed 7 approximately equal
507
  // to real-time speed 6,
508
  // all-intra speed 8 close to real-time speed 7, and all-intra speed 9
509
  // close to real-time speed 8
510
3.78k
  if (speed >= 7) {
511
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
512
0
    sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
513
0
    sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
514
0
    sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
515
0
    sf->rt_sf.var_part_split_threshold_shift = 7;
516
0
  }
517
518
3.78k
  if (speed >= 8) {
519
0
    sf->rt_sf.hybrid_intra_pickmode = 1;
520
0
    sf->rt_sf.use_nonrd_pick_mode = 1;
521
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 1;
522
0
    sf->rt_sf.nonrd_check_partition_split = 0;
523
0
    sf->rt_sf.var_part_split_threshold_shift = 8;
524
    // Set mask for intra modes.
525
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
526
0
      if (i >= BLOCK_32X32)
527
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
528
0
      else
529
        // Use DC, H, V intra mode for block sizes < 32X32.
530
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
531
0
  }
532
533
3.78k
  if (speed >= 9) {
534
0
    sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
535
0
    sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
536
537
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 0;
538
0
    sf->rt_sf.hybrid_intra_pickmode = 0;
539
0
    sf->rt_sf.var_part_split_threshold_shift = 9;
540
0
  }
541
3.78k
}
542
543
static void set_good_speed_feature_framesize_dependent(
544
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
545
0
  const AV1_COMMON *const cm = &cpi->common;
546
0
  const int is_480p_or_lesser = AOMMIN(cm->width, cm->height) <= 480;
547
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
548
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
549
0
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
550
0
  const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
551
0
  const bool use_hbd = cpi->oxcf.use_highbitdepth;
552
0
  const int boosted = frame_is_boosted(cpi);
553
0
  const int is_boosted_arf2_bwd_type =
554
0
      boosted ||
555
0
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
556
0
  const int is_lf_frame =
557
0
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == LF_UPDATE;
558
559
0
  if (is_480p_or_larger) {
560
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
561
0
    if (is_720p_or_larger)
562
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
563
0
    else
564
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
565
0
  } else {
566
0
    sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
567
0
    sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
568
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
569
0
  }
570
571
0
  if (is_4k_or_larger) {
572
0
    sf->part_sf.default_min_partition_size = BLOCK_8X8;
573
0
  }
574
575
  // TODO(huisu@google.com): train models for 720P and above.
576
0
  if (!is_720p_or_larger) {
577
0
    sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
578
0
    sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
579
0
    sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
580
0
    sf->part_sf.ml_partition_search_breakout_thresh[3] = 500;  // BLOCK_64X64
581
0
    sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;   // BLOCK_128X128
582
0
    sf->part_sf.ml_early_term_after_part_split_level = 1;
583
0
  }
584
585
0
  if (is_720p_or_larger) {
586
    // TODO(chiyotsai@google.com): make this speed feature adaptive based on
587
    // current block's vertical texture instead of hardcoded with resolution
588
0
    sf->mv_sf.use_downsampled_sad = 1;
589
0
  }
590
591
0
  if (!is_720p_or_larger) {
592
0
    const RateControlCfg *const rc_cfg = &cpi->oxcf.rc_cfg;
593
0
    const int rate_tolerance =
594
0
        AOMMIN(rc_cfg->under_shoot_pct, rc_cfg->over_shoot_pct);
595
0
    sf->hl_sf.recode_tolerance = 25 + (rate_tolerance >> 2);
596
0
  }
597
598
0
  if (speed >= 1) {
599
0
    if (is_480p_or_lesser) sf->inter_sf.skip_newmv_in_drl = 1;
600
601
0
    if (is_720p_or_larger) {
602
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
603
0
    } else if (is_480p_or_larger) {
604
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
605
0
    } else {
606
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
607
0
    }
608
609
0
    if (!is_720p_or_larger) {
610
0
      sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
611
0
      sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
612
0
      sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
613
0
      sf->part_sf.ml_partition_search_breakout_thresh[3] = 300;  // BLOCK_64X64
614
0
      sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;  // BLOCK_128X128
615
0
    }
616
0
    sf->part_sf.ml_early_term_after_part_split_level = 2;
617
618
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
619
0
  }
620
621
0
  if (speed >= 2) {
622
0
    if (is_720p_or_larger) {
623
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
624
0
    } else if (is_480p_or_larger) {
625
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
626
0
    } else {
627
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
628
0
    }
629
630
0
    if (is_720p_or_larger) {
631
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
632
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
633
0
    } else {
634
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
635
0
      sf->part_sf.partition_search_breakout_rate_thr = 100;
636
0
    }
637
638
0
    if (is_720p_or_larger) {
639
0
      sf->inter_sf.prune_obmc_prob_thresh = 16;
640
0
    } else {
641
0
      sf->inter_sf.prune_obmc_prob_thresh = 8;
642
0
    }
643
644
0
    if (is_480p_or_larger) {
645
0
      sf->inter_sf.disable_interintra_wedge_var_thresh = 100;
646
0
    } else {
647
0
      sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
648
0
    }
649
650
0
    if (is_480p_or_lesser) sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
651
652
0
    if (is_720p_or_larger) {
653
0
      sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 1 : 0;
654
0
    } else {
655
0
      sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 2 : 0;
656
0
    }
657
658
0
    if (is_480p_or_larger) {
659
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
660
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
661
0
    } else {
662
0
      if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
663
0
      sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = boosted ? 0 : 1;
664
0
      sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = boosted ? 0 : 1;
665
0
    }
666
667
0
    if (!is_720p_or_larger) {
668
0
      sf->mv_sf.disable_second_mv = 1;
669
0
      sf->mv_sf.auto_mv_step_size = 2;
670
0
    } else {
671
0
      sf->mv_sf.disable_second_mv = boosted ? 0 : 2;
672
0
      sf->mv_sf.auto_mv_step_size = 1;
673
0
    }
674
675
0
    if (!is_720p_or_larger) {
676
0
      sf->hl_sf.recode_tolerance = 50;
677
0
      sf->inter_sf.disable_interinter_wedge_newmv_search =
678
0
          is_boosted_arf2_bwd_type ? 0 : 1;
679
0
      sf->inter_sf.enable_fast_wedge_mask_search = 1;
680
0
    }
681
0
  }
682
683
0
  if (speed >= 3) {
684
0
    sf->inter_sf.enable_fast_wedge_mask_search = 1;
685
0
    sf->inter_sf.skip_newmv_in_drl = 2;
686
0
    sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
687
0
    sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 3 : 0;
688
0
    sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
689
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 1;
690
0
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch =
691
0
        frame_is_intra_only(&cpi->common) ? 0 : 1;
692
693
0
    sf->part_sf.ml_early_term_after_part_split_level = 0;
694
695
0
    if (is_720p_or_larger) {
696
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
697
0
      sf->part_sf.partition_search_breakout_rate_thr = 200;
698
0
      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 2 : 0;
699
0
    } else {
700
0
      sf->part_sf.max_intra_bsize = BLOCK_32X32;
701
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
702
0
      sf->part_sf.partition_search_breakout_rate_thr = 120;
703
0
      sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 1 : 0;
704
0
    }
705
0
    if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
706
707
0
    if (is_480p_or_larger) {
708
0
      sf->part_sf.early_term_after_none_split = 1;
709
0
    } else {
710
0
      sf->part_sf.early_term_after_none_split = 0;
711
0
    }
712
0
    if (is_720p_or_larger) {
713
0
      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 2;
714
0
    } else {
715
0
      sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 3;
716
0
    }
717
718
0
    if (is_720p_or_larger) {
719
0
      sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
720
0
      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 1;
721
0
    } else {
722
0
      sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
723
0
      sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
724
0
      sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL2;
725
0
    }
726
727
0
    sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
728
0
  }
729
730
0
  if (speed >= 4) {
731
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
732
0
    sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
733
0
    if (is_720p_or_larger) {
734
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
735
0
    } else {
736
0
      sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
737
0
    }
738
0
    sf->part_sf.early_term_after_none_split = 1;
739
740
0
    if (is_480p_or_larger) {
741
0
      sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
742
0
    }
743
744
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
745
0
    sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
746
0
    sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
747
0
    if (is_480p_or_lesser) sf->inter_sf.skip_newmv_in_drl = 3;
748
749
0
    if (is_720p_or_larger)
750
0
      sf->hl_sf.recode_tolerance = 32;
751
0
    else
752
0
      sf->hl_sf.recode_tolerance = 55;
753
754
0
    sf->intra_sf.skip_intra_in_interframe = 4;
755
756
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
757
0
  }
758
759
0
  if (speed >= 5) {
760
0
    if (is_720p_or_larger) {
761
0
      sf->inter_sf.prune_warped_prob_thresh = 16;
762
0
    } else if (is_480p_or_larger) {
763
0
      sf->inter_sf.prune_warped_prob_thresh = 8;
764
0
    }
765
0
    if (is_720p_or_larger) sf->hl_sf.recode_tolerance = 40;
766
767
0
    sf->inter_sf.skip_newmv_in_drl = 4;
768
769
0
    if (!is_720p_or_larger) {
770
0
      sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW_SET;
771
0
    }
772
773
0
    if (!is_480p_or_larger) {
774
0
      sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
775
0
          boosted ? INT_MAX : 250;
776
0
    }
777
778
0
    if (is_480p_or_lesser) {
779
0
      sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL1;
780
0
    } else {
781
0
      sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL2;
782
0
    }
783
0
  }
784
785
0
  if (speed >= 6) {
786
0
    sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
787
0
    sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
788
0
    if (is_720p_or_larger) {
789
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
790
0
    } else if (is_480p_or_larger) {
791
0
      sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
792
0
    }
793
794
0
    if (is_1080p_or_larger) {
795
0
      sf->part_sf.default_min_partition_size = BLOCK_8X8;
796
0
    }
797
798
0
    if (is_720p_or_larger) {
799
0
      sf->inter_sf.disable_masked_comp = 1;
800
0
    }
801
802
0
    if (!is_720p_or_larger) {
803
0
      sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
804
0
      sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
805
0
    }
806
807
0
    if (is_720p_or_larger) {
808
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
809
0
    } else {
810
0
      sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
811
0
    }
812
813
0
    if (is_720p_or_larger) {
814
0
      sf->inter_sf.prune_ref_mv_idx_search = 2;
815
0
    } else {
816
0
      sf->inter_sf.prune_ref_mv_idx_search = 1;
817
0
    }
818
819
0
    if (!is_720p_or_larger) {
820
0
      sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh = 150;
821
0
    }
822
823
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
824
0
  }
825
0
}
826
827
static void set_good_speed_features_framesize_independent(
828
0
    const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
829
0
  const AV1_COMMON *const cm = &cpi->common;
830
0
  const GF_GROUP *const gf_group = &cpi->ppi->gf_group;
831
0
  const int boosted = frame_is_boosted(cpi);
832
0
  const int is_boosted_arf2_bwd_type =
833
0
      boosted || gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
834
0
  const int is_inter_frame =
835
0
      gf_group->frame_type[cpi->gf_frame_index] == INTER_FRAME;
836
0
  const int allow_screen_content_tools =
837
0
      cm->features.allow_screen_content_tools;
838
0
  const int use_hbd = cpi->oxcf.use_highbitdepth;
839
0
  if (!cpi->oxcf.tile_cfg.enable_large_scale_tile) {
840
0
    sf->hl_sf.high_precision_mv_usage = LAST_MV_DATA;
841
0
  }
842
843
  // Speed 0 for all speed features that give neutral coding performance change.
844
0
  sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_L2_L3;
845
846
0
  sf->part_sf.less_rectangular_check_level = 1;
847
0
  sf->part_sf.ml_prune_partition = 1;
848
0
  sf->part_sf.prune_ext_partition_types_search_level = 1;
849
0
  sf->part_sf.prune_part4_search = 2;
850
0
  sf->part_sf.simple_motion_search_prune_rect = 1;
851
0
  sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
852
0
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
853
0
  sf->part_sf.use_best_rd_for_pruning = 1;
854
0
  sf->part_sf.simple_motion_search_prune_agg =
855
0
      allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL0;
856
857
  // TODO(debargha): Test, tweak and turn on either 1 or 2
858
0
  sf->inter_sf.inter_mode_rd_model_estimation = 1;
859
0
  sf->inter_sf.model_based_post_interp_filter_breakout = 1;
860
0
  sf->inter_sf.prune_compound_using_single_ref = 1;
861
0
  sf->inter_sf.prune_mode_search_simple_translation = 1;
862
0
  sf->inter_sf.prune_ref_frame_for_rect_partitions =
863
0
      (boosted || (allow_screen_content_tools))
864
0
          ? 0
865
0
          : (is_boosted_arf2_bwd_type ? 1 : 2);
866
0
  sf->inter_sf.reduce_inter_modes = boosted ? 1 : 2;
867
0
  sf->inter_sf.selective_ref_frame = 1;
868
0
  sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_SKIP_MV_SEARCH;
869
870
0
  sf->interp_sf.use_fast_interpolation_filter_search = 1;
871
872
0
  sf->intra_sf.intra_pruning_with_hog = 1;
873
874
0
  sf->tx_sf.adaptive_txb_search_level = 1;
875
0
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
876
0
  sf->tx_sf.model_based_prune_tx_search_level = 1;
877
0
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
878
879
0
  sf->tpl_sf.search_method = NSTEP_8PT;
880
881
0
  sf->rt_sf.use_nonrd_pick_mode = 0;
882
0
  sf->rt_sf.use_real_time_ref_set = 0;
883
884
0
  if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
885
0
      cpi->use_screen_content_tools) {
886
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
887
0
  } else {
888
0
    sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
889
0
  }
890
891
0
  sf->rd_sf.perform_coeff_opt = 1;
892
0
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
893
894
0
  if (speed >= 1) {
895
0
    sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2;
896
0
    sf->gm_sf.prune_ref_frame_for_gm_search = boosted ? 0 : 1;
897
898
0
    sf->part_sf.intra_cnn_based_part_prune_level =
899
0
        allow_screen_content_tools ? 0 : 2;
900
0
    sf->part_sf.simple_motion_search_early_term_none = 1;
901
    // TODO(Venkat): Clean-up frame type dependency for
902
    // simple_motion_search_split in partition search function and set the
903
    // speed feature accordingly
904
0
    sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
905
0
    sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
906
907
0
    sf->mv_sf.exhaustive_searches_thresh <<= 1;
908
0
    sf->mv_sf.obmc_full_pixel_search_level = 1;
909
0
    sf->mv_sf.use_accurate_subpel_search = USE_4_TAPS;
910
0
    sf->mv_sf.disable_extensive_joint_motion_search = 1;
911
912
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 2 : 1;
913
0
    sf->inter_sf.prune_comp_type_by_comp_avg = 1;
914
0
    sf->inter_sf.prune_comp_type_by_model_rd = boosted ? 0 : 1;
915
0
    sf->inter_sf.prune_ref_frame_for_rect_partitions =
916
0
        (frame_is_intra_only(&cpi->common) || (allow_screen_content_tools))
917
0
            ? 0
918
0
            : (boosted ? 1 : 2);
919
0
    sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
920
0
    sf->inter_sf.reuse_inter_intra_mode = 1;
921
0
    sf->inter_sf.selective_ref_frame = 2;
922
0
    sf->inter_sf.skip_arf_compound = 1;
923
924
0
    sf->interp_sf.use_interp_filter = 1;
925
926
0
    sf->intra_sf.prune_palette_search_level = 1;
927
928
0
    sf->tx_sf.adaptive_txb_search_level = 2;
929
0
    sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
930
0
    sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
931
0
    sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
932
0
    sf->tx_sf.model_based_prune_tx_search_level = 0;
933
0
    sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
934
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
935
0
    sf->tx_sf.tx_type_search.skip_tx_search = 1;
936
937
0
    sf->rd_sf.perform_coeff_opt = boosted ? 2 : 3;
938
0
    sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
939
0
    sf->rd_sf.tx_domain_dist_thres_level = 1;
940
941
0
    sf->lpf_sf.dual_sgr_penalty_level = 1;
942
0
    sf->lpf_sf.enable_sgr_ep_pruning = 1;
943
944
    // TODO(any, yunqing): move this feature to speed 0.
945
0
    sf->tpl_sf.skip_alike_starting_mv = 1;
946
0
  }
947
948
0
  if (speed >= 2) {
949
0
    sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
950
951
0
    sf->fp_sf.skip_motion_search_threshold = 25;
952
953
0
    sf->gm_sf.disable_gm_search_based_on_stats = 1;
954
955
0
    sf->part_sf.reuse_best_prediction_for_part_ab =
956
0
        !frame_is_intra_only(&cpi->common);
957
958
0
    sf->mv_sf.simple_motion_subpel_force_stop = QUARTER_PEL;
959
0
    sf->mv_sf.subpel_iters_per_step = 1;
960
0
    sf->mv_sf.reduce_search_range = 1;
961
962
    // TODO(chiyotsai@google.com): We can get 10% speed up if we move
963
    // adaptive_rd_thresh to speed 1. But currently it performs poorly on some
964
    // clips (e.g. 5% loss on dinner_1080p). We need to examine the sequence a
965
    // bit more closely to figure out why.
966
0
    sf->inter_sf.adaptive_rd_thresh = 1;
967
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
968
0
    sf->inter_sf.fast_interintra_wedge_search = 1;
969
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 1;
970
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 1;
971
0
    sf->inter_sf.prune_comp_using_best_single_mode_ref = 2;
972
0
    sf->inter_sf.prune_comp_type_by_comp_avg = 2;
973
0
    sf->inter_sf.selective_ref_frame = 3;
974
0
    sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
975
    // Enable fast search only for COMPOUND_DIFFWTD type.
976
0
    sf->inter_sf.enable_fast_compound_mode_search = 1;
977
0
    sf->inter_sf.reuse_mask_search_results = 1;
978
0
    sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 1;
979
0
    sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 1;
980
0
    sf->inter_sf.alt_ref_search_fp = 1;
981
982
0
    sf->interp_sf.adaptive_interp_filter_search = 1;
983
0
    sf->interp_sf.disable_dual_filter = 1;
984
985
0
    sf->intra_sf.disable_smooth_intra =
986
0
        !frame_is_intra_only(&cpi->common) || (cpi->rc.frames_to_key > 1);
987
0
    sf->intra_sf.intra_pruning_with_hog = 2;
988
0
    sf->intra_sf.skip_intra_in_interframe = is_inter_frame ? 2 : 1;
989
0
    sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
990
991
0
    sf->tpl_sf.prune_starting_mv = 1;
992
0
    sf->tpl_sf.search_method = DIAMOND;
993
994
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 3 : 4;
995
0
    sf->rd_sf.use_mb_rd_hash = 1;
996
997
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 1;
998
0
    sf->lpf_sf.prune_sgr_based_on_wiener = 1;
999
0
    sf->lpf_sf.disable_loop_restoration_chroma = boosted ? 0 : 1;
1000
0
    sf->lpf_sf.reduce_wiener_window_size = boosted ? 0 : 1;
1001
1002
    // TODO(any): Re-evaluate this feature set to 1 in speed 2.
1003
0
    sf->tpl_sf.allow_compound_pred = 0;
1004
0
    sf->tpl_sf.prune_ref_frames_in_tpl = 1;
1005
0
  }
1006
1007
0
  if (speed >= 3) {
1008
0
    sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
1009
1010
0
    sf->gm_sf.gm_search_type = GM_DISABLE_SEARCH;
1011
0
    sf->gm_sf.prune_zero_mv_with_sse = 1;
1012
1013
0
    sf->part_sf.less_rectangular_check_level = 2;
1014
0
    sf->part_sf.simple_motion_search_prune_agg =
1015
0
        allow_screen_content_tools
1016
0
            ? SIMPLE_AGG_LVL0
1017
0
            : (boosted ? SIMPLE_AGG_LVL1 : QIDX_BASED_AGG_LVL1);
1018
0
    sf->part_sf.prune_ext_part_using_split_info = 1;
1019
0
    sf->part_sf.simple_motion_search_rect_split = 1;
1020
1021
0
    sf->mv_sf.full_pixel_search_level = 1;
1022
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1023
0
    sf->mv_sf.search_method = DIAMOND;
1024
0
    sf->mv_sf.disable_second_mv = 2;
1025
0
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_1;
1026
1027
0
    sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
1028
0
    sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1029
0
    sf->inter_sf.disable_onesided_comp = 1;
1030
0
    sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1031
    // TODO(any): Experiment with the early exit mechanism for speeds 0, 1 and 2
1032
    // and clean-up the speed feature
1033
0
    sf->inter_sf.perform_best_rd_based_gating_for_chroma = 1;
1034
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 1;
1035
0
    sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 2;
1036
0
    sf->inter_sf.selective_ref_frame = 5;
1037
0
    sf->inter_sf.skip_repeated_ref_mv = 1;
1038
0
    sf->inter_sf.reuse_compound_type_decision = 1;
1039
0
    sf->inter_sf.txfm_rd_gate_level =
1040
0
        boosted ? 0 : (is_boosted_arf2_bwd_type ? 1 : 2);
1041
0
    sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 2;
1042
1043
0
    sf->interp_sf.adaptive_interp_filter_search = 2;
1044
1045
    // TODO(chiyotsai@google.com): the thresholds chosen for intra hog are
1046
    // inherited directly from luma hog with some minor tweaking. Eventually we
1047
    // should run this with a bayesian optimizer to find the Pareto frontier.
1048
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 2;
1049
0
    sf->intra_sf.intra_pruning_with_hog = 3;
1050
0
    sf->intra_sf.prune_palette_search_level = 2;
1051
0
    sf->intra_sf.top_intra_model_count_allowed = 2;
1052
1053
0
    sf->tpl_sf.prune_starting_mv = 2;
1054
0
    sf->tpl_sf.skip_alike_starting_mv = 2;
1055
0
    sf->tpl_sf.prune_intra_modes = 1;
1056
0
    sf->tpl_sf.reduce_first_step_size = 6;
1057
0
    sf->tpl_sf.subpel_force_stop = QUARTER_PEL;
1058
0
    sf->tpl_sf.gop_length_decision_method = 1;
1059
1060
0
    sf->tx_sf.adaptive_txb_search_level = boosted ? 2 : 3;
1061
0
    sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
1062
0
    sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
1063
1064
    // TODO(any): Refactor the code related to following winner mode speed
1065
    // features
1066
0
    sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
1067
0
    sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
1068
0
    sf->winner_mode_sf.motion_mode_for_winner_cand =
1069
0
        boosted ? 0
1070
0
                : gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE
1071
0
                      ? 1
1072
0
                      : 2;
1073
0
    sf->winner_mode_sf.disable_winner_mode_eval_for_txskip = boosted ? 0 : 1;
1074
1075
    // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
1076
    // loss.
1077
0
    sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
1078
0
    sf->lpf_sf.prune_wiener_based_on_src_var = 2;
1079
0
    sf->lpf_sf.use_coarse_filter_level_search =
1080
0
        frame_is_intra_only(&cpi->common) ? 0 : 1;
1081
0
    sf->lpf_sf.use_downsampled_wiener_stats = 1;
1082
0
  }
1083
1084
0
  if (speed >= 4) {
1085
0
    sf->gm_sf.prune_zero_mv_with_sse = 2;
1086
1087
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1088
1089
0
    sf->part_sf.simple_motion_search_prune_agg =
1090
0
        allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL2;
1091
0
    sf->part_sf.simple_motion_search_reduce_search_steps = 4;
1092
0
    sf->part_sf.prune_ext_part_using_split_info = 2;
1093
0
    sf->part_sf.ml_predict_breakout_level = 3;
1094
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
1095
0
        (allow_screen_content_tools || frame_is_intra_only(&cpi->common)) ? 0
1096
0
                                                                          : 1;
1097
1098
0
    sf->inter_sf.alt_ref_search_fp = 2;
1099
0
    sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 3;
1100
1101
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 2;
1102
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 2;
1103
0
    sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
1104
0
    sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
1105
0
    sf->inter_sf.prune_nearest_near_mv_using_refmv_weight = boosted ? 0 : 1;
1106
1107
0
    sf->interp_sf.cb_pred_filter_search = 1;
1108
0
    sf->interp_sf.skip_sharp_interp_filter_search = 1;
1109
0
    sf->interp_sf.use_interp_filter = 2;
1110
1111
0
    sf->intra_sf.intra_uv_mode_mask[TX_16X16] = UV_INTRA_DC_H_V_CFL;
1112
0
    sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC_H_V_CFL;
1113
0
    sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC_H_V_CFL;
1114
    // TODO(any): "intra_y_mode_mask" doesn't help much at speed 4.
1115
    // sf->intra_sf.intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
1116
    // sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
1117
    // sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC_H_V;
1118
0
    sf->intra_sf.skip_intra_in_interframe = 4;
1119
1120
0
    sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
1121
0
    sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
1122
1123
0
    sf->tpl_sf.subpel_force_stop = HALF_PEL;
1124
0
    sf->tpl_sf.search_method = FAST_BIGDIA;
1125
1126
0
    sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
1127
1128
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 5 : 7;
1129
1130
    // TODO(any): Extend multi-winner mode processing support for inter frames
1131
0
    sf->winner_mode_sf.multi_winner_mode_type =
1132
0
        frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_DEFAULT
1133
0
                                          : MULTI_WINNER_MODE_OFF;
1134
0
    sf->winner_mode_sf.dc_blk_pred_level = boosted ? 0 : 1;
1135
1136
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
1137
0
  }
1138
1139
0
  if (speed >= 5) {
1140
0
    sf->fp_sf.reduce_mv_step_param = 4;
1141
1142
0
    sf->part_sf.simple_motion_search_prune_agg =
1143
0
        allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL3;
1144
0
    sf->part_sf.ext_partition_eval_thresh =
1145
0
        allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
1146
0
    sf->part_sf.prune_sub_8x8_partition_level =
1147
0
        (allow_screen_content_tools || frame_is_intra_only(&cpi->common)) ? 0
1148
0
                                                                          : 2;
1149
1150
0
    sf->inter_sf.prune_inter_modes_if_skippable = 1;
1151
0
    sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 4;
1152
    // Enable fast search for all valid compound modes.
1153
0
    sf->inter_sf.enable_fast_compound_mode_search = 2;
1154
1155
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 3;
1156
1157
    // TODO(any): Extend multi-winner mode processing support for inter frames
1158
0
    sf->winner_mode_sf.multi_winner_mode_type =
1159
0
        frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_FAST
1160
0
                                          : MULTI_WINNER_MODE_OFF;
1161
1162
0
    sf->lpf_sf.disable_lr_filter = 1;
1163
1164
0
    sf->tpl_sf.prune_starting_mv = 3;
1165
0
    sf->tpl_sf.use_y_only_rate_distortion = 1;
1166
0
    sf->tpl_sf.subpel_force_stop = FULL_PEL;
1167
0
    sf->tpl_sf.gop_length_decision_method = 2;
1168
1169
0
    sf->winner_mode_sf.dc_blk_pred_level = 1;
1170
1171
0
    sf->fp_sf.disable_recon = 1;
1172
0
  }
1173
1174
0
  if (speed >= 6) {
1175
0
    sf->hl_sf.disable_extra_sc_testing = 1;
1176
0
    sf->hl_sf.second_alt_ref_filtering = 0;
1177
0
    sf->hl_sf.recode_tolerance = 55;
1178
1179
0
    sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 3;
1180
0
    sf->inter_sf.selective_ref_frame = 6;
1181
0
    sf->inter_sf.prune_ext_comp_using_neighbors = 3;
1182
1183
0
    sf->intra_sf.chroma_intra_pruning_with_hog = 4;
1184
0
    sf->intra_sf.intra_pruning_with_hog = 4;
1185
0
    sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC;
1186
0
    sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC;
1187
0
    sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC;
1188
0
    sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC;
1189
0
    sf->intra_sf.early_term_chroma_palette_size_search = 1;
1190
1191
0
    sf->part_sf.prune_rectangular_split_based_on_qidx =
1192
0
        boosted || allow_screen_content_tools ? 0 : 2;
1193
0
    sf->part_sf.prune_sub_8x8_partition_level =
1194
0
        allow_screen_content_tools ? 0
1195
0
                                   : frame_is_intra_only(&cpi->common) ? 1 : 2;
1196
0
    sf->part_sf.prune_part4_search = 3;
1197
1198
0
    sf->mv_sf.simple_motion_subpel_force_stop = FULL_PEL;
1199
0
    sf->mv_sf.use_bsize_dependent_search_method = 1;
1200
1201
0
    sf->tpl_sf.gop_length_decision_method = 3;
1202
0
    sf->tpl_sf.disable_filtered_key_tpl = 1;
1203
1204
0
    sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 6 : 8;
1205
1206
0
    sf->winner_mode_sf.dc_blk_pred_level = 2;
1207
0
    sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
1208
1209
0
    sf->fp_sf.skip_zeromv_motion_search = 1;
1210
0
  }
1211
0
}
1212
1213
static void set_rt_speed_feature_framesize_dependent(const AV1_COMP *const cpi,
1214
                                                     SPEED_FEATURES *const sf,
1215
0
                                                     int speed) {
1216
0
  const AV1_COMMON *const cm = &cpi->common;
1217
0
  const int boosted = frame_is_boosted(cpi);
1218
0
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
1219
0
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
1220
0
  const int is_360p_or_larger = AOMMIN(cm->width, cm->height) >= 360;
1221
1222
0
  if (!is_360p_or_larger) {
1223
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 1;
1224
0
    if (speed >= 5) sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
1225
0
    if (speed >= 7) sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1226
0
    if (speed >= 8) sf->rt_sf.use_nonrd_filter_search = 0;
1227
0
    if (speed >= 9) {
1228
0
      sf->rt_sf.use_comp_ref_nonrd = 0;
1229
0
      sf->rt_sf.nonrd_agressive_skip = 1;
1230
// TODO(kyslov) Re-enable when AV1 models are trained
1231
#if 0
1232
#if CONFIG_RT_ML_PARTITIONING
1233
      if (!frame_is_intra_only(cm)) {
1234
        sf->part_sf.partition_search_type = ML_BASED_PARTITION;
1235
        sf->rt_sf.reuse_inter_pred_nonrd = 0;
1236
      }
1237
#endif
1238
#endif
1239
0
    }
1240
0
  } else {
1241
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 2;
1242
0
    sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1243
0
    if (speed == 5) {
1244
0
      sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
1245
0
          boosted ? INT_MAX : 350;
1246
0
    }
1247
0
    if (speed == 8 && !cpi->ppi->use_svc) {
1248
0
      sf->rt_sf.short_circuit_low_temp_var = 0;
1249
0
      sf->rt_sf.use_nonrd_altref_frame = 1;
1250
0
    }
1251
0
    if (speed >= 9) {
1252
0
      sf->rt_sf.gf_length_lvl = 1;
1253
0
      sf->rt_sf.skip_cdef_sb = 1;
1254
0
    }
1255
0
  }
1256
0
  if (!is_480p_or_larger) {
1257
0
    if (speed == 7) {
1258
0
      sf->rt_sf.nonrd_check_partition_merge_mode = 2;
1259
0
    }
1260
0
    if (speed >= 8) {
1261
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE;
1262
0
      sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1263
0
    }
1264
0
    if (speed >= 9) {
1265
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1266
0
      sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1267
0
    }
1268
0
  }
1269
0
  if (!is_720p_or_larger) {
1270
0
    if (speed >= 9) {
1271
0
      sf->rt_sf.force_large_partition_blocks_intra = 1;
1272
0
    }
1273
0
  }
1274
0
  if (cpi->ppi->use_svc) {
1275
0
    sf->rt_sf.use_comp_ref_nonrd = 0;
1276
0
    if (cpi->svc.ref_frame_comp[0] || cpi->svc.ref_frame_comp[1] ||
1277
0
        cpi->svc.ref_frame_comp[2]) {
1278
0
      sf->rt_sf.use_comp_ref_nonrd = 1;
1279
0
      sf->rt_sf.ref_frame_comp_nonrd[0] =
1280
0
          cpi->svc.ref_frame_comp[0] && cpi->svc.reference[GOLDEN_FRAME - 1];
1281
0
      sf->rt_sf.ref_frame_comp_nonrd[1] =
1282
0
          cpi->svc.ref_frame_comp[1] && cpi->svc.reference[LAST2_FRAME - 1];
1283
0
      sf->rt_sf.ref_frame_comp_nonrd[2] =
1284
0
          cpi->svc.ref_frame_comp[2] && cpi->svc.reference[ALTREF_FRAME - 1];
1285
0
    }
1286
0
  }
1287
0
  if (cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN)
1288
0
    sf->rt_sf.use_comp_ref_nonrd = 0;
1289
0
}
1290
1291
// TODO(kyslov): now this is very similar to
1292
// set_good_speed_features_framesize_independent
1293
//               except it sets non-rd flag on speed8. This function will likely
1294
//               be modified in the future with RT-specific speed features
1295
static void set_rt_speed_features_framesize_independent(AV1_COMP *cpi,
1296
                                                        SPEED_FEATURES *sf,
1297
0
                                                        int speed) {
1298
0
  AV1_COMMON *const cm = &cpi->common;
1299
0
  const int boosted = frame_is_boosted(cpi);
1300
1301
  // Currently, rt speed 0, 1, 2, 3, 4, 5 are the same.
1302
  // Following set of speed features are not impacting encoder's decisions as
1303
  // the relevant tools are disabled by default.
1304
0
  sf->gm_sf.gm_search_type = GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2;
1305
0
  sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
1306
0
  sf->inter_sf.reuse_inter_intra_mode = 1;
1307
0
  sf->inter_sf.prune_compound_using_single_ref = 0;
1308
0
  sf->inter_sf.prune_comp_search_by_single_result = 2;
1309
0
  sf->inter_sf.prune_comp_type_by_comp_avg = 2;
1310
0
  sf->inter_sf.fast_wedge_sign_estimate = 1;
1311
0
  sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
1312
0
  sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1313
0
  sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
1314
0
  sf->interp_sf.cb_pred_filter_search = 0;
1315
0
  sf->part_sf.ml_prune_partition = 1;
1316
0
  sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
1317
0
  sf->part_sf.prune_ext_partition_types_search_level = 2;
1318
0
  sf->part_sf.less_rectangular_check_level = 2;
1319
0
  sf->mv_sf.obmc_full_pixel_search_level = 1;
1320
0
  sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
1321
0
  sf->tx_sf.model_based_prune_tx_search_level = 0;
1322
0
  sf->lpf_sf.dual_sgr_penalty_level = 1;
1323
0
  sf->lpf_sf.disable_lr_filter = 1;
1324
0
  sf->rt_sf.skip_interp_filter_search = 1;
1325
  // End of set
1326
1327
  // TODO(any, yunqing): tune these features for real-time use cases.
1328
0
  sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_SOLO;
1329
0
  sf->hl_sf.frame_parameter_update = 0;
1330
1331
0
  sf->inter_sf.model_based_post_interp_filter_breakout = 1;
1332
  // TODO(any): As per the experiments, this speed feature is doing redundant
1333
  // computation since the model rd based pruning logic is similar to model rd
1334
  // based gating when inter_mode_rd_model_estimation = 2. Enable this SF if
1335
  // either of the condition becomes true.
1336
  //    (1) inter_mode_rd_model_estimation != 2
1337
  //    (2) skip_interp_filter_search == 0
1338
  //    (3) Motion mode or compound mode is enabled */
1339
0
  sf->inter_sf.prune_mode_search_simple_translation = 0;
1340
0
  sf->inter_sf.prune_ref_frame_for_rect_partitions = !boosted;
1341
0
  sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1342
0
  sf->inter_sf.selective_ref_frame = 4;
1343
0
  sf->inter_sf.alt_ref_search_fp = 2;
1344
0
  sf->inter_sf.txfm_rd_gate_level = boosted ? 0 : 4;
1345
1346
0
  sf->inter_sf.adaptive_rd_thresh = 4;
1347
0
  sf->inter_sf.inter_mode_rd_model_estimation = 2;
1348
0
  sf->inter_sf.prune_inter_modes_if_skippable = 1;
1349
0
  sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
1350
0
  sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
1351
0
  sf->inter_sf.skip_newmv_in_drl = 4;
1352
1353
0
  sf->interp_sf.use_fast_interpolation_filter_search = 1;
1354
0
  sf->interp_sf.use_interp_filter = 1;
1355
0
  sf->interp_sf.adaptive_interp_filter_search = 1;
1356
0
  sf->interp_sf.disable_dual_filter = 1;
1357
1358
0
  sf->part_sf.default_max_partition_size = BLOCK_128X128;
1359
0
  sf->part_sf.default_min_partition_size = BLOCK_8X8;
1360
0
  sf->part_sf.use_best_rd_for_pruning = 1;
1361
0
  sf->part_sf.early_term_after_none_split = 1;
1362
0
  sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
1363
0
  sf->part_sf.max_intra_bsize = BLOCK_16X16;
1364
0
  sf->part_sf.partition_search_breakout_rate_thr = 500;
1365
0
  sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
1366
0
  sf->part_sf.adjust_var_based_rd_partitioning = 2;
1367
1368
0
  sf->mv_sf.full_pixel_search_level = 1;
1369
0
  sf->mv_sf.exhaustive_searches_thresh = INT_MAX;
1370
0
  sf->mv_sf.auto_mv_step_size = 1;
1371
0
  sf->mv_sf.subpel_iters_per_step = 1;
1372
0
  sf->mv_sf.use_accurate_subpel_search = USE_2_TAPS;
1373
0
  sf->mv_sf.search_method = FAST_DIAMOND;
1374
0
  sf->mv_sf.subpel_force_stop = EIGHTH_PEL;
1375
0
  sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1376
1377
0
  for (int i = 0; i < TX_SIZES; ++i) {
1378
0
    sf->intra_sf.intra_y_mode_mask[i] = INTRA_DC;
1379
0
    sf->intra_sf.intra_uv_mode_mask[i] = UV_INTRA_DC_CFL;
1380
0
  }
1381
0
  sf->intra_sf.skip_intra_in_interframe = 5;
1382
0
  sf->intra_sf.disable_smooth_intra = 1;
1383
0
  sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1384
1385
0
  sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
1386
0
  sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
1387
0
  sf->tx_sf.adaptive_txb_search_level = 2;
1388
0
  sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
1389
0
  sf->tx_sf.tx_size_search_lgr_block = 1;
1390
0
  sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
1391
0
  sf->tx_sf.tx_type_search.skip_tx_search = 1;
1392
0
  sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
1393
0
  sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
1394
0
  sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
1395
0
  sf->tx_sf.refine_fast_tx_search_results = 0;
1396
0
  sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
1397
0
  sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
1398
0
  sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
1399
1400
0
  sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
1401
0
  sf->rd_sf.simple_model_rd_from_var = 1;
1402
0
  sf->rd_sf.tx_domain_dist_level = 2;
1403
0
  sf->rd_sf.tx_domain_dist_thres_level = 2;
1404
1405
0
  sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
1406
0
  sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
1407
1408
0
  sf->winner_mode_sf.dc_blk_pred_level = frame_is_intra_only(cm) ? 0 : 2;
1409
0
  sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
1410
0
  sf->winner_mode_sf.tx_size_search_level = 1;
1411
0
  sf->winner_mode_sf.winner_mode_ifs = 1;
1412
1413
0
  sf->rt_sf.check_intra_pred_nonrd = 1;
1414
0
  sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1415
0
  sf->rt_sf.hybrid_intra_pickmode = 1;
1416
0
  sf->rt_sf.use_comp_ref_nonrd = 0;
1417
0
  sf->rt_sf.ref_frame_comp_nonrd[0] = 0;
1418
0
  sf->rt_sf.ref_frame_comp_nonrd[1] = 0;
1419
0
  sf->rt_sf.ref_frame_comp_nonrd[2] = 0;
1420
0
  sf->rt_sf.use_nonrd_filter_search = 1;
1421
0
  sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
1422
0
  sf->rt_sf.num_inter_modes_for_tx_search = 5;
1423
0
  sf->rt_sf.prune_inter_modes_using_temp_var = 1;
1424
0
  sf->rt_sf.use_real_time_ref_set = 1;
1425
0
  sf->rt_sf.use_simple_rd_model = 1;
1426
0
  sf->rt_sf.prune_inter_modes_with_golden_ref = boosted ? 0 : 1;
1427
  // TODO(any): This sf could be removed.
1428
0
  sf->rt_sf.short_circuit_low_temp_var = 1;
1429
0
  sf->rt_sf.check_scene_detection = 1;
1430
0
  if (cpi->rc.rtc_external_ratectrl) sf->rt_sf.check_scene_detection = 0;
1431
0
  if (cm->current_frame.frame_type != KEY_FRAME &&
1432
0
      cpi->oxcf.rc_cfg.mode == AOM_CBR)
1433
0
    sf->rt_sf.overshoot_detection_cbr = FAST_DETECTION_MAXQ;
1434
  // Enable noise estimation only for high resolutions for now.
1435
  //
1436
  // Since use_temporal_noise_estimate has no effect for all-intra frame
1437
  // encoding, it is disabled for this case.
1438
0
  if (cpi->oxcf.kf_cfg.key_freq_max != 0 && cm->width * cm->height > 640 * 480)
1439
0
    sf->rt_sf.use_temporal_noise_estimate = 1;
1440
0
  sf->rt_sf.skip_tx_no_split_var_based_partition = 1;
1441
0
  sf->rt_sf.skip_newmv_mode_based_on_sse = 1;
1442
0
  sf->rt_sf.mode_search_skip_flags =
1443
0
      (cm->current_frame.frame_type == KEY_FRAME)
1444
0
          ? 0
1445
0
          : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
1446
0
                FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR |
1447
0
                FLAG_EARLY_TERMINATE;
1448
0
  sf->rt_sf.var_part_split_threshold_shift = 5;
1449
1450
  // For SVC: use better mv search on base temporal layers, and only
1451
  // on base spatial layer if highest resolution is above 640x360.
1452
0
  if (cpi->svc.number_temporal_layers > 1 &&
1453
0
      cpi->svc.temporal_layer_id < cpi->svc.number_temporal_layers - 1 &&
1454
0
      (cpi->svc.spatial_layer_id == 0 ||
1455
0
       cpi->oxcf.frm_dim_cfg.width * cpi->oxcf.frm_dim_cfg.height <=
1456
0
           640 * 360)) {
1457
0
    sf->mv_sf.search_method = NSTEP;
1458
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE;
1459
0
    sf->rt_sf.fullpel_search_step_param = 6;
1460
0
  }
1461
1462
0
  if (speed >= 6) {
1463
0
    sf->mv_sf.use_fullpel_costlist = 1;
1464
1465
0
    sf->rd_sf.tx_domain_dist_thres_level = 3;
1466
1467
0
    sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh = 0;
1468
0
    sf->inter_sf.limit_inter_mode_cands = 4;
1469
0
    sf->inter_sf.limit_txfm_eval_per_mode = 3;
1470
0
    sf->inter_sf.prune_warped_prob_thresh = 8;
1471
0
    sf->inter_sf.extra_prune_warped = 1;
1472
1473
0
    sf->rt_sf.gf_refresh_based_on_qp = 1;
1474
0
    sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
1475
0
    sf->rt_sf.var_part_split_threshold_shift = 7;
1476
0
  }
1477
1478
0
  if (speed >= 7) {
1479
0
    sf->rt_sf.use_comp_ref_nonrd = 1;
1480
0
    sf->rt_sf.ref_frame_comp_nonrd[2] = 1;  // LAST_ALTREF
1481
0
    sf->tx_sf.intra_tx_size_search_init_depth_sqr = 2;
1482
0
    sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
1483
0
    sf->part_sf.max_intra_bsize = BLOCK_32X32;
1484
1485
0
    sf->gm_sf.gm_search_type = GM_DISABLE_SEARCH;
1486
1487
0
    sf->mv_sf.search_method = FAST_DIAMOND;
1488
0
    sf->mv_sf.subpel_force_stop = QUARTER_PEL;
1489
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1490
1491
0
    sf->inter_sf.inter_mode_rd_model_estimation = 2;
1492
    // This sf is not applicable in non-rd path.
1493
0
    sf->inter_sf.skip_newmv_in_drl = 0;
1494
1495
    // Disable intra_y_mode_mask pruning since the performance at speed 7 isn't
1496
    // good. May need more study.
1497
0
    for (int i = 0; i < TX_SIZES; ++i) {
1498
0
      sf->intra_sf.intra_y_mode_mask[i] = INTRA_ALL;
1499
0
    }
1500
1501
0
    sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
1502
0
    sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL5;
1503
1504
0
    sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
1505
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1506
    // This is for rd path only.
1507
0
    sf->rt_sf.prune_inter_modes_using_temp_var = 0;
1508
0
    sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
1509
0
    sf->rt_sf.prune_intra_mode_based_on_mv_range = 0;
1510
0
#if !CONFIG_REALTIME_ONLY
1511
0
    sf->rt_sf.reuse_inter_pred_nonrd =
1512
0
        (cpi->oxcf.motion_mode_cfg.enable_warped_motion == 0);
1513
#else
1514
    sf->rt_sf.reuse_inter_pred_nonrd = 1;
1515
#endif
1516
#if CONFIG_AV1_TEMPORAL_DENOISING
1517
    sf->rt_sf.reuse_inter_pred_nonrd = (cpi->oxcf.noise_sensitivity == 0);
1518
#endif
1519
0
    sf->rt_sf.short_circuit_low_temp_var = 0;
1520
0
    sf->rt_sf.skip_interp_filter_search = 0;
1521
    // For spatial layers, only LAST and GOLDEN are currently used in the SVC
1522
    // for nonrd. The flag use_nonrd_altref_frame can disable GOLDEN in the
1523
    // get_ref_frame_flags() for some patterns, so disable it here for
1524
    // spatial layers.
1525
0
    sf->rt_sf.use_nonrd_altref_frame =
1526
0
        (cpi->svc.number_spatial_layers > 1) ? 0 : 1;
1527
0
    sf->rt_sf.use_nonrd_pick_mode = 1;
1528
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 1;
1529
0
    sf->rt_sf.nonrd_check_partition_split = 0;
1530
0
    sf->rt_sf.skip_intra_pred_if_tx_skip = 1;
1531
0
    sf->rt_sf.source_metrics_sb_nonrd = 1;
1532
    // For SVC: use better mv search on base temporal layers, and only
1533
    // on base spatial layer if highest resolution is above 640x360.
1534
0
    if (cpi->svc.number_temporal_layers > 1 &&
1535
0
        cpi->svc.temporal_layer_id < cpi->svc.number_temporal_layers - 1 &&
1536
0
        (cpi->svc.spatial_layer_id == 0 ||
1537
0
         cpi->oxcf.frm_dim_cfg.width * cpi->oxcf.frm_dim_cfg.height <=
1538
0
             640 * 360)) {
1539
0
      sf->mv_sf.search_method = NSTEP;
1540
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE;
1541
0
      sf->rt_sf.fullpel_search_step_param = 6;
1542
0
    } else if (cpi->svc.non_reference_frame) {
1543
0
      sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1544
0
      sf->rt_sf.fullpel_search_step_param = 10;
1545
0
    }
1546
    // Set mask for intra modes.
1547
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
1548
0
      if (i >= BLOCK_32X32)
1549
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1550
0
      else
1551
        // Use DC, H, V intra mode for block sizes < 32X32.
1552
0
        sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
1553
1554
0
    sf->winner_mode_sf.dc_blk_pred_level = 0;
1555
0
  }
1556
1557
0
  if (speed >= 8) {
1558
0
    sf->intra_sf.intra_pruning_with_hog = 1;
1559
0
    sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1560
0
    sf->rt_sf.short_circuit_low_temp_var = 1;
1561
0
    sf->rt_sf.use_nonrd_altref_frame = 0;
1562
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 2;
1563
0
    sf->rt_sf.nonrd_check_partition_merge_mode = 0;
1564
0
    sf->rt_sf.nonrd_check_partition_split = 0;
1565
0
    sf->rt_sf.skip_intra_pred_if_tx_skip = 0;
1566
0
    sf->rt_sf.var_part_split_threshold_shift = 8;
1567
0
    sf->interp_sf.cb_pred_filter_search = 1;
1568
0
  }
1569
0
  if (speed >= 9) {
1570
0
    sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1571
0
    sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1572
0
    sf->rt_sf.force_large_partition_blocks = 1;
1573
0
    sf->rt_sf.var_part_split_threshold_shift = 9;
1574
0
    for (int i = 0; i < BLOCK_SIZES; ++i)
1575
0
      sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1576
0
  }
1577
0
  if (speed >= 10) {
1578
0
    sf->rt_sf.skip_intra_pred_if_tx_skip = 1;
1579
0
    sf->rt_sf.nonrd_agressive_skip = 1;
1580
0
    sf->rt_sf.nonrd_prune_ref_frame_search = 3;
1581
0
    sf->rt_sf.var_part_split_threshold_shift = 10;
1582
0
    sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1583
0
    sf->rt_sf.force_half_pel_block = 1;
1584
0
  }
1585
0
}
1586
1587
3.78k
static AOM_INLINE void init_hl_sf(HIGH_LEVEL_SPEED_FEATURES *hl_sf) {
1588
  // best quality defaults
1589
3.78k
  hl_sf->frame_parameter_update = 1;
1590
3.78k
  hl_sf->recode_loop = ALLOW_RECODE;
1591
  // Recode loop tolerance %.
1592
3.78k
  hl_sf->recode_tolerance = 25;
1593
3.78k
  hl_sf->high_precision_mv_usage = CURRENT_Q;
1594
3.78k
  hl_sf->superres_auto_search_type = SUPERRES_AUTO_ALL;
1595
3.78k
  hl_sf->disable_extra_sc_testing = 0;
1596
3.78k
  hl_sf->second_alt_ref_filtering = 1;
1597
3.78k
}
1598
1599
3.78k
static AOM_INLINE void init_fp_sf(FIRST_PASS_SPEED_FEATURES *fp_sf) {
1600
3.78k
  fp_sf->reduce_mv_step_param = 3;
1601
3.78k
  fp_sf->skip_motion_search_threshold = 0;
1602
3.78k
  fp_sf->disable_recon = 0;
1603
3.78k
  fp_sf->skip_zeromv_motion_search = 0;
1604
3.78k
}
1605
1606
3.78k
static AOM_INLINE void init_tpl_sf(TPL_SPEED_FEATURES *tpl_sf) {
1607
3.78k
  tpl_sf->gop_length_decision_method = 0;
1608
3.78k
  tpl_sf->prune_intra_modes = 0;
1609
3.78k
  tpl_sf->prune_starting_mv = 0;
1610
3.78k
  tpl_sf->reduce_first_step_size = 0;
1611
3.78k
  tpl_sf->skip_alike_starting_mv = 0;
1612
3.78k
  tpl_sf->subpel_force_stop = EIGHTH_PEL;
1613
3.78k
  tpl_sf->search_method = NSTEP;
1614
3.78k
  tpl_sf->disable_filtered_key_tpl = 0;
1615
3.78k
  tpl_sf->prune_ref_frames_in_tpl = 0;
1616
3.78k
  tpl_sf->allow_compound_pred = 1;
1617
3.78k
  tpl_sf->use_y_only_rate_distortion = 0;
1618
3.78k
}
1619
1620
3.78k
static AOM_INLINE void init_gm_sf(GLOBAL_MOTION_SPEED_FEATURES *gm_sf) {
1621
3.78k
  gm_sf->gm_search_type = GM_FULL_SEARCH;
1622
3.78k
  gm_sf->prune_ref_frame_for_gm_search = 0;
1623
3.78k
  gm_sf->prune_zero_mv_with_sse = 0;
1624
3.78k
  gm_sf->disable_gm_search_based_on_stats = 0;
1625
3.78k
}
1626
1627
3.78k
static AOM_INLINE void init_part_sf(PARTITION_SPEED_FEATURES *part_sf) {
1628
3.78k
  part_sf->partition_search_type = SEARCH_PARTITION;
1629
3.78k
  part_sf->less_rectangular_check_level = 0;
1630
3.78k
  part_sf->use_square_partition_only_threshold = BLOCK_128X128;
1631
3.78k
  part_sf->auto_max_partition_based_on_simple_motion = NOT_IN_USE;
1632
3.78k
  part_sf->default_max_partition_size = BLOCK_LARGEST;
1633
3.78k
  part_sf->default_min_partition_size = BLOCK_4X4;
1634
3.78k
  part_sf->adjust_var_based_rd_partitioning = 0;
1635
3.78k
  part_sf->max_intra_bsize = BLOCK_LARGEST;
1636
  // This setting only takes effect when partition_search_type is set
1637
  // to FIXED_PARTITION.
1638
3.78k
  part_sf->fixed_partition_size = BLOCK_16X16;
1639
  // Recode loop tolerance %.
1640
3.78k
  part_sf->partition_search_breakout_dist_thr = 0;
1641
3.78k
  part_sf->partition_search_breakout_rate_thr = 0;
1642
3.78k
  part_sf->prune_ext_partition_types_search_level = 0;
1643
3.78k
  part_sf->prune_part4_search = 0;
1644
3.78k
  part_sf->ml_prune_partition = 0;
1645
3.78k
  part_sf->ml_early_term_after_part_split_level = 0;
1646
22.7k
  for (int i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
1647
18.9k
    part_sf->ml_partition_search_breakout_thresh[i] =
1648
18.9k
        -1;  // -1 means not enabled.
1649
18.9k
  }
1650
3.78k
  part_sf->simple_motion_search_prune_agg = SIMPLE_AGG_LVL0;
1651
3.78k
  part_sf->simple_motion_search_split = 0;
1652
3.78k
  part_sf->simple_motion_search_prune_rect = 0;
1653
3.78k
  part_sf->simple_motion_search_early_term_none = 0;
1654
3.78k
  part_sf->simple_motion_search_reduce_search_steps = 0;
1655
3.78k
  part_sf->intra_cnn_based_part_prune_level = 0;
1656
3.78k
  part_sf->ext_partition_eval_thresh = BLOCK_8X8;
1657
3.78k
  part_sf->rect_partition_eval_thresh = BLOCK_128X128;
1658
3.78k
  part_sf->prune_ext_part_using_split_info = 0;
1659
3.78k
  part_sf->prune_rectangular_split_based_on_qidx = 0;
1660
3.78k
  part_sf->early_term_after_none_split = 0;
1661
3.78k
  part_sf->ml_predict_breakout_level = 0;
1662
3.78k
  part_sf->prune_sub_8x8_partition_level = 0;
1663
3.78k
  part_sf->simple_motion_search_rect_split = 0;
1664
3.78k
  part_sf->reuse_prev_rd_results_for_part_ab = 0;
1665
3.78k
  part_sf->reuse_best_prediction_for_part_ab = 0;
1666
3.78k
  part_sf->use_best_rd_for_pruning = 0;
1667
3.78k
  part_sf->skip_non_sq_part_based_on_none = 0;
1668
3.78k
}
1669
1670
3.78k
static AOM_INLINE void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
1671
3.78k
  mv_sf->full_pixel_search_level = 0;
1672
3.78k
  mv_sf->auto_mv_step_size = 0;
1673
3.78k
  mv_sf->exhaustive_searches_thresh = 0;
1674
3.78k
  mv_sf->obmc_full_pixel_search_level = 0;
1675
3.78k
  mv_sf->prune_mesh_search = PRUNE_MESH_SEARCH_DISABLED;
1676
3.78k
  mv_sf->reduce_search_range = 0;
1677
3.78k
  mv_sf->search_method = NSTEP;
1678
3.78k
  mv_sf->simple_motion_subpel_force_stop = EIGHTH_PEL;
1679
3.78k
  mv_sf->subpel_force_stop = EIGHTH_PEL;
1680
3.78k
  mv_sf->subpel_iters_per_step = 2;
1681
3.78k
  mv_sf->subpel_search_method = SUBPEL_TREE;
1682
3.78k
  mv_sf->use_accurate_subpel_search = USE_8_TAPS;
1683
3.78k
  mv_sf->use_bsize_dependent_search_method = 0;
1684
3.78k
  mv_sf->use_fullpel_costlist = 0;
1685
3.78k
  mv_sf->use_downsampled_sad = 0;
1686
3.78k
  mv_sf->disable_extensive_joint_motion_search = 0;
1687
3.78k
  mv_sf->disable_second_mv = 0;
1688
3.78k
}
1689
1690
3.78k
static AOM_INLINE void init_inter_sf(INTER_MODE_SPEED_FEATURES *inter_sf) {
1691
3.78k
  inter_sf->adaptive_rd_thresh = 0;
1692
3.78k
  inter_sf->model_based_post_interp_filter_breakout = 0;
1693
3.78k
  inter_sf->reduce_inter_modes = 0;
1694
3.78k
  inter_sf->alt_ref_search_fp = 0;
1695
3.78k
  inter_sf->selective_ref_frame = 0;
1696
3.78k
  inter_sf->prune_ref_frame_for_rect_partitions = 0;
1697
3.78k
  inter_sf->fast_wedge_sign_estimate = 0;
1698
3.78k
  inter_sf->use_dist_wtd_comp_flag = DIST_WTD_COMP_ENABLED;
1699
3.78k
  inter_sf->reuse_inter_intra_mode = 0;
1700
3.78k
  inter_sf->mv_cost_upd_level = INTERNAL_COST_UPD_SB;
1701
3.78k
  inter_sf->coeff_cost_upd_level = INTERNAL_COST_UPD_SB;
1702
3.78k
  inter_sf->mode_cost_upd_level = INTERNAL_COST_UPD_SB;
1703
3.78k
  inter_sf->prune_inter_modes_based_on_tpl = 0;
1704
3.78k
  inter_sf->prune_nearmv_using_neighbors = PRUNE_NEARMV_OFF;
1705
3.78k
  inter_sf->prune_comp_search_by_single_result = 0;
1706
3.78k
  inter_sf->skip_repeated_ref_mv = 0;
1707
3.78k
  inter_sf->skip_newmv_in_drl = 0;
1708
3.78k
  inter_sf->inter_mode_rd_model_estimation = 0;
1709
3.78k
  inter_sf->prune_compound_using_single_ref = 0;
1710
3.78k
  inter_sf->prune_ext_comp_using_neighbors = 0;
1711
3.78k
  inter_sf->skip_ext_comp_nearmv_mode = 0;
1712
3.78k
  inter_sf->prune_comp_using_best_single_mode_ref = 0;
1713
3.78k
  inter_sf->prune_nearest_near_mv_using_refmv_weight = 0;
1714
3.78k
  inter_sf->disable_onesided_comp = 0;
1715
3.78k
  inter_sf->prune_mode_search_simple_translation = 0;
1716
3.78k
  inter_sf->prune_comp_type_by_comp_avg = 0;
1717
3.78k
  inter_sf->disable_interinter_wedge_newmv_search = 0;
1718
3.78k
  inter_sf->fast_interintra_wedge_search = 0;
1719
3.78k
  inter_sf->prune_comp_type_by_model_rd = 0;
1720
3.78k
  inter_sf->perform_best_rd_based_gating_for_chroma = 0;
1721
3.78k
  inter_sf->prune_obmc_prob_thresh = 0;
1722
3.78k
  inter_sf->disable_interinter_wedge_var_thresh = 0;
1723
3.78k
  inter_sf->disable_interintra_wedge_var_thresh = 0;
1724
3.78k
  inter_sf->prune_ref_mv_idx_search = 0;
1725
3.78k
  inter_sf->prune_warped_prob_thresh = 0;
1726
3.78k
  inter_sf->reuse_compound_type_decision = 0;
1727
3.78k
  inter_sf->txfm_rd_gate_level = 0;
1728
3.78k
  inter_sf->prune_inter_modes_if_skippable = 0;
1729
3.78k
  inter_sf->disable_masked_comp = 0;
1730
3.78k
  inter_sf->enable_fast_compound_mode_search = 0;
1731
3.78k
  inter_sf->reuse_mask_search_results = 0;
1732
3.78k
  inter_sf->enable_fast_wedge_mask_search = 0;
1733
3.78k
  inter_sf->inter_mode_txfm_breakout = 0;
1734
3.78k
  inter_sf->limit_inter_mode_cands = 0;
1735
3.78k
  inter_sf->limit_txfm_eval_per_mode = 0;
1736
3.78k
  inter_sf->skip_arf_compound = 0;
1737
3.78k
}
1738
1739
3.78k
static AOM_INLINE void init_interp_sf(INTERP_FILTER_SPEED_FEATURES *interp_sf) {
1740
3.78k
  interp_sf->adaptive_interp_filter_search = 0;
1741
3.78k
  interp_sf->cb_pred_filter_search = 0;
1742
3.78k
  interp_sf->disable_dual_filter = 0;
1743
3.78k
  interp_sf->skip_sharp_interp_filter_search = 0;
1744
3.78k
  interp_sf->use_fast_interpolation_filter_search = 0;
1745
3.78k
  interp_sf->use_interp_filter = 0;
1746
3.78k
}
1747
1748
3.78k
static AOM_INLINE void init_intra_sf(INTRA_MODE_SPEED_FEATURES *intra_sf) {
1749
3.78k
  intra_sf->dv_cost_upd_level = INTERNAL_COST_UPD_SB;
1750
3.78k
  intra_sf->skip_intra_in_interframe = 1;
1751
3.78k
  intra_sf->intra_pruning_with_hog = 0;
1752
3.78k
  intra_sf->chroma_intra_pruning_with_hog = 0;
1753
3.78k
  intra_sf->prune_palette_search_level = 0;
1754
3.78k
  intra_sf->prune_luma_palette_size_search_level = 0;
1755
1756
22.7k
  for (int i = 0; i < TX_SIZES; i++) {
1757
18.9k
    intra_sf->intra_y_mode_mask[i] = INTRA_ALL;
1758
18.9k
    intra_sf->intra_uv_mode_mask[i] = UV_INTRA_ALL;
1759
18.9k
  }
1760
3.78k
  intra_sf->disable_smooth_intra = 0;
1761
3.78k
  intra_sf->prune_filter_intra_level = 0;
1762
3.78k
  intra_sf->prune_chroma_modes_using_luma_winner = 0;
1763
3.78k
  intra_sf->cfl_search_range = 3;
1764
3.78k
  intra_sf->top_intra_model_count_allowed = TOP_INTRA_MODEL_COUNT;
1765
3.78k
  intra_sf->adapt_top_model_rd_count_using_neighbors = 0;
1766
3.78k
  intra_sf->early_term_chroma_palette_size_search = 0;
1767
3.78k
  intra_sf->skip_filter_intra_in_inter_frames = 0;
1768
3.78k
}
1769
1770
3.78k
static AOM_INLINE void init_tx_sf(TX_SPEED_FEATURES *tx_sf) {
1771
3.78k
  tx_sf->inter_tx_size_search_init_depth_sqr = 0;
1772
3.78k
  tx_sf->inter_tx_size_search_init_depth_rect = 0;
1773
3.78k
  tx_sf->intra_tx_size_search_init_depth_rect = 0;
1774
3.78k
  tx_sf->intra_tx_size_search_init_depth_sqr = 0;
1775
3.78k
  tx_sf->tx_size_search_lgr_block = 0;
1776
3.78k
  tx_sf->model_based_prune_tx_search_level = 0;
1777
3.78k
  tx_sf->tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_1;
1778
3.78k
  tx_sf->tx_type_search.ml_tx_split_thresh = 8500;
1779
3.78k
  tx_sf->tx_type_search.use_skip_flag_prediction = 1;
1780
3.78k
  tx_sf->tx_type_search.use_reduced_intra_txset = 0;
1781
3.78k
  tx_sf->tx_type_search.fast_intra_tx_type_search = 0;
1782
3.78k
  tx_sf->tx_type_search.fast_inter_tx_type_prob_thresh = INT_MAX;
1783
3.78k
  tx_sf->tx_type_search.skip_tx_search = 0;
1784
3.78k
  tx_sf->tx_type_search.prune_tx_type_using_stats = 0;
1785
3.78k
  tx_sf->tx_type_search.prune_tx_type_est_rd = 0;
1786
3.78k
  tx_sf->tx_type_search.winner_mode_tx_type_pruning = 0;
1787
3.78k
  tx_sf->txb_split_cap = 1;
1788
3.78k
  tx_sf->adaptive_txb_search_level = 0;
1789
3.78k
  tx_sf->refine_fast_tx_search_results = 1;
1790
3.78k
  tx_sf->prune_tx_size_level = 0;
1791
3.78k
}
1792
1793
static AOM_INLINE void init_rd_sf(RD_CALC_SPEED_FEATURES *rd_sf,
1794
3.78k
                                  const AV1EncoderConfig *oxcf) {
1795
3.78k
  const int disable_trellis_quant = oxcf->algo_cfg.disable_trellis_quant;
1796
3.78k
  if (disable_trellis_quant == 3) {
1797
3.78k
    rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
1798
3.78k
                                       ? NO_ESTIMATE_YRD_TRELLIS_OPT
1799
3.78k
                                       : NO_TRELLIS_OPT;
1800
3.78k
  } else if (disable_trellis_quant == 2) {
1801
0
    rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
1802
0
                                       ? FINAL_PASS_TRELLIS_OPT
1803
0
                                       : NO_TRELLIS_OPT;
1804
0
  } else if (disable_trellis_quant == 0) {
1805
0
    if (is_lossless_requested(&oxcf->rc_cfg)) {
1806
0
      rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
1807
0
    } else {
1808
0
      rd_sf->optimize_coefficients = FULL_TRELLIS_OPT;
1809
0
    }
1810
0
  } else if (disable_trellis_quant == 1) {
1811
0
    rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
1812
0
  } else {
1813
0
    assert(0 && "Invalid disable_trellis_quant value");
1814
0
  }
1815
3.78k
  rd_sf->use_mb_rd_hash = 0;
1816
3.78k
  rd_sf->simple_model_rd_from_var = 0;
1817
3.78k
  rd_sf->tx_domain_dist_level = 0;
1818
3.78k
  rd_sf->tx_domain_dist_thres_level = 0;
1819
3.78k
  rd_sf->perform_coeff_opt = 0;
1820
3.78k
}
1821
1822
static AOM_INLINE void init_winner_mode_sf(
1823
3.78k
    WINNER_MODE_SPEED_FEATURES *winner_mode_sf) {
1824
3.78k
  winner_mode_sf->motion_mode_for_winner_cand = 0;
1825
  // Set this at the appropriate speed levels
1826
3.78k
  winner_mode_sf->tx_size_search_level = 0;
1827
3.78k
  winner_mode_sf->enable_winner_mode_for_coeff_opt = 0;
1828
3.78k
  winner_mode_sf->enable_winner_mode_for_tx_size_srch = 0;
1829
3.78k
  winner_mode_sf->enable_winner_mode_for_use_tx_domain_dist = 0;
1830
3.78k
  winner_mode_sf->multi_winner_mode_type = 0;
1831
3.78k
  winner_mode_sf->dc_blk_pred_level = 0;
1832
3.78k
  winner_mode_sf->winner_mode_ifs = 0;
1833
3.78k
  winner_mode_sf->prune_winner_mode_processing_using_src_var = 0;
1834
3.78k
  winner_mode_sf->disable_winner_mode_eval_for_txskip = 0;
1835
3.78k
}
1836
1837
3.78k
static AOM_INLINE void init_lpf_sf(LOOP_FILTER_SPEED_FEATURES *lpf_sf) {
1838
3.78k
  lpf_sf->disable_loop_restoration_chroma = 0;
1839
3.78k
  lpf_sf->disable_loop_restoration_luma = 0;
1840
3.78k
  lpf_sf->prune_wiener_based_on_src_var = 0;
1841
3.78k
  lpf_sf->prune_sgr_based_on_wiener = 0;
1842
3.78k
  lpf_sf->enable_sgr_ep_pruning = 0;
1843
3.78k
  lpf_sf->reduce_wiener_window_size = 0;
1844
3.78k
  lpf_sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
1845
3.78k
  lpf_sf->use_coarse_filter_level_search = 0;
1846
3.78k
  lpf_sf->cdef_pick_method = CDEF_FULL_SEARCH;
1847
  // Set decoder side speed feature to use less dual sgr modes
1848
3.78k
  lpf_sf->dual_sgr_penalty_level = 0;
1849
3.78k
  lpf_sf->disable_lr_filter = 0;
1850
3.78k
  lpf_sf->use_downsampled_wiener_stats = 0;
1851
3.78k
}
1852
1853
3.78k
static AOM_INLINE void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
1854
3.78k
  rt_sf->check_intra_pred_nonrd = 0;
1855
3.78k
  rt_sf->skip_intra_pred_if_tx_skip = 0;
1856
3.78k
  rt_sf->estimate_motion_for_var_based_partition = 0;
1857
3.78k
  rt_sf->nonrd_check_partition_merge_mode = 0;
1858
3.78k
  rt_sf->nonrd_check_partition_split = 0;
1859
3.78k
  rt_sf->mode_search_skip_flags = 0;
1860
3.78k
  rt_sf->nonrd_prune_ref_frame_search = 0;
1861
3.78k
  rt_sf->use_nonrd_pick_mode = 0;
1862
3.78k
  rt_sf->use_nonrd_altref_frame = 0;
1863
3.78k
  rt_sf->use_comp_ref_nonrd = 0;
1864
3.78k
  rt_sf->use_real_time_ref_set = 0;
1865
3.78k
  rt_sf->short_circuit_low_temp_var = 0;
1866
3.78k
  rt_sf->use_modeled_non_rd_cost = 0;
1867
3.78k
  rt_sf->reuse_inter_pred_nonrd = 0;
1868
3.78k
  rt_sf->num_inter_modes_for_tx_search = INT_MAX;
1869
3.78k
  rt_sf->use_nonrd_filter_search = 0;
1870
3.78k
  rt_sf->use_simple_rd_model = 0;
1871
3.78k
  rt_sf->skip_interp_filter_search = 0;
1872
3.78k
  rt_sf->hybrid_intra_pickmode = 0;
1873
3.78k
  rt_sf->source_metrics_sb_nonrd = 0;
1874
3.78k
  rt_sf->overshoot_detection_cbr = NO_DETECTION;
1875
3.78k
  rt_sf->check_scene_detection = 0;
1876
3.78k
  rt_sf->force_large_partition_blocks = 0;
1877
3.78k
  rt_sf->use_temporal_noise_estimate = 0;
1878
3.78k
  rt_sf->fullpel_search_step_param = 0;
1879
64.3k
  for (int i = 0; i < BLOCK_SIZES; ++i)
1880
60.5k
    rt_sf->intra_y_mode_bsize_mask_nrd[i] = INTRA_ALL;
1881
3.78k
  rt_sf->nonrd_agressive_skip = 0;
1882
3.78k
  rt_sf->skip_cdef_sb = 0;
1883
3.78k
  rt_sf->force_large_partition_blocks_intra = 0;
1884
3.78k
  rt_sf->skip_tx_no_split_var_based_partition = 0;
1885
3.78k
  rt_sf->skip_newmv_mode_based_on_sse = 0;
1886
3.78k
  rt_sf->gf_length_lvl = 0;
1887
3.78k
  rt_sf->prune_inter_modes_with_golden_ref = 0;
1888
3.78k
  rt_sf->prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
1889
3.78k
  rt_sf->prune_inter_modes_using_temp_var = 0;
1890
3.78k
  rt_sf->force_half_pel_block = 0;
1891
3.78k
  rt_sf->prune_intra_mode_based_on_mv_range = 0;
1892
3.78k
  rt_sf->var_part_split_threshold_shift = 7;
1893
3.78k
  rt_sf->gf_refresh_based_on_qp = 0;
1894
3.78k
}
1895
1896
3.78k
void av1_set_speed_features_framesize_dependent(AV1_COMP *cpi, int speed) {
1897
3.78k
  SPEED_FEATURES *const sf = &cpi->sf;
1898
3.78k
  const AV1EncoderConfig *const oxcf = &cpi->oxcf;
1899
1900
3.78k
  switch (oxcf->mode) {
1901
0
    case GOOD:
1902
0
      set_good_speed_feature_framesize_dependent(cpi, sf, speed);
1903
0
      break;
1904
3.78k
    case ALLINTRA:
1905
3.78k
      set_allintra_speed_feature_framesize_dependent(cpi, sf, speed);
1906
3.78k
      break;
1907
0
    case REALTIME:
1908
0
      set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
1909
0
      break;
1910
3.78k
  }
1911
1912
3.78k
  if (!cpi->ppi->seq_params_locked) {
1913
3.78k
    cpi->common.seq_params->enable_masked_compound &=
1914
3.78k
        !sf->inter_sf.disable_masked_comp;
1915
3.78k
    cpi->common.seq_params->enable_interintra_compound &=
1916
3.78k
        (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
1917
3.78k
  }
1918
1919
  // This is only used in motion vector unit test.
1920
3.78k
  if (cpi->oxcf.unit_test_cfg.motion_vector_unit_test == 1)
1921
0
    cpi->mv_search_params.find_fractional_mv_step = av1_return_max_sub_pixel_mv;
1922
3.78k
  else if (cpi->oxcf.unit_test_cfg.motion_vector_unit_test == 2)
1923
0
    cpi->mv_search_params.find_fractional_mv_step = av1_return_min_sub_pixel_mv;
1924
1925
  // For multi-thread use case with row_mt enabled, cost update for a set of
1926
  // SB rows is not desirable. Hence, the sf mv_cost_upd_level is set to
1927
  // INTERNAL_COST_UPD_SBROW in such cases.
1928
3.78k
  if ((cpi->oxcf.row_mt == 1) && (cpi->mt_info.num_workers > 1)) {
1929
628
    if (sf->inter_sf.mv_cost_upd_level == INTERNAL_COST_UPD_SBROW_SET) {
1930
      // Set mv_cost_upd_level to use row level update.
1931
0
      sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1932
0
    }
1933
628
  }
1934
3.78k
}
1935
1936
3.78k
void av1_set_speed_features_framesize_independent(AV1_COMP *cpi, int speed) {
1937
3.78k
  SPEED_FEATURES *const sf = &cpi->sf;
1938
3.78k
  WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
1939
3.78k
  const AV1EncoderConfig *const oxcf = &cpi->oxcf;
1940
3.78k
  int i;
1941
1942
3.78k
  init_hl_sf(&sf->hl_sf);
1943
3.78k
  init_fp_sf(&sf->fp_sf);
1944
3.78k
  init_tpl_sf(&sf->tpl_sf);
1945
3.78k
  init_gm_sf(&sf->gm_sf);
1946
3.78k
  init_part_sf(&sf->part_sf);
1947
3.78k
  init_mv_sf(&sf->mv_sf);
1948
3.78k
  init_inter_sf(&sf->inter_sf);
1949
3.78k
  init_interp_sf(&sf->interp_sf);
1950
3.78k
  init_intra_sf(&sf->intra_sf);
1951
3.78k
  init_tx_sf(&sf->tx_sf);
1952
3.78k
  init_rd_sf(&sf->rd_sf, oxcf);
1953
3.78k
  init_winner_mode_sf(&sf->winner_mode_sf);
1954
3.78k
  init_lpf_sf(&sf->lpf_sf);
1955
3.78k
  init_rt_sf(&sf->rt_sf);
1956
1957
3.78k
  switch (oxcf->mode) {
1958
0
    case GOOD:
1959
0
      set_good_speed_features_framesize_independent(cpi, sf, speed);
1960
0
      break;
1961
3.78k
    case ALLINTRA:
1962
3.78k
      set_allintra_speed_features_framesize_independent(cpi, sf, speed);
1963
3.78k
      break;
1964
0
    case REALTIME:
1965
0
      set_rt_speed_features_framesize_independent(cpi, sf, speed);
1966
0
      break;
1967
3.78k
  }
1968
1969
3.78k
  if (!oxcf->txfm_cfg.enable_tx_size_search) {
1970
0
    sf->winner_mode_sf.tx_size_search_level = 3;
1971
0
  }
1972
1973
3.78k
  if (!cpi->ppi->seq_params_locked) {
1974
3.78k
    cpi->common.seq_params->order_hint_info.enable_dist_wtd_comp &=
1975
3.78k
        (sf->inter_sf.use_dist_wtd_comp_flag != DIST_WTD_COMP_DISABLED);
1976
3.78k
    cpi->common.seq_params->enable_dual_filter &=
1977
3.78k
        !sf->interp_sf.disable_dual_filter;
1978
3.78k
    cpi->common.seq_params->enable_restoration &= !sf->lpf_sf.disable_lr_filter;
1979
1980
3.78k
    cpi->common.seq_params->enable_interintra_compound &=
1981
3.78k
        (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
1982
3.78k
  }
1983
1984
  // sf->part_sf.partition_search_breakout_dist_thr is set assuming max 64x64
1985
  // blocks. Normalise this if the blocks are bigger.
1986
3.78k
  if (MAX_SB_SIZE_LOG2 > 6) {
1987
3.78k
    sf->part_sf.partition_search_breakout_dist_thr <<=
1988
3.78k
        2 * (MAX_SB_SIZE_LOG2 - 6);
1989
3.78k
  }
1990
1991
3.78k
  const int mesh_speed = AOMMIN(speed, MAX_MESH_SPEED);
1992
18.9k
  for (i = 0; i < MAX_MESH_STEP; ++i) {
1993
15.1k
    sf->mv_sf.mesh_patterns[i].range =
1994
15.1k
        good_quality_mesh_patterns[mesh_speed][i].range;
1995
15.1k
    sf->mv_sf.mesh_patterns[i].interval =
1996
15.1k
        good_quality_mesh_patterns[mesh_speed][i].interval;
1997
15.1k
  }
1998
1999
  // Update the mesh pattern of exhaustive motion search for intraBC
2000
  // Though intraBC mesh pattern is populated for all frame types, it is used
2001
  // only for intra frames of screen contents
2002
18.9k
  for (i = 0; i < MAX_MESH_STEP; ++i) {
2003
15.1k
    sf->mv_sf.intrabc_mesh_patterns[i].range =
2004
15.1k
        intrabc_mesh_patterns[mesh_speed][i].range;
2005
15.1k
    sf->mv_sf.intrabc_mesh_patterns[i].interval =
2006
15.1k
        intrabc_mesh_patterns[mesh_speed][i].interval;
2007
15.1k
  }
2008
2009
  // Slow quant, dct and trellis not worthwhile for first pass
2010
  // so make sure they are always turned off.
2011
3.78k
  if (is_stat_generation_stage(cpi))
2012
0
    sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
2013
2014
  // No recode for 1 pass.
2015
3.78k
  if (oxcf->pass == AOM_RC_ONE_PASS && has_no_stats_stage(cpi))
2016
3.78k
    sf->hl_sf.recode_loop = DISALLOW_RECODE;
2017
2018
3.78k
  MotionVectorSearchParams *const mv_search_params = &cpi->mv_search_params;
2019
3.78k
  if (sf->mv_sf.subpel_search_method == SUBPEL_TREE) {
2020
1.26k
    mv_search_params->find_fractional_mv_step = av1_find_best_sub_pixel_tree;
2021
2.52k
  } else if (sf->mv_sf.subpel_search_method == SUBPEL_TREE_PRUNED) {
2022
0
    mv_search_params->find_fractional_mv_step =
2023
0
        av1_find_best_sub_pixel_tree_pruned;
2024
2.52k
  } else if (sf->mv_sf.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
2025
2.52k
    mv_search_params->find_fractional_mv_step =
2026
2.52k
        av1_find_best_sub_pixel_tree_pruned_more;
2027
2.52k
  }
2028
2029
  // This is only used in motion vector unit test.
2030
3.78k
  if (cpi->oxcf.unit_test_cfg.motion_vector_unit_test == 1)
2031
0
    mv_search_params->find_fractional_mv_step = av1_return_max_sub_pixel_mv;
2032
3.78k
  else if (cpi->oxcf.unit_test_cfg.motion_vector_unit_test == 2)
2033
0
    mv_search_params->find_fractional_mv_step = av1_return_min_sub_pixel_mv;
2034
2035
  // assert ensures that tx_domain_dist_level is accessed correctly
2036
3.78k
  assert(cpi->sf.rd_sf.tx_domain_dist_thres_level >= 0 &&
2037
3.78k
         cpi->sf.rd_sf.tx_domain_dist_thres_level < 4);
2038
3.78k
  memcpy(winner_mode_params->tx_domain_dist_threshold,
2039
3.78k
         tx_domain_dist_thresholds[cpi->sf.rd_sf.tx_domain_dist_thres_level],
2040
3.78k
         sizeof(winner_mode_params->tx_domain_dist_threshold));
2041
2042
3.78k
  assert(cpi->sf.rd_sf.tx_domain_dist_level >= 0 &&
2043
3.78k
         cpi->sf.rd_sf.tx_domain_dist_level < 3);
2044
3.78k
  memcpy(winner_mode_params->use_transform_domain_distortion,
2045
3.78k
         tx_domain_dist_types[cpi->sf.rd_sf.tx_domain_dist_level],
2046
3.78k
         sizeof(winner_mode_params->use_transform_domain_distortion));
2047
2048
  // assert ensures that coeff_opt_thresholds is accessed correctly
2049
3.78k
  assert(cpi->sf.rd_sf.perform_coeff_opt >= 0 &&
2050
3.78k
         cpi->sf.rd_sf.perform_coeff_opt < 9);
2051
3.78k
  memcpy(winner_mode_params->coeff_opt_thresholds,
2052
3.78k
         &coeff_opt_thresholds[cpi->sf.rd_sf.perform_coeff_opt],
2053
3.78k
         sizeof(winner_mode_params->coeff_opt_thresholds));
2054
2055
  // assert ensures that predict_skip_levels is accessed correctly
2056
3.78k
  assert(cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction >= 0 &&
2057
3.78k
         cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction < 3);
2058
3.78k
  memcpy(winner_mode_params->skip_txfm_level,
2059
3.78k
         predict_skip_levels[cpi->sf.tx_sf.tx_type_search
2060
3.78k
                                 .use_skip_flag_prediction],
2061
3.78k
         sizeof(winner_mode_params->skip_txfm_level));
2062
2063
  // assert ensures that tx_size_search_level is accessed correctly
2064
3.78k
  assert(cpi->sf.winner_mode_sf.tx_size_search_level >= 0 &&
2065
3.78k
         cpi->sf.winner_mode_sf.tx_size_search_level < 3);
2066
3.78k
  memcpy(winner_mode_params->tx_size_search_methods,
2067
3.78k
         tx_size_search_methods[cpi->sf.winner_mode_sf.tx_size_search_level],
2068
3.78k
         sizeof(winner_mode_params->tx_size_search_methods));
2069
3.78k
  memcpy(winner_mode_params->predict_dc_level,
2070
3.78k
         predict_dc_levels[cpi->sf.winner_mode_sf.dc_blk_pred_level],
2071
3.78k
         sizeof(winner_mode_params->predict_dc_level));
2072
2073
3.78k
  if (cpi->oxcf.row_mt == 1 && (cpi->mt_info.num_workers > 1)) {
2074
628
    if (sf->inter_sf.inter_mode_rd_model_estimation == 1) {
2075
      // Revert to type 2
2076
0
      sf->inter_sf.inter_mode_rd_model_estimation = 2;
2077
0
    }
2078
2079
628
#if !CONFIG_FRAME_PARALLEL_ENCODE || \
2080
628
    (CONFIG_FRAME_PARALLEL_ENCODE && !CONFIG_FPMT_TEST)
2081
    // Disable the speed feature 'prune_ref_frame_for_gm_search' to achieve
2082
    // better parallelism when number of threads available are greater than or
2083
    // equal to maximum number of reference frames allowed for global motion.
2084
628
    if (sf->gm_sf.gm_search_type != GM_DISABLE_SEARCH &&
2085
628
        (cpi->mt_info.num_workers >=
2086
628
         gm_available_reference_frames[sf->gm_sf.gm_search_type]))
2087
0
      sf->gm_sf.prune_ref_frame_for_gm_search = 0;
2088
628
#endif
2089
628
  }
2090
2091
  // This only applies to the real time mode. Adaptive gf refresh is disabled if
2092
  // gf_cbr_boost_pct that is set by the user is larger than 0.
2093
3.78k
  if (cpi->oxcf.rc_cfg.gf_cbr_boost_pct > 0)
2094
0
    sf->rt_sf.gf_refresh_based_on_qp = 0;
2095
3.78k
}
2096
2097
// Override some speed features based on qindex
2098
1.26k
void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
2099
1.26k
  AV1_COMMON *const cm = &cpi->common;
2100
1.26k
  SPEED_FEATURES *const sf = &cpi->sf;
2101
1.26k
  WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
2102
1.26k
  const int boosted = frame_is_boosted(cpi);
2103
1.26k
  const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
2104
1.26k
  const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
2105
1.26k
  const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
2106
1.26k
  const int is_arf2_bwd_type =
2107
1.26k
      cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
2108
2109
1.26k
  if (cpi->oxcf.mode == REALTIME) {
2110
0
    if (speed >= 6) {
2111
0
      const int qindex_thresh = boosted ? 190 : (is_720p_or_larger ? 120 : 150);
2112
0
      sf->part_sf.adjust_var_based_rd_partitioning =
2113
0
          frame_is_intra_only(cm)
2114
0
              ? 0
2115
0
              : cm->quant_params.base_qindex > qindex_thresh;
2116
0
    }
2117
0
    return;
2118
0
  }
2119
2120
1.26k
  if (speed == 0) {
2121
    // qindex_thresh for resolution < 720p
2122
0
    const int qindex_thresh = boosted ? 70 : (is_arf2_bwd_type ? 110 : 140);
2123
0
    if (!is_720p_or_larger && cm->quant_params.base_qindex <= qindex_thresh) {
2124
0
      sf->part_sf.simple_motion_search_split =
2125
0
          cm->features.allow_screen_content_tools ? 1 : 2;
2126
0
      sf->part_sf.simple_motion_search_early_term_none = 1;
2127
0
      sf->tx_sf.model_based_prune_tx_search_level = 0;
2128
0
    }
2129
2130
0
    if (is_720p_or_larger && cm->quant_params.base_qindex <= 128) {
2131
0
      sf->rd_sf.perform_coeff_opt = 2 + is_1080p_or_larger;
2132
0
      memcpy(winner_mode_params->coeff_opt_thresholds,
2133
0
             &coeff_opt_thresholds[sf->rd_sf.perform_coeff_opt],
2134
0
             sizeof(winner_mode_params->coeff_opt_thresholds));
2135
0
      sf->part_sf.simple_motion_search_split =
2136
0
          cm->features.allow_screen_content_tools ? 1 : 2;
2137
0
      sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
2138
0
      sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
2139
0
      sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
2140
0
      sf->tx_sf.model_based_prune_tx_search_level = 0;
2141
2142
0
      if (is_1080p_or_larger && cm->quant_params.base_qindex <= 108) {
2143
0
        sf->inter_sf.selective_ref_frame = 2;
2144
0
        sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
2145
0
        sf->rd_sf.tx_domain_dist_thres_level = 1;
2146
0
        sf->part_sf.simple_motion_search_early_term_none = 1;
2147
0
        sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
2148
0
        sf->interp_sf.cb_pred_filter_search = 0;
2149
0
        sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
2150
0
        sf->tx_sf.tx_type_search.skip_tx_search = 1;
2151
0
      }
2152
0
    }
2153
0
  }
2154
2155
1.26k
  if (speed >= 2) {
2156
    // Disable extended partitions for lower quantizers
2157
1.26k
    const int aggr = AOMMIN(3, speed - 2);
2158
1.26k
    const int qindex_thresh1[4] = { 50, 50, 80, 100 };
2159
1.26k
    const int qindex_thresh2[4] = { 80, 100, 120, 160 };
2160
1.26k
    int qindex_thresh;
2161
1.26k
    int disable_ext_part;
2162
1.26k
    if (aggr <= 1) {
2163
0
      const int qthresh2 =
2164
0
          (!aggr && !is_480p_or_larger) ? 70 : qindex_thresh2[aggr];
2165
0
      qindex_thresh = cm->features.allow_screen_content_tools
2166
0
                          ? qindex_thresh1[aggr]
2167
0
                          : qthresh2;
2168
0
      disable_ext_part = !boosted;
2169
1.26k
    } else {
2170
1.26k
      qindex_thresh = boosted ? qindex_thresh1[aggr] : qindex_thresh2[aggr];
2171
1.26k
      disable_ext_part = !frame_is_intra_only(cm);
2172
1.26k
    }
2173
1.26k
    if (cm->quant_params.base_qindex <= qindex_thresh && disable_ext_part) {
2174
0
      sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2175
0
    }
2176
1.26k
  }
2177
2178
1.26k
  if (speed >= 4) {
2179
    // Disable rectangular partitions for lower quantizers
2180
1.26k
    const int aggr = AOMMIN(1, speed - 4);
2181
1.26k
    const int qindex_thresh[2] = { 65, 80 };
2182
1.26k
    int disable_rect_part;
2183
1.26k
    disable_rect_part = !boosted;
2184
1.26k
    if (cm->quant_params.base_qindex <= qindex_thresh[aggr] &&
2185
1.26k
        disable_rect_part && is_480p_or_larger) {
2186
0
      sf->part_sf.rect_partition_eval_thresh = BLOCK_8X8;
2187
0
    }
2188
1.26k
  }
2189
2190
1.26k
  if (speed <= 2) {
2191
0
    if (!is_stat_generation_stage(cpi)) {
2192
      // Use faster full-pel motion search for high quantizers.
2193
      // Also use reduced total search range for low resolutions at high
2194
      // quantizers.
2195
0
      const int aggr = speed;
2196
0
      const int qindex_thresh1 = ms_qindex_thresh[aggr][is_720p_or_larger][0];
2197
0
      const int qindex_thresh2 = ms_qindex_thresh[aggr][is_720p_or_larger][1];
2198
0
      const SEARCH_METHODS search_method =
2199
0
          motion_search_method[is_720p_or_larger];
2200
0
      if (cm->quant_params.base_qindex > qindex_thresh1) {
2201
0
        sf->mv_sf.search_method = search_method;
2202
0
        sf->tpl_sf.search_method = search_method;
2203
0
      } else if (cm->quant_params.base_qindex > qindex_thresh2) {
2204
0
        sf->mv_sf.search_method = NSTEP_8PT;
2205
0
      }
2206
0
    }
2207
0
  }
2208
2209
1.26k
  if (speed >= 4) {
2210
    // Disable LR search at low and high quantizers and enable only for
2211
    // mid-quantizer range.
2212
1.26k
    if (!boosted && !is_arf2_bwd_type) {
2213
0
      const int qindex_low[2] = { 100, 60 };
2214
0
      const int qindex_high[2] = { 180, 160 };
2215
0
      if (cm->quant_params.base_qindex <= qindex_low[is_720p_or_larger] ||
2216
0
          cm->quant_params.base_qindex > qindex_high[is_720p_or_larger]) {
2217
0
        sf->lpf_sf.disable_loop_restoration_luma = 1;
2218
0
      }
2219
0
    }
2220
1.26k
  }
2221
1.26k
}