virgl: add virgl_renderer_resource_import_blob

When a blob resource is created with
VIRGL_RENDERER_BLOB_FLAG_USE_CROSS_DEVICE, it can be exported to foreign
devices.

This provides the opposite direction.  When a foreign device allocates a
cross-device resource, virgl_renderer_resource_import_blob imports the
resource into virglrenderer.

This is similar to virgl_renderer_resource_import_eglimage, but is more
generic and is for blob resources.

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 2c2908b296
commit f0b4e97975
  1. 51
      src/virglrenderer.c
  2. 12
      src/virglrenderer.h

@ -1002,6 +1002,57 @@ virgl_renderer_resource_export_blob(uint32_t res_id, uint32_t *fd_type, int *fd)
return 0;
}
int
virgl_renderer_resource_import_blob(const struct virgl_renderer_resource_import_blob_args *args)
{
TRACE_FUNC();
struct virgl_resource *res;
/* user resource id must be greater than 0 */
if (args->res_handle == 0)
return -EINVAL;
switch (args->blob_mem) {
case VIRGL_RENDERER_BLOB_MEM_HOST3D:
break;
default:
return -EINVAL;
}
enum virgl_resource_fd_type fd_type = VIRGL_RESOURCE_FD_INVALID;
switch (args->fd_type) {
case VIRGL_RENDERER_BLOB_FD_TYPE_DMABUF:
fd_type = VIRGL_RESOURCE_FD_DMABUF;
break;
case VIRGL_RENDERER_BLOB_FD_TYPE_OPAQUE:
fd_type = VIRGL_RESOURCE_FD_OPAQUE;
break;
case VIRGL_RENDERER_BLOB_FD_TYPE_SHM:
fd_type = VIRGL_RESOURCE_FD_SHM;
break;
default:
return -EINVAL;
}
if (args->fd < 0)
return -EINVAL;
if (args->size == 0)
return -EINVAL;
res = virgl_resource_create_from_fd(args->res_handle,
fd_type,
args->fd,
NULL,
0);
if (!res)
return -ENOMEM;
res->map_info = 0;
res->map_size = args->size;
return 0;
}
int
virgl_renderer_export_fence(uint32_t client_fence_id, int *fd)
{

@ -328,6 +328,18 @@ VIRGL_EXPORT int virgl_renderer_resource_get_map_info(uint32_t res_handle, uint3
VIRGL_EXPORT int
virgl_renderer_resource_export_blob(uint32_t res_id, uint32_t *fd_type, int *fd);
struct virgl_renderer_resource_import_blob_args
{
uint32_t res_handle;
uint32_t blob_mem;
uint32_t fd_type;
int fd;
uint64_t size;
};
VIRGL_EXPORT int
virgl_renderer_resource_import_blob(const struct virgl_renderer_resource_import_blob_args *args);
VIRGL_EXPORT int
virgl_renderer_export_fence(uint32_t client_fence_id, int *fd);

Loading…
Cancel
Save