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" |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 10 | #include "base/strings/string_number_conversions.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 11 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 12 | #include "gpu/command_buffer/service/context_group.h" |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 13 | #include "gpu/command_buffer/service/gpu_switches.h" |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame] | 14 | #include "gpu/config/gpu_finch_features.h" |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 15 | #include "skia/buildflags.h" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 16 | #include "ui/gl/gl_switches.h" |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 17 | #include "ui/gl/gl_utils.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 18 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 19 | #if defined(USE_EGL) |
| 20 | #include "ui/gl/gl_surface_egl.h" |
| 21 | #endif // defined(USE_EGL) |
| 22 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 23 | namespace gpu { |
| 24 | namespace gles2 { |
| 25 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | bool GetUintFromSwitch(const base::CommandLine* command_line, |
| 29 | const base::StringPiece& switch_string, |
| 30 | uint32_t* value) { |
| 31 | if (!command_line->HasSwitch(switch_string)) |
| 32 | return false; |
| 33 | std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 34 | return base::StringToUint(switch_value, value); |
| 35 | } |
| 36 | |
| 37 | } // namespace |
| 38 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 39 | gl::GLContextAttribs GenerateGLContextAttribs( |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 40 | const ContextCreationAttribs& attribs_helper, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 41 | const ContextGroup* context_group) { |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 42 | return GenerateGLContextAttribs(attribs_helper, |
| 43 | context_group->use_passthrough_cmd_decoder()); |
| 44 | } |
| 45 | |
| 46 | gl::GLContextAttribs GenerateGLContextAttribs( |
| 47 | const ContextCreationAttribs& attribs_helper, |
| 48 | bool use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 49 | gl::GLContextAttribs attribs; |
| 50 | attribs.gpu_preference = attribs_helper.gpu_preference; |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 51 | if (use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 52 | attribs.bind_generates_resource = attribs_helper.bind_generates_resource; |
| 53 | attribs.webgl_compatibility_context = |
| 54 | IsWebGLContextType(attribs_helper.context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 55 | |
| 56 | // Always use the global texture share group for the passthrough command |
| 57 | // decoder |
| 58 | attribs.global_texture_share_group = true; |
| 59 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 60 | attribs.robust_resource_initialization = true; |
Jiajia Qin | 69aeeb2 | 2017-11-09 05:16:18 | [diff] [blame] | 61 | attribs.robust_buffer_access = true; |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 62 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 63 | // Request a specific context version instead of always 3.0 |
Jiajia Qin | 252a813 | 2018-07-19 01:03:22 | [diff] [blame] | 64 | if (IsWebGL2ComputeContextType(attribs_helper.context_type)) { |
| 65 | attribs.client_major_es_version = 3; |
| 66 | attribs.client_minor_es_version = 1; |
| 67 | } else if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 68 | attribs.client_major_es_version = 3; |
| 69 | attribs.client_minor_es_version = 0; |
| 70 | } else { |
| 71 | DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type)); |
| 72 | attribs.client_major_es_version = 2; |
| 73 | attribs.client_minor_es_version = 0; |
| 74 | } |
| 75 | } else { |
| 76 | attribs.client_major_es_version = 3; |
| 77 | attribs.client_minor_es_version = 0; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 78 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 79 | |
| 80 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 81 | switches::kDisableES3GLContext)) { |
| 82 | // Forcefully disable ES3 contexts |
| 83 | attribs.client_major_es_version = 2; |
| 84 | attribs.client_minor_es_version = 0; |
| 85 | } |
| 86 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 87 | return attribs; |
| 88 | } |
| 89 | |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 90 | bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) { |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 91 | return gl::UsePassthroughCommandDecoder(command_line); |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 92 | } |
| 93 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 94 | bool PassthroughCommandDecoderSupported() { |
| 95 | #if defined(USE_EGL) |
| 96 | // Using the passthrough command buffer requires that specific ANGLE |
| 97 | // extensions are exposed |
| 98 | return gl::GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported() && |
| 99 | gl::GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() && |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 100 | gl::GLSurfaceEGL::IsRobustResourceInitSupported() && |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 101 | gl::GLSurfaceEGL::IsDisplayTextureShareGroupSupported() && |
| 102 | gl::GLSurfaceEGL::IsCreateContextClientArraysSupported(); |
| 103 | #else |
| 104 | // The passthrough command buffer is only supported on top of ANGLE/EGL |
| 105 | return false; |
| 106 | #endif // defined(USE_EGL) |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) { |
| 110 | GpuPreferences gpu_preferences; |
| 111 | gpu_preferences.compile_shader_always_succeeds = |
| 112 | command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 113 | gpu_preferences.disable_gl_error_limit = |
| 114 | command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 115 | gpu_preferences.disable_glsl_translator = |
| 116 | command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 117 | gpu_preferences.disable_shader_name_hashing = |
| 118 | command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 119 | gpu_preferences.enable_gpu_command_logging = |
| 120 | command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 121 | gpu_preferences.enable_gpu_debugging = |
| 122 | command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 123 | gpu_preferences.enable_gpu_service_logging_gpu = |
| 124 | command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 125 | gpu_preferences.enable_gpu_driver_debug_logging = |
| 126 | command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging); |
| 127 | gpu_preferences.disable_gpu_program_cache = |
| 128 | command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 129 | gpu_preferences.enforce_gl_minimums = |
| 130 | command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 131 | if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
Wez | 4f8b543 | 2019-12-31 06:40:11 | [diff] [blame] | 132 | &gpu_preferences.force_gpu_mem_available_bytes)) { |
| 133 | gpu_preferences.force_gpu_mem_available_bytes *= 1024 * 1024; |
| 134 | } |
| 135 | if (GetUintFromSwitch( |
| 136 | command_line, switches::kForceGpuMemDiscardableLimitMb, |
| 137 | &gpu_preferences.force_gpu_mem_discardable_limit_bytes)) { |
| 138 | gpu_preferences.force_gpu_mem_discardable_limit_bytes *= 1024 * 1024; |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 139 | } |
| 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); |
| 150 | gpu_preferences.emulate_shader_precision = |
| 151 | command_line->HasSwitch(switches::kEmulateShaderPrecision); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 152 | gpu_preferences.enable_gpu_service_logging = |
| 153 | command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 154 | gpu_preferences.enable_gpu_service_tracing = |
| 155 | command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 156 | gpu_preferences.use_passthrough_cmd_decoder = |
| 157 | gpu::gles2::UsePassthroughCommandDecoder(command_line); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 158 | gpu_preferences.ignore_gpu_blacklist = |
| 159 | command_line->HasSwitch(switches::kIgnoreGpuBlacklist); |
Kai Ninomiya | 328e07a | 2018-08-23 01:08:16 | [diff] [blame] | 160 | gpu_preferences.enable_webgpu = |
| 161 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU); |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 162 | if (command_line->HasSwitch(switches::kUseVulkan)) { |
| 163 | auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan); |
| 164 | if (value.empty() || value == switches::kVulkanImplementationNameNative) { |
Peng Huang | e74bf97 | 2019-10-15 23:44:03 | [diff] [blame] | 165 | gpu_preferences.use_vulkan = VulkanImplementationName::kForcedNative; |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 166 | } else if (value == switches::kVulkanImplementationNameSwiftshader) { |
| 167 | gpu_preferences.use_vulkan = VulkanImplementationName::kSwiftshader; |
| 168 | } else { |
| 169 | gpu_preferences.use_vulkan = VulkanImplementationName::kNone; |
| 170 | } |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 171 | } |
Peng Huang | 556da90 | 2019-03-22 17:49:40 | [diff] [blame] | 172 | gpu_preferences.disable_vulkan_surface = |
| 173 | command_line->HasSwitch(switches::kDisableVulkanSurface); |
Brian Ho | 4e84b17 | 2019-10-18 23:09:52 | [diff] [blame] | 174 | #if defined(OS_MACOSX) |
Sean Gilhuly | c8018df | 2020-01-21 18:20:35 | [diff] [blame] | 175 | gpu_preferences.gr_context_type = |
| 176 | base::FeatureList::IsEnabled(features::kMetal) ? GrContextType::kMetal |
| 177 | : GrContextType::kGL; |
| 178 | #else |
| 179 | gpu_preferences.gr_context_type = |
| 180 | base::FeatureList::IsEnabled(features::kVulkan) ? GrContextType::kVulkan |
| 181 | : GrContextType::kGL; |
Brian Ho | 4e84b17 | 2019-10-18 23:09:52 | [diff] [blame] | 182 | #endif |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 183 | #if BUILDFLAG(SKIA_USE_DAWN) |
Sean Gilhuly | c8018df | 2020-01-21 18:20:35 | [diff] [blame] | 184 | if (base::FeatureList::IsEnabled(features::kSkiaDawn)) |
| 185 | gpu_preferences.gr_context_type = GrContextType::kDawn; |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 186 | #endif |
Peng Huang | 3fea38b | 2019-10-25 13:21:22 | [diff] [blame] | 187 | if (gpu_preferences.gr_context_type == GrContextType::kVulkan && |
| 188 | gpu_preferences.use_vulkan == gpu::VulkanImplementationName::kNone) { |
| 189 | // If gpu_preferences.use_vulkan is not set from --use-vulkan, the native |
| 190 | // vulkan implementation will be used by default. |
| 191 | gpu_preferences.use_vulkan = gpu::VulkanImplementationName::kNative; |
| 192 | } |
Vasiliy Telezhnikov | 533c564 | 2019-12-03 15:10:16 | [diff] [blame] | 193 | |
| 194 | gpu_preferences.enable_gpu_blocked_time_metric = |
| 195 | command_line->HasSwitch(switches::kEnableGpuBlockedTime); |
| 196 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 197 | return gpu_preferences; |
| 198 | } |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 199 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 200 | } // namespace gles2 |
| 201 | } // namespace gpu |