Require INVALID for implicit format modifiers

See [1] for the motivation.

[1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/75
This commit is contained in:
Simon Ser 2021-03-31 17:07:55 +02:00 committed by Simon Zeni
parent d78cb808b1
commit affe9eda57
7 changed files with 43 additions and 47 deletions

View File

@ -118,9 +118,14 @@ static bool add_plane(struct wlr_drm_backend *drm,
p->id = drm_plane->plane_id; p->id = drm_plane->plane_id;
p->props = *props; p->props = *props;
for (size_t j = 0; j < drm_plane->count_formats; ++j) { for (size_t i = 0; i < drm_plane->count_formats; ++i) {
wlr_drm_format_set_add(&p->formats, drm_plane->formats[j], // Force a LINEAR layout for the cursor if the driver doesn't support
DRM_FORMAT_MOD_INVALID); // modifiers
uint64_t mod = DRM_FORMAT_MOD_INVALID;
if (type == DRM_PLANE_TYPE_CURSOR) {
mod = DRM_FORMAT_MOD_LINEAR;
}
wlr_drm_format_set_add(&p->formats, drm_plane->formats[i], mod);
} }
if (p->props.in_formats && drm->addfb2_modifiers) { if (p->props.in_formats && drm->addfb2_modifiers) {
@ -150,13 +155,6 @@ static bool add_plane(struct wlr_drm_backend *drm,
} }
drmModeFreePropertyBlob(blob); drmModeFreePropertyBlob(blob);
} else if (type == DRM_PLANE_TYPE_CURSOR) {
// Force a LINEAR layout for the cursor if the driver doesn't support
// modifiers
for (size_t i = 0; i < p->formats.len; ++i) {
wlr_drm_format_set_add(&p->formats, p->formats.formats[i]->format,
DRM_FORMAT_MOD_LINEAR);
}
} }
switch (type) { switch (type) {

View File

@ -149,7 +149,7 @@ struct wlr_drm_format *drm_plane_pick_render_format(
const struct wlr_drm_format_set *plane_formats = &plane->formats; const struct wlr_drm_format_set *plane_formats = &plane->formats;
uint32_t fmt = DRM_FORMAT_ARGB8888; uint32_t fmt = DRM_FORMAT_ARGB8888;
if (!wlr_drm_format_set_has(&plane->formats, fmt, DRM_FORMAT_MOD_INVALID)) { if (!wlr_drm_format_set_get(&plane->formats, fmt)) {
const struct wlr_pixel_format_info *format_info = const struct wlr_pixel_format_info *format_info =
drm_get_pixel_format_info(fmt); drm_get_pixel_format_info(fmt);
assert(format_info != NULL && assert(format_info != NULL &&

View File

@ -354,6 +354,7 @@ static bool query_formats(struct wlr_x11_backend *x11) {
} }
if (x11->have_dri3) { if (x11->have_dri3) {
// X11 always supports implicit modifiers
wlr_drm_format_set_add(&x11->dri3_formats, format->drm, wlr_drm_format_set_add(&x11->dri3_formats, format->drm,
DRM_FORMAT_MOD_INVALID); DRM_FORMAT_MOD_INVALID);
if (!query_dri3_modifiers(x11, format)) { if (!query_dri3_modifiers(x11, format)) {

View File

@ -10,6 +10,7 @@
#include <xf86drm.h> #include <xf86drm.h>
#include "render/allocator/gbm.h" #include "render/allocator/gbm.h"
#include "render/drm_format_set.h"
static const struct wlr_buffer_impl buffer_impl; static const struct wlr_buffer_impl buffer_impl;
@ -89,17 +90,22 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc,
int width, int height, const struct wlr_drm_format *format) { int width, int height, const struct wlr_drm_format *format) {
struct gbm_device *gbm_device = alloc->gbm_device; struct gbm_device *gbm_device = alloc->gbm_device;
struct gbm_bo *bo = NULL; assert(format->len > 0);
bool has_modifier = true; bool has_modifier = true;
if (format->len > 0) { uint64_t fallback_modifier = DRM_FORMAT_MOD_INVALID;
bo = gbm_bo_create_with_modifiers(gbm_device, width, height, struct gbm_bo *bo = gbm_bo_create_with_modifiers(gbm_device, width, height,
format->format, format->modifiers, format->len); format->format, format->modifiers, format->len);
}
if (bo == NULL) { if (bo == NULL) {
uint32_t usage = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; uint32_t usage = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
if (format->len == 1 && if (format->len == 1 &&
format->modifiers[0] == DRM_FORMAT_MOD_LINEAR) { format->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
usage |= GBM_BO_USE_LINEAR; usage |= GBM_BO_USE_LINEAR;
fallback_modifier = DRM_FORMAT_MOD_LINEAR;
} else if (!wlr_drm_format_has(format, DRM_FORMAT_MOD_INVALID)) {
// If the format doesn't accept an implicit modifier, bail out.
wlr_log(WLR_ERROR, "gbm_bo_create_with_modifiers failed");
return NULL;
} }
bo = gbm_bo_create(gbm_device, width, height, format->format, usage); bo = gbm_bo_create(gbm_device, width, height, format->format, usage);
has_modifier = false; has_modifier = false;
@ -128,7 +134,7 @@ static struct wlr_gbm_buffer *create_buffer(struct wlr_gbm_allocator *alloc,
// don't populate the modifier field: other parts of the stack may not // don't populate the modifier field: other parts of the stack may not
// understand modifiers, and they can't strip the modifier. // understand modifiers, and they can't strip the modifier.
if (!has_modifier) { if (!has_modifier) {
buffer->dmabuf.modifier = DRM_FORMAT_MOD_INVALID; buffer->dmabuf.modifier = fallback_modifier;
} }
wlr_log(WLR_DEBUG, "Allocated %dx%d GBM buffer (format 0x%"PRIX32", " wlr_log(WLR_DEBUG, "Allocated %dx%d GBM buffer (format 0x%"PRIX32", "

View File

@ -43,11 +43,6 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set,
if (!fmt) { if (!fmt) {
return false; return false;
} }
if (modifier == DRM_FORMAT_MOD_INVALID) {
return true;
}
return wlr_drm_format_has(fmt, modifier); return wlr_drm_format_has(fmt, modifier);
} }
@ -112,10 +107,6 @@ bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) {
bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) { bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) {
struct wlr_drm_format *fmt = *fmt_ptr; struct wlr_drm_format *fmt = *fmt_ptr;
if (modifier == DRM_FORMAT_MOD_INVALID) {
return true;
}
if (wlr_drm_format_has(fmt, modifier)) { if (wlr_drm_format_has(fmt, modifier)) {
return true; return true;
} }
@ -153,15 +144,17 @@ struct wlr_drm_format *wlr_drm_format_intersect(
const struct wlr_drm_format *a, const struct wlr_drm_format *b) { const struct wlr_drm_format *a, const struct wlr_drm_format *b) {
assert(a->format == b->format); assert(a->format == b->format);
// Special case: if a format only supports LINEAR and the other doesn't // Special case: if a format only supports LINEAR and the other supports
// support any modifier, force LINEAR. This will force the allocator to // implicit modifiers, force LINEAR. This will force the allocator to
// create a buffer with a LINEAR layout instead of an implicit modifier. // create a buffer with a linear layout instead of an implicit modifier.
if (a->len == 0 && b->len == 1 && b->modifiers[0] == DRM_FORMAT_MOD_LINEAR) { if (a->len == 1 && a->modifiers[0] == DRM_FORMAT_MOD_LINEAR &&
return wlr_drm_format_dup(b); wlr_drm_format_has(b, DRM_FORMAT_MOD_INVALID)) {
}
if (b->len == 0 && a->len == 1 && a->modifiers[0] == DRM_FORMAT_MOD_LINEAR) {
return wlr_drm_format_dup(a); return wlr_drm_format_dup(a);
} }
if (b->len == 1 && b->modifiers[0] == DRM_FORMAT_MOD_LINEAR &&
wlr_drm_format_has(a, DRM_FORMAT_MOD_INVALID)) {
return wlr_drm_format_dup(b);
}
size_t format_cap = a->len < b->len ? a->len : b->len; size_t format_cap = a->len < b->len ? a->len : b->len;
size_t format_size = sizeof(struct wlr_drm_format) + size_t format_size = sizeof(struct wlr_drm_format) +
@ -185,9 +178,9 @@ struct wlr_drm_format *wlr_drm_format_intersect(
} }
} }
// If both formats support modifiers, but the intersection is empty, then // If the intersection is empty, then the formats aren't compatible with
// the formats aren't compatible with each other // each other.
if (format->len == 0 && a->len > 0 && b->len > 0) { if (format->len == 0) {
free(format); free(format);
return NULL; return NULL;
} }

View File

@ -119,12 +119,11 @@ static void init_dmabuf_formats(struct wlr_egl *egl) {
has_modifiers = has_modifiers || modifiers_len > 0; has_modifiers = has_modifiers || modifiers_len > 0;
if (modifiers_len == 0) { // EGL always supports implicit modifiers
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt, wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,
DRM_FORMAT_MOD_INVALID); DRM_FORMAT_MOD_INVALID);
wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt, wlr_drm_format_set_add(&egl->dmabuf_render_formats, fmt,
DRM_FORMAT_MOD_INVALID); DRM_FORMAT_MOD_INVALID);
}
for (int j = 0; j < modifiers_len; j++) { for (int j = 0; j < modifiers_len; j++) {
wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt, wlr_drm_format_set_add(&egl->dmabuf_texture_formats, fmt,

View File

@ -9,6 +9,7 @@
#include <wlr/types/wlr_linux_dmabuf_v1.h> #include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "linux-dmabuf-unstable-v1-protocol.h" #include "linux-dmabuf-unstable-v1-protocol.h"
#include "render/drm_format_set.h"
#include "util/signal.h" #include "util/signal.h"
#define LINUX_DMABUF_VERSION 3 #define LINUX_DMABUF_VERSION 3
@ -427,7 +428,9 @@ static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_impl = {
static void linux_dmabuf_send_modifiers(struct wl_resource *resource, static void linux_dmabuf_send_modifiers(struct wl_resource *resource,
const struct wlr_drm_format *fmt) { const struct wlr_drm_format *fmt) {
if (wl_resource_get_version(resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) { if (wl_resource_get_version(resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
if (wlr_drm_format_has(fmt, DRM_FORMAT_MOD_INVALID)) {
zwp_linux_dmabuf_v1_send_format(resource, fmt->format); zwp_linux_dmabuf_v1_send_format(resource, fmt->format);
}
return; return;
} }
@ -436,10 +439,6 @@ static void linux_dmabuf_send_modifiers(struct wl_resource *resource,
zwp_linux_dmabuf_v1_send_modifier(resource, fmt->format, zwp_linux_dmabuf_v1_send_modifier(resource, fmt->format,
mod >> 32, mod & 0xFFFFFFFF); mod >> 32, mod & 0xFFFFFFFF);
} }
// We always support buffers with an implicit modifier
zwp_linux_dmabuf_v1_send_modifier(resource, fmt->format,
DRM_FORMAT_MOD_INVALID >> 32, DRM_FORMAT_MOD_INVALID & 0xFFFFFFFF);
} }
static void linux_dmabuf_send_formats(struct wlr_linux_dmabuf_v1 *linux_dmabuf, static void linux_dmabuf_send_formats(struct wlr_linux_dmabuf_v1 *linux_dmabuf,