public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH] ui/egl-helpers: Fix FBO recreation and prevent texture accidental deletion
@ 2026-03-03  1:08 dongwon.kim
  2026-03-17 12:51 ` Marc-André Lureau
  0 siblings, 1 reply; 3+ messages in thread
From: dongwon.kim @ 2026-03-03  1:08 UTC (permalink / raw)
  To: qemu-devel

From: Dongwon Kim <dongwon.kim@intel.com>

When egl_fb_setup_for_tex is called, we must handle cases
where the texture ID is reused across different GL contexts.

Texture Preservation - If the new texture ID matches
the cached ID, we must skip egl_fb_delete_texture to avoid
destroying the texture we are about to use.

FBO Recreation - Because FBOs are context-local and not shared,
a cached FBO ID from a previous context is invalid. We must
generate a new FBO handle if we are re-validating the same
texture ID in a potentially new context.

This prevents stale FBO usage and unintended texture deletion
during context transitions.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
---
 ui/egl-helpers.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c
index e3f2872cc1..7ac64f3ba8 100644
--- a/ui/egl-helpers.c
+++ b/ui/egl-helpers.c
@@ -111,15 +111,23 @@ void egl_fb_setup_default(egl_fb *fb, int width, int height, int x, int y)
 void egl_fb_setup_for_tex(egl_fb *fb, int width, int height,
                           GLuint texture, bool delete)
 {
-    egl_fb_delete_texture(fb);
+    if (fb->texture != texture) {
+        egl_fb_delete_texture(fb);
+    }
+
+    /*
+     * If fb->texture == texture, the existing fb->framebuffer is tied to
+     * a previous GL context. Since FBOs are not shared across contexts,
+     * we must create a new FBO for the current context.
+     */
+    if (!fb->framebuffer || (fb->texture == texture)) {
+        glGenFramebuffers(1, &fb->framebuffer);
+    }
 
     fb->width = width;
     fb->height = height;
     fb->texture = texture;
     fb->delete_texture = delete;
-    if (!fb->framebuffer) {
-        glGenFramebuffers(1, &fb->framebuffer);
-    }
 
     glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb->framebuffer);
     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-25 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03  1:08 [PATCH] ui/egl-helpers: Fix FBO recreation and prevent texture accidental deletion dongwon.kim
2026-03-17 12:51 ` Marc-André Lureau
2026-03-25 17:42   ` Kim, Dongwon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox