mesa: add storage flags parameter to Driver.BufferData
authorMarek Olšák <marek.olsak@amd.com>
Mon, 27 Jan 2014 20:15:19 +0000 (21:15 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 25 Feb 2014 15:04:22 +0000 (16:04 +0100)
It will be used by glBufferStorage. The parameters are chosen according
to ARB_buffer_storage.

Reviewed-by: Fredrik Höglund <fredrik@kde.org>
src/mesa/drivers/dri/i915/intel_buffer_objects.c
src/mesa/drivers/dri/i965/intel_buffer_objects.c
src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
src/mesa/drivers/dri/radeon/radeon_buffer_objects.c
src/mesa/main/bufferobj.c
src/mesa/main/dd.h
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/vbo/vbo_exec_api.c
src/mesa/vbo/vbo_exec_draw.c
src/mesa/vbo/vbo_save_api.c

index 345db6dfe0fd336fa52f065e2036e26899879f7d..f4fb9998cde281885b5299a8e323faf236173f4d 100644 (file)
@@ -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 */
 
index d286a9fef608a8991ee8b710dd21fed56022a535..c92ca2fcafe561d65fcb759463e6f10d8c80e2b6 100644 (file)
@@ -182,7 +182,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);
@@ -193,6 +195,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 */
 
index dc16585375958738244ffe6470ece476452cd79a..783a152955f859f87f0e444c99f1fc5e01704d46 100644 (file)
@@ -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);
index ba7ab372790ac3845d42ceb5632802bbc27f2c6b..7663178d63d086bde8c6f1d584b36ccbd3ef03d2 100644 (file)
@@ -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);
index 491b6501ed5c65bafcc69428b4b9f28af4219214..f4dea26c3477f6e1e84f24492e8f46b2d537b931 100644 (file)
@@ -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;
@@ -569,6 +569,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 );
@@ -1305,7 +1306,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()");
    }
 }
index b444b4cf504dfcf4d243ee8090509c66842c50a2..f1ba6000d02a6eb053a2b9c592ad6996769cbb46 100644 (file)
@@ -578,7 +578,7 @@ struct dd_function_table {
 
    GLboolean (*BufferData)(struct gl_context *ctx, GLenum target,
                            GLsizeiptrARB size, const GLvoid *data, GLenum usage,
-                           struct gl_buffer_object *obj);
+                           GLenum storageFlags, struct gl_buffer_object *obj);
 
    void (*BufferSubData)( struct gl_context *ctx, GLintptrARB offset,
                          GLsizeiptrARB size, const GLvoid *data,
index fbbca5528d950a11d73224e88caa82abdf2665a3..536ed31419566a8e225bf9c1620df5c56e5a8b10 100644 (file)
@@ -1449,6 +1449,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 */
index c8f088dc82c3d9f2e499d5e9b0e22a791a067364..347dc90b26988e3223ab95668933d35a1f7003ee 100644 (file)
@@ -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:
index 810913645358aa58988f5945b34b093a36780cac..9858badebf1e6e3106bf26e2b93fa36b64ca1bc4 100644 (file)
@@ -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");
    }
 }
index 75115ce66310272e1e995573c6e7ef9c6b8db044..46be65fc0103c589bc6a1e7b720620bc52939b12 100644 (file)
@@ -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,
index 98ab68623b4b2db2bc44cd9e22258206100f17f5..b86ced5bf89fbcc6115cc48d21f3a261d86ecc4f 100644 (file)
@@ -200,6 +200,8 @@ 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,
                                  vertex_store->bufferobj);
    }
    else {