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

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

Issue 1013463003: Update from https://crrev.com/320931 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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/memory_program_cache.h" 5 #include "gpu/command_buffer/service/memory_program_cache.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void MemoryProgramCache::ClearBackend() { 167 void MemoryProgramCache::ClearBackend() {
168 store_.Clear(); 168 store_.Clear();
169 DCHECK_EQ(0U, curr_size_bytes_); 169 DCHECK_EQ(0U, curr_size_bytes_);
170 } 170 }
171 171
172 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( 172 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram(
173 GLuint program, 173 GLuint program,
174 Shader* shader_a, 174 Shader* shader_a,
175 Shader* shader_b, 175 Shader* shader_b,
176 const LocationMap* bind_attrib_location_map, 176 const LocationMap* bind_attrib_location_map,
177 const std::vector<std::string>& transform_feedback_varyings,
178 GLenum transform_feedback_buffer_mode,
177 const ShaderCacheCallback& shader_callback) { 179 const ShaderCacheCallback& shader_callback) {
178 char a_sha[kHashLength]; 180 char a_sha[kHashLength];
179 char b_sha[kHashLength]; 181 char b_sha[kHashLength];
180 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && 182 DCHECK(shader_a && !shader_a->last_compiled_source().empty() &&
181 shader_b && !shader_b->last_compiled_source().empty()); 183 shader_b && !shader_b->last_compiled_source().empty());
182 ComputeShaderHash( 184 ComputeShaderHash(
183 shader_a->last_compiled_signature(), a_sha); 185 shader_a->last_compiled_signature(), a_sha);
184 ComputeShaderHash( 186 ComputeShaderHash(
185 shader_b->last_compiled_signature(), b_sha); 187 shader_b->last_compiled_signature(), b_sha);
186 188
187 char sha[kHashLength]; 189 char sha[kHashLength];
188 ComputeProgramHash(a_sha, 190 ComputeProgramHash(a_sha,
189 b_sha, 191 b_sha,
190 bind_attrib_location_map, 192 bind_attrib_location_map,
193 transform_feedback_varyings,
194 transform_feedback_buffer_mode,
191 sha); 195 sha);
192 const std::string sha_string(sha, kHashLength); 196 const std::string sha_string(sha, kHashLength);
193 197
194 ProgramMRUCache::iterator found = store_.Get(sha_string); 198 ProgramMRUCache::iterator found = store_.Get(sha_string);
195 if (found == store_.end()) { 199 if (found == store_.end()) {
196 return PROGRAM_LOAD_FAILURE; 200 return PROGRAM_LOAD_FAILURE;
197 } 201 }
198 const scoped_refptr<ProgramCacheValue> value = found->second; 202 const scoped_refptr<ProgramCacheValue> value = found->second;
199 glProgramBinary(program, 203 glProgramBinary(program,
200 value->format(), 204 value->format(),
(...skipping 26 matching lines...) Expand all
227 } 231 }
228 232
229 return PROGRAM_LOAD_SUCCESS; 233 return PROGRAM_LOAD_SUCCESS;
230 } 234 }
231 235
232 void MemoryProgramCache::SaveLinkedProgram( 236 void MemoryProgramCache::SaveLinkedProgram(
233 GLuint program, 237 GLuint program,
234 const Shader* shader_a, 238 const Shader* shader_a,
235 const Shader* shader_b, 239 const Shader* shader_b,
236 const LocationMap* bind_attrib_location_map, 240 const LocationMap* bind_attrib_location_map,
241 const std::vector<std::string>& transform_feedback_varyings,
242 GLenum transform_feedback_buffer_mode,
237 const ShaderCacheCallback& shader_callback) { 243 const ShaderCacheCallback& shader_callback) {
238 GLenum format; 244 GLenum format;
239 GLsizei length = 0; 245 GLsizei length = 0;
240 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); 246 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length);
241 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { 247 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) {
242 return; 248 return;
243 } 249 }
244 scoped_ptr<char[]> binary(new char[length]); 250 scoped_ptr<char[]> binary(new char[length]);
245 glGetProgramBinary(program, 251 glGetProgramBinary(program,
246 length, 252 length,
247 NULL, 253 NULL,
248 &format, 254 &format,
249 binary.get()); 255 binary.get());
250 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length); 256 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length);
251 257
252 char a_sha[kHashLength]; 258 char a_sha[kHashLength];
253 char b_sha[kHashLength]; 259 char b_sha[kHashLength];
254 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && 260 DCHECK(shader_a && !shader_a->last_compiled_source().empty() &&
255 shader_b && !shader_b->last_compiled_source().empty()); 261 shader_b && !shader_b->last_compiled_source().empty());
256 ComputeShaderHash( 262 ComputeShaderHash(
257 shader_a->last_compiled_signature(), a_sha); 263 shader_a->last_compiled_signature(), a_sha);
258 ComputeShaderHash( 264 ComputeShaderHash(
259 shader_b->last_compiled_signature(), b_sha); 265 shader_b->last_compiled_signature(), b_sha);
260 266
261 char sha[kHashLength]; 267 char sha[kHashLength];
262 ComputeProgramHash(a_sha, 268 ComputeProgramHash(a_sha,
263 b_sha, 269 b_sha,
264 bind_attrib_location_map, 270 bind_attrib_location_map,
271 transform_feedback_varyings,
272 transform_feedback_buffer_mode,
265 sha); 273 sha);
266 const std::string sha_string(sha, sizeof(sha)); 274 const std::string sha_string(sha, sizeof(sha));
267 275
268 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeBeforeKb", 276 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeBeforeKb",
269 curr_size_bytes_ / 1024); 277 curr_size_bytes_ / 1024);
270 278
271 // Evict any cached program with the same key in favor of the least recently 279 // Evict any cached program with the same key in favor of the least recently
272 // accessed. 280 // accessed.
273 ProgramMRUCache::iterator existing = store_.Peek(sha_string); 281 ProgramMRUCache::iterator existing = store_.Peek(sha_string);
274 if(existing != store_.end()) 282 if(existing != store_.end())
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 program_cache_->LinkedProgramCacheSuccess(program_hash); 411 program_cache_->LinkedProgramCacheSuccess(program_hash);
404 } 412 }
405 413
406 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { 414 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() {
407 program_cache_->curr_size_bytes_ -= length_; 415 program_cache_->curr_size_bytes_ -= length_;
408 program_cache_->Evict(program_hash_); 416 program_cache_->Evict(program_hash_);
409 } 417 }
410 418
411 } // namespace gles2 419 } // namespace gles2
412 } // namespace gpu 420 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/memory_program_cache.h ('k') | gpu/command_buffer/service/memory_program_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698