blob: 6e327851e814590ac558b34f9a9595b1f20a31c1 [file] [log] [blame]
Jesse Halld02edcb2015-09-08 07:44:48 -07001/*
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 Hall04f4f472015-08-16 19:51:04 -070017#ifndef LIBVULKAN_LOADER_H
18#define LIBVULKAN_LOADER_H 1
19
Jesse Hall1f91d392015-12-11 16:28:44 -080020#include "dispatch_gen.h"
Jesse Hall04f4f472015-08-16 19:51:04 -070021
22namespace vulkan {
23
Jesse Hall1f91d392015-12-11 16:28:44 -080024inline const InstanceDispatchTable& GetDispatchTable(VkInstance instance) {
25 return **reinterpret_cast<InstanceDispatchTable**>(instance);
26}
Jesse Hallb1352bc2015-09-04 16:12:33 -070027
Jesse Hall1f91d392015-12-11 16:28:44 -080028inline const InstanceDispatchTable& GetDispatchTable(
29 VkPhysicalDevice physical_device) {
30 return **reinterpret_cast<InstanceDispatchTable**>(physical_device);
31}
Jesse Hall04f4f472015-08-16 19:51:04 -070032
Jesse Hall1f91d392015-12-11 16:28:44 -080033inline const DeviceDispatchTable& GetDispatchTable(VkDevice device) {
34 return **reinterpret_cast<DeviceDispatchTable**>(device);
35}
Jesse Hall04f4f472015-08-16 19:51:04 -070036
Jesse Hall1f91d392015-12-11 16:28:44 -080037inline const DeviceDispatchTable& GetDispatchTable(VkQueue queue) {
38 return **reinterpret_cast<DeviceDispatchTable**>(queue);
39}
Jesse Hallb1352bc2015-09-04 16:12:33 -070040
Jesse Hall1f91d392015-12-11 16:28:44 -080041inline const DeviceDispatchTable& GetDispatchTable(
42 VkCommandBuffer command_buffer) {
43 return **reinterpret_cast<DeviceDispatchTable**>(command_buffer);
44}
Jesse Hall04f4f472015-08-16 19:51:04 -070045
Jesse Hall1f91d392015-12-11 16:28:44 -080046// -----------------------------------------------------------------------------
47// dispatch_gen.cpp
Jesse Hall04f4f472015-08-16 19:51:04 -070048
Jesse Hall1f91d392015-12-11 16:28:44 -080049PFN_vkVoidFunction GetLoaderExportProcAddr(const char* name);
50PFN_vkVoidFunction GetLoaderGlobalProcAddr(const char* name);
51PFN_vkVoidFunction GetLoaderTopProcAddr(const char* name);
52PFN_vkVoidFunction GetLoaderBottomProcAddr(const char* name);
53PFN_vkVoidFunction GetDispatchProcAddr(const InstanceDispatchTable& dispatch,
54 const char* name);
55PFN_vkVoidFunction GetDispatchProcAddr(const DeviceDispatchTable& dispatch,
56 const char* name);
57bool LoadInstanceDispatchTable(VkInstance instance,
58 PFN_vkGetInstanceProcAddr get_proc_addr,
59 InstanceDispatchTable& dispatch);
60bool LoadDeviceDispatchTable(VkDevice device,
61 PFN_vkGetDeviceProcAddr get_proc_addr,
62 DeviceDispatchTable& dispatch);
63bool LoadDriverDispatchTable(VkInstance instance,
64 PFN_vkGetInstanceProcAddr get_proc_addr,
65 DriverDispatchTable& dispatch);
Jesse Hall04f4f472015-08-16 19:51:04 -070066
67// -----------------------------------------------------------------------------
68// loader.cpp
69
Jesse Hall1f91d392015-12-11 16:28:44 -080070// clang-format off
71VKAPI_ATTR VkResult EnumerateInstanceExtensionProperties_Top(const char* layer_name, uint32_t* count, VkExtensionProperties* properties);
72VKAPI_ATTR VkResult EnumerateInstanceLayerProperties_Top(uint32_t* count, VkLayerProperties* properties);
73VKAPI_ATTR VkResult CreateInstance_Top(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* instance_out);
74VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr_Top(VkInstance instance, const char* name);
75VKAPI_ATTR void DestroyInstance_Top(VkInstance instance, const VkAllocationCallbacks* allocator);
76VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr_Top(VkDevice drv_device, const char* name);
77VKAPI_ATTR void GetDeviceQueue_Top(VkDevice drv_device, uint32_t family, uint32_t index, VkQueue* out_queue);
78VKAPI_ATTR VkResult AllocateCommandBuffers_Top(VkDevice device, const VkCommandBufferAllocateInfo* alloc_info, VkCommandBuffer* cmdbufs);
79VKAPI_ATTR void DestroyDevice_Top(VkDevice drv_device, const VkAllocationCallbacks* allocator);
Jesse Hall04f4f472015-08-16 19:51:04 -070080
Jesse Hall1f91d392015-12-11 16:28:44 -080081VKAPI_ATTR VkResult CreateInstance_Bottom(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* vkinstance);
82VKAPI_ATTR PFN_vkVoidFunction GetInstanceProcAddr_Bottom(VkInstance, const char* name);
83VKAPI_ATTR VkResult EnumeratePhysicalDevices_Bottom(VkInstance vkinstance, uint32_t* pdev_count, VkPhysicalDevice* pdevs);
84VKAPI_ATTR void GetPhysicalDeviceProperties_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceProperties* properties);
85VKAPI_ATTR void GetPhysicalDeviceFeatures_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceFeatures* features);
86VKAPI_ATTR void GetPhysicalDeviceMemoryProperties_Bottom(VkPhysicalDevice pdev, VkPhysicalDeviceMemoryProperties* properties);
87VKAPI_ATTR void GetPhysicalDeviceQueueFamilyProperties_Bottom(VkPhysicalDevice pdev, uint32_t* properties_count, VkQueueFamilyProperties* properties);
88VKAPI_ATTR void GetPhysicalDeviceFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkFormatProperties* properties);
89VKAPI_ATTR VkResult GetPhysicalDeviceImageFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* properties);
90VKAPI_ATTR void GetPhysicalDeviceSparseImageFormatProperties_Bottom(VkPhysicalDevice pdev, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* properties_count, VkSparseImageFormatProperties* properties);
91VKAPI_ATTR VkResult EnumerateDeviceExtensionProperties_Bottom(VkPhysicalDevice pdev, const char* layer_name, uint32_t* properties_count, VkExtensionProperties* properties);
92VKAPI_ATTR VkResult EnumerateDeviceLayerProperties_Bottom(VkPhysicalDevice pdev, uint32_t* properties_count, VkLayerProperties* properties);
93VKAPI_ATTR VkResult CreateDevice_Bottom(VkPhysicalDevice pdev, const VkDeviceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkDevice* device_out);
94VKAPI_ATTR void DestroyInstance_Bottom(VkInstance vkinstance, const VkAllocationCallbacks* allocator);
95VKAPI_ATTR PFN_vkVoidFunction GetDeviceProcAddr_Bottom(VkDevice vkdevice, const char* name);
96// clang-format on
Jesse Halld7b994a2015-09-07 14:17:37 -070097
Jesse Hall1f91d392015-12-11 16:28:44 -080098const VkAllocationCallbacks* GetAllocator(VkInstance instance);
99const VkAllocationCallbacks* GetAllocator(VkDevice device);
100const DriverDispatchTable& GetDriverDispatch(VkDevice device);
101const DriverDispatchTable& GetDriverDispatch(VkQueue queue);
Jesse Hall04f4f472015-08-16 19:51:04 -0700102
Jesse Hallb1352bc2015-09-04 16:12:33 -0700103// -----------------------------------------------------------------------------
104// swapchain.cpp
105
Jesse Hall1f91d392015-12-11 16:28:44 -0800106// clang-format off
Jesse Hallf9fa9a52016-01-08 16:08:51 -0800107VKAPI_ATTR VkResult CreateAndroidSurfaceKHR_Bottom(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
Jesse Hall1f91d392015-12-11 16:28:44 -0800108VKAPI_ATTR void DestroySurfaceKHR_Bottom(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks* allocator);
109VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceSupportKHR_Bottom(VkPhysicalDevice pdev, uint32_t queue_family, VkSurfaceKHR surface, VkBool32* pSupported);
110VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceCapabilitiesKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR* capabilities);
111VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceFormatsKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count, VkSurfaceFormatKHR* formats);
112VKAPI_ATTR VkResult GetPhysicalDeviceSurfacePresentModesKHR_Bottom(VkPhysicalDevice pdev, VkSurfaceKHR surface, uint32_t* count, VkPresentModeKHR* modes);
113VKAPI_ATTR VkResult CreateSwapchainKHR_Bottom(VkDevice device, const VkSwapchainCreateInfoKHR* create_info, const VkAllocationCallbacks* allocator, VkSwapchainKHR* swapchain_handle);
114VKAPI_ATTR void DestroySwapchainKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, const VkAllocationCallbacks* allocator);
115VKAPI_ATTR VkResult GetSwapchainImagesKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, uint32_t* count, VkImage* images);
116VKAPI_ATTR VkResult AcquireNextImageKHR_Bottom(VkDevice device, VkSwapchainKHR swapchain_handle, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t* image_index);
117VKAPI_ATTR VkResult QueuePresentKHR_Bottom(VkQueue queue, const VkPresentInfoKHR* present_info);
118// clang-format on
Jesse Hallb1352bc2015-09-04 16:12:33 -0700119
Jesse Hall80523e22016-01-06 16:47:54 -0800120// -----------------------------------------------------------------------------
121// layers_extensions.cpp
122
123struct Layer;
124class LayerRef {
125 public:
126 LayerRef(Layer* layer);
127 LayerRef(LayerRef&& other);
128 ~LayerRef();
129 LayerRef(const LayerRef&) = delete;
130 LayerRef& operator=(const LayerRef&) = delete;
131
132 // provides bool-like behavior
133 operator const Layer*() const { return layer_; }
134
135 PFN_vkGetInstanceProcAddr GetGetInstanceProcAddr() const;
136 PFN_vkGetDeviceProcAddr GetGetDeviceProcAddr() const;
137
138 private:
139 Layer* layer_;
140};
141
142void DiscoverLayers();
143uint32_t EnumerateLayers(uint32_t count, VkLayerProperties* properties);
144void GetLayerExtensions(const char* name,
145 const VkExtensionProperties** properties,
146 uint32_t* count);
147LayerRef GetLayerRef(const char* name);
148
Jesse Hall04f4f472015-08-16 19:51:04 -0700149} // namespace vulkan
150
151#endif // LIBVULKAN_LOADER_H