anv: Add HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in vk_format
authorNataraj Deshpande <nataraj.deshpande@intel.com>
Tue, 11 Jun 2019 15:01:50 +0000 (08:01 -0700)
committerTapani Pälli <tapani.palli@intel.com>
Mon, 24 Jun 2019 05:28:18 +0000 (08:28 +0300)
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 <nataraj.deshpande@intel.com>
Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
src/intel/vulkan/anv_android.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/vk_format_info.h

index aee11ccacd2f924c315e0cc643f1aa64c86d9ce0..8c785323d36dbe7961a346b9646bbc172c348f1e 100644 (file)
@@ -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;
index dcb570238bab7a826367f349a059106727a91671..9170ed313e533f0f0cfec09550673e5c2ba428b2 100644 (file)
@@ -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,
index 1369f54ee3881af62a3f0a1257a12e350934f33f..006e1f4a6adfe99d82309fb64867ee23f3253238 100644 (file)
 /* 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;