geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 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" |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 12 | #include "build/build_config.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 13 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 14 | #include "gpu/command_buffer/service/context_group.h" |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 15 | #include "gpu/command_buffer/service/gpu_switches.h" |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame] | 16 | #include "gpu/config/gpu_finch_features.h" |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 17 | #include "skia/buildflags.h" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 18 | #include "ui/gl/gl_switches.h" |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 19 | #include "ui/gl/gl_utils.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 20 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 21 | #if defined(USE_EGL) |
| 22 | #include "ui/gl/gl_surface_egl.h" |
| 23 | #endif // defined(USE_EGL) |
| 24 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 25 | namespace gpu { |
| 26 | namespace gles2 { |
| 27 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | bool GetUintFromSwitch(const base::CommandLine* command_line, |
| 31 | const base::StringPiece& switch_string, |
| 32 | uint32_t* value) { |
| 33 | if (!command_line->HasSwitch(switch_string)) |
| 34 | return false; |
| 35 | std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 36 | return base::StringToUint(switch_value, value); |
| 37 | } |
| 38 | |
| 39 | } // namespace |
| 40 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 41 | gl::GLContextAttribs GenerateGLContextAttribs( |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 42 | const ContextCreationAttribs& attribs_helper, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 43 | const ContextGroup* context_group) { |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 44 | return GenerateGLContextAttribs(attribs_helper, |
| 45 | context_group->use_passthrough_cmd_decoder()); |
| 46 | } |
| 47 | |
| 48 | gl::GLContextAttribs GenerateGLContextAttribs( |
| 49 | const ContextCreationAttribs& attribs_helper, |
| 50 | bool use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 51 | gl::GLContextAttribs attribs; |
| 52 | attribs.gpu_preference = attribs_helper.gpu_preference; |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 53 | if (use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 54 | attribs.bind_generates_resource = attribs_helper.bind_generates_resource; |
| 55 | attribs.webgl_compatibility_context = |
| 56 | IsWebGLContextType(attribs_helper.context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 57 | |
| 58 | // Always use the global texture share group for the passthrough command |
| 59 | // decoder |
| 60 | attribs.global_texture_share_group = true; |
| 61 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 62 | attribs.robust_resource_initialization = true; |
Jiajia Qin | 69aeeb2 | 2017-11-09 05:16:18 | [diff] [blame] | 63 | attribs.robust_buffer_access = true; |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 64 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 65 | // Request a specific context version instead of always 3.0 |
Jiajia Qin | 252a813 | 2018-07-19 01:03:22 | [diff] [blame] | 66 | if (IsWebGL2ComputeContextType(attribs_helper.context_type)) { |
| 67 | attribs.client_major_es_version = 3; |
| 68 | attribs.client_minor_es_version = 1; |
| 69 | } else if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 70 | attribs.client_major_es_version = 3; |
| 71 | attribs.client_minor_es_version = 0; |
| 72 | } else { |
| 73 | DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type)); |
| 74 | attribs.client_major_es_version = 2; |
| 75 | attribs.client_minor_es_version = 0; |
| 76 | } |
| 77 | } else { |
| 78 | attribs.client_major_es_version = 3; |
| 79 | attribs.client_minor_es_version = 0; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 80 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 81 | |
| 82 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 83 | switches::kDisableES3GLContext)) { |
| 84 | // Forcefully disable ES3 contexts |
| 85 | attribs.client_major_es_version = 2; |
| 86 | attribs.client_minor_es_version = 0; |
| 87 | } |
| 88 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 89 | return attribs; |
| 90 | } |
| 91 | |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 92 | bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) { |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 93 | return gl::UsePassthroughCommandDecoder(command_line); |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 94 | } |
| 95 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 96 | bool PassthroughCommandDecoderSupported() { |
Jonah Ryan-Davis | 77b562dc | 2020-07-17 19:11:23 | [diff] [blame^] | 97 | return gl::PassthroughCommandDecoderSupported(); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) { |
| 101 | GpuPreferences gpu_preferences; |
| 102 | gpu_preferences.compile_shader_always_succeeds = |
| 103 | command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 104 | gpu_preferences.disable_gl_error_limit = |
| 105 | command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 106 | gpu_preferences.disable_glsl_translator = |
| 107 | command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 108 | gpu_preferences.disable_shader_name_hashing = |
| 109 | command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 110 | gpu_preferences.enable_gpu_command_logging = |
| 111 | command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 112 | gpu_preferences.enable_gpu_debugging = |
| 113 | command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 114 | gpu_preferences.enable_gpu_service_logging_gpu = |
| 115 | command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 116 | gpu_preferences.enable_gpu_driver_debug_logging = |
| 117 | command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging); |
| 118 | gpu_preferences.disable_gpu_program_cache = |
| 119 | command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 120 | gpu_preferences.enforce_gl_minimums = |
| 121 | command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 122 | if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
Wez | 4f8b543 | 2019-12-31 06:40:11 | [diff] [blame] | 123 | &gpu_preferences.force_gpu_mem_available_bytes)) { |
| 124 | gpu_preferences.force_gpu_mem_available_bytes *= 1024 * 1024; |
| 125 | } |
| 126 | if (GetUintFromSwitch( |
| 127 | command_line, switches::kForceGpuMemDiscardableLimitMb, |
| 128 | &gpu_preferences.force_gpu_mem_discardable_limit_bytes)) { |
| 129 | gpu_preferences.force_gpu_mem_discardable_limit_bytes *= 1024 * 1024; |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 130 | } |
Sergey Ulanov | 689c31f | 2020-01-24 23:21:16 | [diff] [blame] | 131 | GetUintFromSwitch(command_line, switches::kForceMaxTextureSize, |
| 132 | &gpu_preferences.force_max_texture_size); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 133 | if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| 134 | &gpu_preferences.gpu_program_cache_size)) { |
| 135 | gpu_preferences.gpu_program_cache_size *= 1024; |
| 136 | } |
| 137 | gpu_preferences.disable_gpu_shader_disk_cache = |
| 138 | command_line->HasSwitch(switches::kDisableGpuShaderDiskCache); |
| 139 | gpu_preferences.enable_threaded_texture_mailboxes = |
| 140 | command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| 141 | gpu_preferences.gl_shader_interm_output = |
| 142 | command_line->HasSwitch(switches::kGLShaderIntermOutput); |
| 143 | gpu_preferences.emulate_shader_precision = |
| 144 | command_line->HasSwitch(switches::kEmulateShaderPrecision); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 145 | gpu_preferences.enable_gpu_service_logging = |
| 146 | command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 147 | gpu_preferences.enable_gpu_service_tracing = |
| 148 | command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 149 | gpu_preferences.use_passthrough_cmd_decoder = |
| 150 | gpu::gles2::UsePassthroughCommandDecoder(command_line); |
Corentin Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 151 | gpu_preferences.ignore_gpu_blocklist = |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 152 | command_line->HasSwitch(switches::kIgnoreGpuBlacklist) || |
| 153 | command_line->HasSwitch(switches::kIgnoreGpuBlocklist); |
| 154 | |
| 155 | if (command_line->HasSwitch(switches::kIgnoreGpuBlacklist)) { |
| 156 | LOG(ERROR) << "--" << switches::kIgnoreGpuBlacklist |
| 157 | << " is deprecated and will be removed in 2020Q4, use --" |
| 158 | << switches::kIgnoreGpuBlocklist << " instead."; |
| 159 | } |
| 160 | |
Kai Ninomiya | 328e07a | 2018-08-23 01:08:16 | [diff] [blame] | 161 | gpu_preferences.enable_webgpu = |
| 162 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU); |
Austin Eng | 32fc8ba | 2020-04-30 01:39:49 | [diff] [blame] | 163 | gpu_preferences.enable_dawn_backend_validation = |
| 164 | command_line->HasSwitch(switches::kEnableDawnBackendValidation); |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 165 | gpu_preferences.gr_context_type = ParseGrContextType(); |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 166 | gpu_preferences.use_vulkan = ParseVulkanImplementationName(command_line); |
Peng Huang | 556da90 | 2019-03-22 17:49:40 | [diff] [blame] | 167 | gpu_preferences.disable_vulkan_surface = |
| 168 | command_line->HasSwitch(switches::kDisableVulkanSurface); |
Vasiliy Telezhnikov | 533c564 | 2019-12-03 15:10:16 | [diff] [blame] | 169 | |
| 170 | gpu_preferences.enable_gpu_blocked_time_metric = |
| 171 | command_line->HasSwitch(switches::kEnableGpuBlockedTime); |
| 172 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 173 | return gpu_preferences; |
| 174 | } |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 175 | |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 176 | GrContextType ParseGrContextType() { |
| 177 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 178 | if (base::FeatureList::IsEnabled(features::kSkiaDawn)) |
| 179 | return GrContextType::kDawn; |
| 180 | #endif |
| 181 | #if defined(OS_MACOSX) |
| 182 | return base::FeatureList::IsEnabled(features::kMetal) ? GrContextType::kMetal |
| 183 | : GrContextType::kGL; |
| 184 | #else |
| 185 | return base::FeatureList::IsEnabled(features::kVulkan) |
| 186 | ? GrContextType::kVulkan |
| 187 | : GrContextType::kGL; |
| 188 | #endif |
| 189 | } |
| 190 | |
| 191 | VulkanImplementationName ParseVulkanImplementationName( |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 192 | const base::CommandLine* command_line) { |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 193 | if (command_line->HasSwitch(switches::kUseVulkan)) { |
| 194 | auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan); |
| 195 | if (value.empty() || value == switches::kVulkanImplementationNameNative) { |
| 196 | return VulkanImplementationName::kForcedNative; |
| 197 | } else if (value == switches::kVulkanImplementationNameSwiftshader) { |
| 198 | return VulkanImplementationName::kSwiftshader; |
| 199 | } |
| 200 | } |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 201 | |
| 202 | // GrContext is not going to use Vulkan. |
| 203 | if (!base::FeatureList::IsEnabled(features::kVulkan)) |
| 204 | return VulkanImplementationName::kNone; |
| 205 | |
| 206 | // If the vulkan feature is enabled from command line, we will force to use |
Corentin Wallez | 5cbffcc | 2020-07-08 10:23:57 | [diff] [blame] | 207 | // vulkan even if it is blocklisted. |
Peng Huang | 07ed1864 | 2020-06-09 00:58:17 | [diff] [blame] | 208 | return base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine( |
| 209 | features::kVulkan.name, base::FeatureList::OVERRIDE_ENABLE_FEATURE) |
| 210 | ? VulkanImplementationName::kForcedNative |
| 211 | : VulkanImplementationName::kNative; |
Sean Gilhuly | 3e84fc8 | 2020-01-22 22:06:45 | [diff] [blame] | 212 | } |
| 213 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 214 | } // namespace gles2 |
| 215 | } // namespace gpu |