From 9edfbd629611109d56d11943f92a4e4bcfebf3ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 3 Oct 2020 16:52:25 -0400 Subject: [PATCH] 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 Part-of: --- 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 cf50ce4..09de7f4 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 8302416..3def259 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 01fbe36..68d9755 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 9190161..b6d62fb 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); } -- 2.7.4