Coverage Report

Created: 2026-05-24 07:45

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