PR #25400 opened by Forgejo_Fairy
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25400
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25400.patch

The new-API benchmark releases destination buffers between iterations, while 
the legacy benchmark reuses a preallocated destination. Add `-reuse_dst 1` to 
measure the new CPU API with the same allocation lifetime, retaining the 
existing default for buffer-sharing coverage.

A separate commit adds unscaled FATE coverage with preallocated destinations 
for each CPU ops backend, performing two conversions per case. This contributes 
to #25397 without changing production conversion behavior or promoting unstable 
backends.

Validation: built with GCC 13.3.0 using `--disable-all --disable-autodetect 
--enable-swscale --enable-unstable`; `make -j4 fate-libswscale 
fate-checkasm-sw_ops SAMPLES=/opt/fate-suite` passed on Ampere-1a AArch64 and 
Ryzen 9 5950X x86-64. Also checked explicit destination alignment and rejection 
of invalid `-reuse_dst` values. Existing SSIM thresholds and 
unsupported-conversion handling are unchanged.


>From df0fd730540d5a2cddd34a7595146e4f6cc862be Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Fri, 23 Oct 2026 18:50:58 +0000
Subject: [PATCH 1/2] swscale/tests: allow reusing preallocated destination
 buffers

Add -reuse_dst to benchmark the new CPU API with the same destination 
allocation lifetime as the legacy API. Preserve the default buffer-sharing 
coverage.

Assisted-by: Fairy
---
 libswscale/tests/swscale.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
index 70ea5de2e18..1ca871188dc 100644
--- a/libswscale/tests/swscale.c
+++ b/libswscale/tests/swscale.c
@@ -63,6 +63,7 @@ struct options {
     int scaler_sub;
     int align_src;
     int align_dst;
+    int reuse_dst;
     int api;
     int pretty;
     int backends;
@@ -263,13 +264,21 @@ static int scale_new(AVFrame *dst, const AVFrame *src,
         return ret;
     }
 
+    if (opts->reuse_dst) {
+        ret = av_frame_get_buffer(dst, opts->align_dst);
+        if (ret < 0)
+            return ret;
+    }
+
     int64_t time = av_gettime_relative();
     for (int i = 0; ret >= 0 && i < opts->iters; i++) {
-        unref_buffers(dst);
-        if (opts->align_dst) {
-            ret = av_frame_get_buffer(dst, opts->align_dst);
-            if (ret < 0)
-                return ret;
+        if (!opts->reuse_dst) {
+            unref_buffers(dst);
+            if (opts->align_dst) {
+                ret = av_frame_get_buffer(dst, opts->align_dst);
+                if (ret < 0)
+                    return ret;
+            }
         }
 
         ret = checked_sws_scale_frame(sws_src_dst, dst, src);
@@ -970,6 +979,9 @@ static int parse_options(int argc, char **argv, struct 
options *opts, FILE **fp)
                     "       If nonzero, allocate source buffers with a custom 
stride alignment\n"
                     "   -align_dst <alignment>\n"
                     "       If nonzero, allocate destination buffers with a 
custom stride alignment\n"
+                    "   -reuse_dst <1 or 0>\n"
+                    "       Preallocate and reuse destination buffers with the 
new CPU API (default: 0)\n"
+                    "       Allocation is excluded from benchmark timing, as 
with the legacy API\n"
                     "   -api <new or legacy>\n"
                     "       Use selected swscale API for the main conversion 
(default: new)\n"
                     "   -hw <device>\n"
@@ -1072,6 +1084,10 @@ static int parse_options(int argc, char **argv, struct 
options *opts, FILE **fp)
                 fprintf(stderr, "invalid alignment %s\n", argv[i + 1]);
                 return -1;
             }
+        } else if (!strcmp(argv[i], "-reuse_dst")) {
+            if (strcmp(argv[i + 1], "0") && strcmp(argv[i + 1], "1"))
+                goto bad_option;
+            opts->reuse_dst = atoi(argv[i + 1]);
         } else if (!strcmp(argv[i], "-api")) {
             ret = parse_implementation(argv[i + 1]);
             if (ret < 0) {
-- 
2.54.0


>From 23196bfd7606a444a61a7197ad89206df9158e36 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Fri, 23 Oct 2026 18:53:14 +0000
Subject: [PATCH 2/2] tests/fate/swscale: cover reused CPU destinations

Run the unscaled conversion matrix with caller-allocated destinations for each 
CPU ops backend. Convert twice to exercise buffer reuse.

Assisted-by: Fairy
---
 tests/fate/libswscale.mak | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/fate/libswscale.mak b/tests/fate/libswscale.mak
index 2542869f57c..6bff29babd0 100644
--- a/tests/fate/libswscale.mak
+++ b/tests/fate/libswscale.mak
@@ -68,7 +68,13 @@ FATE_SWS_UNSCALED := 
$(SWS_UNSTABLE_BACKENDS-yes:%=fate-sws-unscaled-%)
 $(FATE_SWS_UNSCALED): libswscale/tests/swscale$(EXESUF)
 $(FATE_SWS_UNSCALED): CMD = run libswscale/tests/swscale$(EXESUF) -v 16 
$(SWS_HW) -scaler none -backends $(@:fate-sws-unscaled-%=%)
 $(FATE_SWS_UNSCALED): REF = /dev/null
-fate-sws-unscaled: $(FATE_SWS_UNSCALED)
+# Exercise caller-allocated destinations as well as buffer-sharing output.
+FATE_SWS_UNSCALED_REUSE := $(filter-out spirv,$(SWS_UNSTABLE_BACKENDS-yes))
+FATE_SWS_UNSCALED_REUSE := 
$(FATE_SWS_UNSCALED_REUSE:%=fate-sws-unscaled-reuse-%)
+$(FATE_SWS_UNSCALED_REUSE): libswscale/tests/swscale$(EXESUF)
+$(FATE_SWS_UNSCALED_REUSE): CMD = run libswscale/tests/swscale$(EXESUF) -v 16 
-scaler none -backends $(@:fate-sws-unscaled-reuse-%=%) -reuse_dst 1 -bench 2 
-s 96x96
+$(FATE_SWS_UNSCALED_REUSE): REF = /dev/null
+fate-sws-unscaled: $(FATE_SWS_UNSCALED) $(FATE_SWS_UNSCALED_REUSE)
 
 # Run only 2% of swscale tests to keep the run time short, and only check for 
failure
 FATE_SWS_UNSTABLE := $(SWS_UNSTABLE_BACKENDS-yes:%=fate-sws-unstable-%)
@@ -77,7 +83,7 @@ $(FATE_SWS_UNSTABLE): CMD = run 
libswscale/tests/swscale$(EXESUF) -v 16 $(SWS_HW
 $(FATE_SWS_UNSTABLE): REF = /dev/null
 fate-sws-unstable: $(FATE_SWS_UNSTABLE)
 
-FATE_LIBSWSCALE += $(FATE_SWS_UNSCALED) $(FATE_SWS_UNSTABLE)
+FATE_LIBSWSCALE += $(FATE_SWS_UNSCALED) $(FATE_SWS_UNSCALED_REUSE) 
$(FATE_SWS_UNSTABLE)
 endif
 
 ifneq ($(HAVE_BIGENDIAN),yes)
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to