FFmpeg
Loading...
Searching...
No Matches
vvc_pred.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#include <string.h>
20#include "checkasm.h"
21#include "libavcodec/vvc/dsp.h"
25
26static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
27static const int mip_modes[] = {16, 8, 6};
28
29#define SIZEOF_PIXEL ((bit_depth + 7) / 8)
30#define PIXEL_STRIDE (MAX_TB_SIZE * 2) // 2 * max transform size
31#define BUF_SIZE (2 * PIXEL_STRIDE * 64) // Enough for 64x64 with stride=128
32// IntraEdgeParams arrays are uint16_t, rounded up as they are filled 4 bytes at a time
33#define REF_BYTES FFALIGN(2 * (6 * MAX_TB_SIZE + 5), 4)
34#define REF_OFFSET (MAX_TB_SIZE + 3) // Same as offset from prepare_intra_edge_params
35
36#define randomize_buffers() \
37 do { \
38 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
39 for (int i = 0; i < BUF_SIZE; i += 4) { \
40 uint32_t r = rnd() & mask; \
41 AV_WN32A(buf0 + i, r); \
42 AV_WN32A(buf1 + i, r); \
43 } \
44 /* Make sure reference buffer writes don't go out of bounds */ \
45 for (int i = -(REF_OFFSET * SIZEOF_PIXEL); \
46 i < REF_BYTES - REF_OFFSET * SIZEOF_PIXEL; i += 4) { \
47 AV_WN32A(top + i, rnd() & mask); \
48 AV_WN32A(left + i, rnd() & mask); \
49 } \
50 } while (0)
51
52// From prepare_intra_edge_params in avcodec/vvc/intra_template.c
53static int derive_filter_flag(const int mode, const int ref_idx, const int w, const int h)
54{
55 if (ff_vvc_ref_filter_flag_derive(mode) || ref_idx)
56 return 0;
57 const int min_dist_ver_hor = FFMIN(abs(mode - 50), abs(mode - 18));
58 const int intra_hor_ver_dist_thres[] = {24, 14, 2, 0, 0};
59 const int ntbs = (av_log2(w) + av_log2(h)) >> 1;
60 return min_dist_ver_hor > intra_hor_ver_dist_thres[ntbs - 2];
61}
62
64 uint8_t *buf0, uint8_t *buf1,
65 uint8_t *top, uint8_t *left, int bit_depth)
66{
67 declare_func(void, uint8_t *src, const uint8_t *top,
68 const uint8_t *left, const int w, const int h, const ptrdiff_t stride);
69
70 /* Test all sizes 4x4 up to 64x64, including non-square */
71 for (int log2_w = 2; log2_w <= 6; log2_w++) {
72 for (int log2_h = 2; log2_h <= 6; log2_h++) {
73 int w = 1 << log2_w;
74 int h = 1 << log2_h;
75 ptrdiff_t stride = FFALIGN((w + rnd() % 64), 32);
76
77 if (check_func(c->intra.pred_dc, "vvc_pred_dc_%dx%d_%d",
78 w, h, bit_depth)) {
80 call_ref(buf0, top, left, w, h, stride);
81 call_new(buf1, top, left, w, h, stride);
82 if (memcmp(buf0, buf1, BUF_SIZE))
83 fail();
84 if (w == h)
85 bench_new(buf1, top, left, w, h, stride);
86 }
87 }
88 }
89
90 report("pred_dc");
91}
92
94 uint8_t *buf0, uint8_t *buf1,
95 uint8_t *top, uint8_t *left, int bit_depth)
96{
97 declare_func(void, uint8_t *src, const uint8_t *top,
98 const uint8_t *left, const int w, const int h, const ptrdiff_t stride);
99
100 /* Test all sizes 4x1 up to 64x64, including non-square. Heights of 1 and 2
101 * come from ISP splits and from chroma. */
102 for (int log2_w = 2; log2_w <= 6; log2_w++) {
103 for (int log2_h = 0; log2_h <= 6; log2_h++) {
104 int w = 1 << log2_w;
105 int h = 1 << log2_h;
106 ptrdiff_t stride = FFALIGN((w + rnd() % 64), 32);
107
108 if (check_func(c->intra.pred_planar, "vvc_pred_planar_%dx%d_%d",
109 w, h, bit_depth)) {
111 call_ref(buf0, top, left, w, h, stride);
112 call_new(buf1, top, left, w, h, stride);
113 if (memcmp(buf0, buf1, BUF_SIZE))
114 fail();
115 if (w == h)
116 bench_new(buf1, top, left, w, h, stride);
117 }
118 }
119 }
120
121 report("pred_planar");
122}
123
125 uint8_t *buf0, uint8_t *buf1,
126 uint8_t *top, uint8_t *left, int bit_depth)
127{
128 declare_func(void, uint8_t *src, const uint8_t *ref,
129 const int w, const int h, const ptrdiff_t stride);
130
131 /* Test all sizes 4x4 up to 64x64, including non-square */
132 for (int log2_w = 2; log2_w <= 6; log2_w++) {
133 for (int log2_h = 2; log2_h <= 6; log2_h++) {
134 int w = 1 << log2_w;
135 int h = 1 << log2_h;
136 ptrdiff_t stride = FFALIGN((w + rnd() % 64), 32);
137
138 if (check_func(c->intra.pred_v, "vvc_pred_v_%dx%d_%d",
139 w, h, bit_depth)) {
141 call_ref(buf0, top, w, h, stride);
142 call_new(buf1, top, w, h, stride);
143 if (memcmp(buf0, buf1, BUF_SIZE))
144 fail();
145 if (w == h)
146 bench_new(buf1, top, w, h, stride);
147 }
148
149 if (check_func(c->intra.pred_h, "vvc_pred_h_%dx%d_%d",
150 w, h, bit_depth)) {
152 call_ref(buf0, left, w, h, stride);
153 call_new(buf1, left, w, h, stride);
154 if (memcmp(buf0, buf1, BUF_SIZE))
155 fail();
156 if (w == h)
157 bench_new(buf1, left, w, h, stride);
158 }
159 }
160 }
161
162 report("pred_vh");
163}
164
166 uint8_t *buf0, uint8_t *buf1,
167 uint8_t *top, uint8_t *left, int bit_depth)
168{
169 declare_func(void, uint8_t *src, const uint8_t *top,
170 const uint8_t *left, const int w, const int h,
171 const ptrdiff_t stride, int mode_id, int is_transposed);
172
173 /* Test all sizes 4x4 up to 64x64, including non-square */
174 for (int log2_w = 2; log2_w <= 6; log2_w++) {
175 for (int log2_h = 2; log2_h <= 6; log2_h++) {
176 int w = 1 << log2_w;
177 int h = 1 << log2_h;
178 ptrdiff_t stride = FFALIGN((w + rnd() % 64), 32);
179 int size_id = ff_vvc_get_mip_size_id(w, h);
180
181 for (int mode_id = 0; mode_id < mip_modes[size_id]; mode_id++) {
182 if (check_func(c->intra.pred_mip, "vvc_pred_mip_%dx%d_mode%d_%d",
183 w, h, mode_id, bit_depth)) {
185 call_ref(buf0, top, left, w, h, stride, mode_id, 0);
186 call_new(buf1, top, left, w, h, stride, mode_id, 0);
187 if (memcmp(buf0, buf1, BUF_SIZE))
188 fail();
189
190 /* Test transposed */
192 call_ref(buf0, top, left, w, h, stride, mode_id, 1);
193 call_new(buf1, top, left, w, h, stride, mode_id, 1);
194 if (memcmp(buf0, buf1, BUF_SIZE))
195 fail();
196
197 if (w == h)
198 bench_new(buf1, top, left, w, h, stride, mode_id, 0);
199 }
200 }
201 }
202 }
203
204 report("pred_mip");
205}
206
208 uint8_t *buf0, uint8_t *buf1,
209 uint8_t *top, uint8_t *left, int bit_depth)
210{
211 // Set modes to bench
212 static const int bench_modes[] = { 2, 10, 26, INTRA_DIAG, 42, 58, INTRA_VDIAG };
213
214 declare_func(void, uint8_t *src, const uint8_t *top, const uint8_t *left,
215 const int w, const int h, const ptrdiff_t stride, const int c_idx,
216 const int mode, const int ref_idx, const int filter_flag,
217 const int need_pdpc);
218
219 /* Test all sizes 4x4 up to 64x64, including non-square */
220 for (int log2_w = 2; log2_w <= 6; log2_w++) {
221 for (int log2_h = 2; log2_h <= 6; log2_h++) {
222 int w = 1 << log2_w;
223 int h = 1 << log2_h;
224 ptrdiff_t stride = FFALIGN((w + rnd() % 64), 32);
225
226 for (int mode = 2; mode <= INTRA_VDIAG; mode++) {
227 // Skip vertical and horizontal (pred_v, pred_h)
228 if (mode == INTRA_VERT || mode == INTRA_HORZ)
229 continue;
230
231 int dir = mode >= INTRA_DIAG;
232 const char *mode_category;
233
234 if (mode == 2)
235 mode_category = "Hdiag";
236 else if (mode > 2 && mode < INTRA_HORZ)
237 mode_category = "Hpos";
238 else if (mode > INTRA_HORZ && mode < INTRA_DIAG)
239 mode_category = "Hneg";
240 else if (mode == INTRA_DIAG)
241 mode_category = "Diag";
242 else if (mode > INTRA_DIAG && mode < INTRA_VERT)
243 mode_category = "Vneg";
244 else if (mode > INTRA_VERT && mode < INTRA_VDIAG)
245 mode_category = "Vpos";
246 else
247 mode_category = "Vdiag";
248
249 for (int ref_idx = 0; ref_idx <= 2; ref_idx++) {
250 if (check_func(dir ? c->intra.pred_angular_v : c->intra.pred_angular_h, "vvc_pred_angular_%c_%dx%d_%s_mode%d_ref%d_%d",
251 dir ? 'v' : 'h', w, h, mode_category, mode, ref_idx, bit_depth)) {
252 int filter_flag = derive_filter_flag(mode, ref_idx, w, h);
253 int need_pdpc = ff_vvc_need_pdpc(w, h, 0, mode, ref_idx);
254
256 call_ref(buf0, top, left, w, h, stride, 0, mode, ref_idx, filter_flag, need_pdpc);
257 call_new(buf1, top, left, w, h, stride, 0, mode, ref_idx, filter_flag, need_pdpc);
258 if (memcmp(buf0, buf1, BUF_SIZE))
259 fail();
260 for (int i = 0; i < FF_ARRAY_ELEMS(bench_modes); i++) {
261 if (mode == bench_modes[i] && w == h && ref_idx == 0)
262 bench_new(buf1, top, left, w, h, stride, 0, mode, ref_idx, filter_flag, need_pdpc);
263 }
264 }
265 }
266 // TODO: Add c_idx=1 (chroma)
267 }
268 }
269 }
270
271 report("pred_angular");
272}
273
275{
276 LOCAL_ALIGNED_32(uint8_t, buf0, [BUF_SIZE]);
277 LOCAL_ALIGNED_32(uint8_t, buf1, [BUF_SIZE]);
278 LOCAL_ALIGNED_32(uint8_t, top_buf, [REF_BYTES + 16]);
279 LOCAL_ALIGNED_32(uint8_t, left_buf, [REF_BYTES + 16]);
280
281 for (int bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
283
284 uint8_t *top = top_buf + REF_OFFSET * SIZEOF_PIXEL;
285 uint8_t *left = left_buf + REF_OFFSET * SIZEOF_PIXEL;
286
288 check_pred_dc(&c, buf0, buf1, top, left, bit_depth);
289 check_pred_planar(&c, buf0, buf1, top, left, bit_depth);
290 check_pred_vh(&c, buf0, buf1, top, left, bit_depth);
291 check_pred_mip(&c, buf0, buf1, top, left, bit_depth);
292 check_pred_angular(&c, buf0, buf1, top, left, bit_depth);
293 }
294}
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition af_astats.c:246
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:139
@ INTRA_HORZ
Definition ctu.h:237
@ INTRA_DIAG
Definition ctu.h:238
@ INTRA_VDIAG
Definition ctu.h:240
@ INTRA_VERT
Definition ctu.h:239
#define abs(x)
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define av_log2
Definition intmath.h:84
int ff_vvc_need_pdpc(int w, int h, uint8_t bdpcm_flag, int mode, int ref_idx)
Definition intra_utils.c:61
int ff_vvc_ref_filter_flag_derive(int mode)
int ff_vvc_get_mip_size_id(int w, int h)
Definition intra_utils.c:33
uint8_t w
Definition llvidencdsp.c:39
#define FFMIN(a, b)
Definition macros.h:49
#define FFALIGN(x, a)
Definition macros.h:78
#define LOCAL_ALIGNED_32(t, v,...)
#define BUF_SIZE
Definition setpts.c:159
#define FF_ARRAY_ELEMS(a)
Definition swscale.c:71
#define stride
#define SIZEOF_PIXEL
Definition h264chroma.c:28
static const uint32_t pixel_mask[5]
Definition h264dsp.c:31
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
static double c[64]
void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth)
Definition dsp.c:86
static void check_pred_vh(VVCDSPContext *c, uint8_t *buf0, uint8_t *buf1, uint8_t *top, uint8_t *left, int bit_depth)
Definition vvc_pred.c:124
#define randomize_buffers()
Definition vvc_pred.c:36
static const int mip_modes[]
Definition vvc_pred.c:27
static void check_pred_planar(VVCDSPContext *c, uint8_t *buf0, uint8_t *buf1, uint8_t *top, uint8_t *left, int bit_depth)
Definition vvc_pred.c:93
#define REF_BYTES
Definition vvc_pred.c:33
static void check_pred_mip(VVCDSPContext *c, uint8_t *buf0, uint8_t *buf1, uint8_t *top, uint8_t *left, int bit_depth)
Definition vvc_pred.c:165
static void check_pred_dc(VVCDSPContext *c, uint8_t *buf0, uint8_t *buf1, uint8_t *top, uint8_t *left, int bit_depth)
Definition vvc_pred.c:63
static void check_pred_angular(VVCDSPContext *c, uint8_t *buf0, uint8_t *buf1, uint8_t *top, uint8_t *left, int bit_depth)
Definition vvc_pred.c:207
void checkasm_check_vvc_pred(void)
Definition vvc_pred.c:274
#define REF_OFFSET
Definition vvc_pred.c:34
static int derive_filter_flag(const int mode, const int ref_idx, const int w, const int h)
Definition vvc_pred.c:53