blob: 06f9d1b907b68d4391098074ee804880c248fd81 [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"
Peng Huangdc3c68f42019-09-15 02:27:2214#include "gpu/config/gpu_finch_features.h"
geofflang3ab039d2017-02-22 15:33:5815#include "ui/gl/gl_switches.h"
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3316#include "ui/gl/gl_utils.h"
geofflangdf7fff2d42016-11-11 00:34:0317
Geoff Lang619081b2017-08-31 19:23:3118#if defined(USE_EGL)
19#include "ui/gl/gl_surface_egl.h"
20#endif // defined(USE_EGL)
21
geofflangdf7fff2d42016-11-11 00:34:0322namespace gpu {
23namespace gles2 {
24
Jonathan Backer7bc44592018-04-25 19:59:5025namespace {
26
27bool 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
geofflangdf7fff2d42016-11-11 00:34:0338gl::GLContextAttribs GenerateGLContextAttribs(
Antoine Labourfeab2392017-12-21 20:28:3939 const ContextCreationAttribs& attribs_helper,
Geoff Lang619081b2017-08-31 19:23:3140 const ContextGroup* context_group) {
Khushalb2c140b2018-07-09 20:21:1641 return GenerateGLContextAttribs(attribs_helper,
42 context_group->use_passthrough_cmd_decoder());
43}
44
45gl::GLContextAttribs GenerateGLContextAttribs(
46 const ContextCreationAttribs& attribs_helper,
47 bool use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0348 gl::GLContextAttribs attribs;
49 attribs.gpu_preference = attribs_helper.gpu_preference;
Khushalb2c140b2018-07-09 20:21:1650 if (use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0351 attribs.bind_generates_resource = attribs_helper.bind_generates_resource;
52 attribs.webgl_compatibility_context =
53 IsWebGLContextType(attribs_helper.context_type);
geofflang3ab039d2017-02-22 15:33:5854
55 // Always use the global texture share group for the passthrough command
56 // decoder
57 attribs.global_texture_share_group = true;
58
Geoff Lang7f82ef42017-09-23 17:56:0259 attribs.robust_resource_initialization = true;
Jiajia Qin69aeeb22017-11-09 05:16:1860 attribs.robust_buffer_access = true;
Geoff Lang7f82ef42017-09-23 17:56:0261
geofflang3ab039d2017-02-22 15:33:5862 // Request a specific context version instead of always 3.0
Jiajia Qin252a8132018-07-19 01:03:2263 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)) {
geofflang3ab039d2017-02-22 15:33:5867 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;
geofflangdf7fff2d42016-11-11 00:34:0377 }
geofflang3ab039d2017-02-22 15:33:5878
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
geofflangdf7fff2d42016-11-11 00:34:0386 return attribs;
87}
88
Geoff Langd72f1e92017-10-12 23:31:3889bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) {
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3390 return gl::UsePassthroughCommandDecoder(command_line);
Geoff Langd72f1e92017-10-12 23:31:3891}
92
Geoff Lang619081b2017-08-31 19:23:3193bool 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 Langd72f1e92017-10-12 23:31:3899 gl::GLSurfaceEGL::IsRobustResourceInitSupported() &&
Geoff Lang619081b2017-08-31 19:23:31100 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 Backer7bc44592018-04-25 19:59:50106}
107
108GpuPreferences 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 Backer7bc44592018-04-25 19:59:50146 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 Ninomiya328e07a2018-08-23 01:08:16156 gpu_preferences.enable_webgpu =
157 command_line->HasSwitch(switches::kEnableUnsafeWebGPU);
Peng Huang455bc4d2019-06-07 20:17:05158 if (command_line->HasSwitch(switches::kUseVulkan)) {
Peng Huangdc3c68f42019-09-15 02:27:22159 DLOG_IF(ERROR, base::FeatureList::IsEnabled(features::kVulkan))
160 << "--enabled-features=Vulkan is overrided by --use-vulkan.";
Peng Huang455bc4d2019-06-07 20:17:05161 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 Huangdc3c68f42019-09-15 02:27:22170 gpu_preferences.use_vulkan = base::FeatureList::IsEnabled(features::kVulkan)
171 ? gpu::VulkanImplementationName::kNative
172 : gpu::VulkanImplementationName::kNone;
Peng Huang455bc4d2019-06-07 20:17:05173 }
Peng Huang556da902019-03-22 17:49:40174 gpu_preferences.disable_vulkan_surface =
175 command_line->HasSwitch(switches::kDisableVulkanSurface);
Jonathan Backer7bc44592018-04-25 19:59:50176 return gpu_preferences;
177}
Geoff Lang619081b2017-08-31 19:23:31178
geofflangdf7fff2d42016-11-11 00:34:03179} // namespace gles2
180} // namespace gpu