From 7a2e0b2a87f87d57a7a1f8cdc743c25f48b6b029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 14 Jun 2021 15:51:30 -0400 Subject: [PATCH] mesa: unreference zombie buffers when creating buffers to lower memory usage This fixes an issue where one context only creates buffers while another context only destroys buffers. Only the creating context can release its buffers and the destroying context only turns them into zombie buffers. This fix makes the creating context release its zombie buffers. It's not a plot from an apocalyptic movie. Fixes: e014e3b6be6 "mesa: don't count buffer references for the context that created them" Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4840 Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: (cherry picked from commit ec7e26234901359a694b54f72e7ac78f00b6ab60) --- .pick_status.json | 2 +- src/mesa/main/bufferobj.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index fc4081dc6ce..ed90019df52 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1408,7 +1408,7 @@ "description": "mesa: unreference zombie buffers when creating buffers to lower memory usage", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "e014e3b6be638f4192d6eddd3d1033fd571f3a76" }, diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 6a8c80bf535..742ed8be5a9 100644 --- a/src/mesa/main/bufferobj.c +++ b/src/mesa/main/bufferobj.c @@ -1084,8 +1084,18 @@ _mesa_handle_bind_buffer_gen(struct gl_context *ctx, _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller); return false; } - _mesa_HashInsertMaybeLocked(ctx->Shared->BufferObjects, buffer, - *buf_handle, buf != NULL, + _mesa_HashLockMaybeLocked(ctx->Shared->BufferObjects, + ctx->BufferObjectsLocked); + _mesa_HashInsertLocked(ctx->Shared->BufferObjects, buffer, + *buf_handle, buf != NULL); + /* If one context only creates buffers and another context only deletes + * buffers, buffers don't get released because it only produces zombie + * buffers. Only the context that has created the buffers can release + * them. Thus, when we create buffers, we prune the list of zombie + * buffers. + */ + unreference_zombie_buffers_for_ctx(ctx); + _mesa_HashUnlockMaybeLocked(ctx->Shared->BufferObjects, ctx->BufferObjectsLocked); } @@ -1763,6 +1773,13 @@ create_buffers(struct gl_context *ctx, GLsizei n, GLuint *buffers, bool dsa) */ _mesa_HashLockMaybeLocked(ctx->Shared->BufferObjects, ctx->BufferObjectsLocked); + /* If one context only creates buffers and another context only deletes + * buffers, buffers don't get released because it only produces zombie + * buffers. Only the context that has created the buffers can release + * them. Thus, when we create buffers, we prune the list of zombie + * buffers. + */ + unreference_zombie_buffers_for_ctx(ctx); _mesa_HashFindFreeKeys(ctx->Shared->BufferObjects, buffers, n);