Commit f6e9e324 authored by Niklas Haas's avatar Niklas Haas Committed by Hugo Beauzée-Luyssen
Browse files

vulkan: rename instance.h to platform.h

With the removal of the actual vulkan instance from this abstraction in
883a865a, calling this "instance" is confusing and misleading. It should
be called "platform", because the only thing the abstraction is designed
to contain is platform-specific state and operations.

Rename it, and the associated type, for clarity. This frees up the name
`vlc_vk_t` to be used for an actual Vulkan instance, if we ever decide
we need one in the future. (e.g. for GPU filters)
parent 51cdf229
......@@ -24,8 +24,8 @@ vout_LTLIBRARIES += libplacebo_plugin.la
### Vulkan ###
libplacebo_vk_plugin_la_SOURCES = $(LIBPLACEBO_COMMONSOURCES) \
video_output/vulkan/instance.h \
video_output/vulkan/instance.c \
video_output/vulkan/platform.h \
video_output/vulkan/platform.c \
video_output/libplacebo/instance_vulkan.c
libplacebo_vk_plugin_la_CFLAGS = $(AM_CFLAGS) $(LIBPLACEBO_CFLAGS) $(VULKAN_CFLAGS)
libplacebo_vk_plugin_la_LIBADD = $(LIBPLACEBO_LIBS) $(VULKAN_LIBS)
......
......@@ -29,12 +29,12 @@
#include <libplacebo/vulkan.h>
#include "../vulkan/instance.h"
#include "../vulkan/platform.h"
#include "instance.h"
#include "utils.h"
struct vlc_placebo_system_t {
vlc_vk_t *vk;
vlc_vk_platform_t *platform;
const struct pl_vk_inst *instance;
const struct pl_vulkan *vulkan;
};
......@@ -53,16 +53,16 @@ static int InitInstance(vlc_placebo_t *pl, const vout_display_cfg_t *cfg)
return VLC_ENOMEM;
char *platform_name = var_InheritString(pl, "vk-platform");
sys->vk = vlc_vk_Create(cfg->window, platform_name);
sys->platform = vlc_vk_platform_Create(cfg->window, platform_name);
free(platform_name);
if (!sys->vk)
if (!sys->platform)
goto error;
sys->instance = pl_vk_inst_create(pl->ctx, &(struct pl_vk_inst_params) {
.debug = var_InheritBool(pl, "vk-debug"),
.extensions = (const char *[]) {
VK_KHR_SURFACE_EXTENSION_NAME,
sys->vk->platform_ext,
sys->platform->platform_ext,
},
.num_extensions = 2,
});
......@@ -71,7 +71,7 @@ static int InitInstance(vlc_placebo_t *pl, const vout_display_cfg_t *cfg)
// Create the platform-specific surface object
VkSurfaceKHR surface;
if (vlc_vk_CreateSurface(sys->vk, sys->instance->instance, &surface) != VLC_SUCCESS)
if (vlc_vk_CreateSurface(sys->platform, sys->instance->instance, &surface) != VLC_SUCCESS)
goto error;
// Create vulkan device
......@@ -116,8 +116,8 @@ static void CloseInstance(vlc_placebo_t *pl)
pl_vulkan_destroy(&sys->vulkan);
pl_vk_inst_destroy(&sys->instance);
if (sys->vk != NULL)
vlc_vk_Release(sys->vk);
if (sys->platform != NULL)
vlc_vk_platform_Release(sys->platform);
vlc_obj_free(VLC_OBJECT(pl), sys);
pl->sys = NULL;
......
### Vulkan ###
VULKAN_COMMONSOURCES = video_output/vulkan/instance.c \
video_output/vulkan/instance.h
VULKAN_COMMONSOURCES = video_output/vulkan/platform.c \
video_output/vulkan/platform.h
# Trigger the c++ linker because of glslang dependency of libplacebo
VULKAN_COMMONSOURCES += dummy.cpp
......
/*****************************************************************************
* instance.c: Vulkan instance abstraction
* platform.c: Vulkan platform abstraction
*****************************************************************************
* Copyright (C) 2018 Niklas Haas
*
......@@ -29,12 +29,12 @@
#include <vlc_modules.h>
#include <vlc_atomic.h>
#include "instance.h"
#include "platform.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 (*activate)(vlc_vk_platform_t *vk) = func;
vlc_vk_platform_t *vk = va_arg(ap, vlc_vk_platform_t *);
int ret = activate(vk);
/* TODO: vlc_objres_clear, which is not in the public API. */
......@@ -43,16 +43,16 @@ static int vlc_vk_start(void *func, bool forced, va_list ap)
}
/**
* Creates a Vulkan surface (and its underlying instance).
* Initializes a Vulkan platform module for a given window
*
* @param wnd window to use as Vulkan surface
* @param name module name (or NULL for auto)
* @return a new context, or NULL on failure
* @return a new platform object, or NULL on failure
*/
vlc_vk_t *vlc_vk_Create(struct vout_window_t *wnd, const char *name)
vlc_vk_platform_t *vlc_vk_platform_Create(struct vout_window_t *wnd, const char *name)
{
vlc_object_t *parent = (vlc_object_t *) wnd;
struct vlc_vk_t *vk;
struct vlc_vk_platform_t *vk;
vk = vlc_object_create(parent, sizeof (*vk));
if (unlikely(vk == NULL))
......@@ -75,12 +75,12 @@ vlc_vk_t *vlc_vk_Create(struct vout_window_t *wnd, const char *name)
return vk;
}
void vlc_vk_Hold(vlc_vk_t *vk)
void vlc_vk_platform_Hold(vlc_vk_platform_t *vk)
{
vlc_atomic_rc_inc(&vk->ref_count);
}
void vlc_vk_Release(vlc_vk_t *vk)
void vlc_vk_platform_Release(vlc_vk_platform_t *vk)
{
if (!vlc_atomic_rc_dec(&vk->ref_count))
return;
......
/*****************************************************************************
* instance.h: Vulkan instance abstraction
* platform.h: Vulkan platform abstraction
*****************************************************************************
* Copyright (C) 2018 Niklas Haas
*
......@@ -18,8 +18,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef VLC_VULKAN_INSTANCE_H
#define VLC_VULKAN_INSTANCE_H
#ifndef VLC_VULKAN_PLATFORM_H
#define VLC_VULKAN_PLATFORM_H
#include <vlc_common.h>
#include <vlc_atomic.h>
......@@ -30,18 +30,18 @@
struct vout_window_t;
struct vout_window_cfg_t;
struct vlc_vk_t;
struct vlc_vk_operations
struct vlc_vk_platform_t;
struct vlc_vk_platform_operations
{
void (*close)(struct vlc_vk_t *);
int (*create_surface)(struct vlc_vk_t *, VkInstance, VkSurfaceKHR *);
void (*close)(struct vlc_vk_platform_t *);
int (*create_surface)(struct vlc_vk_platform_t *, VkInstance, VkSurfaceKHR *);
};
// Shared struct for vulkan instance / surface / device state
typedef struct vlc_vk_t
// Struct for platform-specific Vulkan state
typedef struct vlc_vk_platform_t
{
// fields internal to instance.c, should not be touched
// fields internal to platform.c, should not be touched
struct vlc_object_t obj;
module_t *module;
vlc_atomic_rc_t ref_count;
......@@ -50,17 +50,18 @@ typedef struct vlc_vk_t
struct vout_window_t *window;
const struct vlc_vk_operations *ops;
} vlc_vk_t;
const struct vlc_vk_platform_operations *ops;
} vlc_vk_platform_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 *);
vlc_vk_platform_t *vlc_vk_platform_Create(struct vout_window_t *, const char *) VLC_USED;
void vlc_vk_platform_Release(vlc_vk_platform_t *);
void vlc_vk_platform_Hold(vlc_vk_platform_t *);
// Create a vulkan surface to vk->surface
static inline int vlc_vk_CreateSurface(vlc_vk_t * vk, VkInstance instance, VkSurfaceKHR *surface_out)
// Create a vulkan surface and store it to `surface_out`
static inline int vlc_vk_CreateSurface(vlc_vk_platform_t * vk, VkInstance instance,
VkSurfaceKHR *surface_out)
{
return vk->ops->create_surface(vk, instance, surface_out);
}
#endif // VLC_VULKAN_INSTANCE_H
#endif // VLC_VULKAN_PLATFORM_H
......@@ -27,18 +27,18 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include "instance.h"
#include "platform.h"
#include "../android/utils.h"
static void ClosePlatform(vlc_vk_t *vk);
static int CreateSurface(vlc_vk_t *vk);
static const struct vlc_vk_operations platform_ops =
static void ClosePlatform(vlc_vk_platform_t *vk);
static int CreateSurface(vlc_vk_platform_t *vk);
static const struct vlc_vk_platform_operations platform_ops =
{
.close = ClosePlatform,
.create_surface = CreateSurface,
};
static int InitPlatform(vlc_vk_t *vk)
static int InitPlatform(vlc_vk_platform_t *vk)
{
if (vk->window->type != VOUT_WINDOW_TYPE_ANDROID_NATIVE)
return VLC_EGENERIC;
......@@ -48,13 +48,13 @@ static int InitPlatform(vlc_vk_t *vk)
return VLC_SUCCESS;
}
static void ClosePlatform(vlc_vk_t *vk)
static void ClosePlatform(vlc_vk_platform_t *vk)
{
AWindowHandler_releaseANativeWindow(vk->window->handle.anativewindow,
AWindow_Video);
}
static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst)
static int CreateSurface(vlc_vk_platform_t *vk, VkInstance vkinst)
{
ANativeWindow *anw =
AWindowHandler_getANativeWindow(vk->window->handle.anativewindow,
......
......@@ -26,17 +26,17 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include "instance.h"
#include "platform.h"
static void ClosePlatform(vlc_vk_t *vk);
static int CreateSurface(vlc_vk_t *vk);
static const struct vlc_vk_operations platform_ops =
static void ClosePlatform(vlc_vk_platform_t *vk);
static int CreateSurface(vlc_vk_platform_t *vk);
static const struct vlc_vk_platform_operations platform_ops =
{
.close = ClosePlatform,
.create_surface = CreateSurface,
};
static int InitPlatform(vlc_vk_t *vk)
static int InitPlatform(vlc_vk_platform_t *vk)
{
if (vk->window->type != VOUT_WINDOW_TYPE_HWND)
return VLC_EGENERIC;
......@@ -46,12 +46,12 @@ static int InitPlatform(vlc_vk_t *vk)
return VLC_SUCCESS;
}
static void ClosePlatform(vlc_vk_t *vk)
static void ClosePlatform(vlc_vk_platform_t *vk)
{
VLC_UNUSED(vk);
}
static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst)
static int CreateSurface(vlc_vk_platform_t *vk, VkInstance vkinst)
{
// Get current win32 HINSTANCE
HINSTANCE hInst = GetModuleHandle(NULL);
......
......@@ -27,18 +27,18 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include "instance.h"
#include "platform.h"
static void ClosePlatform(vlc_vk_t *vk);
static int CreateSurface(vlc_vk_t *vk, VkInstance instance, VkSurfaceKHR *surface_out);
static void ClosePlatform(vlc_vk_platform_t *vk);
static int CreateSurface(vlc_vk_platform_t *vk, VkInstance instance, VkSurfaceKHR *surface_out);
static const struct vlc_vk_operations platform_ops =
static const struct vlc_vk_platform_operations platform_ops =
{
.close = ClosePlatform,
.create_surface = CreateSurface,
};
static int InitPlatform(vlc_vk_t *vk)
static int InitPlatform(vlc_vk_platform_t *vk)
{
if (vk->window->type != VOUT_WINDOW_TYPE_XID)
return VLC_EGENERIC;
......@@ -60,13 +60,13 @@ static int InitPlatform(vlc_vk_t *vk)
return VLC_SUCCESS;
}
static void ClosePlatform(vlc_vk_t *vk)
static void ClosePlatform(vlc_vk_platform_t *vk)
{
xcb_connection_t *conn = vk->platform_sys;
xcb_disconnect(conn);
}
static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
static int CreateSurface(vlc_vk_platform_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
{
xcb_connection_t *conn = vk->platform_sys;
......
......@@ -74,7 +74,7 @@ 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/instance.h \
video_output/vulkan/platform.h \
video_output/wayland/vulkan.c
libvk_wl_plugin_la_CFLAGS = $(AM_CFLAGS) \
$(WAYLAND_CLIENT_CFLAGS) $(VULKAN_COMMONCFLAGS) \
......
......@@ -27,12 +27,12 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include "../vulkan/instance.h"
#include "../vulkan/platform.h"
static void ClosePlatform(vlc_vk_t *vk)
static void ClosePlatform(vlc_vk_platform_t *vk)
{ (void)vk; }
static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
static int CreateSurface(vlc_vk_platform_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_out)
{
VkWaylandSurfaceCreateInfoKHR surface_info = {
.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR,
......@@ -49,13 +49,13 @@ static int CreateSurface(vlc_vk_t *vk, VkInstance vkinst, VkSurfaceKHR *surface_
return VLC_SUCCESS;
}
static const struct vlc_vk_operations platform_ops =
static const struct vlc_vk_platform_operations platform_ops =
{
.close = ClosePlatform,
.create_surface = CreateSurface,
};
static int InitPlatform(vlc_vk_t *vk)
static int InitPlatform(vlc_vk_platform_t *vk)
{
if (vk->window->type != VOUT_WINDOW_TYPE_WAYLAND)
return VLC_EGENERIC;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment