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. --- libmpv/render_gl.h | 8 +++++++- video/out/opengl/context_drm_egl.c | 16 ++++++++++++++++ video/out/opengl/hwdec_vaegl.c | 11 ++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/libmpv/render_gl.h b/libmpv/render_gl.h index 574be86ffd..4d771f2958 100644 --- a/libmpv/render_gl.h +++ b/libmpv/render_gl.h @@ -149,7 +149,7 @@ typedef struct mpv_opengl_fbo { typedef struct mpv_opengl_drm_params { /** - * DRM fd (int). set this to -1 if invalid. + * DRM fd (int). Set to a negative number if invalid. */ int fd; @@ -169,6 +169,12 @@ typedef struct mpv_opengl_drm_params { * The atomic request pointer is usually changed at every renderloop. */ struct _drmModeAtomicReq **atomic_request_ptr; + + /** + * DRM render node. Used for VAAPI interop. + * Set to a negative number if invalid. + */ + int render_fd; } mpv_opengl_drm_params; typedef struct mpv_opengl_drm_osd_size { 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