[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] virgl: Implement resource_query_layout


  • To: Gerd Hoffmann <kraxel@xxxxxxxxxx>, "Michael S . Tsirkin" <mst@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Antonio Caggiano <antonio.caggiano@xxxxxxxxxxxxx>, "Dr . David Alan Gilbert" <dgilbert@xxxxxxxxxx>, Robert Beckett <bob.beckett@xxxxxxxxxxxxx>, <qemu-devel@xxxxxxxxxx>
  • From: Julia Zhang <julia.zhang@xxxxxxx>
  • Date: Fri, 10 Nov 2023 15:40:26 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XntG1E0uj8N6zad76P/32qeRpwpbBJx1Tke7x6cAJhI=; b=Ww6XzYopI1t/JblGGPpo4S3esBRVSKHUJxAjCOY5LH6t3mfhzHnP0+8Ou0NIQKIOSHpGPDjOM9eXgCeGSr6GOfw87fy4FWp0sNQpK6nADFiSvdXZXf6byZLUO4CJZI1YeaZUBsXxfr4rbUD7cxcgB5/YTJN1dzKHYePxNI9B1nNujcxc4rbdIvYHJ9KRwup3ii77cZfv8fpmi4boVvva/OvlU49vV03tAYkefiLFzxffUCdluYuWQmNSG2sieyZRG/KIb/jDnqd3hmiXfXk1KfcLq4pAh0krmLdPwIpsMKZh+fA65n/ev1XX/rub2/QervbTSDA861dv9MHASAupGQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PvJHzzDsr9rxlQYkyovyhC6hW7jT0JDxtmOSZJkwpqqRUI4o5njlf1F0aOLTgsy1124GBN2P1GyM5CJ/YaSdOjSL/shD/2C4ls6RcjAm8ZT7Oqf46IqYxRxj8V2B13ryYn0KVuQZZ97c8KCtidtDMEQkp6uRvbcu3cp0gqRIBYdfsAsxfMs8i/KufKUZOQv/dmTz7jJl2F6kJPLv02vrWQ+xwbBUI6AwAJssISJFMDu0SHuwhYSuowIw0G0cmq+Y+FsKQeUiZDFm8jMwMJ7YQX6HeoUCh+KRcu8c5T+jqpzQETHV+dt9v6GagaVAPC8s4Teei6wDhQBkCWH/9GSFAA==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Alex Deucher <alexander.deucher@xxxxxxx>, Christian König <christian.koenig@xxxxxxx>, Xenia Ragiadakou <burzalodowa@xxxxxxxxx>, "Honglei Huang" <honglei1.huang@xxxxxxx>, Julia Zhang <julia.zhang@xxxxxxx>, "Chen Jiqian" <Jiqian.Chen@xxxxxxx>, Daniel Stone <daniels@xxxxxxxxxxxxx>
  • Delivery-date: Fri, 10 Nov 2023 07:42:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Daniel Stone <daniels@xxxxxxxxxxxxx>

A new ioctl to shuttle information between host and guest about the
actual buffer allocation, which can be used for interop between GL and
Vulkan when supporting standard window systems.
---
 hw/display/virtio-gpu-base.c                |  4 ++
 hw/display/virtio-gpu-virgl.c               | 49 +++++++++++++++++++++
 include/hw/virtio/virtio-gpu-bswap.h        |  7 +++
 include/standard-headers/linux/virtio_gpu.h | 29 ++++++++++++
 meson.build                                 |  4 ++
 5 files changed, 93 insertions(+)

diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 8d8aa2c88f..efaa681e54 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -246,6 +246,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t 
features,
     features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
     features |= (1 << VIRTIO_GPU_F_CONTEXT_FENCE_WAIT);
 
+#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
+    features |= (1 << VIRTIO_GPU_F_RESOURCE_QUERY_LAYOUT);
+#endif /* HAVE_VIRGL_RESOURCE_QUERY_LAYOUT */
+
     return features;
 }
 
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 2ac9a8b864..9c5a07cef1 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -715,6 +715,55 @@ static void virgl_cmd_resource_unmap_blob(VirtIOGPU *g,
     virtio_gpu_virgl_resource_unmap(g, cmd->cmd_hdr.ctx_id, res);
 }
 
+#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
+static void virgl_cmd_resource_query_layout(VirtIOGPU *g,
+                                           struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_query_layout qlayout;
+    struct virtio_gpu_resp_resource_layout resp;
+    struct virgl_renderer_resource_layout rlayout;
+    int ret;
+    int i;
+    VIRTIO_GPU_FILL_CMD(qlayout);
+    virtio_gpu_resource_query_layout_bswap(&qlayout);
+
+    if (qlayout.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, qlayout.resource_id);
+    if (!res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n",
+                      __func__, qlayout.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    ret = virgl_renderer_resource_query_layout(qlayout.resource_id, &rlayout);
+    if (ret != 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource %d is not 
externally-allocated\n",
+                      __func__, qlayout.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    memset(&resp, 0, sizeof(resp));
+    resp.hdr.type = VIRTIO_GPU_RESP_OK_RESOURCE_LAYOUT;
+    resp.num_planes = rlayout.num_planes;
+    resp.modifier = rlayout.modifier;
+    for (i = 0; i < resp.num_planes; i++) {
+        resp.planes[i].offset = rlayout.planes[i].offset;
+        resp.planes[i].stride = rlayout.planes[i].stride;
+       resp.planes[i].size = rlayout.planes[i].size;
+    }
+    virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
+}
+#endif /* HAVE_VIRGL_RESOURCE_QUERY_LAYOUT */
+
 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
                                       struct virtio_gpu_ctrl_command *cmd)
 {
diff --git a/include/hw/virtio/virtio-gpu-bswap.h 
b/include/hw/virtio/virtio-gpu-bswap.h
index 8bbca1e751..49316758cc 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -99,4 +99,11 @@ virtio_gpu_host_wait_bswap(struct virtio_gpu_cmd_host_wait 
*host_wait)
     le64_to_cpus(&host_wait->fence_id);
 }
 
+static inline void
+virtio_gpu_resource_query_layout_bswap(struct virtio_gpu_resource_query_layout 
*rql)
+{
+    virtio_gpu_ctrl_hdr_bswap(&rql->hdr);
+    le32_to_cpus(&rql->resource_id);
+}
+
 #endif
diff --git a/include/standard-headers/linux/virtio_gpu.h 
b/include/standard-headers/linux/virtio_gpu.h
index a04419757f..734fdb6beb 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -70,6 +70,11 @@
  */
 #define VIRTIO_GPU_F_CONTEXT_FENCE_WAIT  5
 
+/*
+ * VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT
+ */
+#define VIRTIO_GPU_F_RESOURCE_QUERY_LAYOUT 6
+
 enum virtio_gpu_ctrl_type {
        VIRTIO_GPU_UNDEFINED = 0,
 
@@ -102,6 +107,7 @@ enum virtio_gpu_ctrl_type {
        VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB,
        VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB,
        VIRTIO_GPU_CMD_WAIT_FENCE,
+       VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT,
 
        /* cursor commands */
        VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
@@ -115,6 +121,7 @@ enum virtio_gpu_ctrl_type {
        VIRTIO_GPU_RESP_OK_EDID,
        VIRTIO_GPU_RESP_OK_RESOURCE_UUID,
        VIRTIO_GPU_RESP_OK_MAP_INFO,
+       VIRTIO_GPU_RESP_OK_RESOURCE_LAYOUT,
 
        /* error responses */
        VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
@@ -495,4 +502,26 @@ struct virtio_gpu_status_freezing {
        __u32 freezing;
 };
 
+/* VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT */
+struct virtio_gpu_resource_query_layout {
+       struct virtio_gpu_ctrl_hdr hdr;
+       uint32_t resource_id;
+       uint32_t padding;
+};
+
+/* VIRTIO_GPU_RESP_OK_RESOURCE_LAYOUT */
+#define VIRTIO_GPU_RES_MAX_PLANES 4
+struct virtio_gpu_resp_resource_layout {
+       struct virtio_gpu_ctrl_hdr hdr;
+       uint64_t modifier;
+       uint32_t num_planes;
+       uint32_t padding;
+       struct virtio_gpu_resource_plane {
+               uint64_t offset;
+               uint64_t size;
+               uint32_t stride;
+               uint32_t padding;
+       } planes[VIRTIO_GPU_RES_MAX_PLANES];
+};
+
 #endif
diff --git a/meson.build b/meson.build
index 59235aff28..0c20a00daa 100644
--- a/meson.build
+++ b/meson.build
@@ -790,6 +790,10 @@ if not get_option('virglrenderer').auto() or have_system 
or have_vhost_user_gpu
                                      'get_egl_display',
                                      prefix: '#include <virglrenderer.h>',
                                      dependencies: virgl))
+  config_host_data.set('HAVE_VIRGL_RESOURCE_QUERY_LAYOUT',
+                       cc.has_function('virgl_renderer_resource_query_layout',
+                                       prefix: '#include <virglrenderer.h>',
+                                       dependencies: virgl))
 endif
 blkio = not_found
 if not get_option('blkio').auto() or have_block
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.