• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 static inline const VkNativeBufferANDROID *
vn_android_find_native_buffer(const VkImageCreateInfo * create_info)26 vn_android_find_native_buffer(const VkImageCreateInfo *create_info)
27 {
28    return vk_find_struct_const(create_info->pNext, NATIVE_BUFFER_ANDROID);
29 }
30 
31 VkResult
32 vn_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 
38 bool
39 vn_android_get_drm_format_modifier_info(
40    const VkPhysicalDeviceImageFormatInfo2 *format_info,
41    VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info);
42 
43 const VkFormat *
44 vn_android_format_to_view_formats(VkFormat format, uint32_t *out_count);
45 
46 uint64_t
47 vn_android_get_ahb_usage(const VkImageUsageFlags usage,
48                          const VkImageCreateFlags flags);
49 
50 VkResult
51 vn_android_image_from_ahb(struct vn_device *dev,
52                           const VkImageCreateInfo *create_info,
53                           const VkAllocationCallbacks *alloc,
54                           struct vn_image **out_img);
55 
56 VkResult
57 vn_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 
64 VkResult
65 vn_android_device_allocate_ahb(struct vn_device *dev,
66                                struct vn_device_memory *mem,
67                                const VkMemoryAllocateInfo *alloc_info,
68                                const VkAllocationCallbacks *alloc);
69 
70 void
71 vn_android_release_ahb(struct AHardwareBuffer *ahb);
72 
73 VkFormat
74 vn_android_drm_format_to_vk_format(uint32_t format);
75 
76 VkResult
77 vn_android_buffer_from_ahb(struct vn_device *dev,
78                            const VkBufferCreateInfo *create_info,
79                            const VkAllocationCallbacks *alloc,
80                            struct vn_buffer **out_buf);
81 
82 VkResult
83 vn_android_get_ahb_buffer_memory_type_bits(struct vn_device *dev,
84                                            uint32_t *out_mem_type_bits);
85 
86 uint32_t
87 vn_android_gralloc_get_shared_present_usage(void);
88 
89 #else
90 
91 static inline const VkNativeBufferANDROID *
vn_android_find_native_buffer(UNUSED const VkImageCreateInfo * create_info)92 vn_android_find_native_buffer(UNUSED const VkImageCreateInfo *create_info)
93 {
94    return NULL;
95 }
96 
97 static inline VkResult
vn_android_image_from_anb(UNUSED struct vn_device * dev,UNUSED const VkImageCreateInfo * image_info,UNUSED const VkNativeBufferANDROID * anb_info,UNUSED const VkAllocationCallbacks * alloc,UNUSED struct vn_image ** out_img)98 vn_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 
107 static inline bool
vn_android_get_drm_format_modifier_info(UNUSED const VkPhysicalDeviceImageFormatInfo2 * format_info,UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT * out_info)108 vn_android_get_drm_format_modifier_info(
109    UNUSED const VkPhysicalDeviceImageFormatInfo2 *format_info,
110    UNUSED VkPhysicalDeviceImageDrmFormatModifierInfoEXT *out_info)
111 {
112    return false;
113 }
114 
115 static inline const VkFormat *
vn_android_format_to_view_formats(UNUSED VkFormat format,UNUSED uint32_t * out_count)116 vn_android_format_to_view_formats(UNUSED VkFormat format,
117                                   UNUSED uint32_t *out_count)
118 {
119    return NULL;
120 }
121 
122 static inline uint64_t
vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,UNUSED const VkImageCreateFlags flags)123 vn_android_get_ahb_usage(UNUSED const VkImageUsageFlags usage,
124                          UNUSED const VkImageCreateFlags flags)
125 {
126    return 0;
127 }
128 
129 static inline VkResult
vn_android_image_from_ahb(UNUSED struct vn_device * dev,UNUSED const VkImageCreateInfo * create_info,UNUSED const VkAllocationCallbacks * alloc,UNUSED struct vn_image ** out_img)130 vn_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 
138 static inline VkResult
vn_android_device_import_ahb(UNUSED struct vn_device * dev,UNUSED struct vn_device_memory * mem,UNUSED const VkMemoryAllocateInfo * alloc_info,UNUSED const VkAllocationCallbacks * alloc,UNUSED struct AHardwareBuffer * ahb,UNUSED bool internal_ahb)139 vn_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 
149 static inline VkResult
vn_android_device_allocate_ahb(UNUSED struct vn_device * dev,UNUSED struct vn_device_memory * mem,UNUSED const VkMemoryAllocateInfo * alloc_info,UNUSED const VkAllocationCallbacks * alloc)150 vn_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 
158 static inline void
vn_android_release_ahb(UNUSED struct AHardwareBuffer * ahb)159 vn_android_release_ahb(UNUSED struct AHardwareBuffer *ahb)
160 {
161    return;
162 }
163 
164 static inline VkFormat
vn_android_drm_format_to_vk_format(UNUSED uint32_t format)165 vn_android_drm_format_to_vk_format(UNUSED uint32_t format)
166 {
167    return VK_FORMAT_UNDEFINED;
168 }
169 
170 static inline VkResult
vn_android_buffer_from_ahb(UNUSED struct vn_device * dev,UNUSED const VkBufferCreateInfo * create_info,UNUSED const VkAllocationCallbacks * alloc,UNUSED struct vn_buffer ** out_buf)171 vn_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 
179 static inline VkResult
vn_android_get_ahb_buffer_memory_type_bits(UNUSED struct vn_device * dev,UNUSED uint32_t * out_mem_type_bits)180 vn_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 
186 static inline uint32_t
vn_android_gralloc_get_shared_present_usage(void)187 vn_android_gralloc_get_shared_present_usage(void)
188 {
189    return 0;
190 }
191 
192 #endif /* ANDROID */
193 
194 #endif /* VN_ANDROID_H */
195