[Mesa-dev] [PATCH 1/4] egl: Inform the client API when ancillary buffers may become undefined.

Eric Anholt eric at anholt.net
Fri Dec 26 10:45:51 PST 2014


This is part of the EGL spec, and is useful for a tiled renderer to avoid
the memory bandwidth cost of storing the depth/stencil buffers.
---
 include/GL/internal/dri_interface.h     |  1 +
 src/egl/drivers/dri2/egl_dri2.c         | 36 +++++++++++++++++++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h         |  3 +++
 src/egl/drivers/dri2/platform_android.c |  2 +-
 src/egl/drivers/dri2/platform_drm.c     |  2 +-
 src/egl/drivers/dri2/platform_wayland.c | 12 +----------
 src/egl/drivers/dri2/platform_x11.c     |  3 +--
 7 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 8c5ceb9..1d670b1 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -279,6 +279,7 @@ struct __DRItexBufferExtensionRec {
 
 #define __DRI2_FLUSH_DRAWABLE (1 << 0) /* the drawable should be flushed. */
 #define __DRI2_FLUSH_CONTEXT  (1 << 1) /* glFlush should be called */
+#define __DRI2_FLUSH_INVALIDATE_ANCILLARY (1 << 2)
 
 enum __DRI2throttleReason {
    __DRI2_THROTTLE_SWAPBUFFER,
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 2a6811c..86e5f24 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1087,6 +1087,42 @@ dri2_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
    return dri2_dpy->vtbl->swap_interval(drv, dpy, surf, interval);
 }
 
+/**
+ * Asks the client API to flush any rendering to the drawable so that we can
+ * do our swapbuffers.
+ */
+void
+dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(draw);
+
+   if (dri2_dpy->flush) {
+      if (dri2_dpy->flush->base.version >= 4) {
+         /* We know there's a current context because:
+          *
+          *     "If surface is not bound to the calling thread’s current
+          *      context, an EGL_BAD_SURFACE error is generated."
+         */
+         _EGLContext *ctx = _eglGetCurrentContext();
+         struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+         /* From the EGL 1.4 spec (page 52):
+          *
+          *     "The contents of ancillary buffers are always undefined
+          *      after calling eglSwapBuffers."
+          */
+         dri2_dpy->flush->flush_with_flags(dri2_ctx->dri_context,
+                                           dri2_surf->dri_drawable,
+                                           __DRI2_FLUSH_DRAWABLE |
+                                           __DRI2_FLUSH_INVALIDATE_ANCILLARY,
+                                           __DRI2_THROTTLE_SWAPBUFFER);
+      } else {
+         dri2_dpy->flush->flush(dri2_surf->dri_drawable);
+      }
+   }
+}
+
 static EGLBoolean
 dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 52f05fb..9efe1f7 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -332,4 +332,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
+void
+dri2_flush_drawable_for_swapbuffers(_EGLDisplay *disp, _EGLSurface *draw);
+
 #endif /* EGL_DRI2_INCLUDED */
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 61a99ba..f482526 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -311,7 +311,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
          dri2_drv->glFlush();
    }
 
-   (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+   dri2_flush_drawable_for_swapbuffers(disp, draw);
 
    if (dri2_surf->buffer)
       droid_window_enqueue_buffer(dri2_surf);
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 753c60f..02e87f7 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -431,7 +431,7 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
          dri2_surf->back = NULL;
       }
 
-      (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+      dri2_flush_drawable_for_swapbuffers(disp, draw);
       (*dri2_dpy->flush->invalidate)(dri2_surf->dri_drawable);
    }
 
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index ba0eb10..e8b4413 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -649,17 +649,7 @@ dri2_wl_swap_buffers_with_damage(_EGLDriver *drv,
       }
    }
 
-   if (dri2_dpy->flush->base.version >= 4) {
-      ctx = _eglGetCurrentContext();
-      dri2_ctx = dri2_egl_context(ctx);
-      (*dri2_dpy->flush->flush_with_flags)(dri2_ctx->dri_context,
-                                           dri2_surf->dri_drawable,
-                                           __DRI2_FLUSH_DRAWABLE,
-                                           __DRI2_THROTTLE_SWAPBUFFER);
-   } else {
-      (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
-   }
-
+   dri2_flush_drawable_for_swapbuffers(disp, draw);
    (*dri2_dpy->flush->invalidate)(dri2_surf->dri_drawable);
 
    wl_surface_commit(dri2_surf->wl_win->surface);
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index f8c4b70..dd88e90 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -771,8 +771,7 @@ dri2_x11_swap_buffers_msc(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw,
    if (draw->SwapBehavior == EGL_BUFFER_PRESERVED || !dri2_dpy->swap_available)
       return dri2_copy_region(drv, disp, draw, dri2_surf->region) ? 0 : -1;
 
-   if (dri2_dpy->flush)
-      (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);
+   dri2_flush_drawable_for_swapbuffers(disp, draw);
 
    cookie = xcb_dri2_swap_buffers_unchecked(dri2_dpy->conn, dri2_surf->drawable,
                   msc_hi, msc_lo, divisor_hi, divisor_lo, remainder_hi, remainder_lo);
-- 
2.1.3



More information about the mesa-dev mailing list