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

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

Issue 10534173: GPU Program Caching (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Patch Created 8 years, 6 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 #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"
greggman 2012/06/26 23:00:27 Is this needed?
dmurph 2012/07/04 00:01:29 I need the definition of GLuint, should I use a di
15 #include "gpu/command_buffer/service/shader_manager.h"
16 #include "net/disk_cache/hash.h"
17
18 namespace gpu {
19 namespace gles2 {
20
21 // Program cache base class for caching linked gpu programs
22 class GPU_EXPORT ProgramCache {
23 public:
24 enum CompiledShaderStatus {
25 COMPILATION_UNKNOWN,
26 COMPILATION_SUCCEEDED
27 };
28
29 enum LinkedProgramStatus {
30 LINK_UNKNOWN,
31 LINK_SUCCEEDED
32 };
33
34 ProgramCache() {}
35 virtual ~ProgramCache();
36
37 CompiledShaderStatus GetShaderCompilationStatus(
38 const std::string& shader_src) const;
39 void ShaderCompilationSucceeded(const std::string& shader_src);
40
41 LinkedProgramStatus GetLinkedProgramStatus(
42 const std::string& untranslated_a,
43 const std::string& untranslated_b,
44 const std::map<std::string, GLint>* bind_attrib_location_map) const;
45
46 virtual bool LoadLinkedProgram(
47 const GLuint program,
48 ShaderManager::ShaderInfo* shader_a,
49 ShaderManager::ShaderInfo* shader_b,
50 const std::map<std::string, GLint>* bind_attrib_location_map) const = 0;
51 virtual void SaveLinkedProgram(
52 const GLuint program,
53 const ShaderManager::ShaderInfo* shader_a,
54 const ShaderManager::ShaderInfo* shader_b,
55 const std::map<std::string, GLint>* bind_attrib_location_map) = 0;
56 // clears the cache
57 void Clear();
58
59 protected:
60 static const size_t kHashLength = base::kSHA1Length;
61
62 // called by implementing class after a shader was successfully cached
63 void LinkedProgramCacheSuccess(const std::string& program_hash,
64 const std::string& shader_a_hash,
65 const std::string& shader_b_hash);
66
67 // result is not null terminated
68 void ComputeShaderHash(const std::string& shader,
69 char* result) const;
70
71 // result is not null terminated. hashed shaders are expected to be
72 // kHashLength in length
73 void ComputeProgramHash(
74 const char* hashed_shader_0,
75 const char* hashed_shader_1,
76 const std::map<std::string, GLint>* bind_attrib_location_map,
77 char* result) const;
78
79 void Evict(const std::string& program_hash,
80 const std::string& shader_0_hash,
81 const std::string& shader_1_hash);
82
83 protected:
84 struct FastHash {
85 const inline uint32 operator()(const std::string& key) const {
86 return disk_cache::SuperFastHash(key.data(),
87 static_cast<int>(key.size()));
88 }
89 };
90
91 private:
92 struct CompiledShaderInfo {
93 CompiledShaderInfo() : status(COMPILATION_UNKNOWN), ref_count(0) { }
94 explicit CompiledShaderInfo(CompiledShaderStatus status_)
95 : status(status_),
96 ref_count(0) { }
97
98 CompiledShaderStatus status;
99 size_t ref_count;
100 };
101
102 typedef base::hash_map<const std::string,
103 CompiledShaderInfo,
104 FastHash> CompileStatusMap;
105 typedef base::hash_map<const std::string,
106 LinkedProgramStatus,
107 FastHash> LinkStatusMap;
108
109 // called to clear the backend cache
110 virtual void ClearBackend() = 0;
111
112 CompileStatusMap shader_status_;
113 LinkStatusMap link_status_;
114
115 DISALLOW_COPY_AND_ASSIGN(ProgramCache);
116 };
117
greggman 2012/06/26 23:00:27 style: remove extra blank lines
dmurph 2012/07/04 00:01:29 Done.
118
119
120 } // namespace gles2
121 } // namespace gpu
122
123 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698