There should be no functional change.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22619>
vk_format_from_android(unsigned android_format, unsigned android_usage)
{
switch (android_format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
- return VK_FORMAT_R8G8B8A8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
- return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
- return VK_FORMAT_R5G6B5_UNORM_PACK16;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
- return VK_FORMAT_R16G16B16A16_SFLOAT;
- case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
- return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
case AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED:
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
else
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_BLOB:
default:
- return VK_FORMAT_UNDEFINED;
+ return vk_ahb_format_to_image_format(android_format);
}
}
vk_format_from_android(unsigned android_format, unsigned android_usage)
{
switch (android_format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- return VK_FORMAT_R8G8B8A8_UNORM;
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
- case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
- return VK_FORMAT_R5G6B5_UNORM_PACK16;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
- return VK_FORMAT_R16G16B16A16_SFLOAT;
- case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
- return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
else
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_BLOB:
default:
- return VK_FORMAT_UNDEFINED;
+ return vk_ahb_format_to_image_format(android_format);
}
}
vk_format_from_android(unsigned android_format, unsigned android_usage)
{
switch (android_format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- return VK_FORMAT_R8G8B8A8_UNORM;
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
- case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
- return VK_FORMAT_R5G6B5_UNORM_PACK16;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
- return VK_FORMAT_R16G16B16A16_SFLOAT;
- case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
- return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL:
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
else
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_BLOB:
default:
- return VK_FORMAT_UNDEFINED;
+ return vk_ahb_format_to_image_format(android_format);
}
}
#define AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT
#endif
+/* Convert an AHB format to a VkFormat, based on the "AHardwareBuffer Format
+ * Equivalence" table in Vulkan spec.
+ *
+ * Note that this only covers a subset of AHB formats defined in NDK. Drivers
+ * can support more AHB formats, including private ones.
+ */
+VkFormat
+vk_ahb_format_to_image_format(uint32_t ahb_format)
+{
+ switch (ahb_format) {
+ case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
+ case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
+ return VK_FORMAT_R8G8B8A8_UNORM;
+ case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
+ return VK_FORMAT_R8G8B8_UNORM;
+ case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
+ return VK_FORMAT_R5G6B5_UNORM_PACK16;
+ case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
+ return VK_FORMAT_R16G16B16A16_SFLOAT;
+ case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
+ return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
+ case AHARDWAREBUFFER_FORMAT_D16_UNORM:
+ return VK_FORMAT_D16_UNORM;
+ case AHARDWAREBUFFER_FORMAT_D24_UNORM:
+ return VK_FORMAT_X8_D24_UNORM_PACK32;
+ case AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT:
+ return VK_FORMAT_D24_UNORM_S8_UINT;
+ case AHARDWAREBUFFER_FORMAT_D32_FLOAT:
+ return VK_FORMAT_D32_SFLOAT;
+ case AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT:
+ return VK_FORMAT_D32_SFLOAT_S8_UINT;
+ case AHARDWAREBUFFER_FORMAT_S8_UINT:
+ return VK_FORMAT_S8_UINT;
+ default:
+ return VK_FORMAT_UNDEFINED;
+ }
+}
+
/* Construct ahw usage mask from image usage bits, see
* 'AHardwareBuffer Usage Equivalence' in Vulkan spec.
*/
#if ANDROID_API_LEVEL >= 26
+VkFormat vk_ahb_format_to_image_format(uint32_t ahb_format);
+
uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
const VkImageUsageFlags vk_usage);
#else /* ANDROID_API_LEVEL >= 26 */
+static inline VkFormat
+vk_ahb_format_to_image_format(uint32_t ahb_format)
+{
+ return VK_FORMAT_UNDEFINED;
+}
+
static inline uint64_t
vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
const VkImageUsageFlags vk_usage)