Mesa (main): mesa: use atomics instead of mutexes for refcounting texture objects
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jun 27 15:02:26 UTC 2021
Module: Mesa
Branch: main
Commit: 0b1914a7c194113df931bdf363e04e8e376155dd
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0b1914a7c194113df931bdf363e04e8e376155dd
Author: Marek Olšák <marek.olsak at amd.com>
Date: Mon Jun 7 09:26:55 2021 -0400
mesa: use atomics instead of mutexes for refcounting texture objects
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Reviewed-by: Emma Anholt <emma at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11339>
---
src/mesa/main/mtypes.h | 1 -
src/mesa/main/texobj.c | 23 ++++-------------------
2 files changed, 4 insertions(+), 20 deletions(-)
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index e7474ad0262..936b1511162 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -966,7 +966,6 @@ struct gl_sampler_object
*/
struct gl_texture_object
{
- simple_mtx_t Mutex; /**< for thread safety */
GLint RefCount; /**< reference count */
GLuint Name; /**< the user-visible texture object ID */
GLenum16 Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 4b8a1260593..b5b873b3ebd 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -313,7 +313,6 @@ _mesa_initialize_texture_object( struct gl_context *ctx,
memset(obj, 0, sizeof(*obj));
/* init the non-zero fields */
- simple_mtx_init(&obj->Mutex, mtx_plain);
obj->RefCount = 1;
obj->Name = name;
obj->Target = target;
@@ -449,10 +448,6 @@ _mesa_delete_texture_object(struct gl_context *ctx,
_mesa_delete_texture_handles(ctx, texObj);
_mesa_reference_buffer_object_shared(ctx, &texObj->BufferObject, NULL);
-
- /* destroy the mutex -- it may have allocated memory (eg on bsd) */
- simple_mtx_destroy(&texObj->Mutex);
-
free(texObj->Label);
/* free this object */
@@ -538,20 +533,14 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
if (*ptr) {
/* Unreference the old texture */
- GLboolean deleteFlag = GL_FALSE;
struct gl_texture_object *oldTex = *ptr;
assert(valid_texture_object(oldTex));
(void) valid_texture_object; /* silence warning in release builds */
- simple_mtx_lock(&oldTex->Mutex);
assert(oldTex->RefCount > 0);
- oldTex->RefCount--;
-
- deleteFlag = (oldTex->RefCount == 0);
- simple_mtx_unlock(&oldTex->Mutex);
- if (deleteFlag) {
+ if (p_atomic_dec_zero(&oldTex->RefCount)) {
/* Passing in the context drastically changes the driver code for
* framebuffer deletion.
*/
@@ -561,21 +550,17 @@ _mesa_reference_texobj_(struct gl_texture_object **ptr,
else
_mesa_problem(NULL, "Unable to delete texture, no context");
}
-
- *ptr = NULL;
}
- assert(!*ptr);
if (tex) {
/* reference new texture */
assert(valid_texture_object(tex));
- simple_mtx_lock(&tex->Mutex);
assert(tex->RefCount > 0);
- tex->RefCount++;
- *ptr = tex;
- simple_mtx_unlock(&tex->Mutex);
+ p_atomic_inc(&tex->RefCount);
}
+
+ *ptr = tex;
}
More information about the mesa-commit
mailing list