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