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

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

Issue 217813004: Make ShaderTranslatorCache thread safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 6 years, 8 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 | Annotate | Revision Log
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 <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/lazy_instance.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 15
15 namespace { 16 namespace {
16 17
17 using gpu::gles2::ShaderTranslator; 18 using gpu::gles2::ShaderTranslator;
18 19
19 bool g_translator_initialized = false; 20 class ShaderTranslatorInitializer {
20 21 public:
21 void FinalizeShaderTranslator(void* /* dummy */) { 22 ShaderTranslatorInitializer() {
22 TRACE_EVENT0("gpu", "ShFinalize");
23 ShFinalize();
24 g_translator_initialized = false;
25 }
26
27 bool InitializeShaderTranslator() {
28 if (!g_translator_initialized) {
29 TRACE_EVENT0("gpu", "ShInitialize"); 23 TRACE_EVENT0("gpu", "ShInitialize");
30 CHECK(ShInitialize()); 24 CHECK(ShInitialize());
31 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL);
32 g_translator_initialized = true;
33 } 25 }
34 return g_translator_initialized; 26
35 } 27 ~ShaderTranslatorInitializer() {
28 TRACE_EVENT0("gpu", "ShFinalize");
29 ShFinalize();
30 }
31 };
32
33 base::LazyInstance<ShaderTranslatorInitializer> g_translator_initializer =
34 LAZY_INSTANCE_INITIALIZER;
36 35
37 #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108 36 #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108
38 typedef int ANGLEGetInfoType; 37 typedef int ANGLEGetInfoType;
39 #else 38 #else
40 typedef size_t ANGLEGetInfoType; 39 typedef size_t ANGLEGetInfoType;
41 #endif 40 #endif
42 41
43 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type, 42 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type,
44 ShaderTranslator::VariableMap* var_map) { 43 ShaderTranslator::VariableMap* var_map) {
45 ANGLEGetInfoType name_len = 0, mapped_name_len = 0; 44 ANGLEGetInfoType name_len = 0, mapped_name_len = 0;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 ShShaderSpec shader_spec, 127 ShShaderSpec shader_spec,
129 const ShBuiltInResources* resources, 128 const ShBuiltInResources* resources,
130 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, 129 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type,
131 ShCompileOptions driver_bug_workarounds) { 130 ShCompileOptions driver_bug_workarounds) {
132 // Make sure Init is called only once. 131 // Make sure Init is called only once.
133 DCHECK(compiler_ == NULL); 132 DCHECK(compiler_ == NULL);
134 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER); 133 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER);
135 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC); 134 DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC);
136 DCHECK(resources != NULL); 135 DCHECK(resources != NULL);
137 136
138 if (!InitializeShaderTranslator()) 137 g_translator_initializer.Get();
139 return false;
140 138
141 ShShaderOutput shader_output = 139 ShShaderOutput shader_output =
142 (glsl_implementation_type == kGlslES ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT); 140 (glsl_implementation_type == kGlslES ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT);
143 141
144 { 142 {
145 TRACE_EVENT0("gpu", "ShConstructCompiler"); 143 TRACE_EVENT0("gpu", "ShConstructCompiler");
146 compiler_ = ShConstructCompiler( 144 compiler_ = ShConstructCompiler(
147 shader_type, shader_spec, shader_output, resources); 145 shader_type, shader_spec, shader_output, resources);
148 } 146 }
149 compiler_options_ = *resources; 147 compiler_options_ = *resources;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 info_log_.reset(); 326 info_log_.reset();
329 attrib_map_.clear(); 327 attrib_map_.clear();
330 uniform_map_.clear(); 328 uniform_map_.clear();
331 varying_map_.clear(); 329 varying_map_.clear();
332 name_map_.clear(); 330 name_map_.clear();
333 } 331 }
334 332
335 } // namespace gles2 333 } // namespace gles2
336 } // namespace gpu 334 } // namespace gpu
337 335
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/in_process_command_buffer.cc ('k') | gpu/command_buffer/service/shader_translator_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698