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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 | 269 |
| 270 void Program::Reset() { | 270 void Program::Reset() { |
| 271 valid_ = false; | 271 valid_ = false; |
| 272 link_status_ = false; | 272 link_status_ = false; |
| 273 max_uniform_name_length_ = 0; | 273 max_uniform_name_length_ = 0; |
| 274 max_attrib_name_length_ = 0; | 274 max_attrib_name_length_ = 0; |
| 275 attrib_infos_.clear(); | 275 attrib_infos_.clear(); |
| 276 uniform_infos_.clear(); | 276 uniform_infos_.clear(); |
| 277 uniform_locations_.clear(); | 277 uniform_locations_.clear(); |
| 278 fragment_input_infos_.clear(); | 278 fragment_input_infos_.clear(); |
| 279 fragment_input_locations_.clear(); | |
| 279 sampler_indices_.clear(); | 280 sampler_indices_.clear(); |
| 280 attrib_location_to_index_map_.clear(); | 281 attrib_location_to_index_map_.clear(); |
| 281 } | 282 } |
| 282 | 283 |
| 283 std::string Program::ProcessLogInfo( | 284 std::string Program::ProcessLogInfo( |
| 284 const std::string& log) { | 285 const std::string& log) { |
| 285 std::string output; | 286 std::string output; |
| 286 re2::StringPiece input(log); | 287 re2::StringPiece input(log); |
| 287 std::string prior_log; | 288 std::string prior_log; |
| 288 std::string hashed_name; | 289 std::string hashed_name; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 uniform_locations_[client_location_base].SetActive(&info); | 655 uniform_locations_[client_location_base].SetActive(&info); |
| 655 | 656 |
| 656 max_uniform_name_length_ = std::max(max_uniform_name_length_, | 657 max_uniform_name_length_ = std::max(max_uniform_name_length_, |
| 657 static_cast<GLsizei>(info.name.size())); | 658 static_cast<GLsizei>(info.name.size())); |
| 658 } | 659 } |
| 659 } | 660 } |
| 660 | 661 |
| 661 void Program::UpdateFragmentInputs() { | 662 void Program::UpdateFragmentInputs() { |
| 662 if (!feature_info().feature_flags().chromium_path_rendering) | 663 if (!feature_info().feature_flags().chromium_path_rendering) |
| 663 return; | 664 return; |
| 665 for (const auto& binding : bind_fragment_input_location_map_) { | |
| 666 if (binding.second < 0) | |
| 667 continue; | |
| 668 size_t client_location = static_cast<size_t>(binding.second); | |
| 669 if (fragment_input_locations_.size() <= client_location) | |
| 670 fragment_input_locations_.resize(client_location + 1); | |
| 671 fragment_input_locations_[client_location].SetInactive(); | |
| 672 } | |
| 673 | |
| 664 GLint num_fragment_inputs = 0; | 674 GLint num_fragment_inputs = 0; |
| 665 glGetProgramInterfaceiv(service_id_, GL_FRAGMENT_INPUT_NV, | 675 glGetProgramInterfaceiv(service_id_, GL_FRAGMENT_INPUT_NV, |
| 666 GL_ACTIVE_RESOURCES, &num_fragment_inputs); | 676 GL_ACTIVE_RESOURCES, &num_fragment_inputs); |
| 667 if (num_fragment_inputs <= 0) | 677 if (num_fragment_inputs <= 0) |
| 668 return; | 678 return; |
| 679 | |
| 669 GLint max_len = 0; | 680 GLint max_len = 0; |
| 670 glGetProgramInterfaceiv(service_id_, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH, | 681 glGetProgramInterfaceiv(service_id_, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH, |
| 671 &max_len); | 682 &max_len); |
| 672 DCHECK(max_len > 0); | 683 DCHECK(max_len > 0); |
| 673 | 684 |
| 674 scoped_ptr<char[]> name_buffer(new char[max_len]); | 685 scoped_ptr<char[]> name_buffer(new char[max_len]); |
| 675 | 686 |
| 676 Shader* fragment_shader = | 687 Shader* fragment_shader = |
| 677 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); | 688 attached_shaders_[ShaderTypeToIndex(GL_FRAGMENT_SHADER)].get(); |
| 678 | 689 |
| 679 const GLenum kQueryProperties[] = {GL_LOCATION, GL_TYPE, GL_ARRAY_SIZE}; | 690 const GLenum kQueryProperties[] = {GL_LOCATION, GL_TYPE, GL_ARRAY_SIZE}; |
| 680 | 691 |
| 692 std::vector<size_t> client_location_indices; | |
| 681 for (GLint ii = 0; ii < num_fragment_inputs; ++ii) { | 693 for (GLint ii = 0; ii < num_fragment_inputs; ++ii) { |
| 682 GLsizei name_length = 0; | 694 GLsizei name_length = 0; |
| 683 glGetProgramResourceName(service_id_, GL_FRAGMENT_INPUT_NV, ii, max_len, | 695 glGetProgramResourceName(service_id_, GL_FRAGMENT_INPUT_NV, ii, max_len, |
| 684 &name_length, name_buffer.get()); | 696 &name_length, name_buffer.get()); |
| 685 DCHECK(name_length < max_len); | 697 DCHECK(name_length < max_len); |
| 686 DCHECK(name_length == 0 || name_buffer[name_length] == '\0'); | 698 DCHECK(name_length == 0 || name_buffer[name_length] == '\0'); |
| 687 // A fragment shader can have gl_FragCoord, gl_FrontFacing or gl_PointCoord | 699 // A fragment shader can have gl_FragCoord, gl_FrontFacing or gl_PointCoord |
| 688 // built-ins as its input, as well as custom varyings. We are interested in | 700 // built-ins as its input, as well as custom varyings. We are interested in |
| 689 // custom varyings, client is allowed to bind only them. | 701 // custom varyings, client is allowed to bind only them. |
| 690 if (ProgramManager::IsInvalidPrefix(name_buffer.get(), name_length)) | 702 if (ProgramManager::IsInvalidPrefix(name_buffer.get(), name_length)) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 719 client_name = service_name; | 731 client_name = service_name; |
| 720 if (size <= 0) | 732 if (size <= 0) |
| 721 continue; | 733 continue; |
| 722 } | 734 } |
| 723 | 735 |
| 724 auto it = bind_fragment_input_location_map_.find(client_name); | 736 auto it = bind_fragment_input_location_map_.find(client_name); |
| 725 if (it != bind_fragment_input_location_map_.end() && it->second >= 0 && | 737 if (it != bind_fragment_input_location_map_.end() && it->second >= 0 && |
| 726 query_results[0] >= 0) { | 738 query_results[0] >= 0) { |
| 727 size_t client_location = static_cast<size_t>(it->second); | 739 size_t client_location = static_cast<size_t>(it->second); |
| 728 GLuint service_location = static_cast<GLuint>(query_results[0]); | 740 GLuint service_location = static_cast<GLuint>(query_results[0]); |
| 729 | 741 fragment_input_infos_.push_back( |
| 730 if (fragment_input_infos_.size() <= client_location) | 742 FragmentInputInfo(type, service_location)); |
| 731 fragment_input_infos_.resize(client_location + 1); | 743 client_location_indices.push_back(client_location); |
| 732 DCHECK(!fragment_input_infos_[client_location].IsValid()); | |
| 733 fragment_input_infos_[client_location] = | |
| 734 FragmentInputInfo(type, service_location); | |
| 735 } | 744 } |
| 736 | 745 |
| 737 if (size <= 1) | 746 if (size <= 1) |
| 738 continue; | 747 continue; |
| 739 GLSLArrayName parsed_client_name(client_name); | 748 GLSLArrayName parsed_client_name(client_name); |
| 740 GLSLArrayName parsed_service_name(service_name); | 749 GLSLArrayName parsed_service_name(service_name); |
| 741 if (!parsed_client_name.IsArrayName() || | 750 if (!parsed_client_name.IsArrayName() || |
| 742 parsed_client_name.element_index() != 0 || | 751 parsed_client_name.element_index() != 0 || |
| 743 !parsed_service_name.IsArrayName() || | 752 !parsed_service_name.IsArrayName() || |
| 744 parsed_service_name.element_index() != 0) { | 753 parsed_service_name.element_index() != 0) { |
| 745 NOTREACHED() << "GLSL array variable names should end with \"[0]\". " | 754 NOTREACHED() << "GLSL array variable names should end with \"[0]\". " |
| 746 "Likely driver or ANGLE error."; | 755 "Likely driver or ANGLE error."; |
| 747 continue; | 756 continue; |
| 748 } | 757 } |
| 749 | 758 |
| 750 for (GLsizei jj = 1; jj < size; ++jj) { | 759 for (GLsizei jj = 1; jj < size; ++jj) { |
| 751 std::string array_spec(std::string("[") + base::IntToString(jj) + "]"); | 760 std::string array_spec(std::string("[") + base::IntToString(jj) + "]"); |
| 752 std::string client_element_name = | 761 std::string client_element_name = |
| 753 parsed_client_name.base_name() + array_spec; | 762 parsed_client_name.base_name() + array_spec; |
| 754 | 763 |
| 755 auto it = bind_fragment_input_location_map_.find(client_element_name); | 764 auto it = bind_fragment_input_location_map_.find(client_element_name); |
| 756 if (it != bind_fragment_input_location_map_.end() && it->second >= 0) { | 765 if (it != bind_fragment_input_location_map_.end() && it->second >= 0) { |
| 757 size_t client_location = static_cast<size_t>(it->second); | 766 size_t client_location = static_cast<size_t>(it->second); |
| 758 std::string service_element_name = | 767 std::string service_element_name = |
| 759 parsed_service_name.base_name() + array_spec; | 768 parsed_service_name.base_name() + array_spec; |
| 760 GLint service_location = glGetProgramResourceLocation( | 769 GLint service_location = glGetProgramResourceLocation( |
| 761 service_id_, GL_FRAGMENT_INPUT_NV, service_element_name.c_str()); | 770 service_id_, GL_FRAGMENT_INPUT_NV, service_element_name.c_str()); |
| 762 if (service_location >= 0) { | 771 if (service_location >= 0) { |
| 763 if (fragment_input_infos_.size() <= client_location) | 772 fragment_input_infos_.push_back( |
| 764 fragment_input_infos_.resize(client_location + 1); | 773 FragmentInputInfo(type, static_cast<GLuint>(service_location))); |
| 765 DCHECK(!fragment_input_infos_[client_location].IsValid()); | 774 client_location_indices.push_back(client_location); |
| 766 fragment_input_infos_[client_location] = | |
| 767 FragmentInputInfo(type, static_cast<GLuint>(service_location)); | |
| 768 } | 775 } |
| 769 } | 776 } |
| 770 } | 777 } |
| 771 } | 778 } |
| 779 for (size_t i = 0; i < client_location_indices.size(); ++i) { | |
| 780 size_t client_location = client_location_indices[i]; | |
| 781 DCHECK(!fragment_input_locations_[client_location].IsActive()); | |
|
zmo
2015/11/20 00:24:50
Add a comment that we already did the conflict det
Kimmo Kinnunen
2015/11/20 08:19:29
Done.
| |
| 782 fragment_input_locations_[client_location].SetActive( | |
| 783 &fragment_input_infos_[i]); | |
| 784 } | |
| 772 } | 785 } |
| 773 | 786 |
| 774 void Program::ExecuteBindAttribLocationCalls() { | 787 void Program::ExecuteBindAttribLocationCalls() { |
| 775 for (const auto& key_value : bind_attrib_location_map_) { | 788 for (const auto& key_value : bind_attrib_location_map_) { |
| 776 const std::string* mapped_name = GetAttribMappedName(key_value.first); | 789 const std::string* mapped_name = GetAttribMappedName(key_value.first); |
| 777 if (mapped_name) | 790 if (mapped_name) |
| 778 glBindAttribLocation(service_id_, key_value.second, mapped_name->c_str()); | 791 glBindAttribLocation(service_id_, key_value.second, mapped_name->c_str()); |
| 779 } | 792 } |
| 780 } | 793 } |
| 781 | 794 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1010 if (fake_location < 0) | 1023 if (fake_location < 0) |
| 1011 return nullptr; | 1024 return nullptr; |
| 1012 size_t location_index = | 1025 size_t location_index = |
| 1013 GetUniformLocationIndexFromFakeLocation(fake_location); | 1026 GetUniformLocationIndexFromFakeLocation(fake_location); |
| 1014 if (location_index >= uniform_locations_.size()) | 1027 if (location_index >= uniform_locations_.size()) |
| 1015 return nullptr; | 1028 return nullptr; |
| 1016 | 1029 |
| 1017 if (!uniform_locations_[location_index].IsActive()) | 1030 if (!uniform_locations_[location_index].IsActive()) |
| 1018 return nullptr; | 1031 return nullptr; |
| 1019 | 1032 |
| 1020 const UniformInfo* info = uniform_locations_[location_index].uniform(); | 1033 const UniformInfo* info = |
| 1034 uniform_locations_[location_index].shader_variable(); | |
| 1021 size_t element_index = GetArrayElementIndexFromFakeLocation(fake_location); | 1035 size_t element_index = GetArrayElementIndexFromFakeLocation(fake_location); |
| 1022 if (static_cast<GLsizei>(element_index) >= info->size) | 1036 if (static_cast<GLsizei>(element_index) >= info->size) |
| 1023 return nullptr; | 1037 return nullptr; |
| 1024 *real_location = info->element_locations[element_index]; | 1038 *real_location = info->element_locations[element_index]; |
| 1025 *array_index = element_index; | 1039 *array_index = element_index; |
| 1026 return info; | 1040 return info; |
| 1027 } | 1041 } |
| 1028 | 1042 |
| 1029 bool Program::IsInactiveUniformLocationByFakeLocation( | 1043 bool Program::IsInactiveUniformLocationByFakeLocation( |
| 1030 GLint fake_location) const { | 1044 GLint fake_location) const { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 shader->GetOriginalNameFromHashedName(hashed_name); | 1085 shader->GetOriginalNameFromHashedName(hashed_name); |
| 1072 if (original_name) | 1086 if (original_name) |
| 1073 return original_name; | 1087 return original_name; |
| 1074 } | 1088 } |
| 1075 } | 1089 } |
| 1076 return nullptr; | 1090 return nullptr; |
| 1077 } | 1091 } |
| 1078 | 1092 |
| 1079 const Program::FragmentInputInfo* Program::GetFragmentInputInfoByFakeLocation( | 1093 const Program::FragmentInputInfo* Program::GetFragmentInputInfoByFakeLocation( |
| 1080 GLint fake_location) const { | 1094 GLint fake_location) const { |
| 1081 if (fake_location < 0 || | 1095 if (fake_location < 0) |
| 1082 static_cast<size_t>(fake_location) >= fragment_input_infos_.size()) | |
| 1083 return nullptr; | 1096 return nullptr; |
| 1084 const FragmentInputInfo* info = &fragment_input_infos_[fake_location]; | 1097 size_t location_index = static_cast<size_t>(fake_location); |
| 1085 if (!info->IsValid()) | 1098 if (location_index >= fragment_input_locations_.size()) |
| 1086 return nullptr; | 1099 return nullptr; |
| 1087 return info; | 1100 if (!fragment_input_locations_[location_index].IsActive()) |
| 1101 return nullptr; | |
| 1102 return fragment_input_locations_[location_index].shader_variable(); | |
| 1103 } | |
| 1104 | |
| 1105 bool Program::IsInactiveFragmentInputLocationByFakeLocation( | |
| 1106 GLint fake_location) const { | |
| 1107 if (fake_location < 0) | |
| 1108 return true; | |
| 1109 size_t location_index = static_cast<size_t>(fake_location); | |
| 1110 if (location_index >= fragment_input_locations_.size()) | |
| 1111 return false; | |
|
zmo
2015/11/20 00:24:50
Sam question as in the other uniform location CL:
Kimmo Kinnunen
2015/11/20 08:19:29
The function returns true only for locations of in
| |
| 1112 return fragment_input_locations_[location_index].IsInactive(); | |
| 1088 } | 1113 } |
| 1089 | 1114 |
| 1090 bool Program::SetUniformLocationBinding( | 1115 bool Program::SetUniformLocationBinding( |
| 1091 const std::string& name, GLint location) { | 1116 const std::string& name, GLint location) { |
| 1092 std::string short_name; | 1117 std::string short_name; |
| 1093 int element_index = 0; | 1118 int element_index = 0; |
| 1094 if (!GetUniformNameSansElement(name, &element_index, &short_name) || | 1119 if (!GetUniformNameSansElement(name, &element_index, &short_name) || |
| 1095 element_index != 0) { | 1120 element_index != 0) { |
| 1096 return false; | 1121 return false; |
| 1097 } | 1122 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 return true; | 1176 return true; |
| 1152 } | 1177 } |
| 1153 size_t location_index = | 1178 size_t location_index = |
| 1154 GetUniformLocationIndexFromFakeLocation(fake_location); | 1179 GetUniformLocationIndexFromFakeLocation(fake_location); |
| 1155 if (location_index >= uniform_infos_.size()) | 1180 if (location_index >= uniform_infos_.size()) |
| 1156 return false; | 1181 return false; |
| 1157 | 1182 |
| 1158 if (!uniform_locations_[location_index].IsActive()) | 1183 if (!uniform_locations_[location_index].IsActive()) |
| 1159 return false; | 1184 return false; |
| 1160 | 1185 |
| 1161 UniformInfo* info = uniform_locations_[location_index].uniform(); | 1186 UniformInfo* info = uniform_locations_[location_index].shader_variable(); |
| 1162 | 1187 |
| 1163 size_t element_index = GetArrayElementIndexFromFakeLocation(fake_location); | 1188 size_t element_index = GetArrayElementIndexFromFakeLocation(fake_location); |
| 1164 if (static_cast<GLsizei>(element_index) >= info->size) | 1189 if (static_cast<GLsizei>(element_index) >= info->size) |
| 1165 return true; | 1190 return true; |
| 1166 count = std::min(info->size - static_cast<GLsizei>(element_index), count); | 1191 count = std::min(info->size - static_cast<GLsizei>(element_index), count); |
| 1167 if (info->IsSampler() && count > 0) { | 1192 if (info->IsSampler() && count > 0) { |
| 1168 for (GLsizei ii = 0; ii < count; ++ii) { | 1193 for (GLsizei ii = 0; ii < count; ++ii) { |
| 1169 if (value[ii] < 0 || value[ii] >= num_texture_units) { | 1194 if (value[ii] < 0 || value[ii] >= num_texture_units) { |
| 1170 return false; | 1195 return false; |
| 1171 } | 1196 } |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2057 DCHECK(program); | 2082 DCHECK(program); |
| 2058 program->ClearUniforms(&zero_); | 2083 program->ClearUniforms(&zero_); |
| 2059 } | 2084 } |
| 2060 | 2085 |
| 2061 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 2086 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
| 2062 return index + element * 0x10000; | 2087 return index + element * 0x10000; |
| 2063 } | 2088 } |
| 2064 | 2089 |
| 2065 } // namespace gles2 | 2090 } // namespace gles2 |
| 2066 } // namespace gpu | 2091 } // namespace gpu |
| OLD | NEW |