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

Plus two more minor adjacent cosmetic fixes.


>From 5b39be1f0aa803634f649de3c2bfa2b25aaf4323 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Wed, 4 Mar 2026 11:51:27 +0100
Subject: [PATCH 1/3] swscale: fix build on --disable-unstable

By excluding the Vulkan makefile entirely when --disable-unstable is passed.
This also correctly avoids compiling e.g. unused GLSL compilers.

Fixes: #22295
See-Also: #22366

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/Makefile  | 2 ++
 libswscale/swscale.c | 2 +-
 libswscale/utils.c   | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libswscale/Makefile b/libswscale/Makefile
index 4331768cfa..c8119e4f43 100644
--- a/libswscale/Makefile
+++ b/libswscale/Makefile
@@ -33,7 +33,9 @@ OBJS-$(CONFIG_UNSTABLE) +=                              \
        ops_memcpy.o                                     \
        ops_optimizer.o                                  \
 
+ifeq ($(CONFIG_UNSTABLE),yes)
 include $(SRC_PATH)/libswscale/vulkan/Makefile
+endif
 
 # Objects duplicated from other libraries for shared builds
 SHLIBOBJS                    += log2_tab.o half2float.o
diff --git a/libswscale/swscale.c b/libswscale/swscale.c
index b04df78a5d..94d9102f97 100644
--- a/libswscale/swscale.c
+++ b/libswscale/swscale.c
@@ -1442,7 +1442,7 @@ int sws_frame_setup(SwsContext *ctx, const AVFrame *dst, 
const AVFrame *src)
         if (dev_ctx->type != AV_HWDEVICE_TYPE_VULKAN)
             return AVERROR(ENOTSUP);
 
-#if CONFIG_VULKAN
+#if CONFIG_UNSTABLE && CONFIG_VULKAN
         ret = ff_sws_vk_init(ctx, src_hwfc->device_ref);
         if (ret < 0)
             return ret;
diff --git a/libswscale/utils.c b/libswscale/utils.c
index f693f9c2db..4f50586e90 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -2248,7 +2248,7 @@ void sws_freeContext(SwsContext *sws)
     if (!c)
         return;
 
-#if CONFIG_VULKAN
+#if CONFIG_UNSTABLE && CONFIG_VULKAN
     ff_sws_vk_uninit(sws);
 #endif
 
-- 
2.52.0


>From 9ca9d45d79f8c55848495e7de007ff200d993547 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Wed, 4 Mar 2026 11:58:35 +0100
Subject: [PATCH 2/3] swscale: switch to refstruct for hw_priv

This is a bit more forward-facing than a bare allocation, and importantly,
allows the `swscale/utils.c` code to remain agnostic about how to correctly
uninit this struct.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/swscale_internal.h |  2 +-
 libswscale/utils.c            |  5 ++---
 libswscale/vulkan/ops.c       | 13 ++++++-------
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h
index d4102d7858..d9fb6d9297 100644
--- a/libswscale/swscale_internal.h
+++ b/libswscale/swscale_internal.h
@@ -696,7 +696,7 @@ struct SwsInternal {
     Half2FloatTables *h2f_tables;
 
     // Hardware specific private data
-    void *hw_priv;
+    void *hw_priv; /* refstruct */
 };
 //FIXME check init (where 0)
 
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 4f50586e90..8a3462c4a3 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -50,6 +50,7 @@
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/refstruct.h"
 #include "libavutil/slicethread.h"
 #include "libavutil/thread.h"
 #include "libavutil/aarch64/cpu.h"
@@ -2248,9 +2249,7 @@ void sws_freeContext(SwsContext *sws)
     if (!c)
         return;
 
-#if CONFIG_UNSTABLE && CONFIG_VULKAN
-    ff_sws_vk_uninit(sws);
-#endif
+    av_refstruct_unref(&c->hw_priv);
 
     for (i = 0; i < FF_ARRAY_ELEMS(c->graph); i++)
         ff_sws_graph_free(&c->graph[i]);
diff --git a/libswscale/vulkan/ops.c b/libswscale/vulkan/ops.c
index 64c9e3d45b..e6c6a5f3c0 100644
--- a/libswscale/vulkan/ops.c
+++ b/libswscale/vulkan/ops.c
@@ -21,14 +21,13 @@
 #include "../ops_internal.h"
 #include "../swscale_internal.h"
 #include "libavutil/mem.h"
+#include "libavutil/refstruct.h"
 #include "ops.h"
 
-void ff_sws_vk_uninit(SwsContext *sws)
+static void ff_sws_vk_uninit(AVRefStructOpaque opaque, void *obj)
 {
-    SwsInternal *c = sws_internal(sws);
-    FFVulkanOpsCtx *s = c->hw_priv;
-    if (!s)
-        return;
+    SwsInternal *c = sws_internal(opaque.nc);
+    FFVulkanOpsCtx *s = obj;
 
 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
     if (s->spvc)
@@ -36,7 +35,6 @@ void ff_sws_vk_uninit(SwsContext *sws)
 #endif
     ff_vk_exec_pool_free(&s->vkctx, &s->e);
     ff_vk_uninit(&s->vkctx);
-    av_freep(&c->hw_priv);
 }
 
 int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
@@ -45,7 +43,8 @@ int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
     SwsInternal *c = sws_internal(sws);
 
     if (!c->hw_priv) {
-        c->hw_priv = av_mallocz(sizeof(FFVulkanOpsCtx));
+        c->hw_priv = av_refstruct_alloc_ext(sizeof(FFVulkanOpsCtx), 0, sws,
+                                            ff_sws_vk_uninit);
         if (!c->hw_priv)
             return AVERROR(ENOMEM);
     }
-- 
2.52.0


>From df8dc6a16b519256d8f502bb18615a894cd74db5 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Wed, 4 Mar 2026 12:00:04 +0100
Subject: [PATCH 3/3] swscale/vulkan: fix include order (cosmetic)

Non-local includes before local includes.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/vulkan/ops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libswscale/vulkan/ops.c b/libswscale/vulkan/ops.c
index e6c6a5f3c0..233a39c981 100644
--- a/libswscale/vulkan/ops.c
+++ b/libswscale/vulkan/ops.c
@@ -18,10 +18,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "../ops_internal.h"
-#include "../swscale_internal.h"
 #include "libavutil/mem.h"
 #include "libavutil/refstruct.h"
+
+#include "../ops_internal.h"
+#include "../swscale_internal.h"
+
 #include "ops.h"
 
 static void ff_sws_vk_uninit(AVRefStructOpaque opaque, void *obj)
-- 
2.52.0

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

Reply via email to