On Tue, Dec 23, 2025 at 11:21 PM Akihiko Odaki <[email protected]> wrote: > > On 2025/12/20 3:38, Joelle van Dyne wrote: > > When supported, virglrenderer will return a MTLTexture handle that can be > > directly used for scanout. > > > > Signed-off-by: Joelle van Dyne <[email protected]> > > --- > > 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(-) > > > > diff --git a/meson.build b/meson.build > > index d9293294d8e..05bad663764 100644 > > --- a/meson.build > > +++ b/meson.build > > @@ -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()) > > This is unnecessary; CONFIG_DARWIN is sufficient. > > > 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. > > > endif > > summary_info += {'D-Bus display': dbus_display} > > summary_info += {'SDL support': sdl} > > diff --git a/include/ui/console.h b/include/ui/console.h > > index 25e45295d44..a45b524c575 100644 > > --- a/include/ui/console.h > > +++ b/include/ui/console.h > > @@ -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; > > > > diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c > > index 9fcc01b6f46..b3e83046643 100644 > > --- a/hw/display/virtio-gpu-virgl.c > > +++ b/hw/display/virtio-gpu-virgl.c > > @@ -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 > > > > diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c > > index 43e88a4daff..38010c0fcc2 100644 > > --- a/hw/display/virtio-gpu.c > > +++ b/hw/display/virtio-gpu.c > > @@ -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"); > > 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 > > Regards, > Akihiko Odaki
