st/interup: flushing objects is a no-op when no context is bound

Luckily this is backwards compatible, because without this change users
would simply run into crashes within _mesa_glthread_finish.

Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36249>
(cherry picked from commit 4d8b08e7ec)
This commit is contained in:
Karol Herbst 2025-07-21 18:01:12 +02:00 committed by Eric Engestrom
parent eaba9c14c0
commit dec55fc830
2 changed files with 25 additions and 5 deletions

View file

@ -6244,7 +6244,7 @@
"description": "st/interup: flushing objects is a no-op when no context is bound",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -383,12 +383,36 @@ st_interop_flush_objects(struct st_context *st,
unsigned count, struct mesa_glinterop_export_in *objects,
struct mesa_glinterop_flush_out *out)
{
GET_CURRENT_CONTEXT(cur_ctx);
struct gl_context *ctx = st->ctx;
bool flush_out_struct = false;
if (!ctx->screen->resource_get_handle && !ctx->screen->interop_export_object)
return MESA_GLINTEROP_UNSUPPORTED;
for (unsigned i = 0; i < count; ++i) {
if (objects[i].version >= 2) {
flush_out_struct = true;
break;
}
}
/* If we don't have a current context bound, there is nothing to flush */
if (!cur_ctx) {
if (flush_out_struct) {
if (out->sync)
*out->sync = NULL;
if (out->fence_fd)
*out->fence_fd = -1;
out->version = MIN2(out->version, 1);
} else {
GLsync *sync = (GLsync *)out;
*sync = NULL;
}
return MESA_GLINTEROP_SUCCESS;
}
/* Wait for glthread to finish to get up-to-date GL object lookups. */
_mesa_glthread_finish(st->ctx);
@ -396,10 +420,6 @@ st_interop_flush_objects(struct st_context *st,
for (unsigned i = 0; i < count; ++i) {
int ret = flush_object(ctx, &objects[i]);
if (objects[i].version >= 2)
flush_out_struct = true;
if (ret != MESA_GLINTEROP_SUCCESS) {
simple_mtx_unlock(&ctx->Shared->Mutex);
return ret;