From b091dfda711a9e0470f6724b13a7669bbaab907f Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 16 Jan 2023 22:28:24 +0100 Subject: hwdec_cuda: drop support for PL_HANDLE_WIN32_KMT This handle type was only needed for backwards compatibility with windows 7. Dropping it allows us to simplify the code: there is no longer a need for runtime checks, as the handle type can now be statically assigned based on the platform. The motivating usecase here, apart from code simplification, is a desired switch to timeline semaphores, which (in the CUDA API) only supports the non-KMT win32 handles. It's worth pointing out that we need no runtime check for IsWindows8OrGreater(), because the `export_caps.sync` check will already fail on versions of windows not supporting PL_HANDLE_WIN32. --- video/out/hwdec/hwdec_cuda.h | 3 --- video/out/hwdec/hwdec_cuda_vk.c | 49 ++++++++++++++--------------------------- 2 files changed, 17 insertions(+), 35 deletions(-) (limited to 'video/out') diff --git a/video/out/hwdec/hwdec_cuda.h b/video/out/hwdec/hwdec_cuda.h index 1d42505179..9c55053d59 100644 --- a/video/out/hwdec/hwdec_cuda.h +++ b/video/out/hwdec/hwdec_cuda.h @@ -29,9 +29,6 @@ struct cuda_hw_priv { CUcontext display_ctx; CUcontext decode_ctx; - // Stored as int to avoid depending on libplacebo enum - int handle_type; - // Do we need to do a full CPU sync after copying bool do_full_sync; diff --git a/video/out/hwdec/hwdec_cuda_vk.c b/video/out/hwdec/hwdec_cuda_vk.c index 3b058d740f..beca291e7f 100644 --- a/video/out/hwdec/hwdec_cuda_vk.c +++ b/video/out/hwdec/hwdec_cuda_vk.c @@ -27,6 +27,9 @@ #if HAVE_WIN32_DESKTOP #include +#define HANDLE_TYPE PL_HANDLE_WIN32 +#else +#define HANDLE_TYPE PL_HANDLE_FD #endif #define CHECK_CU(x) check_cu((mapper)->owner, (x), #x) @@ -62,7 +65,7 @@ static bool cuda_ext_vk_init(struct ra_hwdec_mapper *mapper, .d = 0, .format = ra_pl_fmt_get(format), .sampleable = true, - .export_handle = p_owner->handle_type, + .export_handle = HANDLE_TYPE, }; evk->pltex = pl_tex_create(gpu, &tex_params); @@ -80,19 +83,14 @@ static bool cuda_ext_vk_init(struct ra_hwdec_mapper *mapper, mapper->tex[n] = ratex; #if !HAVE_WIN32_DESKTOP - if (evk->pltex->params.export_handle == PL_HANDLE_FD) { - mem_fd = dup(evk->pltex->shared_mem.handle.fd); - if (mem_fd < 0) { - goto error; - } - } + mem_fd = dup(evk->pltex->shared_mem.handle.fd); + if (mem_fd < 0) + goto error; #endif CUDA_EXTERNAL_MEMORY_HANDLE_DESC ext_desc = { #if HAVE_WIN32_DESKTOP - .type = IsWindows8OrGreater() - ? CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32 - : CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT, + .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32, .handle.win32.handle = evk->pltex->shared_mem.handle.handle, #else .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD, @@ -141,24 +139,20 @@ static bool cuda_ext_vk_init(struct ra_hwdec_mapper *mapper, if (ret < 0) goto error; - evk->sync = pl_sync_create(gpu, p_owner->handle_type); + evk->sync = pl_sync_create(gpu, HANDLE_TYPE); if (!evk->sync) { ret = -1; goto error; } #if !HAVE_WIN32_DESKTOP - if (evk->sync->handle_type == PL_HANDLE_FD) { - wait_fd = dup(evk->sync->wait_handle.fd); - signal_fd = dup(evk->sync->signal_handle.fd); - } + wait_fd = dup(evk->sync->wait_handle.fd); + signal_fd = dup(evk->sync->signal_handle.fd); #endif CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC w_desc = { #if HAVE_WIN32_DESKTOP - .type = IsWindows8OrGreater() - ? CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32 - : CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT, + .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32, .handle.win32.handle = evk->sync->wait_handle.handle, #else .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD, @@ -172,9 +166,7 @@ static bool cuda_ext_vk_init(struct ra_hwdec_mapper *mapper, CUDA_EXTERNAL_SEMAPHORE_HANDLE_DESC s_desc = { #if HAVE_WIN32_DESKTOP - .type = IsWindows8OrGreater() - ? CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32 - : CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT, + .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32, .handle.win32.handle = evk->sync->signal_handle.handle, #else .type = CU_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD, @@ -271,22 +263,15 @@ bool cuda_vk_init(const struct ra_hwdec *hw) { struct cuda_hw_priv *p = hw->priv; CudaFunctions *cu = p->cu; - p->handle_type = -#if HAVE_WIN32_DESKTOP - IsWindows8OrGreater() ? PL_HANDLE_WIN32 : PL_HANDLE_WIN32_KMT; -#else - PL_HANDLE_FD; -#endif - pl_gpu gpu = ra_pl_get(hw->ra); if (gpu != NULL) { - if (!(gpu->export_caps.tex & p->handle_type)) { + if (!(gpu->export_caps.tex & HANDLE_TYPE)) { MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable texture memory of type 0x%X.\n", - p->handle_type); + HANDLE_TYPE); return false; - } else if (!(gpu->export_caps.sync & p->handle_type)) { + } else if (!(gpu->export_caps.sync & HANDLE_TYPE)) { MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable semaphores of type 0x%X.\n", - p->handle_type); + HANDLE_TYPE); return false; } } else { -- cgit v1.2.3