From: "Alex Bennée" <alex.bennee@linaro.org>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: "Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
"Huang Rui" <ray.huang@amd.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Yiwei Zhang" <zzyiwei@gmail.com>,
"Sergio Lopez Pascual" <slp@redhat.com>,
"Gert Wollny" <gert.wollny@collabora.com>,
qemu-devel@nongnu.org,
"Gurchetan Singh" <gurchetansingh@chromium.org>,
"Alyssa Ross" <hi@alyssa.is>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Stefano Stabellini" <stefano.stabellini@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Xenia Ragiadakou" <xenia.ragiadakou@amd.com>,
"Honglei Huang" <honglei1.huang@amd.com>,
"Julia Zhang" <julia.zhang@amd.com>,
"Chen Jiqian" <Jiqian.Chen@amd.com>,
"Rob Clark" <robdclark@gmail.com>,
"Robert Beckett" <bob.beckett@collabora.com>
Subject: Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
Date: Wed, 04 Mar 2026 12:11:09 +0000 [thread overview]
Message-ID: <87ms0npzfm.fsf@draig.linaro.org> (raw)
In-Reply-To: <feff43ef-1618-4a09-aba4-e4e9c2d07e2c@collabora.com> (Dmitry Osipenko's message of "Wed, 4 Mar 2026 13:33:34 +0300")
Dmitry Osipenko <dmitry.osipenko@collabora.com> writes:
> On 3/4/26 11:49, Alex Bennée wrote:
>> Dmitry Osipenko <dmitry.osipenko@collabora.com> writes:
>>
>>> From: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
>>>
>>> If EGL is used, we can rely on dmabuf to import textures without
>>> doing copies.
>>>
>>> To get this working on X11, we use the existing SDL hint:
>>> SDL_HINT_VIDEO_X11_FORCE_EGL (because dmabuf can't be used with GLX).
>>>
>>> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
>>> Acked-by: Michael S. Tsirkin <mst@redhat.com>
>>> Tested-by: Alex Bennée <alex.bennee@linaro.org>
>>> Signed-off-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
>>> Reviewed-by: Yiwei Zhang <zzyiwei@gmail.com>
>>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>>> ---
>>> include/ui/sdl2.h | 7 +++++
>>> meson.build | 6 ++---
>>> ui/sdl2-gl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
>>> ui/sdl2.c | 42 ++++++++++++++++++++++++++++++
>>> 4 files changed, 117 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
>>> index dbe6e3d9739b..9daf5ecffae7 100644
>>> --- a/include/ui/sdl2.h
>>> +++ b/include/ui/sdl2.h
>>> @@ -45,6 +45,7 @@ struct sdl2_console {
>>> bool gui_keysym;
>>> SDL_GLContext winctx;
>>> QKbdState *kbd;
>>> + bool has_dmabuf;
>>> #ifdef CONFIG_OPENGL
>>> QemuGLShader *gls;
>>> egl_fb guest_fb;
>>> @@ -96,5 +97,11 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
>>> void *d3d_tex2d);
>>> void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
>>> uint32_t x, uint32_t y, uint32_t w, uint32_t h);
>>> +void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl,
>>> + QemuDmaBuf *dmabuf);
>>> +void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl,
>>> + QemuDmaBuf *dmabuf);
>>> +bool sdl2_gl_has_dmabuf(DisplayChangeListener *dcl);
>>> +void sdl2_gl_console_init(struct sdl2_console *scon);
>>>
>>> #endif /* SDL2_H */
>>> diff --git a/meson.build b/meson.build
>>> index 3cd1d8dbc669..0ce84d45e6f3 100644
>>> --- a/meson.build
>>> +++ b/meson.build
>>> @@ -1937,10 +1937,8 @@ if get_option('gtk') \
>>> endif
>>> endif
>>>
>>> -x11 = not_found
>>> -if gtkx11.found()
>>> - x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found())
>>> -endif
>>> +x11 = dependency('x11', method: 'pkg-config', required: gtkx11.found())
>>> +
>>> png = not_found
>>> if get_option('png').allowed() and have_system
>>> png = dependency('libpng', version: '>=1.6.34', required: get_option('png'),
>>> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
>>> index fbac3edbc09d..697ba2169c34 100644
>>> --- a/ui/sdl2-gl.c
>>> +++ b/ui/sdl2-gl.c
>>> @@ -26,6 +26,8 @@
>>> */
>>>
>>> #include "qemu/osdep.h"
>>> +#include "qemu/main-loop.h"
>>> +#include "qemu/error-report.h"
>>> #include "ui/console.h"
>>> #include "ui/input.h"
>>> #include "ui/sdl2.h"
>>> @@ -250,3 +252,67 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
>>>
>>> SDL_GL_SwapWindow(scon->real_window);
>>> }
>>> +
>>> +void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl,
>>> + QemuDmaBuf *dmabuf)
>>> +{
>>> + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
>>> + const int *fds;
>>> +
>>> + assert(scon->opengl);
>>> + SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
>>> +
>>> + egl_dmabuf_import_texture(dmabuf);
>>> + if (!qemu_dmabuf_get_texture(dmabuf)) {
>>> + fds = qemu_dmabuf_get_fds(dmabuf, NULL);
>>> + error_report("%s: failed fd=%d", __func__, fds ? fds[0] : -1);
>>> + return;
>>> + }
>>> +
>>> + sdl2_gl_scanout_texture(dcl, qemu_dmabuf_get_texture(dmabuf), false,
>>> + qemu_dmabuf_get_width(dmabuf),
>>> + qemu_dmabuf_get_height(dmabuf),
>>> + 0, 0,
>>> + qemu_dmabuf_get_width(dmabuf),
>>> + qemu_dmabuf_get_height(dmabuf),
>>> + NULL);
>>> +
>>> + if (qemu_dmabuf_get_allow_fences(dmabuf)) {
>>> + scon->guest_fb.dmabuf = dmabuf;
>>> + }
>>> +}
>>> +
>>> +void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl,
>>> + QemuDmaBuf *dmabuf)
>>> +{
>>> + egl_dmabuf_release_texture(dmabuf);
>>> +}
>>> +
>>> +bool sdl2_gl_has_dmabuf(DisplayChangeListener *dcl)
>>> +{
>>> + struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
>>> +
>>> + return scon->has_dmabuf;
>>> +}
>>> +
>>> +void sdl2_gl_console_init(struct sdl2_console *scon)
>>> +{
>>> + bool hidden = scon->hidden;
>>> +
>>> + scon->hidden = true;
>>> + scon->surface = qemu_create_displaysurface(1, 1);
>>> + sdl2_window_create(scon);
>>> +
>>> + /*
>>> + * QEMU checks whether console supports dma-buf before switching
>>> + * to the console. To break this chicken-egg problem we pre-check
>>> + * dma-buf availability beforehand using a dummy SDL window.
>>> + */
>>> + scon->has_dmabuf = qemu_egl_has_dmabuf();
>>> +
>>> + sdl2_window_destroy(scon);
>>> + qemu_free_displaysurface(scon->surface);
>>> +
>>> + scon->surface = NULL;
>>> + scon->hidden = hidden;
>>> +}
>>> diff --git a/ui/sdl2.c b/ui/sdl2.c
>>> index 032dc14bc398..3bb2676f847b 100644
>>> --- a/ui/sdl2.c
>>> +++ b/ui/sdl2.c
>>> @@ -35,6 +35,10 @@
>>> #include "qemu/log.h"
>>> #include "qemu-main.h"
>>>
>>> +#ifdef CONFIG_X11
>>> +#include <X11/Xlib.h>
>>> +#endif
>>> +
>>> static int sdl2_num_outputs;
>>> static struct sdl2_console *sdl2_console;
>>>
>>> @@ -120,6 +124,9 @@ void sdl2_window_create(struct sdl2_console *scon)
>>> /* The SDL renderer is only used by sdl2-2D, when OpenGL is disabled */
>>> scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
>>> }
>>> +
>>> + qemu_egl_display = eglGetCurrentDisplay();
>>> +
>>
>> This fails on MacOS for some reason:
>>
>> o libsystem.a.p/ui_sdl2.c.o -c ../ui/sdl2.c
>> ../ui/sdl2.c:128:5: error: use of undeclared identifier 'qemu_egl_display'
>> 128 | qemu_egl_display = eglGetCurrentDisplay();
>> | ^
>> ../ui/sdl2.c:128:24: error: call to undeclared function
>> 'eglGetCurrentDisplay'; ISO C99 and later do not support implicit
>> function declarations [-Wimplicit-function-declaration]
>> 128 | qemu_egl_display = eglGetCurrentDisplay();
>> | ^
>> 2 errors generated.
>>
>> See: https://gitlab.com/stsquad/qemu/-/jobs/13340079105
>>
>> Not sure what the include differences are because --enable-sdl builds
>> fine on Linux.
>
> Please try with this change and let me know if you could squash it or I
> need to send a patch:
>
> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index 3bb2676f847b..2603b0c2bdd8 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -125,7 +125,9 @@ void sdl2_window_create(struct sdl2_console *scon)
> scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
> }
>
> +#ifdef CONFIG_OPENGL
> qemu_egl_display = eglGetCurrentDisplay();
> +#endif
>
> sdl_update_caption(scon);
> }
There is one remaining build failure for win64:
../ui/sdl2-gl.c: In function 'sdl2_gl_scanout_dmabuf':
../ui/sdl2-gl.c:265:5: error: implicit declaration of function 'egl_dmabuf_import_texture'; did you mean 'qemu_dmabuf_set_texture'? [-Wimplicit-function-declaration]
265 | egl_dmabuf_import_texture(dmabuf);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| qemu_dmabuf_set_texture
../ui/sdl2-gl.c:265:5: error: nested extern declaration of 'egl_dmabuf_import_texture' [-Werror=nested-externs]
../ui/sdl2-gl.c: In function 'sdl2_gl_release_dmabuf':
../ui/sdl2-gl.c:288:5: error: implicit declaration of function 'egl_dmabuf_release_texture'; did you mean 'qemu_dmabuf_set_texture'? [-Wimplicit-function-declaration]
288 | egl_dmabuf_release_texture(dmabuf);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| qemu_dmabuf_set_texture
../ui/sdl2-gl.c:288:5: error: nested extern declaration of 'egl_dmabuf_release_texture' [-Werror=nested-externs]
cc1: all warnings being treated as errors
See: https://gitlab.com/stsquad/qemu/-/jobs/13340078806
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2026-03-04 12:11 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 01/18] ui/gtk: Don't disable scanout when display is refreshed Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 02/18] ui/sdl2: " Dmitry Osipenko
2026-04-07 16:44 ` Stefan Weil via qemu development
2026-04-07 17:24 ` Alex Bennée
2026-04-08 13:47 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 03/18] ui/egl: Don't change bound GL context when creating new context Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 04/18] ui/gdk: Restore original context after new context creation Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 05/18] ui/sdl2: " Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions Dmitry Osipenko
2026-03-04 8:49 ` Alex Bennée
2026-03-04 10:33 ` Dmitry Osipenko
2026-03-04 11:40 ` Alex Bennée
2026-03-04 12:10 ` Alex Bennée
2026-03-04 12:11 ` Alex Bennée [this message]
2026-03-03 15:14 ` [PATCH v22 07/18] virtio-gpu: Ensure BHs are invoked only from main-loop thread Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 08/18] virtio-gpu: Handle virgl fence creation errors Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 09/18] virtio-gpu: Support asynchronous fencing Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 10/18] virtio-gpu: Support DRM native context Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 11/18] docs/system: virtio-gpu: Add link to Mesa VirGL doc Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 12/18] docs/system: virtio-gpu: Update Venus link Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 13/18] docs/system: virtio-gpu: Document host/guest requirements Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 14/18] virtio-gpu: Remove superfluous memory_region_set_enabled() Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 15/18] virtio-gpu: Validate hostmem mapping offset Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 16/18] virtio-gpu: Replace finish_unmapping with mapping_state Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 17/18] virtio-gpu: Destroy virgl resources on virtio-gpu reset Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 18/18] virtio-gpu: Support mapping hostmem blobs with map_fixed Dmitry Osipenko
2026-03-03 17:33 ` [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Alex Bennée
2026-03-03 19:26 ` Dmitry Osipenko
2026-03-04 6:10 ` Akihiko Odaki
2026-03-04 10:34 ` Dmitry Osipenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ms0npzfm.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=Jiqian.Chen@amd.com \
--cc=alexander.deucher@amd.com \
--cc=bob.beckett@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dmitry.osipenko@collabora.com \
--cc=gert.wollny@collabora.com \
--cc=gurchetansingh@chromium.org \
--cc=hi@alyssa.is \
--cc=honglei1.huang@amd.com \
--cc=julia.zhang@amd.com \
--cc=kraxel@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=pierre-eric.pelloux-prayer@amd.com \
--cc=qemu-devel@nongnu.org \
--cc=ray.huang@amd.com \
--cc=robdclark@gmail.com \
--cc=roger.pau@citrix.com \
--cc=slp@redhat.com \
--cc=stefano.stabellini@amd.com \
--cc=xenia.ragiadakou@amd.com \
--cc=zzyiwei@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.