[vlc-devel] [PATCH v3 03/16] vulkan: switch to module for surface implementations

Alexandre Janniaux ajanni at videolabs.io
Wed Apr 21 08:04:37 UTC 2021


Instead of recompiling surface.c while implementing its public functions
and so as to implement the wayland surface provider side by side with
the XCB surface provider.
---
 modules/video_output/vulkan/instance.c | 29 ++++++++++++++++++++++++--
 modules/video_output/vulkan/instance.h | 10 +++++++++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/modules/video_output/vulkan/instance.c b/modules/video_output/vulkan/instance.c
index 1c2361b2ed..791393875f 100644
--- a/modules/video_output/vulkan/instance.c
+++ b/modules/video_output/vulkan/instance.c
@@ -31,6 +31,17 @@
 
 #include "instance.h"
 
+static int vlc_vk_start(void *func, bool forced, va_list ap)
+{
+    int (*activate)(vlc_vk_t *vk) = func;
+    vlc_vk_t *vk = va_arg(ap, vlc_vk_t *);
+
+    int ret = activate(vk);
+    /* TODO: vlc_objres_clear, which is not in the public API. */
+    (void)forced;
+    return ret;
+}
+
 /**
  * Creates a Vulkan surface (and its underlying instance).
  *
@@ -51,9 +62,16 @@ vlc_vk_t *vlc_vk_Create(struct vout_window_t *wnd, const char *name)
     vk->instance = NULL;
     vk->surface = (VkSurfaceKHR) NULL;
     vk->platform_ext = NULL;
+    vk->ops = NULL;
 
     vk->window = wnd;
-    vk->module = module_need(vk, "vulkan", name, true);
+
+    vk->module = vlc_module_load(wnd, "vulkan platform", name, false,
+                                 vlc_vk_start, vk);
+
+    if (vk->module == NULL)
+        vk->module = module_need(vk, "vulkan", name, true);
+
     if (vk->module == NULL)
     {
         vlc_object_delete(vk);
@@ -73,6 +91,13 @@ void vlc_vk_Release(vlc_vk_t *vk)
 {
     if (!vlc_atomic_rc_dec(&vk->ref_count))
         return;
-    module_unneed(vk, vk->module);
+
+    if (vk->ops)
+        vk->ops->close(vk);
+
+    if (module_provides(vk->module, "vulkan"))
+        module_unneed(vk, vk->module);
+
+    /* TODO: use vlc_objres_clear */
     vlc_object_delete(vk);
 }
diff --git a/modules/video_output/vulkan/instance.h b/modules/video_output/vulkan/instance.h
index f9d38bc9c6..2aaabff823 100644
--- a/modules/video_output/vulkan/instance.h
+++ b/modules/video_output/vulkan/instance.h
@@ -31,6 +31,14 @@
 struct vout_window_t;
 struct vout_window_cfg_t;
 
+struct vlc_vk_t;
+struct vlc_vk_operations
+{
+    void (*close)(struct vlc_vk_t *);
+    int (*create_surface)(struct vlc_vk_t *, VkInstance);
+};
+
+
 // Shared struct for vulkan instance / surface / device state
 typedef struct vlc_vk_t
 {
@@ -48,6 +56,8 @@ typedef struct vlc_vk_t
     const struct pl_swapchain *swapchain;
     VkSurfaceKHR surface;
     struct vout_window_t *window;
+
+    const struct vlc_vk_operations *ops;
 } vlc_vk_t;
 
 vlc_vk_t *vlc_vk_Create(struct vout_window_t *, const char *) VLC_USED;
-- 
2.31.1



More information about the vlc-devel mailing list