st/mesa: use u_upload_mgr to upload vertices for glClear fallback
authorMarek Olšák <maraeo@gmail.com>
Fri, 13 Apr 2012 17:27:45 +0000 (19:27 +0200)
committerMarek Olšák <maraeo@gmail.com>
Wed, 18 Apr 2012 14:19:39 +0000 (16:19 +0200)
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_clear.h
src/mesa/state_tracker/st_cb_flush.c
src/mesa/state_tracker/st_context.h

index 1935833727057996cabf31ece0a3fd9320ad6084..f0c30b65ba2b1fc34e38ef59352a4367c35b476c 100644 (file)
@@ -53,6 +53,7 @@
 #include "util/u_inlines.h"
 #include "util/u_simple_shaders.h"
 #include "util/u_draw_quad.h"
+#include "util/u_upload_mgr.h"
 
 #include "cso_cache/cso_context.h"
 
@@ -87,10 +88,6 @@ st_destroy_clear(struct st_context *st)
       cso_delete_vertex_shader(st->cso_context, st->clear.vs);
       st->clear.vs = NULL;
    }
-   if (st->clear.vbuf) {
-      pipe_resource_reference(&st->clear.vbuf, NULL);
-      st->clear.vbuf = NULL;
-   }
 }
 
 
@@ -140,36 +137,8 @@ draw_quad(struct st_context *st,
           const union pipe_color_union *color)
 {
    struct pipe_context *pipe = st->pipe;
-
-   /* XXX: Need to improve buffer_write to allow NO_WAIT (as well as
-    * no_flush) updates to buffers where we know there is no conflict
-    * with previous data.  Currently using max_slots > 1 will cause
-    * synchronous rendering if the driver flushes its command buffers
-    * between one bitmap and the next.  Our flush hook below isn't
-    * sufficient to catch this as the driver doesn't tell us when it
-    * flushes its own command buffers.  Until this gets fixed, pay the
-    * price of allocating a new buffer for each bitmap cache-flush to
-    * avoid synchronous rendering.
-    */
-   const GLuint max_slots = 1; /* 1024 / sizeof(st->clear.vertices); */
-   GLuint i;
-
-   if (st->clear.vbuf_slot >= max_slots) {
-      pipe_resource_reference(&st->clear.vbuf, NULL);
-      st->clear.vbuf_slot = 0;
-   }
-
-   if (!st->clear.vbuf) {
-      st->clear.vbuf = pipe_buffer_create(pipe->screen,
-                                          PIPE_BIND_VERTEX_BUFFER,
-                                          PIPE_USAGE_STREAM,
-                                          max_slots * sizeof(st->clear.vertices));
-   }
-
-   if (!st->clear.vbuf) {
-      /* ran out of memory */
-      return;
-   }
+   struct pipe_resource *vbuf = NULL;
+   GLuint i, offset;
 
    /* positions */
    st->clear.vertices[0][0][0] = x0;
@@ -194,24 +163,22 @@ draw_quad(struct st_context *st,
       st->clear.vertices[i][1][3] = color->f[3];
    }
 
-   /* put vertex data into vbuf */
-   pipe_buffer_write_nooverlap(st->pipe, st->clear.vbuf,
-                                           st->clear.vbuf_slot
-                                             * sizeof(st->clear.vertices),
-                                           sizeof(st->clear.vertices),
-                                           st->clear.vertices);
+   u_upload_data(st->uploader, 0, sizeof(st->clear.vertices),
+                st->clear.vertices, &offset, &vbuf);
+   if (!vbuf) {
+      return;
+   }
+   u_upload_unmap(st->uploader);
 
    /* draw */
    util_draw_vertex_buffer(pipe,
                            st->cso_context,
-                           st->clear.vbuf, 
-                           st->clear.vbuf_slot * sizeof(st->clear.vertices),
+                           vbuf, offset,
                            PIPE_PRIM_TRIANGLE_FAN,
                            4,  /* verts */
                            2); /* attribs/vert */
 
-   /* Increment slot */
-   st->clear.vbuf_slot++;
+   pipe_resource_reference(&vbuf, NULL);
 }
 
 
@@ -465,22 +432,6 @@ check_clear_stencil_with_quad(struct gl_context *ctx, struct gl_renderbuffer *rb
 }
 
 
-
-/**
- * Called when we need to flush.
- */
-void
-st_flush_clear(struct st_context *st)
-{
-   /* Release vertex buffer to avoid synchronous rendering if we were
-    * to map it in the next frame.
-    */
-   pipe_resource_reference(&st->clear.vbuf, NULL);
-   st->clear.vbuf_slot = 0;
-}
-
-
 /**
  * Called via ctx->Driver.Clear()
  */
index b27c09d10e4759640b07ccaca3d9d26f21c0261b..e9297de9ce4eeaf04568917fb2251cf95e2cbdee 100644 (file)
@@ -40,9 +40,6 @@ st_init_clear(struct st_context *st);
 extern void
 st_destroy_clear(struct st_context *st);
 
-extern void
-st_flush_clear(struct st_context *st);
-
 
 extern void
 st_init_clear_functions(struct dd_function_table *functions);
index 0e27cb9a3fd7245ea98badbe8b43603104aff707..724bc1971b476e971b8c1f31c6cc45472ec15cd0 100644 (file)
@@ -85,7 +85,6 @@ void st_flush( struct st_context *st,
     * successive frames:
     */
    st_flush_bitmap(st);
-   st_flush_clear(st);
    util_blit_flush(st->blit);
    util_gen_mipmap_flush(st->gen_mipmap);
 
index 9482ed69969ddf56255c12b17e02143a605473f3..f1342a64615ff9f89c974bd20e1a1cb30aaadb87 100644 (file)
@@ -171,8 +171,6 @@ struct st_context
       void *vs;
       void *fs;
       float vertices[4][2][4];  /**< vertex pos + color */
-      struct pipe_resource *vbuf;
-      unsigned vbuf_slot;
       boolean enable_ds_separate;
    } clear;