From nobody Sun Dec 7 00:31:00 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@getutm.app; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=getutm.app ARC-Seal: i=1; a=rsa-sha256; t=1764734992; cv=none; d=zohomail.com; s=zohoarc; b=iwRmXzyGM/jyDNVOttWKD4YcXRDmuXul95vSd4JuLVtOePV5hzEJLMVoS+3tD1q+lLAVIQUE6jtpx8bKgZr75Fx6tAVe5c2Dv7LD0L2CDhS4YaptLBHDYU5QU6S1z9MQD6n5yFPWwxMEqcPl/1pca9GKrbaaiO8AIX7x/IreLIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764734992; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=suFTTcyRrb4wIFWQkIjPO8ClOthN7ZNFt0MXu8KCaK4=; b=ltAUdtYlhybi3m2MOB3dDMkVE9NknEixcOV4tgOTl4rbBF1uBlzeM0v+zG5gRKD+CQOyDWdSxKzJiAj06Mr3PbWIG+9KkPX+vdBETDRcQMoAmF0rzTWgYZp2/NTGgMQfX5Q2IQs5R6VnlskU8CRgqFdE2iXtZ11/C4+4Ss+z/x4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@getutm.app; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764734992152520.9755834193858; Tue, 2 Dec 2025 20:09:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vQeAX-0002LW-CX; Tue, 02 Dec 2025 23:08:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vQeAV-0002LH-F1 for qemu-devel@nongnu.org; Tue, 02 Dec 2025 23:08:43 -0500 Received: from a4i956.smtp2go.com ([158.120.83.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vQeAT-0000Z2-T2 for qemu-devel@nongnu.org; Tue, 02 Dec 2025 23:08:43 -0500 Received: from [10.159.238.187] (helo=localhost.localdomain) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA512__CHACHA20_POLY1305:256) (Exim 4.98.1-S2G) (envelope-from ) id 1vQeA8-FnQW0hPv7oK-TUF2; Wed, 03 Dec 2025 04:08:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=getutm.app; i=@getutm.app; q=dns/txt; s=s483429; t=1764734918; h=from : subject : to : message-id : date; bh=suFTTcyRrb4wIFWQkIjPO8ClOthN7ZNFt0MXu8KCaK4=; b=dwkyVuQBH0Agd+f28KPBg4VGFrtQWdgXdzFwOoUXSU3pekvUXny1BmOsfEZTRHzfUA2FF vXFNeHs/MkzymALWvNw5OcFBPhgck74LbscC1jOkCuKxNWSLZqsicJ7PNyd94UW60HYu+3a ISzmWKIZBWDKtVx3E4oSuvx7UwQAzhMtuqv2ofNtQ4mCLvWDLcEVeCgXNi4d3pxV/P0l7gm FleHkiLJ2NGtzohDV4uCUN6D3QcP93/IVtjhr9aA5g9bC3Ne/v2awN3T0b3/knItuncUDih kEaRB+ZVKMfdE8s4izPA9Dbg/e1Fp6NmH8LT0L/IWhnBgFSRyvmucr5S2L5A== From: Joelle van Dyne To: qemu-devel@nongnu.org Cc: Joelle van Dyne , "Michael S. Tsirkin" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH RFC 7/7] virtio-gpu-virgl: add support for native blob scanout Date: Tue, 2 Dec 2025 20:07:54 -0800 Message-ID: <20251203040754.94487-8-j@getutm.app> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20251203040754.94487-1-j@getutm.app> References: <20251203040754.94487-1-j@getutm.app> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please forward a copy of this message, including all headers, to Feedback-ID: 483429m:483429abrvJvs:483429sk55hBs0o3 X-smtpcorp-track: dizaJlnuAy8G.7LaSsQcmtKZV.-aehGwppW8Y Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=158.120.83.188; envelope-from=bounce.0wkqiohjvv6lnp5=o30qfjovfq01=g4o3xh0oiya3c7@em483429.getutm.app; helo=a4i956.smtp2go.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @getutm.app) X-ZM-MESSAGEID: 1764734993553019200 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Joelle van Dyne --- meson.build | 5 +++ hw/display/virtio-gpu-virgl.c | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/meson.build b/meson.build index 05bad66376..8917aff044 100644 --- a/meson.build +++ b/meson.build @@ -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_A= PIS', + prefix: '#include ', + dependencies: virgl)) config_host_data.set('VIRGL_VERSION_MAJOR', virgl.version().split('.')[0= ]) endif config_host_data.set('CONFIG_VIRTFS', have_virtfs) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index b7bc095676..3ef37645ca 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -22,6 +22,7 @@ =20 #include "ui/egl-helpers.h" =20 +#define VIRGL_RENDERER_UNSTABLE_APIS #include =20 #define SUPPORTED_VIRGL_INFO_EXT_VERSION (1) @@ -848,6 +849,59 @@ static void virgl_cmd_resource_unmap_blob(VirtIOGPU *g, } } =20 +#if defined(HAVE_VIRGL_RENDERER_NATIVE_SCANOUT) +static void virgl_scanout_native_blob_cleanup(ScanoutTextureNative *native) +{ + assert(native->type =3D=3D SCANOUT_TEXTURE_NATIVE_TYPE_METAL); + virgl_renderer_release_handle_for_scanout(VIRGL_NATIVE_HANDLE_METAL_TE= XTURE, + native->u.metal_texture); +} + +static bool virgl_scanout_native_blob(VirtIOGPU *g, + struct virtio_gpu_set_scanout_blob *= ss) +{ + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[ss->scan= out_id]; + enum virgl_renderer_native_handle_type type; + virgl_renderer_native_handle handle; + ScanoutTextureNative native; + + type =3D virgl_renderer_create_handle_for_scanout(ss->resource_id, + ss->width, + ss->height, + ss->format, + ss->padding, + ss->strides[0], + ss->offsets[0], + &handle); +#ifdef CONFIG_METAL + if (type =3D=3D VIRGL_NATIVE_HANDLE_METAL_TEXTURE) { + native =3D (ScanoutTextureNative){ + .type =3D SCANOUT_TEXTURE_NATIVE_TYPE_METAL, + .u.metal_texture =3D handle, + }; + qemu_console_resize(scanout->con, + ss->r.width, ss->r.height); + dpy_gl_scanout_texture( + scanout->con, 0, + false, + ss->width, ss->height, + ss->r.x, ss->r.y, ss->r.width, ss->r.height, + native, virgl_scanout_native_blob_cleanup); + scanout->resource_id =3D ss->resource_id; + + return true; + } +#endif + + /* don't leak memory if handle type is unknown */ + if (type !=3D VIRGL_NATIVE_HANDLE_NONE) { + virgl_renderer_release_handle_for_scanout(type, handle); + } + + return false; +} +#endif + static void virgl_cmd_set_scanout_blob(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { @@ -886,6 +940,12 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g, return; } =20 +#if defined(HAVE_VIRGL_RENDERER_NATIVE_SCANOUT) + if (virgl_scanout_native_blob(g, &ss)) { + return; + } +#endif + res =3D virtio_gpu_virgl_find_resource(g, ss.resource_id); if (!res) { qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n", --=20 2.41.0