anv: add anv_ahw_usage_from_vk_usage helper function
authorTapani Pälli <tapani.palli@intel.com>
Thu, 8 Nov 2018 08:02:42 +0000 (10:02 +0200)
committerTapani Pälli <tapani.palli@intel.com>
Wed, 19 Dec 2018 07:38:41 +0000 (09:38 +0200)
v2: rebase to b43f955037c changes

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_android.c
src/intel/vulkan/anv_android.h
src/intel/vulkan/anv_android_stubs.c

index 1288b330a841b1eb8b1ef1ceff49710723e17119..7b7e214379ff88afcd4c431cecd57124ca50a178 100644 (file)
@@ -215,6 +215,37 @@ anv_GetAndroidHardwareBufferPropertiesANDROID(
    return VK_SUCCESS;
 }
 
+/* Construct ahw usage mask from image usage bits, see
+ * 'AHardwareBuffer Usage Equivalence' in Vulkan spec.
+ */
+uint64_t
+anv_ahw_usage_from_vk_usage(const VkImageCreateFlags vk_create,
+                            const VkImageUsageFlags vk_usage)
+{
+   uint64_t ahw_usage = 0;
+
+   if (vk_usage & VK_IMAGE_USAGE_SAMPLED_BIT)
+      ahw_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+
+   if (vk_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)
+      ahw_usage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+
+   if (vk_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
+      ahw_usage |= AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT;
+
+   if (vk_create & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)
+      ahw_usage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP;
+
+   if (vk_create & VK_IMAGE_CREATE_PROTECTED_BIT)
+      ahw_usage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT;
+
+   /* No usage bits set - set at least one GPU usage. */
+   if (ahw_usage == 0)
+      ahw_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
+
+   return ahw_usage;
+}
+
 VkResult
 anv_image_from_gralloc(VkDevice device_h,
                        const VkImageCreateInfo *base_info,
index a27c364471bbb852e05e64a57da75f3529b7ddc6..8d748cecc39849553e599712218cff78ef302879 100644 (file)
@@ -34,4 +34,6 @@ VkResult anv_image_from_gralloc(VkDevice device_h,
                                 const VkAllocationCallbacks *alloc,
                                 VkImage *pImage);
 
+uint64_t anv_ahw_usage_from_vk_usage(const VkImageCreateFlags vk_create,
+                                     const VkImageUsageFlags vk_usage);
 #endif /* ANV_ANDROID_H */
index a6fe5a5e6b3dbd242733c4269e3b48171f37d73b..0671d5635ee41abc8f1a026f6a88523670f449c5 100644 (file)
@@ -32,3 +32,10 @@ anv_image_from_gralloc(VkDevice device_h,
 {
    return VK_ERROR_EXTENSION_NOT_PRESENT;
 }
+
+uint64_t
+anv_ahw_usage_from_vk_usage(const VkImageCreateFlags vk_create,
+                            const VkImageUsageFlags vk_usage)
+{
+   return 0;
+}