All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, kraxel@redhat.com
Subject: [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed
Date: Thu,  4 Feb 2021 14:52:30 +0400	[thread overview]
Message-ID: <20210204105232.834642-19-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20210204105232.834642-1-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Displaying rendered resources requires blocking qemu GPU to avoid extra
framebuffer copies. For an external display, via Spice currently, there
is a callback to block/unblock the rendering in the same thread.

But with the vhost-user-gpu backend, the qemu process doesn't handle
the rendering itself, and the blocking callback isn't effective.
Instead, the backend must be notified when the display code is done.

Fix this by adding a new GraphicHwOps callback to indicate the GL state
is flushed, and we are done manipulating the shared GL resources. Call
it from gtk and spice display.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/virtio/virtio-gpu.h |  2 +-
 include/ui/console.h           |  2 ++
 hw/display/vhost-user-gpu.c    |  4 ++--
 hw/display/virtio-gpu-base.c   | 17 ++++++++++++-----
 hw/display/virtio-gpu.c        |  4 ++--
 hw/display/virtio-vga.c        | 11 +++++++++++
 ui/console.c                   |  9 +++++++++
 ui/gtk-egl.c                   |  3 +++
 ui/gtk-gl-area.c               |  3 +++
 ui/sdl2-gl.c                   |  2 ++
 ui/spice-display.c             |  1 +
 11 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 0043268e90..fae149235c 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -121,7 +121,7 @@ struct VirtIOGPUBase {
 struct VirtIOGPUBaseClass {
     VirtioDeviceClass parent;
 
-    void (*gl_unblock)(VirtIOGPUBase *g);
+    void (*gl_flushed)(VirtIOGPUBase *g);
 };
 
 #define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf)                       \
diff --git a/include/ui/console.h b/include/ui/console.h
index 875885d9c7..d30e972d0b 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -387,6 +387,7 @@ typedef struct GraphicHwOps {
     void (*update_interval)(void *opaque, uint64_t interval);
     int (*ui_info)(void *opaque, uint32_t head, QemuUIInfo *info);
     void (*gl_block)(void *opaque, bool block);
+    void (*gl_flushed)(void *opaque);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev, uint32_t head,
@@ -402,6 +403,7 @@ void graphic_hw_update_done(QemuConsole *con);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 void graphic_hw_gl_block(QemuConsole *con, bool block);
+void graphic_hw_gl_flushed(QemuConsole *con);
 
 void qemu_console_early_init(void);
 
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index b7bde9feb6..4d8cb3525b 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -360,7 +360,7 @@ vhost_user_gpu_update_blocked(VhostUserGPU *g, bool blocked)
 }
 
 static void
-vhost_user_gpu_gl_unblock(VirtIOGPUBase *b)
+vhost_user_gpu_gl_flushed(VirtIOGPUBase *b)
 {
     VhostUserGPU *g = VHOST_USER_GPU(b);
 
@@ -578,7 +578,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
 
-    vgc->gl_unblock = vhost_user_gpu_gl_unblock;
+    vgc->gl_flushed = vhost_user_gpu_gl_flushed;
 
     vdc->realize = vhost_user_gpu_device_realize;
     vdc->reset = vhost_user_gpu_reset;
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index f27a6fbe75..4a57350917 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -97,21 +97,27 @@ static int virtio_gpu_ui_info(void *opaque, uint32_t idx, QemuUIInfo *info)
 }
 
 static void
-virtio_gpu_gl_block(void *opaque, bool block)
+virtio_gpu_gl_flushed(void *opaque)
 {
     VirtIOGPUBase *g = opaque;
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_GET_CLASS(g);
 
+    if (vgc->gl_flushed) {
+        vgc->gl_flushed(g);
+    }
+}
+
+static void
+virtio_gpu_gl_block(void *opaque, bool block)
+{
+    VirtIOGPUBase *g = opaque;
+
     if (block) {
         g->renderer_blocked++;
     } else {
         g->renderer_blocked--;
     }
     assert(g->renderer_blocked >= 0);
-
-    if (g->renderer_blocked == 0) {
-        vgc->gl_unblock(g);
-    }
 }
 
 static int
@@ -138,6 +144,7 @@ static const GraphicHwOps virtio_gpu_ops = {
     .text_update = virtio_gpu_text_update,
     .ui_info = virtio_gpu_ui_info,
     .gl_block = virtio_gpu_gl_block,
+    .gl_flushed = virtio_gpu_gl_flushed,
 };
 
 bool
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 7eb4265a6d..2e4a9822b6 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -850,7 +850,7 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
     g->processing_cmdq = false;
 }
 
-static void virtio_gpu_gl_unblock(VirtIOGPUBase *b)
+static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
 {
     VirtIOGPU *g = VIRTIO_GPU(b);
 
@@ -1257,7 +1257,7 @@ static void virtio_gpu_class_init(ObjectClass *klass, void *data)
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
 
-    vgc->gl_unblock = virtio_gpu_gl_unblock;
+    vgc->gl_flushed = virtio_gpu_gl_flushed;
     vdc->realize = virtio_gpu_device_realize;
     vdc->reset = virtio_gpu_reset;
     vdc->get_config = virtio_gpu_get_config;
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index b071909b68..d3c6404061 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -68,6 +68,16 @@ static void virtio_vga_base_gl_block(void *opaque, bool block)
     }
 }
 
+static void virtio_vga_base_gl_flushed(void *opaque)
+{
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
+
+    if (g->hw_ops->gl_flushed) {
+        g->hw_ops->gl_flushed(g);
+    }
+}
+
 static int virtio_vga_base_get_flags(void *opaque)
 {
     VirtIOVGABase *vvga = opaque;
@@ -83,6 +93,7 @@ static const GraphicHwOps virtio_vga_base_ops = {
     .text_update = virtio_vga_base_text_update,
     .ui_info = virtio_vga_base_ui_info,
     .gl_block = virtio_vga_base_gl_block,
+    .gl_flushed = virtio_vga_base_gl_flushed,
 };
 
 static const VMStateDescription vmstate_virtio_vga_base = {
diff --git a/ui/console.c b/ui/console.c
index d8cc640c28..c5d11bc701 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -294,6 +294,15 @@ void graphic_hw_gl_block(QemuConsole *con, bool block)
     }
 }
 
+void graphic_hw_gl_flushed(QemuConsole *con)
+{
+    assert(con != NULL);
+
+    if (con->hw_ops->gl_flushed) {
+        con->hw_ops->gl_flushed(con->hw);
+    }
+}
+
 int qemu_console_get_window_id(QemuConsole *con)
 {
     return con->window_id;
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 71c3d698b4..588e7b1bb1 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -92,6 +92,9 @@ void gd_egl_draw(VirtualConsole *vc)
         vc->gfx.scale_x = (double)ww / surface_width(vc->gfx.ds);
         vc->gfx.scale_y = (double)wh / surface_height(vc->gfx.ds);
     }
+
+    glFlush();
+    graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
 void gd_egl_update(DisplayChangeListener *dcl,
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 72bcd94918..e7ca73c7b1 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -70,6 +70,9 @@ void gd_gl_area_draw(VirtualConsole *vc)
         surface_gl_setup_viewport(vc->gfx.gls, vc->gfx.ds, ww, wh);
         surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
     }
+
+    glFlush();
+    graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
 void gd_gl_area_update(DisplayChangeListener *dcl,
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 82139ba49e..fd594d7461 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -58,6 +58,7 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
 
     surface_gl_render_texture(scon->gls, scon->surface);
     SDL_GL_SwapWindow(scon->real_window);
+    graphic_hw_gl_flushed(scon->dcl.con);
 }
 
 void sdl2_gl_update(DisplayChangeListener *dcl,
@@ -240,4 +241,5 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
     egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top);
 
     SDL_GL_SwapWindow(scon->real_window);
+    graphic_hw_gl_flushed(dcl->con);
 }
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 6a5e189a67..7247a93924 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -826,6 +826,7 @@ static void qemu_spice_gl_unblock_bh(void *opaque)
     SimpleSpiceDisplay *ssd = opaque;
 
     qemu_spice_gl_block(ssd, false);
+    graphic_hw_gl_flushed(ssd->dcl.con);
 }
 
 static void qemu_spice_gl_block_timer(void *opaque)
-- 
2.29.0



  parent reply	other threads:[~2021-02-04 11:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
2021-02-04 11:26   ` Philippe Mathieu-Daudé
2021-02-04 13:43     ` Philippe Mathieu-Daudé
2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
2021-02-05  8:09   ` Alexander Bulekov
2021-02-04 10:52 ` marcandre.lureau [this message]
2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
2021-02-16 16:34   ` Alex Bennée
2021-02-16 17:43     ` Cleber Rosa
2021-02-17  8:27       ` Marc-André Lureau
2021-02-17 12:12         ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210204105232.834642-19-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.