/src/aom/av1/encoder/intra_mode_search_utils.h
Line | Count | Source |
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 | | /*!\file |
13 | | * \brief Defines utility functions used in intra mode search. |
14 | | * |
15 | | * This includes rdcost estimations, histogram based pruning, etc. |
16 | | */ |
17 | | #ifndef AOM_AV1_ENCODER_INTRA_MODE_SEARCH_UTILS_H_ |
18 | | #define AOM_AV1_ENCODER_INTRA_MODE_SEARCH_UTILS_H_ |
19 | | |
20 | | #include "config/av1_rtcd.h" |
21 | | |
22 | | #include "av1/common/enums.h" |
23 | | #include "av1/common/pred_common.h" |
24 | | #include "av1/common/reconintra.h" |
25 | | |
26 | | #include "av1/encoder/encoder.h" |
27 | | #include "av1/encoder/encodeframe.h" |
28 | | #include "av1/encoder/model_rd.h" |
29 | | #include "av1/encoder/palette.h" |
30 | | #include "av1/encoder/hybrid_fwd_txfm.h" |
31 | | |
32 | | #ifdef __cplusplus |
33 | | extern "C" { |
34 | | #endif |
35 | | |
36 | | /*!\cond */ |
37 | | // Macro for computing the speed-preset dependent threshold which is used for |
38 | | // deciding whether to enable/disable variance calculations in |
39 | | // intra_rd_variance_factor(). |
40 | 0 | #define INTRA_RD_VAR_THRESH(X) (1.0 - (0.25 * (X))) |
41 | | |
42 | 0 | #define HOG_BINS 32 |
43 | 0 | #define HOG_FIX_PREC_BITS 16 |
44 | | static const float av1_intra_hog_model_bias[DIRECTIONAL_MODES] = { |
45 | | 0.450578f, 0.695518f, -0.717944f, -0.639894f, |
46 | | -0.602019f, -0.453454f, 0.055857f, -0.465480f, |
47 | | }; |
48 | | |
49 | | static const float av1_intra_hog_model_weights[HOG_BINS * DIRECTIONAL_MODES] = { |
50 | | -3.076402f, -3.757063f, -3.275266f, -3.180665f, -3.452105f, -3.216593f, |
51 | | -2.871212f, -3.134296f, -1.822324f, -2.401411f, -1.541016f, -1.195322f, |
52 | | -0.434156f, 0.322868f, 2.260546f, 3.368715f, 3.989290f, 3.308487f, |
53 | | 2.277893f, 0.923793f, 0.026412f, -0.385174f, -0.718622f, -1.408867f, |
54 | | -1.050558f, -2.323941f, -2.225827f, -2.585453f, -3.054283f, -2.875087f, |
55 | | -2.985709f, -3.447155f, 3.758139f, 3.204353f, 2.170998f, 0.826587f, |
56 | | -0.269665f, -0.702068f, -1.085776f, -2.175249f, -1.623180f, -2.975142f, |
57 | | -2.779629f, -3.190799f, -3.521900f, -3.375480f, -3.319355f, -3.897389f, |
58 | | -3.172334f, -3.594528f, -2.879132f, -2.547777f, -2.921023f, -2.281844f, |
59 | | -1.818988f, -2.041771f, -0.618268f, -1.396458f, -0.567153f, -0.285868f, |
60 | | -0.088058f, 0.753494f, 2.092413f, 3.215266f, -3.300277f, -2.748658f, |
61 | | -2.315784f, -2.423671f, -2.257283f, -2.269583f, -2.196660f, -2.301076f, |
62 | | -2.646516f, -2.271319f, -2.254366f, -2.300102f, -2.217960f, -2.473300f, |
63 | | -2.116866f, -2.528246f, -3.314712f, -1.701010f, -0.589040f, -0.088077f, |
64 | | 0.813112f, 1.702213f, 2.653045f, 3.351749f, 3.243554f, 3.199409f, |
65 | | 2.437856f, 1.468854f, 0.533039f, -0.099065f, -0.622643f, -2.200732f, |
66 | | -4.228861f, -2.875263f, -1.273956f, -0.433280f, 0.803771f, 1.975043f, |
67 | | 3.179528f, 3.939064f, 3.454379f, 3.689386f, 3.116411f, 1.970991f, |
68 | | 0.798406f, -0.628514f, -1.252546f, -2.825176f, -4.090178f, -3.777448f, |
69 | | -3.227314f, -3.479403f, -3.320569f, -3.159372f, -2.729202f, -2.722341f, |
70 | | -3.054913f, -2.742923f, -2.612703f, -2.662632f, -2.907314f, -3.117794f, |
71 | | -3.102660f, -3.970972f, -4.891357f, -3.935582f, -3.347758f, -2.721924f, |
72 | | -2.219011f, -1.702391f, -0.866529f, -0.153743f, 0.107733f, 1.416882f, |
73 | | 2.572884f, 3.607755f, 3.974820f, 3.997783f, 2.970459f, 0.791687f, |
74 | | -1.478921f, -1.228154f, -1.216955f, -1.765932f, -1.951003f, -1.985301f, |
75 | | -1.975881f, -1.985593f, -2.422371f, -2.419978f, -2.531288f, -2.951853f, |
76 | | -3.071380f, -3.277027f, -3.373539f, -4.462010f, -0.967888f, 0.805524f, |
77 | | 2.794130f, 3.685984f, 3.745195f, 3.252444f, 2.316108f, 1.399146f, |
78 | | -0.136519f, -0.162811f, -1.004357f, -1.667911f, -1.964662f, -2.937579f, |
79 | | -3.019533f, -3.942766f, -5.102767f, -3.882073f, -3.532027f, -3.451956f, |
80 | | -2.944015f, -2.643064f, -2.529872f, -2.077290f, -2.809965f, -1.803734f, |
81 | | -1.783593f, -1.662585f, -1.415484f, -1.392673f, -0.788794f, -1.204819f, |
82 | | -1.998864f, -1.182102f, -0.892110f, -1.317415f, -1.359112f, -1.522867f, |
83 | | -1.468552f, -1.779072f, -2.332959f, -2.160346f, -2.329387f, -2.631259f, |
84 | | -2.744936f, -3.052494f, -2.787363f, -3.442548f, -4.245075f, -3.032172f, |
85 | | -2.061609f, -1.768116f, -1.286072f, -0.706587f, -0.192413f, 0.386938f, |
86 | | 0.716997f, 1.481393f, 2.216702f, 2.737986f, 3.109809f, 3.226084f, |
87 | | 2.490098f, -0.095827f, -3.864816f, -3.507248f, -3.128925f, -2.908251f, |
88 | | -2.883836f, -2.881411f, -2.524377f, -2.624478f, -2.399573f, -2.367718f, |
89 | | -1.918255f, -1.926277f, -1.694584f, -1.723790f, -0.966491f, -1.183115f, |
90 | | -1.430687f, 0.872896f, 2.766550f, 3.610080f, 3.578041f, 3.334928f, |
91 | | 2.586680f, 1.895721f, 1.122195f, 0.488519f, -0.140689f, -0.799076f, |
92 | | -1.222860f, -1.502437f, -1.900969f, -3.206816f, |
93 | | }; |
94 | | |
95 | | static const NN_CONFIG av1_intra_hog_model_nnconfig = { |
96 | | HOG_BINS, // num_inputs |
97 | | DIRECTIONAL_MODES, // num_outputs |
98 | | 0, // num_hidden_layers |
99 | | { 0 }, |
100 | | { |
101 | | av1_intra_hog_model_weights, |
102 | | }, |
103 | | { |
104 | | av1_intra_hog_model_bias, |
105 | | }, |
106 | | }; |
107 | | |
108 | | typedef int (*hog_bin_lookup_fn)(int dx, int dy); |
109 | | |
110 | 0 | static AOM_FORCE_INLINE const int32_t *av1_get_hog_thresholds(void) { |
111 | 0 | DECLARE_ALIGNED(64, static const int32_t, thresholds[HOG_BINS]) = { |
112 | 0 | -1334015, -441798, -261605, -183158, -138560, -109331, -88359, -72303, |
113 | 0 | -59392, -48579, -39272, -30982, -23445, -16400, -9715, -3194, |
114 | 0 | 3227, 9748, 16433, 23478, 31015, 39305, 48611, 59425, |
115 | 0 | 72336, 88392, 109364, 138593, 183191, 261638, 441831, INT32_MAX |
116 | 0 | }; |
117 | 0 | return thresholds; |
118 | 0 | } Unexecuted instantiation: rdopt.c:av1_get_hog_thresholds Unexecuted instantiation: temporal_filter.c:av1_get_hog_thresholds Unexecuted instantiation: intra_mode_search.c:av1_get_hog_thresholds Unexecuted instantiation: intra_mode_search_sse2.c:av1_get_hog_thresholds Unexecuted instantiation: compound_type.c:av1_get_hog_thresholds Unexecuted instantiation: encodeframe.c:av1_get_hog_thresholds Unexecuted instantiation: encode_strategy.c:av1_get_hog_thresholds Unexecuted instantiation: encoder.c:av1_get_hog_thresholds Unexecuted instantiation: encoder_utils.c:av1_get_hog_thresholds Unexecuted instantiation: ethread.c:av1_get_hog_thresholds Unexecuted instantiation: palette.c:av1_get_hog_thresholds Unexecuted instantiation: partition_search.c:av1_get_hog_thresholds Unexecuted instantiation: superres_scale.c:av1_get_hog_thresholds Unexecuted instantiation: svc_layercontext.c:av1_get_hog_thresholds Unexecuted instantiation: av1_cx_iface.c:av1_get_hog_thresholds |
119 | | |
120 | 0 | static inline int get_hist_bin_idx(int dx, int dy) { |
121 | 0 | if (dy == 0) return 16; |
122 | 0 | const int32_t ratio = (dy * (1 << HOG_FIX_PREC_BITS)) / dx; |
123 | 0 | const int32_t *const thresholds = av1_get_hog_thresholds(); |
124 | | |
125 | | // Branchless 5-step binary search across the 32 thresholds. |
126 | 0 | int idx = (ratio > thresholds[15]) << 4; |
127 | 0 | idx += (ratio > thresholds[idx + 7]) << 3; |
128 | 0 | idx += (ratio > thresholds[idx + 3]) << 2; |
129 | 0 | idx += (ratio > thresholds[idx + 1]) << 1; |
130 | 0 | idx += (ratio > thresholds[idx]); |
131 | 0 | return idx; |
132 | 0 | } Unexecuted instantiation: rdopt.c:get_hist_bin_idx Unexecuted instantiation: temporal_filter.c:get_hist_bin_idx Unexecuted instantiation: intra_mode_search.c:get_hist_bin_idx Unexecuted instantiation: intra_mode_search_sse2.c:get_hist_bin_idx Unexecuted instantiation: compound_type.c:get_hist_bin_idx Unexecuted instantiation: encodeframe.c:get_hist_bin_idx Unexecuted instantiation: encode_strategy.c:get_hist_bin_idx Unexecuted instantiation: encoder.c:get_hist_bin_idx Unexecuted instantiation: encoder_utils.c:get_hist_bin_idx Unexecuted instantiation: ethread.c:get_hist_bin_idx Unexecuted instantiation: palette.c:get_hist_bin_idx Unexecuted instantiation: partition_search.c:get_hist_bin_idx Unexecuted instantiation: superres_scale.c:get_hist_bin_idx Unexecuted instantiation: svc_layercontext.c:get_hist_bin_idx Unexecuted instantiation: av1_cx_iface.c:get_hist_bin_idx |
133 | | |
134 | | // Normalizes the hog data. |
135 | 0 | static inline void normalize_hog(float total, float *hist) { |
136 | 0 | for (int i = 0; i < HOG_BINS; ++i) hist[i] /= total; |
137 | 0 | } Unexecuted instantiation: rdopt.c:normalize_hog Unexecuted instantiation: temporal_filter.c:normalize_hog Unexecuted instantiation: intra_mode_search.c:normalize_hog Unexecuted instantiation: intra_mode_search_sse2.c:normalize_hog Unexecuted instantiation: compound_type.c:normalize_hog Unexecuted instantiation: encodeframe.c:normalize_hog Unexecuted instantiation: encode_strategy.c:normalize_hog Unexecuted instantiation: encoder.c:normalize_hog Unexecuted instantiation: encoder_utils.c:normalize_hog Unexecuted instantiation: ethread.c:normalize_hog Unexecuted instantiation: palette.c:normalize_hog Unexecuted instantiation: partition_search.c:normalize_hog Unexecuted instantiation: superres_scale.c:normalize_hog Unexecuted instantiation: svc_layercontext.c:normalize_hog Unexecuted instantiation: av1_cx_iface.c:normalize_hog |
138 | | |
139 | | static AOM_FORCE_INLINE void lowbd_generate_hog(const uint8_t *src, int stride, |
140 | | int rows, int cols, float *hist, |
141 | 0 | hog_bin_lookup_fn get_bin_idx) { |
142 | 0 | float total = 0.1f; |
143 | 0 | if (cols >= 3) { |
144 | 0 | src += stride; |
145 | 0 | for (int r = 1; r < rows - 1; ++r) { |
146 | 0 | const uint8_t *row_above = src - stride; |
147 | 0 | const uint8_t *row_cur = src; |
148 | 0 | const uint8_t *row_below = src + stride; |
149 | | |
150 | | // Prime the 3x3 sliding Sobel window with columns 0 and 1. |
151 | 0 | int v0 = row_above[0] + 2 * row_cur[0] + row_below[0]; |
152 | 0 | int v1 = row_above[1] + 2 * row_cur[1] + row_below[1]; |
153 | 0 | int d0 = row_below[0] - row_above[0]; |
154 | 0 | int d1 = row_below[1] - row_above[1]; |
155 | |
|
156 | 0 | for (int c = 1; c < cols - 1; ++c) { |
157 | | // Load the incoming right column (c + 1) and update Sobel gradients. |
158 | 0 | const int above_r = row_above[c + 1]; |
159 | 0 | const int cur_r = row_cur[c + 1]; |
160 | 0 | const int below_r = row_below[c + 1]; |
161 | 0 | const int v2 = above_r + 2 * cur_r + below_r; |
162 | 0 | const int d2 = below_r - above_r; |
163 | 0 | const int dx = v2 - v0; |
164 | 0 | const int dy = d0 + 2 * d1 + d2; |
165 | 0 | v0 = v1; |
166 | 0 | v1 = v2; |
167 | 0 | d0 = d1; |
168 | 0 | d1 = d2; |
169 | |
|
170 | 0 | if ((dx | dy) == 0) continue; |
171 | 0 | const int temp = abs(dx) + abs(dy); |
172 | 0 | total += temp; |
173 | 0 | if (dx == 0) { |
174 | 0 | hist[0] += temp / 2; |
175 | 0 | hist[HOG_BINS - 1] += temp / 2; |
176 | 0 | } else { |
177 | 0 | const int idx = get_bin_idx(dx, dy); |
178 | 0 | assert(idx >= 0 && idx < HOG_BINS); |
179 | 0 | hist[idx] += temp; |
180 | 0 | } |
181 | 0 | } |
182 | 0 | src += stride; |
183 | 0 | } |
184 | 0 | } |
185 | | |
186 | 0 | normalize_hog(total, hist); |
187 | 0 | } Unexecuted instantiation: rdopt.c:lowbd_generate_hog Unexecuted instantiation: temporal_filter.c:lowbd_generate_hog Unexecuted instantiation: intra_mode_search.c:lowbd_generate_hog Unexecuted instantiation: intra_mode_search_sse2.c:lowbd_generate_hog Unexecuted instantiation: compound_type.c:lowbd_generate_hog Unexecuted instantiation: encodeframe.c:lowbd_generate_hog Unexecuted instantiation: encode_strategy.c:lowbd_generate_hog Unexecuted instantiation: encoder.c:lowbd_generate_hog Unexecuted instantiation: encoder_utils.c:lowbd_generate_hog Unexecuted instantiation: ethread.c:lowbd_generate_hog Unexecuted instantiation: palette.c:lowbd_generate_hog Unexecuted instantiation: partition_search.c:lowbd_generate_hog Unexecuted instantiation: superres_scale.c:lowbd_generate_hog Unexecuted instantiation: svc_layercontext.c:lowbd_generate_hog Unexecuted instantiation: av1_cx_iface.c:lowbd_generate_hog |
188 | | |
189 | | // Computes and stores pixel level gradient information of a given superblock |
190 | | // for LBD encode. |
191 | | static AOM_FORCE_INLINE void lowbd_compute_gradient_info_sb( |
192 | | MACROBLOCK *const x, BLOCK_SIZE sb_size, PLANE_TYPE plane, |
193 | 0 | hog_bin_lookup_fn get_bin_idx) { |
194 | 0 | PixelLevelGradientInfo *const grad_info_sb = |
195 | 0 | x->pixel_gradient_info + plane * MAX_SB_SQUARE; |
196 | 0 | const uint8_t *src = x->plane[plane].src.buf; |
197 | 0 | const int stride = x->plane[plane].src.stride; |
198 | 0 | const int ss_x = x->e_mbd.plane[plane].subsampling_x; |
199 | 0 | const int ss_y = x->e_mbd.plane[plane].subsampling_y; |
200 | 0 | const int sb_height = block_size_high[sb_size] >> ss_y; |
201 | 0 | const int sb_width = block_size_wide[sb_size] >> ss_x; |
202 | 0 | if (sb_width < 3) return; |
203 | 0 | src += stride; |
204 | 0 | for (int r = 1; r < sb_height - 1; ++r) { |
205 | 0 | const uint8_t *row_above = src - stride; |
206 | 0 | const uint8_t *row_cur = src; |
207 | 0 | const uint8_t *row_below = src + stride; |
208 | | |
209 | | // Prime the 3x3 sliding Sobel window with columns 0 and 1. |
210 | 0 | int v0 = row_above[0] + 2 * row_cur[0] + row_below[0]; |
211 | 0 | int v1 = row_above[1] + 2 * row_cur[1] + row_below[1]; |
212 | 0 | int d0 = row_below[0] - row_above[0]; |
213 | 0 | int d1 = row_below[1] - row_above[1]; |
214 | 0 | PixelLevelGradientInfo *const row_info = grad_info_sb + r * sb_width; |
215 | |
|
216 | 0 | for (int c = 1; c < sb_width - 1; ++c) { |
217 | | // Load the incoming right column (c + 1) and update Sobel gradients. |
218 | 0 | const int above_r = row_above[c + 1]; |
219 | 0 | const int cur_r = row_cur[c + 1]; |
220 | 0 | const int below_r = row_below[c + 1]; |
221 | 0 | const int v2 = above_r + 2 * cur_r + below_r; |
222 | 0 | const int d2 = below_r - above_r; |
223 | 0 | const int dx = v2 - v0; |
224 | 0 | const int dy = d0 + 2 * d1 + d2; |
225 | 0 | v0 = v1; |
226 | 0 | v1 = v2; |
227 | 0 | d0 = d1; |
228 | 0 | d1 = d2; |
229 | |
|
230 | 0 | row_info[c].abs_dx_abs_dy_sum = (uint16_t)(abs(dx) + abs(dy)); |
231 | 0 | row_info[c].hist_bin_idx = |
232 | 0 | (dx == 0) ? HOG_BINS : (int8_t)get_bin_idx(dx, dy); |
233 | 0 | } |
234 | 0 | src += stride; |
235 | 0 | } |
236 | 0 | } Unexecuted instantiation: rdopt.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: temporal_filter.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: intra_mode_search.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: intra_mode_search_sse2.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: compound_type.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: encodeframe.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: encode_strategy.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: encoder.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: encoder_utils.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: ethread.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: palette.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: partition_search.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: superres_scale.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: svc_layercontext.c:lowbd_compute_gradient_info_sb Unexecuted instantiation: av1_cx_iface.c:lowbd_compute_gradient_info_sb |
237 | | |
238 | | #if CONFIG_AV1_HIGHBITDEPTH |
239 | | static AOM_FORCE_INLINE void highbd_generate_hog( |
240 | | const uint8_t *src8, int stride, int rows, int cols, float *hist, |
241 | 0 | hog_bin_lookup_fn get_bin_idx) { |
242 | 0 | float total = 0.1f; |
243 | 0 | if (cols >= 3) { |
244 | 0 | const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
245 | 0 | src += stride; |
246 | 0 | for (int r = 1; r < rows - 1; ++r) { |
247 | 0 | const uint16_t *row_above = src - stride; |
248 | 0 | const uint16_t *row_cur = src; |
249 | 0 | const uint16_t *row_below = src + stride; |
250 | | |
251 | | // Prime the 3x3 sliding Sobel window with columns 0 and 1. |
252 | 0 | int v0 = row_above[0] + 2 * row_cur[0] + row_below[0]; |
253 | 0 | int v1 = row_above[1] + 2 * row_cur[1] + row_below[1]; |
254 | 0 | int d0 = row_below[0] - row_above[0]; |
255 | 0 | int d1 = row_below[1] - row_above[1]; |
256 | |
|
257 | 0 | for (int c = 1; c < cols - 1; ++c) { |
258 | | // Load the incoming right column (c + 1) and update Sobel gradients. |
259 | 0 | const int above_r = row_above[c + 1]; |
260 | 0 | const int cur_r = row_cur[c + 1]; |
261 | 0 | const int below_r = row_below[c + 1]; |
262 | 0 | const int v2 = above_r + 2 * cur_r + below_r; |
263 | 0 | const int d2 = below_r - above_r; |
264 | 0 | const int dx = v2 - v0; |
265 | 0 | const int dy = d0 + 2 * d1 + d2; |
266 | 0 | v0 = v1; |
267 | 0 | v1 = v2; |
268 | 0 | d0 = d1; |
269 | 0 | d1 = d2; |
270 | |
|
271 | 0 | if ((dx | dy) == 0) continue; |
272 | 0 | const int temp = abs(dx) + abs(dy); |
273 | 0 | total += temp; |
274 | 0 | if (dx == 0) { |
275 | 0 | hist[0] += temp / 2; |
276 | 0 | hist[HOG_BINS - 1] += temp / 2; |
277 | 0 | } else { |
278 | 0 | const int idx = get_bin_idx(dx, dy); |
279 | 0 | assert(idx >= 0 && idx < HOG_BINS); |
280 | 0 | hist[idx] += temp; |
281 | 0 | } |
282 | 0 | } |
283 | 0 | src += stride; |
284 | 0 | } |
285 | 0 | } |
286 | | |
287 | 0 | normalize_hog(total, hist); |
288 | 0 | } Unexecuted instantiation: rdopt.c:highbd_generate_hog Unexecuted instantiation: temporal_filter.c:highbd_generate_hog Unexecuted instantiation: intra_mode_search.c:highbd_generate_hog Unexecuted instantiation: intra_mode_search_sse2.c:highbd_generate_hog Unexecuted instantiation: compound_type.c:highbd_generate_hog Unexecuted instantiation: encodeframe.c:highbd_generate_hog Unexecuted instantiation: encode_strategy.c:highbd_generate_hog Unexecuted instantiation: encoder.c:highbd_generate_hog Unexecuted instantiation: encoder_utils.c:highbd_generate_hog Unexecuted instantiation: ethread.c:highbd_generate_hog Unexecuted instantiation: palette.c:highbd_generate_hog Unexecuted instantiation: partition_search.c:highbd_generate_hog Unexecuted instantiation: superres_scale.c:highbd_generate_hog Unexecuted instantiation: svc_layercontext.c:highbd_generate_hog Unexecuted instantiation: av1_cx_iface.c:highbd_generate_hog |
289 | | |
290 | | // Computes and stores pixel level gradient information of a given superblock |
291 | | // for HBD encode. |
292 | | static AOM_FORCE_INLINE void highbd_compute_gradient_info_sb( |
293 | | MACROBLOCK *const x, BLOCK_SIZE sb_size, PLANE_TYPE plane, |
294 | 0 | hog_bin_lookup_fn get_bin_idx) { |
295 | 0 | PixelLevelGradientInfo *const grad_info_sb = |
296 | 0 | x->pixel_gradient_info + plane * MAX_SB_SQUARE; |
297 | 0 | const uint16_t *src = CONVERT_TO_SHORTPTR(x->plane[plane].src.buf); |
298 | 0 | const int stride = x->plane[plane].src.stride; |
299 | 0 | const int ss_x = x->e_mbd.plane[plane].subsampling_x; |
300 | 0 | const int ss_y = x->e_mbd.plane[plane].subsampling_y; |
301 | 0 | const int sb_height = block_size_high[sb_size] >> ss_y; |
302 | 0 | const int sb_width = block_size_wide[sb_size] >> ss_x; |
303 | 0 | if (sb_width < 3) return; |
304 | 0 | src += stride; |
305 | 0 | for (int r = 1; r < sb_height - 1; ++r) { |
306 | 0 | const uint16_t *row_above = src - stride; |
307 | 0 | const uint16_t *row_cur = src; |
308 | 0 | const uint16_t *row_below = src + stride; |
309 | | |
310 | | // Prime the 3x3 sliding Sobel window with columns 0 and 1. |
311 | 0 | int v0 = row_above[0] + 2 * row_cur[0] + row_below[0]; |
312 | 0 | int v1 = row_above[1] + 2 * row_cur[1] + row_below[1]; |
313 | 0 | int d0 = row_below[0] - row_above[0]; |
314 | 0 | int d1 = row_below[1] - row_above[1]; |
315 | 0 | PixelLevelGradientInfo *const row_info = grad_info_sb + r * sb_width; |
316 | |
|
317 | 0 | for (int c = 1; c < sb_width - 1; ++c) { |
318 | | // Load the incoming right column (c + 1) and update Sobel gradients. |
319 | 0 | const int above_r = row_above[c + 1]; |
320 | 0 | const int cur_r = row_cur[c + 1]; |
321 | 0 | const int below_r = row_below[c + 1]; |
322 | 0 | const int v2 = above_r + 2 * cur_r + below_r; |
323 | 0 | const int d2 = below_r - above_r; |
324 | 0 | const int dx = v2 - v0; |
325 | 0 | const int dy = d0 + 2 * d1 + d2; |
326 | 0 | v0 = v1; |
327 | 0 | v1 = v2; |
328 | 0 | d0 = d1; |
329 | 0 | d1 = d2; |
330 | |
|
331 | 0 | row_info[c].abs_dx_abs_dy_sum = (uint16_t)(abs(dx) + abs(dy)); |
332 | 0 | row_info[c].hist_bin_idx = |
333 | 0 | (dx == 0) ? HOG_BINS : (int8_t)get_bin_idx(dx, dy); |
334 | 0 | } |
335 | 0 | src += stride; |
336 | 0 | } |
337 | 0 | } Unexecuted instantiation: rdopt.c:highbd_compute_gradient_info_sb Unexecuted instantiation: temporal_filter.c:highbd_compute_gradient_info_sb Unexecuted instantiation: intra_mode_search.c:highbd_compute_gradient_info_sb Unexecuted instantiation: intra_mode_search_sse2.c:highbd_compute_gradient_info_sb Unexecuted instantiation: compound_type.c:highbd_compute_gradient_info_sb Unexecuted instantiation: encodeframe.c:highbd_compute_gradient_info_sb Unexecuted instantiation: encode_strategy.c:highbd_compute_gradient_info_sb Unexecuted instantiation: encoder.c:highbd_compute_gradient_info_sb Unexecuted instantiation: encoder_utils.c:highbd_compute_gradient_info_sb Unexecuted instantiation: ethread.c:highbd_compute_gradient_info_sb Unexecuted instantiation: palette.c:highbd_compute_gradient_info_sb Unexecuted instantiation: partition_search.c:highbd_compute_gradient_info_sb Unexecuted instantiation: superres_scale.c:highbd_compute_gradient_info_sb Unexecuted instantiation: svc_layercontext.c:highbd_compute_gradient_info_sb Unexecuted instantiation: av1_cx_iface.c:highbd_compute_gradient_info_sb |
338 | | #endif // CONFIG_AV1_HIGHBITDEPTH |
339 | | |
340 | | static inline void generate_hog(const uint8_t *src8, int stride, int rows, |
341 | 0 | int cols, float *hist, int highbd) { |
342 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
343 | 0 | if (highbd) { |
344 | 0 | av1_highbd_generate_hog(src8, stride, rows, cols, hist); |
345 | 0 | return; |
346 | 0 | } |
347 | | #else |
348 | | (void)highbd; |
349 | | #endif // CONFIG_AV1_HIGHBITDEPTH |
350 | 0 | av1_lowbd_generate_hog(src8, stride, rows, cols, hist); |
351 | 0 | } Unexecuted instantiation: rdopt.c:generate_hog Unexecuted instantiation: temporal_filter.c:generate_hog Unexecuted instantiation: intra_mode_search.c:generate_hog Unexecuted instantiation: intra_mode_search_sse2.c:generate_hog Unexecuted instantiation: compound_type.c:generate_hog Unexecuted instantiation: encodeframe.c:generate_hog Unexecuted instantiation: encode_strategy.c:generate_hog Unexecuted instantiation: encoder.c:generate_hog Unexecuted instantiation: encoder_utils.c:generate_hog Unexecuted instantiation: ethread.c:generate_hog Unexecuted instantiation: palette.c:generate_hog Unexecuted instantiation: partition_search.c:generate_hog Unexecuted instantiation: superres_scale.c:generate_hog Unexecuted instantiation: svc_layercontext.c:generate_hog Unexecuted instantiation: av1_cx_iface.c:generate_hog |
352 | | |
353 | | static inline void compute_gradient_info_sb(MACROBLOCK *const x, |
354 | | BLOCK_SIZE sb_size, |
355 | 0 | PLANE_TYPE plane) { |
356 | 0 | #if CONFIG_AV1_HIGHBITDEPTH |
357 | 0 | if (is_cur_buf_hbd(&x->e_mbd)) { |
358 | 0 | av1_highbd_compute_gradient_info_sb(x, sb_size, plane); |
359 | 0 | return; |
360 | 0 | } |
361 | 0 | #endif // CONFIG_AV1_HIGHBITDEPTH |
362 | 0 | av1_lowbd_compute_gradient_info_sb(x, sb_size, plane); |
363 | 0 | } Unexecuted instantiation: rdopt.c:compute_gradient_info_sb Unexecuted instantiation: temporal_filter.c:compute_gradient_info_sb Unexecuted instantiation: intra_mode_search.c:compute_gradient_info_sb Unexecuted instantiation: intra_mode_search_sse2.c:compute_gradient_info_sb Unexecuted instantiation: compound_type.c:compute_gradient_info_sb Unexecuted instantiation: encodeframe.c:compute_gradient_info_sb Unexecuted instantiation: encode_strategy.c:compute_gradient_info_sb Unexecuted instantiation: encoder.c:compute_gradient_info_sb Unexecuted instantiation: encoder_utils.c:compute_gradient_info_sb Unexecuted instantiation: ethread.c:compute_gradient_info_sb Unexecuted instantiation: palette.c:compute_gradient_info_sb Unexecuted instantiation: partition_search.c:compute_gradient_info_sb Unexecuted instantiation: superres_scale.c:compute_gradient_info_sb Unexecuted instantiation: svc_layercontext.c:compute_gradient_info_sb Unexecuted instantiation: av1_cx_iface.c:compute_gradient_info_sb |
364 | | |
365 | | // Gradient caching at superblock level is allowed only if all of the following |
366 | | // conditions are satisfied: |
367 | | // (1) The current frame is an intra only frame |
368 | | // (2) Non-RD mode decisions are not enabled |
369 | | // (3) The sf partition_search_type is set to SEARCH_PARTITION |
370 | | // (4) Either intra_pruning_with_hog or chroma_intra_pruning_with_hog is enabled |
371 | | // |
372 | | // SB level caching of gradient data may not help in speedup for the following |
373 | | // cases: |
374 | | // (1) Inter frames (due to early intra gating) |
375 | | // (2) When partition_search_type is not SEARCH_PARTITION |
376 | | // Hence, gradient data is computed at block level in such cases. |
377 | | static inline bool is_gradient_caching_for_hog_enabled( |
378 | 0 | const AV1_COMP *const cpi) { |
379 | 0 | const SPEED_FEATURES *const sf = &cpi->sf; |
380 | 0 | return frame_is_intra_only(&cpi->common) && !sf->rt_sf.use_nonrd_pick_mode && |
381 | 0 | (sf->part_sf.partition_search_type == SEARCH_PARTITION) && |
382 | 0 | (sf->intra_sf.intra_pruning_with_hog || |
383 | 0 | sf->intra_sf.chroma_intra_pruning_with_hog); |
384 | 0 | } Unexecuted instantiation: rdopt.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: temporal_filter.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: intra_mode_search.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: intra_mode_search_sse2.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: compound_type.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: encodeframe.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: encode_strategy.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: encoder.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: encoder_utils.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: ethread.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: palette.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: partition_search.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: superres_scale.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: svc_layercontext.c:is_gradient_caching_for_hog_enabled Unexecuted instantiation: av1_cx_iface.c:is_gradient_caching_for_hog_enabled |
385 | | |
386 | | // Function to generate pixel level gradient information for a given superblock. |
387 | | // Sets the flags 'is_sb_gradient_cached' for the specific plane-type if |
388 | | // gradient info is generated for the same. |
389 | | static inline void produce_gradients_for_sb(AV1_COMP *cpi, MACROBLOCK *x, |
390 | | BLOCK_SIZE sb_size, int mi_row, |
391 | 0 | int mi_col) { |
392 | | // Initialise flags related to hog data caching. |
393 | 0 | x->is_sb_gradient_cached[PLANE_TYPE_Y] = false; |
394 | 0 | x->is_sb_gradient_cached[PLANE_TYPE_UV] = false; |
395 | 0 | if (!is_gradient_caching_for_hog_enabled(cpi)) return; |
396 | | |
397 | 0 | const SPEED_FEATURES *sf = &cpi->sf; |
398 | 0 | const int num_planes = av1_num_planes(&cpi->common); |
399 | |
|
400 | 0 | av1_setup_src_planes(x, cpi->source, mi_row, mi_col, num_planes, sb_size); |
401 | |
|
402 | 0 | if (sf->intra_sf.intra_pruning_with_hog) { |
403 | 0 | compute_gradient_info_sb(x, sb_size, PLANE_TYPE_Y); |
404 | 0 | x->is_sb_gradient_cached[PLANE_TYPE_Y] = true; |
405 | 0 | } |
406 | 0 | if (sf->intra_sf.chroma_intra_pruning_with_hog && num_planes > 1) { |
407 | 0 | compute_gradient_info_sb(x, sb_size, PLANE_TYPE_UV); |
408 | 0 | x->is_sb_gradient_cached[PLANE_TYPE_UV] = true; |
409 | 0 | } |
410 | 0 | } Unexecuted instantiation: rdopt.c:produce_gradients_for_sb Unexecuted instantiation: temporal_filter.c:produce_gradients_for_sb Unexecuted instantiation: intra_mode_search.c:produce_gradients_for_sb Unexecuted instantiation: intra_mode_search_sse2.c:produce_gradients_for_sb Unexecuted instantiation: compound_type.c:produce_gradients_for_sb Unexecuted instantiation: encodeframe.c:produce_gradients_for_sb Unexecuted instantiation: encode_strategy.c:produce_gradients_for_sb Unexecuted instantiation: encoder.c:produce_gradients_for_sb Unexecuted instantiation: encoder_utils.c:produce_gradients_for_sb Unexecuted instantiation: ethread.c:produce_gradients_for_sb Unexecuted instantiation: palette.c:produce_gradients_for_sb Unexecuted instantiation: partition_search.c:produce_gradients_for_sb Unexecuted instantiation: superres_scale.c:produce_gradients_for_sb Unexecuted instantiation: svc_layercontext.c:produce_gradients_for_sb Unexecuted instantiation: av1_cx_iface.c:produce_gradients_for_sb |
411 | | |
412 | | // Reuses the pixel level gradient data generated at superblock level for block |
413 | | // level histogram computation. |
414 | | static inline void generate_hog_using_gradient_cache(const MACROBLOCK *x, |
415 | | int rows, int cols, |
416 | | BLOCK_SIZE sb_size, |
417 | | PLANE_TYPE plane, |
418 | 0 | float *hist) { |
419 | 0 | float total = 0.1f; |
420 | 0 | const int ss_x = x->e_mbd.plane[plane].subsampling_x; |
421 | 0 | const int ss_y = x->e_mbd.plane[plane].subsampling_y; |
422 | 0 | const int sb_width = block_size_wide[sb_size] >> ss_x; |
423 | | |
424 | | // Derive the offset from the starting of the superblock in order to locate |
425 | | // the block level gradient data in the cache. |
426 | 0 | const int mi_row_in_sb = x->e_mbd.mi_row & (mi_size_high[sb_size] - 1); |
427 | 0 | const int mi_col_in_sb = x->e_mbd.mi_col & (mi_size_wide[sb_size] - 1); |
428 | 0 | const int block_offset_in_grad_cache = |
429 | 0 | sb_width * (mi_row_in_sb << (MI_SIZE_LOG2 - ss_y)) + |
430 | 0 | (mi_col_in_sb << (MI_SIZE_LOG2 - ss_x)); |
431 | 0 | const PixelLevelGradientInfo *grad_info_blk = x->pixel_gradient_info + |
432 | 0 | plane * MAX_SB_SQUARE + |
433 | 0 | block_offset_in_grad_cache; |
434 | | |
435 | | // Accumulate cached gradients in integers first, using bin HOG_BINS as a |
436 | | // sentinel bucket for dx == 0 so the inner loop is branchless. |
437 | 0 | uint32_t int_hist[HOG_BINS + 1] = { 0 }; |
438 | 0 | for (int r = 1; r < rows - 1; ++r) { |
439 | 0 | const PixelLevelGradientInfo *const row_info = grad_info_blk + r * sb_width; |
440 | 0 | for (int c = 1; c < cols - 1; ++c) { |
441 | 0 | const uint16_t abs_dx_abs_dy_sum = row_info[c].abs_dx_abs_dy_sum; |
442 | 0 | if (!abs_dx_abs_dy_sum) continue; |
443 | 0 | total += abs_dx_abs_dy_sum; |
444 | 0 | const uint8_t idx = (uint8_t)row_info[c].hist_bin_idx; |
445 | 0 | assert(idx <= HOG_BINS); |
446 | 0 | int_hist[idx] += abs_dx_abs_dy_sum; |
447 | 0 | } |
448 | 0 | } |
449 | | |
450 | 0 | const uint32_t dx_zero_half = int_hist[HOG_BINS] >> 1; |
451 | 0 | int_hist[0] += dx_zero_half; |
452 | 0 | int_hist[HOG_BINS - 1] += dx_zero_half; |
453 | 0 | for (int b = 0; b < HOG_BINS; ++b) { |
454 | 0 | hist[b] = (float)int_hist[b]; |
455 | 0 | } |
456 | 0 | normalize_hog(total, hist); |
457 | 0 | } Unexecuted instantiation: rdopt.c:generate_hog_using_gradient_cache Unexecuted instantiation: temporal_filter.c:generate_hog_using_gradient_cache Unexecuted instantiation: intra_mode_search.c:generate_hog_using_gradient_cache Unexecuted instantiation: intra_mode_search_sse2.c:generate_hog_using_gradient_cache Unexecuted instantiation: compound_type.c:generate_hog_using_gradient_cache Unexecuted instantiation: encodeframe.c:generate_hog_using_gradient_cache Unexecuted instantiation: encode_strategy.c:generate_hog_using_gradient_cache Unexecuted instantiation: encoder.c:generate_hog_using_gradient_cache Unexecuted instantiation: encoder_utils.c:generate_hog_using_gradient_cache Unexecuted instantiation: ethread.c:generate_hog_using_gradient_cache Unexecuted instantiation: palette.c:generate_hog_using_gradient_cache Unexecuted instantiation: partition_search.c:generate_hog_using_gradient_cache Unexecuted instantiation: superres_scale.c:generate_hog_using_gradient_cache Unexecuted instantiation: svc_layercontext.c:generate_hog_using_gradient_cache Unexecuted instantiation: av1_cx_iface.c:generate_hog_using_gradient_cache |
458 | | |
459 | | static inline void collect_hog_data(const MACROBLOCK *x, BLOCK_SIZE bsize, |
460 | 0 | BLOCK_SIZE sb_size, int plane, float *hog) { |
461 | 0 | const MACROBLOCKD *xd = &x->e_mbd; |
462 | 0 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
463 | 0 | const int ss_x = pd->subsampling_x; |
464 | 0 | const int ss_y = pd->subsampling_y; |
465 | 0 | const int bh = block_size_high[bsize]; |
466 | 0 | const int bw = block_size_wide[bsize]; |
467 | 0 | const int rows = |
468 | 0 | ((xd->mb_to_bottom_edge >= 0) ? bh : (xd->mb_to_bottom_edge >> 3) + bh) >> |
469 | 0 | ss_y; |
470 | 0 | const int cols = |
471 | 0 | ((xd->mb_to_right_edge >= 0) ? bw : (xd->mb_to_right_edge >> 3) + bw) >> |
472 | 0 | ss_x; |
473 | | |
474 | | // If gradient data is already generated at SB level, reuse the cached data. |
475 | | // Otherwise, compute the data. |
476 | 0 | if (x->is_sb_gradient_cached[plane]) { |
477 | 0 | generate_hog_using_gradient_cache(x, rows, cols, sb_size, plane, hog); |
478 | 0 | } else { |
479 | 0 | const uint8_t *src = x->plane[plane].src.buf; |
480 | 0 | const int src_stride = x->plane[plane].src.stride; |
481 | 0 | generate_hog(src, src_stride, rows, cols, hog, is_cur_buf_hbd(xd)); |
482 | 0 | } |
483 | | |
484 | | // Scale the hog so the luma and chroma are on the same scale |
485 | 0 | if (ss_x | ss_y) { |
486 | 0 | const float scale = (float)((1 + ss_x) * (1 + ss_y)); |
487 | 0 | for (int b = 0; b < HOG_BINS; ++b) { |
488 | 0 | hog[b] *= scale; |
489 | 0 | } |
490 | 0 | } |
491 | 0 | } Unexecuted instantiation: rdopt.c:collect_hog_data Unexecuted instantiation: temporal_filter.c:collect_hog_data Unexecuted instantiation: intra_mode_search.c:collect_hog_data Unexecuted instantiation: intra_mode_search_sse2.c:collect_hog_data Unexecuted instantiation: compound_type.c:collect_hog_data Unexecuted instantiation: encodeframe.c:collect_hog_data Unexecuted instantiation: encode_strategy.c:collect_hog_data Unexecuted instantiation: encoder.c:collect_hog_data Unexecuted instantiation: encoder_utils.c:collect_hog_data Unexecuted instantiation: ethread.c:collect_hog_data Unexecuted instantiation: palette.c:collect_hog_data Unexecuted instantiation: partition_search.c:collect_hog_data Unexecuted instantiation: superres_scale.c:collect_hog_data Unexecuted instantiation: svc_layercontext.c:collect_hog_data Unexecuted instantiation: av1_cx_iface.c:collect_hog_data |
492 | | |
493 | | static inline void prune_intra_mode_with_hog( |
494 | | const MACROBLOCK *x, BLOCK_SIZE bsize, BLOCK_SIZE sb_size, float th, |
495 | 0 | uint8_t *directional_mode_skip_mask, int is_chroma) { |
496 | 0 | const int plane = is_chroma ? AOM_PLANE_U : AOM_PLANE_Y; |
497 | 0 | float hist[HOG_BINS] = { 0.0f }; |
498 | 0 | collect_hog_data(x, bsize, sb_size, plane, hist); |
499 | | |
500 | | // Make prediction for each of the mode |
501 | 0 | float scores[DIRECTIONAL_MODES] = { 0.0f }; |
502 | 0 | av1_nn_predict(hist, &av1_intra_hog_model_nnconfig, 1, scores); |
503 | 0 | for (UV_PREDICTION_MODE uv_mode = UV_V_PRED; uv_mode <= UV_D67_PRED; |
504 | 0 | uv_mode++) { |
505 | 0 | if (scores[uv_mode - UV_V_PRED] <= th) { |
506 | 0 | directional_mode_skip_mask[uv_mode] = 1; |
507 | 0 | } |
508 | 0 | } |
509 | 0 | } Unexecuted instantiation: rdopt.c:prune_intra_mode_with_hog Unexecuted instantiation: temporal_filter.c:prune_intra_mode_with_hog Unexecuted instantiation: intra_mode_search.c:prune_intra_mode_with_hog Unexecuted instantiation: intra_mode_search_sse2.c:prune_intra_mode_with_hog Unexecuted instantiation: compound_type.c:prune_intra_mode_with_hog Unexecuted instantiation: encodeframe.c:prune_intra_mode_with_hog Unexecuted instantiation: encode_strategy.c:prune_intra_mode_with_hog Unexecuted instantiation: encoder.c:prune_intra_mode_with_hog Unexecuted instantiation: encoder_utils.c:prune_intra_mode_with_hog Unexecuted instantiation: ethread.c:prune_intra_mode_with_hog Unexecuted instantiation: palette.c:prune_intra_mode_with_hog Unexecuted instantiation: partition_search.c:prune_intra_mode_with_hog Unexecuted instantiation: superres_scale.c:prune_intra_mode_with_hog Unexecuted instantiation: svc_layercontext.c:prune_intra_mode_with_hog Unexecuted instantiation: av1_cx_iface.c:prune_intra_mode_with_hog |
510 | | |
511 | | int av1_calc_normalized_variance(aom_variance_fn_t vf, const uint8_t *const buf, |
512 | | const int stride, const int is_hbd); |
513 | | |
514 | | // Returns whether caching of source variance for 4x4 sub-blocks is allowed. |
515 | | static inline bool is_src_var_for_4x4_sub_blocks_caching_enabled( |
516 | 0 | const AV1_COMP *const cpi) { |
517 | 0 | const SPEED_FEATURES *const sf = &cpi->sf; |
518 | 0 | if (cpi->oxcf.mode != ALLINTRA) return false; |
519 | | |
520 | 0 | if (sf->part_sf.partition_search_type == SEARCH_PARTITION) return true; |
521 | | |
522 | 0 | if (INTRA_RD_VAR_THRESH(cpi->oxcf.speed) <= 0 || |
523 | 0 | (sf->rt_sf.use_nonrd_pick_mode && !sf->rt_sf.hybrid_intra_pickmode)) |
524 | 0 | return false; |
525 | | |
526 | 0 | return true; |
527 | 0 | } Unexecuted instantiation: rdopt.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: temporal_filter.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: intra_mode_search.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: intra_mode_search_sse2.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: compound_type.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: encodeframe.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: encode_strategy.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: encoder.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: encoder_utils.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: ethread.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: palette.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: partition_search.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: superres_scale.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: svc_layercontext.c:is_src_var_for_4x4_sub_blocks_caching_enabled Unexecuted instantiation: av1_cx_iface.c:is_src_var_for_4x4_sub_blocks_caching_enabled |
528 | | |
529 | | // Initialize the members of Block4x4VarInfo structure to -1 at the start |
530 | | // of every superblock. |
531 | | static inline void init_src_var_info_of_4x4_sub_blocks( |
532 | | const AV1_COMP *const cpi, Block4x4VarInfo *src_var_info_of_4x4_sub_blocks, |
533 | 0 | const BLOCK_SIZE sb_size) { |
534 | 0 | if (!is_src_var_for_4x4_sub_blocks_caching_enabled(cpi)) return; |
535 | | |
536 | 0 | const int mi_count_in_sb = mi_size_wide[sb_size] * mi_size_high[sb_size]; |
537 | 0 | for (int i = 0; i < mi_count_in_sb; i++) { |
538 | 0 | src_var_info_of_4x4_sub_blocks[i].var = -1; |
539 | 0 | src_var_info_of_4x4_sub_blocks[i].log_var = -1.0; |
540 | 0 | } |
541 | 0 | } Unexecuted instantiation: rdopt.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: temporal_filter.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: intra_mode_search.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: intra_mode_search_sse2.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: compound_type.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: encodeframe.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: encode_strategy.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: encoder.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: encoder_utils.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: ethread.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: palette.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: partition_search.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: superres_scale.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: svc_layercontext.c:init_src_var_info_of_4x4_sub_blocks Unexecuted instantiation: av1_cx_iface.c:init_src_var_info_of_4x4_sub_blocks |
542 | | |
543 | | // Returns the cost needed to send a uniformly distributed r.v. |
544 | 0 | static inline int write_uniform_cost(int n, int v) { |
545 | 0 | const int l = get_unsigned_bits(n); |
546 | 0 | const int m = (1 << l) - n; |
547 | 0 | if (l == 0) return 0; |
548 | 0 | if (v < m) |
549 | 0 | return av1_cost_literal(l - 1); |
550 | 0 | else |
551 | 0 | return av1_cost_literal(l); |
552 | 0 | } Unexecuted instantiation: rdopt.c:write_uniform_cost Unexecuted instantiation: temporal_filter.c:write_uniform_cost Unexecuted instantiation: intra_mode_search.c:write_uniform_cost Unexecuted instantiation: intra_mode_search_sse2.c:write_uniform_cost Unexecuted instantiation: compound_type.c:write_uniform_cost Unexecuted instantiation: encodeframe.c:write_uniform_cost Unexecuted instantiation: encode_strategy.c:write_uniform_cost Unexecuted instantiation: encoder.c:write_uniform_cost Unexecuted instantiation: encoder_utils.c:write_uniform_cost Unexecuted instantiation: ethread.c:write_uniform_cost Unexecuted instantiation: palette.c:write_uniform_cost Unexecuted instantiation: partition_search.c:write_uniform_cost Unexecuted instantiation: superres_scale.c:write_uniform_cost Unexecuted instantiation: svc_layercontext.c:write_uniform_cost Unexecuted instantiation: av1_cx_iface.c:write_uniform_cost |
553 | | /*!\endcond */ |
554 | | |
555 | | /*!\brief Returns the rate cost for luma prediction mode info of intra blocks. |
556 | | * |
557 | | * \callergraph |
558 | | */ |
559 | | static inline int intra_mode_info_cost_y(const AV1_COMP *cpi, |
560 | | const MACROBLOCK *x, |
561 | | const MB_MODE_INFO *mbmi, |
562 | | BLOCK_SIZE bsize, int mode_cost, |
563 | 0 | int discount_color_cost) { |
564 | 0 | int total_rate = mode_cost; |
565 | 0 | const ModeCosts *mode_costs = &x->mode_costs; |
566 | 0 | const int use_palette = mbmi->palette_mode_info.palette_size[0] > 0; |
567 | 0 | const int use_filter_intra = mbmi->filter_intra_mode_info.use_filter_intra; |
568 | 0 | const int use_intrabc = mbmi->use_intrabc; |
569 | | // Can only activate one mode. |
570 | 0 | assert(((mbmi->mode != DC_PRED) + use_palette + use_intrabc + |
571 | 0 | use_filter_intra) <= 1); |
572 | 0 | const int try_palette = av1_allow_palette( |
573 | 0 | cpi->common.features.allow_screen_content_tools, mbmi->bsize); |
574 | 0 | if (try_palette && mbmi->mode == DC_PRED) { |
575 | 0 | const MACROBLOCKD *xd = &x->e_mbd; |
576 | 0 | const int bsize_ctx = av1_get_palette_bsize_ctx(bsize); |
577 | 0 | const int mode_ctx = av1_get_palette_mode_ctx(xd); |
578 | 0 | total_rate += |
579 | 0 | mode_costs->palette_y_mode_cost[bsize_ctx][mode_ctx][use_palette]; |
580 | 0 | if (use_palette) { |
581 | 0 | const uint8_t *const color_map = xd->plane[0].color_index_map; |
582 | 0 | int block_width, block_height, rows, cols; |
583 | 0 | av1_get_block_dimensions(bsize, 0, xd, &block_width, &block_height, &rows, |
584 | 0 | &cols); |
585 | 0 | const int plt_size = mbmi->palette_mode_info.palette_size[0]; |
586 | 0 | int palette_mode_cost = |
587 | 0 | mode_costs |
588 | 0 | ->palette_y_size_cost[bsize_ctx][plt_size - PALETTE_MIN_SIZE] + |
589 | 0 | write_uniform_cost(plt_size, color_map[0]); |
590 | 0 | uint16_t color_cache[2 * PALETTE_MAX_SIZE]; |
591 | 0 | const int n_cache = av1_get_palette_cache(xd, 0, color_cache); |
592 | 0 | palette_mode_cost += |
593 | 0 | av1_palette_color_cost_y(&mbmi->palette_mode_info, color_cache, |
594 | 0 | n_cache, cpi->common.seq_params->bit_depth); |
595 | 0 | if (!discount_color_cost) |
596 | 0 | palette_mode_cost += |
597 | 0 | av1_cost_color_map(x, 0, bsize, mbmi->tx_size, PALETTE_MAP); |
598 | |
|
599 | 0 | total_rate += palette_mode_cost; |
600 | 0 | } |
601 | 0 | } |
602 | 0 | if (av1_filter_intra_allowed(&cpi->common, mbmi)) { |
603 | 0 | total_rate += mode_costs->filter_intra_cost[mbmi->bsize][use_filter_intra]; |
604 | 0 | if (use_filter_intra) { |
605 | 0 | total_rate += |
606 | 0 | mode_costs->filter_intra_mode_cost[mbmi->filter_intra_mode_info |
607 | 0 | .filter_intra_mode]; |
608 | 0 | } |
609 | 0 | } |
610 | 0 | if (av1_is_directional_mode(mbmi->mode)) { |
611 | 0 | if (av1_use_angle_delta(bsize)) { |
612 | 0 | total_rate += |
613 | 0 | mode_costs->angle_delta_cost[mbmi->mode - V_PRED] |
614 | 0 | [MAX_ANGLE_DELTA + |
615 | 0 | mbmi->angle_delta[PLANE_TYPE_Y]]; |
616 | 0 | } |
617 | 0 | } |
618 | 0 | if (av1_allow_intrabc(&cpi->common)) |
619 | 0 | total_rate += mode_costs->intrabc_cost[use_intrabc]; |
620 | 0 | return total_rate; |
621 | 0 | } Unexecuted instantiation: rdopt.c:intra_mode_info_cost_y Unexecuted instantiation: temporal_filter.c:intra_mode_info_cost_y Unexecuted instantiation: intra_mode_search.c:intra_mode_info_cost_y Unexecuted instantiation: intra_mode_search_sse2.c:intra_mode_info_cost_y Unexecuted instantiation: compound_type.c:intra_mode_info_cost_y Unexecuted instantiation: encodeframe.c:intra_mode_info_cost_y Unexecuted instantiation: encode_strategy.c:intra_mode_info_cost_y Unexecuted instantiation: encoder.c:intra_mode_info_cost_y Unexecuted instantiation: encoder_utils.c:intra_mode_info_cost_y Unexecuted instantiation: ethread.c:intra_mode_info_cost_y Unexecuted instantiation: palette.c:intra_mode_info_cost_y Unexecuted instantiation: partition_search.c:intra_mode_info_cost_y Unexecuted instantiation: superres_scale.c:intra_mode_info_cost_y Unexecuted instantiation: svc_layercontext.c:intra_mode_info_cost_y Unexecuted instantiation: av1_cx_iface.c:intra_mode_info_cost_y |
622 | | |
623 | | /*!\brief Return the rate cost for chroma prediction mode info of intra blocks. |
624 | | * |
625 | | * \callergraph |
626 | | */ |
627 | | static inline int intra_mode_info_cost_uv(const AV1_COMP *cpi, |
628 | | const MACROBLOCK *x, |
629 | | const MB_MODE_INFO *mbmi, |
630 | 0 | BLOCK_SIZE bsize, int mode_cost) { |
631 | 0 | int total_rate = mode_cost; |
632 | 0 | const ModeCosts *mode_costs = &x->mode_costs; |
633 | 0 | const int use_palette = mbmi->palette_mode_info.palette_size[1] > 0; |
634 | 0 | const UV_PREDICTION_MODE uv_mode = mbmi->uv_mode; |
635 | | // Can only activate one mode. |
636 | 0 | assert(((uv_mode != UV_DC_PRED) + use_palette + mbmi->use_intrabc) <= 1); |
637 | | |
638 | 0 | const int try_palette = av1_allow_palette( |
639 | 0 | cpi->common.features.allow_screen_content_tools, mbmi->bsize); |
640 | 0 | if (try_palette && uv_mode == UV_DC_PRED) { |
641 | 0 | const PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info; |
642 | 0 | total_rate += |
643 | 0 | mode_costs->palette_uv_mode_cost[pmi->palette_size[0] > 0][use_palette]; |
644 | 0 | if (use_palette) { |
645 | 0 | const int bsize_ctx = av1_get_palette_bsize_ctx(bsize); |
646 | 0 | const int plt_size = pmi->palette_size[1]; |
647 | 0 | const MACROBLOCKD *xd = &x->e_mbd; |
648 | 0 | const uint8_t *const color_map = xd->plane[1].color_index_map; |
649 | 0 | int palette_mode_cost = |
650 | 0 | mode_costs |
651 | 0 | ->palette_uv_size_cost[bsize_ctx][plt_size - PALETTE_MIN_SIZE] + |
652 | 0 | write_uniform_cost(plt_size, color_map[0]); |
653 | 0 | uint16_t color_cache[2 * PALETTE_MAX_SIZE]; |
654 | 0 | const int n_cache = av1_get_palette_cache(xd, 1, color_cache); |
655 | 0 | palette_mode_cost += av1_palette_color_cost_uv( |
656 | 0 | pmi, color_cache, n_cache, cpi->common.seq_params->bit_depth); |
657 | 0 | palette_mode_cost += |
658 | 0 | av1_cost_color_map(x, 1, bsize, mbmi->tx_size, PALETTE_MAP); |
659 | 0 | total_rate += palette_mode_cost; |
660 | 0 | } |
661 | 0 | } |
662 | 0 | const PREDICTION_MODE intra_mode = get_uv_mode(uv_mode); |
663 | 0 | if (av1_is_directional_mode(intra_mode)) { |
664 | 0 | if (av1_use_angle_delta(bsize)) { |
665 | 0 | total_rate += |
666 | 0 | mode_costs->angle_delta_cost[intra_mode - V_PRED] |
667 | 0 | [mbmi->angle_delta[PLANE_TYPE_UV] + |
668 | 0 | MAX_ANGLE_DELTA]; |
669 | 0 | } |
670 | 0 | } |
671 | 0 | return total_rate; |
672 | 0 | } Unexecuted instantiation: rdopt.c:intra_mode_info_cost_uv Unexecuted instantiation: temporal_filter.c:intra_mode_info_cost_uv Unexecuted instantiation: intra_mode_search.c:intra_mode_info_cost_uv Unexecuted instantiation: intra_mode_search_sse2.c:intra_mode_info_cost_uv Unexecuted instantiation: compound_type.c:intra_mode_info_cost_uv Unexecuted instantiation: encodeframe.c:intra_mode_info_cost_uv Unexecuted instantiation: encode_strategy.c:intra_mode_info_cost_uv Unexecuted instantiation: encoder.c:intra_mode_info_cost_uv Unexecuted instantiation: encoder_utils.c:intra_mode_info_cost_uv Unexecuted instantiation: ethread.c:intra_mode_info_cost_uv Unexecuted instantiation: palette.c:intra_mode_info_cost_uv Unexecuted instantiation: partition_search.c:intra_mode_info_cost_uv Unexecuted instantiation: superres_scale.c:intra_mode_info_cost_uv Unexecuted instantiation: svc_layercontext.c:intra_mode_info_cost_uv Unexecuted instantiation: av1_cx_iface.c:intra_mode_info_cost_uv |
673 | | |
674 | | /*!\cond */ |
675 | | // Makes a quick intra prediction and estimate the rdcost with a model without |
676 | | // going through the whole txfm/quantize/itxfm process. |
677 | | static int64_t intra_model_rd(const AV1_COMMON *cm, MACROBLOCK *const x, |
678 | | int plane, BLOCK_SIZE plane_bsize, |
679 | | TX_SIZE tx_size, int use_hadamard, |
680 | 0 | bool do_border_pad) { |
681 | 0 | MACROBLOCKD *const xd = &x->e_mbd; |
682 | 0 | const BitDepthInfo bd_info = get_bit_depth_info(xd); |
683 | 0 | int row, col; |
684 | 0 | assert(!is_inter_block(xd->mi[0])); |
685 | 0 | const int stepr = tx_size_high_unit[tx_size]; |
686 | 0 | const int stepc = tx_size_wide_unit[tx_size]; |
687 | 0 | const int txbw = tx_size_wide[tx_size]; |
688 | 0 | const int txbh = tx_size_high[tx_size]; |
689 | 0 | const int max_blocks_wide = max_block_wide(xd, plane_bsize, plane); |
690 | 0 | const int max_blocks_high = max_block_high(xd, plane_bsize, plane); |
691 | 0 | int64_t satd_cost = 0; |
692 | 0 | struct macroblock_plane *p = &x->plane[plane]; |
693 | 0 | struct macroblockd_plane *pd = &xd->plane[plane]; |
694 | | // Prediction. |
695 | 0 | for (row = 0; row < max_blocks_high; row += stepr) { |
696 | 0 | for (col = 0; col < max_blocks_wide; col += stepc) { |
697 | 0 | av1_predict_intra_block_facade(cm, xd, plane, col, row, tx_size); |
698 | | // Here we use p->src_diff and p->coeff as temporary buffers for |
699 | | // prediction residue and transform coefficients. The buffers are only |
700 | | // used in this for loop, therefore we don't need to properly add offset |
701 | | // to the buffers. |
702 | 0 | av1_subtract_block( |
703 | 0 | x, txbh, txbw, p->src_diff, block_size_wide[plane_bsize], |
704 | 0 | p->src.buf + (((row * p->src.stride) + col) << 2), p->src.stride, |
705 | 0 | pd->dst.buf + (((row * pd->dst.stride) + col) << 2), pd->dst.stride, |
706 | 0 | plane, plane_bsize, col, row, DCT_DCT, do_border_pad); |
707 | 0 | av1_quick_txfm(use_hadamard, tx_size, bd_info, p->src_diff, |
708 | 0 | block_size_wide[plane_bsize], p->coeff); |
709 | 0 | satd_cost += aom_satd(p->coeff, tx_size_2d[tx_size]); |
710 | 0 | } |
711 | 0 | } |
712 | 0 | return satd_cost; |
713 | 0 | } Unexecuted instantiation: rdopt.c:intra_model_rd Unexecuted instantiation: temporal_filter.c:intra_model_rd Unexecuted instantiation: intra_mode_search.c:intra_model_rd Unexecuted instantiation: intra_mode_search_sse2.c:intra_model_rd Unexecuted instantiation: compound_type.c:intra_model_rd Unexecuted instantiation: encodeframe.c:intra_model_rd Unexecuted instantiation: encode_strategy.c:intra_model_rd Unexecuted instantiation: encoder.c:intra_model_rd Unexecuted instantiation: encoder_utils.c:intra_model_rd Unexecuted instantiation: ethread.c:intra_model_rd Unexecuted instantiation: palette.c:intra_model_rd Unexecuted instantiation: partition_search.c:intra_model_rd Unexecuted instantiation: superres_scale.c:intra_model_rd Unexecuted instantiation: svc_layercontext.c:intra_model_rd Unexecuted instantiation: av1_cx_iface.c:intra_model_rd |
714 | | /*!\endcond */ |
715 | | |
716 | | /*!\brief Estimate the luma rdcost of a given intra mode and try to prune it. |
717 | | * |
718 | | * \ingroup intra_mode_search |
719 | | * \callergraph |
720 | | * This function first makes a quick luma prediction and estimates the rdcost |
721 | | * with a model without going through the txfm, then try to prune the current |
722 | | * mode if the new estimate y_rd > 1.25 * best_model_rd. |
723 | | * |
724 | | * \return Returns 1 if the given mode is prune; 0 otherwise. |
725 | | */ |
726 | | static inline int model_intra_yrd_and_prune(const AV1_COMP *const cpi, |
727 | | MACROBLOCK *x, BLOCK_SIZE bsize, |
728 | 0 | int64_t *best_model_rd) { |
729 | 0 | const TX_SIZE tx_size = AOMMIN(TX_32X32, max_txsize_lookup[bsize]); |
730 | 0 | const int plane = 0; |
731 | 0 | const AV1_COMMON *cm = &cpi->common; |
732 | 0 | const int64_t this_model_rd = intra_model_rd( |
733 | 0 | cm, x, plane, bsize, tx_size, /*use_hadamard=*/1, cpi->do_border_pad); |
734 | 0 | if (*best_model_rd != INT64_MAX && |
735 | 0 | this_model_rd > *best_model_rd + (*best_model_rd >> 2)) { |
736 | 0 | return 1; |
737 | 0 | } else if (this_model_rd < *best_model_rd) { |
738 | 0 | *best_model_rd = this_model_rd; |
739 | 0 | } |
740 | 0 | return 0; |
741 | 0 | } Unexecuted instantiation: rdopt.c:model_intra_yrd_and_prune Unexecuted instantiation: temporal_filter.c:model_intra_yrd_and_prune Unexecuted instantiation: intra_mode_search.c:model_intra_yrd_and_prune Unexecuted instantiation: intra_mode_search_sse2.c:model_intra_yrd_and_prune Unexecuted instantiation: compound_type.c:model_intra_yrd_and_prune Unexecuted instantiation: encodeframe.c:model_intra_yrd_and_prune Unexecuted instantiation: encode_strategy.c:model_intra_yrd_and_prune Unexecuted instantiation: encoder.c:model_intra_yrd_and_prune Unexecuted instantiation: encoder_utils.c:model_intra_yrd_and_prune Unexecuted instantiation: ethread.c:model_intra_yrd_and_prune Unexecuted instantiation: palette.c:model_intra_yrd_and_prune Unexecuted instantiation: partition_search.c:model_intra_yrd_and_prune Unexecuted instantiation: superres_scale.c:model_intra_yrd_and_prune Unexecuted instantiation: svc_layercontext.c:model_intra_yrd_and_prune Unexecuted instantiation: av1_cx_iface.c:model_intra_yrd_and_prune |
742 | | |
743 | | #ifdef __cplusplus |
744 | | } // extern "C" |
745 | | #endif |
746 | | |
747 | | #endif // AOM_AV1_ENCODER_INTRA_MODE_SEARCH_UTILS_H_ |