Skip to contentSkip to conversation

virtio-gpu-virgl: introduce Venus support for macOS

RFC PATCH In review Joelle van Dyne 2 participants 10 messages Dec 19, 2025 – Jan 4 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#2 lore raw

RFC PATCH v2 2/6 console: rename `d3d_tex2d` to `native`

In reply to Joelle van Dyne

In order to support native texture scanout beyond D3D, we make this more generic allowing for multiple native texture handle types.

---
 include/ui/console.h          | 22 +++++++++++++++++++---
 include/ui/gtk.h              |  4 ++--
 include/ui/sdl2.h             |  2 +-
 hw/display/virtio-gpu-virgl.c | 10 +++++++---
 ui/console.c                  |  8 ++++----
 ui/dbus-console.c             |  2 +-
 ui/dbus-listener.c            |  8 ++++----
 ui/egl-headless.c             |  4 ++--
 ui/gtk-egl.c                  |  4 ++--
 ui/gtk-gl-area.c              |  4 ++--
 ui/sdl2-gl.c                  |  2 +-
 ui/spice-display.c            |  2 +-
 12 files changed, 46 insertions(+), 26 deletions(-)
include/ui/console.h +19 -3
index 98feaa58bdd..25e45295d44 100644
@@ -131,6 +131,22 @@ struct QemuConsoleClass {
     ObjectClass parent_class;
 };
 
+typedef enum ScanoutTextureNativeType {
+    SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
+    SCANOUT_TEXTURE_NATIVE_TYPE_D3D,
+} ScanoutTextureNativeType;
+
+typedef struct ScanoutTextureNative {
+    ScanoutTextureNativeType type;
+    union {
+        void *d3d_tex2d;
+    } u;
+} ScanoutTextureNative;
+
+#define NO_NATIVE_TEXTURE ((ScanoutTextureNative){ \
+    .type = SCANOUT_TEXTURE_NATIVE_TYPE_NONE \
+})
+
 typedef struct ScanoutTexture {
     uint32_t backing_id;
     bool backing_y_0_top;
@@ -140,7 +156,7 @@ typedef struct ScanoutTexture {
     uint32_t y;
     uint32_t width;
     uint32_t height;
-    void *d3d_tex2d;
+    ScanoutTextureNative native;
 } ScanoutTexture;
 
 typedef struct QemuUIInfo {
@@ -245,7 +261,7 @@ typedef struct DisplayChangeListenerOps {
                                    uint32_t backing_height,
                                    uint32_t x, uint32_t y,
                                    uint32_t w, uint32_t h,
-                                   void *d3d_tex2d);
+                                   ScanoutTextureNative native);
     /* optional (default to true if has dpy_gl_scanout_dmabuf) */
     bool (*dpy_has_dmabuf)(DisplayChangeListener *dcl);
     /* optional */
@@ -329,7 +345,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
                             uint32_t backing_id, bool backing_y_0_top,
                             uint32_t backing_width, uint32_t backing_height,
                             uint32_t x, uint32_t y, uint32_t w, uint32_t h,
-                            void *d3d_tex2d);
+                            ScanoutTextureNative native);
 void dpy_gl_scanout_dmabuf(QemuConsole *con,
                            QemuDmaBuf *dmabuf);
 void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
include/ui/gtk.h +2 -2
index 3e6ce3cb48c..f88e2b281d3 100644
@@ -178,7 +178,7 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
                             uint32_t backing_height,
                             uint32_t x, uint32_t y,
                             uint32_t w, uint32_t h,
-                            void *d3d_tex2d);
+                            ScanoutTextureNative native);
 void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
                            QemuDmaBuf *dmabuf);
 void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl,
@@ -215,7 +215,7 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_height,
                                 uint32_t x, uint32_t y,
                                 uint32_t w, uint32_t h,
-                                void *d3d_tex2d);
+                                ScanoutTextureNative native);
 void gd_gl_area_scanout_disable(DisplayChangeListener *dcl);
 void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
                               uint32_t x, uint32_t y, uint32_t w, uint32_t h);
include/ui/sdl2.h +1 -1
index dbe6e3d9739..fdefb882294 100644
@@ -93,7 +93,7 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
                              uint32_t backing_height,
                              uint32_t x, uint32_t y,
                              uint32_t w, uint32_t h,
-                             void *d3d_tex2d);
+                             ScanoutTextureNative native);
 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl,
                            uint32_t x, uint32_t y, uint32_t w, uint32_t h);
 
hw/display/virtio-gpu-virgl.c +7 -3
index 20c856c04e3..f24437163fb 100644
@@ -420,14 +420,18 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
 
     if (ss.resource_id && ss.r.width && ss.r.height) {
         struct virgl_renderer_resource_info info;
-        void *d3d_tex2d = NULL;
+        ScanoutTextureNative native = { .type = SCANOUT_TEXTURE_NATIVE_TYPE_NONE };
 
 #if VIRGL_VERSION_MAJOR >= 1
         struct virgl_renderer_resource_info_ext ext;
         memset(&ext, 0, sizeof(ext));
         ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
         info = ext.base;
-        d3d_tex2d = ext.d3d_tex2d;
+        native = (ScanoutTextureNative){
+            .type = ext.d3d_tex2d ? SCANOUT_TEXTURE_NATIVE_TYPE_D3D :
+                                    SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
+            .u.d3d_tex2d = ext.d3d_tex2d,
+        };
 #else
         memset(&info, 0, sizeof(info));
         ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
@@ -447,7 +451,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
             info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
             info.width, info.height,
             ss.r.x, ss.r.y, ss.r.width, ss.r.height,
-            d3d_tex2d);
+            native);
     } else {
         dpy_gfx_replace_surface(
             g->parent_obj.scanout[ss.scanout_id].con, NULL);
ui/console.c +4 -4
index 2d00828c538..9378afd53db 100644
@@ -295,7 +295,7 @@ static void displaychangelistener_display_console(DisplayChangeListener *dcl,
                                          con->scanout.texture.y,
                                          con->scanout.texture.width,
                                          con->scanout.texture.height,
-                                         con->scanout.texture.d3d_tex2d);
+                                         con->scanout.texture.native);
     }
 }
 
@@ -1023,7 +1023,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
                             uint32_t backing_height,
                             uint32_t x, uint32_t y,
                             uint32_t width, uint32_t height,
-                            void *d3d_tex2d)
+                            ScanoutTextureNative native)
 {
     DisplayState *s = con->ds;
     DisplayChangeListener *dcl;
@@ -1031,7 +1031,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
     con->scanout.kind = SCANOUT_TEXTURE;
     con->scanout.texture = (ScanoutTexture) {
         backing_id, backing_y_0_top, backing_width, backing_height,
-        x, y, width, height, d3d_tex2d,
+        x, y, width, height, native,
     };
     QLIST_FOREACH(dcl, &s->listeners, next) {
         if (con != dcl->con) {
@@ -1042,7 +1042,7 @@ void dpy_gl_scanout_texture(QemuConsole *con,
                                              backing_y_0_top,
                                              backing_width, backing_height,
                                              x, y, width, height,
-                                             d3d_tex2d);
+                                             native);
         }
     }
 }
ui/dbus-console.c +1 -1
index 85e215ef233..651f0daeafa 100644
@@ -99,7 +99,7 @@ dbus_gl_scanout_texture(DisplayChangeListener *dcl,
                         uint32_t backing_height,
                         uint32_t x, uint32_t y,
                         uint32_t w, uint32_t h,
-                        void *d3d_tex2d)
+                        ScanoutTextureNative native)
 {
     DBusDisplayConsole *ddc = container_of(dcl, DBusDisplayConsole, dcl);
 
ui/dbus-listener.c +4 -4
index 52e041edb0f..f401db63c62 100644
@@ -587,7 +587,7 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,
                                  uint32_t backing_height,
                                  uint32_t x, uint32_t y,
                                  uint32_t w, uint32_t h,
-                                 void *d3d_tex2d)
+                                 ScanoutTextureNative native)
 {
     trace_dbus_scanout_texture(tex_id, backing_y_0_top,
                                backing_width, backing_height, x, y, w, h);
@@ -618,8 +618,8 @@ static void dbus_scanout_texture(DisplayChangeListener *dcl,
     assert(surface_width(ddl->ds) == w);
     assert(surface_height(ddl->ds) == h);
 
-    if (d3d_tex2d) {
-        dbus_scanout_share_d3d_texture(ddl, d3d_tex2d, backing_y_0_top,
+    if (native.type == SCANOUT_TEXTURE_NATIVE_TYPE_D3D) {
+        dbus_scanout_share_d3d_texture(ddl, native.u.d3d_tex2d, backing_y_0_top,
                                        backing_width, backing_height, x, y, w, h);
     } else {
         dbus_scanout_map(ddl);
@@ -868,7 +868,7 @@ static void dbus_gl_gfx_switch(DisplayChangeListener *dcl,
 
         /* TODO: lazy send dmabuf (there are unnecessary sent otherwise) */
         dbus_scanout_texture(&ddl->dcl, ddl->ds->texture, false,
-                             width, height, 0, 0, width, height, NULL);
+                             width, height, 0, 0, width, height, NO_NATIVE_TEXTURE);
     }
 }
 #endif
ui/egl-headless.c +2 -2
index 1f6b845500d..ef5cc02dcc3 100644
@@ -62,7 +62,7 @@ static void egl_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_height,
                                 uint32_t x, uint32_t y,
                                 uint32_t w, uint32_t h,
-                                void *d3d_tex2d)
+                                ScanoutTextureNative native)
 {
     egl_dpy *edpy = container_of(dcl, egl_dpy, dcl);
 
@@ -97,7 +97,7 @@ static void egl_scanout_dmabuf(DisplayChangeListener *dcl,
     height = qemu_dmabuf_get_height(dmabuf);
 
     egl_scanout_texture(dcl, texture, false, width, height, 0, 0,
-                        width, height, NULL);
+                        width, height, NO_NATIVE_TEXTURE);
 }
 
 static void egl_cursor_dmabuf(DisplayChangeListener *dcl,
ui/gtk-egl.c +2 -2
index ae9239999cd..24330b98b35 100644
@@ -239,7 +239,7 @@ void gd_egl_scanout_texture(DisplayChangeListener *dcl,
                             uint32_t backing_width, uint32_t backing_height,
                             uint32_t x, uint32_t y,
                             uint32_t w, uint32_t h,
-                            void *d3d_tex2d)
+                            ScanoutTextureNative native)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
@@ -290,7 +290,7 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
     y0_top = qemu_dmabuf_get_y0_top(dmabuf);
 
     gd_egl_scanout_texture(dcl, texture, y0_top, backing_width, backing_height,
-                           x, y, width, height, NULL);
+                           x, y, width, height, NO_NATIVE_TEXTURE);
 
     if (qemu_dmabuf_get_allow_fences(dmabuf)) {
         vc->gfx.guest_fb.dmabuf = dmabuf;
ui/gtk-gl-area.c +2 -2
index cd86022d264..bde5db83981 100644
@@ -306,7 +306,7 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *dcl,
                                 uint32_t backing_height,
                                 uint32_t x, uint32_t y,
                                 uint32_t w, uint32_t h,
-                                void *d3d_tex2d)
+                                ScanoutTextureNative native)
 {
     VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
 
@@ -374,7 +374,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
 
     gd_gl_area_scanout_texture(dcl, texture, y0_top,
                                backing_width, backing_height,
-                               x, y, width, height, NULL);
+                               x, y, width, height, NO_NATIVE_TEXTURE);
 
     if (qemu_dmabuf_get_allow_fences(dmabuf)) {
         vc->gfx.guest_fb.dmabuf = dmabuf;
ui/sdl2-gl.c +1 -1
index 3be17d1079a..b15db86f245 100644
@@ -206,7 +206,7 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,
                              uint32_t backing_height,
                              uint32_t x, uint32_t y,
                              uint32_t w, uint32_t h,
-                             void *d3d_tex2d)
+                             ScanoutTextureNative native)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
 
ui/spice-display.c +1 -1
index db71e866f89..2a2285cb1fd 100644
@@ -1084,7 +1084,7 @@ static void qemu_spice_gl_scanout_texture(DisplayChangeListener *dcl,
                                           uint32_t backing_height,
                                           uint32_t x, uint32_t y,
                                           uint32_t w, uint32_t h,
-                                          void *d3d_tex2d)
+                                          ScanoutTextureNative native)
 {
     SimpleSpiceDisplay *ssd = container_of(dcl, SimpleSpiceDisplay, dcl);
     EGLint offset[DMABUF_MAX_PLANES], stride[DMABUF_MAX_PLANES], fourcc = 0;
Signature · 1 line
2.50.1 (Apple Git-155)
#3 lore raw

RFC PATCH v2 3/6 virtio-gpu-virgl: update virglrenderer defines

In reply to Joelle van Dyne

In order to support additional native texture types, we need to update the defines in virglrenderer. The changes are backwards compatible and so builds should work with either the new version or the old version.

https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1583

---
 hw/display/virtio-gpu-virgl.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
hw/display/virtio-gpu-virgl.c +25 -3
index f24437163fb..9fcc01b6f46 100644
@@ -24,6 +24,8 @@
 
 #include <virglrenderer.h>
 
+#define NATIVE_HANDLE_SUPPORT_VERSION (1)
+
 struct virtio_gpu_virgl_resource {
     struct virtio_gpu_simple_resource base;
     MemoryRegion *mr;
@@ -427,12 +429,30 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
         memset(&ext, 0, sizeof(ext));
         ret = virgl_renderer_resource_get_info_ext(ss.resource_id, &ext);
         info = ext.base;
+        /* fallback to older version */
         native = (ScanoutTextureNative){
             .type = ext.d3d_tex2d ? SCANOUT_TEXTURE_NATIVE_TYPE_D3D :
                                     SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
             .u.d3d_tex2d = ext.d3d_tex2d,
         };
-#else
+#if VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION >= NATIVE_HANDLE_SUPPORT_VERSION
+        if (ext.version >= VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION) {
+            switch (ext.native_type) {
+            case VIRGL_NATIVE_HANDLE_NONE:
+            case VIRGL_NATIVE_HANDLE_D3D_TEX2D: {
+                /* already handled above */
+                break;
+            }
+            default: {
+                qemu_log_mask(LOG_GUEST_ERROR,
+                            "%s: unsupported native texture type %d\n",
+                            __func__, ext.native_type);
+                break;
+            }
+            }
+        }
+#endif
+#else /* VIRGL_VERSION_MAJOR < 1 */
         memset(&info, 0, sizeof(info));
         ret = virgl_renderer_resource_get_info(ss.resource_id, &info);
 #endif
@@ -1155,11 +1175,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
         virtio_gpu_3d_cbs.get_egl_display = virgl_get_egl_display;
     }
 #endif
-#ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE
     if (qemu_egl_angle_native_device) {
+#if defined(VIRGL_RENDERER_NATIVE_SHARE_TEXTURE)
+        flags |= VIRGL_RENDERER_NATIVE_SHARE_TEXTURE;
+#elif defined(VIRGL_RENDERER_D3D11_SHARE_TEXTURE) && defined(WIN32)
         flags |= VIRGL_RENDERER_D3D11_SHARE_TEXTURE;
-    }
 #endif
+    }
 #if VIRGL_VERSION_MAJOR >= 1
     if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
         flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
Signature · 1 line
2.50.1 (Apple Git-155)
#0 lore raw

v2 cover virtio-gpu-virgl: introduce Venus support for macOS

This brings Vulkan guest paravirtualization to macOS hosts. The bulk of the work is being submitted to the virglrenderer project so this is a RFC for now.

In addition to Vulkan, we also introduce Metal texture scanout for GLES guests as well. We also added Metal texture rendering in the Cocoa backend but that builds upon the GLES work by Akihiko Odaki which is not currently upstream.

Fork with all dependent changes:
https://github.com/utmapp/qemu/tree/submit/macos-venus
Instructions for building and testing with all related projects:
https://gist.github.com/osy/a8f705050eed1c8421ad1a0855a8faa9

v2:
- Removed "virtio-gpu-virgl: check page alignment of blob mapping"
- Fixed build on Linux
- Restored check on blob resources
- Renamed new structs in console.c

Joelle van Dyne (6):
egl-helpers: store handle to native device
console: rename d3d_tex2d to native
virtio-gpu-virgl: update virglrenderer defines
virtio-gpu-virgl: support scanout of Metal textures
console: add cleanup callback for ScanoutTexture
virtio-gpu-virgl: add support for native blob scanout

 meson.build                   |   9 +++
 include/ui/console.h          |  31 +++++++++-
 include/ui/egl-helpers.h      |   2 +-
 include/ui/gtk.h              |   4 +-
 include/ui/sdl2.h             |   2 +-
 hw/display/virtio-gpu-virgl.c | 112 +++++++++++++++++++++++++++++++---
 hw/display/virtio-gpu.c       |  10 ++-
 ui/console.c                  |  60 +++++++++++++++---
 ui/dbus-console.c             |   2 +-
 ui/dbus-listener.c            |   8 +--
 ui/egl-headless.c             |   4 +-
 ui/egl-helpers.c              |   4 +-
 ui/gtk-egl.c                  |   4 +-
 ui/gtk-gl-area.c              |   4 +-
 ui/sdl2-gl.c                  |   2 +-
 ui/spice-display.c            |   2 +-
 16 files changed, 220 insertions(+), 40 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
#9 lore raw

RFC PATCH v2 6/6 virtio-gpu-virgl: add support for native blob scanout

On macOS we do not have dmabuf and so we use MTLTexture as our scanout source. For blob scanout, the buffer is untyped and so we cannot get a MTLTexture until we pass more information to virglrenderer (surface size, pixel format, etc). The new API to do this is currently unstable so we need to define VIRGL_RENDERER_UNSTABLE_APIS. This should be removed after the ABI becomes stable.

---
 meson.build                   |  5 +++
 hw/display/virtio-gpu-virgl.c | 60 +++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
meson.build +5 -0
index 05bad663764..8917aff044c 100644
@@ -2549,6 +2549,11 @@ config_host_data.set('CONFIG_VNC', vnc.found())
 config_host_data.set('CONFIG_VNC_JPEG', jpeg.found())
 config_host_data.set('CONFIG_VNC_SASL', sasl.found())
 if virgl.found()
+  config_host_data.set('HAVE_VIRGL_RENDERER_NATIVE_SCANOUT',
+                        cc.has_function('virgl_renderer_create_handle_for_scanout',
+                                        args: '-DVIRGL_RENDERER_UNSTABLE_APIS',
+                                        prefix: '#include <virglrenderer.h>',
+                                        dependencies: virgl))
   config_host_data.set('VIRGL_VERSION_MAJOR', virgl.version().split('.')[0])
 endif
 config_host_data.set('CONFIG_VIRTFS', have_virtfs)
hw/display/virtio-gpu-virgl.c +60 -0

78 lines not on this page · raw message

Signature · 1 line
2.50.1 (Apple Git-155)
#8 lore raw

RFC PATCH v2 5/6 console: add cleanup callback for ScanoutTexture

In reply to Joelle van Dyne

Before we introduce changes that allow for QemuConsole to take ownership of a texture handle, we need scaffolding that will allow us to callback into a cleanup function any time the ScanoutTexture becomes invalid, which is whenever the scanout.kind or scanout.texture gets updated.

The ordering is important: we need to first update the DisplayScanout, then we need to notify all the listeners, and once all the listeners have had the chance to finish using the previous native texture, we are safe to call the cleanup function. This means we need to hold on to the previous scanout native handle locally until all listeners are notified.

---
 include/ui/console.h          |  9 +++++-
 hw/display/virtio-gpu-virgl.c |  2 +-
 ui/console.c                  | 56 +++++++++++++++++++++++++++++++----
 3 files changed, 59 insertions(+), 8 deletions(-)
include/ui/console.h +8 -1
index a45b524c575..5caecd4d7b9 100644
@@ -149,6 +149,11 @@ typedef struct ScanoutTextureNative {
     .type = SCANOUT_TEXTURE_NATIVE_TYPE_NONE \
 })
 
+/**
+ * Cleanup callback function when ScanoutTexture is about to be destroyed
+ */
+typedef void (*ScanoutTextureCleanup)(ScanoutTextureNative *native);
+
 typedef struct ScanoutTexture {
     uint32_t backing_id;
     bool backing_y_0_top;
@@ -159,6 +164,7 @@ typedef struct ScanoutTexture {
     uint32_t width;
     uint32_t height;
     ScanoutTextureNative native;
+    ScanoutTextureCleanup cb_cleanup;
 } ScanoutTexture;
 
 typedef struct QemuUIInfo {
@@ -347,7 +353,8 @@ void dpy_gl_scanout_texture(QemuConsole *con,
                             uint32_t backing_id, bool backing_y_0_top,
                             uint32_t backing_width, uint32_t backing_height,
                             uint32_t x, uint32_t y, uint32_t w, uint32_t h,
-                            ScanoutTextureNative native);
+                            ScanoutTextureNative native,
+                            ScanoutTextureCleanup cb_cleanup);
 void dpy_gl_scanout_dmabuf(QemuConsole *con,
                            QemuDmaBuf *dmabuf);
 void dpy_gl_cursor_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf,
hw/display/virtio-gpu-virgl.c +1 -1
index b3e83046643..c01587bd25c 100644
@@ -478,7 +478,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
             info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP,
             info.width, info.height,
             ss.r.x, ss.r.y, ss.r.width, ss.r.height,
-            native);
+            native, NULL);
     } else {
         dpy_gfx_replace_surface(
             g->parent_obj.scanout[ss.scanout_id].con, NULL);
ui/console.c +50 -6

125 lines not on this page · raw message

Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

RFC PATCH v2 1/6 egl-helpers: store handle to native device

In reply to Joelle van Dyne

Make way for other platforms by making the variable more general. Also we will be using the device in the future so let's save the pointer in the global instead of just a boolean flag.

---
 include/ui/egl-helpers.h      | 2 +-
 hw/display/virtio-gpu-virgl.c | 2 +-
 ui/egl-helpers.c              | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
include/ui/egl-helpers.h +1 -1
index acf993fcf52..c239d323177 100644
@@ -12,7 +12,7 @@
 extern EGLDisplay *qemu_egl_display;
 extern EGLConfig qemu_egl_config;
 extern DisplayGLMode qemu_egl_mode;
-extern bool qemu_egl_angle_d3d;
+extern void *qemu_egl_angle_native_device;
 
 typedef struct egl_fb {
     int width;
hw/display/virtio-gpu-virgl.c +1 -1
index 07f6355ad62..20c856c04e3 100644
@@ -1152,7 +1152,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
     }
 #endif
 #ifdef VIRGL_RENDERER_D3D11_SHARE_TEXTURE
-    if (qemu_egl_angle_d3d) {
+    if (qemu_egl_angle_native_device) {
         flags |= VIRGL_RENDERER_D3D11_SHARE_TEXTURE;
     }
 #endif
ui/egl-helpers.c +2 -2
index e3f2872cc14..57bcf994989 100644
@@ -28,7 +28,7 @@
 EGLDisplay *qemu_egl_display;
 EGLConfig qemu_egl_config;
 DisplayGLMode qemu_egl_mode;
-bool qemu_egl_angle_d3d;
+void *qemu_egl_angle_native_device;
 
 /* ------------------------------------------------------------------ */
 
@@ -651,7 +651,7 @@ int qemu_egl_init_dpy_win32(EGLNativeDisplayType dpy, DisplayGLMode mode)
         }
 
         trace_egl_init_d3d11_device(device);
-        qemu_egl_angle_d3d = device != NULL;
+        qemu_egl_angle_native_device = d3d11_device;
     }
 #endif
 
Signature · 1 line
2.50.1 (Apple Git-155)
#4 lore raw

RFC PATCH v2 4/6 virtio-gpu-virgl: support scanout of Metal textures

In reply to Joelle van Dyne

When supported, virglrenderer will return a MTLTexture handle that can be directly used for scanout.

---
 meson.build                   |  4 ++++
 include/ui/console.h          |  2 ++
 hw/display/virtio-gpu-virgl.c | 12 +++++++++++-
 hw/display/virtio-gpu.c       | 10 ++++++++--
 4 files changed, 25 insertions(+), 3 deletions(-)
meson.build +4 -0
index d9293294d8e..05bad663764 100644
@@ -832,6 +832,7 @@ version_res = []
 coref = []
 iokit = []
 pvg = not_found
+metal = not_found
 emulator_link_args = []
 midl = not_found
 widl = not_found
@@ -859,6 +860,7 @@ elif host_os == 'darwin'
   host_dsosuf = '.dylib'
   pvg = dependency('appleframeworks', modules: ['ParavirtualizedGraphics', 'Metal'],
                    required: get_option('pvg'))
+  metal = dependency('appleframeworks', modules: 'Metal', required: false)
 elif host_os == 'sunos'
   socket = [cc.find_library('socket'),
             cc.find_library('nsl'),
@@ -2591,6 +2593,7 @@ if xen.found()
     ('0' + xen_version[2]).substring(-2)
   config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
 endif
+config_host_data.set('CONFIG_METAL', metal.found())
 config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
 config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
 config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
@@ -4874,6 +4877,7 @@ summary(summary_info, bool_yn: true, section: 'Crypto')
 summary_info = {}
 if host_os == 'darwin'
   summary_info += {'Cocoa support':           cocoa}
+  summary_info += {'Metal support':           metal}
 endif
 summary_info += {'D-Bus display':     dbus_display}
 summary_info += {'SDL support':       sdl}
include/ui/console.h +2 -0
index 25e45295d44..a45b524c575 100644
@@ -134,12 +134,14 @@ struct QemuConsoleClass {
 typedef enum ScanoutTextureNativeType {
     SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
     SCANOUT_TEXTURE_NATIVE_TYPE_D3D,
+    SCANOUT_TEXTURE_NATIVE_TYPE_METAL,
 } ScanoutTextureNativeType;
 
 typedef struct ScanoutTextureNative {
     ScanoutTextureNativeType type;
     union {
         void *d3d_tex2d;
+        void *metal_texture;
     } u;
 } ScanoutTextureNative;
 
hw/display/virtio-gpu-virgl.c +11 -1
index 9fcc01b6f46..b3e83046643 100644
@@ -438,6 +438,13 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
 #if VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION >= NATIVE_HANDLE_SUPPORT_VERSION
         if (ext.version >= VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION) {
             switch (ext.native_type) {
+#ifdef CONFIG_METAL
+            case VIRGL_NATIVE_HANDLE_METAL_TEXTURE: {
+                native.type = SCANOUT_TEXTURE_NATIVE_TYPE_METAL;
+                native.u.metal_texture = ext.native_handle;
+                break;
+            }
+#endif
             case VIRGL_NATIVE_HANDLE_NONE:
             case VIRGL_NATIVE_HANDLE_D3D_TEX2D: {
                 /* already handled above */
@@ -1184,7 +1191,10 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
     }
 #if VIRGL_VERSION_MAJOR >= 1
     if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
-        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
+        flags |= VIRGL_RENDERER_VENUS;
+#ifndef CONFIG_METAL /* Metal does not support render server */
+        flags |= VIRGL_RENDERER_RENDER_SERVER;
+#endif
     }
 #endif
 
hw/display/virtio-gpu.c +8 -2
index 43e88a4daff..38010c0fcc2 100644
@@ -1483,12 +1483,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
     VirtIOGPU *g = VIRTIO_GPU(qdev);
+    bool have_ext_memory;
 
     if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
+#ifdef CONFIG_METAL
+        have_ext_memory = true;
+#else
+        have_ext_memory = virtio_gpu_have_udmabuf();
+#endif
         if (!virtio_gpu_rutabaga_enabled(g->parent_obj.conf) &&
             !virtio_gpu_virgl_enabled(g->parent_obj.conf) &&
-            !virtio_gpu_have_udmabuf()) {
-            error_setg(errp, "need rutabaga or udmabuf for blob resources");
+            !have_ext_memory) {
+            error_setg(errp, "need rutabaga or ext memory for blob resources");
             return;
         }
 
Signature · 1 line
2.50.1 (Apple Git-155)
#5 lore raw

Re: [PATCH RFC v2 4/6] virtio-gpu-virgl: support scanout of Metal textures

Quoted 32 lines · Joelle van Dyne

When supported, virglrenderer will return a MTLTexture handle that can be directly used for scanout.

---
  meson.build                   |  4 ++++
  include/ui/console.h          |  2 ++
  hw/display/virtio-gpu-virgl.c | 12 +++++++++++-
  hw/display/virtio-gpu.c       | 10 ++++++++--
  4 files changed, 25 insertions(+), 3 deletions(-)
meson.build +2 -0
index d9293294d8e..05bad663764 100644
@@ -832,6 +832,7 @@ version_res = []
  coref = []
  iokit = []
  pvg = not_found
+metal = not_found
  emulator_link_args = []
  midl = not_found
  widl = not_found
@@ -859,6 +860,7 @@ elif host_os == 'darwin'
    host_dsosuf = '.dylib'
    pvg = dependency('appleframeworks', modules: ['ParavirtualizedGraphics', 'Metal'],
                     required: get_option('pvg'))
+  metal = dependency('appleframeworks', modules: 'Metal', required: false)
  elif host_os == 'sunos'
    socket = [cc.find_library('socket'),
              cc.find_library('nsl'),

meson.build if xen.found() · line 2596

Quoted 4 lines
meson.build +1 -0
@@ -2591,6 +2593,7 @@ if xen.found()
      ('0' + xen_version[2]).substring(-2)
    config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
  endif
+config_host_data.set('CONFIG_METAL', metal.found())

This is unnecessary; CONFIG_DARWIN is sufficient.

meson.build summary(summary_info, bool_yn: true, section: 'Crypto') · line 4880

Quoted 8 lines
meson.build +1 -0
  config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
  config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
  config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
@@ -4874,6 +4877,7 @@ summary(summary_info, bool_yn: true, section: 'Crypto')
  summary_info = {}
  if host_os == 'darwin'
    summary_info += {'Cocoa support':           cocoa}
+  summary_info += {'Metal support':           metal}

This printing is extraneous. All versions of Darwin QEMU supports have Metal.

Quoted 64 lines
meson.build +0 -0
  endif
  summary_info += {'D-Bus display':     dbus_display}
  summary_info += {'SDL support':       sdl}
include/ui/console.h +2 -0
index 25e45295d44..a45b524c575 100644
@@ -134,12 +134,14 @@ struct QemuConsoleClass {
  typedef enum ScanoutTextureNativeType {
      SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
      SCANOUT_TEXTURE_NATIVE_TYPE_D3D,
+    SCANOUT_TEXTURE_NATIVE_TYPE_METAL,
  } ScanoutTextureNativeType;
 
  typedef struct ScanoutTextureNative {
      ScanoutTextureNativeType type;
      union {
          void *d3d_tex2d;
+        void *metal_texture;
      } u;
  } ScanoutTextureNative;
 
hw/display/virtio-gpu-virgl.c +11 -1
index 9fcc01b6f46..b3e83046643 100644
@@ -438,6 +438,13 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
  #if VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION >= NATIVE_HANDLE_SUPPORT_VERSION
          if (ext.version >= VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION) {
              switch (ext.native_type) {
+#ifdef CONFIG_METAL
+            case VIRGL_NATIVE_HANDLE_METAL_TEXTURE: {
+                native.type = SCANOUT_TEXTURE_NATIVE_TYPE_METAL;
+                native.u.metal_texture = ext.native_handle;
+                break;
+            }
+#endif
              case VIRGL_NATIVE_HANDLE_NONE:
              case VIRGL_NATIVE_HANDLE_D3D_TEX2D: {
                  /* already handled above */
@@ -1184,7 +1191,10 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
      }
  #if VIRGL_VERSION_MAJOR >= 1
      if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
-        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
+        flags |= VIRGL_RENDERER_VENUS;
+#ifndef CONFIG_METAL /* Metal does not support render server */
+        flags |= VIRGL_RENDERER_RENDER_SERVER;
+#endif
      }
  #endif
 
hw/display/virtio-gpu.c +2 -0
index 43e88a4daff..38010c0fcc2 100644
@@ -1483,12 +1483,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
  {
      VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
      VirtIOGPU *g = VIRTIO_GPU(qdev);
+    bool have_ext_memory;
 
      if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
+#ifdef CONFIG_METAL

hw/display/virtio-gpu.c void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) · line 1497

Quoted 10 lines
hw/display/virtio-gpu.c +6 -2
+        have_ext_memory = true;
+#else
+        have_ext_memory = virtio_gpu_have_udmabuf();
+#endif
          if (!virtio_gpu_rutabaga_enabled(g->parent_obj.conf) &&
              !virtio_gpu_virgl_enabled(g->parent_obj.conf) &&
-            !virtio_gpu_have_udmabuf()) {
-            error_setg(errp, "need rutabaga or udmabuf for blob resources");
+            !have_ext_memory) {
+            error_setg(errp, "need rutabaga or ext memory for blob resources");

This change is extraneous. It allows creating blob resources with virtio-gpu (not virtio-gpu-gl) on macOS, which shouldn't happen.

Regards,
Akihiko Odaki

#6 lore raw

Re: [PATCH RFC v2 4/6] virtio-gpu-virgl: support scanout of Metal textures

Quoted 115 lines · Akihiko Odaki
Quoted 32 lines · Joelle van Dyne

When supported, virglrenderer will return a MTLTexture handle that can be directly used for scanout.

---
  meson.build                   |  4 ++++
  include/ui/console.h          |  2 ++
  hw/display/virtio-gpu-virgl.c | 12 +++++++++++-
  hw/display/virtio-gpu.c       | 10 ++++++++--
  4 files changed, 25 insertions(+), 3 deletions(-)
meson.build +2 -0
index d9293294d8e..05bad663764 100644
@@ -832,6 +832,7 @@ version_res = []
  coref = []
  iokit = []
  pvg = not_found
+metal = not_found
  emulator_link_args = []
  midl = not_found
  widl = not_found
@@ -859,6 +860,7 @@ elif host_os == 'darwin'
    host_dsosuf = '.dylib'
    pvg = dependency('appleframeworks', modules: ['ParavirtualizedGraphics', 'Metal'],
                     required: get_option('pvg'))
+  metal = dependency('appleframeworks', modules: 'Metal', required: false)
  elif host_os == 'sunos'
    socket = [cc.find_library('socket'),
              cc.find_library('nsl'),

meson.build if xen.found() · line 2596

Quoted 4 lines
meson.build +1 -0
@@ -2591,6 +2593,7 @@ if xen.found()
      ('0' + xen_version[2]).substring(-2)
    config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
  endif
+config_host_data.set('CONFIG_METAL', metal.found())

This is unnecessary; CONFIG_DARWIN is sufficient.

meson.build summary(summary_info, bool_yn: true, section: 'Crypto') · line 4880

Quoted 8 lines
meson.build +1 -0
  config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
  config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
  config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
@@ -4874,6 +4877,7 @@ summary(summary_info, bool_yn: true, section: 'Crypto')
  summary_info = {}
  if host_os == 'darwin'
    summary_info += {'Cocoa support':           cocoa}
+  summary_info += {'Metal support':           metal}

This printing is extraneous. All versions of Darwin QEMU supports have Metal.

Quoted 62 lines
meson.build +0 -0
  endif
  summary_info += {'D-Bus display':     dbus_display}
  summary_info += {'SDL support':       sdl}
include/ui/console.h +2 -0
index 25e45295d44..a45b524c575 100644
@@ -134,12 +134,14 @@ struct QemuConsoleClass {
  typedef enum ScanoutTextureNativeType {
      SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
      SCANOUT_TEXTURE_NATIVE_TYPE_D3D,
+    SCANOUT_TEXTURE_NATIVE_TYPE_METAL,
  } ScanoutTextureNativeType;
 
  typedef struct ScanoutTextureNative {
      ScanoutTextureNativeType type;
      union {
          void *d3d_tex2d;
+        void *metal_texture;
      } u;
  } ScanoutTextureNative;
 
hw/display/virtio-gpu-virgl.c +11 -1
index 9fcc01b6f46..b3e83046643 100644
@@ -438,6 +438,13 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
  #if VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION >= NATIVE_HANDLE_SUPPORT_VERSION
          if (ext.version >= VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION) {
              switch (ext.native_type) {
+#ifdef CONFIG_METAL
+            case VIRGL_NATIVE_HANDLE_METAL_TEXTURE: {
+                native.type = SCANOUT_TEXTURE_NATIVE_TYPE_METAL;
+                native.u.metal_texture = ext.native_handle;
+                break;
+            }
+#endif
              case VIRGL_NATIVE_HANDLE_NONE:
              case VIRGL_NATIVE_HANDLE_D3D_TEX2D: {
                  /* already handled above */
@@ -1184,7 +1191,10 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
      }
  #if VIRGL_VERSION_MAJOR >= 1
      if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
-        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
+        flags |= VIRGL_RENDERER_VENUS;
+#ifndef CONFIG_METAL /* Metal does not support render server */
+        flags |= VIRGL_RENDERER_RENDER_SERVER;
+#endif
      }
  #endif
 
hw/display/virtio-gpu.c +1 -0
index 43e88a4daff..38010c0fcc2 100644
@@ -1483,12 +1483,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
  {
      VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
      VirtIOGPU *g = VIRTIO_GPU(qdev);
+    bool have_ext_memory;
 
Quoted 15 lines

hw/display/virtio-gpu.c void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) · line 1497

Quoted 12 lines
hw/display/virtio-gpu.c +7 -2
      if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
+#ifdef CONFIG_METAL
+        have_ext_memory = true;
+#else
+        have_ext_memory = virtio_gpu_have_udmabuf();
+#endif
          if (!virtio_gpu_rutabaga_enabled(g->parent_obj.conf) &&
              !virtio_gpu_virgl_enabled(g->parent_obj.conf) &&
-            !virtio_gpu_have_udmabuf()) {
-            error_setg(errp, "need rutabaga or udmabuf for blob resources");
+            !have_ext_memory) {
+            error_setg(errp, "need rutabaga or ext memory for blob resources");

This change is extraneous. It allows creating blob resources with virtio-gpu (not virtio-gpu-gl) on macOS, which shouldn't happen.

virtio_gpu_gl_device_realize() calls virtio_gpu_device_realize() at the end so it will have to pass this check. Would this be better?

#ifdef CONFIG_METAL
have_ext_memory = virtio_gpu_venus_enabled(g->parent_obj.conf); #else
have_ext_memory = virtio_gpu_have_udmabuf();
#endif

Quoted 3 lines

Regards,
Akihiko Odaki

#7 lore raw

Re: [PATCH RFC v2 4/6] virtio-gpu-virgl: support scanout of Metal textures

Quoted 132 lines · Joelle van Dyne
Quoted 115 lines · Akihiko Odaki
Quoted 32 lines · Joelle van Dyne

When supported, virglrenderer will return a MTLTexture handle that can be directly used for scanout.

---
   meson.build                   |  4 ++++
   include/ui/console.h          |  2 ++
   hw/display/virtio-gpu-virgl.c | 12 +++++++++++-
   hw/display/virtio-gpu.c       | 10 ++++++++--
   4 files changed, 25 insertions(+), 3 deletions(-)
meson.build +2 -0
index d9293294d8e..05bad663764 100644
@@ -832,6 +832,7 @@ version_res = []
   coref = []
   iokit = []
   pvg = not_found
+metal = not_found
   emulator_link_args = []
   midl = not_found
   widl = not_found
@@ -859,6 +860,7 @@ elif host_os == 'darwin'
     host_dsosuf = '.dylib'
     pvg = dependency('appleframeworks', modules: ['ParavirtualizedGraphics', 'Metal'],
                      required: get_option('pvg'))
+  metal = dependency('appleframeworks', modules: 'Metal', required: false)
   elif host_os == 'sunos'
     socket = [cc.find_library('socket'),
               cc.find_library('nsl'),

meson.build if xen.found() · line 2596

Quoted 4 lines
meson.build +1 -0
@@ -2591,6 +2593,7 @@ if xen.found()
       ('0' + xen_version[2]).substring(-2)
     config_host_data.set('CONFIG_XEN_CTRL_INTERFACE_VERSION', xen_ctrl_version)
   endif
+config_host_data.set('CONFIG_METAL', metal.found())

This is unnecessary; CONFIG_DARWIN is sufficient.

meson.build summary(summary_info, bool_yn: true, section: 'Crypto') · line 4880

Quoted 8 lines
meson.build +1 -0
   config_host_data.set('QEMU_VERSION', '"@0@"'.format(meson.project_version()))
   config_host_data.set('QEMU_VERSION_MAJOR', meson.project_version().split('.')[0])
   config_host_data.set('QEMU_VERSION_MINOR', meson.project_version().split('.')[1])
@@ -4874,6 +4877,7 @@ summary(summary_info, bool_yn: true, section: 'Crypto')
   summary_info = {}
   if host_os == 'darwin'
     summary_info += {'Cocoa support':           cocoa}
+  summary_info += {'Metal support':           metal}

This printing is extraneous. All versions of Darwin QEMU supports have Metal.

Quoted 62 lines
meson.build +0 -0
   endif
   summary_info += {'D-Bus display':     dbus_display}
   summary_info += {'SDL support':       sdl}
include/ui/console.h +2 -0
index 25e45295d44..a45b524c575 100644
@@ -134,12 +134,14 @@ struct QemuConsoleClass {
   typedef enum ScanoutTextureNativeType {
       SCANOUT_TEXTURE_NATIVE_TYPE_NONE,
       SCANOUT_TEXTURE_NATIVE_TYPE_D3D,
+    SCANOUT_TEXTURE_NATIVE_TYPE_METAL,
   } ScanoutTextureNativeType;
 
   typedef struct ScanoutTextureNative {
       ScanoutTextureNativeType type;
       union {
           void *d3d_tex2d;
+        void *metal_texture;
       } u;
   } ScanoutTextureNative;
 
hw/display/virtio-gpu-virgl.c +11 -1
index 9fcc01b6f46..b3e83046643 100644
@@ -438,6 +438,13 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
   #if VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION >= NATIVE_HANDLE_SUPPORT_VERSION
           if (ext.version >= VIRGL_RENDERER_RESOURCE_INFO_EXT_VERSION) {
               switch (ext.native_type) {
+#ifdef CONFIG_METAL
+            case VIRGL_NATIVE_HANDLE_METAL_TEXTURE: {
+                native.type = SCANOUT_TEXTURE_NATIVE_TYPE_METAL;
+                native.u.metal_texture = ext.native_handle;
+                break;
+            }
+#endif
               case VIRGL_NATIVE_HANDLE_NONE:
               case VIRGL_NATIVE_HANDLE_D3D_TEX2D: {
                   /* already handled above */
@@ -1184,7 +1191,10 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
       }
   #if VIRGL_VERSION_MAJOR >= 1
       if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
-        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
+        flags |= VIRGL_RENDERER_VENUS;
+#ifndef CONFIG_METAL /* Metal does not support render server */
+        flags |= VIRGL_RENDERER_RENDER_SERVER;
+#endif
       }
   #endif
 
hw/display/virtio-gpu.c +1 -0
index 43e88a4daff..38010c0fcc2 100644
@@ -1483,12 +1483,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
   {
       VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
       VirtIOGPU *g = VIRTIO_GPU(qdev);
+    bool have_ext_memory;
 
Quoted 15 lines

hw/display/virtio-gpu.c void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) · line 1497

Quoted 12 lines
hw/display/virtio-gpu.c +7 -2
       if (virtio_gpu_blob_enabled(g->parent_obj.conf)) {
+#ifdef CONFIG_METAL
+        have_ext_memory = true;
+#else
+        have_ext_memory = virtio_gpu_have_udmabuf();
+#endif
           if (!virtio_gpu_rutabaga_enabled(g->parent_obj.conf) &&
               !virtio_gpu_virgl_enabled(g->parent_obj.conf) &&
-            !virtio_gpu_have_udmabuf()) {
-            error_setg(errp, "need rutabaga or udmabuf for blob resources");
+            !have_ext_memory) {
+            error_setg(errp, "need rutabaga or ext memory for blob resources");

This change is extraneous. It allows creating blob resources with virtio-gpu (not virtio-gpu-gl) on macOS, which shouldn't happen.

Quoted 8 lines

virtio_gpu_gl_device_realize() calls virtio_gpu_device_realize() at the end so it will have to pass this check. Would this be better?

#ifdef CONFIG_METAL
have_ext_memory = virtio_gpu_venus_enabled(g->parent_obj.conf); #else
have_ext_memory = virtio_gpu_have_udmabuf();
#endif

It should pass the check since virtio_gpu_virgl_enabled() returns true. The condition means:

1. If it is virtio-gpu-rutabaga, blob resources are available.
2. If it is virtio-gpu-gl, blob resources are available.
3. Otherwise (i.e., if it is virtio-gpu), blob resources require udmabuf.

Regards,
Akihiko Odaki