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

Side by Side Diff: gpu/command_buffer/service/program_cache.h

Issue 10797055: gpu in-memory program cache implementation with a memory limit + lru eviction. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: simplified binary loading logic Created 8 years, 5 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
(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 // Loads the linked program from the cache. If the program is not found or
54 // there was an error, PROGRAM_LOAD_FAILURE should be returned.
55 virtual ProgramLoadResult LoadLinkedProgram(
56 GLuint program,
57 ShaderManager::ShaderInfo* shader_a,
58 ShaderManager::ShaderInfo* shader_b,
59 const LocationMap* bind_attrib_location_map) const = 0;
60
61 // Saves the program into the cache. If successful, the implementation should
62 // call LinkedProgramCacheSuccess.
63 virtual void SaveLinkedProgram(
64 GLuint program,
65 const ShaderManager::ShaderInfo* shader_a,
66 const ShaderManager::ShaderInfo* shader_b,
67 const LocationMap* bind_attrib_location_map) = 0;
68
69 // clears the cache
70 void Clear();
71
72 // Only for testing
73 void LinkedProgramCacheSuccess(const std::string& shader_a,
74 const std::string& shader_b,
75 const LocationMap* bind_attrib_location_map);
76
77 protected:
78 // called by implementing class after a shader was successfully cached
79 void LinkedProgramCacheSuccess(const std::string& program_hash,
80 const std::string& shader_a_hash,
81 const std::string& shader_b_hash);
82
83 // result is not null terminated
84 void ComputeShaderHash(const std::string& shader,
85 char* result) const;
86
87 // result is not null terminated. hashed shaders are expected to be
88 // kHashLength in length
89 void ComputeProgramHash(
90 const char* hashed_shader_0,
91 const char* hashed_shader_1,
92 const LocationMap* bind_attrib_location_map,
93 char* result) const;
94
95 void Evict(const std::string& program_hash,
96 const std::string& shader_0_hash,
97 const std::string& shader_1_hash);
98
99 private:
100 struct CompiledShaderInfo {
101 CompiledShaderInfo() : status(COMPILATION_UNKNOWN), ref_count(0) { }
102 explicit CompiledShaderInfo(CompiledShaderStatus status_)
103 : status(status_),
104 ref_count(0) { }
105
106 CompiledShaderStatus status;
107 size_t ref_count;
108 };
109
110 typedef base::hash_map<std::string,
111 CompiledShaderInfo> CompileStatusMap;
112 typedef base::hash_map<std::string,
113 LinkedProgramStatus> LinkStatusMap;
114
115 // called to clear the backend cache
116 virtual void ClearBackend() = 0;
117
118 CompileStatusMap shader_status_;
119 LinkStatusMap link_status_;
120
121 DISALLOW_COPY_AND_ASSIGN(ProgramCache);
122 };
123
124 } // namespace gles2
125 } // namespace gpu
126
127 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698