vo: hwdec: Pass the ra_ctx to hwdecs instead of just the ra

We will need the full ra_ctx to be able to look up all the state
required to initialise an ffmpeg vulkan hwcontext, so pass let's
pass the ra_ctx instead of just the ra.
This commit is contained in:
Philip Langdale 2022-03-12 10:54:23 -08:00 committed by Philip Langdale
parent 959ef843d2
commit 085f3e31a0
28 changed files with 65 additions and 56 deletions

View File

@ -73,9 +73,9 @@ static int init(struct ra_hwdec *hw)
struct priv_owner *p = hw->priv;
HRESULT hr;
if (!ra_is_d3d11(hw->ra))
if (!ra_is_d3d11(hw->ra_ctx->ra))
return -1;
p->device = ra_d3d11_get_device(hw->ra);
p->device = ra_d3d11_get_device(hw->ra_ctx->ra);
if (!p->device)
return -1;

View File

@ -74,9 +74,9 @@ static int init(struct ra_hwdec *hw)
int ret = -1;
HRESULT hr;
if (!ra_is_d3d11(hw->ra))
if (!ra_is_d3d11(hw->ra_ctx->ra))
goto done;
p->dev11 = ra_d3d11_get_device(hw->ra);
p->dev11 = ra_d3d11_get_device(hw->ra_ctx->ra);
if (!p->dev11)
goto done;

View File

@ -83,7 +83,8 @@ const struct ra_hwdec_driver *const ra_hwdec_drivers[] = {
NULL
};
struct ra_hwdec *ra_hwdec_load_driver(struct ra *ra, struct mp_log *log,
struct ra_hwdec *ra_hwdec_load_driver(struct ra_ctx *ra_ctx,
struct mp_log *log,
struct mpv_global *global,
struct mp_hwdec_devices *devs,
const struct ra_hwdec_driver *drv,
@ -94,7 +95,7 @@ struct ra_hwdec *ra_hwdec_load_driver(struct ra *ra, struct mp_log *log,
.driver = drv,
.log = mp_log_new(hwdec, log, drv->name),
.global = global,
.ra = ra,
.ra_ctx = ra_ctx,
.devs = devs,
.probing = is_auto,
.priv = talloc_zero_size(hwdec, drv->priv_size),
@ -134,7 +135,7 @@ struct ra_hwdec_mapper *ra_hwdec_mapper_create(struct ra_hwdec *hwdec,
.owner = hwdec,
.driver = hwdec->driver->mapper,
.log = hwdec->log,
.ra = hwdec->ra,
.ra = hwdec->ra_ctx->ra,
.priv = talloc_zero_size(mapper, hwdec->driver->mapper->priv_size),
.src_params = *params,
.dst_params = *params,
@ -232,7 +233,7 @@ static void load_add_hwdec(struct ra_hwdec_ctx *ctx, struct mp_hwdec_devices *de
}
struct ra_hwdec *hwdec =
ra_hwdec_load_driver(ctx->ra, ctx->log, ctx->global, devs, drv, is_auto);
ra_hwdec_load_driver(ctx->ra_ctx, ctx->log, ctx->global, devs, drv, is_auto);
if (hwdec)
MP_TARRAY_APPEND(NULL, ctx->hwdecs, ctx->num_hwdecs, hwdec);
}
@ -249,7 +250,7 @@ static void load_hwdecs_all(struct ra_hwdec_ctx *ctx, struct mp_hwdec_devices *d
void ra_hwdec_ctx_init(struct ra_hwdec_ctx *ctx, struct mp_hwdec_devices *devs,
const char *type, bool load_all_by_default)
{
assert(ctx->ra);
assert(ctx->ra_ctx);
/*
* By default, or if the option value is "auto", we will not pre-emptively

View File

@ -2,6 +2,7 @@
#define MPGL_HWDEC_H_
#include "video/mp_image.h"
#include "context.h"
#include "ra.h"
#include "video/hwdec.h"
@ -10,7 +11,7 @@ struct ra_hwdec_ctx {
// Set these before calling `ra_hwdec_ctx_init`
struct mp_log *log;
struct mpv_global *global;
struct ra *ra;
struct ra_ctx *ra_ctx;
bool loading_done;
struct ra_hwdec **hwdecs;
@ -38,7 +39,7 @@ struct ra_hwdec {
const struct ra_hwdec_driver *driver;
struct mp_log *log;
struct mpv_global *global;
struct ra *ra;
struct ra_ctx *ra_ctx;
struct mp_hwdec_devices *devs;
// GLSL extensions required to sample textures from this.
const char **glsl_extensions;
@ -131,7 +132,8 @@ struct ra_hwdec_driver {
extern const struct ra_hwdec_driver *const ra_hwdec_drivers[];
struct ra_hwdec *ra_hwdec_load_driver(struct ra *ra, struct mp_log *log,
struct ra_hwdec *ra_hwdec_load_driver(struct ra_ctx *ra_ctx,
struct mp_log *log,
struct mpv_global *global,
struct mp_hwdec_devices *devs,
const struct ra_hwdec_driver *drv,

View File

@ -81,14 +81,14 @@ static int init(struct render_backend *ctx, mpv_render_param *params)
void *data = params[n].data;
if (entry->size)
data = talloc_memdup(p, data, entry->size);
ra_add_native_resource(p->context->ra, entry->name, data);
ra_add_native_resource(p->context->ra_ctx->ra, entry->name, data);
}
}
p->renderer = gl_video_init(p->context->ra, ctx->log, ctx->global);
p->renderer = gl_video_init(p->context->ra_ctx->ra, ctx->log, ctx->global);
ctx->hwdec_devs = hwdec_devices_create();
gl_video_init_hwdecs(p->renderer, ctx->hwdec_devs, true);
gl_video_init_hwdecs(p->renderer, p->context->ra_ctx, ctx->hwdec_devs, true);
ctx->driver_caps = VO_CAP_ROTATE90;
return 0;
}

View File

@ -9,7 +9,7 @@ struct libmpv_gpu_context {
struct mp_log *log;
const struct libmpv_gpu_context_fns *fns;
struct ra *ra;
struct ra_ctx *ra_ctx;
void *priv;
};

View File

@ -4319,14 +4319,15 @@ struct mp_image *gl_video_get_image(struct gl_video *p, int imgfmt, int w, int h
return res;
}
void gl_video_init_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
void gl_video_init_hwdecs(struct gl_video *p, struct ra_ctx *ra_ctx,
struct mp_hwdec_devices *devs,
bool load_all_by_default)
{
assert(!p->hwdec_ctx.ra);
assert(!p->hwdec_ctx.ra_ctx);
p->hwdec_ctx = (struct ra_hwdec_ctx) {
.log = p->log,
.global = p->global,
.ra = p->ra,
.ra_ctx = ra_ctx,
};
ra_hwdec_ctx_init(&p->hwdec_ctx, devs, p->opts.hwdec_interop, load_all_by_default);
@ -4335,6 +4336,6 @@ void gl_video_init_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
void gl_video_load_hwdecs_for_img_fmt(struct gl_video *p, struct mp_hwdec_devices *devs,
struct hwdec_imgfmt_request *params)
{
assert(p->hwdec_ctx.ra);
assert(p->hwdec_ctx.ra_ctx);
ra_hwdec_ctx_load_fmt(&p->hwdec_ctx, devs, params);
}

View File

@ -222,7 +222,8 @@ void gl_video_reset(struct gl_video *p);
bool gl_video_showing_interpolated_frame(struct gl_video *p);
struct mp_hwdec_devices;
void gl_video_init_hwdecs(struct gl_video *p, struct mp_hwdec_devices *devs,
void gl_video_init_hwdecs(struct gl_video *p, struct ra_ctx *ra_ctx,
struct mp_hwdec_devices *devs,
bool load_all_by_default);
struct hwdec_imgfmt_request;
void gl_video_load_hwdecs_for_img_fmt(struct gl_video *p, struct mp_hwdec_devices *devs,

View File

@ -277,7 +277,7 @@ static void vaapi_gl_unmap(struct ra_hwdec_mapper *mapper)
bool dmabuf_interop_gl_init(const struct ra_hwdec *hw,
struct dmabuf_interop *dmabuf_interop)
{
if (!ra_is_gl(hw->ra)) {
if (!ra_is_gl(hw->ra_ctx->ra)) {
// This is not an OpenGL RA.
return false;
}
@ -289,7 +289,7 @@ bool dmabuf_interop_gl_init(const struct ra_hwdec *hw,
if (!exts)
return false;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (!gl_check_extension(exts, "EGL_EXT_image_dma_buf_import") ||
!gl_check_extension(exts, "EGL_KHR_image_base") ||
!gl_check_extension(gl->extensions, "GL_OES_EGL_image") ||

View File

@ -117,7 +117,7 @@ static void vaapi_pl_unmap(struct ra_hwdec_mapper *mapper)
bool dmabuf_interop_pl_init(const struct ra_hwdec *hw,
struct dmabuf_interop *dmabuf_interop)
{
pl_gpu gpu = ra_pl_get(hw->ra);
pl_gpu gpu = ra_pl_get(hw->ra_ctx->ra);
if (!gpu) {
// This is not a libplacebo RA;
return false;

View File

@ -67,7 +67,7 @@ static void unmap(struct ra_hwdec_mapper *mapper)
bool dmabuf_interop_wl_init(const struct ra_hwdec *hw,
struct dmabuf_interop *dmabuf_interop)
{
if (!ra_is_wldmabuf(hw->ra))
if (!ra_is_wldmabuf(hw->ra_ctx->ra))
return false;
if (strstr(hw->driver->name, "vaapi") != NULL)

View File

@ -129,7 +129,7 @@ static int init(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(hw->ra_ctx->ra))
return -1;
if (!eglGetCurrentContext())
return -1;

View File

@ -110,8 +110,8 @@ bool cuda_gl_init(const struct ra_hwdec *hw) {
struct cuda_hw_priv *p = hw->priv;
CudaFunctions *cu = p->cu;
if (ra_is_gl(hw->ra)) {
GL *gl = ra_gl_get(hw->ra);
if (ra_is_gl(hw->ra_ctx->ra)) {
GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (gl->version < 210 && gl->es < 300) {
MP_VERBOSE(hw, "need OpenGL >= 2.1 or OpenGL-ES >= 3.0\n");
return false;

View File

@ -263,7 +263,7 @@ bool cuda_vk_init(const struct ra_hwdec *hw) {
struct cuda_hw_priv *p = hw->priv;
CudaFunctions *cu = p->cu;
pl_gpu gpu = ra_pl_get(hw->ra);
pl_gpu gpu = ra_pl_get(hw->ra_ctx->ra);
if (gpu != NULL) {
if (!(gpu->export_caps.tex & HANDLE_TYPE)) {
MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable texture memory of type 0x%X.\n",

View File

@ -83,7 +83,7 @@ static int init(struct ra_hwdec *hw)
* there are extensions that supposedly provide this information from the
* drivers. Not properly documented. Of course.
*/
mpv_opengl_drm_params_v2 *params = ra_get_native_resource(hw->ra,
mpv_opengl_drm_params_v2 *params = ra_get_native_resource(hw->ra_ctx->ra,
"drm_params_v2");
/*

View File

@ -148,10 +148,12 @@ static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
struct drm_frame next_frame = {0};
int ret;
struct ra *ra = hw->ra_ctx->ra;
// grab atomic request from native resources
if (p->ctx) {
struct mpv_opengl_drm_params_v2 *drm_params;
drm_params = (mpv_opengl_drm_params_v2 *)ra_get_native_resource(hw->ra, "drm_params_v2");
drm_params = (mpv_opengl_drm_params_v2 *)ra_get_native_resource(ra, "drm_params_v2");
if (!drm_params) {
MP_ERR(hw, "Failed to retrieve drm params from native resources\n");
return -1;
@ -168,7 +170,7 @@ static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
// grab draw plane windowing info to eventually upscale the overlay
// as egl windows could be upscaled to draw plane.
struct mpv_opengl_drm_draw_surface_size *draw_surface_size = ra_get_native_resource(hw->ra, "drm_draw_surface_size");
struct mpv_opengl_drm_draw_surface_size *draw_surface_size = ra_get_native_resource(ra, "drm_draw_surface_size");
if (draw_surface_size) {
scale_dst_rect(hw, draw_surface_size->width, draw_surface_size->height, dst, &p->dst);
} else {
@ -259,7 +261,7 @@ static int init(struct ra_hwdec *hw)
struct mpv_opengl_drm_params_v2 *drm_params;
drm_params = ra_get_native_resource(hw->ra, "drm_params_v2");
drm_params = ra_get_native_resource(hw->ra_ctx->ra, "drm_params_v2");
if (drm_params) {
p->ctx = drm_atomic_create_context(p->log, drm_params->fd, drm_params->crtc_id,
drm_params->connector_id, draw_plane, drmprime_video_plane);

View File

@ -146,7 +146,7 @@ static int init(struct ra_hwdec *hw)
return -1;
}
p->display = create_native_va_display(hw->ra, hw->log);
p->display = create_native_va_display(hw->ra_ctx->ra, hw->log);
if (!p->display) {
MP_VERBOSE(hw, "Could not create a VA display.\n");
return -1;
@ -172,7 +172,7 @@ static int init(struct ra_hwdec *hw)
}
// it's now safe to set the display resource
ra_add_native_resource(hw->ra, "VADisplay", p->display);
ra_add_native_resource(hw->ra_ctx->ra, "VADisplay", p->display);
p->ctx->hwctx.hw_imgfmt = IMGFMT_VAAPI;
p->ctx->hwctx.supported_formats = p->formats;

View File

@ -86,7 +86,7 @@ static int init(struct ra_hwdec *hw)
struct priv_owner *p = hw->priv;
HRESULT hr;
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(hw->ra_ctx->ra))
return -1;
if (!angle_load())
return -1;
@ -98,7 +98,7 @@ static int init(struct ra_hwdec *hw)
if (!eglGetCurrentContext())
return -1;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(hw->ra_ctx->ra);
const char *exts = eglQueryString(egl_display, EGL_EXTENSIONS);
if (!gl_check_extension(exts, "EGL_ANGLE_d3d_share_handle_client_buffer") ||

View File

@ -73,7 +73,7 @@ static int init(struct ra_hwdec *hw)
struct priv_owner *p = hw->priv;
HRESULT hr;
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(hw->ra_ctx->ra))
return -1;
if (!angle_load())
return -1;

View File

@ -58,21 +58,22 @@ static void uninit(struct ra_hwdec *hw)
static int init(struct ra_hwdec *hw)
{
struct priv_owner *p = hw->priv;
struct ra *ra = hw->ra_ctx->ra;
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(ra))
return -1;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(ra);
if (!(gl->mpgl_caps & MPGL_CAP_DXINTEROP))
return -1;
// AMD drivers won't open multiple dxinterop HANDLES on the same D3D device,
// so we request the one already in use by context_dxinterop
p->device_h = ra_get_native_resource(hw->ra, "dxinterop_device_HANDLE");
p->device_h = ra_get_native_resource(ra, "dxinterop_device_HANDLE");
if (!p->device_h)
return -1;
// But we also still need the actual D3D device
p->device = ra_get_native_resource(hw->ra, "IDirect3DDevice9Ex");
p->device = ra_get_native_resource(ra, "IDirect3DDevice9Ex");
if (!p->device)
return -1;
IDirect3DDevice9Ex_AddRef(p->device);

View File

@ -42,10 +42,10 @@ struct priv {
static bool check_hwdec(struct ra_hwdec *hw)
{
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(hw->ra_ctx->ra))
return false;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (gl->es < 200) {
MP_ERR(hw, "need OpenGLES 2.0 for CVOpenGLESTextureCacheCreateTextureFromImage()\n");
return false;

View File

@ -43,10 +43,10 @@ struct priv {
static bool check_hwdec(struct ra_hwdec *hw)
{
if (!ra_is_gl(hw->ra))
if (!ra_is_gl(hw->ra_ctx->ra))
return false;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (gl->version < 300) {
MP_ERR(hw, "need >= OpenGL 3.0 for core rectangle texture support\n");
return false;

View File

@ -130,7 +130,7 @@ static void update_overlay(struct ra_hwdec *hw, bool check_window_only)
struct mp_rect dst = p->dst;
int defs[4] = {0, 0, 0, 0};
int *z = ra_get_native_resource(hw->ra, "MPV_RPI_WINDOW");
int *z = ra_get_native_resource(hw->ra_ctx->ra, "MPV_RPI_WINDOW");
if (!z)
z = defs;

View File

@ -46,10 +46,11 @@ struct priv {
static int init(struct ra_hwdec *hw)
{
Display *x11disp = ra_get_native_resource(hw->ra, "x11");
if (!x11disp || !ra_is_gl(hw->ra))
struct ra *ra = hw->ra_ctx->ra;
Display *x11disp = ra_get_native_resource(ra, "x11");
if (!x11disp || !ra_is_gl(ra))
return -1;
GL *gl = ra_gl_get(hw->ra);
GL *gl = ra_gl_get(ra);
if (!(gl->mpgl_caps & MPGL_CAP_VDPAU))
return -1;
struct priv_owner *p = hw->priv;

View File

@ -60,7 +60,7 @@ static int init(struct libmpv_gpu_context *ctx, mpv_render_param *params)
p->gl->debug_context = debug;
ra_gl_set_debug(p->ra_ctx->ra, debug);
ctx->ra = p->ra_ctx->ra;
ctx->ra_ctx = p->ra_ctx;
return 0;
}

View File

@ -423,7 +423,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_LOAD_HWDEC_API:
assert(p->hwdec_ctx.ra);
assert(p->hwdec_ctx.ra_ctx);
struct hwdec_imgfmt_request* req = (struct hwdec_imgfmt_request*)data;
if (!is_supported_fmt(req->imgfmt))
return 0;
@ -529,11 +529,11 @@ static int preinit(struct vo *vo)
vo->hwdec_devs = hwdec_devices_create();
hwdec_devices_set_loader(vo->hwdec_devs, call_request_hwdec_api, vo);
assert(!p->hwdec_ctx.ra);
assert(!p->hwdec_ctx.ra_ctx);
p->hwdec_ctx = (struct ra_hwdec_ctx) {
.log = p->log,
.global = p->global,
.ra = p->ctx->ra,
.ra_ctx = p->ctx,
};
ra_hwdec_ctx_init(&p->hwdec_ctx, vo->hwdec_devs, NULL, true);

View File

@ -308,7 +308,7 @@ static int preinit(struct vo *vo)
vo->hwdec_devs = hwdec_devices_create();
hwdec_devices_set_loader(vo->hwdec_devs, call_request_hwdec_api, vo);
gl_video_init_hwdecs(p->renderer, vo->hwdec_devs, false);
gl_video_init_hwdecs(p->renderer, p->ctx, vo->hwdec_devs, false);
return 0;

View File

@ -1453,7 +1453,7 @@ static int preinit(struct vo *vo)
p->hwdec_ctx = (struct ra_hwdec_ctx) {
.log = p->log,
.global = p->global,
.ra = p->ra_ctx->ra,
.ra_ctx = p->ra_ctx,
};
vo->hwdec_devs = hwdec_devices_create();