From 9bb696588db0dd568599cbebb43c3eac788f863e Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 21 Mar 2025 11:13:33 +1100 Subject: [PATCH] mesa: fix reuse of deleted sampler object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deleting a sampler 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: 842c9130 ("mesa: enable GL name reuse by default for all drivers except virgl") Part-of: --- src/mesa/main/mtypes.h | 2 ++ src/mesa/main/samplerobj.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index d91d5381a48..88932dbbc71 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -889,6 +889,8 @@ struct gl_sampler_object uint8_t glclamp_mask; /**< mask of GL_CLAMP wraps active */ + bool DeletePending; /**< true if sampler object is removed from the hash */ + /** GL_ARB_bindless_texture */ bool HandleAllocated; struct util_dynarray Handles; diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c index afb18f8c574..87bab4a61b8 100644 --- a/src/mesa/main/samplerobj.c +++ b/src/mesa/main/samplerobj.c @@ -265,6 +265,8 @@ delete_samplers(struct gl_context *ctx, GLsizei count, const GLuint *samplers) } } + sampObj->DeletePending = true; + /* The ID is immediately freed for re-use */ _mesa_HashRemoveLocked(&ctx->Shared->SamplerObjects, samplers[i]); /* But the object exists until its reference count goes to zero */ @@ -402,7 +404,8 @@ bind_samplers(struct gl_context *ctx, GLuint first, GLsizei count, struct gl_sampler_object *sampObj; if (samplers[i] != 0) { - if (currentSampler && currentSampler->Name == samplers[i]) + if (currentSampler && !currentSampler->DeletePending && + currentSampler->Name == samplers[i]) sampObj = currentSampler; else sampObj = lookup_samplerobj_locked(ctx, samplers[i]);