vkr: move memory fd export into vkr_device_memory

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
macos/master
Yiwei Zhang 3 years ago
parent 356042291c
commit ca83e6d97e
  1. 17
      src/venus/vkr_context.c
  2. 23
      src/venus/vkr_device_memory.c
  3. 5
      src/venus/vkr_device_memory.h

@ -273,6 +273,7 @@ vkr_context_get_blob_locked(struct virgl_context *base,
struct vkr_context *ctx = (struct vkr_context *)base; struct vkr_context *ctx = (struct vkr_context *)base;
struct vkr_device_memory *mem; struct vkr_device_memory *mem;
enum virgl_resource_fd_type fd_type = VIRGL_RESOURCE_FD_INVALID; enum virgl_resource_fd_type fd_type = VIRGL_RESOURCE_FD_INVALID;
int fd = -1;
mem = vkr_context_get_object(ctx, blob_id); mem = vkr_context_get_object(ctx, blob_id);
if (!mem || mem->base.type != VK_OBJECT_TYPE_DEVICE_MEMORY) if (!mem || mem->base.type != VK_OBJECT_TYPE_DEVICE_MEMORY)
@ -308,9 +309,10 @@ vkr_context_get_blob_locked(struct virgl_context *base,
fd_type = VIRGL_RESOURCE_FD_OPAQUE; fd_type = VIRGL_RESOURCE_FD_OPAQUE;
} }
int fd = -1;
if (fd_type != VIRGL_RESOURCE_FD_INVALID) { if (fd_type != VIRGL_RESOURCE_FD_INVALID) {
VkExternalMemoryHandleTypeFlagBits handle_type; VkExternalMemoryHandleTypeFlagBits handle_type;
int ret;
switch (fd_type) { switch (fd_type) {
case VIRGL_RESOURCE_FD_DMABUF: case VIRGL_RESOURCE_FD_DMABUF:
handle_type = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT; handle_type = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
@ -322,16 +324,9 @@ vkr_context_get_blob_locked(struct virgl_context *base,
return -EINVAL; return -EINVAL;
} }
VkResult result = ret = vkr_device_memory_export_fd(mem, handle_type, &fd);
mem->device->get_memory_fd(mem->device->base.handle.device, if (ret)
&(VkMemoryGetFdInfoKHR){ return ret;
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
.memory = mem->base.handle.device_memory,
.handleType = handle_type,
},
&fd);
if (result != VK_SUCCESS)
return -EINVAL;
} }
blob->type = fd_type; blob->type = fd_type;

@ -249,3 +249,26 @@ vkr_device_memory_release(struct vkr_device_memory *mem)
{ {
list_del(&mem->exported_head); list_del(&mem->exported_head);
} }
int
vkr_device_memory_export_fd(struct vkr_device_memory *mem,
VkExternalMemoryHandleTypeFlagBits handle_type,
int *out_fd)
{
VkDevice dev_handle = mem->device->base.handle.device;
VkDeviceMemory mem_handle = mem->base.handle.device_memory;
const VkMemoryGetFdInfoKHR fd_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR,
.memory = mem_handle,
.handleType = handle_type,
};
VkResult result;
int fd = -1;
result = mem->device->get_memory_fd(dev_handle, &fd_info, &fd);
if (result != VK_SUCCESS)
return result == VK_ERROR_TOO_MANY_OBJECTS ? -EMFILE : -ENOMEM;
*out_fd = fd;
return 0;
}

@ -27,4 +27,9 @@ vkr_context_init_device_memory_dispatch(struct vkr_context *ctx);
void void
vkr_device_memory_release(struct vkr_device_memory *mem); vkr_device_memory_release(struct vkr_device_memory *mem);
int
vkr_device_memory_export_fd(struct vkr_device_memory *mem,
VkExternalMemoryHandleTypeFlagBits handle_type,
int *out_fd);
#endif /* VKR_DEVICE_MEMORY_H */ #endif /* VKR_DEVICE_MEMORY_H */

Loading…
Cancel
Save