[Mesa-dev] [PATCH 03/22] mesa: Keep track of the last looked-up VAO
Fredrik Höglund
fredrik at kde.org
Wed Mar 18 16:18:29 PDT 2015
This saves the cost of repeated hash table lookups when the same
vertex array object is referenced in a sequence of calls such as:
glVertexArrayAttribFormat(vao, ...);
glVertexArrayAttribBinding(vao, ...);
glEnableVertexArrayAttrib(vao, ...);
...
Note that VAO's are container objects that are not shared between
contexts.
---
src/mesa/main/arrayobj.c | 44 ++++++++++++++++++++++++++++----------------
src/mesa/main/mtypes.h | 3 +++
2 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index ac081b0..862bbb7 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -100,23 +100,32 @@ _mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, const char *caller)
return ctx->Array.DefaultVAO;
} else {
- struct gl_vertex_array_object *vao =
- (struct gl_vertex_array_object *)
- _mesa_HashLookup(ctx->Array.Objects, id);
+ struct gl_vertex_array_object *vao;
- /* The ARB_direct_state_access specification says:
- *
- * "An INVALID_OPERATION error is generated if <vaobj> is not
- * [compatibility profile: zero or] the name of an existing
- * vertex array object."
- */
- if (!vao || !vao->EverBound) {
- const char *format = ctx->API == API_OPENGL_CORE ?
- "%s(vaobj=%d is not the name of an existing vertex array object)" :
- "%s(vaobj=%d is not zero or the name of an existing vertex "
- "array object)";
- _mesa_error(ctx, GL_INVALID_OPERATION, format, caller, id);
- return NULL;
+ if (ctx->Array.LastLookedUpVAO &&
+ ctx->Array.LastLookedUpVAO->Name == id) {
+ vao = ctx->Array.LastLookedUpVAO;
+ } else {
+ vao = (struct gl_vertex_array_object *)
+ _mesa_HashLookup(ctx->Array.Objects, id);
+
+ /* The ARB_direct_state_access specification says:
+ *
+ * "An INVALID_OPERATION error is generated if <vaobj> is not
+ * [compatibility profile: zero or] the name of an existing
+ * vertex array object."
+ */
+ if (!vao || !vao->EverBound) {
+ const char *format = ctx->API == API_OPENGL_CORE ?
+ "%s(vaobj=%d is not the name of an existing vertex "
+ "array object)" :
+ "%s(vaobj=%d is not zero or the name of an existing vertex "
+ "array object)";
+ _mesa_error(ctx, GL_INVALID_OPERATION, format, caller, id);
+ return NULL;
+ }
+
+ _mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, vao);
}
return vao;
@@ -519,6 +528,9 @@ _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
/* The ID is immediately freed for re-use */
remove_array_object(ctx, obj);
+ if (ctx->Array.LastLookedUpVAO == obj)
+ _mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, NULL);
+
/* Unreference the array object.
* If refcount hits zero, the object will be deleted.
*/
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c43c6ac..f46f2b2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1687,6 +1687,9 @@ struct gl_array_attrib
/** The default vertex array object */
struct gl_vertex_array_object *DefaultVAO;
+ /** The last VAO accessed by a DSA function */
+ struct gl_vertex_array_object *LastLookedUpVAO;
+
/** Array objects (GL_ARB/APPLE_vertex_array_object) */
struct _mesa_HashTable *Objects;
--
1.8.5.3
More information about the mesa-dev
mailing list