blob: af30aaaa742c9921af54b64e95e9a261751d393f [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"
Jonathan Backer7bc44592018-04-25 19:59:5010#include "base/strings/string_number_conversions.h"
geofflangdf7fff2d42016-11-11 00:34:0311#include "gpu/command_buffer/common/gles2_cmd_utils.h"
Geoff Lang619081b2017-08-31 19:23:3112#include "gpu/command_buffer/service/context_group.h"
Geoff Langd72f1e92017-10-12 23:31:3813#include "gpu/command_buffer/service/gpu_switches.h"
Geoff Lang94cb9462017-10-25 21:54:0214#include "gpu/config/gpu_finch_features.h"
geofflang3ab039d2017-02-22 15:33:5815#include "ui/gl/gl_switches.h"
geofflangdf7fff2d42016-11-11 00:34:0316
Geoff Lang619081b2017-08-31 19:23:3117#if defined(USE_EGL)
18#include "ui/gl/gl_surface_egl.h"
19#endif // defined(USE_EGL)
20
geofflangdf7fff2d42016-11-11 00:34:0321namespace gpu {
22namespace gles2 {
23
Jonathan Backer7bc44592018-04-25 19:59:5024namespace {
25
26bool GetUintFromSwitch(const base::CommandLine* command_line,
27 const base::StringPiece& switch_string,
28 uint32_t* value) {
29 if (!command_line->HasSwitch(switch_string))
30 return false;
31 std::string switch_value(command_line->GetSwitchValueASCII(switch_string));
32 return base::StringToUint(switch_value, value);
33}
34
35} // namespace
36
geofflangdf7fff2d42016-11-11 00:34:0337gl::GLContextAttribs GenerateGLContextAttribs(
Antoine Labourfeab2392017-12-21 20:28:3938 const ContextCreationAttribs& attribs_helper,
Geoff Lang619081b2017-08-31 19:23:3139 const ContextGroup* context_group) {
Khushalb2c140b2018-07-09 20:21:1640 return GenerateGLContextAttribs(attribs_helper,
41 context_group->use_passthrough_cmd_decoder());
42}
43
44gl::GLContextAttribs GenerateGLContextAttribs(
45 const ContextCreationAttribs& attribs_helper,
46 bool use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0347 gl::GLContextAttribs attribs;
48 attribs.gpu_preference = attribs_helper.gpu_preference;
Khushalb2c140b2018-07-09 20:21:1649 if (use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0350 attribs.bind_generates_resource = attribs_helper.bind_generates_resource;
51 attribs.webgl_compatibility_context =
52 IsWebGLContextType(attribs_helper.context_type);
geofflang3ab039d2017-02-22 15:33:5853
54 // Always use the global texture share group for the passthrough command
55 // decoder
56 attribs.global_texture_share_group = true;
57
Geoff Lang7f82ef42017-09-23 17:56:0258 attribs.robust_resource_initialization = true;
Jiajia Qin69aeeb22017-11-09 05:16:1859 attribs.robust_buffer_access = true;
Geoff Lang7f82ef42017-09-23 17:56:0260
geofflang3ab039d2017-02-22 15:33:5861 // Request a specific context version instead of always 3.0
Jiajia Qin252a8132018-07-19 01:03:2262 if (IsWebGL2ComputeContextType(attribs_helper.context_type)) {
63 attribs.client_major_es_version = 3;
64 attribs.client_minor_es_version = 1;
65 } else if (IsWebGL2OrES3ContextType(attribs_helper.context_type)) {
geofflang3ab039d2017-02-22 15:33:5866 attribs.client_major_es_version = 3;
67 attribs.client_minor_es_version = 0;
68 } else {
69 DCHECK(IsWebGL1OrES2ContextType(attribs_helper.context_type));
70 attribs.client_major_es_version = 2;
71 attribs.client_minor_es_version = 0;
72 }
73 } else {
74 attribs.client_major_es_version = 3;
75 attribs.client_minor_es_version = 0;
geofflangdf7fff2d42016-11-11 00:34:0376 }
geofflang3ab039d2017-02-22 15:33:5877
78 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
79 switches::kDisableES3GLContext)) {
80 // Forcefully disable ES3 contexts
81 attribs.client_major_es_version = 2;
82 attribs.client_minor_es_version = 0;
83 }
84
geofflangdf7fff2d42016-11-11 00:34:0385 return attribs;
86}
87
Geoff Langd72f1e92017-10-12 23:31:3888bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) {
Geoff Lang16f2fc52017-10-23 17:26:3389 std::string switch_value;
90 if (command_line->HasSwitch(switches::kUseCmdDecoder)) {
91 switch_value = command_line->GetSwitchValueASCII(switches::kUseCmdDecoder);
92 }
93
94 if (switch_value == kCmdDecoderPassthroughName) {
95 return true;
96 } else if (switch_value == kCmdDecoderValidatingName) {
97 return false;
98 } else {
99 // Unrecognized or missing switch, use the default.
Geoff Lang94cb9462017-10-25 21:54:02100 return base::FeatureList::IsEnabled(
101 features::kDefaultPassthroughCommandDecoder);
Geoff Lang16f2fc52017-10-23 17:26:33102 }
Geoff Langd72f1e92017-10-12 23:31:38103}
104
Geoff Lang619081b2017-08-31 19:23:31105bool PassthroughCommandDecoderSupported() {
106#if defined(USE_EGL)
107 // Using the passthrough command buffer requires that specific ANGLE
108 // extensions are exposed
109 return gl::GLSurfaceEGL::IsCreateContextBindGeneratesResourceSupported() &&
110 gl::GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() &&
Geoff Langd72f1e92017-10-12 23:31:38111 gl::GLSurfaceEGL::IsRobustResourceInitSupported() &&
Geoff Lang619081b2017-08-31 19:23:31112 gl::GLSurfaceEGL::IsDisplayTextureShareGroupSupported() &&
113 gl::GLSurfaceEGL::IsCreateContextClientArraysSupported();
114#else
115 // The passthrough command buffer is only supported on top of ANGLE/EGL
116 return false;
117#endif // defined(USE_EGL)
Jonathan Backer7bc44592018-04-25 19:59:50118}
119
120GpuPreferences ParseGpuPreferences(const base::CommandLine* command_line) {
121 GpuPreferences gpu_preferences;
122 gpu_preferences.compile_shader_always_succeeds =
123 command_line->HasSwitch(switches::kCompileShaderAlwaysSucceeds);
124 gpu_preferences.disable_gl_error_limit =
125 command_line->HasSwitch(switches::kDisableGLErrorLimit);
126 gpu_preferences.disable_glsl_translator =
127 command_line->HasSwitch(switches::kDisableGLSLTranslator);
128 gpu_preferences.disable_shader_name_hashing =
129 command_line->HasSwitch(switches::kDisableShaderNameHashing);
130 gpu_preferences.enable_gpu_command_logging =
131 command_line->HasSwitch(switches::kEnableGPUCommandLogging);
132 gpu_preferences.enable_gpu_debugging =
133 command_line->HasSwitch(switches::kEnableGPUDebugging);
134 gpu_preferences.enable_gpu_service_logging_gpu =
135 command_line->HasSwitch(switches::kEnableGPUServiceLoggingGPU);
136 gpu_preferences.enable_gpu_driver_debug_logging =
137 command_line->HasSwitch(switches::kEnableGPUDriverDebugLogging);
138 gpu_preferences.disable_gpu_program_cache =
139 command_line->HasSwitch(switches::kDisableGpuProgramCache);
140 gpu_preferences.enforce_gl_minimums =
141 command_line->HasSwitch(switches::kEnforceGLMinimums);
142 if (GetUintFromSwitch(command_line, switches::kForceGpuMemAvailableMb,
143 &gpu_preferences.force_gpu_mem_available)) {
144 gpu_preferences.force_gpu_mem_available *= 1024 * 1024;
145 }
146 if (GetUintFromSwitch(command_line, switches::kGpuProgramCacheSizeKb,
147 &gpu_preferences.gpu_program_cache_size)) {
148 gpu_preferences.gpu_program_cache_size *= 1024;
149 }
150 gpu_preferences.disable_gpu_shader_disk_cache =
151 command_line->HasSwitch(switches::kDisableGpuShaderDiskCache);
152 gpu_preferences.enable_threaded_texture_mailboxes =
153 command_line->HasSwitch(switches::kEnableThreadedTextureMailboxes);
154 gpu_preferences.gl_shader_interm_output =
155 command_line->HasSwitch(switches::kGLShaderIntermOutput);
156 gpu_preferences.emulate_shader_precision =
157 command_line->HasSwitch(switches::kEmulateShaderPrecision);
Jonathan Backer7bc44592018-04-25 19:59:50158 gpu_preferences.enable_gpu_service_logging =
159 command_line->HasSwitch(switches::kEnableGPUServiceLogging);
160 gpu_preferences.enable_gpu_service_tracing =
161 command_line->HasSwitch(switches::kEnableGPUServiceTracing);
162 gpu_preferences.use_passthrough_cmd_decoder =
163 gpu::gles2::UsePassthroughCommandDecoder(command_line);
164 gpu_preferences.disable_gpu_driver_bug_workarounds =
165 command_line->HasSwitch(switches::kDisableGpuDriverBugWorkarounds);
166 gpu_preferences.ignore_gpu_blacklist =
167 command_line->HasSwitch(switches::kIgnoreGpuBlacklist);
Kai Ninomiya328e07a2018-08-23 01:08:16168 gpu_preferences.enable_webgpu =
169 command_line->HasSwitch(switches::kEnableUnsafeWebGPU);
Jonathan Backer7bc44592018-04-25 19:59:50170 return gpu_preferences;
171}
Geoff Lang619081b2017-08-31 19:23:31172
geofflangdf7fff2d42016-11-11 00:34:03173} // namespace gles2
174} // namespace gpu