[Mesa-dev] [PATCH 05/18] i965: Reuse our VBO for streaming fast-clear vertices

Chris Wilson chris at chris-wilson.co.uk
Mon Jul 6 03:33:10 PDT 2015


Rather than allocating a fresh page every time we clear a buffer, keep
that page around between invocations by tracking the last used offset
and only allocating a fresh page when we wrap.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 src/mesa/drivers/dri/i965/brw_meta_fast_clear.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c
index a571a74..ffd1e3b 100644
--- a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c
+++ b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c
@@ -55,6 +55,7 @@
 struct brw_fast_clear_state {
    GLuint vao;
    GLuint vbo;
+   GLuint vbo_offset;
    GLuint shader_prog;
    GLint color_location;
 };
@@ -83,6 +84,8 @@ brw_fast_clear_init(struct brw_context *brw)
    _mesa_VertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
    _mesa_EnableVertexAttribArray(0);
 
+   clear->vbo_offset = 4096; /* Force an allocation on first use */
+
    return true;
 }
 
@@ -166,7 +169,8 @@ struct rect {
 static void
 brw_draw_rectlist(struct gl_context *ctx, struct rect *rect, int num_instances)
 {
-   int start = 0, count = 3;
+   struct brw_fast_clear_state *clear = brw_context(ctx)->fast_clear_state;
+   int start, count = 3, offset;
    struct _mesa_prim prim;
    float verts[6];
 
@@ -178,8 +182,15 @@ brw_draw_rectlist(struct gl_context *ctx, struct rect *rect, int num_instances)
    verts[5] = rect->y0;
 
    /* upload new vertex data */
-   _mesa_BufferData(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts,
-                    GL_DYNAMIC_DRAW_ARB);
+   offset = clear->vbo_offset;
+   clear->vbo_offset += sizeof(verts);
+   if (clear->vbo_offset > 4096) {
+      _mesa_BufferData(GL_ARRAY_BUFFER_ARB, 4096, NULL, GL_STREAM_DRAW_ARB);
+      offset = 0;
+      clear->vbo_offset = sizeof(verts);
+   }
+   _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB, offset, sizeof(verts), verts);
+   start = offset / (2*sizeof(float));
 
    if (ctx->NewState)
       _mesa_update_state(ctx);
-- 
2.1.4



More information about the mesa-dev mailing list