diff options
author | Jason Ekstrand <[email protected]> | 2017-02-28 10:58:40 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2017-04-27 20:08:46 -0700 |
commit | 9bd1f0348734e5dbbdc84e96ac1f11836427ed7c (patch) | |
tree | ec7203946ba99bc2d5823042b7eaf846998c15ac /src/intel/vulkan/anv_device.c | |
parent | 818b8579145196c7a8d4095bd5e65367e02a8fef (diff) |
anv: Implement VK_KHX_external_memory_fd
This commit just exposes the memory handle type. There's interesting we
need to do here for images. So long as the user doesn't set any crazy
environment variables such as INTEL_DEBUG=nohiz, all of the compression
formats etc. should "just work" at least for opaque handle types.
v2 (chadv):
- Rebase.
- Fix vkGetPhysicalDeviceImageFormatProperties2KHR when
handleType == 0.
- Move handleType-independency comments out of handleType-switch, in
vkGetPhysicalDeviceExternalBufferPropertiesKHX. Reduces diff in
future dma_buf patches.
Co-authored-with: Chad Versace <[email protected]>
Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/intel/vulkan/anv_device.c')
-rw-r--r-- | src/intel/vulkan/anv_device.c | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index c8621eec416..62974f19d80 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -366,6 +366,10 @@ static const VkExtensionProperties device_extensions[] = { .extensionName = VK_KHX_EXTERNAL_MEMORY_EXTENSION_NAME, .specVersion = 1, }, + { + .extensionName = VK_KHX_EXTERNAL_MEMORY_FD_EXTENSION_NAME, + .specVersion = 1, + }, }; static void * @@ -1600,7 +1604,7 @@ VkResult anv_AllocateMemory( { ANV_FROM_HANDLE(anv_device, device, _device); struct anv_device_memory *mem; - VkResult result; + VkResult result = VK_SUCCESS; assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); @@ -1638,19 +1642,36 @@ VkResult anv_AllocateMemory( if (mem == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - /* The kernel is going to give us whole pages anyway */ - uint64_t alloc_size = align_u64(pAllocateInfo->allocationSize, 4096); - - result = anv_bo_cache_alloc(device, &device->bo_cache, - alloc_size, &mem->bo); - if (result != VK_SUCCESS) - goto fail; - mem->type_index = pAllocateInfo->memoryTypeIndex; - mem->map = NULL; mem->map_size = 0; + const VkImportMemoryFdInfoKHX *fd_info = + vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHX); + + /* The Vulkan spec permits handleType to be 0, in which case the struct is + * ignored. + */ + if (fd_info && fd_info->handleType) { + /* At the moment, we only support the OPAQUE_FD memory type which is + * just a GEM buffer. + */ + assert(fd_info->handleType == + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX); + + result = anv_bo_cache_import(device, &device->bo_cache, + fd_info->fd, pAllocateInfo->allocationSize, + &mem->bo); + if (result != VK_SUCCESS) + goto fail; + } else { + result = anv_bo_cache_alloc(device, &device->bo_cache, + pAllocateInfo->allocationSize, + &mem->bo); + if (result != VK_SUCCESS) + goto fail; + } + *pMem = anv_device_memory_to_handle(mem); return VK_SUCCESS; @@ -1661,6 +1682,36 @@ VkResult anv_AllocateMemory( return result; } +VkResult anv_GetMemoryFdKHX( + VkDevice device_h, + VkDeviceMemory memory_h, + VkExternalMemoryHandleTypeFlagBitsKHX handleType, + int* pFd) +{ + ANV_FROM_HANDLE(anv_device, dev, device_h); + ANV_FROM_HANDLE(anv_device_memory, mem, memory_h); + + /* We support only one handle type. */ + assert(handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX); + + return anv_bo_cache_export(dev, &dev->bo_cache, mem->bo, pFd); +} + +VkResult anv_GetMemoryFdPropertiesKHX( + VkDevice device_h, + VkExternalMemoryHandleTypeFlagBitsKHX handleType, + int fd, + VkMemoryFdPropertiesKHX* pMemoryFdProperties) +{ + /* The valid usage section for this function says: + * + * "handleType must not be one of the handle types defined as opaque." + * + * Since we only handle opaque handles for now, there are no FD properties. + */ + return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX; +} + void anv_FreeMemory( VkDevice _device, VkDeviceMemory _mem, |