svga: add, use SVGA3D_SURFACE_HINT_VOLUME flag
[mesa.git] / src / gallium / drivers / svga / svga_pipe_draw.c
index d53edcb23c534de320e9f880a5cf1c823e7e3a8d..e72032e685d6c7ac34b2f7ffa5c989f207018799 100644 (file)
  *
  **********************************************************/
 
-#include "svga_cmd.h"
 
 #include "util/u_format.h"
 #include "util/u_inlines.h"
 #include "util/u_prim.h"
 #include "util/u_time.h"
+#include "util/u_upload_mgr.h"
 #include "indices/u_indices.h"
 
 #include "svga_hw_reg.h"
+#include "svga_cmd.h"
 #include "svga_context.h"
 #include "svga_screen.h"
 #include "svga_draw.h"
@@ -39,7 +40,7 @@
 #include "svga_swtnl.h"
 #include "svga_debug.h"
 #include "svga_resource_buffer.h"
-#include "util/u_upload_mgr.h"
+
 
 /**
  * Determine the ranges to upload for the user-buffers referenced
@@ -51,7 +52,6 @@
  * may be uploaded to different hardware buffers chosen by the utility
  * upload manager.
  */
-
 static void
 svga_user_buffer_range(struct svga_context *svga,
                        unsigned start,
@@ -59,7 +59,7 @@ svga_user_buffer_range(struct svga_context *svga,
                        unsigned instance_count)
 {
    const struct pipe_vertex_element *ve = svga->curr.velems->velem;
-   int i;
+   unsigned i;
 
    /*
     * Release old uploaded range (if not done already) and
@@ -95,16 +95,9 @@ svga_user_buffer_range(struct svga_context *svga,
             first = ve[i].src_offset;
             count = (instance_count + instance_div - 1) / instance_div;
             size = vb->stride * (count - 1) + elemSize;
-         } else if (vb->stride) {
+         } else {
             first = vb->stride * start + ve[i].src_offset;
             size = vb->stride * (count - 1) + elemSize;
-         } else {
-            /* Only a single vertex!
-             * Upload with the largest vertex size the hw supports,
-             * if possible.
-             */
-            first = ve[i].src_offset;
-            size = MIN2(16, vb->buffer->width0);
          }
 
          buffer->uploaded.start = MIN2(buffer->uploaded.start, first);
@@ -113,13 +106,13 @@ svga_user_buffer_range(struct svga_context *svga,
    }
 }
 
+
 /**
  * svga_upload_user_buffers - upload parts of user buffers
  *
  * This function streams a part of a user buffer to hw and fills
  * svga_buffer::uploaded with information on the upload.
  */
-
 static int
 svga_upload_user_buffers(struct svga_context *svga,
                          unsigned start,
@@ -138,7 +131,6 @@ svga_upload_user_buffers(struct svga_context *svga,
 
       if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
          struct svga_buffer *buffer = svga_buffer(vb->buffer);
-         boolean flushed;
 
          /*
           * Check if already uploaded. Otherwise go ahead and upload.
@@ -153,8 +145,7 @@ svga_upload_user_buffers(struct svga_context *svga,
                                 buffer->uploaded.end - buffer->uploaded.start,
                                 &buffer->b.b,
                                 &buffer->uploaded.offset,
-                                &buffer->uploaded.buffer,
-                                &flushed);
+                                &buffer->uploaded.buffer);
 
          if (ret)
             return ret;
@@ -177,6 +168,7 @@ svga_upload_user_buffers(struct svga_context *svga,
    return PIPE_OK;
 }
 
+
 /**
  * svga_release_user_upl_buffers - release uploaded parts of user buffers
  *
@@ -188,7 +180,6 @@ svga_upload_user_buffers(struct svga_context *svga,
  * svga_buffer::source_offset is set to 0, and svga_buffer::uploaded::buffer
  * is set to 0.
  */
-
 static void
 svga_release_user_upl_buffers(struct svga_context *svga)
 {
@@ -203,6 +194,17 @@ svga_release_user_upl_buffers(struct svga_context *svga)
       if (vb->buffer && svga_buffer_is_user_buffer(vb->buffer)) {
          struct svga_buffer *buffer = svga_buffer(vb->buffer);
 
+         /* The buffer_offset is relative to the uploaded buffer.
+          * Since we're discarding that buffer we need to reset this offset
+          * so it's not inadvertantly applied to a subsequent draw.
+          *
+          * XXX a root problem here is that the svga->curr.vb[] information
+          * is getting set both by gallium API calls and by code in
+          * svga_upload_user_buffers().  We should instead have two copies
+          * of the vertex buffer information and choose between as needed.
+          */
+         vb->buffer_offset = 0;
+
          buffer->uploaded.start = ~0;
          buffer->uploaded.end = 0;
          if (buffer->uploaded.buffer)
@@ -220,13 +222,13 @@ retry_draw_range_elements( struct svga_context *svga,
                            int index_bias,
                            unsigned min_index,
                            unsigned max_index,
-                           unsigned prim, 
-                           unsigned start, 
+                           unsigned prim,
+                           unsigned start,
                            unsigned count,
                            unsigned instance_count,
                            boolean do_retry )
 {
-   enum pipe_error ret = 0;
+   enum pipe_error ret = PIPE_OK;
 
    svga_hwtnl_set_unfilled( svga->hwtnl,
                             svga->curr.rast->hw_unfilled );
@@ -241,14 +243,14 @@ retry_draw_range_elements( struct svga_context *svga,
       goto retry;
 
    ret = svga_update_state( svga, SVGA_STATE_HW_DRAW );
-   if (ret)
+   if (ret != PIPE_OK)
       goto retry;
 
    ret = svga_hwtnl_draw_range_elements( svga->hwtnl,
                                          index_buffer, index_size, index_bias,
                                          min_index, max_index,
                                          prim, start, count );
-   if (ret)
+   if (ret != PIPE_OK)
       goto retry;
 
    return PIPE_OK;
@@ -271,8 +273,8 @@ retry:
 
 static enum pipe_error
 retry_draw_arrays( struct svga_context *svga,
-                   unsigned prim, 
-                   unsigned start, 
+                   unsigned prim,
+                   unsigned start,
                    unsigned count,
                    unsigned instance_count,
                    boolean do_retry )
@@ -292,18 +294,18 @@ retry_draw_arrays( struct svga_context *svga,
       goto retry;
 
    ret = svga_update_state( svga, SVGA_STATE_HW_DRAW );
-   if (ret)
+   if (ret != PIPE_OK)
       goto retry;
 
    ret = svga_hwtnl_draw_arrays( svga->hwtnl, prim,
                                  start, count );
-   if (ret)
+   if (ret != PIPE_OK)
       goto retry;
 
-   return 0;
+   return PIPE_OK;
 
 retry:
-   if (ret == PIPE_ERROR_OUT_OF_MEMORY && do_retry) 
+   if (ret == PIPE_ERROR_OUT_OF_MEMORY && do_retry)
    {
       svga_context_flush( svga, NULL );
 
@@ -344,7 +346,7 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       svga->curr.reduced_prim = reduced_prim;
       svga->dirty |= SVGA_NEW_REDUCED_PRIMITIVE;
    }
-   
+
    needed_swtnl = svga->state.sw.need_swtnl;
 
    svga_update_state_retry( svga, SVGA_STATE_NEED_SWTNL );
@@ -401,6 +403,9 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       }
    }
 
+   /* XXX: Silence warnings, do something sensible here? */
+   (void)ret;
+
    svga_release_user_upl_buffers( svga );
 
    if (SVGA_DEBUG & DEBUG_FLUSH) {