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