aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2020-03-22 18:13:45 -0400
committerMarge Bot <[email protected]>2020-04-27 11:56:06 +0000
commit03ba57c6c53214b19aa0fdb66c680f2cadc3bbd9 (patch)
tree610dac9af4d21e80675d59406bcf0b068581e985 /src/mesa
parente9afe045cf5382993da7d31c0bf340def7b97107 (diff)
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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/common/meta.c19
-rw-r--r--src/mesa/main/bufferobj.c2
-rw-r--r--src/mesa/main/varray.c17
-rw-r--r--src/mesa/main/varray.h2
-rw-r--r--src/mesa/vbo/vbo_exec_draw.c2
-rw-r--r--src/mesa/vbo/vbo_save_api.c3
6 files changed, 28 insertions, 17 deletions
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.