blob: 0d36776b73ae6e1626544c5c7fa30d1fd7cf4c76 [file] [log] [blame]
Corentin Wallez4a9ef4e2018-07-18 11:40:26 +02001// Copyright 2017 The Dawn Authors
Corentin Wallezf2adf6d2017-11-17 17:52:04 -05002//
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
Corentin Wallezd37523f2018-07-24 13:53:51 +020015#include "dawn_native/vulkan/VulkanFunctions.h"
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050016
17#include "common/DynamicLib.h"
Corentin Wallezd37523f2018-07-24 13:53:51 +020018#include "dawn_native/vulkan/VulkanInfo.h"
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050019
Corentin Wallez49a65d02018-07-24 16:45:45 +020020namespace dawn_native { namespace vulkan {
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050021
Corentin Wallez23b27a22017-11-24 14:18:09 -050022#define GET_GLOBAL_PROC(name) \
23 name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \
24 if (name == nullptr) { \
Austin Eng5603dc92019-08-27 18:10:03 +000025 return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
Corentin Wallez23b27a22017-11-24 14:18:09 -050026 }
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050027
Corentin Wallez85df07a2018-12-03 12:49:56 +000028 MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) {
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050029 if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) {
Austin Eng5603dc92019-08-27 18:10:03 +000030 return DAWN_DEVICE_LOST_ERROR("Couldn't get vkGetInstanceProcAddr");
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050031 }
32
33 GET_GLOBAL_PROC(CreateInstance);
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050034 GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties);
35 GET_GLOBAL_PROC(EnumerateInstanceLayerProperties);
36
Idan Raiter7dec2d12019-07-29 23:31:49 +000037 // Is not available in Vulkan 1.0, so allow nullptr
38 EnumerateInstanceVersion = reinterpret_cast<decltype(EnumerateInstanceVersion)>(
39 GetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion"));
40
Corentin Wallez85df07a2018-12-03 12:49:56 +000041 return {};
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050042 }
43
Corentin Wallez23b27a22017-11-24 14:18:09 -050044#define GET_INSTANCE_PROC(name) \
45 name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #name)); \
46 if (name == nullptr) { \
Austin Eng5603dc92019-08-27 18:10:03 +000047 return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
Corentin Wallez23b27a22017-11-24 14:18:09 -050048 }
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050049
Corentin Wallez85df07a2018-12-03 12:49:56 +000050 MaybeError VulkanFunctions::LoadInstanceProcs(VkInstance instance,
Idan Raiteref4f3bd2019-08-02 18:10:38 +000051 const VulkanGlobalInfo& globalInfo) {
Corentin Wallez23b27a22017-11-24 14:18:09 -050052 // Load this proc first so that we can destroy the instance even if some other
53 // GET_INSTANCE_PROC fails
Corentin Wallez02162332017-11-21 12:52:03 -050054 GET_INSTANCE_PROC(DestroyInstance);
55
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050056 GET_INSTANCE_PROC(CreateDevice);
57 GET_INSTANCE_PROC(DestroyDevice);
58 GET_INSTANCE_PROC(EnumerateDeviceExtensionProperties);
59 GET_INSTANCE_PROC(EnumerateDeviceLayerProperties);
60 GET_INSTANCE_PROC(EnumeratePhysicalDevices);
Corentin Wallez02162332017-11-21 12:52:03 -050061 GET_INSTANCE_PROC(GetDeviceProcAddr);
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050062 GET_INSTANCE_PROC(GetPhysicalDeviceFeatures);
63 GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties);
64 GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties);
65 GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties);
66 GET_INSTANCE_PROC(GetPhysicalDeviceProperties);
67 GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties);
68 GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties);
69
Idan Raiteref4f3bd2019-08-02 18:10:38 +000070 if (globalInfo.debugReport) {
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050071 GET_INSTANCE_PROC(CreateDebugReportCallbackEXT);
72 GET_INSTANCE_PROC(DebugReportMessageEXT);
73 GET_INSTANCE_PROC(DestroyDebugReportCallbackEXT);
74 }
75
Idan Raiteref4f3bd2019-08-02 18:10:38 +000076 // Vulkan 1.1 is not required to report promoted extensions from 1.0
77 if (globalInfo.externalMemoryCapabilities ||
78 globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
79 GET_INSTANCE_PROC(GetPhysicalDeviceExternalBufferPropertiesKHR);
80 }
81
82 if (globalInfo.externalSemaphoreCapabilities ||
83 globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
84 GET_INSTANCE_PROC(GetPhysicalDeviceExternalSemaphorePropertiesKHR);
85 }
86
87 if (globalInfo.getPhysicalDeviceProperties2 ||
88 globalInfo.apiVersion >= VK_MAKE_VERSION(1, 1, 0)) {
89 GET_INSTANCE_PROC(GetPhysicalDeviceFeatures2KHR);
90 GET_INSTANCE_PROC(GetPhysicalDeviceProperties2KHR);
91 GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties2KHR);
92 GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties2KHR);
93 GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties2KHR);
94 GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties2KHR);
95 GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties2KHR);
96 }
97
98 if (globalInfo.surface) {
Corentin Wallez02162332017-11-21 12:52:03 -050099 GET_INSTANCE_PROC(DestroySurfaceKHR);
100 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceSupportKHR);
101 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
102 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
103 GET_INSTANCE_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
104 }
105
Corentin Wallez85df07a2018-12-03 12:49:56 +0000106 return {};
Corentin Wallez02162332017-11-21 12:52:03 -0500107 }
108
Austin Eng5603dc92019-08-27 18:10:03 +0000109#define GET_DEVICE_PROC(name) \
110 name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
111 if (name == nullptr) { \
112 return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't get proc vk") + #name); \
Corentin Wallez23b27a22017-11-24 14:18:09 -0500113 }
Corentin Wallez02162332017-11-21 12:52:03 -0500114
Corentin Wallez85df07a2018-12-03 12:49:56 +0000115 MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device,
116 const VulkanDeviceKnobs& usedKnobs) {
Corentin Wallez02162332017-11-21 12:52:03 -0500117 GET_DEVICE_PROC(AllocateCommandBuffers);
118 GET_DEVICE_PROC(AllocateDescriptorSets);
119 GET_DEVICE_PROC(AllocateMemory);
120 GET_DEVICE_PROC(BeginCommandBuffer);
121 GET_DEVICE_PROC(BindBufferMemory);
122 GET_DEVICE_PROC(BindImageMemory);
123 GET_DEVICE_PROC(CmdBeginQuery);
124 GET_DEVICE_PROC(CmdBeginRenderPass);
125 GET_DEVICE_PROC(CmdBindDescriptorSets);
126 GET_DEVICE_PROC(CmdBindIndexBuffer);
127 GET_DEVICE_PROC(CmdBindPipeline);
128 GET_DEVICE_PROC(CmdBindVertexBuffers);
129 GET_DEVICE_PROC(CmdBlitImage);
130 GET_DEVICE_PROC(CmdClearAttachments);
131 GET_DEVICE_PROC(CmdClearColorImage);
132 GET_DEVICE_PROC(CmdClearDepthStencilImage);
133 GET_DEVICE_PROC(CmdCopyBuffer);
134 GET_DEVICE_PROC(CmdCopyBufferToImage);
135 GET_DEVICE_PROC(CmdCopyImage);
136 GET_DEVICE_PROC(CmdCopyImageToBuffer);
137 GET_DEVICE_PROC(CmdCopyQueryPoolResults);
138 GET_DEVICE_PROC(CmdDispatch);
139 GET_DEVICE_PROC(CmdDispatchIndirect);
140 GET_DEVICE_PROC(CmdDraw);
141 GET_DEVICE_PROC(CmdDrawIndexed);
142 GET_DEVICE_PROC(CmdDrawIndexedIndirect);
143 GET_DEVICE_PROC(CmdDrawIndirect);
144 GET_DEVICE_PROC(CmdEndQuery);
145 GET_DEVICE_PROC(CmdEndRenderPass);
146 GET_DEVICE_PROC(CmdExecuteCommands);
147 GET_DEVICE_PROC(CmdFillBuffer);
148 GET_DEVICE_PROC(CmdNextSubpass);
149 GET_DEVICE_PROC(CmdPipelineBarrier);
150 GET_DEVICE_PROC(CmdPushConstants);
151 GET_DEVICE_PROC(CmdResetEvent);
152 GET_DEVICE_PROC(CmdResetQueryPool);
153 GET_DEVICE_PROC(CmdResolveImage);
154 GET_DEVICE_PROC(CmdSetBlendConstants);
155 GET_DEVICE_PROC(CmdSetDepthBias);
156 GET_DEVICE_PROC(CmdSetDepthBounds);
157 GET_DEVICE_PROC(CmdSetEvent);
158 GET_DEVICE_PROC(CmdSetLineWidth);
159 GET_DEVICE_PROC(CmdSetScissor);
160 GET_DEVICE_PROC(CmdSetStencilCompareMask);
161 GET_DEVICE_PROC(CmdSetStencilReference);
162 GET_DEVICE_PROC(CmdSetStencilWriteMask);
163 GET_DEVICE_PROC(CmdSetViewport);
164 GET_DEVICE_PROC(CmdUpdateBuffer);
165 GET_DEVICE_PROC(CmdWaitEvents);
166 GET_DEVICE_PROC(CmdWriteTimestamp);
167 GET_DEVICE_PROC(CreateBuffer);
168 GET_DEVICE_PROC(CreateBufferView);
169 GET_DEVICE_PROC(CreateCommandPool);
170 GET_DEVICE_PROC(CreateComputePipelines);
171 GET_DEVICE_PROC(CreateDescriptorPool);
172 GET_DEVICE_PROC(CreateDescriptorSetLayout);
173 GET_DEVICE_PROC(CreateEvent);
174 GET_DEVICE_PROC(CreateFence);
175 GET_DEVICE_PROC(CreateFramebuffer);
176 GET_DEVICE_PROC(CreateGraphicsPipelines);
177 GET_DEVICE_PROC(CreateImage);
178 GET_DEVICE_PROC(CreateImageView);
179 GET_DEVICE_PROC(CreatePipelineCache);
180 GET_DEVICE_PROC(CreatePipelineLayout);
181 GET_DEVICE_PROC(CreateQueryPool);
182 GET_DEVICE_PROC(CreateRenderPass);
183 GET_DEVICE_PROC(CreateSampler);
184 GET_DEVICE_PROC(CreateSemaphore);
185 GET_DEVICE_PROC(CreateShaderModule);
186 GET_DEVICE_PROC(DestroyBuffer);
187 GET_DEVICE_PROC(DestroyBufferView);
188 GET_DEVICE_PROC(DestroyCommandPool);
189 GET_DEVICE_PROC(DestroyDescriptorPool);
190 GET_DEVICE_PROC(DestroyDescriptorSetLayout);
191 GET_DEVICE_PROC(DestroyEvent);
192 GET_DEVICE_PROC(DestroyFence);
193 GET_DEVICE_PROC(DestroyFramebuffer);
194 GET_DEVICE_PROC(DestroyImage);
195 GET_DEVICE_PROC(DestroyImageView);
196 GET_DEVICE_PROC(DestroyPipeline);
197 GET_DEVICE_PROC(DestroyPipelineCache);
198 GET_DEVICE_PROC(DestroyPipelineLayout);
199 GET_DEVICE_PROC(DestroyQueryPool);
200 GET_DEVICE_PROC(DestroyRenderPass);
201 GET_DEVICE_PROC(DestroySampler);
202 GET_DEVICE_PROC(DestroySemaphore);
203 GET_DEVICE_PROC(DestroyShaderModule);
204 GET_DEVICE_PROC(DeviceWaitIdle);
205 GET_DEVICE_PROC(EndCommandBuffer);
206 GET_DEVICE_PROC(FlushMappedMemoryRanges);
207 GET_DEVICE_PROC(FreeCommandBuffers);
208 GET_DEVICE_PROC(FreeDescriptorSets);
209 GET_DEVICE_PROC(FreeMemory);
210 GET_DEVICE_PROC(GetBufferMemoryRequirements);
211 GET_DEVICE_PROC(GetDeviceMemoryCommitment);
212 GET_DEVICE_PROC(GetDeviceQueue);
213 GET_DEVICE_PROC(GetEventStatus);
214 GET_DEVICE_PROC(GetFenceStatus);
215 GET_DEVICE_PROC(GetImageMemoryRequirements);
216 GET_DEVICE_PROC(GetImageSparseMemoryRequirements);
217 GET_DEVICE_PROC(GetImageSubresourceLayout);
218 GET_DEVICE_PROC(GetPipelineCacheData);
219 GET_DEVICE_PROC(GetQueryPoolResults);
220 GET_DEVICE_PROC(GetRenderAreaGranularity);
221 GET_DEVICE_PROC(InvalidateMappedMemoryRanges);
222 GET_DEVICE_PROC(MapMemory);
223 GET_DEVICE_PROC(MergePipelineCaches);
224 GET_DEVICE_PROC(QueueBindSparse);
225 GET_DEVICE_PROC(QueueSubmit);
226 GET_DEVICE_PROC(QueueWaitIdle);
227 GET_DEVICE_PROC(ResetCommandBuffer);
228 GET_DEVICE_PROC(ResetCommandPool);
229 GET_DEVICE_PROC(ResetDescriptorPool);
230 GET_DEVICE_PROC(ResetEvent);
231 GET_DEVICE_PROC(ResetFences);
232 GET_DEVICE_PROC(SetEvent);
233 GET_DEVICE_PROC(UnmapMemory);
234 GET_DEVICE_PROC(UpdateDescriptorSets);
235 GET_DEVICE_PROC(WaitForFences);
236
Brandon Jones11d32c82019-02-20 20:21:00 +0000237 if (usedKnobs.debugMarker) {
238 GET_DEVICE_PROC(CmdDebugMarkerBeginEXT);
239 GET_DEVICE_PROC(CmdDebugMarkerEndEXT);
240 GET_DEVICE_PROC(CmdDebugMarkerInsertEXT);
241 }
242
Idan Raiteref4f3bd2019-08-02 18:10:38 +0000243 if (usedKnobs.externalMemoryFD) {
244 GET_DEVICE_PROC(GetMemoryFdKHR);
245 GET_DEVICE_PROC(GetMemoryFdPropertiesKHR);
246 }
247
248 if (usedKnobs.externalSemaphoreFD) {
249 GET_DEVICE_PROC(ImportSemaphoreFdKHR);
250 GET_DEVICE_PROC(GetSemaphoreFdKHR);
251 }
252
Corentin Wallez02162332017-11-21 12:52:03 -0500253 if (usedKnobs.swapchain) {
254 GET_DEVICE_PROC(CreateSwapchainKHR);
255 GET_DEVICE_PROC(DestroySwapchainKHR);
256 GET_DEVICE_PROC(GetSwapchainImagesKHR);
257 GET_DEVICE_PROC(AcquireNextImageKHR);
258 GET_DEVICE_PROC(QueuePresentKHR);
259 }
260
Corentin Wallez85df07a2018-12-03 12:49:56 +0000261 return {};
Corentin Wallez6d9a3b82017-11-20 10:51:23 -0500262 }
263
Corentin Wallez49a65d02018-07-24 16:45:45 +0200264}} // namespace dawn_native::vulkan