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