1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // libvulkan_loader.cpp:
7 //    Helper functions for the loading Vulkan libraries.
8 //
9 
10 #include "common/vulkan/libvulkan_loader.h"
11 
12 #include "common/system_utils.h"
13 
14 namespace angle
15 {
16 namespace vk
17 {
OpenLibVulkan()18 std::unique_ptr<Library> OpenLibVulkan()
19 {
20     constexpr const char *kLibVulkanNames[] = {
21 #if defined(ANGLE_PLATFORM_WINDOWS)
22         "vulkan-1.dll",
23 #elif defined(ANGLE_PLATFORM_APPLE)
24         "libvulkan.dylib",
25         "libvulkan.1.dylib",
26         "libMoltenVK.dylib"
27 #else
28         "libvulkan.so",
29         "libvulkan.so.1",
30 #endif
31     };
32 
33     constexpr SearchType kSearchTypes[] = {
34 // On Android, Fuchsia and GGP we use the system libvulkan.
35 #if defined(ANGLE_USE_CUSTOM_LIBVULKAN)
36         SearchType::ModuleDir,
37 #else
38         SearchType::SystemDir,
39 #endif  // defined(ANGLE_USE_CUSTOM_LIBVULKAN)
40     };
41 
42     for (angle::SearchType searchType : kSearchTypes)
43     {
44         for (const char *libraryName : kLibVulkanNames)
45         {
46             std::unique_ptr<Library> library(
47                 OpenSharedLibraryWithExtension(libraryName, searchType));
48             if (library && library->getNative())
49             {
50                 return library;
51             }
52         }
53     }
54 
55     return nullptr;
56 }
57 }  // namespace vk
58 }  // namespace angle
59