Flutter Engine
The Flutter Engine
vulkan_proc_table.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_VULKAN_PROCS_VULKAN_PROC_TABLE_H_
6#define FLUTTER_VULKAN_PROCS_VULKAN_PROC_TABLE_H_
7
8#include "flutter/fml/macros.h"
9#include "flutter/fml/memory/ref_counted.h"
10#include "flutter/fml/memory/ref_ptr.h"
11#include "flutter/fml/native_library.h"
12#include "flutter/vulkan/procs/vulkan_handle.h"
13#include "flutter/vulkan/procs/vulkan_interface.h"
14
15namespace vulkan {
16
17class VulkanProcTable : public fml::RefCountedThreadSafe<VulkanProcTable> {
18 FML_FRIEND_REF_COUNTED_THREAD_SAFE(VulkanProcTable);
19 FML_FRIEND_MAKE_REF_COUNTED(VulkanProcTable);
20
21 public:
22 template <class T>
23 class Proc {
24 public:
25 using Proto = T;
26
27 explicit Proc(T proc = nullptr) : proc_(proc) {}
28
29 ~Proc() { proc_ = nullptr; }
30
32 proc_ = proc;
33 return *this;
34 }
35
37 proc_ = reinterpret_cast<Proto>(proc);
38 return *this;
39 }
40
41 explicit operator bool() const { return proc_ != nullptr; }
42
43 operator T() const { return proc_; } // NOLINT(google-explicit-constructor)
44
45 private:
46 T proc_;
47 };
48
50 explicit VulkanProcTable(const char* so_path);
53
55
56 bool IsValid() const;
57
58 bool AreInstanceProcsSetup() const;
59
60 bool AreDeviceProcsSetup() const;
61
63
65
67
68#define DEFINE_PROC(name) Proc<PFN_vk##name> name;
69
70 DEFINE_PROC(AcquireNextImageKHR);
71 DEFINE_PROC(AllocateCommandBuffers);
72 DEFINE_PROC(AllocateMemory);
73 DEFINE_PROC(BeginCommandBuffer);
74 DEFINE_PROC(BindImageMemory);
75 DEFINE_PROC(CmdPipelineBarrier);
76 DEFINE_PROC(CreateCommandPool);
77 DEFINE_PROC(CreateDebugReportCallbackEXT);
78 DEFINE_PROC(CreateDevice);
79 DEFINE_PROC(CreateFence);
80 DEFINE_PROC(CreateImage);
81 DEFINE_PROC(CreateInstance);
82 DEFINE_PROC(CreateSemaphore);
83 DEFINE_PROC(CreateSwapchainKHR);
84 DEFINE_PROC(DestroyCommandPool);
85 DEFINE_PROC(DestroyDebugReportCallbackEXT);
86 DEFINE_PROC(DestroyDevice);
87 DEFINE_PROC(DestroyFence);
88 DEFINE_PROC(DestroyImage);
89 DEFINE_PROC(DestroyInstance);
90 DEFINE_PROC(DestroySemaphore);
91 DEFINE_PROC(DestroySurfaceKHR);
92 DEFINE_PROC(DestroySwapchainKHR);
93 DEFINE_PROC(DeviceWaitIdle);
94 DEFINE_PROC(EndCommandBuffer);
95 DEFINE_PROC(EnumerateDeviceLayerProperties);
96 DEFINE_PROC(EnumerateInstanceExtensionProperties);
97 DEFINE_PROC(EnumerateInstanceLayerProperties);
98 DEFINE_PROC(EnumeratePhysicalDevices);
99 DEFINE_PROC(FreeCommandBuffers);
100 DEFINE_PROC(FreeMemory);
101 DEFINE_PROC(GetDeviceProcAddr);
102 DEFINE_PROC(GetDeviceQueue);
103 DEFINE_PROC(GetImageMemoryRequirements);
104 DEFINE_PROC(GetPhysicalDeviceFeatures);
105 DEFINE_PROC(GetPhysicalDeviceQueueFamilyProperties);
106 DEFINE_PROC(QueueSubmit);
107 DEFINE_PROC(QueueWaitIdle);
108 DEFINE_PROC(ResetCommandBuffer);
109 DEFINE_PROC(ResetFences);
110 DEFINE_PROC(WaitForFences);
111 DEFINE_PROC(GetPhysicalDeviceProperties);
112 DEFINE_PROC(GetPhysicalDeviceMemoryProperties);
113 DEFINE_PROC(MapMemory);
114 DEFINE_PROC(UnmapMemory);
115 DEFINE_PROC(FlushMappedMemoryRanges);
116 DEFINE_PROC(InvalidateMappedMemoryRanges);
117 DEFINE_PROC(BindBufferMemory);
118 DEFINE_PROC(GetBufferMemoryRequirements);
119 DEFINE_PROC(CreateBuffer);
120 DEFINE_PROC(DestroyBuffer);
121 DEFINE_PROC(CmdCopyBuffer);
122
123 DEFINE_PROC(GetPhysicalDeviceMemoryProperties2);
124 DEFINE_PROC(GetPhysicalDeviceMemoryProperties2KHR);
125
126 DEFINE_PROC(GetBufferMemoryRequirements2);
127 DEFINE_PROC(GetBufferMemoryRequirements2KHR);
128 DEFINE_PROC(GetImageMemoryRequirements2);
129 DEFINE_PROC(GetImageMemoryRequirements2KHR);
130 DEFINE_PROC(BindBufferMemory2);
131 DEFINE_PROC(BindBufferMemory2KHR);
132 DEFINE_PROC(BindImageMemory2);
133 DEFINE_PROC(BindImageMemory2KHR);
134
135#ifndef TEST_VULKAN_PROCS
136#if FML_OS_ANDROID
137 DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
138 DEFINE_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
139 DEFINE_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
140 DEFINE_PROC(GetPhysicalDeviceSurfaceSupportKHR);
141 DEFINE_PROC(GetSwapchainImagesKHR);
142 DEFINE_PROC(QueuePresentKHR);
143 DEFINE_PROC(CreateAndroidSurfaceKHR);
144#endif // FML_OS_ANDROID
145#if OS_FUCHSIA
146 DEFINE_PROC(ImportSemaphoreZirconHandleFUCHSIA);
147 DEFINE_PROC(GetSemaphoreZirconHandleFUCHSIA);
148 DEFINE_PROC(GetMemoryZirconHandleFUCHSIA);
149 DEFINE_PROC(CreateBufferCollectionFUCHSIA);
150 DEFINE_PROC(DestroyBufferCollectionFUCHSIA);
151 DEFINE_PROC(SetBufferCollectionImageConstraintsFUCHSIA);
152 DEFINE_PROC(GetBufferCollectionPropertiesFUCHSIA);
153#endif // OS_FUCHSIA
154#endif // TEST_VULKAN_PROCS
155
156#undef DEFINE_PROC
157
159
161 const char* proc_name,
163
164 PFN_vkVoidFunction AcquireProc(const char* proc_name,
165 const VulkanHandle<VkDevice>& device) const;
166
167 private:
169 bool acquired_mandatory_proc_addresses_;
170 VulkanHandle<VkInstance> instance_;
172
173 bool OpenLibraryHandle(const char* path);
174 bool SetupGetInstanceProcAddress();
175 bool SetupLoaderProcAddresses();
176 bool CloseLibraryHandle();
177
178 FML_DISALLOW_COPY_AND_ASSIGN(VulkanProcTable);
179};
180
181} // namespace vulkan
182
183#endif // FLUTTER_VULKAN_PROCS_VULKAN_PROC_TABLE_H_
Proc operator=(PFN_vkVoidFunction proc)
DEFINE_PROC(WaitForFences)
DEFINE_PROC(FreeCommandBuffers)
DEFINE_PROC(CreateDebugReportCallbackEXT)
DEFINE_PROC(GetImageMemoryRequirements)
DEFINE_PROC(CmdPipelineBarrier)
DEFINE_PROC(BindBufferMemory2KHR)
DEFINE_PROC(CreateSwapchainKHR)
DEFINE_PROC(GetDeviceQueue)
DEFINE_PROC(GetImageMemoryRequirements2KHR)
DEFINE_PROC(GetDeviceProcAddr)
DEFINE_PROC(CreateBuffer)
DEFINE_PROC(DeviceWaitIdle)
DEFINE_PROC(BindImageMemory2)
DEFINE_PROC(GetPhysicalDeviceFeatures)
DEFINE_PROC(DestroySwapchainKHR)
DEFINE_PROC(EnumerateDeviceLayerProperties)
DEFINE_PROC(EnumerateInstanceLayerProperties)
DEFINE_PROC(DestroyInstance)
DEFINE_PROC(GetBufferMemoryRequirements2KHR)
bool SetupInstanceProcAddresses(const VulkanHandle< VkInstance > &instance)
DEFINE_PROC(EndCommandBuffer)
DEFINE_PROC(EnumerateInstanceExtensionProperties)
DEFINE_PROC(QueueWaitIdle)
DEFINE_PROC(GetPhysicalDeviceProperties)
DEFINE_PROC(CreateSemaphore)
DEFINE_PROC(CreateCommandPool)
DEFINE_PROC(DestroyDevice)
DEFINE_PROC(DestroyFence)
DEFINE_PROC(CreateInstance)
PFN_vkVoidFunction AcquireProc(const char *proc_name, const VulkanHandle< VkInstance > &instance) const
DEFINE_PROC(GetPhysicalDeviceQueueFamilyProperties)
PFN_vkGetInstanceProcAddr NativeGetInstanceProcAddr() const
DEFINE_PROC(CreateImage)
DEFINE_PROC(GetPhysicalDeviceMemoryProperties2)
DEFINE_PROC(GetImageMemoryRequirements2)
DEFINE_PROC(CreateDevice)
DEFINE_PROC(DestroySemaphore)
DEFINE_PROC(ResetFences)
DEFINE_PROC(FlushMappedMemoryRanges)
DEFINE_PROC(AcquireNextImageKHR)
DEFINE_PROC(QueueSubmit)
bool HasAcquiredMandatoryProcAddresses() const
DEFINE_PROC(DestroyBuffer)
DEFINE_PROC(AllocateCommandBuffers)
DEFINE_PROC(BindImageMemory2KHR)
DEFINE_PROC(CreateFence)
DEFINE_PROC(GetPhysicalDeviceMemoryProperties2KHR)
DEFINE_PROC(ResetCommandBuffer)
DEFINE_PROC(CmdCopyBuffer)
DEFINE_PROC(EnumeratePhysicalDevices)
DEFINE_PROC(AllocateMemory)
DEFINE_PROC(BindBufferMemory2)
PFN_vkGetInstanceProcAddr GetInstanceProcAddr
DEFINE_PROC(UnmapMemory)
DEFINE_PROC(BindImageMemory)
bool AreInstanceProcsSetup() const
DEFINE_PROC(DestroySurfaceKHR)
DEFINE_PROC(GetPhysicalDeviceMemoryProperties)
DEFINE_PROC(DestroyImage)
DEFINE_PROC(DestroyDebugReportCallbackEXT)
DEFINE_PROC(GetBufferMemoryRequirements)
DEFINE_PROC(BindBufferMemory)
DEFINE_PROC(DestroyCommandPool)
DEFINE_PROC(GetBufferMemoryRequirements2)
bool SetupDeviceProcAddresses(const VulkanHandle< VkDevice > &device)
DEFINE_PROC(BeginCommandBuffer)
DEFINE_PROC(InvalidateMappedMemoryRanges)
decltype(vkGetInstanceProcAddr) * get_instance_proc_addr
VkDevice device
Definition: main.cc:53
VkInstance instance
Definition: main.cc:48
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
#define T
Definition: precompiler.cc:65
void(VKAPI_PTR * PFN_vkVoidFunction)(void)
Definition: vulkan_core.h:2992
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:3989