mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 11:18:08 +02:00
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 <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>
This commit is contained in:
parent
e9afe045cf
commit
03ba57c6c5
6 changed files with 28 additions and 17 deletions
|
|
@ -356,7 +356,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
|
||||||
GL_FALSE, GL_FALSE,
|
GL_FALSE, GL_FALSE,
|
||||||
offsetof(struct vertex, x));
|
offsetof(struct vertex, x));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_GENERIC(0),
|
_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,
|
_mesa_enable_vertex_array_attrib(ctx, array_obj,
|
||||||
VERT_ATTRIB_GENERIC(0));
|
VERT_ATTRIB_GENERIC(0));
|
||||||
if (texcoord_size > 0) {
|
if (texcoord_size > 0) {
|
||||||
|
|
@ -365,7 +366,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
|
||||||
GL_FALSE, GL_FALSE, GL_FALSE,
|
GL_FALSE, GL_FALSE, GL_FALSE,
|
||||||
offsetof(struct vertex, tex));
|
offsetof(struct vertex, tex));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_GENERIC(1),
|
_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,
|
_mesa_enable_vertex_array_attrib(ctx, array_obj,
|
||||||
VERT_ATTRIB_GENERIC(1));
|
VERT_ATTRIB_GENERIC(1));
|
||||||
}
|
}
|
||||||
|
|
@ -375,7 +377,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
|
||||||
GL_FALSE, GL_FALSE,
|
GL_FALSE, GL_FALSE,
|
||||||
offsetof(struct vertex, x));
|
offsetof(struct vertex, x));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_POS,
|
_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);
|
_mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_POS);
|
||||||
|
|
||||||
if (texcoord_size > 0) {
|
if (texcoord_size > 0) {
|
||||||
|
|
@ -384,7 +387,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
|
||||||
GL_FALSE, GL_FALSE,
|
GL_FALSE, GL_FALSE,
|
||||||
offsetof(struct vertex, tex));
|
offsetof(struct vertex, tex));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(0),
|
_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,
|
_mesa_enable_vertex_array_attrib(ctx, array_obj,
|
||||||
VERT_ATTRIB_TEX(0));
|
VERT_ATTRIB_TEX(0));
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +399,8 @@ _mesa_meta_setup_vertex_objects(struct gl_context *ctx,
|
||||||
GL_FALSE, GL_FALSE,
|
GL_FALSE, GL_FALSE,
|
||||||
offsetof(struct vertex, r));
|
offsetof(struct vertex, r));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_COLOR0,
|
_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,
|
_mesa_enable_vertex_array_attrib(ctx, array_obj,
|
||||||
VERT_ATTRIB_COLOR0);
|
VERT_ATTRIB_COLOR0);
|
||||||
}
|
}
|
||||||
|
|
@ -3397,7 +3402,7 @@ _mesa_meta_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
|
||||||
offsetof(struct vertex, x));
|
offsetof(struct vertex, x));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_POS,
|
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_POS,
|
||||||
drawtex->buf_obj, 0, sizeof(struct vertex),
|
drawtex->buf_obj, 0, sizeof(struct vertex),
|
||||||
false);
|
false, false);
|
||||||
_mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_POS);
|
_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]));
|
offsetof(struct vertex, st[i]));
|
||||||
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(i),
|
_mesa_bind_vertex_buffer(ctx, array_obj, VERT_ATTRIB_TEX(i),
|
||||||
drawtex->buf_obj, 0, sizeof(struct vertex),
|
drawtex->buf_obj, 0, sizeof(struct vertex),
|
||||||
false);
|
false, false);
|
||||||
_mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_TEX(i));
|
_mesa_enable_vertex_array_attrib(ctx, array_obj, VERT_ATTRIB_TEX(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1148,7 +1148,7 @@ unbind(struct gl_context *ctx,
|
||||||
if (vao->BufferBinding[index].BufferObj == obj) {
|
if (vao->BufferBinding[index].BufferObj == obj) {
|
||||||
_mesa_bind_vertex_buffer(ctx, vao, index, NULL,
|
_mesa_bind_vertex_buffer(ctx, vao, index, NULL,
|
||||||
vao->BufferBinding[index].Offset,
|
vao->BufferBinding[index].Offset,
|
||||||
vao->BufferBinding[index].Stride, true);
|
vao->BufferBinding[index].Stride, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
|
||||||
GLuint index,
|
GLuint index,
|
||||||
struct gl_buffer_object *vbo,
|
struct gl_buffer_object *vbo,
|
||||||
GLintptr offset, GLsizei stride,
|
GLintptr offset, GLsizei stride,
|
||||||
bool offset_is_int32)
|
bool offset_is_int32, bool take_vbo_ownership)
|
||||||
{
|
{
|
||||||
assert(index < ARRAY_SIZE(vao->BufferBinding));
|
assert(index < ARRAY_SIZE(vao->BufferBinding));
|
||||||
assert(!vao->SharedAndImmutable);
|
assert(!vao->SharedAndImmutable);
|
||||||
|
|
@ -223,7 +223,12 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
|
||||||
binding->Offset != offset ||
|
binding->Offset != offset ||
|
||||||
binding->Stride != stride) {
|
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->Offset = offset;
|
||||||
binding->Stride = stride;
|
binding->Stride = stride;
|
||||||
|
|
@ -910,7 +915,7 @@ update_array(struct gl_context *ctx,
|
||||||
stride : array->Format._ElementSize;
|
stride : array->Format._ElementSize;
|
||||||
_mesa_bind_vertex_buffer(ctx, vao, attrib,
|
_mesa_bind_vertex_buffer(ctx, vao, attrib,
|
||||||
obj, (GLintptr) ptr,
|
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),
|
_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++)
|
for (i = 0; i < count; i++)
|
||||||
_mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
|
_mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
|
||||||
NULL, 0, 16, false);
|
NULL, 0, 16, false, false);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -3183,7 +3188,7 @@ vertex_array_vertex_buffers(struct gl_context *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
_mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
|
_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);
|
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx,
|
||||||
GLuint index,
|
GLuint index,
|
||||||
struct gl_buffer_object *vbo,
|
struct gl_buffer_object *vbo,
|
||||||
GLintptr offset, GLsizei stride,
|
GLintptr offset, GLsizei stride,
|
||||||
bool offset_is_int32);
|
bool offset_is_int32, bool take_vbo_ownership);
|
||||||
|
|
||||||
extern void GLAPIENTRY
|
extern void GLAPIENTRY
|
||||||
_mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
|
_mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
|
||||||
/* Bind the buffer object */
|
/* Bind the buffer object */
|
||||||
const GLuint stride = exec->vtx.vertex_size*sizeof(GLfloat);
|
const GLuint stride = exec->vtx.vertex_size*sizeof(GLfloat);
|
||||||
_mesa_bind_vertex_buffer(ctx, vao, 0, exec->vtx.bufferobj, buffer_offset,
|
_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
|
/* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
|
||||||
* Note that the position/generic0 aliasing is done in the VAO.
|
* Note that the position/generic0 aliasing is done in the VAO.
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,8 @@ update_vao(struct gl_context *ctx,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Bind the buffer object at binding point 0 */
|
/* 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
|
/* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
|
||||||
* Note that the position/generic0 aliasing is done in the VAO.
|
* Note that the position/generic0 aliasing is done in the VAO.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue