OLD | NEW |
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> |
(...skipping 21 matching lines...) Expand all Loading... |
32 class GPU_EXPORT Program : public base::RefCounted<Program> { | 32 class GPU_EXPORT Program : public base::RefCounted<Program> { |
33 public: | 33 public: |
34 static const int kMaxAttachedShaders = 2; | 34 static const int kMaxAttachedShaders = 2; |
35 | 35 |
36 enum VaryingsPackingOption { | 36 enum VaryingsPackingOption { |
37 kCountOnlyStaticallyUsed, | 37 kCountOnlyStaticallyUsed, |
38 kCountAll | 38 kCountAll |
39 }; | 39 }; |
40 | 40 |
41 enum UniformApiType { | 41 enum UniformApiType { |
| 42 kUniformNone = 0, |
42 kUniform1i = 1 << 0, | 43 kUniform1i = 1 << 0, |
43 kUniform2i = 1 << 1, | 44 kUniform2i = 1 << 1, |
44 kUniform3i = 1 << 2, | 45 kUniform3i = 1 << 2, |
45 kUniform4i = 1 << 3, | 46 kUniform4i = 1 << 3, |
46 kUniform1f = 1 << 4, | 47 kUniform1f = 1 << 4, |
47 kUniform2f = 1 << 5, | 48 kUniform2f = 1 << 5, |
48 kUniform3f = 1 << 6, | 49 kUniform3f = 1 << 6, |
49 kUniform4f = 1 << 7, | 50 kUniform4f = 1 << 7, |
50 kUniformMatrix2f = 1 << 8, | 51 kUniformMatrix2f = 1 << 8, |
51 kUniformMatrix3f = 1 << 9, | 52 kUniformMatrix3f = 1 << 9, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 GLsizei size; | 89 GLsizei size; |
89 GLenum type; | 90 GLenum type; |
90 GLint location; | 91 GLint location; |
91 std::string name; | 92 std::string name; |
92 }; | 93 }; |
93 | 94 |
94 typedef std::vector<UniformInfo> UniformInfoVector; | 95 typedef std::vector<UniformInfo> UniformInfoVector; |
95 typedef std::vector<VertexAttrib> AttribInfoVector; | 96 typedef std::vector<VertexAttrib> AttribInfoVector; |
96 typedef std::vector<int> SamplerIndices; | 97 typedef std::vector<int> SamplerIndices; |
97 typedef std::map<std::string, GLint> LocationMap; | 98 typedef std::map<std::string, GLint> LocationMap; |
| 99 typedef base::hash_map<GLint, GLenum> SubscriptionMap; |
98 | 100 |
99 Program(ProgramManager* manager, GLuint service_id); | 101 Program(ProgramManager* manager, GLuint service_id); |
100 | 102 |
101 GLuint service_id() const { | 103 GLuint service_id() const { |
102 return service_id_; | 104 return service_id_; |
103 } | 105 } |
104 | 106 |
105 const SamplerIndices& sampler_indices() { | 107 const SamplerIndices& sampler_indices() { |
106 return sampler_indices_; | 108 return sampler_indices_; |
107 } | 109 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 186 |
185 const std::string* log_info() const { | 187 const std::string* log_info() const { |
186 return log_info_.get(); | 188 return log_info_.get(); |
187 } | 189 } |
188 | 190 |
189 bool InUse() const { | 191 bool InUse() const { |
190 DCHECK_GE(use_count_, 0); | 192 DCHECK_GE(use_count_, 0); |
191 return use_count_ != 0; | 193 return use_count_ != 0; |
192 } | 194 } |
193 | 195 |
| 196 void SetNeedsUpdateSubscriptions(); |
| 197 bool needs_update_subscriptions() const { |
| 198 return needs_update_subscriptions_; |
| 199 } |
| 200 |
194 // Sets attribute-location binding from a glBindAttribLocation() call. | 201 // Sets attribute-location binding from a glBindAttribLocation() call. |
195 void SetAttribLocationBinding(const std::string& attrib, GLint location) { | 202 void SetAttribLocationBinding(const std::string& attrib, GLint location) { |
196 bind_attrib_location_map_[attrib] = location; | 203 bind_attrib_location_map_[attrib] = location; |
197 } | 204 } |
198 | 205 |
199 // Sets uniform-location binding from a glBindUniformLocationCHROMIUM call. | 206 // Sets uniform-location binding from a glBindUniformLocationCHROMIUM call. |
200 // returns false if error. | 207 // returns false if error. |
201 bool SetUniformLocationBinding(const std::string& name, GLint location); | 208 bool SetUniformLocationBinding(const std::string& name, GLint location); |
202 | 209 |
203 // Detects if there are attribute location conflicts from | 210 // Detects if there are attribute location conflicts from |
(...skipping 15 matching lines...) Expand all Loading... |
219 // GLSL ES spec 1.00.17, section 4.6.4, Invariance and Linkage. | 226 // GLSL ES spec 1.00.17, section 4.6.4, Invariance and Linkage. |
220 bool DetectBuiltInInvariantConflicts() const; | 227 bool DetectBuiltInInvariantConflicts() const; |
221 | 228 |
222 // Return true if an uniform and an attribute share the same name. | 229 // Return true if an uniform and an attribute share the same name. |
223 bool DetectGlobalNameConflicts(std::string* conflicting_name) const; | 230 bool DetectGlobalNameConflicts(std::string* conflicting_name) const; |
224 | 231 |
225 // Return false if varyings can't be packed into the max available | 232 // Return false if varyings can't be packed into the max available |
226 // varying registers. | 233 // varying registers. |
227 bool CheckVaryingsPacking(VaryingsPackingOption option) const; | 234 bool CheckVaryingsPacking(VaryingsPackingOption option) const; |
228 | 235 |
| 236 // Subscribe uniform |location| to |target| |
| 237 void AddSubscription(GLint location, GLenum target); |
| 238 // Unsubscribes uniform |location| for any targets |
| 239 void RemoveSubscription(GLint location); |
| 240 |
229 // Visible for testing | 241 // Visible for testing |
230 const LocationMap& bind_attrib_location_map() const { | 242 const LocationMap& bind_attrib_location_map() const { |
231 return bind_attrib_location_map_; | 243 return bind_attrib_location_map_; |
232 } | 244 } |
233 | 245 |
| 246 const SubscriptionMap& subscription_map() const { return subscription_map_; } |
| 247 |
234 private: | 248 private: |
235 friend class base::RefCounted<Program>; | 249 friend class base::RefCounted<Program>; |
236 friend class ProgramManager; | 250 friend class ProgramManager; |
237 | 251 |
238 ~Program(); | 252 ~Program(); |
239 | 253 |
240 void set_log_info(const char* str) { | 254 void set_log_info(const char* str) { |
241 log_info_.reset(str ? new std::string(str) : NULL); | 255 log_info_.reset(str ? new std::string(str) : NULL); |
242 } | 256 } |
243 | 257 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 355 |
342 // This is true if glLinkProgram was successful at least once. | 356 // This is true if glLinkProgram was successful at least once. |
343 bool valid_; | 357 bool valid_; |
344 | 358 |
345 // This is true if glLinkProgram was successful last time it was called. | 359 // This is true if glLinkProgram was successful last time it was called. |
346 bool link_status_; | 360 bool link_status_; |
347 | 361 |
348 // True if the uniforms have been cleared. | 362 // True if the uniforms have been cleared. |
349 bool uniforms_cleared_; | 363 bool uniforms_cleared_; |
350 | 364 |
| 365 // True if one or more subscription uniforms are out of date |
| 366 bool needs_update_subscriptions_; |
| 367 |
351 // This is different than uniform_infos_.size() because | 368 // This is different than uniform_infos_.size() because |
352 // that is a sparce array. | 369 // that is a sparce array. |
353 GLint num_uniforms_; | 370 GLint num_uniforms_; |
354 | 371 |
355 // Log info | 372 // Log info |
356 scoped_ptr<std::string> log_info_; | 373 scoped_ptr<std::string> log_info_; |
357 | 374 |
358 // attribute-location binding map from glBindAttribLocation() calls. | 375 // attribute-location binding map from glBindAttribLocation() calls. |
359 LocationMap bind_attrib_location_map_; | 376 LocationMap bind_attrib_location_map_; |
360 | 377 |
361 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. | 378 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. |
362 LocationMap bind_uniform_location_map_; | 379 LocationMap bind_uniform_location_map_; |
| 380 |
| 381 SubscriptionMap subscription_map_; |
363 }; | 382 }; |
364 | 383 |
365 // Tracks the Programs. | 384 // Tracks the Programs. |
366 // | 385 // |
367 // NOTE: To support shared resources an instance of this class will | 386 // NOTE: To support shared resources an instance of this class will |
368 // need to be shared by multiple GLES2Decoders. | 387 // need to be shared by multiple GLES2Decoders. |
369 class GPU_EXPORT ProgramManager { | 388 class GPU_EXPORT ProgramManager { |
370 public: | 389 public: |
371 explicit ProgramManager(ProgramCache* program_cache, | 390 explicit ProgramManager(ProgramCache* program_cache, |
372 uint32 max_varying_vectors); | 391 uint32 max_varying_vectors); |
(...skipping 25 matching lines...) Expand all Loading... |
398 | 417 |
399 // Clears the uniforms for this program. | 418 // Clears the uniforms for this program. |
400 void ClearUniforms(Program* program); | 419 void ClearUniforms(Program* program); |
401 | 420 |
402 // Returns true if prefix is invalid for gl. | 421 // Returns true if prefix is invalid for gl. |
403 static bool IsInvalidPrefix(const char* name, size_t length); | 422 static bool IsInvalidPrefix(const char* name, size_t length); |
404 | 423 |
405 // Check if a Program is owned by this ProgramManager. | 424 // Check if a Program is owned by this ProgramManager. |
406 bool IsOwned(Program* program); | 425 bool IsOwned(Program* program); |
407 | 426 |
| 427 // Update the active_state of the subscriptions |
| 428 void ActivateUniformSubscriptionState(); |
| 429 |
408 static int32 MakeFakeLocation(int32 index, int32 element); | 430 static int32 MakeFakeLocation(int32 index, int32 element); |
409 | 431 |
| 432 static Program::UniformApiType ApiTypeForSubscriptionTarget(GLenum target); |
| 433 |
410 uint32 max_varying_vectors() const { | 434 uint32 max_varying_vectors() const { |
411 return max_varying_vectors_; | 435 return max_varying_vectors_; |
412 } | 436 } |
413 | 437 |
414 private: | 438 private: |
415 friend class Program; | 439 friend class Program; |
416 | 440 |
417 void StartTracking(Program* program); | 441 void StartTracking(Program* program); |
418 void StopTracking(Program* program); | 442 void StopTracking(Program* program); |
419 | 443 |
(...skipping 18 matching lines...) Expand all Loading... |
438 | 462 |
439 uint32 max_varying_vectors_; | 463 uint32 max_varying_vectors_; |
440 | 464 |
441 DISALLOW_COPY_AND_ASSIGN(ProgramManager); | 465 DISALLOW_COPY_AND_ASSIGN(ProgramManager); |
442 }; | 466 }; |
443 | 467 |
444 } // namespace gles2 | 468 } // namespace gles2 |
445 } // namespace gpu | 469 } // namespace gpu |
446 | 470 |
447 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 471 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
OLD | NEW |