mirror of https://github.com/mpv-player/mpv
vo_gpu: vulkan: add support for wayland
This commit is contained in:
parent
258487370f
commit
ed345ffc2f
|
@ -4633,7 +4633,7 @@ The following video options are currently all specific to ``--vo=gpu`` and
|
||||||
For internal autoprobing, equivalent to ``x11`` otherwise. Don't use
|
For internal autoprobing, equivalent to ``x11`` otherwise. Don't use
|
||||||
directly, it could be removed without warning as autoprobing is changed.
|
directly, it could be removed without warning as autoprobing is changed.
|
||||||
wayland
|
wayland
|
||||||
Wayland/EGL
|
Wayland/EGL, VK_KHR_wayland_surface
|
||||||
drm
|
drm
|
||||||
DRM/EGL
|
DRM/EGL
|
||||||
x11egl
|
x11egl
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "spirv.h"
|
#include "spirv.h"
|
||||||
|
|
||||||
|
/* OpenGL */
|
||||||
extern const struct ra_ctx_fns ra_ctx_glx;
|
extern const struct ra_ctx_fns ra_ctx_glx;
|
||||||
extern const struct ra_ctx_fns ra_ctx_glx_probe;
|
extern const struct ra_ctx_fns ra_ctx_glx_probe;
|
||||||
extern const struct ra_ctx_fns ra_ctx_x11_egl;
|
extern const struct ra_ctx_fns ra_ctx_x11_egl;
|
||||||
|
@ -45,6 +46,9 @@ extern const struct ra_ctx_fns ra_ctx_dxgl;
|
||||||
extern const struct ra_ctx_fns ra_ctx_rpi;
|
extern const struct ra_ctx_fns ra_ctx_rpi;
|
||||||
extern const struct ra_ctx_fns ra_ctx_mali;
|
extern const struct ra_ctx_fns ra_ctx_mali;
|
||||||
extern const struct ra_ctx_fns ra_ctx_vdpauglx;
|
extern const struct ra_ctx_fns ra_ctx_vdpauglx;
|
||||||
|
|
||||||
|
/* Vulkan */
|
||||||
|
extern const struct ra_ctx_fns ra_ctx_vulkan_wayland;
|
||||||
extern const struct ra_ctx_fns ra_ctx_vulkan_xlib;
|
extern const struct ra_ctx_fns ra_ctx_vulkan_xlib;
|
||||||
|
|
||||||
static const struct ra_ctx_fns *contexts[] = {
|
static const struct ra_ctx_fns *contexts[] = {
|
||||||
|
@ -88,9 +92,14 @@ static const struct ra_ctx_fns *contexts[] = {
|
||||||
|
|
||||||
// Vulkan contexts:
|
// Vulkan contexts:
|
||||||
#if HAVE_VULKAN
|
#if HAVE_VULKAN
|
||||||
|
|
||||||
|
#if HAVE_WAYLAND
|
||||||
|
&ra_ctx_vulkan_wayland,
|
||||||
|
#endif
|
||||||
#if HAVE_X11
|
#if HAVE_X11
|
||||||
&ra_ctx_vulkan_xlib,
|
&ra_ctx_vulkan_xlib,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
// We need to define all platforms we want to support. Since we have
|
// We need to define all platforms we want to support. Since we have
|
||||||
// our own mechanism for checking this, we re-define the right symbols
|
// our own mechanism for checking this, we re-define the right symbols
|
||||||
|
#if HAVE_WAYLAND
|
||||||
|
#define VK_USE_PLATFORM_WAYLAND_KHR
|
||||||
|
#endif
|
||||||
#if HAVE_X11
|
#if HAVE_X11
|
||||||
#define VK_USE_PLATFORM_XLIB_KHR
|
#define VK_USE_PLATFORM_XLIB_KHR
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
* This file is part of mpv.
|
||||||
|
*
|
||||||
|
* mpv 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.
|
||||||
|
*
|
||||||
|
* mpv 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 mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "video/out/gpu/context.h"
|
||||||
|
#include "video/out/wayland_common.h"
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include "context.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
struct priv {
|
||||||
|
struct mpvk_ctx vk;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void wayland_uninit(struct ra_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct priv *p = ctx->priv;
|
||||||
|
|
||||||
|
ra_vk_ctx_uninit(ctx);
|
||||||
|
mpvk_uninit(&p->vk);
|
||||||
|
vo_wayland_uninit(ctx->vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool wayland_init(struct ra_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct priv *p = ctx->priv = talloc_zero(ctx, struct priv);
|
||||||
|
struct mpvk_ctx *vk = &p->vk;
|
||||||
|
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
||||||
|
|
||||||
|
if (!mpvk_instance_init(vk, ctx->log, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
|
||||||
|
ctx->opts.debug))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!vo_wayland_init(ctx->vo))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!vo_wayland_config(ctx->vo))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
VkWaylandSurfaceCreateInfoKHR wlinfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
|
||||||
|
.display = ctx->vo->wayland->display.display,
|
||||||
|
.surface = ctx->vo->wayland->window.video_surface,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkResult res = vkCreateWaylandSurfaceKHR(vk->inst, &wlinfo, MPVK_ALLOCATOR,
|
||||||
|
&vk->surf);
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
MP_MSG(ctx, msgl, "Failed creating Wayland surface: %s\n", vk_err(res));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Because in Wayland clients render whenever they receive a callback from
|
||||||
|
* the compositor, and the fact that the compositor usually stops sending
|
||||||
|
* callbacks once the surface is no longer visible, using FIFO here would
|
||||||
|
* mean the entire player would block on acquiring swapchain images. Hence,
|
||||||
|
* use MAILBOX to guarantee that there'll always be a swapchain image and
|
||||||
|
* the player won't block waiting on those */
|
||||||
|
if (!ra_vk_ctx_init(ctx, vk, VK_PRESENT_MODE_MAILBOX_KHR))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
wayland_uninit(ctx);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool resize(struct ra_ctx *ctx)
|
||||||
|
{
|
||||||
|
struct vo_wayland_state *wl = ctx->vo->wayland;
|
||||||
|
int32_t width = wl->window.sh_width;
|
||||||
|
int32_t height = wl->window.sh_height;
|
||||||
|
int32_t scale = 1;
|
||||||
|
|
||||||
|
if (wl->display.current_output)
|
||||||
|
scale = wl->display.current_output->scale;
|
||||||
|
|
||||||
|
MP_VERBOSE(wl, "resizing %dx%d -> %dx%d\n", wl->window.width,
|
||||||
|
wl->window.height,
|
||||||
|
width,
|
||||||
|
height);
|
||||||
|
|
||||||
|
wl_surface_set_buffer_scale(wl->window.video_surface, scale);
|
||||||
|
int err = ra_vk_ctx_resize(ctx->swapchain, scale*width, scale*height);
|
||||||
|
|
||||||
|
wl->window.width = width;
|
||||||
|
wl->window.height = height;
|
||||||
|
|
||||||
|
wl->vo->dwidth = scale*wl->window.width;
|
||||||
|
wl->vo->dheight = scale*wl->window.height;
|
||||||
|
wl->vo->want_redraw = true;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool wayland_reconfig(struct ra_ctx *ctx)
|
||||||
|
{
|
||||||
|
vo_wayland_config(ctx->vo);
|
||||||
|
return resize(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int wayland_control(struct ra_ctx *ctx, int *events, int request, void *arg)
|
||||||
|
{
|
||||||
|
int ret = vo_wayland_control(ctx->vo, events, request, arg);
|
||||||
|
if (*events & VO_EVENT_RESIZE) {
|
||||||
|
if (!resize(ctx))
|
||||||
|
return VO_ERROR;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wayland_wakeup(struct ra_ctx *ctx)
|
||||||
|
{
|
||||||
|
vo_wayland_wakeup(ctx->vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wayland_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
|
||||||
|
{
|
||||||
|
vo_wayland_wait_events(ctx->vo, until_time_us);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct ra_ctx_fns ra_ctx_vulkan_wayland = {
|
||||||
|
.type = "vulkan",
|
||||||
|
.name = "wayland",
|
||||||
|
.reconfig = wayland_reconfig,
|
||||||
|
.control = wayland_control,
|
||||||
|
.wakeup = wayland_wakeup,
|
||||||
|
.wait_events = wayland_wait_events,
|
||||||
|
.init = wayland_init,
|
||||||
|
.uninit = wayland_uninit,
|
||||||
|
};
|
|
@ -41,15 +41,16 @@ static bool xlib_init(struct ra_ctx *ctx)
|
||||||
struct mpvk_ctx *vk = &p->vk;
|
struct mpvk_ctx *vk = &p->vk;
|
||||||
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
||||||
|
|
||||||
|
if (!mpvk_instance_init(vk, ctx->log, VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
|
||||||
|
ctx->opts.debug))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!vo_x11_init(ctx->vo))
|
if (!vo_x11_init(ctx->vo))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!vo_x11_create_vo_window(ctx->vo, NULL, "mpvk"))
|
if (!vo_x11_create_vo_window(ctx->vo, NULL, "mpvk"))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!mpvk_instance_init(vk, ctx->log, ctx->opts.debug))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
VkXlibSurfaceCreateInfoKHR xinfo = {
|
VkXlibSurfaceCreateInfoKHR xinfo = {
|
||||||
.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||||
.dpy = ctx->vo->x11->display,
|
.dpy = ctx->vo->x11->display,
|
||||||
|
|
|
@ -167,7 +167,8 @@ void mpvk_uninit(struct mpvk_ctx *vk)
|
||||||
*vk = (struct mpvk_ctx){0};
|
*vk = (struct mpvk_ctx){0};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mpvk_instance_init(struct mpvk_ctx *vk, struct mp_log *log, bool debug)
|
bool mpvk_instance_init(struct mpvk_ctx *vk, struct mp_log *log,
|
||||||
|
const char *surf_ext_name, bool debug)
|
||||||
{
|
{
|
||||||
*vk = (struct mpvk_ctx) {
|
*vk = (struct mpvk_ctx) {
|
||||||
.log = log,
|
.log = log,
|
||||||
|
@ -189,11 +190,9 @@ bool mpvk_instance_init(struct mpvk_ctx *vk, struct mp_log *log, bool debug)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable whatever extensions were compiled in.
|
// Enable whatever extensions were compiled in.
|
||||||
static const char *extensions[] = {
|
const char *extensions[] = {
|
||||||
VK_KHR_SURFACE_EXTENSION_NAME,
|
VK_KHR_SURFACE_EXTENSION_NAME,
|
||||||
#if HAVE_X11
|
surf_ext_name,
|
||||||
VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Extra extensions only used for debugging. These are toggled by
|
// Extra extensions only used for debugging. These are toggled by
|
||||||
// decreasing the enabledExtensionCount, so the number needs to be
|
// decreasing the enabledExtensionCount, so the number needs to be
|
||||||
|
|
|
@ -37,7 +37,8 @@ void mpvk_uninit(struct mpvk_ctx *vk);
|
||||||
// finally followed by vk_swchain initialization.
|
// finally followed by vk_swchain initialization.
|
||||||
|
|
||||||
// Create a vulkan instance. Returns VK_NULL_HANDLE on failure
|
// Create a vulkan instance. Returns VK_NULL_HANDLE on failure
|
||||||
bool mpvk_instance_init(struct mpvk_ctx *vk, struct mp_log *log, bool debug);
|
bool mpvk_instance_init(struct mpvk_ctx *vk, struct mp_log *log,
|
||||||
|
const char *surf_ext_name, bool debug);
|
||||||
|
|
||||||
// Generate a VkSurfaceKHR usable for video output. Returns VK_NULL_HANDLE on
|
// Generate a VkSurfaceKHR usable for video output. Returns VK_NULL_HANDLE on
|
||||||
// failure. Must be called after mpvk_instance_init.
|
// failure. Must be called after mpvk_instance_init.
|
||||||
|
|
|
@ -453,6 +453,7 @@ def build(ctx):
|
||||||
( "video/out/vulkan/ra_vk.c", "vulkan" ),
|
( "video/out/vulkan/ra_vk.c", "vulkan" ),
|
||||||
( "video/out/vulkan/context.c", "vulkan" ),
|
( "video/out/vulkan/context.c", "vulkan" ),
|
||||||
( "video/out/vulkan/context_xlib.c", "vulkan && x11" ),
|
( "video/out/vulkan/context_xlib.c", "vulkan && x11" ),
|
||||||
|
( "video/out/vulkan/context_wayland.c", "vulkan && wayland" ),
|
||||||
( "video/out/vulkan/spirv_nvidia.c", "vulkan" ),
|
( "video/out/vulkan/spirv_nvidia.c", "vulkan" ),
|
||||||
( "video/out/win32/exclusive_hack.c", "gl-win32" ),
|
( "video/out/win32/exclusive_hack.c", "gl-win32" ),
|
||||||
( "video/out/wayland_common.c", "wayland" ),
|
( "video/out/wayland_common.c", "wayland" ),
|
||||||
|
|
Loading…
Reference in New Issue