mesa: fix reuse of deleted sampler object

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 <marek.olsak@amd.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fixes: 842c9130 ("mesa: enable GL name reuse by default for all drivers except virgl")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34091>
This commit is contained in:
Timothy Arceri 2025-03-21 11:13:33 +11:00 committed by Marge Bot
parent 95e87f6a6a
commit 9bb696588d
2 changed files with 6 additions and 1 deletions

View file

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

View file

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