svga: use svga_shader_too_large() in compile_vs()
[mesa.git] / src / gallium / drivers / svga / svga_resource_buffer.h
index ca8c8d1f5ea3a37d5d47fe939aa17922667d85df..36467cfdfdffafec7a43880747bc51d9f9498e4d 100644 (file)
@@ -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"
 
 
 /**
@@ -42,7 +45,6 @@
 #define SVGA_BUFFER_MAX_RANGES 32
 
 
-struct svga_screen;
 struct svga_context;
 struct svga_winsys_buffer;
 struct svga_winsys_surface;
@@ -56,6 +58,7 @@ struct svga_buffer_range
    unsigned end;
 };
 
+struct svga_3d_update_gb_image;
 
 /**
  * SVGA pipe buffer.
@@ -167,6 +170,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.
        */
@@ -178,6 +187,8 @@ struct svga_buffer
     * a context. It is only valid if the dma.pending is set above.
     */
    struct list_head head;
+
+   unsigned size;  /**< Approximate size in bytes */
 };
 
 
@@ -206,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 *
@@ -243,10 +320,4 @@ svga_winsys_buffer_create(struct svga_context *svga,
                           unsigned usage,
                           unsigned size);
 
-void
-svga_redefine_user_buffer(struct pipe_context *ctx,
-                          struct pipe_resource *resource,
-                          unsigned offset,
-                          unsigned size);
-
 #endif /* SVGA_BUFFER_H */