blob: 1f777fc372323563b3012b27817194bdceef0cd8 [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
20#define VK_PROTOTYPES
Jesse Hall1356b0d2015-11-23 17:24:58 -080021#define VK_USE_PLATFORM_ANDROID_KHR
Jesse Hall04f4f472015-08-16 19:51:04 -070022#include <vulkan/vulkan.h>
Jesse Hall3e0dc8f2015-11-30 00:42:57 -080023#include <vulkan/vk_android_native_buffer.h>
Jesse Hall04f4f472015-08-16 19:51:04 -070024
25namespace vulkan {
26
Jesse Hallb1352bc2015-09-04 16:12:33 -070027// TODO(jessehall): The InstanceVtbl and DeviceVtbl both have a set of
28// functions used in the app->layers/loader interface, and a different set of
29// functions used only in the loader->driver interface. We should probably
30// split them into two structures: one used for dispatch of application calls,
31// and one to hold the driver entry points.
32
Jesse Hall04f4f472015-08-16 19:51:04 -070033struct InstanceVtbl {
34 // clang-format off
35 VkInstance instance;
36
37 PFN_vkCreateInstance CreateInstance;
38 PFN_vkDestroyInstance DestroyInstance;
39 PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
40 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices;
41
42 PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures;
43 PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties;
44 PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties;
Jesse Hall04f4f472015-08-16 19:51:04 -070045 PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070046 PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties;
Jesse Hall04f4f472015-08-16 19:51:04 -070047 PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties;
48 PFN_vkCreateDevice CreateDevice;
Jesse Hall5ae3abb2015-10-08 14:00:22 -070049 PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties;
50 PFN_vkEnumerateDeviceLayerProperties EnumerateDeviceLayerProperties;
Jesse Hall04f4f472015-08-16 19:51:04 -070051 PFN_vkGetPhysicalDeviceSparseImageFormatProperties GetPhysicalDeviceSparseImageFormatProperties;
Jesse Hallb1352bc2015-09-04 16:12:33 -070052
53 // Layers and loader only, not implemented by drivers
Jesse Hallb00daad2015-11-29 19:46:20 -080054 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR;
55 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
56 PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR;
Jesse Hall1356b0d2015-11-23 17:24:58 -080057 PFN_vkCreateAndroidSurfaceKHR CreateAndroidSurfaceKHR;
58 PFN_vkDestroySurfaceKHR DestroySurfaceKHR;
Jesse Hallb1352bc2015-09-04 16:12:33 -070059 PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
Jesse Hall04f4f472015-08-16 19:51:04 -070060 // clang-format on
61};
62
63struct DeviceVtbl {
64 void* device;
65
66 PFN_vkGetDeviceProcAddr GetDeviceProcAddr;
67 PFN_vkDestroyDevice DestroyDevice;
68 PFN_vkGetDeviceQueue GetDeviceQueue;
69 PFN_vkDeviceWaitIdle DeviceWaitIdle;
Jesse Hall3fbc8562015-11-29 22:10:52 -080070 PFN_vkAllocateMemory AllocateMemory;
Jesse Hall04f4f472015-08-16 19:51:04 -070071 PFN_vkFreeMemory FreeMemory;
72 PFN_vkMapMemory MapMemory;
73 PFN_vkUnmapMemory UnmapMemory;
74 PFN_vkFlushMappedMemoryRanges FlushMappedMemoryRanges;
75 PFN_vkInvalidateMappedMemoryRanges InvalidateMappedMemoryRanges;
76 PFN_vkGetDeviceMemoryCommitment GetDeviceMemoryCommitment;
77 PFN_vkBindBufferMemory BindBufferMemory;
78 PFN_vkBindImageMemory BindImageMemory;
79 PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements;
80 PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements;
81 PFN_vkGetImageSparseMemoryRequirements GetImageSparseMemoryRequirements;
82 PFN_vkCreateFence CreateFence;
83 PFN_vkDestroyFence DestroyFence;
84 PFN_vkResetFences ResetFences;
85 PFN_vkGetFenceStatus GetFenceStatus;
86 PFN_vkWaitForFences WaitForFences;
87 PFN_vkCreateSemaphore CreateSemaphore;
88 PFN_vkDestroySemaphore DestroySemaphore;
89 PFN_vkCreateEvent CreateEvent;
90 PFN_vkDestroyEvent DestroyEvent;
91 PFN_vkGetEventStatus GetEventStatus;
92 PFN_vkSetEvent SetEvent;
93 PFN_vkResetEvent ResetEvent;
94 PFN_vkCreateQueryPool CreateQueryPool;
95 PFN_vkDestroyQueryPool DestroyQueryPool;
96 PFN_vkGetQueryPoolResults GetQueryPoolResults;
97 PFN_vkCreateBuffer CreateBuffer;
98 PFN_vkDestroyBuffer DestroyBuffer;
99 PFN_vkCreateBufferView CreateBufferView;
100 PFN_vkDestroyBufferView DestroyBufferView;
101 PFN_vkCreateImage CreateImage;
102 PFN_vkDestroyImage DestroyImage;
103 PFN_vkGetImageSubresourceLayout GetImageSubresourceLayout;
104 PFN_vkCreateImageView CreateImageView;
105 PFN_vkDestroyImageView DestroyImageView;
Jesse Hall04f4f472015-08-16 19:51:04 -0700106 PFN_vkCreateShaderModule CreateShaderModule;
107 PFN_vkDestroyShaderModule DestroyShaderModule;
Jesse Hall04f4f472015-08-16 19:51:04 -0700108 PFN_vkCreatePipelineCache CreatePipelineCache;
109 PFN_vkDestroyPipelineCache DestroyPipelineCache;
Jesse Hall04f4f472015-08-16 19:51:04 -0700110 PFN_vkGetPipelineCacheData GetPipelineCacheData;
111 PFN_vkMergePipelineCaches MergePipelineCaches;
112 PFN_vkCreateGraphicsPipelines CreateGraphicsPipelines;
113 PFN_vkCreateComputePipelines CreateComputePipelines;
114 PFN_vkDestroyPipeline DestroyPipeline;
115 PFN_vkCreatePipelineLayout CreatePipelineLayout;
116 PFN_vkDestroyPipelineLayout DestroyPipelineLayout;
117 PFN_vkCreateSampler CreateSampler;
118 PFN_vkDestroySampler DestroySampler;
119 PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout;
120 PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout;
121 PFN_vkCreateDescriptorPool CreateDescriptorPool;
122 PFN_vkDestroyDescriptorPool DestroyDescriptorPool;
123 PFN_vkResetDescriptorPool ResetDescriptorPool;
Jesse Hall3fbc8562015-11-29 22:10:52 -0800124 PFN_vkAllocateDescriptorSets AllocateDescriptorSets;
Jesse Hall04f4f472015-08-16 19:51:04 -0700125 PFN_vkFreeDescriptorSets FreeDescriptorSets;
126 PFN_vkUpdateDescriptorSets UpdateDescriptorSets;
Jesse Hall04f4f472015-08-16 19:51:04 -0700127 PFN_vkCreateFramebuffer CreateFramebuffer;
128 PFN_vkDestroyFramebuffer DestroyFramebuffer;
129 PFN_vkCreateRenderPass CreateRenderPass;
130 PFN_vkDestroyRenderPass DestroyRenderPass;
131 PFN_vkGetRenderAreaGranularity GetRenderAreaGranularity;
132 PFN_vkCreateCommandPool CreateCommandPool;
133 PFN_vkDestroyCommandPool DestroyCommandPool;
134 PFN_vkResetCommandPool ResetCommandPool;
Jesse Hall3fbc8562015-11-29 22:10:52 -0800135 PFN_vkAllocateCommandBuffers AllocateCommandBuffers;
Jesse Hallfbf97b02015-11-20 14:17:03 -0800136 PFN_vkFreeCommandBuffers FreeCommandBuffers;
Jesse Hall04f4f472015-08-16 19:51:04 -0700137
138 PFN_vkQueueSubmit QueueSubmit;
139 PFN_vkQueueWaitIdle QueueWaitIdle;
Jesse Halla6429252015-11-29 18:59:42 -0800140 PFN_vkQueueBindSparse QueueBindSparse;
Jesse Hall04f4f472015-08-16 19:51:04 -0700141
142 PFN_vkBeginCommandBuffer BeginCommandBuffer;
143 PFN_vkEndCommandBuffer EndCommandBuffer;
144 PFN_vkResetCommandBuffer ResetCommandBuffer;
145 PFN_vkCmdBindPipeline CmdBindPipeline;
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700146 PFN_vkCmdSetViewport CmdSetViewport;
147 PFN_vkCmdSetScissor CmdSetScissor;
148 PFN_vkCmdSetLineWidth CmdSetLineWidth;
149 PFN_vkCmdSetDepthBias CmdSetDepthBias;
150 PFN_vkCmdSetBlendConstants CmdSetBlendConstants;
151 PFN_vkCmdSetDepthBounds CmdSetDepthBounds;
152 PFN_vkCmdSetStencilCompareMask CmdSetStencilCompareMask;
153 PFN_vkCmdSetStencilWriteMask CmdSetStencilWriteMask;
154 PFN_vkCmdSetStencilReference CmdSetStencilReference;
Jesse Hall04f4f472015-08-16 19:51:04 -0700155 PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets;
156 PFN_vkCmdBindIndexBuffer CmdBindIndexBuffer;
157 PFN_vkCmdBindVertexBuffers CmdBindVertexBuffers;
158 PFN_vkCmdDraw CmdDraw;
159 PFN_vkCmdDrawIndexed CmdDrawIndexed;
160 PFN_vkCmdDrawIndirect CmdDrawIndirect;
161 PFN_vkCmdDrawIndexedIndirect CmdDrawIndexedIndirect;
162 PFN_vkCmdDispatch CmdDispatch;
163 PFN_vkCmdDispatchIndirect CmdDispatchIndirect;
164 PFN_vkCmdCopyBuffer CmdCopyBuffer;
165 PFN_vkCmdCopyImage CmdCopyImage;
166 PFN_vkCmdBlitImage CmdBlitImage;
167 PFN_vkCmdCopyBufferToImage CmdCopyBufferToImage;
168 PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer;
169 PFN_vkCmdUpdateBuffer CmdUpdateBuffer;
170 PFN_vkCmdFillBuffer CmdFillBuffer;
171 PFN_vkCmdClearColorImage CmdClearColorImage;
172 PFN_vkCmdClearDepthStencilImage CmdClearDepthStencilImage;
Jesse Hallae38f732015-11-19 21:32:50 -0800173 PFN_vkCmdClearAttachments CmdClearAttachments;
Jesse Hall04f4f472015-08-16 19:51:04 -0700174 PFN_vkCmdResolveImage CmdResolveImage;
175 PFN_vkCmdSetEvent CmdSetEvent;
176 PFN_vkCmdResetEvent CmdResetEvent;
177 PFN_vkCmdWaitEvents CmdWaitEvents;
178 PFN_vkCmdPipelineBarrier CmdPipelineBarrier;
179 PFN_vkCmdBeginQuery CmdBeginQuery;
180 PFN_vkCmdEndQuery CmdEndQuery;
181 PFN_vkCmdResetQueryPool CmdResetQueryPool;
182 PFN_vkCmdWriteTimestamp CmdWriteTimestamp;
183 PFN_vkCmdCopyQueryPoolResults CmdCopyQueryPoolResults;
184 PFN_vkCmdPushConstants CmdPushConstants;
185 PFN_vkCmdBeginRenderPass CmdBeginRenderPass;
186 PFN_vkCmdNextSubpass CmdNextSubpass;
187 PFN_vkCmdEndRenderPass CmdEndRenderPass;
188 PFN_vkCmdExecuteCommands CmdExecuteCommands;
Jesse Hallb1352bc2015-09-04 16:12:33 -0700189
190 // Layers and loader only, not implemented by drivers
Jesse Hallb1352bc2015-09-04 16:12:33 -0700191 PFN_vkCreateSwapchainKHR CreateSwapchainKHR;
192 PFN_vkDestroySwapchainKHR DestroySwapchainKHR;
193 PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR;
194 PFN_vkAcquireNextImageKHR AcquireNextImageKHR;
195 PFN_vkQueuePresentKHR QueuePresentKHR;
196
197 // Implemented only by drivers, not by layers or the loader
Jesse Hall70f93352015-11-04 09:41:31 -0800198 PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID;
Jesse Hallab9aeef2015-11-04 10:56:20 -0800199 PFN_vkAcquireImageANDROID AcquireImageANDROID;
200 PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID;
Jesse Hallb1352bc2015-09-04 16:12:33 -0700201 PFN_vkImportNativeFenceANDROID ImportNativeFenceANDROID;
202 PFN_vkQueueSignalNativeFenceANDROID QueueSignalNativeFenceANDROID;
Jesse Hall04f4f472015-08-16 19:51:04 -0700203};
204
205// -----------------------------------------------------------------------------
206// loader.cpp
207
Jesse Hall5ae3abb2015-10-08 14:00:22 -0700208VkResult EnumerateInstanceExtensionProperties(
209 const char* layer_name,
210 uint32_t* count,
211 VkExtensionProperties* properties);
212VkResult EnumerateInstanceLayerProperties(uint32_t* count,
213 VkLayerProperties* properties);
Jesse Hall04f4f472015-08-16 19:51:04 -0700214VkResult CreateInstance(const VkInstanceCreateInfo* create_info,
Jesse Hall0e74f002015-11-30 11:37:59 -0800215 const VkAllocationCallbacks* allocator,
Jesse Hall04f4f472015-08-16 19:51:04 -0700216 VkInstance* instance);
217PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
218PFN_vkVoidFunction GetDeviceProcAddr(VkDevice drv_device, const char* name);
Jesse Hall606a54e2015-11-19 22:17:28 -0800219void GetDeviceQueue(VkDevice drv_device,
220 uint32_t family,
221 uint32_t index,
222 VkQueue* out_queue);
Jesse Hallfbf97b02015-11-20 14:17:03 -0800223VkResult AllocCommandBuffers(VkDevice device,
Jesse Hall3fbc8562015-11-29 22:10:52 -0800224 const VkCommandBufferAllocateInfo* alloc_info,
225 VkCommandBuffer* cmdbufs);
226VkResult DestroyDevice(VkDevice drv_device,
Jesse Hall0e74f002015-11-30 11:37:59 -0800227 const VkAllocationCallbacks* allocator);
Jesse Hall04f4f472015-08-16 19:51:04 -0700228
Jesse Hall1356b0d2015-11-23 17:24:58 -0800229void* AllocMem(VkInstance instance,
230 size_t size,
231 size_t align,
Jesse Hall3fbc8562015-11-29 22:10:52 -0800232 VkSystemAllocationScope scope);
Jesse Hall1356b0d2015-11-23 17:24:58 -0800233void FreeMem(VkInstance instance, void* ptr);
234void* AllocMem(VkDevice device,
235 size_t size,
236 size_t align,
Jesse Hall3fbc8562015-11-29 22:10:52 -0800237 VkSystemAllocationScope scope);
Jesse Hall1356b0d2015-11-23 17:24:58 -0800238void FreeMem(VkDevice device, void* ptr);
Jesse Halld7b994a2015-09-07 14:17:37 -0700239const DeviceVtbl& GetDriverVtbl(VkDevice device);
240const DeviceVtbl& GetDriverVtbl(VkQueue queue);
241
Jesse Hall04f4f472015-08-16 19:51:04 -0700242// -----------------------------------------------------------------------------
243// get_proc_addr.cpp
244
245PFN_vkVoidFunction GetGlobalInstanceProcAddr(const char* name);
246PFN_vkVoidFunction GetGlobalDeviceProcAddr(const char* name);
247PFN_vkVoidFunction GetSpecificInstanceProcAddr(const InstanceVtbl* vtbl,
248 const char* name);
249PFN_vkVoidFunction GetSpecificDeviceProcAddr(const DeviceVtbl* vtbl,
250 const char* name);
251
252bool LoadInstanceVtbl(VkInstance instance,
Michael Lentine03c64b02015-08-26 18:27:26 -0500253 VkInstance next_instance,
Jesse Hall04f4f472015-08-16 19:51:04 -0700254 PFN_vkGetInstanceProcAddr get_proc_addr,
255 InstanceVtbl& vtbl);
256bool LoadDeviceVtbl(VkDevice device,
Michael Lentine03c64b02015-08-26 18:27:26 -0500257 VkDevice next_device,
Jesse Hall04f4f472015-08-16 19:51:04 -0700258 PFN_vkGetDeviceProcAddr get_proc_addr,
259 DeviceVtbl& vtbl);
260
Jesse Hallb1352bc2015-09-04 16:12:33 -0700261// -----------------------------------------------------------------------------
262// swapchain.cpp
263
Jesse Hall0e74f002015-11-30 11:37:59 -0800264VKAPI_ATTR VkResult
265CreateAndroidSurfaceKHR(VkInstance instance,
266 ANativeWindow* window,
267 const VkAllocationCallbacks* allocator,
268 VkSurfaceKHR* surface);
269VKAPI_ATTR void DestroySurfaceKHR(VkInstance instance,
270 VkSurfaceKHR surface,
271 const VkAllocationCallbacks* allocator);
Jesse Halle1b12782015-11-30 11:27:32 -0800272VKAPI_ATTR VkResult GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev,
273 uint32_t queue_family,
274 VkSurfaceKHR surface,
275 VkBool32* pSupported);
276VKAPI_ATTR VkResult
277GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice pdev,
278 VkSurfaceKHR surface,
279 VkSurfaceCapabilitiesKHR* capabilities);
280VKAPI_ATTR VkResult
281GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev,
282 VkSurfaceKHR surface,
283 uint32_t* count,
284 VkSurfaceFormatKHR* formats);
285VKAPI_ATTR VkResult
286GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice pdev,
287 VkSurfaceKHR surface,
288 uint32_t* count,
289 VkPresentModeKHR* modes);
290VKAPI_ATTR VkResult
291CreateSwapchainKHR(VkDevice device,
292 const VkSwapchainCreateInfoKHR* create_info,
Jesse Hall0e74f002015-11-30 11:37:59 -0800293 const VkAllocationCallbacks* allocator,
Jesse Halle1b12782015-11-30 11:27:32 -0800294 VkSwapchainKHR* swapchain_handle);
Jesse Hall0e74f002015-11-30 11:37:59 -0800295VKAPI_ATTR VkResult DestroySwapchainKHR(VkDevice device,
296 VkSwapchainKHR swapchain_handle,
297 const VkAllocationCallbacks* allocator);
Jesse Halle1b12782015-11-30 11:27:32 -0800298VKAPI_ATTR VkResult GetSwapchainImagesKHR(VkDevice device,
299 VkSwapchainKHR swapchain_handle,
300 uint32_t* count,
301 VkImage* images);
302VKAPI_ATTR VkResult AcquireNextImageKHR(VkDevice device,
303 VkSwapchainKHR swapchain_handle,
304 uint64_t timeout,
305 VkSemaphore semaphore,
306 uint32_t* image_index);
307VKAPI_ATTR VkResult
Jesse Hallf4ab2b12015-11-30 16:04:55 -0800308QueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* present_info);
Jesse Hallb1352bc2015-09-04 16:12:33 -0700309
Jesse Hall04f4f472015-08-16 19:51:04 -0700310} // namespace vulkan
311
312#endif // LIBVULKAN_LOADER_H