| 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 | 15744 | static int get_alf_vb_pos(const int h, const int vb_pos_above) | |
| 70 | { | ||
| 71 |
2/2✓ Branch 0 taken 912 times.
✓ Branch 1 taken 14832 times.
|
15744 | if (h == MAX_CTU_SIZE) |
| 72 | 912 | 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 7478 times.
✓ Branch 2 taken 7354 times.
|
14832 | return ((rnd() & 1) ? h : MAX_CTU_SIZE) - vb_pos_above; |
| 75 | } | ||
| 76 | |||
| 77 | 42 | static void check_alf_filter(VVCDSPContext *c, const int bit_depth) | |
| 78 | { | ||
| 79 | 42 | LOCAL_ALIGNED_32(uint8_t, dst0, [DST_BUF_SIZE]); | |
| 80 | 42 | LOCAL_ALIGNED_32(uint8_t, dst1, [DST_BUF_SIZE]); | |
| 81 | 42 | LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]); | |
| 82 | 42 | 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 | 42 | const int16_t clip_set[] = { | |
| 87 | 42 | 1 << bit_depth, 1 << (bit_depth - 3), 1 << (bit_depth - 5), 1 << (bit_depth - 7) | |
| 88 | }; | ||
| 89 | |||
| 90 | 42 | ptrdiff_t src_stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL; | |
| 91 | 42 | ptrdiff_t dst_stride = DST_PIXEL_STRIDE * SIZEOF_PIXEL; | |
| 92 | 42 | int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL; | |
| 93 | |||
| 94 | 42 | 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 405216 times.
✓ Branch 2 taken 42 times.
|
405258 | randomize_buffers(src0, src1, SRC_BUF_SIZE); |
| 98 |
2/2✓ Branch 1 taken 516096 times.
✓ Branch 2 taken 42 times.
|
516138 | randomize_buffers2(filter, LUMA_PARAMS_SIZE, 1); |
| 99 |
2/2✓ Branch 1 taken 516096 times.
✓ Branch 2 taken 42 times.
|
516138 | randomize_buffers2(clip, LUMA_PARAMS_SIZE, 0); |
| 100 | |||
| 101 |
2/2✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 42 times.
|
1386 | for (int h = 4; h <= MAX_CTU_SIZE; h += 4) { |
| 102 |
2/2✓ Branch 0 taken 43008 times.
✓ Branch 1 taken 1344 times.
|
44352 | 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 21504 times.
✓ Branch 1 taken 21504 times.
✓ Branch 2 taken 10752 times.
✓ Branch 3 taken 10752 times.
|
43008 | if (!(w % 8) && !(h % 8)) { |
| 105 |
2/2✓ Branch 3 taken 1536 times.
✓ Branch 4 taken 9216 times.
|
10752 | 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 1024 times.
✓ Branch 1 taken 512 times.
|
1536 | checkasm_check_pixel(dst0, dst_stride, dst1, dst_stride, w + 1, h + 1, "dst"); |
| 112 | // Bench only square sizes, and ones with dimensions being a power of two. | ||
| 113 |
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) |
| 114 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
30 | bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos); |
| 115 | } | ||
| 116 | } | ||
| 117 | //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. | ||
| 118 |
8/8✓ Branch 0 taken 21504 times.
✓ Branch 1 taken 21504 times.
✓ Branch 2 taken 10752 times.
✓ Branch 3 taken 10752 times.
✓ Branch 4 taken 16128 times.
✓ Branch 5 taken 16128 times.
✓ Branch 6 taken 8064 times.
✓ Branch 7 taken 8064 times.
|
43008 | if ((w <= 64 || !(w % 8)) && (h <= 64 || !(h % 8))) { |
| 119 |
2/2✓ Branch 3 taken 3456 times.
✓ Branch 4 taken 20736 times.
|
24192 | if (check_func(c->alf.filter[CHROMA], "vvc_alf_filter_chroma_%dx%d_%d", w, h, bit_depth)) { |
| 120 | 3456 | const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_CHROMA); | |
| 121 | 3456 | memset(dst0, 0, DST_BUF_SIZE); | |
| 122 | 3456 | memset(dst1, 0, DST_BUF_SIZE); | |
| 123 | 3456 | call_ref(dst0, dst_stride, src0 + offset, src_stride, w, h, filter, clip, vb_pos); | |
| 124 | 3456 | call_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos); | |
| 125 |
2/2✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 1152 times.
|
3456 | checkasm_check_pixel(dst0, dst_stride, dst1, dst_stride, w + 1, h + 1, "dst"); |
| 126 |
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) |
| 127 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
36 | bench_new(dst1, dst_stride, src1 + offset, src_stride, w, h, filter, clip, vb_pos); |
| 128 | } | ||
| 129 | } | ||
| 130 | } | ||
| 131 | } | ||
| 132 | 42 | } | |
| 133 | |||
| 134 | 42 | static void check_alf_classify(VVCDSPContext *c, const int bit_depth) | |
| 135 | { | ||
| 136 | 42 | LOCAL_ALIGNED_32(int, class_idx0, [SRC_BUF_SIZE]); | |
| 137 | 42 | LOCAL_ALIGNED_32(int, transpose_idx0, [SRC_BUF_SIZE]); | |
| 138 | 42 | LOCAL_ALIGNED_32(int, class_idx1, [SRC_BUF_SIZE]); | |
| 139 | 42 | LOCAL_ALIGNED_32(int, transpose_idx1, [SRC_BUF_SIZE]); | |
| 140 | 42 | LOCAL_ALIGNED_32(uint8_t, src0, [SRC_BUF_SIZE]); | |
| 141 | 42 | LOCAL_ALIGNED_32(uint8_t, src1, [SRC_BUF_SIZE]); | |
| 142 | 42 | LOCAL_ALIGNED_32(int32_t, alf_gradient_tmp, [ALF_GRADIENT_SIZE * ALF_GRADIENT_SIZE * ALF_NUM_DIR]); | |
| 143 | |||
| 144 | 42 | ptrdiff_t stride = SRC_PIXEL_STRIDE * SIZEOF_PIXEL; | |
| 145 | 42 | int offset = (3 * SRC_PIXEL_STRIDE + 3) * SIZEOF_PIXEL; | |
| 146 | |||
| 147 | 42 | declare_func(void, int *class_idx, int *transpose_idx, | |
| 148 | const uint8_t *src, ptrdiff_t src_stride, int width, int height, int vb_pos, int *gradient_tmp); | ||
| 149 | |||
| 150 |
2/2✓ Branch 1 taken 405216 times.
✓ Branch 2 taken 42 times.
|
405258 | randomize_buffers(src0, src1, SRC_BUF_SIZE); |
| 151 | |||
| 152 | //Both picture size and virtual boundaries are 8-aligned. Classify is luma only, we only need to check 8-aligned sizes. | ||
| 153 |
2/2✓ Branch 0 taken 672 times.
✓ Branch 1 taken 42 times.
|
714 | for (int h = 8; h <= MAX_CTU_SIZE; h += 8) { |
| 154 |
2/2✓ Branch 0 taken 10752 times.
✓ Branch 1 taken 672 times.
|
11424 | for (int w = 8; w <= MAX_CTU_SIZE; w += 8) { |
| 155 | 10752 | const int id_size = w * h / ALF_BLOCK_SIZE / ALF_BLOCK_SIZE * sizeof(int); | |
| 156 | 10752 | const int vb_pos = get_alf_vb_pos(h, ALF_VB_POS_ABOVE_LUMA); | |
| 157 |
2/2✓ Branch 3 taken 1536 times.
✓ Branch 4 taken 9216 times.
|
10752 | if (check_func(c->alf.classify, "vvc_alf_classify_%dx%d_%d", w, h, bit_depth)) { |
| 158 | 1536 | memset(class_idx0, 0, id_size); | |
| 159 | 1536 | memset(class_idx1, 0, id_size); | |
| 160 | 1536 | memset(transpose_idx0, 0, id_size); | |
| 161 | 1536 | memset(transpose_idx1, 0, id_size); | |
| 162 | 1536 | call_ref(class_idx0, transpose_idx0, src0 + offset, stride, w, h, vb_pos, alf_gradient_tmp); | |
| 163 | |||
| 164 | 1536 | call_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp); | |
| 165 | |||
| 166 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1536 times.
|
1536 | if (memcmp(class_idx0, class_idx1, id_size)) |
| 167 | ✗ | fail(); | |
| 168 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1536 times.
|
1536 | if (memcmp(transpose_idx0, transpose_idx1, id_size)) |
| 169 | ✗ | fail(); | |
| 170 | // Bench only square sizes, and ones with dimensions being a power of two. | ||
| 171 |
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) |
| 172 |
1/8✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
30 | bench_new(class_idx1, transpose_idx1, src1 + offset, stride, w, h, vb_pos, alf_gradient_tmp); |
| 173 | } | ||
| 174 | } | ||
| 175 | } | ||
| 176 | 42 | } | |
| 177 | |||
| 178 | 14 | void checkasm_check_vvc_alf(void) | |
| 179 | { | ||
| 180 | int bit_depth; | ||
| 181 | VVCDSPContext h; | ||
| 182 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 14 times.
|
56 | for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { |
| 183 | 42 | ff_vvc_dsp_init(&h, bit_depth); | |
| 184 | 42 | check_alf_filter(&h, bit_depth); | |
| 185 | } | ||
| 186 | 14 | report("alf_filter"); | |
| 187 | |||
| 188 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 14 times.
|
56 | for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) { |
| 189 | 42 | ff_vvc_dsp_init(&h, bit_depth); | |
| 190 | 42 | check_alf_classify(&h, bit_depth); | |
| 191 | } | ||
| 192 | 14 | report("alf_classify"); | |
| 193 | 14 | } | |
| 194 |