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

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

Issue 10534173: GPU Program Caching (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: solid in-memory implementation 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
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 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "gpu/command_buffer/service/common_decoder.h" 15 #include "gpu/command_buffer/service/common_decoder.h"
16 #include "gpu/command_buffer/service/feature_info.h"
16 #include "gpu/command_buffer/service/gl_utils.h" 17 #include "gpu/command_buffer/service/gl_utils.h"
18 #include "gpu/command_buffer/service/program_cache.h"
17 #include "gpu/command_buffer/service/shader_manager.h" 19 #include "gpu/command_buffer/service/shader_manager.h"
18 #include "gpu/gpu_export.h" 20 #include "gpu/gpu_export.h"
19 21
20 namespace gpu { 22 namespace gpu {
23
21 namespace gles2 { 24 namespace gles2 {
22 25
23 // Tracks the Programs. 26 // Tracks the Programs.
24 // 27 //
25 // NOTE: To support shared resources an instance of this class will 28 // NOTE: To support shared resources an instance of this class will
26 // need to be shared by multiple GLES2Decoders. 29 // need to be shared by multiple GLES2Decoders.
27 class GPU_EXPORT ProgramManager { 30 class GPU_EXPORT ProgramManager {
28 public: 31 public:
29 // This is used to track which attributes a particular program needs 32 // This is used to track which attributes a particular program needs
30 // so we can verify at glDrawXXX time that every attribute is either disabled 33 // so we can verify at glDrawXXX time that every attribute is either disabled
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 bool IsValid() const { 144 bool IsValid() const {
142 return valid_; 145 return valid_;
143 } 146 }
144 147
145 bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); 148 bool AttachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
146 bool DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info); 149 bool DetachShader(ShaderManager* manager, ShaderManager::ShaderInfo* info);
147 150
148 bool CanLink() const; 151 bool CanLink() const;
149 152
150 // Performs glLinkProgram and related activities. 153 // Performs glLinkProgram and related activities.
151 bool Link(); 154 bool Link(ShaderManager* manager,
155 ShaderTranslator* vertex_translator,
156 ShaderTranslator* fragment_shader,
157 FeatureInfo* feature_info);
152 158
153 // Performs glValidateProgram and related activities. 159 // Performs glValidateProgram and related activities.
154 void Validate(); 160 void Validate();
155 161
156 const std::string* log_info() const { 162 const std::string* log_info() const {
157 return log_info_.get(); 163 return log_info_.get();
158 } 164 }
159 165
160 bool InUse() const { 166 bool InUse() const {
161 DCHECK_GE(use_count_, 0); 167 DCHECK_GE(use_count_, 0);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // True if the uniforms have been cleared. 288 // True if the uniforms have been cleared.
283 bool uniforms_cleared_; 289 bool uniforms_cleared_;
284 290
285 // Log info 291 // Log info
286 scoped_ptr<std::string> log_info_; 292 scoped_ptr<std::string> log_info_;
287 293
288 // attribute-location binding map from glBindAttribLocation() calls. 294 // attribute-location binding map from glBindAttribLocation() calls.
289 std::map<std::string, GLint> bind_attrib_location_map_; 295 std::map<std::string, GLint> bind_attrib_location_map_;
290 }; 296 };
291 297
292 ProgramManager(); 298 explicit ProgramManager(base::WeakPtr<ProgramCache> program_cache);
293 ~ProgramManager(); 299 ~ProgramManager();
294 300
295 // Must call before destruction. 301 // Must call before destruction.
296 void Destroy(bool have_context); 302 void Destroy(bool have_context);
297 303
298 // Creates a new program info. 304 // Creates a new program info.
299 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id); 305 ProgramInfo* CreateProgramInfo(GLuint client_id, GLuint service_id);
300 306
301 // Gets a program info 307 // Gets a program info
302 ProgramInfo* GetProgramInfo(GLuint client_id); 308 ProgramInfo* GetProgramInfo(GLuint client_id);
303 309
304 // Gets a client id for a given service id. 310 // Gets a client id for a given service id.
305 bool GetClientId(GLuint service_id, GLuint* client_id) const; 311 bool GetClientId(GLuint service_id, GLuint* client_id) const;
306 312
313 // Gets the shader cache
314 ProgramCache* GetProgramCache() const;
315
307 // Marks a program as deleted. If it is not used the info will be deleted. 316 // Marks a program as deleted. If it is not used the info will be deleted.
308 void MarkAsDeleted(ShaderManager* shader_manager, ProgramInfo* info); 317 void MarkAsDeleted(ShaderManager* shader_manager, ProgramInfo* info);
309 318
310 // Marks a program as used. 319 // Marks a program as used.
311 void UseProgram(ProgramInfo* info); 320 void UseProgram(ProgramInfo* info);
312 321
313 // Makes a program as unused. If deleted the program info will be removed. 322 // Makes a program as unused. If deleted the program info will be removed.
314 void UnuseProgram(ShaderManager* shader_manager, ProgramInfo* info); 323 void UnuseProgram(ShaderManager* shader_manager, ProgramInfo* info);
315 324
316 // Clears the uniforms for this program. 325 // Clears the uniforms for this program.
317 void ClearUniforms(ProgramInfo* info); 326 void ClearUniforms(ProgramInfo* info);
318 327
319 // Returns true if prefix is invalid for gl. 328 // Returns true if prefix is invalid for gl.
320 static bool IsInvalidPrefix(const char* name, size_t length); 329 static bool IsInvalidPrefix(const char* name, size_t length);
321 330
322 // Check if a ProgramInfo is owned by this ProgramManager. 331 // Check if a ProgramInfo is owned by this ProgramManager.
323 bool IsOwned(ProgramInfo* info); 332 bool IsOwned(ProgramInfo* info);
324 333
325 GLint SwizzleLocation(GLint unswizzled_location) const; 334 GLint SwizzleLocation(GLint unswizzled_location) const;
326 GLint UnswizzleLocation(GLint swizzled_location) const; 335 GLint UnswizzleLocation(GLint swizzled_location) const;
327 336
337 void DoCompileShader(ShaderManager::ShaderInfo* info,
338 ShaderTranslator* translator,
339 FeatureInfo* feature_info);
340
328 private: 341 private:
329 void StartTracking(ProgramInfo* info); 342 void StartTracking(ProgramInfo* info);
330 void StopTracking(ProgramInfo* info); 343 void StopTracking(ProgramInfo* info);
331 344
332 // Info for each "successfully linked" program by service side program Id. 345 // Info for each "successfully linked" program by service side program Id.
333 // TODO(gman): Choose a faster container. 346 // TODO(gman): Choose a faster container.
334 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap; 347 typedef std::map<GLuint, ProgramInfo::Ref> ProgramInfoMap;
335 ProgramInfoMap program_infos_; 348 ProgramInfoMap program_infos_;
336 349
337 int uniform_swizzle_; 350 int uniform_swizzle_;
338 351
339 // Counts the number of ProgramInfo allocated with 'this' as its manager. 352 // Counts the number of ProgramInfo allocated with 'this' as its manager.
340 // Allows to check no ProgramInfo will outlive this. 353 // Allows to check no ProgramInfo will outlive this.
341 unsigned int program_info_count_; 354 unsigned int program_info_count_;
342 355
343 bool have_context_; 356 bool have_context_;
344 357
345 bool disable_workarounds_; 358 bool disable_workarounds_;
346 359
347 // Used to clear uniforms. 360 // Used to clear uniforms.
348 std::vector<uint8> zero_; 361 std::vector<uint8> zero_;
349 362
363 base::WeakPtr<ProgramCache> program_cache_;
364
350 void RemoveProgramInfoIfUnused( 365 void RemoveProgramInfoIfUnused(
351 ShaderManager* shader_manager, ProgramInfo* info); 366 ShaderManager* shader_manager, ProgramInfo* info);
352 367
353 DISALLOW_COPY_AND_ASSIGN(ProgramManager); 368 DISALLOW_COPY_AND_ASSIGN(ProgramManager);
354 }; 369 };
355 370
356 } // namespace gles2 371 } // namespace gles2
357 } // namespace gpu 372 } // namespace gpu
358 373
359 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ 374 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698