[vlc-commits] [Git][videolan/vlc][master] 16 commits: contrib: libplacebo: check version number

Jean-Baptiste Kempf gitlab at videolan.org
Sun May 2 15:01:41 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
11a409d3 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
contrib: libplacebo: check version number

libplacebo 1.18 is required for pl_swapchain_resize.

- - - - -
ac1790f8 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: move platform ext string to vlc_vk_t

The platform string will be used by vulkan implementation not following
the surface.c implementation so as to remove it later.

- - - - -
02fb339c by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: switch to module for surface implementations

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.

- - - - -
68569158 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: platform: forward VkInstance to CreateSurface

- - - - -
883a865a by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: move placebo usage to display.c

The vulkan providers are not supposed to depend upon libplacebo, and
only the display is supposed to bring the libplacebo dependency. In
addition, many of the libplacebo options are designed for the display.

- - - - -
4cef477b by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: platform_xcb: rework as vulkan platform

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.

- - - - -
a64a2cba by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: platform_win32: rework as vulkan platform

Instead of recompiling surface.c while implementing its public
functions, and so as to remove surface.c.

- - - - -
f0ad77c8 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: platform_android: rework as vulkan platform

Instead of recompiling surface.c while implementing its public
functions, and so as to remove surface.c.

- - - - -
b77da02b by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: force swapchain resize on display size change

On Windows the swapchain might not be re-created automatically, which
results in glitches when using the vk output. This enforces the creation
of the swapchain as soon as the display size is changed.

On Wayland, the size of the window is the size of the content so there
is no automatic swapchain sizing and this call is mandatory.

Co-authored-by: Niklas Haas <git at haasn.xyz>

- - - - -
f62a5287 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: surface: remove now useless file

- - - - -
5dcc6ff8 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: remove previous vulkan capability

The platform support has been offloaded to the `vulkan platform`
capability, keep the `vulkan` capability to provide multiple Vulkan
implementation through the VkInstance and initial functions pointers.

- - - - -
caab121a by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: display: remove default vulkan name

- - - - -
79fb158a by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: remove surface from vlc_vk_t

- - - - -
e7d0b88e by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: move platform header to instance.h

The header is mostly unused now.

- - - - -
a1814bdd by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
wayland: add vulkan wayland platform support

Add a `vulkan platform` implementation for wayland, effectively enabling
the usage of the vulkan libplacebo display on Wayland environments.

- - - - -
183c8d99 by Alexandre Janniaux at 2021-05-02T12:43:15+00:00
vulkan: display: use vd->fmt instead of source

vd->source doesn't contain the new chroma that has been chosen by the
chroma fallback mechanism, so when using VAAPI chroma, it was leading
to the display module trying to use a VAAPI libplacebo format description
although it doesn't have one, and thus leading to NULL dereferencement.

- - - - -


12 changed files:

- contrib/src/libplacebo/rules.mak
- modules/video_output/vulkan/Makefile.am
- modules/video_output/vulkan/display.c
- modules/video_output/vulkan/instance.c
- modules/video_output/vulkan/instance.h
- modules/video_output/vulkan/platform_android.c
- modules/video_output/vulkan/platform_win32.c
- modules/video_output/vulkan/platform_xcb.c
- − modules/video_output/vulkan/surface.c
- modules/video_output/wayland/Makefile.am
- modules/video_output/vulkan/platform.h → modules/video_output/wayland/vulkan.c
- modules/video_output/xcb/Makefile.am


Changes:

=====================================
contrib/src/libplacebo/rules.mak
=====================================
@@ -9,7 +9,7 @@ DEPS_libplacebo = glslang
 ifndef HAVE_WINSTORE
 PKGS += libplacebo
 endif
-ifeq ($(call need_pkg,"libplacebo"),)
+ifeq ($(call need_pkg,"libplacebo >= 1.18"),)
 PKGS_FOUND += libplacebo
 endif
 


=====================================
modules/video_output/vulkan/Makefile.am
=====================================
@@ -17,13 +17,13 @@ libvk_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/display.c
 libvk_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS)
 libvk_plugin_la_LIBADD = $(VULKAN_COMMONLIBS)
 
-libvk_win32_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/surface.c \
+libvk_win32_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) \
 				video_output/vulkan/platform_win32.c
 libvk_win32_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
 			       -DVK_USE_PLATFORM_WIN32_KHR -DPLATFORM_NAME=Win32
 libvk_win32_plugin_la_LIBADD = $(VULKAN_COMMONLIBS)
 
-libvk_android_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) video_output/vulkan/surface.c \
+libvk_android_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) \
 				video_output/vulkan/platform_android.c
 libvk_android_plugin_la_CFLAGS = $(AM_CFLAGS) $(VULKAN_COMMONCFLAGS) \
 			       -DVK_USE_PLATFORM_ANDROID_KHR -DPLATFORM_NAME=Android


=====================================
modules/video_output/vulkan/display.c
=====================================
@@ -43,8 +43,14 @@ struct vout_display_sys_t
 {
     vlc_vk_t *vk;
     const struct pl_tex *plane_tex[4];
+    struct pl_context *ctx;
+    const struct pl_vk_inst *instance;
+    const struct pl_vulkan *vulkan;
+    const struct pl_swapchain *swapchain;
     struct pl_renderer *renderer;
 
+    VkSurfaceKHR surface;
+
     // Pool of textures for the subpictures
     struct pl_overlay *overlays;
     const struct pl_tex **overlay_tex;
@@ -101,17 +107,62 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     if (sys->vk == NULL)
         goto error;
 
-    const struct pl_gpu *gpu = sys->vk->vulkan->gpu;
-    sys->renderer = pl_renderer_create(sys->vk->ctx, gpu);
+    sys->ctx = vlc_placebo_Create(VLC_OBJECT(sys->vk));
+    if (!sys->ctx)
+        goto error;
+
+    sys->instance = pl_vk_inst_create(sys->ctx, &(struct pl_vk_inst_params) {
+        .debug = var_InheritBool(sys->vk, "vk-debug"),
+        .extensions = (const char *[]) {
+            VK_KHR_SURFACE_EXTENSION_NAME,
+            sys->vk->platform_ext,
+        },
+        .num_extensions = 2,
+    });
+    if (!sys->instance)
+        goto error;
+
+    // Create the platform-specific surface object
+    if (vlc_vk_CreateSurface(sys->vk, sys->instance->instance, &sys->surface) != VLC_SUCCESS)
+        goto error;
+
+    // Create vulkan device
+    char *device_name = var_InheritString(sys->vk, "vk-device");
+    sys->vulkan = pl_vulkan_create(sys->ctx, &(struct pl_vulkan_params) {
+        .instance = sys->instance->instance,
+        .surface = sys->surface,
+        .device_name = device_name,
+        .allow_software = var_InheritBool(vd, "allow-sw"),
+        .async_transfer = var_InheritBool(vd, "async-xfer"),
+        .async_compute = var_InheritBool(vd, "async-comp"),
+        .queue_count = var_InheritInteger(vd, "queue-count"),
+    });
+    free(device_name);
+    if (!sys->vulkan)
+        goto error;
+
+    // Create swapchain for this surface
+    struct pl_vulkan_swapchain_params swap_params = {
+        .surface = sys->surface,
+        .present_mode = var_InheritInteger(vd, "present-mode"),
+        .swapchain_depth = var_InheritInteger(vd, "queue-depth"),
+    };
+
+    sys->swapchain = pl_vulkan_create_swapchain(sys->vulkan, &swap_params);
+    if (!sys->swapchain)
+        goto error;
+
+    const struct pl_gpu *gpu = sys->vulkan->gpu;
+    sys->renderer = pl_renderer_create(sys->ctx, gpu);
     if (!sys->renderer)
         goto error;
 
     // Attempt using the input format as the display format
-    if (vlc_placebo_FormatSupported(gpu, vd->source->i_chroma)) {
-        fmt->i_chroma = vd->source->i_chroma;
+    if (vlc_placebo_FormatSupported(gpu, vd->fmt->i_chroma)) {
+        fmt->i_chroma = vd->fmt->i_chroma;
     } else {
         const vlc_fourcc_t *fcc;
-        for (fcc = vlc_fourcc_GetFallback(vd->source->i_chroma); *fcc; fcc++) {
+        for (fcc = vlc_fourcc_GetFallback(vd->fmt->i_chroma); *fcc; fcc++) {
             if (vlc_placebo_FormatSupported(gpu, *fcc)) {
                 fmt->i_chroma = *fcc;
                 break;
@@ -151,6 +202,11 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
 
 error:
     pl_renderer_destroy(&sys->renderer);
+    pl_swapchain_destroy(&sys->swapchain);
+    pl_vulkan_destroy(&sys->vulkan);
+    pl_vk_inst_destroy(&sys->instance);
+    pl_context_destroy(&sys->ctx);
+
     if (sys->vk != NULL)
         vlc_vk_Release(sys->vk);
     return VLC_EGENERIC;
@@ -159,7 +215,7 @@ error:
 static void Close(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    const struct pl_gpu *gpu = sys->vk->vulkan->gpu;
+    const struct pl_gpu *gpu = sys->vulkan->gpu;
 
     for (int i = 0; i < 4; i++)
         pl_tex_destroy(gpu, &sys->plane_tex[i]);
@@ -181,11 +237,11 @@ static void PictureRender(vout_display_t *vd, picture_t *pic,
 {
     VLC_UNUSED(date);
     vout_display_sys_t *sys = vd->sys;
-    const struct pl_gpu *gpu = sys->vk->vulkan->gpu;
+    const struct pl_gpu *gpu = sys->vulkan->gpu;
     bool failed = false;
 
     struct pl_swapchain_frame frame;
-    if (!pl_swapchain_start_frame(sys->vk->swapchain, &frame))
+    if (!pl_swapchain_start_frame(sys->swapchain, &frame))
         return; // Probably benign error, ignore it
 
     struct pl_image img = {
@@ -193,8 +249,8 @@ static void PictureRender(vout_display_t *vd, picture_t *pic,
         .num_planes = pic->i_planes,
         .width      = pic->format.i_visible_width,
         .height     = pic->format.i_visible_height,
-        .color      = vlc_placebo_ColorSpace(vd->source),
-        .repr       = vlc_placebo_ColorRepr(vd->source),
+        .color      = vlc_placebo_ColorSpace(vd->fmt),
+        .repr       = vlc_placebo_ColorRepr(vd->fmt),
         .src_rect = {
             .x0 = pic->format.i_x_offset,
             .y0 = pic->format.i_y_offset,
@@ -321,7 +377,7 @@ done:
     if (failed)
         pl_tex_clear(gpu, frame.fbo, (float[4]){ 1.0, 0.0, 0.0, 1.0 });
 
-    if (!pl_swapchain_submit_frame(sys->vk->swapchain)) {
+    if (!pl_swapchain_submit_frame(sys->swapchain)) {
         msg_Err(vd, "Failed rendering frame!");
         return;
     }
@@ -331,7 +387,7 @@ static void PictureDisplay(vout_display_t *vd, picture_t *pic)
 {
     VLC_UNUSED(pic);
     vout_display_sys_t *sys = vd->sys;
-    pl_swapchain_swap_buffers(sys->vk->swapchain);
+    pl_swapchain_swap_buffers(sys->swapchain);
 }
 
 static int Control(vout_display_t *vd, int query)
@@ -345,7 +401,31 @@ static int Control(vout_display_t *vd, int query)
     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
     case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
     case VOUT_DISPLAY_CHANGE_ZOOM: {
-        vout_display_PlacePicture(&sys->place, vd->source, vd->cfg);
+        vout_display_PlacePicture(&sys->place, vd->fmt, vd->cfg);
+
+        /* The following resize should be automatic on most platforms but can
+         * trigger bugs on some platform with some drivers, that have been seen
+         * on Windows in particular. Doing it right now enforces the correct
+         * behavior and prevents these bugs.
+         * In addition, platforms like Wayland need the call as the size of the
+         * window is defined by the size of the content, and not the opposite.
+         * The swapchain creation won't be done twice with this call. */
+#if PL_API_VER >= 18
+        if (query == VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
+        {
+            int width = (int) vd->cfg->display.width;
+            int height = (int) vd->cfg->display.height;
+            pl_swapchain_resize(sys->swapchain, &width, &height);
+
+            /* NOTE: We currently ignore resizing failures that are transient
+             * on X11. Maybe improving resizing might fix that, but we don't
+             * implement reset_pictures anyway.
+            if (width != (int) vd->cfg->display.width
+             || height != (int) vd->cfg->display.height)
+                return VLC_EGENERIC;
+            */
+        }
+#endif
         return VLC_SUCCESS;
     }
 
@@ -365,6 +445,44 @@ static int Control(vout_display_t *vd, int query)
 #define DISABLE_DR_TEXT "Disable direct rendering / zero-copy upload"
 #define DISABLE_DR_LONGTEXT "Direct rendering is a technique where image data is uploaded via a mapped buffer instead of via memcpy. On some platforms this might be very slow (due to poor readback performance from mapped memory), in which cases this flag would help."
 
+#define DEBUG_TEXT "Enable API debugging"
+#define DEBUG_LONGTEXT "This loads the vulkan standard validation layers, which can help catch API usage errors. Comes at a small performance penalty."
+
+#define DEVICE_TEXT "Device name override"
+#define DEVICE_LONGTEXT "If set to something non-empty, only a device with this exact name will be used. To see a list of devices and their names, run vlc -v with this module active."
+
+#define ALLOWSW_TEXT "Allow software devices"
+#define ALLOWSW_LONGTEXT "If enabled, allow the use of software emulation devices, which are not real devices and therefore typically very slow. (This option has no effect if forcing a specific device name)"
+
+#define ASYNC_XFER_TEXT "Allow asynchronous transfer"
+#define ASYNC_XFER_LONGTEXT "Allows the use of an asynchronous transfer queue if the device has one. Typically this maps to a DMA engine, which can perform texture uploads/downloads without blocking the GPU's compute units. Highly recommended for 4K and above."
+
+#define ASYNC_COMP_TEXT "Allow asynchronous compute"
+#define ASYNC_COMP_LONGTEXT "Allows the use of dedicated compute queue families if the device has one. Sometimes these will schedule concurrent compute work better than the main graphics queue. Turn this off if you have any issues."
+
+#define QUEUE_COUNT_TEXT "Queue count"
+#define QUEUE_COUNT_LONGTEXT "How many queues to use on the device. Increasing this might improve rendering throughput for GPUs capable of concurrent scheduling. Increasing this past the driver's limit has no effect."
+
+#define QUEUE_DEPTH_TEXT "Maximum frame latency"
+#define QUEUE_DEPTH_LONGTEXT "Affects how many frames to render/present in advance. Increasing this can improve performance at the cost of latency, by allowing better pipelining between frames. May have no effect, depending on the VLC clock settings."
+
+static const int present_values[] = {
+    VK_PRESENT_MODE_IMMEDIATE_KHR,
+    VK_PRESENT_MODE_MAILBOX_KHR,
+    VK_PRESENT_MODE_FIFO_KHR,
+    VK_PRESENT_MODE_FIFO_RELAXED_KHR,
+};
+
+static const char * const present_text[] = {
+    "Immediate (non-blocking, tearing)",
+    "Mailbox (non-blocking, non-tearing)",
+    "FIFO (blocking, non-tearing)",
+    "Relaxed FIFO (blocking, tearing)",
+};
+
+#define PRESENT_MODE_TEXT "Preferred present mode"
+#define PRESENT_MODE_LONGTEXT "Which present mode to use when creating the swapchain. If the chosen mode is not supported, VLC will fall back to using FIFO."
+
 vlc_module_begin ()
     set_shortname ("Vulkan")
     set_description (N_("Vulkan video output"))
@@ -372,7 +490,7 @@ vlc_module_begin ()
     set_subcategory (SUBCAT_VIDEO_VOUT)
     set_callback_display(Open, 0)
     add_shortcut ("vulkan", "vk")
-    add_module ("vk", "vulkan", NULL, VK_TEXT, PROVIDER_LONGTEXT)
+    add_module ("vk", "", NULL, VK_TEXT, PROVIDER_LONGTEXT)
 
     set_section("Scaling", NULL)
     add_integer("upscaler-preset", SCALE_BUILTIN,
@@ -507,6 +625,24 @@ vlc_module_begin ()
     add_bool("delayed-peak", false, DELAYED_PEAK_TEXT, DELAYED_PEAK_LONGTEXT, false)
 #endif
 
+    set_section("Device selection", NULL)
+    add_bool("vk-debug", false, DEBUG_TEXT, DEBUG_LONGTEXT, false)
+    add_string("vk-device", "", DEVICE_TEXT, DEVICE_LONGTEXT, false)
+    add_bool("allow-sw", pl_vulkan_default_params.allow_software,
+            ALLOWSW_TEXT, ALLOWSW_LONGTEXT, false)
+
+    set_section("Performance tuning", NULL)
+    add_bool("async-xfer", pl_vulkan_default_params.async_transfer,
+            ASYNC_XFER_TEXT, ASYNC_XFER_LONGTEXT, false)
+    add_bool("async-comp", pl_vulkan_default_params.async_compute,
+            ASYNC_COMP_TEXT, ASYNC_COMP_LONGTEXT, false)
+    add_integer_with_range("queue-count", pl_vulkan_default_params.queue_count,
+            1, 8, QUEUE_COUNT_TEXT, QUEUE_COUNT_LONGTEXT, false)
+    add_integer_with_range("queue-depth", 3,
+            1, 8, QUEUE_DEPTH_TEXT, QUEUE_DEPTH_LONGTEXT, false)
+    add_integer("present-mode", VK_PRESENT_MODE_FIFO_KHR,
+            PRESENT_MODE_TEXT, PRESENT_MODE_LONGTEXT, false)
+            change_integer_list(present_values, present_text)
 vlc_module_end ()
 
 // Update the renderer settings based on the current configuration.


=====================================
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).
  *
@@ -47,12 +58,13 @@ vlc_vk_t *vlc_vk_Create(struct vout_window_t *wnd, const char *name)
     if (unlikely(vk == NULL))
         return NULL;
 
-    vk->ctx = NULL;
-    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)
     {
         vlc_object_delete(vk);
@@ -72,6 +84,10 @@ 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);
+
+    /* TODO: use vlc_objres_clear */
     vlc_object_delete(vk);
 }


=====================================
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, VkSurfaceKHR *);
+};
+
+
 // Shared struct for vulkan instance / surface / device state
 typedef struct vlc_vk_t
 {
@@ -39,18 +47,21 @@ typedef struct vlc_vk_t
     module_t *module;
     vlc_atomic_rc_t ref_count;
     void *platform_sys;
+    const char *platform_ext;
 
-    // these should be initialized by the surface module (i.e. surface.c)
-    struct pl_context *ctx;
-    const struct pl_vk_inst *instance;
-    const struct pl_vulkan *vulkan;
-    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;
 void vlc_vk_Release(vlc_vk_t *);
 void vlc_vk_Hold(vlc_vk_t *);
 
+// Create a vulkan surface to vk->surface
+static inline int vlc_vk_CreateSurface(vlc_vk_t * vk, VkInstance instance, VkSurfaceKHR *surface_out)
+{
+    return vk->ops->create_surface(vk, instance, surface_out);
+}
+
 #endif // VLC_VULKAN_INSTANCE_H


=====================================
modules/video_output/vulkan/platform_android.c
=====================================
@@ -20,29 +20,42 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "platform.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+
+#include "instance.h"
 #include "../android/utils.h"
 
-int vlc_vk_InitPlatform(vlc_vk_t *vk)
+static void ClosePlatform(vlc_vk_t *vk);
+static int CreateSurface(vlc_vk_t *vk);
+static const struct vlc_vk_operations platform_ops =
+{
+    .close = ClosePlatform,
+    .create_surface = CreateSurface,
+};
+
+static int InitPlatform(vlc_vk_t *vk)
 {
     if (vk->window->type != VOUT_WINDOW_TYPE_ANDROID_NATIVE)
         return VLC_EGENERIC;
 
+    vk->platform_ext = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
+    vk->platform_ops = &platform_ops;
     return VLC_SUCCESS;
 }
 
-void vlc_vk_ClosePlatform(vlc_vk_t *vk)
+static void ClosePlatform(vlc_vk_t *vk)
 {
     AWindowHandler_releaseANativeWindow(vk->window->handle.anativewindow,
                                         AWindow_Video);
 }
 
-const char * const vlc_vk_PlatformExt = VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
-
-int vlc_vk_CreateSurface(vlc_vk_t *vk)
+static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst)
 {
-    VkInstance vkinst = vk->instance->instance;
-
     ANativeWindow *anw =
         AWindowHandler_getANativeWindow(vk->window->handle.anativewindow,
                                         AWindow_Video);
@@ -62,3 +75,13 @@ int vlc_vk_CreateSurface(vlc_vk_t *vk)
 
     return VLC_SUCCESS;
 }
+
+vlc_module_begin()
+    set_shortname("Vulkan Android")
+    set_description(N_("Android platform support for Vulkan"))
+    set_category(CAT_VIDEO)
+    set_subcategory(SUBCAT_VIDEO_VOUT)
+    set_capability("vulkan platform", 50)
+    set_callback(InitPlatform)
+    add_shortcut("vk_android")
+vlc_module_end()


=====================================
modules/video_output/vulkan/platform_win32.c
=====================================
@@ -24,27 +24,35 @@
 # include "config.h"
 #endif
 
-#include "platform.h"
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include "instance.h"
 
-int vlc_vk_InitPlatform(vlc_vk_t *vk)
+static void ClosePlatform(vlc_vk_t *vk);
+static int CreateSurface(vlc_vk_t *vk);
+static const struct vlc_vk_operations platform_ops =
+{
+    .close = ClosePlatform,
+    .create_surface = CreateSurface,
+};
+
+static int InitPlatform(vlc_vk_t *vk)
 {
     if (vk->window->type != VOUT_WINDOW_TYPE_HWND)
         return VLC_EGENERIC;
 
+    vk->platform_ext = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
+    vk->platform_ops = &platform_ops;
     return VLC_SUCCESS;
 }
 
-void vlc_vk_ClosePlatform(vlc_vk_t *vk)
+static void ClosePlatform(vlc_vk_t *vk)
 {
     VLC_UNUSED(vk);
 }
 
-const char * const vlc_vk_PlatformExt = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
-
-int vlc_vk_CreateSurface(vlc_vk_t *vk)
+static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst)
 {
-    VkInstance vkinst = vk->instance->instance;
-
     // Get current win32 HINSTANCE
     HINSTANCE hInst = GetModuleHandle(NULL);
 
@@ -62,3 +70,13 @@ int vlc_vk_CreateSurface(vlc_vk_t *vk)
 
     return VLC_SUCCESS;
 }
+
+vlc_module_begin()
+    set_shortname("Vulkan Win32")
+    set_description(N_("Win32 platform support for Vulkan"))
+    set_category(CAT_VIDEO)
+    set_subcategory(SUBCAT_VIDEO_VOUT)
+    set_capability("vulkan platform", 50)
+    set_callback(InitPlatform)
+    add_shortcut("vk_win32")
+vlc_module_end()


=====================================
modules/video_output/vulkan/platform_xcb.c
=====================================
@@ -20,15 +20,31 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "platform.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
 
-int vlc_vk_InitPlatform(vlc_vk_t *vk)
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+
+#include "instance.h"
+
+static void ClosePlatform(vlc_vk_t *vk);
+static int CreateSurface(vlc_vk_t *vk, VkInstance instance, VkSurfaceKHR *surface_out);
+
+static const struct vlc_vk_operations platform_ops =
+{
+    .close = ClosePlatform,
+    .create_surface = CreateSurface,
+};
+
+static int InitPlatform(vlc_vk_t *vk)
 {
     if (vk->window->type != VOUT_WINDOW_TYPE_XID)
         return VLC_EGENERIC;
 
     const char *display = vk->window->display.x11;
-    xcb_connection_t *conn = vk->platform_sys = xcb_connect(display, NULL);
+    xcb_connection_t *conn = xcb_connect(display, NULL);
     if (xcb_connection_has_error(conn))
     {
         msg_Err(vk, "Failed connecting to X server (%s)",
@@ -37,21 +53,21 @@ int vlc_vk_InitPlatform(vlc_vk_t *vk)
         return VLC_EGENERIC;
     }
 
+    vk->platform_sys = conn;
+    vk->platform_ext = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
+    vk->ops = &platform_ops;
+
     return VLC_SUCCESS;
 }
 
-void vlc_vk_ClosePlatform(vlc_vk_t *vk)
+static void ClosePlatform(vlc_vk_t *vk)
 {
     xcb_connection_t *conn = vk->platform_sys;
-
     xcb_disconnect(conn);
 }
 
-const char * const vlc_vk_PlatformExt = VK_KHR_XCB_SURFACE_EXTENSION_NAME;
-
-int vlc_vk_CreateSurface(vlc_vk_t *vk)
+static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
 {
-    VkInstance vkinst = vk->instance->instance;
     xcb_connection_t *conn = vk->platform_sys;
 
     VkXcbSurfaceCreateInfoKHR xinfo = {
@@ -60,7 +76,7 @@ int vlc_vk_CreateSurface(vlc_vk_t *vk)
          .connection = conn,
     };
 
-    VkResult res = vkCreateXcbSurfaceKHR(vkinst, &xinfo, NULL, &vk->surface);
+    VkResult res = vkCreateXcbSurfaceKHR(vkinst, &xinfo, NULL, surface_out);
     if (res != VK_SUCCESS) {
         msg_Err(vk, "Failed creating XCB surface");
         return VLC_EGENERIC;
@@ -68,3 +84,13 @@ int vlc_vk_CreateSurface(vlc_vk_t *vk)
 
     return VLC_SUCCESS;
 }
+
+vlc_module_begin()
+    set_shortname("Vulkan XCB")
+    set_description(N_("XCB/X11 platform support for Vulkan"))
+    set_category(CAT_VIDEO)
+    set_subcategory(SUBCAT_VIDEO_VOUT)
+    set_capability("vulkan platform", 50)
+    set_callback(InitPlatform)
+    add_shortcut("vk_x11")
+vlc_module_end()


=====================================
modules/video_output/vulkan/surface.c deleted
=====================================
@@ -1,186 +0,0 @@
-/**
- * @file surface.c
- * @brief Vulkan platform-specific surface extension module
- */
-/*****************************************************************************
- * Copyright © 2018 Niklas Haas
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#include <stdlib.h>
-#include <assert.h>
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_vout_window.h>
-
-#include "../placebo_utils.h"
-#include "instance.h"
-#include "platform.h"
-
-static int Open (vlc_object_t *obj)
-{
-    vlc_vk_t *vk = (vlc_vk_t *) obj;
-
-    if (vlc_vk_InitPlatform(vk) != VLC_SUCCESS)
-        goto error;
-
-    // Initialize Vulkan instance
-    vk->ctx = vlc_placebo_Create(VLC_OBJECT(vk));
-    if (!vk->ctx)
-        goto error;
-
-    vk->instance = pl_vk_inst_create(vk->ctx, &(struct pl_vk_inst_params) {
-        .debug = var_InheritBool(vk, "vk-debug"),
-        .extensions = (const char *[]) {
-            VK_KHR_SURFACE_EXTENSION_NAME,
-            vlc_vk_PlatformExt,
-        },
-        .num_extensions = 2,
-    });
-    if (!vk->instance)
-        goto error;
-
-    // Create the platform-specific surface object
-    if (vlc_vk_CreateSurface(vk) != VLC_SUCCESS)
-        goto error;
-
-    // Create vulkan device
-    char *device_name = var_InheritString(vk, "vk-device");
-    vk->vulkan = pl_vulkan_create(vk->ctx, &(struct pl_vulkan_params) {
-        .instance = vk->instance->instance,
-        .surface = vk->surface,
-        .device_name = device_name,
-        .allow_software = var_InheritBool(vk, "allow-sw"),
-        .async_transfer = var_InheritBool(vk, "async-xfer"),
-        .async_compute = var_InheritBool(vk, "async-comp"),
-        .queue_count = var_InheritInteger(vk, "queue-count"),
-    });
-    free(device_name);
-    if (!vk->vulkan)
-        goto error;
-
-    // Create swapchain for this surface
-    struct pl_vulkan_swapchain_params swap_params = {
-        .surface = vk->surface,
-        .present_mode = var_InheritInteger(vk, "present-mode"),
-        .swapchain_depth = var_InheritInteger(vk, "queue-depth"),
-    };
-
-    vk->swapchain = pl_vulkan_create_swapchain(vk->vulkan, &swap_params);
-    if (!vk->swapchain)
-        goto error;
-
-    return VLC_SUCCESS;
-
-error:
-    pl_swapchain_destroy(&vk->swapchain);
-    if (vk->surface)
-        vkDestroySurfaceKHR(vk->instance->instance, vk->surface, NULL);
-
-    pl_vulkan_destroy(&vk->vulkan);
-    pl_vk_inst_destroy(&vk->instance);
-    pl_context_destroy(&vk->ctx);
-    vlc_vk_ClosePlatform(vk);
-
-    return VLC_EGENERIC;
-}
-
-static void Close (vlc_object_t *obj)
-{
-    vlc_vk_t *vk = (vlc_vk_t *) obj;
-
-    pl_swapchain_destroy(&vk->swapchain);
-    vkDestroySurfaceKHR(vk->instance->instance, vk->surface, NULL);
-    pl_vulkan_destroy(&vk->vulkan);
-    pl_vk_inst_destroy(&vk->instance);
-    pl_context_destroy(&vk->ctx);
-    vlc_vk_ClosePlatform(vk);
-}
-
-#define DEBUG_TEXT "Enable API debugging"
-#define DEBUG_LONGTEXT "This loads the vulkan standard validation layers, which can help catch API usage errors. Comes at a small performance penalty."
-
-#define DEVICE_TEXT "Device name override"
-#define DEVICE_LONGTEXT "If set to something non-empty, only a device with this exact name will be used. To see a list of devices and their names, run vlc -v with this module active."
-
-#define ALLOWSW_TEXT "Allow software devices"
-#define ALLOWSW_LONGTEXT "If enabled, allow the use of software emulation devices, which are not real devices and therefore typically very slow. (This option has no effect if forcing a specific device name)"
-
-#define ASYNC_XFER_TEXT "Allow asynchronous transfer"
-#define ASYNC_XFER_LONGTEXT "Allows the use of an asynchronous transfer queue if the device has one. Typically this maps to a DMA engine, which can perform texture uploads/downloads without blocking the GPU's compute units. Highly recommended for 4K and above."
-
-#define ASYNC_COMP_TEXT "Allow asynchronous compute"
-#define ASYNC_COMP_LONGTEXT "Allows the use of dedicated compute queue families if the device has one. Sometimes these will schedule concurrent compute work better than the main graphics queue. Turn this off if you have any issues."
-
-#define QUEUE_COUNT_TEXT "Queue count"
-#define QUEUE_COUNT_LONGTEXT "How many queues to use on the device. Increasing this might improve rendering throughput for GPUs capable of concurrent scheduling. Increasing this past the driver's limit has no effect."
-
-#define QUEUE_DEPTH_TEXT "Maximum frame latency"
-#define QUEUE_DEPTH_LONGTEXT "Affects how many frames to render/present in advance. Increasing this can improve performance at the cost of latency, by allowing better pipelining between frames. May have no effect, depending on the VLC clock settings."
-
-static const int present_values[] = {
-    VK_PRESENT_MODE_IMMEDIATE_KHR,
-    VK_PRESENT_MODE_MAILBOX_KHR,
-    VK_PRESENT_MODE_FIFO_KHR,
-    VK_PRESENT_MODE_FIFO_RELAXED_KHR,
-};
-
-static const char * const present_text[] = {
-    "Immediate (non-blocking, tearing)",
-    "Mailbox (non-blocking, non-tearing)",
-    "FIFO (blocking, non-tearing)",
-    "Relaxed FIFO (blocking, tearing)",
-};
-
-#define PRESENT_MODE_TEXT "Preferred present mode"
-#define PRESENT_MODE_LONGTEXT "Which present mode to use when creating the swapchain. If the chosen mode is not supported, VLC will fall back to using FIFO."
-
-#define XSTR(x) #x
-#define STR(x) XSTR(x)
-
-vlc_module_begin ()
-    set_shortname ("Vulkan/" STR(PLATFORM_NAME))
-    set_description ("Vulkan context (" STR(PLATFORM_NAME) ")")
-    set_category (CAT_VIDEO)
-    set_subcategory (SUBCAT_VIDEO_VOUT)
-    set_capability ("vulkan", 10)
-    set_callbacks (Open, Close)
-
-    set_section("Device selection", NULL)
-    add_bool("vk-debug", false, DEBUG_TEXT, DEBUG_LONGTEXT, false)
-    add_string("vk-device", "", DEVICE_TEXT, DEVICE_LONGTEXT, false)
-    add_bool("allow-sw", pl_vulkan_default_params.allow_software,
-            ALLOWSW_TEXT, ALLOWSW_LONGTEXT, false)
-
-    set_section("Performance tuning", NULL)
-    add_bool("async-xfer", pl_vulkan_default_params.async_transfer,
-            ASYNC_XFER_TEXT, ASYNC_XFER_LONGTEXT, false)
-    add_bool("async-comp", pl_vulkan_default_params.async_compute,
-            ASYNC_COMP_TEXT, ASYNC_COMP_LONGTEXT, false)
-    add_integer_with_range("queue-count", pl_vulkan_default_params.queue_count,
-            1, 8, QUEUE_COUNT_TEXT, QUEUE_COUNT_LONGTEXT, false)
-    add_integer_with_range("queue-depth", 3,
-            1, 8, QUEUE_DEPTH_TEXT, QUEUE_DEPTH_LONGTEXT, false)
-    add_integer("present-mode", VK_PRESENT_MODE_FIFO_KHR,
-            PRESENT_MODE_TEXT, PRESENT_MODE_LONGTEXT, false)
-            change_integer_list(present_values, present_text)
-
-vlc_module_end ()


=====================================
modules/video_output/wayland/Makefile.am
=====================================
@@ -73,6 +73,14 @@ libegl_wl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -DUSE_PLATFORM_WAYLAND=1
 libegl_wl_plugin_la_CFLAGS = $(AM_CFLAGS) $(EGL_CFLAGS) $(WAYLAND_EGL_CFLAGS)
 libegl_wl_plugin_la_LIBADD = $(EGL_LIBS) $(WAYLAND_EGL_LIBS)
 
+libvk_wl_plugin_la_SOURCES = \
+	video_output/vulkan/platform.h \
+	video_output/wayland/vulkan.c
+libvk_wl_plugin_la_CFLAGS = $(AM_CFLAGS) \
+	$(WAYLAND_CFLAGS) $(VULKAN_COMMONCFLAGS) \
+	-DVK_USE_PLATFORM_WAYLAND_KHR
+libvk_wl_plugin_la_LIBADD = $(VULKAN_COMMONLIBS) $(WAYLAND_LIBS)
+
 if HAVE_WAYLAND
 BUILT_SOURCES += $(nodist_libwl_shm_plugin_la_SOURCES)
 vout_LTLIBRARIES += libwl_shm_plugin.la
@@ -82,4 +90,7 @@ vout_LTLIBRARIES += libxdg_shell_plugin.la
 if HAVE_EGL
 vout_LTLIBRARIES += libegl_wl_plugin.la
 endif
+if HAVE_VULKAN
+vout_LTLIBRARIES += libvk_wl_plugin.la
+endif
 endif


=====================================
modules/video_output/vulkan/platform.h → modules/video_output/wayland/vulkan.c
=====================================
@@ -1,7 +1,9 @@
+/**
+ * @file vulkan.c
+ * @brief Vulkan platform-specific code for Wayland
+ */
 /*****************************************************************************
- * platform.h: Vulkan platform-specific functions
- *****************************************************************************
- * Copyright (C) 2018 Niklas Haas
+ * Copyright © 2020 VideoLabs
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -18,19 +20,57 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#ifndef VLC_VULKAN_PLATFORM_H
-#define VLC_VULKAN_PLATFORM_H
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
-#include "instance.h"
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 
-// Initializes a platform-specific context to vk->platform_sys
-int vlc_vk_InitPlatform(vlc_vk_t *);
-void vlc_vk_ClosePlatform(vlc_vk_t *);
+#include "../vulkan/instance.h"
 
-// Contains the required platform-specific instance extension
-extern const char * const vlc_vk_PlatformExt;
+static void ClosePlatform(vlc_vk_t *vk)
+    { (void)vk; }
 
-// Create a vulkan surface to vk->surface
-int vlc_vk_CreateSurface(vlc_vk_t *);
+static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
+{
+    VkWaylandSurfaceCreateInfoKHR surface_info = {
+        .sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
+        .display = vk->window->display.wl,
+        .surface = vk->window->handle.wl,
+    };
 
-#endif // VLC_VULKAN_PLATFORM_H
+    VkResult res = vkCreateWaylandSurfaceKHR(vkinst, &surface_info, NULL, surface_out);
+    if (res != VK_SUCCESS) {
+        msg_Err(vk, "Failed creating Wayland surface");
+        return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
+
+static const struct vlc_vk_operations platform_ops =
+{
+    .close = ClosePlatform,
+    .create_surface = CreateSurface,
+};
+
+static int InitPlatform(vlc_vk_t *vk)
+{
+    if (vk->window->type != VOUT_WINDOW_TYPE_WAYLAND)
+        return VLC_EGENERIC;
+
+    vk->platform_ext = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
+    vk->ops = &platform_ops;
+    return VLC_SUCCESS;
+}
+
+vlc_module_begin()
+    set_shortname("Vulkan Wayland")
+    set_description(N_("Wayland platform support for Vulkan"))
+    set_category(CAT_VIDEO)
+    set_subcategory(SUBCAT_VIDEO_VOUT)
+    set_capability("vulkan platform", 50)
+    set_callback(InitPlatform)
+    add_shortcut("vk_wl")
+vlc_module_end()


=====================================
modules/video_output/xcb/Makefile.am
=====================================
@@ -33,7 +33,6 @@ libxcb_window_plugin_la_LIBADD = $(XPROTO_LIBS) $(XCB_LIBS) \
 	$(XCB_XKB_LIBS) $(XKBCOMMON_X11_LIBS)
 
 libvk_x11_plugin_la_SOURCES = $(VULKAN_COMMONSOURCES) \
-	video_output/vulkan/surface.c \
 	video_output/vulkan/platform_xcb.c
 libvk_x11_plugin_la_CFLAGS = $(AM_CFLAGS) \
 	$(XCB_CFLAGS) $(VULKAN_COMMONCFLAGS) \



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b82eb43c7b43328a4ef7048cf400d9589ee570da...183c8d997139e39a424debea97e195f6e02d1dc4

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b82eb43c7b43328a4ef7048cf400d9589ee570da...183c8d997139e39a424debea97e195f6e02d1dc4
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list