Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: gpu/command_buffer/service/shader_translator.cc

Issue 1716813002: Use GpuPreferences to avoid directly accessing switches in gpu related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/shader_translator.h" 5 #include "gpu/command_buffer/service/shader_translator.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <string.h> 9 #include <string.h>
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/at_exit.h" 12 #include "base/at_exit.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "gpu/command_buffer/service/gpu_switches.h"
19 #include "ui/gl/gl_implementation.h" 18 #include "ui/gl/gl_implementation.h"
20 #include "ui/gl/gl_version_info.h" 19 #include "ui/gl/gl_version_info.h"
21 20
22 namespace gpu { 21 namespace gpu {
23 namespace gles2 { 22 namespace gles2 {
24 23
25 namespace { 24 namespace {
26 25
27 class ShaderTranslatorInitializer { 26 class ShaderTranslatorInitializer {
28 public: 27 public:
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 154 }
156 155
157 ShaderTranslator::DestructionObserver::DestructionObserver() { 156 ShaderTranslator::DestructionObserver::DestructionObserver() {
158 } 157 }
159 158
160 ShaderTranslator::DestructionObserver::~DestructionObserver() { 159 ShaderTranslator::DestructionObserver::~DestructionObserver() {
161 } 160 }
162 161
163 ShaderTranslator::ShaderTranslator() 162 ShaderTranslator::ShaderTranslator()
164 : compiler_(NULL), 163 : compiler_(NULL),
165 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)) { 164 driver_bug_workarounds_(static_cast<ShCompileOptions>(0)),
165 gl_shader_interm_output_(false) {
166 } 166 }
167 167
168 bool ShaderTranslator::Init(GLenum shader_type, 168 bool ShaderTranslator::Init(GLenum shader_type,
169 ShShaderSpec shader_spec, 169 ShShaderSpec shader_spec,
170 const ShBuiltInResources* resources, 170 const ShBuiltInResources* resources,
171 ShShaderOutput shader_output_language, 171 ShShaderOutput shader_output_language,
172 ShCompileOptions driver_bug_workarounds) { 172 ShCompileOptions driver_bug_workarounds,
173 bool gl_shader_interm_output) {
173 // Make sure Init is called only once. 174 // Make sure Init is called only once.
174 DCHECK(compiler_ == NULL); 175 DCHECK(compiler_ == NULL);
175 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER); 176 DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER);
176 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC || 177 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC ||
177 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC); 178 shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC);
178 DCHECK(resources != NULL); 179 DCHECK(resources != NULL);
179 180
180 g_translator_initializer.Get(); 181 g_translator_initializer.Get();
181 182
182 183
183 { 184 {
184 TRACE_EVENT0("gpu", "ShConstructCompiler"); 185 TRACE_EVENT0("gpu", "ShConstructCompiler");
185 compiler_ = ShConstructCompiler(shader_type, shader_spec, 186 compiler_ = ShConstructCompiler(shader_type, shader_spec,
186 shader_output_language, resources); 187 shader_output_language, resources);
187 } 188 }
188 driver_bug_workarounds_ = driver_bug_workarounds; 189 driver_bug_workarounds_ = driver_bug_workarounds;
190 gl_shader_interm_output_ = gl_shader_interm_output;
189 return compiler_ != NULL; 191 return compiler_ != NULL;
190 } 192 }
191 193
192 int ShaderTranslator::GetCompileOptions() const { 194 int ShaderTranslator::GetCompileOptions() const {
193 int compile_options = 195 int compile_options =
194 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS | 196 SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS |
195 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | 197 SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH |
196 SH_CLAMP_INDIRECT_ARRAY_BOUNDS; 198 SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
197 199
198 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 200 if (gl_shader_interm_output_)
199 switches::kGLShaderIntermOutput))
200 compile_options |= SH_INTERMEDIATE_TREE; 201 compile_options |= SH_INTERMEDIATE_TREE;
201 202
202 compile_options |= driver_bug_workarounds_; 203 compile_options |= driver_bug_workarounds_;
203 204
204 return compile_options; 205 return compile_options;
205 } 206 }
206 207
207 bool ShaderTranslator::Translate(const std::string& shader_source, 208 bool ShaderTranslator::Translate(const std::string& shader_source,
208 std::string* info_log, 209 std::string* info_log,
209 std::string* translated_source, 210 std::string* translated_source,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 destruction_observers_, 276 destruction_observers_,
276 OnDestruct(this)); 277 OnDestruct(this));
277 278
278 if (compiler_ != NULL) 279 if (compiler_ != NULL)
279 ShDestruct(compiler_); 280 ShDestruct(compiler_);
280 } 281 }
281 282
282 } // namespace gles2 283 } // namespace gles2
283 } // namespace gpu 284 } // namespace gpu
284 285
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_translator.h ('k') | gpu/command_buffer/service/shader_translator_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698