From e2c02a4ce3af792251839307c42c85aa34bdd125 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Sat, 26 Feb 2022 15:13:10 +0100 Subject: hwdec_vaapi_vk: rename to vaapi_pl There's really nothing vulkan-specific about this hwdec wrapper, and it actually works perfectly fine with an OpenGL-based ra_pl. This is not hugely important at the time, but I still think it makes sense in case we ever decide to make vo_gpu_next wrap OpenGL contexts to ra_pl instead of exposing the underlying ra_gl. --- video/out/hwdec/hwdec_vaapi.c | 4 +- video/out/hwdec/hwdec_vaapi.h | 3 +- video/out/hwdec/hwdec_vaapi_pl.c | 132 +++++++++++++++++++++++++++++++++++++++ video/out/hwdec/hwdec_vaapi_vk.c | 132 --------------------------------------- 4 files changed, 135 insertions(+), 136 deletions(-) create mode 100644 video/out/hwdec/hwdec_vaapi_pl.c delete mode 100644 video/out/hwdec/hwdec_vaapi_vk.c (limited to 'video/out') diff --git a/video/out/hwdec/hwdec_vaapi.c b/video/out/hwdec/hwdec_vaapi.c index 7f3fb5ed25..01b5be476c 100644 --- a/video/out/hwdec/hwdec_vaapi.c +++ b/video/out/hwdec/hwdec_vaapi.c @@ -111,8 +111,8 @@ const static vaapi_interop_init interop_inits[] = { #if HAVE_VAAPI_EGL vaapi_gl_init, #endif -#if HAVE_VAAPI_VULKAN - vaapi_vk_init, +#if HAVE_VAAPI_LIBPLACEBO + vaapi_pl_init, #endif NULL }; diff --git a/video/out/hwdec/hwdec_vaapi.h b/video/out/hwdec/hwdec_vaapi.h index 44379e8bf6..76f1c37c13 100644 --- a/video/out/hwdec/hwdec_vaapi.h +++ b/video/out/hwdec/hwdec_vaapi.h @@ -52,5 +52,4 @@ struct priv { typedef bool (*vaapi_interop_init)(const struct ra_hwdec *hw); bool vaapi_gl_init(const struct ra_hwdec *hw); - -bool vaapi_vk_init(const struct ra_hwdec *hw); +bool vaapi_pl_init(const struct ra_hwdec *hw); diff --git a/video/out/hwdec/hwdec_vaapi_pl.c b/video/out/hwdec/hwdec_vaapi_pl.c new file mode 100644 index 0000000000..790150e223 --- /dev/null +++ b/video/out/hwdec/hwdec_vaapi_pl.c @@ -0,0 +1,132 @@ +/* + * 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 . + */ + +#include +#include + +#include "config.h" +#include "hwdec_vaapi.h" +#include "video/out/placebo/ra_pl.h" +#include "video/out/placebo/utils.h" + +static bool vaapi_pl_map(struct ra_hwdec_mapper *mapper, bool probing) +{ + struct priv *p = mapper->priv; + pl_gpu gpu = ra_pl_get(mapper->ra); + + struct ra_imgfmt_desc desc = {0}; + if (!ra_get_imgfmt_desc(mapper->ra, mapper->dst_params.imgfmt, &desc)) + return false; + + for (int n = 0; n < p->num_planes; n++) { + if (p->desc.layers[n].num_planes > 1) { + // Should never happen because we request separate layers + MP_ERR(mapper, "Multi-plane VA surfaces are not supported\n"); + return false; + } + + const struct ra_format *format = desc.planes[n]; + int id = p->desc.layers[n].object_index[0]; + int fd = p->desc.objects[id].fd; + uint32_t size = p->desc.objects[id].size; + uint32_t offset = p->desc.layers[n].offset[0]; + uint32_t pitch = p->desc.layers[n].pitch[0]; + + // AMD drivers do not return the size in the surface description, so we + // need to query it manually. + if (size == 0) { + size = lseek(fd, 0, SEEK_END); + if (size == -1) { + MP_ERR(mapper, "Cannot obtain size of object with fd %d: %s\n", + fd, mp_strerror(errno)); + return false; + } + off_t err = lseek(fd, 0, SEEK_SET); + if (err == -1) { + MP_ERR(mapper, "Failed to reset offset for fd %d: %s\n", + fd, mp_strerror(errno)); + return false; + } + } + + struct pl_tex_params tex_params = { + .w = mp_image_plane_w(&p->layout, n), + .h = mp_image_plane_h(&p->layout, n), + .d = 0, + .format = format->priv, + .sampleable = true, + .import_handle = PL_HANDLE_DMA_BUF, + .shared_mem = (struct pl_shared_mem) { + .handle = { + .fd = fd, + }, + .size = size, + .offset = offset, + .drm_format_mod = p->desc.objects[id].drm_format_modifier, + .stride_w = pitch, + }, + }; + + mppl_log_set_probing(gpu->log, probing); + pl_tex pltex = pl_tex_create(gpu, &tex_params); + mppl_log_set_probing(gpu->log, false); + if (!pltex) + return false; + + struct ra_tex *ratex = talloc_ptrtype(NULL, ratex); + int ret = mppl_wrap_tex(mapper->ra, pltex, ratex); + if (!ret) { + pl_tex_destroy(gpu, &pltex); + talloc_free(ratex); + return false; + } + mapper->tex[n] = ratex; + + MP_TRACE(mapper, "Object %d with fd %d imported as %p\n", + id, fd, ratex); + } + return true; +} + +static void vaapi_pl_unmap(struct ra_hwdec_mapper *mapper) +{ + for (int n = 0; n < 4; n++) + ra_tex_free(mapper->ra, &mapper->tex[n]); +} + +bool vaapi_pl_init(const struct ra_hwdec *hw) +{ + struct priv_owner *p = hw->priv; + pl_gpu gpu = ra_pl_get(hw->ra); + if (!gpu) { + // This is not a libplacebo RA; + return false; + } + + if (!(gpu->import_caps.tex & PL_HANDLE_DMA_BUF)) { + MP_VERBOSE(hw, "VAAPI libplacebo interop requires support for " + "PL_HANDLE_DMA_BUF import.\n"); + return false; + } + + MP_VERBOSE(hw, "using VAAPI libplacebo interop\n"); + + p->interop_map = vaapi_pl_map; + p->interop_unmap = vaapi_pl_unmap; + + return true; +} diff --git a/video/out/hwdec/hwdec_vaapi_vk.c b/video/out/hwdec/hwdec_vaapi_vk.c deleted file mode 100644 index 38ac76a3a7..0000000000 --- a/video/out/hwdec/hwdec_vaapi_vk.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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 . - */ - -#include -#include - -#include "config.h" -#include "hwdec_vaapi.h" -#include "video/out/placebo/ra_pl.h" -#include "video/out/placebo/utils.h" - -static bool vaapi_vk_map(struct ra_hwdec_mapper *mapper, bool probing) -{ - struct priv *p = mapper->priv; - pl_gpu gpu = ra_pl_get(mapper->ra); - - struct ra_imgfmt_desc desc = {0}; - if (!ra_get_imgfmt_desc(mapper->ra, mapper->dst_params.imgfmt, &desc)) - return false; - - for (int n = 0; n < p->num_planes; n++) { - if (p->desc.layers[n].num_planes > 1) { - // Should never happen because we request separate layers - MP_ERR(mapper, "Multi-plane VA surfaces are not supported\n"); - return false; - } - - const struct ra_format *format = desc.planes[n]; - int id = p->desc.layers[n].object_index[0]; - int fd = p->desc.objects[id].fd; - uint32_t size = p->desc.objects[id].size; - uint32_t offset = p->desc.layers[n].offset[0]; - uint32_t pitch = p->desc.layers[n].pitch[0]; - - // AMD drivers do not return the size in the surface description, so we - // need to query it manually. - if (size == 0) { - size = lseek(fd, 0, SEEK_END); - if (size == -1) { - MP_ERR(mapper, "Cannot obtain size of object with fd %d: %s\n", - fd, mp_strerror(errno)); - return false; - } - off_t err = lseek(fd, 0, SEEK_SET); - if (err == -1) { - MP_ERR(mapper, "Failed to reset offset for fd %d: %s\n", - fd, mp_strerror(errno)); - return false; - } - } - - struct pl_tex_params tex_params = { - .w = mp_image_plane_w(&p->layout, n), - .h = mp_image_plane_h(&p->layout, n), - .d = 0, - .format = format->priv, - .sampleable = true, - .import_handle = PL_HANDLE_DMA_BUF, - .shared_mem = (struct pl_shared_mem) { - .handle = { - .fd = fd, - }, - .size = size, - .offset = offset, - .drm_format_mod = p->desc.objects[id].drm_format_modifier, - .stride_w = pitch, - }, - }; - - mppl_log_set_probing(gpu->log, probing); - pl_tex pltex = pl_tex_create(gpu, &tex_params); - mppl_log_set_probing(gpu->log, false); - if (!pltex) - return false; - - struct ra_tex *ratex = talloc_ptrtype(NULL, ratex); - int ret = mppl_wrap_tex(mapper->ra, pltex, ratex); - if (!ret) { - pl_tex_destroy(gpu, &pltex); - talloc_free(ratex); - return false; - } - mapper->tex[n] = ratex; - - MP_TRACE(mapper, "Object %d with fd %d imported as %p\n", - id, fd, ratex); - } - return true; -} - -static void vaapi_vk_unmap(struct ra_hwdec_mapper *mapper) -{ - for (int n = 0; n < 4; n++) - ra_tex_free(mapper->ra, &mapper->tex[n]); -} - -bool vaapi_vk_init(const struct ra_hwdec *hw) -{ - struct priv_owner *p = hw->priv; - pl_gpu gpu = ra_pl_get(hw->ra); - if (!gpu) { - // This is not a Vulkan RA; - return false; - } - - if (!(gpu->import_caps.tex & PL_HANDLE_DMA_BUF)) { - MP_VERBOSE(hw, "VAAPI Vulkan interop requires support for " - "dma_buf import in Vulkan.\n"); - return false; - } - - MP_VERBOSE(hw, "using VAAPI Vulkan interop\n"); - - p->interop_map = vaapi_vk_map; - p->interop_unmap = vaapi_vk_unmap; - - return true; -} -- cgit v1.2.3