<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 15, 2018 at 7:57 AM, Daniel Stone <span dir="ltr"><<a href="mailto:daniels@collabora.com" target="_blank">daniels@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Louis-Francis Ratté-Boulianne <<a href="mailto:lfrb@collabora.com">lfrb@collabora.com</a>><br>
<br>
If PresentCompleteNotify event says the pixmap was presented<br>
with mode PresentCompleteModeSuboptimalC<wbr>opy, it means the pixmap<br>
could possibly have been flipped instead if allocated with a<br>
different format/modifier.<br>
<br>
Signed-off-by: Louis-Francis Ratté-Boulianne <<a href="mailto:lfrb@collabora.com">lfrb@collabora.com</a>><br>
Reviewed-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
Signed-off-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
 src/egl/drivers/dri2/egl_dri2.<wbr>c          |  2 ++<br>
 src/egl/drivers/dri2/egl_dri2.<wbr>h          |  2 ++<br>
 src/egl/drivers/dri2/platform_<wbr>x11_dri3.c |  3 +++<br>
 src/loader/loader_dri3_helper.<wbr>c          | 37 ++++++++++++++++++++++++++++--<wbr>--<br>
 src/loader/loader_dri3_helper.<wbr>h          |  2 ++<br>
 src/loader/meson.build                   |  2 +-<br>
 6 files changed, 43 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/egl/drivers/dri2/egl_<wbr>dri2.c b/src/egl/drivers/dri2/egl_<wbr>dri2.c<br>
index 9a7e43bafb6..921d1a52931 100644<br>
--- a/src/egl/drivers/dri2/egl_<wbr>dri2.c<br>
+++ b/src/egl/drivers/dri2/egl_<wbr>dri2.c<br>
@@ -885,6 +885,8 @@ dri2_setup_extensions(_<wbr>EGLDisplay *disp)<br>
    dri2_dpy->multibuffers_<wbr>available =<br>
       (dri2_dpy->dri3_major_version > 1 || (dri2_dpy->dri3_major_version == 1 &&<br>
                                             dri2_dpy->dri3_minor_version >= 1)) &&<br>
+      (dri2_dpy->present_major_<wbr>version > 1 || (dri2_dpy->present_major_<wbr>version == 1 &&<br>
+                                               dri2_dpy->present_minor_<wbr>version >= 1)) &&<br>
       (dri2_dpy->image && dri2_dpy->image->base.version >= 15);<br>
 #endif<br>
<br>
diff --git a/src/egl/drivers/dri2/egl_<wbr>dri2.h b/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
index 00c4768d421..bd637f73c9d 100644<br>
--- a/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
+++ b/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
@@ -202,6 +202,8 @@ struct dri2_egl_display<br>
    bool                     multibuffers_available;<br>
    int                      dri3_major_version;<br>
    int                      dri3_minor_version;<br>
+   int                      present_major_version;<br>
+   int                      present_minor_version;<br>
    struct loader_dri3_extensions loader_dri3_ext;<br>
 #endif<br>
 #endif<br>
diff --git a/src/egl/drivers/dri2/<wbr>platform_x11_dri3.c b/src/egl/drivers/dri2/<wbr>platform_x11_dri3.c<br>
index 15c349eb828..ae2588d04c4 100644<br>
--- a/src/egl/drivers/dri2/<wbr>platform_x11_dri3.c<br>
+++ b/src/egl/drivers/dri2/<wbr>platform_x11_dri3.c<br>
@@ -557,6 +557,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy)<br>
       free(error);<br>
       return EGL_FALSE;<br>
    }<br>
+<br>
+   dri2_dpy->present_major_<wbr>version = present_query->major_version;<br>
+   dri2_dpy->present_minor_<wbr>version = present_query->minor_version;<br>
    free(present_query);<br>
<br>
    dri2_dpy->fd = loader_dri3_open(dri2_dpy-><wbr>conn, dri2_dpy->screen->root, 0);<br>
diff --git a/src/loader/loader_dri3_<wbr>helper.c b/src/loader/loader_dri3_<wbr>helper.c<br>
index 038216c2637..855ec5ce343 100644<br>
--- a/src/loader/loader_dri3_<wbr>helper.c<br>
+++ b/src/loader/loader_dri3_<wbr>helper.c<br>
@@ -34,6 +34,8 @@<br>
 #include <X11/Xlib-xcb.h><br>
<br>
 #include "loader_dri3_helper.h"<br>
+#include "util/macros.h"<br>
+#include "drm_fourcc.h"<br>
<br>
 /* From xmlpool/options.h, user exposed so should be stable */<br>
 #define DRI_CONF_VBLANK_NEVER 0<br>
@@ -373,11 +375,25 @@ dri3_handle_present_event(<wbr>struct loader_dri3_drawable *draw,<br>
             draw->recv_sbc -= 0x100000000;<br>
          switch (ce->mode) {<br>
          case XCB_PRESENT_COMPLETE_MODE_<wbr>FLIP:<br>
-            draw->flipping = true;<br>
+            if (!draw->flipping) {<br>
+               draw->flipping = true;<br>
+               for (int b = 0; b < ARRAY_SIZE(draw->buffers); b++) {<br>
+                  if (draw->buffers[b])<br>
+                     draw->buffers[b]->realloc_<wbr>suboptimal = true;<br>
+               }<br>
+            }<br>
             break;<br>
          case XCB_PRESENT_COMPLETE_MODE_<wbr>COPY:<br>
             draw->flipping = false;<br>
             break;<br>
+#if XCB_PRESENT_MAJOR_VERSION > 1 || (XCB_PRESENT_MAJOR_VERSION == 1 && XCB_PRESENT_MINOR_VERSION >= 1)<br>
+         case XCB_PRESENT_COMPLETE_MODE_<wbr>SUBOPTIMAL_COPY:<br>
+            draw->flipping = false;<br>
+            for (int b = 0; b < ARRAY_SIZE(draw->buffers); b++) {<br>
+               if (draw->buffers[b])<br>
+                  draw->buffers[b]->suboptimal = true;<br>
+            }<br>
+#endif<br>
          }<br>
<br>
          if (draw->vtable->show_fps)<br>
@@ -885,6 +901,11 @@ loader_dri3_swap_buffers_msc(<wbr>struct loader_dri3_drawable *draw,<br>
       if (!loader_dri3_have_image_blit(<wbr>draw) && draw->cur_blit_source != -1)<br>
          options |= XCB_PRESENT_OPTION_COPY;<br>
<br>
+#if XCB_PRESENT_MAJOR_VERSION > 1 || (XCB_PRESENT_MAJOR_VERSION == 1 && XCB_PRESENT_MINOR_VERSION >= 1)<br>
+      if (draw->multiplanes_available)<br>
+         options  |= XCB_PRESENT_OPTION_SUBOPTIMAL;<br>
+#endif<br>
+<br>
       back->busy = 1;<br>
       back->last_swap = draw->send_sbc;<br>
       xcb_present_pixmap(draw->conn,<br>
@@ -1287,6 +1308,8 @@ dri3_alloc_render_buffer(<wbr>struct loader_dri3_drawable *draw, unsigned int format,<br>
    buffer->shm_fence = shm_fence;<br>
    buffer->width = width;<br>
    buffer->height = height;<br>
+   buffer->suboptimal = false;<br>
+   buffer->realloc_suboptimal = true;<br>
<br>
    /* Mark the buffer as idle<br>
     */<br>
@@ -1629,11 +1652,12 @@ dri3_get_buffer(__DRIdrawable *driDrawable,<br>
<br>
    buffer = draw->buffers[buf_id];<br>
<br>
-   /* Allocate a new buffer if there isn't an old one, or if that<br>
-    * old one is the wrong size<br>
+   /* Allocate a new buffer if there isn't an old one, if that<br>
+    * old one is the wrong size, or if it's suboptimal<br>
     */<br>
    if (!buffer || buffer->width != draw->width ||<br>
-       buffer->height != draw->height) {<br>
+       buffer->height != draw->height ||<br>
+       (buffer->suboptimal && buffer->realloc_suboptimal)) {<br>
       struct loader_dri3_buffer *new_buffer;<br>
<br>
       /* Allocate the new buffers<br>
@@ -1692,6 +1716,11 @@ dri3_get_buffer(__DRIdrawable *driDrawable,<br>
                                           0, 0, 0);<br>
          }<br>
       }<br>
+<br>
+      /* Avoid multiple reallocations when the best we can use is a suboptimal<br>
+       * format/modifier. */<br>
+      new_buffer->realloc_suboptimal = buffer ? !buffer->suboptimal : true;<br>
+<br>
       buffer = new_buffer;<br>
       draw->buffers[buf_id] = buffer;<br>
    }<br>
diff --git a/src/loader/loader_dri3_<wbr>helper.h b/src/loader/loader_dri3_<wbr>helper.h<br>
index 5689e2707c5..2668a05b758 100644<br>
--- a/src/loader/loader_dri3_<wbr>helper.h<br>
+++ b/src/loader/loader_dri3_<wbr>helper.h<br>
@@ -61,6 +61,8 @@ struct loader_dri3_buffer {<br>
    struct xshmfence *shm_fence; /* pointer to xshmfence object */<br>
    bool         busy;           /* Set on swap, cleared on IdleNotify */<br>
    bool         own_pixmap;     /* We allocated the pixmap ID, free on destroy */<br>
+   bool         suboptimal;     /* Set when CompleteNotify has ModeSuboptimalCopy */<br>
+   bool         realloc_suboptimal; /* Avoid constant reallocation on worst cases */<br></blockquote><div><br></div><div>As I pointed out in the Vulkan one, I don't really understand what the semantics of this are.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
    uint32_t     num_planes;<br>
    uint32_t     size;<br>
diff --git a/src/loader/meson.build b/src/loader/meson.build<br>
index e4455e9a72b..76fcae2cb44 100644<br>
--- a/src/loader/meson.build<br>
+++ b/src/loader/meson.build<br>
@@ -25,7 +25,7 @@ if with_platform_x11 and with_dri3<br>
     'loader_dri3_helper',<br>
     ['loader_dri3_helper.c', 'loader_dri3_helper.h'],<br>
     c_args : c_vis_args,<br>
-    include_directories : inc_include,<br>
+    include_directories : [inc_include, inc_src, inc_drm_uapi],<br>
     dependencies : [<br>
       dep_libdrm, dep_xcb_dri3, dep_xcb_present, dep_xcb_sync, dep_xshmfence,<br>
     ],<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>