summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2021-06-14 15:51:30 -0400
committerMarge Bot <eric+marge@anholt.net>2021-06-23 06:06:04 +0000
commitec7e26234901359a694b54f72e7ac78f00b6ab60 (patch)
tree65f4adc1a11f08114f32c891af0136b98467ddd3 /src
parent29d272f144ba800933af656717ed57adaa5e6510 (diff)
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 <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11514>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/bufferobj.c21
1 files 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);