Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: gpu/command_buffer/service/program_manager.cc

Issue 660123002: Detect built-in varyings' invariant setting conflicts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 DCHECK(attached_shaders_[0].get() && 1077 DCHECK(attached_shaders_[0].get() &&
1065 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && 1078 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER &&
1066 attached_shaders_[1].get() && 1079 attached_shaders_[1].get() &&
1067 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); 1080 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER);
1068 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); 1081 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map());
1069 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); 1082 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map());
1070 1083
1071 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); 1084 for (VaryingMap::const_iterator iter = fragment_varyings->begin();
1072 iter != fragment_varyings->end(); ++iter) { 1085 iter != fragment_varyings->end(); ++iter) {
1073 const std::string& name = iter->first; 1086 const std::string& name = iter->first;
1074 if (IsBuiltInVarying(name)) 1087 if (IsBuiltInFragmentVarying(name))
1075 continue; 1088 continue;
1076 1089
1077 VaryingMap::const_iterator hit = vertex_varyings->find(name); 1090 VaryingMap::const_iterator hit = vertex_varyings->find(name);
1078 if (hit == vertex_varyings->end()) { 1091 if (hit == vertex_varyings->end()) {
1079 if (iter->second.staticUse) { 1092 if (iter->second.staticUse) {
1080 *conflicting_name = name; 1093 *conflicting_name = name;
1081 return true; 1094 return true;
1082 } 1095 }
1083 continue; 1096 continue;
1084 } 1097 }
1085 1098
1086 if (!hit->second.isSameVaryingAtLinkTime(iter->second)) { 1099 if (!hit->second.isSameVaryingAtLinkTime(iter->second)) {
1087 *conflicting_name = name; 1100 *conflicting_name = name;
1088 return true; 1101 return true;
1089 } 1102 }
1090 1103
1091 } 1104 }
1092 return false; 1105 return false;
1093 } 1106 }
1094 1107
1108 bool Program::DetectBuiltInInvariantConflicts() const {
1109 DCHECK(attached_shaders_[0].get() &&
1110 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER &&
1111 attached_shaders_[1].get() &&
1112 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER);
1113 const VaryingMap& vertex_varyings = attached_shaders_[0]->varying_map();
1114 const VaryingMap& fragment_varyings = attached_shaders_[1]->varying_map();
1115
1116 bool gl_position_invariant = IsBuiltInInvariant(
1117 vertex_varyings, "gl_Position");
1118 bool gl_point_size_invariant = IsBuiltInInvariant(
1119 vertex_varyings, "gl_PointSize");
1120
1121 bool gl_frag_coord_invariant = IsBuiltInInvariant(
1122 fragment_varyings, "gl_FragCoord");
1123 bool gl_point_coord_invariant = IsBuiltInInvariant(
1124 fragment_varyings, "gl_PointCoord");
1125
1126 return ((gl_frag_coord_invariant && !gl_position_invariant) ||
1127 (gl_point_coord_invariant && !gl_point_size_invariant));
1128 }
1129
1095 bool Program::DetectGlobalNameConflicts(std::string* conflicting_name) const { 1130 bool Program::DetectGlobalNameConflicts(std::string* conflicting_name) const {
1096 DCHECK(attached_shaders_[0].get() && 1131 DCHECK(attached_shaders_[0].get() &&
1097 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && 1132 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER &&
1098 attached_shaders_[1].get() && 1133 attached_shaders_[1].get() &&
1099 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); 1134 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER);
1100 const UniformMap* uniforms[2]; 1135 const UniformMap* uniforms[2];
1101 uniforms[0] = &(attached_shaders_[0]->uniform_map()); 1136 uniforms[0] = &(attached_shaders_[0]->uniform_map());
1102 uniforms[1] = &(attached_shaders_[1]->uniform_map()); 1137 uniforms[1] = &(attached_shaders_[1]->uniform_map());
1103 const AttributeMap* attribs = 1138 const AttributeMap* attribs =
1104 &(attached_shaders_[0]->attrib_map()); 1139 &(attached_shaders_[0]->attrib_map());
(...skipping 18 matching lines...) Expand all
1123 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); 1158 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER);
1124 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map()); 1159 const VaryingMap* vertex_varyings = &(attached_shaders_[0]->varying_map());
1125 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map()); 1160 const VaryingMap* fragment_varyings = &(attached_shaders_[1]->varying_map());
1126 1161
1127 std::map<std::string, ShVariableInfo> combined_map; 1162 std::map<std::string, ShVariableInfo> combined_map;
1128 1163
1129 for (VaryingMap::const_iterator iter = fragment_varyings->begin(); 1164 for (VaryingMap::const_iterator iter = fragment_varyings->begin();
1130 iter != fragment_varyings->end(); ++iter) { 1165 iter != fragment_varyings->end(); ++iter) {
1131 if (!iter->second.staticUse && option == kCountOnlyStaticallyUsed) 1166 if (!iter->second.staticUse && option == kCountOnlyStaticallyUsed)
1132 continue; 1167 continue;
1133 if (!IsBuiltInVarying(iter->first)) { 1168 if (!IsBuiltInFragmentVarying(iter->first)) {
1134 VaryingMap::const_iterator vertex_iter = 1169 VaryingMap::const_iterator vertex_iter =
1135 vertex_varyings->find(iter->first); 1170 vertex_varyings->find(iter->first);
1136 if (vertex_iter == vertex_varyings->end() || 1171 if (vertex_iter == vertex_varyings->end() ||
1137 (!vertex_iter->second.staticUse && 1172 (!vertex_iter->second.staticUse &&
1138 option == kCountOnlyStaticallyUsed)) 1173 option == kCountOnlyStaticallyUsed))
1139 continue; 1174 continue;
1140 } 1175 }
1141 1176
1142 ShVariableInfo var; 1177 ShVariableInfo var;
1143 var.type = static_cast<sh::GLenum>(iter->second.type); 1178 var.type = static_cast<sh::GLenum>(iter->second.type);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 DCHECK(program); 1412 DCHECK(program);
1378 program->ClearUniforms(&zero_); 1413 program->ClearUniforms(&zero_);
1379 } 1414 }
1380 1415
1381 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { 1416 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) {
1382 return index + element * 0x10000; 1417 return index + element * 0x10000;
1383 } 1418 }
1384 1419
1385 } // namespace gles2 1420 } // namespace gles2
1386 } // namespace gpu 1421 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_manager.h ('k') | gpu/command_buffer/service/shader_translator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698