Skip to contentSkip to conversation

Support virtio-gpu DRM native context

PATCH Superseded Dmitry Osipenko 6 participants 38 messages Jan 26, 2025 – Feb 17, 2025 Arm/Amlogic Meson SoC support

v6 of 22 Superseded Latest is v22 →

lore
Share & tools
lore
#0 lore raw

v6 cover Support virtio-gpu DRM native context

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

[1] https://www.youtube.com/watch?v=9sFP_yddLLQ

Today there are four DRM native context drivers existing in a wild:

- Freedreno (Qualcomm SoC GPUs), completely upstreamed
- AMDGPU, completely upstreamed
- Intel (i915), merge requests are opened
- Asahi (Apple SoC GPUs), partially merged upstream

# How to try out DRM context:

1. DRM context uses host blobs and on host requires latest 6.13 version of Linux kernel that contains necessary KVM fixes.

2. Use latest Mesa (both guest and host) and libvirglrenderer versions. Use build flags documented in tha patch #10 of this series.

3. On guest, use latest Linux kernel v6.14-rc or newer.

Example Qemu cmdline that enables DRM context:

  qemu-system-x86_64 -device virtio-vga-gl,hostmem=4G,blob=on,drm_native_context=on \
      -machine q35,accel=kvm,memory-backend=mem1 \
      -object memory-backend-memfd,id=mem1,size=8G -m 8G

# Note about known performance problem in Qemu:

DRM contexts are mapping host blobs extensively and these mapping operations work slowly in Qemu. Exact reason is unknown. Mappings work fast on Crosvm For DRM contexts this problem is more visible than for Venus/Virgl.

Changelog:

v6: - Fixed compilation warning using older version of virglrenderer,
which wasn't fixed properly in v5.

- Added t-bs from Alex Bennée.

- Added patches to improve virgl/venus doc by adding links to the Mesa doc as was suggested by Akihiko Odaki.

- Updated patch that documents guest/host requirements. Added links to Asahi nctx and reworked the doc structure by adding requirements to each context-type section instead of having one big blob or requirements, which was objected by Akihiko Odaki.

v5: - Added r-bs from Akihiko Odaki.

- Added acks from Michael Tsirkin.

- Fixed compilation warning using older version of virglrenderer that was reported by Alex Bennée. Noticed that I need to keep old virgl_write_fence() code around for the older virglrenderer in "Support asynchronous fencing" patch, so added it back and verified that old virglrenderer works properly.

- Added new patch from Alex Bennée that adds more virtio-gpu documentation with a couple corrections and additions to it from me.

- Rebased patches on top of latest staging tree.

v4: - Improved SDL2/dmabuf patch by reusing existing Meson X11 config
option, better handling EGL error and extending comment telling that it's safe to enable SDL2 EGL preference hint. As was suggested by Akihiko Odaki.

- Replaced another QSLIST_FOREACH_SAFE with QSLIST_EMPTY+FIRST in the async-fencing patch for more consistency of the code. As was suggested by Akihiko Odaki.

- Added missing braces around if-statement that was spotted by Alex Bennée.

- Renamed 'drm=on' option of virtio-gpu-gl device to 'drm_native_context=on' for more clarity as was suggested by Alex Bennée. Haven't added added new context-type option that was also proposed by Alex, might do it with a separate patch. This context-type option will duplicate and depecate existing options, but in a longer run likely will be worthwhile adding it.

- Dropped Linux headers-update patch as headers has been updated in the staging tree.

v3: - Improved EGL presence-check code on X11 systems for the SDL2
hint that prefers EGL over GLX by using better ifdefs and checking Xlib presence at a build time to avoid build failure if lib SDL2 and system are configured with a disabled X11 support. Also added clarifying comment telling that X11 hint doesn't affect Wayland systems. Suggested by Akihiko Odaki.

- Corrected strerror(err) that used negative error where it should be positive and vice versa that was caught by Akihiko Odaki. Added clarifying comment for the case where we get positive error code from virglrenderer that differs from other virglrenderer API functions.

- Improved QSLIST usage by dropping mutex protecting the async fence list and using atomic variant of QSLIST helpers instead. Switched away from using FOREACH helper to improve readability of the code, showing that we don't precess list in unoptimal way. Like was suggested by Akihiko Odaki.

- Updated patchset base to Venus v18.

v2: - Updated SDL2-dmabuf patch by making use of error_report() and
checking presense of X11+EGL in the system before making SDL2 to prefer EGL backend over GLX, suggested by Akihiko Odaki.

- Improved SDL2's dmabuf-presence check that wasn't done properly in v1, where EGL was set up only after first console was fully inited, and thus, SDL's display .has_dmabuf callback didn't work for the first console. Now dmabuf support status is pre-checked before console is registered.

- Updated commit description of the patch that fixes SDL2's context switching logic with a more detailed explanation of the problem. Suggested by Akihiko Odaki.

- Corrected rebase typo in the async-fencing patch and switched async-fencing to use a sigle-linked list instead of the double, as was suggested by Akihiko Odaki.

- Replaced "=true" with "=on" in the DRM native context documentation example and made virtio_gpu_virgl_init() to fail with a error message if DRM context can't be initialized instead of giving a warning message, as was suggested by Akihiko Odaki.

- Added patchew's dependecy tag to the cover letter as was suggested by Akihiko Odaki.

Alex Bennée (1):
docs/system: virtio-gpu: Document host/guest requirements

Dmitry Osipenko (8):
ui/sdl2: Restore original context after new context creation
virtio-gpu: Handle virgl fence creation errors
virtio-gpu: Support asynchronous fencing
virtio-gpu: Support DRM native context
ui/sdl2: Don't disable scanout when display is refreshed ui/gtk: Don't disable scanout when display is refreshed docs/system: virtio-gpu: Add link to Mesa VirGL doc docs/system: virtio-gpu: Update Venus link

Pierre-Eric Pelloux-Prayer (1):
ui/sdl2: Implement dpy dmabuf functions

 docs/system/devices/virtio-gpu.rst | 123 +++++++++++++++++++++-
 hw/display/virtio-gpu-gl.c         |   5 +
 hw/display/virtio-gpu-virgl.c      | 164 ++++++++++++++++++++++++++++-
 hw/display/virtio-gpu.c            |  15 +++
 include/hw/virtio/virtio-gpu.h     |  16 +++
 include/ui/sdl2.h                  |   7 ++
 meson.build                        |   6 +-
 ui/gtk-egl.c                       |   1 -
 ui/gtk-gl-area.c                   |   1 -
 ui/sdl2-gl.c                       |  68 +++++++++++-
 ui/sdl2.c                          |  42 ++++++++
 11 files changed, 437 insertions(+), 11 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH v6 1/10 ui/sdl2: Restore original context after new context creation

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.

---
 ui/sdl2-gl.c | 3 +++
 1 file changed, 3 insertions(+)
ui/sdl2-gl.c +3 -0
index e01d9ab0c7bf..b1fe96d6af22 100644
@@ -168,6 +168,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, scon->winctx);
+
     return (QEMUGLContext)ctx;
 }
 
Signature · 1 line
2.47.1
#2 lore raw

PATCH v6 2/10 ui/sdl2: Implement dpy dmabuf functions

In reply to Dmitry Osipenko

From: Pierre-Eric Pelloux-Prayer <[email protected]>

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).

---
 include/ui/sdl2.h |  7 ++++++
 meson.build       |  6 ++---
 ui/sdl2-gl.c      | 64 +++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2.c         | 42 +++++++++++++++++++++++++++++++
 4 files changed, 115 insertions(+), 4 deletions(-)
include/ui/sdl2.h +7 -0
index dbe6e3d9739b..9daf5ecffae7 100644
@@ -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 */
meson.build +2 -4
index 15a066043b7b..dfee104582b0 100644
@@ -1964,10 +1964,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'),
ui/sdl2-gl.c +64 -0

73 lines not on this page · raw message

ui/sdl2.c +42 -0

78 lines not on this page · raw message

Signature · 1 line
2.47.1
#3 lore raw

PATCH v6 3/10 virtio-gpu: Handle virgl fence creation errors

In reply to Dmitry Osipenko

Print out error messages when virgl fence creation fails to aid debugging of the fence-related bugs.

---
 hw/display/virtio-gpu-virgl.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +12 -1
index 145a0b387956..2eb6aaab4e84 100644
@@ -872,6 +872,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);
 
@@ -970,7 +971,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
     }
 
     trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type);
-    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)
Signature · 1 line
2.47.1
#4 lore raw

PATCH v6 4/10 virtio-gpu: Support asynchronous fencing

In reply to Dmitry Osipenko

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.

---
 hw/display/virtio-gpu-gl.c     |   3 +
 hw/display/virtio-gpu-virgl.c  | 147 +++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-gpu.h |  13 +++
 3 files changed, 154 insertions(+), 9 deletions(-)
hw/display/virtio-gpu-gl.c +3 -0
index 683fad3bf8a8..d9bb50ac1d4a 100644
@@ -169,6 +169,9 @@ 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);
+
+        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);
hw/display/virtio-gpu-virgl.c +138 -9

183 lines not on this page · raw message

include/hw/virtio/virtio-gpu.h +13 -0
index a42957c4e2cc..bd2cccdc60d7 100644
@@ -230,6 +230,13 @@ struct VirtIOGPUClass {
                              Error **errp);
 };
 
+struct virtio_gpu_virgl_context_fence {
+    uint32_t ctx_id;
+    int64_t ring_idx;
+    uint64_t fence_id;
+    QSLIST_ENTRY(virtio_gpu_virgl_context_fence) next;
+};
+
 /* VirtIOGPUGL renderer states */
 typedef enum {
     RS_START,       /* starting state */
@@ -247,6 +254,11 @@ struct VirtIOGPUGL {
     QEMUTimer *print_stats;
 
     QEMUBH *cmdq_resume_bh;
+
+    QEMUBH *async_fence_bh;
+    QSLIST_HEAD(, virtio_gpu_virgl_context_fence) async_fenceq;
+
+    bool context_fence_enabled;
 };
 
 struct VhostUserGPU {
@@ -376,5 +388,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
Signature · 1 line
2.47.1
Reviewed-by on v6 4/10
#5 lore raw

Re: [PATCH v6 04/10] virtio-gpu: Support asynchronous fencing

Quoted 10 lines · Dmitry Osipenko

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.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#6 lore raw

PATCH v6 5/10 virtio-gpu: Support DRM native context

In reply to Dmitry Osipenko

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.

---
 docs/system/devices/virtio-gpu.rst | 11 +++++++++++
 hw/display/virtio-gpu-gl.c         |  2 ++
 hw/display/virtio-gpu-virgl.c      | 22 ++++++++++++++++++++++
 hw/display/virtio-gpu.c            | 15 +++++++++++++++
 include/hw/virtio/virtio-gpu.h     |  3 +++
 5 files changed, 53 insertions(+)
docs/system/devices/virtio-gpu.rst +11 -0
index b7eb0fc0e727..f20c60016376 100644
@@ -82,6 +82,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
 -------------------
 
hw/display/virtio-gpu-gl.c +2 -0
index d9bb50ac1d4a..5f374ad56396 100644
@@ -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)
hw/display/virtio-gpu-virgl.c +22 -0
index ee896eced67c..184ad2c588f7 100644
@@ -1248,6 +1248,19 @@ 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 (!gl->context_fence_enabled) {
+            /*
+             * 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.
+             */
+            error_report("DRM native context requires EGL display");
+            return -EINVAL;
+        }
+    }
 #endif
 
     ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs);
@@ -1310,5 +1323,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;
 }
hw/display/virtio-gpu.c +15 -0
index 11a7a8575027..165a0976480d 100644
@@ -1505,6 +1505,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,
include/hw/virtio/virtio-gpu.h +3 -0
index bd2cccdc60d7..dcdf52b192b5 100644
@@ -99,6 +99,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) \
@@ -121,6 +122,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;
Signature · 1 line
2.47.1
#7 lore raw

PATCH v6 6/10 ui/sdl2: Don't disable scanout when display is refreshed

In reply to 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.

---
 ui/sdl2-gl.c | 1 -
 1 file changed, 1 deletion(-)
ui/sdl2-gl.c +0 -1
index 8d53e340d40d..31f8fbe03286 100644
@@ -53,7 +53,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);
Signature · 1 line
2.47.1
#8 lore raw

PATCH v6 7/10 ui/gtk: Don't disable scanout when display is refreshed

In reply to 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.

---
 ui/gtk-egl.c     | 1 -
 ui/gtk-gl-area.c | 1 -
 2 files changed, 2 deletions(-)
ui/gtk-egl.c +0 -1
index f7a428c86a8d..0d1547d63ad0 100644
@@ -179,7 +179,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);
     }
 }
ui/gtk-gl-area.c +0 -1
index 2c9a0db42571..53d81124f211 100644
@@ -148,7 +148,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));
     }
 }
Signature · 1 line
2.47.1
#9 lore raw

PATCH v6 8/10 docs/system: virtio-gpu: Add link to Mesa VirGL doc

In reply to Dmitry Osipenko

Extend virtio-gpu documentation with a link to the Mesa VirGL documentation.

---
 docs/system/devices/virtio-gpu.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +2 -1
index f20c60016376..f8963c1f13cf 100644
@@ -59,7 +59,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
@@ -68,6 +68,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/
 
Signature · 1 line
2.47.1
#10 lore raw

PATCH v6 9/10 docs/system: virtio-gpu: Update Venus link

In reply to Dmitry Osipenko

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.

---
 docs/system/devices/virtio-gpu.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +1 -1
index f8963c1f13cf..ea3eb052df3c 100644
@@ -81,7 +81,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
Signature · 1 line
2.47.1
#11 lore raw

PATCH v6 10/10 docs/system: virtio-gpu: Document host/guest requirements

In reply to Dmitry Osipenko

From: Alex Bennée <[email protected]>

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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]
---
 docs/system/devices/virtio-gpu.rst | 107 ++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +106 -1
index ea3eb052df3c..b3db984ff2d3 100644
@@ -5,7 +5,9 @@ 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
 --------------------
@@ -13,6 +15,24 @@ Linux kernel support
 virtio-gpu requires a guest Linux kernel built with the
 ``CONFIG_DRM_VIRTIO_GPU`` option.
 
+Dependencies
+............
+
+.. note::
+  GPU virtualisation is still an evolving field. Depending on the mode
+  you are running you may need to override distribution supplied
+  libraries with more recent versions or enable build options.
+
+  Depending on the mode there are a number of requirements the host must
+  meet to be able to be able to support guests. For 3D acceleration QEMU
+  must be able to access the hosts GPU and for the best performance be
+  able to reliably share GPU memory with the guest.
+
+  Virtio-gpu requires a guest Linux kernel built with the
+  ``CONFIG_DRM_VIRTIO_GPU`` option. For 3D accelerations you
+  will need support from guest Mesa configured for whichever encapsulation
+  you need.
+
 QEMU virtio-gpu variants
 ------------------------
 
@@ -56,6 +76,16 @@ on typical modern Linux distributions.
 .. _Mesa: https://www.mesa3d.org/
 .. _SwiftShader: https://github.com/google/swiftshader
 
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu
+    - Framebuffer enabled
+    - GTK or SDL display
+
 virtio-gpu virglrenderer
 ------------------------
 
@@ -94,6 +124,61 @@ 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:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - GPU enabled
+    - libvirglrenderer (virgl support)
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.0.0, venus support)
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.1.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - Linux 6.4+
+    - libvirglrenderer (>= 1.0.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1384`_, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1274`_, DRM renderer support)
+
+.. _mr1384: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1384
+.. _mr1274: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1274
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - 20.3.0+
+    - -Dgallium-drivers=virgl
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - 24.2.0+
+    - -Dvulkan-drivers=virtio
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - 25.0.0+
+    - -Dgallium-drivers=radeonsi -Dvulkan-drivers=amd -Damdgpu-virtio=true
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - 23.1.0+
+    - -Dgallium-drivers=freedreno -Dvulkan-drivers=freedreno
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - `mr29870`_
+    - -Dgallium-drivers=iris -Dvulkan-drivers=intel -Dintel-virtio-experimental=true
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - 24.2.0+
+    - -Dgallium-drivers=asahi -Dvulkan-drivers=asahi
+
+.. _mr29870: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870
+
 virtio-gpu rutabaga
 -------------------
 
@@ -133,3 +218,23 @@ 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:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - 24.3.0+
+    - -Dvulkan-drivers=gfxstream
Signature · 1 line
2.47.1
#12 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

Quoted 31 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>

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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]
---
  docs/system/devices/virtio-gpu.rst | 107 ++++++++++++++++++++++++++++-
  1 file changed, 106 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +3 -1
index ea3eb052df3c..b3db984ff2d3 100644
@@ -5,7 +5,9 @@ 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
  --------------------

docs/system/devices/virtio-gpu.rst Linux kernel support · line 24

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +7 -0
@@ -13,6 +15,24 @@ Linux kernel support
  virtio-gpu requires a guest Linux kernel built with the
  ``CONFIG_DRM_VIRTIO_GPU`` option.
 
+Dependencies
+............
+
+.. note::
+  GPU virtualisation is still an evolving field. Depending on the mode
+  you are running you may need to override distribution supplied
+  libraries with more recent versions or enable build options.

s/virtualisation/virtualization/ for consistency with other documentations.

docs/system/devices/virtio-gpu.rst Linux kernel support · line 34

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+  Depending on the mode there are a number of requirements the host must
+  meet to be able to be able to support guests. For 3D acceleration QEMU
+  must be able to access the hosts GPU and for the best performance be
+  able to reliably share GPU memory with the guest.
+
+  Virtio-gpu requires a guest Linux kernel built with the
+  ``CONFIG_DRM_VIRTIO_GPU`` option. For 3D accelerations you
+  will need support from guest Mesa configured for whichever encapsulation
+  you need.

This section is part of the "Linux kernel support" chapter, which used to describe the guest Linux kernel requirement, but this section discusses a broader topic that includes the host requirements and guest Mesa. This section needs to be re-structured.

It says "GPU virtualisation is still an evolving field", but I believe the main evolving field is 3D acceleration. The later parts also repetitively mention 3D acceleration. Instead of repeating the same phrase, let the reader know that this section talks about 3D acceleration at the beginning. It will make the section more concise and allows readers to skip it when they do not care 3D acceleration.

The ``CONFIG_DRM_VIRTIO_GPU`` option is already described earlier so its description is redundant.

Quoted 6 lines
docs/system/devices/virtio-gpu.rst +1 -0
+
  QEMU virtio-gpu variants
  ------------------------
 
@@ -56,6 +76,16 @@ on typical modern Linux distributions.
  .. _Mesa: https://www.mesa3d.org/

docs/system/devices/virtio-gpu.rst on typical modern Linux distributions. · line 86

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +8 -0
  .. _SwiftShader: https://github.com/google/swiftshader
 
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu
+    - Framebuffer enabled

It is not clear what "framebuffer enabled" means, and it is also inconsistent with the host requirements tables in later sections that describes the Linux kernel version. Also be aware that virtio-gpu works effectively anywhere, not just Linux.

docs/system/devices/virtio-gpu.rst on typical modern Linux distributions. · line 87

Quoted 1 line
docs/system/devices/virtio-gpu.rst +1 -0
+    - GTK or SDL display

It is also inconsistent with later section that describes acceleration backends instead of the display. virtio-gpu also works with any display and is not restricted to GTK or SDL.

Quoted 5 lines
docs/system/devices/virtio-gpu.rst +1 -0
+
  virtio-gpu virglrenderer
  ------------------------
 

docs/system/devices/virtio-gpu.rst of virtio-gpu host memory window. This is typically between 256M and 8G. · line 133

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +7 -0
@@ -94,6 +124,61 @@ 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:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (OpenGL pass-through)

It's already in the "virtio-gpu virglrenderer" setion so you don't have to mention "virtio-gpu-gl" again here.

docs/system/devices/virtio-gpu.rst of virtio-gpu host memory window. This is typically between 256M and 8G. · line 134

Quoted 1 line
docs/system/devices/virtio-gpu.rst +1 -0
+    - GPU enabled> +    - libvirglrenderer (virgl support)> +  * - virtio-gpu-gl (Vulkan 

pass-through)

docs/system/devices/virtio-gpu.rst of virtio-gpu host memory window. This is typically between 256M and 8G. · line 138

Quoted 2 lines
docs/system/devices/virtio-gpu.rst +2 -0
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.0.0, venus support)

"venus support" is a vague wording. I can guess it means it requires a build flag, but it's not clear for a novice.

Perhaps you may write the build flag as you did for Mesa.

docs/system/devices/virtio-gpu.rst of virtio-gpu host memory window. This is typically between 256M and 8G. · line 137

Quoted 1 line
docs/system/devices/virtio-gpu.rst +1 -0
+  * - virtio-gpu-gl (vDRM native context/AMD)

The later part of documentation calls it "DRM native context", not "vDRM native context"; let's keep them consistent. "vDRM native context" seems rarely used; I could only find one example of existing literature:
https://www.collabora.com/news-and-blog/blog/2025/01/15/the-state-of-gfx-virtualization-using-virglrenderer/

Mesa has a directory named vdrm but it is mentioned in no user-facing documentation.

Quoted 48 lines
docs/system/devices/virtio-gpu.rst +41 -0
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.1.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - Linux 6.4+
+    - libvirglrenderer (>= 1.0.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1384`_, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1274`_, DRM renderer support)
+
+.. _mr1384: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1384
+.. _mr1274: https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1274
+> +.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - 20.3.0+
+    - -Dgallium-drivers=virgl
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - 24.2.0+
+    - -Dvulkan-drivers=virtio
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - 25.0.0+
+    - -Dgallium-drivers=radeonsi -Dvulkan-drivers=amd -Damdgpu-virtio=true
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - 23.1.0+
+    - -Dgallium-drivers=freedreno -Dvulkan-drivers=freedreno
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - `mr29870`_
+    - -Dgallium-drivers=iris -Dvulkan-drivers=intel -Dintel-virtio-experimental=true
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - 24.2.0+
+    - -Dgallium-drivers=asahi -Dvulkan-drivers=asahi
+
+.. _mr29870: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870
+
  virtio-gpu rutabaga
  -------------------
 
@@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 230

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support

Let's omit the mention of aemu. It is a dependency of rutabaga_gfx_ffi and referring to dependencies of our dependencies will make the documentation too cluttered. Users should also see rutabaga_gfx_ffi needs aemu anyway in its build guide; the reference of aemu here is effectively redundant.

I don't see the vhost-user support in Rutabaga. Does it really exist?

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - 24.3.0+
+    - -Dvulkan-drivers=gfxstream
#13 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

Quoted 11 lines · Akihiko Odaki
Quoted 10 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>
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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]

<snip>

Quoted 24 lines
Quoted 7 lines

virtio-gpu rutabaga
-------------------
@@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 230

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support

Let's omit the mention of aemu. It is a dependency of rutabaga_gfx_ffi and referring to dependencies of our dependencies will make the documentation too cluttered. Users should also see rutabaga_gfx_ffi needs aemu anyway in its build guide; the reference of aemu here is effectively redundant.

Quoted 1 line

I don't see the vhost-user support in Rutabaga. Does it really exist?

vhost-device-gpu supports gfxstream although the 3D acceleration parts of that are still WIP:

https://github.com/rust-vmm/vhost-device/tree/main/staging/vhost-device-gpu

Quoted 11 lines
Quoted 11 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - 24.3.0+
+    - -Dvulkan-drivers=gfxstream
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#14 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

Quoted 38 lines · Alex Bennée
Quoted 11 lines · Akihiko Odaki
Quoted 10 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>
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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]

<snip>

Quoted 24 lines
Quoted 7 lines
   virtio-gpu rutabaga
   -------------------
   @@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 230

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support

Let's omit the mention of aemu. It is a dependency of rutabaga_gfx_ffi and referring to dependencies of our dependencies will make the documentation too cluttered. Users should also see rutabaga_gfx_ffi needs aemu anyway in its build guide; the reference of aemu here is effectively redundant.

Quoted 6 lines
Quoted 1 line

I don't see the vhost-user support in Rutabaga. Does it really exist?

vhost-device-gpu supports gfxstream although the 3D acceleration parts of that are still WIP:

https://github.com/rust-vmm/vhost-device/tree/main/staging/vhost-device-gpu

It is nice to know the project.

vhost-user support is implemented with virtio-gpu-gl but it has its own device variant so it is not a right place to describe it. vhost-user-gpu is not documented at all so if you are going to write its documentation it will be a great addition.

Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
docs/system/devices/virtio-gpu.rst +10 -0
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)
+    - 24.3.0+
+    - -Dvulkan-drivers=gfxstream
#15 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

In reply to Akihiko Odaki

On 1/27/25 09:28, Akihiko Odaki wrote:
...

Thanks for the doc review! Will improve the patch in the next iteration.

Signature · 2 lines
Best regards,
Dmitry
#16 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

In reply to Dmitry Osipenko
Quoted 157 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>

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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]
---
 docs/system/devices/virtio-gpu.rst | 107 ++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +31 -1
index ea3eb052df3c..b3db984ff2d3 100644
@@ -5,7 +5,9 @@ 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
 --------------------
@@ -13,6 +15,24 @@ Linux kernel support
 virtio-gpu requires a guest Linux kernel built with the
 ``CONFIG_DRM_VIRTIO_GPU`` option.
 
+Dependencies
+............
+
+.. note::
+  GPU virtualisation is still an evolving field. Depending on the mode
+  you are running you may need to override distribution supplied
+  libraries with more recent versions or enable build options.
+
+  Depending on the mode there are a number of requirements the host must
+  meet to be able to be able to support guests. For 3D acceleration QEMU
+  must be able to access the hosts GPU and for the best performance be
+  able to reliably share GPU memory with the guest.
+
+  Virtio-gpu requires a guest Linux kernel built with the
+  ``CONFIG_DRM_VIRTIO_GPU`` option. For 3D accelerations you
+  will need support from guest Mesa configured for whichever encapsulation
+  you need.
+
 QEMU virtio-gpu variants
 ------------------------
 
@@ -56,6 +76,16 @@ on typical modern Linux distributions.
 .. _Mesa: https://www.mesa3d.org/
 .. _SwiftShader: https://github.com/google/swiftshader
 
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu
+    - Framebuffer enabled
+    - GTK or SDL display
+
 virtio-gpu virglrenderer
 ------------------------
 
@@ -94,6 +124,61 @@ 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:: Host Requirements

docs/system/devices/virtio-gpu.rst +25 -0
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - GPU enabled
+    - libvirglrenderer (virgl support)
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.0.0, venus support)
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.1.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - Linux 6.4+
+    - libvirglrenderer (>= 1.0.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1384`_, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1274`_, DRM renderer support)
+
+.. _mr1384:

https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1384
+.. _mr1274:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1274

docs/system/devices/virtio-gpu.rst +27 -1
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - 20.3.0+
+    - -Dgallium-drivers=virgl
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - 24.2.0+
+    - -Dvulkan-drivers=virtio
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - 25.0.0+
+    - -Dgallium-drivers=radeonsi -Dvulkan-drivers=amd -Damdgpu-virtio=true
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - 23.1.0+
+    - -Dgallium-drivers=freedreno -Dvulkan-drivers=freedreno
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - `mr29870`_
+    - -Dgallium-drivers=iris -Dvulkan-drivers=intel
-Dintel-virtio-experimental=true
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - 24.2.0+
+    - -Dgallium-drivers=asahi -Dvulkan-drivers=asahi
+
+.. _mr29870:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870

docs/system/devices/virtio-gpu.rst +1 -0
+
 virtio-gpu rutabaga
 -------------------
@@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst +8 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 238

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)

Shouldn't this be virtio-gpu-rutabaga instead of virtio-gpu-gl? If we're including WiP MRs, can we include Magma too??

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33190

Quoted 6 lines
docs/system/devices/virtio-gpu.rst +2 -1
+    - 24.3.0+
+    - -Dvulkan-drivers=gfxstream
--

2.47.1

#17 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

Quoted 174 lines · Gurchetan Singh
Quoted 157 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>

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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]
---
 docs/system/devices/virtio-gpu.rst | 107 ++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +31 -1
index ea3eb052df3c..b3db984ff2d3 100644
@@ -5,7 +5,9 @@ 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
 --------------------
@@ -13,6 +15,24 @@ Linux kernel support
 virtio-gpu requires a guest Linux kernel built with the
 ``CONFIG_DRM_VIRTIO_GPU`` option.
 
+Dependencies
+............
+
+.. note::
+  GPU virtualisation is still an evolving field. Depending on the mode
+  you are running you may need to override distribution supplied
+  libraries with more recent versions or enable build options.
+
+  Depending on the mode there are a number of requirements the host must
+  meet to be able to be able to support guests. For 3D acceleration QEMU
+  must be able to access the hosts GPU and for the best performance be
+  able to reliably share GPU memory with the guest.
+
+  Virtio-gpu requires a guest Linux kernel built with the
+  ``CONFIG_DRM_VIRTIO_GPU`` option. For 3D accelerations you
+  will need support from guest Mesa configured for whichever encapsulation
+  you need.
+
 QEMU virtio-gpu variants
 ------------------------
 
@@ -56,6 +76,16 @@ on typical modern Linux distributions.
 .. _Mesa: https://www.mesa3d.org/
 .. _SwiftShader: https://github.com/google/swiftshader
 
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu
+    - Framebuffer enabled
+    - GTK or SDL display
+
 virtio-gpu virglrenderer
 ------------------------
 
@@ -94,6 +124,61 @@ 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:: Host Requirements

docs/system/devices/virtio-gpu.rst +25 -0
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - GPU enabled
+    - libvirglrenderer (virgl support)
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.0.0, venus support)
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.1.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - Linux 6.4+
+    - libvirglrenderer (>= 1.0.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1384`_, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1274`_, DRM renderer support)
+
+.. _mr1384:

https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1384
+.. _mr1274:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1274

docs/system/devices/virtio-gpu.rst +27 -1
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - 20.3.0+
+    - -Dgallium-drivers=virgl
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - 24.2.0+
+    - -Dvulkan-drivers=virtio
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - 25.0.0+
+    - -Dgallium-drivers=radeonsi -Dvulkan-drivers=amd -Damdgpu-virtio=true
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - 23.1.0+
+    - -Dgallium-drivers=freedreno -Dvulkan-drivers=freedreno
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - `mr29870`_
+    - -Dgallium-drivers=iris -Dvulkan-drivers=intel
-Dintel-virtio-experimental=true
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - 24.2.0+
+    - -Dgallium-drivers=asahi -Dvulkan-drivers=asahi
+
+.. _mr29870:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870

docs/system/devices/virtio-gpu.rst +1 -0
+
 virtio-gpu rutabaga
 -------------------
@@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst +8 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 238

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)

Shouldn't this be virtio-gpu-rutabaga instead of virtio-gpu-gl? If we're including WiP MRs, can we include Magma too??

Quoted 1 line

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33190

Indeed, will correct it. And add the link. Thanks!

Signature · 2 lines
Best regards,
Dmitry
#18 lore raw

Re: [PATCH v6 10/10] docs/system: virtio-gpu: Document host/guest requirements

Quoted 175 lines · Dmitry Osipenko
Quoted 174 lines · Gurchetan Singh
Quoted 157 lines · Dmitry Osipenko

From: Alex Bennée <[email protected]>

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.

Cc Sergio Lopez Pascual <[email protected]>
[[email protected]: Extended and corrected doc]
---
 docs/system/devices/virtio-gpu.rst | 107 ++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)
docs/system/devices/virtio-gpu.rst +31 -1
index ea3eb052df3c..b3db984ff2d3 100644
@@ -5,7 +5,9 @@ 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
 --------------------
@@ -13,6 +15,24 @@ Linux kernel support
 virtio-gpu requires a guest Linux kernel built with the
 ``CONFIG_DRM_VIRTIO_GPU`` option.
 
+Dependencies
+............
+
+.. note::
+  GPU virtualisation is still an evolving field. Depending on the mode
+  you are running you may need to override distribution supplied
+  libraries with more recent versions or enable build options.
+
+  Depending on the mode there are a number of requirements the host must
+  meet to be able to be able to support guests. For 3D acceleration QEMU
+  must be able to access the hosts GPU and for the best performance be
+  able to reliably share GPU memory with the guest.
+
+  Virtio-gpu requires a guest Linux kernel built with the
+  ``CONFIG_DRM_VIRTIO_GPU`` option. For 3D accelerations you
+  will need support from guest Mesa configured for whichever encapsulation
+  you need.
+
 QEMU virtio-gpu variants
 ------------------------
 
@@ -56,6 +76,16 @@ on typical modern Linux distributions.
 .. _Mesa: https://www.mesa3d.org/
 .. _SwiftShader: https://github.com/google/swiftshader
 
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu
+    - Framebuffer enabled
+    - GTK or SDL display
+
 virtio-gpu virglrenderer
 ------------------------
 
@@ -94,6 +124,61 @@ 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:: Host Requirements

docs/system/devices/virtio-gpu.rst +25 -0
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - GPU enabled
+    - libvirglrenderer (virgl support)
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.0.0, venus support)
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - Linux 6.13+
+    - libvirglrenderer (>= 1.1.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - Linux 6.4+
+    - libvirglrenderer (>= 1.0.0, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1384`_, DRM renderer support)
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - Linux 6.13+
+    - libvirglrenderer (`mr1274`_, DRM renderer support)
+
+.. _mr1384:

https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1384
+.. _mr1274:
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1274

docs/system/devices/virtio-gpu.rst +27 -1
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (OpenGL pass-through)
+    - 20.3.0+
+    - -Dgallium-drivers=virgl
+  * - virtio-gpu-gl (Vulkan pass-through)
+    - 24.2.0+
+    - -Dvulkan-drivers=virtio
+  * - virtio-gpu-gl (vDRM native context/AMD)
+    - 25.0.0+
+    - -Dgallium-drivers=radeonsi -Dvulkan-drivers=amd -Damdgpu-virtio=true
+  * - virtio-gpu-gl (vDRM native context/Freedreno)
+    - 23.1.0+
+    - -Dgallium-drivers=freedreno -Dvulkan-drivers=freedreno
+  * - virtio-gpu-gl (vDRM native context/Intel i915)
+    - `mr29870`_
+    - -Dgallium-drivers=iris -Dvulkan-drivers=intel
-Dintel-virtio-experimental=true
+  * - virtio-gpu-gl (vDRM native context/Asahi)
+    - 24.2.0+
+    - -Dgallium-drivers=asahi -Dvulkan-drivers=asahi
+
+.. _mr29870:

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29870

docs/system/devices/virtio-gpu.rst +1 -0
+
 virtio-gpu rutabaga
 -------------------
@@ -133,3 +218,23 @@ 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

docs/system/devices/virtio-gpu.rst +8 -0
+
+.. list-table:: Host Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Kernel
+    - Userspace
+  * - virtio-gpu-gl (rutabaga/gfxstream)

docs/system/devices/virtio-gpu.rst Surfaceless is the default if ``wsi`` is not specified. · line 238

Quoted 10 lines
docs/system/devices/virtio-gpu.rst +10 -0
+    - GPU enabled
+    - aemu/rutabaga_gfx_ffi or vhost-user client with support
+
+.. list-table:: Guest Requirements
+  :header-rows: 1
+
+  * - Mode
+    - Mesa Version
+    - Mesa build flags
+  * - virtio-gpu-gl (rutabaga/gfxstream)

Shouldn't this be virtio-gpu-rutabaga instead of virtio-gpu-gl? If we're including WiP MRs, can we include Magma too??

Quoted 3 lines
Quoted 1 line

https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33190

Indeed, will correct it. And add the link. Thanks!

RE the link. virtio-gpu-rutabaga doesn't support gfxstream-magma capset, hence I see no place to add the link. We are adding links to supported features only here. For the magma link should be added once virtio-gpu-rutabaga will support it, like it was done for venus and now for nctx capsets.

Signature · 2 lines
Best regards,
Dmitry
#19 lore raw
In reply to Dmitry Osipenko
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

Quoted 6 lines

[1] https://www.youtube.com/watch?v=9sFP_yddLLQ

Today there are four DRM native context drivers existing in a wild:

- Freedreno (Qualcomm SoC GPUs), completely upstreamed
- AMDGPU, completely upstreamed

Well good news and bad news.

I can verify that AMD native context works when I run my Aarch64 guest on my Aarch64 host with -accel TCG (therefor avoiding KVM all together). I get potato frame rates though (~150FPS) although I suspect that is because the PCI errata workaround.

When it comes to graphics memory allocation is there anything I can do to force all allocations to be very aligned? Is this in the purview of the AMD drm drivers or TTM itself?

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

Quoted 3 lines

- Intel (i915), merge requests are opened
- Asahi (Apple SoC GPUs), partially merged upstream

<snip>

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#20 lore raw
Quoted 20 lines · Alex Bennée
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

Quoted 6 lines

[1] https://www.youtube.com/watch?v=9sFP_yddLLQ

Today there are four DRM native context drivers existing in a wild:

- Freedreno (Qualcomm SoC GPUs), completely upstreamed
- AMDGPU, completely upstreamed

Well good news and bad news.

Quoted 8 lines

I can verify that AMD native context works when I run my Aarch64 guest on my Aarch64 host with -accel TCG (therefor avoiding KVM all together). I get potato frame rates though (~150FPS) although I suspect that is because the PCI errata workaround.

When it comes to graphics memory allocation is there anything I can do to force all allocations to be very aligned? Is this in the purview of the AMD drm drivers or TTM itself?

All GPU allocations should be aligned to a page size. Alignment is specified by AMD driver. I don't expect that alignment is the problem. What's the size of your host and guest pages?

Signature · 2 lines
Best regards,
Dmitry
#21 lore raw
Quoted 26 lines · Dmitry Osipenko
Quoted 25 lines · Alex Bennée
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

Quoted 6 lines

[1] https://www.youtube.com/watch?v=9sFP_yddLLQ

Today there are four DRM native context drivers existing in a wild:

- Freedreno (Qualcomm SoC GPUs), completely upstreamed
- AMDGPU, completely upstreamed

Well good news and bad news.

I can verify that AMD native context works when I run my Aarch64 guest on my Aarch64 host with -accel TCG (therefor avoiding KVM all together). I get potato frame rates though (~150FPS) although I suspect that is because the PCI errata workaround.

Quoted 7 lines
Quoted 3 lines

When it comes to graphics memory allocation is there anything I can do to force all allocations to be very aligned? Is this in the purview of the AMD drm drivers or TTM itself?

All GPU allocations should be aligned to a page size. Alignment is specified by AMD driver. I don't expect that alignment is the problem. What's the size of your host and guest pages?

4k AFAIK.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
author Acked-by Marc-André Lureau
#22 lore raw
In reply to Alex Bennée

On 1/27/25 19:17, Alex Bennée wrote:
...

Quoted 3 lines

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

I reproduced the display mirroring/corruption issue and bisected it to the following commit. The problem only happens when QEMU/GTK uses Wayland display directly, while previously I was running QEMU with XWayland that doesn't have the problem. Why this change breaks dmabuf displaying with Wayland/GTK is unclear. Reverting commit fixes the bug.

+Dongwon Kim +Vivek Kasireddy

commit 77bf310084dad38b3a2badf01766c659056f1cf2

Author: Dongwon Kim <[email protected]>
Date:   Fri Apr 26 15:50:59 2024 -0700

ui/gtk: Draw guest frame at refresh cycle

Draw routine needs to be manually invoked in the next refresh if there is a scanout blob from the guest. This is to prevent a situation where there is a scheduled draw event but it won't happen bacause the window is currently in inactive state (minimized or tabified). If draw is not done for a long time, gl_block timeout and/or fence timeout (on the guest) will happen eventually.

v2: Use gd_gl_area_draw(vc) in gtk-gl-area.c

Message-Id: <[email protected]>

Signature · 2 lines
Best regards,
Dmitry
#23 lore raw
Quoted 11 lines · Dmitry Osipenko

On 1/27/25 19:17, Alex Bennée wrote:
...

Quoted 3 lines

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

I reproduced the display mirroring/corruption issue and bisected it to the following commit. The problem only happens when QEMU/GTK uses Wayland display directly, while previously I was running QEMU with XWayland that doesn't have the problem. Why this change breaks dmabuf displaying with Wayland/GTK is unclear.

Ahh that makes sense - I obviously forgot to mention I'm running sway/wayland across both machines.

Quoted 20 lines

Reverting commit fixes the bug.

+Dongwon Kim +Vivek Kasireddy

commit 77bf310084dad38b3a2badf01766c659056f1cf2

Author: Dongwon Kim <[email protected]>
Date:   Fri Apr 26 15:50:59 2024 -0700

ui/gtk: Draw guest frame at refresh cycle

Draw routine needs to be manually invoked in the next refresh if there is a scanout blob from the guest. This is to prevent a situation where there is a scheduled draw event but it won't happen bacause the window is currently in inactive state (minimized or tabified). If draw is not done for a long time, gl_block timeout and/or fence timeout (on the guest) will happen eventually.

v2: Use gd_gl_area_draw(vc) in gtk-gl-area.c

Quoted 7 lines

Message-Id: <[email protected]>

Maybe a race on:

    QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;

?

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#24 lore raw

Hi,

The commit below could change the timing of drawing by making the drawing done at refresh cycle instead of via drawing event. So it looks like either dmabuf or client's framebuffer is being written and read at the same time. Hey, can you describe how the corruption looks like? Is it just garbage image with random noise or the actual frame with some defects like tearing...?

Quoted 55 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 11 lines · Dmitry Osipenko

On 1/27/25 19:17, Alex Bennée wrote:
...

Quoted 3 lines

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

I reproduced the display mirroring/corruption issue and bisected it to the following commit. The problem only happens when QEMU/GTK uses Wayland display directly, while previously I was running QEMU with XWayland that doesn't have the problem. Why this change breaks dmabuf displaying with Wayland/GTK is unclear.

Ahh that makes sense - I obviously forgot to mention I'm running sway/wayland across both machines.

Quoted 20 lines

Reverting commit fixes the bug.

+Dongwon Kim +Vivek Kasireddy

commit 77bf310084dad38b3a2badf01766c659056f1cf2

Author: Dongwon Kim <[email protected]>
Date:   Fri Apr 26 15:50:59 2024 -0700

ui/gtk: Draw guest frame at refresh cycle

Draw routine needs to be manually invoked in the next refresh if there is a scanout blob from the guest. This is to prevent a situation where there is a scheduled draw event but it won't happen bacause the window is currently in inactive state (minimized or tabified). If draw is not done for a long time, gl_block timeout and/or fence timeout (on the guest) will happen eventually.

v2: Use gd_gl_area_draw(vc) in gtk-gl-area.c

Quoted 7 lines

Message-Id: <[email protected]>

Maybe a race on:

    QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; ?

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

#25 lore raw
Quoted 7 lines · Dongwon

Hi,

The commit below could change the timing of drawing by making the drawing done at refresh cycle instead of via drawing event. So it looks like either dmabuf or client's framebuffer is being written and read at the same time. Hey, can you describe how the corruption looks like? Is it just garbage image with random noise or the actual frame with some defects like tearing...?

The terminal gets mirrored upside down and the mouse creates damage as it moves about.

Quoted 56 lines
Quoted 56 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 11 lines · Dmitry Osipenko

On 1/27/25 19:17, Alex Bennée wrote:
...

Quoted 3 lines

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

I reproduced the display mirroring/corruption issue and bisected it to the following commit. The problem only happens when QEMU/GTK uses Wayland display directly, while previously I was running QEMU with XWayland that doesn't have the problem. Why this change breaks dmabuf displaying with Wayland/GTK is unclear.

Ahh that makes sense - I obviously forgot to mention I'm running sway/wayland across both machines.

Quoted 20 lines

Reverting commit fixes the bug.

+Dongwon Kim +Vivek Kasireddy

commit 77bf310084dad38b3a2badf01766c659056f1cf2

Author: Dongwon Kim <[email protected]>
Date:   Fri Apr 26 15:50:59 2024 -0700

ui/gtk: Draw guest frame at refresh cycle

Draw routine needs to be manually invoked in the next refresh if there is a scanout blob from the guest. This is to prevent a situation where there is a scheduled draw event but it won't happen bacause the window is currently in inactive state (minimized or tabified). If draw is not done for a long time, gl_block timeout and/or fence timeout (on the guest) will happen eventually.

v2: Use gd_gl_area_draw(vc) in gtk-gl-area.c

Quoted 7 lines

Message-Id: <[email protected]>

Maybe a race on:

    QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; ?

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#26 lore raw
Quoted 11 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 7 lines · Dongwon

Hi,

The commit below could change the timing of drawing by making the drawing done at refresh cycle instead of via drawing event. So it looks like either dmabuf or client's framebuffer is being written and read at the same time. Hey, can you describe how the corruption looks like? Is it just garbage image with random noise or the actual frame with some

Quoted 4 lines

defects like tearing...?

The terminal gets mirrored upside down and the mouse creates damage as it moves about.

I am wondering if this is reproducible without virgl and drm native context (like w/ sw rasterizer on the guest) as well.

Quoted 61 lines
Quoted 50 lines
Quoted 50 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 11 lines · Dmitry Osipenko

On 1/27/25 19:17, Alex Bennée wrote:
...

Quoted 3 lines

I'm still seeing corruption with -display gtk,gl=on on my x86 system BTW. I would like to understand if that is a problem with QEMU, GTK or something else in the stack before we merge.

I reproduced the display mirroring/corruption issue and bisected it to the following commit. The problem only happens when QEMU/GTK uses Wayland display directly, while previously I was running QEMU with XWayland that doesn't have the problem. Why this change breaks dmabuf displaying with Wayland/GTK is unclear.

Ahh that makes sense - I obviously forgot to mention I'm running sway/wayland across both machines.

Quoted 27 lines

Reverting commit fixes the bug.

+Dongwon Kim +Vivek Kasireddy

commit 77bf310084dad38b3a2badf01766c659056f1cf2

Author: Dongwon Kim <[email protected]>
Date:   Fri Apr 26 15:50:59 2024 -0700

ui/gtk: Draw guest frame at refresh cycle

Draw routine needs to be manually invoked in the next refresh if there is a scanout blob from the guest. This is to prevent a situation where there is a scheduled draw event but it won't happen bacause the window is currently in inactive state (minimized or tabified). If draw is not done for a long time, gl_block timeout and/or fence timeout (on the guest) will happen eventually.

v2: Use gd_gl_area_draw(vc) in gtk-gl-area.c

Message-Id: <[email protected]>

Quoted 7 lines
Quoted 7 lines

Maybe a race on:

    QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; ?

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

--
Alex Bennée
Virtualisation Tech Lead @ Linaro

#27 lore raw
Quoted 11 lines · Dongwon
Quoted 11 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 7 lines · Dongwon

Hi,

The commit below could change the timing of drawing by making the drawing done at refresh cycle instead of via drawing event. So it looks like either dmabuf or client's framebuffer is being written and read at the same time. Hey, can you describe how the corruption looks like? Is it just garbage image with random noise or the actual frame with some

Quoted 7 lines
Quoted 4 lines

defects like tearing...?

The terminal gets mirrored upside down and the mouse creates damage as it moves about.

I am wondering if this is reproducible without virgl and drm native context (like w/ sw rasterizer on the guest) as well.

It looks like a problem with redraw areas, see video sample [1].

[1]
https://drive.google.com/file/d/13PN2sFoPsM2ox6_gf9GLXStbsZ27xlLy/view?usp=sharing

It's reproducible without native context with a SW render using '-device virtio-vga,hostmem=8G,blob=on'

Signature · 2 lines
Best regards,
Dmitry
#28 lore raw

Thanks for showing me the video. I will take a look and check what would go wrong here. I kinda understand corruption may happen in some scenario but I don't know what could cause the upside down image. Do you have any idea?? Maybe the frame was temporarily replaced with a mishandled texture that QEMU creates from the surface temporarily but I am not sure..

In the worst case scenario, I think we may have to revert the change from gtk-gl-area.c for now until the problem is root-caused. But you would see some rendering timeout in case the GTK window is in invisible state (like minimization).

Quoted 35 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 12 lines · Dongwon
Quoted 12 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 8 lines · Dongwon

Hi,

The commit below could change the timing of drawing by making the drawing done at refresh cycle instead of via drawing event. So it looks like either dmabuf or client's framebuffer is being written and read at the same time. Hey, can you describe how the corruption looks like? Is it just garbage image with random noise or the actual frame with some

Quoted 7 lines
Quoted 4 lines

defects like tearing...?

The terminal gets mirrored upside down and the mouse creates damage as it moves about.

I am wondering if this is reproducible without virgl and drm native context (like w/ sw rasterizer on the guest) as well.

It looks like a problem with redraw areas, see video sample [1].

[1]
https://drive.google.com/file/d/13PN2sFoPsM2ox6_gf9GLXStbsZ27xlLy/view?u
sp=sharing

It's reproducible without native context with a SW render using '-device virtio- vga,hostmem=8G,blob=on'

--
Best regards,
Dmitry

#29 lore raw
Quoted 3 lines · Dongwon

Thanks for showing me the video. I will take a look and check what would go wrong here. I kinda understand corruption may happen in some scenario but I don't know what could cause the upside down image. Do you have any idea?? Maybe the frame was temporarily replaced with a mishandled texture that QEMU creates from the surface temporarily but I am not sure..

No clue. Could be anything. Could be a GTK/Wayland bug, could be an obscure QEMU bug. GTK expert wanted here.

Quoted 1 line

In the worst case scenario, I think we may have to revert the change from gtk-gl-area.c for now until the problem is root-caused.

Good to me

Quoted 1 line

But you would see some rendering timeout in case the GTK window is in invisible state (like minimization).

No timeouts observed

Signature · 2 lines
Best regards,
Dmitry
#30 lore raw
Quoted 5 lines · Dmitry Osipenko
Quoted 3 lines

Thanks for showing me the video. I will take a look and check what would go wrong here. I kinda understand corruption may happen in some scenario but I don't know what could cause the upside down image. Do you have any idea?? Maybe the frame was temporarily replaced with a mishandled texture that QEMU creates from the surface temporarily but I am not sure..

No clue. Could be anything. Could be a GTK/Wayland bug, could be an obscure QEMU bug. GTK expert wanted here.

Alright, it's bugged with "blob=on", but works with "blob=off". While I don't see QEMU using blobs. Might be QEMU's bug then.

Signature · 2 lines
Best regards,
Dmitry
#31 lore raw
Quoted 10 lines · Dmitry Osipenko
Quoted 5 lines · Dmitry Osipenko
Quoted 3 lines

Thanks for showing me the video. I will take a look and check what would go wrong here. I kinda understand corruption may happen in some scenario but I don't know what could cause the upside down image. Do you have any idea?? Maybe the frame was temporarily replaced with a mishandled texture that QEMU creates from the surface temporarily but I am not sure..

No clue. Could be anything. Could be a GTK/Wayland bug, could be an obscure QEMU bug. GTK expert wanted here.

Alright, it's bugged with "blob=on", but works with "blob=off". While I don't see QEMU using blobs. Might be QEMU's bug then.

Looked further at it. So QEMU was using blobs with "blob=on" and I was looking at a wrong place. Then I found that setting y0_top=true for dmabuf makes display to show upside down, but there is no rendering bug with it. Something redraws display with y0_top=true, while it should be y0_top=false. I couldn't figure out how it's related to the offending change.

I also noticed that QEMU checks Wayland presence in early_gtk_display_init() and doesn't use EGL callbacks that are used for X11 display, but the y0_top logic looks the same. Interestingly, Windows should be using same display code paths as Wayland, but I don't have ability to test Windows.

If nobody will be able to fix the bug soon, at least reverting the Wayland part will be good to do.

Signature · 2 lines
Best regards,
Dmitry
#32 lore raw

Hi Dmitry,

Quoted 18 lines

Subject: Re: [PATCH v6 00/10] Support virtio-gpu DRM native context

Quoted 2 lines · Dmitry Osipenko
Quoted 1 line · Dmitry Osipenko
Quoted 1 line

Thanks for showing me the video. I will take a look and check what would

go wrong here. I kinda understand corruption may happen

Quoted 1 line
Quoted 1 line
Quoted 1 line

in some scenario but I don't know what could cause the upside down

image. Do you have any idea?? Maybe the frame was temporarily replaced with

Quoted 1 line
Quoted 1 line
Quoted 1 line

a mishandled texture that QEMU creates from the surface temporarily but

I am not sure..

Quoted 6 lines
Quoted 2 lines

No clue. Could be anything. Could be a GTK/Wayland bug, could be an obscure QEMU bug. GTK expert wanted here.

Alright, it's bugged with "blob=on", but works with "blob=off". While I don't see QEMU using blobs. Might be QEMU's bug then.

Quoted 6 lines

Looked further at it. So QEMU was using blobs with "blob=on" and I was looking at a wrong place. Then I found that setting y0_top=true for dmabuf makes display to show upside down, but there is no rendering bug with it. Something redraws display with y0_top=true, while it should be y0_top=false. I couldn't figure out how it's related to the offending change.

It is possible that the additional draw call (offending change) is exposing a bug elsewhere. This is because having both blob=on and virgl=on was not a valid combo until recently. IIUC, virgl directly calls gd_gl_area_scanout_texture() with y0_top=true (sometimes) but I guess gd_gl_area_scanout_texture() might be getting called again with yo_top=false via gd_gl_area_scanout_dmabuf() in the same repaint cycle?

Quoted 9 lines

I also noticed that QEMU checks Wayland presence in early_gtk_display_init() and doesn't use EGL callbacks that are used for X11 display, but the y0_top logic looks the same. Interestingly, Windows should be using same display code paths as Wayland, but I don't have ability to test Windows.

If nobody will be able to fix the bug soon, at least reverting the Wayland part will be good to do.

Hope we can find a proper fix soon but looks like Dongwon already sent the patch to revert the changes in gtk-gl-area.c.

Thanks,
Vivek

Quoted 4 lines

--
Best regards,
Dmitry

#33 lore raw
In reply to Dmitry Osipenko
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

<snip>

So first the good news. I can now get this up and running (x86/kvm guest with Intel graphics) and as far as I can tell the native context mode is working. With Dongwon Kim's patch the mirroring/corruption I was seeing is gone.

I can successfully run glmark2-wayland (although see bellow) but vkmark completely fails to start reporting:

MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_FENCE_PASSING
MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_GUEST_HANDLE
MESA: error: DRM_IOCTL_VIRTGPU_GET_CAPS failed with Invalid argument
MESA: error: DRM_IOCTL_VIRTGPU_CONTEXT_INIT failed with Invalid argument, continuing without context...
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:681: VK_ERROR_DEVICE_LOST
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:332: VK_ERROR_DEVICE_LOST === Physical Device 0 ===

      Vendor ID:      0x8086
      Device ID:      0xA780
      Device Name:    Intel(R) Graphics (RPL-S)
      Driver Version: 101068899
      Device UUID:    b39e1cf39b101489e3c6039406f78d6c

I was booting with 4G of shared memory.

Later versions of vkmark (2025.01) fail due to missing the VK_KHR_display extension required as of
https://github.com/vkmark/vkmark/commit/7c3189c6482cb84c3c0e69d6dabb9d80e0c0092a

Quoted 6 lines

# Note about known performance problem in Qemu:

DRM contexts are mapping host blobs extensively and these mapping operations work slowly in Qemu. Exact reason is unknown. Mappings work fast on Crosvm For DRM contexts this problem is more visible than for Venus/Virgl.

And how!

With drm_native I get a lot of stutter while running and barely 100FPS (compared to ~8000 on pure venus). IMHO we need to figure out why there is such a discrepancy before merging because currently it makes more sense to use Venus.

<snip>

I'll do some more testing with my AMD/Aarch64 rig next week.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#34 lore raw
Quoted 40 lines · Alex Bennée
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

<snip>

So first the good news. I can now get this up and running (x86/kvm guest with Intel graphics) and as far as I can tell the native context mode is working. With Dongwon Kim's patch the mirroring/corruption I was seeing is gone.

I can successfully run glmark2-wayland (although see bellow) but vkmark completely fails to start reporting:

MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_FENCE_PASSING
MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_GUEST_HANDLE
MESA: error: DRM_IOCTL_VIRTGPU_GET_CAPS failed with Invalid argument
MESA: error: DRM_IOCTL_VIRTGPU_CONTEXT_INIT failed with Invalid argument, continuing without context...
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:681: VK_ERROR_DEVICE_LOST
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:332: VK_ERROR_DEVICE_LOST === Physical Device 0 ===

Quoted 7 lines
      Vendor ID:      0x8086
      Device ID:      0xA780
      Device Name:    Intel(R) Graphics (RPL-S)
      Driver Version: 101068899
      Device UUID:    b39e1cf39b101489e3c6039406f78d6c

I was booting with 4G of shared memory.

Thanks for the testing.

I assume all these errors are generated by the failing gfxstream. Hence, may ignore them since you don't have enabled gfxstream.

Quoted 3 lines

Later versions of vkmark (2025.01) fail due to missing the VK_KHR_display extension required as of
https://github.com/vkmark/vkmark/commit/7c3189c6482cb84c3c0e69d6dabb9d80e0c0092a

This VK_KHR_display problem is only reproducible with your rootfs that you shared with me. It could be a trouble with your build configs or a buggy package version used by your rootfs build, more likely the former.

Quoted 7 lines
Quoted 6 lines

# Note about known performance problem in Qemu:

DRM contexts are mapping host blobs extensively and these mapping operations work slowly in Qemu. Exact reason is unknown. Mappings work fast on Crosvm For DRM contexts this problem is more visible than for Venus/Virgl.

Quoted 6 lines

And how!

With drm_native I get a lot of stutter while running and barely 100FPS (compared to ~8000 on pure venus). IMHO we need to figure out why there is such a discrepancy before merging because currently it makes more sense to use

If you'd run with Xorg/Wayland directly without a DE, then it should work okay. This should be a problem with unmapping performance that I'm thinking about.

That unmapping problem is partially understood. Unmapping code works correctly, but we'll need to optimize the flatview code to perform unmapping immediately. Meanwhile, you may apply the QEMU hack below, it should resolve most of the stutter, please let me know if it helps.

There is also a pending Mesa intel-virtio blob mapping optimization that currently isn't available in my gitlab code, I'll refresh that feature and then ask you to try it.

Could be that there is more to the unmapping perf issue in QEMU. I'm investigating.

AMDGPU nctx is less affected by the bad unmapping performance. I expect it will work well for you.

util/rcu.c +2 -2
index fa32c942e4bb..aac3522c323c 100644
@@ -174,7 +174,7 @@ void synchronize_rcu(void)
 }
 
 
-#define RCU_CALL_MIN_SIZE        30
+#define RCU_CALL_MIN_SIZE        1
 
 /* Multi-producer, single-consumer queue based on urcu/static/wfqueue.h
  * from liburcu.  Note that head is only used by the consumer.
@@ -267,7 +267,7 @@ static void *call_rcu_thread(void *opaque)
          * added before synchronize_rcu() starts.
          */
         while (n == 0 || (n < RCU_CALL_MIN_SIZE && ++tries <= 5)) {
-            g_usleep(10000);
+            g_usleep(1000);
             if (n == 0) {
                 qemu_event_reset(&rcu_call_ready_event);
                 n = qatomic_read(&rcu_call_count);
Signature · 2 lines
Best regards,
Dmitry
#35 lore raw
Quoted 54 lines · Dmitry Osipenko
Quoted 40 lines · Alex Bennée
Quoted 9 lines · Dmitry Osipenko

This patchset adds DRM native context support to VirtIO-GPU on Qemu.

Contarary to Virgl and Venus contexts that mediates high level GFX APIs, DRM native context [1] mediates lower level kernel driver UAPI, which reflects in a less CPU overhead and less/simpler code needed to support it. DRM context consists of a host and guest parts that have to be implemented for each GPU driver. On a guest side, DRM context presents a virtual GPU as a real/native host GPU device for GL/VK applications.

<snip>

So first the good news. I can now get this up and running (x86/kvm guest with Intel graphics) and as far as I can tell the native context mode is working. With Dongwon Kim's patch the mirroring/corruption I was seeing is gone.

I can successfully run glmark2-wayland (although see bellow) but vkmark completely fails to start reporting:

MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_FENCE_PASSING
MESA: info: virtgpu backend not enabling VIRTGPU_PARAM_CREATE_GUEST_HANDLE
MESA: error: DRM_IOCTL_VIRTGPU_GET_CAPS failed with Invalid argument
MESA: error: DRM_IOCTL_VIRTGPU_CONTEXT_INIT failed with Invalid argument, continuing without context...
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:681: VK_ERROR_DEVICE_LOST
MESA: error: DRM_VIRTGPU_RESOURCE_CREATE_BLOB failed with No space left on device
MESA: error: Failed to create virtgpu AddressSpaceStream
MESA: error: vulkan: Failed to get host connection
MESA: warning: ../src/gfxstream/guest/vulkan/gfxstream_vk_device.cpp:332: VK_ERROR_DEVICE_LOST === Physical Device 0 ===

Quoted 7 lines
      Vendor ID:      0x8086
      Device ID:      0xA780
      Device Name:    Intel(R) Graphics (RPL-S)
      Driver Version: 101068899
      Device UUID:    b39e1cf39b101489e3c6039406f78d6c

I was booting with 4G of shared memory.

Thanks for the testing.

I assume all these errors are generated by the failing gfxstream. Hence, may ignore them since you don't have enabled gfxstream.

Quoted 8 lines
Quoted 3 lines

Later versions of vkmark (2025.01) fail due to missing the VK_KHR_display extension required as of
https://github.com/vkmark/vkmark/commit/7c3189c6482cb84c3c0e69d6dabb9d80e0c0092a

This VK_KHR_display problem is only reproducible with your rootfs that you shared with me. It could be a trouble with your build configs or a buggy package version used by your rootfs build, more likely the former.

So you have built that latest vkmark? This is a recent addition to vkmark for the 2025.1 release.

Does vulkaninfo --summary show the extension available for you? It is certainly available on the host side:

VK_KHR_display : extension revision 23

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

# Note about known performance problem in Qemu:

DRM contexts are mapping host blobs extensively and these mapping operations work slowly in Qemu. Exact reason is unknown. Mappings work fast on Crosvm For DRM contexts this problem is more visible than for Venus/Virgl.

Quoted 6 lines

And how!

With drm_native I get a lot of stutter while running and barely 100FPS (compared to ~8000 on pure venus). IMHO we need to figure out why there is such a discrepancy before merging because currently it makes more sense to use

Quoted 7 lines

If you'd run with Xorg/Wayland directly without a DE, then it should work okay. This should be a problem with unmapping performance that I'm thinking about.

That unmapping problem is partially understood. Unmapping code works correctly, but we'll need to optimize the flatview code to perform unmapping immediately.

Why immediately? Surely if we are unmapping we can defer it. Or is this a case of having stale mappings making the life of new allocations harder?

Quoted 37 lines

Meanwhile, you may apply the QEMU hack below, it
should resolve most of the stutter, please let me know if it helps.

There is also a pending Mesa intel-virtio blob mapping optimization that currently isn't available in my gitlab code, I'll refresh that feature and then ask you to try it.

Could be that there is more to the unmapping perf issue in QEMU. I'm investigating.

AMDGPU nctx is less affected by the bad unmapping performance. I expect it will work well for you.

util/rcu.c +2 -2
index fa32c942e4bb..aac3522c323c 100644
@@ -174,7 +174,7 @@ void synchronize_rcu(void)
 }
 
 
-#define RCU_CALL_MIN_SIZE        30
+#define RCU_CALL_MIN_SIZE        1
 
 /* Multi-producer, single-consumer queue based on urcu/static/wfqueue.h
  * from liburcu.  Note that head is only used by the consumer.
@@ -267,7 +267,7 @@ static void *call_rcu_thread(void *opaque)
          * added before synchronize_rcu() starts.
          */
         while (n == 0 || (n < RCU_CALL_MIN_SIZE && ++tries <= 5)) {
-            g_usleep(10000);
+            g_usleep(1000);
             if (n == 0) {
                 qemu_event_reset(&rcu_call_ready_event);
                 n = qatomic_read(&rcu_call_count);
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#36 lore raw

On 2/17/25 18:22, Alex Bennée wrote:
...

Quoted 6 lines
Quoted 4 lines

This VK_KHR_display problem is only reproducible with your rootfs that you shared with me. It could be a trouble with your build configs or a buggy package version used by your rootfs build, more likely the former.

So you have built that latest vkmark? This is a recent addition to vkmark for the 2025.1 release.

Yes, latest 2025.1 from git/master.

Quoted 5 lines

Does vulkaninfo --summary show the extension available for you? It is certainly available on the host side:

VK_KHR_display : extension revision 23

Have it on guest with my rootfs, not with yours. I'd suspect problem is with the your Mesa build flags, maybe you haven't enabled necessary flags related to WSI.

..

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

With drm_native I get a lot of stutter while running and barely 100FPS (compared to ~8000 on pure venus). IMHO we need to figure out why there is such a discrepancy before merging because currently it makes more sense to use

If you'd run with Xorg/Wayland directly without a DE, then it should work okay. This should be a problem with unmapping performance that I'm thinking about.

Quoted 6 lines
Quoted 3 lines

That unmapping problem is partially understood. Unmapping code works correctly, but we'll need to optimize the flatview code to perform unmapping immediately.

Why immediately? Surely if we are unmapping we can defer it. Or is this a case of having stale mappings making the life of new allocations harder?

Unmapping currently works synchronously for virtio-gpu in QEMU, hence deferring it blocks whole virtio-gpu up to 100+ ms. And if multiple unmappings are done in a row, then it's 100ms multiplied by the number of unmappings.

Signature · 2 lines
Best regards,
Dmitry
#37 lore raw
Quoted 14 lines · Dmitry Osipenko

On 2/17/25 18:22, Alex Bennée wrote:
...

Quoted 6 lines
Quoted 4 lines

This VK_KHR_display problem is only reproducible with your rootfs that you shared with me. It could be a trouble with your build configs or a buggy package version used by your rootfs build, more likely the former.

So you have built that latest vkmark? This is a recent addition to vkmark for the 2025.1 release.

Yes, latest 2025.1 from git/master.

Quoted 3 lines

Does vulkaninfo --summary show the extension available for you? It is certainly available on the host side:

Quoted 6 lines
Quoted 2 lines

VK_KHR_display : extension revision 23

Have it on guest with my rootfs, not with yours. I'd suspect problem is with the your Mesa build flags, maybe you haven't enabled necessary flags related to WSI.

I can't see any reference in the buildroot recipes. What is your mesa's build flags?

Quoted 21 lines

..

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

With drm_native I get a lot of stutter while running and barely 100FPS (compared to ~8000 on pure venus). IMHO we need to figure out why there is such a discrepancy before merging because currently it makes more sense to use

If you'd run with Xorg/Wayland directly without a DE, then it should work okay. This should be a problem with unmapping performance that I'm thinking about.

Quoted 6 lines
Quoted 3 lines

That unmapping problem is partially understood. Unmapping code works correctly, but we'll need to optimize the flatview code to perform unmapping immediately.

Why immediately? Surely if we are unmapping we can defer it. Or is this a case of having stale mappings making the life of new allocations harder?

Unmapping currently works synchronously for virtio-gpu in QEMU, hence deferring it blocks whole virtio-gpu up to 100+ ms. And if multiple unmappings are done in a row, then it's 100ms multiplied by the number of unmappings.

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