radv: Implement VK_EXT_external_memory_dma_buf
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 28 Nov 2017 02:43:43 +0000 (18:43 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 4 Dec 2017 18:04:19 +0000 (10:04 -0800)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Chad Versace <chadversary@chromium.org>
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_extensions.py
src/amd/vulkan/radv_formats.c

index 7b1b20e335318d8da27b292a3102d3fbef43d6da..81d04e99fbbe5657fcb398d627f81027328c565e 100644 (file)
@@ -2166,7 +2166,9 @@ VkResult radv_alloc_memory(VkDevice                        _device,
 
        if (import_info) {
                assert(import_info->handleType ==
-                      VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+                      VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
+                      import_info->handleType ==
+                      VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
                mem->bo = device->ws->buffer_from_fd(device->ws, import_info->fd,
                                                     NULL, NULL);
                if (!mem->bo) {
@@ -3534,9 +3536,11 @@ VkResult radv_GetMemoryFdKHR(VkDevice _device,
 
        assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
 
-       /* We support only one handle type. */
+       /* At the moment, we support only the below handle types. */
        assert(pGetFdInfo->handleType ==
-              VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+              VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR ||
+              pGetFdInfo->handleType ==
+              VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
 
        bool ret = radv_get_memory_fd(device, memory, pFD);
        if (ret == false)
@@ -3549,13 +3553,21 @@ VkResult radv_GetMemoryFdPropertiesKHR(VkDevice _device,
                                       int fd,
                                       VkMemoryFdPropertiesKHR *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(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
+   switch (handleType) {
+   case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+      pMemoryFdProperties->memoryTypeBits = (1 << RADV_MEM_TYPE_COUNT) - 1;
+      return VK_SUCCESS;
+
+   default:
+      /* The valid usage section for this function says:
+       *
+       *    "handleType must not be one of the handle types defined as
+       *    opaque."
+       *
+       * So opaque handle types fall into the default "unsupported" case.
+       */
+      return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
+   }
 }
 
 VkResult radv_ImportSemaphoreFdKHR(VkDevice _device,
index eeb679d65a01903fead2d3cf1e8377c856befcf9..4af137c9c131d4c8581e355d637c5c113f531b6d 100644 (file)
@@ -78,6 +78,7 @@ EXTENSIONS = [
     Extension('VK_KHR_xlib_surface',                      6, 'VK_USE_PLATFORM_XLIB_KHR'),
     Extension('VK_KHX_multiview',                         1, True),
     Extension('VK_EXT_debug_report',                      8, True),
+    Extension('VK_EXT_external_memory_dma_buf',           1, True),
     Extension('VK_EXT_global_priority',                   1, 'device->rad_info.has_ctx_priority'),
     Extension('VK_AMD_draw_indirect_count',               1, True),
     Extension('VK_AMD_rasterization_order',               1, 'device->rad_info.chip_class >= VI && device->rad_info.max_se >= 2'),
index 5c79ea74069f847c1e50007fe50d6ec7217e284f..c008c1bae67a2a58df0642fe339687856451c68c 100644 (file)
@@ -1182,7 +1182,8 @@ get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2KHR *
        switch (pImageFormatInfo->type) {
        case VK_IMAGE_TYPE_2D:
                flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHR|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR;
-               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
+               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR |
+                                             VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
                break;
        default:
                break;
@@ -1241,6 +1242,7 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties2KHR(
        if (external_info && external_info->handleType != 0) {
                switch (external_info->handleType) {
                case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+               case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
                        get_external_image_format_properties(base_info, &external_props->externalMemoryProperties);
                        break;
                default:
@@ -1309,9 +1311,11 @@ void radv_GetPhysicalDeviceExternalBufferPropertiesKHR(
        VkExternalMemoryHandleTypeFlagsKHR compat_flags = 0;
        switch(pExternalBufferInfo->handleType) {
        case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+       case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
                flags = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR |
                        VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR;
-               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
+               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR |
+                                             VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
                break;
        default:
                break;