• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_VULKAN_VULKANFUNCTIONS_H_
16 #define DAWNNATIVE_VULKAN_VULKANFUNCTIONS_H_
17 
18 #include "common/vulkan_platform.h"
19 
20 #include "dawn_native/Error.h"
21 
22 class DynamicLib;
23 
24 namespace dawn_native { namespace vulkan {
25 
26     struct VulkanGlobalInfo;
27     struct VulkanDeviceInfo;
28 
29     // Stores the Vulkan entry points. Also loads them from the dynamic library
30     // and the vkGet*ProcAddress entry points.
31     struct VulkanFunctions {
32         MaybeError LoadGlobalProcs(const DynamicLib& vulkanLib);
33         MaybeError LoadInstanceProcs(VkInstance instance, const VulkanGlobalInfo& globalInfo);
34         MaybeError LoadDeviceProcs(VkDevice device, const VulkanDeviceInfo& deviceInfo);
35 
36         // ---------- Global procs
37 
38         // Initial proc from which we can get all the others
39         PFN_vkGetInstanceProcAddr GetInstanceProcAddr = nullptr;
40 
41         PFN_vkCreateInstance CreateInstance = nullptr;
42         PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties = nullptr;
43         PFN_vkEnumerateInstanceLayerProperties EnumerateInstanceLayerProperties = nullptr;
44         // DestroyInstance isn't technically a global proc but we want to be able to use it
45         // before querying the instance procs in case we need to error out during initialization.
46         PFN_vkDestroyInstance DestroyInstance = nullptr;
47 
48         // Core Vulkan 1.1
49         PFN_vkEnumerateInstanceVersion EnumerateInstanceVersion = nullptr;
50 
51         // ---------- Instance procs
52 
53         // Core Vulkan 1.0
54         PFN_vkCreateDevice CreateDevice = nullptr;
55         PFN_vkEnumerateDeviceExtensionProperties EnumerateDeviceExtensionProperties = nullptr;
56         PFN_vkEnumerateDeviceLayerProperties EnumerateDeviceLayerProperties = nullptr;
57         PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices = nullptr;
58         PFN_vkGetDeviceProcAddr GetDeviceProcAddr = nullptr;
59         PFN_vkGetPhysicalDeviceFeatures GetPhysicalDeviceFeatures = nullptr;
60         PFN_vkGetPhysicalDeviceFormatProperties GetPhysicalDeviceFormatProperties = nullptr;
61         PFN_vkGetPhysicalDeviceImageFormatProperties GetPhysicalDeviceImageFormatProperties =
62             nullptr;
63         PFN_vkGetPhysicalDeviceMemoryProperties GetPhysicalDeviceMemoryProperties = nullptr;
64         PFN_vkGetPhysicalDeviceProperties GetPhysicalDeviceProperties = nullptr;
65         PFN_vkGetPhysicalDeviceQueueFamilyProperties GetPhysicalDeviceQueueFamilyProperties =
66             nullptr;
67         PFN_vkGetPhysicalDeviceSparseImageFormatProperties
68             GetPhysicalDeviceSparseImageFormatProperties = nullptr;
69         // Not technically an instance proc but we want to be able to use it as soon as the
70         // device is created.
71         PFN_vkDestroyDevice DestroyDevice = nullptr;
72 
73         // VK_EXT_debug_utils
74         PFN_vkCmdBeginDebugUtilsLabelEXT CmdBeginDebugUtilsLabelEXT = nullptr;
75         PFN_vkCmdEndDebugUtilsLabelEXT CmdEndDebugUtilsLabelEXT = nullptr;
76         PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsertDebugUtilsLabelEXT = nullptr;
77         PFN_vkCreateDebugUtilsMessengerEXT CreateDebugUtilsMessengerEXT = nullptr;
78         PFN_vkDestroyDebugUtilsMessengerEXT DestroyDebugUtilsMessengerEXT = nullptr;
79         PFN_vkQueueBeginDebugUtilsLabelEXT QueueBeginDebugUtilsLabelEXT = nullptr;
80         PFN_vkQueueEndDebugUtilsLabelEXT QueueEndDebugUtilsLabelEXT = nullptr;
81         PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsertDebugUtilsLabelEXT = nullptr;
82         PFN_vkSetDebugUtilsObjectNameEXT SetDebugUtilsObjectNameEXT = nullptr;
83         PFN_vkSetDebugUtilsObjectTagEXT SetDebugUtilsObjectTagEXT = nullptr;
84         PFN_vkSubmitDebugUtilsMessageEXT SubmitDebugUtilsMessageEXT = nullptr;
85 
86         // VK_KHR_surface
87         PFN_vkDestroySurfaceKHR DestroySurfaceKHR = nullptr;
88         PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR = nullptr;
89         PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR =
90             nullptr;
91         PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR = nullptr;
92         PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR =
93             nullptr;
94 
95         // Core Vulkan 1.1 promoted extensions, set if either the core version or the extension is
96         // present.
97 
98         // VK_KHR_external_memory_capabilities
99         PFN_vkGetPhysicalDeviceExternalBufferProperties GetPhysicalDeviceExternalBufferProperties =
100             nullptr;
101 
102         // VK_KHR_external_semaphore_capabilities
103         PFN_vkGetPhysicalDeviceExternalSemaphoreProperties
104             GetPhysicalDeviceExternalSemaphoreProperties = nullptr;
105 
106         // VK_KHR_get_physical_device_properties2
107         PFN_vkGetPhysicalDeviceFeatures2 GetPhysicalDeviceFeatures2 = nullptr;
108         PFN_vkGetPhysicalDeviceProperties2 GetPhysicalDeviceProperties2 = nullptr;
109         PFN_vkGetPhysicalDeviceFormatProperties2 GetPhysicalDeviceFormatProperties2 = nullptr;
110         PFN_vkGetPhysicalDeviceImageFormatProperties2 GetPhysicalDeviceImageFormatProperties2 =
111             nullptr;
112         PFN_vkGetPhysicalDeviceQueueFamilyProperties2 GetPhysicalDeviceQueueFamilyProperties2 =
113             nullptr;
114         PFN_vkGetPhysicalDeviceMemoryProperties2 GetPhysicalDeviceMemoryProperties2 = nullptr;
115         PFN_vkGetPhysicalDeviceSparseImageFormatProperties2
116             GetPhysicalDeviceSparseImageFormatProperties2 = nullptr;
117 
118 #if defined(VK_USE_PLATFORM_FUCHSIA)
119         // FUCHSIA_image_pipe_surface
120         PFN_vkCreateImagePipeSurfaceFUCHSIA CreateImagePipeSurfaceFUCHSIA = nullptr;
121 #endif  // defined(VK_USE_PLATFORM_FUCHSIA)
122 
123 #if defined(DAWN_ENABLE_BACKEND_METAL)
124         // EXT_metal_surface
125         PFN_vkCreateMetalSurfaceEXT CreateMetalSurfaceEXT = nullptr;
126 #endif  // defined(DAWN_ENABLE_BACKEND_METAL)
127 
128 #if defined(DAWN_PLATFORM_WINDOWS)
129         // KHR_win32_surface
130         PFN_vkCreateWin32SurfaceKHR CreateWin32SurfaceKHR = nullptr;
131         PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR
132             GetPhysicalDeviceWin32PresentationSupportKHR = nullptr;
133 #endif  // defined(DAWN_PLATFORM_WINDOWS)
134 
135 #if defined(DAWN_USE_X11)
136         // KHR_xlib_surface
137         PFN_vkCreateXlibSurfaceKHR CreateXlibSurfaceKHR = nullptr;
138         PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
139             GetPhysicalDeviceXlibPresentationSupportKHR = nullptr;
140 
141         // KHR_xcb_surface
142         PFN_vkCreateXcbSurfaceKHR CreateXcbSurfaceKHR = nullptr;
143         PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
144             GetPhysicalDeviceXcbPresentationSupportKHR = nullptr;
145 #endif  // defined(DAWN_USE_X11)
146 
147         // ---------- Device procs
148 
149         // Core Vulkan 1.0
150         PFN_vkAllocateCommandBuffers AllocateCommandBuffers = nullptr;
151         PFN_vkAllocateDescriptorSets AllocateDescriptorSets = nullptr;
152         PFN_vkAllocateMemory AllocateMemory = nullptr;
153         PFN_vkBeginCommandBuffer BeginCommandBuffer = nullptr;
154         PFN_vkBindBufferMemory BindBufferMemory = nullptr;
155         PFN_vkBindImageMemory BindImageMemory = nullptr;
156         PFN_vkCmdBeginQuery CmdBeginQuery = nullptr;
157         PFN_vkCmdBeginRenderPass CmdBeginRenderPass = nullptr;
158         PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets = nullptr;
159         PFN_vkCmdBindIndexBuffer CmdBindIndexBuffer = nullptr;
160         PFN_vkCmdBindPipeline CmdBindPipeline = nullptr;
161         PFN_vkCmdBindVertexBuffers CmdBindVertexBuffers = nullptr;
162         PFN_vkCmdBlitImage CmdBlitImage = nullptr;
163         PFN_vkCmdClearAttachments CmdClearAttachments = nullptr;
164         PFN_vkCmdClearColorImage CmdClearColorImage = nullptr;
165         PFN_vkCmdClearDepthStencilImage CmdClearDepthStencilImage = nullptr;
166         PFN_vkCmdCopyBuffer CmdCopyBuffer = nullptr;
167         PFN_vkCmdCopyBufferToImage CmdCopyBufferToImage = nullptr;
168         PFN_vkCmdCopyImage CmdCopyImage = nullptr;
169         PFN_vkCmdCopyImageToBuffer CmdCopyImageToBuffer = nullptr;
170         PFN_vkCmdCopyQueryPoolResults CmdCopyQueryPoolResults = nullptr;
171         PFN_vkCmdDispatch CmdDispatch = nullptr;
172         PFN_vkCmdDispatchIndirect CmdDispatchIndirect = nullptr;
173         PFN_vkCmdDraw CmdDraw = nullptr;
174         PFN_vkCmdDrawIndexed CmdDrawIndexed = nullptr;
175         PFN_vkCmdDrawIndexedIndirect CmdDrawIndexedIndirect = nullptr;
176         PFN_vkCmdDrawIndirect CmdDrawIndirect = nullptr;
177         PFN_vkCmdEndQuery CmdEndQuery = nullptr;
178         PFN_vkCmdEndRenderPass CmdEndRenderPass = nullptr;
179         PFN_vkCmdExecuteCommands CmdExecuteCommands = nullptr;
180         PFN_vkCmdFillBuffer CmdFillBuffer = nullptr;
181         PFN_vkCmdNextSubpass CmdNextSubpass = nullptr;
182         PFN_vkCmdPipelineBarrier CmdPipelineBarrier = nullptr;
183         PFN_vkCmdPushConstants CmdPushConstants = nullptr;
184         PFN_vkCmdResetEvent CmdResetEvent = nullptr;
185         PFN_vkCmdResetQueryPool CmdResetQueryPool = nullptr;
186         PFN_vkCmdResolveImage CmdResolveImage = nullptr;
187         PFN_vkCmdSetBlendConstants CmdSetBlendConstants = nullptr;
188         PFN_vkCmdSetDepthBias CmdSetDepthBias = nullptr;
189         PFN_vkCmdSetDepthBounds CmdSetDepthBounds = nullptr;
190         PFN_vkCmdSetEvent CmdSetEvent = nullptr;
191         PFN_vkCmdSetLineWidth CmdSetLineWidth = nullptr;
192         PFN_vkCmdSetScissor CmdSetScissor = nullptr;
193         PFN_vkCmdSetStencilCompareMask CmdSetStencilCompareMask = nullptr;
194         PFN_vkCmdSetStencilReference CmdSetStencilReference = nullptr;
195         PFN_vkCmdSetStencilWriteMask CmdSetStencilWriteMask = nullptr;
196         PFN_vkCmdSetViewport CmdSetViewport = nullptr;
197         PFN_vkCmdUpdateBuffer CmdUpdateBuffer = nullptr;
198         PFN_vkCmdWaitEvents CmdWaitEvents = nullptr;
199         PFN_vkCmdWriteTimestamp CmdWriteTimestamp = nullptr;
200         PFN_vkCreateBuffer CreateBuffer = nullptr;
201         PFN_vkCreateBufferView CreateBufferView = nullptr;
202         PFN_vkCreateCommandPool CreateCommandPool = nullptr;
203         PFN_vkCreateComputePipelines CreateComputePipelines = nullptr;
204         PFN_vkCreateDescriptorPool CreateDescriptorPool = nullptr;
205         PFN_vkCreateDescriptorSetLayout CreateDescriptorSetLayout = nullptr;
206         PFN_vkCreateEvent CreateEvent = nullptr;
207         PFN_vkCreateFence CreateFence = nullptr;
208         PFN_vkCreateFramebuffer CreateFramebuffer = nullptr;
209         PFN_vkCreateGraphicsPipelines CreateGraphicsPipelines = nullptr;
210         PFN_vkCreateImage CreateImage = nullptr;
211         PFN_vkCreateImageView CreateImageView = nullptr;
212         PFN_vkCreatePipelineCache CreatePipelineCache = nullptr;
213         PFN_vkCreatePipelineLayout CreatePipelineLayout = nullptr;
214         PFN_vkCreateQueryPool CreateQueryPool = nullptr;
215         PFN_vkCreateRenderPass CreateRenderPass = nullptr;
216         PFN_vkCreateSampler CreateSampler = nullptr;
217         PFN_vkCreateSemaphore CreateSemaphore = nullptr;
218         PFN_vkCreateShaderModule CreateShaderModule = nullptr;
219         PFN_vkDestroyBuffer DestroyBuffer = nullptr;
220         PFN_vkDestroyBufferView DestroyBufferView = nullptr;
221         PFN_vkDestroyCommandPool DestroyCommandPool = nullptr;
222         PFN_vkDestroyDescriptorPool DestroyDescriptorPool = nullptr;
223         PFN_vkDestroyDescriptorSetLayout DestroyDescriptorSetLayout = nullptr;
224         PFN_vkDestroyEvent DestroyEvent = nullptr;
225         PFN_vkDestroyFence DestroyFence = nullptr;
226         PFN_vkDestroyFramebuffer DestroyFramebuffer = nullptr;
227         PFN_vkDestroyImage DestroyImage = nullptr;
228         PFN_vkDestroyImageView DestroyImageView = nullptr;
229         PFN_vkDestroyPipeline DestroyPipeline = nullptr;
230         PFN_vkDestroyPipelineCache DestroyPipelineCache = nullptr;
231         PFN_vkDestroyPipelineLayout DestroyPipelineLayout = nullptr;
232         PFN_vkDestroyQueryPool DestroyQueryPool = nullptr;
233         PFN_vkDestroyRenderPass DestroyRenderPass = nullptr;
234         PFN_vkDestroySampler DestroySampler = nullptr;
235         PFN_vkDestroySemaphore DestroySemaphore = nullptr;
236         PFN_vkDestroyShaderModule DestroyShaderModule = nullptr;
237         PFN_vkDeviceWaitIdle DeviceWaitIdle = nullptr;
238         PFN_vkEndCommandBuffer EndCommandBuffer = nullptr;
239         PFN_vkFlushMappedMemoryRanges FlushMappedMemoryRanges = nullptr;
240         PFN_vkFreeCommandBuffers FreeCommandBuffers = nullptr;
241         PFN_vkFreeDescriptorSets FreeDescriptorSets = nullptr;
242         PFN_vkFreeMemory FreeMemory = nullptr;
243         PFN_vkGetBufferMemoryRequirements GetBufferMemoryRequirements = nullptr;
244         PFN_vkGetDeviceMemoryCommitment GetDeviceMemoryCommitment = nullptr;
245         PFN_vkGetDeviceQueue GetDeviceQueue = nullptr;
246         PFN_vkGetEventStatus GetEventStatus = nullptr;
247         PFN_vkGetFenceStatus GetFenceStatus = nullptr;
248         PFN_vkGetImageMemoryRequirements GetImageMemoryRequirements = nullptr;
249         PFN_vkGetImageSparseMemoryRequirements GetImageSparseMemoryRequirements = nullptr;
250         PFN_vkGetImageSubresourceLayout GetImageSubresourceLayout = nullptr;
251         PFN_vkGetPipelineCacheData GetPipelineCacheData = nullptr;
252         PFN_vkGetQueryPoolResults GetQueryPoolResults = nullptr;
253         PFN_vkGetRenderAreaGranularity GetRenderAreaGranularity = nullptr;
254         PFN_vkInvalidateMappedMemoryRanges InvalidateMappedMemoryRanges = nullptr;
255         PFN_vkMapMemory MapMemory = nullptr;
256         PFN_vkMergePipelineCaches MergePipelineCaches = nullptr;
257         PFN_vkQueueBindSparse QueueBindSparse = nullptr;
258         PFN_vkQueueSubmit QueueSubmit = nullptr;
259         PFN_vkQueueWaitIdle QueueWaitIdle = nullptr;
260         PFN_vkResetCommandBuffer ResetCommandBuffer = nullptr;
261         PFN_vkResetCommandPool ResetCommandPool = nullptr;
262         PFN_vkResetDescriptorPool ResetDescriptorPool = nullptr;
263         PFN_vkResetEvent ResetEvent = nullptr;
264         PFN_vkResetFences ResetFences = nullptr;
265         PFN_vkSetEvent SetEvent = nullptr;
266         PFN_vkUnmapMemory UnmapMemory = nullptr;
267         PFN_vkUpdateDescriptorSets UpdateDescriptorSets = nullptr;
268         PFN_vkWaitForFences WaitForFences = nullptr;
269 
270         // VK_KHR_external_memory_fd
271         PFN_vkGetMemoryFdKHR GetMemoryFdKHR = nullptr;
272         PFN_vkGetMemoryFdPropertiesKHR GetMemoryFdPropertiesKHR = nullptr;
273 
274         // VK_KHR_external_semaphore_fd
275         PFN_vkImportSemaphoreFdKHR ImportSemaphoreFdKHR = nullptr;
276         PFN_vkGetSemaphoreFdKHR GetSemaphoreFdKHR = nullptr;
277 
278         // VK_KHR_get_memory_requirements2
279         PFN_vkGetBufferMemoryRequirements2KHR GetBufferMemoryRequirements2 = nullptr;
280         PFN_vkGetImageMemoryRequirements2KHR GetImageMemoryRequirements2 = nullptr;
281         PFN_vkGetImageSparseMemoryRequirements2KHR GetImageSparseMemoryRequirements2 = nullptr;
282 
283         // VK_KHR_swapchain
284         PFN_vkCreateSwapchainKHR CreateSwapchainKHR = nullptr;
285         PFN_vkDestroySwapchainKHR DestroySwapchainKHR = nullptr;
286         PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR = nullptr;
287         PFN_vkAcquireNextImageKHR AcquireNextImageKHR = nullptr;
288         PFN_vkQueuePresentKHR QueuePresentKHR = nullptr;
289 
290 #if VK_USE_PLATFORM_FUCHSIA
291         // VK_FUCHSIA_external_memory
292         PFN_vkGetMemoryZirconHandleFUCHSIA GetMemoryZirconHandleFUCHSIA = nullptr;
293         PFN_vkGetMemoryZirconHandlePropertiesFUCHSIA GetMemoryZirconHandlePropertiesFUCHSIA =
294             nullptr;
295 
296         // VK_FUCHSIA_external_semaphore
297         PFN_vkImportSemaphoreZirconHandleFUCHSIA ImportSemaphoreZirconHandleFUCHSIA = nullptr;
298         PFN_vkGetSemaphoreZirconHandleFUCHSIA GetSemaphoreZirconHandleFUCHSIA = nullptr;
299 #endif
300     };
301 
302     // Create a wrapper around VkResult in the dawn_native::vulkan namespace. This shadows the
303     // default VkResult (::VkResult). This ensures that assigning or creating a VkResult from a raw
304     // ::VkResult uses WrapUnsafe. This makes it clear that users of VkResult must be intentional
305     // about handling error cases.
306     class VkResult {
307       public:
WrapUnsafe(::VkResult value)308         constexpr static VkResult WrapUnsafe(::VkResult value) {
309             return VkResult(value);
310         }
311 
VkResult()312         constexpr operator ::VkResult() const {
313             return mValue;
314         }
315 
316       private:
317         // Private. Use VkResult::WrapUnsafe instead.
VkResult(::VkResult value)318         constexpr VkResult(::VkResult value) : mValue(value) {
319         }
320 
321         ::VkResult mValue;
322     };
323 
324 }}  // namespace dawn_native::vulkan
325 
326 #endif  // DAWNNATIVE_VULKAN_VULKANFUNCTIONS_H_
327