OLD | NEW |
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/memory_program_cache.h" | 5 #include "gpu/command_buffer/service/memory_program_cache.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 shader_b->set_attrib_map(value->attrib_map_1); | 81 shader_b->set_attrib_map(value->attrib_map_1); |
82 shader_b->set_uniform_map(value->uniform_map_1); | 82 shader_b->set_uniform_map(value->uniform_map_1); |
83 return PROGRAM_LOAD_SUCCESS; | 83 return PROGRAM_LOAD_SUCCESS; |
84 } | 84 } |
85 | 85 |
86 void MemoryProgramCache::SaveLinkedProgram( | 86 void MemoryProgramCache::SaveLinkedProgram( |
87 GLuint program, | 87 GLuint program, |
88 const ShaderManager::ShaderInfo* shader_a, | 88 const ShaderManager::ShaderInfo* shader_a, |
89 const ShaderManager::ShaderInfo* shader_b, | 89 const ShaderManager::ShaderInfo* shader_b, |
90 const LocationMap* bind_attrib_location_map) { | 90 const LocationMap* bind_attrib_location_map) { |
91 GLsizei length; | |
92 GLenum format; | 91 GLenum format; |
93 GLsizei buffer_length = 0; | 92 GLsizei length = 0; |
94 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &buffer_length); | 93 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); |
95 if (static_cast<unsigned int>(buffer_length) > max_size_bytes_) { | 94 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { |
96 return; | 95 return; |
97 } | 96 } |
98 scoped_array<char> binary(new char[buffer_length]); | 97 scoped_array<char> binary(new char[length]); |
99 glGetProgramBinary(program, | 98 glGetProgramBinary(program, |
100 buffer_length, | 99 length, |
101 &length, | 100 NULL, |
102 &format, | 101 &format, |
103 binary.get()); | 102 binary.get()); |
104 if (length == 0) { | |
105 return; | |
106 } | |
107 | 103 |
108 char a_sha[kHashLength]; | 104 char a_sha[kHashLength]; |
109 char b_sha[kHashLength]; | 105 char b_sha[kHashLength]; |
110 ComputeShaderHash(*shader_a->deferred_compilation_source(), a_sha); | 106 ComputeShaderHash(*shader_a->deferred_compilation_source(), a_sha); |
111 ComputeShaderHash(*shader_b->deferred_compilation_source(), b_sha); | 107 ComputeShaderHash(*shader_b->deferred_compilation_source(), b_sha); |
112 | 108 |
113 char sha[kHashLength]; | 109 char sha[kHashLength]; |
114 ComputeProgramHash(a_sha, | 110 ComputeProgramHash(a_sha, |
115 b_sha, | 111 b_sha, |
116 bind_attrib_location_map, | 112 bind_attrib_location_map, |
117 sha); | 113 sha); |
118 const std::string sha_string(sha, sizeof(sha)); | 114 const std::string sha_string(sha, sizeof(sha)); |
119 | 115 |
120 if (store_.find(sha_string) != store_.end()) { | 116 if (store_.find(sha_string) != store_.end()) { |
121 return; | 117 const StoreMap::iterator found = store_.find(sha_string); |
| 118 const ProgramCacheValue* evicting = found->second; |
| 119 curr_size_bytes_ -= evicting->length; |
| 120 Evict(sha_string, evicting->shader_0_hash, evicting->shader_1_hash); |
| 121 store_.erase(found); |
122 } | 122 } |
123 | 123 |
124 while (curr_size_bytes_ + length > max_size_bytes_) { | 124 while (curr_size_bytes_ + length > max_size_bytes_) { |
125 DCHECK(!eviction_helper_.IsEmpty()); | 125 DCHECK(!eviction_helper_.IsEmpty()); |
126 const std::string* program = eviction_helper_.PeekKey(); | 126 const std::string* program = eviction_helper_.PeekKey(); |
127 const StoreMap::iterator found = store_.find(*program); | 127 const StoreMap::iterator found = store_.find(*program); |
128 const ProgramCacheValue* evicting = found->second.get(); | 128 const ProgramCacheValue* evicting = found->second.get(); |
129 curr_size_bytes_ -= evicting->length; | 129 curr_size_bytes_ -= evicting->length; |
130 Evict(*program, evicting->shader_0_hash, evicting->shader_1_hash); | 130 Evict(*program, evicting->shader_0_hash, evicting->shader_1_hash); |
131 store_.erase(found); | 131 store_.erase(found); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 attrib_map_0(_attrib_map_0), | 164 attrib_map_0(_attrib_map_0), |
165 uniform_map_0(_uniform_map_0), | 165 uniform_map_0(_uniform_map_0), |
166 shader_1_hash(_shader_1_hash, kHashLength), | 166 shader_1_hash(_shader_1_hash, kHashLength), |
167 attrib_map_1(_attrib_map_1), | 167 attrib_map_1(_attrib_map_1), |
168 uniform_map_1(_uniform_map_1) {} | 168 uniform_map_1(_uniform_map_1) {} |
169 | 169 |
170 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {} | 170 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {} |
171 | 171 |
172 } // namespace gles2 | 172 } // namespace gles2 |
173 } // namespace gpu | 173 } // namespace gpu |
OLD | NEW |