From: Marek Olšák Date: Sun, 22 Mar 2020 22:13:45 +0000 (-0400) Subject: mesa: extend _mesa_bind_vertex_buffer to take ownership of the buffer reference X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=03ba57c6c53214b19aa0fdb66c680f2cadc3bbd9;p=mesa.git mesa: extend _mesa_bind_vertex_buffer to take ownership of the buffer reference 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 Part-of: --- diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index f079d736d98..59049b951d2 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -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)); } } diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 4e10cc42b98..c8116cfda53 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -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); } } diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 34b6eda6363..ff743f751c4 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -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); diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h index 93fac8b43fd..0db3fa9083c 100644 --- a/src/mesa/main/varray.h +++ b/src/mesa/main/varray.h @@ -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, diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c index b3ea9c28fde..b31c1f90156 100644 --- a/src/mesa/vbo/vbo_exec_draw.c +++ b/src/mesa/vbo/vbo_exec_draw.c @@ -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. diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index 0839f110965..d6f9b53d68a 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -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.