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