virtio-gpu: enable Venus/Vulkan without OpenGL display
v4 cover virtio-gpu: enable Venus/Vulkan without OpenGL display
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.
v3 -> v4:
- Rebased onto current master (conflict resolved in virtio-gpu.c with new upstream drm feature check)
- Split Linux header changes into dedicated patch (checkpatch)
- Fix line-over-80 warnings
- Resent as new top-level thread (Alex Bennée)
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 (4):
ui: introduce GRAPHIC_FLAGS_VK for Vulkan scanout
virtio-gpu: decouple Venus from CONFIG_OPENGL
virtio-gpu: add VIRTIO_GPU_F_BLOB_ALIGNMENT header definitions
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 | 7 ++ 8 files changed, 121 insertions(+), 16 deletions(-)
Signature · 1 line
2.52.0
PATCH v4 1/4 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 | 7 +++++++ 2 files changed, 9 insertions(+)
include/ui/console.h +2 -0
@@ -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 +7 -0
@@ -594,6 +594,13 @@ 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, +"Vulkan scanout not yet implemented" ); +return false; + } +return true; }
Signature · 1 line
2.52.0
PATCH v4 2/4 virtio-gpu: decouple Venus from CONFIG_OPENGL
In reply to Lucas AmaralVenus (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
@@ -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
@@ -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
@@ -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 uses Vulkan in the render server, no GL needed */ + }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
Re: [PATCH v4 2/4] virtio-gpu: decouple Venus from CONFIG_OPENGL
Hi Lucas,
Quoted 84 lines · 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_OPENGLanddisplay_opengl:
- Only advertise VIRGL/VIRGL2 capsets whendisplay_openglis set
- Only passVIRGL_RENDERER_NO_VIRGLwhen !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 realizeSigned-off-by Lucas Amaral <[email protected]>--- 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@@ -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} endifhw/display/virtio-gpu-base.c +13
-1@@ -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 ; }
hw/display/virtio-gpu-base.c virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, · line 288
Quoted 4 lines
hw/display/virtio-gpu-base.c +1
-0@@ -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 );
Thanks for the patch.
You are using VIRTIO_GPU_F_BLOB_ALIGNMENT here in patch2, but the macro isn't actually defined until Patch 3. This breaks git bisect because the project will fail to compile if someone checks out this specific commit.
Here is the build error it causes:
../hw/display/virtio-gpu-base.c: In function ‘virtio_gpu_base_get_features’:../hw/display/virtio-gpu-base.c:288:27: error: ‘VIRTIO_GPU_F_BLOB_ALIGNMENT’ undeclared (first use in this function); did you mean ‘VIRTIO_GPU_BLOB_MEM_GUEST’?
288 | features |= (1 << VIRTIO_GPU_F_BLOB_ALIGNMENT);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| VIRTIO_GPU_BLOB_MEM_GUESTRegards,
Kuan-Wei
Quoted 179 lines
hw/display/virtio-gpu-base.c +0
-0}if (virtio_gpu_context_init_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT );hw/display/virtio-gpu-gl.c +5
-1@@ -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 uses Vulkan in the render server, no GL needed */ + }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@@ -19,8 +19,10 @@#include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-gpu-bswap.h" #include "hw/virtio/virtio-gpu-pixman.h" - +#include "system/system.h" +#ifdef CONFIG_OPENGL #include "ui/egl-helpers.h" +#endif #include <virglrenderer.h> @@ -50,6 +52,16 @@ struct virtio_gpu_virgl_resource {void *map_fixed; }; +/* +* Venus no-GL mode: Venus is enabled but no OpenGL display is available. +* Display commands use software (pixman) rendering; Venus/3D commands +* go through the virglrenderer render server. +*/ +static bool virtio_gpu_venus_nogl (VirtIOGPU *g) +{ +return virtio_gpu_venus_enabled (g->parent_obj.conf) && !display_opengl; +} +static struct virtio_gpu_virgl_resource *virtio_gpu_virgl_find_resource (VirtIOGPU *g,uint32_t resource_id) {@@ -63,7 +75,7 @@ virtio_gpu_virgl_find_resource(VirtIOGPU *g, uint32_t resource_id) return container_of(res, struct virtio_gpu_virgl_resource, base); } -#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 +#if VIRGL_RENDERER_CALLBACKS_VERSION >=4 && defined(CONFIG_OPENGL )static void * virgl_get_egl_display(G_GNUC_UNUSED void *cookie) {@@ -1032,6 +1044,45 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (cmd->cmd_hdr); +/* +* Venus no-GL mode: route 2D display commands to the base software +* renderer (pixman). The guest kernel always uses 2D commands for +* display framebuffers even with VIRGL enabled; Venus/3D commands +* go through the virglrenderer render server as usual. +*/ +if (virtio_gpu_venus_nogl (g)) { +switch (cmd->cmd_hdr.type) { +case VIRTIO_GPU_CMD_RESOURCE_CREATE_2D : +case VIRTIO_GPU_CMD_SET_SCANOUT : +case VIRTIO_GPU_CMD_RESOURCE_FLUSH : +case VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D : +case VIRTIO_GPU_CMD_GET_DISPLAY_INFO : +case VIRTIO_GPU_CMD_GET_EDID : +virtio_gpu_simple_process_cmd (g, cmd); +return ; +case VIRTIO_GPU_CMD_RESOURCE_UNREF : +case VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING : +case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING : { +/* +* Both 2D (simple) and blob (virgl) resources share g->reslist. +* Check if virglrenderer owns the resource to pick +* the right handler. +*/ +struct virtio_gpu_resource_unref hdr; +struct virgl_renderer_resource_info info; +VIRTIO_GPU_FILL_CMD (hdr); +if (virgl_renderer_resource_get_info (hdr.resource_id, &info)) { +/* Not in virglrenderer — it's a 2D software resource */ +virtio_gpu_simple_process_cmd (g, cmd); +return ; + } +break ;/* virglrenderer owns it — fall through */ + } +default : +break ; + } + } +virgl_renderer_force_ctx_0 ();switch (cmd->cmd_hdr.type) {case VIRTIO_GPU_CMD_CTX_CREATE :@@ -1433,6 +1484,7 @@ static int virtio_gpu_virgl_init(VirtIOGPU *g)uint32_t flags =0 ;VirtIOGPUGL *gl =VIRTIO_GPU_GL (g); +#ifdef CONFIG_OPENGL #if VIRGL_RENDERER_CALLBACKS_VERSION >= 4 if (qemu_egl_display) { virtio_gpu_3d_cbs.version = 4;@@ -1450,9 +1502,14 @@ static int virtio_gpu_virgl_init(VirtIOGPU *g) flags |=VIRGL_RENDERER_D3D11_SHARE_TEXTURE ; }#endif +#endif /* CONFIG_OPENGL */ #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 + |VIRGL_RENDERER_RENDER_SERVER ; +if (!display_opengl) { + flags |=VIRGL_RENDERER_NO_VIRGL ; + } }if (virtio_gpu_drm_enabled (g->parent_obj.conf)) { flags |=VIRGL_RENDERER_DRM ;@@ -1475,6 +1532,12 @@ static int virtio_gpu_virgl_init(VirtIOGPU *g) }#endif +if (!display_opengl) { + virtio_gpu_3d_cbs.create_gl_context =NULL ; + virtio_gpu_3d_cbs.destroy_gl_context =NULL ; + virtio_gpu_3d_cbs.make_current =NULL ; + } + ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);@@ -1546,14 +1609,16 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) capset_ids =g_array_new (false, false,sizeof (uint32_t )); -/* VIRGL is always supported. */ -virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_VIRGL ); +/* OpenGL: VIRGL/VIRGL2 require a GL display backend */ +if (display_opengl) { +virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_VIRGL ); -virgl_renderer_get_cap_set (VIRTIO_GPU_CAPSET_VIRGL2 , - &capset_max_ver, - &capset_max_size); -if (capset_max_ver) { -virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_VIRGL2 ); +virgl_renderer_get_cap_set (VIRTIO_GPU_CAPSET_VIRGL2 , + &capset_max_ver, + &capset_max_size); +if (capset_max_ver) { +virtio_gpu_virgl_add_capset (capset_ids,VIRTIO_GPU_CAPSET_VIRGL2 ); + } }if (virtio_gpu_venus_enabled (g->parent_obj.conf)) {Signature · 1 line
2.52.0
PATCH v4 3/4 virtio-gpu: add VIRTIO_GPU_F_BLOB_ALIGNMENT header definitions
In reply to Lucas AmaralDefine VIRTIO_GPU_F_BLOB_ALIGNMENT (feature bit 5) and the blob_alignment field in virtio_gpu_config per the OASIS virtio specification.
--- include/standard-headers/linux/virtio_gpu.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/standard-headers/linux/virtio_gpu.h +6 -0
@@ -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 5enum 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
PATCH v4 4/4 virtio-gpu: advertise VIRTIO_GPU_F_BLOB_ALIGNMENT
In reply to Lucas AmaralSet 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 ++++++++ 1 file changed, 8 insertions(+)
hw/display/virtio-gpu.c +8 -0
@@ -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,
Signature · 1 line
2.52.0