1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __VK_ANDROID_NATIVE_BUFFER_H__ 18 #define __VK_ANDROID_NATIVE_BUFFER_H__ 19 20 /* MESA: A hack to avoid #ifdefs in driver code. */ 21 #ifdef __ANDROID__ 22 #include <cutils/native_handle.h> 23 #include <vulkan/vulkan.h> 24 25 #if ANDROID_API_LEVEL < 28 26 /* buffer_handle_t was defined in the deprecated system/window.h */ 27 typedef const native_handle_t *buffer_handle_t; 28 #endif 29 30 #else 31 typedef void *buffer_handle_t; 32 #endif 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #define VK_ANDROID_native_buffer 1 39 40 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 11 41 /* 42 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 43 * 44 * This version of the extension transitions from gralloc0 to gralloc1 usage 45 * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue 46 * to fill out deprecated fields in VkNativeBufferANDROID, and will call the 47 * deprecated vkGetSwapchainGrallocUsageANDROID if the new 48 * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary 49 * backwards-compatibility support is temporary, and will likely be removed 50 * (along with all gralloc0 support) in a future release. 51 */ 52 /* 53 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 54 * 55 * This version of the extension doesn't introduce new types or structs, but is 56 * to accommodate the new struct VkBindImageMemorySwapchainInfoKHR added in 57 * VK_KHR_swapchain spec version 69. When VkBindImageMemorySwapchainInfoKHR is 58 * chained in the pNext chain of VkBindImageMemoryInfo, a VkNativeBufferANDROID 59 * that holds the correct gralloc handle according to the imageIndex specified 60 * in VkBindImageMemorySwapchainInfoKHR will be additionally chained to the 61 * pNext chain of VkBindImageMemoryInfo and passed down to the driver. 62 */ 63 /* 64 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 9 65 * 66 * This version of the extension is largely designed to clean up the mix of 67 * GrallocUsage and GrallocUsage2 68 */ 69 /* 70 * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 10 71 * 72 * This version of the extension cleans up a bug introduced in version 9 73 */ 74 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 10 75 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 76 77 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type, id) \ 78 ((type)(1000000000 + \ 79 (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) 80 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID \ 81 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 82 #define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID \ 83 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1) 84 #define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID \ 85 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2) 86 #define VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_ANDROID \ 87 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 3) 88 #define VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_2_ANDROID \ 89 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 4) 90 91 /* clang-format off */ 92 typedef enum VkSwapchainImageUsageFlagBitsANDROID { 93 VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001, 94 VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF 95 } VkSwapchainImageUsageFlagBitsANDROID; 96 typedef VkFlags VkSwapchainImageUsageFlagsANDROID; 97 98 /* 99 * struct VkNativeBufferUsage2ANDROID 100 * 101 * consumer: gralloc1 consumer usage flag 102 * producer: gralloc1 producer usage flag 103 */ 104 typedef struct { 105 uint64_t consumer; 106 uint64_t producer; 107 } VkNativeBufferUsage2ANDROID; 108 109 /* 110 * struct VkNativeBufferANDROID 111 * 112 * sType: VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 113 * pNext: NULL or a pointer to a structure extending this structure 114 * handle: buffer handle returned from gralloc alloc() 115 * stride: stride returned from gralloc alloc() 116 * format: gralloc format requested when the buffer was allocated 117 * usage: gralloc usage requested when the buffer was allocated 118 * usage2: gralloc usage requested when the buffer was allocated 119 * usage3: gralloc usage requested when the buffer was allocated 120 */ 121 typedef struct { 122 VkStructureType sType; 123 const void* pNext; 124 buffer_handle_t handle; 125 int stride; 126 int format; 127 int usage; /* DEPRECATED in SPEC_VERSION 6 */ 128 VkNativeBufferUsage2ANDROID usage2; /* DEPRECATED in SPEC_VERSION 9 */ 129 uint64_t usage3; /* ADDED in SPEC_VERSION 9 */ 130 } VkNativeBufferANDROID; 131 132 /* 133 * struct VkSwapchainImageCreateInfoANDROID 134 * 135 * sType: VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID 136 * pNext: NULL or a pointer to a structure extending this structure 137 * usage: is a bitmask of VkSwapchainImageUsageFlagsANDROID 138 */ 139 typedef struct { 140 VkStructureType sType; 141 const void* pNext; 142 VkSwapchainImageUsageFlagsANDROID usage; 143 } VkSwapchainImageCreateInfoANDROID; 144 145 /* 146 * struct VkPhysicalDevicePresentationPropertiesANDROID 147 * 148 * sType: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID 149 * pNext: NULL or a pointer to a structure extending this structure 150 * sharedImage: specifies if the image can be shared with the display system 151 */ 152 typedef struct { 153 VkStructureType sType; 154 const void* pNext; 155 VkBool32 sharedImage; 156 } VkPhysicalDevicePresentationPropertiesANDROID; 157 158 /* 159 * struct VkGrallocUsageInfoANDROID 160 * 161 * sType: VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_ANDROID 162 * pNext: NULL or a pointer to a structure extending this structure 163 * format: value specifying the format the image will be created with 164 * imageUsage: bitmask of VkImageUsageFlagBits describing intended usage 165 */ 166 typedef struct { 167 VkStructureType sType; 168 const void* pNext; 169 VkFormat format; 170 VkImageUsageFlags imageUsage; 171 } VkGrallocUsageInfoANDROID; 172 173 /* 174 * struct VkGrallocUsageInfo2ANDROID 175 * 176 * sType: VK_STRUCTURE_TYPE_GRALLOC_USAGE_INFO_2_ANDROID 177 * pNext: NULL or a pointer to a structure extending this structure 178 * format: value specifying the format the image will be created with 179 * imageUsage: bitmask of VkImageUsageFlagBits describing intended usage 180 * swapchainImageUsage: is a bitmask of VkSwapchainImageUsageFlagsANDROID 181 */ 182 typedef struct { 183 VkStructureType sType; 184 const void* pNext; 185 VkFormat format; 186 VkImageUsageFlags imageUsage; 187 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage; 188 } VkGrallocUsageInfo2ANDROID; 189 190 /* DEPRECATED in SPEC_VERSION 6 */ 191 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)( 192 VkDevice device, 193 VkFormat format, 194 VkImageUsageFlags imageUsage, 195 int* grallocUsage); 196 197 /* DEPRECATED in SPEC_VERSION 9 */ 198 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)( 199 VkDevice device, 200 VkFormat format, 201 VkImageUsageFlags imageUsage, 202 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 203 uint64_t* grallocConsumerUsage, 204 uint64_t* grallocProducerUsage); 205 206 /* DEPRECATED in SPEC_VERSION 10 */ 207 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage3ANDROID)( 208 VkDevice device, 209 const VkGrallocUsageInfoANDROID* grallocUsageInfo, 210 uint64_t* grallocUsage); 211 212 /* ADDED in SPEC_VERSION 10 */ 213 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage4ANDROID)( 214 VkDevice device, 215 const VkGrallocUsageInfo2ANDROID* grallocUsageInfo, 216 uint64_t* grallocUsage); 217 218 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)( 219 VkDevice device, 220 VkImage image, 221 int nativeFenceFd, 222 VkSemaphore semaphore, 223 VkFence fence); 224 225 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)( 226 VkQueue queue, 227 uint32_t waitSemaphoreCount, 228 const VkSemaphore* pWaitSemaphores, 229 VkImage image, 230 int* pNativeFenceFd); 231 232 #ifndef VK_NO_PROTOTYPES 233 234 /* DEPRECATED in SPEC_VERSION 6 */ 235 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 236 VkDevice device, 237 VkFormat format, 238 VkImageUsageFlags imageUsage, 239 int* grallocUsage 240 ); 241 242 /* DEPRECATED in SPEC_VERSION 9 */ 243 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( 244 VkDevice device, 245 VkFormat format, 246 VkImageUsageFlags imageUsage, 247 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 248 uint64_t* grallocConsumerUsage, 249 uint64_t* grallocProducerUsage 250 ); 251 252 /* DEPRECATED in SPEC_VERSION 10 */ 253 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage3ANDROID( 254 VkDevice device, 255 const VkGrallocUsageInfoANDROID* grallocUsageInfo, 256 uint64_t* grallocUsage 257 ); 258 259 /* ADDED in SPEC_VERSION 10 */ 260 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage4ANDROID( 261 VkDevice device, 262 const VkGrallocUsageInfo2ANDROID* grallocUsageInfo, 263 uint64_t* grallocUsage 264 ); 265 266 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 267 VkDevice device, 268 VkImage image, 269 int nativeFenceFd, 270 VkSemaphore semaphore, 271 VkFence fence 272 ); 273 274 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 275 VkQueue queue, 276 uint32_t waitSemaphoreCount, 277 const VkSemaphore* pWaitSemaphores, 278 VkImage image, 279 int* pNativeFenceFd 280 ); 281 282 #endif 283 /* clang-format on */ 284 285 #ifdef __cplusplus 286 } 287 #endif 288 289 #endif /* __VK_ANDROID_NATIVE_BUFFER_H__ */ 290