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 /* NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 6 31 * 32 * This version of the extension transitions from gralloc0 to gralloc1 usage 33 * flags (int -> 2x uint64_t). The WSI implementation will temporarily continue 34 * to fill out deprecated fields in VkNativeBufferANDROID, and will call the 35 * deprecated vkGetSwapchainGrallocUsageANDROID if the new 36 * vkGetSwapchainGrallocUsage2ANDROID is not supported. This transitionary 37 * backwards-compatibility support is temporary, and will likely be removed in 38 * (along with all gralloc0 support) in a future release. 39 */ 40 /* NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 41 * 42 * This version of the extension doesn't introduce new types or structs, but is 43 * to accommodate the new struct VkBindImageMemorySwapchainInfoKHR added in 44 * VK_KHR_swapchain spec version 69. When VkBindImageMemorySwapchainInfoKHR is 45 * chained in the pNext chain of VkBindImageMemoryInfo, a VkNativeBufferANDROID 46 * that holds the correct gralloc handle according to the imageIndex specified 47 * in VkBindImageMemorySwapchainInfoKHR will be additionally chained to the 48 * pNext chain of VkBindImageMemoryInfo and passed down to the driver. 49 */ 50 #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 8 51 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 52 53 #define VK_ANDROID_NATIVE_BUFFER_ENUM(type,id) ((type)(1000000000 + (1000 * (VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER - 1)) + (id))) 54 #define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 55 #define VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 1) 56 #define VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 2) 57 58 typedef enum VkSwapchainImageUsageFlagBitsANDROID { 59 VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID = 0x00000001, 60 VK_SWAPCHAIN_IMAGE_USAGE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF 61 } VkSwapchainImageUsageFlagBitsANDROID; 62 typedef VkFlags VkSwapchainImageUsageFlagsANDROID; 63 64 typedef struct { 65 VkStructureType sType; // must be VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 66 const void* pNext; 67 68 // Buffer handle and stride returned from gralloc alloc() 69 buffer_handle_t handle; 70 int stride; 71 72 // Gralloc format and usage requested when the buffer was allocated. 73 int format; 74 int usage; // DEPRECATED in SPEC_VERSION 6 75 // -- Added in SPEC_VERSION 6 -- 76 struct { 77 uint64_t consumer; 78 uint64_t producer; 79 } usage2; 80 } VkNativeBufferANDROID; 81 82 typedef struct { 83 VkStructureType sType; // must be VK_STRUCTURE_TYPE_SWAPCHAIN_IMAGE_CREATE_INFO_ANDROID 84 const void* pNext; 85 86 VkSwapchainImageUsageFlagsANDROID usage; 87 } VkSwapchainImageCreateInfoANDROID; 88 89 typedef struct { 90 VkStructureType sType; // must be VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENTATION_PROPERTIES_ANDROID 91 const void* pNext; 92 93 VkBool32 sharedImage; 94 } VkPhysicalDevicePresentationPropertiesANDROID; 95 96 // -- DEPRECATED in SPEC_VERSION 6 -- 97 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 98 // -- ADDED in SPEC_VERSION 6 -- 99 typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsage2ANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, uint64_t* grallocConsumerUsage, uint64_t* grallocProducerUsage); 100 typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore, VkFence fence); 101 typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(VkQueue queue, uint32_t waitSemaphoreCount, const VkSemaphore* pWaitSemaphores, VkImage image, int* pNativeFenceFd); 102 103 #ifndef VK_NO_PROTOTYPES 104 105 // -- DEPRECATED in SPEC_VERSION 6 -- 106 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 107 VkDevice device, 108 VkFormat format, 109 VkImageUsageFlags imageUsage, 110 int* grallocUsage 111 ); 112 // -- ADDED in SPEC_VERSION 6 -- 113 VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsage2ANDROID( 114 VkDevice device, 115 VkFormat format, 116 VkImageUsageFlags imageUsage, 117 VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, 118 uint64_t* grallocConsumerUsage, 119 uint64_t* grallocProducerUsage 120 ); 121 VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 122 VkDevice device, 123 VkImage image, 124 int nativeFenceFd, 125 VkSemaphore semaphore, 126 VkFence fence 127 ); 128 VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 129 VkQueue queue, 130 uint32_t waitSemaphoreCount, 131 const VkSemaphore* pWaitSemaphores, 132 VkImage image, 133 int* pNativeFenceFd 134 ); 135 #endif 136 137 #ifdef __cplusplus 138 } 139 #endif 140 141 #endif // __VK_ANDROID_NATIVE_BUFFER_H__ 142