blob: 9722bece3aa65b5cc7192dd44dd2eddb9d2cb3dd [file] [log] [blame]
Avi Drissman05dfbc822022-09-13 21:25:341// Copyright 2016 The Chromium Authors
geofflangdf7fff2d42016-11-11 00:34:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "gpu/command_buffer/service/service_utils.h"
6
Jonathan Backer7bc44592018-04-25 19:59:507#include <string>
Helmut Januschkab81e97dc2024-04-17 14:57:058#include <string_view>
Jonathan Backer7bc44592018-04-25 19:59:509
geofflang3ab039d2017-02-22 15:33:5810#include "base/command_line.h"
Corentin Walleze660b152020-07-15 16:07:5411#include "base/logging.h"
Jonathan Backer7bc44592018-04-25 19:59:5012#include "base/strings/string_number_conversions.h"
Jiawei Shao04b8bcd2020-11-14 01:29:4713#include "base/strings/string_split.h"
David Sanders79044f02025-01-17 21:42:4714#include "base/strings/string_util.h"
Sean Gilhuly3e84fc82020-01-22 22:06:4515#include "build/build_config.h"
geofflangdf7fff2d42016-11-11 00:34:0316#include "gpu/command_buffer/common/gles2_cmd_utils.h"
Geoff Lang619081b2017-08-31 19:23:3117#include "gpu/command_buffer/service/context_group.h"
Geoff Langd72f1e92017-10-12 23:31:3818#include "gpu/command_buffer/service/gpu_switches.h"
Peng Huangdc3c68f42019-09-15 02:27:2219#include "gpu/config/gpu_finch_features.h"
Sean Gilhulye5342322019-11-08 16:40:5320#include "skia/buildflags.h"
Geoff Lang7e4a3072024-02-16 15:04:5921#include "ui/gl/gl_bindings.h"
Geoff Lang2ccdaab2025-03-20 17:14:3522#include "ui/gl/gl_features.h"
Geoff Lang7e4a3072024-02-16 15:04:5923#include "ui/gl/gl_implementation.h"
Geoff Lang2ccdaab2025-03-20 17:14:3524#include "ui/gl/gl_surface_egl.h"
geofflang3ab039d2017-02-22 15:33:5825#include "ui/gl/gl_switches.h"
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3326#include "ui/gl/gl_utils.h"
Geoff Lang619081b2017-08-31 19:23:3127
geofflangdf7fff2d42016-11-11 00:34:0328namespace gpu {
29namespace gles2 {
30
Jonathan Backer7bc44592018-04-25 19:59:5031namespace {
32
33bool GetUintFromSwitch(const base::CommandLine* command_line,
Helmut Januschkab81e97dc2024-04-17 14:57:0534 std::string_view switch_string,
Jonathan Backer7bc44592018-04-25 19:59:5035 uint32_t* value) {
Antonio Maiorano32b31002023-08-30 14:07:1736 if (!command_line->HasSwitch(switch_string)) {
Jonathan Backer7bc44592018-04-25 19:59:5037 return false;
Antonio Maiorano32b31002023-08-30 14:07:1738 }
Jonathan Backer7bc44592018-04-25 19:59:5039 std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
40 return base::StringToUint(switch_value, value);
41}
42
Sunny Sachanandani76396e82024-07-17 22:00:3343// Parse the value of --use-vulkan from the command line. If unspecified and
44// features::kVulkan is enabled (GrContext is going to use vulkan), default to
45// the native implementation.
46VulkanImplementationName ParseVulkanImplementationName(
47 const base::CommandLine* command_line) {
48#if BUILDFLAG(IS_ANDROID)
49 if (command_line->HasSwitch(switches::kWebViewDrawFunctorUsesVulkan)) {
50 return VulkanImplementationName::kForcedNative;
51 }
52#endif
53
54 if (command_line->HasSwitch(switches::kUseVulkan)) {
55 auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan);
56 if (value.empty() || value == switches::kVulkanImplementationNameNative) {
57 return VulkanImplementationName::kForcedNative;
58 } else if (value == switches::kVulkanImplementationNameSwiftshader) {
59 return VulkanImplementationName::kSwiftshader;
60 }
61 }
62
63 if (features::IsUsingVulkan()) {
64 // If the vulkan feature is enabled from command line, we will force to use
65 // vulkan even if it is blocklisted.
66 return base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine(
67 features::kVulkan.name,
68 base::FeatureList::OVERRIDE_ENABLE_FEATURE)
69 ? VulkanImplementationName::kForcedNative
70 : VulkanImplementationName::kNative;
71 }
72
73 // GrContext is not going to use Vulkan.
74 return VulkanImplementationName::kNone;
75}
76
77WebGPUAdapterName ParseWebGPUAdapterName(
78 const base::CommandLine* command_line) {
79 if (command_line->HasSwitch(switches::kUseWebGPUAdapter)) {
80 auto value = command_line->GetSwitchValueASCII(switches::kUseWebGPUAdapter);
81
82 static const struct {
83 const char* name;
84 WebGPUAdapterName value;
85 } kAdapterNames[] = {
86 {"", WebGPUAdapterName::kDefault},
87 {"default", WebGPUAdapterName::kDefault},
88 {"d3d11", WebGPUAdapterName::kD3D11},
89 {"opengles", WebGPUAdapterName::kOpenGLES},
90 {"swiftshader", WebGPUAdapterName::kSwiftShader},
91 };
92
93 for (const auto& adapter_name : kAdapterNames) {
94 if (value == adapter_name.name) {
95 return adapter_name.value;
96 }
97 }
98
99 DLOG(ERROR) << "Invalid switch " << switches::kUseWebGPUAdapter << "="
100 << value << ".";
101 }
102 return WebGPUAdapterName::kDefault;
103}
104
105WebGPUPowerPreference ParseWebGPUPowerPreference(
106 const base::CommandLine* command_line) {
107 if (command_line->HasSwitch(switches::kUseWebGPUPowerPreference)) {
108 auto value =
109 command_line->GetSwitchValueASCII(switches::kUseWebGPUPowerPreference);
110 if (value.empty()) {
111 return WebGPUPowerPreference::kNone;
112 } else if (value == "none") {
113 return WebGPUPowerPreference::kNone;
114 } else if (value == "default-low-power") {
115 return WebGPUPowerPreference::kDefaultLowPower;
116 } else if (value == "default-high-performance") {
117 return WebGPUPowerPreference::kDefaultHighPerformance;
118 } else if (value == "force-low-power") {
119 return WebGPUPowerPreference::kForceLowPower;
120 } else if (value == "force-high-performance") {
121 return WebGPUPowerPreference::kForceHighPerformance;
122 } else {
123 DLOG(ERROR) << "Invalid switch " << switches::kUseWebGPUPowerPreference
124 << "=" << value << ".";
125 }
126 }
127 return WebGPUPowerPreference::kNone;
128}
129
Jonathan Backer7bc44592018-04-25 19:59:50130} // namespace
131
Vasiliy Telezhnikovc18ab412023-11-14 16:27:07132gl::GLContextAttribs GenerateGLContextAttribsForDecoder(
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46133 ContextType context_type,
134 gl::GpuPreference gpu_preference,
Geoff Lang619081b2017-08-31 19:23:31135 const ContextGroup* context_group) {
geofflangdf7fff2d42016-11-11 00:34:03136 gl::GLContextAttribs attribs;
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46137 attribs.gpu_preference = gpu_preference;
Vasiliy Telezhnikovc18ab412023-11-14 16:27:07138 if (context_group->use_passthrough_cmd_decoder()) {
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46139 attribs.webgl_compatibility_context = IsWebGLContextType(context_type);
geofflang3ab039d2017-02-22 15:33:58140
Jonathan Ross6b1ca232020-07-31 16:43:36141 // Always use the global texture and semaphore share group for the
142 // passthrough command decoder
geofflang3ab039d2017-02-22 15:33:58143 attribs.global_texture_share_group = true;
Jonathan Ross6b1ca232020-07-31 16:43:36144 attribs.global_semaphore_share_group = true;
geofflang3ab039d2017-02-22 15:33:58145
Geoff Lang7f82ef42017-09-23 17:56:02146 attribs.robust_resource_initialization = true;
Jiajia Qin69aeeb22017-11-09 05:16:18147 attribs.robust_buffer_access = true;
Geoff Lang52469f32024-07-25 14:41:08148 attribs.allow_client_arrays = false;
Geoff Lang7f82ef42017-09-23 17:56:02149
geofflang3ab039d2017-02-22 15:33:58150 // Request a specific context version instead of always 3.0
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46151 if (IsWebGL2OrES3ContextType(context_type)) {
geofflang3ab039d2017-02-22 15:33:58152 attribs.client_major_es_version = 3;
153 attribs.client_minor_es_version = 0;
154 } else {
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46155 DCHECK(IsWebGL1OrES2ContextType(context_type));
geofflang3ab039d2017-02-22 15:33:58156 attribs.client_major_es_version = 2;
157 attribs.client_minor_es_version = 0;
158 }
159 } else {
160 attribs.client_major_es_version = 3;
161 attribs.client_minor_es_version = 0;
geofflangdf7fff2d42016-11-11 00:34:03162 }
geofflang3ab039d2017-02-22 15:33:58163
Will Harrisc5313ac2023-03-01 23:42:03164 if (gl::GetGlWorkarounds().disable_es3gl_context) {
geofflang3ab039d2017-02-22 15:33:58165 // Forcefully disable ES3 contexts
166 attribs.client_major_es_version = 2;
167 attribs.client_minor_es_version = 0;
168 }
169
Vasiliy Telezhnikovfc0556ed2025-09-08 18:46:46170 if (IsES31ForTestingContextType(context_type)) {
Geoff Langd0c755c2021-01-18 21:58:16171 // Forcefully disable ES 3.1 contexts. Tests create contexts by initializing
172 // the attributes directly.
173 attribs.client_major_es_version = 2;
174 attribs.client_minor_es_version = 0;
175 }
176
geofflangdf7fff2d42016-11-11 00:34:03177 return attribs;
178}
179
Vasiliy Telezhnikovc18ab412023-11-14 16:27:07180gl::GLContextAttribs GenerateGLContextAttribsForCompositor(
181 bool use_passthrough_cmd_decoder) {
182 gl::GLContextAttribs attribs;
183 if (use_passthrough_cmd_decoder) {
Vasiliy Telezhnikovc18ab412023-11-14 16:27:07184 // Always use the global texture and semaphore share group for the
185 // passthrough command decoder
186 attribs.global_texture_share_group = true;
187 attribs.global_semaphore_share_group = true;
188
Geoff Lang2ccdaab2025-03-20 17:14:35189 attribs.passthrough_shaders = features::IsANGLEPassthroughShadersAllowed();
190
Geoff Lang18df8bba2024-04-03 17:04:04191 // Disable resource initialization and buffer bounds checks for trusted
192 // contexts.
193 attribs.robust_resource_initialization = false;
194 attribs.robust_buffer_access = false;
Geoff Lang52469f32024-07-25 14:41:08195 attribs.allow_client_arrays = true;
Vasiliy Telezhnikovc18ab412023-11-14 16:27:07196 }
197
198 bool force_es2_context = gl::GetGlWorkarounds().disable_es3gl_context;
199 if (features::UseGles2ForOopR() && use_passthrough_cmd_decoder) {
200 force_es2_context = true;
201 }
202
203 attribs.client_major_es_version = force_es2_context ? 2 : 3;
204 attribs.client_minor_es_version = 0;
205
206 return attribs;
207}
208
Geoff Langd72f1e92017-10-12 23:31:38209bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) {
Jonah Ryan-Davis570ab8b92019-07-08 20:03:33210 return gl::UsePassthroughCommandDecoder(command_line);
Geoff Langd72f1e92017-10-12 23:31:38211}
212
Jonathan Backer7bc44592018-04-25 19:59:50213GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) {
214 GpuPreferences gpu_preferences;
215 gpu_preferences.compile_shader_always_succeeds =
216 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
217 gpu_preferences.disable_gl_error_limit =
218 command_line->HasSwitch(switches::kDisableGLErrorLimit);
219 gpu_preferences.disable_glsl_translator =
220 command_line->HasSwitch(switches::kDisableGLSLTranslator);
221 gpu_preferences.disable_shader_name_hashing =
222 command_line->HasSwitch(switches::kDisableShaderNameHashing);
223 gpu_preferences.enable_gpu_command_logging =
224 command_line->HasSwitch(switches::kEnableGPUCommandLogging);
225 gpu_preferences.enable_gpu_debugging =
226 command_line->HasSwitch(switches::kEnableGPUDebugging);
227 gpu_preferences.enable_gpu_service_logging_gpu =
228 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
229 gpu_preferences.enable_gpu_driver_debug_logging =
230 command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging);
231 gpu_preferences.disable_gpu_program_cache =
232 command_line->HasSwitch(switches::kDisableGpuProgramCache);
233 gpu_preferences.enforce_gl_minimums =
234 command_line->HasSwitch(switches::kEnforceGLMinimums);
Wez4f8b5432019-12-31 06:40:11235 if (GetUintFromSwitch(
236 command_line, switches::kForceGpuMemDiscardableLimitMb,
237 &gpu_preferences.force_gpu_mem_discardable_limit_bytes)) {
238 gpu_preferences.force_gpu_mem_discardable_limit_bytes *= 1024 * 1024;
Jonathan Backer7bc44592018-04-25 19:59:50239 }
Sergey Ulanov689c31f2020-01-24 23:21:16240 GetUintFromSwitch(command_line, switches::kForceMaxTextureSize,
241 &gpu_preferences.force_max_texture_size);
Jonathan Backer7bc44592018-04-25 19:59:50242 if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
243 &gpu_preferences.gpu_program_cache_size)) {
244 gpu_preferences.gpu_program_cache_size *= 1024;
245 }
246 gpu_preferences.disable_gpu_shader_disk_cache =
247 command_line->HasSwitch(switches::kDisableGpuShaderDiskCache);
248 gpu_preferences.enable_threaded_texture_mailboxes =
249 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
250 gpu_preferences.gl_shader_interm_output =
251 command_line->HasSwitch(switches::kGLShaderIntermOutput);
Jonathan Backer7bc44592018-04-25 19:59:50252 gpu_preferences.enable_gpu_service_logging =
253 command_line->HasSwitch(switches::kEnableGPUServiceLogging);
254 gpu_preferences.enable_gpu_service_tracing =
255 command_line->HasSwitch(switches::kEnableGPUServiceTracing);
256 gpu_preferences.use_passthrough_cmd_decoder =
257 gpu::gles2::UsePassthroughCommandDecoder(command_line);
Corentin Wallez5cbffcc2020-07-08 10:23:57258 gpu_preferences.ignore_gpu_blocklist =
Corentin Walleze660b152020-07-15 16:07:54259 command_line->HasSwitch(switches::kIgnoreGpuBlocklist);
Kai Ninomiya328e07a2018-08-23 01:08:16260 gpu_preferences.enable_webgpu =
shrekshaoc6539252021-04-29 19:21:56261 command_line->HasSwitch(switches::kEnableUnsafeWebGPU) ||
Corentin Walleza059a3a22021-07-30 09:44:54262 base::FeatureList::IsEnabled(features::kWebGPUService);
Austin Enga442d5832022-01-15 03:00:15263 gpu_preferences.enable_unsafe_webgpu =
Corentin Wallez721293f2021-06-03 22:42:00264 command_line->HasSwitch(switches::kEnableUnsafeWebGPU);
François Beaufort64123362023-10-04 13:56:50265 gpu_preferences.enable_webgpu_developer_features =
266 command_line->HasSwitch(switches::kEnableWebGPUDeveloperFeatures);
Austin Eng80eb7962022-02-07 20:35:37267 gpu_preferences.use_webgpu_adapter = ParseWebGPUAdapterName(command_line);
Shrek Shaod457e862023-03-22 23:06:05268 gpu_preferences.use_webgpu_power_preference =
269 ParseWebGPUPowerPreference(command_line);
Stephen White602bf502023-05-17 21:10:50270 gpu_preferences.force_webgpu_compat =
271 command_line->HasSwitch(switches::kForceWebGPUCompat);
Austin Engbac59e692021-05-13 16:46:54272 if (command_line->HasSwitch(switches::kEnableDawnBackendValidation)) {
273 auto value = command_line->GetSwitchValueASCII(
274 switches::kEnableDawnBackendValidation);
275 if (value.empty() || value == "full") {
276 gpu_preferences.enable_dawn_backend_validation =
277 DawnBackendValidationLevel::kFull;
278 } else if (value == "partial") {
279 gpu_preferences.enable_dawn_backend_validation =
280 DawnBackendValidationLevel::kPartial;
281 }
282 }
Jiawei Shao04b8bcd2020-11-14 01:29:47283 if (command_line->HasSwitch(switches::kEnableDawnFeatures)) {
284 gpu_preferences.enabled_dawn_features_list = base::SplitString(
285 command_line->GetSwitchValueASCII(switches::kEnableDawnFeatures), ",",
286 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
287 }
288 if (command_line->HasSwitch(switches::kDisableDawnFeatures)) {
289 gpu_preferences.disabled_dawn_features_list = base::SplitString(
290 command_line->GetSwitchValueASCII(switches::kDisableDawnFeatures), ",",
291 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
292 }
Sunny Sachanandanifb74c17f2023-04-10 21:29:17293 gpu_preferences.gr_context_type = ParseGrContextType(command_line);
Peng Huanga5299ec2023-12-18 21:51:42294 // ParseGrContextType checks Vulkan setting as well, so only parse Vulkan
295 // implementation name if gr_context_type is kVulkan.
296 gpu_preferences.use_vulkan =
297 gpu_preferences.gr_context_type == GrContextType::kVulkan
298 ? ParseVulkanImplementationName(command_line)
299 : VulkanImplementationName::kNone;
Sergey Ulanovefa2af12022-06-28 23:17:47300
301#if BUILDFLAG(IS_FUCHSIA)
302 // Vulkan Surface is not used on Fuchsia.
303 gpu_preferences.disable_vulkan_surface = true;
304#else
Peng Huang556da902019-03-22 17:49:40305 gpu_preferences.disable_vulkan_surface =
306 command_line->HasSwitch(switches::kDisableVulkanSurface);
Sergey Ulanovefa2af12022-06-28 23:17:47307#endif
Vasiliy Telezhnikov533c5642019-12-03 15:10:16308
309 gpu_preferences.enable_gpu_blocked_time_metric =
310 command_line->HasSwitch(switches::kEnableGpuBlockedTime);
311
Jonathan Backer7bc44592018-04-25 19:59:50312 return gpu_preferences;
313}
Geoff Lang619081b2017-08-31 19:23:31314
Sunny Sachanandanifb74c17f2023-04-10 21:29:17315GrContextType ParseGrContextType(const base::CommandLine* command_line) {
Sunny Sachanandaniaba318bb2023-09-06 20:22:22316 if (features::IsSkiaGraphiteEnabled(command_line)) {
Sunny Sachanandanifb74c17f2023-04-10 21:29:17317 [[maybe_unused]] auto value =
318 command_line->GetSwitchValueASCII(switches::kSkiaGraphiteBackend);
Sean Gilhuly3e84fc82020-01-22 22:06:45319#if BUILDFLAG(SKIA_USE_DAWN)
Sunny Sachanandani1bcc2c82025-05-16 01:35:19320 if (value.empty() ||
321 base::StartsWith(value, switches::kSkiaGraphiteBackendDawn)) {
Sunny Sachanandanifb74c17f2023-04-10 21:29:17322 return GrContextType::kGraphiteDawn;
323 }
324#endif // BUILDFLAG(SKIA_USE_DAWN)
325#if BUILDFLAG(SKIA_USE_METAL)
Ian Vollickbde1d5832023-11-10 17:49:11326 if (value == switches::kSkiaGraphiteBackendMetal) {
Sunny Sachanandanifb74c17f2023-04-10 21:29:17327 return GrContextType::kGraphiteMetal;
328 }
329#endif // BUILDFLAG(SKIA_USE_METAL)
Sunny Sachanandani0a26ac5b2023-05-01 22:05:42330 LOG(ERROR) << "Skia Graphite backend = \"" << value
331 << "\" not found - falling back to Ganesh!";
Sunny Sachanandanifb74c17f2023-04-10 21:29:17332 }
Sunny Sachanandanifb74c17f2023-04-10 21:29:17333 if (features::IsUsingVulkan()) {
Peng Huangdbde9c72022-02-18 21:48:44334 return GrContextType::kVulkan;
Sunny Sachanandanifb74c17f2023-04-10 21:29:17335 }
Peng Huangdbde9c72022-02-18 21:48:44336 return GrContextType::kGL;
Sean Gilhuly3e84fc82020-01-22 22:06:45337}
338
Justin Novosad5730d362023-07-19 22:05:47339bool MSAAIsSlow(const GpuDriverBugWorkarounds& workarounds) {
Justin Novosad5730d362023-07-19 22:05:47340 // Only query the kEnableMSAAOnNewIntelGPUs feature flag if the host device
341 // is affected by the experiment (i.e. is a new Intel GPU).
342 // This is to avoid activating the experiment on hosts that are irrelevant
343 // to the study in order to boost statistical power.
344 bool affected_by_experiment =
345 workarounds.msaa_is_slow && !workarounds.msaa_is_slow_2;
346
347 return affected_by_experiment ? !base::FeatureList::IsEnabled(
348 features::kEnableMSAAOnNewIntelGPUs)
349 : workarounds.msaa_is_slow;
350}
351
geofflangdf7fff2d42016-11-11 00:34:03352} // namespace gles2
Geoff Lang7e4a3072024-02-16 15:04:59353
354#if BUILDFLAG(IS_MAC)
Colin Blundell9d81c471c2024-06-14 07:25:41355uint32_t GetTextureTargetForIOSurfaces() {
Geoff Lang7e4a3072024-02-16 15:04:59356 // On MacOS, the default texture target for native GpuMemoryBuffers is
357 // GL_TEXTURE_RECTANGLE_ARB. This is due to CGL's requirements for creating
358 // a GL surface. However, when ANGLE is used on top of SwiftShader or Metal,
359 // it's necessary to use GL_TEXTURE_2D instead.
Alison Gale47d1537d2024-04-19 21:31:46360 // TODO(crbug.com/40676774): The proper behavior is to check the config
Geoff Lang7e4a3072024-02-16 15:04:59361 // parameter set by the EGL_ANGLE_iosurface_client_buffer extension
362 if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE &&
363 (gl::GetANGLEImplementation() == gl::ANGLEImplementation::kSwiftShader ||
364 gl::GetANGLEImplementation() == gl::ANGLEImplementation::kMetal)) {
Colin Blundella50230372024-03-22 08:18:51365 return GL_TEXTURE_2D;
Geoff Lang7e4a3072024-02-16 15:04:59366 }
Geoff Lang8fc21cd2025-05-26 13:13:29367 return GL_TEXTURE_RECTANGLE_ANGLE;
Colin Blundella50230372024-03-22 08:18:51368}
Geoff Lang7e4a3072024-02-16 15:04:59369#endif // BUILDFLAG(IS_MAC)
370
Saifuddin Hitawalad75c2c72025-04-22 15:14:57371size_t UpdateShaderCacheSizeOnMemoryPressure(
372 size_t max_cache_size,
373 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
374 switch (memory_pressure_level) {
375 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE:
376 return max_cache_size;
377 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE:
378 if (base::FeatureList::IsEnabled(
379 ::features::kAggressiveShaderCacheLimits)) {
380 // Ignore moderate memory pressure.
381 } else {
382 max_cache_size /= 4;
383 }
384 break;
385 case base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL:
386 if (base::FeatureList::IsEnabled(
387 ::features::kAggressiveShaderCacheLimits)) {
388#if BUILDFLAG(IS_ANDROID)
389 // On Android, critical memory pressure notifications are very common,
390 // and not necessarily tied to actual critical memory pressure. Ignore.
391 break;
392#else
393 max_cache_size /= 4;
394#endif
395 } else {
396 max_cache_size = 0;
397 }
398 break;
399 }
400
401 return max_cache_size;
402}
403
geofflangdf7fff2d42016-11-11 00:34:03404} // namespace gpu