diff options
author | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 01:58:44 +0000 |
---|---|---|
committer | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-11 01:58:44 +0000 |
commit | f1f4dd5f454c1ea1c4e942ea8387a92455d49218 (patch) | |
tree | 19b0795463fca17856ab412aae0cefa9d1da1457 /gpu | |
parent | f386bb5b7433903e3e105c7725906366f4a85559 (diff) | |
download | chromium_src-f1f4dd5f454c1ea1c4e942ea8387a92455d49218.zip chromium_src-f1f4dd5f454c1ea1c4e942ea8387a92455d49218.tar.gz chromium_src-f1f4dd5f454c1ea1c4e942ea8387a92455d49218.tar.bz2 |
Send shader information to disk cache on access as well as create.
Currently we send the shader information to the disk cache when the
shader is first saved. This patch also sends the shaders when we
read them from the memory cache. This allows us to use the
LRU capabilities of the shader cache and re-cache any shaders
if the disk cache has been cleared.
BUG=226998
Review URL: https://chromiumcodereview.appspot.com/13722006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193538 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/memory_program_cache.cc | 55 | ||||
-rw-r--r-- | gpu/command_buffer/service/memory_program_cache.h | 3 | ||||
-rw-r--r-- | gpu/command_buffer/service/memory_program_cache_unittest.cc | 36 | ||||
-rw-r--r-- | gpu/command_buffer/service/mocks.h | 5 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_cache.h | 3 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_cache_unittest.cc | 3 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_manager.cc | 3 | ||||
-rw-r--r-- | gpu/command_buffer/service/program_manager_unittest.cc | 3 |
8 files changed, 77 insertions, 34 deletions
diff --git a/gpu/command_buffer/service/memory_program_cache.cc b/gpu/command_buffer/service/memory_program_cache.cc index f90a8cf..726c60d 100644 --- a/gpu/command_buffer/service/memory_program_cache.cc +++ b/gpu/command_buffer/service/memory_program_cache.cc @@ -68,6 +68,24 @@ void RetrieveShaderInfo(const ShaderInfoProto& proto, (*map)[proto.key()] = info; } +void FillShaderProto(ShaderProto* proto, const char* sha, + const Shader* shader) { + proto->set_sha(sha, gpu::gles2::ProgramCache::kHashLength); + StoreShaderInfo(ATTRIB_MAP, proto, shader->attrib_map()); + StoreShaderInfo(UNIFORM_MAP, proto, shader->uniform_map()); +} + +void RunShaderCallback(const ShaderCacheCallback& callback, + GpuProgramProto* proto, + std::string sha_string) { + std::string shader; + proto->SerializeToString(&shader); + + std::string key; + base::Base64Encode(sha_string, &key); + callback.Run(key, shader); +} + } // namespace MemoryProgramCache::MemoryProgramCache() @@ -90,7 +108,8 @@ ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( GLuint program, Shader* shader_a, Shader* shader_b, - const LocationMap* bind_attrib_location_map) const { + const LocationMap* bind_attrib_location_map, + const ShaderCacheCallback& shader_callback) const { char a_sha[kHashLength]; char b_sha[kHashLength]; ComputeShaderHash(*shader_a->deferred_compilation_source(), a_sha); @@ -121,6 +140,20 @@ ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( shader_a->set_uniform_map(value->uniform_map_0); shader_b->set_attrib_map(value->attrib_map_1); shader_b->set_uniform_map(value->uniform_map_1); + + if (!shader_callback.is_null() && + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableGpuShaderDiskCache)) { + GpuProgramProto* proto = GpuProgramProto::default_instance().New(); + proto->set_sha(sha, kHashLength); + proto->set_format(value->format); + proto->set_program(value->data.get(), value->length); + + FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); + FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); + RunShaderCallback(shader_callback, proto, sha_string); + } + return PROGRAM_LOAD_SUCCESS; } @@ -181,28 +214,14 @@ void MemoryProgramCache::SaveLinkedProgram( if (!shader_callback.is_null() && CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableGpuShaderDiskCache)) { - std::string key; - base::Base64Encode(sha_string, &key); - GpuProgramProto* proto = GpuProgramProto::default_instance().New(); proto->set_sha(sha, kHashLength); proto->set_format(format); proto->set_program(binary.get(), length); - ShaderProto* vertex_shader = proto->mutable_vertex_shader(); - vertex_shader->set_sha(a_sha, kHashLength); - StoreShaderInfo(ATTRIB_MAP, vertex_shader, shader_a->attrib_map()); - StoreShaderInfo(UNIFORM_MAP, vertex_shader, shader_a->uniform_map()); - - ShaderProto* fragment_shader = proto->mutable_fragment_shader(); - fragment_shader->set_sha(b_sha, kHashLength); - StoreShaderInfo(ATTRIB_MAP, fragment_shader, shader_b->attrib_map()); - StoreShaderInfo(UNIFORM_MAP, fragment_shader, shader_b->uniform_map()); - - std::string shader; - proto->SerializeToString(&shader); - - shader_callback.Run(key, shader); + FillShaderProto(proto->mutable_vertex_shader(), a_sha, shader_a); + FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); + RunShaderCallback(shader_callback, proto, sha_string); } store_[sha_string] = new ProgramCacheValue(length, diff --git a/gpu/command_buffer/service/memory_program_cache.h b/gpu/command_buffer/service/memory_program_cache.h index 19d3798..7d5f808 100644 --- a/gpu/command_buffer/service/memory_program_cache.h +++ b/gpu/command_buffer/service/memory_program_cache.h @@ -30,7 +30,8 @@ class GPU_EXPORT MemoryProgramCache : public ProgramCache { GLuint program, Shader* shader_a, Shader* shader_b, - const LocationMap* bind_attrib_location_map) const OVERRIDE; + const LocationMap* bind_attrib_location_map, + const ShaderCacheCallback& shader_callback) const OVERRIDE; virtual void SaveLinkedProgram( GLuint program, const Shader* shader_a, diff --git a/gpu/command_buffer/service/memory_program_cache_unittest.cc b/gpu/command_buffer/service/memory_program_cache_unittest.cc index 7751ad3..a1d07fc 100644 --- a/gpu/command_buffer/service/memory_program_cache_unittest.cc +++ b/gpu/command_buffer/service/memory_program_cache_unittest.cc @@ -237,7 +237,9 @@ TEST_F(MemoryProgramCacheTest, CacheLoadMatchesSave) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); // apparently the hash_map implementation on android doesn't have the // equality operator @@ -280,7 +282,9 @@ TEST_F(MemoryProgramCacheTest, LoadProgramMatchesSave) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); // apparently the hash_map implementation on android doesn't have the // equality operator @@ -312,7 +316,9 @@ TEST_F(MemoryProgramCacheTest, LoadFailOnLinkFalse) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); } TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentSource) { @@ -338,7 +344,9 @@ TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentSource) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); vertex_shader_->UpdateSource(vertex_orig_source.c_str()); vertex_shader_->FlagSourceAsCompiled(true); @@ -348,7 +356,9 @@ TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentSource) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); } TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentMap) { @@ -376,12 +386,16 @@ TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentMap) { kProgramId, vertex_shader_, fragment_shader_, - &binding_map)); + &binding_map, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram( kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); } TEST_F(MemoryProgramCacheTest, MemoryProgramCacheEviction) { @@ -486,7 +500,9 @@ TEST_F(MemoryProgramCacheTest, LoadCorrectProgram) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); } TEST_F(MemoryProgramCacheTest, OverwriteOnNewSave) { @@ -520,7 +536,9 @@ TEST_F(MemoryProgramCacheTest, OverwriteOnNewSave) { kProgramId, vertex_shader_, fragment_shader_, - NULL)); + NULL, + base::Bind(&MemoryProgramCacheTest::ShaderCacheCb, + base::Unretained(this)))); } } // namespace gles2 diff --git a/gpu/command_buffer/service/mocks.h b/gpu/command_buffer/service/mocks.h index 949314d..0964ada 100644 --- a/gpu/command_buffer/service/mocks.h +++ b/gpu/command_buffer/service/mocks.h @@ -98,11 +98,12 @@ class MockProgramCache : public ProgramCache { MockProgramCache(); virtual ~MockProgramCache(); - MOCK_CONST_METHOD4(LoadLinkedProgram, ProgramLoadResult( + MOCK_CONST_METHOD5(LoadLinkedProgram, ProgramLoadResult( GLuint program, Shader* shader_a, Shader* shader_b, - const LocationMap* bind_attrib_location_map)); + const LocationMap* bind_attrib_location_map, + const ShaderCacheCallback& callback)); MOCK_METHOD5(SaveLinkedProgram, void( GLuint program, diff --git a/gpu/command_buffer/service/program_cache.h b/gpu/command_buffer/service/program_cache.h index e7057e5..c4b50e8 100644 --- a/gpu/command_buffer/service/program_cache.h +++ b/gpu/command_buffer/service/program_cache.h @@ -60,7 +60,8 @@ class GPU_EXPORT ProgramCache { GLuint program, Shader* shader_a, Shader* shader_b, - const LocationMap* bind_attrib_location_map) const = 0; + const LocationMap* bind_attrib_location_map, + const ShaderCacheCallback& shader_callback) const = 0; // Saves the program into the cache. If successful, the implementation should // call LinkedProgramCacheSuccess. diff --git a/gpu/command_buffer/service/program_cache_unittest.cc b/gpu/command_buffer/service/program_cache_unittest.cc index 65f39be..46a2fe1 100644 --- a/gpu/command_buffer/service/program_cache_unittest.cc +++ b/gpu/command_buffer/service/program_cache_unittest.cc @@ -16,7 +16,8 @@ class NoBackendProgramCache : public ProgramCache { GLuint /* program */, Shader* /* shader_a */, Shader* /* shader_b */, - const LocationMap* /* bind_attrib_location_map */) const OVERRIDE { + const LocationMap* /* bind_attrib_location_map */, + const ShaderCacheCallback& /* callback */) const OVERRIDE { return PROGRAM_LOAD_SUCCESS; } virtual void SaveLinkedProgram( diff --git a/gpu/command_buffer/service/program_manager.cc b/gpu/command_buffer/service/program_manager.cc index 5c31f14..a692712 100644 --- a/gpu/command_buffer/service/program_manager.cc +++ b/gpu/command_buffer/service/program_manager.cc @@ -561,7 +561,8 @@ bool Program::Link(ShaderManager* manager, service_id(), attached_shaders_[0], attached_shaders_[1], - &bind_attrib_location_map_); + &bind_attrib_location_map_, + shader_callback); link = success != ProgramCache::PROGRAM_LOAD_SUCCESS; UMA_HISTOGRAM_BOOLEAN("GPU.ProgramCache.LoadBinarySuccess", !link); } diff --git a/gpu/command_buffer/service/program_manager_unittest.cc b/gpu/command_buffer/service/program_manager_unittest.cc index 94bce93..8770e93 100644 --- a/gpu/command_buffer/service/program_manager_unittest.cc +++ b/gpu/command_buffer/service/program_manager_unittest.cc @@ -1267,7 +1267,8 @@ class ProgramManagerWithCacheTest : public testing::Test { LoadLinkedProgram(service_program_id, vertex_shader, fragment_shader, - &program->bind_attrib_location_map())) + &program->bind_attrib_location_map(), + _)) .WillOnce(Return(result)); } |