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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 return false; | 74 return false; |
75 } | 75 } |
76 index = index * 10 + digit; | 76 index = index * 10 + digit; |
77 } | 77 } |
78 | 78 |
79 *element_index = index; | 79 *element_index = index; |
80 *new_name = name.substr(0, open_pos); | 80 *new_name = name.substr(0, open_pos); |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 bool IsBuiltInVarying(const std::string& name) { | 84 bool IsBuiltInFragmentVarying(const std::string& name) { |
85 // Built-in variables. | 85 // Built-in variables for fragment shaders. |
86 const char* kBuiltInVaryings[] = { | 86 const char* kBuiltInVaryings[] = { |
87 "gl_FragCoord", | 87 "gl_FragCoord", |
88 "gl_FrontFacing", | 88 "gl_FrontFacing", |
89 "gl_PointCoord" | 89 "gl_PointCoord" |
90 }; | 90 }; |
91 for (size_t ii = 0; ii < arraysize(kBuiltInVaryings); ++ii) { | 91 for (size_t ii = 0; ii < arraysize(kBuiltInVaryings); ++ii) { |
92 if (name == kBuiltInVaryings[ii]) | 92 if (name == kBuiltInVaryings[ii]) |
93 return true; | 93 return true; |
94 } | 94 } |
95 return false; | 95 return false; |
96 } | 96 } |
97 | 97 |
98 bool IsBuiltInInvariant( | |
99 const VaryingMap& varyings, const std::string& name) { | |
100 VaryingMap::const_iterator hit = varyings.find(name); | |
101 if (hit == varyings.end()) | |
102 return false; | |
103 return hit->second.isInvariant; | |
104 } | |
105 | |
98 } // anonymous namespace. | 106 } // anonymous namespace. |
99 | 107 |
100 Program::UniformInfo::UniformInfo() | 108 Program::UniformInfo::UniformInfo() |
101 : size(0), | 109 : size(0), |
102 type(GL_NONE), | 110 type(GL_NONE), |
103 fake_location_base(0), | 111 fake_location_base(0), |
104 is_array(false) { | 112 is_array(false) { |
105 } | 113 } |
106 | 114 |
107 Program::UniformInfo::UniformInfo(GLsizei _size, | 115 Program::UniformInfo::UniformInfo(GLsizei _size, |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 set_log_info(ProcessLogInfo(info_log).c_str()); | 527 set_log_info(ProcessLogInfo(info_log).c_str()); |
520 return false; | 528 return false; |
521 } | 529 } |
522 if (DetectVaryingsMismatch(&conflicting_name)) { | 530 if (DetectVaryingsMismatch(&conflicting_name)) { |
523 std::string info_log = "Varyings with the same name but different type, " | 531 std::string info_log = "Varyings with the same name but different type, " |
524 "or statically used varyings in fragment shader are " | 532 "or statically used varyings in fragment shader are " |
525 "not declared in vertex shader: " + conflicting_name; | 533 "not declared in vertex shader: " + conflicting_name; |
526 set_log_info(ProcessLogInfo(info_log).c_str()); | 534 set_log_info(ProcessLogInfo(info_log).c_str()); |
527 return false; | 535 return false; |
528 } | 536 } |
537 if (DetectBuiltInInvariantConflicts()) { | |
538 set_log_info("Invariant settings for certain built-in varyings " | |
539 "have to match"); | |
540 return false; | |
541 } | |
529 if (DetectGlobalNameConflicts(&conflicting_name)) { | 542 if (DetectGlobalNameConflicts(&conflicting_name)) { |
530 std::string info_log = "Name conflicts between an uniform and an " | 543 std::string info_log = "Name conflicts between an uniform and an " |
531 "attribute: " + conflicting_name; | 544 "attribute: " + conflicting_name; |
532 set_log_info(ProcessLogInfo(info_log).c_str()); | 545 set_log_info(ProcessLogInfo(info_log).c_str()); |
533 return false; | 546 return false; |
534 } | 547 } |
535 if (!CheckVaryingsPacking(varyings_packing_option)) { | 548 if (!CheckVaryingsPacking(varyings_packing_option)) { |
536 set_log_info("Varyings over maximum register limit"); | 549 set_log_info("Varyings over maximum register limit"); |
537 return false; | 550 return false; |
538 } | 551 } |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 DCHECK(attached_shaders_[0].get() && | 1073 DCHECK(attached_shaders_[0].get() && |
1061 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | 1074 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && |
1062 attached_shaders_[1].get() && | 1075 attached_shaders_[1].get() && |
1063 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1076 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
1064 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); | 1077 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); |
1065 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); | 1078 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); |
1066 | 1079 |
1067 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); | 1080 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); |
1068 iter != fragment_varyings->end(); ++iter) { | 1081 iter != fragment_varyings->end(); ++iter) { |
1069 const std::string& name = iter->first; | 1082 const std::string& name = iter->first; |
1070 if (IsBuiltInVarying(name)) | 1083 if (IsBuiltInFragmentVarying(name)) |
1071 continue; | 1084 continue; |
1072 | 1085 |
1073 VaryingMap::const_iterator hit = vertex_varyings->find(name); | 1086 VaryingMap::const_iterator hit = vertex_varyings->find(name); |
1074 if (hit == vertex_varyings->end()) { | 1087 if (hit == vertex_varyings->end()) { |
1075 if (iter->second.staticUse) { | 1088 if (iter->second.staticUse) { |
1076 *conflicting_name = name; | 1089 *conflicting_name = name; |
1077 return true; | 1090 return true; |
1078 } | 1091 } |
1079 continue; | 1092 continue; |
1080 } | 1093 } |
1081 | 1094 |
1082 if (!hit->second.isSameVaryingAtLinkTime(iter->second)) { | 1095 if (!hit->second.isSameVaryingAtLinkTime(iter->second)) { |
1083 *conflicting_name = name; | 1096 *conflicting_name = name; |
1084 return true; | 1097 return true; |
1085 } | 1098 } |
1086 | 1099 |
1087 } | 1100 } |
1088 return false; | 1101 return false; |
1089 } | 1102 } |
1090 | 1103 |
1104 bool Program::DetectBuiltInInvariantConflicts() const { | |
1105 DCHECK(attached_shaders_[0].get() && | |
1106 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | |
1107 attached_shaders_[1].get() && | |
1108 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | |
1109 const VaryingMap& vertex_varyings = attached_shaders_[0]->varying_map(); | |
1110 const VaryingMap& fragment_varyings = attached_shaders_[1]->varying_map(); | |
1111 | |
1112 bool gl_position_invariant = IsBuiltInInvariant( | |
1113 vertex_varyings, "gl_Position"); | |
1114 bool gl_point_size_invariant = IsBuiltInInvariant( | |
1115 vertex_varyings, "gl_PointSize"); | |
1116 | |
1117 bool gl_frag_coord_invariant = IsBuiltInInvariant( | |
1118 fragment_varyings, "gl_FragCoord");; | |
bajones
2014/10/16 22:12:18
Extra ";" at the line end here.
Zhenyao Mo
2014/10/16 22:14:11
Done.
| |
1119 bool gl_point_coord_invariant = IsBuiltInInvariant( | |
1120 fragment_varyings, "gl_PointCoord"); | |
1121 | |
1122 return ((gl_frag_coord_invariant && !gl_position_invariant) || | |
1123 (gl_point_coord_invariant && !gl_point_size_invariant)); | |
1124 } | |
1125 | |
1091 bool Program::DetectGlobalNameConflicts(std::string* conflicting_name) const { | 1126 bool Program::DetectGlobalNameConflicts(std::string* conflicting_name) const { |
1092 DCHECK(attached_shaders_[0].get() && | 1127 DCHECK(attached_shaders_[0].get() && |
1093 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | 1128 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && |
1094 attached_shaders_[1].get() && | 1129 attached_shaders_[1].get() && |
1095 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1130 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
1096 const UniformMap* uniforms[2]; | 1131 const UniformMap* uniforms[2]; |
1097 uniforms[0] = &(attached_shaders_[0]->uniform_map()); | 1132 uniforms[0] = &(attached_shaders_[0]->uniform_map()); |
1098 uniforms[1] = &(attached_shaders_[1]->uniform_map()); | 1133 uniforms[1] = &(attached_shaders_[1]->uniform_map()); |
1099 const AttributeMap* attribs = | 1134 const AttributeMap* attribs = |
1100 &(attached_shaders_[0]->attrib_map()); | 1135 &(attached_shaders_[0]->attrib_map()); |
(...skipping 18 matching lines...) Expand all Loading... | |
1119 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1154 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
1120 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); | 1155 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); |
1121 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); | 1156 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); |
1122 | 1157 |
1123 std::map<std::string, ShVariableInfo> combined_map; | 1158 std::map<std::string, ShVariableInfo> combined_map; |
1124 | 1159 |
1125 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); | 1160 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); |
1126 iter != fragment_varyings->end(); ++iter) { | 1161 iter != fragment_varyings->end(); ++iter) { |
1127 if (!iter->second.staticUse && option == kCountOnlyStaticallyUsed) | 1162 if (!iter->second.staticUse && option == kCountOnlyStaticallyUsed) |
1128 continue; | 1163 continue; |
1129 if (!IsBuiltInVarying(iter->first)) { | 1164 if (!IsBuiltInFragmentVarying(iter->first)) { |
1130 VaryingMap::const_iterator vertex_iter = | 1165 VaryingMap::const_iterator vertex_iter = |
1131 vertex_varyings->find(iter->first); | 1166 vertex_varyings->find(iter->first); |
1132 if (vertex_iter == vertex_varyings->end() || | 1167 if (vertex_iter == vertex_varyings->end() || |
1133 (!vertex_iter->second.staticUse && | 1168 (!vertex_iter->second.staticUse && |
1134 option == kCountOnlyStaticallyUsed)) | 1169 option == kCountOnlyStaticallyUsed)) |
1135 continue; | 1170 continue; |
1136 } | 1171 } |
1137 | 1172 |
1138 ShVariableInfo var; | 1173 ShVariableInfo var; |
1139 var.type = static_cast<sh::GLenum>(iter->second.type); | 1174 var.type = static_cast<sh::GLenum>(iter->second.type); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1373 DCHECK(program); | 1408 DCHECK(program); |
1374 program->ClearUniforms(&zero_); | 1409 program->ClearUniforms(&zero_); |
1375 } | 1410 } |
1376 | 1411 |
1377 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1412 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1378 return index + element * 0x10000; | 1413 return index + element * 0x10000; |
1379 } | 1414 } |
1380 | 1415 |
1381 } // namespace gles2 | 1416 } // namespace gles2 |
1382 } // namespace gpu | 1417 } // namespace gpu |
OLD | NEW |