mesa: add no error support to teximage()
[mesa.git] / src / amd / vulkan / radv_formats.c
index 8da18189df0366ee3618a51291768f1e6256ffbd..b13adb9abdcb40b80fc4fe25b53eca88b75bc968 100644 (file)
@@ -28,6 +28,8 @@
 #include "sid.h"
 #include "r600d_common.h"
 
+#include "vk_util.h"
+
 #include "util/u_half.h"
 #include "util/format_srgb.h"
 #include "util/format_r11g11b10f.h"
@@ -1140,14 +1142,107 @@ VkResult radv_GetPhysicalDeviceImageFormatProperties(
                                                pImageFormatProperties);
 }
 
+static void
+get_external_image_format_properties(const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo,
+                                    VkExternalMemoryPropertiesKHX *external_properties)
+{
+       VkExternalMemoryFeatureFlagBitsKHX flags = 0;
+       VkExternalMemoryHandleTypeFlagsKHX export_flags = 0;
+       VkExternalMemoryHandleTypeFlagsKHX compat_flags = 0;
+       switch (pImageFormatInfo->type) {
+       case VK_IMAGE_TYPE_2D:
+               flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHX|VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX|VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHX;
+               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX;
+               break;
+       default:
+               break;
+       }
+
+       *external_properties = (VkExternalMemoryPropertiesKHX) {
+               .externalMemoryFeatures = flags,
+               .exportFromImportedHandleTypes = export_flags,
+               .compatibleHandleTypes = compat_flags,
+       };
+}
+
 VkResult radv_GetPhysicalDeviceImageFormatProperties2KHR(
        VkPhysicalDevice                            physicalDevice,
        const VkPhysicalDeviceImageFormatInfo2KHR  *base_info,
        VkImageFormatProperties2KHR                *base_props)
 {
        RADV_FROM_HANDLE(radv_physical_device, physical_device, physicalDevice);
-       return radv_get_image_format_properties(physical_device, base_info,
+       const VkPhysicalDeviceExternalImageFormatInfoKHX *external_info = NULL;
+       VkExternalImageFormatPropertiesKHX *external_props = NULL;
+       VkResult result;
+
+       result = radv_get_image_format_properties(physical_device, base_info,
                                                &base_props->imageFormatProperties);
+       if (result != VK_SUCCESS)
+               return result;
+
+          /* Extract input structs */
+       vk_foreach_struct_const(s, base_info->pNext) {
+               switch (s->sType) {
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHX:
+                       external_info = (const void *) s;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* Extract output structs */
+       vk_foreach_struct(s, base_props->pNext) {
+               switch (s->sType) {
+               case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHX:
+                       external_props = (void *) s;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* From the Vulkan 1.0.42 spec:
+        *
+        *    If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
+        *    behave as if VkPhysicalDeviceExternalImageFormatInfoKHX was not
+        *    present and VkExternalImageFormatPropertiesKHX will be ignored.
+        */
+       if (external_info && external_info->handleType != 0) {
+               switch (external_info->handleType) {
+               case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX:
+                       get_external_image_format_properties(base_info, &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(VK_ERROR_FORMAT_NOT_SUPPORTED,
+                                          "unsupported VkExternalMemoryTypeFlagBitsKHX 0x%x",
+                                          external_info->handleType);
+                       goto fail;
+               }
+       }
+
+       return VK_SUCCESS;
+
+fail:
+       if (result == VK_ERROR_FORMAT_NOT_SUPPORTED) {
+               /* From the Vulkan 1.0.42 spec:
+                *
+                *    If the combination of parameters to
+                *    vkGetPhysicalDeviceImageFormatProperties2KHR is not supported by
+                *    the implementation for use in vkCreateImage, then all members of
+                *    imageFormatProperties will be filled with zero.
+                */
+               base_props->imageFormatProperties = (VkImageFormatProperties) {0};
+       }
+
+       return result;
 }
 
 void radv_GetPhysicalDeviceSparseImageFormatProperties(
@@ -1173,3 +1268,28 @@ void radv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
        /* Sparse images are not yet supported. */
        *pPropertyCount = 0;
 }
+
+void radv_GetPhysicalDeviceExternalBufferPropertiesKHX(
+       VkPhysicalDevice                            physicalDevice,
+       const VkPhysicalDeviceExternalBufferInfoKHX *pExternalBufferInfo,
+       VkExternalBufferPropertiesKHX               *pExternalBufferProperties)
+{
+       VkExternalMemoryFeatureFlagBitsKHX flags = 0;
+       VkExternalMemoryHandleTypeFlagsKHX export_flags = 0;
+       VkExternalMemoryHandleTypeFlagsKHX compat_flags = 0;
+       switch(pExternalBufferInfo->handleType) {
+       case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX:
+               flags = VK_EXTERNAL_MEMORY_FEATURE_DEDICATED_ONLY_BIT_KHX |
+                       VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHX |
+                       VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHX;
+               compat_flags = export_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHX;
+               break;
+       default:
+               break;
+       }
+       pExternalBufferProperties->externalMemoryProperties = (VkExternalMemoryPropertiesKHX) {
+               .externalMemoryFeatures = flags,
+               .exportFromImportedHandleTypes = export_flags,
+               .compatibleHandleTypes = compat_flags,
+       };
+}