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 | #include "VkDevice.hpp" |
17 | |
18 | #include <unordered_map> |
19 | #include <string> |
20 | #include <vector> |
21 | |
22 | #ifdef __ANDROID__ |
23 | #include <cerrno> |
24 | #include <hardware/hwvulkan.h> |
25 | #include <vulkan/vk_android_native_buffer.h> |
26 | #endif |
27 | |
28 | namespace vk |
29 | { |
30 | |
31 | #define MAKE_VULKAN_GLOBAL_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) } |
32 | static const std::unordered_map<std::string, PFN_vkVoidFunction> globalFunctionPointers = |
33 | { |
34 | MAKE_VULKAN_GLOBAL_ENTRY(vkCreateInstance), |
35 | MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceExtensionProperties), |
36 | MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceLayerProperties), |
37 | MAKE_VULKAN_GLOBAL_ENTRY(vkEnumerateInstanceVersion), |
38 | }; |
39 | #undef MAKE_VULKAN_GLOBAL_ENTRY |
40 | |
41 | #define MAKE_VULKAN_INSTANCE_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) } |
42 | static const std::unordered_map<std::string, PFN_vkVoidFunction> instanceFunctionPointers = |
43 | { |
44 | MAKE_VULKAN_INSTANCE_ENTRY(vkDestroyInstance), |
45 | MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDevices), |
46 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures), |
47 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties), |
48 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties), |
49 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties), |
50 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties), |
51 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties), |
52 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateDevice), |
53 | MAKE_VULKAN_INSTANCE_ENTRY(vkEnumerateDeviceExtensionProperties), |
54 | MAKE_VULKAN_INSTANCE_ENTRY(vkEnumerateDeviceLayerProperties), |
55 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties), |
56 | MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDeviceGroups), |
57 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures2), |
58 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties2), |
59 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties2), |
60 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties2), |
61 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties2), |
62 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties2), |
63 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties2), |
64 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalBufferProperties), |
65 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalFenceProperties), |
66 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalSemaphoreProperties), |
67 | // VK_KHR_device_group_creation |
68 | MAKE_VULKAN_INSTANCE_ENTRY(vkEnumeratePhysicalDeviceGroupsKHR), |
69 | // VK_KHR_external_fence_capabilities |
70 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalFencePropertiesKHR), |
71 | // VK_KHR_external_memory_capabilities |
72 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalBufferPropertiesKHR), |
73 | // VK_KHR_external_semaphore_capabilities |
74 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR), |
75 | // VK_KHR_get_physical_device_properties2 |
76 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFeatures2KHR), |
77 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceProperties2KHR), |
78 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceFormatProperties2KHR), |
79 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceImageFormatProperties2KHR), |
80 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceQueueFamilyProperties2KHR), |
81 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceMemoryProperties2KHR), |
82 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSparseImageFormatProperties2KHR), |
83 | #ifndef __ANDROID__ |
84 | // VK_KHR_surface |
85 | MAKE_VULKAN_INSTANCE_ENTRY(vkDestroySurfaceKHR), |
86 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSurfaceSupportKHR), |
87 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSurfaceCapabilitiesKHR), |
88 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSurfaceFormatsKHR), |
89 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceSurfacePresentModesKHR), |
90 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDevicePresentRectanglesKHR), |
91 | #endif |
92 | #ifdef VK_USE_PLATFORM_XCB_KHR |
93 | // VK_KHR_Xcb_surface |
94 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateXcbSurfaceKHR), |
95 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceXcbPresentationSupportKHR), |
96 | #endif |
97 | #ifdef VK_USE_PLATFORM_XLIB_KHR |
98 | // VK_KHR_xlib_surface |
99 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateXlibSurfaceKHR), |
100 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceXlibPresentationSupportKHR), |
101 | #endif |
102 | #ifdef VK_USE_PLATFORM_MACOS_MVK |
103 | // VK_MVK_macos_surface |
104 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateMacOSSurfaceMVK), |
105 | #endif |
106 | #ifdef VK_USE_PLATFORM_METAL_EXT |
107 | // VK_EXT_metal_surface |
108 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateMetalSurfaceEXT), |
109 | #endif |
110 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
111 | // VK_KHR_win32_surface |
112 | MAKE_VULKAN_INSTANCE_ENTRY(vkCreateWin32SurfaceKHR), |
113 | MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceWin32PresentationSupportKHR), |
114 | #endif |
115 | }; |
116 | #undef MAKE_VULKAN_INSTANCE_ENTRY |
117 | |
118 | #define MAKE_VULKAN_DEVICE_ENTRY(aFunction) { #aFunction, reinterpret_cast<PFN_vkVoidFunction>(aFunction) } |
119 | static const std::unordered_map<std::string, PFN_vkVoidFunction> deviceFunctionPointers = |
120 | { |
121 | MAKE_VULKAN_DEVICE_ENTRY(vkGetInstanceProcAddr), |
122 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceProcAddr), |
123 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDevice), |
124 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceQueue), |
125 | MAKE_VULKAN_DEVICE_ENTRY(vkQueueSubmit), |
126 | MAKE_VULKAN_DEVICE_ENTRY(vkQueueWaitIdle), |
127 | MAKE_VULKAN_DEVICE_ENTRY(vkDeviceWaitIdle), |
128 | MAKE_VULKAN_DEVICE_ENTRY(vkAllocateMemory), |
129 | MAKE_VULKAN_DEVICE_ENTRY(vkFreeMemory), |
130 | MAKE_VULKAN_DEVICE_ENTRY(vkMapMemory), |
131 | MAKE_VULKAN_DEVICE_ENTRY(vkUnmapMemory), |
132 | MAKE_VULKAN_DEVICE_ENTRY(vkFlushMappedMemoryRanges), |
133 | MAKE_VULKAN_DEVICE_ENTRY(vkInvalidateMappedMemoryRanges), |
134 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceMemoryCommitment), |
135 | MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory), |
136 | MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory), |
137 | MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements), |
138 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements), |
139 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements), |
140 | MAKE_VULKAN_DEVICE_ENTRY(vkQueueBindSparse), |
141 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateFence), |
142 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyFence), |
143 | MAKE_VULKAN_DEVICE_ENTRY(vkResetFences), |
144 | MAKE_VULKAN_DEVICE_ENTRY(vkGetFenceStatus), |
145 | MAKE_VULKAN_DEVICE_ENTRY(vkWaitForFences), |
146 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateSemaphore), |
147 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroySemaphore), |
148 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateEvent), |
149 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyEvent), |
150 | MAKE_VULKAN_DEVICE_ENTRY(vkGetEventStatus), |
151 | MAKE_VULKAN_DEVICE_ENTRY(vkSetEvent), |
152 | MAKE_VULKAN_DEVICE_ENTRY(vkResetEvent), |
153 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateQueryPool), |
154 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyQueryPool), |
155 | MAKE_VULKAN_DEVICE_ENTRY(vkGetQueryPoolResults), |
156 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateBuffer), |
157 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyBuffer), |
158 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateBufferView), |
159 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyBufferView), |
160 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateImage), |
161 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyImage), |
162 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSubresourceLayout), |
163 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateImageView), |
164 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyImageView), |
165 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateShaderModule), |
166 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyShaderModule), |
167 | MAKE_VULKAN_DEVICE_ENTRY(vkCreatePipelineCache), |
168 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipelineCache), |
169 | MAKE_VULKAN_DEVICE_ENTRY(vkGetPipelineCacheData), |
170 | MAKE_VULKAN_DEVICE_ENTRY(vkMergePipelineCaches), |
171 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateGraphicsPipelines), |
172 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateComputePipelines), |
173 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipeline), |
174 | MAKE_VULKAN_DEVICE_ENTRY(vkCreatePipelineLayout), |
175 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyPipelineLayout), |
176 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateSampler), |
177 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroySampler), |
178 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorSetLayout), |
179 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorSetLayout), |
180 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorPool), |
181 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorPool), |
182 | MAKE_VULKAN_DEVICE_ENTRY(vkResetDescriptorPool), |
183 | MAKE_VULKAN_DEVICE_ENTRY(vkAllocateDescriptorSets), |
184 | MAKE_VULKAN_DEVICE_ENTRY(vkFreeDescriptorSets), |
185 | MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSets), |
186 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateFramebuffer), |
187 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyFramebuffer), |
188 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateRenderPass), |
189 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyRenderPass), |
190 | MAKE_VULKAN_DEVICE_ENTRY(vkGetRenderAreaGranularity), |
191 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateCommandPool), |
192 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyCommandPool), |
193 | MAKE_VULKAN_DEVICE_ENTRY(vkResetCommandPool), |
194 | MAKE_VULKAN_DEVICE_ENTRY(vkAllocateCommandBuffers), |
195 | MAKE_VULKAN_DEVICE_ENTRY(vkFreeCommandBuffers), |
196 | MAKE_VULKAN_DEVICE_ENTRY(vkBeginCommandBuffer), |
197 | MAKE_VULKAN_DEVICE_ENTRY(vkEndCommandBuffer), |
198 | MAKE_VULKAN_DEVICE_ENTRY(vkResetCommandBuffer), |
199 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindPipeline), |
200 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetViewport), |
201 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetScissor), |
202 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetLineWidth), |
203 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDepthBias), |
204 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetBlendConstants), |
205 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDepthBounds), |
206 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilCompareMask), |
207 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilWriteMask), |
208 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetStencilReference), |
209 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindDescriptorSets), |
210 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindIndexBuffer), |
211 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBindVertexBuffers), |
212 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDraw), |
213 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndexed), |
214 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndirect), |
215 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDrawIndexedIndirect), |
216 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatch), |
217 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchIndirect), |
218 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyBuffer), |
219 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyImage), |
220 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBlitImage), |
221 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyBufferToImage), |
222 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyImageToBuffer), |
223 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdUpdateBuffer), |
224 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdFillBuffer), |
225 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearColorImage), |
226 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearDepthStencilImage), |
227 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdClearAttachments), |
228 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdResolveImage), |
229 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetEvent), |
230 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdResetEvent), |
231 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdWaitEvents), |
232 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdPipelineBarrier), |
233 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBeginQuery), |
234 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdEndQuery), |
235 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdResetQueryPool), |
236 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdWriteTimestamp), |
237 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdCopyQueryPoolResults), |
238 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdPushConstants), |
239 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdBeginRenderPass), |
240 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdNextSubpass), |
241 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdEndRenderPass), |
242 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdExecuteCommands), |
243 | MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory2), |
244 | MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory2), |
245 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupPeerMemoryFeatures), |
246 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDeviceMask), |
247 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchBase), |
248 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements2), |
249 | MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements2), |
250 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements2), |
251 | MAKE_VULKAN_DEVICE_ENTRY(vkTrimCommandPool), |
252 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceQueue2), |
253 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateSamplerYcbcrConversion), |
254 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroySamplerYcbcrConversion), |
255 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorUpdateTemplate), |
256 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorUpdateTemplate), |
257 | MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSetWithTemplate), |
258 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDescriptorSetLayoutSupport), |
259 | #ifdef __ANDROID__ |
260 | MAKE_VULKAN_DEVICE_ENTRY(vkGetSwapchainGrallocUsageANDROID), |
261 | MAKE_VULKAN_DEVICE_ENTRY(vkGetSwapchainGrallocUsage2ANDROID), |
262 | MAKE_VULKAN_DEVICE_ENTRY(vkAcquireImageANDROID), |
263 | MAKE_VULKAN_DEVICE_ENTRY(vkQueueSignalReleaseImageANDROID), |
264 | #endif |
265 | }; |
266 | |
267 | static const std::vector<std::pair<const char*, std::unordered_map<std::string, PFN_vkVoidFunction>>> deviceExtensionFunctionPointers = |
268 | { |
269 | // VK_KHR_descriptor_update_template |
270 | { |
271 | VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, |
272 | { |
273 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateDescriptorUpdateTemplateKHR), |
274 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroyDescriptorUpdateTemplateKHR), |
275 | MAKE_VULKAN_DEVICE_ENTRY(vkUpdateDescriptorSetWithTemplateKHR), |
276 | } |
277 | }, |
278 | // VK_KHR_device_group |
279 | { |
280 | VK_KHR_DEVICE_GROUP_EXTENSION_NAME, |
281 | { |
282 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupPeerMemoryFeaturesKHR), |
283 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdSetDeviceMaskKHR), |
284 | MAKE_VULKAN_DEVICE_ENTRY(vkCmdDispatchBaseKHR), |
285 | } |
286 | }, |
287 | // VK_KHR_maintenance1 |
288 | { |
289 | VK_KHR_MAINTENANCE1_EXTENSION_NAME, |
290 | { |
291 | MAKE_VULKAN_DEVICE_ENTRY(vkTrimCommandPoolKHR), |
292 | } |
293 | }, |
294 | // VK_KHR_sampler_ycbcr_conversion |
295 | { |
296 | VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, |
297 | { |
298 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateSamplerYcbcrConversionKHR), |
299 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroySamplerYcbcrConversionKHR), |
300 | } |
301 | }, |
302 | // VK_KHR_bind_memory2 |
303 | { |
304 | VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, |
305 | { |
306 | MAKE_VULKAN_DEVICE_ENTRY(vkBindBufferMemory2KHR), |
307 | MAKE_VULKAN_DEVICE_ENTRY(vkBindImageMemory2KHR), |
308 | } |
309 | }, |
310 | // VK_KHR_get_memory_requirements2 |
311 | { |
312 | VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, |
313 | { |
314 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageMemoryRequirements2KHR), |
315 | MAKE_VULKAN_DEVICE_ENTRY(vkGetBufferMemoryRequirements2KHR), |
316 | MAKE_VULKAN_DEVICE_ENTRY(vkGetImageSparseMemoryRequirements2KHR), |
317 | } |
318 | }, |
319 | // VK_KHR_maintenance3 |
320 | { |
321 | VK_KHR_MAINTENANCE3_EXTENSION_NAME, |
322 | { |
323 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDescriptorSetLayoutSupportKHR), |
324 | } |
325 | }, |
326 | #ifndef __ANDROID__ |
327 | // VK_KHR_swapchain |
328 | { |
329 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
330 | { |
331 | MAKE_VULKAN_DEVICE_ENTRY(vkCreateSwapchainKHR), |
332 | MAKE_VULKAN_DEVICE_ENTRY(vkDestroySwapchainKHR), |
333 | MAKE_VULKAN_DEVICE_ENTRY(vkGetSwapchainImagesKHR), |
334 | MAKE_VULKAN_DEVICE_ENTRY(vkAcquireNextImageKHR), |
335 | MAKE_VULKAN_DEVICE_ENTRY(vkAcquireNextImage2KHR), |
336 | MAKE_VULKAN_DEVICE_ENTRY(vkQueuePresentKHR), |
337 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupPresentCapabilitiesKHR), |
338 | MAKE_VULKAN_DEVICE_ENTRY(vkGetDeviceGroupSurfacePresentModesKHR), |
339 | } |
340 | }, |
341 | #endif |
342 | |
343 | #if SWIFTSHADER_EXTERNAL_SEMAPHORE_LINUX_MEMFD |
344 | // VK_KHR_external_semaphore_fd |
345 | { |
346 | VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, |
347 | { |
348 | MAKE_VULKAN_DEVICE_ENTRY(vkGetSemaphoreFdKHR), |
349 | MAKE_VULKAN_DEVICE_ENTRY(vkImportSemaphoreFdKHR), |
350 | } |
351 | }, |
352 | #endif |
353 | |
354 | #if SWIFTSHADER_EXTERNAL_SEMAPHORE_ZIRCON_EVENT |
355 | // VK_FUCHSIA_external_semaphore |
356 | { |
357 | VK_FUCHSIA_EXTERNAL_SEMAPHORE_EXTENSION_NAME, |
358 | { |
359 | MAKE_VULKAN_DEVICE_ENTRY(vkGetSemaphoreZirconHandleFUCHSIA), |
360 | MAKE_VULKAN_DEVICE_ENTRY(vkImportSemaphoreZirconHandleFUCHSIA), |
361 | } |
362 | }, |
363 | #endif |
364 | |
365 | #if SWIFTSHADER_EXTERNAL_MEMORY_LINUX_MEMFD |
366 | // VK_KHR_external_memory_fd |
367 | { |
368 | VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, |
369 | { |
370 | MAKE_VULKAN_DEVICE_ENTRY(vkGetMemoryFdKHR), |
371 | MAKE_VULKAN_DEVICE_ENTRY(vkGetMemoryFdPropertiesKHR), |
372 | } |
373 | }, |
374 | #endif |
375 | }; |
376 | |
377 | #undef MAKE_VULKAN_DEVICE_ENTRY |
378 | |
379 | PFN_vkVoidFunction GetInstanceProcAddr(Instance* instance, const char* pName) |
380 | { |
381 | auto globalFunction = globalFunctionPointers.find(std::string(pName)); |
382 | if(globalFunction != globalFunctionPointers.end()) |
383 | { |
384 | return globalFunction->second; |
385 | } |
386 | |
387 | if(instance) |
388 | { |
389 | auto instanceFunction = instanceFunctionPointers.find(std::string(pName)); |
390 | if(instanceFunction != instanceFunctionPointers.end()) |
391 | { |
392 | return instanceFunction->second; |
393 | } |
394 | |
395 | auto deviceFunction = deviceFunctionPointers.find(std::string(pName)); |
396 | if(deviceFunction != deviceFunctionPointers.end()) |
397 | { |
398 | return deviceFunction->second; |
399 | } |
400 | |
401 | for(const auto& deviceExtensionFunctions : deviceExtensionFunctionPointers) |
402 | { |
403 | deviceFunction = deviceExtensionFunctions.second.find(std::string(pName)); |
404 | if(deviceFunction != deviceExtensionFunctions.second.end()) |
405 | { |
406 | return deviceFunction->second; |
407 | } |
408 | } |
409 | } |
410 | |
411 | return nullptr; |
412 | } |
413 | |
414 | PFN_vkVoidFunction GetDeviceProcAddr(Device* device, const char* pName) |
415 | { |
416 | auto deviceFunction = deviceFunctionPointers.find(std::string(pName)); |
417 | if(deviceFunction != deviceFunctionPointers.end()) |
418 | { |
419 | return deviceFunction->second; |
420 | } |
421 | |
422 | for(const auto& deviceExtensionFunctions : deviceExtensionFunctionPointers) |
423 | { |
424 | if(device->hasExtension(deviceExtensionFunctions.first)) |
425 | { |
426 | deviceFunction = deviceExtensionFunctions.second.find(std::string(pName)); |
427 | if(deviceFunction != deviceExtensionFunctions.second.end()) |
428 | { |
429 | return deviceFunction->second; |
430 | } |
431 | } |
432 | } |
433 | |
434 | return nullptr; |
435 | } |
436 | |
437 | } |
438 | |
439 | #ifdef __ANDROID__ |
440 | |
441 | extern "C" hwvulkan_module_t HAL_MODULE_INFO_SYM; |
442 | |
443 | namespace { |
444 | |
445 | int CloseDevice(struct hw_device_t *) { return 0; } |
446 | |
447 | hwvulkan_device_t hal_device = { |
448 | .common = { |
449 | .tag = HARDWARE_DEVICE_TAG, |
450 | .version = HWVULKAN_DEVICE_API_VERSION_0_1, |
451 | .module = &HAL_MODULE_INFO_SYM.common, |
452 | .close = CloseDevice, |
453 | }, |
454 | .EnumerateInstanceExtensionProperties = vkEnumerateInstanceExtensionProperties, |
455 | .CreateInstance = vkCreateInstance, |
456 | .GetInstanceProcAddr = vkGetInstanceProcAddr, |
457 | }; |
458 | |
459 | int OpenDevice(const hw_module_t *module, const char *id, hw_device_t **device) |
460 | { |
461 | if (strcmp(id, HWVULKAN_DEVICE_0) != 0) return -ENOENT; |
462 | *device = &hal_device.common; |
463 | return 0; |
464 | } |
465 | |
466 | hw_module_methods_t module_methods = { .open = OpenDevice }; |
467 | |
468 | } |
469 | |
470 | extern "C" hwvulkan_module_t HAL_MODULE_INFO_SYM = |
471 | { |
472 | .common = |
473 | { |
474 | .tag = HARDWARE_MODULE_TAG, |
475 | .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1, |
476 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
477 | .id = HWVULKAN_HARDWARE_MODULE_ID, |
478 | .name = "Swiftshader Pastel" , |
479 | .author = "Google" , |
480 | .methods = &module_methods, |
481 | } |
482 | }; |
483 | |
484 | #endif |
485 | |