diff mbox series

[FFmpeg-devel] V2: avutil/hwcontext_vulkan: disable multiplane when deriving from cuda

Message ID 20230603004328.139825-1-philipl@overt.org
State Accepted
Commit 378fb4028294bcf27df09d145a1f6ab1d014924e
Headers show
Series [FFmpeg-devel] V2: avutil/hwcontext_vulkan: disable multiplane when deriving from cuda | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Philip Langdale June 3, 2023, 12:43 a.m. UTC
Today, cuda is not able to import multiplane images, and cuda requires
images to be imported whether you trying to import to cuda or export
from cuda (in the later case, the image is imported and then copied
into on the cuda side). So any interop between cuda and vulkan requires
that multiplane be disabled.

The existing option for this is not sufficient, because when deriving
devices it is not possible to specify any options.

And, it is necessary to derive the Vulkan device, because any pipeline
that involves uploading from cuda to vulkan and then back to cuda must
use the same cuda context on both sides, and the only way to propagate
the cuda context all the way through is to derive the device at each
stage.

ie:

-vf hwupload=derive_device=vulkan,<filters>,hwupload=derive_device=cuda

Signed-off-by: Philip Langdale <philipl@overt.org>
---
 libavutil/hwcontext_vulkan.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

Comments

Lynne June 3, 2023, 9:31 p.m. UTC | #1
Jun 3, 2023, 02:43 by philipl@overt.org:

> Today, cuda is not able to import multiplane images, and cuda requires
> images to be imported whether you trying to import to cuda or export
> from cuda (in the later case, the image is imported and then copied
> into on the cuda side). So any interop between cuda and vulkan requires
> that multiplane be disabled.
>
> The existing option for this is not sufficient, because when deriving
> devices it is not possible to specify any options.
>
> And, it is necessary to derive the Vulkan device, because any pipeline
> that involves uploading from cuda to vulkan and then back to cuda must
> use the same cuda context on both sides, and the only way to propagate
> the cuda context all the way through is to derive the device at each
> stage.
>

LGTM
diff mbox series

Patch

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index e8241638d9..ec084d94d7 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1180,6 +1180,7 @@  static void vulkan_device_free(AVHWDeviceContext *ctx)
 
 static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
                                          VulkanDeviceSelection *dev_select,
+                                         int disable_multiplane,
                                          AVDictionary *opts, int flags)
 {
     int err = 0;
@@ -1335,9 +1336,15 @@  static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
     if (opt_d)
         p->use_linear_images = strtol(opt_d->value, NULL, 10);
 
-    opt_d = av_dict_get(opts, "disable_multiplane", NULL, 0);
-    if (opt_d)
-        p->disable_multiplane = strtol(opt_d->value, NULL, 10);
+    /*
+     * The disable_multiplane argument takes precedent over the option.
+     */
+    p->disable_multiplane = disable_multiplane;
+    if (!p->disable_multiplane) {
+        opt_d = av_dict_get(opts, "disable_multiplane", NULL, 0);
+        if (opt_d)
+            p->disable_multiplane = strtol(opt_d->value, NULL, 10);
+    }
 
     hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
     hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
@@ -1511,7 +1518,7 @@  static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device,
         }
     }
 
-    return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
+    return vulkan_device_create_internal(ctx, &dev_select, 0, opts, flags);
 }
 
 static int vulkan_device_derive(AVHWDeviceContext *ctx,
@@ -1537,7 +1544,7 @@  static int vulkan_device_derive(AVHWDeviceContext *ctx,
         if (strstr(vendor, "AMD"))
             dev_select.vendor_id = 0x1002;
 
-        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
+        return vulkan_device_create_internal(ctx, &dev_select, 0, opts, flags);
     }
 #endif
 #if CONFIG_LIBDRM
@@ -1570,7 +1577,7 @@  static int vulkan_device_derive(AVHWDeviceContext *ctx,
 
         drmFreeDevice(&drm_dev_info);
 
-        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
+        return vulkan_device_create_internal(ctx, &dev_select, 0, opts, flags);
     }
 #endif
 #if CONFIG_CUDA
@@ -1589,7 +1596,11 @@  static int vulkan_device_derive(AVHWDeviceContext *ctx,
 
         dev_select.has_uuid = 1;
 
-        return vulkan_device_create_internal(ctx, &dev_select, opts, flags);
+        /*
+         * CUDA is not able to import multiplane images, so always derive a
+         * Vulkan device with multiplane disabled.
+         */
+        return vulkan_device_create_internal(ctx, &dev_select, 1, opts, flags);
     }
 #endif
     default: