glthread: fix an upload buffer leak

Fixes: befbd54864 - glthread: don't use atomics for refcounting to decrease overhead on AMD Zen

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20804>
This commit is contained in:
Marek Olšák
2023-01-19 19:57:02 -05:00
committed by Marge Bot
parent 6f02f9d108
commit 4d4995b32b
3 changed files with 17 additions and 6 deletions
+1
View File
@@ -189,6 +189,7 @@ _mesa_glthread_destroy(struct gl_context *ctx, const char *reason)
_mesa_HashDeleteAll(glthread->VAOs, free_vao, NULL);
_mesa_DeleteHashTable(glthread->VAOs);
_mesa_glthread_release_upload_buffer(ctx);
ctx->GLThread.enabled = false;
ctx->CurrentClientDispatch = ctx->CurrentServerDispatch;
+1
View File
@@ -274,6 +274,7 @@ void _mesa_glthread_init_dispatch7(struct gl_context *ctx,
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_release_upload_buffer(struct gl_context *ctx);
void _mesa_glthread_upload(struct gl_context *ctx, const void *data,
GLsizeiptr size, unsigned *out_offset,
struct gl_buffer_object **out_buffer,
+15 -6
View File
@@ -62,6 +62,19 @@ new_upload_buffer(struct gl_context *ctx, GLsizeiptr size, uint8_t **ptr)
return obj;
}
void
_mesa_glthread_release_upload_buffer(struct gl_context *ctx)
{
struct glthread_state *glthread = &ctx->GLThread;
if (glthread->upload_buffer_private_refcount > 0) {
p_atomic_add(&glthread->upload_buffer->RefCount,
-glthread->upload_buffer_private_refcount);
glthread->upload_buffer_private_refcount = 0;
}
_mesa_reference_buffer_object(ctx, &glthread->upload_buffer, NULL);
}
void
_mesa_glthread_upload(struct gl_context *ctx, const void *data,
GLsizeiptr size, unsigned *out_offset,
@@ -100,12 +113,8 @@ _mesa_glthread_upload(struct gl_context *ctx, const void *data,
return;
}
if (glthread->upload_buffer_private_refcount > 0) {
p_atomic_add(&glthread->upload_buffer->RefCount,
-glthread->upload_buffer_private_refcount);
glthread->upload_buffer_private_refcount = 0;
}
_mesa_reference_buffer_object(ctx, &glthread->upload_buffer, NULL);
_mesa_glthread_release_upload_buffer(ctx);
glthread->upload_buffer =
new_upload_buffer(ctx, default_size, &glthread->upload_ptr);
glthread->upload_offset = 0;