Skip to contentSkip to conversation

virtio-gpu: enable Venus/Vulkan without OpenGL display

PATCH Superseded Lucas Amaral 2 participants 13 messages Mar 9 – Mar 13 Arm/Amlogic Meson SoC support

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover virtio-gpu: enable Venus/Vulkan without OpenGL display

Venus (virtio-gpu Vulkan context) currently requires OpenGL display support due to build-time and runtime coupling with the GL backend. On macOS, no OpenGL display backend exists (only Cocoa/SDL2 without GL).

This series decouples Venus from OpenGL:

1. Define VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) in the virtio-gpu header per the OASIS virtio specification. Header-only change.

2. Remove opengl.found() build requirement for virtio-gpu-gl module (virglrenderer provides Venus independently of GL). Gate GL-specific code paths behind CONFIG_OPENGL and display_opengl checks. Route 2D display commands to the software renderer when Venus runs without GL. Define GRAPHIC_FLAGS_VK for future Vulkan scanout support. Gate Venus at device realize when the HVF map granule exceeds the guest page size, ensuring blob mappings succeed at runtime.

3. Advertise blob_alignment in the device configuration so the host can communicate its page alignment requirement to the guest.

Patch 1 is a prerequisite for patch 2 (which advertises the feature bit). Patch 3 is independent and can be taken separately. Guest kernel support (Sergio Lopez's patches) is pending upstream Linux.

Dependencies: none.
Independent of: hvf-isv0-emulation and hvf-map-granule series. All three QEMU series touch disjoint files and can be merged in any order.

Lucas Amaral (3):
include/standard-headers: add VIRTIO_GPU_F_BLOB_ALIGNMENT
virtio-gpu: decouple Venus from CONFIG_OPENGL
virtio-gpu: advertise and populate blob alignment

 hw/display/meson.build                      |  8 +-
 hw/display/virtio-gpu-base.c                |  8 +-
 hw/display/virtio-gpu-gl.c                  | 17 +++-
 hw/display/virtio-gpu-virgl.c               | 89 ++++++++++++++++++---
 hw/display/virtio-gpu.c                     |  7 ++
 include/standard-headers/linux/virtio_gpu.h |  6 ++
 include/ui/console.h                        |  2 +
 ui/console.c                                |  7 ++
 8 files changed, 127 insertions(+), 17 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/3 include/standard-headers: add VIRTIO_GPU_F_BLOB_ALIGNMENT

Define VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) per the OASIS virtio specification and add the blob_alignment field to struct virtio_gpu_config.

This allows the host to communicate its memory alignment requirement to the guest via the device configuration space.

Header-only change, no functional impact.

---
 include/standard-headers/linux/virtio_gpu.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/standard-headers/linux/virtio_gpu.h +6 -0
index 00cd3f0..252704e 100644
@@ -64,6 +64,11 @@
  * context_init and multiple timelines
  */
 #define VIRTIO_GPU_F_CONTEXT_INIT        4
+/*
+ * VIRTIO_GPU_F_BLOB_ALIGNMENT: device advertises blob_alignment
+ * in virtio_gpu_config (OASIS virtio-spec feature bit 5)
+ */
+#define VIRTIO_GPU_F_BLOB_ALIGNMENT      5
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -365,6 +370,7 @@ struct virtio_gpu_config {
 	uint32_t events_clear;
 	uint32_t num_scanouts;
 	uint32_t num_capsets;
+	uint32_t blob_alignment;
 };
 
 /* simple formats for fbcon/X use */
Signature · 1 line
2.52.0
#2 lore raw

PATCH 2/3 virtio-gpu: decouple Venus from CONFIG_OPENGL

In reply to Lucas Amaral

Venus (virtio-gpu Vulkan context) currently requires an OpenGL display backend due to build-time and runtime coupling. On macOS, no OpenGL display backend exists.

Remove the opengl.found() build requirement for the virtio-gpu-gl module; virglrenderer provides Venus independently of OpenGL.

Gate GL-specific code paths behind CONFIG_OPENGL and display_opengl:
- Only advertise VIRGL/VIRGL2 capsets when display_opengl is set
- Only pass VIRGL_RENDERER_NO_VIRGL when !display_opengl with Venus
- Null out GL context callbacks when no GL display is available
- Route 2D display commands to the software renderer (pixman) when Venus runs without GL (venus no-GL mode)
- Allow Venus to bypass the OpenGL display check at device realize

Introduce GRAPHIC_FLAGS_VK (bit 2) in the console flags for future Vulkan scanout support alongside the existing GL and DMABUF paths.

Gate Venus at device realize when the HVF map granule exceeds the guest page size; this ensures blob mappings succeed at runtime.

---
 hw/display/meson.build        |  8 ++--
 hw/display/virtio-gpu-base.c  |  8 +++-
 hw/display/virtio-gpu-gl.c    | 17 ++++++-
 hw/display/virtio-gpu-virgl.c | 89 ++++++++++++++++++++++++++++++-----
 include/ui/console.h          |  2 +
 ui/console.c                  |  7 +++
 6 files changed, 114 insertions(+), 17 deletions(-)
hw/display/meson.build +4 -4
index 90e6c04..509479e 100644
@@ -76,9 +76,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
   virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
   hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_gl_ss = ss.source_set()
-    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl, opengl],
+    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl],
                          if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-virgl.c'), pixman, virgl])
     hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
   endif
@@ -99,9 +99,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
                         if_true: files('vhost-user-gpu-pci.c'))
   hw_display_modules += {'virtio-gpu-pci': virtio_gpu_pci_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_pci_gl_ss = ss.source_set()
-    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl, opengl],
+    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl],
                              if_true: [files('virtio-gpu-pci-gl.c'), pixman])
     hw_display_modules += {'virtio-gpu-pci-gl': virtio_gpu_pci_gl_ss}
   endif
hw/display/virtio-gpu-base.c +7 -1
index 7269477..faee6dc 100644
@@ -18,6 +18,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/display/edid.h"
+#include "system/system.h"
 #include "trace.h"
 #include "qapi/qapi-types-virtio.h"
 
@@ -157,7 +158,11 @@ virtio_gpu_get_flags(void *opaque)
     VirtIOGPUBase *g = opaque;
     int flags = GRAPHIC_FLAGS_NONE;
 
-    if (virtio_gpu_virgl_enabled(g->conf)) {
+    if (virtio_gpu_venus_enabled(g->conf)) {
+        /* TODO: set GRAPHIC_FLAGS_VK for direct Vulkan scanout */
+    }
+
+    if (virtio_gpu_virgl_enabled(g->conf) && display_opengl) {
         flags |= GRAPHIC_FLAGS_GL;
     }
 
@@ -257,6 +262,7 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
     }
     if (virtio_gpu_blob_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
+        features |= (1 << VIRTIO_GPU_F_BLOB_ALIGNMENT);
     }
     if (virtio_gpu_context_init_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
hw/display/virtio-gpu-gl.c +16 -1
index b98ef2e..e55fe87 100644
@@ -17,6 +17,8 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "system/system.h"
+#include "system/hvf.h"
+#include "exec/target_page.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-gpu.h"
 #include "hw/virtio/virtio-gpu-bswap.h"
@@ -133,7 +135,18 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
         return;
     }
 
-    if (!display_opengl) {
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+        /* Venus renders via Vulkan -- no GL display needed */
+        uint64_t map_gran = hvf_get_map_granule();
+        if (map_gran > qemu_target_page_size()) {
+            error_report("Venus disabled: host map granule (%zu) > guest "
+                         "page size (%zu). Requires macOS 26+ or guest "
+                         "F_BLOB_ALIGNMENT support.",
+                         (size_t)map_gran, qemu_target_page_size());
+            g->parent_obj.conf.flags &=
+                ~(1 << VIRTIO_GPU_FLAG_VENUS_ENABLED);
+        }
+    } else if (!display_opengl) {
         error_setg(errp,
                    "The display backend does not have OpenGL support enabled");
         error_append_hint(errp,
@@ -217,4 +230,6 @@ static void virtio_register_types(void)
 type_init(virtio_register_types)
 
 module_dep("hw-display-virtio-gpu");
+#ifdef CONFIG_OPENGL
 module_dep("ui-opengl");
+#endif
hw/display/virtio-gpu-virgl.c +78 -11

145 lines not on this page · raw message

include/ui/console.h +2 -0
index 98feaa5..fa7fdec 100644
@@ -361,6 +361,8 @@ enum {
     GRAPHIC_FLAGS_GL       = 1 << 0,
     /* require a console/display with DMABUF import */
     GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+    /* require a console/display with Vulkan scanout */
+    GRAPHIC_FLAGS_VK       = 1 << 2,
 };
 
 typedef struct GraphicHwOps {
ui/console.c +7 -0
index f445db1..d53dc10 100644
@@ -594,6 +594,13 @@ static bool console_compatible_with(QemuConsole *con,
         return false;
     }
 
+    if (flags & GRAPHIC_FLAGS_VK) {
+        error_setg(errp,
+                   "The console requires Vulkan scanout "
+                   "(not yet implemented).");
+        return false;
+    }
+
     return true;
 }
 
Signature · 1 line
2.52.0
#3 lore raw

PATCH 3/3 virtio-gpu: advertise and populate blob alignment

In reply to Lucas Amaral

Set blob_alignment in the device configuration to the host page size so the guest kernel can align blob BAR offsets accordingly, avoiding alignment mismatches with the VMM's memory mapping API (e.g., hv_vm_map on macOS).

Uses VIRTIO_GPU_F_BLOB_ALIGNMENT defined in the preceding header patch, and advertised via the feature bit in get_features.

---
 hw/display/virtio-gpu.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/display/virtio-gpu.c +7 -0
index 643e91c..15e8be0 100644
@@ -1517,6 +1517,13 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
 #endif
     }
 
+    /*
+     * Advertise blob alignment so the guest kernel can align BAR offsets.
+     * Guest-side F_BLOB_ALIGNMENT support pending upstream Linux merge.
+     */
+    g->parent_obj.virtio_config.blob_alignment =
+        cpu_to_le32(qemu_real_host_page_size());
+
     if (!virtio_gpu_base_device_realize(qdev,
                                         virtio_gpu_handle_ctrl_cb,
                                         virtio_gpu_handle_cursor_cb,
Signature · 1 line
2.52.0
#4 lore raw

v2 cover virtio-gpu: enable Venus/Vulkan without OpenGL display

In reply to Lucas Amaral

Venus (virtio-gpu Vulkan context) currently requires OpenGL display support due to build-time and runtime coupling with the GL backend. On macOS, no OpenGL display backend exists (only Cocoa/SDL2 without GL).

This series decouples Venus from OpenGL:

1. Define GRAPHIC_FLAGS_VK for future Vulkan scanout support.

2. Remove opengl.found() build requirement for virtio-gpu-gl module (virglrenderer provides Venus independently of GL). Gate GL-specific code paths behind CONFIG_OPENGL and display_opengl checks. Route 2D display commands to the software renderer when Venus runs without GL.

3. Define VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) in the virtio-gpu header per the OASIS virtio specification and advertise blob_alignment in the device configuration so the host can communicate its page alignment requirement to the guest.

Dependencies: none.

Changes v1 → v2:
- Remove hvf_get_map_granule() Venus safety check from this series; the check moves to hvf-map-granule where the function is defined, so venus-nogl compiles on all platforms without cross-series dependencies.
- Extract GRAPHIC_FLAGS_VK into its own patch.
- Fold standard-headers addition into the blob_alignment patch.

Lucas Amaral (3):
ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout
virtio-gpu: decouple Venus from CONFIG_OPENGL
virtio-gpu: advertise VIRTIO_GPU_F_BLOB_ALIGNMENT

 hw/display/meson.build                      |  8 +-
 hw/display/virtio-gpu-base.c                | 15 +++-
 hw/display/virtio-gpu-gl.c                  |  6 +-
 hw/display/virtio-gpu-virgl.c               | 84 ++++++++++++++++++---
 hw/display/virtio-gpu.c                     |  8 ++
 include/standard-headers/linux/virtio_gpu.h |  6 ++
 include/ui/console.h                        |  2 +
 ui/console.c                                |  6 ++
 8 files changed, 119 insertions(+), 16 deletions(-)

--
2.52.0

#5 lore raw

PATCH v2 1/3 ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout

Define GRAPHIC_FLAGS_VK (bit 2) in the console flags for future Vulkan scanout support. The compatibility check currently returns an error indicating the feature is not yet implemented.

This prepares the display framework for direct Vulkan scanout alongside the existing GL and DMABUF paths.

---
 include/ui/console.h | 2 ++
 ui/console.c         | 6 ++++++
 2 files changed, 8 insertions(+)
include/ui/console.h +2 -0
index 98feaa5..6b8bbaf 100644
@@ -361,6 +361,8 @@ enum {
     GRAPHIC_FLAGS_GL       = 1 << 0,
     /* require a console/display with DMABUF import */
     GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+    /* TODO: require a console/display with Vulkan scanout */
+    GRAPHIC_FLAGS_VK       = 1 << 2,
 };
 
 typedef struct GraphicHwOps {
ui/console.c +6 -0
index f445db1..76d54bf 100644
@@ -594,6 +594,12 @@ static bool console_compatible_with(QemuConsole *con,
         return false;
     }
 
+    if (flags & GRAPHIC_FLAGS_VK) {
+        /* TODO: check for Vulkan scanout support in display backend */
+        error_setg(errp, "The console requires Vulkan scanout (not yet implemented).");
+        return false;
+    }
+
     return true;
 }
 
Signature · 1 line
2.52.0
Reviewed-by on v2 1/3
#6 lore raw

Re: [PATCH v2 1/3] ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout

Hi

Quoted 9 lines · Lucas Amaral

Define GRAPHIC_FLAGS_VK (bit 2) in the console flags for future Vulkan scanout support. The compatibility check currently returns an error indicating the feature is not yet implemented.

This prepares the display framework for direct Vulkan scanout alongside the existing GL and DMABUF paths.

Quoted 39 lines
---
 include/ui/console.h | 2 ++
 ui/console.c         | 6 ++++++
 2 files changed, 8 insertions(+)
include/ui/console.h +2 -0
index 98feaa5..6b8bbaf 100644
@@ -361,6 +361,8 @@ enum {
     GRAPHIC_FLAGS_GL       = 1 << 0,
     /* require a console/display with DMABUF import */
     GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+    /* TODO: require a console/display with Vulkan scanout */
+    GRAPHIC_FLAGS_VK       = 1 << 2,
 };
 
 typedef struct GraphicHwOps {
ui/console.c +6 -1
index f445db1..76d54bf 100644
@@ -594,6 +594,12 @@ static bool console_compatible_with(QemuConsole *con,
         return false;
     }
 
+    if (flags & GRAPHIC_FLAGS_VK) {
+        /* TODO: check for Vulkan scanout support in display backend */
+        error_setg(errp, "The console requires Vulkan scanout (not yet implemented).");
+        return false;
+    }
+
     return true;
 }
 
--

2.52.0

Signature · 1 line
Marc-André Lureau
#7 lore raw

PATCH v2 2/3 virtio-gpu: decouple Venus from CONFIG_OPENGL

In reply to Lucas Amaral

Venus (virtio-gpu Vulkan context) currently requires an OpenGL display backend due to build-time and runtime coupling. On macOS, no OpenGL display backend exists.

Remove the opengl.found() build requirement for the virtio-gpu-gl module; virglrenderer provides Venus independently of OpenGL.

Gate GL-specific code paths behind CONFIG_OPENGL and display_opengl:
- Only advertise VIRGL/VIRGL2 capsets when display_opengl is set
- Only pass VIRGL_RENDERER_NO_VIRGL when !display_opengl with Venus
- Null out GL context callbacks when no GL display is available
- Route 2D display commands to the software renderer (pixman) when Venus runs without GL (venus no-GL mode)
- Allow Venus to bypass the OpenGL display check at device realize

---
 hw/display/meson.build        |  8 ++--
 hw/display/virtio-gpu-base.c  | 15 ++++++-
 hw/display/virtio-gpu-gl.c    |  6 ++-
 hw/display/virtio-gpu-virgl.c | 84 ++++++++++++++++++++++++++++++-----
 4 files changed, 97 insertions(+), 16 deletions(-)
hw/display/meson.build +4 -4
index 90e6c04..509479e 100644
@@ -76,9 +76,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
   virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
   hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_gl_ss = ss.source_set()
-    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl, opengl],
+    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl],
                          if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-virgl.c'), pixman, virgl])
     hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
   endif
@@ -99,9 +99,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
                         if_true: files('vhost-user-gpu-pci.c'))
   hw_display_modules += {'virtio-gpu-pci': virtio_gpu_pci_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_pci_gl_ss = ss.source_set()
-    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl, opengl],
+    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl],
                              if_true: [files('virtio-gpu-pci-gl.c'), pixman])
     hw_display_modules += {'virtio-gpu-pci-gl': virtio_gpu_pci_gl_ss}
   endif
hw/display/virtio-gpu-base.c +14 -1
index 7269477..dd93b65 100644
@@ -18,6 +18,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/display/edid.h"
+#include "system/system.h"
 #include "trace.h"
 #include "qapi/qapi-types-virtio.h"
 
@@ -157,7 +158,18 @@ virtio_gpu_get_flags(void *opaque)
     VirtIOGPUBase *g = opaque;
     int flags = GRAPHIC_FLAGS_NONE;
 
-    if (virtio_gpu_virgl_enabled(g->conf)) {
+    if (virtio_gpu_venus_enabled(g->conf)) {
+        /* TODO: set GRAPHIC_FLAGS_VK for direct Vulkan scanout */
+    }
+
+    /*
+     * TODO: virtio_gpu_virgl_enabled() checks VIRTIO_GPU_FLAG_VIRGL_ENABLED
+     * which is set for both OpenGL (VIRGL) and Vulkan (Venus) backends.
+     * This condition should ideally use a dedicated OpenGL-only flag. For
+     * now, display_opengl correctly gates GL scanout since Venus leaves it
+     * at 0.
+     */
+    if (virtio_gpu_virgl_enabled(g->conf) && display_opengl) {
         flags |= GRAPHIC_FLAGS_GL;
     }
 
@@ -257,6 +269,7 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
     }
     if (virtio_gpu_blob_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
+        features |= (1 << VIRTIO_GPU_F_BLOB_ALIGNMENT);
     }
     if (virtio_gpu_context_init_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
hw/display/virtio-gpu-gl.c +5 -1
index b98ef2e..b5526cd 100644
@@ -133,7 +133,9 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
         return;
     }
 
-    if (!display_opengl) {
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+        /* Venus renders via Vulkan in the render server — no GL display needed */
+    } else if (!display_opengl) {
         error_setg(errp,
                    "The display backend does not have OpenGL support enabled");
         error_append_hint(errp,
@@ -217,4 +219,6 @@ static void virtio_register_types(void)
 type_init(virtio_register_types)
 
 module_dep("hw-display-virtio-gpu");
+#ifdef CONFIG_OPENGL
 module_dep("ui-opengl");
+#endif
hw/display/virtio-gpu-virgl.c +74 -10

133 lines not on this page · raw message

Signature · 1 line
2.52.0
#8 lore raw

PATCH v2 3/3 virtio-gpu: advertise VIRTIO_GPU_F_BLOB_ALIGNMENT

In reply to Lucas Amaral

Define VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) per the OASIS virtio specification. This allows the host to communicate its memory alignment requirement to the guest via the blob_alignment field in virtio_gpu_config.

Set blob_alignment to the host page size so the guest kernel can align blob BAR offsets accordingly, avoiding alignment mismatches with the VMM's memory mapping API (e.g., hv_vm_map on macOS).

Guest-side kernel support (drm_mm alignment) is pending upstream Linux merge.

---
 hw/display/virtio-gpu.c                     | 8 ++++++++
 include/standard-headers/linux/virtio_gpu.h | 6 ++++++
 2 files changed, 14 insertions(+)
hw/display/virtio-gpu.c +8 -0
index 643e91c..c12273d 100644
@@ -1517,6 +1517,14 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
 #endif
     }
 
+    /*
+     * TODO: guest-side F_BLOB_ALIGNMENT support pending upstream Linux merge
+     * (Sergio Lopez's patches, Nov 2025). Until merged, the guest won't
+     * negotiate this feature. The host advertises it per OASIS virtio spec.
+     */
+    g->parent_obj.virtio_config.blob_alignment =
+        cpu_to_le32(qemu_real_host_page_size());
+
     if (!virtio_gpu_base_device_realize(qdev,
                                         virtio_gpu_handle_ctrl_cb,
                                         virtio_gpu_handle_cursor_cb,
include/standard-headers/linux/virtio_gpu.h +6 -0
index 00cd3f0..252704e 100644
@@ -64,6 +64,11 @@
  * context_init and multiple timelines
  */
 #define VIRTIO_GPU_F_CONTEXT_INIT        4
+/*
+ * VIRTIO_GPU_F_BLOB_ALIGNMENT: device advertises blob_alignment
+ * in virtio_gpu_config (OASIS virtio-spec feature bit 5)
+ */
+#define VIRTIO_GPU_F_BLOB_ALIGNMENT      5
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -365,6 +370,7 @@ struct virtio_gpu_config {
 	uint32_t events_clear;
 	uint32_t num_scanouts;
 	uint32_t num_capsets;
+	uint32_t blob_alignment;
 };
 
 /* simple formats for fbcon/X use */
Signature · 1 line
2.52.0
#9 lore raw

v3 cover virtio-gpu: enable Venus/Vulkan without OpenGL display

In reply to Lucas Amaral

Decouple Venus from CONFIG_OPENGL so it works on hosts with no GL display (e.g. macOS with MoltenVK). 2D display commands fall back to pixman; 3D/Vulkan goes through the render server as usual.

v2 -> v3:
- Rebased onto current master
- Fixed line-over-80 warnings

v1 -> v2:
- Remove hvf_get_map_granule() safety check (moved to hvf-map-granule)
- Extract GRAPHIC_FLAGS_VK into its own patch
- Fold standard-headers addition into blob_alignment patch

Lucas Amaral (3):
ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout
virtio-gpu: decouple Venus from CONFIG_OPENGL
virtio-gpu: advertise VIRTIO_GPU_F_BLOB_ALIGNMENT

 hw/display/meson.build                      |  8 +-
 hw/display/virtio-gpu-base.c                | 15 +++-
 hw/display/virtio-gpu-gl.c                  |  6 +-
 hw/display/virtio-gpu-virgl.c               | 85 ++++++++++++++++++---
 hw/display/virtio-gpu.c                     |  8 ++
 include/standard-headers/linux/virtio_gpu.h |  6 ++
 include/ui/console.h                        |  2 +
 ui/console.c                                |  8 ++
 8 files changed, 122 insertions(+), 16 deletions(-)
Signature · 1 line
2.52.0
#10 lore raw

PATCH v3 1/3 ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout

Define GRAPHIC_FLAGS_VK (bit 2) in the console flags for future Vulkan scanout support. The compatibility check currently returns an error indicating the feature is not yet implemented.

This prepares the display framework for direct Vulkan scanout alongside the existing GL and DMABUF paths.

---
 include/ui/console.h | 2 ++
 ui/console.c         | 8 ++++++++
 2 files changed, 10 insertions(+)
include/ui/console.h +2 -0
index 3677a9d3..19ac06e0 100644
@@ -361,6 +361,8 @@ enum {
     GRAPHIC_FLAGS_GL       = 1 << 0,
     /* require a console/display with DMABUF import */
     GRAPHIC_FLAGS_DMABUF   = 1 << 1,
+    /* TODO: require a console/display with Vulkan scanout */
+    GRAPHIC_FLAGS_VK       = 1 << 2,
 };
 
 typedef struct GraphicHwOps {
ui/console.c +8 -0
index f445db11..d29733ad 100644
@@ -594,6 +594,14 @@ static bool console_compatible_with(QemuConsole *con,
         return false;
     }
 
+    if (flags & GRAPHIC_FLAGS_VK) {
+        /* TODO: check for Vulkan scanout support in display backend */
+        error_setg(errp,
+                   "The console requires Vulkan scanout "
+                   "(not yet implemented).");
+        return false;
+    }
+
     return true;
 }
 
Signature · 1 line
2.52.0
#11 lore raw

PATCH v3 2/3 virtio-gpu: decouple Venus from CONFIG_OPENGL

In reply to Lucas Amaral

Venus (virtio-gpu Vulkan context) currently requires an OpenGL display backend due to build-time and runtime coupling. On macOS, no OpenGL display backend exists.

Remove the opengl.found() build requirement for the virtio-gpu-gl module; virglrenderer provides Venus independently of OpenGL.

Gate GL-specific code paths behind CONFIG_OPENGL and display_opengl:
- Only advertise VIRGL/VIRGL2 capsets when display_opengl is set
- Only pass VIRGL_RENDERER_NO_VIRGL when !display_opengl with Venus
- Null out GL context callbacks when no GL display is available
- Route 2D display commands to the software renderer (pixman) when Venus runs without GL (venus no-GL mode)
- Allow Venus to bypass the OpenGL display check at device realize

---
 hw/display/meson.build        |  8 ++--
 hw/display/virtio-gpu-base.c  | 15 ++++++-
 hw/display/virtio-gpu-gl.c    |  6 ++-
 hw/display/virtio-gpu-virgl.c | 85 ++++++++++++++++++++++++++++++-----
 4 files changed, 98 insertions(+), 16 deletions(-)
hw/display/meson.build +4 -4
index 90e6c041..509479e7 100644
@@ -76,9 +76,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU')
   virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c'))
   hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_gl_ss = ss.source_set()
-    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl, opengl],
+    virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl],
                          if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-virgl.c'), pixman, virgl])
     hw_display_modules += {'virtio-gpu-gl': virtio_gpu_gl_ss}
   endif
@@ -99,9 +99,9 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI')
                         if_true: files('vhost-user-gpu-pci.c'))
   hw_display_modules += {'virtio-gpu-pci': virtio_gpu_pci_ss}
 
-  if virgl.found() and opengl.found()
+  if virgl.found()
     virtio_gpu_pci_gl_ss = ss.source_set()
-    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl, opengl],
+    virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PCI', virgl],
                              if_true: [files('virtio-gpu-pci-gl.c'), pixman])
     hw_display_modules += {'virtio-gpu-pci-gl': virtio_gpu_pci_gl_ss}
   endif
hw/display/virtio-gpu-base.c +14 -1
index cb76302e..cc9704cd 100644
@@ -18,6 +18,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/display/edid.h"
+#include "system/system.h"
 #include "trace.h"
 #include "qapi/qapi-types-virtio.h"
 
@@ -157,7 +158,18 @@ virtio_gpu_get_flags(void *opaque)
     VirtIOGPUBase *g = opaque;
     int flags = GRAPHIC_FLAGS_NONE;
 
-    if (virtio_gpu_virgl_enabled(g->conf)) {
+    if (virtio_gpu_venus_enabled(g->conf)) {
+        /* TODO: set GRAPHIC_FLAGS_VK for direct Vulkan scanout */
+    }
+
+    /*
+     * TODO: virtio_gpu_virgl_enabled() checks VIRTIO_GPU_FLAG_VIRGL_ENABLED
+     * which is set for both OpenGL (VIRGL) and Vulkan (Venus) backends.
+     * This condition should ideally use a dedicated OpenGL-only flag. For
+     * now, display_opengl correctly gates GL scanout since Venus leaves it
+     * at 0.
+     */
+    if (virtio_gpu_virgl_enabled(g->conf) && display_opengl) {
         flags |= GRAPHIC_FLAGS_GL;
     }
 
@@ -273,6 +285,7 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
     }
     if (virtio_gpu_blob_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
+        features |= (1 << VIRTIO_GPU_F_BLOB_ALIGNMENT);
     }
     if (virtio_gpu_context_init_enabled(g->conf)) {
         features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
hw/display/virtio-gpu-gl.c +5 -1
index 2b7a41c4..67d88e32 100644
@@ -124,7 +124,9 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
         return;
     }
 
-    if (!display_opengl) {
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+        /* Venus renders via Vulkan in the render server */
+    } else if (!display_opengl) {
         error_setg(errp,
                    "The display backend does not have OpenGL support enabled");
         error_append_hint(errp,
@@ -245,4 +247,6 @@ static void virtio_register_types(void)
 type_init(virtio_register_types)
 
 module_dep("hw-display-virtio-gpu");
+#ifdef CONFIG_OPENGL
 module_dep("ui-opengl");
+#endif
hw/display/virtio-gpu-virgl.c +75 -10

137 lines not on this page · raw message

Signature · 1 line
2.52.0
#12 lore raw

PATCH v3 3/3 virtio-gpu: advertise VIRTIO_GPU_F_BLOB_ALIGNMENT

In reply to Lucas Amaral

Define VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) per the OASIS virtio specification. This allows the host to communicate its memory alignment requirement to the guest via the blob_alignment field in virtio_gpu_config.

Set blob_alignment to the host page size so the guest kernel can align blob BAR offsets accordingly, avoiding alignment mismatches with the VMM's memory mapping API (e.g., hv_vm_map on macOS).

Guest-side kernel support (drm_mm alignment) is pending upstream Linux merge.

---
 hw/display/virtio-gpu.c                     | 8 ++++++++
 include/standard-headers/linux/virtio_gpu.h | 6 ++++++
 2 files changed, 14 insertions(+)
hw/display/virtio-gpu.c +8 -0
index de7a86a7..44ae5034 100644
@@ -1532,6 +1532,14 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
 #endif
     }
 
+    /*
+     * TODO: guest-side F_BLOB_ALIGNMENT support pending upstream Linux merge
+     * (Sergio Lopez's patches, Nov 2025). Until merged, the guest won't
+     * negotiate this feature. The host advertises it per OASIS virtio spec.
+     */
+    g->parent_obj.virtio_config.blob_alignment =
+        cpu_to_le32(qemu_real_host_page_size());
+
     if (!virtio_gpu_base_device_realize(qdev,
                                         virtio_gpu_handle_ctrl_cb,
                                         virtio_gpu_handle_cursor_cb,
include/standard-headers/linux/virtio_gpu.h +6 -0
index 00cd3f04..252704e7 100644
@@ -64,6 +64,11 @@
  * context_init and multiple timelines
  */
 #define VIRTIO_GPU_F_CONTEXT_INIT        4
+/*
+ * VIRTIO_GPU_F_BLOB_ALIGNMENT: device advertises blob_alignment
+ * in virtio_gpu_config (OASIS virtio-spec feature bit 5)
+ */
+#define VIRTIO_GPU_F_BLOB_ALIGNMENT      5
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -365,6 +370,7 @@ struct virtio_gpu_config {
 	uint32_t events_clear;
 	uint32_t num_scanouts;
 	uint32_t num_capsets;
+	uint32_t blob_alignment;
 };
 
 /* simple formats for fbcon/X use */
Signature · 1 line
2.52.0