Coverage Report

Created: 2026-04-01 07:24

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