Avi Drissman | 05dfbc82 | 2022-09-13 21:25:34 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 2 | // 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 Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 7 | #include <string> |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 8 | #include <string_view> |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 9 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 10 | #include "base/command_line.h" |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 11 | #include "base/logging.h" |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
Jiawei Shao | 04b8bcd | 2020-11-14 01:29:47 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
David Sanders | 79044f0 | 2025-01-17 21:42:47 | [diff] [blame] | 14 | #include "base/strings/string_util.h" |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 15 | #include "build/build_config.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 16 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 17 | #include "gpu/command_buffer/service/context_group.h" |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 18 | #include "gpu/command_buffer/service/gpu_switches.h" |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame] | 19 | #include "gpu/config/gpu_finch_features.h" |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 20 | #include "skia/buildflags.h" |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 21 | #include "ui/gl/gl_bindings.h" |
Geoff Lang | 2ccdaab | 2025-03-20 17:14:35 | [diff] [blame] | 22 | #include "ui/gl/gl_features.h" |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 23 | #include "ui/gl/gl_implementation.h" |
Geoff Lang | 2ccdaab | 2025-03-20 17:14:35 | [diff] [blame] | 24 | #include "ui/gl/gl_surface_egl.h" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 25 | #include "ui/gl/gl_switches.h" |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 26 | #include "ui/gl/gl_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 27 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 28 | namespace gpu { |
| 29 | namespace gles2 { |
| 30 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 31 | namespace { |
| 32 | |
| 33 | bool GetUintFromSwitch(const base::CommandLine* command_line, |
Helmut Januschka | b81e97dc | 2024-04-17 14:57:05 | [diff] [blame] | 34 | std::string_view switch_string, |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 35 | uint32_t* value) { |
Antonio Maiorano | 32b3100 | 2023-08-30 14:07:17 | [diff] [blame] | 36 | if (!command_line->HasSwitch(switch_string)) { |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 37 | return false; |
Antonio Maiorano | 32b3100 | 2023-08-30 14:07:17 | [diff] [blame] | 38 | } |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 39 | std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 40 | return base::StringToUint(switch_value, value); |
| 41 | } |
| 42 | |
Sunny Sachanandani | 76396e8 | 2024-07-17 22:00:33 | [diff] [blame] | 43 | // 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. |
| 46 | VulkanImplementationName 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 | |
| 77 | WebGPUAdapterName 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 | |
| 105 | WebGPUPowerPreference 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 Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 130 | } // namespace |
| 131 | |
Vasiliy Telezhnikov | c18ab41 | 2023-11-14 16:27:07 | [diff] [blame] | 132 | gl::GLContextAttribs GenerateGLContextAttribsForDecoder( |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 133 | ContextType context_type, |
| 134 | gl::GpuPreference gpu_preference, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 135 | const ContextGroup* context_group) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 136 | gl::GLContextAttribs attribs; |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 137 | attribs.gpu_preference = gpu_preference; |
Vasiliy Telezhnikov | c18ab41 | 2023-11-14 16:27:07 | [diff] [blame] | 138 | if (context_group->use_passthrough_cmd_decoder()) { |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 139 | attribs.webgl_compatibility_context = IsWebGLContextType(context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 140 | |
Jonathan Ross | 6b1ca23 | 2020-07-31 16:43:36 | [diff] [blame] | 141 | // Always use the global texture and semaphore share group for the |
| 142 | // passthrough command decoder |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 143 | attribs.global_texture_share_group = true; |
Jonathan Ross | 6b1ca23 | 2020-07-31 16:43:36 | [diff] [blame] | 144 | attribs.global_semaphore_share_group = true; |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 145 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 146 | attribs.robust_resource_initialization = true; |
Jiajia Qin | 69aeeb2 | 2017-11-09 05:16:18 | [diff] [blame] | 147 | attribs.robust_buffer_access = true; |
Geoff Lang | 52469f3 | 2024-07-25 14:41:08 | [diff] [blame] | 148 | attribs.allow_client_arrays = false; |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 149 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 150 | // Request a specific context version instead of always 3.0 |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 151 | if (IsWebGL2OrES3ContextType(context_type)) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 152 | attribs.client_major_es_version = 3; |
| 153 | attribs.client_minor_es_version = 0; |
| 154 | } else { |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 155 | DCHECK(IsWebGL1OrES2ContextType(context_type)); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 156 | 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; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 162 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 163 | |
Will Harris | c5313ac | 2023-03-01 23:42:03 | [diff] [blame] | 164 | if (gl::GetGlWorkarounds().disable_es3gl_context) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 165 | // Forcefully disable ES3 contexts |
| 166 | attribs.client_major_es_version = 2; |
| 167 | attribs.client_minor_es_version = 0; |
| 168 | } |
| 169 | |
Vasiliy Telezhnikov | fc0556ed | 2025-09-08 18:46:46 | [diff] [blame] | 170 | if (IsES31ForTestingContextType(context_type)) { |
Geoff Lang | d0c755c | 2021-01-18 21:58:16 | [diff] [blame] | 171 | // 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 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 177 | return attribs; |
| 178 | } |
| 179 | |
Vasiliy Telezhnikov | c18ab41 | 2023-11-14 16:27:07 | [diff] [blame] | 180 | gl::GLContextAttribs GenerateGLContextAttribsForCompositor( |
| 181 | bool use_passthrough_cmd_decoder) { |
| 182 | gl::GLContextAttribs attribs; |
| 183 | if (use_passthrough_cmd_decoder) { |
Vasiliy Telezhnikov | c18ab41 | 2023-11-14 16:27:07 | [diff] [blame] | 184 | // 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 Lang | 2ccdaab | 2025-03-20 17:14:35 | [diff] [blame] | 189 | attribs.passthrough_shaders = features::IsANGLEPassthroughShadersAllowed(); |
| 190 | |
Geoff Lang | 18df8bba | 2024-04-03 17:04:04 | [diff] [blame] | 191 | // Disable resource initialization and buffer bounds checks for trusted |
| 192 | // contexts. |
| 193 | attribs.robust_resource_initialization = false; |
| 194 | attribs.robust_buffer_access = false; |
Geoff Lang | 52469f3 | 2024-07-25 14:41:08 | [diff] [blame] | 195 | attribs.allow_client_arrays = true; |
Vasiliy Telezhnikov | c18ab41 | 2023-11-14 16:27:07 | [diff] [blame] | 196 | } |
| 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 Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 209 | bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) { |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 210 | return gl::UsePassthroughCommandDecoder(command_line); |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 211 | } |
| 212 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 213 | GpuPreferences 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); |
Wez | 4f8b543 | 2019-12-31 06:40:11 | [diff] [blame] | 235 | 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 Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 239 | } |
Sergey Ulanov | 689c31f | 2020-01-24 23:21:16 | [diff] [blame] | 240 | GetUintFromSwitch(command_line, switches::kForceMaxTextureSize, |
| 241 | &gpu_preferences.force_max_texture_size); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 242 | 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 Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 252 | 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 Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 258 | gpu_preferences.ignore_gpu_blocklist = |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 259 | command_line->HasSwitch(switches::kIgnoreGpuBlocklist); |
Kai Ninomiya | 328e07a | 2018-08-23 01:08:16 | [diff] [blame] | 260 | gpu_preferences.enable_webgpu = |
shrekshao | c653925 | 2021-04-29 19:21:56 | [diff] [blame] | 261 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU) || |
Corentin Wallez | a059a3a2 | 2021-07-30 09:44:54 | [diff] [blame] | 262 | base::FeatureList::IsEnabled(features::kWebGPUService); |
Austin Eng | a442d583 | 2022-01-15 03:00:15 | [diff] [blame] | 263 | gpu_preferences.enable_unsafe_webgpu = |
Corentin Wallez | 721293f | 2021-06-03 22:42:00 | [diff] [blame] | 264 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU); |
François Beaufort | 6412336 | 2023-10-04 13:56:50 | [diff] [blame] | 265 | gpu_preferences.enable_webgpu_developer_features = |
| 266 | command_line->HasSwitch(switches::kEnableWebGPUDeveloperFeatures); |
Austin Eng | 80eb796 | 2022-02-07 20:35:37 | [diff] [blame] | 267 | gpu_preferences.use_webgpu_adapter = ParseWebGPUAdapterName(command_line); |
Shrek Shao | d457e86 | 2023-03-22 23:06:05 | [diff] [blame] | 268 | gpu_preferences.use_webgpu_power_preference = |
| 269 | ParseWebGPUPowerPreference(command_line); |
Stephen White | 602bf50 | 2023-05-17 21:10:50 | [diff] [blame] | 270 | gpu_preferences.force_webgpu_compat = |
| 271 | command_line->HasSwitch(switches::kForceWebGPUCompat); |
Austin Eng | bac59e69 | 2021-05-13 16:46:54 | [diff] [blame] | 272 | 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 Shao | 04b8bcd | 2020-11-14 01:29:47 | [diff] [blame] | 283 | 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 Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 293 | gpu_preferences.gr_context_type = ParseGrContextType(command_line); |
Peng Huang | a5299ec | 2023-12-18 21:51:42 | [diff] [blame] | 294 | // 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 Ulanov | efa2af1 | 2022-06-28 23:17:47 | [diff] [blame] | 300 | |
| 301 | #if BUILDFLAG(IS_FUCHSIA) |
| 302 | // Vulkan Surface is not used on Fuchsia. |
| 303 | gpu_preferences.disable_vulkan_surface = true; |
| 304 | #else |
Peng Huang | 556da90 | 2019-03-22 17:49:40 | [diff] [blame] | 305 | gpu_preferences.disable_vulkan_surface = |
| 306 | command_line->HasSwitch(switches::kDisableVulkanSurface); |
Sergey Ulanov | efa2af1 | 2022-06-28 23:17:47 | [diff] [blame] | 307 | #endif |
Vasiliy Telezhnikov | 533c564 | 2019-12-03 15:10:16 | [diff] [blame] | 308 | |
| 309 | gpu_preferences.enable_gpu_blocked_time_metric = |
| 310 | command_line->HasSwitch(switches::kEnableGpuBlockedTime); |
| 311 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 312 | return gpu_preferences; |
| 313 | } |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 314 | |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 315 | GrContextType ParseGrContextType(const base::CommandLine* command_line) { |
Sunny Sachanandani | aba318bb | 2023-09-06 20:22:22 | [diff] [blame] | 316 | if (features::IsSkiaGraphiteEnabled(command_line)) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 317 | [[maybe_unused]] auto value = |
| 318 | command_line->GetSwitchValueASCII(switches::kSkiaGraphiteBackend); |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 319 | #if BUILDFLAG(SKIA_USE_DAWN) |
Sunny Sachanandani | 1bcc2c8 | 2025-05-16 01:35:19 | [diff] [blame] | 320 | if (value.empty() || |
| 321 | base::StartsWith(value, switches::kSkiaGraphiteBackendDawn)) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 322 | return GrContextType::kGraphiteDawn; |
| 323 | } |
| 324 | #endif // BUILDFLAG(SKIA_USE_DAWN) |
| 325 | #if BUILDFLAG(SKIA_USE_METAL) |
Ian Vollick | bde1d583 | 2023-11-10 17:49:11 | [diff] [blame] | 326 | if (value == switches::kSkiaGraphiteBackendMetal) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 327 | return GrContextType::kGraphiteMetal; |
| 328 | } |
| 329 | #endif // BUILDFLAG(SKIA_USE_METAL) |
Sunny Sachanandani | 0a26ac5b | 2023-05-01 22:05:42 | [diff] [blame] | 330 | LOG(ERROR) << "Skia Graphite backend = \"" << value |
| 331 | << "\" not found - falling back to Ganesh!"; |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 332 | } |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 333 | if (features::IsUsingVulkan()) { |
Peng Huang | dbde9c7 | 2022-02-18 21:48:44 | [diff] [blame] | 334 | return GrContextType::kVulkan; |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 335 | } |
Peng Huang | dbde9c7 | 2022-02-18 21:48:44 | [diff] [blame] | 336 | return GrContextType::kGL; |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 337 | } |
| 338 | |
Justin Novosad | 5730d36 | 2023-07-19 22:05:47 | [diff] [blame] | 339 | bool MSAAIsSlow(const GpuDriverBugWorkarounds& workarounds) { |
Justin Novosad | 5730d36 | 2023-07-19 22:05:47 | [diff] [blame] | 340 | // 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 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 352 | } // namespace gles2 |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 353 | |
| 354 | #if BUILDFLAG(IS_MAC) |
Colin Blundell | 9d81c471c | 2024-06-14 07:25:41 | [diff] [blame] | 355 | uint32_t GetTextureTargetForIOSurfaces() { |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 356 | // 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 Gale | 47d1537d | 2024-04-19 21:31:46 | [diff] [blame] | 360 | // TODO(crbug.com/40676774): The proper behavior is to check the config |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 361 | // 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 Blundell | a5023037 | 2024-03-22 08:18:51 | [diff] [blame] | 365 | return GL_TEXTURE_2D; |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 366 | } |
Geoff Lang | 8fc21cd | 2025-05-26 13:13:29 | [diff] [blame] | 367 | return GL_TEXTURE_RECTANGLE_ANGLE; |
Colin Blundell | a5023037 | 2024-03-22 08:18:51 | [diff] [blame] | 368 | } |
Geoff Lang | 7e4a307 | 2024-02-16 15:04:59 | [diff] [blame] | 369 | #endif // BUILDFLAG(IS_MAC) |
| 370 | |
Saifuddin Hitawala | d75c2c7 | 2025-04-22 15:14:57 | [diff] [blame] | 371 | size_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 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 404 | } // namespace gpu |