vk_android_native_buffer.h revision e1b12783fff0b8e2defcc94c54fac8d737e6b996
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 <vulkan/vulkan.h> 21#include <system/window.h> 22 23// TODO(jessehall): Get a real extension number officially assigned. 24#define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER 1024 25#define VK_ANDROID_NATIVE_BUFFER_REVISION 1 26#define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" 27 28#ifdef __cplusplus 29extern "C" { 30#endif 31 32// See https://gitlab.khronos.org/vulkan/vulkan/blob/master/doc/proposals/proposed/NVIDIA/VulkanRegistryProposal.txt 33// and Khronos bug 14154 for explanation of these magic numbers. 34#define VK_ANDROID_NATIVE_BUFFER_ENUM(type,id) ((type)((int)0xc0000000 - VK_ANDROID_NATIVE_BUFFER_EXTENSION_NUMBER * -1024 + (id))) 35#define VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID VK_ANDROID_NATIVE_BUFFER_ENUM(VkStructureType, 0) 36 37typedef struct { 38 VkStructureType sType; // must be VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID 39 const void* pNext; 40 41 // Buffer handle and stride returned from gralloc alloc() 42 buffer_handle_t handle; 43 int stride; 44 45 // Gralloc format and usage requested when the buffer was allocated. 46 int format; 47 int usage; 48} VkNativeBufferANDROID; 49 50typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainGrallocUsageANDROID)(VkDevice device, VkFormat format, VkImageUsageFlags imageUsage, int* grallocUsage); 51typedef VkResult (VKAPI_PTR *PFN_vkAcquireImageANDROID)(VkDevice device, VkImage image, int nativeFenceFd, VkSemaphore semaphore); 52typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalReleaseImageANDROID)(VkQueue queue, VkImage image, int* pNativeFenceFd); 53// -- DEPRECATED -- 54typedef VkResult (VKAPI_PTR *PFN_vkImportNativeFenceANDROID)(VkDevice device, VkSemaphore semaphore, int nativeFenceFd); 55typedef VkResult (VKAPI_PTR *PFN_vkQueueSignalNativeFenceANDROID)(VkQueue queue, int* pNativeFenceFd); 56// ---------------- 57 58#ifdef VK_PROTOTYPES 59VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainGrallocUsageANDROID( 60 VkDevice device, 61 VkFormat format, 62 VkImageUsageFlags imageUsage, 63 int* grallocUsage 64); 65VKAPI_ATTR VkResult VKAPI_CALL vkAcquireImageANDROID( 66 VkDevice device, 67 VkImage image, 68 int nativeFenceFd, 69 VkSemaphore semaphore 70); 71VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalReleaseImageANDROID( 72 VkQueue queue, 73 VkImage image, 74 int* pNativeFenceFd 75); 76// -- DEPRECATED -- 77VKAPI_ATTR VkResult VKAPI_CALL vkImportNativeFenceANDROID( 78 VkDevice device, 79 VkSemaphore semaphore, 80 int nativeFenceFd 81); 82VKAPI_ATTR VkResult VKAPI_CALL vkQueueSignalNativeFenceANDROID( 83 VkQueue queue, 84 int* pNativeFenceFd 85); 86// ---------------- 87#endif 88 89#ifdef __cplusplus 90} 91#endif 92 93#endif // __VK_ANDROID_NATIVE_BUFFER_H__ 94