PR #25582 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25582
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25582.patch

This removes the speed penalty from the extra aux conversions in !25567


>From 47ac7aed7b4fb629122701acafa211faf647009b Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Thu, 29 Oct 2026 13:38:06 +0100
Subject: [PATCH 1/4] swscale/ops: skip printing op lists below the log level

ff_sws_op_list_print() formatted every op even when av_log() then
discarded the result. Op lists are printed during every graph setup, so
at the default log level this took about a quarter of the swscale
self-test runtime.

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libswscale/ops.c b/libswscale/ops.c
index 2660d66d063..30597c375dd 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -1042,6 +1042,9 @@ void ff_sws_op_list_print(void *log, int lev, int 
lev_extra,
                           const SwsOpList *ops)
 {
     AVBPrint bpc, *bp = &bpc;
+    if (av_log_get_level() < lev)
+        return;
+
     if (!ops->num_ops) {
         av_log(log, lev, "  (empty)\n");
         return;
-- 
2.54.0


>From 91ba96c91a4eac98c865c946f93dc99086dc1086 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Thu, 29 Oct 2026 13:42:45 +0100
Subject: [PATCH 2/4] swscale/ops: clamp lev_extra >= lev

This doesn't make sense to pass otherwise, but the clamp is cheap.

Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libswscale/ops.c b/libswscale/ops.c
index 30597c375dd..07dd1aba482 100644
--- a/libswscale/ops.c
+++ b/libswscale/ops.c
@@ -1051,6 +1051,7 @@ void ff_sws_op_list_print(void *log, int lev, int 
lev_extra,
     }
 
     av_bprint_init(bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
+    lev_extra = FFMAX(lev_extra, lev);
 
     for (int n = 0; n < ops->num_ops; n++) {
         const SwsOp *op = &ops->ops[n];
-- 
2.54.0


>From cce3be47104f6e232719a209ef7c9b42926f24fe Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Thu, 29 Oct 2026 13:48:36 +0100
Subject: [PATCH 3/4] swscale/uops: factor out ff_sws_uop_list_print()

The same loop was duplicated in three backends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/uops.c         | 10 ++++++++++
 libswscale/uops.h         |  5 +++++
 libswscale/uops_backend.c |  7 +------
 libswscale/vulkan/ops.c   |  7 +------
 libswscale/x86/ops.c      |  7 +------
 5 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/libswscale/uops.c b/libswscale/uops.c
index 906cb0c7be6..1d06a70e5f5 100644
--- a/libswscale/uops.c
+++ b/libswscale/uops.c
@@ -198,6 +198,16 @@ void ff_sws_uop_list_remove_at(SwsUOpList *uops, int 
index, int count)
     uops->num_ops = end;
 }
 
+void ff_sws_uop_list_print(void *log, int lev, const SwsUOpList *uops)
+{
+    av_log(log, lev, "Compiled micro-ops:\n");
+    for (int i = 0; i < uops->num_ops; i++) {
+        char name[SWS_UOP_NAME_MAX];
+        ff_sws_uop_name(&uops->ops[i], name);
+        av_log(log, lev, "    %s\n", name);
+    }
+}
+
 int ff_sws_dither_height(const SwsDitherUOp *dither)
 {
     int max_offset = 0;
diff --git a/libswscale/uops.h b/libswscale/uops.h
index a70a6ac4600..506b3ff6222 100644
--- a/libswscale/uops.h
+++ b/libswscale/uops.h
@@ -348,6 +348,11 @@ int ff_sws_uop_list_append(SwsUOpList *uops, SwsUOp *uop);
  */
 int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags flags, SwsUOpList 
*uops);
 
+/**
+ * Print the micro-ops of a compiled list at the given log level.
+ */
+void ff_sws_uop_list_print(void *log_ctx, int log_level, const SwsUOpList 
*uops);
+
 /**
  * Translate a list of operations down to micro-ops, which can be further
  * optimized and then directly executed by backends.
diff --git a/libswscale/uops_backend.c b/libswscale/uops_backend.c
index f206d454432..1fd07fdeeec 100644
--- a/libswscale/uops_backend.c
+++ b/libswscale/uops_backend.c
@@ -165,12 +165,7 @@ static int compile_uops_c(SwsContext *ctx, const 
SwsUOpList *uops, SwsCompiledOp
     memcpy(out->over_read,  chain->over_read,  sizeof(out->over_read));
     memcpy(out->over_write, chain->over_write, sizeof(out->over_write));
 
-    av_log(ctx, AV_LOG_DEBUG, "Compiled micro-ops:\n");
-    for (int i = 0; i < uops->num_ops; i++) {
-        char name[SWS_UOP_NAME_MAX];
-        ff_sws_uop_name(&uops->ops[i], name);
-        av_log(ctx, AV_LOG_DEBUG, "    %s\n", name);
-    }
+    ff_sws_uop_list_print(ctx, AV_LOG_DEBUG, uops);
 
     return 0;
 
diff --git a/libswscale/vulkan/ops.c b/libswscale/vulkan/ops.c
index 915696a012d..f18be1efe20 100644
--- a/libswscale/vulkan/ops.c
+++ b/libswscale/vulkan/ops.c
@@ -1317,12 +1317,7 @@ static int compile_ops_spirv(SwsContext *sws, const 
SwsOpList *ops,
         .free        = spirv_free,
     };
 
-    av_log(sws, AV_LOG_DEBUG, "Compiled micro-ops:\n");
-    for (int i = 0; i < uops->num_ops; i++) {
-        char name[SWS_UOP_NAME_MAX];
-        ff_sws_uop_name(&uops->ops[i], name);
-        av_log(sws, AV_LOG_DEBUG, "    %s\n", name);
-    }
+    ff_sws_uop_list_print(sws, AV_LOG_DEBUG, uops);
 
     ff_sws_uop_list_free(&uops);
     return 0;
diff --git a/libswscale/x86/ops.c b/libswscale/x86/ops.c
index fa754910367..9cc5ba7a0aa 100644
--- a/libswscale/x86/ops.c
+++ b/libswscale/x86/ops.c
@@ -702,12 +702,7 @@ static int compile_uops_x86(SwsContext *ctx, const 
SwsUOpList *uops, SwsCompiled
     memcpy(out->over_read,  chain->over_read,  sizeof(out->over_read));
     memcpy(out->over_write, chain->over_write, sizeof(out->over_write));
 
-    av_log(ctx, AV_LOG_DEBUG, "Compiled micro-ops:\n");
-    for (int i = 0; i < uops->num_ops; i++) {
-        char name[SWS_UOP_NAME_MAX];
-        ff_sws_uop_name(&uops->ops[i], name);
-        av_log(ctx, AV_LOG_DEBUG, "    %s\n", name);
-    }
+    ff_sws_uop_list_print(ctx, AV_LOG_DEBUG, uops);
 
     return 0;
 
-- 
2.54.0


>From 4944daba7c1b962dbf10f8178b95c36a6341424b Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Thu, 29 Oct 2026 13:48:36 +0100
Subject: [PATCH 4/4] swscale/uops: skip printing uop lists below the log level

As for op lists, avoid formatting the names of all uops when av_log()
discards them anyway.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/uops.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libswscale/uops.c b/libswscale/uops.c
index 1d06a70e5f5..a7150c11307 100644
--- a/libswscale/uops.c
+++ b/libswscale/uops.c
@@ -200,6 +200,9 @@ void ff_sws_uop_list_remove_at(SwsUOpList *uops, int index, 
int count)
 
 void ff_sws_uop_list_print(void *log, int lev, const SwsUOpList *uops)
 {
+    if (av_log_get_level() < lev)
+        return;
+
     av_log(log, lev, "Compiled micro-ops:\n");
     for (int i = 0; i < uops->num_ops; i++) {
         char name[SWS_UOP_NAME_MAX];
-- 
2.54.0

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

Reply via email to