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_; } | |
116 void SetInactive() { | |
117 uniform_ = nullptr; | |
118 inactive_ = true; | |
119 } | |
120 void SetActive(UniformInfo* uniform) { | |
121 uniform_ = uniform; | |
Zhenyao Mo
2015/11/20 00:15:01
Maybe DCHECK(uniform)?
Kimmo Kinnunen
2015/11/20 07:56:53
Done.
| |
122 inactive_ = false; | |
123 } | |
124 const UniformInfo* uniform() const { | |
125 DCHECK(IsActive()); | |
126 return uniform_; | |
127 } | |
128 UniformInfo* uniform() { | |
129 DCHECK(IsActive()); | |
130 return uniform_; | |
131 } | |
132 | |
133 private: | |
134 UniformInfo* uniform_; // Pointer to uniform_info_ vector entry. | |
135 bool inactive_; | |
136 }; | |
137 | |
113 typedef std::vector<UniformInfo> UniformInfoVector; | 138 typedef std::vector<UniformInfo> UniformInfoVector; |
139 typedef std::vector<UniformLocationEntry> UniformLocationVector; | |
114 typedef std::vector<VertexAttrib> AttribInfoVector; | 140 typedef std::vector<VertexAttrib> AttribInfoVector; |
115 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; | 141 typedef std::vector<FragmentInputInfo> FragmentInputInfoVector; |
116 typedef std::vector<int> SamplerIndices; | 142 typedef std::vector<int> SamplerIndices; |
117 typedef std::map<std::string, GLint> LocationMap; | 143 typedef std::map<std::string, GLint> LocationMap; |
118 typedef std::vector<std::string> StringVector; | 144 typedef std::vector<std::string> StringVector; |
119 | 145 |
120 Program(ProgramManager* manager, GLuint service_id); | 146 Program(ProgramManager* manager, GLuint service_id); |
121 | 147 |
122 GLuint service_id() const { | 148 GLuint service_id() const { |
123 return service_id_; | 149 return service_id_; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( | 191 const FragmentInputInfo* GetFragmentInputInfoByFakeLocation( |
166 GLint fake_location) const; | 192 GLint fake_location) const; |
167 | 193 |
168 // Gets the fake location of a uniform by name. | 194 // Gets the fake location of a uniform by name. |
169 GLint GetUniformFakeLocation(const std::string& name) const; | 195 GLint GetUniformFakeLocation(const std::string& name) const; |
170 | 196 |
171 // Gets the UniformInfo of a uniform by location. | 197 // Gets the UniformInfo of a uniform by location. |
172 const UniformInfo* GetUniformInfoByFakeLocation( | 198 const UniformInfo* GetUniformInfoByFakeLocation( |
173 GLint fake_location, GLint* real_location, GLint* array_index) const; | 199 GLint fake_location, GLint* real_location, GLint* array_index) const; |
174 | 200 |
201 // Returns true if |fake_location| is a location for an inactive uniform, | |
202 // -1 or bound, non-existing uniform. | |
Zhenyao Mo
2015/11/20 00:15:01
nit: or -> for
Kimmo Kinnunen
2015/11/20 07:56:53
Done.
| |
203 bool IsInactiveUniformLocationByFakeLocation(GLint fake_location) const; | |
204 | |
175 // Gets all the program info. | 205 // Gets all the program info. |
176 void GetProgramInfo( | 206 void GetProgramInfo( |
177 ProgramManager* manager, CommonDecoder::Bucket* bucket) const; | 207 ProgramManager* manager, CommonDecoder::Bucket* bucket) const; |
178 | 208 |
179 // Gets all the UniformBlock info. | 209 // Gets all the UniformBlock info. |
180 // Return false on overflow. | 210 // Return false on overflow. |
181 bool GetUniformBlocks(CommonDecoder::Bucket* bucket) const; | 211 bool GetUniformBlocks(CommonDecoder::Bucket* bucket) const; |
182 | 212 |
183 // Gets all the TransformFeedbackVarying info. | 213 // Gets all the TransformFeedbackVarying info. |
184 // Return false on overflow. | 214 // Return false on overflow. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 void MarkAsDeleted() { | 356 void MarkAsDeleted() { |
327 DCHECK(!deleted_); | 357 DCHECK(!deleted_); |
328 deleted_ = true; | 358 deleted_ = true; |
329 } | 359 } |
330 | 360 |
331 // Resets the program. | 361 // Resets the program. |
332 void Reset(); | 362 void Reset(); |
333 | 363 |
334 // Updates the program info after a successful link. | 364 // Updates the program info after a successful link. |
335 void Update(); | 365 void Update(); |
366 void UpdateUniforms(); | |
336 void UpdateFragmentInputs(); | 367 void UpdateFragmentInputs(); |
337 | 368 |
338 // Process the program log, replacing the hashed names with original names. | 369 // Process the program log, replacing the hashed names with original names. |
339 std::string ProcessLogInfo(const std::string& log); | 370 std::string ProcessLogInfo(const std::string& log); |
340 | 371 |
341 // Updates the program log info from GL | 372 // Updates the program log info from GL |
342 void UpdateLogInfo(); | 373 void UpdateLogInfo(); |
343 | 374 |
344 // Clears all the uniforms. | 375 // Clears all the uniforms. |
345 void ClearUniforms(std::vector<uint8>* zero_buffer); | 376 void ClearUniforms(std::vector<uint8>* zero_buffer); |
346 | 377 |
347 // If long attribate names are mapped during shader translation, call | 378 // If long attribate names are mapped during shader translation, call |
348 // glBindAttribLocation() again with the mapped names. | 379 // glBindAttribLocation() again with the mapped names. |
349 // This is called right before the glLink() call, but after shaders are | 380 // This is called right before the glLink() call, but after shaders are |
350 // translated. | 381 // translated. |
351 void ExecuteBindAttribLocationCalls(); | 382 void ExecuteBindAttribLocationCalls(); |
352 | 383 |
353 // The names of transform feedback varyings need to be hashed just | 384 // The names of transform feedback varyings need to be hashed just |
354 // like bound attributes' locations, just before the link call. | 385 // like bound attributes' locations, just before the link call. |
355 // Returns false upon failure. | 386 // Returns false upon failure. |
356 bool ExecuteTransformFeedbackVaryingsCall(); | 387 bool ExecuteTransformFeedbackVaryingsCall(); |
357 | 388 |
358 void AddUniformInfo( | |
359 GLsizei size, GLenum type, GLint location, GLint fake_base_location, | |
360 const std::string& name, const std::string& original_name, | |
361 size_t* next_available_index); | |
362 | |
363 // Query uniform data returned by ANGLE translator by the mapped name. | |
364 // Some drivers incorrectly return an uniform name of size-1 array without | |
365 // "[0]". In this case, we correct the name by appending "[0]" to it. | |
366 void GetCorrectedUniformData( | |
367 const std::string& name, | |
368 std::string* corrected_name, std::string* original_name, | |
369 GLsizei* size, GLenum* type) const; | |
370 | |
371 // Query VertexAttrib data returned by ANGLE translator by the mapped name. | 389 // Query VertexAttrib data returned by ANGLE translator by the mapped name. |
372 void GetVertexAttribData( | 390 void GetVertexAttribData( |
373 const std::string& name, std::string* original_name, GLenum* type) const; | 391 const std::string& name, std::string* original_name, GLenum* type) const; |
374 | 392 |
375 void DetachShaders(ShaderManager* manager); | 393 void DetachShaders(ShaderManager* manager); |
376 | 394 |
377 static inline GLint GetUniformInfoIndexFromFakeLocation( | 395 static inline size_t GetUniformLocationIndexFromFakeLocation( |
378 GLint fake_location) { | 396 GLint fake_location) { |
379 return fake_location & 0xFFFF; | 397 return static_cast<size_t>(fake_location & 0xFFFF); |
380 } | 398 } |
381 | 399 |
382 static inline GLint GetArrayElementIndexFromFakeLocation( | 400 static inline size_t GetArrayElementIndexFromFakeLocation( |
383 GLint fake_location) { | 401 GLint fake_location) { |
384 return (fake_location >> 16) & 0xFFFF; | 402 return static_cast<size_t>((fake_location >> 16) & 0xFFFF); |
385 } | 403 } |
386 | 404 |
387 const FeatureInfo& feature_info() const; | 405 const FeatureInfo& feature_info() const; |
388 | 406 |
389 ProgramManager* manager_; | 407 ProgramManager* manager_; |
390 | 408 |
391 int use_count_; | 409 int use_count_; |
392 | 410 |
393 GLsizei max_attrib_name_length_; | 411 GLsizei max_attrib_name_length_; |
394 | 412 |
395 // Attrib by index. | 413 // Attrib by index. |
396 AttribInfoVector attrib_infos_; | 414 AttribInfoVector attrib_infos_; |
397 | 415 |
398 // Attrib by location to index. | 416 // Attrib by location to index. |
399 std::vector<GLint> attrib_location_to_index_map_; | 417 std::vector<GLint> attrib_location_to_index_map_; |
400 | 418 |
401 GLsizei max_uniform_name_length_; | 419 GLsizei max_uniform_name_length_; |
402 | 420 |
403 // Uniform info by index. | 421 // Uniform info by index. |
404 UniformInfoVector uniform_infos_; | 422 UniformInfoVector uniform_infos_; |
423 UniformLocationVector uniform_locations_; | |
405 | 424 |
406 // The indices of the uniforms that are samplers. | 425 // The indices of the uniforms that are samplers. |
407 SamplerIndices sampler_indices_; | 426 SamplerIndices sampler_indices_; |
408 | 427 |
409 FragmentInputInfoVector fragment_input_infos_; | 428 FragmentInputInfoVector fragment_input_infos_; |
410 | 429 |
411 // The program this Program is tracking. | 430 // The program this Program is tracking. |
412 GLuint service_id_; | 431 GLuint service_id_; |
413 | 432 |
414 // Shaders by type of shader. | 433 // Shaders by type of shader. |
415 scoped_refptr<Shader> | 434 scoped_refptr<Shader> |
416 attached_shaders_[kMaxAttachedShaders]; | 435 attached_shaders_[kMaxAttachedShaders]; |
417 | 436 |
418 // True if this program is marked as deleted. | 437 // True if this program is marked as deleted. |
419 bool deleted_; | 438 bool deleted_; |
420 | 439 |
421 // This is true if glLinkProgram was successful at least once. | 440 // This is true if glLinkProgram was successful at least once. |
422 bool valid_; | 441 bool valid_; |
423 | 442 |
424 // This is true if glLinkProgram was successful last time it was called. | 443 // This is true if glLinkProgram was successful last time it was called. |
425 bool link_status_; | 444 bool link_status_; |
426 | 445 |
427 // True if the uniforms have been cleared. | 446 // True if the uniforms have been cleared. |
428 bool uniforms_cleared_; | 447 bool uniforms_cleared_; |
429 | 448 |
430 // This is different than uniform_infos_.size() because | |
431 // that is a sparce array. | |
432 GLint num_uniforms_; | |
433 | |
434 // Log info | 449 // Log info |
435 scoped_ptr<std::string> log_info_; | 450 scoped_ptr<std::string> log_info_; |
436 | 451 |
437 // attribute-location binding map from glBindAttribLocation() calls. | 452 // attribute-location binding map from glBindAttribLocation() calls. |
438 LocationMap bind_attrib_location_map_; | 453 LocationMap bind_attrib_location_map_; |
439 | 454 |
440 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. | 455 // uniform-location binding map from glBindUniformLocationCHROMIUM() calls. |
441 LocationMap bind_uniform_location_map_; | 456 LocationMap bind_uniform_location_map_; |
442 | 457 |
443 std::vector<std::string> transform_feedback_varyings_; | 458 std::vector<std::string> transform_feedback_varyings_; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
532 }; | 547 }; |
533 | 548 |
534 inline const FeatureInfo& Program::feature_info() const { | 549 inline const FeatureInfo& Program::feature_info() const { |
535 return *manager_->feature_info_.get(); | 550 return *manager_->feature_info_.get(); |
536 } | 551 } |
537 | 552 |
538 } // namespace gles2 | 553 } // namespace gles2 |
539 } // namespace gpu | 554 } // namespace gpu |
540 | 555 |
541 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ | 556 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_MANAGER_H_ |
OLD | NEW |