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 <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent 7990977ebf
commit 59449ad4d1
  1. 2
      src/virgl_resource.h
  2. 4
      src/virglrenderer.c
  3. 1
      src/virglrenderer.h
  4. 5
      vtest/vtest_renderer.c

@ -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,
};

@ -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;
}

@ -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);

@ -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);

Loading…
Cancel
Save