mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-01 11:50:09 +01:00
mesa: use atomics instead of mutexes for refcounting texture objects
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>
This commit is contained in:
parent
f3d331a5e3
commit
0b1914a7c1
2 changed files with 4 additions and 20 deletions
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue