forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpu_info_collector_win.cc
672 lines (595 loc) · 24.5 KB
/
gpu_info_collector_win.cc
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/config/gpu_info_collector.h"
// This has to be included before windows.h.
#include "third_party/re2/src/re2/re2.h"
#include <windows.h>
#include <cfgmgr32.h>
#include <d3d11.h>
#include <d3d12.h>
#include <d3d9.h>
#include <dxgi.h>
#include <setupapi.h>
#include <stddef.h>
#include <stdint.h>
// Initguid.h must come before Devpkey.h for DEFINE_DEVPROPKEY macros
// to resolve without giving unresolved external externals linker errors.
#include <initguid.h>
#include <Devpkey.h>
#include "base/file_version_info_win.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/scoped_native_library.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
#include "base/trace_event/trace_event.h"
#include "base/win/scoped_com_initializer.h"
#include "build/branding_buildflags.h"
#include "gpu/config/nvml_info.h"
#include "third_party/vulkan/include/vulkan/vulkan.h"
namespace gpu {
namespace {
void DeviceIDToVendorAndDevice(const std::wstring& id,
uint32_t* vendor_id,
uint32_t* device_id) {
*vendor_id = 0;
*device_id = 0;
if (id.length() < 21)
return;
base::string16 vendor_id_string = id.substr(8, 4);
base::string16 device_id_string = id.substr(17, 4);
int vendor = 0;
int device = 0;
base::HexStringToInt(base::UTF16ToASCII(vendor_id_string), &vendor);
base::HexStringToInt(base::UTF16ToASCII(device_id_string), &device);
*vendor_id = vendor;
*device_id = device;
}
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This should match enum D3DFeatureLevel in \tools\metrics\histograms\enums.xml
enum class D3D12FeatureLevel {
kD3DFeatureLevelUnknown = 0,
kD3DFeatureLevel_12_0 = 1,
kD3DFeatureLevel_12_1 = 2,
kMaxValue = kD3DFeatureLevel_12_1,
};
inline D3D12FeatureLevel ConvertToHistogramFeatureLevel(
uint32_t d3d_feature_level) {
switch (d3d_feature_level) {
case 0:
return D3D12FeatureLevel::kD3DFeatureLevelUnknown;
case D3D_FEATURE_LEVEL_12_0:
return D3D12FeatureLevel::kD3DFeatureLevel_12_0;
case D3D_FEATURE_LEVEL_12_1:
return D3D12FeatureLevel::kD3DFeatureLevel_12_1;
default:
NOTREACHED();
return D3D12FeatureLevel::kD3DFeatureLevelUnknown;
}
}
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This should match enum VulkanVersion in \tools\metrics\histograms\enums.xml
enum class VulkanVersion {
kVulkanVersionUnknown = 0,
kVulkanVersion_1_0_0 = 1,
kVulkanVersion_1_1_0 = 2,
kMaxValue = kVulkanVersion_1_1_0,
};
inline VulkanVersion ConvertToHistogramVulkanVersion(uint32_t vulkan_version) {
switch (vulkan_version) {
case 0:
return VulkanVersion::kVulkanVersionUnknown;
case VK_MAKE_VERSION(1, 0, 0):
return VulkanVersion::kVulkanVersion_1_0_0;
case VK_MAKE_VERSION(1, 1, 0):
return VulkanVersion::kVulkanVersion_1_1_0;
default:
NOTREACHED();
return VulkanVersion::kVulkanVersionUnknown;
}
}
std::string GetDeviceStringProperty(DEVINST dev_inst,
const DEVPROPKEY* prop_key) {
ULONG buffer_size = 0;
DEVPROPTYPE prop_type;
// To find out how big to make the buffer that receives the string, we must
// first call CM_Get_DevNode_PropertyW with a nullptr buffer and zero buffer
// size. buffer_size will receive the number of bytes to make the buffer.
CONFIGRET config_ret = CM_Get_DevNode_PropertyW(
dev_inst, prop_key, &prop_type, nullptr, &buffer_size, 0);
if (config_ret != CR_BUFFER_SMALL)
return std::string();
std::vector<WCHAR> property_value;
property_value.resize(buffer_size / sizeof(WCHAR));
config_ret = CM_Get_DevNode_PropertyW(
dev_inst, prop_key, &prop_type,
reinterpret_cast<PBYTE>(property_value.data()), &buffer_size, 0);
if (config_ret != CR_SUCCESS)
return std::string();
DCHECK(prop_type == DEVPROP_TYPE_STRING);
return base::UTF16ToASCII(property_value.data());
}
} // namespace
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OFFICIAL_BUILD)
// This function has a real implementation for official builds that can
// be found in src/third_party/amd.
bool GetAMDSwitchableInfo(bool* is_switchable,
uint32_t* active_vendor_id,
uint32_t* active_device_id);
#else
bool GetAMDSwitchableInfo(bool* is_switchable,
uint32_t* active_vendor_id,
uint32_t* active_device_id) {
return false;
}
#endif
std::string ParseNVIDIARegistryDriverVersion(std::string registry_version) {
// The NVIDIA driver version in the registry is most commonly in the format:
// XX.XX.XD.DDDD
// Where "X" corresponds to an OS-specific digit and "D" corresponds to a
// digit of the actual driver version. We convert it to the following format:
// DDD.DD
// This matches with the actual driver version that NVML also returns.
std::string second_to_last_digits;
std::string last_digits;
if (!RE2::FullMatch(registry_version, "\\d+\\.\\d+\\.(\\d+)\\.(\\d+)",
&second_to_last_digits, &last_digits)) {
return registry_version;
}
std::string digits = second_to_last_digits + last_digits;
if (digits.length() < 5u) {
return registry_version;
}
digits.erase(0, digits.length() - 5u);
DCHECK(digits.length() == 5u);
return digits.substr(0u, 3u) + "." + digits.substr(3u);
}
bool CollectDriverInfoD3D(const std::wstring& device_id, GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "CollectDriverInfoD3D");
// Display adapter class GUID from
// https://msdn.microsoft.com/en-us/library/windows/hardware/ff553426%28v=vs.85%29.aspx
const GUID display_class = {0x4d36e968,
0xe325,
0x11ce,
{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}};
// create device info for the display device
const HDEVINFO device_info =
::SetupDiGetClassDevs(&display_class, nullptr, nullptr, DIGCF_PRESENT);
if (device_info == INVALID_HANDLE_VALUE) {
LOG(ERROR) << "Creating device info failed";
return false;
}
std::vector<GPUInfo::GPUDevice> devices;
size_t primary_device = std::numeric_limits<size_t>::max();
bool found_amd = false;
bool found_intel = false;
bool amd_is_primary = false;
DWORD index = 0;
SP_DEVINFO_DATA device_info_data;
device_info_data.cbSize = sizeof(device_info_data);
while (SetupDiEnumDeviceInfo(device_info, index++, &device_info_data)) {
GPUInfo::GPUDevice device;
device.driver_version = GetDeviceStringProperty(
device_info_data.DevInst, &DEVPKEY_Device_DriverVersion);
device.driver_vendor = GetDeviceStringProperty(
device_info_data.DevInst, &DEVPKEY_Device_DriverProvider);
wchar_t new_device_id[MAX_DEVICE_ID_LEN];
const CONFIGRET status = CM_Get_Device_ID(
device_info_data.DevInst, new_device_id, MAX_DEVICE_ID_LEN, 0);
if (status == CR_SUCCESS) {
std::wstring id = new_device_id;
DeviceIDToVendorAndDevice(id, &(device.vendor_id), &(device.device_id));
if (id.compare(0, device_id.size(), device_id) == 0) {
primary_device = devices.size();
if (device.vendor_id == 0x1002)
amd_is_primary = true;
}
if (device.vendor_id == 0x8086)
found_intel = true;
if (device.vendor_id == 0x1002)
found_amd = true;
if (device.vendor_id == 0x10de) {
std::string nvml_driver_version;
int major_cuda_compute_capability = 0;
int minor_cuda_compute_capability = 0;
bool nvml_success = GetNvmlDeviceInfo(
device.device_id, &nvml_driver_version,
&major_cuda_compute_capability, &minor_cuda_compute_capability);
if (nvml_success) {
// We use the NVML driver version instead of the registry version,
// since the registry version includes OS-specific digits that are
// not part of the actual driver version.
device.driver_version = nvml_driver_version;
device.cuda_compute_capability_major = major_cuda_compute_capability;
} else {
// If we can't get the actual driver version from NVML, do
// best-effort parsing of the actual driver version from the
// registry driver version.
device.driver_version =
ParseNVIDIARegistryDriverVersion(device.driver_version);
}
}
devices.push_back(device);
}
}
SetupDiDestroyDeviceInfoList(device_info);
if (found_amd && found_intel) {
// Potential AMD Switchable system found.
if (!amd_is_primary) {
// Some machines aren't properly detected as AMD switchable, but count
// them anyway. This may erroneously count machines where there are
// independent AMD and Intel cards and the AMD isn't hooked up to
// anything, but that should be rare.
gpu_info->amd_switchable = true;
} else {
bool is_amd_switchable = false;
uint32_t active_vendor = 0, active_device = 0;
GetAMDSwitchableInfo(&is_amd_switchable, &active_vendor, &active_device);
gpu_info->amd_switchable = is_amd_switchable;
}
}
bool found = false;
for (size_t i = 0; i < devices.size(); ++i) {
const GPUInfo::GPUDevice& device = devices[i];
if (i == primary_device) {
found = true;
gpu_info->gpu = device;
} else {
gpu_info->secondary_gpus.push_back(device);
}
}
return found;
}
// DirectX 12 are included with Windows 10 and Server 2016.
void GetGpuSupportedD3D12Version(Dx12VulkanVersionInfo* info) {
TRACE_EVENT0("gpu", "GetGpuSupportedD3D12Version");
info->supports_dx12 = false;
info->d3d12_feature_level = 0;
base::NativeLibrary d3d12_library =
base::LoadNativeLibrary(base::FilePath(L"d3d12.dll"), nullptr);
if (!d3d12_library) {
return;
}
// The order of feature levels to attempt to create in D3D CreateDevice
const D3D_FEATURE_LEVEL feature_levels[] = {D3D_FEATURE_LEVEL_12_1,
D3D_FEATURE_LEVEL_12_0};
PFN_D3D12_CREATE_DEVICE D3D12CreateDevice =
reinterpret_cast<PFN_D3D12_CREATE_DEVICE>(
GetProcAddress(d3d12_library, "D3D12CreateDevice"));
if (D3D12CreateDevice) {
// For the default adapter only. (*pAdapter == nullptr)
// Check to see if the adapter supports Direct3D 12, but don't create the
// actual device yet. (**ppDevice == nullptr)
for (auto level : feature_levels) {
if (SUCCEEDED(D3D12CreateDevice(nullptr, level, _uuidof(ID3D12Device),
nullptr))) {
info->d3d12_feature_level = level;
info->supports_dx12 = true;
break;
}
}
}
base::UnloadNativeLibrary(d3d12_library);
}
bool BadAMDVulkanDriverVersion() {
// Both 32-bit and 64-bit dll are broken. If 64-bit doesn't exist,
// 32-bit dll will be used to detect the AMD Vulkan driver.
const base::FilePath kAmdDriver64(FILE_PATH_LITERAL("amdvlk64.dll"));
const base::FilePath kAmdDriver32(FILE_PATH_LITERAL("amdvlk32.dll"));
std::unique_ptr<FileVersionInfoWin> file_version_info =
FileVersionInfoWin::CreateFileVersionInfoWin(kAmdDriver64);
if (!file_version_info) {
file_version_info =
FileVersionInfoWin::CreateFileVersionInfoWin(kAmdDriver32);
if (!file_version_info)
return false;
}
const VS_FIXEDFILEINFO* fixed_file_info =
file_version_info->fixed_file_info();
const int major = HIWORD(fixed_file_info->dwFileVersionMS);
const int minor = LOWORD(fixed_file_info->dwFileVersionMS);
const int minor_1 = HIWORD(fixed_file_info->dwFileVersionLS);
// From the Canary crash logs, the broken amdvlk64.dll versions
// are 1.0.39.0, 1.0.51.0 and 1.0.54.0. In the manual test, version
// 9.2.10.1 dated 12/6/2017 works and version 1.0.54.0 dated 11/2/1017
// crashes. All version numbers small than 1.0.54.0 will be marked as
// broken.
if (major == 1 && minor == 0 && minor_1 <= 54) {
return true;
}
return false;
}
bool BadVulkanDllVersion() {
std::unique_ptr<FileVersionInfoWin> file_version_info =
FileVersionInfoWin::CreateFileVersionInfoWin(
base::FilePath(FILE_PATH_LITERAL("vulkan-1.dll")));
if (!file_version_info)
return false;
const VS_FIXEDFILEINFO* fixed_file_info =
file_version_info->fixed_file_info();
const int major = HIWORD(fixed_file_info->dwFileVersionMS);
const int minor = LOWORD(fixed_file_info->dwFileVersionMS);
const int build_1 = HIWORD(fixed_file_info->dwFileVersionLS);
const int build_2 = LOWORD(fixed_file_info->dwFileVersionLS);
// From the logs, most vulkan-1.dll crashs are from the following versions.
// As of 7/23/2018.
// 0.0.0.0 - # of crashes: 6556
// 1.0.26.0 - # of crashes: 5890
// 1.0.33.0 - # of crashes: 12271
// 1.0.42.0 - # of crashes: 35749
// 1.0.42.1 - # of crashes: 68214
// 1.0.51.0 - # of crashes: 5152
// The GPU could be from any vendor, but only some certain models would crash.
// For those that don't crash, they usually return failures upon GPU vulkan
// support querying even though the GPU drivers can support it.
if ((major == 0 && minor == 0 && build_1 == 0 && build_2 == 0) ||
(major == 1 && minor == 0 && build_1 == 26 && build_2 == 0) ||
(major == 1 && minor == 0 && build_1 == 33 && build_2 == 0) ||
(major == 1 && minor == 0 && build_1 == 42 && build_2 == 0) ||
(major == 1 && minor == 0 && build_1 == 42 && build_2 == 1) ||
(major == 1 && minor == 0 && build_1 == 51 && build_2 == 0)) {
return true;
}
return false;
}
bool InitVulkan(base::NativeLibrary* vulkan_library,
PFN_vkGetInstanceProcAddr* vkGetInstanceProcAddr,
PFN_vkCreateInstance* vkCreateInstance) {
*vulkan_library =
base::LoadNativeLibrary(base::FilePath(L"vulkan-1.dll"), nullptr);
if (!(*vulkan_library)) {
return false;
}
*vkGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(
GetProcAddress(*vulkan_library, "vkGetInstanceProcAddr"));
if (*vkGetInstanceProcAddr) {
*vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(
(*vkGetInstanceProcAddr)(nullptr, "vkCreateInstance"));
if (*vkCreateInstance) {
return true;
}
}
base::UnloadNativeLibrary(*vulkan_library);
return false;
}
bool InitVulkanInstanceProc(
const VkInstance& vk_instance,
const PFN_vkGetInstanceProcAddr& vkGetInstanceProcAddr,
PFN_vkDestroyInstance* vkDestroyInstance,
PFN_vkEnumeratePhysicalDevices* vkEnumeratePhysicalDevices,
PFN_vkEnumerateDeviceExtensionProperties*
vkEnumerateDeviceExtensionProperties) {
*vkDestroyInstance = reinterpret_cast<PFN_vkDestroyInstance>(
vkGetInstanceProcAddr(vk_instance, "vkDestroyInstance"));
*vkEnumeratePhysicalDevices =
reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(
vkGetInstanceProcAddr(vk_instance, "vkEnumeratePhysicalDevices"));
*vkEnumerateDeviceExtensionProperties =
reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(
vkGetInstanceProcAddr(vk_instance,
"vkEnumerateDeviceExtensionProperties"));
if ((*vkDestroyInstance) && (*vkEnumeratePhysicalDevices) &&
(*vkEnumerateDeviceExtensionProperties)) {
return true;
}
return false;
}
void GetGpuSupportedVulkanVersionAndExtensions(
Dx12VulkanVersionInfo* info,
const std::vector<const char*>& requested_vulkan_extensions,
std::vector<bool>* extension_support) {
TRACE_EVENT0("gpu", "GetGpuSupportedVulkanVersionAndExtensions");
base::NativeLibrary vulkan_library;
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
PFN_vkCreateInstance vkCreateInstance;
PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices;
PFN_vkEnumerateDeviceExtensionProperties vkEnumerateDeviceExtensionProperties;
PFN_vkDestroyInstance vkDestroyInstance;
VkInstance vk_instance = VK_NULL_HANDLE;
uint32_t physical_device_count = 0;
info->supports_vulkan = false;
info->vulkan_version = 0;
// Skip if the system has an older AMD Vulkan driver amdvlk64.dll or
// amdvlk32.dll which crashes when vkCreateInstance() is called. This bug has
// been fixed in the latest AMD driver.
if (BadAMDVulkanDriverVersion()) {
return;
}
// Some early versions of vulkan-1.dll might crash
if (BadVulkanDllVersion()) {
return;
}
if (!InitVulkan(&vulkan_library, &vkGetInstanceProcAddr, &vkCreateInstance)) {
return;
}
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
VkInstanceCreateInfo create_info = {};
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
create_info.pApplicationInfo = &app_info;
// Get the Vulkan API version supported in the GPU driver
for (int minor_version = 1; minor_version >= 0; --minor_version) {
app_info.apiVersion = VK_MAKE_VERSION(1, minor_version, 0);
VkResult result = vkCreateInstance(&create_info, nullptr, &vk_instance);
if (result == VK_SUCCESS && vk_instance &&
InitVulkanInstanceProc(vk_instance, vkGetInstanceProcAddr,
&vkDestroyInstance, &vkEnumeratePhysicalDevices,
&vkEnumerateDeviceExtensionProperties)) {
result = vkEnumeratePhysicalDevices(vk_instance, &physical_device_count,
nullptr);
if (result == VK_SUCCESS && physical_device_count > 0) {
info->supports_vulkan = true;
info->vulkan_version = app_info.apiVersion;
break;
} else {
vkDestroyInstance(vk_instance, nullptr);
vk_instance = VK_NULL_HANDLE;
}
}
}
// Check whether the requested_vulkan_extensions are supported
if (info->supports_vulkan) {
std::vector<VkPhysicalDevice> physical_devices(physical_device_count);
vkEnumeratePhysicalDevices(vk_instance, &physical_device_count,
physical_devices.data());
// physical_devices[0]: Only query the default device for now
uint32_t property_count;
vkEnumerateDeviceExtensionProperties(physical_devices[0], nullptr,
&property_count, nullptr);
std::vector<VkExtensionProperties> extension_properties(property_count);
if (property_count > 0) {
vkEnumerateDeviceExtensionProperties(physical_devices[0], nullptr,
&property_count,
extension_properties.data());
}
for (size_t i = 0; i < requested_vulkan_extensions.size(); ++i) {
for (size_t p = 0; p < property_count; ++p) {
if (strcmp(requested_vulkan_extensions[i],
extension_properties[p].extensionName) == 0) {
(*extension_support)[i] = true;
break;
}
}
}
}
if (vk_instance) {
vkDestroyInstance(vk_instance, nullptr);
}
base::UnloadNativeLibrary(vulkan_library);
}
void RecordGpuSupportedRuntimeVersionHistograms(Dx12VulkanVersionInfo* info) {
// D3D
GetGpuSupportedD3D12Version(info);
UMA_HISTOGRAM_BOOLEAN("GPU.SupportsDX12", info->supports_dx12);
UMA_HISTOGRAM_ENUMERATION(
"GPU.D3D12FeatureLevel",
ConvertToHistogramFeatureLevel(info->d3d12_feature_level));
// Vulkan
const std::vector<const char*> vulkan_extensions = {
"VK_KHR_external_memory_win32", "VK_KHR_external_semaphore_win32",
"VK_KHR_win32_keyed_mutex"};
std::vector<bool> extension_support(vulkan_extensions.size(), false);
GetGpuSupportedVulkanVersionAndExtensions(info, vulkan_extensions,
&extension_support);
UMA_HISTOGRAM_BOOLEAN("GPU.SupportsVulkan", info->supports_vulkan);
UMA_HISTOGRAM_ENUMERATION(
"GPU.VulkanVersion",
ConvertToHistogramVulkanVersion(info->vulkan_version));
for (size_t i = 0; i < vulkan_extensions.size(); ++i) {
std::string name = "GPU.VulkanExtSupport.";
name.append(vulkan_extensions[i]);
base::UmaHistogramBoolean(name, extension_support[i]);
}
}
bool CollectContextGraphicsInfo(GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "CollectGraphicsInfo");
DCHECK(gpu_info);
if (!CollectGraphicsInfoGL(gpu_info))
return false;
// ANGLE's renderer strings are of the form:
// ANGLE (<adapter_identifier> Direct3D<version> vs_x_x ps_x_x)
std::string direct3d_version;
int vertex_shader_major_version = 0;
int vertex_shader_minor_version = 0;
int pixel_shader_major_version = 0;
int pixel_shader_minor_version = 0;
if (RE2::FullMatch(gpu_info->gl_renderer,
"ANGLE \\(.*\\)") &&
RE2::PartialMatch(gpu_info->gl_renderer,
" Direct3D(\\w+)",
&direct3d_version) &&
RE2::PartialMatch(gpu_info->gl_renderer,
" vs_(\\d+)_(\\d+)",
&vertex_shader_major_version,
&vertex_shader_minor_version) &&
RE2::PartialMatch(gpu_info->gl_renderer,
" ps_(\\d+)_(\\d+)",
&pixel_shader_major_version,
&pixel_shader_minor_version)) {
gpu_info->vertex_shader_version =
base::StringPrintf("%d.%d",
vertex_shader_major_version,
vertex_shader_minor_version);
gpu_info->pixel_shader_version =
base::StringPrintf("%d.%d",
pixel_shader_major_version,
pixel_shader_minor_version);
DCHECK(!gpu_info->vertex_shader_version.empty());
// Note: do not reorder, used by UMA_HISTOGRAM below
enum ShaderModel {
SHADER_MODEL_UNKNOWN,
SHADER_MODEL_2_0,
SHADER_MODEL_3_0,
SHADER_MODEL_4_0,
SHADER_MODEL_4_1,
SHADER_MODEL_5_0,
NUM_SHADER_MODELS
};
ShaderModel shader_model = SHADER_MODEL_UNKNOWN;
if (gpu_info->vertex_shader_version == "5.0") {
shader_model = SHADER_MODEL_5_0;
} else if (gpu_info->vertex_shader_version == "4.1") {
shader_model = SHADER_MODEL_4_1;
} else if (gpu_info->vertex_shader_version == "4.0") {
shader_model = SHADER_MODEL_4_0;
} else if (gpu_info->vertex_shader_version == "3.0") {
shader_model = SHADER_MODEL_3_0;
} else if (gpu_info->vertex_shader_version == "2.0") {
shader_model = SHADER_MODEL_2_0;
}
UMA_HISTOGRAM_ENUMERATION("GPU.D3DShaderModel", shader_model,
NUM_SHADER_MODELS);
// DirectX diagnostics are collected asynchronously because it takes a
// couple of seconds.
}
return true;
}
bool CollectBasicGraphicsInfo(GPUInfo* gpu_info) {
TRACE_EVENT0("gpu", "CollectPreliminaryGraphicsInfo");
DCHECK(gpu_info);
// nvd3d9wrap.dll is loaded into all processes when Optimus is enabled.
HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll");
gpu_info->optimus = nvd3d9wrap != nullptr;
// Taken from http://www.nvidia.com/object/device_ids.html
DISPLAY_DEVICE dd;
dd.cb = sizeof(DISPLAY_DEVICE);
std::wstring id;
for (int i = 0; EnumDisplayDevices(nullptr, i, &dd, 0); ++i) {
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
id = dd.DeviceID;
break;
}
}
if (id.length() <= 20) {
// EnumDisplayDevices returns an empty id when called inside a remote
// session (unless that session happens to be attached to the console). In
// that case, we do not want to fail, as we should be able to grab the
// device/vendor ids from the D3D context, below. Therefore, only fail if
// the device string is not one of either the RDP mirror driver "RDPUDD
// Chained DD" or the citrix display driver.
if (wcscmp(dd.DeviceString, L"RDPUDD Chained DD") != 0 &&
wcscmp(dd.DeviceString, L"Citrix Systems Inc. Display Driver") != 0) {
// Set vendor_id/device_id for blacklisting purpose.
gpu_info->gpu.vendor_id = 0xffff;
gpu_info->gpu.device_id = 0xfffe;
return false;
}
}
DeviceIDToVendorAndDevice(id, &gpu_info->gpu.vendor_id,
&gpu_info->gpu.device_id);
// TODO(zmo): we only need to call CollectDriverInfoD3D() if we use ANGLE.
return CollectDriverInfoD3D(id, gpu_info);
}
} // namespace gpu