From: Chad Versace <chadvers...@chromium.org> For now, we support dma_bufs only for VkBuffers. The VK_MESAX_external_memory_dma_buf spec allows us to support dma_buf VkImages, but we choose to defer that support until VK_MESAX_external_image_dma_buf.
Signed-off-by: Daniel Stone <dani...@collabora.com> --- src/intel/vulkan/anv_device.c | 28 +++++++++++++++++++--------- src/intel/vulkan/anv_entrypoints_gen.py | 1 + src/intel/vulkan/anv_formats.c | 22 +++++++++++++++++++--- src/intel/vulkan/anv_private.h | 4 ++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 72a96b7eac..9af6d4d632 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -495,6 +495,10 @@ static const VkExtensionProperties device_extensions[] = { .extensionName = VK_KHX_MULTIVIEW_EXTENSION_NAME, .specVersion = 1, }, + { + .extensionName = VK_MESAX_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME, + .specVersion = 0, + }, }; static void * @@ -1561,11 +1565,7 @@ VkResult anv_AllocateMemory( * 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); + assert((fd_info->handleType & ~ANV_SUPPORTED_MEMORY_HANDLE_TYPES) == 0); result = anv_bo_cache_import(device, &device->bo_cache, fd_info->fd, pAllocateInfo->allocationSize, @@ -1606,8 +1606,7 @@ VkResult anv_GetMemoryFdKHX( 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); + assert((handleType & ~ANV_SUPPORTED_MEMORY_HANDLE_TYPES) == 0); return anv_bo_cache_export(dev, &dev->bo_cache, mem->bo, pFd); } @@ -1618,13 +1617,24 @@ VkResult anv_GetMemoryFdPropertiesKHX( int fd, VkMemoryFdPropertiesKHX* pMemoryFdProperties) { + ANV_FROM_HANDLE(anv_device, device, device_h); + + if (fd == -1) + return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX; + /* 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. + * The only non-opaque fd type we support is dma_buf. */ - return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX; + if (handleType != VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX) + return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHX; + + /* We support exactly one memory type on LLC, two on non-LLC. */ + pMemoryFdProperties->memoryTypeBits = device->info.has_llc ? 1 : 3; + + return VK_SUCCESS; } void anv_FreeMemory( diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index c89f77b5c5..b06a0ab29b 100644 --- a/src/intel/vulkan/anv_entrypoints_gen.py +++ b/src/intel/vulkan/anv_entrypoints_gen.py @@ -54,6 +54,7 @@ SUPPORTED_EXTENSIONS = [ 'VK_KHX_external_semaphore_capabilities', 'VK_KHX_external_semaphore_fd', 'VK_KHX_multiview', + 'VK_MESAX_external_memory_dma_buf', ] # We generate a static hash table for entry point lookup diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 5144fc581d..6a71651ce1 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -662,7 +662,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties( pImageFormatProperties); } -static const VkExternalMemoryPropertiesKHX prime_fd_props = { +static const VkExternalMemoryPropertiesKHX opaque_fd_props = { /* If we can handle external, then we can both import and export it. */ .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX | VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHX, @@ -673,6 +673,17 @@ static const VkExternalMemoryPropertiesKHX prime_fd_props = { VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX, }; +static const VkExternalMemoryPropertiesKHX dma_buf_mem_props = { + /* If we can handle external, then we can both import and export it. */ + .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX | + VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHX, + /* For the moment, let's not support mixing and matching */ + .exportFromImportedHandleTypes = + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX, + .compatibleHandleTypes = + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX, +}; + VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR( VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2KHR* base_info, @@ -722,8 +733,10 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR( switch (external_info->handleType) { case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX: if (external_props) - external_props->externalMemoryProperties = prime_fd_props; + external_props->externalMemoryProperties = opaque_fd_props; break; + case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX: + /* Fallthrough. We support dma_buf for VkBuffer but not yet VkImage. */ default: /* From the Vulkan 1.0.42 spec: * @@ -802,7 +815,10 @@ void anv_GetPhysicalDeviceExternalBufferPropertiesKHX( switch (pExternalBufferInfo->handleType) { case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX: - pExternalBufferProperties->externalMemoryProperties = prime_fd_props; + pExternalBufferProperties->externalMemoryProperties = opaque_fd_props; + return; + case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX: + pExternalBufferProperties->externalMemoryProperties = dma_buf_mem_props; return; default: goto unsupported; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index f121b55d91..e24b60ce49 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -1025,6 +1025,10 @@ struct anv_device_memory { void * map; }; +#define ANV_SUPPORTED_MEMORY_HANDLE_TYPES \ + (VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX | \ + VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_MESAX) + /** * Header for Vertex URB Entry (VUE) */ -- 2.13.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev