17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2021 Google LLC
37ec681f3Smrg * SPDX-License-Identifier: MIT
47ec681f3Smrg *
57ec681f3Smrg * based in part on anv and radv which are:
67ec681f3Smrg * Copyright © 2015 Intel Corporation
77ec681f3Smrg * Copyright © 2016 Red Hat
87ec681f3Smrg * Copyright © 2016 Bas Nieuwenhuizen
97ec681f3Smrg */
107ec681f3Smrg
117ec681f3Smrg#ifndef VN_ANDROID_H
127ec681f3Smrg#define VN_ANDROID_H
137ec681f3Smrg
147ec681f3Smrg#include "vn_common.h"
157ec681f3Smrg
167ec681f3Smrg#include <vulkan/vk_android_native_buffer.h>
177ec681f3Smrg#include <vulkan/vulkan.h>
187ec681f3Smrg#include <vulkan/vulkan_android.h>
197ec681f3Smrg
207ec681f3Smrg/* venus implements VK_ANDROID_native_buffer up to spec version 7 */
217ec681f3Smrg#define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7
227ec681f3Smrg
237ec681f3Smrg#ifdef ANDROID
247ec681f3Smrg
257ec681f3Smrgstatic inline const VkNativeBufferANDROID *
267ec681f3Smrgvn_android_find_native_buffer(const VkImageCreateInfo *create_info)
277ec681f3Smrg{
287ec681f3Smrg   return vk_find_struct_const(create_info->pNext, NATIVE_BUFFER_ANDROID);
297ec681f3Smrg}
307ec681f3Smrg
317ec681f3SmrgVkResult
327ec681f3Smrgvn_android_image_from_anb(struct vn_device *dev,
337ec681f3Smrg                          const VkImageCreateInfo *image_info,
347ec681f3Smrg                          const VkNativeBufferANDROID *anb_info,
357ec681f3Smrg                          const VkAllocationCallbacks *alloc,
367ec681f3Smrg                          struct vn_image **out_img);
377ec681f3Smrg
387ec681f3Smrgbool
397ec681f3Smrgvn_android_get_drm_format_modifier_info(
407ec681f3Smrg   const VkPhysicalDeviceImageFormatInfo2 *format_info,
417ec681f3Smrg   VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info);
427ec681f3Smrg
437ec681f3Smrguint64_t
447ec681f3Smrgvn_android_get_ahb_usage(const VkImageUsageFlags usage,
457ec681f3Smrg                         const VkImageCreateFlags flags);
467ec681f3Smrg
477ec681f3SmrgVkResult
487ec681f3Smrgvn_android_image_from_ahb(struct vn_device *dev,
497ec681f3Smrg                          const VkImageCreateInfo *create_info,
507ec681f3Smrg                          const VkAllocationCallbacks *alloc,
517ec681f3Smrg                          struct vn_image **out_img);
527ec681f3Smrg
537ec681f3SmrgVkResult
547ec681f3Smrgvn_android_device_import_ahb(struct vn_device *dev,
557ec681f3Smrg                             struct vn_device_memory *mem,
567ec681f3Smrg                             const VkMemoryAllocateInfo *alloc_info,
577ec681f3Smrg                             const VkAllocationCallbacks *alloc,
587ec681f3Smrg                             struct AHardwareBuffer *ahb);
597ec681f3Smrg
607ec681f3SmrgVkResult
617ec681f3Smrgvn_android_device_allocate_ahb(struct vn_device *dev,
627ec681f3Smrg                               struct vn_device_memory *mem,
637ec681f3Smrg                               const VkMemoryAllocateInfo *alloc_info,
647ec681f3Smrg                               const VkAllocationCallbacks *alloc);
657ec681f3Smrg
667ec681f3Smrgvoid
677ec681f3Smrgvn_android_release_ahb(struct AHardwareBuffer *ahb);
687ec681f3Smrg
697ec681f3SmrgVkFormat
707ec681f3Smrgvn_android_drm_format_to_vk_format(uint32_t format);
717ec681f3Smrg
727ec681f3SmrgVkResult
737ec681f3Smrgvn_android_buffer_from_ahb(struct vn_device *dev,
747ec681f3Smrg                           const VkBufferCreateInfo *create_info,
757ec681f3Smrg                           const VkAllocationCallbacks *alloc,
767ec681f3Smrg                           struct vn_buffer **out_buf);
777ec681f3Smrg
787ec681f3SmrgVkResult
797ec681f3Smrgvn_android_init_ahb_buffer_memory_type_bits(struct vn_device *dev);
807ec681f3Smrg
817ec681f3Smrg#else
827ec681f3Smrg
837ec681f3Smrgstatic inline const VkNativeBufferANDROID *
847ec681f3Smrgvn_android_find_native_buffer(UNUSED const VkImageCreateInfo *create_info)
857ec681f3Smrg{
867ec681f3Smrg   return NULL;
877ec681f3Smrg}
887ec681f3Smrg
897ec681f3Smrgstatic inline VkResult
907ec681f3Smrgvn_android_image_from_anb(UNUSED struct vn_device *dev,
917ec681f3Smrg                          UNUSED const VkImageCreateInfo *image_info,
927ec681f3Smrg                          UNUSED const VkNativeBufferANDROID *anb_info,
937ec681f3Smrg                          UNUSED const VkAllocationCallbacks *alloc,
947ec681f3Smrg                          UNUSED struct vn_image **out_img)
957ec681f3Smrg{
967ec681f3Smrg   return VK_ERROR_OUT_OF_HOST_MEMORY;
977ec681f3Smrg}
987ec681f3Smrg
997ec681f3Smrgstatic inline bool
1007ec681f3Smrgvn_android_get_drm_format_modifier_info(
1017ec681f3Smrg   UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info,
1027ec681f3Smrg   UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info)
1037ec681f3Smrg{
1047ec681f3Smrg   return false;
1057ec681f3Smrg}
1067ec681f3Smrg
1077ec681f3Smrgstatic inline uint64_t
1087ec681f3Smrgvn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,
1097ec681f3Smrg                         UNUSED const VkImageCreateFlags flags)
1107ec681f3Smrg{
1117ec681f3Smrg   return 0;
1127ec681f3Smrg}
1137ec681f3Smrg
1147ec681f3Smrgstatic inline VkResult
1157ec681f3Smrgvn_android_image_from_ahb(UNUSED struct vn_device *dev,
1167ec681f3Smrg                          UNUSED const VkImageCreateInfo *create_info,
1177ec681f3Smrg                          UNUSED const VkAllocationCallbacks *alloc,
1187ec681f3Smrg                          UNUSED struct vn_image **out_img)
1197ec681f3Smrg{
1207ec681f3Smrg   return VK_ERROR_OUT_OF_HOST_MEMORY;
1217ec681f3Smrg}
1227ec681f3Smrg
1237ec681f3Smrgstatic inline VkResult
1247ec681f3Smrgvn_android_device_import_ahb(UNUSED struct vn_device *dev,
1257ec681f3Smrg                             UNUSED struct vn_device_memory *mem,
1267ec681f3Smrg                             UNUSED const VkMemoryAllocateInfo *alloc_info,
1277ec681f3Smrg                             UNUSED const VkAllocationCallbacks *alloc,
1287ec681f3Smrg                             UNUSED struct AHardwareBuffer *ahb)
1297ec681f3Smrg{
1307ec681f3Smrg   return VK_ERROR_OUT_OF_HOST_MEMORY;
1317ec681f3Smrg}
1327ec681f3Smrg
1337ec681f3Smrgstatic inline VkResult
1347ec681f3Smrgvn_android_device_allocate_ahb(UNUSED struct vn_device *dev,
1357ec681f3Smrg                               UNUSED struct vn_device_memory *mem,
1367ec681f3Smrg                               UNUSED const VkMemoryAllocateInfo *alloc_info,
1377ec681f3Smrg                               UNUSED const VkAllocationCallbacks *alloc)
1387ec681f3Smrg{
1397ec681f3Smrg   return VK_ERROR_OUT_OF_HOST_MEMORY;
1407ec681f3Smrg}
1417ec681f3Smrg
1427ec681f3Smrgstatic inline void
1437ec681f3Smrgvn_android_release_ahb(UNUSED struct AHardwareBuffer *ahb)
1447ec681f3Smrg{
1457ec681f3Smrg   return;
1467ec681f3Smrg}
1477ec681f3Smrg
1487ec681f3Smrgstatic inline VkFormat
1497ec681f3Smrgvn_android_drm_format_to_vk_format(UNUSED uint32_t format)
1507ec681f3Smrg{
1517ec681f3Smrg   return VK_FORMAT_UNDEFINED;
1527ec681f3Smrg}
1537ec681f3Smrg
1547ec681f3Smrgstatic inline VkResult
1557ec681f3Smrgvn_android_buffer_from_ahb(UNUSED struct vn_device *dev,
1567ec681f3Smrg                           UNUSED const VkBufferCreateInfo *create_info,
1577ec681f3Smrg                           UNUSED const VkAllocationCallbacks *alloc,
1587ec681f3Smrg                           UNUSED struct vn_buffer **out_buf)
1597ec681f3Smrg{
1607ec681f3Smrg   return VK_ERROR_OUT_OF_HOST_MEMORY;
1617ec681f3Smrg}
1627ec681f3Smrg
1637ec681f3Smrgstatic inline VkResult
1647ec681f3Smrgvn_android_init_ahb_buffer_memory_type_bits(UNUSED struct vn_device *dev)
1657ec681f3Smrg{
1667ec681f3Smrg   return VK_ERROR_FEATURE_NOT_PRESENT;
1677ec681f3Smrg}
1687ec681f3Smrg
1697ec681f3Smrg#endif /* ANDROID */
1707ec681f3Smrg
1717ec681f3Smrg#endif /* VN_ANDROID_H */
172