mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
0abe34ed21
commit
237f5fa1b7
|
@ -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;
|
||||
for (int i = 0; interop_inits[i]; i++) {
|
||||
if (interop_inits[i](hw)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if HAVE_VULKAN
|
||||
if (!cuda_vk_init(hw)) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!p->ext_init || !p->ext_uninit) {
|
||||
MP_VERBOSE(hw, "CUDA hwdec only works with OpenGL or Vulkan backends.\n");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue