From: Nataraj Deshpande Date: Tue, 11 Jun 2019 15:01:50 +0000 (-0700) Subject: anv: Add HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in vk_format X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d94fca54203edc0b7fece6aa2dc8703ad4e93c79;p=mesa.git anv: Add HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in vk_format When HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform gralloc module will select a format based on the usage flags provided by the camera device and the other endpoint of the stream. The patch fixes crash in vulkan when the test is run with camera stream set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. Test: android.graphics.cts.CameraVulkanGpuTest#testCameraImportAndRendering on chromebook with camera HAL3. v2: use AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED and take AHARDWAREBUFFER_USAGE_CAMERA_MASK in to account (Gurchetan) Fixes: f1654fa7e31 "anv/android: support creating images from external format" Signed-off-by: Nataraj Deshpande Signed-off-by: Gurchetan Singh Signed-off-by: Tapani Pälli Reviewed-by: Tapani Pälli Reviewed-by: Gurchetan Singh Acked-by: Lionel Landwerlin Acked-by: Jason Ekstrand --- diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index aee11ccacd2..8c785323d36 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -126,7 +126,7 @@ get_ahw_buffer_format_properties( /* Fill properties fields based on description. */ VkAndroidHardwareBufferFormatPropertiesANDROID *p = pProperties; - p->format = vk_format_from_android(desc.format); + p->format = vk_format_from_android(desc.format, desc.usage); const struct anv_format *anv_format = anv_get_format(p->format); p->externalFormat = (uint64_t) (uintptr_t) anv_format; diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index dcb570238ba..9170ed313e5 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -835,7 +835,7 @@ resolve_ahw_image(struct anv_device *device, vk_tiling == VK_IMAGE_TILING_OPTIMAL); /* Check format. */ - VkFormat vk_format = vk_format_from_android(desc.format); + VkFormat vk_format = vk_format_from_android(desc.format, desc.usage); enum isl_format isl_fmt = anv_get_isl_format(&device->info, vk_format, VK_IMAGE_ASPECT_COLOR_BIT, diff --git a/src/intel/vulkan/vk_format_info.h b/src/intel/vulkan/vk_format_info.h index 1369f54ee38..006e1f4a6ad 100644 --- a/src/intel/vulkan/vk_format_info.h +++ b/src/intel/vulkan/vk_format_info.h @@ -32,8 +32,13 @@ /* See i915_private_android_types.h in minigbm. */ #define HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL 0x100 +enum { + /* Usage bit equal to GRALLOC_USAGE_HW_CAMERA_MASK */ + AHARDWAREBUFFER_USAGE_CAMERA_MASK = 0x00060000U, +}; + static inline VkFormat -vk_format_from_android(unsigned android_format) +vk_format_from_android(unsigned android_format, unsigned android_usage) { switch (android_format) { case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: @@ -50,6 +55,11 @@ vk_format_from_android(unsigned android_format) case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420: case HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL: return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; + case AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED: + if (android_usage & AHARDWAREBUFFER_USAGE_CAMERA_MASK) + return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; + else + return VK_FORMAT_R8G8B8_UNORM; case AHARDWAREBUFFER_FORMAT_BLOB: default: return VK_FORMAT_UNDEFINED;