forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulkan_proc_table.h
160 lines (131 loc) · 4.85 KB
/
vulkan_proc_table.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_
#define FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/fml/native_library.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
#include "vulkan_handle.h"
#include "vulkan_interface.h"
namespace vulkan {
class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> {
FML_FRIEND_REF_COUNTED_THREAD_SAFE(VulkanProcTable);
FML_FRIEND_MAKE_REF_COUNTED(VulkanProcTable);
public:
template <class T>
class Proc {
public:
using Proto = T;
explicit Proc(T proc = nullptr) : proc_(proc) {}
~Proc() { proc_ = nullptr; }
Proc operator=(T proc) {
proc_ = proc;
return *this;
}
Proc operator=(PFN_vkVoidFunction proc) {
proc_ = reinterpret_cast<Proto>(proc);
return *this;
}
explicit operator bool() const { return proc_ != nullptr; }
operator T() const { return proc_; } // NOLINT(google-explicit-constructor)
private:
T proc_;
};
VulkanProcTable();
explicit VulkanProcTable(const char* so_path);
explicit VulkanProcTable(
std::function<void*(VkInstance, const char*)> get_instance_proc_addr);
~VulkanProcTable();
bool HasAcquiredMandatoryProcAddresses() const;
bool IsValid() const;
bool AreInstanceProcsSetup() const;
bool AreDeviceProcsSetup() const;
bool SetupInstanceProcAddresses(const VulkanHandle<VkInstance>& instance);
bool SetupDeviceProcAddresses(const VulkanHandle<VkDevice>& device);
GrVkGetProc CreateSkiaGetProc() const;
std::function<void*(VkInstance, const char*)> GetInstanceProcAddr = nullptr;
#define DEFINE_PROC(name) Proc<PFN_vk##name> name;
DEFINE_PROC(AcquireNextImageKHR);
DEFINE_PROC(AllocateCommandBuffers);
DEFINE_PROC(AllocateMemory);
DEFINE_PROC(BeginCommandBuffer);
DEFINE_PROC(BindImageMemory);
DEFINE_PROC(CmdPipelineBarrier);
DEFINE_PROC(CreateCommandPool);
DEFINE_PROC(CreateDebugReportCallbackEXT);
DEFINE_PROC(CreateDevice);
DEFINE_PROC(CreateFence);
DEFINE_PROC(CreateImage);
DEFINE_PROC(CreateInstance);
DEFINE_PROC(CreateSemaphore);
DEFINE_PROC(CreateSwapchainKHR);
DEFINE_PROC(DestroyCommandPool);
DEFINE_PROC(DestroyDebugReportCallbackEXT);
DEFINE_PROC(DestroyDevice);
DEFINE_PROC(DestroyFence);
DEFINE_PROC(DestroyImage);
DEFINE_PROC(DestroyInstance);
DEFINE_PROC(DestroySemaphore);
DEFINE_PROC(DestroySurfaceKHR);
DEFINE_PROC(DestroySwapchainKHR);
DEFINE_PROC(DeviceWaitIdle);
DEFINE_PROC(EndCommandBuffer);
DEFINE_PROC(EnumerateDeviceLayerProperties);
DEFINE_PROC(EnumerateInstanceExtensionProperties);
DEFINE_PROC(EnumerateInstanceLayerProperties);
DEFINE_PROC(EnumeratePhysicalDevices);
DEFINE_PROC(FreeCommandBuffers);
DEFINE_PROC(FreeMemory);
DEFINE_PROC(GetDeviceProcAddr);
DEFINE_PROC(GetDeviceQueue);
DEFINE_PROC(GetImageMemoryRequirements);
DEFINE_PROC(GetPhysicalDeviceFeatures);
DEFINE_PROC(GetPhysicalDeviceQueueFamilyProperties);
DEFINE_PROC(QueueSubmit);
DEFINE_PROC(QueueWaitIdle);
DEFINE_PROC(ResetCommandBuffer);
DEFINE_PROC(ResetFences);
DEFINE_PROC(WaitForFences);
#ifndef TEST_VULKAN_PROCS
#if FML_OS_ANDROID
DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
DEFINE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
DEFINE_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
DEFINE_PROC(GetPhysicalDeviceSurfaceSupportKHR);
DEFINE_PROC(GetSwapchainImagesKHR);
DEFINE_PROC(QueuePresentKHR);
DEFINE_PROC(CreateAndroidSurfaceKHR);
#endif // FML_OS_ANDROID
#if OS_FUCHSIA
DEFINE_PROC(ImportSemaphoreZirconHandleFUCHSIA);
DEFINE_PROC(GetSemaphoreZirconHandleFUCHSIA);
DEFINE_PROC(GetMemoryZirconHandleFUCHSIA);
DEFINE_PROC(CreateBufferCollectionFUCHSIA);
DEFINE_PROC(DestroyBufferCollectionFUCHSIA);
DEFINE_PROC(SetBufferCollectionImageConstraintsFUCHSIA);
DEFINE_PROC(GetBufferCollectionPropertiesFUCHSIA);
#endif // OS_FUCHSIA
#endif // TEST_VULKAN_PROCS
#undef DEFINE_PROC
private:
fml::RefPtr<fml::NativeLibrary> handle_;
bool acquired_mandatory_proc_addresses_;
VulkanHandle<VkInstance> instance_;
VulkanHandle<VkDevice> device_;
bool OpenLibraryHandle(const char* path);
bool SetupGetInstanceProcAddress();
bool SetupLoaderProcAddresses();
bool CloseLibraryHandle();
PFN_vkVoidFunction AcquireProc(
const char* proc_name,
const VulkanHandle<VkInstance>& instance) const;
PFN_vkVoidFunction AcquireProc(const char* proc_name,
const VulkanHandle<VkDevice>& device) const;
FML_DISALLOW_COPY_AND_ASSIGN(VulkanProcTable);
};
} // namespace vulkan
#endif // FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_