From 0b16d7ebb92e05a5bcdaf70626e0d916551015e1 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 26 Jul 2024 17:39:23 +0100 Subject: [PATCH] dri: Allow INVALID for modifier-less drivers If the user passes in DRM_FORMAT_MOD_INVALID as an acceptable modifier, we can progress with implicit modifiers. Add this to a more comprehensive special case along with linear to make sure that we can still allocate when users pass in a modifier list to a driver which doesn't support modifiers. Signed-off-by: Daniel Stone Fixes: 361f3622587 ("dri: Unify createImage and createImageWithModifiers") Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/frontends/dri/dri2.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index 35cdd882eb1..8ed1a0c1392 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -1170,15 +1170,29 @@ dri2_create_image(__DRIscreen *_screen, if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) { count = 0; modifiers = NULL; - } else if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_LINEAR && - !pscreen->resource_create_with_modifiers) { - count = 0; - modifiers = NULL; - use |= __DRI_IMAGE_USE_LINEAR; } - else if ((count > 1 || modifiers) && - !pscreen->resource_create_with_modifiers) { - return NULL; + + if (!pscreen->resource_create_with_modifiers && count > 0) { + bool invalid_ok = false; + bool linear_ok = false; + + for (unsigned i = 0; i < _count; i++) { + if (modifiers[i] == DRM_FORMAT_MOD_LINEAR) + linear_ok = true; + else if (modifiers[i] == DRM_FORMAT_MOD_INVALID) + invalid_ok = true; + } + + if (invalid_ok) { + count = 0; + modifiers = NULL; + } else if (linear_ok) { + count = 0; + modifiers = NULL; + use |= __DRI_IMAGE_USE_LINEAR; + } else { + return NULL; + } } if (pscreen->is_format_supported(pscreen, map->pipe_format, screen->target,