[Mesa-dev] [PATCH] vbo: access VBO memory more efficiently when building display lists

Jose Fonseca jfonseca at vmware.com
Tue Oct 15 21:06:13 CEST 2013


The change looks good as far as as I can tell.

Jose

----- Original Message -----
> Use GL_MAP_INVALIDATE_RANGE, UNSYNCHRONIZED and FLUSH_EXPLICIT flags
> when mapping VBOs during display list compilation.  This mirrors what
> we do for immediate-mode VBO building in vbo_exec_vtx_map().
> 
> This improves performance for applications which interleave display
> list compilation with execution.  For example:
> 
> glNewList(A);
> glBegin/End prims;
> glEndList();
> glCallList(A);
> glNewList(B);
> glBegin/End prims;
> glEndList();
> glCallList(B);
> 
> Mesa's vbo module tries to combine the vertex data from lists A and B
> into the same VBO when there's room.  Before, when we mapped the VBO for
> building list B, we did so with GL_MAP_WRITE_BIT only.  Even though we
> were writing to an unused part of the buffer, the map would stall until
> the preceeding drawing call finished.
> 
> Use the extra map flags and FlushMappedBufferRange() to avoid the stall.
> ---
>  src/mesa/vbo/vbo_save_api.c |   39 +++++++++++++++++++++++++++++++--------
>  1 file changed, 31 insertions(+), 8 deletions(-)
> 
> diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
> index b5f9517..411c006 100644
> --- a/src/mesa/vbo/vbo_save_api.c
> +++ b/src/mesa/vbo/vbo_save_api.c
> @@ -237,16 +237,31 @@ GLfloat *
>  vbo_save_map_vertex_store(struct gl_context *ctx,
>                            struct vbo_save_vertex_store *vertex_store)
>  {
> +   const GLbitfield access = (GL_MAP_WRITE_BIT |
> +                              GL_MAP_INVALIDATE_RANGE_BIT |
> +                              GL_MAP_UNSYNCHRONIZED_BIT |
> +                              GL_MAP_FLUSH_EXPLICIT_BIT);
> +
>     assert(vertex_store->bufferobj);
> -   assert(!vertex_store->buffer);
> +   assert(!vertex_store->buffer);  /* the buffer should not be mapped */
> +
>     if (vertex_store->bufferobj->Size > 0) {
> -      vertex_store->buffer =
> -         (GLfloat *) ctx->Driver.MapBufferRange(ctx, 0,
> -
> vertex_store->bufferobj->Size,
> -                                                GL_MAP_WRITE_BIT,  /* not
> used */
> -                                                vertex_store->bufferobj);
> -      assert(vertex_store->buffer);
> -      return vertex_store->buffer + vertex_store->used;
> +      /* Map the remaining free space in the VBO */
> +      GLintptr offset = vertex_store->used * sizeof(GLfloat);
> +      GLsizeiptr size = vertex_store->bufferobj->Size - offset;
> +      GLfloat *range = (GLfloat *)
> +         ctx->Driver.MapBufferRange(ctx, offset, size, access,
> +                                    vertex_store->bufferobj);
> +      if (range) {
> +         /* compute address of start of whole buffer (needed elsewhere) */
> +         vertex_store->buffer = range - vertex_store->used;
> +         assert(vertex_store->buffer);
> +         return range;
> +      }
> +      else {
> +         vertex_store->buffer = NULL;
> +         return NULL;
> +      }
>     }
>     else {
>        /* probably ran out of memory for buffers */
> @@ -260,6 +275,14 @@ vbo_save_unmap_vertex_store(struct gl_context *ctx,
>                              struct vbo_save_vertex_store *vertex_store)
>  {
>     if (vertex_store->bufferobj->Size > 0) {
> +      GLintptr offset = 0;
> +      GLsizeiptr length = vertex_store->used * sizeof(GLfloat)
> +         - vertex_store->bufferobj->Offset;
> +
> +      /* Explicitly flush the region we wrote to */
> +      ctx->Driver.FlushMappedBufferRange(ctx, offset, length,
> +                                         vertex_store->bufferobj);
> +
>        ctx->Driver.UnmapBuffer(ctx, vertex_store->bufferobj);
>     }
>     vertex_store->buffer = NULL;
> --
> 1.7.10.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 


More information about the mesa-dev mailing list