1 //
2 // Copyright 2016 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
7 // driver_utils.h : provides more information about current driver.
8
9 #ifndef LIBANGLE_RENDERER_DRIVER_UTILS_H_
10 #define LIBANGLE_RENDERER_DRIVER_UTILS_H_
11
12 #include "common/platform.h"
13 #include "common/platform_helpers.h"
14 #include "libANGLE/angletypes.h"
15
16 namespace angle
17 {
18 struct VersionInfo;
19 }
20
21 namespace rx
22 {
23
24 enum VendorID : uint32_t
25 {
26 VENDOR_ID_UNKNOWN = 0x0,
27 VENDOR_ID_AMD = 0x1002,
28 VENDOR_ID_APPLE = 0x106B,
29 VENDOR_ID_ARM = 0x13B5,
30 // Broadcom devices won't use PCI, but this is their Vulkan vendor id.
31 VENDOR_ID_BROADCOM = 0x14E4,
32 VENDOR_ID_GOOGLE = 0x1AE0,
33 VENDOR_ID_INTEL = 0x8086,
34 VENDOR_ID_MESA = 0x10005,
35 VENDOR_ID_MICROSOFT = 0x1414,
36 VENDOR_ID_NVIDIA = 0x10DE,
37 VENDOR_ID_POWERVR = 0x1010,
38 VENDOR_ID_QUALCOMM_DXGI = 0x4D4F4351,
39 VENDOR_ID_QUALCOMM = 0x5143,
40 VENDOR_ID_SAMSUNG = 0x144D,
41 VENDOR_ID_VIVANTE = 0x9999,
42 VENDOR_ID_VMWARE = 0x15AD,
43 VENDOR_ID_VIRTIO = 0x1AF4,
44 };
45
46 enum AndroidDeviceID : uint32_t
47 {
48 ANDROID_DEVICE_ID_UNKNOWN = 0x0,
49 ANDROID_DEVICE_ID_NEXUS5X = 0x4010800,
50 ANDROID_DEVICE_ID_PIXEL2 = 0x5040001,
51 ANDROID_DEVICE_ID_PIXEL1XL = 0x5030004,
52 ANDROID_DEVICE_ID_PIXEL4 = 0x6040001,
53 ANDROID_DEVICE_ID_GALAXYA23 = 0x6010901,
54 ANDROID_DEVICE_ID_GALAXYS23 = 0x43050A01,
55 ANDROID_DEVICE_ID_SWIFTSHADER = 0xC0DE,
56 };
57
IsAMD(uint32_t vendorId)58 inline bool IsAMD(uint32_t vendorId)
59 {
60 return vendorId == VENDOR_ID_AMD;
61 }
62
IsAppleGPU(uint32_t vendorId)63 inline bool IsAppleGPU(uint32_t vendorId)
64 {
65 return vendorId == VENDOR_ID_APPLE;
66 }
67
IsARM(uint32_t vendorId)68 inline bool IsARM(uint32_t vendorId)
69 {
70 return vendorId == VENDOR_ID_ARM;
71 }
72
IsBroadcom(uint32_t vendorId)73 inline bool IsBroadcom(uint32_t vendorId)
74 {
75 return vendorId == VENDOR_ID_BROADCOM;
76 }
77
IsIntel(uint32_t vendorId)78 inline bool IsIntel(uint32_t vendorId)
79 {
80 return vendorId == VENDOR_ID_INTEL;
81 }
82
IsGoogle(uint32_t vendorId)83 inline bool IsGoogle(uint32_t vendorId)
84 {
85 return vendorId == VENDOR_ID_GOOGLE;
86 }
87
IsMicrosoft(uint32_t vendorId)88 inline bool IsMicrosoft(uint32_t vendorId)
89 {
90 return vendorId == VENDOR_ID_MICROSOFT;
91 }
92
IsNvidia(uint32_t vendorId)93 inline bool IsNvidia(uint32_t vendorId)
94 {
95 return vendorId == VENDOR_ID_NVIDIA;
96 }
97
IsPowerVR(uint32_t vendorId)98 inline bool IsPowerVR(uint32_t vendorId)
99 {
100 return vendorId == VENDOR_ID_POWERVR;
101 }
102
IsQualcomm(uint32_t vendorId)103 inline bool IsQualcomm(uint32_t vendorId)
104 {
105 // Qualcomm is an unusual one. It has two different vendor IDs depending on
106 // where you look. On Windows, DXGI will report the VENDOR_ID_QUALCOMM_DXGI
107 // value (due to it being an ACPI device rather than PCI device), but their
108 // native Vulkan driver will actually report their PCI vendor ID (the
109 // VENDOR_ID_QUALCOMM value). So we have to check both, to ensure we arrive
110 // at the right conclusion regardless of what source we are querying for
111 // vendor information.
112 return vendorId == VENDOR_ID_QUALCOMM || vendorId == VENDOR_ID_QUALCOMM_DXGI;
113 }
114
IsSamsung(uint32_t vendorId)115 inline bool IsSamsung(uint32_t vendorId)
116 {
117 return vendorId == VENDOR_ID_SAMSUNG;
118 }
119
IsVivante(uint32_t vendorId)120 inline bool IsVivante(uint32_t vendorId)
121 {
122 return vendorId == VENDOR_ID_VIVANTE;
123 }
124
IsVMWare(uint32_t vendorId)125 inline bool IsVMWare(uint32_t vendorId)
126 {
127 return vendorId == VENDOR_ID_VMWARE;
128 }
129
IsVirtIO(uint32_t vendorId)130 inline bool IsVirtIO(uint32_t vendorId)
131 {
132 return vendorId == VENDOR_ID_VIRTIO;
133 }
134
IsNexus5X(uint32_t vendorId,uint32_t deviceId)135 inline bool IsNexus5X(uint32_t vendorId, uint32_t deviceId)
136 {
137 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_NEXUS5X;
138 }
139
IsPixel1XL(uint32_t vendorId,uint32_t deviceId)140 inline bool IsPixel1XL(uint32_t vendorId, uint32_t deviceId)
141 {
142 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL1XL;
143 }
144
IsPixel2(uint32_t vendorId,uint32_t deviceId)145 inline bool IsPixel2(uint32_t vendorId, uint32_t deviceId)
146 {
147 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL2;
148 }
149
IsPixel4(uint32_t vendorId,uint32_t deviceId)150 inline bool IsPixel4(uint32_t vendorId, uint32_t deviceId)
151 {
152 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_PIXEL4;
153 }
154
IsGalaxyA23(uint32_t vendorId,uint32_t deviceId)155 inline bool IsGalaxyA23(uint32_t vendorId, uint32_t deviceId)
156 {
157 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_GALAXYA23;
158 }
159
IsGalaxyS23(uint32_t vendorId,uint32_t deviceId)160 inline bool IsGalaxyS23(uint32_t vendorId, uint32_t deviceId)
161 {
162 return IsQualcomm(vendorId) && deviceId == ANDROID_DEVICE_ID_GALAXYS23;
163 }
164
IsSwiftshader(uint32_t vendorId,uint32_t deviceId)165 inline bool IsSwiftshader(uint32_t vendorId, uint32_t deviceId)
166 {
167 return IsGoogle(vendorId) && deviceId == ANDROID_DEVICE_ID_SWIFTSHADER;
168 }
169
170 std::string GetVendorString(uint32_t vendorId);
171
172 bool IsSandyBridge(uint32_t DeviceId);
173 bool IsIvyBridge(uint32_t DeviceId);
174 bool IsHaswell(uint32_t DeviceId);
175 bool IsBroadwell(uint32_t DeviceId);
176 bool IsCherryView(uint32_t DeviceId);
177 bool IsSkylake(uint32_t DeviceId);
178 bool IsBroxton(uint32_t DeviceId);
179 bool IsKabyLake(uint32_t DeviceId);
180 bool IsGeminiLake(uint32_t DeviceId);
181 bool IsCoffeeLake(uint32_t DeviceId);
182 bool IsMeteorLake(uint32_t DeviceId);
183 bool Is9thGenIntel(uint32_t DeviceId);
184 bool Is11thGenIntel(uint32_t DeviceId);
185 bool Is12thGenIntel(uint32_t DeviceId);
186
187 // For ease of comparison of SystemInfo's external-facing VersionInfo with ANGLE's more commonly
188 // used VersionTriple.
189 bool operator==(const angle::VersionInfo &a, const angle::VersionTriple &b);
190 bool operator!=(const angle::VersionInfo &a, const angle::VersionTriple &b);
191 bool operator<(const angle::VersionInfo &a, const angle::VersionTriple &b);
192 bool operator>=(const angle::VersionInfo &a, const angle::VersionTriple &b);
193
194 // Platform helpers
195 using angle::IsAndroid;
196 using angle::IsApple;
197 using angle::IsChromeOS;
198 using angle::IsFuchsia;
199 using angle::IsIOS;
200 using angle::IsLinux;
201 using angle::IsMac;
202 using angle::IsWindows;
203 using angle::IsWindows10OrLater;
204 using angle::IsWindows8OrLater;
205 using angle::IsWindowsVistaOrLater;
206
207 bool IsWayland();
208
209 using OSVersion = angle::VersionTriple;
210
211 OSVersion GetMacOSVersion();
212
213 OSVersion GetiOSVersion();
214
215 OSVersion GetLinuxOSVersion();
216
217 int GetAndroidSDKVersion();
218
219 } // namespace rx
220 #endif // LIBANGLE_RENDERER_DRIVER_UTILS_H_
221