From 2bbe0462e8a11c4363272163cb98a1c45163fe33 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 20 Apr 2023 23:46:30 -0700 Subject: [PATCH] vulkan: define inline stubs when android api level < 26 This allows us to reduce ANDROID #ifdef's. v2: always include vk_android.h in radv_formats.c Part-of: --- src/amd/vulkan/radv_formats.c | 7 +------ src/intel/vulkan/anv_formats.c | 7 +------ src/intel/vulkan_hasvk/anv_formats.c | 7 +------ src/vulkan/runtime/vk_android.h | 19 ++++++++++++++++++- src/vulkan/runtime/vk_device_memory.c | 2 -- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index fb44bdd..ed24cf2 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -28,6 +28,7 @@ #include "sid.h" #include "vk_format.h" +#include "vk_android.h" #include "vk_util.h" #include "ac_drm_fourcc.h" @@ -38,10 +39,6 @@ #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: diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index bc06312..0a71bae 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -23,15 +23,12 @@ #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: * diff --git a/src/intel/vulkan_hasvk/anv_formats.c b/src/intel/vulkan_hasvk/anv_formats.c index 9d0bfd5..ee883ab 100644 --- a/src/intel/vulkan_hasvk/anv_formats.c +++ b/src/intel/vulkan_hasvk/anv_formats.c @@ -23,15 +23,12 @@ #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: * diff --git a/src/vulkan/runtime/vk_android.h b/src/vulkan/runtime/vk_android.h index 25b346c..2920f26 100644 --- a/src/vulkan/runtime/vk_android.h +++ b/src/vulkan/runtime/vk_android.h @@ -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 } diff --git a/src/vulkan/runtime/vk_device_memory.c b/src/vulkan/runtime/vk_device_memory.c index 6fc5c15..5a35090 100644 --- a/src/vulkan/runtime/vk_device_memory.c +++ b/src/vulkan/runtime/vk_device_memory.c @@ -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; } -- 2.7.4