From dec55fc83048e55f3c7314a20c8573fae5f5e6b4 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Mon, 21 Jul 2025 18:01:12 +0200 Subject: [PATCH] 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: (cherry picked from commit 4d8b08e7ec57601765e0f3e9e656762d0902d5b2) --- .pick_status.json | 2 +- src/mesa/state_tracker/st_interop.c | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 2a3261de311..fb328e5226f 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -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 diff --git a/src/mesa/state_tracker/st_interop.c b/src/mesa/state_tracker/st_interop.c index 2418d63fe7c..531b57aeb7b 100644 --- a/src/mesa/state_tracker/st_interop.c +++ b/src/mesa/state_tracker/st_interop.c @@ -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;