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> |
| 8 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 9 | #include "base/command_line.h" |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 10 | #include "base/logging.h" |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 11 | #include "base/strings/string_number_conversions.h" |
Jiawei Shao | 04b8bcd | 2020-11-14 01:29:47 | [diff] [blame] | 12 | #include "base/strings/string_split.h" |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 13 | #include "build/build_config.h" |
Jonathan Backer | f48f920 | 2021-01-14 18:39:46 | [diff] [blame] | 14 | #include "build/chromeos_buildflags.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 15 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 16 | #include "gpu/command_buffer/service/context_group.h" |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 17 | #include "gpu/command_buffer/service/gpu_switches.h" |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame] | 18 | #include "gpu/config/gpu_finch_features.h" |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 19 | #include "skia/buildflags.h" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 20 | #include "ui/gl/gl_switches.h" |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 21 | #include "ui/gl/gl_utils.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 22 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 23 | #if defined(USE_EGL) |
| 24 | #include "ui/gl/gl_surface_egl.h" |
| 25 | #endif // defined(USE_EGL) |
| 26 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 27 | namespace gpu { |
| 28 | namespace gles2 { |
| 29 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | bool GetUintFromSwitch(const base::CommandLine* command_line, |
| 33 | const base::StringPiece& switch_string, |
| 34 | uint32_t* value) { |
Antonio Maiorano | 32b3100 | 2023-08-30 14:07:17 | [diff] [blame] | 35 | if (!command_line->HasSwitch(switch_string)) { |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 36 | return false; |
Antonio Maiorano | 32b3100 | 2023-08-30 14:07:17 | [diff] [blame] | 37 | } |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 38 | std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 39 | return base::StringToUint(switch_value, value); |
| 40 | } |
| 41 | |
| 42 | } // namespace |
| 43 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 44 | gl::GLContextAttribs GenerateGLContextAttribs( |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 45 | const ContextCreationAttribs& attribs_helper, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 46 | const ContextGroup* context_group) { |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 47 | return GenerateGLContextAttribs(attribs_helper, |
| 48 | context_group->use_passthrough_cmd_decoder()); |
| 49 | } |
| 50 | |
| 51 | gl::GLContextAttribs GenerateGLContextAttribs( |
| 52 | const ContextCreationAttribs& attribs_helper, |
| 53 | bool use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 54 | gl::GLContextAttribs attribs; |
| 55 | attribs.gpu_preference = attribs_helper.gpu_preference; |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 56 | if (use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 57 | attribs.bind_generates_resource = attribs_helper.bind_generates_resource; |
| 58 | attribs.webgl_compatibility_context = |
| 59 | IsWebGLContextType(attribs_helper.context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 60 | |
Jonathan Ross | 6b1ca23 | 2020-07-31 16:43:36 | [diff] [blame] | 61 | // Always use the global texture and semaphore share group for the |
| 62 | // passthrough command decoder |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 63 | attribs.global_texture_share_group = true; |
Jonathan Ross | 6b1ca23 | 2020-07-31 16:43:36 | [diff] [blame] | 64 | attribs.global_semaphore_share_group = true; |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 65 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 66 | attribs.robust_resource_initialization = true; |
Jiajia Qin | 69aeeb2 | 2017-11-09 05:16:18 | [diff] [blame] | 67 | attribs.robust_buffer_access = true; |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 68 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 69 | // Request a specific context version instead of always 3.0 |
Geoff Lang | d0c755c | 2021-01-18 21:58:16 | [diff] [blame] | 70 | if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 71 | attribs.client_major_es_version = 3; |
| 72 | attribs.client_minor_es_version = 0; |
| 73 | } else { |
| 74 | DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type)); |
| 75 | attribs.client_major_es_version = 2; |
| 76 | attribs.client_minor_es_version = 0; |
| 77 | } |
| 78 | } else { |
| 79 | attribs.client_major_es_version = 3; |
| 80 | attribs.client_minor_es_version = 0; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 81 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 82 | |
Will Harris | c5313ac | 2023-03-01 23:42:03 | [diff] [blame] | 83 | if (gl::GetGlWorkarounds().disable_es3gl_context) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 84 | // Forcefully disable ES3 contexts |
| 85 | attribs.client_major_es_version = 2; |
| 86 | attribs.client_minor_es_version = 0; |
| 87 | } |
| 88 | |
Geoff Lang | d0c755c | 2021-01-18 21:58:16 | [diff] [blame] | 89 | if (IsES31ForTestingContextType(attribs_helper.context_type)) { |
| 90 | // Forcefully disable ES 3.1 contexts. Tests create contexts by initializing |
| 91 | // the attributes directly. |
| 92 | attribs.client_major_es_version = 2; |
| 93 | attribs.client_minor_es_version = 0; |
| 94 | } |
| 95 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 96 | return attribs; |
| 97 | } |
| 98 | |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 99 | bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) { |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 100 | return gl::UsePassthroughCommandDecoder(command_line); |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 101 | } |
| 102 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 103 | bool PassthroughCommandDecoderSupported() { |
Jonah Ryan-Davis | 77b562dc | 2020-07-17 19:11:23 | [diff] [blame] | 104 | return gl::PassthroughCommandDecoderSupported(); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) { |
| 108 | GpuPreferences gpu_preferences; |
| 109 | gpu_preferences.compile_shader_always_succeeds = |
| 110 | command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 111 | gpu_preferences.disable_gl_error_limit = |
| 112 | command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 113 | gpu_preferences.disable_glsl_translator = |
| 114 | command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 115 | gpu_preferences.disable_shader_name_hashing = |
| 116 | command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 117 | gpu_preferences.enable_gpu_command_logging = |
| 118 | command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 119 | gpu_preferences.enable_gpu_debugging = |
| 120 | command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 121 | gpu_preferences.enable_gpu_service_logging_gpu = |
| 122 | command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 123 | gpu_preferences.enable_gpu_driver_debug_logging = |
| 124 | command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging); |
| 125 | gpu_preferences.disable_gpu_program_cache = |
| 126 | command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 127 | gpu_preferences.enforce_gl_minimums = |
| 128 | command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 129 | if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
Wez | 4f8b543 | 2019-12-31 06:40:11 | [diff] [blame] | 130 | &gpu_preferences.force_gpu_mem_available_bytes)) { |
| 131 | gpu_preferences.force_gpu_mem_available_bytes *= 1024 * 1024; |
| 132 | } |
| 133 | if (GetUintFromSwitch( |
| 134 | command_line, switches::kForceGpuMemDiscardableLimitMb, |
| 135 | &gpu_preferences.force_gpu_mem_discardable_limit_bytes)) { |
| 136 | gpu_preferences.force_gpu_mem_discardable_limit_bytes *= 1024 * 1024; |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 137 | } |
Sergey Ulanov | 689c31f | 2020-01-24 23:21:16 | [diff] [blame] | 138 | GetUintFromSwitch(command_line, switches::kForceMaxTextureSize, |
| 139 | &gpu_preferences.force_max_texture_size); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 140 | if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| 141 | &gpu_preferences.gpu_program_cache_size)) { |
| 142 | gpu_preferences.gpu_program_cache_size *= 1024; |
| 143 | } |
| 144 | gpu_preferences.disable_gpu_shader_disk_cache = |
| 145 | command_line->HasSwitch(switches::kDisableGpuShaderDiskCache); |
| 146 | gpu_preferences.enable_threaded_texture_mailboxes = |
| 147 | command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| 148 | gpu_preferences.gl_shader_interm_output = |
| 149 | command_line->HasSwitch(switches::kGLShaderIntermOutput); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 150 | gpu_preferences.enable_gpu_service_logging = |
| 151 | command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 152 | gpu_preferences.enable_gpu_service_tracing = |
| 153 | command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 154 | gpu_preferences.use_passthrough_cmd_decoder = |
| 155 | gpu::gles2::UsePassthroughCommandDecoder(command_line); |
Corentin Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 156 | gpu_preferences.ignore_gpu_blocklist = |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 157 | command_line->HasSwitch(switches::kIgnoreGpuBlocklist); |
Kai Ninomiya | 328e07a | 2018-08-23 01:08:16 | [diff] [blame] | 158 | gpu_preferences.enable_webgpu = |
shrekshao | c653925 | 2021-04-29 19:21:56 | [diff] [blame] | 159 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU) || |
Corentin Wallez | a059a3a2 | 2021-07-30 09:44:54 | [diff] [blame] | 160 | base::FeatureList::IsEnabled(features::kWebGPUService); |
Austin Eng | a442d583 | 2022-01-15 03:00:15 | [diff] [blame] | 161 | gpu_preferences.enable_unsafe_webgpu = |
Corentin Wallez | 721293f | 2021-06-03 22:42:00 | [diff] [blame] | 162 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU); |
Austin Eng | 80eb796 | 2022-02-07 20:35:37 | [diff] [blame] | 163 | gpu_preferences.use_webgpu_adapter = ParseWebGPUAdapterName(command_line); |
Shrek Shao | d457e86 | 2023-03-22 23:06:05 | [diff] [blame] | 164 | gpu_preferences.use_webgpu_power_preference = |
| 165 | ParseWebGPUPowerPreference(command_line); |
Stephen White | 602bf50 | 2023-05-17 21:10:50 | [diff] [blame] | 166 | gpu_preferences.force_webgpu_compat = |
| 167 | command_line->HasSwitch(switches::kForceWebGPUCompat); |
Austin Eng | bac59e69 | 2021-05-13 16:46:54 | [diff] [blame] | 168 | if (command_line->HasSwitch(switches::kEnableDawnBackendValidation)) { |
| 169 | auto value = command_line->GetSwitchValueASCII( |
| 170 | switches::kEnableDawnBackendValidation); |
| 171 | if (value.empty() || value == "full") { |
| 172 | gpu_preferences.enable_dawn_backend_validation = |
| 173 | DawnBackendValidationLevel::kFull; |
| 174 | } else if (value == "partial") { |
| 175 | gpu_preferences.enable_dawn_backend_validation = |
| 176 | DawnBackendValidationLevel::kPartial; |
| 177 | } |
| 178 | } |
Jiawei Shao | 04b8bcd | 2020-11-14 01:29:47 | [diff] [blame] | 179 | if (command_line->HasSwitch(switches::kEnableDawnFeatures)) { |
| 180 | gpu_preferences.enabled_dawn_features_list = base::SplitString( |
| 181 | command_line->GetSwitchValueASCII(switches::kEnableDawnFeatures), ",", |
| 182 | base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 183 | } |
| 184 | if (command_line->HasSwitch(switches::kDisableDawnFeatures)) { |
| 185 | gpu_preferences.disabled_dawn_features_list = base::SplitString( |
| 186 | command_line->GetSwitchValueASCII(switches::kDisableDawnFeatures), ",", |
| 187 | base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 188 | } |
Antonio Maiorano | 32b3100 | 2023-08-30 14:07:17 | [diff] [blame] | 189 | #ifdef DAWN_USE_BUILT_DXC |
| 190 | // Drive "use_dxc" with Finch feature flag, unless user forces option via |
| 191 | // command line. |
| 192 | if (!base::Contains(gpu_preferences.enabled_dawn_features_list, "use_dxc") && |
| 193 | !base::Contains(gpu_preferences.disabled_dawn_features_list, "use_dxc")) { |
| 194 | if (base::FeatureList::IsEnabled(features::kWebGPUUseDXC)) { |
| 195 | gpu_preferences.enabled_dawn_features_list.push_back("use_dxc"); |
| 196 | } else { |
| 197 | gpu_preferences.disabled_dawn_features_list.push_back("use_dxc"); |
| 198 | } |
| 199 | } |
| 200 | #endif |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 201 | gpu_preferences.gr_context_type = ParseGrContextType(command_line); |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 202 | gpu_preferences.use_vulkan = ParseVulkanImplementationName(command_line); |
Sergey Ulanov | efa2af1 | 2022-06-28 23:17:47 | [diff] [blame] | 203 | |
| 204 | #if BUILDFLAG(IS_FUCHSIA) |
| 205 | // Vulkan Surface is not used on Fuchsia. |
| 206 | gpu_preferences.disable_vulkan_surface = true; |
| 207 | #else |
Peng Huang | 556da90 | 2019-03-22 17:49:40 | [diff] [blame] | 208 | gpu_preferences.disable_vulkan_surface = |
| 209 | command_line->HasSwitch(switches::kDisableVulkanSurface); |
Sergey Ulanov | efa2af1 | 2022-06-28 23:17:47 | [diff] [blame] | 210 | #endif |
Vasiliy Telezhnikov | 533c564 | 2019-12-03 15:10:16 | [diff] [blame] | 211 | |
| 212 | gpu_preferences.enable_gpu_blocked_time_metric = |
| 213 | command_line->HasSwitch(switches::kEnableGpuBlockedTime); |
| 214 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 215 | return gpu_preferences; |
| 216 | } |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 217 | |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 218 | GrContextType ParseGrContextType(const base::CommandLine* command_line) { |
Sunny Sachanandani | aba318bb | 2023-09-06 20:22:22 | [diff] [blame^] | 219 | if (features::IsSkiaGraphiteEnabled(command_line)) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 220 | [[maybe_unused]] auto value = |
| 221 | command_line->GetSwitchValueASCII(switches::kSkiaGraphiteBackend); |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 222 | #if BUILDFLAG(SKIA_USE_DAWN) |
Sunny Sachanandani | ddc82cc | 2023-08-30 16:16:21 | [diff] [blame] | 223 | if (value.empty() || |
| 224 | base::StartsWith(value, switches::kSkiaGraphiteBackendDawn)) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 225 | return GrContextType::kGraphiteDawn; |
| 226 | } |
| 227 | #endif // BUILDFLAG(SKIA_USE_DAWN) |
| 228 | #if BUILDFLAG(SKIA_USE_METAL) |
Ian Vollick | e4832bd | 2023-07-24 21:29:47 | [diff] [blame] | 229 | if ( |
| 230 | #if BUILDFLAG(IS_IOS) |
| 231 | value.empty() || |
| 232 | #endif // BUILDFLAG(IS_IOS) |
| 233 | value == switches::kSkiaGraphiteBackendMetal) { |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 234 | return GrContextType::kGraphiteMetal; |
| 235 | } |
| 236 | #endif // BUILDFLAG(SKIA_USE_METAL) |
Sunny Sachanandani | 0a26ac5b | 2023-05-01 22:05:42 | [diff] [blame] | 237 | LOG(ERROR) << "Skia Graphite backend = \"" << value |
| 238 | << "\" not found - falling back to Ganesh!"; |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 239 | } |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 240 | if (features::IsUsingVulkan()) { |
Peng Huang | dbde9c7 | 2022-02-18 21:48:44 | [diff] [blame] | 241 | return GrContextType::kVulkan; |
Sunny Sachanandani | fb74c17f | 2023-04-10 21:29:17 | [diff] [blame] | 242 | } |
Peng Huang | dbde9c7 | 2022-02-18 21:48:44 | [diff] [blame] | 243 | return GrContextType::kGL; |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | VulkanImplementationName ParseVulkanImplementationName( |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 247 | const base::CommandLine* command_line) { |
Xiaohan Wang | fa22d3e | 2022-01-15 02:02:43 | [diff] [blame] | 248 | #if BUILDFLAG(IS_ANDROID) |
Bo Liu | 693cea5 | 2020-11-05 21:52:44 | [diff] [blame] | 249 | if (command_line->HasSwitch(switches::kWebViewDrawFunctorUsesVulkan) && |
| 250 | base::FeatureList::IsEnabled(features::kWebViewVulkan)) { |
| 251 | return VulkanImplementationName::kForcedNative; |
| 252 | } |
| 253 | #endif |
| 254 | |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 255 | if (command_line->HasSwitch(switches::kUseVulkan)) { |
| 256 | auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan); |
| 257 | if (value.empty() || value == switches::kVulkanImplementationNameNative) { |
| 258 | return VulkanImplementationName::kForcedNative; |
| 259 | } else if (value == switches::kVulkanImplementationNameSwiftshader) { |
| 260 | return VulkanImplementationName::kSwiftshader; |
| 261 | } |
| 262 | } |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 263 | |
Jonathan Backer | f48f920 | 2021-01-14 18:39:46 | [diff] [blame] | 264 | if (features::IsUsingVulkan()) { |
| 265 | // If the vulkan feature is enabled from command line, we will force to use |
| 266 | // vulkan even if it is blocklisted. |
| 267 | return base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine( |
| 268 | features::kVulkan.name, |
| 269 | base::FeatureList::OVERRIDE_ENABLE_FEATURE) |
| 270 | ? VulkanImplementationName::kForcedNative |
| 271 | : VulkanImplementationName::kNative; |
| 272 | } |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 273 | |
Jonathan Backer | f48f920 | 2021-01-14 18:39:46 | [diff] [blame] | 274 | // GrContext is not going to use Vulkan. |
| 275 | return VulkanImplementationName::kNone; |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 276 | } |
| 277 | |
Austin Eng | 80eb796 | 2022-02-07 20:35:37 | [diff] [blame] | 278 | WebGPUAdapterName ParseWebGPUAdapterName( |
| 279 | const base::CommandLine* command_line) { |
| 280 | if (command_line->HasSwitch(switches::kUseWebGPUAdapter)) { |
| 281 | auto value = command_line->GetSwitchValueASCII(switches::kUseWebGPUAdapter); |
Peng Huang | 8db6546e | 2023-05-15 19:13:19 | [diff] [blame] | 282 | |
| 283 | static const struct { |
| 284 | const char* name; |
| 285 | WebGPUAdapterName value; |
| 286 | } kAdapterNames[] = { |
| 287 | {"", WebGPUAdapterName::kDefault}, |
| 288 | {"default", WebGPUAdapterName::kDefault}, |
| 289 | {"d3d11", WebGPUAdapterName::kD3D11}, |
| 290 | {"opengles", WebGPUAdapterName::kOpenGLES}, |
| 291 | {"swiftshader", WebGPUAdapterName::kSwiftShader}, |
| 292 | }; |
| 293 | |
| 294 | for (const auto& adapter_name : kAdapterNames) { |
| 295 | if (value == adapter_name.name) { |
| 296 | return adapter_name.value; |
| 297 | } |
Austin Eng | 80eb796 | 2022-02-07 20:35:37 | [diff] [blame] | 298 | } |
Peng Huang | 8db6546e | 2023-05-15 19:13:19 | [diff] [blame] | 299 | |
| 300 | DLOG(ERROR) << "Invalid switch " << switches::kUseWebGPUAdapter << "=" |
| 301 | << value << "."; |
Austin Eng | 80eb796 | 2022-02-07 20:35:37 | [diff] [blame] | 302 | } |
| 303 | return WebGPUAdapterName::kDefault; |
| 304 | } |
| 305 | |
Shrek Shao | d457e86 | 2023-03-22 23:06:05 | [diff] [blame] | 306 | WebGPUPowerPreference ParseWebGPUPowerPreference( |
| 307 | const base::CommandLine* command_line) { |
| 308 | if (command_line->HasSwitch(switches::kUseWebGPUPowerPreference)) { |
| 309 | auto value = |
| 310 | command_line->GetSwitchValueASCII(switches::kUseWebGPUPowerPreference); |
| 311 | if (value.empty()) { |
Austin Eng | 34ba1d9 | 2023-05-04 01:39:47 | [diff] [blame] | 312 | return WebGPUPowerPreference::kNone; |
| 313 | } else if (value == "none") { |
| 314 | return WebGPUPowerPreference::kNone; |
Shrek Shao | d457e86 | 2023-03-22 23:06:05 | [diff] [blame] | 315 | } else if (value == "default-low-power") { |
| 316 | return WebGPUPowerPreference::kDefaultLowPower; |
| 317 | } else if (value == "default-high-performance") { |
| 318 | return WebGPUPowerPreference::kDefaultHighPerformance; |
| 319 | } else if (value == "force-low-power") { |
| 320 | return WebGPUPowerPreference::kForceLowPower; |
| 321 | } else if (value == "force-high-performance") { |
| 322 | return WebGPUPowerPreference::kForceHighPerformance; |
| 323 | } else { |
| 324 | DLOG(ERROR) << "Invalid switch " << switches::kUseWebGPUPowerPreference |
| 325 | << "=" << value << "."; |
| 326 | } |
| 327 | } |
Austin Eng | 34ba1d9 | 2023-05-04 01:39:47 | [diff] [blame] | 328 | return WebGPUPowerPreference::kNone; |
Shrek Shao | d457e86 | 2023-03-22 23:06:05 | [diff] [blame] | 329 | } |
| 330 | |
Justin Novosad | 5730d36 | 2023-07-19 22:05:47 | [diff] [blame] | 331 | bool MSAAIsSlow(const GpuDriverBugWorkarounds& workarounds) { |
Justin Novosad | 5730d36 | 2023-07-19 22:05:47 | [diff] [blame] | 332 | // Only query the kEnableMSAAOnNewIntelGPUs feature flag if the host device |
| 333 | // is affected by the experiment (i.e. is a new Intel GPU). |
| 334 | // This is to avoid activating the experiment on hosts that are irrelevant |
| 335 | // to the study in order to boost statistical power. |
| 336 | bool affected_by_experiment = |
| 337 | workarounds.msaa_is_slow && !workarounds.msaa_is_slow_2; |
| 338 | |
| 339 | return affected_by_experiment ? !base::FeatureList::IsEnabled( |
| 340 | features::kEnableMSAAOnNewIntelGPUs) |
| 341 | : workarounds.msaa_is_slow; |
| 342 | } |
| 343 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 344 | } // namespace gles2 |
| 345 | } // namespace gpu |