glthread: handle buffer unbinding via glDeleteBuffers
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4124>
This commit is contained in:
parent
15b0719ae2
commit
bde4505f61
|
@ -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"/>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue