FFmpeg
Loading...
Searching...
No Matches
sw_ops.c
Go to the documentation of this file.
1/**
2 * Copyright (C) 2025 Niklas Haas
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <string.h>
22
23#include "libavutil/avassert.h"
25#include "libavutil/refstruct.h"
26
27#include "libswscale/filters.h"
29#include "libswscale/uops.h"
31
32#include "checkasm.h"
33
34enum {
35 MAX_UOPS = 3, /* read, op, write */
37 PIXELS = 64,
38 LINES = 16,
39};
40
41typedef struct Test {
42 const char *name;
45
46 /* Extra metadata for the test harness */
47 SwsPixelType type_in; /* data format to fill */
48 SwsPixelType type_out; /* data format to compare */
49 SwsCompMask planes_in; /* planes to fill */
50 SwsCompMask planes_out; /* planes to compare */
51 int pixel_bits_in; /* read pixel stride */
52 int pixel_bits_out; /* write pixel stride */
53 unsigned ranges[NB_PLANES]; /* pixel range to fill */
54} Test;
55
56#define FMT(fmt, ...) tprintf((char[256]) {0}, 256, fmt, __VA_ARGS__)
57static const char *tprintf(char buf[], size_t size, const char *fmt, ...)
58{
59 va_list ap;
60 va_start(ap, fmt);
61 vsnprintf(buf, size, fmt, ap);
62 va_end(ap);
63 return buf;
64}
65
66static float rndf(void)
67{
68 union { uint32_t u; float f; } x;
69 do {
70 x.u = rnd();
71 } while (!isnormal(x.f));
72 return x.f;
73}
74
76{
77 switch (type) {
78 case SWS_PIXEL_U8: return (SwsPixel) { .u8 = val };
79 case SWS_PIXEL_U16: return (SwsPixel) { .u16 = val };
80 case SWS_PIXEL_U32: return (SwsPixel) { .u32 = val };
81 case SWS_PIXEL_F32: return (SwsPixel) { .f32 = val };
82 default: return (SwsPixel) {0};
83 }
84}
85
87{
88 switch (type) {
89 case SWS_PIXEL_U8: return (SwsPixel) { .u8 = rnd() & 0xFF };
90 case SWS_PIXEL_U16: return (SwsPixel) { .u16 = rnd() & 0xFFFF };
91 case SWS_PIXEL_U32: return (SwsPixel) { .u32 = rnd() };
92 case SWS_PIXEL_F32: return (SwsPixel) { .f32 = rndf() };
93 default: return (SwsPixel) {0};
94 }
95}
96
97static void fill32f(float *line, int num, unsigned range)
98{
99 const float scale = (float) range / UINT32_MAX;
100 for (int i = 0; i < num; i++)
101 line[i] = range ? scale * rnd() : rndf();
102}
103
104static void fill32(uint32_t *line, int num, unsigned range)
105{
106 for (int i = 0; i < num; i++)
107 line[i] = (range && range < UINT_MAX) ? rnd() % (range + 1) : rnd();
108}
109
110static void fill16(uint16_t *line, int num, unsigned range)
111{
112 if (!range) {
113 fill32((uint32_t *) line, AV_CEIL_RSHIFT(num, 1), 0);
114 } else {
115 for (int i = 0; i < num; i++)
116 line[i] = rnd() % (range + 1);
117 }
118}
119
120static void fill8(uint8_t *line, int num, unsigned range)
121{
122 if (!range) {
123 fill32((uint32_t *) line, AV_CEIL_RSHIFT(num, 2), 0);
124 } else {
125 for (int i = 0; i < num; i++)
126 line[i] = rnd() % (range + 1);
127 }
128}
129
131{
132 switch (ff_sws_pixel_type_size(type)) {
133 case 1: return SWS_PIXEL_U8;
134 case 2: return SWS_PIXEL_U16;
135 case 4: return SWS_PIXEL_U32;
136 default: break;
137 }
138
139 av_unreachable("Invalid pixel type!");
140 return SWS_PIXEL_NONE;
141}
142
143static void check_compiled(const Test *test,
144 const SwsCompiledOp *comp_ref,
145 const SwsCompiledOp *comp_new)
146{
147 /**
148 * We can't use `check_func()` alone because the actual function pointer
149 * may be a wrapper or entry point shared by multiple implementations.
150 * Solve it by hashing in the active CPU flags as well.
151 */
152 uintptr_t id = (uintptr_t) comp_new->func;
153 id ^= (id << 6) + (id >> 2) + 0x9e3779b97f4a7c15 + comp_new->cpu_flags;
154 if (!check_key(id, "%s", test->name))
155 return;
156
157 declare_func(void, const SwsOpExec *, const void *, int bx, int y, int bx_end, int y_end);
158
159 static DECLARE_ALIGNED_64(char, src0)[NB_PLANES][LINES][PIXELS * sizeof(uint32_t[4])];
160 static DECLARE_ALIGNED_64(char, src1)[NB_PLANES][LINES][PIXELS * sizeof(uint32_t[4])];
161 /* All output planes are stacked vertically in a single padded buffer */
162 static BUF_RECT(uint8_t, dst0, PIXELS * sizeof(uint32_t[4]), NB_PLANES * LINES);
163 static BUF_RECT(uint8_t, dst1, PIXELS * sizeof(uint32_t[4]), NB_PLANES * LINES);
164
165 av_assert0(PIXELS % comp_new->block_size == 0);
166 for (int p = 0; p < NB_PLANES; p++) {
167 void *plane = src0[p];
168 if (!SWS_COMP_TEST(test->planes_in, p)) {
169 memset(plane, 0, sizeof(src0[p]));
170 continue;
171 }
172
173 switch (test->type_in) {
174 case SWS_PIXEL_U8:
175 fill8(plane, sizeof(src0[p]) / sizeof(uint8_t), test->ranges[p]);
176 break;
177 case SWS_PIXEL_U16:
178 fill16(plane, sizeof(src0[p]) / sizeof(uint16_t), test->ranges[p]);
179 break;
180 case SWS_PIXEL_U32:
181 fill32(plane, sizeof(src0[p]) / sizeof(uint32_t), test->ranges[p]);
182 break;
183 case SWS_PIXEL_F32:
184 fill32f(plane, sizeof(src0[p]) / sizeof(uint32_t), test->ranges[p]);
185 break;
186 }
187 }
188
189 memcpy(src1, src0, sizeof(src0));
190 CLEAR_BUF_RECT(dst0);
191 CLEAR_BUF_RECT(dst1);
192
193 const int read_size = PIXELS * test->pixel_bits_in >> 3;
194 const int write_size = PIXELS * test->pixel_bits_out >> 3;
195
196 SwsOpExec exec = {0};
197 exec.width = PIXELS;
198 exec.height = exec.slice_h = LINES;
199 for (int i = 0; i < NB_PLANES; i++) {
200 exec.in_stride[i] = sizeof(src0[i][0]);
201 exec.out_stride[i] = dst0_stride;
202 exec.in_bump[i] = exec.in_stride[i] - read_size;
203 exec.out_bump[i] = exec.out_stride[i] - write_size;
204 }
205
206 int32_t in_bump_y[LINES];
207 int32_t in_offset_x[PIXELS];
208 const SwsUOp *read_op = &test->uops[0];
209 switch (read_op->uop) {
211 exec.in_bump[1] = exec.in_stride[1] = 0;
212 static_assert(sizeof(src0[1]) >= sizeof(uint32_t[256]), "palette plane too small");
213 break;
215 const int *offsets = read_op->data.kernel->offsets;
216 for (int y = 0; y < LINES - 1; y++)
217 in_bump_y[y] = offsets[y + 1] - offsets[y] - 1;
218 in_bump_y[LINES - 1] = 0;
219 exec.in_bump_y = in_bump_y;
220 break;
221 }
223 const int *offsets = read_op->data.kernel->offsets;
224 for (int x = 0; x < PIXELS; x++)
225 in_offset_x[x] = offsets[x] * test->pixel_bits_in >> 3;
226 exec.in_offset_x = in_offset_x;
227 }
228 }
229
230 for (int i = 0; i < NB_PLANES; i++) {
231 exec.in[i] = (void *) src0[i];
232 exec.out[i] = dst0 + i * LINES * dst0_stride;
233 exec.block_size_in[i] = comp_ref->block_size * test->pixel_bits_in >> 3;
234 exec.block_size_out[i] = comp_ref->block_size * test->pixel_bits_out >> 3;
235 }
236 checkasm_call(comp_ref->func, &exec, comp_ref->priv, 0, 0, PIXELS / comp_ref->block_size, LINES);
237
238 for (int i = 0; i < NB_PLANES; i++) {
239 exec.in[i] = (void *) src1[i];
240 exec.out[i] = dst1 + i * LINES * dst1_stride;
241 exec.block_size_in[i] = comp_new->block_size * test->pixel_bits_in >> 3;
242 exec.block_size_out[i] = comp_new->block_size * test->pixel_bits_out >> 3;
243 }
244 checkasm_call_checked(comp_new->func, &exec, comp_new->priv, 0, 0, PIXELS / comp_new->block_size, LINES);
245
246 for (int i = 0; i < NB_PLANES; i++) {
247 if (!SWS_COMP_TEST(test->planes_out, i))
248 continue;
249
250 /* checkasm_check_padded() assumes a power of two alignment, but our
251 * overwrite may be an arbitrary number of bytes. Smooth out the
252 * difference by manually copying over the padding from the reference
253 * to the output buffer, and extending the checked padding past it. */
254 const int elem_size = ff_sws_pixel_type_size(test->type_out);
255 const int over_write = comp_new->over_write[i];
256 const int padding = (over_write + elem_size - 1) / elem_size + 8;
257 const int w = write_size / elem_size;
258 const uint8_t *out_ref = dst0 + i * LINES * dst0_stride;
259 uint8_t *out_new = exec.out[i];
260 for (int y = 0; y < LINES; y++) {
261 memcpy(&out_new[y * dst1_stride + write_size],
262 &out_ref[y * dst0_stride + write_size], over_write);
263 }
264
265 const char *desc = FMT("%s[%d]", test->name, i);
266 switch (test->type_out) {
267 case SWS_PIXEL_U8:
268 checkasm_check_padded(uint8_t, out_ref, dst0_stride, out_new, dst1_stride,
269 w, LINES, desc, 1, 0, padding);
270 break;
271 case SWS_PIXEL_U16:
272 checkasm_check_padded(uint16_t, (void *) out_ref, dst0_stride,
273 (void *) out_new, dst1_stride,
274 w, LINES, desc, 1, 0, padding);
275 break;
276 case SWS_PIXEL_U32:
277 checkasm_check_padded(uint32_t, (void *) out_ref, dst0_stride,
278 (void *) out_new, dst1_stride,
279 w, LINES, desc, 1, 0, padding);
280 break;
281 case SWS_PIXEL_F32:
282 checkasm_check_padded(float_ulp, (void *) out_ref, dst0_stride,
283 (void *) out_new, dst1_stride,
284 w, LINES, desc, 0, 1, 0, padding);
285 break;
286 }
287 }
288
289 bench(comp_new->func, &exec, comp_new->priv, 0, 0, PIXELS / comp_new->block_size, LINES);
290}
291
292static void run_test(const Test *test)
293{
295 if (!ctx)
296 return;
297 ctx->flags = SWS_BITEXACT;
298
299 /* Generate dummy uop list on-stack */
300 SwsUOpList oplist = {
301 .ops = (SwsUOp *) test->uops,
302 .num_ops = test->num_uops,
303
304 /* Less efficient, but works universally */
305 .planes_in = SWS_COMP_ALL,
306 .planes_out = SWS_COMP_ALL,
307 };
308
309 for (int i = 0; i < test->num_uops; i++) {
310 const int pixel_size = ff_sws_pixel_type_size(test->uops[i].type);
311 if (pixel_size > oplist.pixel_size_max)
312 oplist.pixel_size_max = pixel_size;
313 }
314
315 static const SwsOpBackend *backend_ref;
316 if (!backend_ref) {
317 for (int n = 0; ff_sws_op_backends[n]; n++) {
318 if (!strcmp(ff_sws_op_backends[n]->name, "c")) {
319 backend_ref = ff_sws_op_backends[n];
320 break;
321 }
322 }
323 av_assert0(backend_ref);
324 }
325
326 /* Always compile `ops` using the C backend as a reference */
327 SwsCompiledOp comp_ref = {0};
328 int ret = backend_ref->compile_uops(ctx, &oplist, &comp_ref);
329 if (ret < 0) {
330 av_assert0(ret != AVERROR(ENOTSUP));
331 fail();
332 goto done;
333 }
334
335 /* Check with the C backend to establish a reference */
336 check_compiled(test, &comp_ref, &comp_ref);
337
338 /* Iterate over every other backend, and test it against the C reference */
339 for (int n = 0; ff_sws_op_backends[n]; n++) {
340 const SwsOpBackend *backend = ff_sws_op_backends[n];
341 if (backend->hw_format != AV_PIX_FMT_NONE || backend == backend_ref)
342 continue;
343 if (!backend->compile_uops)
344 continue;
345
346 SwsCompiledOp comp_new = {0};
347 int ret = backend->compile_uops(ctx, &oplist, &comp_new);
348 if (ret == AVERROR(ENOTSUP)) {
349 continue;
350 } else if (ret < 0) {
351 fail();
352 goto done;
353 }
354
355 /* Distinguish backends from each other even with same CPU flags */
357 check_compiled(test, &comp_ref, &comp_new);
358 ff_sws_compiled_op_unref(&comp_new);
359 }
360
361done:
362 ff_sws_compiled_op_unref(&comp_ref);
364}
365
366static void check_uop(const char *name, const SwsUOp *uop,
367 SwsCompMask mask_in, SwsCompMask mask_out,
368 const unsigned ranges[NB_PLANES])
369{
370 Test t = {
371 .name = name,
372 .type_in = uop->type,
373 .type_out = uop->type,
374 };
375
376 for (int i = 0; ranges && i < NB_PLANES; i++)
377 t.ranges[i] = ranges[i];
378
379 /* uops with non-standard output type conversions */
380 switch (uop->uop) {
381 case SWS_UOP_TO_U8: t.type_out = SWS_PIXEL_U8; break;
382 case SWS_UOP_TO_U16: t.type_out = SWS_PIXEL_U16; break;
383 case SWS_UOP_TO_U32: t.type_out = SWS_PIXEL_U32; break;
384 case SWS_UOP_TO_F32: t.type_out = SWS_PIXEL_F32; break;
389 t.type_out = uop->par.filter.type;
390 break;
391 }
392
393 /* Set up read/write metadata for rw uops */
394 const int bits_in = ff_sws_pixel_type_size(t.type_in) * 8;
395 const int bits_out = ff_sws_pixel_type_size(t.type_out) * 8;
396 switch (uop->uop) {
400 t.planes_in = uop->mask;
401 t.pixel_bits_in = bits_in;
402 break;
404 t.planes_out = uop->mask;
405 t.pixel_bits_out = bits_out;
406 break;
409 t.pixel_bits_in = bits_in * SWS_COMP_COUNT(uop->mask);
410 break;
413 t.pixel_bits_out = bits_out * SWS_COMP_COUNT(uop->mask);
414 break;
417 t.pixel_bits_in = 4;
418 break;
421 t.pixel_bits_out = 4;
422 break;
423 case SWS_UOP_READ_BIT:
425 t.pixel_bits_in = 1;
426 break;
429 t.pixel_bits_out = 1;
430 break;
433 t.pixel_bits_in = 8; /* size of index */
434 break;
435 }
436
437 /* Add read uop if needed */
438 if (!t.planes_in) {
439 t.planes_in = mask_in;
440 t.pixel_bits_in = bits_in;
441 t.uops[t.num_uops++] = (SwsUOp) {
442 .type = pixel_type_to_int(t.type_in),
443 .uop = SWS_UOP_READ_PLANAR,
444 .mask = SWS_COMP_ALL, /* extra planes are zero'd */
445 };
446 }
447
448 /* Add the UOp itself */
449 t.uops[t.num_uops++] = *uop;
450
451 /* Add write uop if needed */
452 if (!t.planes_out) {
453 t.planes_out = mask_out;
454 t.pixel_bits_out = bits_out;
455 t.uops[t.num_uops++] = (SwsUOp) {
456 .type = pixel_type_to_int(t.type_out),
458 .mask = SWS_COMP_ALL, /* extra planes are ignored */
459 };
460 }
461
462 run_test(&t);
463}
464
465static void check_range(const char *name, const SwsUOp *uop,
466 const unsigned ranges[NB_PLANES])
467{
468 /* Test all planes to ensure data remains untouched */
469 check_uop(name, uop, SWS_COMP_ALL, SWS_COMP_ALL, ranges);
470}
471
472static void check_simple(const char *name, const SwsUOp *uop)
473{
474 check_range(name, uop, NULL);
475}
476
477static void check_vec4(const char *name, SwsUOp *uop)
478{
479 for (int i = 0; i < 4; i++)
480 uop->data.vec4[i] = rndpx(uop->type);
481
482 check_simple(name, uop);
483}
484
485static void check_clear(const char *name, SwsUOp *uop)
486{
487 /* Clear values are always expanded to 32 bits, see SwsClearUOp */
488 for (int i = 0; i < 4; i++)
489 uop->data.vec4[i] = ff_sws_pixel_expand32(uop->type, rndpx(uop->type));
490
491 check_simple(name, uop);
492}
493
494#define MK_RANGES(R) ((const unsigned[]) { R, R, R, R })
495
496static void check_read(const char *name, SwsUOp *uop)
497{
498 check_uop(name, uop, uop->mask, uop->mask, NULL);
499}
500
501static void check_write(const char *name, const SwsUOp *uop)
502{
503 const int frac = uop->uop == SWS_UOP_WRITE_BIT ? 3 :
504 uop->uop == SWS_UOP_WRITE_NIBBLE ? 1 : 0;
505 const int bits = 8 >> frac;
506 const unsigned range = (1 << bits) - 1;
507 check_uop(name, uop, uop->mask, uop->mask, MK_RANGES(range));
508}
509
510static void check_filter(const char *name, SwsUOp *uop)
511{
512 const bool is_vert = uop->uop == SWS_UOP_READ_PLANAR_FV;
513
514 SwsFilterParams par = {
515 .scaler_params = { SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT },
516 .dst_size = is_vert ? LINES : PIXELS,
517 };
518
519 const SwsScaler scalers[] = {
522 };
523
524 for (int s = 0; s < FF_ARRAY_ELEMS(scalers); s++) {
525 par.scaler = scalers[s];
526
527 for (par.src_size = 1; par.src_size <= par.dst_size; par.src_size <<= 1) {
528 if (ff_sws_filter_generate(NULL, &par, &uop->data.kernel) < 0) {
529 fail();
530 return;
531 }
532
533 char desc[256];
534 snprintf(desc, sizeof(desc), "%s_%s_%d", name,
536
537 check_read(desc, uop);
539 }
540 }
541}
542
543static void check_swizzle(const char *name, const SwsUOp *uop)
544{
545 /* Only check data equality in needed components; since the others
546 * could either remain untouched or contain garbage */
547 check_uop(name, uop, SWS_COMP_ALL, uop->mask, NULL);
548}
549
550static void check_expand_bit(const char *name, const SwsUOp *uop)
551{
552 check_range(name, uop, MK_RANGES(1));
553}
554
555static void check_cast(const char *name, const SwsUOp *uop)
556{
558 switch (uop->uop) {
559 case SWS_UOP_TO_U8: dst = SWS_PIXEL_U8; break;
560 case SWS_UOP_TO_U16: dst = SWS_PIXEL_U16; break;
561 case SWS_UOP_TO_U32: dst = SWS_PIXEL_U32; break;
562 case SWS_UOP_TO_F32: dst = SWS_PIXEL_F32; break;
565 default: return;
566 }
567
568 const int isize = ff_sws_pixel_type_size(uop->type);
569 const int osize = ff_sws_pixel_type_size(dst);
570 unsigned range = UINT32_MAX >> (32 - osize * 8);
571 if (isize < osize || !ff_sws_pixel_type_is_int(dst))
572 range = 0;
573
574 check_uop(name, uop, uop->mask, uop->mask, MK_RANGES(range));
575}
576
577static void check_scale(const char *name, SwsUOp *uop)
578{
579 const int bits = ff_sws_pixel_type_size(uop->type) * 8;
580 const unsigned max = UINT32_MAX >> (32 - bits);
581 SwsPixel scale = uop->data.scalar = rndpx(uop->type);
582 unsigned range = 0;
583
584 /* Ensure the result won't exceed the value range */
585 switch (uop->type) {
586 case SWS_PIXEL_U8: range = max / (scale.u8 ? scale.u8 : 1); break;
587 case SWS_PIXEL_U16: range = max / (scale.u16 ? scale.u16 : 1); break;
588 case SWS_PIXEL_U32: range = max / (scale.u32 ? scale.u32 : 1); break;
589 }
590
592}
593
594static void check_unpack(const char *name, const SwsUOp *uop)
595{
596 const uint8_t *pat = uop->par.pack.pattern;
597 const int total = pat[0] + pat[1] + pat[2] + pat[3];
598 const unsigned range = UINT32_MAX >> (32 - total);
599
600 check_uop(name, uop, SWS_COMP(0), uop->mask, MK_RANGES(range));
601}
602
603static void check_pack(const char *name, const SwsUOp *uop)
604{
605 const uint8_t *pat = uop->par.pack.pattern;
606 const unsigned ranges[4] = {
607 (1 << pat[0]) - 1, (1 << pat[1]) - 1,
608 (1 << pat[2]) - 1, (1 << pat[3]) - 1,
609 };
610
611 check_uop(name, uop, uop->mask, SWS_COMP(0), ranges);
612}
613
614static void check_linear(const char *name, SwsUOp *uop)
615{
616 const SwsLinearUOp *par = &uop->par.lin;
617 for (int i = 0; i < 4; i++) {
618 for (int j = 0; j < 5; j++) {
619 if (par->zero & SWS_MASK(i, j))
620 uop->data.mat4x5[i][j] = constpx(uop->type, 0);
621 else if (par->one & SWS_MASK(i, j))
622 uop->data.mat4x5[i][j] = constpx(uop->type, 1);
623 else
624 uop->data.mat4x5[i][j] = rndpx(uop->type);
625 }
626 }
627
628 check_simple(name, uop);
629}
630
631static void check_dither(const char *name, SwsUOp *uop)
632{
634
635 const int size = 1 << uop->par.dither.size_log2;
636 const int height = ff_sws_dither_height(&uop->par.dither);
638 if (!matrix) {
639 fail();
640 return;
641 }
642
643 for (int i = 0; i < size * size; i++)
644 matrix[i] = rndpx(uop->type);
645 memcpy(matrix + size * size, matrix,
646 size * (height - size) * sizeof(*matrix));
647
648 uop->data.ptr = matrix;
649 check_simple(name, uop);
650
652}
653
654static void check_lut_3d(const char *name, SwsUOp *uop)
655{
656 SwsLut3D *lut3d = ff_sws_lut3d_alloc();
657 if (!lut3d) {
658 fail();
659 return;
660 }
661
662 checkasm_init(&lut3d->input, sizeof(lut3d->input));
663
664 if (uop->par.lut3d.dynamic) {
665 checkasm_init(&lut3d->tone_map, sizeof(lut3d->tone_map));
666 checkasm_init(&lut3d->output, sizeof(lut3d->output));
667 lut3d->dynamic = true;
668
669 /* Prevent out-of-bounds read from IPT values with abs(PT) > 0.5 */
670 for (int i = 0; i < FF_ARRAY_ELEMS(lut3d->tone_map); i++)
671 lut3d->tone_map[i].y = FFMIN(lut3d->tone_map[i].y, 1 << 15);
672 }
673
674 uop->data.lut3d = lut3d;
676
677 av_refstruct_unref(&lut3d);
678}
679
680#define CHECK_FUNCTION(CHECK, NAME, ...) \
681 CHECK(#NAME, &(SwsUOp) { __VA_ARGS__ });
682
683#define CHECK_FOR(UOP, CHECK) \
684 SWS_FOR_STRUCT(U8, UOP, CHECK_FUNCTION, CHECK) \
685 SWS_FOR_STRUCT(U16, UOP, CHECK_FUNCTION, CHECK) \
686 SWS_FOR_STRUCT(U32, UOP, CHECK_FUNCTION, CHECK) \
687 SWS_FOR_STRUCT(F32, UOP, CHECK_FUNCTION, CHECK) \
688 report(#UOP)
689
691{
692 CHECK_FOR(READ_PLANAR, check_read);
693 CHECK_FOR(READ_PLANAR_FH, check_filter);
694 CHECK_FOR(READ_PLANAR_FV, check_filter);
695 CHECK_FOR(READ_PACKED, check_read);
696 CHECK_FOR(READ_NIBBLE, check_read);
697 CHECK_FOR(READ_BIT, check_read);
698 CHECK_FOR(READ_PALETTE, check_read);
699 CHECK_FOR(WRITE_PLANAR, check_write);
700 CHECK_FOR(WRITE_PACKED, check_write);
701 CHECK_FOR(WRITE_NIBBLE, check_write);
702 CHECK_FOR(WRITE_BIT, check_write);
703 CHECK_FOR(PERMUTE, check_swizzle);
705 CHECK_FOR(SWAP_BYTES, check_simple);
706 CHECK_FOR(EXPAND_BIT, check_expand_bit);
707 CHECK_FOR(EXPAND_PAIR, check_cast);
708 CHECK_FOR(EXPAND_QUAD, check_cast);
709 CHECK_FOR(TO_U8, check_cast);
710 CHECK_FOR(TO_U16, check_cast);
711 CHECK_FOR(TO_U32, check_cast);
712 CHECK_FOR(TO_F32, check_cast);
717 CHECK_FOR(UNPACK, check_unpack);
718 CHECK_FOR(PACK, check_pack);
719 CHECK_FOR(LSHIFT, check_simple);
723 CHECK_FOR(DITHER, check_dither);
724 CHECK_FOR(LUT_3D, check_lut_3d);
725}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
static double val(void *priv, double ch)
Definition aeval.c:77
static AVFormatContext * ctx
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define COPY(src, name)
#define MAX
Definition blend_modes.c:46
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
#define bench(...)
Definition checkasm.h:142
#define rnd
Definition checkasm.h:140
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define RSHIFT(a, b)
Definition common.h:56
#define NULL
Definition coverity.c:32
#define max(a, b)
#define SCALE(c)
Definition dcadata.c:7338
#define ADD(a, b)
static const char * checkasm_get_cpu_suffix(void)
Get the suffix for the current CPU flag, or "c" if none.
Definition checkasm.h:350
static const uint8_t bits[8]
Definition fastaudio.c:100
int ret
Definition ffplay.c:391
SDL_atomic_t done
Definition ffplay.c:392
const char * ff_sws_scaler_name(SwsScaler scaler)
Return the friendly name of a given scaler enum, or NULL if invalid.
Definition filters.c:510
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
Definition filters.c:203
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define check_key
Definition test.h:482
#define BUF_RECT(type, name, w, h)
Definition utils.h:689
#define CLEAR_BUF_RECT(name)
Clear a rectangular buffer (including padding)
Definition utils.h:707
#define AVERROR(e)
Definition error.h:45
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition utils.c:1081
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition utils.c:2408
#define SWS_PARAM_DEFAULT
Definition swscale.h:456
SwsScaler
Definition swscale.h:96
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
Definition swscale.h:100
@ SWS_SCALE_SINC
unwindowed sinc
Definition swscale.h:103
@ SWS_BITEXACT
Definition swscale.h:178
CHECKASM_API void checkasm_init(void *buf, size_t bytes)
Initialize a buffer with pathological test patterns.
Definition utils.c:431
static const int offsets[]
Definition hevc_pel.c:34
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
enum MPFType type
Definition jpegmpfenc.c:55
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
const char * desc
Definition libsvtav1.c:83
@ INPUT_LUT_SIZE
Definition lut3d.h:36
uint8_t w
Definition llvidencdsp.c:39
SwsLut3D * ff_sws_lut3d_alloc(void)
Allocates a refstruct.
Definition lut3d.c:33
#define FFMIN(a, b)
Definition macros.h:49
enum AVColorRange range
#define DECLARE_ALIGNED_64(t, v)
const SwsOpBackend *const ff_sws_op_backends[]
Definition ops.c:42
void ff_sws_compiled_op_unref(SwsCompiledOp *comp)
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
#define checkasm_call_checked(func,...)
Definition aarch64.h:93
const char * name
Definition qsvenc.c:142
#define MIN(a, b)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition refstruct.h:105
#define FF_ARRAY_ELEMS(a)
SwsOpFunc func
Main external API structure.
Definition swscale.h:227
uint8_t size_log2
Definition uops.h:283
int src_size
The relative sizes of the input and output images.
Definition filters.h:63
SwsScaler scaler
The filter kernel and parameters to use.
Definition filters.h:55
SwsPixelType type
Definition uops.h:237
int * offsets
The computed source pixel positions for each row of the filter.
Definition filters.h:111
uint32_t zero
Definition uops.h:269
uint32_t one
Definition uops.h:268
int dynamic
Definition uops.h:287
v3u16_t output[OUTPUT_LUT_SIZE_PT][OUTPUT_LUT_SIZE_PT][OUTPUT_LUT_SIZE_I]
Definition lut3d.h:56
v3u16_t input[INPUT_LUT_SIZE][INPUT_LUT_SIZE][INPUT_LUT_SIZE]
Definition lut3d.h:55
bool dynamic
Definition lut3d.h:52
v2u16_t tone_map[TONE_LUT_SIZE+1]
Definition lut3d.h:59
const char * name
int(* compile_uops)(SwsContext *ctx, const SwsUOpList *uops, SwsCompiledOp *out)
Alternative to compile that takes a list of micro-ops directly.
enum AVPixelFormat hw_format
If NONE, backend only supports software frames.
Copyright (C) 2026 Niklas Haas.
int32_t block_size_out[4]
ptrdiff_t out_stride[4]
uint8_t * out[4]
int32_t * in_offset_x
Pixel offset map; for horizontal scaling, in bytes.
const uint8_t * in[4]
int32_t height
int32_t slice_h
ptrdiff_t in_stride[4]
int32_t width
int32_t block_size_in[4]
ptrdiff_t in_bump[4]
Pointer bump, difference between stride and processed line size.
ptrdiff_t out_bump[4]
int32_t * in_bump_y
Line bump; determines how many additional lines to advance (after incrementing normally to the next l...
uint8_t pattern[4]
Definition uops.h:255
int pixel_size_max
Definition uops.h:351
Definition uops.h:308
SwsPixel scalar
Definition uops.h:319
SwsCompMask mask
Definition uops.h:312
SwsUOpType uop
Definition uops.h:311
SwsUOpParams par
Definition uops.h:313
const SwsLut3D * lut3d
Definition uops.h:323
SwsFilterWeights * kernel
Definition uops.h:317
SwsPixel * ptr
Definition uops.h:318
union SwsUOp::@242237116251216327057105100216205033300341206345 data
SwsPixelType type
Definition uops.h:310
SwsPixel mat4x5[4][5]
Definition uops.h:321
SwsPixel vec4[4]
Definition uops.h:320
Definition sw_ops.c:41
int pixel_bits_out
Definition sw_ops.c:52
SwsPixelType type_out
Definition sw_ops.c:48
SwsCompMask planes_in
Definition sw_ops.c:49
SwsPixelType type_in
Definition sw_ops.c:47
SwsUOp uops[MAX_UOPS]
Definition sw_ops.c:43
int num_uops
Definition sw_ops.c:44
SwsCompMask planes_out
Definition sw_ops.c:50
unsigned ranges[NB_PLANES]
Definition sw_ops.c:53
const char * name
Definition sw_ops.c:42
int pixel_bits_in
Definition sw_ops.c:51
Definition idctdsp.c:35
const char * name
Definition idctdsp.c:36
uint16_t y
Definition csputils.h:69
static void fill16(uint16_t *line, int num, unsigned range)
Definition sw_ops.c:110
static void fill8(uint8_t *line, int num, unsigned range)
Definition sw_ops.c:120
static void check_expand_bit(const char *name, const SwsUOp *uop)
Definition sw_ops.c:550
static void check_lut_3d(const char *name, SwsUOp *uop)
Definition sw_ops.c:654
#define CHECK_FOR(UOP, CHECK)
Definition sw_ops.c:683
static void fill32f(float *line, int num, unsigned range)
Definition sw_ops.c:97
static void check_write(const char *name, const SwsUOp *uop)
Definition sw_ops.c:501
static SwsPixel rndpx(SwsPixelType type)
Definition sw_ops.c:86
static void check_uop(const char *name, const SwsUOp *uop, SwsCompMask mask_in, SwsCompMask mask_out, const unsigned ranges[NB_PLANES])
Definition sw_ops.c:366
static void run_test(const Test *test)
Definition sw_ops.c:292
static float rndf(void)
Definition sw_ops.c:66
static void check_filter(const char *name, SwsUOp *uop)
Definition sw_ops.c:510
static void check_vec4(const char *name, SwsUOp *uop)
Definition sw_ops.c:477
void checkasm_check_sw_ops(void)
Definition sw_ops.c:690
static void check_read(const char *name, SwsUOp *uop)
Definition sw_ops.c:496
static void check_dither(const char *name, SwsUOp *uop)
Definition sw_ops.c:631
static void check_linear(const char *name, SwsUOp *uop)
Definition sw_ops.c:614
#define MK_RANGES(R)
Definition sw_ops.c:494
@ LINES
Definition sw_ops.c:38
@ NB_PLANES
Definition sw_ops.c:36
@ MAX_UOPS
Definition sw_ops.c:35
static void check_scale(const char *name, SwsUOp *uop)
Definition sw_ops.c:577
static void check_simple(const char *name, const SwsUOp *uop)
Definition sw_ops.c:472
static void check_pack(const char *name, const SwsUOp *uop)
Definition sw_ops.c:603
static void check_swizzle(const char *name, const SwsUOp *uop)
Definition sw_ops.c:543
static void check_unpack(const char *name, const SwsUOp *uop)
Definition sw_ops.c:594
static SwsPixelType pixel_type_to_int(const SwsPixelType type)
Definition sw_ops.c:130
static void check_cast(const char *name, const SwsUOp *uop)
Definition sw_ops.c:555
static void check_range(const char *name, const SwsUOp *uop, const unsigned ranges[NB_PLANES])
Definition sw_ops.c:465
static const char * tprintf(char buf[], size_t size, const char *fmt,...)
Definition sw_ops.c:57
static SwsPixel constpx(SwsPixelType type, int val)
Definition sw_ops.c:75
static void fill32(uint32_t *line, int num, unsigned range)
Definition sw_ops.c:104
static void check_compiled(const Test *test, const SwsCompiledOp *comp_ref, const SwsCompiledOp *comp_new)
Definition sw_ops.c:143
#define FMT(fmt,...)
Definition sw_ops.c:56
#define checkasm_call(func,...)
Call a function with signal handling.
Definition test.h:252
CHECKASM_API CheckasmKey CHECKASM_API void checkasm_set_func_variant(const char *id,...) CHECKASM_PRINTF(1
Set a custom variant identifier for the next checkasm_check_func() call.
#define check_clear(func, size)
Definition blockdsp.c:42
#define src1
Definition h264pred.c:141
#define src0
Definition h264pred.c:140
#define PIXELS
int num
Definition error.c:23
#define height
Definition dsp.h:99
int size
SwsDitherUOp dither
Definition uops.h:304
SwsFilterUOp filter
Definition uops.h:298
SwsLut3DUOp lut3d
Definition uops.h:305
SwsLinearUOp lin
Definition uops.h:303
SwsPackUOp pack
Definition uops.h:301
int ff_sws_dither_height(const SwsDitherUOp *dither)
Computes (1 << size_log2) + MAX(y_offset).
Definition uops.c:218
@ SWS_COMP_ALL
Definition uops.h:132
SwsPixelType
Definition uops.h:40
@ SWS_PIXEL_F32
Definition uops.h:45
@ SWS_PIXEL_U32
Definition uops.h:44
@ SWS_PIXEL_U16
Definition uops.h:43
@ SWS_PIXEL_NONE
Definition uops.h:41
@ SWS_PIXEL_U8
Definition uops.h:42
#define SWS_COMP(X)
Definition uops.h:133
#define SWS_COMP_TEST(mask, X)
Definition uops.h:134
#define SWS_COMP_ELEMS(N)
Definition uops.h:136
#define SWS_MASK(I, J)
Definition uops.h:275
@ SWS_UOP_TO_U8
Definition uops.h:199
@ SWS_UOP_EXPAND_QUAD
Definition uops.h:198
@ SWS_UOP_READ_PLANAR
Definition uops.h:173
@ SWS_UOP_WRITE_PLANAR
Definition uops.h:182
@ SWS_UOP_READ_NIBBLE
Definition uops.h:178
@ SWS_UOP_READ_BIT
Definition uops.h:179
@ SWS_UOP_WRITE_NIBBLE
Definition uops.h:184
@ SWS_UOP_READ_PLANAR_FH
Definition uops.h:174
@ SWS_UOP_WRITE_PACKED
Definition uops.h:183
@ SWS_UOP_WRITE_BIT
Definition uops.h:185
@ SWS_UOP_READ_PACKED
Definition uops.h:177
@ SWS_UOP_EXPAND_PAIR
Definition uops.h:197
@ SWS_UOP_TO_U16
Definition uops.h:200
@ SWS_UOP_READ_PALETTE
Definition uops.h:180
@ SWS_UOP_READ_PLANAR_FV
Definition uops.h:175
@ SWS_UOP_TO_U32
Definition uops.h:201
@ SWS_UOP_TO_F32
Definition uops.h:202
static SwsPixel ff_sws_pixel_expand32(SwsPixelType type, SwsPixel val)
Definition uops.h:105
#define SWS_COMP_COUNT(mask)
Definition uops.h:137
static av_const bool ff_sws_pixel_type_is_int(SwsPixelType type)
Definition uops.h:64
uint8_t SwsCompMask
Bit-mask of components.
Definition uops.h:129
static av_const int ff_sws_pixel_type_size(SwsPixelType type)
Definition uops.h:51
#define NB_PLANES
Definition vf_geq.c:41
#define LINEAR
#define CLEAR(destin)
Definition wavpackenc.c:50