Skip to content

Commit

Permalink
revert: "gpu: don't hard error on invalid drm format modifiers"
Browse files Browse the repository at this point in the history
This reverts commit c238c51.

Turns out that we actually need this check in order to prevent mpv from
accidentally choosing hwdec=vaapi instead of hwdec=vaapi-copy on older
drivers that don't support DRM modifiers, at the very least.

In general, the lesson learned is that we _really_ shouldn't allow
passing invalid DRM format modifiers. Users need to get this right to
use the API. That's simply the way it is.

Fixes #98
Fixes mpv-player/mpv#8702
See also mpv-player/mpv#8668
  • Loading branch information
haasn committed May 3, 2021
1 parent 8a4323a commit 534d43a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/gpu.c
Expand Up @@ -530,29 +530,20 @@ pl_fmt pl_find_fourcc(pl_gpu gpu, uint32_t fourcc)
return NULL;
}

static bool warned_mods = false;

static inline void check_mod(pl_gpu gpu, pl_fmt fmt, uint64_t mod)
static inline bool check_mod(pl_gpu gpu, pl_fmt fmt, uint64_t mod)
{
if (warned_mods)
return;

for (int i = 0; i < fmt->num_modifiers; i++) {
if (fmt->modifiers[i] == mod)
return;
return true;
}

// This is not a hard error because modifier support is fickle at best,
// in both libplacebo and other APIs. So just be somewhat annoying in this
// case.

PL_WARN(gpu, "DRM modifier %s not available for format %s. Ignoring, "
"but expect possible corruption. Available modifiers:",
PRINT_DRM_MOD(mod), fmt->name);
PL_ERR(gpu, "DRM modifier %s not available for format %s. Available modifiers:",
PRINT_DRM_MOD(mod), fmt->name);
for (int i = 0; i < fmt->num_modifiers; i++)
PL_WARN(gpu, " %s", PRINT_DRM_MOD(fmt->modifiers[i]));
PL_ERR(gpu, " %s", PRINT_DRM_MOD(fmt->modifiers[i]));

warned_mods = true;
return false;
}

pl_tex pl_tex_create(pl_gpu gpu, const struct pl_tex_params *params)
Expand All @@ -568,7 +559,8 @@ pl_tex pl_tex_create(pl_gpu gpu, const struct pl_tex_params *params)
require(PL_ISPOT(params->import_handle));
require(params->shared_mem.size > 0);
if (params->import_handle == PL_HANDLE_DMA_BUF) {
check_mod(gpu, params->format, params->shared_mem.drm_format_mod);
if (!check_mod(gpu, params->format, params->shared_mem.drm_format_mod))
goto error;
if (params->shared_mem.stride_w)
require(params->w && params->shared_mem.stride_w >= params->w);
if (params->shared_mem.stride_h)
Expand Down

0 comments on commit 534d43a

Please sign in to comment.