1 /*
2 * Copyright (c) 2020, 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 #ifndef AOM_AV1_ENCODER_ENCODER_UTILS_H_
13 #define AOM_AV1_ENCODER_ENCODER_UTILS_H_
14
15 #include "config/aom_dsp_rtcd.h"
16 #include "config/aom_scale_rtcd.h"
17
18 #include "av1/encoder/encoder.h"
19 #include "av1/encoder/encodetxb.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define AM_SEGMENT_ID_INACTIVE 7
26 #define AM_SEGMENT_ID_ACTIVE 0
27 #define DUMP_RECON_FRAMES 0
28
29 extern const int default_tx_type_probs[FRAME_UPDATE_TYPES][TX_SIZES_ALL]
30 [TX_TYPES];
31
32 extern const int default_obmc_probs[FRAME_UPDATE_TYPES][BLOCK_SIZES_ALL];
33
34 extern const int default_warped_probs[FRAME_UPDATE_TYPES];
35
36 extern const int default_switchable_interp_probs[FRAME_UPDATE_TYPES]
37 [SWITCHABLE_FILTER_CONTEXTS]
38 [SWITCHABLE_FILTERS];
39
40 // Mark all inactive blocks as active. Other segmentation features may be set
41 // so memset cannot be used, instead only inactive blocks should be reset.
suppress_active_map(AV1_COMP * cpi)42 static AOM_INLINE void suppress_active_map(AV1_COMP *cpi) {
43 unsigned char *const seg_map = cpi->enc_seg.map;
44 int i;
45 const int num_mis =
46 cpi->common.mi_params.mi_rows * cpi->common.mi_params.mi_cols;
47 if (cpi->active_map.enabled || cpi->active_map.update)
48 for (i = 0; i < num_mis; ++i)
49 if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
50 seg_map[i] = AM_SEGMENT_ID_ACTIVE;
51 }
52
53 // Returns 'size' in the number of Mode Info (MI) units. 'size' is either the
54 // width or height.
size_in_mi(int size)55 static AOM_INLINE int size_in_mi(int size) {
56 // Ensure that the decoded width and height are both multiples of
57 // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if
58 // subsampling is used).
59 // This simplifies the implementation of various experiments,
60 // eg. cdef, which operates on units of 8x8 luma pixels.
61 const int aligned_size = ALIGN_POWER_OF_TWO(size, 3);
62 return aligned_size >> MI_SIZE_LOG2;
63 }
64
set_mb_mi(CommonModeInfoParams * mi_params,int width,int height)65 static AOM_INLINE void set_mb_mi(CommonModeInfoParams *mi_params, int width,
66 int height) {
67 mi_params->mi_cols = size_in_mi(width);
68 mi_params->mi_rows = size_in_mi(height);
69 mi_params->mi_stride = calc_mi_size(mi_params->mi_cols);
70
71 mi_params->mb_cols = ROUND_POWER_OF_TWO(mi_params->mi_cols, 2);
72 mi_params->mb_rows = ROUND_POWER_OF_TWO(mi_params->mi_rows, 2);
73 mi_params->MBs = mi_params->mb_rows * mi_params->mb_cols;
74
75 const int mi_alloc_size_1d = mi_size_wide[mi_params->mi_alloc_bsize];
76 mi_params->mi_alloc_stride =
77 (mi_params->mi_stride + mi_alloc_size_1d - 1) / mi_alloc_size_1d;
78
79 assert(mi_size_wide[mi_params->mi_alloc_bsize] ==
80 mi_size_high[mi_params->mi_alloc_bsize]);
81 }
82
enc_free_mi(CommonModeInfoParams * mi_params)83 static AOM_INLINE void enc_free_mi(CommonModeInfoParams *mi_params) {
84 aom_free(mi_params->mi_alloc);
85 mi_params->mi_alloc = NULL;
86 aom_free(mi_params->mi_grid_base);
87 mi_params->mi_grid_base = NULL;
88 mi_params->mi_alloc_size = 0;
89 aom_free(mi_params->tx_type_map);
90 mi_params->tx_type_map = NULL;
91 }
92
enc_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height,BLOCK_SIZE min_partition_size)93 static AOM_INLINE void enc_set_mb_mi(CommonModeInfoParams *mi_params, int width,
94 int height,
95 BLOCK_SIZE min_partition_size) {
96 mi_params->mi_alloc_bsize = min_partition_size;
97
98 set_mb_mi(mi_params, width, height);
99 }
100
stat_stage_set_mb_mi(CommonModeInfoParams * mi_params,int width,int height,BLOCK_SIZE min_partition_size)101 static AOM_INLINE void stat_stage_set_mb_mi(CommonModeInfoParams *mi_params,
102 int width, int height,
103 BLOCK_SIZE min_partition_size) {
104 (void)min_partition_size;
105 mi_params->mi_alloc_bsize = BLOCK_16X16;
106
107 set_mb_mi(mi_params, width, height);
108 }
109
enc_setup_mi(CommonModeInfoParams * mi_params)110 static AOM_INLINE void enc_setup_mi(CommonModeInfoParams *mi_params) {
111 const int mi_grid_size =
112 mi_params->mi_stride * calc_mi_size(mi_params->mi_rows);
113 memset(mi_params->mi_alloc, 0,
114 mi_params->mi_alloc_size * sizeof(*mi_params->mi_alloc));
115 memset(mi_params->mi_grid_base, 0,
116 mi_grid_size * sizeof(*mi_params->mi_grid_base));
117 memset(mi_params->tx_type_map, 0,
118 mi_grid_size * sizeof(*mi_params->tx_type_map));
119 }
120
init_buffer_indices(ForceIntegerMVInfo * const force_intpel_info,int * const remapped_ref_idx)121 static AOM_INLINE void init_buffer_indices(
122 ForceIntegerMVInfo *const force_intpel_info, int *const remapped_ref_idx) {
123 int fb_idx;
124 for (fb_idx = 0; fb_idx < REF_FRAMES; ++fb_idx)
125 remapped_ref_idx[fb_idx] = fb_idx;
126 force_intpel_info->rate_index = 0;
127 force_intpel_info->rate_size = 0;
128 }
129
130 #define HIGHBD_BFP(BT, SDF, SDAF, VF, SVF, SVAF, SDX4DF, SDX3DF, JSDAF, JSVAF) \
131 ppi->fn_ptr[BT].sdf = SDF; \
132 ppi->fn_ptr[BT].sdaf = SDAF; \
133 ppi->fn_ptr[BT].vf = VF; \
134 ppi->fn_ptr[BT].svf = SVF; \
135 ppi->fn_ptr[BT].svaf = SVAF; \
136 ppi->fn_ptr[BT].sdx4df = SDX4DF; \
137 ppi->fn_ptr[BT].sdx3df = SDX3DF; \
138 ppi->fn_ptr[BT].jsdaf = JSDAF; \
139 ppi->fn_ptr[BT].jsvaf = JSVAF;
140
141 #define HIGHBD_BFP_WRAPPER(WIDTH, HEIGHT, BD) \
142 HIGHBD_BFP( \
143 BLOCK_##WIDTH##X##HEIGHT, aom_highbd_sad##WIDTH##x##HEIGHT##_bits##BD, \
144 aom_highbd_sad##WIDTH##x##HEIGHT##_avg_bits##BD, \
145 aom_highbd_##BD##_variance##WIDTH##x##HEIGHT, \
146 aom_highbd_##BD##_sub_pixel_variance##WIDTH##x##HEIGHT, \
147 aom_highbd_##BD##_sub_pixel_avg_variance##WIDTH##x##HEIGHT, \
148 aom_highbd_sad##WIDTH##x##HEIGHT##x4d_bits##BD, \
149 aom_highbd_sad##WIDTH##x##HEIGHT##x3d_bits##BD, \
150 aom_highbd_dist_wtd_sad##WIDTH##x##HEIGHT##_avg_bits##BD, \
151 aom_highbd_##BD##_dist_wtd_sub_pixel_avg_variance##WIDTH##x##HEIGHT)
152
153 #define MAKE_BFP_SAD_WRAPPER(fnname) \
154 static unsigned int fnname##_bits8(const uint8_t *src_ptr, \
155 int source_stride, \
156 const uint8_t *ref_ptr, int ref_stride) { \
157 return fnname(src_ptr, source_stride, ref_ptr, ref_stride); \
158 } \
159 static unsigned int fnname##_bits10( \
160 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
161 int ref_stride) { \
162 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 2; \
163 } \
164 static unsigned int fnname##_bits12( \
165 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
166 int ref_stride) { \
167 return fnname(src_ptr, source_stride, ref_ptr, ref_stride) >> 4; \
168 }
169
170 #define MAKE_BFP_SADAVG_WRAPPER(fnname) \
171 static unsigned int fnname##_bits8( \
172 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
173 int ref_stride, const uint8_t *second_pred) { \
174 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred); \
175 } \
176 static unsigned int fnname##_bits10( \
177 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
178 int ref_stride, const uint8_t *second_pred) { \
179 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
180 2; \
181 } \
182 static unsigned int fnname##_bits12( \
183 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
184 int ref_stride, const uint8_t *second_pred) { \
185 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred) >> \
186 4; \
187 }
188
189 #define MAKE_BFP_SAD4D_WRAPPER(fnname) \
190 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
191 const uint8_t *const ref_ptr[], int ref_stride, \
192 unsigned int *sad_array) { \
193 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
194 } \
195 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
196 const uint8_t *const ref_ptr[], int ref_stride, \
197 unsigned int *sad_array) { \
198 int i; \
199 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
200 for (i = 0; i < 4; i++) sad_array[i] >>= 2; \
201 } \
202 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
203 const uint8_t *const ref_ptr[], int ref_stride, \
204 unsigned int *sad_array) { \
205 int i; \
206 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
207 for (i = 0; i < 4; i++) sad_array[i] >>= 4; \
208 }
209
210 #define MAKE_BFP_JSADAVG_WRAPPER(fnname) \
211 static unsigned int fnname##_bits8( \
212 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
213 int ref_stride, const uint8_t *second_pred, \
214 const DIST_WTD_COMP_PARAMS *jcp_param) { \
215 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
216 jcp_param); \
217 } \
218 static unsigned int fnname##_bits10( \
219 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
220 int ref_stride, const uint8_t *second_pred, \
221 const DIST_WTD_COMP_PARAMS *jcp_param) { \
222 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
223 jcp_param) >> \
224 2; \
225 } \
226 static unsigned int fnname##_bits12( \
227 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
228 int ref_stride, const uint8_t *second_pred, \
229 const DIST_WTD_COMP_PARAMS *jcp_param) { \
230 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, second_pred, \
231 jcp_param) >> \
232 4; \
233 }
234
235 #if CONFIG_AV1_HIGHBITDEPTH
236 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x128)
MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)237 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x128_avg)
238 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x4d)
239 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x128x3d)
240 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad128x64)
241 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad128x64_avg)
242 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x4d)
243 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad128x64x3d)
244 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x128)
245 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x128_avg)
246 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x4d)
247 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x128x3d)
248 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x16)
249 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x16_avg)
250 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x4d)
251 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x16x3d)
252 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x32)
253 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x32_avg)
254 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x4d)
255 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x32x3d)
256 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x32)
257 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x32_avg)
258 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x4d)
259 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x32x3d)
260 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x64)
261 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x64_avg)
262 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x4d)
263 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x64x3d)
264 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x32)
265 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x32_avg)
266 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x4d)
267 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x32x3d)
268 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x64)
269 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x64_avg)
270 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x4d)
271 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x64x3d)
272 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x16)
273 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x16_avg)
274 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x4d)
275 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x16x3d)
276 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x8)
277 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x8_avg)
278 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x4d)
279 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x8x3d)
280 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x16)
281 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x16_avg)
282 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x4d)
283 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x16x3d)
284 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x8)
285 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x8_avg)
286 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x4d)
287 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x8x3d)
288 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x4)
289 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x4_avg)
290 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x4d)
291 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x4x3d)
292 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x8)
293 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x8_avg)
294 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x4d)
295 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x8x3d)
296 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x4)
297 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x4_avg)
298 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x4d)
299 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x4x3d)
300
301 #if !CONFIG_REALTIME_ONLY
302 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad4x16)
303 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad4x16_avg)
304 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x4d)
305 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad4x16x3d)
306 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x4)
307 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x4_avg)
308 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x4d)
309 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x4x3d)
310 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad8x32)
311 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad8x32_avg)
312 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x4d)
313 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad8x32x3d)
314 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad32x8)
315 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad32x8_avg)
316 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x4d)
317 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad32x8x3d)
318 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad16x64)
319 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad16x64_avg)
320 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x4d)
321 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad16x64x3d)
322 MAKE_BFP_SAD_WRAPPER(aom_highbd_sad64x16)
323 MAKE_BFP_SADAVG_WRAPPER(aom_highbd_sad64x16_avg)
324 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x4d)
325 MAKE_BFP_SAD4D_WRAPPER(aom_highbd_sad64x16x3d)
326 #endif
327
328 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x128_avg)
329 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad128x64_avg)
330 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x128_avg)
331 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x16_avg)
332 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x32_avg)
333 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x32_avg)
334 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x64_avg)
335 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x32_avg)
336 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x64_avg)
337 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x16_avg)
338 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x8_avg)
339 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x16_avg)
340 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x8_avg)
341 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x4_avg)
342 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x8_avg)
343 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x4_avg)
344 #if !CONFIG_REALTIME_ONLY
345 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad4x16_avg)
346 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x4_avg)
347 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad8x32_avg)
348 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad32x8_avg)
349 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad16x64_avg)
350 MAKE_BFP_JSADAVG_WRAPPER(aom_highbd_dist_wtd_sad64x16_avg)
351 #endif
352 #endif // CONFIG_AV1_HIGHBITDEPTH
353
354 #define HIGHBD_MBFP(BT, MCSDF, MCSVF) \
355 ppi->fn_ptr[BT].msdf = MCSDF; \
356 ppi->fn_ptr[BT].msvf = MCSVF;
357
358 #define HIGHBD_MBFP_WRAPPER(WIDTH, HEIGHT, BD) \
359 HIGHBD_MBFP(BLOCK_##WIDTH##X##HEIGHT, \
360 aom_highbd_masked_sad##WIDTH##x##HEIGHT##_bits##BD, \
361 aom_highbd_##BD##_masked_sub_pixel_variance##WIDTH##x##HEIGHT)
362
363 #define MAKE_MBFP_COMPOUND_SAD_WRAPPER(fnname) \
364 static unsigned int fnname##_bits8( \
365 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
366 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
367 int m_stride, int invert_mask) { \
368 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
369 second_pred_ptr, m, m_stride, invert_mask); \
370 } \
371 static unsigned int fnname##_bits10( \
372 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
373 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
374 int m_stride, int invert_mask) { \
375 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
376 second_pred_ptr, m, m_stride, invert_mask) >> \
377 2; \
378 } \
379 static unsigned int fnname##_bits12( \
380 const uint8_t *src_ptr, int source_stride, const uint8_t *ref_ptr, \
381 int ref_stride, const uint8_t *second_pred_ptr, const uint8_t *m, \
382 int m_stride, int invert_mask) { \
383 return fnname(src_ptr, source_stride, ref_ptr, ref_stride, \
384 second_pred_ptr, m, m_stride, invert_mask) >> \
385 4; \
386 }
387
388 #if CONFIG_AV1_HIGHBITDEPTH
389 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x128)
390 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad128x64)
391 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x128)
392 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x64)
393 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x32)
394 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x64)
395 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x32)
396 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x16)
397 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x32)
398 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x16)
399 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x8)
400 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x16)
401 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x8)
402 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x4)
403 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x8)
404 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x4)
405 #if !CONFIG_REALTIME_ONLY
406 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad4x16)
407 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x4)
408 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad8x32)
409 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad32x8)
410 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad16x64)
411 MAKE_MBFP_COMPOUND_SAD_WRAPPER(aom_highbd_masked_sad64x16)
412 #endif
413 #endif
414
415 #define HIGHBD_SDSFP(BT, SDSF, SDSX4DF) \
416 ppi->fn_ptr[BT].sdsf = SDSF; \
417 ppi->fn_ptr[BT].sdsx4df = SDSX4DF;
418
419 #define HIGHBD_SDSFP_WRAPPER(WIDTH, HEIGHT, BD) \
420 HIGHBD_SDSFP(BLOCK_##WIDTH##X##HEIGHT, \
421 aom_highbd_sad_skip_##WIDTH##x##HEIGHT##_bits##BD, \
422 aom_highbd_sad_skip_##WIDTH##x##HEIGHT##x4d##_bits##BD)
423
424 #define MAKE_SDSF_SKIP_SAD_WRAPPER(fnname) \
425 static unsigned int fnname##_bits8(const uint8_t *src, int src_stride, \
426 const uint8_t *ref, int ref_stride) { \
427 return fnname(src, src_stride, ref, ref_stride); \
428 } \
429 static unsigned int fnname##_bits10(const uint8_t *src, int src_stride, \
430 const uint8_t *ref, int ref_stride) { \
431 return fnname(src, src_stride, ref, ref_stride) >> 2; \
432 } \
433 static unsigned int fnname##_bits12(const uint8_t *src, int src_stride, \
434 const uint8_t *ref, int ref_stride) { \
435 return fnname(src, src_stride, ref, ref_stride) >> 4; \
436 }
437
438 #define MAKE_SDSF_SKIP_SAD_4D_WRAPPER(fnname) \
439 static void fnname##_bits8(const uint8_t *src_ptr, int source_stride, \
440 const uint8_t *const ref_ptr[], int ref_stride, \
441 unsigned int *sad_array) { \
442 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
443 } \
444 static void fnname##_bits10(const uint8_t *src_ptr, int source_stride, \
445 const uint8_t *const ref_ptr[], int ref_stride, \
446 unsigned int *sad_array) { \
447 int i; \
448 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
449 for (i = 0; i < 4; i++) sad_array[i] >>= 2; \
450 } \
451 static void fnname##_bits12(const uint8_t *src_ptr, int source_stride, \
452 const uint8_t *const ref_ptr[], int ref_stride, \
453 unsigned int *sad_array) { \
454 int i; \
455 fnname(src_ptr, source_stride, ref_ptr, ref_stride, sad_array); \
456 for (i = 0; i < 4; i++) sad_array[i] >>= 4; \
457 }
458
459 #if CONFIG_AV1_HIGHBITDEPTH
460 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x128)
461 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_128x64)
462 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x128)
463 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x64)
464 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x32)
465 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x64)
466 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x32)
467 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x16)
468 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x32)
469 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x16)
470 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x8)
471 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x16)
472 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x8)
473 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x8)
474
475 #if !CONFIG_REALTIME_ONLY
476 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_64x16)
477 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_32x8)
478 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_16x64)
479 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_4x16)
480 MAKE_SDSF_SKIP_SAD_WRAPPER(aom_highbd_sad_skip_8x32)
481 #endif
482
483 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x128x4d)
484 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_128x64x4d)
485 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x128x4d)
486 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x64x4d)
487 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x32x4d)
488 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x64x4d)
489 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x32x4d)
490 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x16x4d)
491 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x32x4d)
492 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x16x4d)
493 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x8x4d)
494 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x16x4d)
495 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x8x4d)
496 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x8x4d)
497
498 #if !CONFIG_REALTIME_ONLY
499 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_64x16x4d)
500 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_32x8x4d)
501 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_16x64x4d)
502 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_4x16x4d)
503 MAKE_SDSF_SKIP_SAD_4D_WRAPPER(aom_highbd_sad_skip_8x32x4d)
504 #endif
505 #endif
506
507 #if !CONFIG_REALTIME_ONLY
508
509 #if CONFIG_AV1_HIGHBITDEPTH
510 #define HIGHBD_OBFP_WRAPPER_8(WIDTH, HEIGHT) \
511 HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT, \
512 aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits8, \
513 aom_highbd_obmc_variance##WIDTH##x##HEIGHT, \
514 aom_highbd_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
515
516 #define HIGHBD_OBFP(BT, OSDF, OVF, OSVF) \
517 ppi->fn_ptr[BT].osdf = OSDF; \
518 ppi->fn_ptr[BT].ovf = OVF; \
519 ppi->fn_ptr[BT].osvf = OSVF;
520
521 #define HIGHBD_OBFP_WRAPPER(WIDTH, HEIGHT, BD) \
522 HIGHBD_OBFP(BLOCK_##WIDTH##X##HEIGHT, \
523 aom_highbd_obmc_sad##WIDTH##x##HEIGHT##_bits##BD, \
524 aom_highbd_##BD##_obmc_variance##WIDTH##x##HEIGHT, \
525 aom_highbd_##BD##_obmc_sub_pixel_variance##WIDTH##x##HEIGHT)
526
527 #define MAKE_OBFP_SAD_WRAPPER(fnname) \
528 static unsigned int fnname##_bits8(const uint8_t *ref, int ref_stride, \
529 const int32_t *wsrc, \
530 const int32_t *msk) { \
531 return fnname(ref, ref_stride, wsrc, msk); \
532 } \
533 static unsigned int fnname##_bits10(const uint8_t *ref, int ref_stride, \
534 const int32_t *wsrc, \
535 const int32_t *msk) { \
536 return fnname(ref, ref_stride, wsrc, msk) >> 2; \
537 } \
538 static unsigned int fnname##_bits12(const uint8_t *ref, int ref_stride, \
539 const int32_t *wsrc, \
540 const int32_t *msk) { \
541 return fnname(ref, ref_stride, wsrc, msk) >> 4; \
542 }
543 #endif // CONFIG_AV1_HIGHBITDEPTH
544 #endif // !CONFIG_REALTIME_ONLY
545
546 #if CONFIG_AV1_HIGHBITDEPTH
547 #if !CONFIG_REALTIME_ONLY
548 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x128)
549 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad128x64)
550 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x128)
551 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x64)
552 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x32)
553 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x64)
554 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x32)
555 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x16)
556 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x32)
557 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x16)
558 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x8)
559 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x16)
560 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x8)
561 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x4)
562 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x8)
563 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x4)
564 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad4x16)
565 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x4)
566 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad8x32)
567 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad32x8)
568 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad16x64)
569 MAKE_OBFP_SAD_WRAPPER(aom_highbd_obmc_sad64x16)
570 #endif
571
572 static AOM_INLINE void highbd_set_var_fns(AV1_PRIMARY *const ppi) {
573 SequenceHeader *const seq_params = &ppi->seq_params;
574 if (seq_params->use_highbitdepth) {
575 switch (seq_params->bit_depth) {
576 case AOM_BITS_8:
577 #if !CONFIG_REALTIME_ONLY
578 HIGHBD_BFP_WRAPPER(64, 16, 8)
579 HIGHBD_BFP_WRAPPER(16, 64, 8)
580 HIGHBD_BFP_WRAPPER(32, 8, 8)
581 HIGHBD_BFP_WRAPPER(8, 32, 8)
582 HIGHBD_BFP_WRAPPER(16, 4, 8)
583 HIGHBD_BFP_WRAPPER(4, 16, 8)
584 #endif
585 HIGHBD_BFP_WRAPPER(32, 16, 8)
586 HIGHBD_BFP_WRAPPER(16, 32, 8)
587 HIGHBD_BFP_WRAPPER(64, 32, 8)
588 HIGHBD_BFP_WRAPPER(32, 64, 8)
589 HIGHBD_BFP_WRAPPER(32, 32, 8)
590 HIGHBD_BFP_WRAPPER(64, 64, 8)
591 HIGHBD_BFP_WRAPPER(16, 16, 8)
592 HIGHBD_BFP_WRAPPER(16, 8, 8)
593 HIGHBD_BFP_WRAPPER(8, 16, 8)
594 HIGHBD_BFP_WRAPPER(8, 8, 8)
595 HIGHBD_BFP_WRAPPER(8, 4, 8)
596 HIGHBD_BFP_WRAPPER(4, 8, 8)
597 HIGHBD_BFP_WRAPPER(4, 4, 8)
598 HIGHBD_BFP_WRAPPER(128, 128, 8)
599 HIGHBD_BFP_WRAPPER(128, 64, 8)
600 HIGHBD_BFP_WRAPPER(64, 128, 8)
601
602 HIGHBD_MBFP_WRAPPER(128, 128, 8)
603 HIGHBD_MBFP_WRAPPER(128, 64, 8)
604 HIGHBD_MBFP_WRAPPER(64, 128, 8)
605 HIGHBD_MBFP_WRAPPER(64, 64, 8)
606 HIGHBD_MBFP_WRAPPER(64, 32, 8)
607 HIGHBD_MBFP_WRAPPER(32, 64, 8)
608 HIGHBD_MBFP_WRAPPER(32, 32, 8)
609 HIGHBD_MBFP_WRAPPER(32, 16, 8)
610 HIGHBD_MBFP_WRAPPER(16, 32, 8)
611 HIGHBD_MBFP_WRAPPER(16, 16, 8)
612 HIGHBD_MBFP_WRAPPER(8, 16, 8)
613 HIGHBD_MBFP_WRAPPER(16, 8, 8)
614 HIGHBD_MBFP_WRAPPER(8, 8, 8)
615 HIGHBD_MBFP_WRAPPER(4, 8, 8)
616 HIGHBD_MBFP_WRAPPER(8, 4, 8)
617 HIGHBD_MBFP_WRAPPER(4, 4, 8)
618 #if !CONFIG_REALTIME_ONLY
619 HIGHBD_MBFP_WRAPPER(64, 16, 8)
620 HIGHBD_MBFP_WRAPPER(16, 64, 8)
621 HIGHBD_MBFP_WRAPPER(32, 8, 8)
622 HIGHBD_MBFP_WRAPPER(8, 32, 8)
623 HIGHBD_MBFP_WRAPPER(16, 4, 8)
624 HIGHBD_MBFP_WRAPPER(4, 16, 8)
625 #endif
626
627 // OBMC excluded from realtime only build.
628 #if !CONFIG_REALTIME_ONLY
629 HIGHBD_OBFP_WRAPPER_8(128, 128)
630 HIGHBD_OBFP_WRAPPER_8(128, 64)
631 HIGHBD_OBFP_WRAPPER_8(64, 128)
632 HIGHBD_OBFP_WRAPPER_8(64, 64)
633 HIGHBD_OBFP_WRAPPER_8(64, 32)
634 HIGHBD_OBFP_WRAPPER_8(32, 64)
635 HIGHBD_OBFP_WRAPPER_8(32, 32)
636 HIGHBD_OBFP_WRAPPER_8(32, 16)
637 HIGHBD_OBFP_WRAPPER_8(16, 32)
638 HIGHBD_OBFP_WRAPPER_8(16, 16)
639 HIGHBD_OBFP_WRAPPER_8(8, 16)
640 HIGHBD_OBFP_WRAPPER_8(16, 8)
641 HIGHBD_OBFP_WRAPPER_8(8, 8)
642 HIGHBD_OBFP_WRAPPER_8(4, 8)
643 HIGHBD_OBFP_WRAPPER_8(8, 4)
644 HIGHBD_OBFP_WRAPPER_8(4, 4)
645 HIGHBD_OBFP_WRAPPER_8(64, 16)
646 HIGHBD_OBFP_WRAPPER_8(16, 64)
647 HIGHBD_OBFP_WRAPPER_8(32, 8)
648 HIGHBD_OBFP_WRAPPER_8(8, 32)
649 HIGHBD_OBFP_WRAPPER_8(16, 4)
650 HIGHBD_OBFP_WRAPPER_8(4, 16)
651 #endif
652
653 HIGHBD_SDSFP_WRAPPER(128, 128, 8)
654 HIGHBD_SDSFP_WRAPPER(128, 64, 8)
655 HIGHBD_SDSFP_WRAPPER(64, 128, 8)
656 HIGHBD_SDSFP_WRAPPER(64, 64, 8)
657 HIGHBD_SDSFP_WRAPPER(64, 32, 8)
658 HIGHBD_SDSFP_WRAPPER(32, 64, 8)
659 HIGHBD_SDSFP_WRAPPER(32, 32, 8)
660 HIGHBD_SDSFP_WRAPPER(32, 16, 8)
661 HIGHBD_SDSFP_WRAPPER(16, 32, 8)
662 HIGHBD_SDSFP_WRAPPER(16, 16, 8)
663 HIGHBD_SDSFP_WRAPPER(16, 8, 8)
664 HIGHBD_SDSFP_WRAPPER(8, 16, 8)
665 HIGHBD_SDSFP_WRAPPER(8, 8, 8)
666 HIGHBD_SDSFP_WRAPPER(4, 8, 8)
667 #if !CONFIG_REALTIME_ONLY
668 HIGHBD_SDSFP_WRAPPER(64, 16, 8)
669 HIGHBD_SDSFP_WRAPPER(32, 8, 8)
670 HIGHBD_SDSFP_WRAPPER(16, 64, 8)
671 HIGHBD_SDSFP_WRAPPER(8, 32, 8)
672 HIGHBD_SDSFP_WRAPPER(4, 16, 8)
673 #endif
674 break;
675
676 case AOM_BITS_10:
677 #if !CONFIG_REALTIME_ONLY
678 HIGHBD_BFP_WRAPPER(64, 16, 10)
679 HIGHBD_BFP_WRAPPER(16, 64, 10)
680 HIGHBD_BFP_WRAPPER(32, 8, 10)
681 HIGHBD_BFP_WRAPPER(8, 32, 10)
682 HIGHBD_BFP_WRAPPER(16, 4, 10)
683 HIGHBD_BFP_WRAPPER(4, 16, 10)
684 #endif
685 HIGHBD_BFP_WRAPPER(32, 16, 10)
686 HIGHBD_BFP_WRAPPER(16, 32, 10)
687 HIGHBD_BFP_WRAPPER(64, 32, 10)
688 HIGHBD_BFP_WRAPPER(32, 64, 10)
689 HIGHBD_BFP_WRAPPER(32, 32, 10)
690 HIGHBD_BFP_WRAPPER(64, 64, 10)
691 HIGHBD_BFP_WRAPPER(16, 16, 10)
692 HIGHBD_BFP_WRAPPER(16, 8, 10)
693 HIGHBD_BFP_WRAPPER(8, 16, 10)
694 HIGHBD_BFP_WRAPPER(8, 8, 10)
695 HIGHBD_BFP_WRAPPER(8, 4, 10)
696 HIGHBD_BFP_WRAPPER(4, 8, 10)
697 HIGHBD_BFP_WRAPPER(4, 4, 10)
698 HIGHBD_BFP_WRAPPER(128, 128, 10)
699 HIGHBD_BFP_WRAPPER(128, 64, 10)
700 HIGHBD_BFP_WRAPPER(64, 128, 10)
701
702 HIGHBD_MBFP_WRAPPER(128, 128, 10)
703 HIGHBD_MBFP_WRAPPER(128, 64, 10)
704 HIGHBD_MBFP_WRAPPER(64, 128, 10)
705 HIGHBD_MBFP_WRAPPER(64, 64, 10)
706 HIGHBD_MBFP_WRAPPER(64, 32, 10)
707 HIGHBD_MBFP_WRAPPER(32, 64, 10)
708 HIGHBD_MBFP_WRAPPER(32, 32, 10)
709 HIGHBD_MBFP_WRAPPER(32, 16, 10)
710 HIGHBD_MBFP_WRAPPER(16, 32, 10)
711 HIGHBD_MBFP_WRAPPER(16, 16, 10)
712 HIGHBD_MBFP_WRAPPER(8, 16, 10)
713 HIGHBD_MBFP_WRAPPER(16, 8, 10)
714 HIGHBD_MBFP_WRAPPER(8, 8, 10)
715 HIGHBD_MBFP_WRAPPER(4, 8, 10)
716 HIGHBD_MBFP_WRAPPER(8, 4, 10)
717 HIGHBD_MBFP_WRAPPER(4, 4, 10)
718 #if !CONFIG_REALTIME_ONLY
719 HIGHBD_MBFP_WRAPPER(64, 16, 10)
720 HIGHBD_MBFP_WRAPPER(16, 64, 10)
721 HIGHBD_MBFP_WRAPPER(32, 8, 10)
722 HIGHBD_MBFP_WRAPPER(8, 32, 10)
723 HIGHBD_MBFP_WRAPPER(16, 4, 10)
724 HIGHBD_MBFP_WRAPPER(4, 16, 10)
725 #endif
726
727 // OBMC excluded from realtime only build.
728 #if !CONFIG_REALTIME_ONLY
729 HIGHBD_OBFP_WRAPPER(128, 128, 10)
730 HIGHBD_OBFP_WRAPPER(128, 64, 10)
731 HIGHBD_OBFP_WRAPPER(64, 128, 10)
732 HIGHBD_OBFP_WRAPPER(64, 64, 10)
733 HIGHBD_OBFP_WRAPPER(64, 32, 10)
734 HIGHBD_OBFP_WRAPPER(32, 64, 10)
735 HIGHBD_OBFP_WRAPPER(32, 32, 10)
736 HIGHBD_OBFP_WRAPPER(32, 16, 10)
737 HIGHBD_OBFP_WRAPPER(16, 32, 10)
738 HIGHBD_OBFP_WRAPPER(16, 16, 10)
739 HIGHBD_OBFP_WRAPPER(8, 16, 10)
740 HIGHBD_OBFP_WRAPPER(16, 8, 10)
741 HIGHBD_OBFP_WRAPPER(8, 8, 10)
742 HIGHBD_OBFP_WRAPPER(4, 8, 10)
743 HIGHBD_OBFP_WRAPPER(8, 4, 10)
744 HIGHBD_OBFP_WRAPPER(4, 4, 10)
745 HIGHBD_OBFP_WRAPPER(64, 16, 10)
746 HIGHBD_OBFP_WRAPPER(16, 64, 10)
747 HIGHBD_OBFP_WRAPPER(32, 8, 10)
748 HIGHBD_OBFP_WRAPPER(8, 32, 10)
749 HIGHBD_OBFP_WRAPPER(16, 4, 10)
750 HIGHBD_OBFP_WRAPPER(4, 16, 10)
751 #endif
752
753 HIGHBD_SDSFP_WRAPPER(128, 128, 10)
754 HIGHBD_SDSFP_WRAPPER(128, 64, 10)
755 HIGHBD_SDSFP_WRAPPER(64, 128, 10)
756 HIGHBD_SDSFP_WRAPPER(64, 64, 10)
757 HIGHBD_SDSFP_WRAPPER(64, 32, 10)
758 HIGHBD_SDSFP_WRAPPER(32, 64, 10)
759 HIGHBD_SDSFP_WRAPPER(32, 32, 10)
760 HIGHBD_SDSFP_WRAPPER(32, 16, 10)
761 HIGHBD_SDSFP_WRAPPER(16, 32, 10)
762 HIGHBD_SDSFP_WRAPPER(16, 16, 10)
763 HIGHBD_SDSFP_WRAPPER(16, 8, 10)
764 HIGHBD_SDSFP_WRAPPER(8, 16, 10)
765 HIGHBD_SDSFP_WRAPPER(8, 8, 10)
766 HIGHBD_SDSFP_WRAPPER(4, 8, 10)
767
768 #if !CONFIG_REALTIME_ONLY
769 HIGHBD_SDSFP_WRAPPER(64, 16, 10)
770 HIGHBD_SDSFP_WRAPPER(32, 8, 10)
771 HIGHBD_SDSFP_WRAPPER(16, 64, 10)
772 HIGHBD_SDSFP_WRAPPER(8, 32, 10)
773 HIGHBD_SDSFP_WRAPPER(4, 16, 10)
774 #endif
775 break;
776
777 case AOM_BITS_12:
778 #if !CONFIG_REALTIME_ONLY
779 HIGHBD_BFP_WRAPPER(64, 16, 12)
780 HIGHBD_BFP_WRAPPER(16, 64, 12)
781 HIGHBD_BFP_WRAPPER(32, 8, 12)
782 HIGHBD_BFP_WRAPPER(8, 32, 12)
783 HIGHBD_BFP_WRAPPER(16, 4, 12)
784 HIGHBD_BFP_WRAPPER(4, 16, 12)
785 #endif
786 HIGHBD_BFP_WRAPPER(32, 16, 12)
787 HIGHBD_BFP_WRAPPER(16, 32, 12)
788 HIGHBD_BFP_WRAPPER(64, 32, 12)
789 HIGHBD_BFP_WRAPPER(32, 64, 12)
790 HIGHBD_BFP_WRAPPER(32, 32, 12)
791 HIGHBD_BFP_WRAPPER(64, 64, 12)
792 HIGHBD_BFP_WRAPPER(16, 16, 12)
793 HIGHBD_BFP_WRAPPER(16, 8, 12)
794 HIGHBD_BFP_WRAPPER(8, 16, 12)
795 HIGHBD_BFP_WRAPPER(8, 8, 12)
796 HIGHBD_BFP_WRAPPER(8, 4, 12)
797 HIGHBD_BFP_WRAPPER(4, 8, 12)
798 HIGHBD_BFP_WRAPPER(4, 4, 12)
799 HIGHBD_BFP_WRAPPER(128, 128, 12)
800 HIGHBD_BFP_WRAPPER(128, 64, 12)
801 HIGHBD_BFP_WRAPPER(64, 128, 12)
802
803 HIGHBD_MBFP_WRAPPER(128, 128, 12)
804 HIGHBD_MBFP_WRAPPER(128, 64, 12)
805 HIGHBD_MBFP_WRAPPER(64, 128, 12)
806 HIGHBD_MBFP_WRAPPER(64, 64, 12)
807 HIGHBD_MBFP_WRAPPER(64, 32, 12)
808 HIGHBD_MBFP_WRAPPER(32, 64, 12)
809 HIGHBD_MBFP_WRAPPER(32, 32, 12)
810 HIGHBD_MBFP_WRAPPER(32, 16, 12)
811 HIGHBD_MBFP_WRAPPER(16, 32, 12)
812 HIGHBD_MBFP_WRAPPER(16, 16, 12)
813 HIGHBD_MBFP_WRAPPER(8, 16, 12)
814 HIGHBD_MBFP_WRAPPER(16, 8, 12)
815 HIGHBD_MBFP_WRAPPER(8, 8, 12)
816 HIGHBD_MBFP_WRAPPER(4, 8, 12)
817 HIGHBD_MBFP_WRAPPER(8, 4, 12)
818 HIGHBD_MBFP_WRAPPER(4, 4, 12)
819 #if !CONFIG_REALTIME_ONLY
820 HIGHBD_MBFP_WRAPPER(64, 16, 12)
821 HIGHBD_MBFP_WRAPPER(16, 64, 12)
822 HIGHBD_MBFP_WRAPPER(32, 8, 12)
823 HIGHBD_MBFP_WRAPPER(8, 32, 12)
824 HIGHBD_MBFP_WRAPPER(16, 4, 12)
825 HIGHBD_MBFP_WRAPPER(4, 16, 12)
826 #endif
827
828 // OBMC excluded from realtime only build.
829 #if !CONFIG_REALTIME_ONLY
830 HIGHBD_OBFP_WRAPPER(128, 128, 12)
831 HIGHBD_OBFP_WRAPPER(128, 64, 12)
832 HIGHBD_OBFP_WRAPPER(64, 128, 12)
833 HIGHBD_OBFP_WRAPPER(64, 64, 12)
834 HIGHBD_OBFP_WRAPPER(64, 32, 12)
835 HIGHBD_OBFP_WRAPPER(32, 64, 12)
836 HIGHBD_OBFP_WRAPPER(32, 32, 12)
837 HIGHBD_OBFP_WRAPPER(32, 16, 12)
838 HIGHBD_OBFP_WRAPPER(16, 32, 12)
839 HIGHBD_OBFP_WRAPPER(16, 16, 12)
840 HIGHBD_OBFP_WRAPPER(8, 16, 12)
841 HIGHBD_OBFP_WRAPPER(16, 8, 12)
842 HIGHBD_OBFP_WRAPPER(8, 8, 12)
843 HIGHBD_OBFP_WRAPPER(4, 8, 12)
844 HIGHBD_OBFP_WRAPPER(8, 4, 12)
845 HIGHBD_OBFP_WRAPPER(4, 4, 12)
846 HIGHBD_OBFP_WRAPPER(64, 16, 12)
847 HIGHBD_OBFP_WRAPPER(16, 64, 12)
848 HIGHBD_OBFP_WRAPPER(32, 8, 12)
849 HIGHBD_OBFP_WRAPPER(8, 32, 12)
850 HIGHBD_OBFP_WRAPPER(16, 4, 12)
851 HIGHBD_OBFP_WRAPPER(4, 16, 12)
852 #endif
853
854 HIGHBD_SDSFP_WRAPPER(128, 128, 12)
855 HIGHBD_SDSFP_WRAPPER(128, 64, 12)
856 HIGHBD_SDSFP_WRAPPER(64, 128, 12)
857 HIGHBD_SDSFP_WRAPPER(64, 64, 12)
858 HIGHBD_SDSFP_WRAPPER(64, 32, 12)
859 HIGHBD_SDSFP_WRAPPER(32, 64, 12)
860 HIGHBD_SDSFP_WRAPPER(32, 32, 12)
861 HIGHBD_SDSFP_WRAPPER(32, 16, 12)
862 HIGHBD_SDSFP_WRAPPER(16, 32, 12)
863 HIGHBD_SDSFP_WRAPPER(16, 16, 12)
864 HIGHBD_SDSFP_WRAPPER(16, 8, 12)
865 HIGHBD_SDSFP_WRAPPER(8, 16, 12)
866 HIGHBD_SDSFP_WRAPPER(8, 8, 12)
867 HIGHBD_SDSFP_WRAPPER(4, 8, 12)
868
869 #if !CONFIG_REALTIME_ONLY
870 HIGHBD_SDSFP_WRAPPER(64, 16, 12)
871 HIGHBD_SDSFP_WRAPPER(32, 8, 12)
872 HIGHBD_SDSFP_WRAPPER(16, 64, 12)
873 HIGHBD_SDSFP_WRAPPER(8, 32, 12)
874 HIGHBD_SDSFP_WRAPPER(4, 16, 12)
875 #endif
876 break;
877
878 default:
879 assert(0 &&
880 "cm->seq_params->bit_depth should be AOM_BITS_8, "
881 "AOM_BITS_10 or AOM_BITS_12");
882 }
883 }
884 }
885 #endif // CONFIG_AV1_HIGHBITDEPTH
886
copy_frame_prob_info(AV1_COMP * cpi)887 static AOM_INLINE void copy_frame_prob_info(AV1_COMP *cpi) {
888 FrameProbInfo *const frame_probs = &cpi->ppi->frame_probs;
889 if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
890 av1_copy(frame_probs->tx_type_probs, default_tx_type_probs);
891 }
892 if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
893 cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
894 av1_copy(frame_probs->obmc_probs, default_obmc_probs);
895 }
896 if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
897 av1_copy(frame_probs->warped_probs, default_warped_probs);
898 }
899 if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
900 av1_copy(frame_probs->switchable_interp_probs,
901 default_switchable_interp_probs);
902 }
903
904 #if CONFIG_FPMT_TEST
905 if (cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE) {
906 FrameProbInfo *const temp_frame_probs = &cpi->ppi->temp_frame_probs;
907 if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
908 av1_copy(temp_frame_probs->tx_type_probs, default_tx_type_probs);
909 }
910 if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
911 cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
912 av1_copy(temp_frame_probs->obmc_probs, default_obmc_probs);
913 }
914 if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
915 av1_copy(temp_frame_probs->warped_probs, default_warped_probs);
916 }
917 if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
918 av1_copy(temp_frame_probs->switchable_interp_probs,
919 default_switchable_interp_probs);
920 }
921
922 FrameProbInfo *const temp_frame_probs_simulation =
923 &cpi->ppi->temp_frame_probs_simulation;
924 if (cpi->sf.tx_sf.tx_type_search.prune_tx_type_using_stats) {
925 av1_copy(temp_frame_probs_simulation->tx_type_probs,
926 default_tx_type_probs);
927 }
928 if (cpi->sf.inter_sf.prune_obmc_prob_thresh > 0 &&
929 cpi->sf.inter_sf.prune_obmc_prob_thresh < INT_MAX) {
930 av1_copy(temp_frame_probs_simulation->obmc_probs, default_obmc_probs);
931 }
932 if (cpi->sf.inter_sf.prune_warped_prob_thresh > 0) {
933 av1_copy(temp_frame_probs_simulation->warped_probs, default_warped_probs);
934 }
935 if (cpi->sf.interp_sf.adaptive_interp_filter_search == 2) {
936 av1_copy(temp_frame_probs_simulation->switchable_interp_probs,
937 default_switchable_interp_probs);
938 }
939 }
940 #endif
941 }
942
restore_cdef_coding_context(CdefInfo * const dst,const CdefInfo * const src)943 static AOM_INLINE void restore_cdef_coding_context(CdefInfo *const dst,
944 const CdefInfo *const src) {
945 dst->cdef_bits = src->cdef_bits;
946 dst->cdef_damping = src->cdef_damping;
947 av1_copy(dst->cdef_strengths, src->cdef_strengths);
948 av1_copy(dst->cdef_uv_strengths, src->cdef_uv_strengths);
949 dst->nb_cdef_strengths = src->nb_cdef_strengths;
950 }
951
952 // Coding context that only needs to be restored when recode loop includes
953 // filtering (deblocking, CDEF, superres post-encode upscale and/or loop
954 // restoraton).
restore_extra_coding_context(AV1_COMP * cpi)955 static AOM_INLINE void restore_extra_coding_context(AV1_COMP *cpi) {
956 CODING_CONTEXT *const cc = &cpi->coding_context;
957 AV1_COMMON *cm = &cpi->common;
958 cm->lf = cc->lf;
959 restore_cdef_coding_context(&cm->cdef_info, &cc->cdef_info);
960 cpi->rc = cc->rc;
961 cpi->ppi->mv_stats = cc->mv_stats;
962 }
963
equal_dimensions_and_border(const YV12_BUFFER_CONFIG * a,const YV12_BUFFER_CONFIG * b)964 static AOM_INLINE int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
965 const YV12_BUFFER_CONFIG *b) {
966 return a->y_height == b->y_height && a->y_width == b->y_width &&
967 a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
968 a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
969 a->border == b->border &&
970 (a->flags & YV12_FLAG_HIGHBITDEPTH) ==
971 (b->flags & YV12_FLAG_HIGHBITDEPTH);
972 }
973
update_entropy(bool * ext_refresh_frame_context,bool * ext_refresh_frame_context_pending,bool update)974 static AOM_INLINE int update_entropy(bool *ext_refresh_frame_context,
975 bool *ext_refresh_frame_context_pending,
976 bool update) {
977 *ext_refresh_frame_context = update;
978 *ext_refresh_frame_context_pending = 1;
979 return 0;
980 }
981
982 #if !CONFIG_REALTIME_ONLY
combine_prior_with_tpl_boost(double min_factor,double max_factor,int prior_boost,int tpl_boost,int frames_to_key)983 static AOM_INLINE int combine_prior_with_tpl_boost(double min_factor,
984 double max_factor,
985 int prior_boost,
986 int tpl_boost,
987 int frames_to_key) {
988 double factor = sqrt((double)frames_to_key);
989 double range = max_factor - min_factor;
990 factor = AOMMIN(factor, max_factor);
991 factor = AOMMAX(factor, min_factor);
992 factor -= min_factor;
993 int boost =
994 (int)((factor * prior_boost + (range - factor) * tpl_boost) / range);
995 return boost;
996 }
997 #endif
998
set_size_independent_vars(AV1_COMP * cpi)999 static AOM_INLINE void set_size_independent_vars(AV1_COMP *cpi) {
1000 int i;
1001 AV1_COMMON *const cm = &cpi->common;
1002 FeatureFlags *const features = &cm->features;
1003 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
1004 cm->global_motion[i] = default_warp_params;
1005 }
1006 cpi->gm_info.search_done = 0;
1007
1008 av1_set_speed_features_framesize_independent(cpi, cpi->speed);
1009 av1_set_rd_speed_thresholds(cpi);
1010 features->interp_filter = SWITCHABLE;
1011 features->switchable_motion_mode = is_switchable_motion_mode_allowed(
1012 features->allow_warped_motion, cpi->oxcf.motion_mode_cfg.enable_obmc);
1013 }
1014
release_scaled_references(AV1_COMP * cpi)1015 static AOM_INLINE void release_scaled_references(AV1_COMP *cpi) {
1016 // TODO(isbs): only refresh the necessary frames, rather than all of them
1017 for (int i = 0; i < INTER_REFS_PER_FRAME; ++i) {
1018 RefCntBuffer *const buf = cpi->scaled_ref_buf[i];
1019 if (buf != NULL) {
1020 --buf->ref_count;
1021 cpi->scaled_ref_buf[i] = NULL;
1022 }
1023 }
1024 }
1025
restore_all_coding_context(AV1_COMP * cpi)1026 static AOM_INLINE void restore_all_coding_context(AV1_COMP *cpi) {
1027 restore_extra_coding_context(cpi);
1028 if (!frame_is_intra_only(&cpi->common)) release_scaled_references(cpi);
1029 }
1030
reduce_num_ref_buffers(const AV1_COMP * cpi)1031 static AOM_INLINE int reduce_num_ref_buffers(const AV1_COMP *cpi) {
1032 const SequenceHeader *const seq_params = cpi->common.seq_params;
1033 return is_one_pass_rt_params(cpi) &&
1034 use_rtc_reference_structure_one_layer(cpi) &&
1035 (seq_params->order_hint_info.enable_order_hint == 0) &&
1036 cpi->rt_reduce_num_ref_buffers;
1037 }
1038
1039 // Refresh reference frame buffers according to refresh_frame_flags.
refresh_reference_frames(AV1_COMP * cpi)1040 static AOM_INLINE void refresh_reference_frames(AV1_COMP *cpi) {
1041 AV1_COMMON *const cm = &cpi->common;
1042 // All buffers are refreshed for shown keyframes and S-frames.
1043 // In case of RT, golden frame refreshes the 6th slot and other reference
1044 // frames refresh slots 0 to 5. Slot 7 is not refreshed by any reference
1045 // frame. Thus, only 7 buffers are refreshed for keyframes and S-frames
1046 // instead of 8.
1047 int num_ref_buffers = REF_FRAMES;
1048 if (reduce_num_ref_buffers(cpi)) {
1049 const int refresh_all_bufs =
1050 (cpi->ppi->gf_group.refbuf_state[cpi->gf_frame_index] == REFBUF_RESET ||
1051 frame_is_sframe(cm));
1052 assert(IMPLIES(((cm->current_frame.refresh_frame_flags >> 7) & 1) == 1,
1053 refresh_all_bufs));
1054 (void)refresh_all_bufs;
1055 num_ref_buffers--;
1056 }
1057
1058 for (int ref_frame = 0; ref_frame < num_ref_buffers; ref_frame++) {
1059 if (((cm->current_frame.refresh_frame_flags >> ref_frame) & 1) == 1) {
1060 assign_frame_buffer_p(&cm->ref_frame_map[ref_frame], cm->cur_frame);
1061 }
1062 }
1063 }
1064
1065 void av1_update_film_grain_parameters_seq(struct AV1_PRIMARY *ppi,
1066 const AV1EncoderConfig *oxcf);
1067 void av1_update_film_grain_parameters(struct AV1_COMP *cpi,
1068 const AV1EncoderConfig *oxcf);
1069
1070 void av1_scale_references(AV1_COMP *cpi, const InterpFilter filter,
1071 const int phase, const int use_optimized_scaler);
1072
1073 void av1_setup_frame(AV1_COMP *cpi);
1074
1075 BLOCK_SIZE av1_select_sb_size(const AV1EncoderConfig *const oxcf, int width,
1076 int height, int number_spatial_layers);
1077
1078 void av1_apply_active_map(AV1_COMP *cpi);
1079
1080 #if !CONFIG_REALTIME_ONLY
1081 uint16_t av1_setup_interp_filter_search_mask(AV1_COMP *cpi);
1082
1083 void av1_determine_sc_tools_with_encoding(AV1_COMP *cpi, const int q_orig);
1084 #endif
1085
1086 void av1_set_size_dependent_vars(AV1_COMP *cpi, int *q, int *bottom_index,
1087 int *top_index);
1088
1089 void av1_finalize_encoded_frame(AV1_COMP *const cpi);
1090
1091 int av1_is_integer_mv(const YV12_BUFFER_CONFIG *cur_picture,
1092 const YV12_BUFFER_CONFIG *last_picture,
1093 ForceIntegerMVInfo *const force_intpel_info);
1094
1095 void av1_set_mb_ssim_rdmult_scaling(AV1_COMP *cpi);
1096
1097 void av1_save_all_coding_context(AV1_COMP *cpi);
1098
1099 #if DUMP_RECON_FRAMES == 1
1100 void av1_dump_filtered_recon_frames(AV1_COMP *cpi);
1101 #endif
1102
av1_get_enc_border_size(bool resize,bool all_intra,BLOCK_SIZE sb_size)1103 static AOM_INLINE int av1_get_enc_border_size(bool resize, bool all_intra,
1104 BLOCK_SIZE sb_size) {
1105 // For allintra encoding mode, inter-frame motion search is not applicable and
1106 // the intraBC motion vectors are restricted within the tile boundaries. Hence
1107 // a smaller frame border size (AOM_ENC_ALLINTRA_BORDER) is used in this case.
1108 if (resize) {
1109 return AOM_BORDER_IN_PIXELS;
1110 }
1111 if (all_intra) {
1112 return AOM_ENC_ALLINTRA_BORDER;
1113 }
1114 return block_size_wide[sb_size] + 32;
1115 }
1116
av1_is_resize_needed(const AV1EncoderConfig * oxcf)1117 static AOM_INLINE bool av1_is_resize_needed(const AV1EncoderConfig *oxcf) {
1118 const ResizeCfg *resize_cfg = &oxcf->resize_cfg;
1119 const SuperResCfg *superres_cfg = &oxcf->superres_cfg;
1120 return resize_cfg->resize_mode || superres_cfg->superres_mode;
1121 }
1122
1123 #ifdef __cplusplus
1124 } // extern "C"
1125 #endif
1126
1127 #endif // AOM_AV1_ENCODER_ENCODER_UTILS_H_
1128