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@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7053>
This commit is contained in:
Marek Olšák 2020-10-03 16:52:25 -04:00 committed by Marge Bot
parent 8e7270de55
commit 9edfbd6296
4 changed files with 14 additions and 4 deletions

View file

@ -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);

View file

@ -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 */
/*@{*/

View file

@ -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);
}

View file

@ -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);
}