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

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

Powered by Google App Engine
This is Rietveld 408576698