Skip to content

Commit

Permalink
hwdec_cuda: reduce nesting in check functions
Browse files Browse the repository at this point in the history
This simplifies the code and makes it easier to read.
  • Loading branch information
jrelvas-ipc authored and kasper93 committed May 6, 2024
1 parent 58f50c8 commit 1759d73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
14 changes: 6 additions & 8 deletions video/out/hwdec/hwdec_cuda_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ static void cuda_ext_gl_uninit(const struct ra_hwdec_mapper *mapper, int n)
#define CHECK_CU(x) check_cu(hw, (x), #x)

static bool cuda_gl_check(const struct ra_hwdec *hw) {
if (ra_is_gl(hw->ra_ctx->ra)) {
GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (gl->version < 210 && gl->es < 300) {
MP_VERBOSE(hw, "need OpenGL >= 2.1 or OpenGL-ES >= 3.0\n");
return false;
}
} else {
// This is not an OpenGL RA.
if (!ra_is_gl(hw->ra_ctx->ra))
return false; // This is not an OpenGL RA.

GL *gl = ra_gl_get(hw->ra_ctx->ra);
if (gl->version < 210 && gl->es < 300) {
MP_VERBOSE(hw, "need OpenGL >= 2.1 or OpenGL-ES >= 3.0\n");
return false;
}

Expand Down
22 changes: 10 additions & 12 deletions video/out/hwdec/hwdec_cuda_vk.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,16 @@ static bool cuda_ext_vk_signal(const struct ra_hwdec_mapper *mapper, int n)

static bool cuda_vk_check(const struct ra_hwdec *hw) {
pl_gpu gpu = ra_pl_get(hw->ra_ctx->ra);
if (gpu != NULL) {
if (!(gpu->export_caps.tex & HANDLE_TYPE)) {
MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable texture memory of type 0x%X.\n",
HANDLE_TYPE);
return false;
} else if (!(gpu->export_caps.sync & HANDLE_TYPE)) {
MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable semaphores of type 0x%X.\n",
HANDLE_TYPE);
return false;
}
} else {
// This is not a Vulkan RA.
if (gpu == NULL)
return false; // This is not a Vulkan RA.

if (!(gpu->export_caps.tex & HANDLE_TYPE)) {
MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable texture memory of type 0x%X.\n",
HANDLE_TYPE);
return false;
} else if (!(gpu->export_caps.sync & HANDLE_TYPE)) {
MP_VERBOSE(hw, "CUDA hwdec with Vulkan requires exportable semaphores of type 0x%X.\n",
HANDLE_TYPE);
return false;
}

Expand Down

0 comments on commit 1759d73

Please sign in to comment.