mesa: extend _mesa_bind_vertex_buffer to take ownership of the buffer reference
authorMarek Olšák <marek.olsak@amd.com>
Sun, 22 Mar 2020 22:13:45 +0000 (18:13 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 27 Apr 2020 11:56:06 +0000 (11:56 +0000)
This reduces overhead of _mesa_reference_buffer_object_ from 6% to 4%
with glthread when profiling the game "torcs" with non-VBO data uploaded
by glthread.

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>

src/mesa/drivers/common/meta.c
src/mesa/main/bufferobj.c
src/mesa/main/varray.c
src/mesa/main/varray.h
src/mesa/vbo/vbo_exec_draw.c
src/mesa/vbo/vbo_save_api.c

index f079d736d9869f5ca97d1cd9c4067068b9242fc8..59049b951d2e808823f7f816fa2b3e9d5c660b73 100644 (file)
@@ -356,7 +356,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                    GL_FALSE, GL_FALSE,
                                    offsetof(struct vertex, x));
          _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_GENERIC(0),
-                                  *buf_obj, 0, sizeof(struct vertex), false);
+                                  *buf_obj, 0, sizeof(struct vertex), false,
+                                  false);
          _mesa_enable_vertex_array_attrib(ctx, array_obj,
                                           VERT_ATTRIB_GENERIC(0));
          if (texcoord_size > 0) {
@@ -365,7 +366,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                       GL_FALSE, GL_FALSE, GL_FALSE,
                                       offsetof(struct vertex, tex));
             _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_GENERIC(1),
-                                     *buf_obj, 0, sizeof(struct vertex), false);
+                                     *buf_obj, 0, sizeof(struct vertex), false,
+                                     false);
             _mesa_enable_vertex_array_attrib(ctx, array_obj,
                                              VERT_ATTRIB_GENERIC(1));
          }
@@ -375,7 +377,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                    GL_FALSE, GL_FALSE,
                                    offsetof(struct vertex, x));
          _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_POS,
-                                  *buf_obj, 0, sizeof(struct vertex), false);
+                                  *buf_obj, 0, sizeof(struct vertex), false,
+                                  false);
          _mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_POS);
 
          if (texcoord_size > 0) {
@@ -384,7 +387,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                       GL_FALSE, GL_FALSE,
                                       offsetof(struct vertex, tex));
             _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(0),
-                                     *buf_obj, 0, sizeof(struct vertex), false);
+                                     *buf_obj, 0, sizeof(struct vertex), false,
+                                     false);
             _mesa_enable_vertex_array_attrib(ctx, array_obj,
                                              VERT_ATTRIB_TEX(0));
          }
@@ -395,7 +399,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
                                       GL_FALSE, GL_FALSE,
                                       offsetof(struct vertex, r));
             _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_COLOR0,
-                                     *buf_obj, 0, sizeof(struct vertex), false);
+                                     *buf_obj, 0, sizeof(struct vertex), false,
+                                     false);
             _mesa_enable_vertex_array_attrib(ctx, array_obj,
                                              VERT_ATTRIB_COLOR0);
          }
@@ -3397,7 +3402,7 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
                                 offsetof(struct vertex, x));
       _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_POS,
                                drawtex->buf_obj, 0, sizeof(struct vertex),
-                               false);
+                               false, false);
       _mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_POS);
 
 
@@ -3409,7 +3414,7 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
                                    offsetof(struct vertex, st[i]));
          _mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(i),
                                   drawtex->buf_obj, 0, sizeof(struct vertex),
-                                  false);
+                                  false, false);
          _mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_TEX(i));
       }
    }
index 4e10cc42b982feced760569f736097d21bdff89f..c8116cfda5331df4dfb37003ee3a2a8ec40d6ba6 100644 (file)
@@ -1148,7 +1148,7 @@ unbind(struct gl_context *ctx,
    if (vao->BufferBinding[index].BufferObj == obj) {
       _mesa_bind_vertex_buffer(ctx, vao, index, NULL,
                                vao->BufferBinding[index].Offset,
-                               vao->BufferBinding[index].Stride, true);
+                               vao->BufferBinding[index].Stride, true, false);
    }
 }
 
index 34b6eda6363f5a9be84d528c9b9cfc3fbedae691..ff743f751c40c28aa637886360bb87eedb1ce60c 100644 (file)
@@ -199,7 +199,7 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
                          GLuint index,
                          struct gl_buffer_object *vbo,
                          GLintptr offset, GLsizei stride,
-                         bool offset_is_int32)
+                         bool offset_is_int32, bool take_vbo_ownership)
 {
    assert(index < ARRAY_SIZE(vao->BufferBinding));
    assert(!vao->SharedAndImmutable);
@@ -223,7 +223,12 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
        binding->Offset != offset ||
        binding->Stride != stride) {
 
-      _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
+      if (take_vbo_ownership) {
+         _mesa_reference_buffer_object(ctx, &binding->BufferObj, NULL);
+         binding->BufferObj = vbo;
+      } else {
+         _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
+      }
 
       binding->Offset = offset;
       binding->Stride = stride;
@@ -910,7 +915,7 @@ update_array(struct gl_context *ctx,
       stride : array->Format._ElementSize;
    _mesa_bind_vertex_buffer(ctx, vao, attrib,
                             obj, (GLintptr) ptr,
-                            effectiveStride, false);
+                            effectiveStride, false, false);
 }
 
 
@@ -2940,7 +2945,7 @@ vertex_array_vertex_buffer(struct gl_context *ctx,
    }
 
    _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
-                            vbo, offset, stride, false);
+                            vbo, offset, stride, false, false);
 }
 
 
@@ -3105,7 +3110,7 @@ vertex_array_vertex_buffers(struct gl_context *ctx,
        */
       for (i = 0; i < count; i++)
          _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
-                                  NULL, 0, 16, false);
+                                  NULL, 0, 16, false, false);
 
       return;
    }
@@ -3183,7 +3188,7 @@ vertex_array_vertex_buffers(struct gl_context *ctx,
       }
 
       _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
-                               vbo, offsets[i], strides[i], false);
+                               vbo, offsets[i], strides[i], false, false);
    }
 
    _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
index 93fac8b43fd138481610b61a4232c737d5dcbc0b..0db3fa9083c0601b5acc494ef372b399166efbce 100644 (file)
@@ -110,7 +110,7 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
                          GLuint index,
                          struct gl_buffer_object *vbo,
                          GLintptr offset, GLsizei stride,
-                         bool offset_is_int32);
+                         bool offset_is_int32, bool take_vbo_ownership);
 
 extern void GLAPIENTRY
 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
index b3ea9c28fde8f256fa18f6cd70e48eaaeb63cabf..b31c1f901568f2aa1963e820fcd8c518eaa42092 100644 (file)
@@ -110,7 +110,7 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
    /* Bind the buffer object */
    const GLuint stride = exec->vtx.vertex_size*sizeof(GLfloat);
    _mesa_bind_vertex_buffer(ctx, vao, 0, exec->vtx.bufferobj, buffer_offset,
-                            stride, false);
+                            stride, false, false);
 
    /* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
     * Note that the position/generic0 aliasing is done in the VAO.
index 0839f1109651d1e4f6d96eaf485330bb53af4d6c..d6f9b53d68a60ecf34b6a60bd7a48d25e654316d 100644 (file)
@@ -434,7 +434,8 @@ update_vao(struct gl_context *ctx,
     */
 
    /* Bind the buffer object at binding point 0 */
-   _mesa_bind_vertex_buffer(ctx, *vao, 0, bo, buffer_offset, stride, false);
+   _mesa_bind_vertex_buffer(ctx, *vao, 0, bo, buffer_offset, stride, false,
+                            false);
 
    /* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
     * Note that the position/generic0 aliasing is done in the VAO.