Skip to contentSkip to conversation

add drm modifier support for dmabufs.

PATCH Superseded Gerd Hoffmann 2 participants 6 messages May 24, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover add drm modifier support for dmabufs.

Gerd Hoffmann (4):
console: add dmabuf modifier field.
vfio/display: set dmabuf modifier field
egl-helpers: add modifier support to egl_get_fd_for_texture().
egl-helpers: add modifier support to egl_dmabuf_import_texture()

 include/ui/console.h     |  1 +
 include/ui/egl-helpers.h |  3 ++-
 hw/vfio/display.c        |  1 +
 ui/egl-helpers.c         | 37 ++++++++++++++++++++++++++-----------
 ui/spice-display.c       |  7 ++++---
 5 files changed, 34 insertions(+), 15 deletions(-)
Signature · 1 line
2.18.1
#1 lore raw

PATCH v2 1/4 console: add dmabuf modifier field.

dmabufs can have a format modifier (DRM_FORMAT_MOD_*) which is used for tiled layouts for example. Add a field to QemuDmaBuf so we can carry around that information.

---
 include/ui/console.h | 1 +
 1 file changed, 1 insertion(+)
include/ui/console.h +1 -0
index fef900db76a5..f9816968487c 100644
@@ -175,6 +175,7 @@ typedef struct QemuDmaBuf {
     uint32_t  height;
     uint32_t  stride;
     uint32_t  fourcc;
+    uint64_t  modifier;
     uint32_t  texture;
     bool      y0_top;
 } QemuDmaBuf;
Signature · 1 line
2.18.1
#2 lore raw

PATCH v2 2/4 vfio/display: set dmabuf modifier field

In reply to Gerd Hoffmann

Fill the new QemuDmaBuf->modifier field properly from plane info.

---
 hw/vfio/display.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/display.c +1 -0
index a3d9c8f5beac..13969180b2dd 100644
@@ -248,6 +248,7 @@ static VFIODMABuf *vfio_display_get_dmabuf(VFIOPCIDevice *vdev,
     dmabuf->buf.height = plane.height;
     dmabuf->buf.stride = plane.stride;
     dmabuf->buf.fourcc = plane.drm_format;
+    dmabuf->buf.modifier = plane.drm_format_mod;
     dmabuf->buf.fd     = fd;
     if (plane_type == DRM_PLANE_TYPE_CURSOR) {
         vfio_display_update_cursor(dmabuf, &plane);
Signature · 1 line
2.18.1
Acked-by on v2 2/4
#3 lore raw

Re: [Qemu-devel] [PATCH v2 2/4] vfio/display: set dmabuf modifier field

Quoted 13 lines · On Fri, 24 May 2019 09:01:16 +0200 Gerd Hoffmann <[email protected]> wrote:

Fill the new QemuDmaBuf->modifier field properly from plane info.

---
 hw/vfio/display.c | 1 +
 1 file changed, 1 insertion(+)
hw/vfio/display.c +0 -0
index a3d9c8f5beac..13969180b2dd 100644

hw/vfio/display.c static VFIODMABuf *vfio_display_get_dmabuf(VFIOPCIDevice *vdev, · line 254

Quoted 7 lines
hw/vfio/display.c +1 -0
@@ -248,6 +248,7 @@ static VFIODMABuf *vfio_display_get_dmabuf(VFIOPCIDevice *vdev,
     dmabuf->buf.height = plane.height;
     dmabuf->buf.stride = plane.stride;
     dmabuf->buf.fourcc = plane.drm_format;
+    dmabuf->buf.modifier = plane.drm_format_mod;
     dmabuf->buf.fd     = fd;
     if (plane_type == DRM_PLANE_TYPE_CURSOR) {
         vfio_display_update_cursor(dmabuf, &plane);
#4 lore raw

PATCH v2 3/4 egl-helpers: add modifier support to egl_get_fd_for_texture().

In reply to Gerd Hoffmann

Add modifier parameter to egl_get_fd_for_texture(), to return the used modifier on dmabuf exports.

---
 include/ui/egl-helpers.h | 3 ++-
 ui/egl-helpers.c         | 5 +++--
 ui/spice-display.c       | 7 ++++---
 3 files changed, 9 insertions(+), 6 deletions(-)
include/ui/egl-helpers.h +2 -1
index b976cb872821..d71412779913 100644
@@ -36,7 +36,8 @@ extern struct gbm_device *qemu_egl_rn_gbm_dev;
 extern EGLContext qemu_egl_rn_ctx;
 
 int egl_rendernode_init(const char *rendernode, DisplayGLMode mode);
-int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc);
+int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
+                           EGLuint64KHR *modifier);
 
 void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf);
 void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf);
ui/egl-helpers.c +3 -2
index e90eef8c9c3a..0c9716067cfb 100644
@@ -200,7 +200,8 @@ err:
     return -1;
 }
 
-int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc)
+int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
+                           EGLuint64KHR *modifier)
 {
     EGLImageKHR image;
     EGLint num_planes, fd;
@@ -214,7 +215,7 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc)
     }
 
     eglExportDMABUFImageQueryMESA(qemu_egl_display, image, fourcc,
-                                  &num_planes, NULL);
+                                  &num_planes, modifier);
     if (num_planes != 1) {
         eglDestroyImageKHR(qemu_egl_display, image);
         return -1;
ui/spice-display.c +4 -3
index a5e26479a866..104df2302575 100644
@@ -888,7 +888,8 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
     if (ssd->ds) {
         surface_gl_create_texture(ssd->gls, ssd->ds);
         fd = egl_get_fd_for_texture(ssd->ds->texture,
-                                    &stride, &fourcc);
+                                    &stride, &fourcc,
+                                    NULL);
         if (fd < 0) {
             surface_gl_destroy_texture(ssd->gls, ssd->ds);
             return;
@@ -945,7 +946,7 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,
     int fd = -1;
 
     assert(tex_id);
-    fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc);
+    fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc, NULL);
     if (fd < 0) {
         fprintf(stderr, "%s: failed to get fd for texture\n", __func__);
         return;
@@ -1063,7 +1064,7 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,
                 egl_fb_setup_new_tex(&ssd->blit_fb,
                                      dmabuf->width, dmabuf->height);
                 fd = egl_get_fd_for_texture(ssd->blit_fb.texture,
-                                            &stride, &fourcc);
+                                            &stride, &fourcc, NULL);
                 spice_qxl_gl_scanout(&ssd->qxl, fd,
                                      dmabuf->width, dmabuf->height,
                                      stride, fourcc, false);
Signature · 1 line
2.18.1
#5 lore raw

PATCH v2 4/4 egl-helpers: add modifier support to egl_dmabuf_import_texture()

In reply to Gerd Hoffmann

Check and use QemuDmaBuf->modifier in egl_dmabuf_import_texture() for dmabuf imports.

---
 ui/egl-helpers.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
ui/egl-helpers.c +23 -9
index 0c9716067cfb..87bfd32e8ddb 100644
@@ -229,20 +229,34 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,
 void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf)
 {
     EGLImageKHR image = EGL_NO_IMAGE_KHR;
-    EGLint attrs[] = {
-        EGL_DMA_BUF_PLANE0_FD_EXT,      dmabuf->fd,
-        EGL_DMA_BUF_PLANE0_PITCH_EXT,   dmabuf->stride,
-        EGL_DMA_BUF_PLANE0_OFFSET_EXT,  0,
-        EGL_WIDTH,                      dmabuf->width,
-        EGL_HEIGHT,                     dmabuf->height,
-        EGL_LINUX_DRM_FOURCC_EXT,       dmabuf->fourcc,
-        EGL_NONE, /* end of list */
-    };
+    EGLint attrs[64];
+    int i = 0;
 
     if (dmabuf->texture != 0) {
         return;
     }
 
+    attrs[i++] = EGL_WIDTH;
+    attrs[i++] = dmabuf->width;
+    attrs[i++] = EGL_HEIGHT;
+    attrs[i++] = dmabuf->height;
+    attrs[i++] = EGL_LINUX_DRM_FOURCC_EXT;
+    attrs[i++] = dmabuf->fourcc;
+
+    attrs[i++] = EGL_DMA_BUF_PLANE0_FD_EXT;
+    attrs[i++] = dmabuf->fd;
+    attrs[i++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
+    attrs[i++] = dmabuf->stride;
+    attrs[i++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
+    attrs[i++] = 0;
+    if (dmabuf->modifier) {
+        attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
+        attrs[i++] = (dmabuf->modifier >>  0) & 0xffffffff;
+        attrs[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
+        attrs[i++] = (dmabuf->modifier >> 32) & 0xffffffff;
+    }
+    attrs[i++] = EGL_NONE;
+
     image = eglCreateImageKHR(qemu_egl_display,
                               EGL_NO_CONTEXT,
                               EGL_LINUX_DMA_BUF_EXT,
Signature · 1 line
2.18.1