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 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 53 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 54 55 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type, id) \ 56 ((type)(1000000000 + \ 57 (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) 58 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID \ 59 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 60 #define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID \ 61 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1) 62 #define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID \ 63 VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2) 64 65 /* clang-format off */ 66 typedef enum VkSwapchainImageUsageFlagBitsANDROID { 67 VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001, 68 VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF 69 } VkSwapchainImageUsageFlagBitsANDROID; 70 typedef VkFlags VkSwapchainImageUsageFlagsANDROID; 71 72 /* 73 * struct VkNativeBufferUsage2ANDROID 74 * 75 * consumer: gralloc1 consumer usage flag 76 * producer: gralloc1 producer usage flag 77 */ 78 typedef struct { 79 uint64_t consumer; 80 uint64_t producer; 81 } VkNativeBufferUsage2ANDROID; 82 83 /* 84 * struct VkNativeBufferANDROID 85 * 86 * sType: VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 87 * pNext: NULL or a pointer to a structure extending this structure 88 * handle: buffer handle returned from gralloc alloc() 89 * stride: stride returned from gralloc alloc() 90 * format: gralloc format requested when the buffer was allocated 91 * usage: gralloc usage requested when the buffer was allocated 92 * usage2: gralloc usage requested when the buffer was allocated 93 */ 94 typedef struct { 95 VkStructureType sType; 96 const void* pNext; 97 buffer_handle_t handle; 98 int stride; 99 int format; 100 int usage; /* DEPRECATED in SPEC_VERSION 6 */ 101 VkNativeBufferUsage2ANDROID usage2; /* ADDED in SPEC_VERSION 6 */ 102 } VkNativeBufferANDROID; 103 104 /* 105 * struct VkSwapchainImageCreateInfoANDROID 106 * 107 * sType: VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID 108 * pNext: NULL or a pointer to a structure extending this structure 109 * usage: is a bitmask of VkSwapchainImageUsageFlagsANDROID 110 */ 111 typedef struct { 112 VkStructureType sType; 113 const void* pNext; 114 VkSwapchainImageUsageFlagsANDROID usage; 115 } VkSwapchainImageCreateInfoANDROID; 116 117 /* 118 * struct VkPhysicalDevicePresentationPropertiesANDROID 119 * 120 * sType: VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID 121 * pNext: NULL or a pointer to a structure extending this structure 122 * sharedImage: specifies if the image can be shared with the display system 123 */ 124 typedef struct { 125 VkStructureType sType; 126 const void* pNext; 127 VkBool32 sharedImage; 128 } VkPhysicalDevicePresentationPropertiesANDROID; 129 130 /* DEPRECATED in SPEC_VERSION 6 */ 131 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)( 132 VkDevice device, 133 VkFormat format, 134 VkImageUsageFlags imageUsage, 135 int* grallocUsage); 136 137 /* ADDED in SPEC_VERSION 6 */ 138 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)( 139 VkDevice device, 140 VkFormat format, 141 VkImageUsageFlags imageUsage, 142 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 143 uint64_t* grallocConsumerUsage, 144 uint64_t* grallocProducerUsage); 145 146 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)( 147 VkDevice device, 148 VkImage image, 149 int nativeFenceFd, 150 VkSemaphore semaphore, 151 VkFence fence); 152 153 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)( 154 VkQueue queue, 155 uint32_t waitSemaphoreCount, 156 const VkSemaphore* pWaitSemaphores, 157 VkImage image, 158 int* pNativeFenceFd); 159 160 #ifndef VK_NO_PROTOTYPES 161 162 /* DEPRECATED in SPEC_VERSION 6 */ 163 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 164 VkDevice device, 165 VkFormat format, 166 VkImageUsageFlags imageUsage, 167 int* grallocUsage 168 ); 169 170 /* ADDED in SPEC_VERSION 6 */ 171 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( 172 VkDevice device, 173 VkFormat format, 174 VkImageUsageFlags imageUsage, 175 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 176 uint64_t* grallocConsumerUsage, 177 uint64_t* grallocProducerUsage 178 ); 179 180 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 181 VkDevice device, 182 VkImage image, 183 int nativeFenceFd, 184 VkSemaphore semaphore, 185 VkFence fence 186 ); 187 188 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 189 VkQueue queue, 190 uint32_t waitSemaphoreCount, 191 const VkSemaphore* pWaitSemaphores, 192 VkImage image, 193 int* pNativeFenceFd 194 ); 195 196 #endif 197 /* clang-format on */ 198 199 #ifdef __cplusplus 200 } 201 #endif 202 203 #endif /* __VK_ANDROID_NATIVE_BUFFER_H__ */ 204