Mesa (master): mesa: lock Shared->TexMutex only once for a glthread batch
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Nov 21 21:21:13 UTC 2020
Module: Mesa
Branch: master
Commit: 9edfbd629611109d56d11943f92a4e4bcfebf3ab
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=9edfbd629611109d56d11943f92a4e4bcfebf3ab
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sat Oct 3 16:52:25 2020 -0400
mesa: lock Shared->TexMutex only once for a glthread batch
This removes a lot of locking from the driver thread.
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7053>
---
src/mesa/main/glthread.c | 4 ++++
src/mesa/main/mtypes.h | 2 ++
src/mesa/main/texobj.c | 6 ++++--
src/mesa/main/texobj.h | 6 ++++--
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c
index cf50ce45496..09de7f436d0 100644
--- a/src/mesa/main/glthread.c
+++ b/src/mesa/main/glthread.c
@@ -54,6 +54,8 @@ glthread_unmarshal_batch(void *job, int thread_index)
_mesa_HashLockMutex(ctx->Shared->BufferObjects);
ctx->BufferObjectsLocked = true;
+ mtx_lock(&ctx->Shared->TexMutex);
+ ctx->TexturesLocked = true;
while (pos < used) {
const struct marshal_cmd_base *cmd =
@@ -63,6 +65,8 @@ glthread_unmarshal_batch(void *job, int thread_index)
pos += cmd->cmd_size;
}
+ ctx->TexturesLocked = false;
+ mtx_unlock(&ctx->Shared->TexMutex);
ctx->BufferObjectsLocked = false;
_mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8302416d50a..3def2590627 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4928,6 +4928,8 @@ struct gl_context
/** Whether Shared->BufferObjects has already been locked for this context. */
bool BufferObjectsLocked;
+ /** Whether Shared->TexMutex has already been locked for this context. */
+ bool TexturesLocked;
/** \name API function pointer tables */
/*@{*/
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 01fbe36dc23..68d9755a087 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -2193,7 +2193,8 @@ _mesa_IsTexture( GLuint texture )
void
_mesa_lock_context_textures( struct gl_context *ctx )
{
- mtx_lock(&ctx->Shared->TexMutex);
+ if (!ctx->TexturesLocked)
+ mtx_lock(&ctx->Shared->TexMutex);
if (ctx->Shared->TextureStateStamp != ctx->TextureStateTimestamp) {
ctx->NewState |= _NEW_TEXTURE_OBJECT;
@@ -2206,7 +2207,8 @@ void
_mesa_unlock_context_textures( struct gl_context *ctx )
{
assert(ctx->Shared->TextureStateStamp == ctx->TextureStateTimestamp);
- mtx_unlock(&ctx->Shared->TexMutex);
+ if (!ctx->TexturesLocked)
+ mtx_unlock(&ctx->Shared->TexMutex);
}
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 91901617c68..b6d62fbd67f 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -106,7 +106,8 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
static inline void
_mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
{
- mtx_lock(&ctx->Shared->TexMutex);
+ if (!ctx->TexturesLocked)
+ mtx_lock(&ctx->Shared->TexMutex);
ctx->Shared->TextureStateStamp++;
(void) texObj;
}
@@ -115,7 +116,8 @@ static inline void
_mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
{
(void) texObj;
- mtx_unlock(&ctx->Shared->TexMutex);
+ if (!ctx->TexturesLocked)
+ mtx_unlock(&ctx->Shared->TexMutex);
}
More information about the mesa-commit
mailing list