diff options
author | Marek Olšák <[email protected]> | 2020-03-04 16:18:28 -0500 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2020-03-20 23:01:13 -0400 |
commit | bde4505f61e2964b16b04faadf4062a59e471bfd (patch) | |
tree | f1eb0e2a8f1b34a392349394458a8e3f1f87f453 | |
parent | 15b0719ae2d5cc80c063b1748443392f701bcdce (diff) |
glthread: handle buffer unbinding via glDeleteBuffers
Reviewed-by: Timothy Arceri <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4124>
-rw-r--r-- | src/mapi/glapi/gen/gl_API.xml | 3 | ||||
-rw-r--r-- | src/mesa/main/glthread.h | 21 | ||||
-rw-r--r-- | src/mesa/main/glthread_bufferobj.c | 26 | ||||
-rw-r--r-- | src/mesa/main/glthread_marshal.h | 17 | ||||
-rw-r--r-- | src/mesa/main/glthread_varray.c | 5 |
5 files changed, 43 insertions, 29 deletions
diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml index 7d6e01eb031..aec65155b8e 100644 --- a/src/mapi/glapi/gen/gl_API.xml +++ b/src/mapi/glapi/gen/gl_API.xml @@ -5078,7 +5078,8 @@ <glx ignore="true"/> </function> - <function name="DeleteBuffers" es1="1.1" es2="2.0" no_error="true"> + <function name="DeleteBuffers" es1="1.1" es2="2.0" no_error="true" + marshal_call_after="if (COMPAT) _mesa_glthread_DeleteBuffers(ctx, n, buffer);"> <param name="n" type="GLsizei" counter="true"/> <param name="buffer" type="const GLuint *" count="n"/> <glx ignore="true"/> diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h index 0d48438b9bd..5491e1994c1 100644 --- a/src/mesa/main/glthread.h +++ b/src/mesa/main/glthread.h @@ -54,7 +54,7 @@ struct _mesa_HashTable; struct glthread_vao { GLuint Name; bool HasUserPointer; - bool IndexBufferIsUserPointer; + GLuint CurrentElementBufferName; }; /** A single batch of commands queued up for execution. */ @@ -104,17 +104,9 @@ struct glthread_state struct glthread_vao *LastLookedUpVAO; struct glthread_vao DefaultVAO; - /** - * Tracks on the main thread side whether the current vertex array binding - * is in a VBO. - */ - bool vertex_array_is_vbo; - - /** - * Tracks on the main thread side whether the current element array (index - * buffer) binding is in a VBO. - */ - bool draw_indirect_buffer_is_vbo; + /** Currently-bound buffer object IDs. */ + GLuint CurrentArrayBufferName; + GLuint CurrentDrawIndirectBufferName; }; void _mesa_glthread_init(struct gl_context *ctx); @@ -126,6 +118,11 @@ void _mesa_glthread_flush_batch(struct gl_context *ctx); void _mesa_glthread_finish(struct gl_context *ctx); void _mesa_glthread_finish_before(struct gl_context *ctx, const char *func); +void _mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, + GLuint buffer); +void _mesa_glthread_DeleteBuffers(struct gl_context *ctx, GLsizei n, + const GLuint *buffers); + void _mesa_glthread_BindVertexArray(struct gl_context *ctx, GLuint id); void _mesa_glthread_DeleteVertexArrays(struct gl_context *ctx, GLsizei n, const GLuint *ids); diff --git a/src/mesa/main/glthread_bufferobj.c b/src/mesa/main/glthread_bufferobj.c index 872bcbc69b8..2a9c913cdfc 100644 --- a/src/mesa/main/glthread_bufferobj.c +++ b/src/mesa/main/glthread_bufferobj.c @@ -54,21 +54,41 @@ _mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, GLuint buffer) switch (target) { case GL_ARRAY_BUFFER: - glthread->vertex_array_is_vbo = (buffer != 0); + glthread->CurrentArrayBufferName = buffer; break; case GL_ELEMENT_ARRAY_BUFFER: /* The current element array buffer binding is actually tracked in the * vertex array object instead of the context, so this would need to * change on vertex array object updates. */ - glthread->CurrentVAO->IndexBufferIsUserPointer = buffer != 0; + glthread->CurrentVAO->CurrentElementBufferName = buffer; break; case GL_DRAW_INDIRECT_BUFFER: - glthread->draw_indirect_buffer_is_vbo = buffer != 0; + glthread->CurrentDrawIndirectBufferName = buffer; break; } } +void +_mesa_glthread_DeleteBuffers(struct gl_context *ctx, GLsizei n, + const GLuint *buffers) +{ + struct glthread_state *glthread = &ctx->GLThread; + + if (!buffers) + return; + + for (unsigned i = 0; i < n; i++) { + GLuint id = buffers[i]; + + if (id == glthread->CurrentArrayBufferName) + _mesa_glthread_BindBuffer(ctx, GL_ARRAY_BUFFER, 0); + if (id == glthread->CurrentVAO->CurrentElementBufferName) + _mesa_glthread_BindBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, 0); + if (id == glthread->CurrentDrawIndirectBufferName) + _mesa_glthread_BindBuffer(ctx, GL_DRAW_INDIRECT_BUFFER, 0); + } +} /* BufferData: marshalled asynchronously */ struct marshal_cmd_BufferData diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index e3781b0437f..3adabb217bb 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -81,10 +81,10 @@ static inline bool _mesa_glthread_is_non_vbo_draw_elements(const struct gl_context *ctx) { const struct glthread_state *glthread = &ctx->GLThread; + struct glthread_vao *vao = glthread->CurrentVAO; return ctx->API != API_OPENGL_CORE && - (glthread->CurrentVAO->IndexBufferIsUserPointer || - glthread->CurrentVAO->HasUserPointer); + (vao->CurrentElementBufferName == 0 || vao->HasUserPointer); } static inline bool @@ -101,28 +101,25 @@ _mesa_glthread_is_non_vbo_draw_arrays_indirect(const struct gl_context *ctx) const struct glthread_state *glthread = &ctx->GLThread; return ctx->API != API_OPENGL_CORE && - (!glthread->draw_indirect_buffer_is_vbo || - glthread->CurrentVAO->HasUserPointer ); + (glthread->CurrentDrawIndirectBufferName == 0 || + glthread->CurrentVAO->HasUserPointer); } static inline bool _mesa_glthread_is_non_vbo_draw_elements_indirect(const struct gl_context *ctx) { const struct glthread_state *glthread = &ctx->GLThread; + struct glthread_vao *vao = glthread->CurrentVAO; return ctx->API != API_OPENGL_CORE && - (!glthread->draw_indirect_buffer_is_vbo || - glthread->CurrentVAO->IndexBufferIsUserPointer || - glthread->CurrentVAO->HasUserPointer); + (glthread->CurrentDrawIndirectBufferName == 0 || + vao->CurrentElementBufferName == 0 || vao->HasUserPointer); } struct _glapi_table * _mesa_create_marshal_table(const struct gl_context *ctx); -void -_mesa_glthread_BindBuffer(struct gl_context *ctx, GLenum target, GLuint buffer); - static inline unsigned _mesa_buffer_enum_to_count(GLenum buffer) { diff --git a/src/mesa/main/glthread_varray.c b/src/mesa/main/glthread_varray.c index d246d2d4253..8049a9d2ff1 100644 --- a/src/mesa/main/glthread_varray.c +++ b/src/mesa/main/glthread_varray.c @@ -124,12 +124,11 @@ _mesa_glthread_GenVertexArrays(struct gl_context *ctx, GLuint id = arrays[i]; struct glthread_vao *vao; - vao = malloc(sizeof(*vao)); + vao = calloc(1, sizeof(*vao)); if (!vao) continue; /* Is that all we can do? */ vao->Name = id; - vao->HasUserPointer = false; _mesa_HashInsertLocked(glthread->VAOs, id, vao); } } @@ -139,6 +138,6 @@ _mesa_glthread_AttribPointer(struct gl_context *ctx) { struct glthread_state *glthread = &ctx->GLThread; - if (!glthread->vertex_array_is_vbo) + if (glthread->CurrentArrayBufferName == 0) glthread->CurrentVAO->HasUserPointer = true; } |