From 351c083487050c88adb0e3d60f2174850f869018 Mon Sep 17 00:00:00 2001 From: Anton Kindestam Date: Thu, 28 Jun 2018 15:06:41 +0200 Subject: hwdec_vaegl: Fix VAAPI EGL interop used with gpu-context=drm Add another parameter to mpv_opengl_drm_params to hold the FD to the render node, so that the fd can be passed to hwdec_vaegl. The render node is opened in context_drm_egl and inferred from the primary device fd using drmGetRenderDeviceNameFromFd. --- video/out/opengl/context_drm_egl.c | 16 ++++++++++++++++ video/out/opengl/hwdec_vaegl.c | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'video/out') diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c index 52774d8170..72eb2e3b98 100644 --- a/video/out/opengl/context_drm_egl.c +++ b/video/out/opengl/context_drm_egl.c @@ -513,6 +513,8 @@ static void drm_egl_uninit(struct ra_ctx *ctx) p->egl.context = EGL_NO_CONTEXT; eglDestroyContext(p->egl.display, p->egl.context); + close(p->drm_params.render_fd); + if (p->kms) { kms_destroy(p->kms); p->kms = 0; @@ -664,6 +666,20 @@ static bool drm_egl_init(struct ra_ctx *ctx) p->drm_params.connector_id = p->kms->connector->connector_id; if (p->kms->atomic_context) p->drm_params.atomic_request_ptr = &p->kms->atomic_context->request; + char *rendernode_path = drmGetRenderDeviceNameFromFd(p->kms->fd); + if (rendernode_path) { + MP_VERBOSE(ctx, "Opening render node \"%s\"\n", rendernode_path); + p->drm_params.render_fd = open(rendernode_path, O_RDWR | O_CLOEXEC); + if (p->drm_params.render_fd < 0) { + MP_WARN(ctx, "Cannot open render node \"%s\": %s. VAAPI hwdec will be disabled\n", + rendernode_path, mp_strerror(errno)); + } + free(rendernode_path); + } else { + p->drm_params.render_fd = -1; + MP_VERBOSE(ctx, "Could not find path to render node. VAAPI hwdec will be disabled\n"); + } + struct ra_gl_ctx_params params = { .swap_buffers = drm_egl_swap_buffers, .external_swapchain = p->kms->atomic_context ? &drm_atomic_swapchain : diff --git a/video/out/opengl/hwdec_vaegl.c b/video/out/opengl/hwdec_vaegl.c index 1620617c03..2ff0d98df3 100644 --- a/video/out/opengl/hwdec_vaegl.c +++ b/video/out/opengl/hwdec_vaegl.c @@ -36,6 +36,7 @@ #include "video/vaapi.h" #include "common.h" #include "ra_gl.h" +#include "libmpv/render_gl.h" #ifndef GL_OES_EGL_image typedef void* GLeglImageOES; @@ -77,11 +78,11 @@ static VADisplay *create_wayland_va_display(struct ra *ra) static VADisplay *create_drm_va_display(struct ra *ra) { - int drm_fd = (intptr_t)ra_get_native_resource(ra, "drm"); - // Note: yes, drm_fd==0 could be valid - but it's rare and doesn't fit with - // our slightly crappy way of passing it through, so consider 0 not - // valid. - return drm_fd ? vaGetDisplayDRM(drm_fd) : NULL; + mpv_opengl_drm_params *params = ra_get_native_resource(ra, "drm_params"); + if (!params || params->render_fd < 0) + return NULL; + + return vaGetDisplayDRM(params->render_fd); } #endif -- cgit v1.2.3