vhost-user-gpu: support dmabuf modifiers
cover vhost-user-gpu: support dmabuf modifiers
virglrenderer recently added virgl_renderer_resource_get_info_ext as a new api, which gets resource information, including dmabuf modifiers.
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1024
We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers to improve performance, and importing buffers without modifiers information may result in completely broken rendering.
Currently trying to use vhost-user-gpu for rendering backend and using the qemu dbus ui as a ui backend results in a broken framebuffer with Intel GPUs as the buffer is allocated with a modifier. With this patchset, that is fixed.
It is tricky to support since it requires to keep compatibility at the same time with:
(1) build against older virglrenderer which do not provide virgl_renderer_resource_get_info_ext;
(2) runtime between frontend (qemu) and backend (vhost-user-gpu) due to increased size and a new field in the VHOST_USER_GPU_DMABUF_SCANOUT message.
I tried to reach a compromise here by not defining a completely new message and duplicate VHOST_USER_GPU_DMABUF_SCANOUT but it still feels like a bit of a hack, so I appreciate feedback if there is a better way (or naming) to handle it.
Erico Nunes (3):
docs: vhost-user-gpu: add protocol changes for dmabuf modifiers contrib/vhost-user-gpu: add support for sending dmabuf modifiers
vhost-user-gpu: support dmabuf modifiers
contrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-gpu/virgl.c | 51 +++++++++++++++++++++++-- contrib/vhost-user-gpu/vugpu.h | 9 +++++ docs/interop/vhost-user-gpu.rst | 26 ++++++++++++- hw/display/vhost-user-gpu.c | 17 ++++++++- 5 files changed, 102 insertions(+), 6 deletions(-)
Signature · 1 line
2.40.1
PATCH 1/3 docs: vhost-user-gpu: add protocol changes for dmabuf modifiers
VHOST_USER_GPU_DMABUF_SCANOUT2 is defined as a message with all the contents of VHOST_USER_GPU_DMABUF_SCANOUT plus the dmabuf modifiers which were ommitted.
The VHOST_USER_GPU_PROTOCOL_F_DMABUF2 protocol feature is defined as a way to check whether this new message is supported or not.
--- docs/interop/vhost-user-gpu.rst | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
docs/interop/vhost-user-gpu.rst +25 -1
@@ -134,6 +134,19 @@ VhostUserGpuEdidRequest :scanout-id: ``u32``, the scanout to get edid from +VhostUserGpuDMABUFScanout2 +^^^^^^^^^^^^^^^^^^^^^^^^^^ + ++----------------+----------+ +| dmabuf_scanout | modifier | ++----------------+----------+ + +:dmabuf_scanout: ``VhostUserGpuDMABUFScanout``, filled as described in the + VhostUserGpuDMABUFScanout structure. + +:modifier: ``u64``, the DMABUF modifiers + + C structure -----------
@@ -163,7 +176,8 @@ Protocol features .. code:: c - #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 + #define VHOST_USER_GPU_PROTOCOL_F_EDID 0 + #define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1 New messages and communication changes are negotiated thanks to the ``VHOST_USER_GPU_GET_PROTOCOL_FEATURES`` and
@@ -263,3 +277,13 @@ Message types Retrieve the EDID data for a given scanout. This message requires the ``VHOST_USER_GPU_PROTOCOL_F_EDID`` protocol feature to be supported. + +``VHOST_USER_GPU_DMABUF_SCANOUT2`` + :id: 12 + :request payload: ``VhostUserGpuDMABUFScanout2`` + :reply payload: N/A + + Same as VHOST_USER_GPU_DMABUF_SCANOUT, but also sends the dmabuf modifiers + appended to the message, which were not provided in the other message. + This message requires the ``VHOST_USER_GPU_PROTOCOL_F_DMABUF2`` protocol + feature to be supported.
Signature · 1 line
2.40.1
PATCH 2/3 contrib/vhost-user-gpu: add support for sending dmabuf modifiers
In reply to Erico Nunesvirglrenderer recently added virgl_renderer_resource_get_info_ext as a new api, which gets resource information, including dmabuf modifiers.
We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers for efficiency, and importing buffers without modifiers information may result in completely broken rendering.
--- contrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-gpu/virgl.c | 51 +++++++++++++++++++++++-- contrib/vhost-user-gpu/vugpu.h | 9 +++++ 3 files changed, 61 insertions(+), 4 deletions(-)
contrib/vhost-user-gpu/vhost-user-gpu.c +4 -1
@@ -1071,6 +1071,7 @@ static gboolean protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data) { const uint64_t protocol_edid = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID); +const uint64_t protocol_dmabuf2 = (1 <<VHOST_USER_GPU_PROTOCOL_F_DMABUF2 );VuGpu *g = user_data;uint64_t protocol_features; VhostUserGpuMsg msg = {
@@ -1082,7 +1083,7 @@ protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data)return G_SOURCE_CONTINUE ; } - protocol_features &= protocol_edid; + protocol_features &= (protocol_edid | protocol_dmabuf2); msg = (VhostUserGpuMsg ) { .request =VHOST_USER_GPU_SET_PROTOCOL_FEATURES ,
@@ -1100,6 +1101,8 @@ protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data)exit (EXIT_FAILURE ); } + g->use_modifiers = !!(protocol_features & protocol_dmabuf2); +return G_SOURCE_REMOVE ; }
contrib/vhost-user-gpu/virgl.c +48 -3
75 lines not on this page · raw message
contrib/vhost-user-gpu/vugpu.h +9 -0
@@ -37,6 +37,7 @@ typedef enum VhostUserGpuRequest {VHOST_USER_GPU_DMABUF_SCANOUT ,VHOST_USER_GPU_DMABUF_UPDATE ,VHOST_USER_GPU_GET_EDID , +VHOST_USER_GPU_DMABUF_SCANOUT2 , } VhostUserGpuRequest; typedef struct VhostUserGpuDisplayInfoReply {
@@ -84,6 +85,11 @@ typedef struct VhostUserGpuDMABUFScanout {int fd_drm_fourcc; }QEMU_PACKED VhostUserGpuDMABUFScanout; +typedef struct VhostUserGpuDMABUFScanout2 { +struct VhostUserGpuDMABUFScanout dmabuf_scanout; +uint64_t modifier; +} QEMU_PACKED VhostUserGpuDMABUFScanout2; +typedef struct VhostUserGpuEdidRequest {uint32_t scanout_id; } QEMU_PACKED VhostUserGpuEdidRequest;
@@ -98,6 +104,7 @@ typedef struct VhostUserGpuMsg {VhostUserGpuScanout scanout;VhostUserGpuUpdate update;VhostUserGpuDMABUFScanout dmabuf_scanout; +VhostUserGpuDMABUFScanout2 dmabuf_scanout2;VhostUserGpuEdidRequest edid_req;struct virtio_gpu_resp_edid resp_edid;struct virtio_gpu_resp_display_info display_info;
@@ -112,6 +119,7 @@ static VhostUserGpuMsg m __attribute__ ((unused));#define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4#define VHOST_USER_GPU_PROTOCOL_F_EDID 0 +#define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1struct virtio_gpu_scanout {uint32_t width, height;
@@ -132,6 +140,7 @@ typedef struct VuGpu {bool virgl;bool virgl_inited;bool edid_inited; +bool use_modifiers;uint32_t inflight;struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS ];
Signature · 1 line
2.40.1
PATCH 3/3 vhost-user-gpu: support dmabuf modifiers
In reply to Erico NunesWhen the backend sends VHOST_USER_GPU_DMABUF_SCANOUT2, handle it by getting the modifiers information which is now available.
--- hw/display/vhost-user-gpu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/display/vhost-user-gpu.c +16 -1
@@ -32,6 +32,7 @@ typedef enum VhostUserGpuRequest {VHOST_USER_GPU_DMABUF_SCANOUT ,VHOST_USER_GPU_DMABUF_UPDATE ,VHOST_USER_GPU_GET_EDID , +VHOST_USER_GPU_DMABUF_SCANOUT2 , } VhostUserGpuRequest; typedef struct VhostUserGpuDisplayInfoReply {
@@ -79,6 +80,11 @@ typedef struct VhostUserGpuDMABUFScanout {int fd_drm_fourcc; }QEMU_PACKED VhostUserGpuDMABUFScanout; +typedef struct VhostUserGpuDMABUFScanout2 { +struct VhostUserGpuDMABUFScanout dmabuf_scanout; +uint64_t modifier; +} QEMU_PACKED VhostUserGpuDMABUFScanout2; +typedef struct VhostUserGpuEdidRequest {uint32_t scanout_id; } QEMU_PACKED VhostUserGpuEdidRequest;
@@ -93,6 +99,7 @@ typedef struct VhostUserGpuMsg {VhostUserGpuScanout scanout;VhostUserGpuUpdate update;VhostUserGpuDMABUFScanout dmabuf_scanout; +VhostUserGpuDMABUFScanout2 dmabuf_scanout2;VhostUserGpuEdidRequest edid_req;struct virtio_gpu_resp_edid resp_edid;struct virtio_gpu_resp_display_info display_info;
@@ -107,6 +114,7 @@ static VhostUserGpuMsg m __attribute__ ((unused));#define VHOST_USER_GPU_MSG_FLAG_REPLY 0x4#define VHOST_USER_GPU_PROTOCOL_F_EDID 0 +#define VHOST_USER_GPU_PROTOCOL_F_DMABUF2 1static void vhost_user_gpu_update_blocked (VhostUserGPU *g,bool blocked);
@@ -171,7 +179,8 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) .flags = VHOST_USER_GPU_MSG_FLAG_REPLY, .size = sizeof(uint64_t), .payload = { - .u64 = (1 << VHOST_USER_GPU_PROTOCOL_F_EDID) + .u64 = (1 <<VHOST_USER_GPU_PROTOCOL_F_EDID ) | + (1 <<VHOST_USER_GPU_PROTOCOL_F_DMABUF2 ) } };
@@ -236,6 +245,7 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg)break ; } +case VHOST_USER_GPU_DMABUF_SCANOUT2 :case VHOST_USER_GPU_DMABUF_SCANOUT : {VhostUserGpuDMABUFScanout *m = &msg->payload.dmabuf_scanout;int fd =qemu_chr_fe_get_msgfd (&g->vhost_chr);
@@ -269,6 +279,11 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUserGpuMsg *msg) .fourcc = m->fd_drm_fourcc, .y0_top = m->fd_flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, }; +if (msg->request ==VHOST_USER_GPU_DMABUF_SCANOUT2 ) { +VhostUserGpuDMABUFScanout2 *m2 = &msg->payload.dmabuf_scanout2; + dmabuf->modifier = m2->modifier; + } +dpy_gl_scanout_dmabuf (con, dmabuf);break ; }
Signature · 1 line
2.40.1
Hi
Quoted 23 lines · Erico Nunes
virglrenderer recently added
virgl_renderer_resource_get_info_extas a new api, which gets resource information, including dmabuf modifiers.
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1024We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers to improve performance, and importing buffers without modifiers information may result in completely broken rendering.
Currently trying to use vhost-user-gpu for rendering backend and using the qemu dbus ui as a ui backend results in a broken framebuffer with Intel GPUs as the buffer is allocated with a modifier. With this patchset, that is fixed.
It is tricky to support since it requires to keep compatibility at the same time with:
(1) build against older virglrenderer which do not providevirgl_renderer_resource_get_info_ext;
(2) runtime between frontend (qemu) and backend (vhost-user-gpu) due to increased size and a new field in theVHOST_USER_GPU_DMABUF_SCANOUTmessage.
Quoted 5 lines
I tried to reach a compromise here by not defining a completely new message and duplicate
VHOST_USER_GPU_DMABUF_SCANOUTbut it still feels like a bit of a hack, so I appreciate feedback if there is a better way (or naming) to handle it.
looks fine to me, we may consider this as a fix for 8.1 imho
Quoted 19 lines
Erico Nunes (3):
docs: vhost-user-gpu: add protocol changes for dmabuf modifiers contrib/vhost-user-gpu: add support for sending dmabuf modifiers
vhost-user-gpu: support dmabuf modifierscontrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-gpu/virgl.c | 51 +++++++++++++++++++++++-- contrib/vhost-user-gpu/vugpu.h | 9 +++++ docs/interop/vhost-user-gpu.rst | 26 ++++++++++++- hw/display/vhost-user-gpu.c | 17 ++++++++- 5 files changed, 102 insertions(+), 6 deletions(-)--
2.40.1
Signature · 1 line
Marc-André Lureau
Hello,
Quoted 34 lines · Marc-André Lureau
Hi
On Fri, Jul 14, 2023 at 7:42 PM Erico Nunes <[email protected] <mailto:[email protected]>> wrote:
virglrenderer recently added
virgl_renderer_resource_get_info_extas a
new api, which gets resource information, including dmabuf modifiers.
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1024 <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1024>We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers to improve performance, and importing buffers without modifiers information may result in completely broken rendering.
Currently trying to use vhost-user-gpu for rendering backend and using the qemu dbus ui as a ui backend results in a broken framebuffer with Intel GPUs as the buffer is allocated with a modifier. With this patchset, that is fixed.
It is tricky to support since it requires to keep compatibility at the same time with:
(1) build against older virglrenderer which do not providevirgl_renderer_resource_get_info_ext;
(2) runtime between frontend (qemu) and backend (vhost-user-gpu) due to increased size and a new field in theVHOST_USER_GPU_DMABUF_SCANOUTmessage.I tried to reach a compromise here by not defining a completely new message and duplicate
VHOST_USER_GPU_DMABUF_SCANOUTbut it still feels like a bit of a hack, so I appreciate feedback if there is a better way (or naming) to handle it.
Quoted 3 lines
looks fine to me, we may consider this as a fix for 8.1 imho
Reviewed-by Marc-André Lureau <[email protected]<mailto:[email protected]>>
Just making sure this one didn't fall through the cracks; should I do something about this series or is it set to be in an upcoming merge?
Thanks
Erico
Quoted 34 lines · Erico Nunes
virglrenderer recently added
virgl_renderer_resource_get_info_extas a new api, which gets resource information, including dmabuf modifiers.
https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1024We have to support dmabuf modifiers since the driver may choose to allocate buffers with these modifiers to improve performance, and importing buffers without modifiers information may result in completely broken rendering.
Currently trying to use vhost-user-gpu for rendering backend and using the qemu dbus ui as a ui backend results in a broken framebuffer with Intel GPUs as the buffer is allocated with a modifier. With this patchset, that is fixed.
It is tricky to support since it requires to keep compatibility at the same time with:
(1) build against older virglrenderer which do not providevirgl_renderer_resource_get_info_ext;
(2) runtime between frontend (qemu) and backend (vhost-user-gpu) due to increased size and a new field in theVHOST_USER_GPU_DMABUF_SCANOUTmessage.I tried to reach a compromise here by not defining a completely new message and duplicate
VHOST_USER_GPU_DMABUF_SCANOUTbut it still feels like a bit of a hack, so I appreciate feedback if there is a better way (or naming) to handle it.Erico Nunes (3):
docs: vhost-user-gpu: add protocol changes for dmabuf modifiers contrib/vhost-user-gpu: add support for sending dmabuf modifiers
vhost-user-gpu: support dmabuf modifiers
Quoted 6 lines
contrib/vhost-user-gpu/vhost-user-gpu.c | 5 ++- contrib/vhost-user-gpu/virgl.c | 51 +++++++++++++++++++++++-- contrib/vhost-user-gpu/vugpu.h | 9 +++++ docs/interop/vhost-user-gpu.rst | 26 ++++++++++++- hw/display/vhost-user-gpu.c | 17 ++++++++- 5 files changed, 102 insertions(+), 6 deletions(-)
Series: