egl/x11: Re-allocate buffers if format is suboptimal
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>
Fri, 6 Oct 2017 05:26:51 +0000 (01:26 -0400)
committerDaniel Stone <daniels@collabora.com>
Fri, 9 Mar 2018 17:47:14 +0000 (17:47 +0000)
If PresentCompleteNotify event says the pixmap was presented
with mode PresentCompleteModeSuboptimalCopy, it means the pixmap
could possibly have been flipped instead if allocated with a
different format/modifier.

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_x11_dri3.c
src/glx/dri3_glx.c
src/loader/loader_dri3_helper.c
src/loader/loader_dri3_helper.h

index 1bd57c9ea311e802f4f7ee975e879fa0443c2ff7..864f7eb0c68308e04bbec889eeec2909ccfa1ce0 100644 (file)
@@ -885,6 +885,8 @@ dri2_setup_extensions(_EGLDisplay *disp)
    dri2_dpy->multibuffers_available =
       (dri2_dpy->dri3_major_version > 1 || (dri2_dpy->dri3_major_version == 1 &&
                                             dri2_dpy->dri3_minor_version >= 2)) &&
+      (dri2_dpy->present_major_version > 1 || (dri2_dpy->present_major_version == 1 &&
+                                               dri2_dpy->present_minor_version >= 2)) &&
       (dri2_dpy->image && dri2_dpy->image->base.version >= 15);
 #endif
 
index 00c4768d421a6b43ca78a9dbb591bb8f8192a690..bd637f73c9ded3916c834d499673d731de2914cd 100644 (file)
@@ -202,6 +202,8 @@ struct dri2_egl_display
    bool                     multibuffers_available;
    int                      dri3_major_version;
    int                      dri3_minor_version;
+   int                      present_major_version;
+   int                      present_minor_version;
    struct loader_dri3_extensions loader_dri3_ext;
 #endif
 #endif
index c1efa93015921e673dd7c7a49f418b991be022ad..dce33561a6f7f608498b9f1bf8b11dc8d81f9420 100644 (file)
@@ -565,6 +565,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)
       free(error);
       return EGL_FALSE;
    }
+
+   dri2_dpy->present_major_version = present_query->major_version;
+   dri2_dpy->present_minor_version = present_query->minor_version;
    free(present_query);
 
    dri2_dpy->fd = loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0);
index 71ecebbc16c5e6e2c1efbfc7a833064d4ddf69ce..aec803adfd8bd09d78e6a0bef3cf0105433df8fc 100644 (file)
@@ -372,7 +372,9 @@ dri3_create_drawable(struct glx_screen *base, XID xDrawable,
    pdraw->base.psc = &psc->base;
 
    if ((psc->image && psc->image->base.version >= 15) &&
-       (pdp->dri3Major > 1 || (pdp->dri3Major == 1 && pdp->dri3Minor >= 2)))
+       (pdp->dri3Major > 1 || (pdp->dri3Major == 1 && pdp->dri3Minor >= 2)) &&
+       (pdp->presentMajor > 1 ||
+        (pdp->presentMajor == 1 && pdp->presentMinor >= 2)))
       has_multibuffer = true;
 
    (void) __glXInitialize(psc->base.dpy);
index 6587281c4ab8c5be507ab4c586eccbbb506b3dcb..585f7ce3eceb7fd6457f5c5c1e87ec38ed3edfae 100644 (file)
@@ -374,6 +374,29 @@ dri3_handle_present_event(struct loader_dri3_drawable *draw,
          if (draw->recv_sbc > draw->send_sbc)
             draw->recv_sbc -= 0x100000000;
 
+         /* When moving from flip to copy, we assume that we can allocate in
+          * a more optimal way if we don't need to cater for the display
+          * controller.
+          */
+         if (ce->mode == XCB_PRESENT_COMPLETE_MODE_COPY &&
+             draw->last_present_mode == XCB_PRESENT_COMPLETE_MODE_FLIP) {
+            for (int b = 0; b < ARRAY_SIZE(draw->buffers); b++) {
+               if (draw->buffers[b])
+                  draw->buffers[b]->reallocate = true;
+            }
+         }
+
+        /* If the server tells us that our allocation is suboptimal, we
+          * reallocate once.
+          */
+         if (ce->mode == XCB_PRESENT_COMPLETE_MODE_SUBOPTIMAL_COPY &&
+             draw->last_present_mode != ce->mode) {
+            for (int b = 0; b < ARRAY_SIZE(draw->buffers); b++) {
+               if (draw->buffers[b])
+                  draw->buffers[b]->reallocate = true;
+            }
+         }
+
          draw->last_present_mode = ce->mode;
 
          if (draw->vtable->show_fps)
@@ -397,9 +420,9 @@ dri3_handle_present_event(struct loader_dri3_drawable *draw,
          if (buf && buf->pixmap == ie->pixmap)
             buf->busy = 0;
 
-         if (buf && draw->num_back <= b && b < LOADER_DRI3_MAX_BACK &&
-             draw->cur_blit_source != b &&
-             !buf->busy) {
+         if (buf && draw->cur_blit_source != b && !buf->busy &&
+             (buf->reallocate ||
+             (draw->num_back <= b && b < LOADER_DRI3_MAX_BACK))) {
             dri3_free_render_buffer(draw, buf);
             draw->buffers[b] = NULL;
          }
@@ -881,6 +904,9 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw,
       if (!loader_dri3_have_image_blit(draw) && draw->cur_blit_source != -1)
          options |= XCB_PRESENT_OPTION_COPY;
 
+      if (draw->multiplanes_available)
+         options |= XCB_PRESENT_OPTION_SUBOPTIMAL;
+
       back->busy = 1;
       back->last_swap = draw->send_sbc;
       xcb_present_pixmap(draw->conn,
@@ -1626,11 +1652,12 @@ dri3_get_buffer(__DRIdrawable *driDrawable,
 
    buffer = draw->buffers[buf_id];
 
-   /* Allocate a new buffer if there isn't an old one, or if that
-    * old one is the wrong size
+   /* Allocate a new buffer if there isn't an old one, if that
+    * old one is the wrong size, or if it's suboptimal
     */
    if (!buffer || buffer->width != draw->width ||
-       buffer->height != draw->height) {
+       buffer->height != draw->height ||
+       buffer->reallocate) {
       struct loader_dri3_buffer *new_buffer;
 
       /* Allocate the new buffers
index c54c668032e6e35f167808122986124ac9e1aa8d..de22c19a578fae7da3b967cadfe0dca174daebf2 100644 (file)
@@ -61,6 +61,7 @@ struct loader_dri3_buffer {
    struct xshmfence *shm_fence; /* pointer to xshmfence object */
    bool         busy;           /* Set on swap, cleared on IdleNotify */
    bool         own_pixmap;     /* We allocated the pixmap ID, free on destroy */
+   bool         reallocate;     /* Buffer should be reallocated and not reused */
 
    uint32_t     num_planes;
    uint32_t     size;