| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 FragmentInputInfo(GLenum _type, GLuint _location) | 66 FragmentInputInfo(GLenum _type, GLuint _location) |
| 67 : type(_type), location(_location) {} | 67 : type(_type), location(_location) {} |
| 68 FragmentInputInfo() : type(GL_NONE), location(0) {} | 68 FragmentInputInfo() : type(GL_NONE), location(0) {} |
| 69 bool IsValid() const { return type != GL_NONE; } | 69 bool IsValid() const { return type != GL_NONE; } |
| 70 GLenum type; | 70 GLenum type; |
| 71 GLuint location; | 71 GLuint location; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 struct UniformInfo { | 74 struct UniformInfo { |
| 75 UniformInfo(); | 75 UniformInfo(); |
| 76 UniformInfo( | 76 UniformInfo(const std::string& client_name, |
| 77 GLsizei _size, GLenum _type, GLint _fake_location_base, | 77 GLint client_location_base, |
| 78 const std::string& _name); | 78 GLenum _type, |
| 79 bool _is_array, |
| 80 const std::vector<GLint>& service_locations); |
| 79 ~UniformInfo(); | 81 ~UniformInfo(); |
| 80 | |
| 81 bool IsValid() const { | |
| 82 return size != 0; | |
| 83 } | |
| 84 | |
| 85 bool IsSampler() const { | 82 bool IsSampler() const { |
| 86 return type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || | 83 return type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 87 type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES; | 84 type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES; |
| 88 } | 85 } |
| 89 | 86 |
| 90 GLsizei size; | 87 GLsizei size; |
| 91 GLenum type; | 88 GLenum type; |
| 92 uint32 accepts_api_type; | 89 uint32 accepts_api_type; |
| 93 GLint fake_location_base; | 90 GLint fake_location_base; |
| 94 bool is_array; | 91 bool is_array; |
| 95 std::string name; | 92 std::string name; |
| 96 std::vector<GLint> element_locations; | 93 std::vector<GLint> element_locations; |
| 97 std::vector<GLuint> texture_units; | 94 std::vector<GLuint> texture_units; |
| 98 }; | 95 }; |
| 99 struct VertexAttrib { | 96 struct VertexAttrib { |
| 100 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, | 97 VertexAttrib(GLsizei _size, GLenum _type, const std::string& _name, |
| 101 GLint _location) | 98 GLint _location) |
| 102 : size(_size), | 99 : size(_size), |
| 103 type(_type), | 100 type(_type), |
| 104 location(_location), | 101 location(_location), |
| 105 name(_name) { | 102 name(_name) { |
| 106 } | 103 } |
| 107 GLsizei size; | 104 GLsizei size; |
| 108 GLenum type; | 105 GLenum type; |
| 109 GLint location; | 106 GLint location; |
| 110 std::string name; | 107 std::string name; |
| 111 }; | 108 }; |
| 112 | 109 |
| 110 class UniformLocationEntry { |
| 111 public: |
| 112 UniformLocationEntry() : uniform_(nullptr), inactive_(false) {} |
| 113 bool IsUnused() const { return !uniform_ && !inactive_; } |
| 114 bool IsInactive() const { return inactive_; } |
| 115 bool IsActive() const { return uniform_ != nullptr; } |
| 116 void SetInactive() { |
| 117 uniform_ = nullptr; |
| 118 inactive_ = true; |
| 119 } |
| 120 void SetActive(UniformInfo* uniform) { |
| 121 DCHECK(uniform); |
| 122 uniform_ = uniform; |
| 123 inactive_ = false; |
| 124 } |
| 125 const UniformInfo* uniform() const { |
| 126 DCHECK(IsActive()); |
| 127 return uniform_; |
| 128 } |
| 129 UniformInfo* uniform() { |
| 130 DCHECK(IsActive()); |
| 131 return uniform_; |
| 132 } |
| 133 |
| 134 private: |
| 135 UniformInfo* uniform_; // Pointer to uniform_info_ vector entry. |
| 136 bool inactive_; |
| 137 }; |
| 138 |
| 113 typedef std::vector<UniformInfo> UniformInfoVector; | 139 typedef std::vector<UniformInfo> UniformInfoVector; |
| 140 typedef std::vector<UniformLocationEntry> UniformLocationVector; |
| 114 typedef std::vector<VertexAttrib> AttribInfoVector; | 141 typedef std::vector<VertexAttrib> AttribInfoVector; |
| 115 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; | 142 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; |
| 116 typedef std::vector<int> SamplerIndices; | 143 typedef std::vector<int> SamplerIndices; |
| 117 typedef std::map<std::string, GLint> LocationMap; | 144 typedef std::map<std::string, GLint> LocationMap; |
| 118 typedef std::vector<std::string> StringVector; | 145 typedef std::vector<std::string> StringVector; |
| 119 | 146 |
| 120 Program(ProgramManager* manager, GLuint service_id); | 147 Program(ProgramManager* manager, GLuint service_id); |
| 121 | 148 |
| 122 GLuint service_id() const { | 149 GLuint service_id() const { |
| 123 return service_id_; | 150 return service_id_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( | 192 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( |
| 166 GLint fake_location) const; | 193 GLint fake_location) const; |
| 167 | 194 |
| 168 // Gets the fake location of a uniform by name. | 195 // Gets the fake location of a uniform by name. |
| 169 GLint GetUniformFakeLocation(const std::string& name) const; | 196 GLint GetUniformFakeLocation(const std::string& name) const; |
| 170 | 197 |
| 171 // Gets the UniformInfo of a uniform by location. | 198 // Gets the UniformInfo of a uniform by location. |
| 172 const UniformInfo* GetUniformInfoByFakeLocation( | 199 const UniformInfo* GetUniformInfoByFakeLocation( |
| 173 GLint fake_location, GLint* real_location, GLint* array_index) const; | 200 GLint fake_location, GLint* real_location, GLint* array_index) const; |
| 174 | 201 |
| 202 // Returns true if |fake_location| is a location for an inactive uniform, |
| 203 // -1 for bound, non-existing uniform. |
| 204 bool IsInactiveUniformLocationByFakeLocation(GLint fake_location) const; |
| 205 |
| 175 // Gets all the program info. | 206 // Gets all the program info. |
| 176 void GetProgramInfo( | 207 void GetProgramInfo( |
| 177 ProgramManager* manager, CommonDecoder::Bucket* bucket) const; | 208 ProgramManager* manager, CommonDecoder::Bucket* bucket) const; |
| 178 | 209 |
| 179 // Gets all the UniformBlock info. | 210 // Gets all the UniformBlock info. |
| 180 // Return false on overflow. | 211 // Return false on overflow. |
| 181 bool GetUniformBlocks(CommonDecoder::Bucket* bucket) const; | 212 bool GetUniformBlocks(CommonDecoder::Bucket* bucket) const; |
| 182 | 213 |
| 183 // Gets all the TransformFeedbackVarying info. | 214 // Gets all the TransformFeedbackVarying info. |
| 184 // Return false on overflow. | 215 // Return false on overflow. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 void MarkAsDeleted() { | 357 void MarkAsDeleted() { |
| 327 DCHECK(!deleted_); | 358 DCHECK(!deleted_); |
| 328 deleted_ = true; | 359 deleted_ = true; |
| 329 } | 360 } |
| 330 | 361 |
| 331 // Resets the program. | 362 // Resets the program. |
| 332 void Reset(); | 363 void Reset(); |
| 333 | 364 |
| 334 // Updates the program info after a successful link. | 365 // Updates the program info after a successful link. |
| 335 void Update(); | 366 void Update(); |
| 367 void UpdateUniforms(); |
| 336 void UpdateFragmentInputs(); | 368 void UpdateFragmentInputs(); |
| 337 | 369 |
| 338 // Process the program log, replacing the hashed names with original names. | 370 // Process the program log, replacing the hashed names with original names. |
| 339 std::string ProcessLogInfo(const std::string& log); | 371 std::string ProcessLogInfo(const std::string& log); |
| 340 | 372 |
| 341 // Updates the program log info from GL | 373 // Updates the program log info from GL |
| 342 void UpdateLogInfo(); | 374 void UpdateLogInfo(); |
| 343 | 375 |
| 344 template <typename VarT> | 376 template <typename VarT> |
| 345 void GetUniformBlockMembers( | 377 void GetUniformBlockMembers( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 360 // glBindAttribLocation() again with the mapped names. | 392 // glBindAttribLocation() again with the mapped names. |
| 361 // This is called right before the glLink() call, but after shaders are | 393 // This is called right before the glLink() call, but after shaders are |
| 362 // translated. | 394 // translated. |
| 363 void ExecuteBindAttribLocationCalls(); | 395 void ExecuteBindAttribLocationCalls(); |
| 364 | 396 |
| 365 // The names of transform feedback varyings need to be hashed just | 397 // The names of transform feedback varyings need to be hashed just |
| 366 // like bound attributes' locations, just before the link call. | 398 // like bound attributes' locations, just before the link call. |
| 367 // Returns false upon failure. | 399 // Returns false upon failure. |
| 368 bool ExecuteTransformFeedbackVaryingsCall(); | 400 bool ExecuteTransformFeedbackVaryingsCall(); |
| 369 | 401 |
| 370 void AddUniformInfo( | |
| 371 GLsizei size, GLenum type, GLint location, GLint fake_base_location, | |
| 372 const std::string& name, const std::string& original_name, | |
| 373 size_t* next_available_index); | |
| 374 | |
| 375 // Query uniform data returned by ANGLE translator by the mapped name. | |
| 376 // Some drivers incorrectly return an uniform name of size-1 array without | |
| 377 // "[0]". In this case, we correct the name by appending "[0]" to it. | |
| 378 void GetCorrectedUniformData( | |
| 379 const std::string& name, | |
| 380 std::string* corrected_name, std::string* original_name, | |
| 381 GLsizei* size, GLenum* type) const; | |
| 382 | |
| 383 // Query VertexAttrib data returned by ANGLE translator by the mapped name. | 402 // Query VertexAttrib data returned by ANGLE translator by the mapped name. |
| 384 void GetVertexAttribData( | 403 void GetVertexAttribData( |
| 385 const std::string& name, std::string* original_name, GLenum* type) const; | 404 const std::string& name, std::string* original_name, GLenum* type) const; |
| 386 | 405 |
| 387 void DetachShaders(ShaderManager* manager); | 406 void DetachShaders(ShaderManager* manager); |
| 388 | 407 |
| 389 static inline GLint GetUniformInfoIndexFromFakeLocation( | 408 static inline size_t GetUniformLocationIndexFromFakeLocation( |
| 390 GLint fake_location) { | 409 GLint fake_location) { |
| 391 return fake_location & 0xFFFF; | 410 return static_cast<size_t>(fake_location & 0xFFFF); |
| 392 } | 411 } |
| 393 | 412 |
| 394 static inline GLint GetArrayElementIndexFromFakeLocation( | 413 static inline size_t GetArrayElementIndexFromFakeLocation( |
| 395 GLint fake_location) { | 414 GLint fake_location) { |
| 396 return (fake_location >> 16) & 0xFFFF; | 415 return static_cast<size_t>((fake_location >> 16) & 0xFFFF); |
| 397 } | 416 } |
| 398 | 417 |
| 399 const FeatureInfo& feature_info() const; | 418 const FeatureInfo& feature_info() const; |
| 400 | 419 |
| 401 ProgramManager* manager_; | 420 ProgramManager* manager_; |
| 402 | 421 |
| 403 int use_count_; | 422 int use_count_; |
| 404 | 423 |
| 405 GLsizei max_attrib_name_length_; | 424 GLsizei max_attrib_name_length_; |
| 406 | 425 |
| 407 // Attrib by index. | 426 // Attrib by index. |
| 408 AttribInfoVector attrib_infos_; | 427 AttribInfoVector attrib_infos_; |
| 409 | 428 |
| 410 // Attrib by location to index. | 429 // Attrib by location to index. |
| 411 std::vector<GLint> attrib_location_to_index_map_; | 430 std::vector<GLint> attrib_location_to_index_map_; |
| 412 | 431 |
| 413 GLsizei max_uniform_name_length_; | 432 GLsizei max_uniform_name_length_; |
| 414 | 433 |
| 415 // Uniform info by index. | 434 // Uniform info by index. |
| 416 UniformInfoVector uniform_infos_; | 435 UniformInfoVector uniform_infos_; |
| 436 UniformLocationVector uniform_locations_; |
| 417 | 437 |
| 418 // The indices of the uniforms that are samplers. | 438 // The indices of the uniforms that are samplers. |
| 419 SamplerIndices sampler_indices_; | 439 SamplerIndices sampler_indices_; |
| 420 | 440 |
| 421 FragmentInputInfoVector fragment_input_infos_; | 441 FragmentInputInfoVector fragment_input_infos_; |
| 422 | 442 |
| 423 // The program this Program is tracking. | 443 // The program this Program is tracking. |
| 424 GLuint service_id_; | 444 GLuint service_id_; |
| 425 | 445 |
| 426 // Shaders by type of shader. | 446 // Shaders by type of shader. |
| 427 scoped_refptr<Shader> | 447 scoped_refptr<Shader> |
| 428 attached_shaders_[kMaxAttachedShaders]; | 448 attached_shaders_[kMaxAttachedShaders]; |
| 429 | 449 |
| 430 // True if this program is marked as deleted. | 450 // True if this program is marked as deleted. |
| 431 bool deleted_; | 451 bool deleted_; |
| 432 | 452 |
| 433 // This is true if glLinkProgram was successful at least once. | 453 // This is true if glLinkProgram was successful at least once. |
| 434 bool valid_; | 454 bool valid_; |
| 435 | 455 |
| 436 // This is true if glLinkProgram was successful last time it was called. | 456 // This is true if glLinkProgram was successful last time it was called. |
| 437 bool link_status_; | 457 bool link_status_; |
| 438 | 458 |
| 439 // True if the uniforms have been cleared. | 459 // True if the uniforms have been cleared. |
| 440 bool uniforms_cleared_; | 460 bool uniforms_cleared_; |
| 441 | 461 |
| 442 // This is different than uniform_infos_.size() because | |
| 443 // that is a sparce array. | |
| 444 GLint num_uniforms_; | |
| 445 | |
| 446 // Log info | 462 // Log info |
| 447 scoped_ptr<std::string> log_info_; | 463 scoped_ptr<std::string> log_info_; |
| 448 | 464 |
| 449 // attribute-location binding map from glBindAttribLocation() calls. | 465 // attribute-location binding map from glBindAttribLocation() calls. |
| 450 LocationMap bind_attrib_location_map_; | 466 LocationMap bind_attrib_location_map_; |
| 451 | 467 |
| 452 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. | 468 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. |
| 453 LocationMap bind_uniform_location_map_; | 469 LocationMap bind_uniform_location_map_; |
| 454 | 470 |
| 455 std::vector<std::string> transform_feedback_varyings_; | 471 std::vector<std::string> transform_feedback_varyings_; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 }; | 560 }; |
| 545 | 561 |
| 546 inline const FeatureInfo& Program::feature_info() const { | 562 inline const FeatureInfo& Program::feature_info() const { |
| 547 return *manager_->feature_info_.get(); | 563 return *manager_->feature_info_.get(); |
| 548 } | 564 } |
| 549 | 565 |
| 550 } // namespace gles2 | 566 } // namespace gles2 |
| 551 } // namespace gpu | 567 } // namespace gpu |
| 552 | 568 |
| 553 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 569 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
| OLD | NEW |