turnip: add support for VK_KHR_external_memory_{fd,dma_buf}
This commit is contained in:
parent
6d1c4049de
commit
6545461041
|
@ -1390,7 +1390,33 @@ tu_alloc_memory(struct tu_device *device,
|
||||||
if (mem == NULL)
|
if (mem == NULL)
|
||||||
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||||
|
|
||||||
result = tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize);
|
const VkImportMemoryFdInfoKHR *fd_info =
|
||||||
|
vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
|
||||||
|
if (fd_info && !fd_info->handleType)
|
||||||
|
fd_info = NULL;
|
||||||
|
|
||||||
|
if (fd_info) {
|
||||||
|
assert(fd_info->handleType ==
|
||||||
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
||||||
|
fd_info->handleType ==
|
||||||
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO Importing the same fd twice gives us the same handle without
|
||||||
|
* reference counting. We need to maintain a per-instance handle-to-bo
|
||||||
|
* table and add reference count to tu_bo.
|
||||||
|
*/
|
||||||
|
result = tu_bo_init_dmabuf(device, &mem->bo,
|
||||||
|
pAllocateInfo->allocationSize, fd_info->fd);
|
||||||
|
if (result == VK_SUCCESS) {
|
||||||
|
/* take ownership and close the fd */
|
||||||
|
close(fd_info->fd);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result =
|
||||||
|
tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
vk_free2(&device->alloc, pAllocator, mem);
|
vk_free2(&device->alloc, pAllocator, mem);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1964,6 +1990,41 @@ vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion)
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
tu_GetMemoryFdKHR(VkDevice _device,
|
||||||
|
const VkMemoryGetFdInfoKHR *pGetFdInfo,
|
||||||
|
int *pFd)
|
||||||
|
{
|
||||||
|
TU_FROM_HANDLE(tu_device, device, _device);
|
||||||
|
TU_FROM_HANDLE(tu_device_memory, memory, pGetFdInfo->memory);
|
||||||
|
|
||||||
|
assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
|
||||||
|
|
||||||
|
/* At the moment, we support only the below handle types. */
|
||||||
|
assert(pGetFdInfo->handleType ==
|
||||||
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT ||
|
||||||
|
pGetFdInfo->handleType ==
|
||||||
|
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
||||||
|
|
||||||
|
int prime_fd = tu_bo_export_dmabuf(device, &memory->bo);
|
||||||
|
if (prime_fd < 0)
|
||||||
|
return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
||||||
|
|
||||||
|
*pFd = prime_fd;
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkResult
|
||||||
|
tu_GetMemoryFdPropertiesKHR(VkDevice _device,
|
||||||
|
VkExternalMemoryHandleTypeFlagBits handleType,
|
||||||
|
int fd,
|
||||||
|
VkMemoryFdPropertiesKHR *pMemoryFdProperties)
|
||||||
|
{
|
||||||
|
assert(handleType == VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
|
||||||
|
pMemoryFdProperties->memoryTypeBits = 1;
|
||||||
|
return VK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tu_GetPhysicalDeviceExternalSemaphoreProperties(
|
tu_GetPhysicalDeviceExternalSemaphoreProperties(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
|
|
|
@ -73,6 +73,8 @@ EXTENSIONS = [
|
||||||
Extension('VK_EXT_debug_report', 9, True),
|
Extension('VK_EXT_debug_report', 9, True),
|
||||||
Extension('VK_KHR_external_memory_capabilities', 1, True),
|
Extension('VK_KHR_external_memory_capabilities', 1, True),
|
||||||
Extension('VK_KHR_external_memory', 1, True),
|
Extension('VK_KHR_external_memory', 1, True),
|
||||||
|
Extension('VK_KHR_external_memory_fd', 1, True),
|
||||||
|
Extension('VK_EXT_external_memory_dma_buf', 1, True),
|
||||||
]
|
]
|
||||||
|
|
||||||
class VkVersion:
|
class VkVersion:
|
||||||
|
|
Loading…
Reference in New Issue