[PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display

marcandre.lureau@redhat.com posted 21 patches 2 years, 8 months ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Stefan Weil <sw@weilnetz.de>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Laurent Vivier <lvivier@redhat.com>
[PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Posted by marcandre.lureau@redhat.com 2 years, 8 months ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

virgl offers a few features that require to have access to the
underlying EGLDisplay. This is the case for the D3D texture sharing support.

The API callback is merged for virgl 1.0:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 1c47603d40..9831c482e5 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -18,9 +18,17 @@
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-gpu.h"
 
+#include "ui/egl-helpers.h"
+
 #include <virglrenderer.h>
 
-static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
+#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
+static void *
+virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
+{
+    return qemu_egl_display;
+}
+#endif
 
 static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
                                          struct virtio_gpu_ctrl_command *cmd)
@@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
 {
     int ret;
 
+#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
+    if (qemu_egl_display) {
+        virtio_gpu_3d_cbs.version = 4;
+        virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
+    }
+#endif
+
     ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
     if (ret != 0) {
         error_report("virgl could not be initialized: %d", ret);
-- 
2.40.1


Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Posted by Antonio Caggiano 2 years, 5 months ago
Hi Marc-André,

I've been testing this, but I can't find where qemu_egl_display is set 
when using sdl.

Whil ui/gtk.c sets that in gl_area_realize, from my understanding there 
is no equivalent call in ui/sdl2-gl.c

Also, in which case SDL would use EGL, and is there a way to request 
that (e.g. as opposed to GLX)?

Kind regards,
Antonio Caggiano

On 06/06/2023 13:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> virgl offers a few features that require to have access to the
> underlying EGLDisplay. This is the case for the D3D texture sharing support.
> 
> The API callback is merged for virgl 1.0:
> https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 1c47603d40..9831c482e5 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -18,9 +18,17 @@
>   #include "hw/virtio/virtio.h"
>   #include "hw/virtio/virtio-gpu.h"
>   
> +#include "ui/egl-helpers.h"
> +
>   #include <virglrenderer.h>
>   
> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> +static void *
> +virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
> +{
> +    return qemu_egl_display;
> +}
> +#endif
>   
>   static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
>                                            struct virtio_gpu_ctrl_command *cmd)
> @@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
>   {
>       int ret;
>   
> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> +    if (qemu_egl_display) {
> +        virtio_gpu_3d_cbs.version = 4;
> +        virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
> +    }
> +#endif
> +
>       ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
>       if (ret != 0) {
>           error_report("virgl could not be initialized: %d", ret);

Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Posted by Marc-André Lureau 2 years, 5 months ago
Hi Antonio

On Wed, Aug 30, 2023 at 3:14 PM Antonio Caggiano
<quic_acaggian@quicinc.com> wrote:
>
> Hi Marc-André,
>
> I've been testing this, but I can't find where qemu_egl_display is set
> when using sdl.
>
> Whil ui/gtk.c sets that in gl_area_realize, from my understanding there
> is no equivalent call in ui/sdl2-gl.c
>
> Also, in which case SDL would use EGL, and is there a way to request
> that (e.g. as opposed to GLX)?

I am not sure, it's a tricky question. It seems SDL will use EGL when
requesting ES (-display sdl,gl=es), at least with x11 and wayland (and
win32 iirc). There is also SDL_VIDEO_X11_FORCE_EGL.

Yes, some code is missing in sdl2.c to set qemu_egl_display so virgl
can rely on it. Patches welcome!

>
> Kind regards,
> Antonio Caggiano
>
> On 06/06/2023 13:56, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > virgl offers a few features that require to have access to the
> > underlying EGLDisplay. This is the case for the D3D texture sharing support.
> >
> > The API callback is merged for virgl 1.0:
> > https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++-
> >   1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> > index 1c47603d40..9831c482e5 100644
> > --- a/hw/display/virtio-gpu-virgl.c
> > +++ b/hw/display/virtio-gpu-virgl.c
> > @@ -18,9 +18,17 @@
> >   #include "hw/virtio/virtio.h"
> >   #include "hw/virtio/virtio-gpu.h"
> >
> > +#include "ui/egl-helpers.h"
> > +
> >   #include <virglrenderer.h>
> >
> > -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
> > +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> > +static void *
> > +virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
> > +{
> > +    return qemu_egl_display;
> > +}
> > +#endif
> >
> >   static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
> >                                            struct virtio_gpu_ctrl_command *cmd)
> > @@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
> >   {
> >       int ret;
> >
> > +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> > +    if (qemu_egl_display) {
> > +        virtio_gpu_3d_cbs.version = 4;
> > +        virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
> > +    }
> > +#endif
> > +
> >       ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
> >       if (ret != 0) {
> >           error_report("virgl could not be initialized: %d", ret);
>
Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Posted by Antonio Caggiano 2 years, 5 months ago
Thanks for your answer, that'll help.

On 30/08/2023 13:49, Marc-André Lureau wrote:
> Hi Antonio
> 
> On Wed, Aug 30, 2023 at 3:14 PM Antonio Caggiano
> <quic_acaggian@quicinc.com> wrote:
>>
>> Hi Marc-André,
>>
>> I've been testing this, but I can't find where qemu_egl_display is set
>> when using sdl.
>>
>> Whil ui/gtk.c sets that in gl_area_realize, from my understanding there
>> is no equivalent call in ui/sdl2-gl.c
>>
>> Also, in which case SDL would use EGL, and is there a way to request
>> that (e.g. as opposed to GLX)?
> 
> I am not sure, it's a tricky question. It seems SDL will use EGL when
> requesting ES (-display sdl,gl=es), at least with x11 and wayland (and
> win32 iirc). There is also SDL_VIDEO_X11_FORCE_EGL >
> Yes, some code is missing in sdl2.c to set qemu_egl_display so virgl
> can rely on it. Patches welcome!

Good, I'll take care of that.

> 
>>
>> Kind regards,
>> Antonio Caggiano
>>
>> On 06/06/2023 13:56, marcandre.lureau@redhat.com wrote:
>>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>
>>> virgl offers a few features that require to have access to the
>>> underlying EGLDisplay. This is the case for the D3D texture sharing support.
>>>
>>> The API callback is merged for virgl 1.0:
>>> https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>>    hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++-
>>>    1 file changed, 16 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
>>> index 1c47603d40..9831c482e5 100644
>>> --- a/hw/display/virtio-gpu-virgl.c
>>> +++ b/hw/display/virtio-gpu-virgl.c
>>> @@ -18,9 +18,17 @@
>>>    #include "hw/virtio/virtio.h"
>>>    #include "hw/virtio/virtio-gpu.h"
>>>
>>> +#include "ui/egl-helpers.h"
>>> +
>>>    #include <virglrenderer.h>
>>>
>>> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
>>> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
>>> +static void *
>>> +virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
>>> +{
>>> +    return qemu_egl_display;
>>> +}
>>> +#endif
>>>
>>>    static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
>>>                                             struct virtio_gpu_ctrl_command *cmd)
>>> @@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
>>>    {
>>>        int ret;
>>>
>>> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
>>> +    if (qemu_egl_display) {
>>> +        virtio_gpu_3d_cbs.version = 4;
>>> +        virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
>>> +    }
>>> +#endif
>>> +
>>>        ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
>>>        if (ret != 0) {
>>>            error_report("virgl could not be initialized: %d", ret);
>>
> 

Cheers,
Antonio Caggiano

Re: [PATCH 17/21] virtio-gpu-virgl: teach it to get the QEMU EGL display
Posted by Antonio Caggiano 2 years, 5 months ago
Hi Marc-André,

I've been testing this, but I can't find where qemu_egl_display is set 
when using sdl.

Whil ui/gtk.c sets that in gl_area_realize, from my understanding there 
is no equivalent call in ui/sdl2-gl.c

Also, in which case SDL would use EGL, and is there a way to request 
that (e.g. as opposed to GLX)?

Kind regards,
Antonio Caggiano

On 06/06/2023 13:56, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> virgl offers a few features that require to have access to the
> underlying EGLDisplay. This is the case for the D3D texture sharing support.
> 
> The API callback is merged for virgl 1.0:
> https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1113
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 1c47603d40..9831c482e5 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -18,9 +18,17 @@
>   #include "hw/virtio/virtio.h"
>   #include "hw/virtio/virtio-gpu.h"
>   
> +#include "ui/egl-helpers.h"
> +
>   #include <virglrenderer.h>
>   
> -static struct virgl_renderer_callbacks virtio_gpu_3d_cbs;
> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> +static void *
> +virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
> +{
> +    return qemu_egl_display;
> +}
> +#endif
>   
>   static void virgl_cmd_create_resource_2d(VirtIOGPU *g,
>                                            struct virtio_gpu_ctrl_command *cmd)
> @@ -608,6 +616,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
>   {
>       int ret;
>   
> +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
> +    if (qemu_egl_display) {
> +        virtio_gpu_3d_cbs.version = 4;
> +        virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
> +    }
> +#endif
> +
>       ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
>       if (ret != 0) {
>           error_report("virgl could not be initialized: %d", ret);