Flutter Impeller
driver_info_vk.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_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_
7 
10 
11 namespace impeller {
12 
13 // https://en.wikipedia.org/wiki/Adreno
14 enum class AdrenoGPU {
15  // I don't think the 400 series will ever run Vulkan, but if some show up we
16  // can add them here.
17  // 500s
18  kAdreno504,
19  kAdreno505,
20  kAdreno506,
21  kAdreno508,
22  kAdreno509,
23  kAdreno510,
24  kAdreno512,
25  kAdreno530,
26  kAdreno540,
27  // 600s
28  kAdreno605,
29  kAdreno608,
30  kAdreno610,
31  kAdreno612,
32  kAdreno613,
33  kAdreno615,
34  kAdreno616,
35  kAdreno618,
37  kAdreno619,
38  kAdreno620,
39  kAdreno630,
40  // The 640 is the first GPU inside an Android device with upgradable drivers.
41  // Anything before this point exhibiting broken behavior is broken forever.
42  kAdreno640,
44  kAdreno642,
46  kAdreno644,
47  kAdreno650,
48  kAdreno660,
49  kAdreno663,
50  kAdreno675,
51  kAdreno680,
52  kAdreno685,
53  kAdreno690,
54  kAdreno695,
55  // 700s
56  kAdreno702,
57  kAdreno710,
58  kAdreno720,
59  kAdreno725,
60  kAdreno730,
61  kAdreno732,
62  kAdreno735,
63  kAdreno740,
64  kAdreno750,
65  // X
68  // Unknown GPU, likely newer model.
69  kUnknown,
70 };
71 
72 // https://en.wikipedia.org/wiki/Mali_(processor)
73 enum class MaliGPU {
74  // These might be Vulkan 1.0 Only.
75  kT760,
76  kT820,
77  kT830,
78  kT860,
79  kT880,
80 
81  // Bifrost
82  kG31,
83  kG51,
84  kG71,
85  kG52,
86  kG72,
87  kG76,
88 
89  // Valhall
90  // Note: there is an Immortalis-G715 a Mali-G715
91  kG57,
92  kG77,
93  kG68,
94  kG78,
95  kG310,
96  kG510,
97  kG610,
98  kG710,
99  kG615,
100  kG715,
101 
102  // 5th Gen
103  kG620,
104  kG720,
105  kG625,
106  kG725,
107  kG925,
108  kUnknown,
109 };
110 
111 enum class VendorVK {
112  kUnknown,
113  //----------------------------------------------------------------------------
114  /// Includes the SwiftShader CPU implementation.
115  ///
116  kGoogle,
117  kQualcomm,
118  kARM,
119  kImgTec,
120  kPowerVR = kImgTec,
121  kAMD,
122  kNvidia,
123  kIntel,
124  kHuawei,
125  kSamsung,
126  //----------------------------------------------------------------------------
127  /// Includes the LLVM Pipe CPU implementation.
128  ///
129  kMesa,
130  //----------------------------------------------------------------------------
131  /// Includes Vulkan on Metal via MoltenVK.
132  ///
133  kApple,
134 };
135 
136 enum class DeviceTypeVK {
137  kUnknown,
138  //----------------------------------------------------------------------------
139  /// The device is an integrated GPU. Typically mobile GPUs.
140  ///
142  //----------------------------------------------------------------------------
143  /// The device is a discrete GPU. Typically desktop GPUs.
144  ///
145  kDiscreteGPU,
146  //----------------------------------------------------------------------------
147  /// The device is a GPU in a virtualized environment.
148  ///
149  kVirtualGPU,
150  //----------------------------------------------------------------------------
151  /// There is no GPU. Vulkan is implemented on the CPU. This is typically
152  /// emulators like SwiftShader and LLVMPipe.
153  ///
154  kCPU,
155 };
156 
157 // visible for testing.
158 AdrenoGPU GetAdrenoVersion(std::string_view version);
159 
160 // visible for testing.
161 MaliGPU GetMaliVersion(std::string_view version);
162 
163 //------------------------------------------------------------------------------
164 /// @brief Get information about the Vulkan driver.
165 ///
166 /// @warning Be extremely cautious about the information reported here. This
167 /// is self-reported information (by the driver) and may be
168 /// inaccurate and or inconsistent.
169 ///
170 /// Before gating features behind any of the information reported by
171 /// the driver, consider alternatives (extensions checks perhaps)
172 /// and try to get a reviewer buddy to convince you to avoid using
173 /// this.
174 ///
176  public:
177  explicit DriverInfoVK(const vk::PhysicalDevice& device);
178 
180 
181  DriverInfoVK(const DriverInfoVK&) = delete;
182 
184 
185  //----------------------------------------------------------------------------
186  /// @brief Gets the Vulkan API version. Should be at or above Vulkan 1.1
187  /// which is the Impeller baseline.
188  ///
189  /// @return The Vulkan API version.
190  ///
191  const Version& GetAPIVersion() const;
192 
193  //----------------------------------------------------------------------------
194  /// @brief Get the vendor of the Vulkan implementation. This is a broad
195  /// check and includes multiple drivers and platforms.
196  ///
197  /// @return The vendor.
198  ///
199  const VendorVK& GetVendor() const;
200 
201  //----------------------------------------------------------------------------
202  /// @brief Get the device type. Typical use might be to check if the
203  /// device is a CPU implementation.
204  ///
205  /// @return The device type.
206  ///
207  const DeviceTypeVK& GetDeviceType() const;
208 
209  //----------------------------------------------------------------------------
210  /// @brief Get the self-reported name of the graphics driver.
211  ///
212  /// @return The driver name.
213  ///
214  const std::string& GetDriverName() const;
215 
216  //----------------------------------------------------------------------------
217  /// @brief Dumps the current driver info to the log.
218  ///
219  void DumpToLog() const;
220 
221  //----------------------------------------------------------------------------
222  /// @brief Determines if the driver represents an emulator. There is no
223  /// definitive way to tell if a driver is an emulator and drivers
224  /// don't self identify as emulators. So take this information
225  /// with a pinch of salt.
226  ///
227  /// @return True if emulator, False otherwise.
228  ///
229  bool IsEmulator() const;
230 
231  //----------------------------------------------------------------------------
232  /// @brief Determines if the driver has been tested and determined to be
233  /// non-functional.
234  ///
235  /// If true, context setup should fail such that the device falls
236  /// back to OpenGLES.
237  ///
238  /// @return True if non-functional device, False otherwise.
239  ///
240  bool IsKnownBadDriver() const;
241 
242  //----------------------------------------------------------------------------
243  /// @brief Returns Mali GPU info if this is a Mali GPU, otherwise
244  /// std::nullopt.
245  ///
246  std::optional<MaliGPU> GetMaliGPUInfo() const;
247 
248  //----------------------------------------------------------------------------
249  /// @brief Returns Adreno GPU info if this is a Adreno GPU, otherwise
250  /// std::nullopt.
251  ///
252  std::optional<AdrenoGPU> GetAdrenoGPUInfo() const;
253 
254  private:
255  bool is_valid_ = false;
256  Version api_version_;
257  VendorVK vendor_ = VendorVK::kUnknown;
259  // If the VendorVK is VendorVK::kQualcomm, this will be populated with the
260  // identified Adreno GPU.
261  std::optional<AdrenoGPU> adreno_gpu_ = std::nullopt;
262  std::optional<MaliGPU> mali_gpu_ = std::nullopt;
263  std::string driver_name_;
264 };
265 
266 } // namespace impeller
267 
268 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DRIVER_INFO_VK_H_
Get information about the Vulkan driver.
const VendorVK & GetVendor() const
Get the vendor of the Vulkan implementation. This is a broad check and includes multiple drivers and ...
DriverInfoVK(const vk::PhysicalDevice &device)
bool IsKnownBadDriver() const
Determines if the driver has been tested and determined to be non-functional.
const std::string & GetDriverName() const
Get the self-reported name of the graphics driver.
DriverInfoVK & operator=(const DriverInfoVK &)=delete
std::optional< AdrenoGPU > GetAdrenoGPUInfo() const
Returns Adreno GPU info if this is a Adreno GPU, otherwise std::nullopt.
void DumpToLog() const
Dumps the current driver info to the log.
std::optional< MaliGPU > GetMaliGPUInfo() const
Returns Mali GPU info if this is a Mali GPU, otherwise std::nullopt.
DriverInfoVK(const DriverInfoVK &)=delete
bool IsEmulator() const
Determines if the driver represents an emulator. There is no definitive way to tell if a driver is an...
const DeviceTypeVK & GetDeviceType() const
Get the device type. Typical use might be to check if the device is a CPU implementation.
const Version & GetAPIVersion() const
Gets the Vulkan API version. Should be at or above Vulkan 1.1 which is the Impeller baseline.
MaliGPU GetMaliVersion(std::string_view version)
AdrenoGPU GetAdrenoVersion(std::string_view version)