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
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_features.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/strings/string_split.h"
#include "build/build_config.h"
#include "ui/gl/gl_switches.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/pattern.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "third_party/angle/src/gpu_info_util/SystemInfo.h" // nogncheck
#include "ui/gfx/android/achoreographer_compat.h"
#include "ui/gfx/android/android_surface_control_compat.h"
#endif
namespace features {
namespace {
#if BUILDFLAG(IS_ANDROID) && BUILDFLAG(ENABLE_VALIDATING_COMMAND_DECODER)
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByBrand{
&kDefaultPassthroughCommandDecoder, "BlockListByBrand", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByDevice{
&kDefaultPassthroughCommandDecoder, "BlockListByDevice", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByAndroidBuildId{
&kDefaultPassthroughCommandDecoder, "BlockListByAndroidBuildId", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByManufacturer{
&kDefaultPassthroughCommandDecoder, "BlockListByManufacturer", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByModel{
&kDefaultPassthroughCommandDecoder, "BlockListByModel", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByBoard{
&kDefaultPassthroughCommandDecoder, "BlockListByBoard", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByAndroidBuildFP{
&kDefaultPassthroughCommandDecoder, "BlockListByAndroidBuildFP", ""};
const base::FeatureParam<std::string>
kPassthroughCommandDecoderBlockListByGPUVendorId{
&kDefaultPassthroughCommandDecoder, "BlockListByGPUVendorId", ""};
bool IsDeviceBlocked(const std::string& field, const std::string& block_list) {
auto disable_patterns = base::SplitString(
block_list, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const auto& disable_pattern : disable_patterns) {
if (base::MatchPattern(field, disable_pattern))
return true;
}
return false;
}
bool IsDeviceBlocked(angle::VendorID vendor_id, const std::string& block_list) {
auto disable_vendors = base::SplitString(
block_list, "|", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for (const auto& disable_vendor_str : disable_vendors) {
angle::VendorID disable_vendor = 0;
if (!base::StringToUint(disable_vendor_str, &disable_vendor)) {
DCHECK(false) << "BlockListByGPUVendorId vendor \"" << disable_vendor_str
<< "\" failed to parse as a VendorID.";
return false;
}
if (vendor_id == disable_vendor) {
return true;
}
}
return false;
}
#endif
BASE_FEATURE(kForceANGLEFeatures,
"ForceANGLEFeatures",
base::FEATURE_DISABLED_BY_DEFAULT);
const base::FeatureParam<std::string> kForcedANGLEEnabledFeaturesFP{
&kForceANGLEFeatures, "EnabledFeatures", ""};
const base::FeatureParam<std::string> kForcedANGLEDisabledFeaturesFP{
&kForceANGLEFeatures, "DisabledFeatures", ""};
void SplitAndAppendANGLEFeatureList(const std::string& list,
std::vector<std::string>& out_features) {
for (std::string& feature_name : base::SplitString(
list, ", ;", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
out_features.push_back(std::move(feature_name));
}
}
} // namespace
#if BUILDFLAG(IS_APPLE)
BASE_FEATURE(kGpuVsync, "GpuVsync", base::FEATURE_DISABLED_BY_DEFAULT);
#else
BASE_FEATURE(kGpuVsync, "GpuVsync", base::FEATURE_ENABLED_BY_DEFAULT);
#endif
#if BUILDFLAG(ENABLE_VALIDATING_COMMAND_DECODER)
// Use the passthrough command decoder by default. This can be overridden with
// the --use-cmd-decoder=passthrough or --use-cmd-decoder=validating flags.
// Feature lives in ui/gl because it affects the GL binding initialization on
// platforms that would otherwise not default to using EGL bindings.
BASE_FEATURE(kDefaultPassthroughCommandDecoder,
"DefaultPassthroughCommandDecoder",
base::FEATURE_DISABLED_BY_DEFAULT);
// Add a small delay in shader compiling if validating command decoder is used.
// This is to verify if passthrough command decoder impacting negatively top
// level metrics could be due to slower shader compiling.
BASE_FEATURE(kAddDelayToGLCompileShader,
"AddDelayToGLCompileShader",
base::FEATURE_DISABLED_BY_DEFAULT);
// Histogram |GrCompileShaderUs| mean is 1.8ms (native) vs 3.1ms (ANGLE).
// Therefore, we add a 1.3ms delay to shader compiling.
constexpr base::FeatureParam<base::TimeDelta> kGLCompileShaderDelay = {
&kAddDelayToGLCompileShader, /*name=*/"interval",
/*default_value=*/base::Microseconds(1300)};
#endif // !defined(PASSTHROUGH_COMMAND_DECODER_LAUNCHED)
#if BUILDFLAG(IS_WIN)
// If true, VSyncThreadWin will use the primary monitor's
// refresh rate as the vsync interval.
BASE_FEATURE(kUsePrimaryMonitorVSyncIntervalOnSV3,
"UsePrimaryMonitorVSyncIntervalOnSV3",
base::FEATURE_ENABLED_BY_DEFAULT);
// If true, VsyncThreadWin will use the compositor clock
// to determine the vsync interval.
BASE_FEATURE(kUseCompositorClockVSyncInterval,
"UseCompositorClockVSyncInterval",
base::FEATURE_DISABLED_BY_DEFAULT);
bool UseCompositorClockVSyncInterval() {
return base::win::GetVersion() >= base::win::Version::WIN11_24H2 &&
base::FeatureList::IsEnabled(
features::kUseCompositorClockVSyncInterval);
}
#endif // BUILDFLAG(IS_WIN)
bool UseGpuVsync() {
return !base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuVsync) &&
base::FeatureList::IsEnabled(features::kGpuVsync);
}
bool IsAndroidFrameDeadlineEnabled() {
#if BUILDFLAG(IS_ANDROID)
static bool enabled = base::android::BuildInfo::GetInstance()->sdk_int() >=
base::android::SDK_VERSION_T &&
gfx::AChoreographerCompat33::Get().supported &&
gfx::SurfaceControl::SupportsSetFrameTimeline() &&
gfx::SurfaceControl::SupportsSetEnableBackPressure();
return enabled;
#else
return false;
#endif
}
bool UsePassthroughCommandDecoder() {
#if !BUILDFLAG(ENABLE_VALIDATING_COMMAND_DECODER)
return true;
#else
if (!base::FeatureList::IsEnabled(kDefaultPassthroughCommandDecoder))
return false;
#if BUILDFLAG(IS_ANDROID)
// Check block list against build info.
const auto* build_info = base::android::BuildInfo::GetInstance();
if (IsDeviceBlocked(build_info->brand(),
kPassthroughCommandDecoderBlockListByBrand.Get()))
return false;
if (IsDeviceBlocked(build_info->device(),
kPassthroughCommandDecoderBlockListByDevice.Get()))
return false;
if (IsDeviceBlocked(
build_info->android_build_id(),
kPassthroughCommandDecoderBlockListByAndroidBuildId.Get()))
return false;
if (IsDeviceBlocked(build_info->manufacturer(),
kPassthroughCommandDecoderBlockListByManufacturer.Get()))
return false;
if (IsDeviceBlocked(build_info->model(),
kPassthroughCommandDecoderBlockListByModel.Get()))
return false;
if (IsDeviceBlocked(build_info->board(),
kPassthroughCommandDecoderBlockListByBoard.Get()))
return false;
if (IsDeviceBlocked(
build_info->android_build_fp(),
kPassthroughCommandDecoderBlockListByAndroidBuildFP.Get()))
return false;
// Only check system info once and cache if the vendor is blocked.
static std::optional<bool> gpu_vendor_blocked;
if (!gpu_vendor_blocked.has_value()) {
angle::SystemInfo angle_system_info;
if (angle::GetSystemInfo(&angle_system_info) &&
!angle_system_info.gpus.empty()) {
angle::VendorID gpu_vendor_id =
angle_system_info.gpus[angle_system_info.activeGPUIndex].vendorId;
gpu_vendor_blocked = IsDeviceBlocked(
gpu_vendor_id,
kPassthroughCommandDecoderBlockListByGPUVendorId.Get());
} else {
// If system info collection fails, do not blocklist this device by GPU
// vendor ID. Instead rely on individual device model or device ID
// blocking.
gpu_vendor_blocked = false;
}
}
DCHECK(gpu_vendor_blocked.has_value());
if (gpu_vendor_blocked.value()) {
return false;
}
#endif // BUILDFLAG(IS_ANDROID)
return true;
#endif // defined(PASSTHROUGH_COMMAND_DECODER_LAUNCHED)
}
#if DCHECK_IS_ON()
bool IsANGLEValidationEnabled() {
return true;
}
#else
// Enables the use of ANGLE validation for EGL and GL (non-WebGL) contexts.
BASE_FEATURE(kDefaultEnableANGLEValidation,
"DefaultEnableANGLEValidation",
base::FEATURE_DISABLED_BY_DEFAULT);
bool IsANGLEValidationEnabled() {
return base::FeatureList::IsEnabled(kDefaultEnableANGLEValidation) &&
UsePassthroughCommandDecoder();
}
#endif
// Killswitch feature for allowing ANGLE to pass untranslated shaders to the
// driver.
BASE_FEATURE(kAllowANGLEPassthroughShaders,
"AllowANGLEPassthroughShaders",
base::FEATURE_ENABLED_BY_DEFAULT);
bool IsANGLEPassthroughShadersAllowed() {
return base::FeatureList::IsEnabled(kAllowANGLEPassthroughShaders);
}
void GetANGLEFeaturesFromCommandLineAndFinch(
const base::CommandLine* command_line,
std::vector<std::string>& enabled_angle_features,
std::vector<std::string>& disabled_angle_features) {
SplitAndAppendANGLEFeatureList(
command_line->GetSwitchValueASCII(switches::kEnableANGLEFeatures),
enabled_angle_features);
SplitAndAppendANGLEFeatureList(
command_line->GetSwitchValueASCII(switches::kDisableANGLEFeatures),
disabled_angle_features);
if (base::FeatureList::IsEnabled(kForceANGLEFeatures)) {
SplitAndAppendANGLEFeatureList(kForcedANGLEEnabledFeaturesFP.Get(),
enabled_angle_features);
SplitAndAppendANGLEFeatureList(kForcedANGLEDisabledFeaturesFP.Get(),
disabled_angle_features);
}
}
#if BUILDFLAG(ENABLE_SWIFTSHADER)
bool IsSwiftShaderAllowedByCommandLine(const base::CommandLine* command_line) {
// If the switch to opt-into unsafe SwiftShader is present, always allow
// SwiftShader.
if (command_line->HasSwitch(switches::kEnableUnsafeSwiftShader)) {
return true;
}
std::string angle_name =
command_line->GetSwitchValueASCII(switches::kUseANGLE);
if (angle_name == gl::kANGLEImplementationSwiftShaderName) {
// If SwiftShader is specifically requested with the --use-angle command
// line flag, allow it.
return true;
}
return false;
}
// Allow fallback to SwfitShader without command line flags during the
// deprecation period.
BASE_FEATURE(kAllowSwiftShaderFallback,
"AllowSwiftShaderFallback",
base::FEATURE_ENABLED_BY_DEFAULT);
bool IsSwiftShaderAllowedByFeature() {
return base::FeatureList::IsEnabled(kAllowSwiftShaderFallback);
}
#else
bool IsSwiftShaderAllowedByCommandLine(const base::CommandLine*) {
return false;
}
bool IsSwiftShaderAllowedByFeature() {
return false;
}
#endif
bool IsSwiftShaderAllowed(const base::CommandLine* command_line) {
return IsSwiftShaderAllowedByCommandLine(command_line) ||
IsSwiftShaderAllowedByFeature();
}
#if BUILDFLAG(IS_WIN)
BASE_FEATURE(kAllowD3D11WarpFallback,
"AllowD3D11WarpFallback",
base::FEATURE_DISABLED_BY_DEFAULT);
#endif
bool IsAnySoftwareGLAllowed(const base::CommandLine* command_line) {
#if BUILDFLAG(IS_WIN)
if (base::FeatureList::IsEnabled(kAllowD3D11WarpFallback)) {
return true;
}
#endif
return IsSwiftShaderAllowed(command_line);
}
BASE_FEATURE(kAllowSoftwareGLFallbackDueToCrashes,
"AllowSoftwareGLFallbackDueToCrashes",
base::FEATURE_ENABLED_BY_DEFAULT);
bool IsSoftwareGLFallbackDueToCrashesAllowed(
const base::CommandLine* command_line) {
if (!IsAnySoftwareGLAllowed(command_line)) {
return false;
}
return base::FeatureList::IsEnabled(kAllowSoftwareGLFallbackDueToCrashes);
}
base::TimeDelta GetGLCompileShaderDelay() {
#if BUILDFLAG(ENABLE_VALIDATING_COMMAND_DECODER)
if (UsePassthroughCommandDecoder()) {
return base::TimeDelta();
}
if (!base::FeatureList::IsEnabled(kAddDelayToGLCompileShader)) {
return base::TimeDelta();
}
return kGLCompileShaderDelay.Get();
#else
return base::TimeDelta();
#endif // BUILDFLAG(ENABLE_VALIDATING_COMMAND_DECODER)
}
} // namespace features
|