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 <daniels@collabora.com>

Fixes: 361f362258 ("dri: Unify createImage and createImageWithModifiers")

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30383>
This commit is contained in:
Daniel Stone
2024-07-26 17:39:23 +01:00
committed by Marge Bot
parent 349e7a2919
commit 0b16d7ebb9

View File

@@ -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,