Chromium Code Reviews| 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 #include "gpu/command_buffer/service/program_manager.h" | 5 #include "gpu/command_buffer/service/program_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 } | 486 } |
| 487 #endif | 487 #endif |
| 488 | 488 |
| 489 valid_ = true; | 489 valid_ = true; |
| 490 } | 490 } |
| 491 | 491 |
| 492 void Program::ExecuteBindAttribLocationCalls() { | 492 void Program::ExecuteBindAttribLocationCalls() { |
| 493 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); | 493 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); |
| 494 it != bind_attrib_location_map_.end(); ++it) { | 494 it != bind_attrib_location_map_.end(); ++it) { |
| 495 const std::string* mapped_name = GetAttribMappedName(it->first); | 495 const std::string* mapped_name = GetAttribMappedName(it->first); |
| 496 if (mapped_name && *mapped_name != it->first) | 496 if (mapped_name) |
|
Ken Russell (switch to Gerrit)
2014/10/11 03:29:03
Do you know why this test used to be there and wha
Zhenyao Mo
2014/10/11 04:30:08
It's used to be there because we do call glBindAtt
| |
| 497 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); | 497 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 | 500 |
| 501 bool Program::Link(ShaderManager* manager, | 501 bool Program::Link(ShaderManager* manager, |
| 502 ShaderTranslator* vertex_translator, | 502 ShaderTranslator* vertex_translator, |
| 503 ShaderTranslator* fragment_translator, | 503 ShaderTranslator* fragment_translator, |
| 504 Program::VaryingsPackingOption varyings_packing_option, | 504 Program::VaryingsPackingOption varyings_packing_option, |
| 505 const ShaderCacheCallback& shader_callback) { | 505 const ShaderCacheCallback& shader_callback) { |
| 506 ClearLinkStatus(); | 506 ClearLinkStatus(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 return ProgramManager::MakeFakeLocation( | 648 return ProgramManager::MakeFakeLocation( |
| 649 info.fake_location_base, index); | 649 info.fake_location_base, index); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 return -1; | 654 return -1; |
| 655 } | 655 } |
| 656 | 656 |
| 657 GLint Program::GetAttribLocation( | 657 GLint Program::GetAttribLocation( |
| 658 const std::string& name) const { | 658 const std::string& original_name) const { |
| 659 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { | 659 for (GLuint ii = 0; ii < attrib_infos_.size(); ++ii) { |
| 660 const VertexAttrib& info = attrib_infos_[ii]; | 660 const VertexAttrib& info = attrib_infos_[ii]; |
| 661 if (info.name == name) { | 661 if (info.name == original_name) { |
| 662 return info.location; | 662 return info.location; |
| 663 } | 663 } |
| 664 } | 664 } |
| 665 return -1; | 665 return -1; |
| 666 } | 666 } |
| 667 | 667 |
| 668 const Program::UniformInfo* | 668 const Program::UniformInfo* |
| 669 Program::GetUniformInfoByFakeLocation( | 669 Program::GetUniformInfoByFakeLocation( |
| 670 GLint fake_location, GLint* real_location, GLint* array_index) const { | 670 GLint fake_location, GLint* real_location, GLint* array_index) const { |
| 671 DCHECK(real_location); | 671 DCHECK(real_location); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 return false; | 982 return false; |
| 983 } | 983 } |
| 984 } | 984 } |
| 985 return true; | 985 return true; |
| 986 } | 986 } |
| 987 | 987 |
| 988 bool Program::DetectAttribLocationBindingConflicts() const { | 988 bool Program::DetectAttribLocationBindingConflicts() const { |
| 989 std::set<GLint> location_binding_used; | 989 std::set<GLint> location_binding_used; |
| 990 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); | 990 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); |
| 991 it != bind_attrib_location_map_.end(); ++it) { | 991 it != bind_attrib_location_map_.end(); ++it) { |
| 992 // Find out if an attribute is declared in this program's shaders. | 992 // Find out if an attribute is statically used in this program's shaders. |
| 993 bool active = false; | 993 const sh::Attribute* attrib = NULL; |
| 994 const std::string* mapped_name = GetAttribMappedName(it->first); | |
| 995 if (!mapped_name) | |
| 996 continue; | |
| 994 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { | 997 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { |
| 995 if (!attached_shaders_[ii].get() || !attached_shaders_[ii]->valid()) | 998 if (!attached_shaders_[ii].get() || !attached_shaders_[ii]->valid()) |
| 996 continue; | 999 continue; |
| 997 if (attached_shaders_[ii]->GetAttribInfo(it->first)) { | 1000 attrib = attached_shaders_[ii]->GetAttribInfo(*mapped_name); |
| 998 active = true; | 1001 if (attrib) { |
| 999 break; | 1002 if (attrib->staticUse) |
| 1003 break; | |
| 1004 else | |
| 1005 attrib = NULL; | |
| 1000 } | 1006 } |
| 1001 } | 1007 } |
| 1002 if (active) { | 1008 if (attrib) { |
| 1003 std::pair<std::set<GLint>::iterator, bool> result = | 1009 size_t num_of_locations = 1; |
| 1004 location_binding_used.insert(it->second); | 1010 switch (attrib->type) { |
| 1005 if (!result.second) | 1011 case GL_FLOAT_MAT2: |
| 1006 return true; | 1012 num_of_locations = 2; |
| 1013 break; | |
| 1014 case GL_FLOAT_MAT3: | |
| 1015 num_of_locations = 3; | |
| 1016 break; | |
| 1017 case GL_FLOAT_MAT4: | |
| 1018 num_of_locations = 4; | |
| 1019 break; | |
| 1020 default: | |
| 1021 break; | |
| 1022 } | |
| 1023 for (size_t ii = 0; ii < num_of_locations; ++ii) { | |
| 1024 GLint loc = it->second + ii; | |
| 1025 std::pair<std::set<GLint>::iterator, bool> result = | |
| 1026 location_binding_used.insert(loc); | |
| 1027 if (!result.second) | |
| 1028 return true; | |
| 1029 } | |
| 1007 } | 1030 } |
| 1008 } | 1031 } |
| 1009 return false; | 1032 return false; |
| 1010 } | 1033 } |
| 1011 | 1034 |
| 1012 bool Program::DetectUniformsMismatch(std::string* conflicting_name) const { | 1035 bool Program::DetectUniformsMismatch(std::string* conflicting_name) const { |
| 1013 typedef std::map<std::string, const sh::Uniform*> UniformPointerMap; | 1036 typedef std::map<std::string, const sh::Uniform*> UniformPointerMap; |
| 1014 UniformPointerMap uniform_pointer_map; | 1037 UniformPointerMap uniform_pointer_map; |
| 1015 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { | 1038 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { |
| 1016 const UniformMap& shader_uniforms = attached_shaders_[ii]->uniform_map(); | 1039 const UniformMap& shader_uniforms = attached_shaders_[ii]->uniform_map(); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 DCHECK(program); | 1373 DCHECK(program); |
| 1351 program->ClearUniforms(&zero_); | 1374 program->ClearUniforms(&zero_); |
| 1352 } | 1375 } |
| 1353 | 1376 |
| 1354 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1377 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
| 1355 return index + element * 0x10000; | 1378 return index + element * 0x10000; |
| 1356 } | 1379 } |
| 1357 | 1380 |
| 1358 } // namespace gles2 | 1381 } // namespace gles2 |
| 1359 } // namespace gpu | 1382 } // namespace gpu |
| OLD | NEW |