PR #25886 opened by Ramiro Polla (ramiro) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25886 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25886.patch
Track how many unscaled conversions each SIMD instruction set supports, so that coverage regressions in the ops backends show up as ref diffs. This will be used to test the completeness of the conversion to swscale2. >From 96354da5f4f8cb17c5e5d349bcf4ee7e8fb984a8 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Mon, 19 Oct 2026 15:46:53 +0200 Subject: [PATCH 1/3] swscale/ops_dispatch: record CPU flags on passes Copy the informative CPU flags of the compiled op list to the pass, so that tests can tell which implementation a conversion ended up using. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ramiro Polla <[email protected]> --- libswscale/graph.h | 1 + libswscale/ops_dispatch.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libswscale/graph.h b/libswscale/graph.h index 7380a991ce5..e1e2a795471 100644 --- a/libswscale/graph.h +++ b/libswscale/graph.h @@ -92,6 +92,7 @@ struct SwsPass { */ SwsPassFunc run; SwsBackend backend; /* backend this pass is using, or 0 */ + int cpu_flags; /* CPU flags used by the backend (informative) */ enum AVPixelFormat format; /* new pixel format */ int lines; /* pass dispatch size */ int slice_h; /* filter granularity */ diff --git a/libswscale/ops_dispatch.c b/libswscale/ops_dispatch.c index bfc776c43ac..129251daf12 100644 --- a/libswscale/ops_dispatch.c +++ b/libswscale/ops_dispatch.c @@ -571,7 +571,8 @@ static int compile_single(const CompileArgs *args, const SwsOpList *ops, input, 0, c.slice_align, c.func_opaque, NULL, c.priv, c.free, output); if (ret >= 0) { - (*output)->backend = c.backend->flags; + (*output)->backend = c.backend->flags; + (*output)->cpu_flags = c.cpu_flags; op_list_get_plane_copy(ops, *output); ff_sws_pass_link_output(*output, link); } @@ -689,7 +690,8 @@ static int compile_single(const CompileArgs *args, const SwsOpList *ops, if (ret < 0) return ret; - (*output)->backend = comp->backend->flags; + (*output)->backend = comp->backend->flags; + (*output)->cpu_flags = comp->cpu_flags; op_list_get_plane_copy(ops, *output); ff_sws_pass_link_output(*output, link); align_pass(*output, comp->block_size, comp->over_write, p->pixel_bits_out); -- 2.54.0 >From 939ff8bf57c52137a055246867ac1ae5d6280f46 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Tue, 20 Oct 2026 22:15:49 +0200 Subject: [PATCH 2/3] swscale/tests/swscale: add -coverage option Set up each conversion with sws_frame_setup() without running it, and print the backend and CPU flags of each of its passes. Also print a summary with how many conversions are supported and an MD5 of the per-conversion lines. The MD5 changes when a conversion switches to a different backend or CPU flags, even if the count stays the same. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ramiro Polla <[email protected]> --- libswscale/tests/swscale.c | 174 ++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 3 deletions(-) diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c index 23b41dc7298..0e47df117fb 100644 --- a/libswscale/tests/swscale.c +++ b/libswscale/tests/swscale.c @@ -33,6 +33,7 @@ #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" #include "libavutil/lfg.h" +#include "libavutil/md5.h" #include "libavutil/sfc64.h" #include "libavutil/slicethread.h" #include "libavutil/thread.h" @@ -47,6 +48,7 @@ #include "libswscale/swscale.h" #include "libswscale/format.h" +#include "libswscale/swscale_internal.h" #define IMPL_NEW 0 #define IMPL_LEGACY 1 @@ -77,6 +79,7 @@ struct options { int api; int pretty; int backends; + int coverage; }; struct mode { @@ -133,6 +136,10 @@ static struct { double speedup_max; int speedup_count; + int coverage_total; + int coverage_supported; + struct AVMD5 *coverage_md5; + struct runner *runners; AVFrame *ref; FILE *fp; @@ -631,6 +638,139 @@ static int init_frame(AVFrame **pframe, const AVFrame *ref, return 0; } +static const char *backend_name(SwsBackend backend) +{ + switch (backend) { + case SWS_BACKEND_LEGACY: return "legacy"; + case SWS_BACKEND_C: return "c"; + case SWS_BACKEND_MEMCPY: return "memcpy"; + case SWS_BACKEND_X86: return "x86"; + case SWS_BACKEND_AARCH64: return "aarch64"; + case SWS_BACKEND_SPIRV: return "spirv"; + default: return "unknown"; + } +} + +static void describe_passes(AVBPrint *bp, const SwsGraph *graph) +{ + if (graph->noop) { + av_bprintf(bp, "noop"); + return; + } + + for (int i = 0; i < graph->num_passes; i++) { + const SwsPass *pass = graph->passes[i]; + av_bprintf(bp, "%s%s", i ? ", " : "", backend_name(pass->backend)); + if (pass->cpu_flags) + av_bprintf(bp, "/0x%x", pass->cpu_flags); + } +} + +static void print_coverage_result(const AVFrame *src, const AVFrame *dst, + const struct mode *mode, + const struct options *opts, + const SwsGraph *graph) +{ + AVBPrint bp; + + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC); + print_test_params(&bp, src, dst, mode, opts); + av_bprintf(&bp, ", "); + if (graph) { + describe_passes(&bp, graph); + } else { + av_bprintf(&bp, "unsupported"); + } + av_bprintf(&bp, "\n"); + + av_md5_update(state.coverage_md5, (const uint8_t *) bp.str, strlen(bp.str)); + + if (av_log_get_level() >= AV_LOG_INFO) { + fputs(bp.str, stdout); + fflush(stdout); + } +} + +/* Sets up the src -> dst conversion without running it, and records whether + * the selected backends support it and which passes they use */ +static int check_coverage(struct runner *runner, const struct test_case *t, + const struct mode *mode, const struct options *opts) +{ + const AVFrame *ref = state.ref; + SwsContext *sws_src_dst = runner->sws_src_dst; + AVFrame *src = NULL; + AVFrame *dst = NULL; + const SwsGraph *graph = NULL; + int ret; + + ret = init_frame(&src, ref, ref->width, ref->height, t->src_fmt); + if (ret < 0) + goto error; + ret = init_frame(&dst, ref, t->dst_w, t->dst_h, t->dst_fmt); + if (ret < 0) + goto error; + + sws_src_dst->flags = mode->flags; + sws_src_dst->dither = mode->dither; + sws_src_dst->scaler = mode->scaler; + sws_src_dst->scaler_sub = mode->scaler_sub; + sws_src_dst->threads = opts->threads; + sws_src_dst->backends = opts->backends; + + ret = sws_frame_setup(sws_src_dst, dst, src); + if (ret < 0 && ret != AVERROR(ENOTSUP)) + goto error; + + state.coverage_total++; + if (ret >= 0) { + graph = sws_internal(sws_src_dst)->graph[0]; + state.coverage_supported++; + } + + print_coverage_result(src, dst, mode, opts, graph); + + ret = 0; + +error: + av_frame_free(&src); + av_frame_free(&dst); + return ret; +} + +static const SwsFlags coverage_flags[] = { + 0, + SWS_ACCURATE_RND, + SWS_BITEXACT, + SWS_ACCURATE_RND | SWS_BITEXACT, +}; + +static int run_coverage(struct runner *runner, const struct test_case *t, + const struct options *opts) +{ + if (opts->flags >= 0) + return check_coverage(runner, t, &t->mode, opts); + + for (int i = 0; i < FF_ARRAY_ELEMS(coverage_flags); i++) { + struct mode flags_mode = t->mode; + flags_mode.flags |= coverage_flags[i]; + int ret = check_coverage(runner, t, &flags_mode, opts); + if (ret < 0) + return ret; + } + + return 0; +} + +static void print_coverage_summary(void) +{ + uint8_t md5[16]; + + av_md5_final(state.coverage_md5, md5); + for (int i = 0; i < sizeof(md5); i++) + printf("%02x", md5[i]); + printf(" %d/%d\n", state.coverage_supported, state.coverage_total); +} + /* Runs a series of ref -> src -> dst -> out, and compares out vs ref */ static int run_test(struct runner *runner, const struct test_case *t, const struct options *opts) @@ -786,6 +926,8 @@ static int push_test(const struct test_case *t, const struct options *opts) { if (state.queue) return av_thread_message_queue_send(state.queue, (void *) t, 0); + if (opts->coverage) + return run_coverage(&state.runners[0], t, opts); return run_test(&state.runners[0], t, opts); } @@ -1149,6 +1291,10 @@ static int parse_options(int argc, char **argv, struct options *opts, FILE **fp) " Uses the specified cpuflags in the tests\n" " -pretty <1 or 0>\n" " Align fields while printing results\n" + " -coverage <1 or 0>\n" + " Set up each conversion without running it, and print the backend and\n" + " CPU flags of each of its passes. Also print a summary with how many\n" + " conversions are supported and an MD5 of the per-conversion lines.\n" " -v <level>\n" " Enable log verbosity at given level\n" ); @@ -1282,6 +1428,8 @@ static int parse_options(int argc, char **argv, struct options *opts, FILE **fp) opts->prob = atof(argv[i + 1]); } else if (!strcmp(argv[i], "-pretty")) { opts->pretty = atoi(argv[i + 1]); + } else if (!strcmp(argv[i], "-coverage")) { + opts->coverage = atoi(argv[i + 1]); } else if (!strcmp(argv[i], "-v")) { av_log_set_level(atoi(argv[i + 1])); } else { @@ -1292,6 +1440,13 @@ bad_option: } } + if (opts->coverage && + (state.hw_device_ctx || opts->api == IMPL_LEGACY || opts->runners > 1)) { + fprintf(stderr, "-coverage is not supported with -hw, -api legacy or multiple runners\n"); + ret = AVERROR(EINVAL); + goto end; + } + if (opts->w < 0 || opts->h < 0) { opts->w = opts->bench ? 1920 : 96; opts->h = opts->bench ? 1080 : 96; @@ -1358,9 +1513,18 @@ int main(int argc, char **argv) state.ref->height = opts.h; state.ref->format = AV_PIX_FMT_YUVA444P; - ret = init_ref(state.ref, &opts); - if (ret < 0) - goto error; + if (opts.coverage) { + state.coverage_md5 = av_md5_alloc(); + if (!state.coverage_md5) { + ret = AVERROR(ENOMEM); + goto error; + } + av_md5_init(state.coverage_md5); + } else { + ret = init_ref(state.ref, &opts); + if (ret < 0) + goto error; + } if (opts.runners > 1) { ret = av_thread_message_queue_alloc(&state.queue, opts.runners, @@ -1380,6 +1544,9 @@ int main(int argc, char **argv) ret = run_tests(&opts); } + if (opts.coverage && ret >= 0) + print_coverage_summary(); + /* fall through */ error: avpriv_slicethread_free(&slicethread); @@ -1390,6 +1557,7 @@ error: av_buffer_unref(&state.hw_device_ctx); av_hwframe_constraints_free(&state.hw_device_constr); av_frame_free(&state.ref); + av_freep(&state.coverage_md5); if (state.fp) fclose(state.fp); exit_handler(ret); -- 2.54.0 >From f26f6117b3fe47cca405d777f35ca66d5d2d60fa Mon Sep 17 00:00:00 2001 From: Ramiro Polla <[email protected]> Date: Tue, 20 Oct 2026 22:15:55 +0200 Subject: [PATCH 3/3] tests/fate/libswscale: add ops backend coverage tests Track how many unscaled conversions each SIMD instruction set supports, so that coverage regressions in the ops backends show up as ref diffs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ramiro Polla <[email protected]> --- tests/fate/libswscale.mak | 31 ++++++++++++++++++++++- tests/ref/fate/sws-coverage-aarch64-neon | 1 + tests/ref/fate/sws-coverage-memcpy | 1 + tests/ref/fate/sws-coverage-x86-avx2 | 1 + tests/ref/fate/sws-coverage-x86-avx512 | 1 + tests/ref/fate/sws-coverage-x86-avx512icl | 1 + tests/ref/fate/sws-coverage-x86-sse4 | 1 + 7 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/sws-coverage-aarch64-neon create mode 100644 tests/ref/fate/sws-coverage-memcpy create mode 100644 tests/ref/fate/sws-coverage-x86-avx2 create mode 100644 tests/ref/fate/sws-coverage-x86-avx512 create mode 100644 tests/ref/fate/sws-coverage-x86-avx512icl create mode 100644 tests/ref/fate/sws-coverage-x86-sse4 diff --git a/tests/fate/libswscale.mak b/tests/fate/libswscale.mak index 097241f3bce..f0428de00c1 100644 --- a/tests/fate/libswscale.mak +++ b/tests/fate/libswscale.mak @@ -102,7 +102,36 @@ $(FATE_SWS_UNPADDED) $(FATE_SWS_FLIPPED): SWS_PROB = -p 0.01 fate-sws-unpadded-memcpy fate-sws-flipped-memcpy: SWS_PROB = fate-sws-unpadded-memcpy fate-sws-flipped-memcpy: SWS_SCALER = -scaler none -FATE_LIBSWSCALE += $(FATE_SWS_UNSCALED) $(FATE_SWS_UNSTABLE) $(FATE_SWS_UNPADDED) $(FATE_SWS_FLIPPED) +# Count the unscaled conversions supported by each SIMD instruction set, +# without running them. +SWS_CPUFLAGS_SSE4 := sse4.1 +SWS_CPUFLAGS_AVX2 := $(SWS_CPUFLAGS_SSE4)+avx2+fma3 +SWS_CPUFLAGS_AVX512 := $(SWS_CPUFLAGS_AVX2)+avx512 +SWS_CPUFLAGS_AVX512ICL := $(SWS_CPUFLAGS_AVX512)+avx512icl +SWS_CPUFLAGS_NEON := neon + +FATE_SWS_COVERAGE-yes += fate-sws-coverage-memcpy +ifeq ($(ARCH_X86_64),yes) +FATE_SWS_COVERAGE-$(HAVE_SSE4_EXTERNAL) += fate-sws-coverage-x86-sse4 +FATE_SWS_COVERAGE-$(HAVE_AVX2_EXTERNAL) += fate-sws-coverage-x86-avx2 +FATE_SWS_COVERAGE-$(HAVE_AVX512_EXTERNAL) += fate-sws-coverage-x86-avx512 +FATE_SWS_COVERAGE-$(HAVE_AVX512ICL_EXTERNAL) += fate-sws-coverage-x86-avx512icl +endif +ifeq ($(ARCH_AARCH64),yes) +FATE_SWS_COVERAGE-$(HAVE_NEON) += fate-sws-coverage-aarch64-neon +endif + +fate-sws-coverage-x86-sse4: SWS_COVERAGE = -backends +x86 -cpuflags $(SWS_CPUFLAGS_SSE4) +fate-sws-coverage-x86-avx2: SWS_COVERAGE = -backends +x86 -cpuflags $(SWS_CPUFLAGS_AVX2) +fate-sws-coverage-x86-avx512: SWS_COVERAGE = -backends +x86 -cpuflags $(SWS_CPUFLAGS_AVX512) +fate-sws-coverage-x86-avx512icl: SWS_COVERAGE = -backends +x86 -cpuflags $(SWS_CPUFLAGS_AVX512ICL) +fate-sws-coverage-aarch64-neon: SWS_COVERAGE = -backends +aarch64 -cpuflags $(SWS_CPUFLAGS_NEON) + +$(FATE_SWS_COVERAGE-yes): libswscale/tests/swscale$(EXESUF) +$(FATE_SWS_COVERAGE-yes): CMD = run libswscale/tests/swscale$(EXESUF) -v 16 -coverage 1 -scaler none -backends memcpy $(SWS_COVERAGE) +fate-sws-coverage: $(FATE_SWS_COVERAGE-yes) + +FATE_LIBSWSCALE += $(FATE_SWS_UNSCALED) $(FATE_SWS_UNSTABLE) $(FATE_SWS_UNPADDED) $(FATE_SWS_FLIPPED) $(FATE_SWS_COVERAGE-yes) ifneq ($(HAVE_BIGENDIAN),yes) diff --git a/tests/ref/fate/sws-coverage-aarch64-neon b/tests/ref/fate/sws-coverage-aarch64-neon new file mode 100644 index 00000000000..2a6d735e506 --- /dev/null +++ b/tests/ref/fate/sws-coverage-aarch64-neon @@ -0,0 +1 @@ +3e084cc8f6cb0d5f41c51f80322237ec 59628/69696 diff --git a/tests/ref/fate/sws-coverage-memcpy b/tests/ref/fate/sws-coverage-memcpy new file mode 100644 index 00000000000..da76247d23f --- /dev/null +++ b/tests/ref/fate/sws-coverage-memcpy @@ -0,0 +1 @@ +9268734acc33a90ca35246403f69eb37 640/69696 diff --git a/tests/ref/fate/sws-coverage-x86-avx2 b/tests/ref/fate/sws-coverage-x86-avx2 new file mode 100644 index 00000000000..b8718e96a12 --- /dev/null +++ b/tests/ref/fate/sws-coverage-x86-avx2 @@ -0,0 +1 @@ +87ded3b004e8ba045e906c7df7314256 55552/69696 diff --git a/tests/ref/fate/sws-coverage-x86-avx512 b/tests/ref/fate/sws-coverage-x86-avx512 new file mode 100644 index 00000000000..357ee626572 --- /dev/null +++ b/tests/ref/fate/sws-coverage-x86-avx512 @@ -0,0 +1 @@ +8e5f309871a99dfebca7664cceec60c1 55552/69696 diff --git a/tests/ref/fate/sws-coverage-x86-avx512icl b/tests/ref/fate/sws-coverage-x86-avx512icl new file mode 100644 index 00000000000..40668ba4616 --- /dev/null +++ b/tests/ref/fate/sws-coverage-x86-avx512icl @@ -0,0 +1 @@ +9b2e5964946a026398b9cf32b556889e 55552/69696 diff --git a/tests/ref/fate/sws-coverage-x86-sse4 b/tests/ref/fate/sws-coverage-x86-sse4 new file mode 100644 index 00000000000..28385f1b467 --- /dev/null +++ b/tests/ref/fate/sws-coverage-x86-sse4 @@ -0,0 +1 @@ +7f01107c7207090d60551b386b653a11 2984/69696 -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
