[Mesa-dev] [PATCH 12/19] svga: add new helper functions for GBS buffers

Brian Paul brianp at vmware.com
Thu Feb 13 17:21:04 PST 2014


Reviewed-by: Thomas Hellstrom <thellstrom at vmware.com>
Cc: "10.1" <mesa-stable at lists.freedesktop.org>
---
 src/gallium/drivers/svga/svga_resource_buffer.h |   76 +++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/src/gallium/drivers/svga/svga_resource_buffer.h b/src/gallium/drivers/svga/svga_resource_buffer.h
index b431d7b..36467cf 100644
--- a/src/gallium/drivers/svga/svga_resource_buffer.h
+++ b/src/gallium/drivers/svga/svga_resource_buffer.h
@@ -34,6 +34,9 @@
 #include "util/u_double_list.h"
 
 #include "svga_screen_cache.h"
+#include "svga_screen.h"
+#include "svga_cmd.h"
+#include "svga_context.h"
 
 
 /**
@@ -55,6 +58,7 @@ struct svga_buffer_range
    unsigned end;
 };
 
+struct svga_3d_update_gb_image;
 
 /**
  * SVGA pipe buffer.
@@ -167,6 +171,12 @@ struct svga_buffer
       SVGA3dCopyBox *boxes;
 
       /**
+       * Pointer to the sequence of update commands
+       * *inside* the command buffer.
+       */
+      struct svga_3d_update_gb_image *updates;
+
+      /**
        * Context that has the pending DMA to this buffer.
        */
       struct svga_context *svga;
@@ -207,7 +217,73 @@ svga_buffer_is_user_buffer( struct pipe_resource *buffer )
    }
 }
 
+/**
+ * Returns a pointer to a struct svga_winsys_screen given a
+ * struct svga_buffer.
+ */
+static INLINE struct svga_winsys_screen *
+svga_buffer_winsys_screen(struct svga_buffer *sbuf)
+{
+   return svga_screen(sbuf->b.b.screen)->sws;
+}
+
+
+/**
+ * Returns whether a buffer has hardware storage that is
+ * visible to the GPU.
+ */
+static INLINE boolean
+svga_buffer_has_hw_storage(struct svga_buffer *sbuf)
+{
+   if (svga_buffer_winsys_screen(sbuf)->have_gb_objects)
+      return (sbuf->handle ? TRUE : FALSE);
+   else
+      return (sbuf->hwbuf ? TRUE : FALSE);
+}
+
+/**
+ * Map the hardware storage of a buffer.
+ */
+static INLINE void *
+svga_buffer_hw_storage_map(struct svga_context *svga,
+                           struct svga_buffer *sbuf,
+                           unsigned flags, boolean *retry)
+{
+   struct svga_winsys_screen *sws = svga_buffer_winsys_screen(sbuf);
+   if (sws->have_gb_objects) {
+      return svga->swc->surface_map(svga->swc, sbuf->handle, flags, retry);
+   } else {
+      *retry = FALSE;
+      return sws->buffer_map(sws, sbuf->hwbuf, flags);
+   }
+}
 
+/**
+ * Unmap the hardware storage of a buffer.
+ */
+static INLINE void
+svga_buffer_hw_storage_unmap(struct svga_context *svga,
+                             struct svga_buffer *sbuf)
+{
+   struct svga_winsys_screen *sws = svga_buffer_winsys_screen(sbuf);
+
+   if (sws->have_gb_objects) {
+      struct svga_winsys_context *swc = svga->swc;
+      boolean rebind;
+      swc->surface_unmap(swc, sbuf->handle, &rebind);
+      if (rebind) {
+         enum pipe_error ret;
+         ret = SVGA3D_BindGBSurface(swc, sbuf->handle);
+         if (ret != PIPE_OK) {
+            /* flush and retry */
+            svga_context_flush(svga, NULL);
+            ret = SVGA3D_BindGBSurface(swc, sbuf->handle);
+            assert(ret == PIPE_OK);
+         }
+      }
+   } else
+      sws->buffer_unmap(sws, sbuf->hwbuf);
+}
 
 
 struct pipe_resource *
-- 
1.7.10.4



More information about the mesa-dev mailing list