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" |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 15 | #include "ui/gl/gl_switches.h" |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 16 | #include "ui/gl/gl_utils.h" |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 17 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 18 | #if defined(USE_EGL) |
| 19 | #include "ui/gl/gl_surface_egl.h" |
| 20 | #endif // defined(USE_EGL) |
| 21 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 22 | namespace gpu { |
| 23 | namespace gles2 { |
| 24 | |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 25 | namespace { |
| 26 | |
| 27 | bool GetUintFromSwitch(const base::CommandLine* command_line, |
| 28 | const base::StringPiece& switch_string, |
| 29 | uint32_t* value) { |
| 30 | if (!command_line->HasSwitch(switch_string)) |
| 31 | return false; |
| 32 | std::string switch_value(command_line->GetSwitchValueASCII(switch_string)); |
| 33 | return base::StringToUint(switch_value, value); |
| 34 | } |
| 35 | |
| 36 | } // namespace |
| 37 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 38 | gl::GLContextAttribs GenerateGLContextAttribs( |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 39 | const ContextCreationAttribs& attribs_helper, |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 40 | const ContextGroup* context_group) { |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 41 | return GenerateGLContextAttribs(attribs_helper, |
| 42 | context_group->use_passthrough_cmd_decoder()); |
| 43 | } |
| 44 | |
| 45 | gl::GLContextAttribs GenerateGLContextAttribs( |
| 46 | const ContextCreationAttribs& attribs_helper, |
| 47 | bool use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 48 | gl::GLContextAttribs attribs; |
| 49 | attribs.gpu_preference = attribs_helper.gpu_preference; |
Khushal | b2c140b | 2018-07-09 20:21:16 | [diff] [blame] | 50 | if (use_passthrough_cmd_decoder) { |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 51 | attribs.bind_generates_resource = attribs_helper.bind_generates_resource; |
| 52 | attribs.webgl_compatibility_context = |
| 53 | IsWebGLContextType(attribs_helper.context_type); |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 54 | |
| 55 | // Always use the global texture share group for the passthrough command |
| 56 | // decoder |
| 57 | attribs.global_texture_share_group = true; |
| 58 | |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 59 | attribs.robust_resource_initialization = true; |
Jiajia Qin | 69aeeb2 | 2017-11-09 05:16:18 | [diff] [blame] | 60 | attribs.robust_buffer_access = true; |
Geoff Lang | 7f82ef4 | 2017-09-23 17:56:02 | [diff] [blame] | 61 | |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 62 | // Request a specific context version instead of always 3.0 |
Jiajia Qin | 252a813 | 2018-07-19 01:03:22 | [diff] [blame] | 63 | if (IsWebGL2ComputeContextType(attribs_helper.context_type)) { |
| 64 | attribs.client_major_es_version = 3; |
| 65 | attribs.client_minor_es_version = 1; |
| 66 | } else if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) { |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 67 | attribs.client_major_es_version = 3; |
| 68 | attribs.client_minor_es_version = 0; |
| 69 | } else { |
| 70 | DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type)); |
| 71 | attribs.client_major_es_version = 2; |
| 72 | attribs.client_minor_es_version = 0; |
| 73 | } |
| 74 | } else { |
| 75 | attribs.client_major_es_version = 3; |
| 76 | attribs.client_minor_es_version = 0; |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 77 | } |
geofflang | 3ab039d | 2017-02-22 15:33:58 | [diff] [blame] | 78 | |
| 79 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 80 | switches::kDisableES3GLContext)) { |
| 81 | // Forcefully disable ES3 contexts |
| 82 | attribs.client_major_es_version = 2; |
| 83 | attribs.client_minor_es_version = 0; |
| 84 | } |
| 85 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 86 | return attribs; |
| 87 | } |
| 88 | |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 89 | bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) { |
Jonah Ryan-Davis | 570ab8b9 | 2019-07-08 20:03:33 | [diff] [blame] | 90 | return gl::UsePassthroughCommandDecoder(command_line); |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 91 | } |
| 92 | |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 93 | bool PassthroughCommandDecoderSupported() { |
| 94 | #if defined(USE_EGL) |
| 95 | // Using the passthrough command buffer requires that specific ANGLE |
| 96 | // extensions are exposed |
| 97 | return gl::GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported() && |
| 98 | gl::GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() && |
Geoff Lang | d72f1e9 | 2017-10-12 23:31:38 | [diff] [blame] | 99 | gl::GLSurfaceEGL::IsRobustResourceInitSupported() && |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 100 | gl::GLSurfaceEGL::IsDisplayTextureShareGroupSupported() && |
| 101 | gl::GLSurfaceEGL::IsCreateContextClientArraysSupported(); |
| 102 | #else |
| 103 | // The passthrough command buffer is only supported on top of ANGLE/EGL |
| 104 | return false; |
| 105 | #endif // defined(USE_EGL) |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) { |
| 109 | GpuPreferences gpu_preferences; |
| 110 | gpu_preferences.compile_shader_always_succeeds = |
| 111 | command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds); |
| 112 | gpu_preferences.disable_gl_error_limit = |
| 113 | command_line->HasSwitch(switches::kDisableGLErrorLimit); |
| 114 | gpu_preferences.disable_glsl_translator = |
| 115 | command_line->HasSwitch(switches::kDisableGLSLTranslator); |
| 116 | gpu_preferences.disable_shader_name_hashing = |
| 117 | command_line->HasSwitch(switches::kDisableShaderNameHashing); |
| 118 | gpu_preferences.enable_gpu_command_logging = |
| 119 | command_line->HasSwitch(switches::kEnableGPUCommandLogging); |
| 120 | gpu_preferences.enable_gpu_debugging = |
| 121 | command_line->HasSwitch(switches::kEnableGPUDebugging); |
| 122 | gpu_preferences.enable_gpu_service_logging_gpu = |
| 123 | command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU); |
| 124 | gpu_preferences.enable_gpu_driver_debug_logging = |
| 125 | command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging); |
| 126 | gpu_preferences.disable_gpu_program_cache = |
| 127 | command_line->HasSwitch(switches::kDisableGpuProgramCache); |
| 128 | gpu_preferences.enforce_gl_minimums = |
| 129 | command_line->HasSwitch(switches::kEnforceGLMinimums); |
| 130 | if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb, |
| 131 | &gpu_preferences.force_gpu_mem_available)) { |
| 132 | gpu_preferences.force_gpu_mem_available *= 1024 * 1024; |
| 133 | } |
| 134 | if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb, |
| 135 | &gpu_preferences.gpu_program_cache_size)) { |
| 136 | gpu_preferences.gpu_program_cache_size *= 1024; |
| 137 | } |
| 138 | gpu_preferences.disable_gpu_shader_disk_cache = |
| 139 | command_line->HasSwitch(switches::kDisableGpuShaderDiskCache); |
| 140 | gpu_preferences.enable_threaded_texture_mailboxes = |
| 141 | command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes); |
| 142 | gpu_preferences.gl_shader_interm_output = |
| 143 | command_line->HasSwitch(switches::kGLShaderIntermOutput); |
| 144 | gpu_preferences.emulate_shader_precision = |
| 145 | command_line->HasSwitch(switches::kEmulateShaderPrecision); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 146 | gpu_preferences.enable_gpu_service_logging = |
| 147 | command_line->HasSwitch(switches::kEnableGPUServiceLogging); |
| 148 | gpu_preferences.enable_gpu_service_tracing = |
| 149 | command_line->HasSwitch(switches::kEnableGPUServiceTracing); |
| 150 | gpu_preferences.use_passthrough_cmd_decoder = |
| 151 | gpu::gles2::UsePassthroughCommandDecoder(command_line); |
| 152 | gpu_preferences.disable_gpu_driver_bug_workarounds = |
| 153 | command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds); |
| 154 | gpu_preferences.ignore_gpu_blacklist = |
| 155 | command_line->HasSwitch(switches::kIgnoreGpuBlacklist); |
Kai Ninomiya | 328e07a | 2018-08-23 01:08:16 | [diff] [blame] | 156 | gpu_preferences.enable_webgpu = |
| 157 | command_line->HasSwitch(switches::kEnableUnsafeWebGPU); |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 158 | if (command_line->HasSwitch(switches::kUseVulkan)) { |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame^] | 159 | DLOG_IF(ERROR, base::FeatureList::IsEnabled(features::kVulkan)) |
| 160 | << "--enabled-features=Vulkan is overrided by --use-vulkan."; |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 161 | auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan); |
| 162 | if (value.empty() || value == switches::kVulkanImplementationNameNative) { |
| 163 | gpu_preferences.use_vulkan = VulkanImplementationName::kNative; |
| 164 | } else if (value == switches::kVulkanImplementationNameSwiftshader) { |
| 165 | gpu_preferences.use_vulkan = VulkanImplementationName::kSwiftshader; |
| 166 | } else { |
| 167 | gpu_preferences.use_vulkan = VulkanImplementationName::kNone; |
| 168 | } |
| 169 | } else { |
Peng Huang | dc3c68f4 | 2019-09-15 02:27:22 | [diff] [blame^] | 170 | gpu_preferences.use_vulkan = base::FeatureList::IsEnabled(features::kVulkan) |
| 171 | ? gpu::VulkanImplementationName::kNative |
| 172 | : gpu::VulkanImplementationName::kNone; |
Peng Huang | 455bc4d | 2019-06-07 20:17:05 | [diff] [blame] | 173 | } |
Peng Huang | 556da90 | 2019-03-22 17:49:40 | [diff] [blame] | 174 | gpu_preferences.disable_vulkan_surface = |
| 175 | command_line->HasSwitch(switches::kDisableVulkanSurface); |
Jonathan Backer | 7bc4459 | 2018-04-25 19:59:50 | [diff] [blame] | 176 | return gpu_preferences; |
| 177 | } |
Geoff Lang | 619081b | 2017-08-31 19:23:31 | [diff] [blame] | 178 | |
geofflang | df7fff2d4 | 2016-11-11 00:34:03 | [diff] [blame] | 179 | } // namespace gles2 |
| 180 | } // namespace gpu |