i915g: Keep vertex buffers in a fifo
authorJakob Bornecrantz <wallbraker@gmail.com>
Tue, 8 Sep 2009 19:40:37 +0000 (20:40 +0100)
committerJakob Bornecrantz <jakob@vmware.com>
Tue, 8 Sep 2009 23:43:35 +0000 (00:43 +0100)
src/gallium/drivers/i915simple/i915_prim_vbuf.c

index 508f4560e4847287c7d88153aa5de65e39132d8d..f10f10a72a6b8ed634c2303a43faa020336b6915 100644 (file)
@@ -44,6 +44,7 @@
 #include "pipe/p_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "util/u_fifo.h"
 
 #include "i915_context.h"
 #include "i915_reg.h"
@@ -78,6 +79,11 @@ struct i915_vbuf_render {
    void *vbo_ptr;
    size_t vbo_alloc_size;
    size_t vbo_max_used;
+
+   /* stuff for the pool */
+   struct util_fifo *pool_fifo;
+   unsigned pool_used;
+   boolean pool_not_used;
 };
 
 
@@ -120,9 +126,14 @@ i915_vbuf_render_allocate_vertices(struct vbuf_render *render,
 
    if (i915_render->vbo_size > size + i915_render->vbo_offset && !i915->vbo_flushed) {
    } else {
+      if (i915->vbo_flushed)
+         i915_render->pool_used = 0;
       i915->vbo_flushed = 0;
       if (i915_render->vbo) {
-         iws->buffer_destroy(iws, i915_render->vbo);
+         if (i915_render->pool_not_used)
+            iws->buffer_destroy(iws, i915_render->vbo);
+         else
+            u_fifo_add(i915_render->pool_fifo, i915_render->vbo);
          i915_render->vbo = NULL;
       }
    }
@@ -130,9 +141,21 @@ i915_vbuf_render_allocate_vertices(struct vbuf_render *render,
    if (!i915_render->vbo) {
       i915_render->vbo_size = MAX2(size, i915_render->vbo_alloc_size);
       i915_render->vbo_offset = 0;
-      i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, 64,
-                                            INTEL_NEW_VERTEX);
 
+      if (i915_render->vbo_size != i915_render->vbo_alloc_size) {
+         i915_render->pool_not_used = TRUE;
+         i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, 64,
+                                               INTEL_NEW_VERTEX);
+      } else {
+         i915_render->pool_not_used = FALSE;
+
+         if (i915_render->pool_used >= 2) {
+            FLUSH_BATCH(NULL);
+            i915->vbo_flushed = 0;
+            i915_render->pool_used = 0;
+         }
+         u_fifo_pop(i915_render->pool_fifo, (void**)&i915_render->vbo);
+      }
    }
 
    i915_render->vertex_size = vertex_size;
@@ -504,6 +527,7 @@ i915_vbuf_render_create(struct i915_context *i915)
 {
    struct i915_vbuf_render *i915_render = CALLOC_STRUCT(i915_vbuf_render);
    struct intel_winsys *iws = i915->iws;
+   int i;
 
    i915_render->i915 = i915;
    
@@ -527,8 +551,15 @@ i915_vbuf_render_create(struct i915_context *i915)
    i915_render->vbo_alloc_size = 128 * 4096;
    i915_render->vbo_size = i915_render->vbo_alloc_size;
    i915_render->vbo_offset = 0;
-   i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, 64,
-                                         INTEL_NEW_VERTEX);
+
+   i915_render->pool_fifo = u_fifo_create(6);
+   for (i = 0; i < 6; i++)
+      u_fifo_add(i915_render->pool_fifo,
+                 iws->buffer_create(iws, i915_render->vbo_size, 64,
+                                    INTEL_NEW_VERTEX));
+   u_fifo_pop(i915_render->pool_fifo, (void**)&i915_render->vbo);
+   i915_render->pool_used = 1;
+
    /* TODO JB: is this realy needed? */
    i915_render->vbo_ptr = iws->buffer_map(iws, i915_render->vbo, TRUE);
    iws->buffer_unmap(iws, i915_render->vbo);