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>
(cherry picked from commit 4d4995b32b)
This commit is contained in:
Marek Olšák 2023-01-19 19:57:02 -05:00 committed by Eric Engestrom
parent 7b38217922
commit 6c869d993a
4 changed files with 18 additions and 7 deletions

View file

@ -1957,7 +1957,7 @@
"description": "glthread: fix an upload buffer leak",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "befbd54864d2959b83e3d2d46d0825f19cb4fc46"
},

View file

@ -186,6 +186,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;

View file

@ -275,6 +275,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,

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;