qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fixes for ui/gtk-gl-area
@ 2022-06-05  8:50 Volker Rümelin
  2022-06-05  8:51 ` [PATCH 1/2] ui/gtk-gl-area: implement GL context destruction Volker Rümelin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Volker Rümelin @ 2022-06-05  8:50 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

The first patch fixes a GL context leak.

The second patch fixes a black guest screen on Wayland with OpenGL 
accelerated QEMU graphics devices. This bug doesn't seem to be related 
to issues #910, #865, #671 or #298.

Volker Rümelin (2):
   ui/gtk-gl-area: implement GL context destruction
   ui/gtk-gl-area: create the requested GL context version

  ui/gtk-gl-area.c | 39 +++++++++++++++++++++++++++++++++++++--
  ui/trace-events  |  2 ++
  2 files changed, 39 insertions(+), 2 deletions(-)

-- 
2.35.3



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

* [PATCH 1/2] ui/gtk-gl-area: implement GL context destruction
  2022-06-05  8:50 [PATCH 0/2] Fixes for ui/gtk-gl-area Volker Rümelin
@ 2022-06-05  8:51 ` Volker Rümelin
  2022-06-05  8:51 ` [PATCH 2/2] ui/gtk-gl-area: create the requested GL context version Volker Rümelin
  2022-06-09  9:24 ` [PATCH 0/2] Fixes for ui/gtk-gl-area Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2022-06-05  8:51 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

The counterpart function for gd_gl_area_create_context() is
currently empty. Implement the gd_gl_area_destroy_context()
function to avoid GL context leaks.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 ui/gtk-gl-area.c | 8 +++++++-
 ui/trace-events  | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index fc5a082eb8..0e20ea031d 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -201,7 +201,13 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
 
 void gd_gl_area_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)
 {
-    /* FIXME */
+    GdkGLContext *current_ctx = gdk_gl_context_get_current();
+
+    trace_gd_gl_area_destroy_context(ctx, current_ctx);
+    if (ctx == current_ctx) {
+        gdk_gl_context_clear_current();
+    }
+    g_clear_object(&ctx);
 }
 
 void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
diff --git a/ui/trace-events b/ui/trace-events
index f78b5e6606..1040ba0f88 100644
--- a/ui/trace-events
+++ b/ui/trace-events
@@ -26,6 +26,7 @@ gd_key_event(const char *tab, int gdk_keycode, int qkeycode, const char *action)
 gd_grab(const char *tab, const char *device, const char *reason) "tab=%s, dev=%s, reason=%s"
 gd_ungrab(const char *tab, const char *device) "tab=%s, dev=%s"
 gd_keymap_windowing(const char *name) "backend=%s"
+gd_gl_area_destroy_context(void *ctx, void *current_ctx) "ctx=%p, current_ctx=%p"
 
 # vnc-auth-sasl.c
 # vnc-auth-vencrypt.c
-- 
2.35.3



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

* [PATCH 2/2] ui/gtk-gl-area: create the requested GL context version
  2022-06-05  8:50 [PATCH 0/2] Fixes for ui/gtk-gl-area Volker Rümelin
  2022-06-05  8:51 ` [PATCH 1/2] ui/gtk-gl-area: implement GL context destruction Volker Rümelin
@ 2022-06-05  8:51 ` Volker Rümelin
  2022-06-09  9:24 ` [PATCH 0/2] Fixes for ui/gtk-gl-area Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2022-06-05  8:51 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

Since about 2018 virglrenderer (commit fa835b0f88 "vrend: don't
hardcode context version") tries to open the highest available GL
context version. This is done by creating the known GL context
versions from the highest to the lowest until (*create_gl_context)
returns a context != NULL.

This does not work properly with
the current QEMU gd_gl_area_create_context() function, because
gdk_gl_context_realize() on Wayland creates a version 3.0 legacy
context if the requested GL context version can't be created.

In order for virglrenderer to find the highest available GL
context version, return NULL if the created context version is
lower than the requested version.

This fixes the following error:
QEMU started with -device virtio-vga-gl -display gtk,gl=on.
Under Wayland, the guest window remains black and the following
information can be seen on the host.

gl_version 30 - compat profile
(qemu:5978): Gdk-WARNING **: 16:19:01.533:
  gdk_gl_context_set_required_version
  - GL context versions less than 3.2 are not supported.

(qemu:5978): Gdk-WARNING **: 16:19:01.537:
  gdk_gl_context_set_required_version -
  GL context versions less than 3.2 are not supported.

(qemu:5978): Gdk-WARNING **: 16:19:01.554:
  gdk_gl_context_set_required_version -
  GL context versions less than 3.2 are not supported.
vrend_renderer_fill_caps: Entering with stale GL error: 1282

To reproduce this error, an OpenGL driver is required on the host
that doesn't have the latest OpenGL extensions fully implemented.
An example for this is the Intel i965 driver on a Haswell processor.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 ui/gtk-gl-area.c | 31 ++++++++++++++++++++++++++++++-
 ui/trace-events  |  1 +
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 0e20ea031d..2e0129c28c 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -170,6 +170,23 @@ void gd_gl_area_switch(DisplayChangeListener *dcl,
     }
 }
 
+static int gd_cmp_gl_context_version(int major, int minor, QEMUGLParams *params)
+{
+    if (major > params->major_ver) {
+        return 1;
+    }
+    if (major < params->major_ver) {
+        return -1;
+    }
+    if (minor > params->minor_ver) {
+        return 1;
+    }
+    if (minor < params->minor_ver) {
+        return -1;
+    }
+    return 0;
+}
+
 QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
                                         QEMUGLParams *params)
 {
@@ -177,8 +194,8 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
     GdkWindow *window;
     GdkGLContext *ctx;
     GError *err = NULL;
+    int major, minor;
 
-    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
     window = gtk_widget_get_window(vc->gfx.drawing_area);
     ctx = gdk_window_create_gl_context(window, &err);
     if (err) {
@@ -196,6 +213,18 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
         g_clear_object(&ctx);
         return NULL;
     }
+
+    gdk_gl_context_make_current(ctx);
+    gdk_gl_context_get_version(ctx, &major, &minor);
+    gdk_gl_context_clear_current();
+    gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+
+    if (gd_cmp_gl_context_version(major, minor, params) == -1) {
+        /* created ctx version < requested version */
+        g_clear_object(&ctx);
+    }
+
+    trace_gd_gl_area_create_context(ctx, params->major_ver, params->minor_ver);
     return ctx;
 }
 
diff --git a/ui/trace-events b/ui/trace-events
index 1040ba0f88..a922f00e10 100644
--- a/ui/trace-events
+++ b/ui/trace-events
@@ -26,6 +26,7 @@ gd_key_event(const char *tab, int gdk_keycode, int qkeycode, const char *action)
 gd_grab(const char *tab, const char *device, const char *reason) "tab=%s, dev=%s, reason=%s"
 gd_ungrab(const char *tab, const char *device) "tab=%s, dev=%s"
 gd_keymap_windowing(const char *name) "backend=%s"
+gd_gl_area_create_context(void *ctx, int major, int minor) "ctx=%p, major=%d, minor=%d"
 gd_gl_area_destroy_context(void *ctx, void *current_ctx) "ctx=%p, current_ctx=%p"
 
 # vnc-auth-sasl.c
-- 
2.35.3



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

* Re: [PATCH 0/2] Fixes for ui/gtk-gl-area
  2022-06-05  8:50 [PATCH 0/2] Fixes for ui/gtk-gl-area Volker Rümelin
  2022-06-05  8:51 ` [PATCH 1/2] ui/gtk-gl-area: implement GL context destruction Volker Rümelin
  2022-06-05  8:51 ` [PATCH 2/2] ui/gtk-gl-area: create the requested GL context version Volker Rümelin
@ 2022-06-09  9:24 ` Gerd Hoffmann
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-06-09  9:24 UTC (permalink / raw)
  To: Volker Rümelin; +Cc: qemu-devel

On Sun, Jun 05, 2022 at 10:50:28AM +0200, Volker Rümelin wrote:
> The first patch fixes a GL context leak.
> 
> The second patch fixes a black guest screen on Wayland with OpenGL
> accelerated QEMU graphics devices. This bug doesn't seem to be related to
> issues #910, #865, #671 or #298.

Both queueed up.

thanks,
  Gerd



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

end of thread, other threads:[~2022-06-09 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-05  8:50 [PATCH 0/2] Fixes for ui/gtk-gl-area Volker Rümelin
2022-06-05  8:51 ` [PATCH 1/2] ui/gtk-gl-area: implement GL context destruction Volker Rümelin
2022-06-05  8:51 ` [PATCH 2/2] ui/gtk-gl-area: create the requested GL context version Volker Rümelin
2022-06-09  9:24 ` [PATCH 0/2] Fixes for ui/gtk-gl-area Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).