Skip to contentSkip to conversation

Change spice-server protocol for GL texture passing

PATCH In review Frediano Ziglio 3 participants 8 messages Jul 15, 2016 – Jul 21, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 Change spice-server protocol for GL texture passing

---
 ui/spice-core.c    |  5 -----
 ui/spice-display.c | 29 ++++++++---------------------
 2 files changed, 8 insertions(+), 26 deletions(-)
ui/spice-core.c +0 -5
index da05054..f7647f7 100644
@@ -828,11 +828,6 @@ void qemu_spice_init(void)
 
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
-        if ((port != 0) || (tls_port != 0)) {
-            error_report("SPICE GL support is local-only for now and "
-                         "incompatible with -spice port/tls-port");
-            exit(1);
-        }
         if (egl_rendernode_init() != 0) {
             error_report("Failed to initialize EGL render node for SPICE GL");
             exit(1);
ui/spice-display.c +8 -21
index 2a77a54..72137bd 100644
@@ -852,6 +852,10 @@ static void qemu_spice_gl_block_timer(void *opaque)
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener *dcl,
                                                   QEMUGLParams *params)
 {
+    SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
+
+    spice_qxl_gl_init(&ssd->qxl, qemu_egl_display, qemu_egl_rn_ctx);
+
     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    qemu_egl_rn_ctx);
     return qemu_egl_create_context(dcl, params);
@@ -864,28 +868,11 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl,
                                   uint32_t w, uint32_t h)
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
-    EGLint stride = 0, fourcc = 0;
-    int fd = -1;
-
-    if (tex_id) {
-        fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc);
-        if (fd < 0) {
-            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__);
-    }
-
-    assert(!tex_id || fd >= 0);
 
-    /* note: spice server will close the fd */
-    spice_qxl_gl_scanout(&ssd->qxl, fd,
-                         surface_width(ssd->ds),
-                         surface_height(ssd->ds),
-                         stride, fourcc, y_0_top);
+    spice_qxl_gl_scanout_texture(&ssd->qxl, tex_id,
+                                 surface_width(ssd->ds),
+                                 surface_height(ssd->ds),
+                                 y_0_top);
 
     qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }
Signature · 1 line
2.7.4
#2 lore raw

Forgot to add RFC to the subject

Frediano

Quoted 73 lines
---
 ui/spice-core.c    |  5 -----
 ui/spice-display.c | 29 ++++++++---------------------
 2 files changed, 8 insertions(+), 26 deletions(-)
ui/spice-core.c +0 -5
index da05054..f7647f7 100644
@@ -828,11 +828,6 @@ void qemu_spice_init(void)
 
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
-        if ((port != 0) || (tls_port != 0)) {
-            error_report("SPICE GL support is local-only for now and "
-                         "incompatible with -spice port/tls-port");
-            exit(1);
-        }
         if (egl_rendernode_init() != 0) {
             error_report("Failed to initialize EGL render node for SPICE
             GL");
             exit(1);
ui/spice-display.c +4 -0
index 2a77a54..72137bd 100644
@@ -852,6 +852,10 @@ static void qemu_spice_gl_block_timer(void *opaque)
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener
 *dcl,
                                                   QEMUGLParams *params)
 {
+    SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
+
+    spice_qxl_gl_init(&ssd->qxl, qemu_egl_display, qemu_egl_rn_ctx);
+
     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    qemu_egl_rn_ctx);
     return qemu_egl_create_context(dcl, params);
ui/spice-display.c +4 -21
@@ -864,28 +868,11 @@ static void qemu_spice_gl_scanout(DisplayChangeListener
 *dcl,
                                   uint32_t w, uint32_t h)
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
-    EGLint stride = 0, fourcc = 0;
-    int fd = -1;
-
-    if (tex_id) {
-        fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc);
-        if (fd < 0) {
-            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__);
-    }
-
-    assert(!tex_id || fd >= 0);
 
-    /* note: spice server will close the fd */
-    spice_qxl_gl_scanout(&ssd->qxl, fd,
-                         surface_width(ssd->ds),
-                         surface_height(ssd->ds),
-                         stride, fourcc, y_0_top);
+    spice_qxl_gl_scanout_texture(&ssd->qxl, tex_id,
+                                 surface_width(ssd->ds),
+                                 surface_height(ssd->ds),
+                                 y_0_top);
 
     qemu_spice_gl_monitor_config(ssd, x, y, w, h);

}

#3 lore raw

Hi

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

Quoted 2 lines

Forgot to add RFC to the subject

What's the rationale? if you share the texture id, you must share the GL context too, right? Why not use a lower level dmabuf fd that can be imported by the server gl context (which is also what the protocol require anyway)?

Quoted 81 lines
Quoted 66 lines

---
 ui/spice-core.c    |  5 -----
 ui/spice-display.c | 29 ++++++++---------------------
 2 files changed, 8 insertions(+), 26 deletions(-)
ui/spice-core.c +0 -5
index da05054..f7647f7 100644
@@ -828,11 +828,6 @@ void qemu_spice_init(void)
 
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
-        if ((port != 0) || (tls_port != 0)) {
-            error_report("SPICE GL support is local-only for now and "
-                         "incompatible with -spice port/tls-port");
-            exit(1);
-        }
         if (egl_rendernode_init() != 0) {
             error_report("Failed to initialize EGL render node for SPICE
             GL");
             exit(1);
ui/spice-display.c +4 -0
index 2a77a54..72137bd 100644
@@ -852,6 +852,10 @@ static void qemu_spice_gl_block_timer(void *opaque)
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener
 *dcl,
                                                   QEMUGLParams *params)
 {
+    SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
+
+    spice_qxl_gl_init(&ssd->qxl, qemu_egl_display, qemu_egl_rn_ctx);
+
     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    qemu_egl_rn_ctx);
     return qemu_egl_create_context(dcl, params);
ui/spice-display.c +0 -0
@@ -864,28 +868,11 @@ static void

qemu_spice_gl_scanout(DisplayChangeListener
*dcl,

                                   uint32_t w, uint32_t h)
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
ui/spice-display.c +0 -7
-    EGLint stride = 0, fourcc = 0;
-    int fd = -1;
-
-    if (tex_id) {
-        fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc);
-        if (fd < 0) {
-            fprintf(stderr, "%s: failed to get fd for texture\n",

__func__);

ui/spice-display.c +0 -11
-            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__);
-    }
-
-    assert(!tex_id || fd >= 0);
 
-    /* note: spice server will close the fd */
-    spice_qxl_gl_scanout(&ssd->qxl, fd,

ui/spice-display.c static void qemu_spice_gl_scanout(DisplayChangeListener *dcl, · line 878

Quoted 10 lines
ui/spice-display.c +4 -3
-                         surface_width(ssd->ds),
-                         surface_height(ssd->ds),
-                         stride, fourcc, y_0_top);
+    spice_qxl_gl_scanout_texture(&ssd->qxl, tex_id,
+                                 surface_width(ssd->ds),
+                                 surface_height(ssd->ds),
+                                 y_0_top);
 
     qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }

_______________________________________________
Spice-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/spice-devel

#4 lore raw
Quoted 11 lines

Hi

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

Quoted 2 lines

Forgot to add RFC to the subject

What's the rationale? if you share the texture id, you must share the GL context too, right? Why not use a lower level dmabuf fd that can be imported by the server gl context (which is also what the protocol require anyway)?

Yes, the display and context are shared using spice_qxl_gl_init. Importing again into a gl context would mean that you have to export the DRM prime and import again in a separate (not shared) context. It's also doable, just add 2 system call and wrapping/unwrapping. Would be good to pass the EGLDisplay then so spice-server don't have to initialize again possibly using another physical card.

We have 4 cases:
- client not connected;
- local client;
- remote client, software encoding;
- remote client, hardware encoding.

Client not connected
Passing the texture is a no-operation, passing DRM prime require to extract the handle and close every frame.

Local client
In this case there is no overhear, DRM prime is always extracted and passed to the client

Remote client, software encoding
Due to different problems (DRM prime not mmap-able or data not portably extractable) we'll need to import the DRM prime into a different EGL context (not shared with the original one), create another texture, extract data and free all texture/DRM prime.

Remote client, hardware encoding
It's not clear if it's better to pass the DRM prime or the texture, some API pass the texture. I got confirmation that gst_dmabuf_allocator_new could try to use mmap in some cases so we should check this somehow to make sure it does not.

Taking into account that DRM prime came with "free" reference counting creating the DRM prime from texture basically increase a counter which is used by our implementation to make sure texture is still existing so possibly passing texture instead of DRM prime just save a system call in the normal case. I don't know what happens to the DRM object handle when the texture is destroyed (in Qemu) with glDeleteTextures if bindings keep texture "alive" or are all reset.

Could be that keeping qemu_spice_gl_scanout and spice_qxl_gl_scanout_texture as current implementation and adding a spice_qxl_gl_init/spice_qxl_gl_setup passing just QXLInstance and EGLDisplay is a better solution.

Does is sound reasonable?

Frediano

Quoted 78 lines
Quoted 78 lines
Quoted 78 lines

---
 ui/spice-core.c    |  5 -----
 ui/spice-display.c | 29 ++++++++---------------------
 2 files changed, 8 insertions(+), 26 deletions(-)
ui/spice-core.c +0 -5
index da05054..f7647f7 100644
@@ -828,11 +828,6 @@ void qemu_spice_init(void)
 
 #ifdef HAVE_SPICE_GL
     if (qemu_opt_get_bool(opts, "gl", 0)) {
-        if ((port != 0) || (tls_port != 0)) {
-            error_report("SPICE GL support is local-only for now and "
-                         "incompatible with -spice port/tls-port");
-            exit(1);
-        }
         if (egl_rendernode_init() != 0) {
             error_report("Failed to initialize EGL render node for SPICE
             GL");
             exit(1);
ui/spice-display.c +4 -0
index 2a77a54..72137bd 100644
@@ -852,6 +852,10 @@ static void qemu_spice_gl_block_timer(void *opaque)
 static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener
 *dcl,
                                                   QEMUGLParams *params)
 {
+    SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay,
 dcl);
+
+    spice_qxl_gl_init(&ssd->qxl, qemu_egl_display, qemu_egl_rn_ctx);
+
     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    qemu_egl_rn_ctx);
     return qemu_egl_create_context(dcl, params);
ui/spice-display.c +0 -0
@@ -864,28 +868,11 @@ static void

qemu_spice_gl_scanout(DisplayChangeListener
*dcl,

                                   uint32_t w, uint32_t h)

{
SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);

ui/spice-display.c +0 -7
-    EGLint stride = 0, fourcc = 0;
-    int fd = -1;
-
-    if (tex_id) {
-        fd = egl_get_fd_for_texture(tex_id, &stride, &fourcc);
-        if (fd < 0) {
-            fprintf(stderr, "%s: failed to get fd for texture\n",

__func__);

ui/spice-display.c +4 -14
-            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__);
-    }
-
-    assert(!tex_id || fd >= 0);
 
-    /* note: spice server will close the fd */
-    spice_qxl_gl_scanout(&ssd->qxl, fd,
-                         surface_width(ssd->ds),
-                         surface_height(ssd->ds),
-                         stride, fourcc, y_0_top);
+    spice_qxl_gl_scanout_texture(&ssd->qxl, tex_id,
+                                 surface_width(ssd->ds),
+                                 surface_height(ssd->ds),
+                                 y_0_top);
 
     qemu_spice_gl_monitor_config(ssd, x, y, w, h);
 }
#5 lore raw

Hi

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

Quoted 20 lines
Quoted 12 lines

Hi

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

Quoted 2 lines

Forgot to add RFC to the subject

What's the rationale? if you share the texture id, you must share the GL context too, right? Why not use a lower level dmabuf fd that can be imported
by the server gl context (which is also what the protocol require anyway)?

Yes, the display and context are shared using spice_qxl_gl_init. Importing again into a gl context would mean that you have to export the DRM prime and import again in a separate (not shared) context. It's also doable, just add 2 system call and wrapping/unwrapping. Would be good to pass the EGLDisplay then so spice-server don't have to initialize again possibly using another physical card.

Quoted 6 lines

We have 4 cases:
- client not connected;
- local client;
- remote client, software encoding;
- remote client, hardware encoding.

Before optimizing those syscalls and changing API etc, I would like to know if they are expensive (it's not my feeling)

Also, it is possible virglrenderer could be optimized to avoid exporting the prime fd for each scanout, if the backing image is always the same.

Sharing a GL context brings new issues. If spice server could use its own context, we have some context isolation (gl is still bad at MT iirc).

Quoted 8 lines

Client not connected
Passing the texture is a no-operation, passing DRM prime require to extract the handle and close every frame.

Local client
In this case there is no overhear, DRM prime is always extracted and passed to the client

Quoted 5 lines

Remote client, software encoding
Due to different problems (DRM prime not mmap-able or data not portably extractable) we'll need to import the DRM prime into a different EGL context (not shared with the original one), create another texture, extract data and free all texture/DRM prime.

I don't think we have strong reasons to support software encoding, video encoding is really expensive, and that mmap/copy is not going to be marginal, so even less these 2 syscalls.

Quoted 7 lines

Remote client, hardware encoding
It's not clear if it's better to pass the DRM prime or the texture, some API pass the texture. I got confirmation that gst_dmabuf_allocator_new could try to use mmap in some cases so we should check this somehow to make sure it does not.

We definitely don't want any mmap/copy to take place for hw encoding.

Quoted 9 lines

Taking into account that DRM prime came with "free" reference counting creating the DRM prime from texture basically increase a counter which is used by our implementation to make sure texture is still existing so possibly passing texture instead of DRM prime just save a system call in the normal case. I don't know what happens to the DRM object handle when the texture is destroyed (in Qemu) with glDeleteTextures if bindings keep texture "alive" or are all reset.

Quoted 5 lines

Could be that keeping qemu_spice_gl_scanout and spice_qxl_gl_scanout_texture as current implementation and adding a spice_qxl_gl_init/spice_qxl_gl_setup passing just QXLInstance and EGLDisplay is a better solution.

Does is sound reasonable?

I wouldn't rush with API changes before we have a better idea how hw encoding can be done without mmap and wether its really worth it (I would rather see spice spawning a seperate gl context and process for the encoding than sharing it)

#6 lore raw
Quoted 54 lines

Hi

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

Quoted 21 lines
Quoted 4 lines

Hi

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

Quoted 9 lines
Quoted 2 lines

Forgot to add RFC to the subject

What's the rationale? if you share the texture id, you must share the GL context too, right? Why not use a lower level dmabuf fd that can be imported
by the server gl context (which is also what the protocol require anyway)?

Yes, the display and context are shared using spice_qxl_gl_init. Importing again into a gl context would mean that you have to export the DRM prime and import again in a separate (not shared) context. It's also doable, just add 2 system call and wrapping/unwrapping. Would be good to pass the EGLDisplay then so spice-server don't have to initialize again possibly using another physical card.

Quoted 6 lines

We have 4 cases:
- client not connected;
- local client;
- remote client, software encoding;
- remote client, hardware encoding.

Before optimizing those syscalls and changing API etc, I would like to know if they are expensive (it's not my feeling)

Also, it is possible virglrenderer could be optimized to avoid exporting the prime fd for each scanout, if the backing image is always the same.

Sharing a GL context brings new issues. If spice server could use its own context, we have some context isolation (gl is still bad at MT iirc).

Quoted 8 lines

Client not connected
Passing the texture is a no-operation, passing DRM prime require to extract the handle and close every frame.

Local client
In this case there is no overhear, DRM prime is always extracted and passed to the client

Quoted 5 lines

Remote client, software encoding
Due to different problems (DRM prime not mmap-able or data not portably extractable) we'll need to import the DRM prime into a different EGL context (not shared with the original one), create another texture, extract data and free all texture/DRM prime.

Quoted 4 lines

I don't think we have strong reasons to support software encoding, video encoding is really expensive, and that mmap/copy is not going to be marginal, so even less these 2 syscalls.

Using HW encoding is not easy at it seems:
- you have to have client supporting server HW encoders;
- you have to install additional software often closed source, accepting patents;
- you have to have right permission on the system.
What are you doing if these option are not respected? Do not allow connections? Showing blank screen?
With a good (local) connection I can easily play using software MJPEG, why we should avoid such configurations?

Quoted 10 lines
Quoted 7 lines

Remote client, hardware encoding
It's not clear if it's better to pass the DRM prime or the texture, some API pass the texture. I got confirmation that gst_dmabuf_allocator_new could try to use mmap in some cases so we should check this somehow to make sure it does not.

We definitely don't want any mmap/copy to take place for hw encoding.

Sure but that's hard to avoid fall backs with all different setups.

Quoted 14 lines
Quoted 14 lines

Taking into account that DRM prime came with "free" reference counting creating the DRM prime from texture basically increase a counter which is used by our implementation to make sure texture is still existing so possibly passing texture instead of DRM prime just save a system call in the normal case. I don't know what happens to the DRM object handle when the texture is destroyed (in Qemu) with glDeleteTextures if bindings keep texture "alive" or are all reset.

Could be that keeping qemu_spice_gl_scanout and spice_qxl_gl_scanout_texture
as current implementation and adding a spice_qxl_gl_init/spice_qxl_gl_setup passing just QXLInstance and EGLDisplay is a better solution.

Quoted 7 lines
Quoted 1 line

Does is sound reasonable?

I wouldn't rush with API changes before we have a better idea how hw encoding can be done without mmap and wether its really worth it (I would rather see spice spawning a seperate gl context and process for the encoding than sharing it)

I'm not rushing, this was the idea of RFC.
Spawing a process helps just to solve library licenses.
My list of patches for spice-server used the passed context just to create a new context which is shared with the provided one, as I said using different gl context and importing the DRM prime is a good option.

Passing the EGLDisplay from Qemu helps solving:
- double EGL initialization;
- multiple cards issues;
- -chroot/-runas Qemu options, where you loose access and you are not able to initialize EGL/VAAPI again.
I can see that Qemu searching for the card is different from VAAPI. In case of multiple cards and Qemu run as a daemon (not having Xwayland/X) you can end up using two physical cards.

I'll try VAAPI DRM prime passing, I hope this week.

Frediano

#7 lore raw
Quoted 5 lines · Frediano Ziglio
Quoted 4 lines

I don't think we have strong reasons to support software encoding, video encoding is really expensive, and that mmap/copy is not going to be marginal, so even less these 2 syscalls.

Quoted 9 lines

Using HW encoding is not easy at it seems:
- you have to have client supporting server HW encoders;
- you have to install additional software often closed source, accepting patents;
- you have to have right permission on the system.
What are you doing if these option are not respected? Do not allow connections? Showing blank screen?
With a good (local) connection I can easily play using software MJPEG, why we should avoid such configurations?

What we should be aiming/optimizing for is the hardware-accelerated case. We will need a fallback when this is not usable, but the various copies/encoding/... are going to be very expensive by themselves. Are these changes (passing texture rather than dmabuf) making a significant difference with software encoding?

Christophe

#8 lore raw
Quoted 17 lines · Frediano Ziglio
Quoted 5 lines
Quoted 4 lines

I don't think we have strong reasons to support software encoding, video encoding is really expensive, and that mmap/copy is not going to be marginal, so even less these 2 syscalls.

Quoted 9 lines

Using HW encoding is not easy at it seems:
- you have to have client supporting server HW encoders;
- you have to install additional software often closed source, accepting patents;
- you have to have right permission on the system.
What are you doing if these option are not respected? Do not allow connections? Showing blank screen?
With a good (local) connection I can easily play using software MJPEG, why we should avoid such configurations?

Quoted 8 lines

What we should be aiming/optimizing for is the hardware-accelerated case. We will need a fallback when this is not usable, but the various copies/encoding/... are going to be very expensive by themselves. Are these changes (passing texture rather than dmabuf) making a significant difference with software encoding?

Christophe

Got some experimental results passing DRM primes to gstreamer
(https://www.youtube.com/watch?v=NFDvMHfXUHA).
With VAAPI it's working the full frame processing decreased by a 50%. No, they are not expensive and we could just (in case of fallback) import in a new GL context to have them extracted correctly. I'm actually trying to make it works again with software encoders (no VAAPI and having to extract raw data). It's working as with kernel 4.6 i915 allows mmap but as the texture are in a different format I get quite some garbage (they should be extracted with GL which know these problems).

Frediano