1 | #pragma once |
---|---|
2 | |
3 | #include <thread> |
4 | #include <mutex> |
5 | |
6 | #include "taichi/rhi/vulkan/vulkan_common.h" |
7 | #include "taichi/system/dynamic_loader.h" |
8 | |
9 | namespace taichi::lang { |
10 | namespace vulkan { |
11 | |
12 | class TI_DLL_EXPORT VulkanLoader { |
13 | public: |
14 | static VulkanLoader &instance() { |
15 | static VulkanLoader instance; |
16 | return instance; |
17 | } |
18 | |
19 | public: |
20 | VulkanLoader(VulkanLoader const &) = delete; |
21 | void operator=(VulkanLoader const &) = delete; |
22 | |
23 | bool check_vulkan_device(); |
24 | |
25 | void load_instance(VkInstance instance_); |
26 | void load_device(VkDevice device_); |
27 | bool init(PFN_vkGetInstanceProcAddr get_proc_addr = nullptr); |
28 | PFN_vkVoidFunction load_function(const char *name); |
29 | VkInstance get_instance() { |
30 | return vulkan_instance_; |
31 | } |
32 | std::string visible_device_id; |
33 | |
34 | private: |
35 | std::once_flag init_flag_; |
36 | bool initialized_{false}; |
37 | |
38 | VulkanLoader(); |
39 | |
40 | #if defined(__APPLE__) |
41 | std::unique_ptr<DynamicLoader> vulkan_rt_{nullptr}; |
42 | #endif |
43 | |
44 | VkInstance vulkan_instance_{VK_NULL_HANDLE}; |
45 | VkDevice vulkan_device_{VK_NULL_HANDLE}; |
46 | }; |
47 | |
48 | TI_DLL_EXPORT bool is_vulkan_api_available(); |
49 | |
50 | TI_DLL_EXPORT void set_vulkan_visible_device(std::string id); |
51 | |
52 | } // namespace vulkan |
53 | } // namespace taichi::lang |
54 |