[cairo-commit] src/cairo-gl-composite.c src/cairo-gl-device.c src/cairo-gl-private.h

Chris Wilson ickle at kemper.freedesktop.org
Mon May 21 03:34:20 PDT 2012


 src/cairo-gl-composite.c |   29 +++++------------------------
 src/cairo-gl-device.c    |    9 +++------
 src/cairo-gl-private.h   |    8 +++-----
 3 files changed, 11 insertions(+), 35 deletions(-)

New commits:
commit aed94a5bc650f579368b4b814a8729570c32147e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat May 19 10:20:20 2012 +0100

    gl: Replace vbo with static allocation and immediate arrays
    
    Some drivers have terrible latency issues when using VBO and for our
    dynamic use-case (we never reuse a VBO currently) there is little
    benefit from using a VBO and often a loss of performance from doing so.
    And there is the benefit from reducing the number of our own code paths.

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index b4c3e3d..bcf41ec 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -244,7 +244,7 @@ _cairo_gl_context_setup_operand (cairo_gl_context_t *ctx,
 
 	dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2,
 					GL_FLOAT, GL_FALSE, vertex_size,
-					(void *) (uintptr_t) vertex_offset);
+					ctx->vb + vertex_offset);
 	dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit);
         break;
     case CAIRO_GL_OPERAND_LINEAR_GRADIENT:
@@ -258,7 +258,7 @@ _cairo_gl_context_setup_operand (cairo_gl_context_t *ctx,
 
 	dispatch->VertexAttribPointer (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit, 2,
 				       GL_FLOAT, GL_FALSE, vertex_size,
-				       (void *) (uintptr_t) vertex_offset);
+				       ctx->vb + vertex_offset);
 	dispatch->EnableVertexAttribArray (CAIRO_GL_TEXCOORD0_ATTRIB_INDEX + tex_unit);
 	break;
     }
@@ -273,7 +273,7 @@ _cairo_gl_context_setup_spans (cairo_gl_context_t *ctx,
 
     dispatch->VertexAttribPointer (CAIRO_GL_COLOR_ATTRIB_INDEX, 4,
 				   GL_UNSIGNED_BYTE, GL_TRUE, vertex_size,
-				   (void *) (uintptr_t) vertex_offset);
+				   ctx->vb + vertex_offset);
     dispatch->EnableVertexAttribArray (CAIRO_GL_COLOR_ATTRIB_INDEX);
     ctx->spans = TRUE;
 }
@@ -496,10 +496,9 @@ _cairo_gl_composite_setup_vbo (cairo_gl_context_t *ctx,
         _cairo_gl_composite_flush (ctx);
 
     if (_cairo_gl_context_is_flushed (ctx)) {
-        ctx->dispatch.BindBuffer (GL_ARRAY_BUFFER, ctx->vbo);
-
 	ctx->dispatch.VertexAttribPointer (CAIRO_GL_VERTEX_ATTRIB_INDEX, 2,
-					   GL_FLOAT, GL_FALSE, size_per_vertex, NULL);
+					   GL_FLOAT, GL_FALSE, size_per_vertex,
+					   ctx->vb);
 	ctx->dispatch.EnableVertexAttribArray (CAIRO_GL_VERTEX_ATTRIB_INDEX);
     }
     ctx->vertex_size = size_per_vertex;
@@ -746,13 +745,6 @@ _cairo_gl_composite_draw (cairo_gl_context_t *ctx,
 static void
 _cairo_gl_composite_unmap_vertex_buffer (cairo_gl_context_t *ctx)
 {
-    if (ctx->has_map_buffer)
-	ctx->dispatch.UnmapBuffer (GL_ARRAY_BUFFER);
-    else
-	ctx->dispatch.BufferData (GL_ARRAY_BUFFER, ctx->vb_offset,
-				  ctx->vb, GL_DYNAMIC_DRAW);
-
-    ctx->vb = NULL;
     ctx->vb_offset = 0;
 }
 
@@ -812,17 +804,6 @@ _cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx,
 
     if (ctx->vb_offset + n_vertices * ctx->vertex_size > CAIRO_GL_VBO_SIZE)
 	_cairo_gl_composite_flush (ctx);
-
-    if (ctx->vb == NULL) {
-	if (ctx->has_map_buffer) {
-	    dispatch->BufferData (GL_ARRAY_BUFFER, CAIRO_GL_VBO_SIZE,
-				  NULL, GL_DYNAMIC_DRAW);
-	    ctx->vb = dispatch->MapBuffer (GL_ARRAY_BUFFER, GL_WRITE_ONLY);
-	}
-	else {
-	    ctx->vb = ctx->vb_mem;
-	}
-    }
 }
 
 static inline void
diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index f2b2243..ff0f6c8 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -139,7 +139,7 @@ _gl_destroy (void *device)
     cairo_region_destroy (ctx->clip_region);
     _cairo_clip_destroy (ctx->clip);
 
-    free (ctx->vb_mem);
+    free (ctx->vb);
 
     ctx->destroy (ctx);
 
@@ -267,19 +267,16 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx)
     if (unlikely (status))
         return status;
 
-    if (! ctx->has_map_buffer) {
-	ctx->vb_mem = _cairo_malloc_ab (CAIRO_GL_VBO_SIZE, 1);
-	if (unlikely (ctx->vb_mem == NULL)) {
+    ctx->vb = malloc (CAIRO_GL_VBO_SIZE);
+    if (unlikely (ctx->vb == NULL)) {
 	    _cairo_cache_fini (&ctx->gradients);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	}
     }
 
     _cairo_array_init (&ctx->tristrip_indices, sizeof (unsigned short));
 
     /* PBO for any sort of texture upload */
     dispatch->GenBuffers (1, &ctx->texture_load_pbo);
-    dispatch->GenBuffers (1, &ctx->vbo);
 
     ctx->max_framebuffer_size = 0;
     glGetIntegerv (GL_MAX_RENDERBUFFER_SIZE, &ctx->max_framebuffer_size);
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 87fe213..eb75cd9 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -92,7 +92,7 @@
 #define CAIRO_GL_MAX_SHADERS_PER_CONTEXT 64
 
 /* VBO size that we allocate, smaller size means we gotta flush more often */
-#define CAIRO_GL_VBO_SIZE 16384
+#define CAIRO_GL_VBO_SIZE (256*1024)
 
 typedef struct _cairo_gl_surface cairo_gl_surface_t;
 
@@ -302,7 +302,6 @@ struct _cairo_gl_context {
     const cairo_compositor_t *compositor;
 
     GLuint texture_load_pbo;
-    GLuint vbo;
     GLint max_framebuffer_size;
     GLint max_texture_size;
     GLint max_textures;
@@ -310,6 +309,7 @@ struct _cairo_gl_context {
 
     GLint num_samples;
     cairo_bool_t supports_msaa;
+    char *vb;
 
     const cairo_gl_shader_impl_t *shader_impl;
 
@@ -330,8 +330,6 @@ struct _cairo_gl_context {
     cairo_gl_operand_t operands[2];
     cairo_bool_t spans;
 
-    char *vb;
-    char *vb_mem;
     unsigned int vb_offset;
     unsigned int vertex_size;
     cairo_region_t *clip_region;
@@ -601,7 +599,7 @@ _cairo_gl_context_fini_shaders (cairo_gl_context_t *ctx);
 static cairo_always_inline cairo_bool_t
 _cairo_gl_context_is_flushed (cairo_gl_context_t *ctx)
 {
-    return ctx->vb == NULL;
+    return ctx->vb_offset == 0;
 }
 
 cairo_private cairo_status_t


More information about the cairo-commit mailing list