turnip: Fix error behavior for VkPhysicalDeviceExternalImageFormatInfo
authorChad Versace <chadversary@chromium.org>
Sat, 2 Feb 2019 00:48:44 +0000 (16:48 -0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:02:13 +0000 (10:02 -0700)
If the handle type is unsupported, then the spec requires us to return
VK_ERROR_FORMAT_NOT_SUPPORTED.

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Closes: https://gitlab.freedesktop.org/bnieuwenhuizen/mesa/merge_requests/17
src/freedreno/vulkan/tu_formats.c

index e0a2d39436f6dddc5e0bb4d200697859bb1f207d..7f936f5f114784e992da489d43895192d29a9d14 100644 (file)
@@ -544,8 +544,9 @@ tu_GetPhysicalDeviceImageFormatProperties(
                                          pImageFormatProperties);
 }
 
-static void
-get_external_image_format_properties(
+static VkResult
+tu_get_external_image_format_properties(
+   const struct tu_physical_device *physical_device,
    const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo,
    VkExternalMemoryHandleTypeFlagBitsKHR handleType,
    VkExternalMemoryPropertiesKHR *external_properties)
@@ -553,6 +554,15 @@ get_external_image_format_properties(
    VkExternalMemoryFeatureFlagBitsKHR flags = 0;
    VkExternalMemoryHandleTypeFlagsKHR export_flags = 0;
    VkExternalMemoryHandleTypeFlagsKHR compat_flags = 0;
+
+   /* From the Vulkan 1.1.98 spec:
+    *
+    *    If handleType is not compatible with the format, type, tiling,
+    *    usage, and flags specified in VkPhysicalDeviceImageFormatInfo2,
+    *    then vkGetPhysicalDeviceImageFormatProperties2 returns
+    *    VK_ERROR_FORMAT_NOT_SUPPORTED.
+    */
+
    switch (handleType) {
    case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
    case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT:
@@ -566,7 +576,9 @@ get_external_image_format_properties(
             VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT;
          break;
       default:
-         break;
+         return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
+                          "VkExternalMemoryTypeFlagBits(0x%x) unsupported for VkImageType(%d)",
+                          handleType, pImageFormatInfo->type);
       }
       break;
    case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
@@ -574,7 +586,9 @@ get_external_image_format_properties(
       compat_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT;
       break;
    default:
-      break;
+      return vk_errorf(physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
+                       "VkExternalMemoryTypeFlagBits(0x%x) unsupported",
+                       handleType);
    }
 
    *external_properties = (VkExternalMemoryPropertiesKHR) {
@@ -582,6 +596,8 @@ get_external_image_format_properties(
       .exportFromImportedHandleTypes = export_flags,
       .compatibleHandleTypes = compat_flags,
    };
+
+   return VK_SUCCESS;
 }
 
 VkResult
@@ -631,29 +647,11 @@ tu_GetPhysicalDeviceImageFormatProperties2(
     *    present and VkExternalImageFormatPropertiesKHR will be ignored.
     */
    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:
-      case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT:
-         get_external_image_format_properties(
-            base_info, external_info->handleType,
-            &external_props->externalMemoryProperties);
-         break;
-      default:
-         /* From the Vulkan 1.0.42 spec:
-          *
-          *    If handleType is not compatible with the [parameters]
-          * specified
-          *    in VkPhysicalDeviceImageFormatInfo2KHR, then
-          *    vkGetPhysicalDeviceImageFormatProperties2KHR returns
-          *    VK_ERROR_FORMAT_NOT_SUPPORTED.
-          */
-         result = vk_errorf(
-            physical_device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
-            "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
-            external_info->handleType);
+      result = tu_get_external_image_format_properties(
+         physical_device, base_info, external_info->handleType,
+         &external_props->externalMemoryProperties);
+      if (result != VK_SUCCESS)
          goto fail;
-      }
    }
 
    return VK_SUCCESS;