vo_gpu_next: factor out context-specific code to gpu_next/context.c

This is done to avoid cluttering vo_gpu_next.c with more ifdeffery and context-specific code
when additional backends are added in the near future.
Eventually gpu_ctx is intended to take the place of ra_ctx to further separate gpu and gpu_next.
This commit is contained in:
sfan5 2021-11-20 20:59:37 +01:00
parent f32ea013dd
commit d5d62c6a64
5 changed files with 141 additions and 28 deletions

View File

@ -979,7 +979,8 @@ if libplacebo.found()
features += 'libplacebo-v4' features += 'libplacebo-v4'
libplacebo_v4 = true libplacebo_v4 = true
message('libplacebo v4.170+ found! Enabling vo_gpu_next.') message('libplacebo v4.170+ found! Enabling vo_gpu_next.')
sources += files('video/out/vo_gpu_next.c') sources += files('video/out/vo_gpu_next.c',
'video/out/gpu_next/context.c')
else else
message('libplacebo v4.170+ not found! Disabling vo_gpu_next.') message('libplacebo v4.170+ not found! Disabling vo_gpu_next.')
endif endif

View File

@ -0,0 +1,80 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#include <libplacebo/config.h>
#include "context.h"
#include "config.h"
#include "common/common.h"
#include "options/m_config.h"
#include "video/out/placebo/utils.h"
#include "video/out/gpu/video.h"
#if HAVE_VULKAN
#include "video/out/vulkan/context.h"
#endif
struct priv {
char dummy;
};
struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts)
{
struct gpu_ctx *ctx = talloc_zero(NULL, struct gpu_ctx);
ctx->log = vo->log;
ctx->priv = talloc_zero(ctx, struct priv);
struct ra_ctx_opts *ctx_opts = mp_get_config_group(ctx, vo->global, &ra_ctx_conf);
ctx_opts->want_alpha = gl_opts->alpha_mode == ALPHA_YES;
ctx->ra_ctx = ra_ctx_create(vo, *ctx_opts);
if (!ctx->ra_ctx)
goto err_out;
#if HAVE_VULKAN
struct mpvk_ctx *vkctx = ra_vk_ctx_get(ctx->ra_ctx);
if (vkctx) {
ctx->pllog = vkctx->ctx;
ctx->gpu = vkctx->gpu;
ctx->swapchain = vkctx->swapchain;
return ctx;
}
#endif
// TODO: wrap GL contexts
err_out:
gpu_ctx_destroy(&ctx);
return NULL;
}
bool gpu_ctx_resize(struct gpu_ctx *ctx, int w, int h)
{
// Not (yet) used
return true;
}
void gpu_ctx_destroy(struct gpu_ctx **ctxp)
{
struct gpu_ctx *ctx = *ctxp;
if (!ctx)
return;
ra_ctx_destroy(&ctx->ra_ctx);
talloc_free(ctx);
*ctxp = NULL;
}

View File

@ -0,0 +1,41 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <libplacebo/renderer.h>
struct mp_log;
struct ra_ctx;
struct vo;
struct gl_video_opts;
struct gpu_ctx {
struct mp_log *log;
struct ra_ctx *ra_ctx;
pl_log pllog;
pl_gpu gpu;
pl_swapchain swapchain;
void *priv;
};
struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts);
bool gpu_ctx_resize(struct gpu_ctx *ctx, int w, int h);
void gpu_ctx_destroy(struct gpu_ctx **ctxp);

View File

@ -39,10 +39,7 @@
#include "gpu/video.h" #include "gpu/video.h"
#include "gpu/video_shaders.h" #include "gpu/video_shaders.h"
#include "sub/osd.h" #include "sub/osd.h"
#include "gpu_next/context.h"
#if HAVE_VULKAN
#include "vulkan/context.h"
#endif
struct osd_entry { struct osd_entry {
pl_tex tex; pl_tex tex;
@ -77,6 +74,7 @@ struct priv {
struct mp_log *log; struct mp_log *log;
struct mpv_global *global; struct mpv_global *global;
struct ra_ctx *ra_ctx; struct ra_ctx *ra_ctx;
struct gpu_ctx *context;
pl_log pllog; pl_log pllog;
pl_gpu gpu; pl_gpu gpu;
@ -809,6 +807,7 @@ static void resize(struct vo *vo)
{ {
struct priv *p = vo->priv; struct priv *p = vo->priv;
vo_get_src_dst_rects(vo, &p->src, &p->dst, &p->osd_res); vo_get_src_dst_rects(vo, &p->src, &p->dst, &p->osd_res);
gpu_ctx_resize(p->context, vo->dwidth, vo->dheight);
vo->want_redraw = true; vo->want_redraw = true;
} }
@ -966,7 +965,12 @@ static void uninit(struct vo *vo)
} }
pl_renderer_destroy(&p->rr); pl_renderer_destroy(&p->rr);
ra_ctx_destroy(&p->ra_ctx);
p->ra_ctx = NULL;
p->pllog = NULL;
p->gpu = NULL;
p->sw = NULL;
gpu_ctx_destroy(&p->context);
} }
static int preinit(struct vo *vo) static int preinit(struct vo *vo)
@ -978,30 +982,16 @@ static int preinit(struct vo *vo)
p->log = vo->log; p->log = vo->log;
struct gl_video_opts *gl_opts = p->opts_cache->opts; struct gl_video_opts *gl_opts = p->opts_cache->opts;
struct ra_ctx_opts *ctx_opts = mp_get_config_group(p, vo->global, &ra_ctx_conf);
struct ra_ctx_opts opts = *ctx_opts; p->context = gpu_ctx_create(vo, gl_opts);
opts.context_type = "vulkan"; if (!p->context)
opts.context_name = NULL;
opts.want_alpha = gl_opts->alpha_mode == ALPHA_YES;
p->ra_ctx = ra_ctx_create(vo, opts);
if (!p->ra_ctx)
goto err_out; goto err_out;
// For the time being
p->ra_ctx = p->context->ra_ctx;
p->pllog = p->context->pllog;
p->gpu = p->context->gpu;
p->sw = p->context->swapchain;
#if HAVE_VULKAN
struct mpvk_ctx *vkctx = ra_vk_ctx_get(p->ra_ctx);
if (vkctx) {
p->pllog = vkctx->ctx;
p->gpu = vkctx->gpu;
p->sw = vkctx->swapchain;
goto done;
}
#endif
// TODO: wrap GL contexts
goto err_out;
done:
p->rr = pl_renderer_create(p->pllog, p->gpu); p->rr = pl_renderer_create(p->pllog, p->gpu);
p->queue = pl_queue_create(p->gpu); p->queue = pl_queue_create(p->gpu);
p->osd_fmt[SUBBITMAP_LIBASS] = pl_find_named_fmt(p->gpu, "r8"); p->osd_fmt[SUBBITMAP_LIBASS] = pl_find_named_fmt(p->gpu, "r8");

View File

@ -451,6 +451,7 @@ def build(ctx):
( "video/out/gpu/utils.c" ), ( "video/out/gpu/utils.c" ),
( "video/out/gpu/video.c" ), ( "video/out/gpu/video.c" ),
( "video/out/gpu/video_shaders.c" ), ( "video/out/gpu/video_shaders.c" ),
( "video/out/gpu_next/context.c", "libplacebo-v4" ),
( "video/out/hwdec/hwdec_cuda.c", "cuda-interop" ), ( "video/out/hwdec/hwdec_cuda.c", "cuda-interop" ),
( "video/out/hwdec/hwdec_cuda_gl.c", "cuda-interop && gl" ), ( "video/out/hwdec/hwdec_cuda_gl.c", "cuda-interop && gl" ),
( "video/out/hwdec/hwdec_cuda_vk.c", "cuda-interop && vulkan" ), ( "video/out/hwdec/hwdec_cuda_vk.c", "cuda-interop && vulkan" ),