blob: f6da77022df72bb6f7be1e84eea0a9f2344783c5 [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"
Sean Gilhulye5342322019-11-08 16:40:5315#include "skia/buildflags.h"
geofflang3ab039d2017-02-22 15:33:5816#include "ui/gl/gl_switches.h"
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3317#include "ui/gl/gl_utils.h"
geofflangdf7fff2d42016-11-11 00:34:0318
Geoff Lang619081b2017-08-31 19:23:3119#if defined(USE_EGL)
20#include "ui/gl/gl_surface_egl.h"
21#endif // defined(USE_EGL)
22
geofflangdf7fff2d42016-11-11 00:34:0323namespace gpu {
24namespace gles2 {
25
Jonathan Backer7bc44592018-04-25 19:59:5026namespace {
27
28bool 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
geofflangdf7fff2d42016-11-11 00:34:0339gl::GLContextAttribs GenerateGLContextAttribs(
Antoine Labourfeab2392017-12-21 20:28:3940 const ContextCreationAttribs& attribs_helper,
Geoff Lang619081b2017-08-31 19:23:3141 const ContextGroup* context_group) {
Khushalb2c140b2018-07-09 20:21:1642 return GenerateGLContextAttribs(attribs_helper,
43 context_group->use_passthrough_cmd_decoder());
44}
45
46gl::GLContextAttribs GenerateGLContextAttribs(
47 const ContextCreationAttribs& attribs_helper,
48 bool use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0349 gl::GLContextAttribs attribs;
50 attribs.gpu_preference = attribs_helper.gpu_preference;
Khushalb2c140b2018-07-09 20:21:1651 if (use_passthrough_cmd_decoder) {
geofflangdf7fff2d42016-11-11 00:34:0352 attribs.bind_generates_resource = attribs_helper.bind_generates_resource;
53 attribs.webgl_compatibility_context =
54 IsWebGLContextType(attribs_helper.context_type);
geofflang3ab039d2017-02-22 15:33:5855
56 // Always use the global texture share group for the passthrough command
57 // decoder
58 attribs.global_texture_share_group = true;
59
Geoff Lang7f82ef42017-09-23 17:56:0260 attribs.robust_resource_initialization = true;
Jiajia Qin69aeeb22017-11-09 05:16:1861 attribs.robust_buffer_access = true;
Geoff Lang7f82ef42017-09-23 17:56:0262
geofflang3ab039d2017-02-22 15:33:5863 // Request a specific context version instead of always 3.0
Jiajia Qin252a8132018-07-19 01:03:2264 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)) {
geofflang3ab039d2017-02-22 15:33:5868 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;
geofflangdf7fff2d42016-11-11 00:34:0378 }
geofflang3ab039d2017-02-22 15:33:5879
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
geofflangdf7fff2d42016-11-11 00:34:0387 return attribs;
88}
89
Geoff Langd72f1e92017-10-12 23:31:3890bool UsePassthroughCommandDecoder(const base::CommandLine* command_line) {
Jonah Ryan-Davis570ab8b92019-07-08 20:03:3391 return gl::UsePassthroughCommandDecoder(command_line);
Geoff Langd72f1e92017-10-12 23:31:3892}
93
Geoff Lang619081b2017-08-31 19:23:3194bool 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 Langd72f1e92017-10-12 23:31:38100 gl::GLSurfaceEGL::IsRobustResourceInitSupported() &&
Geoff Lang619081b2017-08-31 19:23:31101 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 Backer7bc44592018-04-25 19:59:50107}
108
109GpuPreferences 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,
Wez4f8b5432019-12-31 06:40:11132 &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 Backer7bc44592018-04-25 19:59:50139 }
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 Backer7bc44592018-04-25 19:59:50152 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 Backer7bc44592018-04-25 19:59:50158 gpu_preferences.ignore_gpu_blacklist =
159 command_line->HasSwitch(switches::kIgnoreGpuBlacklist);
Kai Ninomiya328e07a2018-08-23 01:08:16160 gpu_preferences.enable_webgpu =
161 command_line->HasSwitch(switches::kEnableUnsafeWebGPU);
Peng Huang455bc4d2019-06-07 20:17:05162 if (command_line->HasSwitch(switches::kUseVulkan)) {
163 auto value = command_line->GetSwitchValueASCII(switches::kUseVulkan);
164 if (value.empty() || value == switches::kVulkanImplementationNameNative) {
Peng Huange74bf972019-10-15 23:44:03165 gpu_preferences.use_vulkan = VulkanImplementationName::kForcedNative;
Peng Huang455bc4d2019-06-07 20:17:05166 } else if (value == switches::kVulkanImplementationNameSwiftshader) {
167 gpu_preferences.use_vulkan = VulkanImplementationName::kSwiftshader;
168 } else {
169 gpu_preferences.use_vulkan = VulkanImplementationName::kNone;
170 }
Peng Huang455bc4d2019-06-07 20:17:05171 }
Peng Huang556da902019-03-22 17:49:40172 gpu_preferences.disable_vulkan_surface =
173 command_line->HasSwitch(switches::kDisableVulkanSurface);
Brian Ho4e84b172019-10-18 23:09:52174#if defined(OS_MACOSX)
Sean Gilhulyc8018df2020-01-21 18:20:35175 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 Ho4e84b172019-10-18 23:09:52182#endif
Sean Gilhulye5342322019-11-08 16:40:53183#if BUILDFLAG(SKIA_USE_DAWN)
Sean Gilhulyc8018df2020-01-21 18:20:35184 if (base::FeatureList::IsEnabled(features::kSkiaDawn))
185 gpu_preferences.gr_context_type = GrContextType::kDawn;
Sean Gilhulye5342322019-11-08 16:40:53186#endif
Peng Huang3fea38b2019-10-25 13:21:22187 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 Telezhnikov533c5642019-12-03 15:10:16193
194 gpu_preferences.enable_gpu_blocked_time_metric =
195 command_line->HasSwitch(switches::kEnableGpuBlockedTime);
196
Jonathan Backer7bc44592018-04-25 19:59:50197 return gpu_preferences;
198}
Geoff Lang619081b2017-08-31 19:23:31199
geofflangdf7fff2d42016-11-11 00:34:03200} // namespace gles2
201} // namespace gpu