1/* 2 * Copyright 2021 Google LLC 3 * SPDX-License-Identifier: MIT 4 * 5 * based in part on anv and radv which are: 6 * Copyright © 2015 Intel Corporation 7 * Copyright © 2016 Red Hat 8 * Copyright © 2016 Bas Nieuwenhuizen 9 */ 10 11#ifndef VN_ANDROID_H 12#define VN_ANDROID_H 13 14#include "vn_common.h" 15 16#include <vulkan/vk_android_native_buffer.h> 17#include <vulkan/vulkan.h> 18#include <vulkan/vulkan_android.h> 19 20/* venus implements VK_ANDROID_native_buffer up to spec version 7 */ 21#define VN_ANDROID_NATIVE_BUFFER_SPEC_VERSION 7 22 23#ifdef ANDROID 24 25static inline const VkNativeBufferANDROID * 26vn_android_find_native_buffer(const VkImageCreateInfo *create_info) 27{ 28 return vk_find_struct_const(create_info->pNext, NATIVE_BUFFER_ANDROID); 29} 30 31VkResult 32vn_android_image_from_anb(struct vn_device *dev, 33 const VkImageCreateInfo *image_info, 34 const VkNativeBufferANDROID *anb_info, 35 const VkAllocationCallbacks *alloc, 36 struct vn_image **out_img); 37 38bool 39vn_android_get_drm_format_modifier_info( 40 const VkPhysicalDeviceImageFormatInfo2 *format_info, 41 VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info); 42 43const VkFormat * 44vn_android_format_to_view_formats(VkFormat format, uint32_t *out_count); 45 46uint64_t 47vn_android_get_ahb_usage(const VkImageUsageFlags usage, 48 const VkImageCreateFlags flags); 49 50VkResult 51vn_android_image_from_ahb(struct vn_device *dev, 52 const VkImageCreateInfo *create_info, 53 const VkAllocationCallbacks *alloc, 54 struct vn_image **out_img); 55 56VkResult 57vn_android_device_import_ahb(struct vn_device *dev, 58 struct vn_device_memory *mem, 59 const VkMemoryAllocateInfo *alloc_info, 60 const VkAllocationCallbacks *alloc, 61 struct AHardwareBuffer *ahb, 62 bool internal_ahb); 63 64VkResult 65vn_android_device_allocate_ahb(struct vn_device *dev, 66 struct vn_device_memory *mem, 67 const VkMemoryAllocateInfo *alloc_info, 68 const VkAllocationCallbacks *alloc); 69 70void 71vn_android_release_ahb(struct AHardwareBuffer *ahb); 72 73VkFormat 74vn_android_drm_format_to_vk_format(uint32_t format); 75 76VkResult 77vn_android_buffer_from_ahb(struct vn_device *dev, 78 const VkBufferCreateInfo *create_info, 79 const VkAllocationCallbacks *alloc, 80 struct vn_buffer **out_buf); 81 82VkResult 83vn_android_get_ahb_buffer_memory_type_bits(struct vn_device *dev, 84 uint32_t *out_mem_type_bits); 85 86uint32_t 87vn_android_gralloc_get_shared_present_usage(void); 88 89#else 90 91static inline const VkNativeBufferANDROID * 92vn_android_find_native_buffer(UNUSED const VkImageCreateInfo *create_info) 93{ 94 return NULL; 95} 96 97static inline VkResult 98vn_android_image_from_anb(UNUSED struct vn_device *dev, 99 UNUSED const VkImageCreateInfo *image_info, 100 UNUSED const VkNativeBufferANDROID *anb_info, 101 UNUSED const VkAllocationCallbacks *alloc, 102 UNUSED struct vn_image **out_img) 103{ 104 return VK_ERROR_OUT_OF_HOST_MEMORY; 105} 106 107static inline bool 108vn_android_get_drm_format_modifier_info( 109 UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info, 110 UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info) 111{ 112 return false; 113} 114 115static inline const VkFormat * 116vn_android_format_to_view_formats(UNUSED VkFormat format, 117 UNUSED uint32_t *out_count) 118{ 119 return NULL; 120} 121 122static inline uint64_t 123vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage, 124 UNUSED const VkImageCreateFlags flags) 125{ 126 return 0; 127} 128 129static inline VkResult 130vn_android_image_from_ahb(UNUSED struct vn_device *dev, 131 UNUSED const VkImageCreateInfo *create_info, 132 UNUSED const VkAllocationCallbacks *alloc, 133 UNUSED struct vn_image **out_img) 134{ 135 return VK_ERROR_OUT_OF_HOST_MEMORY; 136} 137 138static inline VkResult 139vn_android_device_import_ahb(UNUSED struct vn_device *dev, 140 UNUSED struct vn_device_memory *mem, 141 UNUSED const VkMemoryAllocateInfo *alloc_info, 142 UNUSED const VkAllocationCallbacks *alloc, 143 UNUSED struct AHardwareBuffer *ahb, 144 UNUSED bool internal_ahb) 145{ 146 return VK_ERROR_OUT_OF_HOST_MEMORY; 147} 148 149static inline VkResult 150vn_android_device_allocate_ahb(UNUSED struct vn_device *dev, 151 UNUSED struct vn_device_memory *mem, 152 UNUSED const VkMemoryAllocateInfo *alloc_info, 153 UNUSED const VkAllocationCallbacks *alloc) 154{ 155 return VK_ERROR_OUT_OF_HOST_MEMORY; 156} 157 158static inline void 159vn_android_release_ahb(UNUSED struct AHardwareBuffer *ahb) 160{ 161 return; 162} 163 164static inline VkFormat 165vn_android_drm_format_to_vk_format(UNUSED uint32_t format) 166{ 167 return VK_FORMAT_UNDEFINED; 168} 169 170static inline VkResult 171vn_android_buffer_from_ahb(UNUSED struct vn_device *dev, 172 UNUSED const VkBufferCreateInfo *create_info, 173 UNUSED const VkAllocationCallbacks *alloc, 174 UNUSED struct vn_buffer **out_buf) 175{ 176 return VK_ERROR_OUT_OF_HOST_MEMORY; 177} 178 179static inline VkResult 180vn_android_get_ahb_buffer_memory_type_bits(UNUSED struct vn_device *dev, 181 UNUSED uint32_t *out_mem_type_bits) 182{ 183 return VK_ERROR_FEATURE_NOT_PRESENT; 184} 185 186static inline uint32_t 187vn_android_gralloc_get_shared_present_usage(void) 188{ 189 return 0; 190} 191 192#endif /* ANDROID */ 193 194#endif /* VN_ANDROID_H */ 195