summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2019-09-15 17:49:13 -0700
committerPhilip Langdale <philipl@overt.org>2019-09-15 17:51:47 -0700
commit237f5fa1b7302d61466991d109179f86ce00b8bb (patch)
tree91cca425a57e18083ef69b386d1f1783a0b36186
parent0abe34ed21023b83c7311d85ea317f3af7b5b89c (diff)
downloadmpv-237f5fa1b7302d61466991d109179f86ce00b8bb.tar.bz2
mpv-237f5fa1b7302d61466991d109179f86ce00b8bb.tar.xz
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.
-rw-r--r--video/out/hwdec/hwdec_cuda.c25
-rw-r--r--video/out/hwdec/hwdec_cuda.h2
-rw-r--r--video/out/hwdec/hwdec_cuda_gl.c4
-rw-r--r--video/out/hwdec/hwdec_cuda_vk.c4
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) {