[go: nahoru, domu]

gpu: pulls webgpu blocking checking into standalone target/function

A utility process will use webgpu, and we want to use this code to
determine if we should use the gpu. In order to minimize
dependencies I pulled the check into a separate target.

Bug: b:301662165
Change-Id: I67e70981c08fef7fe246b324b7db7a93fa8ef53a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5034154
Reviewed-by: Brandon Jones <bajones@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1225271}
diff --git a/gpu/config/webgpu_blocklist.cc b/gpu/config/webgpu_blocklist.cc
index fcd9fc288..2199be1 100644
--- a/gpu/config/webgpu_blocklist.cc
+++ b/gpu/config/webgpu_blocklist.cc
@@ -5,27 +5,19 @@
 #include "gpu/config/webgpu_blocklist.h"
 
 #include "base/metrics/field_trial_params.h"
-#include "base/strings/pattern.h"
-#include "base/strings/string_split.h"
+#include "build/build_config.h"
 #include "gpu/config/gpu_finch_features.h"
 #include "ui/gl/buildflags.h"
 
-#if BUILDFLAG(IS_MAC)
-#include "base/mac/mac_util.h"
-#endif
-
-#if BUILDFLAG(IS_ANDROID)
-#include "base/android/build_info.h"
-#endif
-
 #if BUILDFLAG(USE_DAWN)
-#include "third_party/dawn/include/dawn/webgpu.h"  // nogncheck
+#include "gpu/config/webgpu_blocklist_impl.h"  // nogncheck
 #endif
 
 namespace gpu {
 
 namespace {
 
+#if BUILDFLAG(USE_DAWN)
 // List of patterns, delimited by |. Each pattern is of the form:
 // `vendorId(:deviceIdOrArchitecture(:driverDescription)?)?`
 // Vendor and device ids should be in hexadecimal representation, without a
@@ -36,93 +28,13 @@
 // where `params` is URL-encoded.
 const base::FeatureParam<std::string> kAdapterBlockList{
     &features::kWebGPUService, "AdapterBlockList", ""};
+#endif
 
 }  // namespace
 
 bool IsWebGPUAdapterBlocklisted(const WGPUAdapterProperties& properties) {
-  return IsWebGPUAdapterBlocklisted(properties, kAdapterBlockList.Get());
-}
-
-bool IsWebGPUAdapterBlocklisted(const WGPUAdapterProperties& properties,
-                                const std::string& blocklist) {
 #if BUILDFLAG(USE_DAWN)
-#if BUILDFLAG(IS_MAC)
-  constexpr uint32_t kAMDVendorID = 0x1002;
-  // Blocklisted due to https://crbug.com/tint/1094
-  if (base::mac::MacOSMajorVersion() < 13 &&
-      properties.vendorID == kAMDVendorID &&
-      properties.backendType == WGPUBackendType_Metal) {
-    return true;
-  }
-#endif
-
-#if BUILDFLAG(IS_ANDROID)
-  constexpr uint32_t kARMVendorID = 0x13B5;
-  constexpr uint32_t kQualcommVendorID = 0x5143;
-
-  const auto* build_info = base::android::BuildInfo::GetInstance();
-  // Only Android 12 with an ARM or Qualcomm GPU is enabled for initially.
-  // Other OS versions and GPU vendors may be fine, but have not had sufficient
-  // testing yet.
-  if (build_info->sdk_int() < base::android::SDK_VERSION_S ||
-      (properties.vendorID != kARMVendorID &&
-       properties.vendorID != kQualcommVendorID)) {
-    return true;
-  }
-#endif  // BUILDFLAG(IS_ANDROID)
-
-  // TODO(crbug.com/1266550): SwiftShader and CPU adapters are blocked until
-  // fully tested.
-  if (properties.adapterType == WGPUAdapterType_CPU) {
-    return true;
-  }
-
-  // TODO(dawn:1705): d3d11 is not full implemented yet.
-  if (properties.backendType == WGPUBackendType_D3D11) {
-    return true;
-  }
-
-  auto U32ToHexString = [](uint32_t value) {
-    std::ostringstream o;
-    o << std::hex << value;
-    return o.str();
-  };
-
-  auto blocked_patterns = base::SplitString(
-      blocklist, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-
-  for (const auto& blocked_pattern : blocked_patterns) {
-    std::vector<std::string> segments = base::SplitString(
-        blocked_pattern, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-
-    // Check if the vendorID matches the first segment.
-    if (segments.size() >= 1) {
-      if (!base::MatchPattern(U32ToHexString(properties.vendorID),
-                              segments[0])) {
-        continue;
-      }
-    }
-
-    // Check if the deviceID or architecture matches the second segment.
-    if (segments.size() >= 2) {
-      if (!base::MatchPattern(U32ToHexString(properties.deviceID),
-                              segments[1]) &&
-          !base::MatchPattern(properties.architecture, segments[1])) {
-        continue;
-      }
-    }
-
-    // Check if the driver description matches the third segment.
-    if (segments.size() >= 3) {
-      if (!base::MatchPattern(properties.driverDescription, segments[2])) {
-        continue;
-      }
-    }
-
-    // Adapter is blocked.
-    return true;
-  }
-  return false;
+  return IsWebGPUAdapterBlocklisted(properties, kAdapterBlockList.Get());
 #else
   return true;
 #endif