From 237f5fa1b7302d61466991d109179f86ce00b8bb Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sun, 15 Sep 2019 17:49:13 -0700 Subject: vo_gpu: hwdec_cuda: Improve interop selection mechanism This change updates the interop selection to match what I did for VAAPI, by iterating through an array of init functions until one of them works. --- video/out/hwdec/hwdec_cuda.c | 25 ++++++++++++++----------- video/out/hwdec/hwdec_cuda.h | 2 ++ video/out/hwdec/hwdec_cuda_gl.c | 4 ++-- video/out/hwdec/hwdec_cuda_vk.c | 4 ++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/video/out/hwdec/hwdec_cuda.c b/video/out/hwdec/hwdec_cuda.c index 78eb936f17..3edc58c6eb 100644 --- a/video/out/hwdec/hwdec_cuda.c +++ b/video/out/hwdec/hwdec_cuda.c @@ -56,6 +56,16 @@ int check_cu(const struct ra_hwdec *hw, CUresult err, const char *func) #define CHECK_CU(x) check_cu(hw, (x), #x) +const static cuda_interop_init interop_inits[] = { +#if HAVE_GL + cuda_gl_init, +#endif +#if HAVE_VULKAN + cuda_vk_init, +#endif + NULL +}; + static int cuda_init(struct ra_hwdec *hw) { AVBufferRef *hw_device_ctx = NULL; @@ -76,18 +86,11 @@ static int cuda_init(struct ra_hwdec *hw) return -1; // Initialise CUDA context from backend. - // We call all possible inits because these will do nothing if the ra context - // doesn't match. -#if HAVE_GL - if (!cuda_gl_init(hw)) { - return -1; - } -#endif -#if HAVE_VULKAN - if (!cuda_vk_init(hw)) { - return -1; + for (int i = 0; interop_inits[i]; i++) { + if (interop_inits[i](hw)) { + break; + } } -#endif if (!p->ext_init || !p->ext_uninit) { MP_VERBOSE(hw, "CUDA hwdec only works with OpenGL or Vulkan backends.\n"); diff --git a/video/out/hwdec/hwdec_cuda.h b/video/out/hwdec/hwdec_cuda.h index 95a6b9c34c..fc0b3e97f8 100644 --- a/video/out/hwdec/hwdec_cuda.h +++ b/video/out/hwdec/hwdec_cuda.h @@ -50,6 +50,8 @@ struct cuda_mapper_priv { void *ext[4]; }; +typedef bool (*cuda_interop_init)(const struct ra_hwdec *hw); + bool cuda_gl_init(const struct ra_hwdec *hw); bool cuda_vk_init(const struct ra_hwdec *hw); diff --git a/video/out/hwdec/hwdec_cuda_gl.c b/video/out/hwdec/hwdec_cuda_gl.c index ba3d181a27..c87c372cfa 100644 --- a/video/out/hwdec/hwdec_cuda_gl.c +++ b/video/out/hwdec/hwdec_cuda_gl.c @@ -118,8 +118,8 @@ bool cuda_gl_init(const struct ra_hwdec *hw) { return false; } } else { - // This is not an error. - return true; + // This is not an OpenGL RA. + return false; } CUdevice display_dev; diff --git a/video/out/hwdec/hwdec_cuda_vk.c b/video/out/hwdec/hwdec_cuda_vk.c index ad51d15b4e..70a0accf42 100644 --- a/video/out/hwdec/hwdec_cuda_vk.c +++ b/video/out/hwdec/hwdec_cuda_vk.c @@ -292,8 +292,8 @@ bool cuda_vk_init(const struct ra_hwdec *hw) { return false; } } else { - // This is not an error. - return true; + // This is not a Vulkan RA. + return false; } if (!cu->cuImportExternalMemory) { -- cgit v1.2.3