[Mesa-dev] [PATCH 4/4] pipe: Add new bind flag for shared resources with flush_resource call

Axel Davy axel.davy at ens.fr
Wed Oct 21 03:28:03 PDT 2015


Add a new bind flag to differentiate shared resources
that must be readable after any flush, or that can afford
being readable only after flush_resource.

Previously the two cases were mixed, and implictly things were done
such that there would be no issues.

flush_resource is called for:
. st/nine back buffers
. dri2 and dri3 back buffers (both wayland and x11)

flush_resource is not called for:
. gbm buffers
. dri2 and dri3 x11 (fake/real) front buffers
. EGLImages (they can be shared)

I didn't look at what the other state trackers do, but a grep
said there is no flush_resource call outside dri2 and nine state
trackers.

Signed-off-by: Axel Davy <axel.davy at ens.fr>
---
 src/gallium/include/pipe/p_defines.h          |  8 ++++++++
 src/gallium/state_trackers/dri/dri2.c         | 17 +++++++++--------
 src/gallium/state_trackers/dri/dri_drawable.c |  9 +++++++--
 src/gallium/state_trackers/nine/swapchain9.c  | 10 +++++++---
 4 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 1ad545a..f877893 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -399,6 +399,14 @@ enum pipe_flush_flags
 #define PIPE_BIND_SHARED      (1 << 19) /* get_texture_handle ??? */
 #define PIPE_BIND_LINEAR      (1 << 20)
 
+/* This flag indicates that in addition to being shared, the resource won't be
+ * read by any external process before we call flush_resource. This allows
+ * things like compressing the buffer when drawing, while uncompressing on
+ * flush_resource. The PIPE_BIND_SHARED must still be set with this flag.
+ * If PIPE_BIND_SHARED is specified but not
+ * PIPE_BIND_SHARED_FLUSH_RESOURCE, then the resource must be
+ * readable by external processes after any normal flush. */
+#define PIPE_BIND_SHARED_FLUSH_RESOURCE   (1 << 21)
 
 /**
  * Flags for the driver about resource behaviour:
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 5f5bc86..74b398f 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -291,27 +291,25 @@ dri2_allocate_buffer(__DRIscreen *sPriv,
    struct dri2_buffer *buffer;
    struct pipe_resource templ;
    enum pipe_format pf;
-   unsigned bind = 0;
+   unsigned bind = PIPE_BIND_SHARED; /* because we get the handle and stride */
    struct winsys_handle whandle;
 
    switch (attachment) {
       case __DRI_BUFFER_FRONT_LEFT:
       case __DRI_BUFFER_FAKE_FRONT_LEFT:
-         bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+         bind |= PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
          break;
       case __DRI_BUFFER_BACK_LEFT:
-         bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+         bind |= PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW |
+            PIPE_BIND_SHARED_FLUSH_RESOURCE;
          break;
       case __DRI_BUFFER_DEPTH:
       case __DRI_BUFFER_DEPTH_STENCIL:
       case __DRI_BUFFER_STENCIL:
-            bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
+            bind |= PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
          break;
    }
 
-   /* because we get the handle and stride */
-   bind |= PIPE_BIND_SHARED;
-
    switch (format) {
       case 32:
          pf = PIPE_FORMAT_BGRA8888_UNORM;
@@ -555,7 +553,8 @@ dri2_allocate_textures(struct dri_context *ctx,
          if (drawable->textures[statt]) {
             templ.format = drawable->textures[statt]->format;
             templ.bind = drawable->textures[statt]->bind &
-               ~(PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
+               ~(PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |
+                 PIPE_BIND_SHARED_FLUSH_RESOURCE);
             templ.nr_samples = drawable->stvis.samples;
 
             /* Try to reuse the resource.
@@ -834,6 +833,8 @@ dri2_create_image(__DRIscreen *_screen,
       tex_usage |= PIPE_BIND_SCANOUT;
    if (use & __DRI_IMAGE_USE_SHARE)
       tex_usage |= PIPE_BIND_SHARED;
+   if (use & __DRI_IMAGE_USE_BACKBUFFER)
+      tex_usage |= PIPE_BIND_SHARED | PIPE_BIND_SHARED_FLUSH_RESOURCE;
    if (use & __DRI_IMAGE_USE_LINEAR)
       tex_usage |= PIPE_BIND_LINEAR;
    if (use & __DRI_IMAGE_USE_CURSOR) {
diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c
index 04041d6..badd111 100644
--- a/src/gallium/state_trackers/dri/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/dri_drawable.c
@@ -276,9 +276,7 @@ dri_drawable_get_format(struct dri_drawable *drawable,
 {
    switch (statt) {
    case ST_ATTACHMENT_FRONT_LEFT:
-   case ST_ATTACHMENT_BACK_LEFT:
    case ST_ATTACHMENT_FRONT_RIGHT:
-   case ST_ATTACHMENT_BACK_RIGHT:
       /* Other pieces of the driver stack get confused and behave incorrectly
        * when they get an sRGB drawable. st/mesa receives "drawable->stvis"
        * though other means and handles it correctly, so we don't really need
@@ -288,6 +286,13 @@ dri_drawable_get_format(struct dri_drawable *drawable,
       *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW |
          PIPE_BIND_SHARED;
       break;
+   case ST_ATTACHMENT_BACK_LEFT:
+   case ST_ATTACHMENT_BACK_RIGHT:
+      /* Idem */
+      *format = util_format_linear(drawable->stvis.color_format);
+      *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW |
+         PIPE_BIND_SHARED | PIPE_BIND_SHARED_FLUSH_RESOURCE;
+      break;
    case ST_ATTACHMENT_DEPTH_STENCIL:
       *format = drawable->stvis.depth_stencil_format;
       *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
diff --git a/src/gallium/state_trackers/nine/swapchain9.c b/src/gallium/state_trackers/nine/swapchain9.c
index 3f5be26..39da084 100644
--- a/src/gallium/state_trackers/nine/swapchain9.c
+++ b/src/gallium/state_trackers/nine/swapchain9.c
@@ -296,7 +296,8 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
                      PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_RENDER_TARGET;
         tmplt.nr_samples = pParams->MultiSampleType;
         if (!has_present_buffers)
-            tmplt.bind |= PIPE_BIND_SHARED | PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET;
+            tmplt.bind |= PIPE_BIND_SHARED | PIPE_BIND_SHARED_FLUSH_RESOURCE |
+                          PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET;
         tmplt.format = d3d9_to_pipe_format_checked(This->screen,
                                                    pParams->BackBufferFormat,
                                                    PIPE_TEXTURE_2D,
@@ -330,7 +331,9 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
         }
         if (has_present_buffers) {
             tmplt.format = PIPE_FORMAT_B8G8R8X8_UNORM;
-            tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHARED | PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET;
+            tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHARED |
+                         PIPE_BIND_SHARED_FLUSH_RESOURCE | PIPE_BIND_SCANOUT |
+                         PIPE_BIND_DISPLAY_TARGET;
             tmplt.nr_samples = 0;
             if (This->actx->linear_framebuffer)
                 tmplt.bind |= PIPE_BIND_LINEAR;
@@ -540,7 +543,8 @@ create_present_buffer( struct NineSwapChain9 *This,
     tmplt.format = PIPE_FORMAT_B8G8R8X8_UNORM;
     tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_TRANSFER_READ |
                  PIPE_BIND_TRANSFER_WRITE | PIPE_BIND_RENDER_TARGET |
-                 PIPE_BIND_SHARED | PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET;
+                 PIPE_BIND_SHARED | PIPE_BIND_SHARED_FLUSH_RESOURCE |
+                 PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET;
     tmplt.nr_samples = 0;
     if (This->actx->linear_framebuffer)
         tmplt.bind |= PIPE_BIND_LINEAR;
-- 
2.6.1



More information about the mesa-dev mailing list