From 59449ad4d16d36c44f4e4088ec62382fb919e716 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 11 Nov 2021 08:33:06 -0800 Subject: [PATCH] virgl: add VIRGL_RENDERER_BLOB_FD_TYPE_SHM This allows a blob resource to be backed by a mmap()-able fd. Internally, it is a memfd or a shm. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang Reviewed-by: Ryan Neph --- src/virgl_resource.h | 2 ++ src/virglrenderer.c | 4 ++++ src/virglrenderer.h | 1 + vtest/vtest_renderer.c | 5 +++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/virgl_resource.h b/src/virgl_resource.h index 7377994..3ccbd2e 100644 --- a/src/virgl_resource.h +++ b/src/virgl_resource.h @@ -33,6 +33,8 @@ struct pipe_resource; enum virgl_resource_fd_type { VIRGL_RESOURCE_FD_DMABUF, VIRGL_RESOURCE_FD_OPAQUE, + /* mmap()-able, usually memfd or shm */ + VIRGL_RESOURCE_FD_SHM, VIRGL_RESOURCE_FD_INVALID = -1, }; diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 9e9cc07..46513fe 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -925,6 +925,7 @@ int virgl_renderer_resource_map(uint32_t res_handle, void **out_map, uint64_t *o } else { switch (res->fd_type) { case VIRGL_RESOURCE_FD_DMABUF: + case VIRGL_RESOURCE_FD_SHM: map = mmap(NULL, res->map_size, PROT_WRITE | PROT_READ, MAP_SHARED, res->fd, 0); break; case VIRGL_RESOURCE_FD_OPAQUE: @@ -991,6 +992,9 @@ virgl_renderer_resource_export_blob(uint32_t res_id, uint32_t *fd_type, int *fd) case VIRGL_RESOURCE_FD_OPAQUE: *fd_type = VIRGL_RENDERER_BLOB_FD_TYPE_OPAQUE; break; + case VIRGL_RESOURCE_FD_SHM: + *fd_type = VIRGL_RENDERER_BLOB_FD_TYPE_SHM; + break; default: return EINVAL; } diff --git a/src/virglrenderer.h b/src/virglrenderer.h index a1c06ff..1a4318d 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -323,6 +323,7 @@ VIRGL_EXPORT int virgl_renderer_resource_get_map_info(uint32_t res_handle, uint3 #define VIRGL_RENDERER_BLOB_FD_TYPE_DMABUF 0x0001 #define VIRGL_RENDERER_BLOB_FD_TYPE_OPAQUE 0x0002 +#define VIRGL_RENDERER_BLOB_FD_TYPE_SHM 0x0003 VIRGL_EXPORT int virgl_renderer_resource_export_blob(uint32_t res_id, uint32_t *fd_type, int *fd); diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c index 9d27ec5..29d3851 100644 --- a/vtest/vtest_renderer.c +++ b/vtest/vtest_renderer.c @@ -1192,7 +1192,7 @@ int vtest_resource_create_blob(UNUSED uint32_t length_dw) return report_failed_call("virgl_renderer_resource_create_blob", ret); } - /* need dmabuf */ + /* export blob */ if (args.blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D) { uint32_t fd_type; ret = virgl_renderer_resource_export_blob(res->res_id, &fd_type, &fd); @@ -1200,7 +1200,8 @@ int vtest_resource_create_blob(UNUSED uint32_t length_dw) vtest_unref_resource(res); return report_failed_call("virgl_renderer_resource_export_blob", ret); } - if (fd_type != VIRGL_RENDERER_BLOB_FD_TYPE_DMABUF) { + if (fd_type != VIRGL_RENDERER_BLOB_FD_TYPE_DMABUF && + fd_type != VIRGL_RENDERER_BLOB_FD_TYPE_SHM) { close(fd); vtest_unref_resource(res); return report_failed_call("virgl_renderer_resource_export_blob", -EINVAL);