FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/vvc_alf.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 81 85 95.3%
Functions: 4 4 100.0%
Branches: 65 90 72.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2023-2024 Nuo Mi <nuomi2021@gmail.com>
3 * Copyright (c) 2023-2024 Wu Jianhua <toqsxw@outlook.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <string.h>
23
24 #include "checkasm.h"
25 #include "libavcodec/vvc/ctu.h"
26 #include "libavcodec/vvc/data.h"
27 #include "libavcodec/vvc/dsp.h"
28
29 #include "libavutil/common.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mem_internal.h"
32
33 static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
34
35 #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
36 #define SRC_PIXEL_STRIDE (MAX_CTU_SIZE + 2 * ALF_PADDING_SIZE)
37 #define DST_PIXEL_STRIDE (SRC_PIXEL_STRIDE + 4)
38 #define SRC_BUF_SIZE (SRC_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2) //+3 * 2 for top and bottom row, *2 for high bit depth
39 #define DST_BUF_SIZE (DST_PIXEL_STRIDE * (MAX_CTU_SIZE + 3 * 2) * 2)
40 #define LUMA_PARAMS_SIZE (MAX_CTU_SIZE * MAX_CTU_SIZE / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * ALF_NUM_COEFF_LUMA)
41
42 #define randomize_buffers(buf0, buf1, size) \
43 do { \
44 uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
45 int k; \
46 for (k = 0; k < size; k += 4) { \
47 uint32_t r = rnd() & mask; \
48 AV_WN32A(buf0 + k, r); \
49 AV_WN32A(buf1 + k, r); \
50 } \
51 } while (0)
52
53 #define randomize_buffers2(buf, size, filter) \
54 do { \
55 int k; \
56 if (filter) { \
57 for (k = 0; k < size; k++) { \
58 int8_t r = rnd(); \
59 buf[k] = r; \
60 } \
61 } else { \
62 for (k = 0; k < size; k++) { \
63 int r = rnd() % FF_ARRAY_ELEMS(clip_set); \
64 buf[k] = clip_set[r]; \
65 } \
66 } \
67 } while (0)
68
69 14976 static int get_alf_vb_pos(const int h, const int vb_pos_above)
70 {
71
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 14112 times.
14976 if (h == MAX_CTU_SIZE)
72 864 return MAX_CTU_SIZE - vb_pos_above;
73 // If h < MAX_CTU_SIZE and picture virtual boundaries are involved, ALF virtual boundaries can either be within or outside this ALF block.
74
2/2
✓ Branch 1 taken 7123 times.
✓ Branch 2 taken 6989 times.
14112 return ((rnd() & 1) ? h : MAX_CTU_SIZE) - vb_pos_above;
75 }
76
77 39 static void check_alf_filter(VVCDSPContext *c, const int bit_depth)
78 {
79 39 LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]);
80 39 LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]);
81 39 LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
82 39 LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
83 int16_t filter[LUMA_PARAMS_SIZE];
84 int16_t clip[LUMA_PARAMS_SIZE];
85
86 39 const int16_t clip_set[] = {
87 39 1 << bit_depth, 1 << (bit_depth - 3), 1 << (bit_depth - 5), 1 << (bit_depth - 7)
88 };
89
90 39 ptrdiff_t src_stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL;
91 39 ptrdiff_t dst_stride = DST_PIXEL_STRIDE * SIZEOF_PIXEL;
92 39 int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL;
93
94 39 declare_func(void, uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *src, ptrdiff_t src_stride,
95 int width, int height, const int16_t *filter, const int16_t *clip, const int vb_pos);
96
97
2/2
✓ Branch 1 taken 376272 times.
✓ Branch 2 taken 39 times.
376311 randomize_buffers(src0, src1, SRC_BUF_SIZE);
98
2/2
✓ Branch 1 taken 479232 times.
✓ Branch 2 taken 39 times.
479271 randomize_buffers2(filter, LUMA_PARAMS_SIZE, 1);
99
2/2
✓ Branch 1 taken 479232 times.
✓ Branch 2 taken 39 times.
479271 randomize_buffers2(clip, LUMA_PARAMS_SIZE, 0);
100
101
2/2
✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 39 times.
1287 for (int h = 4; h <= MAX_CTU_SIZE; h += 4) {
102
2/2
✓ Branch 0 taken 39936 times.
✓ Branch 1 taken 1248 times.
41184 for (int w = 4; w <= MAX_CTU_SIZE; w += 4) {
103 //Both picture size and virtual boundaries are 8-aligned. For luma, we only need to check 8-aligned sizes.
104
4/4
✓ Branch 0 taken 19968 times.
✓ Branch 1 taken 19968 times.
✓ Branch 2 taken 9984 times.
✓ Branch 3 taken 9984 times.
39936 if (!(w % 8) && !(h % 8)) {
105
2/2
✓ Branch 3 taken 1536 times.
✓ Branch 4 taken 8448 times.
9984 if (check_func(c->alf.filter[LUMA], "vvc_alf_filter_luma_%dx%d_%d", w, h, bit_depth)) {
106 1536 const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_LUMA);
107 1536 memset(dst0, 0, DST_BUF_SIZE);
108 1536 memset(dst1, 0, DST_BUF_SIZE);
109 1536 call_ref(dst0, dst_stride, src0 + offset, src_stride, w, h, filter, clip, vb_pos);
110 1536 call_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
111
2/2
✓ Branch 0 taken 105984 times.
✓ Branch 1 taken 1536 times.
107520 for (int i = 0; i < (h + 1); i++) {
112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 105984 times.
105984 if (memcmp(dst0 + i * dst_stride, dst1 + i * dst_stride, (w + 1) * SIZEOF_PIXEL))
113 fail();
114 }
115 // Bench only square sizes, and ones with dimensions being a power of two.
116
4/4
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 1440 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 66 times.
1536 if (w == h && (w & (w - 1)) == 0)
117
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
30 bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
118 }
119 }
120 //For chroma, once it exceeds 64, it's not a 4:2:0 format, so we only need to check 8-aligned sizes as well.
121
8/8
✓ Branch 0 taken 19968 times.
✓ Branch 1 taken 19968 times.
✓ Branch 2 taken 9984 times.
✓ Branch 3 taken 9984 times.
✓ Branch 4 taken 14976 times.
✓ Branch 5 taken 14976 times.
✓ Branch 6 taken 7488 times.
✓ Branch 7 taken 7488 times.
39936 if ((w <= 64 || !(w % 8)) && (h <= 64 || !(h % 8))) {
122
2/2
✓ Branch 3 taken 3456 times.
✓ Branch 4 taken 19008 times.
22464 if (check_func(c->alf.filter[CHROMA], "vvc_alf_filter_chroma_%dx%d_%d", w, h, bit_depth)) {
123 3456 const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_CHROMA);
124 3456 memset(dst0, 0, DST_BUF_SIZE);
125 3456 memset(dst1, 0, DST_BUF_SIZE);
126 3456 call_ref(dst0, dst_stride, src0 + offset, src_stride, w, h, filter, clip, vb_pos);
127 3456 call_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
128
2/2
✓ Branch 0 taken 196992 times.
✓ Branch 1 taken 3456 times.
200448 for (int i = 0; i < (h + 1); i++) {
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 196992 times.
196992 if (memcmp(dst0 + i * dst_stride, dst1 + i * dst_stride, (w + 1) * SIZEOF_PIXEL))
130 fail();
131 }
132
4/4
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 3312 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 108 times.
3456 if (w == h && (w & (w - 1)) == 0)
133
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
36 bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos);
134 }
135 }
136 }
137 }
138 39 }
139
140 39 static void check_alf_classify(VVCDSPContext *c, const int bit_depth)
141 {
142 39 LOCAL_ALIGNED_32(int, class_idx0, [SRC_BUF_SIZE]);
143 39 LOCAL_ALIGNED_32(int, transpose_idx0, [SRC_BUF_SIZE]);
144 39 LOCAL_ALIGNED_32(int, class_idx1, [SRC_BUF_SIZE]);
145 39 LOCAL_ALIGNED_32(int, transpose_idx1, [SRC_BUF_SIZE]);
146 39 LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]);
147 39 LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]);
148 39 LOCAL_ALIGNED_32(int32_t, alf_gradient_tmp, [ALF_GRADIENT_SIZE * ALF_GRADIENT_SIZE * ALF_NUM_DIR]);
149
150 39 ptrdiff_t stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL;
151 39 int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL;
152
153 39 declare_func(void, int *class_idx, int *transpose_idx,
154 const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, int *gradient_tmp);
155
156
2/2
✓ Branch 1 taken 376272 times.
✓ Branch 2 taken 39 times.
376311 randomize_buffers(src0, src1, SRC_BUF_SIZE);
157
158 //Both picture size and virtual boundaries are 8-aligned. Classify is luma only, we only need to check 8-aligned sizes.
159
2/2
✓ Branch 0 taken 624 times.
✓ Branch 1 taken 39 times.
663 for (int h = 8; h <= MAX_CTU_SIZE; h += 8) {
160
2/2
✓ Branch 0 taken 9984 times.
✓ Branch 1 taken 624 times.
10608 for (int w = 8; w <= MAX_CTU_SIZE; w += 8) {
161 9984 const int id_size = w * h / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * sizeof(int);
162 9984 const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_LUMA);
163
2/2
✓ Branch 3 taken 1536 times.
✓ Branch 4 taken 8448 times.
9984 if (check_func(c->alf.classify, "vvc_alf_classify_%dx%d_%d", w, h, bit_depth)) {
164 1536 memset(class_idx0, 0, id_size);
165 1536 memset(class_idx1, 0, id_size);
166 1536 memset(transpose_idx0, 0, id_size);
167 1536 memset(transpose_idx1, 0, id_size);
168 1536 call_ref(class_idx0, transpose_idx0, src0 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
169
170 1536 call_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
171
172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1536 times.
1536 if (memcmp(class_idx0, class_idx1, id_size))
173 fail();
174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1536 times.
1536 if (memcmp(transpose_idx0, transpose_idx1, id_size))
175 fail();
176 // Bench only square sizes, and ones with dimensions being a power of two.
177
4/4
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 1440 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 66 times.
1536 if (w == h && (w & (w - 1)) == 0)
178
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
30 bench_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp);
179 }
180 }
181 }
182 39 }
183
184 13 void checkasm_check_vvc_alf(void)
185 {
186 int bit_depth;
187 VVCDSPContext h;
188
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
189 39 ff_vvc_dsp_init(&h, bit_depth);
190 39 check_alf_filter(&h, bit_depth);
191 }
192 13 report("alf_filter");
193
194
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
195 39 ff_vvc_dsp_init(&h, bit_depth);
196 39 check_alf_classify(&h, bit_depth);
197 }
198 13 report("alf_classify");
199 13 }
200