blob: 886b8d155ee67817f22afaedd0ff0dbb5ef75d95 [file] [log] [blame]
Corentin Wallezf2adf6d2017-11-17 17:52:04 -05001// Copyright 2017 The NXT 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#include "backend/vulkan/VulkanFunctions.h"
16
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050017#include "backend/vulkan/VulkanInfo.h"
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050018#include "common/DynamicLib.h"
19
Corentin Wallez23b27a22017-11-24 14:18:09 -050020namespace backend { 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) { \
25 return false; \
26 }
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050027
28 bool VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) {
29 if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) {
30 return false;
31 }
32
33 GET_GLOBAL_PROC(CreateInstance);
Corentin Wallezf2adf6d2017-11-17 17:52:04 -050034 GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties);
35 GET_GLOBAL_PROC(EnumerateInstanceLayerProperties);
36
37 return true;
38 }
39
Corentin Wallez23b27a22017-11-24 14:18:09 -050040#define GET_INSTANCE_PROC(name) \
41 name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #name)); \
42 if (name == nullptr) { \
43 return false; \
44 }
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050045
Corentin Wallez23b27a22017-11-24 14:18:09 -050046 bool VulkanFunctions::LoadInstanceProcs(VkInstance instance,
47 const VulkanGlobalKnobs& usedKnobs) {
48 // Load this proc first so that we can destroy the instance even if some other
49 // GET_INSTANCE_PROC fails
Corentin Wallez02162332017-11-21 12:52:03 -050050 GET_INSTANCE_PROC(DestroyInstance);
51
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050052 GET_INSTANCE_PROC(CreateDevice);
53 GET_INSTANCE_PROC(DestroyDevice);
54 GET_INSTANCE_PROC(EnumerateDeviceExtensionProperties);
55 GET_INSTANCE_PROC(EnumerateDeviceLayerProperties);
56 GET_INSTANCE_PROC(EnumeratePhysicalDevices);
Corentin Wallez02162332017-11-21 12:52:03 -050057 GET_INSTANCE_PROC(GetDeviceProcAddr);
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050058 GET_INSTANCE_PROC(GetPhysicalDeviceFeatures);
59 GET_INSTANCE_PROC(GetPhysicalDeviceFormatProperties);
60 GET_INSTANCE_PROC(GetPhysicalDeviceImageFormatProperties);
61 GET_INSTANCE_PROC(GetPhysicalDeviceMemoryProperties);
62 GET_INSTANCE_PROC(GetPhysicalDeviceProperties);
63 GET_INSTANCE_PROC(GetPhysicalDeviceQueueFamilyProperties);
64 GET_INSTANCE_PROC(GetPhysicalDeviceSparseImageFormatProperties);
65
Corentin Wallez02162332017-11-21 12:52:03 -050066 if (usedKnobs.debugReport) {
Corentin Wallez6d9a3b82017-11-20 10:51:23 -050067 GET_INSTANCE_PROC(CreateDebugReportCallbackEXT);
68 GET_INSTANCE_PROC(DebugReportMessageEXT);
69 GET_INSTANCE_PROC(DestroyDebugReportCallbackEXT);
70 }
71
Corentin Wallez02162332017-11-21 12:52:03 -050072 if (usedKnobs.surface) {
73 GET_INSTANCE_PROC(DestroySurfaceKHR);
74 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceSupportKHR);
75 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
76 GET_INSTANCE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
77 GET_INSTANCE_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
78 }
79
80 return true;
81 }
82
Corentin Wallez23b27a22017-11-24 14:18:09 -050083#define GET_DEVICE_PROC(name) \
84 name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
85 if (name == nullptr) { \
86 return false; \
87 }
Corentin Wallez02162332017-11-21 12:52:03 -050088
89 bool VulkanFunctions::LoadDeviceProcs(VkDevice device, const VulkanDeviceKnobs& usedKnobs) {
90 GET_DEVICE_PROC(AllocateCommandBuffers);
91 GET_DEVICE_PROC(AllocateDescriptorSets);
92 GET_DEVICE_PROC(AllocateMemory);
93 GET_DEVICE_PROC(BeginCommandBuffer);
94 GET_DEVICE_PROC(BindBufferMemory);
95 GET_DEVICE_PROC(BindImageMemory);
96 GET_DEVICE_PROC(CmdBeginQuery);
97 GET_DEVICE_PROC(CmdBeginRenderPass);
98 GET_DEVICE_PROC(CmdBindDescriptorSets);
99 GET_DEVICE_PROC(CmdBindIndexBuffer);
100 GET_DEVICE_PROC(CmdBindPipeline);
101 GET_DEVICE_PROC(CmdBindVertexBuffers);
102 GET_DEVICE_PROC(CmdBlitImage);
103 GET_DEVICE_PROC(CmdClearAttachments);
104 GET_DEVICE_PROC(CmdClearColorImage);
105 GET_DEVICE_PROC(CmdClearDepthStencilImage);
106 GET_DEVICE_PROC(CmdCopyBuffer);
107 GET_DEVICE_PROC(CmdCopyBufferToImage);
108 GET_DEVICE_PROC(CmdCopyImage);
109 GET_DEVICE_PROC(CmdCopyImageToBuffer);
110 GET_DEVICE_PROC(CmdCopyQueryPoolResults);
111 GET_DEVICE_PROC(CmdDispatch);
112 GET_DEVICE_PROC(CmdDispatchIndirect);
113 GET_DEVICE_PROC(CmdDraw);
114 GET_DEVICE_PROC(CmdDrawIndexed);
115 GET_DEVICE_PROC(CmdDrawIndexedIndirect);
116 GET_DEVICE_PROC(CmdDrawIndirect);
117 GET_DEVICE_PROC(CmdEndQuery);
118 GET_DEVICE_PROC(CmdEndRenderPass);
119 GET_DEVICE_PROC(CmdExecuteCommands);
120 GET_DEVICE_PROC(CmdFillBuffer);
121 GET_DEVICE_PROC(CmdNextSubpass);
122 GET_DEVICE_PROC(CmdPipelineBarrier);
123 GET_DEVICE_PROC(CmdPushConstants);
124 GET_DEVICE_PROC(CmdResetEvent);
125 GET_DEVICE_PROC(CmdResetQueryPool);
126 GET_DEVICE_PROC(CmdResolveImage);
127 GET_DEVICE_PROC(CmdSetBlendConstants);
128 GET_DEVICE_PROC(CmdSetDepthBias);
129 GET_DEVICE_PROC(CmdSetDepthBounds);
130 GET_DEVICE_PROC(CmdSetEvent);
131 GET_DEVICE_PROC(CmdSetLineWidth);
132 GET_DEVICE_PROC(CmdSetScissor);
133 GET_DEVICE_PROC(CmdSetStencilCompareMask);
134 GET_DEVICE_PROC(CmdSetStencilReference);
135 GET_DEVICE_PROC(CmdSetStencilWriteMask);
136 GET_DEVICE_PROC(CmdSetViewport);
137 GET_DEVICE_PROC(CmdUpdateBuffer);
138 GET_DEVICE_PROC(CmdWaitEvents);
139 GET_DEVICE_PROC(CmdWriteTimestamp);
140 GET_DEVICE_PROC(CreateBuffer);
141 GET_DEVICE_PROC(CreateBufferView);
142 GET_DEVICE_PROC(CreateCommandPool);
143 GET_DEVICE_PROC(CreateComputePipelines);
144 GET_DEVICE_PROC(CreateDescriptorPool);
145 GET_DEVICE_PROC(CreateDescriptorSetLayout);
146 GET_DEVICE_PROC(CreateEvent);
147 GET_DEVICE_PROC(CreateFence);
148 GET_DEVICE_PROC(CreateFramebuffer);
149 GET_DEVICE_PROC(CreateGraphicsPipelines);
150 GET_DEVICE_PROC(CreateImage);
151 GET_DEVICE_PROC(CreateImageView);
152 GET_DEVICE_PROC(CreatePipelineCache);
153 GET_DEVICE_PROC(CreatePipelineLayout);
154 GET_DEVICE_PROC(CreateQueryPool);
155 GET_DEVICE_PROC(CreateRenderPass);
156 GET_DEVICE_PROC(CreateSampler);
157 GET_DEVICE_PROC(CreateSemaphore);
158 GET_DEVICE_PROC(CreateShaderModule);
159 GET_DEVICE_PROC(DestroyBuffer);
160 GET_DEVICE_PROC(DestroyBufferView);
161 GET_DEVICE_PROC(DestroyCommandPool);
162 GET_DEVICE_PROC(DestroyDescriptorPool);
163 GET_DEVICE_PROC(DestroyDescriptorSetLayout);
164 GET_DEVICE_PROC(DestroyEvent);
165 GET_DEVICE_PROC(DestroyFence);
166 GET_DEVICE_PROC(DestroyFramebuffer);
167 GET_DEVICE_PROC(DestroyImage);
168 GET_DEVICE_PROC(DestroyImageView);
169 GET_DEVICE_PROC(DestroyPipeline);
170 GET_DEVICE_PROC(DestroyPipelineCache);
171 GET_DEVICE_PROC(DestroyPipelineLayout);
172 GET_DEVICE_PROC(DestroyQueryPool);
173 GET_DEVICE_PROC(DestroyRenderPass);
174 GET_DEVICE_PROC(DestroySampler);
175 GET_DEVICE_PROC(DestroySemaphore);
176 GET_DEVICE_PROC(DestroyShaderModule);
177 GET_DEVICE_PROC(DeviceWaitIdle);
178 GET_DEVICE_PROC(EndCommandBuffer);
179 GET_DEVICE_PROC(FlushMappedMemoryRanges);
180 GET_DEVICE_PROC(FreeCommandBuffers);
181 GET_DEVICE_PROC(FreeDescriptorSets);
182 GET_DEVICE_PROC(FreeMemory);
183 GET_DEVICE_PROC(GetBufferMemoryRequirements);
184 GET_DEVICE_PROC(GetDeviceMemoryCommitment);
185 GET_DEVICE_PROC(GetDeviceQueue);
186 GET_DEVICE_PROC(GetEventStatus);
187 GET_DEVICE_PROC(GetFenceStatus);
188 GET_DEVICE_PROC(GetImageMemoryRequirements);
189 GET_DEVICE_PROC(GetImageSparseMemoryRequirements);
190 GET_DEVICE_PROC(GetImageSubresourceLayout);
191 GET_DEVICE_PROC(GetPipelineCacheData);
192 GET_DEVICE_PROC(GetQueryPoolResults);
193 GET_DEVICE_PROC(GetRenderAreaGranularity);
194 GET_DEVICE_PROC(InvalidateMappedMemoryRanges);
195 GET_DEVICE_PROC(MapMemory);
196 GET_DEVICE_PROC(MergePipelineCaches);
197 GET_DEVICE_PROC(QueueBindSparse);
198 GET_DEVICE_PROC(QueueSubmit);
199 GET_DEVICE_PROC(QueueWaitIdle);
200 GET_DEVICE_PROC(ResetCommandBuffer);
201 GET_DEVICE_PROC(ResetCommandPool);
202 GET_DEVICE_PROC(ResetDescriptorPool);
203 GET_DEVICE_PROC(ResetEvent);
204 GET_DEVICE_PROC(ResetFences);
205 GET_DEVICE_PROC(SetEvent);
206 GET_DEVICE_PROC(UnmapMemory);
207 GET_DEVICE_PROC(UpdateDescriptorSets);
208 GET_DEVICE_PROC(WaitForFences);
209
210 if (usedKnobs.swapchain) {
211 GET_DEVICE_PROC(CreateSwapchainKHR);
212 GET_DEVICE_PROC(DestroySwapchainKHR);
213 GET_DEVICE_PROC(GetSwapchainImagesKHR);
214 GET_DEVICE_PROC(AcquireNextImageKHR);
215 GET_DEVICE_PROC(QueuePresentKHR);
216 }
217
Corentin Wallez6d9a3b82017-11-20 10:51:23 -0500218 return true;
219 }
220
Corentin Wallez23b27a22017-11-24 14:18:09 -0500221}} // namespace backend::vulkan