Skip to contentSkip to conversation

ui/spice: Enable gl=on option for non-local or remote clients

PATCH Superseded Vivek Kasireddy 6 participants 18 messages May 29, 2025 – Jun 11, 2025

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover ui/spice: Enable gl=on option for non-local or remote clients

To address the limitation that this option is incompatible with remote clients, this patch series adds an option to select a preferred codec and also enable gl=on option for clients that are connected via the network. In other words, with this option enabled (and the below linked Spice series merged), it would be possible to have Qemu share a dmabuf fd with Spice, which would then forward it to a hardware or software based encoder and eventually send the data associated with the fd to a client that could be located on a different machine.

Essentially, this patch series provides a hardware accelerated, opensource VDI option for users using Qemu and Spice by leveraging the iGPU/dGPU on the host machine to encode the Guest FB via the Gstreamer framework.

v4 -> v5 (suggestions from Marc-André):
- Fix the errors (mostly 80 chars limit violations) identified by scripts/checkpatch.pl
- Rename the globals to have a spice_ prefix for consistency
- Rename MAX_REFRESH_RATE to DEFAULT_MAX_REFRESH_RATE
- Added comments to explain how/when the gl_draw request is submitted to spice server in the remote clients case
- Fix the mem_obj leak that would occur when the associated texture is destroyed or when an error is encountered while creating a texture from an fd (Dmitry and Michael)
- Merged Michael's patch to fix the mem_obj leak into this series and added his Co-developed-by tag to the relevant patches

v3 -> v4 (suggestions from Marc-André):
- Add a new parameter to make max_refresh_rate configurable
- Have surface_gl_create_texture_from_fd() return bool after checking for errors
- Remove the check for PIXMAN_r5g6b5() in spice_gl_replace_fd_texture()
- Report errors in spice_gl_replace_fd_texture() when someting fails
- Use glGetError() correctly by adding an additional (dummy) call before checking for actual errors (Dmitry)
- Add a new patch to check fd values in egl_dmabuf_export_texture()
- Rebase on Qemu master

v2 -> v3:
- Check for errors after invoking glImportMemoryFdEXT() using glGetError() and report the error to user (Dmitry)

v1 -> v2:
- Replace the option name preferred-codec with video-codecs (Marc-André)
- Add a warning when an fd cannot be created from texture (Marc-André)
- Add a new patch to blit the scanout texture into a linear one to make it work with virgl
- Rebased and tested against the latest Spice master

Tested with the following Qemu parameters:
-device virtio-vga,max_outputs=1,xres=1920,yres=1080,blob=true -spice port=3001,gl=on,disable-ticketing=on,video-codecs=gstreamer:h264

and remote-viewer --spice-debug spice://x.x.x.x:3001 on the client side.

Associated Spice server MR (merged):
https://gitlab.freedesktop.org/spice/spice/-/merge_requests/229

---
Cc: Gerd Hoffmann <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Dmitry Osipenko <[email protected]>
Cc: Frediano Ziglio <[email protected]>
Cc: Michael Scherle <[email protected]>
Cc: Dongwon Kim <[email protected]>
Cc: Alex Bennée <[email protected]>

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Add an option for users to provide a preferred codec ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
enabled
ui/spice: Blit the scanout texture if its memory layout is not linear

 include/ui/console.h       |   3 +
 include/ui/spice-display.h |   5 +
 include/ui/surface.h       |   1 +
 qemu-options.hx            |  10 ++
 ui/console-gl.c            |  54 +++++++++
 ui/egl-helpers.c           |   6 +
 ui/spice-core.c            |  28 +++++
 ui/spice-display.c         | 226 ++++++++++++++++++++++++++++++++++---
 8 files changed, 317 insertions(+), 16 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH v5 1/7 ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture()

While trying to export and obtain fds associated with a texture, it is possible that the fds returned after eglExportDMABUFImageMESA() call have error values. Therefore, we need to evaluate the value of all fds and return false if any of them are negative.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 ui/egl-helpers.c | 6 ++++++
 1 file changed, 6 insertions(+)
ui/egl-helpers.c +6 -0
index 5503a795e4..e3f2872cc1 100644
@@ -295,6 +295,7 @@ bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, EGLint *offset,
 {
     EGLImageKHR image;
     EGLuint64KHR modifiers[DMABUF_MAX_PLANES];
+    int i;
 
     image = eglCreateImageKHR(qemu_egl_display, eglGetCurrentContext(),
                               EGL_GL_TEXTURE_2D_KHR,
@@ -314,6 +315,11 @@ bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, EGLint *offset,
         *modifier = modifiers[0];
     }
 
+    for (i = 0; i < *num_planes; i++) {
+        if (fd[i] < 0) {
+            return false;
+        }
+    }
     return true;
 }
 
Signature · 1 line
2.49.0
#2 lore raw

PATCH v5 2/7 ui/spice: Add an option for users to provide a preferred codec

In reply to Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
qemu-options.hx +5 -0
index 7eb8e02b4b..fcddb583c9 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.
+
     ``gl=[on|off]``
         Enable/disable OpenGL context. Default is off.
 
ui/spice-core.c +12 -0
index 0326c63bec..907b0e9a81 100644
@@ -488,6 +488,9 @@ static QemuOptsList qemu_spice_opts = {
         },{
             .name = "streaming-video",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "video-codecs",
+            .type = QEMU_OPT_STRING,
         },{
             .name = "agent-mouse",
             .type = QEMU_OPT_BOOL,
@@ -662,6 +665,7 @@ static void qemu_spice_init(void)
     char *x509_key_file = NULL,
         *x509_cert_file = NULL,
         *x509_cacert_file = NULL;
+    const char *video_codecs = NULL;
     int port, tls_port, addr_flags;
     spice_image_compression_t compression;
     spice_wan_compression_t wan_compr;
@@ -801,6 +805,14 @@ static void qemu_spice_init(void)
         spice_server_set_streaming_video(spice_server, SPICE_STREAM_VIDEO_OFF);
     }
 
+    video_codecs = qemu_opt_get(opts, "video-codecs");
+    if (video_codecs) {
+        if (spice_server_set_video_codecs(spice_server, video_codecs)) {
+            error_report("invalid video codecs");
+            exit(1);
+        }
+    }
+
     spice_server_set_agent_mouse
         (spice_server, qemu_opt_get_bool(opts, "agent-mouse", 1));
     spice_server_set_playback_compression
Signature · 1 line
2.49.0
#3 lore raw

Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 29 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
qemu-options.hx +1 -0
index 7eb8e02b4b..fcddb583c9 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",

qemu-options.hx SRST · line 2375

Quoted 6 lines
qemu-options.hx +3 -0
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Why can't this be done as separate parameters

video-encoder=<blah>
video-codec=<blah>

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

RE: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Hi Daniel,

Quoted 37 lines

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 21 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
qemu-options.hx +0 -0
index 7eb8e02b4b..fcddb583c9 100644

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2283

Quoted 3 lines
qemu-options.hx +0 -0
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-

migration=[on|off]]\n"

Quoted 8 lines
qemu-options.hx +1 -0
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
Quoted 8 lines

qemu-options.hx SRST · line 2375

Quoted 3 lines
qemu-options.hx +3 -0
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Why can't this be done as separate parameters

The Spice server API used by Qemu (spice_server_set_video_codecs) to set the preferred codec requires the video-codecs string to be in encoder:codec format. AFAIK, there is no other option or API to set the encoder and codec values separately.

Thanks,
Vivek

Quoted 13 lines

video-encoder=<blah>
video-codec=<blah>

With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange
:|

|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange
:|
#5 lore raw

Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 46 lines · Vivek

Hi Daniel,

Quoted 44 lines

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 21 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
qemu-options.hx +0 -0
index 7eb8e02b4b..fcddb583c9 100644

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2283

Quoted 3 lines
qemu-options.hx +0 -0
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-

migration=[on|off]]\n"

qemu-options.hx SRST · line 2375

Quoted 11 lines
qemu-options.hx +4 -0
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Quoted 5 lines
Quoted 1 line

Why can't this be done as separate parameters

The Spice server API used by Qemu (spice_server_set_video_codecs) to set the preferred codec requires the video-codecs string to be in encoder:codec format. AFAIK, there is no other option or API to set the encoder and codec values separately.

QEMU can accept the separate parameters and format them into the string format that the spice API requires so our public API is not impacted by this spice design choice.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw

Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Hi

Quoted 52 lines · Daniel P. Berrangé
Quoted 3 lines · Vivek

Hi Daniel,

Quoted 1 line

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to

provide a

Quoted 19 lines
Quoted 19 lines

preferred codec

Quoted 16 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
Quoted 6 lines
Quoted 6 lines

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2281

Quoted 6 lines
qemu-options.hx +0 -0
index 7eb8e02b4b..fcddb583c9 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "

[,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"

Quoted 1 line
Quoted 1 line

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2282

Quoted 1 line
qemu-options.hx +0 -0
     "

[,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"

Quoted 6 lines
Quoted 6 lines

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2283

Quoted 1 line
qemu-options.hx +0 -0
     "       [,playback-compression=[on|off]][,seamless-

migration=[on|off]]\n"

Quoted 4 lines
qemu-options.hx +1 -0
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is

mandatory\n",

Quoted 12 lines
Quoted 12 lines

qemu-options.hx SRST · line 2375

Quoted 7 lines
qemu-options.hx +3 -0
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Why can't this be done as separate parameters

Quoted 10 lines
Quoted 4 lines

The Spice server API used by Qemu (spice_server_set_video_codecs) to set the preferred codec requires the video-codecs string to be in encoder:codec format. AFAIK, there is no other option or API to set the encoder and codec values separately.

QEMU can accept the separate parameters and format them into the string format that the spice API requires so our public API is not impacted by this spice design choice.

Apparently you cannot mix and match freely, it has a rather fixed set of actually working values.

See here and related code:
https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/reds.cpp?ref_type=heads#L3468

Tbh, I don't think the encoder matters much, and I don't know why it was decided to associate it with video codec names.

Maybe the spice API should provide a simpler form: accept only codec names.

In the meantime, qemu should perhaps add the "working" encoder prefixes (spice: for mjpeg, gstreamer: for others) itself and not expose any extra option to the user?

#7 lore raw

Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 67 lines · Marc-André Lureau

Hi

Quoted 52 lines · Daniel P. Berrangé
Quoted 3 lines · Vivek

Hi Daniel,

Quoted 1 line

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to

provide a

Quoted 19 lines
Quoted 19 lines

preferred codec

Quoted 16 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
Quoted 6 lines
Quoted 6 lines

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2281

Quoted 6 lines
qemu-options.hx +0 -0
index 7eb8e02b4b..fcddb583c9 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "

[,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"

Quoted 1 line
Quoted 1 line

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2282

Quoted 1 line
qemu-options.hx +0 -0
     "

[,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"

Quoted 6 lines
Quoted 6 lines

qemu-options.hx DEF("spice", HAS_ARG, QEMU_OPTION_spice, · line 2283

Quoted 1 line
qemu-options.hx +0 -0
     "       [,playback-compression=[on|off]][,seamless-

migration=[on|off]]\n"

Quoted 4 lines
qemu-options.hx +1 -0
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is

mandatory\n",

Quoted 12 lines
Quoted 12 lines

qemu-options.hx SRST · line 2375

Quoted 7 lines
qemu-options.hx +3 -0
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Why can't this be done as separate parameters

Quoted 10 lines
Quoted 4 lines

The Spice server API used by Qemu (spice_server_set_video_codecs) to set the preferred codec requires the video-codecs string to be in encoder:codec format. AFAIK, there is no other option or API to set the encoder and codec values separately.

QEMU can accept the separate parameters and format them into the string format that the spice API requires so our public API is not impacted by this spice design choice.

Quoted 5 lines

Apparently you cannot mix and match freely, it has a rather fixed set of actually working values.

See here and related code:
https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/reds.cpp?ref_type=heads#L3468

That's just showing the built-in defaults - the parsing code is not enforcing any constraints. The impl though cleary only allows 'mjpeg' with 'spice':

https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/mjpeg-encoder.c#L1371

Quoted 2 lines

Tbh, I don't think the encoder matters much, and I don't know why it was decided to associate it with video codec names.

AFAICT the only way in which the encoder matters is to distinguish the built-in "mjpeg" impl from the gstreamer "mjpeg" coder.

Quoted 5 lines

Maybe the spice API should provide a simpler form: accept only codec names.

In the meantime, qemu should perhaps add the "working" encoder prefixes (spice: for mjpeg, gstreamer: for others) itself and not expose any extra option to the user?

Ths question is whether we need to be able to request the gstreamer 'mjpeg' impl ?

If we do, and we also assume that 'spice' will never gain any more codec impls as built-ins, we could do

builtin, mjpeg, vp8, vp9, h264

where 'builtin' is the standard mjpeg encoder ?

Alternatively we could just go with

mjpeg, vp8, vp9, h264

and in the unlikely event we need to be able to skip the built-in mjpeg, we could add a boolean 'prefer-gstreamer=on|off'

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#8 lore raw

Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 30 lines · Daniel P. Berrangé
Quoted 10 lines · Marc-André Lureau

Hi

On Fri, Jun 6, 2025 at 11:16 AM Daniel P. Berrangé <[email protected]> wrote:

Apparently you cannot mix and match freely, it has a rather fixed set of actually working values.

See here and related code:
https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/reds.cpp?ref_type=heads#L3468

That's just showing the built-in defaults - the parsing code is not enforcing any constraints. The impl though cleary only allows 'mjpeg' with 'spice':

https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/mjpeg-encoder.c#L1371

Quoted 2 lines

Tbh, I don't think the encoder matters much, and I don't know why it was decided to associate it with video codec names.

AFAICT the only way in which the encoder matters is to distinguish the built-in "mjpeg" impl from the gstreamer "mjpeg" coder.

Quoted 5 lines

Maybe the spice API should provide a simpler form: accept only codec names.

In the meantime, qemu should perhaps add the "working" encoder prefixes (spice: for mjpeg, gstreamer: for others) itself and not expose any extra option to the user?

Quoted 7 lines

Ths question is whether we need to be able to request the gstreamer 'mjpeg' impl ?

If we do, and we also assume that 'spice' will never gain any more codec impls as built-ins, we could do

   builtin, mjpeg, vp8, vp9, h264

With 'spice' you mean only that the builtin will not get any more codecs right? because I want to do an MR for spice gstreamer to add more codecs, like av1.

Also It might be useful to set more parameters in future, like chroma sub-sampling or which GStreamer plugin is wanted like: msdk, va, vaapi....

Another point is that it can actually be a list of codecs like:
gstreamer:vp8;gstreamer:h264;spice:mjpeg

Which is maybe not clear from the current documentation, which might rather be:
[,video-codecs=<encoder>:<codec>[;...]]

This is useful the specify the allowed codecs and also set the priority.

Quoted 5 lines

where 'builtin' is the standard mjpeg encoder ?

Alternatively we could just go with

Quoted 7 lines
   mjpeg, vp8, vp9, h264

and in the unlikely event we need to be able to skip the built-in mjpeg, we could add a boolean 'prefer-gstreamer=on|off'

With regards,
Daniel

Greetings,
Michael

#9 lore raw

RE: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

In reply to Daniel P. Berrangé

Hi Daniel,

Quoted 108 lines

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to provide a preferred codec

Quoted 29 lines · Marc-André Lureau

Hi

Quoted 24 lines · Daniel P. Berrangé
Quoted 3 lines · Vivek

Hi Daniel,

Quoted 1 line

Subject: Re: [PATCH v5 2/7] ui/spice: Add an option for users to

provide a

Quoted 19 lines
Quoted 19 lines

preferred codec

Quoted 16 lines · Vivek Kasireddy

Giving users an option to choose a particular codec will enable them to make an appropriate decision based on their hardware and use-case.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 qemu-options.hx |  5 +++++
 ui/spice-core.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

qemu-options.hx DEF("spice", HAS_ARG,

Quoted 5 lines
qemu-options.hx +0 -0
index 7eb8e02b4b..fcddb583c9 100644
@@ -2281,6 +2281,7 @@ DEF("spice", HAS_ARG,

QEMU_OPTION_spice,

Quoted 22 lines
Quoted 22 lines
Quoted 1 line
Quoted 1 line

qemu-options.hx DEF("spice", HAS_ARG, · line 2281

Quoted 1 line
qemu-options.hx +0 -0
     "

[,streaming-video=[off|all|filter]][,disable-copy-paste=on|off]\n"

Quoted 1 line
Quoted 1 line

qemu-options.hx DEF("spice", HAS_ARG, · line 2282

Quoted 1 line
qemu-options.hx +0 -0
     "

[,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"

Quoted 6 lines
Quoted 6 lines

qemu-options.hx DEF("spice", HAS_ARG, · line 2283

Quoted 1 line
qemu-options.hx +0 -0
     "       [,playback-compression=[on|off]][,seamless-

migration=[on|off]]\n"

Quoted 4 lines
qemu-options.hx +1 -0
+    "       [,video-codecs=<encoder>:<codec>\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is

mandatory\n",

Quoted 11 lines
Quoted 11 lines

qemu-options.hx SRST · line 2375

Quoted 7 lines
qemu-options.hx +3 -0
@@ -2369,6 +2370,10 @@ SRST
     ``seamless-migration=[on|off]``
         Enable/disable spice seamless migration. Default is off.
 
+    ``video-codecs=<encoder>:<codec>``
+        Provide the preferred codec the Spice server should use.
+        Default would be spice:mjpeg.

This looks like two distinct settings overloaded into one command line parameter, which is a design anti-pattern.

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Why can't this be done as separate parameters

The Spice server API used by Qemu (spice_server_set_video_codecs) to set the preferred codec requires the video-codecs string to be in encoder:codec format. AFAIK, there is no other option or API to set the encoder and codec values separately.

QEMU can accept the separate parameters and format them into the

string

Quoted 9 lines
Quoted 4 lines

format that the spice API requires so our public API is not impacted by this spice design choice.

Apparently you cannot mix and match freely, it has a rather fixed set of actually working values.

See here and related code:
https://gitlab.freedesktop.org/spice/spice/-

/blob/master/server/reds.cpp?ref_type=heads#L3468

That's just showing the built-in defaults - the parsing code is not enforcing any constraints. The impl though cleary only allows 'mjpeg' with 'spice':

https://gitlab.freedesktop.org/spice/spice/-/blob/master/server/mjpeg-
encoder.c#L1371

Quoted 2 lines

Tbh, I don't think the encoder matters much, and I don't know why it was decided to associate it with video codec names.

AFAICT the only way in which the encoder matters is to distinguish the built-in "mjpeg" impl from the gstreamer "mjpeg" coder.

Quoted 1 line

Maybe the spice API should provide a simpler form: accept only codec

names.

Quoted 4 lines

In the meantime, qemu should perhaps add the "working" encoder prefixes (spice: for mjpeg, gstreamer: for others) itself and not expose any extra option to the user?

Ths question is whether we need to be able to request the gstreamer 'mjpeg' impl ?

If we do, and we also assume that 'spice' will never gain any more codec impls as built-ins, we could do

builtin, mjpeg, vp8, vp9, h264

Quoted 8 lines

where 'builtin' is the standard mjpeg encoder ?

Alternatively we could just go with

mjpeg, vp8, vp9, h264

and in the unlikely event we need to be able to skip the built-in mjpeg, we could add a boolean 'prefer-gstreamer=on|off'

This patch series is intended to be used only with the "gstreamer" encoder type. So, I guess Qemu can just accept video-codecs=<codec> where codec could be any of mjpeg, vp8, vp9, h264 and we could then invoke the Spice API spice_server_set_video_codecs() with the appropriately formatted codecs string (i.e, gstreamer:<codec>).

Thanks,
Vivek

Quoted 7 lines

With regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

PATCH v5 3/7 ui/spice: Enable gl=on option for non-local or remote clients

In reply to Vivek Kasireddy

Newer versions of Spice server should be able to accept dmabuf fds from Qemu for clients that are connected via the network. In other words, when this option is enabled, Qemu would share a dmabuf fd with Spice which would encode and send the data associated with the fd to a client that could be located on a different machine.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 include/ui/spice-display.h | 1 +
 ui/spice-core.c            | 4 ++++
 ui/spice-display.c         | 1 +
 3 files changed, 6 insertions(+)
include/ui/spice-display.h +1 -0
index e1a9b36185..6c55f38c8b 100644
@@ -151,6 +151,7 @@ struct SimpleSpiceCursor {
 };
 
 extern bool spice_opengl;
+extern bool spice_remote_client;
 
 int qemu_spice_rect_is_empty(const QXLRect* r);
 void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
ui/spice-core.c +4 -0
index 907b0e9a81..f92dd55392 100644
@@ -848,9 +848,13 @@ static void qemu_spice_init(void)
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
         if ((port != 0) || (tls_port != 0)) {
+#if SPICE_SERVER_VERSION >= 0x000f03 /* release 0.15.3 */
+            spice_remote_client = 1;
+#else
             error_report("SPICE GL support is local-only for now and "
                          "incompatible with -spice port/tls-port");
             exit(1);
+#endif
         }
         egl_init(qemu_opt_get(opts, "rendernode"), DISPLAY_GL_MODE_ON, &error_fatal);
         spice_opengl = 1;
ui/spice-display.c +1 -0
index 9c39d2c5c8..0fb72f6d6f 100644
@@ -31,6 +31,7 @@
 #include "standard-headers/drm/drm_fourcc.h"
 
 bool spice_opengl;
+bool spice_remote_client;
 
 int qemu_spice_rect_is_empty(const QXLRect* r)
 {
Signature · 1 line
2.49.0
#11 lore raw

PATCH v5 4/7 ui/spice: Add an option to submit gl_draw requests at fixed rate

In reply to Vivek Kasireddy

In the specific case where the display layer (virtio-gpu) is using dmabuf, and if remote clients are enabled (-spice gl=on,port=xxxx), it makes sense to limit the maximum (streaming) rate (refresh rate) to a fixed value using the GUI refresh timer. Otherwise, the updates or gl_draw requests would be sent as soon as the Guest submits a new frame which is not optimal as it would lead to increased network traffic and wastage of GPU cycles if the frames get dropped.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 include/ui/spice-display.h |  1 +
 qemu-options.hx            |  5 +++
 ui/spice-core.c            | 12 ++++++++
 ui/spice-display.c         | 62 ++++++++++++++++++++++++++++++++------
 4 files changed, 70 insertions(+), 10 deletions(-)
include/ui/spice-display.h +1 -0
index 6c55f38c8b..9bdde78266 100644
@@ -152,6 +152,7 @@ struct SimpleSpiceCursor {
 
 extern bool spice_opengl;
 extern bool spice_remote_client;
+extern int spice_max_refresh_rate;
 
 int qemu_spice_rect_is_empty(const QXLRect* r);
 void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r);
qemu-options.hx +5 -0
index fcddb583c9..98af43953d 100644
@@ -2282,6 +2282,7 @@ DEF("spice", HAS_ARG, QEMU_OPTION_spice,
     "       [,disable-agent-file-xfer=on|off][,agent-mouse=[on|off]]\n"
     "       [,playback-compression=[on|off]][,seamless-migration=[on|off]]\n"
     "       [,video-codecs=<encoder>:<codec>\n"
+    "       [,max-refresh-rate=rate\n"
     "       [,gl=[on|off]][,rendernode=<file>]\n"
     "                enable spice\n"
     "                at least one of {port, tls-port} is mandatory\n",
@@ -2374,6 +2375,10 @@ SRST
         Provide the preferred codec the Spice server should use.
         Default would be spice:mjpeg.
 
+    ``max-refresh-rate=rate``
+        Provide the maximum refresh rate (or FPS) at which the encoding
+        requests should be sent to the Spice server. Default would be 30.
+
     ``gl=[on|off]``
         Enable/disable OpenGL context. Default is off.
 
ui/spice-core.c +12 -0
index f92dd55392..6576bfd20d 100644
@@ -56,6 +56,8 @@ struct SpiceTimer {
     QEMUTimer *timer;
 };
 
+#define DEFAULT_MAX_REFRESH_RATE 30
+
 static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque)
 {
     SpiceTimer *timer;
@@ -491,6 +493,9 @@ static QemuOptsList qemu_spice_opts = {
         },{
             .name = "video-codecs",
             .type = QEMU_OPT_STRING,
+        },{
+            .name = "max-refresh-rate",
+            .type = QEMU_OPT_NUMBER,
         },{
             .name = "agent-mouse",
             .type = QEMU_OPT_BOOL,
@@ -813,6 +818,13 @@ static void qemu_spice_init(void)
         }
     }
 
+    spice_max_refresh_rate = qemu_opt_get_number(opts, "max-refresh-rate",
+                                                 DEFAULT_MAX_REFRESH_RATE);
+    if (spice_max_refresh_rate <= 0) {
+        error_report("max refresh rate/fps is invalid");
+        exit(1);
+    }
+
     spice_server_set_agent_mouse
         (spice_server, qemu_opt_get_bool(opts, "agent-mouse", 1));
     spice_server_set_playback_compression
ui/spice-display.c +52 -10

102 lines not on this page · raw message

Signature · 1 line
2.49.0
#12 lore raw

PATCH v5 5/7 ui/console-gl: Add a helper to create a texture with linear memory layout

In reply to Vivek Kasireddy

There are cases where we do not want the memory layout of a texture to be tiled as the component processing the texture would not know how to de-tile either via software or hardware. Therefore, ensuring that the memory backing the texture has a linear layout is absolutely necessary in these situations.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
---
 include/ui/console.h |  3 +++
 ui/console-gl.c      | 48 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
include/ui/console.h +3 -0
index 46b3128185..98feaa58bd 100644
@@ -422,6 +422,9 @@ bool console_gl_check_format(DisplayChangeListener *dcl,
                              pixman_format_code_t format);
 void surface_gl_create_texture(QemuGLShader *gls,
                                DisplaySurface *surface);
+bool surface_gl_create_texture_from_fd(DisplaySurface *surface,
+                                       int fd, GLuint *texture,
+                                       GLuint *mem_obj);
 void surface_gl_update_texture(QemuGLShader *gls,
                                DisplaySurface *surface,
                                int x, int y, int w, int h);
ui/console-gl.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.49.0
#13 lore raw

PATCH v5 6/7 ui/spice: Create a new texture with linear layout when gl=on is enabled

In reply to Vivek Kasireddy

Since most encoders/decoders (invoked by Spice) may not work properly with tiled memory associated with a texture, we need to create another texture that has linear memory layout and use that instead.

Note that, there does not seem to be a direct way to indicate to the GL implementation that a texture's backing memory needs to be linear. Instead, we have to do it in a roundabout way where we need to first create a tiled texture and import that as a memory object to create a new texture that has a linear memory layout.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
---
 include/ui/surface.h |  1 +
 ui/console-gl.c      |  6 ++++
 ui/spice-display.c   | 82 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)
include/ui/surface.h +1 -0
index f16f7be8be..006b1986bb 100644
@@ -22,6 +22,7 @@ typedef struct DisplaySurface {
     GLenum glformat;
     GLenum gltype;
     GLuint texture;
+    GLuint mem_obj;
 #endif
     qemu_pixman_shareable share_handle;
     uint32_t share_handle_offset;
ui/console-gl.c +6 -0
index afb36dba64..403fc36fbd 100644
@@ -184,6 +184,12 @@ void surface_gl_destroy_texture(QemuGLShader *gls,
     }
     glDeleteTextures(1, &surface->texture);
     surface->texture = 0;
+#ifdef GL_EXT_memory_object_fd
+    if (surface->mem_obj) {
+        glDeleteMemoryObjectsEXT(1, &surface->mem_obj);
+        surface->mem_obj = 0;
+    }
+#endif
 }
 
 void surface_gl_setup_viewport(QemuGLShader *gls,
ui/spice-display.c +82 -0

100 lines not on this page · raw message

Signature · 1 line
2.49.0
#14 lore raw

PATCH v5 7/7 ui/spice: Blit the scanout texture if its memory layout is not linear

In reply to Vivek Kasireddy

In cases where the scanout buffer is provided as a texture (e.g. Virgl) we need to check to see if it has a linear memory layout or not. If it doesn't have a linear layout, then blitting it onto the texture associated with the display surface (which already has a linear layout) seems to ensure that there is no corruption seen regardless of which encoder or decoder is used.

Cc Gerd Hoffmann <[email protected]>
Cc Marc-André Lureau <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Frediano Ziglio <[email protected]>
Cc Dongwon Kim <[email protected]>
Cc Michael Scherle <[email protected]>
---
 include/ui/spice-display.h |  3 ++
 ui/spice-display.c         | 81 +++++++++++++++++++++++++++++++++++---
 2 files changed, 78 insertions(+), 6 deletions(-)
include/ui/spice-display.h +3 -0
index 9bdde78266..690ece7380 100644
@@ -132,6 +132,9 @@ struct SimpleSpiceDisplay {
     egl_fb guest_fb;
     egl_fb blit_fb;
     egl_fb cursor_fb;
+    bool backing_y_0_top;
+    bool blit_scanout_texture;
+    bool new_scanout_texture;
     bool have_hot;
 #endif
 };
ui/spice-display.c +75 -6

111 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on the v5 series
#15 lore raw
In reply to Vivek Kasireddy

Hi Vivek

Quoted 11 lines · Vivek Kasireddy

To address the limitation that this option is incompatible with remote clients, this patch series adds an option to select a preferred codec and also enable gl=on option for clients that are connected via the network. In other words, with this option enabled (and the below linked Spice series merged), it would be possible to have Qemu share a dmabuf fd with Spice, which would then forward it to a hardware or software based encoder and eventually send the data associated with the fd to a client that could be located on a different machine.

Quoted 5 lines

Essentially, this patch series provides a hardware accelerated, opensource VDI option for users using Qemu and Spice by leveraging the iGPU/dGPU on the host machine to encode the Guest FB via the Gstreamer framework.

I tested the series on fedora with intel-media-driver installed from rpmfusion.

Without explicit video-codecs argument I get:
qemu-system-x86_64: warning: Spice:
../server/dcc-send.cpp:1780:red_marshall_gl_draw_stream: No video encoder available for this stream
qemu-system-x86_64: warning: spice: no gl-draw-done within one second

If I specify video-codecs=gstreamer:h264, then it seems to work fine.

I wish all of this would be better documented or more explicit, as each step took me a while to figure out (why it didn't pick a compatible encoder, what was the argument for video-codecs, why gst didn't support h264enc, where to find the encoder, ...). I am not even sure I am doing all this correctly. Maybe there should be some docs/interop/spice.rst to document qemu -spice and video-codecs usages? (and move docs/spice-port-fqdn.txt content there too)

I suppose the issue with better default for video-codecs is on spice-server side, so for this series:

Quoted 78 lines

v4 -> v5 (suggestions from Marc-André):
- Fix the errors (mostly 80 chars limit violations) identified by scripts/checkpatch.pl
- Rename the globals to have a spice_ prefix for consistency
- Rename MAX_REFRESH_RATE to DEFAULT_MAX_REFRESH_RATE
- Added comments to explain how/when the gl_draw request is submitted to spice server in the remote clients case
- Fix the mem_obj leak that would occur when the associated texture is destroyed or when an error is encountered while creating a texture from an fd (Dmitry and Michael)
- Merged Michael's patch to fix the mem_obj leak into this series and added his Co-developed-by tag to the relevant patches

v3 -> v4 (suggestions from Marc-André):
- Add a new parameter to make max_refresh_rate configurable
- Have surface_gl_create_texture_from_fd() return bool after checking for errors
- Remove the check for PIXMAN_r5g6b5() in spice_gl_replace_fd_texture()
- Report errors in spice_gl_replace_fd_texture() when someting fails
- Use glGetError() correctly by adding an additional (dummy) call before checking for actual errors (Dmitry)
- Add a new patch to check fd values in egl_dmabuf_export_texture()
- Rebase on Qemu master

v2 -> v3:
- Check for errors after invoking glImportMemoryFdEXT() using glGetError() and report the error to user (Dmitry)

v1 -> v2:
- Replace the option name preferred-codec with video-codecs (Marc-André)
- Add a warning when an fd cannot be created from texture (Marc-André)
- Add a new patch to blit the scanout texture into a linear one to make it work with virgl
- Rebased and tested against the latest Spice master

Tested with the following Qemu parameters:

(quoted diff) +0 -2
-device virtio-vga,max_outputs=1,xres=1920,yres=1080,blob=true
-spice port=3001,gl=on,disable-ticketing=on,video-codecs=gstreamer:h264

and remote-viewer --spice-debug spice://x.x.x.x:3001 on the client side.

Associated Spice server MR (merged):
https://gitlab.freedesktop.org/spice/spice/-/merge_requests/229

---
Cc: Gerd Hoffmann <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Dmitry Osipenko <[email protected]>
Cc: Frediano Ziglio <[email protected]>
Cc: Michael Scherle <[email protected]>
Cc: Dongwon Kim <[email protected]>
Cc: Alex Bennée <[email protected]>

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Add an option for users to provide a preferred codec ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
enabled
ui/spice: Blit the scanout texture if its memory layout is not linear

 include/ui/console.h       |   3 +
 include/ui/spice-display.h |   5 +
 include/ui/surface.h       |   1 +
 qemu-options.hx            |  10 ++
 ui/console-gl.c            |  54 +++++++++
 ui/egl-helpers.c           |   6 +
 ui/spice-core.c            |  28 +++++
 ui/spice-display.c         | 226 ++++++++++++++++++++++++++++++++++---
 8 files changed, 317 insertions(+), 16 deletions(-)

--
2.49.0

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

Hi Marc-André,

Quoted 28 lines

Subject: Re: [PATCH v5 0/7] ui/spice: Enable gl=on option for non-local or remote clients

Quoted 11 lines

To address the limitation that this option is incompatible with remote clients, this patch series adds an option to select a preferred codec and also enable gl=on option for clients that are connected via the network. In other words, with this option enabled (and the below linked Spice series merged), it would be possible to have Qemu share a dmabuf fd with Spice, which would then forward it to a hardware or software based encoder and eventually send the data associated with the fd to a client that could be located on a different machine.

Quoted 5 lines

Essentially, this patch series provides a hardware accelerated, opensource VDI option for users using Qemu and Spice by leveraging the iGPU/dGPU on the host machine to encode the Guest FB via the Gstreamer framework.

I tested the series on fedora with intel-media-driver installed from rpmfusion.

Without explicit video-codecs argument I get:
qemu-system-x86_64: warning: Spice:
../server/dcc-send.cpp:1780:red_marshall_gl_draw_stream: No video encoder available for this stream
qemu-system-x86_64: warning: spice: no gl-draw-done within one second

Quoted 3 lines

If I specify video-codecs=gstreamer:h264, then it seems to work fine.

I wish all of this would be better documented or more explicit, as

Do you think it makes sense to use "gstreamer:h264" as default if the user chose -spice gl=on but did not specify any video-codecs explicitly?

Quoted 6 lines

each step took me a while to figure out (why it didn't pick a compatible encoder, what was the argument for video-codecs, why gst didn't support h264enc, where to find the encoder, ...). I am not even sure I am doing all this correctly. Maybe there should be some docs/interop/spice.rst to document qemu -spice and video-codecs usages? (and move docs/spice-port-fqdn.txt content there too)

The codecs negotiation between Qemu and Spice can definitely be improved as we test/add newer codecs such as AV1, etc. As far as documentation is concerned, I'd like to do it in a follow up series if it is ok with you since it might delay this series given that it would probably require few more revisions/versions to get it right.

Quoted 4 lines

I suppose the issue with better default for video-codecs is on spice-server side, so for this series:

Thank you so much!

Thanks,
Vivek

Quoted 84 lines
Quoted 76 lines

v4 -> v5 (suggestions from Marc-André):
- Fix the errors (mostly 80 chars limit violations) identified by scripts/checkpatch.pl
- Rename the globals to have a spice_ prefix for consistency
- Rename MAX_REFRESH_RATE to DEFAULT_MAX_REFRESH_RATE
- Added comments to explain how/when the gl_draw request is submitted to spice server in the remote clients case
- Fix the mem_obj leak that would occur when the associated texture is destroyed or when an error is encountered while creating a texture from an fd (Dmitry and Michael)
- Merged Michael's patch to fix the mem_obj leak into this series and added his Co-developed-by tag to the relevant patches

v3 -> v4 (suggestions from Marc-André):
- Add a new parameter to make max_refresh_rate configurable
- Have surface_gl_create_texture_from_fd() return bool after checking for errors
- Remove the check for PIXMAN_r5g6b5() in spice_gl_replace_fd_texture()
- Report errors in spice_gl_replace_fd_texture() when someting fails
- Use glGetError() correctly by adding an additional (dummy) call before checking for actual errors (Dmitry)
- Add a new patch to check fd values in egl_dmabuf_export_texture()
- Rebase on Qemu master

v2 -> v3:
- Check for errors after invoking glImportMemoryFdEXT() using glGetError() and report the error to user (Dmitry)

v1 -> v2:
- Replace the option name preferred-codec with video-codecs (Marc-André)
- Add a warning when an fd cannot be created from texture (Marc-André)
- Add a new patch to blit the scanout texture into a linear one to make it work with virgl
- Rebased and tested against the latest Spice master

Tested with the following Qemu parameters:

(quoted diff) +0 -2
-device virtio-vga,max_outputs=1,xres=1920,yres=1080,blob=true
-spice port=3001,gl=on,disable-ticketing=on,video-codecs=gstreamer:h264

and remote-viewer --spice-debug spice://x.x.x.x:3001 on the client side.

Associated Spice server MR (merged):
https://gitlab.freedesktop.org/spice/spice/-/merge_requests/229

---
Cc: Gerd Hoffmann <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Dmitry Osipenko <[email protected]>
Cc: Frediano Ziglio <[email protected]>
Cc: Michael Scherle <[email protected]>
Cc: Dongwon Kim <[email protected]>
Cc: Alex Bennée <[email protected]>

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Add an option for users to provide a preferred codec ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
enabled
ui/spice: Blit the scanout texture if its memory layout is not linear

 include/ui/console.h       |   3 +
 include/ui/spice-display.h |   5 +
 include/ui/surface.h       |   1 +
 qemu-options.hx            |  10 ++
 ui/console-gl.c            |  54 +++++++++
 ui/egl-helpers.c           |   6 +
 ui/spice-core.c            |  28 +++++
 ui/spice-display.c         | 226 ++++++++++++++++++++++++++++++++++---
 8 files changed, 317 insertions(+), 16 deletions(-)
Quoted 4 lines

--
2.49.0

--
Marc-André Lureau

#17 lore raw
In reply to Vivek Kasireddy
Quoted 79 lines · Vivek Kasireddy

To address the limitation that this option is incompatible with remote clients, this patch series adds an option to select a preferred codec and also enable gl=on option for clients that are connected via the network. In other words, with this option enabled (and the below linked Spice series merged), it would be possible to have Qemu share a dmabuf fd with Spice, which would then forward it to a hardware or software based encoder and eventually send the data associated with the fd to a client that could be located on a different machine.

Essentially, this patch series provides a hardware accelerated, opensource VDI option for users using Qemu and Spice by leveraging the iGPU/dGPU on the host machine to encode the Guest FB via the Gstreamer framework.

v4 -> v5 (suggestions from Marc-André):
- Fix the errors (mostly 80 chars limit violations) identified by scripts/checkpatch.pl
- Rename the globals to have a spice_ prefix for consistency
- Rename MAX_REFRESH_RATE to DEFAULT_MAX_REFRESH_RATE
- Added comments to explain how/when the gl_draw request is submitted to spice server in the remote clients case
- Fix the mem_obj leak that would occur when the associated texture is destroyed or when an error is encountered while creating a texture from an fd (Dmitry and Michael)
- Merged Michael's patch to fix the mem_obj leak into this series and added his Co-developed-by tag to the relevant patches

v3 -> v4 (suggestions from Marc-André):
- Add a new parameter to make max_refresh_rate configurable
- Have surface_gl_create_texture_from_fd() return bool after checking for errors
- Remove the check for PIXMAN_r5g6b5() in spice_gl_replace_fd_texture()
- Report errors in spice_gl_replace_fd_texture() when someting fails
- Use glGetError() correctly by adding an additional (dummy) call before checking for actual errors (Dmitry)
- Add a new patch to check fd values in egl_dmabuf_export_texture()
- Rebase on Qemu master

v2 -> v3:
- Check for errors after invoking glImportMemoryFdEXT() using glGetError() and report the error to user (Dmitry)

v1 -> v2:
- Replace the option name preferred-codec with video-codecs (Marc-André)
- Add a warning when an fd cannot be created from texture (Marc-André)
- Add a new patch to blit the scanout texture into a linear one to make it work with virgl
- Rebased and tested against the latest Spice master

Tested with the following Qemu parameters:

(quoted diff) +0 -2
-device virtio-vga,max_outputs=1,xres=1920,yres=1080,blob=true
-spice port=3001,gl=on,disable-ticketing=on,video-codecs=gstreamer:h264

and remote-viewer --spice-debug spice://x.x.x.x:3001 on the client side.

Associated Spice server MR (merged):
https://gitlab.freedesktop.org/spice/spice/-/merge_requests/229

---
Cc: Gerd Hoffmann <[email protected]>
Cc: Marc-André Lureau <[email protected]>
Cc: Dmitry Osipenko <[email protected]>
Cc: Frediano Ziglio <[email protected]>
Cc: Michael Scherle <[email protected]>
Cc: Dongwon Kim <[email protected]>
Cc: Alex Bennée <[email protected]>

Vivek Kasireddy (7):
ui/egl-helpers: Error check the fds in egl_dmabuf_export_texture() ui/spice: Add an option for users to provide a preferred codec ui/spice: Enable gl=on option for non-local or remote clients ui/spice: Add an option to submit gl_draw requests at fixed rate ui/console-gl: Add a helper to create a texture with linear memory
layout
ui/spice: Create a new texture with linear layout when gl=on is
enabled
ui/spice: Blit the scanout texture if its memory layout is not linear

Quoted 4 lines
 include/ui/console.h       |   3 +
 include/ui/spice-display.h |   5 +
 include/ui/surface.h       |   1 +
 qemu-options.hx            |  10 ++

Aside from the qemu-options we don't see a lot about SPICE in the docs. Could we add a section to cover the configuration or maybe just expand system/devices/virtio-gpu with information about how acceleration works with remote SPICE viewers?

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro