mesa: use atomics instead of mutexes for refcounting sampler objects
authorMarek Olšák <marek.olsak@amd.com>
Mon, 7 Jun 2021 13:26:55 +0000 (09:26 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Sun, 27 Jun 2021 14:27:09 +0000 (10:27 -0400)
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11339>

src/mesa/main/mtypes.h
src/mesa/main/samplerobj.c

index 936b151..77bfdf7 100644 (file)
@@ -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;
index 841e07f..05bf181 100644 (file)
@@ -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;