| 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/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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "gpu/command_buffer/common/constants.h" | 12 #include "gpu/command_buffer/common/constants.h" |
| 13 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" | 13 #include "gpu/command_buffer/service/disk_cache_proto.pb.h" |
| 14 #include "gpu/command_buffer/service/gl_utils.h" | 14 #include "gpu/command_buffer/service/gl_utils.h" |
| 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 15 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 16 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
| 17 #include "gpu/command_buffer/service/shader_manager.h" | 17 #include "gpu/command_buffer/service/shader_manager.h" |
| 18 #include "gpu/command_buffer/service/shader_translator.h" | |
| 19 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 size_t GetCacheSizeBytes() { | 22 size_t GetCacheSizeBytes() { |
| 24 const base::CommandLine* command_line = | 23 const base::CommandLine* command_line = |
| 25 base::CommandLine::ForCurrentProcess(); | 24 base::CommandLine::ForCurrentProcess(); |
| 26 if (command_line->HasSwitch(switches::kGpuProgramCacheSizeKb)) { | 25 if (command_line->HasSwitch(switches::kGpuProgramCacheSizeKb)) { |
| 27 size_t size; | 26 size_t size; |
| 28 if (base::StringToSizeT( | 27 if (base::StringToSizeT( |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 MemoryProgramCache::~MemoryProgramCache() {} | 165 MemoryProgramCache::~MemoryProgramCache() {} |
| 167 | 166 |
| 168 void MemoryProgramCache::ClearBackend() { | 167 void MemoryProgramCache::ClearBackend() { |
| 169 store_.Clear(); | 168 store_.Clear(); |
| 170 DCHECK_EQ(0U, curr_size_bytes_); | 169 DCHECK_EQ(0U, curr_size_bytes_); |
| 171 } | 170 } |
| 172 | 171 |
| 173 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( | 172 ProgramCache::ProgramLoadResult MemoryProgramCache::LoadLinkedProgram( |
| 174 GLuint program, | 173 GLuint program, |
| 175 Shader* shader_a, | 174 Shader* shader_a, |
| 176 const ShaderTranslatorInterface* translator_a, | |
| 177 Shader* shader_b, | 175 Shader* shader_b, |
| 178 const ShaderTranslatorInterface* translator_b, | |
| 179 const LocationMap* bind_attrib_location_map, | 176 const LocationMap* bind_attrib_location_map, |
| 180 const ShaderCacheCallback& shader_callback) { | 177 const ShaderCacheCallback& shader_callback) { |
| 181 char a_sha[kHashLength]; | 178 char a_sha[kHashLength]; |
| 182 char b_sha[kHashLength]; | 179 char b_sha[kHashLength]; |
| 183 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && | 180 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && |
| 184 shader_b && !shader_b->last_compiled_source().empty()); | 181 shader_b && !shader_b->last_compiled_source().empty()); |
| 185 ComputeShaderHash( | 182 ComputeShaderHash( |
| 186 shader_a->last_compiled_source(), translator_a, a_sha); | 183 shader_a->last_compiled_signature(), a_sha); |
| 187 ComputeShaderHash( | 184 ComputeShaderHash( |
| 188 shader_b->last_compiled_source(), translator_b, b_sha); | 185 shader_b->last_compiled_signature(), b_sha); |
| 189 | 186 |
| 190 char sha[kHashLength]; | 187 char sha[kHashLength]; |
| 191 ComputeProgramHash(a_sha, | 188 ComputeProgramHash(a_sha, |
| 192 b_sha, | 189 b_sha, |
| 193 bind_attrib_location_map, | 190 bind_attrib_location_map, |
| 194 sha); | 191 sha); |
| 195 const std::string sha_string(sha, kHashLength); | 192 const std::string sha_string(sha, kHashLength); |
| 196 | 193 |
| 197 ProgramMRUCache::iterator found = store_.Get(sha_string); | 194 ProgramMRUCache::iterator found = store_.Get(sha_string); |
| 198 if (found == store_.end()) { | 195 if (found == store_.end()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 228 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); | 225 FillShaderProto(proto->mutable_fragment_shader(), b_sha, shader_b); |
| 229 RunShaderCallback(shader_callback, proto.get(), sha_string); | 226 RunShaderCallback(shader_callback, proto.get(), sha_string); |
| 230 } | 227 } |
| 231 | 228 |
| 232 return PROGRAM_LOAD_SUCCESS; | 229 return PROGRAM_LOAD_SUCCESS; |
| 233 } | 230 } |
| 234 | 231 |
| 235 void MemoryProgramCache::SaveLinkedProgram( | 232 void MemoryProgramCache::SaveLinkedProgram( |
| 236 GLuint program, | 233 GLuint program, |
| 237 const Shader* shader_a, | 234 const Shader* shader_a, |
| 238 const ShaderTranslatorInterface* translator_a, | |
| 239 const Shader* shader_b, | 235 const Shader* shader_b, |
| 240 const ShaderTranslatorInterface* translator_b, | |
| 241 const LocationMap* bind_attrib_location_map, | 236 const LocationMap* bind_attrib_location_map, |
| 242 const ShaderCacheCallback& shader_callback) { | 237 const ShaderCacheCallback& shader_callback) { |
| 243 GLenum format; | 238 GLenum format; |
| 244 GLsizei length = 0; | 239 GLsizei length = 0; |
| 245 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); | 240 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH_OES, &length); |
| 246 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { | 241 if (length == 0 || static_cast<unsigned int>(length) > max_size_bytes_) { |
| 247 return; | 242 return; |
| 248 } | 243 } |
| 249 scoped_ptr<char[]> binary(new char[length]); | 244 scoped_ptr<char[]> binary(new char[length]); |
| 250 glGetProgramBinary(program, | 245 glGetProgramBinary(program, |
| 251 length, | 246 length, |
| 252 NULL, | 247 NULL, |
| 253 &format, | 248 &format, |
| 254 binary.get()); | 249 binary.get()); |
| 255 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length); | 250 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.ProgramBinarySizeBytes", length); |
| 256 | 251 |
| 257 char a_sha[kHashLength]; | 252 char a_sha[kHashLength]; |
| 258 char b_sha[kHashLength]; | 253 char b_sha[kHashLength]; |
| 259 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && | 254 DCHECK(shader_a && !shader_a->last_compiled_source().empty() && |
| 260 shader_b && !shader_b->last_compiled_source().empty()); | 255 shader_b && !shader_b->last_compiled_source().empty()); |
| 261 ComputeShaderHash( | 256 ComputeShaderHash( |
| 262 shader_a->last_compiled_source(), translator_a, a_sha); | 257 shader_a->last_compiled_signature(), a_sha); |
| 263 ComputeShaderHash( | 258 ComputeShaderHash( |
| 264 shader_b->last_compiled_source(), translator_b, b_sha); | 259 shader_b->last_compiled_signature(), b_sha); |
| 265 | 260 |
| 266 char sha[kHashLength]; | 261 char sha[kHashLength]; |
| 267 ComputeProgramHash(a_sha, | 262 ComputeProgramHash(a_sha, |
| 268 b_sha, | 263 b_sha, |
| 269 bind_attrib_location_map, | 264 bind_attrib_location_map, |
| 270 sha); | 265 sha); |
| 271 const std::string sha_string(sha, sizeof(sha)); | 266 const std::string sha_string(sha, sizeof(sha)); |
| 272 | 267 |
| 273 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeBeforeKb", | 268 UMA_HISTOGRAM_COUNTS("GPU.ProgramCache.MemorySizeBeforeKb", |
| 274 curr_size_bytes_ / 1024); | 269 curr_size_bytes_ / 1024); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 program_cache_->LinkedProgramCacheSuccess(program_hash); | 403 program_cache_->LinkedProgramCacheSuccess(program_hash); |
| 409 } | 404 } |
| 410 | 405 |
| 411 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { | 406 MemoryProgramCache::ProgramCacheValue::~ProgramCacheValue() { |
| 412 program_cache_->curr_size_bytes_ -= length_; | 407 program_cache_->curr_size_bytes_ -= length_; |
| 413 program_cache_->Evict(program_hash_); | 408 program_cache_->Evict(program_hash_); |
| 414 } | 409 } |
| 415 | 410 |
| 416 } // namespace gles2 | 411 } // namespace gles2 |
| 417 } // namespace gpu | 412 } // namespace gpu |
| OLD | NEW |