xref: /aosp_15_r20/external/angle/src/common/vulkan/libvulkan_loader.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 void *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             void *library = OpenSystemLibraryWithExtension(libraryName, searchType);
47             if (library)
48             {
49                 return library;
50             }
51         }
52     }
53 
54     return nullptr;
55 }
56 }  // namespace vk
57 }  // namespace angle
58