Coverage Report

Created: 2026-04-01 07:49

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