blob: ef4eaf19f0d4f1a93232c70352ba9a190f3f4aee [file] [log] [blame]
geofflangdf7fff2d42016-11-11 00:34:031// 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 Backer7bc44592018-04-25 19:59:507#include <string>
8
geofflang3ab039d2017-02-22 15:33:589#include "base/command_line.h"
Corentin Walleze660b152020-07-15 16:07:5410#include "base/logging.h"
Jonathan Backer7bc44592018-04-25 19:59:5011#include "base/strings/string_number_conversions.h"
Sean Gilhuly3e84fc82020-01-22 22:06:4512#include "build/build_config.h"
geofflangdf7fff2d42016-11-11 00:34:0313#include "gpu/command_buffer/common/gles2_cmd_utils.h"
Geoff Lang619081b2017-08-31 19:23:3114#include "gpu/command_buffer/service/context_group.h"
Geoff Langd72f1e92017-10-12 23:31:3815#include "gpu/command_buffer/service/gpu_switches.h"
Peng Huangdc3c68f42019-09-15 02:27:2216#include "gpu/config/gpu_finch_features.h"
Sean Gilhulye5342322019-11-08 16:40:5317#include "skia/buildflags.h"
geofflang3ab039d2017-02-22 15:33:5818#include "ui/gl/gl_switches.h"
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3319#include "ui/gl/gl_utils.h"
geofflangdf7fff2d42016-11-11 00:34:0320
Geoff Lang619081b2017-08-31 19:23:3121#if defined(USE_EGL)
22#include "ui/gl/gl_surface_egl.h"
23#endif // defined(USE_EGL)
24
geofflangdf7fff2d42016-11-11 00:34:0325namespace gpu {
26namespace gles2 {
27
Jonathan Backer7bc44592018-04-25 19:59:5028namespace {
29
30bool 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
geofflangdf7fff2d42016-11-11 00:34:0341gl::GLContextAttribs GenerateGLContextAttribs(
Antoine Labourfeab2392017-12-21 20:28:3942 const ContextCreationAttribs& attribs_helper,
Geoff Lang619081b2017-08-31 19:23:3143 const ContextGroup* context_group) {
Khushalb2c140b2018-07-09 20:21:1644 return GenerateGLContextAttribs(attribs_helper,
45 context_group->use_passthrough_cmd_decoder());
46}
47
48gl::GLContextAttribs GenerateGLContextAttribs(
49 const ContextCreationAttribs& attribs_helper,
50 bool use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0351 gl::GLContextAttribs attribs;
52 attribs.gpu_preference = attribs_helper.gpu_preference;
Khushalb2c140b2018-07-09 20:21:1653 if (use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0354 attribs.bind_generates_resource = attribs_helper.bind_generates_resource;
55 attribs.webgl_compatibility_context =
56 IsWebGLContextType(attribs_helper.context_type);
geofflang3ab039d2017-02-22 15:33:5857
58 // Always use the global texture share group for the passthrough command
59 // decoder
60 attribs.global_texture_share_group = true;
61
Geoff Lang7f82ef42017-09-23 17:56:0262 attribs.robust_resource_initialization = true;
Jiajia Qin69aeeb22017-11-09 05:16:1863 attribs.robust_buffer_access = true;
Geoff Lang7f82ef42017-09-23 17:56:0264
geofflang3ab039d2017-02-22 15:33:5865 // Request a specific context version instead of always 3.0
Jiajia Qin252a8132018-07-19 01:03:2266 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)) {
geofflang3ab039d2017-02-22 15:33:5870 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;
geofflangdf7fff2d42016-11-11 00:34:0380 }
geofflang3ab039d2017-02-22 15:33:5881
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
geofflangdf7fff2d42016-11-11 00:34:0389 return attribs;
90}
91
Geoff Langd72f1e92017-10-12 23:31:3892bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) {
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3393 return gl::UsePassthroughCommandDecoder(command_line);
Geoff Langd72f1e92017-10-12 23:31:3894}
95
Geoff Lang619081b2017-08-31 19:23:3196bool PassthroughCommandDecoderSupported() {
Jonah Ryan-Davis77b562dc2020-07-17 19:11:2397 return gl::PassthroughCommandDecoderSupported();
Jonathan Backer7bc44592018-04-25 19:59:5098}
99
100GpuPreferences 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,
Wez4f8b5432019-12-31 06:40:11123 &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 Backer7bc44592018-04-25 19:59:50130 }
Sergey Ulanov689c31f2020-01-24 23:21:16131 GetUintFromSwitch(command_line, switches::kForceMaxTextureSize,
132 &gpu_preferences.force_max_texture_size);
Jonathan Backer7bc44592018-04-25 19:59:50133 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 Backer7bc44592018-04-25 19:59:50145 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 Wallez5cbffcc2020-07-08 10:23:57151 gpu_preferences.ignore_gpu_blocklist =
Corentin Walleze660b152020-07-15 16:07:54152 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 Ninomiya328e07a2018-08-23 01:08:16161 gpu_preferences.enable_webgpu =
162 command_line->HasSwitch(switches::kEnableUnsafeWebGPU);
Austin Eng32fc8ba2020-04-30 01:39:49163 gpu_preferences.enable_dawn_backend_validation =
164 command_line->HasSwitch(switches::kEnableDawnBackendValidation);
Sean Gilhuly3e84fc82020-01-22 22:06:45165 gpu_preferences.gr_context_type = ParseGrContextType();
Peng Huang07ed18642020-06-09 00:58:17166 gpu_preferences.use_vulkan = ParseVulkanImplementationName(command_line);
Peng Huang556da902019-03-22 17:49:40167 gpu_preferences.disable_vulkan_surface =
168 command_line->HasSwitch(switches::kDisableVulkanSurface);
Vasiliy Telezhnikov533c5642019-12-03 15:10:16169
170 gpu_preferences.enable_gpu_blocked_time_metric =
171 command_line->HasSwitch(switches::kEnableGpuBlockedTime);
172
Jonathan Backer7bc44592018-04-25 19:59:50173 return gpu_preferences;
174}
Geoff Lang619081b2017-08-31 19:23:31175
Sean Gilhuly3e84fc82020-01-22 22:06:45176GrContextType 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
191VulkanImplementationName ParseVulkanImplementationName(
Peng Huang07ed18642020-06-09 00:58:17192 const base::CommandLine* command_line) {
Sean Gilhuly3e84fc82020-01-22 22:06:45193 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 Huang07ed18642020-06-09 00:58:17201
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 Wallez5cbffcc2020-07-08 10:23:57207 // vulkan even if it is blocklisted.
Peng Huang07ed18642020-06-09 00:58:17208 return base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine(
209 features::kVulkan.name, base::FeatureList::OVERRIDE_ENABLE_FEATURE)
210 ? VulkanImplementationName::kForcedNative
211 : VulkanImplementationName::kNative;
Sean Gilhuly3e84fc82020-01-22 22:06:45212}
213
geofflangdf7fff2d42016-11-11 00:34:03214} // namespace gles2
215} // namespace gpu