[FFmpeg-cvslog] lavfi/vf_libplacebo: move vulkan initialization to init

Anton Khirnov git at videolan.org
Tue Oct 15 11:44:38 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Oct  7 16:17:17 2024 +0200| [8160178dfc0e6bdaacf80dec58e595a9d595eedc] | committer: Anton Khirnov

lavfi/vf_libplacebo: move vulkan initialization to init

avfilter API requires all the filter parameters, including hw context
(if present) to be available during init, so that is the proper place to
perform such setup.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8160178dfc0e6bdaacf80dec58e595a9d595eedc
---

 libavfilter/vf_libplacebo.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c
index 2176a7188c..5bf8b7e77a 100644
--- a/libavfilter/vf_libplacebo.c
+++ b/libavfilter/vf_libplacebo.c
@@ -194,6 +194,8 @@ typedef struct LibplaceboContext {
     int color_trc;
     AVDictionary *extra_opts;
 
+    int have_hwdevice;
+
     /* pl_render_params */
     pl_options opts;
     char *upscaler;
@@ -493,11 +495,13 @@ static int parse_shader(AVFilterContext *avctx, const void *shader, size_t len)
 
 static void libplacebo_uninit(AVFilterContext *avctx);
 static int libplacebo_config_input(AVFilterLink *inlink);
+static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwctx);
 
 static int libplacebo_init(AVFilterContext *avctx)
 {
     int err = 0;
     LibplaceboContext *s = avctx->priv;
+    const AVVulkanDeviceContext *vkhwctx = NULL;
 
     /* Create libplacebo log context */
     s->log = pl_log_create(PL_API_VER, pl_log_params(
@@ -559,7 +563,14 @@ static int libplacebo_init(AVFilterContext *avctx)
     if (strcmp(s->fps_string, "none") != 0)
         RET(av_parse_video_rate(&s->fps, s->fps_string));
 
-    /* Note: s->vulkan etc. are initialized later, when hwctx is available */
+    if (avctx->hw_device_ctx) {
+        const AVHWDeviceContext *avhwctx = (void *) avctx->hw_device_ctx->data;
+        if (avhwctx->type == AV_HWDEVICE_TYPE_VULKAN)
+            vkhwctx = avhwctx->hwctx;
+    }
+
+    RET(init_vulkan(avctx, vkhwctx));
+
     return 0;
 
 fail:
@@ -648,6 +659,8 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct
         err = AVERROR_EXTERNAL;
         goto fail;
 #endif
+
+        s->have_hwdevice = 1;
     } else {
         s->vulkan = pl_vulkan_create(s->log, pl_vulkan_params(
             .queue_count = 0, /* enable all queues for parallelization */
@@ -1081,18 +1094,9 @@ static int libplacebo_query_format(AVFilterContext *ctx)
 {
     int err;
     LibplaceboContext *s = ctx->priv;
-    const AVVulkanDeviceContext *vkhwctx = NULL;
     const AVPixFmtDescriptor *desc = NULL;
     AVFilterFormats *infmts = NULL, *outfmts = NULL;
 
-    if (ctx->hw_device_ctx) {
-        const AVHWDeviceContext *avhwctx = (void *) ctx->hw_device_ctx->data;
-        if (avhwctx->type == AV_HWDEVICE_TYPE_VULKAN)
-            vkhwctx = avhwctx->hwctx;
-    }
-
-    RET(init_vulkan(ctx, vkhwctx));
-
     while ((desc = av_pix_fmt_desc_next(desc))) {
         enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc);
 
@@ -1103,10 +1107,8 @@ static int libplacebo_query_format(AVFilterContext *ctx)
             continue;
 #endif
 
-        if (pixfmt == AV_PIX_FMT_VULKAN) {
-            if (!vkhwctx || vkhwctx->act_dev != s->vulkan->device)
-                continue;
-        }
+        if (pixfmt == AV_PIX_FMT_VULKAN && !s->have_hwdevice)
+            continue;
 
         if (!pl_test_pixfmt(s->gpu, pixfmt))
             continue;



More information about the ffmpeg-cvslog mailing list