From 9b85142e40468196dcf9d6d4260a6cef86d4243f Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 19 Mar 2025 10:20:45 +1100 Subject: [PATCH] mesa: fix reuse of deleted texture object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deleting a texture object will only cause it to be unbound from the current context. To avoid reusing something that it still bound in another context we need to check the DeletePending flag first. Reviewed-by: Marek Olšák Reviewed-by: Pierre-Eric Pelloux-Prayer Fixes: 842c91300fd0 ("mesa: enable GL name reuse by default for all drivers except virgl") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12710 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12722 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12830 Part-of: --- src/mesa/main/mtypes.h | 1 + src/mesa/main/texobj.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 15bff7bd6fd..d91d5381a48 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -932,6 +932,7 @@ struct gl_texture_object GLboolean _IsFloat; /**< GL_OES_float_texture */ GLboolean _IsHalfFloat; /**< GL_OES_half_float_texture */ bool HandleAllocated; /**< GL_ARB_bindless_texture */ + bool DeletePending; /**< true if texture object is removed from the hash */ /* This should not be restored by glPopAttrib: */ bool StencilSampling; /**< Should we sample stencil instead of depth? */ diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index 436e082b763..22e68e6fd87 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -1560,6 +1560,8 @@ delete_textures(struct gl_context *ctx, GLsizei n, const GLuint *textures) */ _mesa_make_texture_handles_non_resident(ctx, delObj); + delObj->DeletePending = true; + _mesa_unlock_texture(ctx, delObj); ctx->NewState |= _NEW_TEXTURE_OBJECT; @@ -1985,7 +1987,8 @@ bind_textures(struct gl_context *ctx, GLuint first, GLsizei count, struct gl_texture_object *current = texUnit->_Current; struct gl_texture_object *texObj; - if (current && current->Name == textures[i]) + if (current && !current->DeletePending && + current->Name == textures[i]) texObj = current; else texObj = _mesa_lookup_texture_locked(ctx, textures[i]);