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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 attrib_location_to_index_map_.clear(); | 173 attrib_location_to_index_map_.clear(); |
174 } | 174 } |
175 | 175 |
176 std::string Program::ProcessLogInfo( | 176 std::string Program::ProcessLogInfo( |
177 const std::string& log) { | 177 const std::string& log) { |
178 std::string output; | 178 std::string output; |
179 re2::StringPiece input(log); | 179 re2::StringPiece input(log); |
180 std::string prior_log; | 180 std::string prior_log; |
181 std::string hashed_name; | 181 std::string hashed_name; |
182 while (RE2::Consume(&input, | 182 while (RE2::Consume(&input, |
183 "(.*)(webgl_[0123456789abcdefABCDEF]+)", | 183 "(.*?)(webgl_[0123456789abcdefABCDEF]+)", |
184 &prior_log, | 184 &prior_log, |
185 &hashed_name)) { | 185 &hashed_name)) { |
186 output += prior_log; | 186 output += prior_log; |
187 | 187 |
188 const std::string* original_name = | 188 const std::string* original_name = |
189 GetOriginalNameFromHashedName(hashed_name); | 189 GetOriginalNameFromHashedName(hashed_name); |
190 if (original_name) | 190 if (original_name) |
191 output += *original_name; | 191 output += *original_name; |
192 else | 192 else |
193 output += hashed_name; | 193 output += hashed_name; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 attrib_location_to_index_map_[ii] = -1; | 351 attrib_location_to_index_map_[ii] = -1; |
352 } | 352 } |
353 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { | 353 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { |
354 const VertexAttrib& info = attrib_infos_[ii]; | 354 const VertexAttrib& info = attrib_infos_[ii]; |
355 attrib_location_to_index_map_[info.location] = ii; | 355 attrib_location_to_index_map_[info.location] = ii; |
356 } | 356 } |
357 | 357 |
358 #if !defined(NDEBUG) | 358 #if !defined(NDEBUG) |
359 if (CommandLine::ForCurrentProcess()->HasSwitch( | 359 if (CommandLine::ForCurrentProcess()->HasSwitch( |
360 switches::kEnableGPUServiceLoggingGPU)) { | 360 switches::kEnableGPUServiceLoggingGPU)) { |
361 DLOG(INFO) << "----: attribs for service_id: " << service_id(); | 361 DVLOG(1) << "----: attribs for service_id: " << service_id(); |
362 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { | 362 for (size_t ii = 0; ii < attrib_infos_.size(); ++ii) { |
363 const VertexAttrib& info = attrib_infos_[ii]; | 363 const VertexAttrib& info = attrib_infos_[ii]; |
364 DLOG(INFO) << ii << ": loc = " << info.location | 364 DVLOG(1) << ii << ": loc = " << info.location |
365 << ", size = " << info.size | 365 << ", size = " << info.size |
366 << ", type = " << GLES2Util::GetStringEnum(info.type) | 366 << ", type = " << GLES2Util::GetStringEnum(info.type) |
367 << ", name = " << info.name; | 367 << ", name = " << info.name; |
368 } | 368 } |
369 } | 369 } |
370 #endif | 370 #endif |
371 | 371 |
372 max_len = 0; | 372 max_len = 0; |
373 GLint num_uniforms = 0; | 373 GLint num_uniforms = 0; |
374 glGetProgramiv(service_id_, GL_ACTIVE_UNIFORMS, &num_uniforms); | 374 glGetProgramiv(service_id_, GL_ACTIVE_UNIFORMS, &num_uniforms); |
375 glGetProgramiv(service_id_, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_len); | 375 glGetProgramiv(service_id_, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_len); |
376 name_buffer.reset(new char[max_len]); | 376 name_buffer.reset(new char[max_len]); |
377 | 377 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 if (!data.added) { | 429 if (!data.added) { |
430 AddUniformInfo( | 430 AddUniformInfo( |
431 data.size, data.type, data.location, -1, data.corrected_name, | 431 data.size, data.type, data.location, -1, data.corrected_name, |
432 data.original_name, &next_available_index); | 432 data.original_name, &next_available_index); |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 #if !defined(NDEBUG) | 436 #if !defined(NDEBUG) |
437 if (CommandLine::ForCurrentProcess()->HasSwitch( | 437 if (CommandLine::ForCurrentProcess()->HasSwitch( |
438 switches::kEnableGPUServiceLoggingGPU)) { | 438 switches::kEnableGPUServiceLoggingGPU)) { |
439 DLOG(INFO) << "----: uniforms for service_id: " << service_id(); | 439 DVLOG(1) << "----: uniforms for service_id: " << service_id(); |
440 for (size_t ii = 0; ii < uniform_infos_.size(); ++ii) { | 440 for (size_t ii = 0; ii < uniform_infos_.size(); ++ii) { |
441 const UniformInfo& info = uniform_infos_[ii]; | 441 const UniformInfo& info = uniform_infos_[ii]; |
442 if (info.IsValid()) { | 442 if (info.IsValid()) { |
443 DLOG(INFO) << ii << ": loc = " << info.element_locations[0] | 443 DVLOG(1) << ii << ": loc = " << info.element_locations[0] |
444 << ", size = " << info.size | 444 << ", size = " << info.size |
445 << ", type = " << GLES2Util::GetStringEnum(info.type) | 445 << ", type = " << GLES2Util::GetStringEnum(info.type) |
446 << ", name = " << info.name; | 446 << ", name = " << info.name; |
447 } | 447 } |
448 } | 448 } |
449 } | 449 } |
450 #endif | 450 #endif |
451 | 451 |
452 valid_ = true; | 452 valid_ = true; |
453 } | 453 } |
454 | 454 |
455 void Program::ExecuteBindAttribLocationCalls() { | 455 void Program::ExecuteBindAttribLocationCalls() { |
456 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); | 456 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 const ShaderCacheCallback& shader_callback) { | 526 const ShaderCacheCallback& shader_callback) { |
527 ClearLinkStatus(); | 527 ClearLinkStatus(); |
528 if (!CanLink()) { | 528 if (!CanLink()) { |
529 set_log_info("missing shaders"); | 529 set_log_info("missing shaders"); |
530 return false; | 530 return false; |
531 } | 531 } |
532 if (DetectAttribLocationBindingConflicts()) { | 532 if (DetectAttribLocationBindingConflicts()) { |
533 set_log_info("glBindAttribLocation() conflicts"); | 533 set_log_info("glBindAttribLocation() conflicts"); |
534 return false; | 534 return false; |
535 } | 535 } |
536 if (DetectUniformsMismatch()) { | 536 std::string conflicting_name; |
537 set_log_info("Uniforms with the same name but different type/precision"); | 537 if (DetectUniformsMismatch(&conflicting_name)) { |
| 538 std::string info_log = "Uniforms with the same name but different " |
| 539 "type/precision: " + conflicting_name; |
| 540 set_log_info(ProcessLogInfo(info_log).c_str()); |
538 return false; | 541 return false; |
539 } | 542 } |
540 if (DetectVaryingsMismatch()) { | 543 if (DetectVaryingsMismatch(&conflicting_name)) { |
541 set_log_info("Varyings with the same name but different type, " | 544 std::string info_log = "Varyings with the same name but different type, " |
542 "or statically used varyings in fragment shader are not " | 545 "or statically used varyings in fragment shader are " |
543 "declared in vertex shader"); | 546 "not declared in vertex shader: " + conflicting_name; |
| 547 set_log_info(ProcessLogInfo(info_log).c_str()); |
544 return false; | 548 return false; |
545 } | 549 } |
546 if (DetectGlobalNameConflicts()) { | 550 if (DetectGlobalNameConflicts(&conflicting_name)) { |
547 set_log_info("Name conflicts between an uniform and an attribute"); | 551 std::string info_log = "Name conflicts between an uniform and an " |
| 552 "attribute: " + conflicting_name; |
| 553 set_log_info(ProcessLogInfo(info_log).c_str()); |
548 return false; | 554 return false; |
549 } | 555 } |
550 if (!CheckVaryingsPacking()) { | 556 if (!CheckVaryingsPacking()) { |
551 set_log_info("Varyings over maximum register limit"); | 557 set_log_info("Varyings over maximum register limit"); |
552 return false; | 558 return false; |
553 } | 559 } |
554 | 560 |
555 TimeTicks before_time = TimeTicks::HighResNow(); | 561 TimeTicks before_time = TimeTicks::HighResNow(); |
556 bool link = true; | 562 bool link = true; |
557 ProgramCache* cache = manager_->program_cache_; | 563 ProgramCache* cache = manager_->program_cache_; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 if (active) { | 1004 if (active) { |
999 std::pair<std::set<GLint>::iterator, bool> result = | 1005 std::pair<std::set<GLint>::iterator, bool> result = |
1000 location_binding_used.insert(it->second); | 1006 location_binding_used.insert(it->second); |
1001 if (!result.second) | 1007 if (!result.second) |
1002 return true; | 1008 return true; |
1003 } | 1009 } |
1004 } | 1010 } |
1005 return false; | 1011 return false; |
1006 } | 1012 } |
1007 | 1013 |
1008 bool Program::DetectUniformsMismatch() const { | 1014 bool Program::DetectUniformsMismatch(std::string* conflicting_name) const { |
1009 typedef std::map<std::string, UniformType> UniformMap; | 1015 typedef std::map<std::string, UniformType> UniformMap; |
1010 UniformMap uniform_map; | 1016 UniformMap uniform_map; |
1011 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { | 1017 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { |
1012 const ShaderTranslator::VariableMap& shader_uniforms = | 1018 const ShaderTranslator::VariableMap& shader_uniforms = |
1013 attached_shaders_[ii]->uniform_map(); | 1019 attached_shaders_[ii]->uniform_map(); |
1014 for (ShaderTranslator::VariableMap::const_iterator iter = | 1020 for (ShaderTranslator::VariableMap::const_iterator iter = |
1015 shader_uniforms.begin(); | 1021 shader_uniforms.begin(); |
1016 iter != shader_uniforms.end(); ++iter) { | 1022 iter != shader_uniforms.end(); ++iter) { |
1017 const std::string& name = iter->first; | 1023 const std::string& name = iter->first; |
1018 UniformType type(iter->second); | 1024 UniformType type(iter->second); |
1019 UniformMap::iterator map_entry = uniform_map.find(name); | 1025 UniformMap::iterator map_entry = uniform_map.find(name); |
1020 if (map_entry == uniform_map.end()) { | 1026 if (map_entry == uniform_map.end()) { |
1021 uniform_map[name] = type; | 1027 uniform_map[name] = type; |
1022 } else { | 1028 } else { |
1023 // If a uniform is already in the map, i.e., it has already been | 1029 // If a uniform is already in the map, i.e., it has already been |
1024 // declared by other shader, then the type and precision must match. | 1030 // declared by other shader, then the type and precision must match. |
1025 if (map_entry->second == type) | 1031 if (map_entry->second == type) |
1026 continue; | 1032 continue; |
| 1033 *conflicting_name = name; |
1027 return true; | 1034 return true; |
1028 } | 1035 } |
1029 } | 1036 } |
1030 } | 1037 } |
1031 return false; | 1038 return false; |
1032 } | 1039 } |
1033 | 1040 |
1034 bool Program::DetectVaryingsMismatch() const { | 1041 bool Program::DetectVaryingsMismatch(std::string* conflicting_name) const { |
1035 DCHECK(attached_shaders_[0] && | 1042 DCHECK(attached_shaders_[0] && |
1036 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | 1043 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && |
1037 attached_shaders_[1] && | 1044 attached_shaders_[1] && |
1038 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1045 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
1039 const ShaderTranslator::VariableMap* vertex_varyings = | 1046 const ShaderTranslator::VariableMap* vertex_varyings = |
1040 &(attached_shaders_[0]->varying_map()); | 1047 &(attached_shaders_[0]->varying_map()); |
1041 const ShaderTranslator::VariableMap* fragment_varyings = | 1048 const ShaderTranslator::VariableMap* fragment_varyings = |
1042 &(attached_shaders_[1]->varying_map()); | 1049 &(attached_shaders_[1]->varying_map()); |
1043 | 1050 |
1044 for (ShaderTranslator::VariableMap::const_iterator iter = | 1051 for (ShaderTranslator::VariableMap::const_iterator iter = |
1045 fragment_varyings->begin(); | 1052 fragment_varyings->begin(); |
1046 iter != fragment_varyings->end(); ++iter) { | 1053 iter != fragment_varyings->end(); ++iter) { |
1047 const std::string& name = iter->first; | 1054 const std::string& name = iter->first; |
1048 if (IsBuiltInVarying(name)) | 1055 if (IsBuiltInVarying(name)) |
1049 continue; | 1056 continue; |
1050 | 1057 |
1051 ShaderTranslator::VariableMap::const_iterator hit = | 1058 ShaderTranslator::VariableMap::const_iterator hit = |
1052 vertex_varyings->find(name); | 1059 vertex_varyings->find(name); |
1053 if (hit == vertex_varyings->end()) { | 1060 if (hit == vertex_varyings->end()) { |
1054 if (iter->second.static_use) | 1061 if (iter->second.static_use) { |
| 1062 *conflicting_name = name; |
1055 return true; | 1063 return true; |
| 1064 } |
1056 continue; | 1065 continue; |
1057 } | 1066 } |
1058 | 1067 |
1059 if (hit->second.type != iter->second.type || | 1068 if (hit->second.type != iter->second.type || |
1060 hit->second.size != iter->second.size) | 1069 hit->second.size != iter->second.size) { |
| 1070 *conflicting_name = name; |
1061 return true; | 1071 return true; |
| 1072 } |
1062 | 1073 |
1063 } | 1074 } |
1064 return false; | 1075 return false; |
1065 } | 1076 } |
1066 | 1077 |
1067 bool Program::DetectGlobalNameConflicts() const { | 1078 bool Program::DetectGlobalNameConflicts(std::string* conflicting_name) const { |
1068 DCHECK(attached_shaders_[0] && | 1079 DCHECK(attached_shaders_[0] && |
1069 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | 1080 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && |
1070 attached_shaders_[1] && | 1081 attached_shaders_[1] && |
1071 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1082 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
1072 const ShaderTranslator::VariableMap* uniforms[2]; | 1083 const ShaderTranslator::VariableMap* uniforms[2]; |
1073 uniforms[0] = &(attached_shaders_[0]->uniform_map()); | 1084 uniforms[0] = &(attached_shaders_[0]->uniform_map()); |
1074 uniforms[1] = &(attached_shaders_[1]->uniform_map()); | 1085 uniforms[1] = &(attached_shaders_[1]->uniform_map()); |
1075 const ShaderTranslator::VariableMap* attribs = | 1086 const ShaderTranslator::VariableMap* attribs = |
1076 &(attached_shaders_[0]->attrib_map()); | 1087 &(attached_shaders_[0]->attrib_map()); |
1077 | 1088 |
1078 for (ShaderTranslator::VariableMap::const_iterator iter = | 1089 for (ShaderTranslator::VariableMap::const_iterator iter = |
1079 attribs->begin(); iter != attribs->end(); ++iter) { | 1090 attribs->begin(); iter != attribs->end(); ++iter) { |
1080 for (int ii = 0; ii < 2; ++ii) { | 1091 for (int ii = 0; ii < 2; ++ii) { |
1081 if (uniforms[ii]->find(iter->first) != uniforms[ii]->end()) | 1092 if (uniforms[ii]->find(iter->first) != uniforms[ii]->end()) { |
| 1093 *conflicting_name = iter->first; |
1082 return true; | 1094 return true; |
| 1095 } |
1083 } | 1096 } |
1084 } | 1097 } |
1085 return false; | 1098 return false; |
1086 } | 1099 } |
1087 | 1100 |
1088 bool Program::CheckVaryingsPacking() const { | 1101 bool Program::CheckVaryingsPacking() const { |
1089 DCHECK(attached_shaders_[0] && | 1102 DCHECK(attached_shaders_[0] && |
1090 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && | 1103 attached_shaders_[0]->shader_type() == GL_VERTEX_SHADER && |
1091 attached_shaders_[1] && | 1104 attached_shaders_[1] && |
1092 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); | 1105 attached_shaders_[1]->shader_type() == GL_FRAGMENT_SHADER); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 program->ClearUniforms(&zero_); | 1367 program->ClearUniforms(&zero_); |
1355 } | 1368 } |
1356 } | 1369 } |
1357 | 1370 |
1358 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1371 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1359 return index + element * 0x10000; | 1372 return index + element * 0x10000; |
1360 } | 1373 } |
1361 | 1374 |
1362 } // namespace gles2 | 1375 } // namespace gles2 |
1363 } // namespace gpu | 1376 } // namespace gpu |
OLD | NEW |