• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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 "VkGetProcAddress.h"
16 
17 #include <unordered_map>
18 #include <string>
19 
20 namespace vk
21 {
22 
23 #define MAKE_VULKAN_GLOBAL_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) }
24 static const std::unordered_map<std::string, PFN_vkVoidFunction> globalFunctionPointers =
25 {
26 	MAKE_VULKAN_GLOBAL_ENTRY(vkCreateInstance),
27 	MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceExtensionProperties),
28 	MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceLayerProperties),
29 	MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceVersion),
30 };
31 #undef MAKE_VULKAN_GLOBAL_ENTRY
32 
33 #define MAKE_VULKAN_INSTANCE_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) }
34 static const std::unordered_map<std::string, PFN_vkVoidFunction> instanceFunctionPointers =
35 {
36 	MAKE_VULKAN_INSTANCE_ENTRY(vkDestroyInstance),
37 	MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDevices),
38 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures),
39 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties),
40 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties),
41 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties),
42 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties),
43 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties),
44 	MAKE_VULKAN_INSTANCE_ENTRY(vkCreateDevice),
45 	MAKE_VULKAN_INSTANCE_ENTRY(vkEnumerateDeviceExtensionProperties),
46 	MAKE_VULKAN_INSTANCE_ENTRY(vkEnumerateDeviceLayerProperties),
47 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties),
48 	MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDeviceGroups),
49 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures2),
50 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties2),
51 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties2),
52 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties2),
53 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties2),
54 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties2),
55 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties2),
56 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalBufferProperties),
57 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalFenceProperties),
58 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalSemaphoreProperties),
59 	// VK_KHR_device_group_creation
60 	MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDeviceGroupsKHR),
61 	// VK_KHR_external_fence_capabilities
62 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalFencePropertiesKHR),
63 	// VK_KHR_external_memory_capabilities
64 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalBufferPropertiesKHR),
65 	// VK_KHR_external_semaphore_capabilities
66 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR),
67 	// VK_KHR_get_physical_device_properties2
68 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures2KHR),
69 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties2KHR),
70 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties2KHR),
71 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties2KHR),
72 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties2KHR),
73 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties2KHR),
74 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties2KHR),
75 };
76 #undef MAKE_VULKAN_GLOBAL_ENTRY
77 
78 #define MAKE_VULKAN_DEVICE_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) }
79 static const std::unordered_map<std::string, PFN_vkVoidFunction> deviceFunctionPointers =
80 {
81 	MAKE_VULKAN_DEVICE_ENTRY(vkGetInstanceProcAddr),
82 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceProcAddr),
83 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDevice),
84 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceQueue),
85 	MAKE_VULKAN_DEVICE_ENTRY(vkQueueSubmit),
86 	MAKE_VULKAN_DEVICE_ENTRY(vkQueueWaitIdle),
87 	MAKE_VULKAN_DEVICE_ENTRY(vkDeviceWaitIdle),
88 	MAKE_VULKAN_DEVICE_ENTRY(vkAllocateMemory),
89 	MAKE_VULKAN_DEVICE_ENTRY(vkFreeMemory),
90 	MAKE_VULKAN_DEVICE_ENTRY(vkMapMemory),
91 	MAKE_VULKAN_DEVICE_ENTRY(vkUnmapMemory),
92 	MAKE_VULKAN_DEVICE_ENTRY(vkFlushMappedMemoryRanges),
93 	MAKE_VULKAN_DEVICE_ENTRY(vkInvalidateMappedMemoryRanges),
94 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceMemoryCommitment),
95 	MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory),
96 	MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory),
97 	MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements),
98 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements),
99 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements),
100 	MAKE_VULKAN_DEVICE_ENTRY(vkQueueBindSparse),
101 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateFence),
102 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyFence),
103 	MAKE_VULKAN_DEVICE_ENTRY(vkResetFences),
104 	MAKE_VULKAN_DEVICE_ENTRY(vkGetFenceStatus),
105 	MAKE_VULKAN_DEVICE_ENTRY(vkWaitForFences),
106 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateSemaphore),
107 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroySemaphore),
108 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateEvent),
109 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyEvent),
110 	MAKE_VULKAN_DEVICE_ENTRY(vkGetEventStatus),
111 	MAKE_VULKAN_DEVICE_ENTRY(vkSetEvent),
112 	MAKE_VULKAN_DEVICE_ENTRY(vkResetEvent),
113 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateQueryPool),
114 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyQueryPool),
115 	MAKE_VULKAN_DEVICE_ENTRY(vkGetQueryPoolResults),
116 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateBuffer),
117 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyBuffer),
118 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateBufferView),
119 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyBufferView),
120 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateImage),
121 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyImage),
122 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSubresourceLayout),
123 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateImageView),
124 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyImageView),
125 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateShaderModule),
126 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyShaderModule),
127 	MAKE_VULKAN_DEVICE_ENTRY(vkCreatePipelineCache),
128 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipelineCache),
129 	MAKE_VULKAN_DEVICE_ENTRY(vkGetPipelineCacheData),
130 	MAKE_VULKAN_DEVICE_ENTRY(vkMergePipelineCaches),
131 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateGraphicsPipelines),
132 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateComputePipelines),
133 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipeline),
134 	MAKE_VULKAN_DEVICE_ENTRY(vkCreatePipelineLayout),
135 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipelineLayout),
136 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateSampler),
137 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroySampler),
138 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorSetLayout),
139 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorSetLayout),
140 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorPool),
141 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorPool),
142 	MAKE_VULKAN_DEVICE_ENTRY(vkResetDescriptorPool),
143 	MAKE_VULKAN_DEVICE_ENTRY(vkAllocateDescriptorSets),
144 	MAKE_VULKAN_DEVICE_ENTRY(vkFreeDescriptorSets),
145 	MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSets),
146 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateFramebuffer),
147 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyFramebuffer),
148 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateRenderPass),
149 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyRenderPass),
150 	MAKE_VULKAN_DEVICE_ENTRY(vkGetRenderAreaGranularity),
151 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateCommandPool),
152 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyCommandPool),
153 	MAKE_VULKAN_DEVICE_ENTRY(vkResetCommandPool),
154 	MAKE_VULKAN_DEVICE_ENTRY(vkAllocateCommandBuffers),
155 	MAKE_VULKAN_DEVICE_ENTRY(vkFreeCommandBuffers),
156 	MAKE_VULKAN_DEVICE_ENTRY(vkBeginCommandBuffer),
157 	MAKE_VULKAN_DEVICE_ENTRY(vkEndCommandBuffer),
158 	MAKE_VULKAN_DEVICE_ENTRY(vkResetCommandBuffer),
159 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindPipeline),
160 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetViewport),
161 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetScissor),
162 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetLineWidth),
163 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDepthBias),
164 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetBlendConstants),
165 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDepthBounds),
166 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilCompareMask),
167 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilWriteMask),
168 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilReference),
169 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindDescriptorSets),
170 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindIndexBuffer),
171 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindVertexBuffers),
172 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDraw),
173 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndexed),
174 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndirect),
175 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndexedIndirect),
176 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatch),
177 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchIndirect),
178 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyBuffer),
179 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyImage),
180 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBlitImage),
181 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyBufferToImage),
182 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyImageToBuffer),
183 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdUpdateBuffer),
184 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdFillBuffer),
185 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearColorImage),
186 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearDepthStencilImage),
187 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearAttachments),
188 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdResolveImage),
189 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetEvent),
190 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdResetEvent),
191 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdWaitEvents),
192 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdPipelineBarrier),
193 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBeginQuery),
194 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdEndQuery),
195 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdResetQueryPool),
196 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdWriteTimestamp),
197 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyQueryPoolResults),
198 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdPushConstants),
199 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdBeginRenderPass),
200 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdNextSubpass),
201 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdEndRenderPass),
202 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdExecuteCommands),
203 	MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory2),
204 	MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory2),
205 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupPeerMemoryFeatures),
206 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDeviceMask),
207 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchBase),
208 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements2),
209 	MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements2),
210 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements2),
211 	MAKE_VULKAN_DEVICE_ENTRY(vkTrimCommandPool),
212 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceQueue2),
213 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateSamplerYcbcrConversion),
214 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroySamplerYcbcrConversion),
215 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorUpdateTemplate),
216 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorUpdateTemplate),
217 	MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSetWithTemplate),
218 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDescriptorSetLayoutSupport),
219 	// VK_KHR_descriptor_update_template
220 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorUpdateTemplateKHR),
221 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorUpdateTemplateKHR),
222 	MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSetWithTemplateKHR),
223 	// VK_KHR_device_group
224 	MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupPeerMemoryFeaturesKHR),
225 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDeviceMaskKHR),
226 	MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchBaseKHR),
227 	// VK_KHR_maintenance1
228 	MAKE_VULKAN_DEVICE_ENTRY(vkTrimCommandPoolKHR),
229 	// VK_KHR_sampler_ycbcr_conversion
230 	MAKE_VULKAN_DEVICE_ENTRY(vkCreateSamplerYcbcrConversionKHR),
231 	MAKE_VULKAN_DEVICE_ENTRY(vkDestroySamplerYcbcrConversionKHR),
232 	// VK_KHR_bind_memory2
233 	MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory2KHR),
234 	MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory2KHR),
235 	// VK_KHR_get_memory_requirements2
236 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements2KHR),
237 	MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements2KHR),
238 	MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements2KHR),
239 	// VK_KHR_maintenance3
240 	MAKE_VULKAN_INSTANCE_ENTRY(vkGetDescriptorSetLayoutSupportKHR),
241 };
242 #undef MAKE_VULKAN_DEVICE_ENTRY
243 
GetInstanceProcAddr(VkInstance instance,const char * pName)244 PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* pName)
245 {
246 	auto globalFunction = globalFunctionPointers.find(std::string(pName));
247 	if(globalFunction != globalFunctionPointers.end())
248 	{
249 		return globalFunction->second;
250 	}
251 
252 	if(instance != VK_NULL_HANDLE)
253 	{
254 		auto instanceFunction = instanceFunctionPointers.find(std::string(pName));
255 		if(instanceFunction != instanceFunctionPointers.end())
256 		{
257 			return instanceFunction->second;
258 		}
259 
260 		auto deviceFunction = deviceFunctionPointers.find(std::string(pName));
261 		if(deviceFunction != deviceFunctionPointers.end())
262 		{
263 			return deviceFunction->second;
264 		}
265 	}
266 
267 	return nullptr;
268 }
269 
GetDeviceProcAddr(VkDevice device,const char * pName)270 PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* pName)
271 {
272 	auto deviceFunction = deviceFunctionPointers.find(std::string(pName));
273 	if(deviceFunction != deviceFunctionPointers.end())
274 	{
275 		return deviceFunction->second;
276 	}
277 
278 	return nullptr;
279 }
280 
281 }
282