vulkan: define inline stubs when android api level < 26
authorChia-I Wu <olvaffe@gmail.com>
Fri, 21 Apr 2023 06:46:30 +0000 (23:46 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 11 May 2023 22:18:02 +0000 (22:18 +0000)
This allows us to reduce ANDROID #ifdef's.

v2: always include vk_android.h in radv_formats.c

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22619>

src/amd/vulkan/radv_formats.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan_hasvk/anv_formats.c
src/vulkan/runtime/vk_android.h
src/vulkan/runtime/vk_device_memory.c

index fb44bdd..ed24cf2 100644 (file)
@@ -28,6 +28,7 @@
 #include "sid.h"
 #include "vk_format.h"
 
+#include "vk_android.h"
 #include "vk_util.h"
 
 #include "ac_drm_fourcc.h"
 #include "vulkan/util/vk_format.h"
 #include "vulkan/util/vk_enum_defines.h"
 
-#ifdef ANDROID
-#include "vk_android.h"
-#endif
-
 uint32_t
 radv_translate_buffer_dataformat(const struct util_format_description *desc, int first_non_void)
 {
@@ -1812,10 +1809,8 @@ radv_GetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,
    bool ahb_supported =
       physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer;
    if (android_usage && ahb_supported) {
-#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
       android_usage->androidHardwareBufferUsage =
          vk_image_usage_to_ahb_usage(base_info->flags, base_info->usage);
-#endif
    }
 
    /* From the Vulkan 1.0.97 spec:
index bc06312..0a71bae 100644 (file)
 
 #include "anv_private.h"
 #include "drm-uapi/drm_fourcc.h"
+#include "vk_android.h"
 #include "vk_enum_defines.h"
 #include "vk_enum_to_str.h"
 #include "vk_format.h"
 #include "vk_util.h"
 
-#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
-#include "vk_android.h"
-#endif
-
 /*
  * gcc-4 and earlier don't allow compound literals where a constant
  * is required in -std=c99/gnu99 mode, so we can't use ISL_SWIZZLE()
@@ -1587,7 +1584,6 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
    bool ahw_supported =
       physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer;
 
-#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
    if (ahw_supported && android_usage) {
       android_usage->androidHardwareBufferUsage =
          vk_image_usage_to_ahb_usage(base_info->flags, base_info->usage);
@@ -1595,7 +1591,6 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
       /* Limit maxArrayLayers to 1 for AHardwareBuffer based images for now. */
       base_props->imageFormatProperties.maxArrayLayers = 1;
    }
-#endif
 
    /* From the Vulkan 1.0.42 spec:
     *
index 9d0bfd5..ee883ab 100644 (file)
 
 #include "anv_private.h"
 #include "drm-uapi/drm_fourcc.h"
+#include "vk_android.h"
 #include "vk_enum_defines.h"
 #include "vk_enum_to_str.h"
 #include "vk_format.h"
 #include "vk_util.h"
 
-#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
-#include "vk_android.h"
-#endif
-
 /*
  * gcc-4 and earlier don't allow compound literals where a constant
  * is required in -std=c99/gnu99 mode, so we can't use ISL_SWIZZLE()
@@ -1427,7 +1424,6 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
    bool ahw_supported =
       physical_device->vk.supported_extensions.ANDROID_external_memory_android_hardware_buffer;
 
-#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
    if (ahw_supported && android_usage) {
       android_usage->androidHardwareBufferUsage =
          vk_image_usage_to_ahb_usage(base_info->flags,
@@ -1436,7 +1432,6 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
       /* Limit maxArrayLayers to 1 for AHardwareBuffer based images for now. */
       base_props->imageFormatProperties.maxArrayLayers = 1;
    }
-#endif
 
    /* From the Vulkan 1.0.42 spec:
     *
index 25b346c..2920f26 100644 (file)
@@ -30,12 +30,29 @@ extern "C" {
 #endif
 
 #if ANDROID_API_LEVEL >= 26
+
 uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
                                      const VkImageUsageFlags vk_usage);
 
 struct AHardwareBuffer *
 vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
-#endif
+
+#else /* ANDROID_API_LEVEL >= 26 */
+
+static inline uint64_t
+vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
+                            const VkImageUsageFlags vk_usage)
+{
+   return 0;
+}
+
+static inline struct AHardwareBuffer *
+vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo)
+{
+   return NULL;
+}
+
+#endif /* ANDROID_API_LEVEL >= 26 */
 
 #ifdef __cplusplus
 }
index 6fc5c15..5a35090 100644 (file)
@@ -138,7 +138,6 @@ vk_device_memory_create(struct vk_device *device,
       }
    }
 
-#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
    if ((mem->export_handle_types &
         VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) &&
        mem->ahardware_buffer == NULL) {
@@ -151,7 +150,6 @@ vk_device_memory_create(struct vk_device *device,
          return NULL;
       }
    }
-#endif
 
    return mem;
 }