| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/hash_tables.h" |
| 13 #include "base/sha1.h" |
| 14 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 15 #include "gpu/command_buffer/service/shader_manager.h" |
| 16 |
| 17 namespace gpu { |
| 18 namespace gles2 { |
| 19 |
| 20 // Program cache base class for caching linked gpu programs |
| 21 class GPU_EXPORT ProgramCache { |
| 22 public: |
| 23 static const size_t kHashLength = base::kSHA1Length; |
| 24 |
| 25 typedef std::map<std::string, GLint> LocationMap; |
| 26 |
| 27 enum CompiledShaderStatus { |
| 28 COMPILATION_UNKNOWN, |
| 29 COMPILATION_SUCCEEDED |
| 30 }; |
| 31 |
| 32 enum LinkedProgramStatus { |
| 33 LINK_UNKNOWN, |
| 34 LINK_SUCCEEDED |
| 35 }; |
| 36 |
| 37 enum ProgramLoadResult { |
| 38 PROGRAM_LOAD_FAILURE, |
| 39 PROGRAM_LOAD_SUCCESS |
| 40 }; |
| 41 |
| 42 ProgramCache() {} |
| 43 virtual ~ProgramCache(); |
| 44 |
| 45 CompiledShaderStatus GetShaderCompilationStatus( |
| 46 const std::string& shader_src) const; |
| 47 void ShaderCompilationSucceeded(const std::string& shader_src); |
| 48 |
| 49 LinkedProgramStatus GetLinkedProgramStatus( |
| 50 const std::string& untranslated_a, |
| 51 const std::string& untranslated_b, |
| 52 const LocationMap* bind_attrib_location_map) const; |
| 53 |
| 54 virtual ProgramLoadResult LoadLinkedProgram( |
| 55 const GLuint program, |
| 56 ShaderManager::ShaderInfo* shader_a, |
| 57 ShaderManager::ShaderInfo* shader_b, |
| 58 const LocationMap* bind_attrib_location_map) const = 0; |
| 59 virtual void SaveLinkedProgram( |
| 60 const GLuint program, |
| 61 const ShaderManager::ShaderInfo* shader_a, |
| 62 const ShaderManager::ShaderInfo* shader_b, |
| 63 const LocationMap* bind_attrib_location_map) = 0; |
| 64 |
| 65 // clears the cache |
| 66 void Clear(); |
| 67 |
| 68 // Only for testing |
| 69 void LinkedProgramCacheSuccess(const std::string& shader_a, |
| 70 const std::string& shader_b, |
| 71 const LocationMap* bind_attrib_location_map); |
| 72 |
| 73 protected: |
| 74 // called by implementing class after a shader was successfully cached |
| 75 void LinkedProgramCacheSuccess(const std::string& program_hash, |
| 76 const std::string& shader_a_hash, |
| 77 const std::string& shader_b_hash); |
| 78 |
| 79 // result is not null terminated |
| 80 void ComputeShaderHash(const std::string& shader, |
| 81 char* result) const; |
| 82 |
| 83 // result is not null terminated. hashed shaders are expected to be |
| 84 // kHashLength in length |
| 85 void ComputeProgramHash( |
| 86 const char* hashed_shader_0, |
| 87 const char* hashed_shader_1, |
| 88 const LocationMap* bind_attrib_location_map, |
| 89 char* result) const; |
| 90 |
| 91 void Evict(const std::string& program_hash, |
| 92 const std::string& shader_0_hash, |
| 93 const std::string& shader_1_hash); |
| 94 |
| 95 private: |
| 96 struct CompiledShaderInfo { |
| 97 CompiledShaderInfo() : status(COMPILATION_UNKNOWN), ref_count(0) { } |
| 98 explicit CompiledShaderInfo(CompiledShaderStatus status_) |
| 99 : status(status_), |
| 100 ref_count(0) { } |
| 101 |
| 102 CompiledShaderStatus status; |
| 103 size_t ref_count; |
| 104 }; |
| 105 |
| 106 typedef base::hash_map<std::string, |
| 107 CompiledShaderInfo> CompileStatusMap; |
| 108 typedef base::hash_map<std::string, |
| 109 LinkedProgramStatus> LinkStatusMap; |
| 110 |
| 111 // called to clear the backend cache |
| 112 virtual void ClearBackend() = 0; |
| 113 |
| 114 CompileStatusMap shader_status_; |
| 115 LinkStatusMap link_status_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(ProgramCache); |
| 118 }; |
| 119 |
| 120 } // namespace gles2 |
| 121 } // namespace gpu |
| 122 |
| 123 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_ |
| OLD | NEW |