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 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/config/gpu_util.h"
#include <string_view>
#include "build/build_config.h"
#include "ui/gl/gpu_preference.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
// Must be included after windows.h.
#include <psapi.h>
#endif // BUILDFLAG(IS_WIN)
#include <vulkan/vulkan.h>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <thread>
#include <vector>
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/trace_event/trace_event.h"
#include "gpu/config/device_perf_info.h"
#include "gpu/config/gpu_blocklist.h"
#include "gpu/config/gpu_crash_keys.h"
#include "gpu/config/gpu_driver_bug_list.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h"
#include "gpu/config/gpu_feature_type.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/gpu_info.h"
#include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_preferences.h"
#include "gpu/config/gpu_switches.h"
#include "gpu/vulkan/buildflags.h"
#include "services/webnn/public/mojom/features.mojom-features.h"
#include "skia/buildflags.h"
#include "ui/gfx/extension_set.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_display.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/gl_utils.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "ui/gfx/android/android_surface_control_compat.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/init/gl_factory.h"
#endif // BUILDFLAG(IS_ANDROID)
namespace gpu {
namespace {
#if BUILDFLAG(IS_WIN)
// These values are persistent to logs. Entries should not be renumbered and
// numeric values should never be reused.
// This should match enum D3D11FeatureLevel in
// \tools\metrics\histograms\enums.xml
enum class D3D11FeatureLevel {
kUnknown = 0,
k9_1 = 4,
k9_2 = 5,
k9_3 = 6,
k10_0 = 7,
k10_1 = 8,
k11_0 = 9,
k11_1 = 10,
k12_0 = 11,
k12_1 = 12,
k12_2 = 13,
kMaxValue = k12_2,
};
inline D3D11FeatureLevel ConvertToHistogramD3D11FeatureLevel(
D3D_FEATURE_LEVEL d3d11_feature_level) {
switch (d3d11_feature_level) {
case D3D_FEATURE_LEVEL_1_0_CORE:
return D3D11FeatureLevel::kUnknown;
case D3D_FEATURE_LEVEL_9_1:
return D3D11FeatureLevel::k9_1;
case D3D_FEATURE_LEVEL_9_2:
return D3D11FeatureLevel::k9_2;
case D3D_FEATURE_LEVEL_9_3:
return D3D11FeatureLevel::k9_3;
case D3D_FEATURE_LEVEL_10_0:
return D3D11FeatureLevel::k10_0;
case D3D_FEATURE_LEVEL_10_1:
return D3D11FeatureLevel::k10_1;
case D3D_FEATURE_LEVEL_11_0:
return D3D11FeatureLevel::k11_0;
case D3D_FEATURE_LEVEL_11_1:
return D3D11FeatureLevel::k11_1;
case D3D_FEATURE_LEVEL_12_0:
return D3D11FeatureLevel::k12_0;
case D3D_FEATURE_LEVEL_12_1:
return D3D11FeatureLevel::k12_1;
case D3D_FEATURE_LEVEL_12_2:
return D3D11FeatureLevel::k12_2;
default:
NOTREACHED();
}
}
#endif // BUILDFLAG(IS_WIN)
GpuFeatureStatus GetAndroidSurfaceControlFeatureStatus(
const std::set<int>& blocklisted_features,
const GpuPreferences& gpu_preferences) {
#if !BUILDFLAG(IS_ANDROID)
return kGpuFeatureStatusDisabled;
#else
if (!gpu_preferences.enable_android_surface_control)
return kGpuFeatureStatusDisabled;
// SurfaceControl as used by Chrome requires using GpuFence for
// synchronization, this is based on Android native fence sync
// support. If that is unavailable, i.e. on emulator or SwiftShader,
// don't claim SurfaceControl support.
if (!gl::GetDefaultDisplayEGL()->IsAndroidNativeFenceSyncSupported())
return kGpuFeatureStatusDisabled;
DCHECK(gfx::SurfaceControl::IsSupported());
return kGpuFeatureStatusEnabled;
#endif
}
GpuFeatureStatus GetVulkanFeatureStatus(
const std::set<int>& blocklisted_features,
const GpuPreferences& gpu_preferences) {
#if BUILDFLAG(ENABLE_VULKAN)
// Only blocklist native vulkan.
if (gpu_preferences.use_vulkan == VulkanImplementationName::kNative &&
blocklisted_features.count(GPU_FEATURE_TYPE_VULKAN))
return kGpuFeatureStatusBlocklisted;
if (gpu_preferences.use_vulkan == VulkanImplementationName::kNone)
return kGpuFeatureStatusDisabled;
return kGpuFeatureStatusEnabled;
#else
return kGpuFeatureStatusDisabled;
#endif
}
GpuFeatureStatus GetGpuRasterizationFeatureStatus(
const std::set<int>& blocklisted_features,
const base::CommandLine& command_line,
bool use_swift_shader) {
if (command_line.HasSwitch(switches::kDisableGpuRasterization))
return kGpuFeatureStatusDisabled;
else if (command_line.HasSwitch(switches::kEnableGpuRasterization))
return kGpuFeatureStatusEnabled;
// If swiftshader is being used, the blocklist should be ignored.
if (!use_swift_shader &&
blocklisted_features.count(GPU_FEATURE_TYPE_GPU_TILE_RASTERIZATION)) {
return kGpuFeatureStatusBlocklisted;
}
// Enable gpu rasterization for vulkan, unless it is overridden by
// commandline.
if (features::IsUsingVulkan() &&
!base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine(
features::kDefaultEnableGpuRasterization.name,
base::FeatureList::OVERRIDE_DISABLE_FEATURE)) {
return kGpuFeatureStatusEnabled;
}
// Gpu Rasterization on platforms that are not fully enabled is controlled by
// a finch experiment.
if (!base::FeatureList::IsEnabled(features::kDefaultEnableGpuRasterization))
return kGpuFeatureStatusDisabled;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetWebGLFeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader)
return kGpuFeatureStatusEnabled;
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_WEBGL))
return kGpuFeatureStatusBlocklisted;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetWebGL2FeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader)
return kGpuFeatureStatusEnabled;
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_WEBGL2))
return kGpuFeatureStatusBlocklisted;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetWebGPUFeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader)
return kGpuFeatureStatusSoftware;
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_WEBGPU))
return kGpuFeatureStatusSoftware;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus Get2DCanvasFeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader) {
// This is for testing only. Chrome should exercise the GPU accelerated
// path on top of SwiftShader driver.
return kGpuFeatureStatusEnabled;
}
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS))
return kGpuFeatureStatusSoftware;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetAcceleratedVideoDecodeFeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader) {
// This is for testing only. Chrome should exercise the GPU accelerated
// path on top of SwiftShader driver.
return kGpuFeatureStatusEnabled;
}
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE))
return kGpuFeatureStatusBlocklisted;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetAcceleratedVideoEncodeFeatureStatus(
const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader) {
// This is for testing only. Chrome should exercise the GPU accelerated
// path on top of SwiftShader driver.
return kGpuFeatureStatusEnabled;
}
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE))
return kGpuFeatureStatusBlocklisted;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetGLFeatureStatus(const std::set<int>& blocklisted_features,
bool use_swift_shader) {
if (use_swift_shader) {
// This is for testing only. Chrome should exercise the GPU accelerated
// path on top of SwiftShader driver.
return kGpuFeatureStatusEnabled;
}
if (blocklisted_features.count(GPU_FEATURE_TYPE_ACCELERATED_GL))
return kGpuFeatureStatusBlocklisted;
return kGpuFeatureStatusEnabled;
}
GpuFeatureStatus GetSkiaGraphiteFeatureStatus(
const std::set<int>& blocklisted_features,
const GpuPreferences& gpu_preferences) {
if (blocklisted_features.count(GPU_FEATURE_TYPE_SKIA_GRAPHITE)) {
return kGpuFeatureStatusDisabled;
}
#if BUILDFLAG(SKIA_USE_DAWN)
if (gpu_preferences.gr_context_type == GrContextType::kGraphiteDawn) {
return kGpuFeatureStatusEnabled;
}
#endif // BUILDFLAG(SKIA_USE_DAWN)
#if BUILDFLAG(SKIA_USE_METAL)
if (gpu_preferences.gr_context_type == GrContextType::kGraphiteMetal) {
return kGpuFeatureStatusEnabled;
}
#endif // BUILDFLAG(SKIA_USE_METAL)
return kGpuFeatureStatusDisabled;
}
GpuFeatureStatus GetWebNNFeatureStatus(
const std::set<int>& blocklisted_features) {
if (!base::FeatureList::IsEnabled(
webnn::mojom::features::kWebMachineLearningNeuralNetwork)) {
return kGpuFeatureStatusDisabled;
}
if (blocklisted_features.count(GPU_FEATURE_TYPE_WEBNN)) {
return kGpuFeatureStatusSoftware;
}
return kGpuFeatureStatusEnabled;
}
void SetProcessGlWorkaroundsFromGpuFeatures(
const GpuFeatureInfo& gpu_feature_info) {
const auto is_enabled =
[&gpu_feature_info](const gpu::GpuDriverBugWorkaroundType& type) {
return gpu_feature_info.IsWorkaroundEnabled(type);
};
gl::GlWorkarounds workarounds = {
.disable_d3d11 = is_enabled(DISABLE_D3D11),
.disable_metal = is_enabled(DISABLE_METAL),
.disable_es3gl_context = is_enabled(DISABLE_ES3_GL_CONTEXT),
#if BUILDFLAG(IS_WIN)
.disable_direct_composition_video_overlays =
is_enabled(DISABLE_DIRECT_COMPOSITION_VIDEO_OVERLAYS),
.disable_vp_auto_hdr = is_enabled(DISABLE_VP_AUTO_HDR),
#endif
};
gl::SetGlWorkarounds(workarounds);
}
// Adjust gpu feature status based on enabled gpu driver bug workarounds.
void AdjustGpuFeatureStatusToWorkarounds(GpuFeatureInfo* gpu_feature_info,
const GPUInfo& gpu_info) {
if (gpu_feature_info->IsWorkaroundEnabled(DISABLE_D3D11) ||
gpu_feature_info->IsWorkaroundEnabled(DISABLE_ES3_GL_CONTEXT)) {
gpu_feature_info->status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL2] =
kGpuFeatureStatusBlocklisted;
}
// If disable_webnn_for_gpu workaround is enabled for the GPU device, we need
// to check to see if there is a NPU device available before setting the WebNN
// gpu feature status. If there is a NPU device, check the
// disable_webnn_for_npu workaround.
if (gpu_feature_info->IsWorkaroundEnabled(DISABLE_WEBNN_FOR_GPU)) {
if (gpu_info.npus.size() > 0) {
if (gpu_feature_info->IsWorkaroundEnabled(DISABLE_WEBNN_FOR_NPU)) {
gpu_feature_info->status_values[GPU_FEATURE_TYPE_WEBNN] =
kGpuFeatureStatusSoftware;
}
} else {
gpu_feature_info->status_values[GPU_FEATURE_TYPE_WEBNN] =
kGpuFeatureStatusSoftware;
}
}
}
// Estimates roughly user total disk space by counting in the drives where
// the exe is, where the temporary space is, where the user home is.
// If total space and free space are of the same size, they are considered
// the same drive. There could be corner cases this estimation is far from
// the actual total disk space, but for histogram purpose, limited numbers
// of outliers do not matter.
uint32_t EstimateAmountOfTotalDiskSpaceMB() {
const base::BasePathKey kPathKeys[] = {base::DIR_EXE, base::DIR_TEMP,
base::DIR_HOME};
std::vector<uint32_t> total_space_vector, free_space_vector;
uint32_t sum = 0;
for (const auto& path_key : kPathKeys) {
base::FilePath path;
if (base::PathService::Get(path_key, &path)) {
uint32_t total_space = static_cast<uint32_t>(
base::SysInfo::AmountOfTotalDiskSpace(path) / 1024 / 1024);
uint32_t free_space = static_cast<uint32_t>(
base::SysInfo::AmountOfFreeDiskSpace(path) / 1024 / 1024);
bool duplicated = false;
for (size_t ii = 0; ii < total_space_vector.size(); ++ii) {
if (total_space == total_space_vector[ii] &&
free_space == free_space_vector[ii]) {
duplicated = true;
break;
}
}
if (!duplicated) {
total_space_vector.push_back(total_space);
free_space_vector.push_back(free_space);
sum += total_space;
}
}
}
return sum;
}
// Only record Nvidia and AMD GPUs.
void RecordGpuHistogram(uint32_t vendor_id, uint32_t device_id) {
switch (vendor_id) {
case 0x10de:
base::SparseHistogram::FactoryGet(
"GPU.MultiGpu.Nvidia", base::HistogramBase::kUmaTargetedHistogramFlag)
->Add(device_id);
break;
case 0x1002:
base::SparseHistogram::FactoryGet(
"GPU.MultiGpu.AMD", base::HistogramBase::kUmaTargetedHistogramFlag)
->Add(device_id);
break;
default:
// Do nothing if it's not Nvidia/AMD.
break;
}
}
#if BUILDFLAG(IS_WIN)
uint32_t GetSystemCommitLimitMb() {
PERFORMANCE_INFORMATION perf_info = {sizeof(perf_info)};
if (::GetPerformanceInfo(&perf_info, sizeof(perf_info))) {
uint64_t limit = perf_info.CommitLimit;
limit *= perf_info.PageSize;
limit /= 1024 * 1024;
return static_cast<uint32_t>(limit);
}
return 0u;
}
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_ANDROID)
GPUInfo* g_gpu_info_cache = nullptr;
GpuFeatureInfo* g_gpu_feature_info_cache = nullptr;
#endif // BUILDFLAG(IS_ANDROID)
} // namespace
GpuFeatureInfo ComputeGpuFeatureInfoWithNoGpu() {
GpuFeatureInfo gpu_feature_info;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_TILE_RASTERIZATION] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL2] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ANDROID_SURFACE_CONTROL] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_GL] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_VULKAN] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGPU] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_SKIA_GRAPHITE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_WEBNN] =
kGpuFeatureStatusSoftware;
#if DCHECK_IS_ON()
for (int ii = 0; ii < NUMBER_OF_GPU_FEATURE_TYPES; ++ii) {
DCHECK_NE(kGpuFeatureStatusUndefined, gpu_feature_info.status_values[ii]);
}
#endif
return gpu_feature_info;
}
GpuFeatureInfo ComputeGpuFeatureInfoForSoftwareGL() {
GpuFeatureInfo gpu_feature_info;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_TILE_RASTERIZATION] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL2] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ANDROID_SURFACE_CONTROL] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_GL] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_VULKAN] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGPU] =
kGpuFeatureStatusSoftware;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_SKIA_GRAPHITE] =
kGpuFeatureStatusDisabled;
gpu_feature_info.status_values[GPU_FEATURE_TYPE_WEBNN] =
kGpuFeatureStatusSoftware;
#if DCHECK_IS_ON()
for (int ii = 0; ii < NUMBER_OF_GPU_FEATURE_TYPES; ++ii) {
DCHECK_NE(kGpuFeatureStatusUndefined, gpu_feature_info.status_values[ii]);
}
#endif
return gpu_feature_info;
}
GpuFeatureInfo ComputeGpuFeatureInfo(const GPUInfo& gpu_info,
const GpuPreferences& gpu_preferences,
base::CommandLine* command_line,
bool* needs_more_info) {
TRACE_EVENT("gpu,startup", "gpu_util::ComputeGpuFeatureInfo");
bool use_software_gl = false;
bool blocklist_needs_more_info = false;
std::optional<gl::GLImplementationParts> requested_impl =
gl::GetRequestedGLImplementationFromCommandLine(command_line);
if (requested_impl) {
if (*requested_impl == gl::kGLImplementationNone)
return ComputeGpuFeatureInfoWithNoGpu();
use_software_gl = gl::IsSoftwareGLImplementation(*requested_impl);
if (use_software_gl) {
std::string use_gl = command_line->GetSwitchValueASCII(switches::kUseGL);
std::string use_angle =
command_line->GetSwitchValueASCII(switches::kUseANGLE);
if (use_angle == gl::kANGLEImplementationSwiftShaderForWebGLName ||
use_angle == gl::kANGLEImplementationD3D11WarpForWebGLName) {
return ComputeGpuFeatureInfoForSoftwareGL();
}
}
}
if (gpu_preferences.use_vulkan ==
gpu::VulkanImplementationName::kSwiftshader) {
use_software_gl = true;
}
GpuFeatureInfo gpu_feature_info;
std::set<int> blocklisted_features;
if (!gpu_preferences.ignore_gpu_blocklist &&
!command_line->HasSwitch(switches::kUseGpuInTests)) {
std::unique_ptr<GpuBlocklist> list(GpuBlocklist::Create());
if (gpu_preferences.log_gpu_control_list_decisions)
list->EnableControlListLogging("gpu_blocklist");
unsigned target_test_group = 0u;
if (command_line->HasSwitch(switches::kGpuBlocklistTestGroup)) {
std::string test_group_string =
command_line->GetSwitchValueASCII(switches::kGpuBlocklistTestGroup);
if (!base::StringToUint(test_group_string, &target_test_group))
target_test_group = 0u;
} else if (base::FeatureList::IsEnabled(
::features::kGPUBlockListTestGroup)) {
target_test_group = ::features::kGPUBlockListTestGroupId.Get();
}
blocklisted_features = list->MakeDecision(
GpuControlList::kOsAny, std::string(), gpu_info, target_test_group);
gpu_feature_info.applied_gpu_blocklist_entries = list->GetActiveEntries();
blocklist_needs_more_info = list->needs_more_info();
}
if (needs_more_info) {
*needs_more_info = blocklist_needs_more_info;
}
#if !BUILDFLAG(IS_CHROMEOS)
gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_TILE_RASTERIZATION] =
GetGpuRasterizationFeatureStatus(blocklisted_features, *command_line,
use_software_gl);
#else
// TODO(penghuang): call GetGpuRasterizationFeatureStatus() with
// |use_software_gl|.
gpu_feature_info.status_values[GPU_FEATURE_TYPE_GPU_TILE_RASTERIZATION] =
GetGpuRasterizationFeatureStatus(blocklisted_features, *command_line,
/*use_software_gl=*/false);
#endif
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] =
GetWebGLFeatureStatus(blocklisted_features, use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL2] =
GetWebGL2FeatureStatus(blocklisted_features, use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGPU] =
GetWebGPUFeatureStatus(blocklisted_features, use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS] =
Get2DCanvasFeatureStatus(blocklisted_features, use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE] =
GetAcceleratedVideoDecodeFeatureStatus(blocklisted_features,
use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_VIDEO_ENCODE] =
GetAcceleratedVideoEncodeFeatureStatus(blocklisted_features,
use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ANDROID_SURFACE_CONTROL] =
GetAndroidSurfaceControlFeatureStatus(blocklisted_features,
gpu_preferences);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_GL] =
GetGLFeatureStatus(blocklisted_features, use_software_gl);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_VULKAN] =
GetVulkanFeatureStatus(blocklisted_features, gpu_preferences);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_SKIA_GRAPHITE] =
GetSkiaGraphiteFeatureStatus(blocklisted_features, gpu_preferences);
gpu_feature_info.status_values[GPU_FEATURE_TYPE_WEBNN] =
GetWebNNFeatureStatus(blocklisted_features);
#if DCHECK_IS_ON()
for (int ii = 0; ii < NUMBER_OF_GPU_FEATURE_TYPES; ++ii) {
DCHECK_NE(kGpuFeatureStatusUndefined, gpu_feature_info.status_values[ii]);
}
#endif
gfx::ExtensionSet all_disabled_extensions;
std::string disabled_gl_extensions_value =
command_line->GetSwitchValueASCII(switches::kDisableGLExtensions);
if (!disabled_gl_extensions_value.empty()) {
std::vector<std::string_view> command_line_disabled_extensions =
base::SplitStringPiece(disabled_gl_extensions_value, ", ;",
base::KEEP_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
all_disabled_extensions.insert(command_line_disabled_extensions.begin(),
command_line_disabled_extensions.end());
}
std::set<int> enabled_driver_bug_workarounds;
std::vector<std::string> driver_bug_disabled_extensions;
if (!command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds)) {
std::unique_ptr<gpu::GpuDriverBugList> list(GpuDriverBugList::Create());
unsigned target_test_group = 0u;
if (command_line->HasSwitch(switches::kGpuDriverBugListTestGroup)) {
std::string test_group_string = command_line->GetSwitchValueASCII(
switches::kGpuDriverBugListTestGroup);
if (!base::StringToUint(test_group_string, &target_test_group))
target_test_group = 0u;
} else if (base::FeatureList::IsEnabled(
::features::kGPUDriverBugListTestGroup)) {
target_test_group = ::features::kGPUDriverBugListTestGroupId.Get();
}
enabled_driver_bug_workarounds = list->MakeDecision(
GpuControlList::kOsAny, std::string(), gpu_info, target_test_group);
gpu_feature_info.applied_gpu_driver_bug_list_entries =
list->GetActiveEntries();
driver_bug_disabled_extensions = list->GetDisabledExtensions();
all_disabled_extensions.insert(driver_bug_disabled_extensions.begin(),
driver_bug_disabled_extensions.end());
// Disabling WebGL extensions only occurs via the blocklist, so
// the logic is simpler.
gfx::ExtensionSet disabled_webgl_extensions;
std::vector<std::string> disabled_webgl_extension_list =
list->GetDisabledWebGLExtensions();
disabled_webgl_extensions.insert(disabled_webgl_extension_list.begin(),
disabled_webgl_extension_list.end());
gpu_feature_info.disabled_webgl_extensions =
gfx::MakeExtensionString(disabled_webgl_extensions);
}
gpu::GpuDriverBugList::AppendWorkaroundsFromCommandLine(
&enabled_driver_bug_workarounds, *command_line);
gpu_feature_info.enabled_gpu_driver_bug_workarounds.insert(
gpu_feature_info.enabled_gpu_driver_bug_workarounds.begin(),
enabled_driver_bug_workarounds.begin(),
enabled_driver_bug_workarounds.end());
if (all_disabled_extensions.size()) {
gpu_feature_info.disabled_extensions =
gfx::MakeExtensionString(all_disabled_extensions);
}
AdjustGpuFeatureStatusToWorkarounds(&gpu_feature_info, gpu_info);
SetProcessGlWorkaroundsFromGpuFeatures(gpu_feature_info);
return gpu_feature_info;
}
void SetKeysForCrashLogging(const GPUInfo& gpu_info) {
const GPUInfo::GPUDevice& active_gpu = gpu_info.active_gpu();
// Don't record vendor/device ids on Android when running with GL.
constexpr bool record_zero_ids = !BUILDFLAG(IS_ANDROID);
if (record_zero_ids || active_gpu.vendor_id) {
crash_keys::gpu_vendor_id.Set(
base::StringPrintf("0x%04x", active_gpu.vendor_id));
}
if (record_zero_ids || active_gpu.device_id) {
crash_keys::gpu_device_id.Set(
base::StringPrintf("0x%04x", active_gpu.device_id));
}
#if !BUILDFLAG(IS_ANDROID)
crash_keys::gpu_count.Set(base::StringPrintf("%d", gpu_info.GpuCount()));
#endif // !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_WIN)
crash_keys::gpu_sub_sys_id.Set(
base::StringPrintf("0x%08x", active_gpu.sub_sys_id));
crash_keys::gpu_revision.Set(base::StringPrintf("%u", active_gpu.revision));
#endif // BUILDFLAG(IS_WIN)
crash_keys::gpu_driver_version.Set(active_gpu.driver_version);
crash_keys::gpu_pixel_shader_version.Set(gpu_info.pixel_shader_version);
crash_keys::gpu_vertex_shader_version.Set(gpu_info.vertex_shader_version);
crash_keys::gpu_generation_intel.Set(base::StringPrintf(
"%d", static_cast<int>(GetIntelGpuGeneration(gpu_info))));
#if BUILDFLAG(IS_MAC)
crash_keys::gpu_gl_version.Set(gpu_info.gl_version);
#elif BUILDFLAG(IS_POSIX)
crash_keys::gpu_vendor.Set(gpu_info.gl_vendor);
crash_keys::gpu_renderer.Set(gpu_info.gl_renderer);
#endif
}
#if BUILDFLAG(IS_ANDROID)
void CacheGPUInfo(const GPUInfo& gpu_info) {
DCHECK(!g_gpu_info_cache);
g_gpu_info_cache = new GPUInfo;
*g_gpu_info_cache = gpu_info;
}
bool PopGPUInfoCache(GPUInfo* gpu_info) {
if (!g_gpu_info_cache)
return false;
*gpu_info = *g_gpu_info_cache;
delete g_gpu_info_cache;
g_gpu_info_cache = nullptr;
return true;
}
void CacheGpuFeatureInfo(const GpuFeatureInfo& gpu_feature_info) {
DCHECK(!g_gpu_feature_info_cache);
g_gpu_feature_info_cache = new GpuFeatureInfo;
*g_gpu_feature_info_cache = gpu_feature_info;
}
bool PopGpuFeatureInfoCache(GpuFeatureInfo* gpu_feature_info) {
if (!g_gpu_feature_info_cache)
return false;
*gpu_feature_info = *g_gpu_feature_info_cache;
delete g_gpu_feature_info_cache;
g_gpu_feature_info_cache = nullptr;
return true;
}
gl::GLDisplay* InitializeGLThreadSafe(base::CommandLine* command_line,
const GpuPreferences& gpu_preferences,
GPUInfo* out_gpu_info,
GpuFeatureInfo* out_gpu_feature_info) {
static base::NoDestructor<base::Lock> gl_bindings_initialization_lock;
base::AutoLock auto_lock(*gl_bindings_initialization_lock);
DCHECK(command_line);
DCHECK(out_gpu_info && out_gpu_feature_info);
bool gpu_info_cached = PopGPUInfoCache(out_gpu_info);
bool gpu_feature_info_cached = PopGpuFeatureInfoCache(out_gpu_feature_info);
DCHECK_EQ(gpu_info_cached, gpu_feature_info_cached);
if (gpu_info_cached) {
// GL bindings have already been initialized in another thread.
DCHECK_NE(gl::kGLImplementationNone, gl::GetGLImplementation());
return gl::GetDefaultDisplayEGL();
}
gl::GLDisplay* gl_display = nullptr;
if (gl::GetGLImplementation() == gl::kGLImplementationNone) {
// Some tests initialize bindings by themselves.
gl_display = gl::init::InitializeGLNoExtensionsOneOff(
/*init_bindings=*/true,
/*gpu_preference=*/gl::GpuPreference::kDefault);
if (!gl_display) {
VLOG(1) << "gl::init::InitializeGLNoExtensionsOneOff failed";
return nullptr;
}
} else {
gl_display = gl::GetDefaultDisplayEGL();
}
CollectContextGraphicsInfo(out_gpu_info);
*out_gpu_feature_info = ComputeGpuFeatureInfo(*out_gpu_info, gpu_preferences,
command_line, nullptr);
if (!out_gpu_feature_info->disabled_extensions.empty()) {
gl::init::SetDisabledExtensionsPlatform(
out_gpu_feature_info->disabled_extensions);
}
if (!gl::init::InitializeExtensionSettingsOneOffPlatform(gl_display)) {
VLOG(1) << "gl::init::InitializeExtensionSettingsOneOffPlatform failed";
return nullptr;
}
CacheGPUInfo(*out_gpu_info);
CacheGpuFeatureInfo(*out_gpu_feature_info);
return gl_display;
}
#endif // BUILDFLAG(IS_ANDROID)
bool EnableSwiftShaderIfNeeded(base::CommandLine* command_line,
const GpuFeatureInfo& gpu_feature_info,
bool disable_software_rasterizer,
bool blocklist_needs_more_info) {
#if BUILDFLAG(ENABLE_SWIFTSHADER)
if (disable_software_rasterizer || blocklist_needs_more_info)
return false;
// Don't overwrite user preference.
if (gl::GetRequestedGLImplementationFromCommandLine(command_line)
.has_value()) {
return false;
}
if (gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_WEBGL] !=
kGpuFeatureStatusEnabled ||
gpu_feature_info.status_values[GPU_FEATURE_TYPE_ACCELERATED_GL] !=
kGpuFeatureStatusEnabled) {
gl::SetSoftwareWebGLCommandLineSwitches(command_line);
return true;
}
return false;
#else
return false;
#endif
}
IntelGpuSeriesType GetIntelGpuSeriesType(uint32_t vendor_id,
uint32_t device_id) {
// Note that this function's output should only depend on vendor_id and
// device_id of a GPU. This is because we record a histogram on the output
// and we don't want to expose an extra bit other than the already recorded
// vendor_id and device_id.
if (vendor_id == 0x8086) { // Intel
// The device IDs of Intel GPU are based on following Mesa source files:
// include/pci_ids/i965_pci_ids.h and iris_pci_ids.h
uint32_t masked_device_id = device_id & 0xFF00;
switch (masked_device_id) {
case 0x2900:
return IntelGpuSeriesType::kBroadwater;
case 0x2A00:
if (device_id == 0x2A02 || device_id == 0x2A12)
return IntelGpuSeriesType::kBroadwater;
if (device_id == 0x2A42)
return IntelGpuSeriesType::kEaglelake;
break;
case 0x2E00:
return IntelGpuSeriesType::kEaglelake;
case 0x0000:
return IntelGpuSeriesType::kIronlake;
case 0x0100:
if (device_id == 0x0152 || device_id == 0x0156 || device_id == 0x015A ||
device_id == 0x0162 || device_id == 0x0166 || device_id == 0x016A)
return IntelGpuSeriesType::kIvybridge;
if (device_id == 0x0155 || device_id == 0x0157)
return IntelGpuSeriesType::kBaytrail;
return IntelGpuSeriesType::kSandybridge;
case 0x0F00:
return IntelGpuSeriesType::kBaytrail;
case 0x0A00:
if (device_id == 0x0A84)
return IntelGpuSeriesType::kApollolake;
return IntelGpuSeriesType::kHaswell;
case 0x0400:
case 0x0C00:
case 0x0D00:
return IntelGpuSeriesType::kHaswell;
case 0x2200:
return IntelGpuSeriesType::kCherrytrail;
case 0x1600:
return IntelGpuSeriesType::kBroadwell;
case 0x5A00:
if (device_id == 0x5A85 || device_id == 0x5A84)
return IntelGpuSeriesType::kApollolake;
return IntelGpuSeriesType::kCannonlake;
case 0x1900:
return IntelGpuSeriesType::kSkylake;
case 0x1A00:
return IntelGpuSeriesType::kApollolake;
case 0x3100:
return IntelGpuSeriesType::kGeminilake;
case 0x5900:
if (device_id == 0x591C)
return IntelGpuSeriesType::kAmberlake;
return IntelGpuSeriesType::kKabylake;
case 0x8700:
if (device_id == 0x87C0)
return IntelGpuSeriesType::kKabylake;
if (device_id == 0x87CA)
return IntelGpuSeriesType::kCoffeelake;
break;
case 0x3E00:
if (device_id == 0x3EA0 || device_id == 0x3EA1 || device_id == 0x3EA2
|| device_id == 0x3EA4 || device_id == 0x3EA3)
return IntelGpuSeriesType::kWhiskeylake;
return IntelGpuSeriesType::kCoffeelake;
case 0x9B00:
return IntelGpuSeriesType::kCometlake;
case 0x8A00:
return IntelGpuSeriesType::kIcelake;
case 0x4500:
return IntelGpuSeriesType::kElkhartlake;
case 0x4E00:
return IntelGpuSeriesType::kJasperlake;
case 0x9A00:
return IntelGpuSeriesType::kTigerlake;
case 0x4c00:
return IntelGpuSeriesType::kRocketlake;
case 0x4900:
return IntelGpuSeriesType::kDG1;
case 0x4600:
return IntelGpuSeriesType::kAlderlake;
case 0x4F00:
case 0x5600:
return IntelGpuSeriesType::kAlchemist;
case 0xA700:
return IntelGpuSeriesType::kRaptorlake;
case 0x7D00:
if (device_id == 0x7D41 || device_id == 0x7D51 || device_id == 0x7D67 ||
device_id == 0x7DD1) {
return IntelGpuSeriesType::kArrowlake;
}
return IntelGpuSeriesType::kMeteorlake;
case 0x6400:
return IntelGpuSeriesType::kLunarlake;
case 0xE200:
return IntelGpuSeriesType::kBattlemage;
case 0xB000:
return IntelGpuSeriesType::kPantherlake;
default:
break;
}
}
return IntelGpuSeriesType::kUnknown;
}
std::string GetIntelGpuGeneration(uint32_t vendor_id, uint32_t device_id) {
if (vendor_id == 0x8086) {
IntelGpuSeriesType gpu_series = GetIntelGpuSeriesType(vendor_id, device_id);
switch (gpu_series) {
case IntelGpuSeriesType::kBroadwater:
case IntelGpuSeriesType::kEaglelake:
return "4";
case IntelGpuSeriesType::kIronlake:
return "5";
case IntelGpuSeriesType::kSandybridge:
return "6";
case IntelGpuSeriesType::kBaytrail:
case IntelGpuSeriesType::kIvybridge:
case IntelGpuSeriesType::kHaswell:
return "7";
case IntelGpuSeriesType::kCherrytrail:
case IntelGpuSeriesType::kBroadwell:
return "8";
case IntelGpuSeriesType::kApollolake:
case IntelGpuSeriesType::kSkylake:
case IntelGpuSeriesType::kGeminilake:
case IntelGpuSeriesType::kKabylake:
case IntelGpuSeriesType::kAmberlake:
case IntelGpuSeriesType::kCoffeelake:
case IntelGpuSeriesType::kWhiskeylake:
case IntelGpuSeriesType::kCometlake:
return "9";
case IntelGpuSeriesType::kCannonlake:
return "10";
case IntelGpuSeriesType::kIcelake:
case IntelGpuSeriesType::kElkhartlake:
case IntelGpuSeriesType::kJasperlake:
return "11";
case IntelGpuSeriesType::kTigerlake:
case IntelGpuSeriesType::kRocketlake:
case IntelGpuSeriesType::kDG1:
case IntelGpuSeriesType::kAlderlake:
case IntelGpuSeriesType::kAlchemist:
case IntelGpuSeriesType::kRaptorlake:
case IntelGpuSeriesType::kMeteorlake:
case IntelGpuSeriesType::kArrowlake:
return "12";
case IntelGpuSeriesType::kLunarlake:
case IntelGpuSeriesType::kBattlemage:
return "13";
case IntelGpuSeriesType::kPantherlake:
return "14";
default:
break;
}
}
return "";
}
IntelGpuGeneration GetIntelGpuGeneration(const GPUInfo& gpu_info) {
const uint32_t kIntelVendorId = 0x8086;
IntelGpuGeneration latest = IntelGpuGeneration::kNonIntel;
std::vector<uint32_t> intel_device_ids;
if (gpu_info.gpu.vendor_id == kIntelVendorId)
intel_device_ids.push_back(gpu_info.gpu.device_id);
for (const auto& gpu : gpu_info.secondary_gpus) {
if (gpu.vendor_id == kIntelVendorId)
intel_device_ids.push_back(gpu.device_id);
}
if (intel_device_ids.empty())
return latest;
latest = IntelGpuGeneration::kUnknownIntel;
for (uint32_t device_id : intel_device_ids) {
std::string gen_str = gpu::GetIntelGpuGeneration(kIntelVendorId, device_id);
int gen_int = 0;
if (gen_str.empty() || !base::StringToInt(gen_str, &gen_int))
continue;
DCHECK_GE(gen_int, static_cast<int>(IntelGpuGeneration::kUnknownIntel));
DCHECK_LE(gen_int, static_cast<int>(IntelGpuGeneration::kMaxValue));
if (gen_int > static_cast<int>(latest))
latest = static_cast<IntelGpuGeneration>(gen_int);
}
return latest;
}
void CollectDevicePerfInfo(DevicePerfInfo* device_perf_info,
bool in_browser_process) {
DCHECK(device_perf_info);
device_perf_info->total_physical_memory_mb =
static_cast<uint32_t>(base::SysInfo::AmountOfPhysicalMemoryMB());
if (!in_browser_process)
device_perf_info->total_disk_space_mb = EstimateAmountOfTotalDiskSpaceMB();
device_perf_info->hardware_concurrency =
static_cast<uint32_t>(std::thread::hardware_concurrency());
#if BUILDFLAG(IS_WIN)
device_perf_info->system_commit_limit_mb = GetSystemCommitLimitMb();
if (!in_browser_process) {
D3D_FEATURE_LEVEL d3d11_feature_level = D3D_FEATURE_LEVEL_1_0_CORE;
bool has_discrete_gpu = false;
if (CollectD3D11FeatureInfo(&d3d11_feature_level, &has_discrete_gpu)) {
device_perf_info->d3d11_feature_level = d3d11_feature_level;
device_perf_info->has_discrete_gpu =
has_discrete_gpu ? HasDiscreteGpu::kYes : HasDiscreteGpu::kNo;
}
}
#endif
}
void RecordDevicePerfInfoHistograms() {
std::optional<DevicePerfInfo> device_perf_info = GetDevicePerfInfo();
if (!device_perf_info.has_value())
return;
UMA_HISTOGRAM_COUNTS_1000("Hardware.TotalDiskSpace",
device_perf_info->total_disk_space_mb / 1024);
#if BUILDFLAG(IS_WIN)
UMA_HISTOGRAM_COUNTS_100("Memory.Total.SystemCommitLimit",
device_perf_info->system_commit_limit_mb / 1024);
UMA_HISTOGRAM_ENUMERATION("GPU.D3D11FeatureLevel",
ConvertToHistogramD3D11FeatureLevel(
device_perf_info->d3d11_feature_level));
UMA_HISTOGRAM_ENUMERATION("GPU.HasDiscreteGpu",
device_perf_info->has_discrete_gpu);
#endif // BUILDFLAG(IS_WIN)
UMA_HISTOGRAM_ENUMERATION("GPU.IntelGpuGeneration",
device_perf_info->intel_gpu_generation);
UMA_HISTOGRAM_BOOLEAN("GPU.SoftwareRendering",
device_perf_info->software_rendering);
}
void RecordDiscreteGpuHistograms(const GPUInfo& gpu_info) {
if (gpu_info.GpuCount() < 2)
return;
// To simplify logic, if there are multiple GPUs identified on a device,
// assume AMD or Nvidia is the discrete GPU.
RecordGpuHistogram(gpu_info.gpu.vendor_id, gpu_info.gpu.device_id);
for (const auto& gpu : gpu_info.secondary_gpus)
RecordGpuHistogram(gpu.vendor_id, gpu.device_id);
}
#if BUILDFLAG(IS_WIN)
std::string DirectMLFeatureLevelToString(uint32_t directml_feature_level) {
if (directml_feature_level == 0) {
return "Not supported";
} else {
return base::StringPrintf("%d.%d", (directml_feature_level >> 12) & 0xF,
(directml_feature_level >> 8) & 0xF);
}
}
std::string D3DFeatureLevelToString(uint32_t d3d_feature_level) {
if (d3d_feature_level == 0) {
return "Not supported";
} else {
return base::StringPrintf("D3D %d.%d", (d3d_feature_level >> 12) & 0xF,
(d3d_feature_level >> 8) & 0xF);
}
}
std::string VulkanVersionToString(uint32_t vulkan_version) {
if (vulkan_version == 0) {
return "Not supported";
} else {
// Vulkan version number VK_MAKE_VERSION(major, minor, patch)
// (((major) << 22) | ((minor) << 12) | (patch))
return base::StringPrintf(
"Vulkan API %d.%d.%d", (vulkan_version >> 22) & 0x3FF,
(vulkan_version >> 12) & 0x3FF, vulkan_version & 0xFFF);
}
}
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
// GPU picking is only effective with ANGLE/Metal backend on Mac and
// on Windows with EGL.
void TrySetNonSoftwareDevicePreferenceForTesting(
gl::GpuPreference gpu_preference) {
// `SetGpuPreferenceEGL` fails when a preference was previously already set.
if (GetSystemDeviceIdEGLForTesting(gpu_preference) != 0) { // IN-TEST
return;
}
GPUInfo gpu_info;
CHECK(CollectBasicGraphicsInfo(&gpu_info));
uint64_t non_software_renderer_device_id = 0;
if (!gpu_info.active_gpu().IsSoftwareRenderer()) {
non_software_renderer_device_id = gpu_info.active_gpu().system_device_id;
} else if (auto it =
std::ranges::find_if(gpu_info.secondary_gpus,
[](const GPUInfo::GPUDevice& device) {
return !device.IsSoftwareRenderer();
});
it != gpu_info.secondary_gpus.end()) {
non_software_renderer_device_id = it->system_device_id;
}
if (non_software_renderer_device_id != 0) {
SetGpuPreferenceEGL(gpu_preference, non_software_renderer_device_id);
} else {
LOG(WARNING) << "No hardware renderer device available. Tests that require "
"one may fail.";
}
}
#endif
} // namespace gpu
|