Jesse Hall | d02edcb | 2015-09-08 07:44:48 -0700 | [diff] [blame] | 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 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 17 | #ifndef LIBVULKAN_LOADER_H |
| 18 | #define LIBVULKAN_LOADER_H 1 |
| 19 | |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 20 | #include <bitset> |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 21 | #include "dispatch_gen.h" |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 22 | #include "debug_report.h" |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 23 | |
| 24 | namespace vulkan { |
| 25 | |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 26 | enum InstanceExtension { |
| 27 | kKHR_surface, |
| 28 | kKHR_android_surface, |
| 29 | kEXT_debug_report, |
| 30 | kInstanceExtensionCount |
| 31 | }; |
| 32 | typedef std::bitset<kInstanceExtensionCount> InstanceExtensionSet; |
| 33 | |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 34 | enum DeviceExtension { |
| 35 | kKHR_swapchain, |
| 36 | kANDROID_native_buffer, |
| 37 | kDeviceExtensionCount |
| 38 | }; |
| 39 | typedef std::bitset<kDeviceExtensionCount> DeviceExtensionSet; |
| 40 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 41 | inline const InstanceDispatchTable& GetDispatchTable(VkInstance instance) { |
| 42 | return **reinterpret_cast<InstanceDispatchTable**>(instance); |
| 43 | } |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 44 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 45 | inline const InstanceDispatchTable& GetDispatchTable( |
| 46 | VkPhysicalDevice physical_device) { |
| 47 | return **reinterpret_cast<InstanceDispatchTable**>(physical_device); |
| 48 | } |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 49 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 50 | inline const DeviceDispatchTable& GetDispatchTable(VkDevice device) { |
| 51 | return **reinterpret_cast<DeviceDispatchTable**>(device); |
| 52 | } |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 53 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 54 | inline const DeviceDispatchTable& GetDispatchTable(VkQueue queue) { |
| 55 | return **reinterpret_cast<DeviceDispatchTable**>(queue); |
| 56 | } |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 57 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 58 | inline const DeviceDispatchTable& GetDispatchTable( |
| 59 | VkCommandBuffer command_buffer) { |
| 60 | return **reinterpret_cast<DeviceDispatchTable**>(command_buffer); |
| 61 | } |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 62 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 63 | // ----------------------------------------------------------------------------- |
| 64 | // dispatch_gen.cpp |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 65 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 66 | PFN_vkVoidFunction GetLoaderExportProcAddr(const char* name); |
| 67 | PFN_vkVoidFunction GetLoaderGlobalProcAddr(const char* name); |
| 68 | PFN_vkVoidFunction GetLoaderTopProcAddr(const char* name); |
| 69 | PFN_vkVoidFunction GetLoaderBottomProcAddr(const char* name); |
| 70 | PFN_vkVoidFunction GetDispatchProcAddr(const InstanceDispatchTable& dispatch, |
| 71 | const char* name); |
| 72 | PFN_vkVoidFunction GetDispatchProcAddr(const DeviceDispatchTable& dispatch, |
| 73 | const char* name); |
| 74 | bool LoadInstanceDispatchTable(VkInstance instance, |
| 75 | PFN_vkGetInstanceProcAddr get_proc_addr, |
| 76 | InstanceDispatchTable& dispatch); |
| 77 | bool LoadDeviceDispatchTable(VkDevice device, |
| 78 | PFN_vkGetDeviceProcAddr get_proc_addr, |
| 79 | DeviceDispatchTable& dispatch); |
| 80 | bool LoadDriverDispatchTable(VkInstance instance, |
| 81 | PFN_vkGetInstanceProcAddr get_proc_addr, |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 82 | const InstanceExtensionSet& extensions, |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 83 | DriverDispatchTable& dispatch); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 84 | |
| 85 | // ----------------------------------------------------------------------------- |
| 86 | // loader.cpp |
| 87 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 88 | // clang-format off |
| 89 | VKAPI_ATTR VkResult EnumerateInstanceExtensionProperties_Top(const char* layer_name, uint32_t* count, VkExtensionProperties* properties); |
| 90 | VKAPI_ATTR VkResult EnumerateInstanceLayerProperties_Top(uint32_t* count, VkLayerProperties* properties); |
| 91 | VKAPI_ATTR VkResult CreateInstance_Top(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* instance_out); |
| 92 | VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr_Top(VkInstance instance, const char* name); |
| 93 | VKAPI_ATTR void DestroyInstance_Top(VkInstance instance, const VkAllocationCallbacks* allocator); |
| 94 | VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr_Top(VkDevice drv_device, const char* name); |
| 95 | VKAPI_ATTR void GetDeviceQueue_Top(VkDevice drv_device, uint32_t family, uint32_t index, VkQueue* out_queue); |
| 96 | VKAPI_ATTR VkResult AllocateCommandBuffers_Top(VkDevice device, const VkCommandBufferAllocateInfo* alloc_info, VkCommandBuffer* cmdbufs); |
Courtney Goeltzenleuchter | a90ce61 | 2016-02-08 20:48:05 -0700 | [diff] [blame] | 97 | VKAPI_ATTR VkResult CreateDevice_Top(VkPhysicalDevice pdev, const VkDeviceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkDevice* device_out); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 98 | VKAPI_ATTR void DestroyDevice_Top(VkDevice drv_device, const VkAllocationCallbacks* allocator); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 99 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 100 | VKAPI_ATTR VkResult CreateInstance_Bottom(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* vkinstance); |
| 101 | VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr_Bottom(VkInstance, const char* name); |
| 102 | VKAPI_ATTR VkResult EnumeratePhysicalDevices_Bottom(VkInstance vkinstance, uint32_t* pdev_count, VkPhysicalDevice* pdevs); |
| 103 | VKAPI_ATTR void GetPhysicalDeviceProperties_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceProperties* properties); |
| 104 | VKAPI_ATTR void GetPhysicalDeviceFeatures_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceFeatures* features); |
| 105 | VKAPI_ATTR void GetPhysicalDeviceMemoryProperties_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceMemoryProperties* properties); |
| 106 | VKAPI_ATTR void GetPhysicalDeviceQueueFamilyProperties_Bottom(VkPhysicalDevice pdev, uint32_t* properties_count, VkQueueFamilyProperties* properties); |
| 107 | VKAPI_ATTR void GetPhysicalDeviceFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkFormatProperties* properties); |
| 108 | VKAPI_ATTR VkResult GetPhysicalDeviceImageFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* properties); |
| 109 | VKAPI_ATTR void GetPhysicalDeviceSparseImageFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* properties_count, VkSparseImageFormatProperties* properties); |
| 110 | VKAPI_ATTR VkResult EnumerateDeviceExtensionProperties_Bottom(VkPhysicalDevice pdev, const char* layer_name, uint32_t* properties_count, VkExtensionProperties* properties); |
| 111 | VKAPI_ATTR VkResult EnumerateDeviceLayerProperties_Bottom(VkPhysicalDevice pdev, uint32_t* properties_count, VkLayerProperties* properties); |
| 112 | VKAPI_ATTR VkResult CreateDevice_Bottom(VkPhysicalDevice pdev, const VkDeviceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkDevice* device_out); |
| 113 | VKAPI_ATTR void DestroyInstance_Bottom(VkInstance vkinstance, const VkAllocationCallbacks* allocator); |
| 114 | VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr_Bottom(VkDevice vkdevice, const char* name); |
| 115 | // clang-format on |
Jesse Hall | d7b994a | 2015-09-07 14:17:37 -0700 | [diff] [blame] | 116 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 117 | const VkAllocationCallbacks* GetAllocator(VkInstance instance); |
| 118 | const VkAllocationCallbacks* GetAllocator(VkDevice device); |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 119 | VkInstance GetDriverInstance(VkInstance instance); |
| 120 | const DriverDispatchTable& GetDriverDispatch(VkInstance instance); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 121 | const DriverDispatchTable& GetDriverDispatch(VkDevice device); |
| 122 | const DriverDispatchTable& GetDriverDispatch(VkQueue queue); |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 123 | DebugReportCallbackList& GetDebugReportCallbacks(VkInstance instance); |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 124 | |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 125 | // ----------------------------------------------------------------------------- |
| 126 | // swapchain.cpp |
| 127 | |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 128 | // clang-format off |
Jesse Hall | f9fa9a5 | 2016-01-08 16:08:51 -0800 | [diff] [blame] | 129 | VKAPI_ATTR VkResult CreateAndroidSurfaceKHR_Bottom(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); |
Jesse Hall | 1f91d39 | 2015-12-11 16:28:44 -0800 | [diff] [blame] | 130 | VKAPI_ATTR void DestroySurfaceKHR_Bottom(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* allocator); |
| 131 | VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceSupportKHR_Bottom(VkPhysicalDevice pdev, uint32_t queue_family, VkSurfaceKHR surface, VkBool32* pSupported); |
| 132 | VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* capabilities); |
| 133 | VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceFormatsKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count, VkSurfaceFormatKHR* formats); |
| 134 | VKAPI_ATTR VkResult GetPhysicalDeviceSurfacePresentModesKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count, VkPresentModeKHR* modes); |
| 135 | VKAPI_ATTR VkResult CreateSwapchainKHR_Bottom(VkDevice device, const VkSwapchainCreateInfoKHR* create_info, const VkAllocationCallbacks* allocator, VkSwapchainKHR* swapchain_handle); |
| 136 | VKAPI_ATTR void DestroySwapchainKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, const VkAllocationCallbacks* allocator); |
| 137 | VKAPI_ATTR VkResult GetSwapchainImagesKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, uint32_t* count, VkImage* images); |
| 138 | VKAPI_ATTR VkResult AcquireNextImageKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* image_index); |
| 139 | VKAPI_ATTR VkResult QueuePresentKHR_Bottom(VkQueue queue, const VkPresentInfoKHR* present_info); |
| 140 | // clang-format on |
Jesse Hall | b1352bc | 2015-09-04 16:12:33 -0700 | [diff] [blame] | 141 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 142 | // ----------------------------------------------------------------------------- |
| 143 | // layers_extensions.cpp |
| 144 | |
| 145 | struct Layer; |
| 146 | class LayerRef { |
| 147 | public: |
| 148 | LayerRef(Layer* layer); |
| 149 | LayerRef(LayerRef&& other); |
| 150 | ~LayerRef(); |
| 151 | LayerRef(const LayerRef&) = delete; |
| 152 | LayerRef& operator=(const LayerRef&) = delete; |
| 153 | |
Courtney Goeltzenleuchter | eff6311 | 2016-02-08 20:12:59 -0700 | [diff] [blame] | 154 | const char* GetName(); |
| 155 | uint32_t GetSpecVersion(); |
| 156 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 157 | // provides bool-like behavior |
| 158 | operator const Layer*() const { return layer_; } |
| 159 | |
| 160 | PFN_vkGetInstanceProcAddr GetGetInstanceProcAddr() const; |
| 161 | PFN_vkGetDeviceProcAddr GetGetDeviceProcAddr() const; |
| 162 | |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 163 | bool SupportsExtension(const char* name) const; |
| 164 | |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 165 | private: |
| 166 | Layer* layer_; |
| 167 | }; |
| 168 | |
| 169 | void DiscoverLayers(); |
Jesse Hall | aa41094 | 2016-01-17 13:07:10 -0800 | [diff] [blame] | 170 | uint32_t EnumerateInstanceLayers(uint32_t count, VkLayerProperties* properties); |
| 171 | uint32_t EnumerateDeviceLayers(uint32_t count, VkLayerProperties* properties); |
| 172 | void GetInstanceLayerExtensions(const char* name, |
| 173 | const VkExtensionProperties** properties, |
| 174 | uint32_t* count); |
| 175 | void GetDeviceLayerExtensions(const char* name, |
| 176 | const VkExtensionProperties** properties, |
| 177 | uint32_t* count); |
| 178 | LayerRef GetInstanceLayerRef(const char* name); |
| 179 | LayerRef GetDeviceLayerRef(const char* name); |
Jesse Hall | 80523e2 | 2016-01-06 16:47:54 -0800 | [diff] [blame] | 180 | |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 181 | InstanceExtension InstanceExtensionFromName(const char* name); |
Jesse Hall | b147127 | 2016-01-17 21:36:58 -0800 | [diff] [blame] | 182 | DeviceExtension DeviceExtensionFromName(const char* name); |
Jesse Hall | 6bd5dfa | 2016-01-16 17:13:30 -0800 | [diff] [blame] | 183 | |
Jesse Hall | 04f4f47 | 2015-08-16 19:51:04 -0700 | [diff] [blame] | 184 | } // namespace vulkan |
| 185 | |
| 186 | #endif // LIBVULKAN_LOADER_H |