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

gpu / config / gpu_info_collector.cc [blame]

// 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_info_collector.h"

#include <stddef.h>
#include <stdint.h>

#include <optional>
#include <string>
#include <utility>
#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_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "gpu/config/gpu_switches.h"
#include "gpu/config/webgpu_blocklist.h"
#include "skia/buildflags.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/angle/src/gpu_info_util/SystemInfo.h"  // nogncheck
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/gl_utils.h"
#include "ui/gl/gl_version_info.h"
#include "ui/gl/init/create_gr_gl_interface.h"
#include "ui/gl/init/gl_factory.h"
#include "ui/gl/startup_trace.h"

#if BUILDFLAG(IS_MAC)
#include "base/apple/bundle_locations.h"
#include "base/apple/foundation_util.h"
#endif

#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/ozone_platform.h"           // nogncheck
#include "ui/ozone/public/platform_gl_egl_utility.h"  // nogncheck
#endif

#if !BUILDFLAG(USE_DAWN) && BUILDFLAG(SKIA_USE_DAWN)
#error "SKIA_USE_DAWN used without USE_DAWN is not supposed to work."
#endif

#if BUILDFLAG(USE_DAWN)
#include "third_party/dawn/include/dawn/dawn_proc.h"             // nogncheck
#include "third_party/dawn/include/dawn/native/DawnNative.h"     // nogncheck
#include "third_party/dawn/include/dawn/native/OpenGLBackend.h"  // nogncheck
#include "third_party/dawn/include/dawn/webgpu.h"                // nogncheck
#include "third_party/dawn/include/dawn/webgpu_cpp.h"            // nogncheck
#endif

namespace {

// From ANGLE's egl/eglext.h.
#ifndef EGL_ANGLE_feature_control
#define EGL_ANGLE_feature_control 1
#define EGL_FEATURE_NAME_ANGLE 0x3460
#define EGL_FEATURE_CATEGORY_ANGLE 0x3461
#define EGL_FEATURE_STATUS_ANGLE 0x3464
#define EGL_FEATURE_COUNT_ANGLE 0x3465
#define EGL_FEATURE_OVERRIDES_ENABLED_ANGLE 0x3466
#define EGL_FEATURE_OVERRIDES_DISABLED_ANGLE 0x3467
#endif /* EGL_ANGLE_feature_control */

scoped_refptr<gl::GLSurface> InitializeGLSurface(gl::GLDisplay* display) {
  scoped_refptr<gl::GLSurface> surface(
      gl::init::CreateOffscreenGLSurface(display, gfx::Size()));
  if (!surface.get()) {
    LOG(ERROR) << "gl::GLContext::CreateOffscreenGLSurface failed";
    return nullptr;
  }

  return surface;
}

scoped_refptr<gl::GLContext> InitializeGLContext(gl::GLSurface* surface) {
  GPU_STARTUP_TRACE_EVENT("gpu_info_collector::InitializeGLContext");
  gl::GLContextAttribs attribs;
  attribs.client_major_es_version = 2;
  scoped_refptr<gl::GLContext> context(
      gl::init::CreateGLContext(nullptr, surface, attribs));
  if (!context.get()) {
    LOG(ERROR) << "gl::init::CreateGLContext failed";
    return nullptr;
  }

  if (!context->MakeCurrent(surface)) {
    LOG(ERROR) << "gl::GLContext::MakeCurrent() failed";
    return nullptr;
  }

  return context;
}

std::string GetGLString(unsigned int pname) {
  const char* gl_string = reinterpret_cast<const char*>(glGetString(pname));
  if (gl_string)
    return std::string(gl_string);
  return std::string();
}

std::string QueryEGLStringi(EGLDisplay display,
                            unsigned int name,
                            unsigned int index) {
  const char* egl_string =
      reinterpret_cast<const char*>(eglQueryStringiANGLE(display, name, index));
  if (egl_string)
    return std::string(egl_string);
  return std::string();
}

// Return a version string in the format of "major.minor".
std::string GetVersionFromString(const std::string& version_string) {
  size_t begin = version_string.find_first_of("0123456789");
  if (begin != std::string::npos) {
    size_t end = version_string.find_first_not_of("01234567890.", begin);
    std::string sub_string;
    if (end != std::string::npos)
      sub_string = version_string.substr(begin, end - begin);
    else
      sub_string = version_string.substr(begin);
    std::vector<std::string> pieces = base::SplitString(
        sub_string, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
    if (pieces.size() >= 2)
      return pieces[0] + "." + pieces[1];
  }
  return std::string();
}

// Return the array index of the found name, or return -1.
int StringContainsName(const std::string& str,
                       base::span<const std::string> names) {
  std::vector<std::string> tokens = base::SplitString(
      str, " .,()-_", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
  for (size_t ii = 0; ii < tokens.size(); ++ii) {
    for (size_t name_index = 0; name_index < names.size(); ++name_index) {
      if (tokens[ii] == names[name_index]) {
        return base::checked_cast<int>(name_index);
      }
    }
  }
  return -1;
}

std::string GetDisplayTypeString(gl::DisplayType type) {
  switch (type) {
    case gl::DEFAULT:
      return "DEFAULT";
    case gl::SWIFT_SHADER:
      return "SWIFT_SHADER";
    case gl::ANGLE_WARP:
      return "ANGLE_WARP";
    case gl::ANGLE_D3D9:
      return "ANGLE_D3D9";
    case gl::ANGLE_D3D11:
      return "ANGLE_D3D11";
    case gl::ANGLE_OPENGL:
      return "ANGLE_OPENGL";
    case gl::ANGLE_OPENGLES:
      return "ANGLE_OPENGLES";
    case gl::ANGLE_NULL:
      return "ANGLE_NULL";
    case gl::ANGLE_D3D11_NULL:
      return "ANGLE_D3D11_NULL";
    case gl::ANGLE_OPENGL_NULL:
      return "ANGLE_OPENGL_NULL";
    case gl::ANGLE_OPENGLES_NULL:
      return "ANGLE_OPENGLES_NULL";
    case gl::ANGLE_VULKAN:
      return "ANGLE_VULKAN";
    case gl::ANGLE_VULKAN_NULL:
      return "ANGLE_VULKAN_NULL";
    case gl::ANGLE_D3D11on12:
      return "ANGLE_D3D11on12";
    case gl::ANGLE_SWIFTSHADER:
      return "ANGLE_SWIFTSHADER";
    case gl::ANGLE_OPENGL_EGL:
      return "ANGLE_OPENGL_EGL";
    case gl::ANGLE_OPENGLES_EGL:
      return "ANGLE_OPENGLES_EGL";
    case gl::ANGLE_METAL:
      return "ANGLE_METAL";
    case gl::ANGLE_METAL_NULL:
      return "ANGLE_METAL_NULL";
    default:
      NOTREACHED();
  }
}

#if BUILDFLAG(USE_DAWN)
std::string GetDawnAdapterTypeString(wgpu::AdapterType type) {
  switch (type) {
    case wgpu::AdapterType::IntegratedGPU:
      return "<Integrated GPU> ";
    case wgpu::AdapterType::DiscreteGPU:
      return "<Discrete GPU> ";
    case wgpu::AdapterType::CPU:
      return "<CPU> ";
    default:
      return "<Unknown GPU> ";
  }
}

std::string GetDawnBackendTypeString(wgpu::BackendType type) {
  switch (type) {
    case wgpu::BackendType::D3D11:
      return "D3D11 backend";
    case wgpu::BackendType::D3D12:
      return "D3D12 backend";
    case wgpu::BackendType::Metal:
      return "Metal backend";
    case wgpu::BackendType::Vulkan:
      return "Vulkan backend";
    case wgpu::BackendType::OpenGL:
      return "OpenGL backend";
    case wgpu::BackendType::OpenGLES:
      return "OpenGLES backend";
    default:
      NOTREACHED();
  }
}

void AddTogglesToDawnInfoList(dawn::native::Instance* instance,
                              const std::vector<const char*>& toggle_names,
                              std::vector<std::string>* dawn_info_list) {
  for (auto* name : toggle_names) {
    const dawn::native::ToggleInfo* info = instance->GetToggleInfo(name);
    if (info) {
      dawn_info_list->push_back(info->name);
      dawn_info_list->push_back(info->url);
      dawn_info_list->push_back(info->description);
    }
  }
}

void GetDawnTogglesForWebGPU(
    bool enable_unsafe_webgpu,
    bool enable_webgpu_developer_features,
    const std::vector<std::string>& enabled_preference,
    const std::vector<std::string>& disabled_preference,
    std::vector<const char*>* force_enabled_toggles,
    std::vector<const char*>* force_disabled_toggles) {
  // Disallows usage of SPIR-V by default for security (we only ensure that WGSL
  // is secure).
  force_enabled_toggles->push_back("disallow_spirv");
  // Enable timestamp quantization by default for privacy, unless
  // --enable-webgpu-developer-features is used.
  if (!enable_webgpu_developer_features) {
    force_enabled_toggles->push_back("timestamp_quantization");
  } else {
    force_disabled_toggles->push_back("timestamp_quantization");
  }

  for (const std::string& toggle : enabled_preference) {
    force_enabled_toggles->push_back(toggle.c_str());
  }

  for (const std::string& toggle : disabled_preference) {
    force_disabled_toggles->push_back(toggle.c_str());
  }
}

#if BUILDFLAG(SKIA_USE_DAWN)
void GetDawnTogglesForSkiaGraphite(
    std::vector<const char*>* force_enabled_toggles,
    std::vector<const char*>* force_disabled_toggles) {
#if DCHECK_IS_ON()
  force_enabled_toggles->push_back("use_user_defined_labels_in_backend");
#else
  force_enabled_toggles->push_back("disable_robustness");
  force_enabled_toggles->push_back("skip_validation");
  force_disabled_toggles->push_back("lazy_clear_resource_on_first_use");
#endif
}
#endif  // BUILDFLAG(SKIA_USE_DAWN)

void ReportWebGPUAdapterMetrics(dawn::native::Instance* instance) {
  static BASE_FEATURE(kCollectDawnGpuMetrics, "CollectDawnGpuMetrics",
                      base::FEATURE_ENABLED_BY_DEFAULT);
  if (!base::FeatureList::IsEnabled(kCollectDawnGpuMetrics)) {
    return;
  }
  WGPULimits max_limits{};
  wgpu::AdapterType adapter_type = wgpu::AdapterType::Unknown;

  wgpu::RequestAdapterOptions adapter_options = {};
  // Search for the backend used for core WebGPU.
#if BUILDFLAG(IS_WIN)
  adapter_options.backendType = wgpu::BackendType::D3D12;
#elif BUILDFLAG(IS_MAC)
  adapter_options.backendType = wgpu::BackendType::Metal;
#else
  adapter_options.backendType = wgpu::BackendType::Vulkan;
#endif

  bool supports_shader_f16 = false;
  for (dawn::native::Adapter& nativeAdapter :
       instance->EnumerateAdapters(&adapter_options)) {
    nativeAdapter.SetUseTieredLimits(false);
    wgpu::Adapter adapter = wgpu::Adapter(nativeAdapter.Get());
    wgpu::AdapterInfo info;
    adapter.GetInfo(&info);
    if (info.adapterType != wgpu::AdapterType::DiscreteGPU &&
        info.adapterType != wgpu::AdapterType::IntegratedGPU) {
      // We only care about GPU adapters and not CPU adapters.
      continue;
    }

    wgpu::SupportedLimits limits;
    limits.nextInChain = nullptr;
    if (adapter.GetLimits(&limits) != wgpu::Status::Success) {
      continue;
    }

    // Prefer the adapter with larger buffer binding size.
    if (limits.limits.maxStorageBufferBindingSize >
        max_limits.maxStorageBufferBindingSize) {
      max_limits = limits.limits;
      adapter_type = info.adapterType;
    }

    supports_shader_f16 |=
        wgpu::Adapter(adapter.Get()).HasFeature(wgpu::FeatureName::ShaderF16);
  }

  bool has_gpu_adapter = adapter_type != wgpu::AdapterType::Unknown;
  base::UmaHistogramBoolean("GPU.WebGPU.HasGpuAdapter", has_gpu_adapter);
  if (has_gpu_adapter) {
    std::string adapter_string = adapter_type == wgpu::AdapterType::DiscreteGPU
                                     ? "Discrete"
                                     : "Integrated";
    base::UmaHistogramMemoryLargeMB(
        "GPU.WebGPU.MaxStorageBufferBindingSize." + adapter_string,
        max_limits.maxStorageBufferBindingSize / (1024 * 1024));
    base::UmaHistogramCounts100000(
        "GPU.WebGPU.MaxTextureDimension2D." + adapter_string,
        max_limits.maxTextureDimension2D);

    base::UmaHistogramBoolean("GPU.WebGPU.Support.ShaderF16",
                              supports_shader_f16);
  }
}

void ReportWebGPUSupportMetrics(dawn::native::Instance* instance) {
  static BASE_FEATURE(kCollectWebGPUSupportMetrics,
                      "CollectWebGPUSupportMetrics",
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
                      base::FEATURE_DISABLED_BY_DEFAULT);
#else
                      base::FEATURE_ENABLED_BY_DEFAULT);
#endif
  if (!base::FeatureList::IsEnabled(kCollectWebGPUSupportMetrics)) {
    return;
  }
  // Note: These enum values should not change and should match those in
  // //tools/metrics/histograms/enums.xml
  enum class WebGPUSupport {
    kNone = 0,
    kCoreNone_CompatBlocklisted = 1,
    kCoreNone_CompatSupported = 2,
    kCoreBlocklisted_CompatNone = 3,
    kCoreBlocklisted_CompatBlocklisted = 4,
    kCoreBlocklisted_CompatSupported = 5,
    kCoreSupported = 6,
    kMaxValue = kCoreSupported,
  };

  bool has_core_blocklisted_adapter = false;
  bool has_core_adapter = false;
  bool has_compat_blocklisted_adapter = false;
  bool has_compat_adapter = false;

  wgpu::RequestAdapterOptions adapter_options = {};
  // Search for the backend used for core WebGPU.
#if BUILDFLAG(IS_WIN)
  adapter_options.backendType = wgpu::BackendType::D3D12;
#elif BUILDFLAG(IS_MAC)
  adapter_options.backendType = wgpu::BackendType::Metal;
#else
  adapter_options.backendType = wgpu::BackendType::Vulkan;
#endif
  // Check core adapters.
  for (const dawn::native::Adapter& native_adapter :
       instance->EnumerateAdapters(&adapter_options)) {
    wgpu::Adapter adapter(native_adapter.Get());
    wgpu::AdapterInfo info = {};
    adapter.GetInfo(&info);

    switch (info.adapterType) {
      case wgpu::AdapterType::CPU:
        // Skip CPU adapters.
        break;
      default:
        if (gpu::IsWebGPUAdapterBlocklisted(adapter).blocked) {
          has_core_blocklisted_adapter = true;
        } else {
          has_core_adapter = true;
        }
    }
  }

#if BUILDFLAG(DAWN_ENABLE_BACKEND_OPENGLES)
  // Check for compat adapters on GLES.
  adapter_options.backendType = wgpu::BackendType::OpenGLES;
  adapter_options.featureLevel = wgpu::FeatureLevel::Compatibility;

  dawn::native::opengl::RequestAdapterOptionsGetGLProc
      adapter_options_get_gl_proc = {};
  adapter_options_get_gl_proc.getProc = gl::GetGLProcAddress;
  gl::GLDisplayEGL* gl_display = gl::GLSurfaceEGL::GetGLDisplayEGL();
  if (gl_display) {
    adapter_options_get_gl_proc.display = gl_display->GetDisplay();
  } else {
    adapter_options_get_gl_proc.display = EGL_NO_DISPLAY;
  }
  adapter_options_get_gl_proc.nextInChain = adapter_options.nextInChain;
  adapter_options.nextInChain = &adapter_options_get_gl_proc;

  for (const dawn::native::Adapter& native_adapter :
       instance->EnumerateAdapters(&adapter_options)) {
    wgpu::Adapter adapter(native_adapter.Get());
    wgpu::AdapterInfo info = {};
    adapter.GetInfo(&info);

    switch (info.adapterType) {
      case wgpu::AdapterType::CPU:
        // Skip CPU adapters.
        break;
      default:
        if (gpu::IsWebGPUAdapterBlocklisted(adapter).blocked) {
          has_compat_blocklisted_adapter = true;
        } else {
          has_compat_adapter = true;
        }
    }
  }
#endif

  WebGPUSupport tier;
  if (has_core_adapter) {
    tier = WebGPUSupport::kCoreSupported;
  } else if (has_core_blocklisted_adapter) {
    if (has_compat_adapter) {
      tier = WebGPUSupport::kCoreBlocklisted_CompatSupported;
    } else if (has_compat_blocklisted_adapter) {
      tier = WebGPUSupport::kCoreBlocklisted_CompatBlocklisted;
    } else {
      tier = WebGPUSupport::kCoreBlocklisted_CompatNone;
    }
  } else {
    if (has_compat_adapter) {
      tier = WebGPUSupport::kCoreNone_CompatSupported;
    } else if (has_compat_blocklisted_adapter) {
      tier = WebGPUSupport::kCoreNone_CompatBlocklisted;
    } else {
      tier = WebGPUSupport::kNone;
    }
  }

  UMA_HISTOGRAM_ENUMERATION("GPU.WebGPU.Support", tier);
  ReportWebGPUAdapterMetrics(instance);
}
#endif  // BUILDFLAG(USE_DAWN)

}  // namespace

namespace gpu {

bool CollectGraphicsDeviceInfoFromCommandLine(
    const base::CommandLine* command_line,
    GPUInfo* gpu_info) {
  GPUInfo::GPUDevice& gpu = gpu_info->gpu;

  if (command_line->HasSwitch(switches::kGpuVendorId)) {
    const std::string vendor_id_str =
        command_line->GetSwitchValueASCII(switches::kGpuVendorId);
    base::StringToUint(vendor_id_str, &gpu.vendor_id);
  }

  if (command_line->HasSwitch(switches::kGpuDeviceId)) {
    const std::string device_id_str =
        command_line->GetSwitchValueASCII(switches::kGpuDeviceId);
    base::StringToUint(device_id_str, &gpu.device_id);
  }

#if BUILDFLAG(IS_WIN)
  if (command_line->HasSwitch(switches::kGpuSubSystemId)) {
    const std::string syb_system_id_str =
        command_line->GetSwitchValueASCII(switches::kGpuSubSystemId);
    base::StringToUint(syb_system_id_str, &gpu.sub_sys_id);
  }

  if (command_line->HasSwitch(switches::kGpuRevision)) {
    const std::string revision_str =
        command_line->GetSwitchValueASCII(switches::kGpuRevision);
    base::StringToUint(revision_str, &gpu.revision);
  }
#endif

  if (command_line->HasSwitch(switches::kGpuDriverVersion)) {
    gpu.driver_version =
        command_line->GetSwitchValueASCII(switches::kGpuDriverVersion);
  }

  bool info_updated = gpu.vendor_id || gpu.device_id ||
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
                      gpu.revision ||
#endif
#if BUILDFLAG(IS_WIN)
                      gpu.sub_sys_id ||
#endif
                      !gpu.driver_version.empty();

  return info_updated;
}

bool CollectBasicGraphicsInfo(const base::CommandLine* command_line,
                              GPUInfo* gpu_info) {
  GPU_STARTUP_TRACE_EVENT("gpu_info_collector::CollectBasicGraphicsInfo");
  // In the info-collection GPU process on Windows, we get the device info from
  // the browser.
  if (CollectGraphicsDeviceInfoFromCommandLine(command_line, gpu_info)) {
    return true;
  }

  // We can't check if passthrough is supported yet because GL may not be
  // initialized.
  gpu_info->passthrough_cmd_decoder =
      gl::UsePassthroughCommandDecoder(command_line);

  std::optional<gl::GLImplementationParts> implementation =
      gl::GetRequestedGLImplementationFromCommandLine(command_line);

  if (implementation == gl::kGLImplementationDisabled) {
    // If GL is disabled then we don't need GPUInfo.
    gpu_info->gl_vendor = "Disabled";
    gpu_info->gl_renderer = "Disabled";
    gpu_info->gl_version = "Disabled";
    return true;
  } else if (implementation == gl::GetSoftwareGLImplementation()) {
    // If using the software GL implementation, use fake vendor and
    // device ids to make sure it never gets blocklisted. It allows us
    // to proceed with loading the blocklist which may have non-device
    // specific entries we want to apply anyways (e.g., OS version
    // blocklisting).
    gpu_info->gpu.vendor_id = 0xffff;
    gpu_info->gpu.device_id = 0xffff;

    // Also declare the driver_vendor to be <SwANGLE> to be able to
    // specify exceptions based on driver_vendor==<SwANGLE> for some
    // blocklist rules.
    gpu_info->gpu.driver_vendor = "SwANGLE";

    GPUInfo swangle_gpu_info(*gpu_info);
    if (CollectBasicGraphicsInfo(&swangle_gpu_info)) {
      // Also store the machine model and version
      gpu_info->machine_model_name = swangle_gpu_info.machine_model_name;
      gpu_info->machine_model_version = swangle_gpu_info.machine_model_version;
    }

    return true;
  }

  return CollectBasicGraphicsInfo(gpu_info);
}

bool CollectGraphicsInfoGL(GPUInfo* gpu_info, gl::GLDisplay* display) {
  GPU_STARTUP_TRACE_EVENT("gpu_info_collector::CollectGraphicsInfoGL");
  DCHECK_NE(gl::GetGLImplementationParts(), gl::kGLImplementationNone);
  gl::GLDisplayEGL* egl_display = display->GetAs<gl::GLDisplayEGL>();

  // Now that we can check GL extensions, update passthrough support info.
  if (!gl::PassthroughCommandDecoderSupported()) {
    gpu_info->passthrough_cmd_decoder = false;
  }

  scoped_refptr<gl::GLSurface> surface(InitializeGLSurface(display));
  if (!surface.get()) {
    LOG(ERROR) << "Could not create surface for info collection.";
    return false;
  }

  scoped_refptr<gl::GLContext> context(InitializeGLContext(surface.get()));
  if (!context.get()) {
    LOG(ERROR) << "Could not create context for info collection.";
    return false;
  }

  if (egl_display) {
    gpu_info->display_type =
        GetDisplayTypeString(egl_display->GetDisplayType());
  }
  gpu_info->gl_renderer = GetGLString(GL_RENDERER);
  gpu_info->gl_vendor = GetGLString(GL_VENDOR);
  gpu_info->gl_version = GetGLString(GL_VERSION);
  std::string glsl_version_string = GetGLString(GL_SHADING_LANGUAGE_VERSION);

  gpu_info->gl_extensions = gl::GetGLExtensionsFromCurrentContext();
  gfx::ExtensionSet extension_set =
      gfx::MakeExtensionSet(gpu_info->gl_extensions);

  gl::GLVersionInfo gl_info(gpu_info->gl_version.c_str(),
                            gpu_info->gl_renderer.c_str(), extension_set);
  GPUInfo::GPUDevice& active_gpu = gpu_info->active_gpu();
  if (!gl_info.driver_vendor.empty() && active_gpu.driver_vendor.empty()) {
    active_gpu.driver_vendor = gl_info.driver_vendor;
  }
  if (!gl_info.driver_version.empty() && active_gpu.driver_version.empty()) {
    active_gpu.driver_version = gl_info.driver_version;
  }

  GLint max_samples = 0;
  if (gl_info.IsAtLeastGLES(3, 0) ||
      gfx::HasExtension(extension_set, "GL_ANGLE_framebuffer_multisample") ||
      gfx::HasExtension(extension_set, "GL_APPLE_framebuffer_multisample") ||
      gfx::HasExtension(extension_set, "GL_EXT_framebuffer_multisample") ||
      gfx::HasExtension(extension_set,
                        "GL_EXT_multisampled_render_to_texture") ||
      gfx::HasExtension(extension_set, "GL_NV_framebuffer_multisample")) {
    glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
  }
  gpu_info->max_msaa_samples = base::NumberToString(max_samples);

#if BUILDFLAG(IS_ANDROID)
  gpu_info->can_support_threaded_texture_mailbox =
      egl_display->ext->b_EGL_KHR_fence_sync &&
      egl_display->ext->b_EGL_KHR_image_base &&
      egl_display->ext->b_EGL_KHR_gl_texture_2D_image &&
      gfx::HasExtension(extension_set, "GL_OES_EGL_image");
#else
  gl::GLWindowSystemBindingInfo window_system_binding_info;
  if (gl::init::GetGLWindowSystemBindingInfo(gl_info,
                                             &window_system_binding_info)) {
    gpu_info->gl_ws_vendor = window_system_binding_info.vendor;
    gpu_info->gl_ws_version = window_system_binding_info.version;
    gpu_info->gl_ws_extensions = window_system_binding_info.extensions;
    gpu_info->direct_rendering_version =
        window_system_binding_info.direct_rendering_version;
  }
#endif  // BUILDFLAG(IS_ANDROID)

  bool supports_robustness =
      gfx::HasExtension(extension_set, "GL_EXT_robustness") ||
      gfx::HasExtension(extension_set, "GL_KHR_robustness") ||
      gfx::HasExtension(extension_set, "GL_ARB_robustness");
  if (supports_robustness) {
    glGetIntegerv(
        GL_RESET_NOTIFICATION_STRATEGY_ARB,
        reinterpret_cast<GLint*>(&gpu_info->gl_reset_notification_strategy));
  }

  // TODO(kbr): remove once the destruction of a current context automatically
  // clears the current context.
  context->ReleaseCurrent(surface.get());

  std::string glsl_version = GetVersionFromString(glsl_version_string);
  gpu_info->pixel_shader_version = glsl_version;
  gpu_info->vertex_shader_version = glsl_version;

  bool active_gpu_identified = false;
#if BUILDFLAG(IS_WIN)
  active_gpu_identified = IdentifyActiveGPUWithLuid(gpu_info);
#endif  // BUILDFLAG(IS_WIN)

  if (!active_gpu_identified)
    IdentifyActiveGPU(gpu_info);

  return true;
}

void IdentifyActiveGPU(GPUInfo* gpu_info) {
  const std::string kNVidiaName = "nvidia";
  const std::string kNouveauName = "nouveau";
  const std::string kIntelName = "intel";
  const std::string kAMDName = "amd";
  const std::string kATIName = "ati";
  const std::array<std::string, 5> kVendorNames = {
      {kNVidiaName, kNouveauName, kIntelName, kAMDName, kATIName}};

  const uint32_t kNVidiaID = 0x10de;
  const uint32_t kIntelID = 0x8086;
  const uint32_t kAMDID = 0x1002;
  const uint32_t kATIID = 0x1002;
  const std::array<uint32_t, 5> kVendorIDs = {
      {kNVidiaID, kNVidiaID, kIntelID, kAMDID, kATIID}};

  DCHECK(gpu_info);
  if (gpu_info->secondary_gpus.size() == 0) {
    // If there is only a single GPU, that GPU is active.
    gpu_info->gpu.active = true;
    gpu_info->gpu.vendor_string = gpu_info->gl_vendor;
    gpu_info->gpu.device_string = gpu_info->gl_renderer;
    return;
  }

  uint32_t active_vendor_id = 0;
  if (!gpu_info->gl_vendor.empty()) {
    std::string gl_vendor_lower = base::ToLowerASCII(gpu_info->gl_vendor);
    int index = StringContainsName(gl_vendor_lower, kVendorNames);
    if (index >= 0) {
      active_vendor_id = kVendorIDs[index];
    }
  }
  if (active_vendor_id == 0 && !gpu_info->gl_renderer.empty()) {
    std::string gl_renderer_lower = base::ToLowerASCII(gpu_info->gl_renderer);
    int index = StringContainsName(gl_renderer_lower, kVendorNames);
    if (index >= 0) {
      active_vendor_id = kVendorIDs[index];
    }
  }
  if (active_vendor_id == 0) {
    // We fail to identify the GPU vendor through GL_VENDOR/GL_RENDERER.
    return;
  }
  gpu_info->gpu.active = false;
  for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii)
    gpu_info->secondary_gpus[ii].active = false;

  // TODO(zmo): if two GPUs are from the same vendor, this code will always
  // set the first GPU as active, which could be wrong.
  if (active_vendor_id == gpu_info->gpu.vendor_id) {
    gpu_info->gpu.active = true;
    return;
  }
  for (size_t ii = 0; ii < gpu_info->secondary_gpus.size(); ++ii) {
    if (active_vendor_id == gpu_info->secondary_gpus[ii].vendor_id) {
      gpu_info->secondary_gpus[ii].active = true;
      return;
    }
  }
}

void FillGPUInfoFromSystemInfo(GPUInfo* gpu_info,
                               angle::SystemInfo* system_info) {
  // We fill gpu_info even when angle::GetSystemInfo failed so that we can see
  // partial information even when GPU info collection fails. Handle malformed
  // angle::SystemInfo first.
  if (system_info->gpus.empty()) {
    return;
  }
  if (system_info->activeGPUIndex < 0) {
    system_info->activeGPUIndex = 0;
  }

  angle::GPUDeviceInfo* active =
      &system_info->gpus[system_info->activeGPUIndex];

  gpu_info->gpu.vendor_id = active->vendorId;
  gpu_info->gpu.device_id = active->deviceId;
#if BUILDFLAG(IS_CHROMEOS)
  gpu_info->gpu.revision = active->revisionId;
#endif  // BUILDFLAG(IS_CHROMEOS)
  gpu_info->gpu.system_device_id = active->systemDeviceId;
  gpu_info->gpu.driver_vendor = std::move(active->driverVendor);
  gpu_info->gpu.driver_version = std::move(active->driverVersion);
  gpu_info->gpu.active = true;

  for (size_t i = 0; i < system_info->gpus.size(); i++) {
    if (static_cast<int>(i) == system_info->activeGPUIndex) {
      continue;
    }

    GPUInfo::GPUDevice device;
    device.vendor_id = system_info->gpus[i].vendorId;
    device.device_id = system_info->gpus[i].deviceId;
#if BUILDFLAG(IS_CHROMEOS)
    device.revision = system_info->gpus[i].revisionId;
#endif  // BUILDFLAG(IS_CHROMEOS)
    device.system_device_id = system_info->gpus[i].systemDeviceId;
    device.driver_vendor = std::move(system_info->gpus[i].driverVendor);
    device.driver_version = std::move(system_info->gpus[i].driverVersion);

    gpu_info->secondary_gpus.push_back(device);
  }

  gpu_info->optimus = system_info->isOptimus;
  gpu_info->amd_switchable = system_info->isAMDSwitchable;

  gpu_info->machine_model_name = system_info->machineModelName;
  gpu_info->machine_model_version = system_info->machineModelVersion;
}

void CollectGraphicsInfoForTesting(GPUInfo* gpu_info) {
  DCHECK(gpu_info);
#if BUILDFLAG(IS_ANDROID)
  CollectContextGraphicsInfo(gpu_info);
#else
  CollectBasicGraphicsInfo(gpu_info);
#endif  // BUILDFLAG(IS_ANDROID)
}

bool CollectGpuExtraInfo(gfx::GpuExtraInfo* gpu_extra_info,
                         const GpuPreferences& prefs) {
  GPU_STARTUP_TRACE_EVENT("gpu_info_collector::CollectGpuExtraInfo");
  // Populate the list of ANGLE features by querying the functions exposed by
  // EGL_ANGLE_feature_control if it's available.
  if (gl::g_driver_egl.client_ext.b_EGL_ANGLE_feature_control) {
    EGLDisplay display = gl::GLSurfaceEGL::GetGLDisplayEGL()->GetDisplay();
    EGLAttrib feature_count = 0;
    eglQueryDisplayAttribANGLE(display, EGL_FEATURE_COUNT_ANGLE,
                               &feature_count);
    gpu_extra_info->angle_features.resize(static_cast<size_t>(feature_count));
    for (size_t i = 0; i < gpu_extra_info->angle_features.size(); i++) {
      gpu_extra_info->angle_features[i].name =
          QueryEGLStringi(display, EGL_FEATURE_NAME_ANGLE, i);
      gpu_extra_info->angle_features[i].category =
          QueryEGLStringi(display, EGL_FEATURE_CATEGORY_ANGLE, i);
      gpu_extra_info->angle_features[i].status =
          QueryEGLStringi(display, EGL_FEATURE_STATUS_ANGLE, i);
    }
  }

#if BUILDFLAG(IS_OZONE)
  if (const auto* const egl_utility =
          ui::OzonePlatform::GetInstance()->GetPlatformGLEGLUtility()) {
    egl_utility->CollectGpuExtraInfo(prefs.enable_native_gpu_memory_buffers,
                                     *gpu_extra_info);
  }
#endif
  return true;
}

// TODO(crbug.com/351564777): should be UNSAFE_BUFFER_USAGE
void CollectDawnInfo(const gpu::GpuPreferences& gpu_preferences,
                     bool collect_metrics,
                     std::vector<std::string>* dawn_info_list) {
  GPU_STARTUP_TRACE_EVENT("gpu_info_collector::CollectDawnInfo");
#if BUILDFLAG(USE_DAWN)
  DawnProcTable procs = dawn::native::GetProcs();
  dawnProcSetProcs(&procs);

  std::string dawn_search_path;
  base::FilePath module_path;
#if BUILDFLAG(IS_MAC)
  if (base::apple::AmIBundled()) {
    dawn_search_path = base::apple::FrameworkBundlePath()
                           .Append("Libraries")
                           .AsEndingWithSeparator()
                           .MaybeAsASCII();
  }
  if (dawn_search_path.empty())
#endif
  {
#if BUILDFLAG(IS_IOS)
    if (base::PathService::Get(base::DIR_ASSETS, &module_path)) {
#else
    if (base::PathService::Get(base::DIR_MODULE, &module_path)) {
#endif
      dawn_search_path = module_path.AsEndingWithSeparator().MaybeAsASCII();
    }
  }
  const char* dawn_search_path_c_str = dawn_search_path.c_str();

  // Get the list of required toggles for WebGPU.
  std::vector<const char*> required_enabled_toggles_webgpu;
  std::vector<const char*> required_disabled_toggles_webgpu;

  GetDawnTogglesForWebGPU(gpu_preferences.enable_unsafe_webgpu,
                          gpu_preferences.enable_webgpu_developer_features,
                          gpu_preferences.enabled_dawn_features_list,
                          gpu_preferences.disabled_dawn_features_list,
                          &required_enabled_toggles_webgpu,
                          &required_disabled_toggles_webgpu);

  // Build toggles descriptor for instance, adapters and devices.
  wgpu::DawnTogglesDescriptor dawn_toggles;

  dawn_toggles.enabledToggleCount = required_enabled_toggles_webgpu.size();
  dawn_toggles.enabledToggles = required_enabled_toggles_webgpu.data();
  dawn_toggles.disabledToggleCount = required_disabled_toggles_webgpu.size();
  dawn_toggles.disabledToggles = required_disabled_toggles_webgpu.data();

  dawn::native::DawnInstanceDescriptor dawn_instance_desc = {};
  dawn_instance_desc.additionalRuntimeSearchPathsCount =
      dawn_search_path.empty() ? 0u : 1u;
  dawn_instance_desc.additionalRuntimeSearchPaths = &dawn_search_path_c_str;

  wgpu::InstanceDescriptor instance_desc = {};
  instance_desc.nextInChain = &dawn_instance_desc;
  // Create instance with Dawn toggles.
  dawn_instance_desc.nextInChain = &dawn_toggles;

  auto instance = std::make_unique<dawn::native::Instance>(
      reinterpret_cast<const WGPUInstanceDescriptor*>(&instance_desc));
  if (collect_metrics) {
    ReportWebGPUSupportMetrics(instance.get());
    return;
  }

  // Enumerate adapters with required toggles.
  wgpu::RequestAdapterOptions adapter_options = {};
  adapter_options.nextInChain = &dawn_toggles;

#if BUILDFLAG(DAWN_ENABLE_BACKEND_OPENGLES)
  dawn::native::opengl::RequestAdapterOptionsGetGLProc
      adapter_options_get_gl_proc = {};
  adapter_options_get_gl_proc.getProc = gl::GetGLProcAddress;
  gl::GLDisplayEGL* gl_display = gl::GLSurfaceEGL::GetGLDisplayEGL();
  EGLDisplay display = gl_display ? gl_display->GetDisplay() : EGL_NO_DISPLAY;
  adapter_options_get_gl_proc.display = display;
  adapter_options_get_gl_proc.nextInChain = adapter_options.nextInChain;
  adapter_options.nextInChain = &adapter_options_get_gl_proc;
  EGLSurface drawSurface = eglGetCurrentSurface(EGL_DRAW);
  EGLSurface readSurface = eglGetCurrentSurface(EGL_READ);
  EGLContext context = eglGetCurrentContext();

  // Dawn WebGPU API calls, such as adapter.CreateDevice(), may change the
  // EGLContext. Restore the context on return from this function.
  absl::Cleanup on_return = [display, drawSurface, readSurface, context] {
    eglMakeCurrent(display, drawSurface, readSurface, context);
  };
#endif

  for (wgpu::FeatureLevel featureLevel :
       {wgpu::FeatureLevel::Compatibility, wgpu::FeatureLevel::Core}) {
    adapter_options.featureLevel = featureLevel;
    std::vector<dawn::native::Adapter> adapters = instance->EnumerateAdapters(
        reinterpret_cast<const WGPURequestAdapterOptions*>(&adapter_options));
    for (dawn::native::Adapter& native_adapter : adapters) {
      wgpu::Adapter adapter(native_adapter.Get());
      wgpu::AdapterInfo info = {};
      adapter.GetInfo(&info);
      if (featureLevel == wgpu::FeatureLevel::Compatibility &&
          info.backendType != wgpu::BackendType::OpenGLES) {
        continue;
      }

      // Both Integrated-GPU and Discrete-GPU backend types will be displayed.
      if (info.backendType != wgpu::BackendType::Null) {
        // Get the adapter and the device name.
        std::string gpu_str = GetDawnAdapterTypeString(info.adapterType);
        gpu_str += " " + GetDawnBackendTypeString(info.backendType);
        gpu_str += " - " + std::string(info.device);
        if (featureLevel == wgpu::FeatureLevel::Compatibility) {
          gpu_str += " (Compatibility Mode)";
        }
        dawn_info_list->push_back(gpu_str);

        dawn_info_list->push_back("[WebGPU Status]");
        auto blocklist_result = IsWebGPUAdapterBlocklisted(adapter);
        if (blocklist_result.blocked) {
          dawn_info_list->push_back("Blocklisted - " + blocklist_result.reason);
        } else {
          dawn_info_list->push_back("Available");
        }

        // Get supported features under required adapter toggles if Dawn
        // available, or default toggles otherwise.
        dawn_info_list->push_back("[Adapter Supported Features]");
        wgpu::SupportedFeatures supportedFeatures;
        adapter.GetFeatures(&supportedFeatures);
        // SAFETY: Required from caller
        const auto features =
            UNSAFE_BUFFERS(base::span<const wgpu::FeatureName>(
                supportedFeatures.features, supportedFeatures.featureCount));
        for (const auto& f : features) {
          dawn_info_list->push_back(dawn::native::GetFeatureInfo(f)->name);
        }

        // Scope the lifetime of |device| to avoid accidental use after release.
        {
          // If Dawn is available, create the device with Dawn toggles.
          wgpu::DeviceDescriptor device_descriptor = {};
          device_descriptor.nextInChain = &dawn_toggles;
          wgpu::Device device = adapter.CreateDevice(&device_descriptor);
          // CreateDevice can return null if the device has been removed or
          // we've run out of memory. Ensure we don't crash in these instances.
          if (device) {
            // Get the list of enabled toggles on the device
            dawn_info_list->push_back("[Enabled Toggle Names]");
            std::vector<const char*> toggle_names =
                dawn::native::GetTogglesUsed(device.Get());
            AddTogglesToDawnInfoList(instance.get(), toggle_names,
                                     dawn_info_list);
          }
        }

        if (!required_enabled_toggles_webgpu.empty()) {
          dawn_info_list->push_back("[WebGPU Required Toggles - enabled]");
          AddTogglesToDawnInfoList(
              instance.get(), required_enabled_toggles_webgpu, dawn_info_list);
        }

        if (!required_disabled_toggles_webgpu.empty()) {
          dawn_info_list->push_back("[WebGPU Required Toggles - disabled]");
          AddTogglesToDawnInfoList(
              instance.get(), required_disabled_toggles_webgpu, dawn_info_list);
        }

#if BUILDFLAG(SKIA_USE_DAWN)
        if (gpu_preferences.gr_context_type == GrContextType::kGraphiteDawn) {
          // Get the list of required toggles for Skia.
          // TODO(sunnyps): Ideally these should come from a single source of
          // truth e.g. from DawnContextProvider or a common helper, instead of
          // just assuming some values here.
          std::vector<const char*> force_enabled_toggles_skia;
          std::vector<const char*> force_disabled_toggles_skia;
          GetDawnTogglesForSkiaGraphite(&force_enabled_toggles_skia,
                                        &force_disabled_toggles_skia);

          if (!force_enabled_toggles_skia.empty()) {
            dawn_info_list->push_back("[Skia Required Toggles - enabled]");
            AddTogglesToDawnInfoList(instance.get(), force_enabled_toggles_skia,
                                     dawn_info_list);
          }

          if (!force_disabled_toggles_skia.empty()) {
            dawn_info_list->push_back("[Skia Required Toggles - disabled]");
            AddTogglesToDawnInfoList(
                instance.get(), force_disabled_toggles_skia, dawn_info_list);
          }
        }
#endif  // BUILDFLAG(SKIA_USE_DAWN)
      }
    }
  }
#endif  // BUILDFLAG(USE_DAWN)
}

}  // namespace gpu