Skip to contentSkip to conversation

spice: add opengl/virgl/dmabuf support

PATCH In review Gerd Hoffmann 3 participants 25 messages Feb 19, 2016 – May 24, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover spice: add opengl/virgl/dmabuf support

Hi,

This patch series adds support for opengl and dma-buf passing to spice. With this in place you can use virtio-gpu in 3d (virgl) mode with spice.

In v2 I've reordered the patches a bit, cherry-picked the forgotton monitor-config patch, addressed the review comments from Marc.

Merge plan: Patches 1-6 should be (almost) ready for merge and are needed for initial support. They go probably first, so the work higher up the stack (libvirt etc) can start.

The remaining patches will hopefully follow before 2.6 release too, but they probably need some more discussion and coordination with spice-server. I expect they will go into a separate pull request.

Patch #12 will be squashed, either patch #11 or patch #9, depending on the merge ordering, so I kept it separate for now.

please review,
Gerd

Gerd Hoffmann (11):
spice: init dcl before registering qxl interface
configure: add dma-buf support detection.
egl-helpers: add functions for render nodes and dma-buf passing
spice: add opengl/virgl/dmabuf support
spice: add unblock timer
spice: tweak debug messages.
console: track gl_block state in QemuConsole spice/gl: render DisplaySurface via opengl
spice/gl: create dummy primary surface (RfC)
spice: add & use qemu_spice_gl_monitor_config
[fixup] spice: qemu_spice_gl_monitor_config + surface

Marc-André Lureau (1):
spice: reset cursor on resize

 configure                  |  20 +++-
 include/ui/console.h       |   1 +
 include/ui/egl-helpers.h   |  13 +++
 include/ui/spice-display.h |  19 ++++
 qemu-options.hx            |   4 +
 ui/console.c               |  15 ++-
 ui/egl-helpers.c           | 129 ++++++++++++++++++++++
 ui/spice-core.c            |  15 ++-
 ui/spice-display.c         | 263 +++++++++++++++++++++++++++++++++++++++++++--
 9 files changed, 463 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/12 spice: init dcl before registering qxl interface

Without this spice might callback into qemu before ssd->dcl.con is initialized, resulting in a segfault due to NULL pointer dereference.

---
 ui/spice-display.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
ui/spice-display.c +3 -3
index 8a5b325..cdbc78d 100644
@@ -775,14 +775,14 @@ static void qemu_spice_display_init_one(QemuConsole *con)
 
     qemu_spice_display_init_common(ssd);
 
+    ssd->dcl.ops = &display_listener_ops;
+    ssd->dcl.con = con;
+
     ssd->qxl.base.sif = &dpy_interface.base;
     qemu_spice_add_display_interface(&ssd->qxl, con);
     assert(ssd->worker);
-
     qemu_spice_create_host_memslot(ssd);
 
-    ssd->dcl.ops = &display_listener_ops;
-    ssd->dcl.con = con;
     register_displaychangelistener(&ssd->dcl);
 }
 
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 2/12 configure: add dma-buf support detection.

In reply to Gerd Hoffmann

Set CONFIG_OPENGL_DMABUF in case both mesa and libepoxy are new enough to have support for dma-buf import/export.

---
 configure | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
configure +19 -1
index 0aa249b..0c0472a 100755
@@ -279,6 +279,7 @@ smartcard=""
 libusb=""
 usb_redir=""
 opengl=""
+opengl_dmabuf="no"
 zlib="yes"
 lzo=""
 snappy=""
@@ -3274,7 +3275,7 @@ libs_softmmu="$libs_softmmu $fdt_libs"
 # opengl probe (for sdl2, gtk, milkymist-tmu2)
 
 if test "$opengl" != "no" ; then
-  opengl_pkgs="epoxy"
+  opengl_pkgs="epoxy libdrm gbm"
   if $pkg_config $opengl_pkgs x11; then
     opengl_cflags="$($pkg_config --cflags $opengl_pkgs) $x11_cflags"
     opengl_libs="$($pkg_config --libs $opengl_pkgs) $x11_libs"
@@ -3292,6 +3293,18 @@ if test "$opengl" != "no" ; then
   fi
 fi
 
+if test "$opengl" = "yes"; then
+  cat > $TMPC << EOF
+#include <epoxy/egl.h>
+#ifndef EGL_MESA_image_dma_buf_export
+# error mesa/epoxy lacks support for dmabufs (mesa 10.6+)
+#endif
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "" ; then
+    opengl_dmabuf=yes
+  fi
+fi
 
 ##########################################
 # archipelago probe
@@ -4752,6 +4765,7 @@ echo "smartcard support $smartcard"
 echo "libusb            $libusb"
 echo "usb net redir     $usb_redir"
 echo "OpenGL support    $opengl"
+echo "OpenGL dmabufs    $opengl_dmabuf"
 echo "libiscsi support  $libiscsi"
 echo "libnfs support    $libnfs"
 echo "build guest agent $guest_agent"
@@ -5050,6 +5064,7 @@ if test "$gtk" = "yes" ; then
   echo "CONFIG_GTK=y" >> $config_host_mak
   echo "CONFIG_GTKABI=$gtkabi" >> $config_host_mak
   echo "GTK_CFLAGS=$gtk_cflags" >> $config_host_mak
+  echo "GTK_LIBS=$gtk_libs" >> $config_host_mak
   if test "$gtk_gl" = "yes" ; then
     echo "CONFIG_GTK_GL=y" >> $config_host_mak
   fi
@@ -5158,6 +5173,9 @@ if test "$opengl" = "yes" ; then
   echo "CONFIG_OPENGL=y" >> $config_host_mak
   echo "OPENGL_CFLAGS=$opengl_cflags" >> $config_host_mak
   echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
+  if test "$opengl_dmabuf" = "yes" ; then
+    echo "CONFIG_OPENGL_DMABUF=y" >> $config_host_mak
+  fi
 fi
 
 if test "$lzo" = "yes" ; then
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v2 3/12 egl-helpers: add functions for render nodes and dma-buf passing

In reply to Gerd Hoffmann

Adds helpers to open a drm render node and create a opengl context for it. Also add a helper to export a texture as dma-buf.

---
 include/ui/egl-helpers.h |  13 +++++
 ui/egl-helpers.c         | 129 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)
include/ui/egl-helpers.h +13 -0
index 8c84398..03fcf4b 100644
@@ -3,10 +3,23 @@
 
 #include <epoxy/gl.h>
 #include <epoxy/egl.h>
+#include <gbm.h>
 
 extern EGLDisplay *qemu_egl_display;
 extern EGLConfig qemu_egl_config;
 
+#ifdef CONFIG_OPENGL_DMABUF
+
+extern int qemu_egl_rn_fd;
+extern struct gbm_device *qemu_egl_rn_gbm_dev;
+extern EGLContext qemu_egl_rn_ctx;
+
+int qemu_egl_rendernode_open(void);
+int egl_rendernode_init(void);
+int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc);
+
+#endif
+
 EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win);
 
 int qemu_egl_init_dpy(EGLNativeDisplayType dpy, bool gles, bool debug);
ui/egl-helpers.c +129 -0

141 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v2 4/12 spice: reset cursor on resize

In reply to Gerd Hoffmann

From: Marc-André Lureau <[email protected]>

Spice server will clear the cursor on resize. QXL driver reset it after resize, however, virtio and other devices do not. Teach qemu to set it back.

---
 ui/spice-display.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
ui/spice-display.c +12 -2
index cdbc78d..4e5c8a2 100644
@@ -460,6 +460,13 @@ void qemu_spice_display_switch(SimpleSpiceDisplay *ssd,
 
     memset(&ssd->dirty, 0, sizeof(ssd->dirty));
     ssd->notify++;
+
+    qemu_mutex_lock(&ssd->lock);
+    if (ssd->cursor) {
+        g_free(ssd->ptr_define);
+        ssd->ptr_define = qemu_spice_create_cursor_update(ssd, ssd->cursor, 0);
+    }
+    qemu_mutex_unlock(&ssd->lock);
 }
 
 static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
@@ -467,8 +474,6 @@ static void qemu_spice_cursor_refresh_unlocked(SimpleSpiceDisplay *ssd)
     if (ssd->cursor) {
         assert(ssd->dcl.con);
         dpy_cursor_define(ssd->dcl.con, ssd->cursor);
-        cursor_put(ssd->cursor);
-        ssd->cursor = NULL;
     }
     if (ssd->mouse_x != -1 && ssd->mouse_y != -1) {
         assert(ssd->dcl.con);
@@ -750,6 +755,11 @@ static void display_mouse_define(DisplayChangeListener *dcl,
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
 
     qemu_mutex_lock(&ssd->lock);
+    if (c) {
+        cursor_get(c);
+    }
+    cursor_put(ssd->cursor);
+    ssd->cursor = c;
     ssd->hot_x = c->hot_x;
     ssd->hot_y = c->hot_y;
     g_free(ssd->ptr_move);
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v2 5/12 spice: add opengl/virgl/dmabuf support

In reply to Gerd Hoffmann

This adds support for dma-buf passing to spice. This makes virtio-gpu with 3d acceleration work with spice.

Workflow:
* virglrenderer renders the guest command stream into a texture.
* qemu exports the texture as dma-buf and passes on that dma-buf to spice-server.
* spice-server passes the dma-buf to spice-client, using unix socket file descriptor passing.
* spice-client asks the window systems composer to render the dma-buf to the screen.

Requires cutting edge spice (server) and spice-gtk (client) builds, from git master branch.

Also requires libvirt managing your qemu instance, and using "virt-viewer --attach $guest". libvirt will connect spice-server and spice-client using unix sockets instead of tcp sockets then, which is required for file descriptor passing.

Works for the local case (spice server and client on the same machine) only. Supporting remote too is planned (by feeding the dma-bufs into gpu-assisted video encoder), but not there yet.

gl mode is turned off by default, use "-spice gl=on,$otherargs" to enable it.

---
 include/ui/spice-display.h |  15 +++++++
 qemu-options.hx            |   4 ++
 ui/spice-core.c            |  15 ++++++-
 ui/spice-display.c         | 110 +++++++++++++++++++++++++++++++++++++++++++--
 4 files changed, 140 insertions(+), 4 deletions(-)
include/ui/spice-display.h +15 -0
index b25328a..48dc8c4 100644
@@ -24,6 +24,14 @@
 #include "ui/console.h"
 #include "sysemu/sysemu.h"
 
+#if defined(CONFIG_OPENGL_DMABUF)
+# if SPICE_SERVER_VERSION >= 0x000d00 /* release 0.13.0 */
+#  define HAVE_SPICE_GL 1
+#  include "ui/egl-helpers.h"
+#  include "ui/egl-context.h"
+# endif
+#endif
+
 #define NUM_MEMSLOTS 8
 #define MEMSLOT_GENERATION_BITS 8
 #define MEMSLOT_SLOT_BITS 8
@@ -50,6 +58,7 @@ enum {
     QXL_COOKIE_TYPE_IO,
     QXL_COOKIE_TYPE_RENDER_UPDATE_AREA,
     QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
+    QXL_COOKIE_TYPE_GL_DRAW_DONE,
 };
 
 typedef struct QXLCookie {
@@ -104,6 +113,12 @@ struct SimpleSpiceDisplay {
     QEMUCursor *cursor;
     int mouse_x, mouse_y;
     QEMUBH *cursor_bh;
+
+#ifdef HAVE_SPICE_GL
+    /* opengl rendering */
+    QEMUBH *gl_unblock_bh;
+    int dmabuf_fd;
+#endif
 };
 
 struct SimpleSpiceUpdate {
qemu-options.hx +4 -0
index 2f0465e..f528405 100644
@@ -1051,6 +1051,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste]\n"
     "       [,disable-agent-file-xfer][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
+    "       [,gl=[on|off]]\n"
     "   enable spice\n"
     "   at least one of {port, tls-port} is mandatory\n",
     QEMU_ARCH_ALL)
@@ -1142,6 +1143,9 @@ Enable/disable audio stream compression (using celt 0.5.1).  Default is on.
 @item seamless-migration=[on|off]
 Enable/disable spice seamless migration. Default is off.
 
+@item gl=[on|off]
+Enable/disable OpenGL context. Default is off.
+
 @end table
 ETEXI
 
ui/spice-core.c +14 -1
index 4dbd99a..5abec17 100644
@@ -494,9 +494,14 @@ static QemuOptsList qemu_spice_opts = {
         },{
             .name = "playback-compression",
             .type = QEMU_OPT_BOOL,
-        }, {
+        },{
             .name = "seamless-migration",
             .type = QEMU_OPT_BOOL,
+#ifdef HAVE_SPICE_GL
+        },{
+            .name = "gl",
+            .type = QEMU_OPT_BOOL,
+#endif
         },
         { /* end of list */ }
     },
@@ -819,6 +824,14 @@ void qemu_spice_init(void)
 #if SPICE_SERVER_VERSION >= 0x000c02
     qemu_spice_register_ports();
 #endif
+
+#ifdef HAVE_SPICE_GL
+    if (qemu_opt_get_bool(opts, "gl", 0)) {
+        if (egl_rendernode_init() == 0) {
+            display_opengl = 1;
+        }
+    }
+#endif
 }
 
 int qemu_spice_add_interface(SpiceBaseInstance *sin)
ui/spice-display.c +107 -3

128 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#7 lore raw

PATCH v2 6/12 spice: add unblock timer

In reply to Gerd Hoffmann

Pure debug aid, print a warning in case unblocking doesn't happen within one second.

---
 include/ui/spice-display.h |  1 +
 ui/spice-display.c         | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
include/ui/spice-display.h +1 -0
index 48dc8c4..69a222b 100644
@@ -117,6 +117,7 @@ struct SimpleSpiceDisplay {
 #ifdef HAVE_SPICE_GL
     /* opengl rendering */
     QEMUBH *gl_unblock_bh;
+    QEMUTimer *gl_unblock_timer;
     int dmabuf_fd;
 #endif
 };
ui/spice-display.c +16 -0
index 904fb33..d6e31e4 100644
@@ -797,6 +797,15 @@ static const DisplayChangeListenerOps display_listener_ops = {
 
 static void qemu_spice_gl_block(SimpleSpiceDisplay *ssd, bool block)
 {
+    uint64_t timeout;
+
+    if (block) {
+        timeout = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+        timeout += 1000; /* one sec */
+        timer_mod(ssd->gl_unblock_timer, timeout);
+    } else {
+        timer_del(ssd->gl_unblock_timer);
+    }
     graphic_hw_gl_block(ssd->dcl.con, block);
 }
 
@@ -807,6 +816,11 @@ static void qemu_spice_gl_unblock_bh(void *opaque)
     qemu_spice_gl_block(ssd, false);
 }
 
+static void qemu_spice_gl_block_timer(void *opaque)
+{
+    fprintf(stderr, "WARNING: spice: no gl-draw-done within one second\n");
+}
+
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener *dcl,
                                                   QEMUGLParams *params)
 {
@@ -888,6 +902,8 @@ static void qemu_spice_display_init_one(QemuConsole *con)
         ssd->dcl.ops = &display_listener_gl_ops;
         ssd->dmabuf_fd = -1;
         ssd->gl_unblock_bh = qemu_bh_new(qemu_spice_gl_unblock_bh, ssd);
+        ssd->gl_unblock_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
+                                             qemu_spice_gl_block_timer, ssd);
     }
 #endif
     ssd->dcl.con = con;
Signature · 1 line
1.8.3.1
Reviewed-by on v2 6/12
#8 lore raw

Re: [Qemu-devel] [PATCH v2 06/12] spice: add unblock timer

Hi

Quoted 5 lines · Gerd Hoffmann

Pure debug aid, print a warning in case unblocking doesn't happen within one second.

---

Quoted 60 lines
 include/ui/spice-display.h |  1 +
 ui/spice-display.c         | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
include/ui/spice-display.h +1 -0
index 48dc8c4..69a222b 100644
@@ -117,6 +117,7 @@ struct SimpleSpiceDisplay {
 #ifdef HAVE_SPICE_GL
     /* opengl rendering */
     QEMUBH *gl_unblock_bh;
+    QEMUTimer *gl_unblock_timer;
     int dmabuf_fd;
 #endif
 };
ui/spice-display.c +16 -1
index 904fb33..d6e31e4 100644
@@ -797,6 +797,15 @@ static const DisplayChangeListenerOps display_listener_ops = {
 
 static void qemu_spice_gl_block(SimpleSpiceDisplay *ssd, bool block)
 {
+    uint64_t timeout;
+
+    if (block) {
+        timeout = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+        timeout += 1000; /* one sec */
+        timer_mod(ssd->gl_unblock_timer, timeout);
+    } else {
+        timer_del(ssd->gl_unblock_timer);
+    }
     graphic_hw_gl_block(ssd->dcl.con, block);
 }
 
@@ -807,6 +816,11 @@ static void qemu_spice_gl_unblock_bh(void *opaque)
     qemu_spice_gl_block(ssd, false);
 }
 
+static void qemu_spice_gl_block_timer(void *opaque)
+{
+    fprintf(stderr, "WARNING: spice: no gl-draw-done within one second\n");
+}
+
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener *dcl,
                                                   QEMUGLParams *params)
 {
@@ -888,6 +902,8 @@ static void qemu_spice_display_init_one(QemuConsole *con)
         ssd->dcl.ops = &display_listener_gl_ops;
         ssd->dmabuf_fd = -1;
         ssd->gl_unblock_bh = qemu_bh_new(qemu_spice_gl_unblock_bh, ssd);
+        ssd->gl_unblock_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
+                                             qemu_spice_gl_block_timer, ssd);
     }
 #endif
     ssd->dcl.con = con;
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#9 lore raw

PATCH v2 7/12 spice: tweak debug messages.

In reply to Gerd Hoffmann

Adjust message levels, make messages more verbose.

---
 ui/spice-display.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
ui/spice-display.c +7 -5
index d6e31e4..242ab5f 100644
@@ -568,7 +568,7 @@ static int interface_get_command(QXLInstance *sin, QXLCommandExt *ext)
 
 static int interface_req_cmd_notification(QXLInstance *sin)
 {
-    dprint(1, "%s/%d:\n", __func__, sin->id);
+    dprint(2, "%s/%d:\n", __func__, sin->id);
     return 1;
 }
 
@@ -621,7 +621,7 @@ static int interface_get_cursor_command(QXLInstance *sin, QXLCommandExt *ext)
 
 static int interface_req_cursor_notification(QXLInstance *sin)
 {
-    dprint(1, "%s:\n", __FUNCTION__);
+    dprint(2, "%s:\n", __func__);
     return 1;
 }
 
@@ -845,9 +845,11 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,
             fprintf(stderr, "%s: failed to get fd for texture\n", __func__);
             return;
         }
+        dprint(1, "%s: %dx%d (stride %d, fourcc 0x%x)\n", __func__,
+               w, h, stride, fourcc);
+    } else {
+        dprint(1, "%s: no texture (no framebuffer)\n", __func__);
     }
-    dprint(0, "%s: %dx%d (stride %d, fourcc 0x%x)\n", __func__,
-           w, h, stride, fourcc);
 
     assert(!tex_id || fd >= 0);
 
@@ -864,7 +866,7 @@ static void qemu_spice_gl_update(DisplayChangeListener *dcl,
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
     uint64_t cookie;
 
-    dprint(1, "%s\n", __func__);
+    dprint(2, "%s: %dx%d+%d+%d\n", __func__, w, h, x, y);
     qemu_spice_gl_block(ssd, true);
     cookie = (uintptr_t)qxl_cookie_new(QXL_COOKIE_TYPE_GL_DRAW_DONE, 0);
     spice_qxl_gl_draw_async(&ssd->qxl, x, y, w, h, cookie);
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v2 8/12 console: track gl_block state in QemuConsole

In reply to Gerd Hoffmann

Keep track of gl_block state (added in bba19b8 console: block rendering until client is done) in QemuConsole and allow to query it. This way we can avoid state inconsistencies in case different code paths make use of this.

---
 include/ui/console.h |  1 +
 ui/console.c         | 15 +++++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
include/ui/console.h +1 -0
index c8f9f7e..9672ad9 100644
@@ -382,6 +382,7 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+bool qemu_console_is_gl_blocked(QemuConsole *con);
 char *qemu_console_get_label(QemuConsole *con);
 int qemu_console_get_index(QemuConsole *con);
 uint32_t qemu_console_get_head(QemuConsole *con);
ui/console.c +11 -4
index b739ae9..215c98d 100644
@@ -123,6 +123,7 @@ struct QemuConsole {
     DisplaySurface *surface;
     int dcls;
     DisplayChangeListener *gl;
+    bool gl_block;
 
     /* Graphic console state.  */
     Object *device;
@@ -264,10 +265,10 @@ void graphic_hw_update(QemuConsole *con)
 
 void graphic_hw_gl_block(QemuConsole *con, bool block)
 {
-    if (!con) {
-        con = active_console;
-    }
-    if (con && con->hw_ops->gl_block) {
+    assert(con != NULL);
+
+    con->gl_block = block;
+    if (con->hw_ops->gl_block) {
         con->hw_ops->gl_block(con->hw, block);
     }
 }
@@ -1811,6 +1812,12 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
     return con && (con->console_type != TEXT_CONSOLE);
 }
 
+bool qemu_console_is_gl_blocked(QemuConsole *con)
+{
+    assert(con != NULL);
+    return con->gl_block;
+}
+
 char *qemu_console_get_label(QemuConsole *con)
 {
     if (con->console_type == GRAPHIC_CONSOLE) {
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 9/12 spice/gl: render DisplaySurface via opengl

In reply to Gerd Hoffmann

This switches over spice (in opengl mode) to render DisplaySurface updates into a opengl texture, using the helper functions in ui/console-gl.c. With this patch applied spice (with gl=on) will stop using qxl rendering ops, it will use dma-buf passing all the time, i.e. for bios/bootloader (before virtio-gpu driver is loaded) too.

This should improve performance even using spice (with gl=on) with non-accelerated stdvga because we stop squeezing all display updates through a unix/tcp socket and basically using a shared memory transport instead.

---
 include/ui/spice-display.h |  2 ++
 ui/spice-display.c         | 77 +++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 72 insertions(+), 7 deletions(-)
include/ui/spice-display.h +2 -0
index 69a222b..dd9cf6f 100644
@@ -119,6 +119,8 @@ struct SimpleSpiceDisplay {
     QEMUBH *gl_unblock_bh;
     QEMUTimer *gl_unblock_timer;
     int dmabuf_fd;
+    ConsoleGLState *gls;
+    int gl_updates;
 #endif
 };
 
ui/spice-display.c +70 -7

95 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v2 10/12 spice/gl: create dummy primary surface (RfC)

In reply to Gerd Hoffmann

Current spice client expects we create a primary surface, even if we do display updates using dma-bufs exclusively.

So just do that to get things going.

Not fully clear whenever that is intentional or a bug on the spice side, so I keep this as separate patch for now.

I think this should either be squashed into the previous patch, or dropped after fixing things on the spice side.

---
 ui/spice-display.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
ui/spice-display.c +14 -0
index 15d7906..96beb02 100644
@@ -856,13 +856,27 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
     EGLint stride, fourcc;
+    bool resize = true;
     int fd;
 
+    if (ssd->ds && new_surface &&
+        surface_width(ssd->ds)  == surface_width(new_surface)  &&
+        surface_height(ssd->ds) == surface_height(new_surface) &&
+        surface_format(ssd->ds) == surface_format(new_surface)) {
+        resize = false;
+    }
+
     if (ssd->ds) {
         surface_gl_destroy_texture(ssd->gls, ssd->ds);
+        if (resize) {
+            qemu_spice_destroy_host_primary(ssd);
+        }
     }
     ssd->ds = new_surface;
     if (ssd->ds) {
+        if (resize) {
+            qemu_spice_create_host_primary(ssd);
+        }
         surface_gl_create_texture(ssd->gls, ssd->ds);
         fd = egl_get_fd_for_texture(ssd->ds->texture,
                                     &stride, &fourcc);
Signature · 1 line
1.8.3.1
#13 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Quoted 10 lines · Gerd Hoffmann

Current spice client expects we create a primary surface, even if we do display updates using dma-bufs exclusively.

So just do that to get things going.

Not fully clear whenever that is intentional or a bug on the spice side, so I keep this as separate patch for now.

I think this should either be squashed into the previous patch, or dropped after fixing things on the spice side.

Ping Marc? Any comment on this?

thanks,
Gerd

#14 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Hi

Quoted 1 line · Gerd Hoffmann

Ping Marc? Any comment on this?

Could you send a rebased series, for the patches that lead to the issue? I assume "render DisplaySurface via opengl" patch?

Signature · 1 line
Marc-André Lureau
#15 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Quoted 8 lines · Marc-André Lureau

Hi

Quoted 1 line · Gerd Hoffmann

Ping Marc? Any comment on this?

Could you send a rebased series, for the patches that lead to the issue?

Update pushed to https://www.kraxel.org/cgit/qemu/log/?h=work/virgl
with some cherry-picks to fix nettle build issue and to sidestep conflict with in-flight pull request.

That work better for testing. I'll resent the patch series once the temporary issues with master are settled. There hasn't changed much in the code though, other than rebasing and minor tweaks to adapt to the include changes.

Quoted 1 line

I assume "render DisplaySurface via opengl" patch?

Yes, that one.

cheers,
Gerd

#16 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Hi

Quoted 14 lines · Gerd Hoffmann
Quoted 8 lines · Marc-André Lureau

Hi

Quoted 1 line · Gerd Hoffmann

Ping Marc? Any comment on this?

Could you send a rebased series, for the patches that lead to the issue?

Update pushed to https://www.kraxel.org/cgit/qemu/log/?h=work/virgl
with some cherry-picks to fix nettle build issue and to sidestep conflict with in-flight pull request.

Quoted 8 lines

That work better for testing. I'll resent the patch series once the temporary issues with master are settled. There hasn't changed much in the code though, other than rebasing and minor tweaks to adapt to the include changes.

Quoted 1 line

I assume "render DisplaySurface via opengl" patch?

Yes, that one.

I have done some more testing and sent a series for spice-gtk fixing display with gl scanout-only case. And a minor patch to spice server to solve a cursor initialization when there is no canvas. Your series works ok with that, only when doing a reboot, virtio_gpu_virgl_reset() calls spice_qxl_gl_scanout( fd = -1), and later spice_gl_refresh() calls spice_qxl_gl_draw_async() and reaches the following error:

(process:21117): Spice-CRITICAL **:
red-qxl.c:900:spice_qxl_gl_draw_async: condition
`qxl_state->scanout.drm_dma_buf_fd != -1' failed

Signature · 1 line
Marc-André Lureau
#17 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Hi,

Resuming to work on this after 2.6 freeze break ...

Quoted 10 lines

I have done some more testing and sent a series for spice-gtk fixing display with gl scanout-only case. And a minor patch to spice server to solve a cursor initialization when there is no canvas. Your series works ok with that, only when doing a reboot, virtio_gpu_virgl_reset() calls spice_qxl_gl_scanout( fd = -1), and later spice_gl_refresh() calls spice_qxl_gl_draw_async() and reaches the following error:

(process:21117): Spice-CRITICAL **:
red-qxl.c:900:spice_qxl_gl_draw_async: condition
`qxl_state->scanout.drm_dma_buf_fd != -1' failed

Hmm, that is sort-of intentional. It's valid for scanouts to not be backed by a resource, and in that case qemu_spice_gl_scanout() calls spice_qxl_gl_scanout() with fd=-1.

So, what do you think we should do here? Fix spice to handle that case? Should qemu do something else instead? Such as not calling spice_qxl_gl_scanout() to keep the previous dma-buf alive?

cheers,
Gerd

#18 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Hi

Quoted 11 lines · Gerd Hoffmann

Hi,

Resuming to work on this after 2.6 freeze break ...

Quoted 7 lines

I have done some more testing and sent a series for spice-gtk fixing display with gl scanout-only case. And a minor patch to spice server to solve a cursor initialization when there is no canvas. Your series works ok with that, only when doing a reboot, virtio_gpu_virgl_reset() calls spice_qxl_gl_scanout( fd = -1), and later spice_gl_refresh() calls spice_qxl_gl_draw_async() and reaches the following error:

Quoted 7 lines
Quoted 3 lines

(process:21117): Spice-CRITICAL **:
red-qxl.c:900:spice_qxl_gl_draw_async: condition
`qxl_state->scanout.drm_dma_buf_fd != -1' failed

Hmm, that is sort-of intentional. It's valid for scanouts to not be backed by a resource, and in that case qemu_spice_gl_scanout() calls spice_qxl_gl_scanout() with fd=-1.

Ok, then I suppose the display should be marked as non-ready, and the client should reflect that (blank display or "not ready" message)

Quoted 4 lines

So, what do you think we should do here? Fix spice to handle that case? Should qemu do something else instead? Such as not calling spice_qxl_gl_scanout() to keep the previous dma-buf alive?

I can't really make sense of a call to spice_qxl_gl_draw_async() if there is no scanout backing. So I can imagine the fix is on qemu side.

Do you have an up to date branch for testing?

thanks

Signature · 1 line
Marc-André Lureau
#19 lore raw

Re: [Qemu-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Quoted 10 lines · Marc-André Lureau

Hi

Quoted 7 lines · Gerd Hoffmann

Hi,

Resuming to work on this after 2.6 freeze break ...

Quoted 3 lines

I have done some more testing and sent a series for spice-gtk fixing display with gl scanout-only case. And a minor patch to spice server to solve a cursor initialization when there is no canvas.

What is the upstream status of this? Built a bunch of fresh packages today, including new spice-server and spice-gtk from master branch. And a bunch spice-gtk dependencies, due to soname change. Still not working without the dummy primary surface.

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

(process:21117): Spice-CRITICAL **:
red-qxl.c:900:spice_qxl_gl_draw_async: condition
`qxl_state->scanout.drm_dma_buf_fd != -1' failed

I can't really make sense of a call to spice_qxl_gl_draw_async() if there is no scanout backing. So I can imagine the fix is on qemu side.

Indeed. That one should be fixed now.

Quoted 1 line

Do you have an up to date branch for testing?

Pushed fresh branch to the usual work/virgl location.

cheers,
Gerd

#20 lore raw

Re: [Qemu-devel] [Spice-devel] [PATCH v2 10/12] spice/gl: create dummy primary surface (RfC)

Hi

----- Original Message -----

Quoted 8 lines · Marc-André Lureau
Quoted 7 lines

Hi

Quoted 4 lines · Gerd Hoffmann

Hi,

Resuming to work on this after 2.6 freeze break ...

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I have done some more testing and sent a series for spice-gtk fixing display with gl scanout-only case. And a minor patch to spice server to solve a cursor initialization when there is no canvas.

What is the upstream status of this? Built a bunch of fresh packages today, including new spice-server and spice-gtk from master branch. And a bunch spice-gtk dependencies, due to soname change. Still not working without the dummy primary surface.

spicy from master works for me. However I found an issue with virt-viewer, due to delayed widget realize in this gl-only case, see: https://lists.freedesktop.org/archives/spice-devel/2016-May/029446.html

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

(process:21117): Spice-CRITICAL **:
red-qxl.c:900:spice_qxl_gl_draw_async: condition
`qxl_state->scanout.drm_dma_buf_fd != -1' failed

I can't really make sense of a call to spice_qxl_gl_draw_async() if there is no scanout backing. So I can imagine the fix is on qemu side.

Indeed. That one should be fixed now.

Thanks

Quoted 4 lines
Quoted 2 lines

Do you have an up to date branch for testing?

Pushed fresh branch to the usual work/virgl location.

I found a cursor issue, due to spice worker being idle, and this solves it: What do you think?

commit bae34dde7b229cc87347639ac34d835b80725e1f

Author: Marc-André Lureau <[email protected]>
Date:   Tue May 24 20:34:05 2016 +0200

spice: wakeup worker to pick up mouse changes

ui/spice-display.c +2 -0
index 5ed7630..a04432c 100644
@@ -766,6 +766,7 @@ static void display_mouse_set(DisplayChangeListener *dcl,
     g_free(ssd->ptr_move);
     ssd->ptr_move = qemu_spice_create_cursor_update(ssd, NULL, on);
     qemu_mutex_unlock(&ssd->lock);
+    qemu_spice_wakeup(ssd);
 }
 
 static void display_mouse_define(DisplayChangeListener *dcl,
@@ -784,6 +785,7 @@ static void display_mouse_define(DisplayChangeListener *dcl,
     g_free(ssd->ptr_define);
     ssd->ptr_define = qemu_spice_create_cursor_update(ssd, c, 0);
     qemu_mutex_unlock(&ssd->lock);
+    qemu_spice_wakeup(ssd);
 }
 
 static const DisplayChangeListenerOps display_listener_ops = {
#21 lore raw

PATCH v2 11/12 spice: add & use qemu_spice_gl_monitor_config

In reply to Gerd Hoffmann
---
 include/ui/spice-display.h |  1 +
 ui/spice-display.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
include/ui/spice-display.h +1 -0
index dd9cf6f..f9388c2 100644
@@ -71,6 +71,7 @@ typedef struct QXLCookie {
             QXLRect area;
             int redraw;
         } render;
+        void *data;
     } u;
 } QXLCookie;
 
ui/spice-display.c +30 -0
index 96beb02..34e6d51 100644
@@ -660,6 +660,11 @@ static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
         qemu_bh_schedule(ssd->gl_unblock_bh);
         break;
     }
+    case QXL_COOKIE_TYPE_IO:
+        if (cookie->io == QXL_IO_MONITORS_CONFIG_ASYNC) {
+            g_free(cookie->u.data);
+        }
+        break;
 #endif
     default:
         /* should never be called, used in qxl native mode only */
@@ -795,6 +800,29 @@ static const DisplayChangeListenerOps display_listener_ops = {
 
 #ifdef HAVE_SPICE_GL
 
+static void qemu_spice_gl_monitor_config(SimpleSpiceDisplay *ssd,
+                                         int x, int y, int w, int h)
+{
+    QXLMonitorsConfig *config;
+    QXLCookie *cookie;
+
+    config = g_malloc0(sizeof(QXLMonitorsConfig) + sizeof(QXLHead));
+    config->count = 1;
+    config->max_allowed = 1;
+    config->heads[0].x = x;
+    config->heads[0].y = y;
+    config->heads[0].width = w;
+    config->heads[0].height = h;
+    cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                            QXL_IO_MONITORS_CONFIG_ASYNC);
+    cookie->u.data = config;
+
+    spice_qxl_monitors_config_async(&ssd->qxl,
+                                    (uintptr_t)config,
+                                    MEMSLOT_GROUP_HOST,
+                                    (uintptr_t)cookie);
+}
+
 static void qemu_spice_gl_block(SimpleSpiceDisplay *ssd, bool block)
 {
     uint64_t timeout;
@@ -934,6 +962,8 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,
                          surface_width(ssd->ds),
                          surface_height(ssd->ds),
                          stride, fourcc, y_0_top);
+
+    qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }
 
 static void qemu_spice_gl_update(DisplayChangeListener *dcl,
Signature · 1 line
1.8.3.1
Reviewed-by on v2 11/12
#22 lore raw

Re: [Qemu-devel] [PATCH v2 11/12] spice: add & use qemu_spice_gl_monitor_config

Hi

Quoted 6 lines · Gerd Hoffmann
---
 include/ui/spice-display.h |  1 +
 ui/spice-display.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

Could eventually be squashed with "add opengl/virgl/dmabuf support" patch

Quoted 70 lines
include/ui/spice-display.h +1 -0
index dd9cf6f..f9388c2 100644
@@ -71,6 +71,7 @@ typedef struct QXLCookie {
             QXLRect area;
             int redraw;
         } render;
+        void *data;
     } u;
 } QXLCookie;
 
ui/spice-display.c +30 -1
index 96beb02..34e6d51 100644
@@ -660,6 +660,11 @@ static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
         qemu_bh_schedule(ssd->gl_unblock_bh);
         break;
     }
+    case QXL_COOKIE_TYPE_IO:
+        if (cookie->io == QXL_IO_MONITORS_CONFIG_ASYNC) {
+            g_free(cookie->u.data);
+        }
+        break;
 #endif
     default:
         /* should never be called, used in qxl native mode only */
@@ -795,6 +800,29 @@ static const DisplayChangeListenerOps display_listener_ops = {
 
 #ifdef HAVE_SPICE_GL
 
+static void qemu_spice_gl_monitor_config(SimpleSpiceDisplay *ssd,
+                                         int x, int y, int w, int h)
+{
+    QXLMonitorsConfig *config;
+    QXLCookie *cookie;
+
+    config = g_malloc0(sizeof(QXLMonitorsConfig) + sizeof(QXLHead));
+    config->count = 1;
+    config->max_allowed = 1;
+    config->heads[0].x = x;
+    config->heads[0].y = y;
+    config->heads[0].width = w;
+    config->heads[0].height = h;
+    cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                            QXL_IO_MONITORS_CONFIG_ASYNC);
+    cookie->u.data = config;
+
+    spice_qxl_monitors_config_async(&ssd->qxl,
+                                    (uintptr_t)config,
+                                    MEMSLOT_GROUP_HOST,
+                                    (uintptr_t)cookie);
+}
+
 static void qemu_spice_gl_block(SimpleSpiceDisplay *ssd, bool block)
 {
     uint64_t timeout;
@@ -934,6 +962,8 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,
                          surface_width(ssd->ds),
                          surface_height(ssd->ds),
                          stride, fourcc, y_0_top);
+
+    qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }
 
 static void qemu_spice_gl_update(DisplayChangeListener *dcl,
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#23 lore raw

Re: [Qemu-devel] [PATCH v2 11/12] spice: add & use qemu_spice_gl_monitor_config

Hi Gerd

Quoted 10 lines · Marc-André Lureau

Hi

Quoted 6 lines · Gerd Hoffmann
---
 include/ui/spice-display.h |  1 +
 ui/spice-display.c         | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
Quoted 3 lines

Could eventually be squashed with "add opengl/virgl/dmabuf support" patch

Sigh, too bad this wasn't actually picked or squashed with the series. This is required for the spice client to know the area of the GL surface to draw. (currently it also receives monitor config from 2d/QXL, which it associates to GL scanout when enabled, which results in some clipping visible in virt-manager). Imho it would be worth to include in 2.6.

Quoted 76 lines
Quoted 69 lines
include/ui/spice-display.h +1 -0
index dd9cf6f..f9388c2 100644
@@ -71,6 +71,7 @@ typedef struct QXLCookie {
             QXLRect area;
             int redraw;
         } render;
+        void *data;
     } u;
 } QXLCookie;
 
ui/spice-display.c +30 -1
index 96beb02..34e6d51 100644
@@ -660,6 +660,11 @@ static void interface_async_complete(QXLInstance *sin, uint64_t cookie_token)
         qemu_bh_schedule(ssd->gl_unblock_bh);
         break;
     }
+    case QXL_COOKIE_TYPE_IO:
+        if (cookie->io == QXL_IO_MONITORS_CONFIG_ASYNC) {
+            g_free(cookie->u.data);
+        }
+        break;
 #endif
     default:
         /* should never be called, used in qxl native mode only */
@@ -795,6 +800,29 @@ static const DisplayChangeListenerOps display_listener_ops = {
 
 #ifdef HAVE_SPICE_GL
 
+static void qemu_spice_gl_monitor_config(SimpleSpiceDisplay *ssd,
+                                         int x, int y, int w, int h)
+{
+    QXLMonitorsConfig *config;
+    QXLCookie *cookie;
+
+    config = g_malloc0(sizeof(QXLMonitorsConfig) + sizeof(QXLHead));
+    config->count = 1;
+    config->max_allowed = 1;
+    config->heads[0].x = x;
+    config->heads[0].y = y;
+    config->heads[0].width = w;
+    config->heads[0].height = h;
+    cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
+                            QXL_IO_MONITORS_CONFIG_ASYNC);
+    cookie->u.data = config;
+
+    spice_qxl_monitors_config_async(&ssd->qxl,
+                                    (uintptr_t)config,
+                                    MEMSLOT_GROUP_HOST,
+                                    (uintptr_t)cookie);
+}
+
 static void qemu_spice_gl_block(SimpleSpiceDisplay *ssd, bool block)
 {
     uint64_t timeout;
@@ -934,6 +962,8 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,
                          surface_width(ssd->ds),
                          surface_height(ssd->ds),
                          stride, fourcc, y_0_top);
+
+    qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }
 
 static void qemu_spice_gl_update(DisplayChangeListener *dcl,
--
Quoted 2 lines

1.8.3.1

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau
#24 lore raw

PATCH v2 12/12 spice: qemu_spice_gl_monitor_config + surface

In reply to Gerd Hoffmann
---
 ui/spice-display.c | 4 ++++
 1 file changed, 4 insertions(+)
ui/spice-display.c +4 -0
index 34e6d51..806851f 100644
@@ -922,6 +922,10 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
                              surface_width(ssd->ds),
                              surface_height(ssd->ds),
                              stride, fourcc, false);
+
+        qemu_spice_gl_monitor_config(ssd, 0, 0,
+                                     surface_width(ssd->ds),
+                                     surface_height(ssd->ds));
     }
 }
 
Signature · 1 line
1.8.3.1