Mesa (main): mesa: use atomics instead of mutexes for refcounting sampler objects
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jun 27 15:02:26 UTC 2021
Module: Mesa
Branch: main
Commit: e77adbffb45bfad805a880135bfadea0cfb0c49e
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e77adbffb45bfad805a880135bfadea0cfb0c49e
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 sampler 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/samplerobj.c | 19 ++++---------------
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 936b1511162..77bfdf7cda1 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -947,7 +947,6 @@ struct gl_texture_object_attrib
*/
struct gl_sampler_object
{
- simple_mtx_t Mutex;
GLuint Name;
GLchar *Label; /**< GL_KHR_debug */
GLint RefCount;
diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c
index 841e07f8a4c..05bf181175e 100644
--- a/src/mesa/main/samplerobj.c
+++ b/src/mesa/main/samplerobj.c
@@ -63,7 +63,6 @@ delete_sampler_object(struct gl_context *ctx,
struct gl_sampler_object *sampObj)
{
_mesa_delete_sampler_handles(ctx, sampObj);
- simple_mtx_destroy(&sampObj->Mutex);
free(sampObj->Label);
free(sampObj);
}
@@ -80,31 +79,22 @@ _mesa_reference_sampler_object_(struct gl_context *ctx,
if (*ptr) {
/* Unreference the old sampler */
- GLboolean deleteFlag = GL_FALSE;
struct gl_sampler_object *oldSamp = *ptr;
- simple_mtx_lock(&oldSamp->Mutex);
assert(oldSamp->RefCount > 0);
- oldSamp->RefCount--;
- deleteFlag = (oldSamp->RefCount == 0);
- simple_mtx_unlock(&oldSamp->Mutex);
- if (deleteFlag)
+ if (p_atomic_dec_zero(&oldSamp->RefCount))
delete_sampler_object(ctx, oldSamp);
-
- *ptr = NULL;
}
- assert(!*ptr);
if (samp) {
/* reference new sampler */
- simple_mtx_lock(&samp->Mutex);
assert(samp->RefCount > 0);
- samp->RefCount++;
- *ptr = samp;
- simple_mtx_unlock(&samp->Mutex);
+ p_atomic_inc(&samp->RefCount);
}
+
+ *ptr = samp;
}
@@ -114,7 +104,6 @@ _mesa_reference_sampler_object_(struct gl_context *ctx,
static void
_mesa_init_sampler_object(struct gl_sampler_object *sampObj, GLuint name)
{
- simple_mtx_init(&sampObj->Mutex, mtx_plain);
sampObj->Name = name;
sampObj->RefCount = 1;
sampObj->Attrib.WrapS = GL_REPEAT;
More information about the mesa-commit
mailing list