* [PATCH v2 0/1] Implementation of resource_query_layout
@ 2023-12-21 10:23 Julia Zhang
2023-12-21 10:23 ` [PATCH v2 1/1] virgl: Implement resource_query_layout Julia Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Julia Zhang @ 2023-12-21 10:23 UTC (permalink / raw)
To: Gerd Hoffmann, Michael S . Tsirkin, Stefano Stabellini,
Anthony PERARD, Antonio Caggiano, Dr . David Alan Gilbert,
Robert Beckett, qemu-devel
Cc: xen-devel, Alex Deucher, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian
Hi all,
Sorry to late reply. This is v2 of the implementation of
resource_query_layout. This adds a new ioctl to let guest query information
of host resource, which is originally from Daniel Stone. We add some
changes to support query the correct stride of host resource before it's
created, which is to support dGPU prime feature. Without correct stride,
dGPU can not blit data to virtio iGPU correctly.
Changes from v1 to v2:
-Squash two patches to a single patch.
-A small modification of VIRTIO_GPU_F_RESOURCE_QUERY_LAYOUT
Below is description of v1:
This add implementation of resource_query_layout to get the information of
how the host has actually allocated the buffer. This function is now used
to query the stride for guest linear resource for dGPU prime on guest VMs.
v1 of qemu side:
https:
//lore.kernel.org/qemu-devel/20231110074027.24862-1-julia.zhang@amd.com/T/#t
v1 of kernel side:
https:
//lore.kernel.org/xen-devel/20231110074027.24862-1-julia.zhang@amd.com/T/#t
Daniel Stone (1):
virgl: Implement resource_query_layout
hw/display/virtio-gpu-base.c | 4 +++
hw/display/virtio-gpu-virgl.c | 40 +++++++++++++++++++++
include/hw/virtio/virtio-gpu-bswap.h | 7 ++++
include/standard-headers/linux/virtio_gpu.h | 30 ++++++++++++++++
meson.build | 4 +++
5 files changed, 85 insertions(+)
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/1] virgl: Implement resource_query_layout
2023-12-21 10:23 [PATCH v2 0/1] Implementation of resource_query_layout Julia Zhang
@ 2023-12-21 10:23 ` Julia Zhang
2024-01-02 13:39 ` Marc-André Lureau
0 siblings, 1 reply; 3+ messages in thread
From: Julia Zhang @ 2023-12-21 10:23 UTC (permalink / raw)
To: Gerd Hoffmann, Michael S . Tsirkin, Stefano Stabellini,
Anthony PERARD, Antonio Caggiano, Dr . David Alan Gilbert,
Robert Beckett, qemu-devel
Cc: xen-devel, Alex Deucher, Christian König, Xenia Ragiadakou,
Honglei Huang, Julia Zhang, Chen Jiqian, Daniel Stone
From: Daniel Stone <daniels@collabora.com>
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.
Signed-off-by: Daniel Stone <daniels@collabora.com>
Co-developed-by: Julia Zhang <julia.zhang@amd.com>
Signed-off-by: Julia Zhang <julia.zhang@amd.com>
---
hw/display/virtio-gpu-base.c | 4 +++
hw/display/virtio-gpu-virgl.c | 40 +++++++++++++++++++++
include/hw/virtio/virtio-gpu-bswap.h | 7 ++++
include/standard-headers/linux/virtio_gpu.h | 30 ++++++++++++++++
meson.build | 4 +++
5 files changed, 85 insertions(+)
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index 6bcee3882f..09b37f015d 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -240,6 +240,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
}
+#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 c1e7c6d0c6..b331232fee 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -813,6 +813,40 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g,
#endif /* HAVE_VIRGL_RESOURCE_BLOB */
+#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
+static void virgl_cmd_resource_query_layout(VirtIOGPU *g,
+ struct virtio_gpu_ctrl_command *cmd)
+{
+ 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);
+
+ ret = virgl_renderer_resource_query_layout(qlayout.resource_id, &rlayout,
+ qlayout.width, qlayout.height,
+ qlayout.format, qlayout.bind);
+ 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;
+ }
+ 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)
{
@@ -896,6 +930,12 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
virgl_cmd_set_scanout_blob(g, cmd);
break;
#endif /* HAVE_VIRGL_RESOURCE_BLOB */
+
+#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
+ case VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT:
+ virgl_cmd_resource_query_layout(g, cmd);
+ break;
+#endif /* HAVE_VIRGL_RESOURCE_QUERY_LAYOUT*/
default:
cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
break;
diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
index dd1975e2d4..dea8cf6fd3 100644
--- a/include/hw/virtio/virtio-gpu-bswap.h
+++ b/include/hw/virtio/virtio-gpu-bswap.h
@@ -92,4 +92,11 @@ virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
le32_to_cpus(&ssb->offsets[3]);
}
+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 c621389f3d..c9a2f58237 100644
--- a/include/standard-headers/linux/virtio_gpu.h
+++ b/include/standard-headers/linux/virtio_gpu.h
@@ -65,6 +65,11 @@
*/
#define VIRTIO_GPU_F_CONTEXT_INIT 4
+/*
+ * VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT
+ */
+#define VIRTIO_GPU_F_RESOURCE_QUERY_LAYOUT 5
+
enum virtio_gpu_ctrl_type {
VIRTIO_GPU_UNDEFINED = 0,
@@ -95,6 +100,7 @@ enum virtio_gpu_ctrl_type {
VIRTIO_GPU_CMD_SUBMIT_3D,
VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB,
VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB,
+ VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT,
/* cursor commands */
VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
@@ -108,6 +114,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,
@@ -455,4 +462,27 @@ struct virtio_gpu_resource_unmap_blob {
uint32_t padding;
};
+
+/* VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT */
+struct virtio_gpu_resource_query_layout {
+ struct virtio_gpu_ctrl_hdr hdr;
+ uint32_t resource_id;
+ uint32_t width;
+ uint32_t height;
+ uint32_t format;
+ uint32_t bind;
+};
+
+/* 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;
+ struct virtio_gpu_resource_plane {
+ uint64_t offset;
+ uint32_t stride;
+ } planes[VIRTIO_GPU_RES_MAX_PLANES];
+};
+
#endif
diff --git a/meson.build b/meson.build
index a739a62f2c..72024f5f01 100644
--- a/meson.build
+++ b/meson.build
@@ -1058,6 +1058,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
cc.has_function('virgl_renderer_resource_create_blob',
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
endif
rutabaga = not_found
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/1] virgl: Implement resource_query_layout
2023-12-21 10:23 ` [PATCH v2 1/1] virgl: Implement resource_query_layout Julia Zhang
@ 2024-01-02 13:39 ` Marc-André Lureau
0 siblings, 0 replies; 3+ messages in thread
From: Marc-André Lureau @ 2024-01-02 13:39 UTC (permalink / raw)
To: Julia Zhang
Cc: Gerd Hoffmann, Michael S . Tsirkin, Stefano Stabellini,
Anthony PERARD, Antonio Caggiano, Dr . David Alan Gilbert,
Robert Beckett, qemu-devel, xen-devel, Alex Deucher,
Christian König, Xenia Ragiadakou, Honglei Huang,
Chen Jiqian, Daniel Stone
Hi
On Thu, Dec 21, 2023 at 3:36 PM Julia Zhang <julia.zhang@amd.com> wrote:
>
> From: Daniel Stone <daniels@collabora.com>
>
> 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.
>
The command hasn't been added to the kernel yet. The function is not
in the virgl library either.
> Signed-off-by: Daniel Stone <daniels@collabora.com>
> Co-developed-by: Julia Zhang <julia.zhang@amd.com>
> Signed-off-by: Julia Zhang <julia.zhang@amd.com>
> ---
> hw/display/virtio-gpu-base.c | 4 +++
> hw/display/virtio-gpu-virgl.c | 40 +++++++++++++++++++++
> include/hw/virtio/virtio-gpu-bswap.h | 7 ++++
> include/standard-headers/linux/virtio_gpu.h | 30 ++++++++++++++++
> meson.build | 4 +++
> 5 files changed, 85 insertions(+)
>
> diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
> index 6bcee3882f..09b37f015d 100644
> --- a/hw/display/virtio-gpu-base.c
> +++ b/hw/display/virtio-gpu-base.c
> @@ -240,6 +240,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
> features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
> }
>
> +#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 c1e7c6d0c6..b331232fee 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -813,6 +813,40 @@ static void virgl_cmd_set_scanout_blob(VirtIOGPU *g,
>
> #endif /* HAVE_VIRGL_RESOURCE_BLOB */
>
> +#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
> +static void virgl_cmd_resource_query_layout(VirtIOGPU *g,
> + struct virtio_gpu_ctrl_command *cmd)
> +{
> + 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);
> +
> + ret = virgl_renderer_resource_query_layout(qlayout.resource_id, &rlayout,
> + qlayout.width, qlayout.height,
> + qlayout.format, qlayout.bind);
> + 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;
> + }
> + 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)
> {
> @@ -896,6 +930,12 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
> virgl_cmd_set_scanout_blob(g, cmd);
> break;
> #endif /* HAVE_VIRGL_RESOURCE_BLOB */
> +
> +#ifdef HAVE_VIRGL_RESOURCE_QUERY_LAYOUT
> + case VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT:
> + virgl_cmd_resource_query_layout(g, cmd);
> + break;
> +#endif /* HAVE_VIRGL_RESOURCE_QUERY_LAYOUT*/
> default:
> cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
> break;
> diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virtio-gpu-bswap.h
> index dd1975e2d4..dea8cf6fd3 100644
> --- a/include/hw/virtio/virtio-gpu-bswap.h
> +++ b/include/hw/virtio/virtio-gpu-bswap.h
> @@ -92,4 +92,11 @@ virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
> le32_to_cpus(&ssb->offsets[3]);
> }
>
> +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 c621389f3d..c9a2f58237 100644
> --- a/include/standard-headers/linux/virtio_gpu.h
> +++ b/include/standard-headers/linux/virtio_gpu.h
> @@ -65,6 +65,11 @@
> */
> #define VIRTIO_GPU_F_CONTEXT_INIT 4
>
> +/*
> + * VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT
> + */
> +#define VIRTIO_GPU_F_RESOURCE_QUERY_LAYOUT 5
> +
> enum virtio_gpu_ctrl_type {
> VIRTIO_GPU_UNDEFINED = 0,
>
> @@ -95,6 +100,7 @@ enum virtio_gpu_ctrl_type {
> VIRTIO_GPU_CMD_SUBMIT_3D,
> VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB,
> VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB,
> + VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT,
>
> /* cursor commands */
> VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
> @@ -108,6 +114,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,
> @@ -455,4 +462,27 @@ struct virtio_gpu_resource_unmap_blob {
> uint32_t padding;
> };
>
> +
> +/* VIRTIO_GPU_CMD_RESOURCE_QUERY_LAYOUT */
> +struct virtio_gpu_resource_query_layout {
> + struct virtio_gpu_ctrl_hdr hdr;
> + uint32_t resource_id;
> + uint32_t width;
> + uint32_t height;
> + uint32_t format;
> + uint32_t bind;
> +};
> +
> +/* 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;
> + struct virtio_gpu_resource_plane {
> + uint64_t offset;
> + uint32_t stride;
> + } planes[VIRTIO_GPU_RES_MAX_PLANES];
> +};
> +
> #endif
> diff --git a/meson.build b/meson.build
> index a739a62f2c..72024f5f01 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1058,6 +1058,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
> cc.has_function('virgl_renderer_resource_create_blob',
> 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
> endif
> rutabaga = not_found
> --
> 2.34.1
>
>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-02 13:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 10:23 [PATCH v2 0/1] Implementation of resource_query_layout Julia Zhang
2023-12-21 10:23 ` [PATCH v2 1/1] virgl: Implement resource_query_layout Julia Zhang
2024-01-02 13:39 ` Marc-André Lureau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).