GL console related fixes
cover GL console related fixes
From: Marc-André Lureau <[email protected]>
Hi,
In the thread "[PATCH 0/6] ui/dbus: Share one listener for a console", Akihiko Odaki reported a number of issues with the GL and D-Bus display. His series propose a different design, and reverting some of my previous generic console changes to fix those issues.
However, as I work through the issue so far, they can be solved by reasonable simple fixes while keeping the console changes generic (not specific to the D-Bus display backend).
Thanks a lot Akihiko for reporting the issues and trying to solve them! Please test this alternative series and let me know of any further issues. My understanding is that you are mainly concerned with the Cocoa backend, and I don't have a way to test it, so please check it. If necessary, we may well have to revert my earlier changes and go your way, eventually.
Marc-André Lureau (3):
ui/console: fix crash when using gl context with non-gl listeners ui/console: fix texture leak when calling surface_gl_create_texture()
ui: do not create a surface when resizing a GL scanout
ui/console-gl.c | 4 ++++ ui/console.c | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
PATCH 1/3 ui/console: fix crash when using gl context with non-gl listeners
From: Marc-André Lureau <[email protected]>
The commit 7cc712e98 ("ui: dispatch GL events to all listener") mechanically replaced the dpy_gl calls with a dispatch loop, using the same pre-conditions. However, it didn't take into account that all listeners do not have to implement the GL callbacks.
Add the missing pre-conditions before calling the callbacks.
Fix crash when running a GL-enabled VM with "-device virtio-gpu-gl-pci -display egl-headless -vnc :0".
--- ui/console.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
ui/console.c +15 -7
@@ -1860,7 +1860,9 @@ void dpy_gl_scanout_disable(QemuConsole *con) con->scanout.kind =SCANOUT_NONE ; } QLIST_FOREACH(dcl, &s->listeners, next) { - dcl->ops->dpy_gl_scanout_disable (dcl); +if (dcl->ops->dpy_gl_scanout_disable) { + dcl->ops->dpy_gl_scanout_disable (dcl); + } } }
@@ -1881,10 +1883,12 @@ void dpy_gl_scanout_texture(QemuConsole *con, x, y, width, height }; QLIST_FOREACH(dcl, &s->listeners, next) { - dcl->ops->dpy_gl_scanout_texture (dcl, backing_id, - backing_y_0_top, - backing_width, backing_height, - x, y, width, height); +if (dcl->ops->dpy_gl_scanout_texture) { + dcl->ops->dpy_gl_scanout_texture (dcl, backing_id, + backing_y_0_top, + backing_width, backing_height, + x, y, width, height); + } } }
@@ -1897,7 +1901,9 @@ void dpy_gl_scanout_dmabuf(QemuConsole *con, con->scanout.kind =SCANOUT_DMABUF ; con->scanout.dmabuf = dmabuf; QLIST_FOREACH(dcl, &s->listeners, next) { - dcl->ops->dpy_gl_scanout_dmabuf (dcl, dmabuf); +if (dcl->ops->dpy_gl_scanout_dmabuf) { + dcl->ops->dpy_gl_scanout_dmabuf (dcl, dmabuf); + } } }
@@ -1951,7 +1957,9 @@ void dpy_gl_update(QemuConsole *con,graphic_hw_gl_block (con, true); QLIST_FOREACH(dcl, &s->listeners, next) { - dcl->ops->dpy_gl_update (dcl, x, y, w, h); +if (dcl->ops->dpy_gl_update) { + dcl->ops->dpy_gl_update (dcl, x, y, w, h); + } }graphic_hw_gl_block (con, false); }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
Re: [PATCH 1/3] ui/console: fix crash when using gl context with non-gl listeners
Quoted 12 lines · On 14/2/22 21:13, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
The commit
7cc712e98("ui: dispatch GL events to all listener") mechanically replaced thedpy_glcalls with a dispatch loop, using the same pre-conditions. However, it didn't take into account that all listeners do not have to implement the GL callbacks.Add the missing pre-conditions before calling the callbacks.
Fix crash when running a GL-enabled VM with "-device virtio-gpu-gl-pci -display egl-headless -vnc :0".
Quoted 6 lines
Fixes 7cc712e98 ("ui: dispatch GL events to all listener")Reported-by Akihiko Odaki <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>--- ui/console.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
PATCH 2/3 ui/console: fix texture leak when calling surface_gl_create_texture()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Make surface_gl_create_texture() idempotent: if the surface is already bound to a texture, do not create a new one.
This fixes texture leaks when there are multiple DBus listeners, for example.
--- ui/console-gl.c | 4 ++++ 1 file changed, 4 insertions(+)
ui/console-gl.c +4 -0
@@ -49,6 +49,10 @@ void surface_gl_create_texture(QemuGLShader *gls,assert (gls);assert (QEMU_IS_ALIGNED (surface_stride (surface),surface_bytes_per_pixel (surface))); +if (surface->texture) { +return ; + } +switch (surface->format) {case PIXMAN_BE_b8g8r8x8:case PIXMAN_BE_b8g8r8a8:
Signature · 1 line
2.34.1.428.gdcc0cd074f0c
PATCH 3/3 ui: do not create a surface when resizing a GL scanout
In reply to [email protected]From: Marc-André Lureau <[email protected]>
qemu_console_resize() will create a blank surface and replace the current scanout with it if called while the current scanout is GL (texture or dmabuf).
This is not only very costly, but also can produce glitches on the display/listener side.
Instead, compare the current console size with the fitting console functions, which also works when the scanout is GL.
Note: there might be still an unnecessary surface creation on calling qemu_console_resize() when the size is actually changing, but display backends currently rely on DisplaySurface details during dpy_gfx_switch() to handle various resize aspects. We would need more refactoring to handle resize without DisplaySurface, this is left for a future improvement.
--- ui/console.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
ui/console.c +3 -4
@@ -2400,13 +2400,12 @@ static void vc_chr_open(Chardev *chr,void qemu_console_resize (QemuConsole *s,int width,int height) { -DisplaySurface *surface =qemu_console_surface (s); +DisplaySurface *surface;assert (s->console_type ==GRAPHIC_CONSOLE ); -if (surface && (surface->flags &QEMU_ALLOCATED_FLAG ) && -pixman_image_get_width (surface->image) == width && -pixman_image_get_height (surface->image) == height) { +if (qemu_console_get_width (s,-1 ) == width && +qemu_console_get_height (s,-1 ) == height) {return ; }
Signature · 1 line
2.34.1.428.gdcc0cd074f0c