diff options
author | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:28:04 +0000 |
---|---|---|
committer | backer@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:28:04 +0000 |
commit | 87fb6ab83f9ec419bfc820c375da244353b39f77 (patch) | |
tree | 801eaef2cea32267f9c4ed09c922d8144ba5c88d /gpu | |
parent | 8d98f03466b775772739b89192e502c5dcf994ee (diff) | |
download | chromium_src-87fb6ab83f9ec419bfc820c375da244353b39f77.zip chromium_src-87fb6ab83f9ec419bfc820c375da244353b39f77.tar.gz chromium_src-87fb6ab83f9ec419bfc820c375da244353b39f77.tar.bz2 |
Cache shader translators.
Each shader translator takes about 700 KB of memory in the GPU proces in Release. There are typically between 2-4 of these per tab with --force-compositing-mode. This CL introduces a cache, so that tabs share shader translators whenever possible.
BUG=132426
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10535128
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 24 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator.cc | 21 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator.h | 24 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator_cache.cc | 62 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator_cache.h | 95 | ||||
-rw-r--r-- | gpu/command_buffer/service/shader_translator_unittest.cc | 121 | ||||
-rw-r--r-- | gpu/command_buffer_service.gypi | 2 |
7 files changed, 279 insertions, 70 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index e53f1ee1..3182df8 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -43,6 +43,7 @@ #include "gpu/command_buffer/service/renderbuffer_manager.h" #include "gpu/command_buffer/service/shader_manager.h" #include "gpu/command_buffer/service/shader_translator.h" +#include "gpu/command_buffer/service/shader_translator_cache.h" #include "gpu/command_buffer/service/stream_texture.h" #include "gpu/command_buffer/service/stream_texture_manager.h" #include "gpu/command_buffer/service/texture_definition.h" @@ -1511,8 +1512,8 @@ class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, error::Error current_decoder_error_; bool use_shader_translator_; - scoped_ptr<ShaderTranslator> vertex_translator_; - scoped_ptr<ShaderTranslator> fragment_translator_; + scoped_refptr<ShaderTranslator> vertex_translator_; + scoped_refptr<ShaderTranslator> fragment_translator_; DisallowedFeatures disallowed_features_; @@ -2308,7 +2309,6 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() { feature_info_->feature_flags().arb_texture_rectangle ? 1 : 0; } - vertex_translator_.reset(new ShaderTranslator); ShShaderSpec shader_spec = force_webgl_glsl_validation_ || feature_info_->feature_flags().chromium_webglsl ? SH_WEBGL_SPEC : SH_GLES2_SPEC; @@ -2319,17 +2319,21 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() { needs_glsl_built_in_function_emulation_ ? ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; - if (!vertex_translator_->Init( - SH_VERTEX_SHADER, shader_spec, &resources, - implementation_type, function_behavior)) { + + ShaderTranslatorCache* cache = ShaderTranslatorCache::GetInstance(); + vertex_translator_ = cache->GetTranslator( + SH_VERTEX_SHADER, shader_spec, &resources, + implementation_type, function_behavior); + if (!vertex_translator_.get()) { LOG(ERROR) << "Could not initialize vertex shader translator."; Destroy(true); return false; } - fragment_translator_.reset(new ShaderTranslator); - if (!fragment_translator_->Init( - SH_FRAGMENT_SHADER, shader_spec, &resources, - implementation_type, function_behavior)) { + + fragment_translator_ = cache->GetTranslator( + SH_FRAGMENT_SHADER, shader_spec, &resources, + implementation_type, function_behavior); + if (!fragment_translator_.get()) { LOG(ERROR) << "Could not initialize fragment shader translator."; Destroy(true); return false; diff --git a/gpu/command_buffer/service/shader_translator.cc b/gpu/command_buffer/service/shader_translator.cc index 63f1457..6839736 100644 --- a/gpu/command_buffer/service/shader_translator.cc +++ b/gpu/command_buffer/service/shader_translator.cc @@ -5,6 +5,7 @@ #include "gpu/command_buffer/service/shader_translator.h" #include <string.h> +#include <algorithm> #include "base/at_exit.h" #include "base/logging.h" @@ -76,6 +77,12 @@ void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type, namespace gpu { namespace gles2 { +ShaderTranslator::DestructionObserver::DestructionObserver() { +} + +ShaderTranslator::DestructionObserver::~DestructionObserver() { +} + ShaderTranslator::ShaderTranslator() : compiler_(NULL), implementation_is_glsl_es_(false), @@ -83,6 +90,10 @@ ShaderTranslator::ShaderTranslator() } ShaderTranslator::~ShaderTranslator() { + FOR_EACH_OBSERVER(DestructionObserver, + destruction_observers_, + OnDestruct(this)); + if (compiler_ != NULL) ShDestruct(compiler_); } @@ -170,6 +181,16 @@ ShaderTranslator::uniform_map() const { return uniform_map_; } +void ShaderTranslator::AddDestructionObserver( + DestructionObserver* observer) { + destruction_observers_.AddObserver(observer); +} + +void ShaderTranslator::RemoveDestructionObserver( + DestructionObserver* observer) { + destruction_observers_.RemoveObserver(observer); +} + void ShaderTranslator::ClearResults() { translated_shader_.reset(); info_log_.reset(); diff --git a/gpu/command_buffer/service/shader_translator.h b/gpu/command_buffer/service/shader_translator.h index ea981c6..9173740 100644 --- a/gpu/command_buffer/service/shader_translator.h +++ b/gpu/command_buffer/service/shader_translator.h @@ -9,7 +9,9 @@ #include "base/basictypes.h" #include "base/hash_tables.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/observer_list.h" #include "gpu/gpu_export.h" #include "third_party/angle/include/GLSLANG/ShaderLang.h" @@ -74,10 +76,20 @@ class ShaderTranslatorInterface { // Implementation of ShaderTranslatorInterface class GPU_EXPORT ShaderTranslator - : NON_EXPORTED_BASE(public ShaderTranslatorInterface) { + : public base::RefCounted<ShaderTranslator>, + NON_EXPORTED_BASE(public ShaderTranslatorInterface) { public: + class DestructionObserver { + public: + DestructionObserver(); + virtual ~DestructionObserver(); + + virtual void OnDestruct(ShaderTranslator* translator) = 0; + private: + DISALLOW_COPY_AND_ASSIGN(DestructionObserver); + }; + ShaderTranslator(); - virtual ~ShaderTranslator(); // Overridden from ShaderTranslatorInterface. virtual bool Init( @@ -98,7 +110,12 @@ class GPU_EXPORT ShaderTranslator virtual const VariableMap& attrib_map() const OVERRIDE; virtual const VariableMap& uniform_map() const OVERRIDE; + void AddDestructionObserver(DestructionObserver* observer); + void RemoveDestructionObserver(DestructionObserver* observer); + private: + virtual ~ShaderTranslator(); + void ClearResults(); ShHandle compiler_; @@ -108,6 +125,9 @@ class GPU_EXPORT ShaderTranslator VariableMap uniform_map_; bool implementation_is_glsl_es_; bool needs_built_in_function_emulation_; + ObserverList<DestructionObserver> destruction_observers_; + + friend class base::RefCounted<ShaderTranslator>; DISALLOW_COPY_AND_ASSIGN(ShaderTranslator); }; diff --git a/gpu/command_buffer/service/shader_translator_cache.cc b/gpu/command_buffer/service/shader_translator_cache.cc new file mode 100644 index 0000000..6e888d5 --- /dev/null +++ b/gpu/command_buffer/service/shader_translator_cache.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gpu/command_buffer/service/shader_translator_cache.h" + +namespace gpu { +namespace gles2 { + +ShaderTranslatorCache* ShaderTranslatorCache::GetInstance() { + return Singleton<ShaderTranslatorCache>::get(); +} + +ShaderTranslatorCache::ShaderTranslatorCache() { +} + +ShaderTranslatorCache::~ShaderTranslatorCache() { +} + +void ShaderTranslatorCache::OnDestruct(ShaderTranslator* translator) { + Cache::iterator it = cache_.begin(); + while (it != cache_.end()) { + if (it->second == translator) { + cache_.erase(it); + return; + } + it++; + } +} + +scoped_refptr<ShaderTranslator> ShaderTranslatorCache::GetTranslator( + ShShaderType shader_type, + ShShaderSpec shader_spec, + const ShBuiltInResources* resources, + ShaderTranslatorInterface::GlslImplementationType + glsl_implementation_type, + ShaderTranslatorInterface::GlslBuiltInFunctionBehavior + glsl_built_in_function_behavior) { + ShaderTranslatorInitParams params(shader_type, + shader_spec, + *resources, + glsl_implementation_type, + glsl_built_in_function_behavior); + + Cache::iterator it = cache_.find(params); + if (it != cache_.end()) + return it->second; + + ShaderTranslator* translator = new ShaderTranslator(); + if (translator->Init(shader_type, shader_spec, resources, + glsl_implementation_type, + glsl_built_in_function_behavior)) { + cache_[params] = translator; + translator->AddDestructionObserver(this); + return translator; + } else { + return NULL; + } +} + +} // namespace gles2 +} // namespace gpu diff --git a/gpu/command_buffer/service/shader_translator_cache.h b/gpu/command_buffer/service/shader_translator_cache.h new file mode 100644 index 0000000..1fbf98d --- /dev/null +++ b/gpu/command_buffer/service/shader_translator_cache.h @@ -0,0 +1,95 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ +#define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ + +#include <string.h> + +#include <map> + +#include "base/memory/ref_counted.h" +#include "base/memory/singleton.h" +#include "gpu/command_buffer/service/shader_translator.h" +#include "third_party/angle/include/GLSLANG/ShaderLang.h" + +namespace gpu { +namespace gles2 { + +// This singleton and the cache that it implements is NOT thread safe. +// We're relying on the fact that the all GLES2DecoderImpl's are used +// on one thread. +// +// TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to +// to this cache. +class ShaderTranslatorCache : public ShaderTranslator::DestructionObserver { + public: + static ShaderTranslatorCache* GetInstance(); + + // ShaderTranslator::DestructionObserver implementation + virtual void OnDestruct(ShaderTranslator* translator) OVERRIDE; + + scoped_refptr<ShaderTranslator> GetTranslator( + ShShaderType shader_type, + ShShaderSpec shader_spec, + const ShBuiltInResources* resources, + ShaderTranslatorInterface::GlslImplementationType + glsl_implementation_type, + ShaderTranslatorInterface::GlslBuiltInFunctionBehavior + glsl_built_in_function_behavior); + + private: + ShaderTranslatorCache(); + virtual ~ShaderTranslatorCache(); + + friend struct DefaultSingletonTraits<ShaderTranslatorCache>; + + // Parameters passed into ShaderTranslator::Init + struct ShaderTranslatorInitParams { + ShShaderType shader_type; + ShShaderSpec shader_spec; + ShBuiltInResources resources; + ShaderTranslatorInterface::GlslImplementationType + glsl_implementation_type; + ShaderTranslatorInterface::GlslBuiltInFunctionBehavior + glsl_built_in_function_behavior; + + ShaderTranslatorInitParams( + ShShaderType shader_type, + ShShaderSpec shader_spec, + const ShBuiltInResources& resources, + ShaderTranslatorInterface::GlslImplementationType + glsl_implementation_type, + ShaderTranslatorInterface::GlslBuiltInFunctionBehavior + glsl_built_in_function_behavior) + : shader_type(shader_type), + shader_spec(shader_spec), + resources(resources), + glsl_implementation_type(glsl_implementation_type), + glsl_built_in_function_behavior(glsl_built_in_function_behavior) { + } + + ShaderTranslatorInitParams(const ShaderTranslatorInitParams& params) { + memcpy(this, ¶ms, sizeof(*this)); + } + + bool operator== (const ShaderTranslatorInitParams& params) const { + return memcmp(¶ms, this, sizeof(*this)) == 0; + } + + bool operator< (const ShaderTranslatorInitParams& params) const { + return memcmp(¶ms, this, sizeof(*this)) < 0; + } + }; + + typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache; + Cache cache_; + + DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache); +}; + +} // namespace gles2 +} // namespace gpu + +#endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_ diff --git a/gpu/command_buffer/service/shader_translator_unittest.cc b/gpu/command_buffer/service/shader_translator_unittest.cc index 9718cf4..3f8d172 100644 --- a/gpu/command_buffer/service/shader_translator_unittest.cc +++ b/gpu/command_buffer/service/shader_translator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -20,31 +20,36 @@ class ShaderTranslatorTest : public testing::Test { virtual void SetUp() { ShBuiltInResources resources; ShInitBuiltInResources(&resources); + vertex_translator_ = new ShaderTranslator(); + fragment_translator_ = new ShaderTranslator(); - ASSERT_TRUE(vertex_translator_.Init( + ASSERT_TRUE(vertex_translator_->Init( SH_VERTEX_SHADER, SH_GLES2_SPEC, &resources, ShaderTranslatorInterface::kGlsl, ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated)); - ASSERT_TRUE(fragment_translator_.Init( + ASSERT_TRUE(fragment_translator_->Init( SH_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources, ShaderTranslatorInterface::kGlsl, ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal)); // Post-init the results must be empty. // Vertex translator results. - EXPECT_TRUE(vertex_translator_.translated_shader() == NULL); - EXPECT_TRUE(vertex_translator_.info_log() == NULL); - EXPECT_TRUE(vertex_translator_.attrib_map().empty()); - EXPECT_TRUE(vertex_translator_.uniform_map().empty()); + EXPECT_TRUE(vertex_translator_->translated_shader() == NULL); + EXPECT_TRUE(vertex_translator_->info_log() == NULL); + EXPECT_TRUE(vertex_translator_->attrib_map().empty()); + EXPECT_TRUE(vertex_translator_->uniform_map().empty()); // Fragment translator results. - EXPECT_TRUE(fragment_translator_.translated_shader() == NULL); - EXPECT_TRUE(fragment_translator_.info_log() == NULL); - EXPECT_TRUE(fragment_translator_.attrib_map().empty()); - EXPECT_TRUE(fragment_translator_.uniform_map().empty()); + EXPECT_TRUE(fragment_translator_->translated_shader() == NULL); + EXPECT_TRUE(fragment_translator_->info_log() == NULL); + EXPECT_TRUE(fragment_translator_->attrib_map().empty()); + EXPECT_TRUE(fragment_translator_->uniform_map().empty()); + } + virtual void TearDown() { + vertex_translator_ = NULL; + fragment_translator_ = NULL; } - virtual void TearDown() {} - ShaderTranslator vertex_translator_; - ShaderTranslator fragment_translator_; + scoped_refptr<ShaderTranslator> vertex_translator_; + scoped_refptr<ShaderTranslator> fragment_translator_; }; TEST_F(ShaderTranslatorTest, ValidVertexShader) { @@ -54,15 +59,15 @@ TEST_F(ShaderTranslatorTest, ValidVertexShader) { "}"; // A valid shader should be successfully translated. - EXPECT_TRUE(vertex_translator_.Translate(shader)); + EXPECT_TRUE(vertex_translator_->Translate(shader)); // Info log must be NULL. - EXPECT_TRUE(vertex_translator_.info_log() == NULL); + EXPECT_TRUE(vertex_translator_->info_log() == NULL); // Translated shader must be valid and non-empty. - EXPECT_TRUE(vertex_translator_.translated_shader() != NULL); - EXPECT_GT(strlen(vertex_translator_.translated_shader()), 0u); + EXPECT_TRUE(vertex_translator_->translated_shader() != NULL); + EXPECT_GT(strlen(vertex_translator_->translated_shader()), 0u); // There should be no attributes or uniforms. - EXPECT_TRUE(vertex_translator_.attrib_map().empty()); - EXPECT_TRUE(vertex_translator_.uniform_map().empty()); + EXPECT_TRUE(vertex_translator_->attrib_map().empty()); + EXPECT_TRUE(vertex_translator_->uniform_map().empty()); } TEST_F(ShaderTranslatorTest, InvalidVertexShader) { @@ -73,21 +78,21 @@ TEST_F(ShaderTranslatorTest, InvalidVertexShader) { "}"; // An invalid shader should fail. - EXPECT_FALSE(vertex_translator_.Translate(bad_shader)); + EXPECT_FALSE(vertex_translator_->Translate(bad_shader)); // Info log must be valid and non-empty. - EXPECT_TRUE(vertex_translator_.info_log() != NULL); - EXPECT_GT(strlen(vertex_translator_.info_log()), 0u); + EXPECT_TRUE(vertex_translator_->info_log() != NULL); + EXPECT_GT(strlen(vertex_translator_->info_log()), 0u); // Translated shader must be NULL. - EXPECT_TRUE(vertex_translator_.translated_shader() == NULL); + EXPECT_TRUE(vertex_translator_->translated_shader() == NULL); // There should be no attributes or uniforms. - EXPECT_TRUE(vertex_translator_.attrib_map().empty()); - EXPECT_TRUE(vertex_translator_.uniform_map().empty()); + EXPECT_TRUE(vertex_translator_->attrib_map().empty()); + EXPECT_TRUE(vertex_translator_->uniform_map().empty()); // Try a good shader after bad. - EXPECT_TRUE(vertex_translator_.Translate(good_shader)); - EXPECT_TRUE(vertex_translator_.info_log() == NULL); - EXPECT_TRUE(vertex_translator_.translated_shader() != NULL); - EXPECT_GT(strlen(vertex_translator_.translated_shader()), 0u); + EXPECT_TRUE(vertex_translator_->Translate(good_shader)); + EXPECT_TRUE(vertex_translator_->info_log() == NULL); + EXPECT_TRUE(vertex_translator_->translated_shader() != NULL); + EXPECT_GT(strlen(vertex_translator_->translated_shader()), 0u); } TEST_F(ShaderTranslatorTest, ValidFragmentShader) { @@ -97,30 +102,30 @@ TEST_F(ShaderTranslatorTest, ValidFragmentShader) { "}"; // A valid shader should be successfully translated. - EXPECT_TRUE(fragment_translator_.Translate(shader)); + EXPECT_TRUE(fragment_translator_->Translate(shader)); // Info log must be NULL. - EXPECT_TRUE(fragment_translator_.info_log() == NULL); + EXPECT_TRUE(fragment_translator_->info_log() == NULL); // Translated shader must be valid and non-empty. - EXPECT_TRUE(fragment_translator_.translated_shader() != NULL); - EXPECT_GT(strlen(fragment_translator_.translated_shader()), 0u); + EXPECT_TRUE(fragment_translator_->translated_shader() != NULL); + EXPECT_GT(strlen(fragment_translator_->translated_shader()), 0u); // There should be no attributes or uniforms. - EXPECT_TRUE(fragment_translator_.attrib_map().empty()); - EXPECT_TRUE(fragment_translator_.uniform_map().empty()); + EXPECT_TRUE(fragment_translator_->attrib_map().empty()); + EXPECT_TRUE(fragment_translator_->uniform_map().empty()); } TEST_F(ShaderTranslatorTest, InvalidFragmentShader) { const char* shader = "foo-bar"; // An invalid shader should fail. - EXPECT_FALSE(fragment_translator_.Translate(shader)); + EXPECT_FALSE(fragment_translator_->Translate(shader)); // Info log must be valid and non-empty. - EXPECT_TRUE(fragment_translator_.info_log() != NULL); - EXPECT_GT(strlen(fragment_translator_.info_log()), 0u); + EXPECT_TRUE(fragment_translator_->info_log() != NULL); + EXPECT_GT(strlen(fragment_translator_->info_log()), 0u); // Translated shader must be NULL. - EXPECT_TRUE(fragment_translator_.translated_shader() == NULL); + EXPECT_TRUE(fragment_translator_->translated_shader() == NULL); // There should be no attributes or uniforms. - EXPECT_TRUE(fragment_translator_.attrib_map().empty()); - EXPECT_TRUE(fragment_translator_.uniform_map().empty()); + EXPECT_TRUE(fragment_translator_->attrib_map().empty()); + EXPECT_TRUE(fragment_translator_->uniform_map().empty()); } TEST_F(ShaderTranslatorTest, GetAttributes) { @@ -130,18 +135,18 @@ TEST_F(ShaderTranslatorTest, GetAttributes) { " gl_Position = vPosition;\n" "}"; - EXPECT_TRUE(vertex_translator_.Translate(shader)); + EXPECT_TRUE(vertex_translator_->Translate(shader)); // Info log must be NULL. - EXPECT_TRUE(vertex_translator_.info_log() == NULL); + EXPECT_TRUE(vertex_translator_->info_log() == NULL); // Translated shader must be valid and non-empty. - EXPECT_TRUE(vertex_translator_.translated_shader() != NULL); - EXPECT_GT(strlen(vertex_translator_.translated_shader()), 0u); + EXPECT_TRUE(vertex_translator_->translated_shader() != NULL); + EXPECT_GT(strlen(vertex_translator_->translated_shader()), 0u); // There should be no uniforms. - EXPECT_TRUE(vertex_translator_.uniform_map().empty()); + EXPECT_TRUE(vertex_translator_->uniform_map().empty()); // There should be one attribute with following characteristics: // name:vPosition type:SH_FLOAT_VEC4 size:1. const ShaderTranslator::VariableMap& attrib_map = - vertex_translator_.attrib_map(); + vertex_translator_->attrib_map(); EXPECT_EQ(1u, attrib_map.size()); ShaderTranslator::VariableMap::const_iterator iter = attrib_map.find("vPosition"); @@ -165,19 +170,19 @@ TEST_F(ShaderTranslatorTest, GetUniforms) { " gl_FragColor = bar[0].foo.color[0] + bar[1].foo.color[0];\n" "}"; - EXPECT_TRUE(fragment_translator_.Translate(shader)); + EXPECT_TRUE(fragment_translator_->Translate(shader)); // Info log must be NULL. - EXPECT_TRUE(fragment_translator_.info_log() == NULL); + EXPECT_TRUE(fragment_translator_->info_log() == NULL); // Translated shader must be valid and non-empty. - EXPECT_TRUE(fragment_translator_.translated_shader() != NULL); - EXPECT_GT(strlen(fragment_translator_.translated_shader()), 0u); + EXPECT_TRUE(fragment_translator_->translated_shader() != NULL); + EXPECT_GT(strlen(fragment_translator_->translated_shader()), 0u); // There should be no attributes. - EXPECT_TRUE(fragment_translator_.attrib_map().empty()); + EXPECT_TRUE(fragment_translator_->attrib_map().empty()); // There should be two uniforms with following characteristics: // 1. name:bar[0].foo.color[0] type:SH_FLOAT_VEC4 size:1 // 2. name:bar[1].foo.color[0] type:SH_FLOAT_VEC4 size:1 const ShaderTranslator::VariableMap& uniform_map = - fragment_translator_.uniform_map(); + fragment_translator_->uniform_map(); EXPECT_EQ(2u, uniform_map.size()); // First uniform. ShaderTranslator::VariableMap::const_iterator iter = @@ -204,12 +209,12 @@ TEST_F(ShaderTranslatorTest, BuiltInFunctionEmulation) { " gl_Position = vec4(dot(1.0, 1.0), 1.0, 1.0, 1.0);\n" "}"; - EXPECT_TRUE(vertex_translator_.Translate(shader)); + EXPECT_TRUE(vertex_translator_->Translate(shader)); // Info log must be NULL. - EXPECT_TRUE(vertex_translator_.info_log() == NULL); + EXPECT_TRUE(vertex_translator_->info_log() == NULL); // Translated shader must be valid and non-empty. - EXPECT_TRUE(vertex_translator_.translated_shader() != NULL); - EXPECT_TRUE(strstr(vertex_translator_.translated_shader(), + EXPECT_TRUE(vertex_translator_->translated_shader() != NULL); + EXPECT_TRUE(strstr(vertex_translator_->translated_shader(), "webgl_dot_emu") != NULL); } #endif diff --git a/gpu/command_buffer_service.gypi b/gpu/command_buffer_service.gypi index 02bfaf6..4fbd06f 100644 --- a/gpu/command_buffer_service.gypi +++ b/gpu/command_buffer_service.gypi @@ -68,6 +68,8 @@ 'command_buffer/service/shader_manager.cc', 'command_buffer/service/shader_translator.h', 'command_buffer/service/shader_translator.cc', + 'command_buffer/service/shader_translator_cache.h', + 'command_buffer/service/shader_translator_cache.cc', 'command_buffer/service/stream_texture.h', 'command_buffer/service/stream_texture_manager.h', 'command_buffer/service/texture_definition.cc', |