[Mesa-dev] [PATCH 02/13] mesa: add storage flags parameter to Driver.BufferData

Fredrik Höglund fredrik at kde.org
Thu Jan 30 10:26:58 PST 2014


On Thursday 30 January 2014, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
> 
> It will be used by glBufferStorage. The parameters are chosen according
> to ARB_buffer_storage.
> ---
>  src/mesa/drivers/dri/i915/intel_buffer_objects.c    | 5 ++++-
>  src/mesa/drivers/dri/i965/intel_buffer_objects.c    | 5 ++++-
>  src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c    | 3 ++-
>  src/mesa/drivers/dri/radeon/radeon_buffer_objects.c | 2 ++
>  src/mesa/main/bufferobj.c                           | 9 +++++++--
>  src/mesa/main/dd.h                                  | 2 +-
>  src/mesa/main/mtypes.h                              | 1 +
>  src/mesa/state_tracker/st_cb_bufferobjects.c        | 6 +++++-
>  src/mesa/vbo/vbo_exec_api.c                         | 6 +++++-
>  src/mesa/vbo/vbo_exec_draw.c                        | 8 ++++++--
>  src/mesa/vbo/vbo_save_api.c                         | 3 +++
>  11 files changed, 40 insertions(+), 10 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i915/intel_buffer_objects.c b/src/mesa/drivers/dri/i915/intel_buffer_objects.c
> index 345db6d..f4fb999 100644
> --- a/src/mesa/drivers/dri/i915/intel_buffer_objects.c
> +++ b/src/mesa/drivers/dri/i915/intel_buffer_objects.c
> @@ -116,13 +116,16 @@ intel_bufferobj_data(struct gl_context * ctx,
>                       GLenum target,
>                       GLsizeiptrARB size,
>                       const GLvoid * data,
> -                     GLenum usage, struct gl_buffer_object *obj)
> +                     GLenum usage,
> +                     GLbitfield storageFlags,
> +                     struct gl_buffer_object *obj)
>  {
>     struct intel_context *intel = intel_context(ctx);
>     struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
>  
>     intel_obj->Base.Size = size;
>     intel_obj->Base.Usage = usage;
> +   intel_obj->Base.StorageFlags = storageFlags;
>  
>     assert(!obj->Pointer); /* Mesa should have unmapped it */
>  
> diff --git a/src/mesa/drivers/dri/i965/intel_buffer_objects.c b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
> index 4d7044a..f7b9020 100644
> --- a/src/mesa/drivers/dri/i965/intel_buffer_objects.c
> +++ b/src/mesa/drivers/dri/i965/intel_buffer_objects.c
> @@ -142,7 +142,9 @@ intel_bufferobj_data(struct gl_context * ctx,
>                       GLenum target,
>                       GLsizeiptrARB size,
>                       const GLvoid * data,
> -                     GLenum usage, struct gl_buffer_object *obj)
> +                     GLenum usage,
> +                     GLbitfield storageFlags,
> +                     struct gl_buffer_object *obj)
>  {
>     struct brw_context *brw = brw_context(ctx);
>     struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
> @@ -153,6 +155,7 @@ intel_bufferobj_data(struct gl_context * ctx,
>  
>     intel_obj->Base.Size = size;
>     intel_obj->Base.Usage = usage;
> +   intel_obj->Base.StorageFlags = storageFlags;
>  
>     assert(!obj->Pointer); /* Mesa should have unmapped it */
>  
> diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
> index 717c0b8..af17196 100644
> --- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
> +++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
> @@ -73,7 +73,7 @@ nouveau_bufferobj_del(struct gl_context *ctx, struct gl_buffer_object *obj)
>  
>  static GLboolean
>  nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
> -		       const GLvoid *data, GLenum usage,
> +		       const GLvoid *data, GLenum usage, GLbitfield storageFlags,
>  		       struct gl_buffer_object *obj)
>  {
>  	struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
> @@ -81,6 +81,7 @@ nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size
>  
>  	obj->Size = size;
>  	obj->Usage = usage;
> +        obj->StorageFlags = storageFlags;
>  
>  	/* Free previous storage */
>  	nouveau_bo_ref(NULL, &nbo->bo);
> diff --git a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
> index 40a16c3..1fa3088 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
> +++ b/src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
> @@ -86,6 +86,7 @@ radeonBufferData(struct gl_context * ctx,
>                   GLsizeiptrARB size,
>                   const GLvoid * data,
>                   GLenum usage,
> +                 GLbitfield storageFlags,
>                   struct gl_buffer_object *obj)
>  {
>      radeonContextPtr radeon = RADEON_CONTEXT(ctx);
> @@ -93,6 +94,7 @@ radeonBufferData(struct gl_context * ctx,
>  
>      radeon_obj->Base.Size = size;
>      radeon_obj->Base.Usage = usage;
> +    radeon_obj->Base.StorageFlags = storageFlags;
>  
>      if (radeon_obj->bo != NULL) {
>          radeon_bo_unref(radeon_obj->bo);
> diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
> index 802c9e3..d9fb812 100644
> --- a/src/mesa/main/bufferobj.c
> +++ b/src/mesa/main/bufferobj.c
> @@ -555,7 +555,7 @@ _mesa_total_buffer_object_memory(struct gl_context *ctx)
>   */
>  static GLboolean
>  _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
> -		   const GLvoid * data, GLenum usage,
> +		   const GLvoid * data, GLenum usage, GLenum storageFlags,
>  		   struct gl_buffer_object * bufObj )
>  {
>     void * new_data;
> @@ -567,6 +567,7 @@ _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
>        bufObj->Data = (GLubyte *) new_data;
>        bufObj->Size = size;
>        bufObj->Usage = usage;
> +      bufObj->StorageFlags = storageFlags;
>  
>        if (data) {
>  	 memcpy( bufObj->Data, data, size );
> @@ -1303,7 +1304,11 @@ _mesa_BufferData(GLenum target, GLsizeiptrARB size,
>  #endif
>  
>     ASSERT(ctx->Driver.BufferData);
> -   if (!ctx->Driver.BufferData( ctx, target, size, data, usage, bufObj )) {
> +   if (!ctx->Driver.BufferData(ctx, target, size, data, usage,
> +                               GL_MAP_READ_BIT |
> +                               GL_MAP_WRITE_BIT |
> +                               GL_DYNAMIC_STORAGE_BIT,
> +                               bufObj)) {
>        _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBufferDataARB()");
>     }
>  }
> diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
> index db55dba..e26f407 100644
> --- a/src/mesa/main/dd.h
> +++ b/src/mesa/main/dd.h
> @@ -561,7 +561,7 @@ struct dd_function_table {
>     void (*DeleteBuffer)( struct gl_context *ctx, struct gl_buffer_object *obj );
>  
>     GLboolean (*BufferData)( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
> -                            const GLvoid *data, GLenum usage,
> +                            const GLvoid *data, GLenum usage, GLenum storageFlags,
>                              struct gl_buffer_object *obj );
>  
>     void (*BufferSubData)( struct gl_context *ctx, GLintptrARB offset,
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 3d42a21..e509a90 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1451,6 +1451,7 @@ struct gl_buffer_object
>     GLuint Name;
>     GLchar *Label;       /**< GL_KHR_debug */
>     GLenum Usage;        /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
> +   GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
>     GLsizeiptrARB Size;  /**< Size of buffer storage in bytes */
>     GLubyte *Data;       /**< Location of storage either in RAM or VRAM. */
>     /** Fields describing a mapped buffer */
> diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
> index ac8d079..dac63a5 100644
> --- a/src/mesa/state_tracker/st_cb_bufferobjects.c
> +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
> @@ -176,6 +176,7 @@ st_bufferobj_data(struct gl_context *ctx,
>  		  GLsizeiptrARB size,
>  		  const GLvoid * data,
>  		  GLenum usage,
> +                  GLbitfield storageFlags,
>  		  struct gl_buffer_object *obj)
>  {
>     struct st_context *st = st_context(ctx);
> @@ -184,7 +185,9 @@ st_bufferobj_data(struct gl_context *ctx,
>     unsigned bind, pipe_usage;
>  
>     if (size && data && st_obj->buffer &&
> -       st_obj->Base.Size == size && st_obj->Base.Usage == usage) {
> +       st_obj->Base.Size == size &&
> +       st_obj->Base.Usage == usage &&
> +       st_obj->Base.StorageFlags == storageFlags) {
>        /* Just discard the old contents and write new data.
>         * This should be the same as creating a new buffer, but we avoid
>         * a lot of validation in Mesa.
> @@ -200,6 +203,7 @@ st_bufferobj_data(struct gl_context *ctx,
>  
>     st_obj->Base.Size = size;
>     st_obj->Base.Usage = usage;
> +   st_obj->Base.StorageFlags = storageFlags;
>  
>     switch (target) {
>     case GL_PIXEL_PACK_BUFFER_ARB:
> diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
> index 8109136..9858bad 100644
> --- a/src/mesa/vbo/vbo_exec_api.c
> +++ b/src/mesa/vbo/vbo_exec_api.c
> @@ -998,7 +998,11 @@ void vbo_use_buffer_objects(struct gl_context *ctx)
>     /* Allocate a real buffer object now */
>     _mesa_reference_buffer_object(ctx, &exec->vtx.bufferobj, NULL);
>     exec->vtx.bufferobj = ctx->Driver.NewBufferObject(ctx, bufName, target);
> -   if (!ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj)) {
> +   if (!ctx->Driver.BufferData(ctx, target, size, NULL, usage,
> +                               GL_MAP_WRITE_BIT |
> +                               GL_DYNAMIC_STORAGE_BIT |
> +                               GL_CLIENT_STORAGE_BIT,
> +                               exec->vtx.bufferobj)) {
>        _mesa_error(ctx, GL_OUT_OF_MEMORY, "VBO allocation");
>     }
>  }
> diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
> index 75115ce..46be65f 100644
> --- a/src/mesa/vbo/vbo_exec_draw.c
> +++ b/src/mesa/vbo/vbo_exec_draw.c
> @@ -325,8 +325,12 @@ vbo_exec_vtx_map( struct vbo_exec_context *exec )
>        exec->vtx.buffer_used = 0;
>  
>        if (ctx->Driver.BufferData(ctx, GL_ARRAY_BUFFER_ARB,
> -                                  VBO_VERT_BUFFER_SIZE, 
> -                                  NULL, usage, exec->vtx.bufferobj)) {
> +                                 VBO_VERT_BUFFER_SIZE,
> +                                 NULL, usage,
> +                                 GL_MAP_WRITE_BIT |
> +                                 GL_DYNAMIC_STORAGE_BIT |
> +                                 GL_CLIENT_STORAGE_BIT,
> +                                 exec->vtx.bufferobj)) {
>           /* buffer allocation worked, now map the buffer */
>           exec->vtx.buffer_map =
>              (GLfloat *)ctx->Driver.MapBufferRange(ctx,
> diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
> index 43243e6..3105fab 100644
> --- a/src/mesa/vbo/vbo_save_api.c
> +++ b/src/mesa/vbo/vbo_save_api.c
> @@ -200,6 +200,9 @@ alloc_vertex_store(struct gl_context *ctx)
>                                   GL_ARRAY_BUFFER_ARB,
>                                   VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat),
>                                   NULL, GL_STATIC_DRAW_ARB,
> +                                 GL_MAP_WRITE_BIT |
> +                                 GL_DYNAMIC_STORAGE_BIT |
> +                                 GL_CLIENT_STORAGE_BIT,

Specifying both GL_STATIC_DRAW and GL_CLIENT_STORAGE_BIT here looks
like a contradiction to me.  Since this is for display lists, I guess the
GL_CLIENT_STORAGE_BIT should be left out.

Fredrik



More information about the mesa-dev mailing list