summaryrefslogtreecommitdiff
path: root/src/loader
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>2017-07-07 02:54:26 -0400
committerDaniel Stone <daniels@collabora.com>2018-03-09 17:47:14 +0000
commit069fdd5f9facbd72fb6a289696c7b74e3237e70f (patch)
tree1a019e8325ed0d9799d710e6131b38a0cc28721d /src/loader
parent61309c2a727d52d543207d6ae79fcb3e68b5cff3 (diff)
downloadmesa-069fdd5f9facbd72fb6a289696c7b74e3237e70f.tar.gz
mesa-069fdd5f9facbd72fb6a289696c7b74e3237e70f.tar.bz2
mesa-069fdd5f9facbd72fb6a289696c7b74e3237e70f.zip
egl/x11: Support DRI3 v1.1
Add support for DRI3 v1.1, which allows pixmaps to be backed by multi-planar buffers, or those with format modifiers. This is both for allocating render buffers, as well as EGLImage imports from a native pixmap (EGL_NATIVE_PIXMAP_KHR). Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader_dri3_helper.c308
-rw-r--r--src/loader/loader_dri3_helper.h15
-rw-r--r--src/loader/meson.build2
3 files changed, 278 insertions, 47 deletions
diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
index 426966a786a..6587281c4ab 100644
--- a/src/loader/loader_dri3_helper.c
+++ b/src/loader/loader_dri3_helper.c
@@ -24,6 +24,7 @@
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include <X11/xshmfence.h>
#include <xcb/xcb.h>
@@ -34,6 +35,7 @@
#include "loader_dri3_helper.h"
#include "util/macros.h"
+#include "drm_fourcc.h"
/* From xmlpool/options.h, user exposed so should be stable */
#define DRI_CONF_VBLANK_NEVER 0
@@ -257,6 +259,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
xcb_drawable_t drawable,
__DRIscreen *dri_screen,
bool is_different_gpu,
+ bool multiplanes_available,
const __DRIconfig *dri_config,
struct loader_dri3_extensions *ext,
const struct loader_dri3_vtable *vtable,
@@ -274,6 +277,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
draw->drawable = drawable;
draw->dri_screen = dri_screen;
draw->is_different_gpu = is_different_gpu;
+ draw->multiplanes_available = multiplanes_available;
draw->have_back = 0;
draw->have_fake_front = 0;
@@ -1023,6 +1027,41 @@ image_format_to_fourcc(int format)
return 0;
}
+static bool
+has_supported_modifier(struct loader_dri3_drawable *draw, unsigned int format,
+ uint64_t *modifiers, uint32_t count)
+{
+ uint64_t *supported_modifiers;
+ int32_t supported_modifiers_count;
+ bool found = false;
+ int i, j;
+
+ if (!draw->ext->image->queryDmaBufModifiers(draw->dri_screen,
+ format, 0, NULL, NULL,
+ &supported_modifiers_count) ||
+ supported_modifiers_count == 0)
+ return false;
+
+ supported_modifiers = malloc(supported_modifiers_count * sizeof(uint64_t));
+ if (!supported_modifiers)
+ return false;
+
+ draw->ext->image->queryDmaBufModifiers(draw->dri_screen, format,
+ supported_modifiers_count,
+ supported_modifiers, NULL,
+ &supported_modifiers_count);
+
+ for (i = 0; !found && i < supported_modifiers_count; i++) {
+ for (j = 0; !found && j < count; j++) {
+ if (supported_modifiers[i] == modifiers[j])
+ found = true;
+ }
+ }
+
+ free(supported_modifiers);
+ return found;
+}
+
/** loader_dri3_alloc_render_buffer
*
* Use the driver createImage function to construct a __DRIimage, then
@@ -1039,8 +1078,10 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
xcb_pixmap_t pixmap;
xcb_sync_fence_t sync_fence;
struct xshmfence *shm_fence;
- int buffer_fd, fence_fd;
- int stride;
+ int buffer_fds[4], fence_fd;
+ int num_planes = 0;
+ int i, mod;
+ int ret;
/* Create an xshmfence object and
* prepare to send that to the X server
@@ -1065,13 +1106,79 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
goto no_image;
if (!draw->is_different_gpu) {
- buffer->image = draw->ext->image->createImage(draw->dri_screen,
- width, height,
- format,
- __DRI_IMAGE_USE_SHARE |
- __DRI_IMAGE_USE_SCANOUT |
- __DRI_IMAGE_USE_BACKBUFFER,
- buffer);
+ if (draw->multiplanes_available &&
+ draw->ext->image->base.version >= 15 &&
+ draw->ext->image->queryDmaBufModifiers &&
+ draw->ext->image->createImageWithModifiers) {
+ xcb_dri3_get_supported_modifiers_cookie_t mod_cookie;
+ xcb_dri3_get_supported_modifiers_reply_t *mod_reply;
+ xcb_generic_error_t *error = NULL;
+ uint64_t *modifiers = NULL;
+ uint32_t count = 0;
+
+ mod_cookie = xcb_dri3_get_supported_modifiers(draw->conn,
+ draw->drawable,
+ depth, buffer->cpp * 8);
+ mod_reply = xcb_dri3_get_supported_modifiers_reply(draw->conn,
+ mod_cookie,
+ &error);
+ if (!mod_reply)
+ goto no_image;
+
+ if (mod_reply->num_window_modifiers) {
+ count = mod_reply->num_window_modifiers;
+ modifiers = malloc(count * sizeof(uint64_t));
+ if (!modifiers) {
+ free(mod_reply);
+ goto no_image;
+ }
+
+ memcpy(modifiers,
+ xcb_dri3_get_supported_modifiers_window_modifiers(mod_reply),
+ count * sizeof(uint64_t));
+
+ if (!has_supported_modifier(draw, image_format_to_fourcc(format),
+ modifiers, count)) {
+ free(modifiers);
+ count = 0;
+ modifiers = NULL;
+ }
+ }
+
+ if (mod_reply->num_screen_modifiers && modifiers == NULL) {
+ count = mod_reply->num_screen_modifiers;
+ modifiers = malloc(count * sizeof(uint64_t));
+ if (!modifiers) {
+ free(modifiers);
+ free(mod_reply);
+ goto no_image;
+ }
+
+ memcpy(modifiers,
+ xcb_dri3_get_supported_modifiers_screen_modifiers(mod_reply),
+ count * sizeof(uint64_t));
+ }
+
+ free(mod_reply);
+
+ buffer->image = draw->ext->image->createImageWithModifiers(draw->dri_screen,
+ width, height,
+ format,
+ modifiers,
+ count,
+ buffer);
+ free(modifiers);
+ }
+
+ if (!buffer->image)
+ buffer->image = draw->ext->image->createImage(draw->dri_screen,
+ width, height,
+ format,
+ __DRI_IMAGE_USE_SHARE |
+ __DRI_IMAGE_USE_SCANOUT |
+ __DRI_IMAGE_USE_BACKBUFFER,
+ buffer);
+
pixmap_buffer = buffer->image;
if (!buffer->image)
@@ -1099,25 +1206,67 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
goto no_linear_buffer;
}
- /* X wants the stride, so ask the image for it
+ /* X want some information about the planes, so ask the image for it
*/
- if (!draw->ext->image->queryImage(pixmap_buffer, __DRI_IMAGE_ATTRIB_STRIDE,
- &stride))
- goto no_buffer_attrib;
+ if (!draw->ext->image->queryImage(pixmap_buffer, __DRI_IMAGE_ATTRIB_NUM_PLANES,
+ &num_planes))
+ num_planes = 1;
+
+ for (i = 0; i < num_planes; i++) {
+ __DRIimage *image = draw->ext->image->fromPlanar(pixmap_buffer, i, NULL);
- buffer->pitch = stride;
+ if (!image) {
+ assert(i == 0);
+ image = pixmap_buffer;
+ }
- if (!draw->ext->image->queryImage(pixmap_buffer, __DRI_IMAGE_ATTRIB_FD,
- &buffer_fd))
- goto no_buffer_attrib;
+ ret = draw->ext->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD,
+ &buffer_fds[i]);
+ ret &= draw->ext->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE,
+ &buffer->strides[i]);
+ ret &= draw->ext->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET,
+ &buffer->offsets[i]);
+ if (image != pixmap_buffer)
+ draw->ext->image->destroyImage(image);
+
+ if (!ret)
+ goto no_buffer_attrib;
+ }
- xcb_dri3_pixmap_from_buffer(draw->conn,
- (pixmap = xcb_generate_id(draw->conn)),
- draw->drawable,
- buffer->size,
- width, height, buffer->pitch,
- depth, buffer->cpp * 8,
- buffer_fd);
+ ret = draw->ext->image->queryImage(pixmap_buffer,
+ __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod);
+ buffer->modifier = (uint64_t) mod << 32;
+ ret &= draw->ext->image->queryImage(pixmap_buffer,
+ __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod);
+ buffer->modifier |= (uint64_t)(mod & 0xffffffff);
+
+ if (!ret)
+ buffer->modifier = DRM_FORMAT_MOD_INVALID;
+
+ pixmap = xcb_generate_id(draw->conn);
+ if (draw->multiplanes_available &&
+ buffer->modifier != DRM_FORMAT_MOD_INVALID) {
+ xcb_dri3_pixmap_from_buffers(draw->conn,
+ pixmap,
+ draw->drawable,
+ num_planes,
+ width, height,
+ buffer->strides[0], buffer->offsets[0],
+ buffer->strides[1], buffer->offsets[1],
+ buffer->strides[2], buffer->offsets[2],
+ buffer->strides[3], buffer->offsets[3],
+ depth, buffer->cpp * 8,
+ buffer->modifier,
+ buffer_fds);
+ } else {
+ xcb_dri3_pixmap_from_buffer(draw->conn,
+ pixmap,
+ draw->drawable,
+ buffer->size,
+ width, height, buffer->strides[0],
+ depth, buffer->cpp * 8,
+ buffer_fds[0]);
+ }
xcb_dri3_fence_from_fd(draw->conn,
pixmap,
@@ -1139,6 +1288,9 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
return buffer;
no_buffer_attrib:
+ do {
+ close(buffer_fds[i]);
+ } while (--i >= 0);
draw->ext->image->destroyImage(pixmap_buffer);
no_linear_buffer:
if (draw->is_different_gpu)
@@ -1295,6 +1447,48 @@ loader_dri3_create_image(xcb_connection_t *c,
return ret;
}
+__DRIimage *
+loader_dri3_create_image_from_buffers(xcb_connection_t *c,
+ xcb_dri3_buffers_from_pixmap_reply_t *bp_reply,
+ unsigned int format,
+ __DRIscreen *dri_screen,
+ const __DRIimageExtension *image,
+ void *loaderPrivate)
+{
+ __DRIimage *ret;
+ int *fds;
+ uint32_t *strides_in, *offsets_in;
+ int strides[4], offsets[4];
+ unsigned error;
+ int i;
+
+ if (bp_reply->nfd > 4)
+ return NULL;
+
+ fds = xcb_dri3_buffers_from_pixmap_reply_fds(c, bp_reply);
+ strides_in = xcb_dri3_buffers_from_pixmap_strides(bp_reply);
+ offsets_in = xcb_dri3_buffers_from_pixmap_offsets(bp_reply);
+ for (i = 0; i < bp_reply->nfd; i++) {
+ strides[i] = strides_in[i];
+ offsets[i] = offsets_in[i];
+ }
+
+ ret = image->createImageFromDmaBufs2(dri_screen,
+ bp_reply->width,
+ bp_reply->height,
+ image_format_to_fourcc(format),
+ bp_reply->modifier,
+ fds, bp_reply->nfd,
+ strides, offsets,
+ 0, 0, 0, 0, /* UNDEFINED */
+ &error, loaderPrivate);
+
+ for (i = 0; i < bp_reply->nfd; i++)
+ close(fds[i]);
+
+ return ret;
+}
+
/** dri3_get_pixmap_buffer
*
* Get the DRM object for a pixmap from the X server and
@@ -1308,10 +1502,10 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
int buf_id = loader_dri3_pixmap_buf_id(buffer_type);
struct loader_dri3_buffer *buffer = draw->buffers[buf_id];
xcb_drawable_t pixmap;
- xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie;
- xcb_dri3_buffer_from_pixmap_reply_t *bp_reply;
xcb_sync_fence_t sync_fence;
struct xshmfence *shm_fence;
+ int width;
+ int height;
int fence_fd;
__DRIscreen *cur_screen;
@@ -1333,17 +1527,6 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
goto no_fence;
}
- xcb_dri3_fence_from_fd(draw->conn,
- pixmap,
- (sync_fence = xcb_generate_id(draw->conn)),
- false,
- fence_fd);
-
- bp_cookie = xcb_dri3_buffer_from_pixmap(draw->conn, pixmap);
- bp_reply = xcb_dri3_buffer_from_pixmap_reply(draw->conn, bp_cookie, NULL);
- if (!bp_reply)
- goto no_image;
-
/* Get the currently-bound screen or revert to using the drawable's screen if
* no contexts are currently bound. The latter case is at least necessary for
* obs-studio, when using Window Capture (Xcomposite) as a Source.
@@ -1353,27 +1536,62 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, unsigned int format,
cur_screen = draw->dri_screen;
}
- buffer->image = loader_dri3_create_image(draw->conn, bp_reply, format,
- cur_screen, draw->ext->image,
- buffer);
+ xcb_dri3_fence_from_fd(draw->conn,
+ pixmap,
+ (sync_fence = xcb_generate_id(draw->conn)),
+ false,
+ fence_fd);
+
+ if (draw->multiplanes_available &&
+ draw->ext->image->base.version >= 15 &&
+ draw->ext->image->createImageFromDmaBufs2) {
+ xcb_dri3_buffers_from_pixmap_cookie_t bps_cookie;
+ xcb_dri3_buffers_from_pixmap_reply_t *bps_reply;
+
+ bps_cookie = xcb_dri3_buffers_from_pixmap(draw->conn, pixmap);
+ bps_reply = xcb_dri3_buffers_from_pixmap_reply(draw->conn, bps_cookie,
+ NULL);
+ if (!bps_reply)
+ goto no_image;
+ buffer->image =
+ loader_dri3_create_image_from_buffers(draw->conn, bps_reply, format,
+ cur_screen, draw->ext->image,
+ buffer);
+ width = bps_reply->width;
+ height = bps_reply->height;
+ free(bps_reply);
+ } else {
+ xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie;
+ xcb_dri3_buffer_from_pixmap_reply_t *bp_reply;
+
+ bp_cookie = xcb_dri3_buffer_from_pixmap(draw->conn, pixmap);
+ bp_reply = xcb_dri3_buffer_from_pixmap_reply(draw->conn, bp_cookie, NULL);
+ if (!bp_reply)
+ goto no_image;
+
+ buffer->image = loader_dri3_create_image(draw->conn, bp_reply, format,
+ cur_screen, draw->ext->image,
+ buffer);
+ width = bp_reply->width;
+ height = bp_reply->height;
+ free(bp_reply);
+ }
+
if (!buffer->image)
goto no_image;
buffer->pixmap = pixmap;
buffer->own_pixmap = false;
- buffer->width = bp_reply->width;
- buffer->height = bp_reply->height;
+ buffer->width = width;
+ buffer->height = height;
buffer->shm_fence = shm_fence;
buffer->sync_fence = sync_fence;
draw->buffers[buf_id] = buffer;
- free(bp_reply);
-
return buffer;
no_image:
- free(bp_reply);
xcb_sync_destroy_fence(draw->conn, sync_fence);
xshmfence_unmap_shm(shm_fence);
no_fence:
diff --git a/src/loader/loader_dri3_helper.h b/src/loader/loader_dri3_helper.h
index 5caf214b372..c54c668032e 100644
--- a/src/loader/loader_dri3_helper.h
+++ b/src/loader/loader_dri3_helper.h
@@ -62,8 +62,11 @@ struct loader_dri3_buffer {
bool busy; /* Set on swap, cleared on IdleNotify */
bool own_pixmap; /* We allocated the pixmap ID, free on destroy */
+ uint32_t num_planes;
uint32_t size;
- uint32_t pitch;
+ int strides[4];
+ int offsets[4];
+ uint64_t modifier;
uint32_t cpp;
uint32_t flags;
uint32_t width, height;
@@ -120,6 +123,7 @@ struct loader_dri3_drawable {
/* Information about the GPU owning the buffer */
__DRIscreen *dri_screen;
bool is_different_gpu;
+ bool multiplanes_available;
/* Present extension capabilities
*/
@@ -180,6 +184,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn,
xcb_drawable_t drawable,
__DRIscreen *dri_screen,
bool is_different_gpu,
+ bool is_multiplanes_available,
const __DRIconfig *dri_config,
struct loader_dri3_extensions *ext,
const struct loader_dri3_vtable *vtable,
@@ -237,6 +242,14 @@ loader_dri3_create_image(xcb_connection_t *c,
const __DRIimageExtension *image,
void *loaderPrivate);
+__DRIimage *
+loader_dri3_create_image_from_buffers(xcb_connection_t *c,
+ xcb_dri3_buffers_from_pixmap_reply_t *bp_reply,
+ unsigned int format,
+ __DRIscreen *dri_screen,
+ const __DRIimageExtension *image,
+ void *loaderPrivate);
+
int
loader_dri3_get_buffers(__DRIdrawable *driDrawable,
unsigned int format,
diff --git a/src/loader/meson.build b/src/loader/meson.build
index 2693970182f..76fcae2cb44 100644
--- a/src/loader/meson.build
+++ b/src/loader/meson.build
@@ -25,7 +25,7 @@ if with_platform_x11 and with_dri3
'loader_dri3_helper',
['loader_dri3_helper.c', 'loader_dri3_helper.h'],
c_args : c_vis_args,
- include_directories : [inc_include, inc_src],
+ include_directories : [inc_include, inc_src, inc_drm_uapi],
dependencies : [
dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence,
],