Module: Mesa Branch: main Commit: ec7e26234901359a694b54f72e7ac78f00b6ab60 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ec7e26234901359a694b54f72e7ac78f00b6ab60
Author: Marek Olšák <[email protected]> Date: Mon Jun 14 15:51:30 2021 -0400 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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11514> --- src/mesa/main/bufferobj.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c index 18fa67d2d74..486aac31a8a 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); _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
