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

libplacebo: add new libplacebo abstraction interface

This will help disentangle the libplacebo-based vout from the individual
pl_gpu providers (vulkan, opengl, etc.)

Rename the existing vlc_placebo_Create helper to
vlc_placebo_CreateContext to avoid symbol collision.
parent 47353b65
### libplacebo ###
LIBPLACEBO_COMMONSOURCES = video_output/libplacebo/utils.h
LIBPLACEBO_COMMONSOURCES = video_output/libplacebo/utils.h \
video_output/libplacebo/instance.h
# Trigger the c++ linker because of glslang dependency of libplacebo
LIBPLACEBO_COMMONSOURCES += dummy.cpp
......
/*****************************************************************************
* instance.c: libplacebo instance abstraction
*****************************************************************************
* Copyright (C) 2021 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_modules.h>
#include "instance.h"
#include "utils.h"
static int vlc_placebo_start(void *func, bool forced, va_list ap)
{
int (*activate)(vlc_placebo_t *, const vout_display_cfg_t *) = func;
vlc_placebo_t *pl = va_arg(ap, vlc_placebo_t *);
const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
int ret = activate(pl, cfg);
/* TODO: vlc_objres_clear, which is not in the public API. */
(void)forced;
return ret;
}
/**
* Creates a libplacebo context, and swapchain, tied to a window
*
* @param cfg vout display cfg to use as the swapchain source
* @param name module name for libplacebo GPU provider (or NULL for auto)
* @return a new context, or NULL on failure
*/
vlc_placebo_t *vlc_placebo_Create(const vout_display_cfg_t *cfg, const char *name)
{
vlc_object_t *parent = VLC_OBJECT(cfg->window);
vlc_placebo_t *pl = vlc_object_create(parent, sizeof (*pl));
if (unlikely(pl == NULL))
return NULL;
pl->sys = NULL;
pl->ops = NULL;
pl->ctx = vlc_placebo_CreateContext(VLC_OBJECT(pl));
pl->module = vlc_module_load(parent, "libplacebo gpu", name, false,
vlc_placebo_start, pl, cfg);
if (pl->module == NULL)
{
vlc_object_delete(pl);
return NULL;
}
return pl;
}
void vlc_placebo_Release(vlc_placebo_t *pl)
{
if (pl->ops)
pl->ops->close(pl);
pl_swapchain_destroy(&pl->swapchain);
pl_context_destroy(&pl->ctx);
/* TODO: use vlc_objres_clear */
vlc_object_delete(pl);
}
/*****************************************************************************
* instance.h: libplacebo instance abstraction
*****************************************************************************
* Copyright (C) 2021 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.
*****************************************************************************/
#ifndef VLC_LIBPLACEBO_INSTANCE_H
#define VLC_LIBPLACEBO_INSTANCE_H
#include <vlc_common.h>
#include <vlc_vout_display.h>
#include <libplacebo/context.h>
#include <libplacebo/swapchain.h>
#include <libplacebo/gpu.h>
struct vlc_placebo_t;
struct vlc_placebo_operations
{
void (*close)(struct vlc_placebo_t *);
};
typedef struct vlc_placebo_system_t vlc_placebo_system_t;
// Shared struct for libplacebo context / gpu / swapchain
typedef struct vlc_placebo_t
{
// fields internal to instance.c, should not be touched
struct vlc_object_t obj;
module_t *module;
vlc_placebo_system_t *sys;
struct pl_context *ctx;
const struct pl_gpu *gpu;
const struct pl_swapchain *swapchain;
const struct vlc_placebo_operations *ops;
} vlc_placebo_t;
vlc_placebo_t *vlc_placebo_Create(const vout_display_cfg_t *, const char*) VLC_USED;
void vlc_placebo_Release(vlc_placebo_t *);
#endif // VLC_LIBPLACEBO_INSTANCE_H
......@@ -43,7 +43,7 @@ static void Log(void *priv, enum pl_log_level level, const char *msg)
}
}
struct pl_context *vlc_placebo_Create(vlc_object_t *obj)
struct pl_context *vlc_placebo_CreateContext(vlc_object_t *obj)
{
return pl_context_create(PL_API_VER, &(struct pl_context_params) {
.log_level = PL_LOG_DEBUG,
......
......@@ -29,7 +29,7 @@
#include <libplacebo/utils/upload.h>
// Create a libplacebo context, hooked up to the log system; or NULL on OOM
struct pl_context *vlc_placebo_Create(vlc_object_t *);
struct pl_context *vlc_placebo_CreateContext(vlc_object_t *);
// Turn a video_format_t into the equivalent libplacebo values
struct pl_color_space vlc_placebo_ColorSpace(const video_format_t *);
......
......@@ -1140,7 +1140,7 @@ CreateSampler(struct vlc_gl_interop *interop, struct vlc_gl_t *gl,
#ifdef HAVE_LIBPLACEBO
// Create the main libplacebo context
priv->pl_ctx = vlc_placebo_Create(VLC_OBJECT(gl));
priv->pl_ctx = vlc_placebo_CreateContext(VLC_OBJECT(gl));
if (priv->pl_ctx) {
# if PL_API_VER >= 20
priv->pl_sh = pl_shader_alloc(priv->pl_ctx, &(struct pl_shader_params) {
......
......@@ -107,7 +107,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
if (sys->vk == NULL)
goto error;
sys->ctx = vlc_placebo_Create(VLC_OBJECT(sys->vk));
sys->ctx = vlc_placebo_CreateContext(VLC_OBJECT(sys->vk));
if (!sys->ctx)
goto error;
......
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