* [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API
@ 2026-03-03 15:14 Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 01/18] ui/gtk: Don't disable scanout when display is refreshed Dmitry Osipenko
` (19 more replies)
0 siblings, 20 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Hello,
This is follow up to DRM native context v16 [1] and MAP_FIXED API v10 [2]
virtio-gpu patches that has been reviewed previously and were waiting for
a new release of libvirglrenderer 1.3.0.
[1] https://lore.kernel.org/qemu-devel/20251116125641.2255794-1-dmitry.osipenko@collabora.com/
[2] https://lore.kernel.org/qemu-devel/20260118162856.223796-1-dmitry.osipenko@collabora.com/
Changelog:
v22:- Added r-b from Marc-André Lureau to ui/gdk patch.
- Corrected qemu_egl_create_context() to take explicit shared GL context
arg needed by gtk-egl display, as was suggested by Akihiko Odaki.
- Changed virtio-gpu BHs to use re-entrance guard as was suggested by
Akihiko Odaki.
v21:- Moved virtio-gpu to use iohandler_get_aio_context() as was
suggested by Akihiko Odaki.
- Updated EGL context-create helper and displays using it to make
helper take care of using appropriate parent GL context by itself,
without a need to switch GL context. Done it all in a single patch:
ui/egl: Don't change bound GL context when creating new context
- Cleaned up GDK context-restoring code as was suggested by Akihiko Odaki.
v20:- Adanbonded GL context unbinding approach as it created difficulties
with GTK assuming UI toolkit processed from a single thread. Omitted
all unbind-context patches and added new patch instead that makes
virtio-gpu to process cmds only from main-loop thread:
virtio-gpu: Bounce virtio_gpu_ctrl_bh() to main-loop thread
- Added r-b from Akihiko Odaki to reviewed v19 patches.
- Added patches restoring GL context when new ctx created for
dbus/spice/egl-headless displays.
v19:- Further improved improved naming of functions and terminology RE
GL context binding. Suggested by Akihiko Odaki.
- Added new patch "ui/gdk: Restore original context after new context
creation" in addition to improved "ui/sdl2: Restore original context"
that now getd actual bound GL context and restores to it instead
of restoring to the console's ctx, for consistency with the rest
of GL context management fixes that ensure context is bound only
when necessary.
- Improved virtio_gpu_virgl_update_render_state() with force_ctx_0()
and unbind_ctx() to make deferred GPU resetting maintain bound GL
context properly.
v18:- Changed dpy_gl_ctx_make_current() to use first scanout when unsetting
virgl's GL ctx0 and improved naming of cmd-processing function.
Suggested by Akihiko Odaki.
- Added "ui/gdk: Unset context after GL operations" patch after
realizing GDK/GL code needed more gdk_gl_context_clear_current().
v17:- Rebased patches on recent upstream, updated doc patches with new
drm native contexts supported by libvirglrenderer.
- Applied minor change that was requested from Akihiko Odaki
by moving virtio_gpu_device_realize() for MAP_FIXED v10.
- Added virtio_gpu_virgl_update_render_state() to virtio_gpu_fence_poll()
that was missed in MAP_FIXED v10.
- Added new patches fixing another GL context switching problem I ran
into recently with virgl commands unexpectedly processed from CPU
thread instead main-loop:
ui/sdl2: Unset context after GL operations
ui/gtk-egl: Unset context after GL operations
virtio-gpu: Unset context after GL operations
Alex Bennée (1):
docs/system: virtio-gpu: Document host/guest requirements
Dmitry Osipenko (16):
ui/gtk: Don't disable scanout when display is refreshed
ui/sdl2: Don't disable scanout when display is refreshed
ui/egl: Don't change bound GL context when creating new context
ui/gdk: Restore original context after new context creation
ui/sdl2: Restore original context after new context creation
virtio-gpu: Ensure BHs are invoked only from main-loop thread
virtio-gpu: Handle virgl fence creation errors
virtio-gpu: Support asynchronous fencing
virtio-gpu: Support DRM native context
docs/system: virtio-gpu: Add link to Mesa VirGL doc
docs/system: virtio-gpu: Update Venus link
virtio-gpu: Remove superfluous memory_region_set_enabled()
virtio-gpu: Validate hostmem mapping offset
virtio-gpu: Replace finish_unmapping with mapping_state
virtio-gpu: Destroy virgl resources on virtio-gpu reset
virtio-gpu: Support mapping hostmem blobs with map_fixed
Pierre-Eric Pelloux-Prayer (1):
ui/sdl2: Implement dpy dmabuf functions
docs/system/devices/virtio/virtio-gpu.rst | 121 ++++++-
hw/display/trace-events | 2 +-
hw/display/virtio-gpu-gl.c | 62 +++-
hw/display/virtio-gpu-virgl.c | 410 ++++++++++++++++++++--
hw/display/virtio-gpu.c | 21 +-
hw/virtio/virtio.c | 10 +
include/hw/virtio/virtio-gpu.h | 23 +-
include/hw/virtio/virtio.h | 10 +
include/ui/egl-context.h | 3 +-
include/ui/sdl2.h | 7 +
meson.build | 8 +-
ui/dbus.c | 4 +-
ui/egl-context.c | 6 +-
ui/egl-headless.c | 4 +-
ui/gtk-egl.c | 5 +-
ui/gtk-gl-area.c | 13 +-
ui/sdl2-gl.c | 74 +++-
ui/sdl2.c | 42 +++
ui/spice-display.c | 4 +-
19 files changed, 735 insertions(+), 94 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH v22 01/18] ui/gtk: Don't disable scanout when display is refreshed
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 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 02/18] ui/sdl2: " Dmitry Osipenko
` (18 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Display refreshment is invoked by a timer and it erroneously disables
the active scanout if it happens to be invoked after scanout has been
enabled. This offending scanout-disable race condition with a timer
can be easily hit when Qemu runs with a disabled vsync by using SDL or
GTK displays (with vblank_mode=0 for GTK). Refreshment of display's
content shouldn't disable the active display. Fix it by keeping the
scanout's state unchanged when display is redrawn.
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>
Acked-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>
---
ui/gtk-egl.c | 1 -
ui/gtk-gl-area.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index ae9239999cdb..0dbb429958e5 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -180,7 +180,6 @@ void gd_egl_refresh(DisplayChangeListener *dcl)
if (vc->gfx.glupdates) {
vc->gfx.glupdates = 0;
- gtk_egl_set_scanout_mode(vc, false);
gd_egl_draw(vc);
}
}
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index cd86022d264a..c709b2ce0f63 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -199,7 +199,6 @@ void gd_gl_area_refresh(DisplayChangeListener *dcl)
if (vc->gfx.glupdates) {
vc->gfx.glupdates = 0;
- gtk_gl_area_set_scanout_mode(vc, false);
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
}
}
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 02/18] ui/sdl2: Don't disable scanout when display is refreshed
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 ` Dmitry Osipenko
2026-04-07 16:44 ` Stefan Weil via qemu development
2026-03-03 15:14 ` [PATCH v22 03/18] ui/egl: Don't change bound GL context when creating new context Dmitry Osipenko
` (17 subsequent siblings)
19 siblings, 1 reply; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Display refreshment is invoked by a timer and it erroneously disables
the active scanout if it happens to be invoked after scanout has been
enabled. This offending scanout-disable race condition with a timer
can be easily hit when Qemu runs with a disabled vsync by using SDL or
GTK displays (with vblank_mode=0 for GTK). Refreshment of display's
content shouldn't disable the active display. Fix it by keeping the
scanout's state unchanged when display is redrawn.
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>
Acked-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>
---
ui/sdl2-gl.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 3be17d1079af..5eca0248233e 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -51,7 +51,6 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
int ww, wh;
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
- sdl2_set_scanout_mode(scon, false);
SDL_GetWindowSize(scon->real_window, &ww, &wh);
surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 03/18] ui/egl: Don't change bound GL context when creating new context
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-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 04/18] ui/gdk: Restore original context after new context creation Dmitry Osipenko
` (16 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Don't change bound GL context when creating new GL context for consistency
with behavior expected by virglrenderer that assumes context-creation doesn't
switch context. eglCreateContext() doesn't require GL context to be bound
when it's invoked. Update qemu_egl_create_context() to spawn GL sub-contexts
from a given shared GL context instead of a currently-bound context.
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
include/ui/egl-context.h | 3 ++-
ui/dbus.c | 4 +---
ui/egl-context.c | 6 +++---
ui/egl-headless.c | 4 +---
ui/gtk-egl.c | 4 +---
ui/spice-display.c | 4 +---
6 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/include/ui/egl-context.h b/include/ui/egl-context.h
index c2761d747a4e..4d559ae7bd46 100644
--- a/include/ui/egl-context.h
+++ b/include/ui/egl-context.h
@@ -5,7 +5,8 @@
#include "ui/egl-helpers.h"
QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
- QEMUGLParams *params);
+ QEMUGLParams *params,
+ EGLContext share_context);
void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx);
int qemu_egl_make_context_current(DisplayGLCtx *dgc,
QEMUGLContext ctx);
diff --git a/ui/dbus.c b/ui/dbus.c
index 905ee6fea71b..4f24215555a4 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -47,9 +47,7 @@ static DBusDisplay *dbus_display;
static QEMUGLContext dbus_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
- eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
- qemu_egl_rn_ctx);
- return qemu_egl_create_context(dgc, params);
+ return qemu_egl_create_context(dgc, params, qemu_egl_rn_ctx);
}
static bool
diff --git a/ui/egl-context.c b/ui/egl-context.c
index aed3e3ba1f3f..5787199347bc 100644
--- a/ui/egl-context.c
+++ b/ui/egl-context.c
@@ -3,7 +3,8 @@
#include "ui/egl-context.h"
QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
- QEMUGLParams *params)
+ QEMUGLParams *params,
+ EGLContext share_context)
{
EGLContext ctx;
EGLint ctx_att_core[] = {
@@ -19,8 +20,7 @@ QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
};
bool gles = (qemu_egl_mode == DISPLAY_GL_MODE_ES);
- ctx = eglCreateContext(qemu_egl_display, qemu_egl_config,
- eglGetCurrentContext(),
+ ctx = eglCreateContext(qemu_egl_display, qemu_egl_config, share_context,
gles ? ctx_att_gles : ctx_att_core);
return ctx;
}
diff --git a/ui/egl-headless.c b/ui/egl-headless.c
index 1f6b845500dd..352b30b43fb9 100644
--- a/ui/egl-headless.c
+++ b/ui/egl-headless.c
@@ -42,9 +42,7 @@ static void egl_gfx_switch(DisplayChangeListener *dcl,
static QEMUGLContext egl_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
- eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
- qemu_egl_rn_ctx);
- return qemu_egl_create_context(dgc, params);
+ return qemu_egl_create_context(dgc, params, qemu_egl_rn_ctx);
}
static void egl_scanout_disable(DisplayChangeListener *dcl)
diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c
index 0dbb429958e5..1b5c1d4533c0 100644
--- a/ui/gtk-egl.c
+++ b/ui/gtk-egl.c
@@ -219,9 +219,7 @@ QEMUGLContext gd_egl_create_context(DisplayGLCtx *dgc,
{
VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
- eglMakeCurrent(qemu_egl_display, vc->gfx.esurface,
- vc->gfx.esurface, vc->gfx.ectx);
- return qemu_egl_create_context(dgc, params);
+ return qemu_egl_create_context(dgc, params, vc->gfx.ectx);
}
void gd_egl_scanout_disable(DisplayChangeListener *dcl)
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 28399f8a8174..5052f371f44e 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -1033,9 +1033,7 @@ static void spice_gl_switch(DisplayChangeListener *dcl,
static QEMUGLContext qemu_spice_gl_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
- eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
- qemu_egl_rn_ctx);
- return qemu_egl_create_context(dgc, params);
+ return qemu_egl_create_context(dgc, params, qemu_egl_rn_ctx);
}
static void qemu_spice_gl_scanout_disable(DisplayChangeListener *dcl)
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 04/18] ui/gdk: Restore original context after new context creation
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (2 preceding siblings ...)
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 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 05/18] ui/sdl2: " Dmitry Osipenko
` (15 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Get currently bound GL context when creating new GL context and restore
it after the creation for consistency with behavior expected by virglrenderer
that assumes context-creation doesn't switch context.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
ui/gtk-gl-area.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index c709b2ce0f63..ce49000d3f17 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -250,11 +250,13 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
VirtualConsole *vc = container_of(dgc, VirtualConsole, gfx.dgc);
+ GdkGLContext *ctx, *current_ctx;
GdkWindow *window;
- GdkGLContext *ctx;
GError *err = NULL;
int major, minor;
+ current_ctx = gdk_gl_context_get_current();
+
window = gtk_widget_get_window(vc->gfx.drawing_area);
ctx = gdk_window_create_gl_context(window, &err);
if (err) {
@@ -275,8 +277,12 @@ QEMUGLContext gd_gl_area_create_context(DisplayGLCtx *dgc,
gdk_gl_context_make_current(ctx);
gdk_gl_context_get_version(ctx, &major, &minor);
- gdk_gl_context_clear_current();
- gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
+
+ if (current_ctx) {
+ gdk_gl_context_make_current(current_ctx);
+ } else {
+ gdk_gl_context_clear_current();
+ }
if (gd_cmp_gl_context_version(major, minor, params) == -1) {
/* created ctx version < requested version */
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 05/18] ui/sdl2: Restore original context after new context creation
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (3 preceding siblings ...)
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 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions Dmitry Osipenko
` (14 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
SDL API changes GL context to a newly created GL context, which differs
from other GL providers that don't switch context. Change SDL backend to
restore the original GL context. This allows Qemu's virtio-gpu to support
new virglrenderer async-fencing feature for Virgl contexts, otherwise
virglrenderer's vrend creates a fence-sync context on the Qemu's
main-loop thread that erroneously stays in-use by the main-loop after
creation, not allowing vrend's fence-sync thread switch to this new
context that belongs to it.
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>
Acked-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>
---
ui/sdl2-gl.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 5eca0248233e..fbac3edbc09d 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -139,10 +139,12 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
QEMUGLParams *params)
{
struct sdl2_console *scon = container_of(dgc, struct sdl2_console, dgc);
- SDL_GLContext ctx;
+ SDL_GLContext ctx, current_ctx;
assert(scon->opengl);
+ current_ctx = SDL_GL_GetCurrentContext();
+
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
@@ -167,6 +169,9 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
SDL_GL_CONTEXT_PROFILE_ES);
ctx = SDL_GL_CreateContext(scon->real_window);
}
+
+ SDL_GL_MakeCurrent(scon->real_window, current_ctx);
+
return (QEMUGLContext)ctx;
}
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (4 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 05/18] ui/sdl2: " Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-04 8:49 ` Alex Bennée
2026-03-03 15:14 ` [PATCH v22 07/18] virtio-gpu: Ensure BHs are invoked only from main-loop thread Dmitry Osipenko
` (13 subsequent siblings)
19 siblings, 1 reply; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
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();
+
sdl_update_caption(scon);
}
@@ -808,6 +815,10 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
.dpy_gl_scanout_disable = sdl2_gl_scanout_disable,
.dpy_gl_scanout_texture = sdl2_gl_scanout_texture,
.dpy_gl_update = sdl2_gl_scanout_flush,
+
+ .dpy_gl_scanout_dmabuf = sdl2_gl_scanout_dmabuf,
+ .dpy_gl_release_dmabuf = sdl2_gl_release_dmabuf,
+ .dpy_has_dmabuf = sdl2_gl_has_dmabuf,
};
static bool
@@ -835,6 +846,35 @@ static void sdl2_display_early_init(DisplayOptions *o)
}
}
+static void sdl2_set_hint_x11_force_egl(void)
+{
+#if defined(SDL_HINT_VIDEO_X11_FORCE_EGL) && defined(CONFIG_OPENGL) && \
+ defined(CONFIG_X11)
+ Display *x_disp = XOpenDisplay(NULL);
+ EGLDisplay egl_display;
+
+ if (!x_disp) {
+ return;
+ }
+
+ /* Prefer EGL over GLX to get dma-buf support. */
+ egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp);
+
+ if (egl_display != EGL_NO_DISPLAY) {
+ /*
+ * Setting X11_FORCE_EGL hint doesn't make SDL to prefer X11 over
+ * Wayland. SDL will use Wayland driver even if XWayland presents.
+ * It's always safe to set the hint even if X11 is not used by SDL.
+ * SDL will work regardless of the hint.
+ */
+ SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
+ eglTerminate(egl_display);
+ }
+
+ XCloseDisplay(x_disp);
+#endif
+}
+
static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
{
uint8_t data = 0;
@@ -862,6 +902,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
#endif
SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
+ sdl2_set_hint_x11_force_egl();
SDL_EnableScreenSaver();
memset(&info, 0, sizeof(info));
SDL_VERSION(&info.version);
@@ -908,6 +949,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
sdl2_console[i].kbd = qkbd_state_init(con);
if (display_opengl) {
qemu_console_set_display_gl_ctx(con, &sdl2_console[i].dgc);
+ sdl2_gl_console_init(&sdl2_console[i]);
}
register_displaychangelistener(&sdl2_console[i].dcl);
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 07/18] virtio-gpu: Ensure BHs are invoked only from main-loop thread
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (5 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 08/18] virtio-gpu: Handle virgl fence creation errors Dmitry Osipenko
` (12 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
QEMU's display GL core is tied to main-loop thread and virtio-gpu
interacts with display while processing GPU commands. Virtio-gpu BHs
work in generic AIO context that can be invoked on vCPU thread, while
GL and UI toolkits are bound to the main-loop thread.
Make virtio-gpu BHs use iohandler AIO context that is handled in a
main-loop thread only.
0 SDL_GL_MakeCurrent() (libSDL3)
1 SDL_GL_MakeCurrent_REAL() (libSDL2)
2 sdl2_gl_make_context_current() (ui/sdl2-gl.c:201)
3 make_current() (virglrenderer.c:639)
4 vrend_finish_context_switch() (vrend_renderer.c:11630)
5 vrend_hw_switch_context() (vrend_renderer.c:11613)
6 vrend_renderer_force_ctx_0() (vrend_renderer.c:12986)
7 virgl_renderer_force_ctx_0() (virglrenderer.c:460)
8 virtio_gpu_virgl_process_cmd() (virtio-gpu-virgl.c:1013)
9 virtio_gpu_process_cmdq() (virtio-gpu.c:1050)
10 virtio_gpu_gl_handle_ctrl() (virtio-gpu-gl.c:86)
11 aio_bh_poll() (util/async.c)
12 aio_poll() (util/aio-posix.c)
13 blk_pwrite() (block/block-gen.c:1985)
14 pflash_update() (pflash_cfi01.c:396)
15 pflash_write() (pflash_cfi01.c:541)
16 memory_region_dispatch_write() (system/memory.c:1554)
17 flatview_write() (system/physmem.c:3333)
18 address_space_write() (system/physmem.c:3453)
19 kvm_cpu_exec() (accel/kvm/kall-all.c:3248)
20 kvm_vcpu_thread_fn() (accel/kvm/kaccel-ops.c:53)
Cc: qemu-stable@nongnu.org
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-virgl.c | 6 +++---
hw/display/virtio-gpu.c | 6 +++---
hw/virtio/virtio.c | 10 ++++++++++
include/hw/virtio/virtio.h | 10 ++++++++++
4 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 0f754829fb71..10c4b5160f40 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -1203,9 +1203,9 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
}
#if VIRGL_VERSION_MAJOR >= 1
- gl->cmdq_resume_bh = aio_bh_new(qemu_get_aio_context(),
- virtio_gpu_virgl_resume_cmdq_bh,
- g);
+ gl->cmdq_resume_bh = virtio_bh_io_new_guarded(DEVICE(g),
+ virtio_gpu_virgl_resume_cmdq_bh,
+ g);
#endif
return 0;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 643e91ca2a7a..38c922e4eba3 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -1526,9 +1526,9 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
g->ctrl_vq = virtio_get_queue(vdev, 0);
g->cursor_vq = virtio_get_queue(vdev, 1);
- g->ctrl_bh = virtio_bh_new_guarded(qdev, virtio_gpu_ctrl_bh, g);
- g->cursor_bh = virtio_bh_new_guarded(qdev, virtio_gpu_cursor_bh, g);
- g->reset_bh = qemu_bh_new(virtio_gpu_reset_bh, g);
+ g->ctrl_bh = virtio_bh_io_new_guarded(qdev, virtio_gpu_ctrl_bh, g);
+ g->cursor_bh = virtio_bh_io_new_guarded(qdev, virtio_gpu_cursor_bh, g);
+ g->reset_bh = virtio_bh_io_new_guarded(qdev, virtio_gpu_reset_bh, g);
qemu_cond_init(&g->reset_cond);
QTAILQ_INIT(&g->reslist);
QTAILQ_INIT(&g->cmdq);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index e9d553295257..7c4868330752 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -4497,3 +4497,13 @@ QEMUBH *virtio_bh_new_guarded_full(DeviceState *dev,
return qemu_bh_new_full(cb, opaque, name,
&transport->mem_reentrancy_guard);
}
+
+QEMUBH *virtio_bh_io_new_guarded_full(DeviceState *dev,
+ QEMUBHFunc *cb, void *opaque,
+ const char *name)
+{
+ DeviceState *transport = qdev_get_parent_bus(dev)->parent;
+
+ return aio_bh_new_full(iohandler_get_aio_context(), cb, opaque, name,
+ &transport->mem_reentrancy_guard);
+}
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 9dd93cf965ae..6fb823f241fd 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -547,4 +547,14 @@ QEMUBH *virtio_bh_new_guarded_full(DeviceState *dev,
#define virtio_bh_new_guarded(dev, cb, opaque) \
virtio_bh_new_guarded_full((dev), (cb), (opaque), (stringify(cb)))
+/*
+ * The "_io" variant runs BH only on a main-loop thread, while generic BH
+ * may run on a vCPU thread.
+ */
+QEMUBH *virtio_bh_io_new_guarded_full(DeviceState *dev,
+ QEMUBHFunc *cb, void *opaque,
+ const char *name);
+#define virtio_bh_io_new_guarded(dev, cb, opaque) \
+ virtio_bh_io_new_guarded_full((dev), (cb), (opaque), (stringify(cb)))
+
#endif
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 08/18] virtio-gpu: Handle virgl fence creation errors
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (6 preceding siblings ...)
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 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 09/18] virtio-gpu: Support asynchronous fencing Dmitry Osipenko
` (11 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Print out error messages when virgl fence creation fails to aid debugging
of the fence-related bugs.
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>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Yiwei Zhang <zzyiwei@gmail.com>
Tested-by: Yiwei Zhang <zzyiwei@gmail.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-virgl.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 10c4b5160f40..f00c666f61f4 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -900,6 +900,7 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd)
{
bool cmd_suspended = false;
+ int ret;
VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr);
@@ -1000,14 +1001,30 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
#if VIRGL_VERSION_MAJOR >= 1
if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) {
- virgl_renderer_context_create_fence(cmd->cmd_hdr.ctx_id,
- VIRGL_RENDERER_FENCE_FLAG_MERGEABLE,
- cmd->cmd_hdr.ring_idx,
- cmd->cmd_hdr.fence_id);
+ const uint32_t flags = VIRGL_RENDERER_FENCE_FLAG_MERGEABLE;
+
+ ret = virgl_renderer_context_create_fence(cmd->cmd_hdr.ctx_id, flags,
+ cmd->cmd_hdr.ring_idx,
+ cmd->cmd_hdr.fence_id);
+ if (ret) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: virgl_renderer_context_create_fence error: %s",
+ __func__, strerror(-ret));
+ }
return;
}
#endif
- virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
+
+ /*
+ * Unlike other virglrenderer functions, this one returns a positive
+ * error code.
+ */
+ ret = virgl_renderer_create_fence(cmd->cmd_hdr.fence_id, 0);
+ if (ret) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: virgl_renderer_create_fence error: %s",
+ __func__, strerror(ret));
+ }
}
static void virgl_write_fence(void *opaque, uint32_t fence)
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 09/18] virtio-gpu: Support asynchronous fencing
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (7 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 08/18] virtio-gpu: Handle virgl fence creation errors Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 10/18] virtio-gpu: Support DRM native context Dmitry Osipenko
` (10 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Support asynchronous fencing feature of virglrenderer. It allows Qemu to
handle fence as soon as it's signalled instead of periodically polling
the fence status. This feature is required for enabling DRM context
support in Qemu because legacy fencing mode isn't supported for DRM
contexts in virglrenderer.
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>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Yiwei Zhang <zzyiwei@gmail.com>
Tested-by: Yiwei Zhang <zzyiwei@gmail.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-gl.c | 5 ++
hw/display/virtio-gpu-virgl.c | 127 +++++++++++++++++++++++++++++++++
include/hw/virtio/virtio-gpu.h | 11 +++
meson.build | 2 +
4 files changed, 145 insertions(+)
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index b98ef2ef9877..3e0680880e14 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -169,6 +169,11 @@ static void virtio_gpu_gl_device_unrealize(DeviceState *qdev)
if (gl->renderer_state >= RS_INITED) {
#if VIRGL_VERSION_MAJOR >= 1
qemu_bh_delete(gl->cmdq_resume_bh);
+
+ if (gl->async_fence_bh) {
+ virtio_gpu_virgl_reset_async_fences(g);
+ qemu_bh_delete(gl->async_fence_bh);
+ }
#endif
if (virtio_gpu_stats_enabled(g->parent_obj.conf)) {
timer_free(gl->print_stats);
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index f00c666f61f4..ae1880c358b2 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -24,6 +24,23 @@
#include <virglrenderer.h>
+/*
+ * VIRGL_CHECK_VERSION available since libvirglrenderer 1.0.1 and was fixed
+ * in 1.1.0. Undefine bugged version of the macro and provide our own.
+ */
+#if defined(VIRGL_CHECK_VERSION) && \
+ VIRGL_VERSION_MAJOR == 1 && VIRGL_VERSION_MINOR < 1
+#undef VIRGL_CHECK_VERSION
+#endif
+
+#ifndef VIRGL_CHECK_VERSION
+#define VIRGL_CHECK_VERSION(major, minor, micro) \
+ (VIRGL_VERSION_MAJOR > (major) || \
+ VIRGL_VERSION_MAJOR == (major) && VIRGL_VERSION_MINOR > (minor) || \
+ VIRGL_VERSION_MAJOR == (major) && VIRGL_VERSION_MINOR == (minor) && \
+ VIRGL_VERSION_MICRO >= (micro))
+#endif
+
struct virtio_gpu_virgl_resource {
struct virtio_gpu_simple_resource base;
MemoryRegion *mr;
@@ -1079,6 +1096,103 @@ static void virgl_write_context_fence(void *opaque, uint32_t ctx_id,
}
#endif
+void virtio_gpu_virgl_reset_async_fences(VirtIOGPU *g)
+{
+ struct virtio_gpu_virgl_context_fence *f;
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+
+ while (!QSLIST_EMPTY(&gl->async_fenceq)) {
+ f = QSLIST_FIRST(&gl->async_fenceq);
+
+ QSLIST_REMOVE_HEAD(&gl->async_fenceq, next);
+
+ g_free(f);
+ }
+}
+
+#if VIRGL_CHECK_VERSION(1, 1, 2)
+static void virtio_gpu_virgl_async_fence_bh(void *opaque)
+{
+ QSLIST_HEAD(, virtio_gpu_virgl_context_fence) async_fenceq;
+ struct virtio_gpu_ctrl_command *cmd, *tmp;
+ struct virtio_gpu_virgl_context_fence *f;
+ VirtIOGPU *g = opaque;
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+
+ if (gl->renderer_state != RS_INITED) {
+ return;
+ }
+
+ QSLIST_MOVE_ATOMIC(&async_fenceq, &gl->async_fenceq);
+
+ while (!QSLIST_EMPTY(&async_fenceq)) {
+ f = QSLIST_FIRST(&async_fenceq);
+
+ QSLIST_REMOVE_HEAD(&async_fenceq, next);
+
+ QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) {
+ /*
+ * the guest can end up emitting fences out of order
+ * so we should check all fenced cmds not just the first one.
+ */
+ if (cmd->cmd_hdr.fence_id > f->fence_id) {
+ continue;
+ }
+ if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_INFO_RING_IDX) {
+ if (cmd->cmd_hdr.ring_idx != f->ring_idx) {
+ continue;
+ }
+ if (cmd->cmd_hdr.ctx_id != f->ctx_id) {
+ continue;
+ }
+ }
+ virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA);
+ QTAILQ_REMOVE(&g->fenceq, cmd, next);
+ g_free(cmd);
+ }
+
+ trace_virtio_gpu_fence_resp(f->fence_id);
+ g_free(f);
+ g->inflight--;
+ if (virtio_gpu_stats_enabled(g->parent_obj.conf)) {
+ trace_virtio_gpu_dec_inflight_fences(g->inflight);
+ }
+ }
+}
+
+static void
+virtio_gpu_virgl_push_async_fence(VirtIOGPU *g, uint32_t ctx_id,
+ uint32_t ring_idx, uint64_t fence_id)
+{
+ struct virtio_gpu_virgl_context_fence *f;
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+
+ f = g_new(struct virtio_gpu_virgl_context_fence, 1);
+ f->ctx_id = ctx_id;
+ f->ring_idx = ring_idx;
+ f->fence_id = fence_id;
+
+ QSLIST_INSERT_HEAD_ATOMIC(&gl->async_fenceq, f, next);
+
+ qemu_bh_schedule(gl->async_fence_bh);
+}
+
+static void virgl_write_async_fence(void *opaque, uint32_t fence)
+{
+ VirtIOGPU *g = opaque;
+
+ virtio_gpu_virgl_push_async_fence(g, 0, UINT32_MAX, fence);
+}
+
+static void virgl_write_async_context_fence(void *opaque, uint32_t ctx_id,
+ uint32_t ring_idx, uint64_t fence)
+{
+ VirtIOGPU *g = opaque;
+
+ virtio_gpu_virgl_push_async_fence(g, ctx_id, ring_idx, fence);
+}
+#endif
+
static virgl_renderer_gl_context
virgl_create_context(void *opaque, int scanout_idx,
struct virgl_renderer_gl_ctx_param *params)
@@ -1178,6 +1292,8 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
void virtio_gpu_virgl_reset(VirtIOGPU *g)
{
virgl_renderer_reset();
+
+ virtio_gpu_virgl_reset_async_fences(g);
}
int virtio_gpu_virgl_init(VirtIOGPU *g)
@@ -1190,6 +1306,12 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
if (qemu_egl_display) {
virtio_gpu_3d_cbs.version = 4;
virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
+#if VIRGL_CHECK_VERSION(1, 1, 2)
+ virtio_gpu_3d_cbs.write_fence = virgl_write_async_fence;
+ virtio_gpu_3d_cbs.write_context_fence = virgl_write_async_context_fence;
+ flags |= VIRGL_RENDERER_ASYNC_FENCE_CB;
+ flags |= VIRGL_RENDERER_THREAD_SYNC;
+#endif
}
#endif
#ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE
@@ -1223,6 +1345,11 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
gl->cmdq_resume_bh = virtio_bh_io_new_guarded(DEVICE(g),
virtio_gpu_virgl_resume_cmdq_bh,
g);
+#if VIRGL_CHECK_VERSION(1, 1, 2)
+ gl->async_fence_bh = virtio_bh_io_new_guarded(DEVICE(g),
+ virtio_gpu_virgl_async_fence_bh,
+ g);
+#endif
#endif
return 0;
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 58e0f91fda65..16e9f6914f07 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -233,6 +233,13 @@ struct VirtIOGPUClass {
Error **errp);
};
+struct virtio_gpu_virgl_context_fence {
+ uint32_t ctx_id;
+ uint32_t ring_idx;
+ uint64_t fence_id;
+ QSLIST_ENTRY(virtio_gpu_virgl_context_fence) next;
+};
+
/* VirtIOGPUGL renderer states */
typedef enum {
RS_START, /* starting state */
@@ -250,6 +257,9 @@ struct VirtIOGPUGL {
QEMUTimer *print_stats;
QEMUBH *cmdq_resume_bh;
+
+ QEMUBH *async_fence_bh;
+ QSLIST_HEAD(, virtio_gpu_virgl_context_fence) async_fenceq;
};
struct VhostUserGPU {
@@ -379,5 +389,6 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g);
void virtio_gpu_virgl_reset(VirtIOGPU *g);
int virtio_gpu_virgl_init(VirtIOGPU *g);
GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g);
+void virtio_gpu_virgl_reset_async_fences(VirtIOGPU *g);
#endif
diff --git a/meson.build b/meson.build
index 0ce84d45e6f3..a8ed44d6b065 100644
--- a/meson.build
+++ b/meson.build
@@ -2515,6 +2515,8 @@ config_host_data.set('CONFIG_VNC_JPEG', jpeg.found())
config_host_data.set('CONFIG_VNC_SASL', sasl.found())
if virgl.found()
config_host_data.set('VIRGL_VERSION_MAJOR', virgl.version().split('.')[0])
+ config_host_data.set('VIRGL_VERSION_MINOR', virgl.version().split('.')[1])
+ config_host_data.set('VIRGL_VERSION_MICRO', virgl.version().split('.')[2])
endif
config_host_data.set('CONFIG_VIRTFS', have_virtfs)
config_host_data.set('CONFIG_VTE', vte.found())
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 10/18] virtio-gpu: Support DRM native context
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (8 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 09/18] virtio-gpu: Support asynchronous fencing Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 11/18] docs/system: virtio-gpu: Add link to Mesa VirGL doc Dmitry Osipenko
` (9 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Add support for DRM native contexts to VirtIO-GPU. DRM context is enabled
using a new virtio-gpu-gl device option "drm_native_context=on".
Unlike Virgl and Venus contexts that operate on application API level,
DRM native contexts work on a kernel UAPI level. This lower level results
in a lightweight context implementations that yield better performance.
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>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Yiwei Zhang <zzyiwei@gmail.com>
Tested-by: Yiwei Zhang <zzyiwei@gmail.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
docs/system/devices/virtio/virtio-gpu.rst | 11 +++++++++
hw/display/virtio-gpu-gl.c | 2 ++
hw/display/virtio-gpu-virgl.c | 28 +++++++++++++++++++++++
hw/display/virtio-gpu.c | 15 ++++++++++++
include/hw/virtio/virtio-gpu.h | 3 +++
5 files changed, 59 insertions(+)
diff --git a/docs/system/devices/virtio/virtio-gpu.rst b/docs/system/devices/virtio/virtio-gpu.rst
index 0f4bb304a9b8..086e2fcf27b9 100644
--- a/docs/system/devices/virtio/virtio-gpu.rst
+++ b/docs/system/devices/virtio/virtio-gpu.rst
@@ -84,6 +84,17 @@ of virtio-gpu host memory window. This is typically between 256M and 8G.
.. _venus: https://gitlab.freedesktop.org/virgl/venus-protocol/
+DRM native context is supported since release of `virglrenderer`_ v1.0.0
+using `drm`_ protocol. ``DRM`` virtio-gpu capability set ("capset") requires
+host blob support (``hostmem`` and ``blob`` fields) and should be enabled
+using ``drm_native_context`` field. The ``hostmem`` field specifies the size
+of virtio-gpu host memory window. This is typically between 256M and 8G.
+
+.. parsed-literal::
+ -device virtio-gpu-gl,hostmem=8G,blob=on,drm_native_context=on
+
+.. _drm: https://gitlab.freedesktop.org/virgl/virglrenderer/-/tree/main/src/drm
+
virtio-gpu rutabaga
-------------------
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index 3e0680880e14..b941e9a4b789 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -159,6 +159,8 @@ static const Property virtio_gpu_gl_properties[] = {
VIRTIO_GPU_FLAG_STATS_ENABLED, false),
DEFINE_PROP_BIT("venus", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_VENUS_ENABLED, false),
+ DEFINE_PROP_BIT("drm_native_context", VirtIOGPU, parent_obj.conf.flags,
+ VIRTIO_GPU_FLAG_DRM_ENABLED, false),
};
static void virtio_gpu_gl_device_unrealize(DeviceState *qdev)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index ae1880c358b2..f5fe1bf4e73c 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -1323,6 +1323,25 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
}
+ if (virtio_gpu_drm_enabled(g->parent_obj.conf)) {
+ flags |= VIRGL_RENDERER_DRM;
+
+ if (!(flags & VIRGL_RENDERER_ASYNC_FENCE_CB)) {
+ /*
+ * Virglrenderer skips enabling DRM context support without
+ * enabled async-fence feature. VirtIO-GPU will initialize
+ * successfully, but DRM context won't be available in guest.
+ *
+ * For vrend async-fencing can be enabled only if EGL display
+ * is used. Vrend can't be disabled in QEMU, hence DRM implicitly
+ * requires EGL too.
+ *
+ * Async-fence was bugged in virglrenderer versions <= 1.1.1.
+ */
+ error_report("drm requires egl display and virglrenderer >= 1.2.0");
+ return -EINVAL;
+ }
+ }
#endif
ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs);
@@ -1386,5 +1405,14 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)
}
}
+ if (virtio_gpu_drm_enabled(g->parent_obj.conf)) {
+ virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_DRM,
+ &capset_max_ver,
+ &capset_max_size);
+ if (capset_max_size) {
+ virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_DRM);
+ }
+ }
+
return capset_ids;
}
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 38c922e4eba3..91e3b30fecde 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -1517,6 +1517,21 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
#endif
}
+ if (virtio_gpu_drm_enabled(g->parent_obj.conf)) {
+#ifdef VIRGL_VERSION_MAJOR
+ #if VIRGL_VERSION_MAJOR >= 1
+ if (!virtio_gpu_blob_enabled(g->parent_obj.conf) ||
+ !virtio_gpu_hostmem_enabled(g->parent_obj.conf)) {
+ error_setg(errp, "drm requires enabled blob and hostmem options");
+ return;
+ }
+ #else
+ error_setg(errp, "old virglrenderer, drm unsupported");
+ return;
+ #endif
+#endif
+ }
+
if (!virtio_gpu_base_device_realize(qdev,
virtio_gpu_handle_ctrl_cb,
virtio_gpu_handle_cursor_cb,
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 16e9f6914f07..718332284305 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -100,6 +100,7 @@ enum virtio_gpu_base_conf_flags {
VIRTIO_GPU_FLAG_RUTABAGA_ENABLED,
VIRTIO_GPU_FLAG_VENUS_ENABLED,
VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED,
+ VIRTIO_GPU_FLAG_DRM_ENABLED,
};
#define virtio_gpu_virgl_enabled(_cfg) \
@@ -122,6 +123,8 @@ enum virtio_gpu_base_conf_flags {
(_cfg.hostmem > 0)
#define virtio_gpu_venus_enabled(_cfg) \
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))
+#define virtio_gpu_drm_enabled(_cfg) \
+ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DRM_ENABLED))
struct virtio_gpu_base_conf {
uint32_t max_outputs;
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 11/18] docs/system: virtio-gpu: Add link to Mesa VirGL doc
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (9 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 10/18] virtio-gpu: Support DRM native context Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 12/18] docs/system: virtio-gpu: Update Venus link Dmitry Osipenko
` (8 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Extend virtio-gpu documentation with a link to the Mesa VirGL
documentation.
Suggested-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-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>
---
docs/system/devices/virtio/virtio-gpu.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/docs/system/devices/virtio/virtio-gpu.rst b/docs/system/devices/virtio/virtio-gpu.rst
index 086e2fcf27b9..89153103b9f8 100644
--- a/docs/system/devices/virtio/virtio-gpu.rst
+++ b/docs/system/devices/virtio/virtio-gpu.rst
@@ -61,7 +61,7 @@ on typical modern Linux distributions.
virtio-gpu virglrenderer
------------------------
-When using virgl accelerated graphics mode in the guest, OpenGL API calls
+When using `virgl`_ accelerated graphics mode in the guest, OpenGL API calls
are translated into an intermediate representation (see `Gallium3D`_). The
intermediate representation is communicated to the host and the
`virglrenderer`_ library on the host translates the intermediate
@@ -70,6 +70,7 @@ representation back to OpenGL API calls.
.. parsed-literal::
-device virtio-gpu-gl
+.. _virgl: https://docs.mesa3d.org/drivers/virgl.html
.. _Gallium3D: https://www.freedesktop.org/wiki/Software/gallium/
.. _virglrenderer: https://gitlab.freedesktop.org/virgl/virglrenderer/
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 12/18] docs/system: virtio-gpu: Update Venus link
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (10 preceding siblings ...)
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 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 13/18] docs/system: virtio-gpu: Document host/guest requirements Dmitry Osipenko
` (7 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Change virtio-gpu Venus link, pointing it at the Mesa Venus
documentation instead of the protocol. The Mesa doc provides more
information and also has a link to the protocol.
Suggested-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-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>
---
docs/system/devices/virtio/virtio-gpu.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/system/devices/virtio/virtio-gpu.rst b/docs/system/devices/virtio/virtio-gpu.rst
index 89153103b9f8..ef5fb0401d5d 100644
--- a/docs/system/devices/virtio/virtio-gpu.rst
+++ b/docs/system/devices/virtio/virtio-gpu.rst
@@ -83,7 +83,7 @@ of virtio-gpu host memory window. This is typically between 256M and 8G.
.. parsed-literal::
-device virtio-gpu-gl,hostmem=8G,blob=true,venus=true
-.. _venus: https://gitlab.freedesktop.org/virgl/venus-protocol/
+.. _venus: https://docs.mesa3d.org/drivers/venus.html
DRM native context is supported since release of `virglrenderer`_ v1.0.0
using `drm`_ protocol. ``DRM`` virtio-gpu capability set ("capset") requires
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 13/18] docs/system: virtio-gpu: Document host/guest requirements
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (11 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 12/18] docs/system: virtio-gpu: Update Venus link Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 14/18] virtio-gpu: Remove superfluous memory_region_set_enabled() Dmitry Osipenko
` (6 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
From: Alex Bennée <alex.bennee@linaro.org>
This attempts to tidy up the VirtIO GPU documentation to make the list
of requirements clearer. There are still a lot of moving parts and the
distros have some catching up to do before this is all handled
automatically.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Sergio Lopez Pascual <slp@redhat.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Acked-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>
[dmitry.osipenko@collabora.com: Extended and corrected doc]
---
docs/system/devices/virtio/virtio-gpu.rst | 105 +++++++++++++++++++++-
1 file changed, 102 insertions(+), 3 deletions(-)
diff --git a/docs/system/devices/virtio/virtio-gpu.rst b/docs/system/devices/virtio/virtio-gpu.rst
index ef5fb0401d5d..d05f8cb8e3f9 100644
--- a/docs/system/devices/virtio/virtio-gpu.rst
+++ b/docs/system/devices/virtio/virtio-gpu.rst
@@ -7,14 +7,28 @@ VirtIO GPU
==========
This document explains the setup and usage of the virtio-gpu device.
-The virtio-gpu device paravirtualizes the GPU and display controller.
+The virtio-gpu device provides a GPU and display controller
+paravirtualized using VirtIO. It supports a number of different modes
+from simple 2D displays to fully accelerated 3D graphics.
-Linux kernel support
---------------------
+Linux guest kernel support
+--------------------------
virtio-gpu requires a guest Linux kernel built with the
``CONFIG_DRM_VIRTIO_GPU`` option.
+3D acceleration
+---------------
+
+3D acceleration of a virtualized GPU is still an evolving field.
+Depending on the 3D mode you are running you may need to override
+distribution supplied libraries with more recent versions or enable
+build options. There are a number of requirements the host must meet
+to be able to be able to support guests. QEMU must be able to access the
+host's GPU and for the best performance be able to reliably share GPU
+memory with the guest. Details of 3D acceleration requirements are
+described in a further sections.
+
QEMU virtio-gpu variants
------------------------
@@ -67,8 +81,14 @@ intermediate representation is communicated to the host and the
`virglrenderer`_ library on the host translates the intermediate
representation back to OpenGL API calls.
+By default OpenGL version on guest is limited to 4.3. In order to enable
+OpenGL 4.6 support, virtio-gpu host blobs feature (``hostmem`` and ``blob``
+fields) should be enabled. The ``hostmem`` field specifies the size of
+virtio-gpu host memory window. This is typically between 256M and 8G.
+
.. parsed-literal::
-device virtio-gpu-gl
+ -device virtio-gpu-gl,hostmem=8G,blob=true
.. _virgl: https://docs.mesa3d.org/drivers/virgl.html
.. _Gallium3D: https://www.freedesktop.org/wiki/Software/gallium/
@@ -96,6 +116,67 @@ of virtio-gpu host memory window. This is typically between 256M and 8G.
.. _drm: https://gitlab.freedesktop.org/virgl/virglrenderer/-/tree/main/src/drm
+.. list-table:: Linux Host Requirements
+ :header-rows: 1
+
+ * - Capability
+ - Kernel Version
+ - Libvirglrenderer Version
+ * - OpenGL pass-through
+ - Any Linux version compatible with QEMU if not using host blobs feature,
+ Linux 6.13+ otherwise
+ - 0.8.2+
+ * - Vulkan pass-through
+ - Linux 6.13+
+ - 1.0.0+
+ * - AMDGPU DRM native context
+ - Linux 6.13+
+ - 1.1.0+
+ * - Freedreno DRM native context
+ - Linux 6.4+
+ - 1.0.0+
+ * - Intel i915 DRM native context
+ - Linux 6.13+
+ - 1.3.0+
+ * - Asahi DRM native context
+ - `Downstream version`_ of Asahi Linux kernel
+ - 1.2.0+
+ * - Panfrost native context
+ - Linux 6.13+
+ - 1.3.0+
+
+.. _Downstream version: https://github.com/AsahiLinux/linux
+
+.. list-table:: Linux Guest Requirements
+ :header-rows: 1
+
+ * - Capability
+ - Kernel Version
+ - Mesa Version
+ * - OpenGL pass-through
+ - Any Linux version supporting virtio-gpu
+ - 16.0.0+
+ * - Vulkan pass-through
+ - Linux 5.16+
+ - 24.2.0+
+ * - AMDGPU DRM native context
+ - Linux 6.14+
+ - 25.0.0+
+ * - Freedreno DRM native context
+ - Linux 6.14+
+ - 23.1.0+
+ * - Intel i915 DRM native context
+ - Linux 6.14+
+ - 26.1.0+
+ * - Asahi DRM native context
+ - Linux 6.14+
+ - 24.2.0+
+ * - Panfrost native context
+ - Linux 6.14+
+ - `mr36814`_
+
+.. _mr36814: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36814
+
virtio-gpu rutabaga
-------------------
@@ -135,3 +216,21 @@ Surfaceless is the default if ``wsi`` is not specified.
.. _Wayland display passthrough: https://www.youtube.com/watch?v=OZJiHMtIQ2M
.. _gfxstream-enabled rutabaga: https://crosvm.dev/book/appendix/rutabaga_gfx.html
.. _guest Wayland proxy: https://crosvm.dev/book/devices/wayland.html
+
+.. list-table:: Linux Host Requirements
+ :header-rows: 1
+
+ * - Capability
+ - Kernel Version
+ * - Vulkan+Wayland pass-through
+ - Linux 6.13+
+
+.. list-table:: Linux Guest Requirements
+ :header-rows: 1
+
+ * - Capability
+ - Kernel Version
+ - Mesa Version
+ * - Vulkan+Wayland pass-through
+ - Linux 5.16+
+ - 24.3.0+
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 14/18] virtio-gpu: Remove superfluous memory_region_set_enabled()
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (12 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 13/18] docs/system: virtio-gpu: Document host/guest requirements Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 15/18] virtio-gpu: Validate hostmem mapping offset Dmitry Osipenko
` (5 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
There is no need to explicitly enable/disable memory region when it's
added or deleted respectively. Remove superfluous set_enabled() calls
for consistency.
Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-virgl.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index f5fe1bf4e73c..abf7c176a65f 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -171,7 +171,6 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
mr = &vmr->mr;
memory_region_init_ram_ptr(mr, OBJECT(vmr), "mr", size, data);
memory_region_add_subregion(&b->hostmem, offset, mr);
- memory_region_set_enabled(mr, true);
res->mr = mr;
@@ -225,7 +224,6 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
b->renderer_blocked++;
/* memory region owns self res->mr object and frees it by itself */
- memory_region_set_enabled(mr, false);
memory_region_del_subregion(&b->hostmem, mr);
object_unparent(OBJECT(vmr));
}
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 15/18] virtio-gpu: Validate hostmem mapping offset
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (13 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 14/18] virtio-gpu: Remove superfluous memory_region_set_enabled() Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 16/18] virtio-gpu: Replace finish_unmapping with mapping_state Dmitry Osipenko
` (4 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Check hostmem mapping boundaries originated from guest.
Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-virgl.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index abf7c176a65f..f4d1113827e3 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -791,6 +791,7 @@ static void virgl_cmd_resource_map_blob(VirtIOGPU *g,
struct virtio_gpu_resource_map_blob mblob;
struct virtio_gpu_virgl_resource *res;
struct virtio_gpu_resp_map_info resp;
+ VirtIOGPUBase *b = VIRTIO_GPU_BASE(g);
int ret;
VIRTIO_GPU_FILL_CMD(mblob);
@@ -804,6 +805,15 @@ static void virgl_cmd_resource_map_blob(VirtIOGPU *g,
return;
}
+ if (mblob.offset + res->base.blob_size > b->conf.hostmem ||
+ mblob.offset + res->base.blob_size < mblob.offset) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: failed to map virgl resource: invalid offset\n",
+ __func__);
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ return;
+ }
+
ret = virtio_gpu_virgl_map_resource_blob(g, res, mblob.offset);
if (ret) {
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 16/18] virtio-gpu: Replace finish_unmapping with mapping_state
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (14 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 15/18] virtio-gpu: Validate hostmem mapping offset Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 17/18] virtio-gpu: Destroy virgl resources on virtio-gpu reset Dmitry Osipenko
` (3 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Allow virtio_gpu_virgl_unmap_resource_blob() to be invoked while async
unmapping is in progress. Do it in preparation to improvement of virtio-gpu
resetting that will require this change.
Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/trace-events | 2 +-
hw/display/virtio-gpu-virgl.c | 28 ++++++++++++++++++++++------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/hw/display/trace-events b/hw/display/trace-events
index e323a82cff24..4bfc457fbac1 100644
--- a/hw/display/trace-events
+++ b/hw/display/trace-events
@@ -39,7 +39,7 @@ virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h)
virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d"
virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" PRId64
virtio_gpu_cmd_res_map_blob(uint32_t res, void *vmr, void *mr) "res 0x%x, vmr %p, mr %p"
-virtio_gpu_cmd_res_unmap_blob(uint32_t res, void *mr, bool finish_unmapping) "res 0x%x, mr %p, finish_unmapping %d"
+virtio_gpu_cmd_res_unmap_blob(uint32_t res, void *mr, int mapping_state) "res 0x%x, mr %p, mapping_state %d"
virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x"
virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x"
virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x"
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index f4d1113827e3..d1b5162f4408 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -68,11 +68,17 @@ virgl_get_egl_display(G_GNUC_UNUSED void *cookie)
#endif
#if VIRGL_VERSION_MAJOR >= 1
+enum virtio_gpu_virgl_hostmem_region_mapping_state {
+ VIRTIO_GPU_MR_MAPPED,
+ VIRTIO_GPU_MR_UNMAP_STARTED,
+ VIRTIO_GPU_MR_UNMAP_COMPLETED,
+};
+
struct virtio_gpu_virgl_hostmem_region {
Object parent_obj;
MemoryRegion mr;
struct VirtIOGPU *g;
- bool finish_unmapping;
+ enum virtio_gpu_virgl_hostmem_region_mapping_state mapping_state;
};
#define TYPE_VIRTIO_GPU_VIRGL_HOSTMEM_REGION "virtio-gpu-virgl-hostmem-region"
@@ -109,7 +115,7 @@ static void virtio_gpu_virgl_hostmem_region_finalize(Object *obj)
return;
}
- vmr->finish_unmapping = true;
+ vmr->mapping_state = VIRTIO_GPU_MR_UNMAP_COMPLETED;
b = VIRTIO_GPU_BASE(vmr->g);
b->renderer_blocked--;
@@ -167,6 +173,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
object_initialize_child(OBJECT(g), name, vmr,
TYPE_VIRTIO_GPU_VIRGL_HOSTMEM_REGION);
vmr->g = g;
+ vmr->mapping_state = VIRTIO_GPU_MR_MAPPED;
mr = &vmr->mr;
memory_region_init_ram_ptr(mr, OBJECT(vmr), "mr", size, data);
@@ -195,7 +202,8 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
vmr = to_hostmem_region(res->mr);
- trace_virtio_gpu_cmd_res_unmap_blob(res->base.resource_id, mr, vmr->finish_unmapping);
+ trace_virtio_gpu_cmd_res_unmap_blob(res->base.resource_id, mr,
+ vmr->mapping_state);
/*
* Perform async unmapping in 3 steps:
@@ -206,7 +214,8 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
* asynchronously by virtio_gpu_virgl_hostmem_region_finalize().
* 3. Finish the unmapping with final virgl_renderer_resource_unmap().
*/
- if (vmr->finish_unmapping) {
+ switch (vmr->mapping_state) {
+ case VIRTIO_GPU_MR_UNMAP_COMPLETED:
res->mr = NULL;
g_free(vmr);
@@ -217,15 +226,22 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
__func__, strerror(-ret));
return ret;
}
- } else {
- *cmd_suspended = true;
+ break;
+ case VIRTIO_GPU_MR_MAPPED:
/* render will be unblocked once MR is freed */
b->renderer_blocked++;
+ vmr->mapping_state = VIRTIO_GPU_MR_UNMAP_STARTED;
+
/* memory region owns self res->mr object and frees it by itself */
memory_region_del_subregion(&b->hostmem, mr);
object_unparent(OBJECT(vmr));
+
+ /* Fallthrough */
+ case VIRTIO_GPU_MR_UNMAP_STARTED:
+ *cmd_suspended = true;
+ break;
}
return 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 17/18] virtio-gpu: Destroy virgl resources on virtio-gpu reset
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (15 preceding siblings ...)
2026-03-03 15:14 ` [PATCH v22 16/18] virtio-gpu: Replace finish_unmapping with mapping_state Dmitry Osipenko
@ 2026-03-03 15:14 ` Dmitry Osipenko
2026-03-03 15:14 ` [PATCH v22 18/18] virtio-gpu: Support mapping hostmem blobs with map_fixed Dmitry Osipenko
` (2 subsequent siblings)
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Properly destroy virgl resources on virtio-gpu reset to not leak resources
on a hot reboot of a VM.
Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-gl.c | 18 +----
hw/display/virtio-gpu-virgl.c | 123 +++++++++++++++++++++++++++------
include/hw/virtio/virtio-gpu.h | 6 +-
3 files changed, 107 insertions(+), 40 deletions(-)
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index b941e9a4b789..8b71dd6fc26f 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -63,29 +63,14 @@ static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOGPU *g = VIRTIO_GPU(vdev);
- VirtIOGPUGL *gl = VIRTIO_GPU_GL(vdev);
struct virtio_gpu_ctrl_command *cmd;
if (!virtio_queue_ready(vq)) {
return;
}
- switch (gl->renderer_state) {
- case RS_RESET:
- virtio_gpu_virgl_reset(g);
- /* fallthrough */
- case RS_START:
- if (virtio_gpu_virgl_init(g)) {
- gl->renderer_state = RS_INIT_FAILED;
- return;
- }
-
- gl->renderer_state = RS_INITED;
- break;
- case RS_INIT_FAILED:
+ if (!virtio_gpu_virgl_update_render_state(g)) {
return;
- case RS_INITED:
- break;
}
cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
@@ -201,6 +186,7 @@ static void virtio_gpu_gl_class_init(ObjectClass *klass, const void *data)
vgc->process_cmd = virtio_gpu_virgl_process_cmd;
vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
+ vgc->resource_destroy = virtio_gpu_virgl_resource_destroy;
vdc->realize = virtio_gpu_gl_device_realize;
vdc->unrealize = virtio_gpu_gl_device_unrealize;
vdc->reset = virtio_gpu_gl_reset;
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index d1b5162f4408..1819f9cb7e9d 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -96,6 +96,10 @@ static void virtio_gpu_virgl_resume_cmdq_bh(void *opaque)
{
VirtIOGPU *g = opaque;
+ if (!virtio_gpu_virgl_update_render_state(g)) {
+ return;
+ }
+
virtio_gpu_process_cmdq(g);
}
@@ -344,14 +348,46 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,
virgl_renderer_resource_create(&args, NULL, 0);
}
+static int
+virtio_gpu_virgl_resource_unref(VirtIOGPU *g,
+ struct virtio_gpu_virgl_resource *res,
+ bool *suspended)
+{
+ struct iovec *res_iovs = NULL;
+ int num_iovs = 0;
+#if VIRGL_VERSION_MAJOR >= 1
+ int ret;
+
+ ret = virtio_gpu_virgl_unmap_resource_blob(g, res, suspended);
+ if (ret) {
+ return ret;
+ }
+ if (*suspended) {
+ return 0;
+ }
+#endif
+
+ virgl_renderer_resource_detach_iov(res->base.resource_id,
+ &res_iovs,
+ &num_iovs);
+ if (res_iovs != NULL && num_iovs != 0) {
+ virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs);
+ }
+ virgl_renderer_resource_unref(res->base.resource_id);
+
+ QTAILQ_REMOVE(&g->reslist, &res->base, next);
+
+ g_free(res);
+
+ return 0;
+}
+
static void virgl_cmd_resource_unref(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd,
bool *cmd_suspended)
{
struct virtio_gpu_resource_unref unref;
struct virtio_gpu_virgl_resource *res;
- struct iovec *res_iovs = NULL;
- int num_iovs = 0;
VIRTIO_GPU_FILL_CMD(unref);
trace_virtio_gpu_cmd_res_unref(unref.resource_id);
@@ -364,27 +400,21 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,
return;
}
-#if VIRGL_VERSION_MAJOR >= 1
- if (virtio_gpu_virgl_unmap_resource_blob(g, res, cmd_suspended)) {
- cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
- return;
- }
- if (*cmd_suspended) {
- return;
- }
-#endif
+ virtio_gpu_virgl_resource_unref(g, res, cmd_suspended);
+}
- virgl_renderer_resource_detach_iov(unref.resource_id,
- &res_iovs,
- &num_iovs);
- if (res_iovs != NULL && num_iovs != 0) {
- virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs);
- }
- virgl_renderer_resource_unref(unref.resource_id);
+void virtio_gpu_virgl_resource_destroy(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *base,
+ Error **errp)
+{
+ struct virtio_gpu_virgl_resource *res;
+ bool suspended = false;
- QTAILQ_REMOVE(&g->reslist, &res->base, next);
+ res = container_of(base, struct virtio_gpu_virgl_resource, base);
- g_free(res);
+ if (virtio_gpu_virgl_resource_unref(g, res, &suspended)) {
+ error_setg(errp, "failed to destroy virgl resource");
+ }
}
static void virgl_cmd_context_create(VirtIOGPU *g,
@@ -1291,6 +1321,10 @@ static void virtio_gpu_fence_poll(void *opaque)
VirtIOGPU *g = opaque;
VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+ if (!virtio_gpu_virgl_update_render_state(g)) {
+ return;
+ }
+
virgl_renderer_poll();
virtio_gpu_process_cmdq(g);
if (!QTAILQ_EMPTY(&g->cmdq) || !QTAILQ_EMPTY(&g->fenceq)) {
@@ -1313,14 +1347,30 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
}
}
-void virtio_gpu_virgl_reset(VirtIOGPU *g)
+static bool virtio_gpu_virgl_reset(VirtIOGPU *g)
{
+ struct virtio_gpu_simple_resource *res, *tmp;
+
+ /*
+ * Virgl blob resource unmapping can be suspended and
+ * deferred on unref, ensure that destruction is completed.
+ */
+ QTAILQ_FOREACH_SAFE(res, &g->reslist, next, tmp) {
+ virtio_gpu_virgl_resource_destroy(g, res, NULL);
+ }
+
+ if (!QTAILQ_EMPTY(&g->reslist)) {
+ return false;
+ }
+
virgl_renderer_reset();
virtio_gpu_virgl_reset_async_fences(g);
+
+ return true;
}
-int virtio_gpu_virgl_init(VirtIOGPU *g)
+static int virtio_gpu_virgl_init(VirtIOGPU *g)
{
int ret;
uint32_t flags = 0;
@@ -1398,6 +1448,35 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
return 0;
}
+bool virtio_gpu_virgl_update_render_state(VirtIOGPU *g)
+{
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+
+ switch (gl->renderer_state) {
+ case RS_RESET:
+ virgl_renderer_force_ctx_0();
+
+ if (!virtio_gpu_virgl_reset(g)) {
+ return false;
+ }
+ /* fallthrough */
+ case RS_START:
+ if (virtio_gpu_virgl_init(g)) {
+ gl->renderer_state = RS_INIT_FAILED;
+ return false;
+ }
+
+ gl->renderer_state = RS_INITED;
+ break;
+ case RS_INIT_FAILED:
+ return false;
+ case RS_INITED:
+ break;
+ }
+
+ return true;
+}
+
static void virtio_gpu_virgl_add_capset(GArray *capset_ids, uint32_t capset_id)
{
g_array_append_val(capset_ids, capset_id);
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 718332284305..1f509d0d5beb 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -389,9 +389,11 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
struct virtio_gpu_ctrl_command *cmd);
void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);
void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g);
-void virtio_gpu_virgl_reset(VirtIOGPU *g);
-int virtio_gpu_virgl_init(VirtIOGPU *g);
GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g);
void virtio_gpu_virgl_reset_async_fences(VirtIOGPU *g);
+void virtio_gpu_virgl_resource_destroy(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res,
+ Error **errp);
+bool virtio_gpu_virgl_update_render_state(VirtIOGPU *g);
#endif
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v22 18/18] virtio-gpu: Support mapping hostmem blobs with map_fixed
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (16 preceding siblings ...)
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 ` 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-04 6:10 ` Akihiko Odaki
19 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 15:14 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Support mapping virgl blobs to a fixed location of a hostmem memory
region using new virglrenderer MAP_FIXED API.
This new feature closes multiple problems for virtio-gpu on QEMU:
- Having dedicated memory region for each mapped blob works notoriously
slow due to QEMU's memory region software design built around RCU that
isn't optimized for frequent removal of the regions
- KVM isn't optimized for a frequent slot changes too
- QEMU/KVM has a limit for a total number of created memory regions,
crashing QEMU when limit is reached
This patch makes virtio-gpu-gl to pre-create a single anonymous memory
region covering whole hostmem area to which blobs will be mapped using
the MAP_FIXED API.
Not all virgl resources will support mapping at a fixed memory address. For
them, we will continue to create individual nested memory sub-regions. In
particular, vrend resources may not have MAP_FIXED capability.
Venus and DRM native contexts will largely benefit from the MAP_FIXED
feature in terms of performance and stability improvement.
Tested-by: Yiwei Zhang <zzyiwei@gmail.com>
Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
hw/display/virtio-gpu-gl.c | 37 ++++++++++++++++++++-
hw/display/virtio-gpu-virgl.c | 59 +++++++++++++++++++++++++++++++++-
include/hw/virtio/virtio-gpu.h | 3 ++
3 files changed, 97 insertions(+), 2 deletions(-)
diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index 8b71dd6fc26f..2b7a41c46643 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "qemu/iov.h"
+#include "qemu/mmap-alloc.h"
#include "qemu/module.h"
#include "qemu/error-report.h"
#include "qapi/error.h"
@@ -106,7 +107,12 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev)
static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
{
ERRP_GUARD();
- VirtIOGPU *g = VIRTIO_GPU(qdev);
+ VirtIOGPUBase *b = VIRTIO_GPU_BASE(qdev);
+ VirtIOGPU *g = VIRTIO_GPU(b);
+#if !defined(CONFIG_WIN32)
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+ void *map;
+#endif
#if HOST_BIG_ENDIAN
error_setg(errp, "virgl is not supported on bigendian platforms");
@@ -136,6 +142,24 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
g->parent_obj.conf.flags |= 1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED;
#endif
+#if !defined(CONFIG_WIN32)
+ if (virtio_gpu_hostmem_enabled(b->conf)) {
+ map = qemu_ram_mmap(-1, b->conf.hostmem, qemu_real_host_page_size(),
+ 0, 0);
+ if (map == MAP_FAILED) {
+ error_setg_errno(errp, errno,
+ "virgl hostmem region could not be initialized");
+ return;
+ }
+
+ gl->hostmem_mmap = map;
+ memory_region_init_ram_ptr(&gl->hostmem_background, NULL,
+ "hostmem-background", b->conf.hostmem,
+ gl->hostmem_mmap);
+ memory_region_add_subregion(&b->hostmem, 0, &gl->hostmem_background);
+ }
+#endif
+
virtio_gpu_device_realize(qdev, errp);
}
@@ -172,6 +196,17 @@ static void virtio_gpu_gl_device_unrealize(DeviceState *qdev)
gl->renderer_state = RS_START;
g_array_unref(g->capset_ids);
+
+ /*
+ * It is not guaranteed that the memory region will be finalized
+ * immediately with memory_region_del_subregion(), there can be
+ * a remaining reference to gl->hostmem_mmap. VirtIO-GPU is not
+ * hotpluggable, hence no need to worry about the leaked mapping.
+ *
+ * The memory_region_del_subregion(gl->hostmem_background) is unnecessary
+ * because b->hostmem and gl->hostmem_background belong to the same
+ * device and will be gone at the same time.
+ */
}
static void virtio_gpu_gl_class_init(ObjectClass *klass, const void *data)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 1819f9cb7e9d..b7a2d160ddd8 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -41,9 +41,13 @@
VIRGL_VERSION_MICRO >= (micro))
#endif
+#define VIRGL_HAS_MAP_FIXED \
+ (VIRGL_CHECK_VERSION(1, 3, 0) && !IS_ENABLED(CONFIG_WIN32))
+
struct virtio_gpu_virgl_resource {
struct virtio_gpu_simple_resource base;
MemoryRegion *mr;
+ void *map_fixed;
};
static struct virtio_gpu_virgl_resource *
@@ -155,6 +159,9 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
g_autofree char *name = NULL;
struct virtio_gpu_virgl_hostmem_region *vmr;
VirtIOGPUBase *b = VIRTIO_GPU_BASE(g);
+#if VIRGL_HAS_MAP_FIXED
+ VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
+#endif
MemoryRegion *mr;
uint64_t size;
void *data;
@@ -165,6 +172,41 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
return -EOPNOTSUPP;
}
+#if VIRGL_HAS_MAP_FIXED
+ /*
+ * virgl_renderer_resource_map_fixed() allows to create multiple
+ * mappings of the same resource, while virgl_renderer_resource_map()
+ * not. Don't allow mapping same resource twice.
+ */
+ if (res->map_fixed || res->mr) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: failed to map(fixed) virgl resource: already mapped\n",
+ __func__);
+ return -EBUSY;
+ }
+
+ ret = virgl_renderer_resource_map_fixed(res->base.resource_id,
+ gl->hostmem_mmap + offset);
+ switch (ret) {
+ case 0:
+ res->map_fixed = gl->hostmem_mmap + offset;
+ return 0;
+
+ case -EOPNOTSUPP:
+ /*
+ * MAP_FIXED is unsupported by this resource.
+ * Mapping falls back to a blob subregion method in that case.
+ */
+ break;
+
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: failed to map(fixed) virgl resource: %s\n",
+ __func__, strerror(-ret));
+ return ret;
+ }
+#endif
+
ret = virgl_renderer_resource_map(res->base.resource_id, &data, &size);
if (ret) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map virgl resource: %s\n",
@@ -181,7 +223,7 @@ virtio_gpu_virgl_map_resource_blob(VirtIOGPU *g,
mr = &vmr->mr;
memory_region_init_ram_ptr(mr, OBJECT(vmr), "mr", size, data);
- memory_region_add_subregion(&b->hostmem, offset, mr);
+ memory_region_add_subregion_overlap(&b->hostmem, offset, mr, 1);
res->mr = mr;
@@ -200,6 +242,21 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g,
MemoryRegion *mr = res->mr;
int ret;
+#if VIRGL_HAS_MAP_FIXED
+ if (res->map_fixed) {
+ if (mmap(res->map_fixed, res->base.blob_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
+ -1, 0) == MAP_FAILED) {
+ ret = -errno;
+ error_report("%s: failed to unmap(fixed) virgl resource: %s",
+ __func__, strerror(-ret));
+ return ret;
+ }
+
+ res->map_fixed = NULL;
+ }
+#endif
+
if (!mr) {
return 0;
}
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 1f509d0d5beb..a48b50d4c825 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -263,6 +263,9 @@ struct VirtIOGPUGL {
QEMUBH *async_fence_bh;
QSLIST_HEAD(, virtio_gpu_virgl_context_fence) async_fenceq;
+
+ MemoryRegion hostmem_background;
+ void *hostmem_mmap;
};
struct VhostUserGPU {
--
2.52.0
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (17 preceding siblings ...)
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 ` Alex Bennée
2026-03-03 19:26 ` Dmitry Osipenko
2026-03-04 6:10 ` Akihiko Odaki
19 siblings, 1 reply; 31+ messages in thread
From: Alex Bennée @ 2026-03-03 17:33 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
Dmitry Osipenko <dmitry.osipenko@collabora.com> writes:
> Hello,
>
> This is follow up to DRM native context v16 [1] and MAP_FIXED API v10 [2]
> virtio-gpu patches that has been reviewed previously and were waiting for
> a new release of libvirglrenderer 1.3.0.
>
> [1] https://lore.kernel.org/qemu-devel/20251116125641.2255794-1-dmitry.osipenko@collabora.com/
> [2]
> https://lore.kernel.org/qemu-devel/20260118162856.223796-1-dmitry.osipenko@collabora.com/
Queued to virtio-gpu/next, thanks.
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API
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
0 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-03 19:26 UTC (permalink / raw)
To: Alex Bennée
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
On 3/3/26 20:33, Alex Bennée wrote:
> Dmitry Osipenko <dmitry.osipenko@collabora.com> writes:
>
>> Hello,
>>
>> This is follow up to DRM native context v16 [1] and MAP_FIXED API v10 [2]
>> virtio-gpu patches that has been reviewed previously and were waiting for
>> a new release of libvirglrenderer 1.3.0.
>>
>> [1] https://lore.kernel.org/qemu-devel/20251116125641.2255794-1-dmitry.osipenko@collabora.com/
>> [2]
>> https://lore.kernel.org/qemu-devel/20260118162856.223796-1-dmitry.osipenko@collabora.com/
>
> Queued to virtio-gpu/next, thanks.
Thanks!
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API
2026-03-03 15:14 [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Dmitry Osipenko
` (18 preceding siblings ...)
2026-03-03 17:33 ` [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API Alex Bennée
@ 2026-03-04 6:10 ` Akihiko Odaki
2026-03-04 10:34 ` Dmitry Osipenko
19 siblings, 1 reply; 31+ messages in thread
From: Akihiko Odaki @ 2026-03-04 6:10 UTC (permalink / raw)
To: Dmitry Osipenko, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
On 2026/03/04 0:14, Dmitry Osipenko wrote:
> Hello,
>
> This is follow up to DRM native context v16 [1] and MAP_FIXED API v10 [2]
> virtio-gpu patches that has been reviewed previously and were waiting for
> a new release of libvirglrenderer 1.3.0.
>
> [1] https://lore.kernel.org/qemu-devel/20251116125641.2255794-1-dmitry.osipenko@collabora.com/
> [2] https://lore.kernel.org/qemu-devel/20260118162856.223796-1-dmitry.osipenko@collabora.com/
>
> Changelog:
>
> v22:- Added r-b from Marc-André Lureau to ui/gdk patch.
>
> - Corrected qemu_egl_create_context() to take explicit shared GL context
> arg needed by gtk-egl display, as was suggested by Akihiko Odaki.
>
> - Changed virtio-gpu BHs to use re-entrance guard as was suggested by
> Akihiko Odaki.
Everything looks good to me. For the entire series:
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>
> v21:- Moved virtio-gpu to use iohandler_get_aio_context() as was
> suggested by Akihiko Odaki.
>
> - Updated EGL context-create helper and displays using it to make
> helper take care of using appropriate parent GL context by itself,
> without a need to switch GL context. Done it all in a single patch:
>
> ui/egl: Don't change bound GL context when creating new context
>
> - Cleaned up GDK context-restoring code as was suggested by Akihiko Odaki.
>
> v20:- Adanbonded GL context unbinding approach as it created difficulties
> with GTK assuming UI toolkit processed from a single thread. Omitted
> all unbind-context patches and added new patch instead that makes
> virtio-gpu to process cmds only from main-loop thread:
>
> virtio-gpu: Bounce virtio_gpu_ctrl_bh() to main-loop thread
>
> - Added r-b from Akihiko Odaki to reviewed v19 patches.
>
> - Added patches restoring GL context when new ctx created for
> dbus/spice/egl-headless displays.
>
> v19:- Further improved improved naming of functions and terminology RE
> GL context binding. Suggested by Akihiko Odaki.
>
> - Added new patch "ui/gdk: Restore original context after new context
> creation" in addition to improved "ui/sdl2: Restore original context"
> that now getd actual bound GL context and restores to it instead
> of restoring to the console's ctx, for consistency with the rest
> of GL context management fixes that ensure context is bound only
> when necessary.
>
> - Improved virtio_gpu_virgl_update_render_state() with force_ctx_0()
> and unbind_ctx() to make deferred GPU resetting maintain bound GL
> context properly.
>
> v18:- Changed dpy_gl_ctx_make_current() to use first scanout when unsetting
> virgl's GL ctx0 and improved naming of cmd-processing function.
> Suggested by Akihiko Odaki.
>
> - Added "ui/gdk: Unset context after GL operations" patch after
> realizing GDK/GL code needed more gdk_gl_context_clear_current().
>
> v17:- Rebased patches on recent upstream, updated doc patches with new
> drm native contexts supported by libvirglrenderer.
>
> - Applied minor change that was requested from Akihiko Odaki
> by moving virtio_gpu_device_realize() for MAP_FIXED v10.
>
> - Added virtio_gpu_virgl_update_render_state() to virtio_gpu_fence_poll()
> that was missed in MAP_FIXED v10.
>
> - Added new patches fixing another GL context switching problem I ran
> into recently with virgl commands unexpectedly processed from CPU
> thread instead main-loop:
>
> ui/sdl2: Unset context after GL operations
> ui/gtk-egl: Unset context after GL operations
> virtio-gpu: Unset context after GL operations
>
> Alex Bennée (1):
> docs/system: virtio-gpu: Document host/guest requirements
>
> Dmitry Osipenko (16):
> ui/gtk: Don't disable scanout when display is refreshed
> ui/sdl2: Don't disable scanout when display is refreshed
> ui/egl: Don't change bound GL context when creating new context
> ui/gdk: Restore original context after new context creation
> ui/sdl2: Restore original context after new context creation
> virtio-gpu: Ensure BHs are invoked only from main-loop thread
> virtio-gpu: Handle virgl fence creation errors
> virtio-gpu: Support asynchronous fencing
> virtio-gpu: Support DRM native context
> docs/system: virtio-gpu: Add link to Mesa VirGL doc
> docs/system: virtio-gpu: Update Venus link
> virtio-gpu: Remove superfluous memory_region_set_enabled()
> virtio-gpu: Validate hostmem mapping offset
> virtio-gpu: Replace finish_unmapping with mapping_state
> virtio-gpu: Destroy virgl resources on virtio-gpu reset
> virtio-gpu: Support mapping hostmem blobs with map_fixed
>
> Pierre-Eric Pelloux-Prayer (1):
> ui/sdl2: Implement dpy dmabuf functions
>
> docs/system/devices/virtio/virtio-gpu.rst | 121 ++++++-
> hw/display/trace-events | 2 +-
> hw/display/virtio-gpu-gl.c | 62 +++-
> hw/display/virtio-gpu-virgl.c | 410 ++++++++++++++++++++--
> hw/display/virtio-gpu.c | 21 +-
> hw/virtio/virtio.c | 10 +
> include/hw/virtio/virtio-gpu.h | 23 +-
> include/hw/virtio/virtio.h | 10 +
> include/ui/egl-context.h | 3 +-
> include/ui/sdl2.h | 7 +
> meson.build | 8 +-
> ui/dbus.c | 4 +-
> ui/egl-context.c | 6 +-
> ui/egl-headless.c | 4 +-
> ui/gtk-egl.c | 5 +-
> ui/gtk-gl-area.c | 13 +-
> ui/sdl2-gl.c | 74 +++-
> ui/sdl2.c | 42 +++
> ui/spice-display.c | 4 +-
> 19 files changed, 735 insertions(+), 94 deletions(-)
>
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
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
0 siblings, 1 reply; 31+ messages in thread
From: Alex Bennée @ 2026-03-04 8:49 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
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.
> sdl_update_caption(scon);
> }
>
> @@ -808,6 +815,10 @@ static const DisplayChangeListenerOps dcl_gl_ops = {
> .dpy_gl_scanout_disable = sdl2_gl_scanout_disable,
> .dpy_gl_scanout_texture = sdl2_gl_scanout_texture,
> .dpy_gl_update = sdl2_gl_scanout_flush,
> +
> + .dpy_gl_scanout_dmabuf = sdl2_gl_scanout_dmabuf,
> + .dpy_gl_release_dmabuf = sdl2_gl_release_dmabuf,
> + .dpy_has_dmabuf = sdl2_gl_has_dmabuf,
> };
>
> static bool
> @@ -835,6 +846,35 @@ static void sdl2_display_early_init(DisplayOptions *o)
> }
> }
>
> +static void sdl2_set_hint_x11_force_egl(void)
> +{
> +#if defined(SDL_HINT_VIDEO_X11_FORCE_EGL) && defined(CONFIG_OPENGL) && \
> + defined(CONFIG_X11)
> + Display *x_disp = XOpenDisplay(NULL);
> + EGLDisplay egl_display;
> +
> + if (!x_disp) {
> + return;
> + }
> +
> + /* Prefer EGL over GLX to get dma-buf support. */
> + egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp);
> +
> + if (egl_display != EGL_NO_DISPLAY) {
> + /*
> + * Setting X11_FORCE_EGL hint doesn't make SDL to prefer X11 over
> + * Wayland. SDL will use Wayland driver even if XWayland presents.
> + * It's always safe to set the hint even if X11 is not used by SDL.
> + * SDL will work regardless of the hint.
> + */
> + SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
> + eglTerminate(egl_display);
> + }
> +
> + XCloseDisplay(x_disp);
> +#endif
> +}
> +
> static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
> {
> uint8_t data = 0;
> @@ -862,6 +902,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
> SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0");
> #endif
> SDL_SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
> + sdl2_set_hint_x11_force_egl();
> SDL_EnableScreenSaver();
> memset(&info, 0, sizeof(info));
> SDL_VERSION(&info.version);
> @@ -908,6 +949,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
> sdl2_console[i].kbd = qkbd_state_init(con);
> if (display_opengl) {
> qemu_console_set_display_gl_ctx(con, &sdl2_console[i].dgc);
> + sdl2_gl_console_init(&sdl2_console[i]);
> }
> register_displaychangelistener(&sdl2_console[i].dcl);
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
2026-03-04 8:49 ` Alex Bennée
@ 2026-03-04 10:33 ` Dmitry Osipenko
2026-03-04 11:40 ` Alex Bennée
` (2 more replies)
0 siblings, 3 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-04 10:33 UTC (permalink / raw)
To: Alex Bennée
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
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);
}
--
Best regards,
Dmitry
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH v22 00/18] Support virtio-gpu DRM native context and MAP_FIXED API
2026-03-04 6:10 ` Akihiko Odaki
@ 2026-03-04 10:34 ` Dmitry Osipenko
0 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-03-04 10:34 UTC (permalink / raw)
To: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
On 3/4/26 09:10, Akihiko Odaki wrote:
> On 2026/03/04 0:14, Dmitry Osipenko wrote:
>> Hello,
>>
>> This is follow up to DRM native context v16 [1] and MAP_FIXED API v10 [2]
>> virtio-gpu patches that has been reviewed previously and were waiting for
>> a new release of libvirglrenderer 1.3.0.
>>
>> [1] https://lore.kernel.org/qemu-devel/20251116125641.2255794-1-
>> dmitry.osipenko@collabora.com/
>> [2] https://lore.kernel.org/qemu-devel/20260118162856.223796-1-
>> dmitry.osipenko@collabora.com/
>>
>> Changelog:
>>
>> v22:- Added r-b from Marc-André Lureau to ui/gdk patch.
>>
>> - Corrected qemu_egl_create_context() to take explicit shared GL
>> context
>> arg needed by gtk-egl display, as was suggested by Akihiko Odaki.
>>
>> - Changed virtio-gpu BHs to use re-entrance guard as was
>> suggested by
>> Akihiko Odaki.
>
> Everything looks good to me. For the entire series:
>
> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Thanks
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
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
2 siblings, 0 replies; 31+ messages in thread
From: Alex Bennée @ 2026-03-04 11:40 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
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>
>>>
<snip>
>>> @@ -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);
> }
heh, I had got to something similar but then ran into a link failure at
the end:
Undefined symbols for architecture arm64:
"_sdl2_gl_console_init", referenced from:
_sdl2_display_init in ui_sdl2.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
make: *** [run-ninja] Error 1
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
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
2 siblings, 0 replies; 31+ messages in thread
From: Alex Bennée @ 2026-03-04 12:10 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
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);
> }
--8<---------------cut here---------------start------------->8---
modified 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);
}
@@ -947,10 +949,12 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
#endif
sdl2_console[i].dcl.con = con;
sdl2_console[i].kbd = qkbd_state_init(con);
+#ifdef CONFIG_OPENGL
if (display_opengl) {
qemu_console_set_display_gl_ctx(con, &sdl2_console[i].dgc);
sdl2_gl_console_init(&sdl2_console[i]);
}
+#endif
register_displaychangelistener(&sdl2_console[i].dcl);
#if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_X11)
--8<---------------cut here---------------end--------------->8---
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 06/18] ui/sdl2: Implement dpy dmabuf functions
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
2 siblings, 0 replies; 31+ messages in thread
From: Alex Bennée @ 2026-03-04 12:11 UTC (permalink / raw)
To: Dmitry Osipenko
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett
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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 02/18] ui/sdl2: Don't disable scanout when display is refreshed
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
0 siblings, 1 reply; 31+ messages in thread
From: Stefan Weil via qemu development @ 2026-04-07 16:44 UTC (permalink / raw)
To: Dmitry Osipenko, Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann, Alex Bennée,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual
Cc: Gert Wollny, qemu-devel, Gurchetan Singh, Alyssa Ross,
Roger Pau Monné, Alex Deucher, Stefano Stabellini,
Christian König, Xenia Ragiadakou, Honglei Huang,
Julia Zhang, Chen Jiqian, Rob Clark, Robert Beckett
Am 03.03.26 um 16:14 schrieb Dmitry Osipenko:
> Display refreshment is invoked by a timer and it erroneously disables
> the active scanout if it happens to be invoked after scanout has been
> enabled. This offending scanout-disable race condition with a timer
> can be easily hit when Qemu runs with a disabled vsync by using SDL or
> GTK displays (with vblank_mode=0 for GTK). Refreshment of display's
> content shouldn't disable the active display. Fix it by keeping the
> scanout's state unchanged when display is redrawn.
>
> 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>
> Acked-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>
> ---
> ui/sdl2-gl.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
> index 3be17d1079af..5eca0248233e 100644
> --- a/ui/sdl2-gl.c
> +++ b/ui/sdl2-gl.c
> @@ -51,7 +51,6 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
> int ww, wh;
>
> SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> - sdl2_set_scanout_mode(scon, false);
>
> SDL_GetWindowSize(scon->real_window, &ww, &wh);
> surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
I got a user report that my latest QEMU for Windows no longer supports
SDL. According to my own test, SDL still worked with git master
(2026-03-07), but was broken with 11.0.0-rc0 (2026-03-18).
Therefore this patch series might have caused the regression which still
exists in 11.0.0-rc2. All test installers are available here:
https://qemu.weilnetz.de/w64/2026/.
Regards
Stefan Weil
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 02/18] ui/sdl2: Don't disable scanout when display is refreshed
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
0 siblings, 1 reply; 31+ messages in thread
From: Alex Bennée @ 2026-04-07 17:24 UTC (permalink / raw)
To: Stefan Weil
Cc: Dmitry Osipenko, Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett, Anthony Roberts
Stefan Weil <sw@weilnetz.de> writes:
> Am 03.03.26 um 16:14 schrieb Dmitry Osipenko:
>> Display refreshment is invoked by a timer and it erroneously disables
>> the active scanout if it happens to be invoked after scanout has been
>> enabled. This offending scanout-disable race condition with a timer
>> can be easily hit when Qemu runs with a disabled vsync by using SDL or
>> GTK displays (with vblank_mode=0 for GTK). Refreshment of display's
>> content shouldn't disable the active display. Fix it by keeping the
>> scanout's state unchanged when display is redrawn.
>> 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>
>> Acked-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>
>> ---
>> ui/sdl2-gl.c | 1 -
>> 1 file changed, 1 deletion(-)
>> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
>> index 3be17d1079af..5eca0248233e 100644
>> --- a/ui/sdl2-gl.c
>> +++ b/ui/sdl2-gl.c
>> @@ -51,7 +51,6 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
>> int ww, wh;
>> SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
>> - sdl2_set_scanout_mode(scon, false);
>> SDL_GetWindowSize(scon->real_window, &ww, &wh);
>> surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
>
> I got a user report that my latest QEMU for Windows no longer supports
> SDL. According to my own test, SDL still worked with git master
> (2026-03-07), but was broken with 11.0.0-rc0 (2026-03-18).
This is:
https://gitlab.com/qemu-project/qemu/-/work_items/3347
Anthony should be posting a patch to the list soon.
>
> Therefore this patch series might have caused the regression which
> still exists in 11.0.0-rc2. All test installers are available here:
> https://qemu.weilnetz.de/w64/2026/.
>
> Regards
> Stefan Weil
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v22 02/18] ui/sdl2: Don't disable scanout when display is refreshed
2026-04-07 17:24 ` Alex Bennée
@ 2026-04-08 13:47 ` Dmitry Osipenko
0 siblings, 0 replies; 31+ messages in thread
From: Dmitry Osipenko @ 2026-04-08 13:47 UTC (permalink / raw)
To: Alex Bennée, Stefan Weil
Cc: Akihiko Odaki, Huang Rui, Marc-André Lureau,
Philippe Mathieu-Daudé, Gerd Hoffmann,
Pierre-Eric Pelloux-Prayer, Michael S . Tsirkin, Paolo Bonzini,
Yiwei Zhang, Sergio Lopez Pascual, Gert Wollny, qemu-devel,
Gurchetan Singh, Alyssa Ross, Roger Pau Monné, Alex Deucher,
Stefano Stabellini, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Rob Clark,
Robert Beckett, Anthony Roberts
On 4/7/26 20:24, Alex Bennée wrote:
> Stefan Weil <sw@weilnetz.de> writes:
>
>> Am 03.03.26 um 16:14 schrieb Dmitry Osipenko:
>>> Display refreshment is invoked by a timer and it erroneously disables
>>> the active scanout if it happens to be invoked after scanout has been
>>> enabled. This offending scanout-disable race condition with a timer
>>> can be easily hit when Qemu runs with a disabled vsync by using SDL or
>>> GTK displays (with vblank_mode=0 for GTK). Refreshment of display's
>>> content shouldn't disable the active display. Fix it by keeping the
>>> scanout's state unchanged when display is redrawn.
>>> 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>
>>> Acked-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>
>>> ---
>>> ui/sdl2-gl.c | 1 -
>>> 1 file changed, 1 deletion(-)
>>> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
>>> index 3be17d1079af..5eca0248233e 100644
>>> --- a/ui/sdl2-gl.c
>>> +++ b/ui/sdl2-gl.c
>>> @@ -51,7 +51,6 @@ static void sdl2_gl_render_surface(struct sdl2_console *scon)
>>> int ww, wh;
>>> SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
>>> - sdl2_set_scanout_mode(scon, false);
>>> SDL_GetWindowSize(scon->real_window, &ww, &wh);
>>> surface_gl_setup_viewport(scon->gls, scon->surface, ww, wh);
>>
>> I got a user report that my latest QEMU for Windows no longer supports
>> SDL. According to my own test, SDL still worked with git master
>> (2026-03-07), but was broken with 11.0.0-rc0 (2026-03-18).
>
> This is:
>
> https://gitlab.com/qemu-project/qemu/-/work_items/3347
>
> Anthony should be posting a patch to the list soon.
Thanks a lot for handling the issue!
--
Best regards,
Dmitry
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2026-04-08 19:19 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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.