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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 19 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
20 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 20 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
21 #include "gpu/command_buffer/service/feature_info.h" | |
22 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 21 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
23 #include "gpu/command_buffer/service/gpu_switches.h" | 22 #include "gpu/command_buffer/service/gpu_switches.h" |
24 #include "gpu/command_buffer/service/program_cache.h" | 23 #include "gpu/command_buffer/service/program_cache.h" |
25 #include "gpu/command_buffer/service/shader_manager.h" | 24 #include "gpu/command_buffer/service/shader_manager.h" |
26 #include "gpu/command_buffer/service/shader_translator.h" | 25 #include "gpu/command_buffer/service/shader_translator.h" |
27 #include "third_party/re2/re2/re2.h" | 26 #include "third_party/re2/re2/re2.h" |
28 | 27 |
29 using base::TimeDelta; | 28 using base::TimeDelta; |
30 using base::TimeTicks; | 29 using base::TimeTicks; |
31 | 30 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 453 |
455 void Program::ExecuteBindAttribLocationCalls() { | 454 void Program::ExecuteBindAttribLocationCalls() { |
456 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); | 455 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); |
457 it != bind_attrib_location_map_.end(); ++it) { | 456 it != bind_attrib_location_map_.end(); ++it) { |
458 const std::string* mapped_name = GetAttribMappedName(it->first); | 457 const std::string* mapped_name = GetAttribMappedName(it->first); |
459 if (mapped_name && *mapped_name != it->first) | 458 if (mapped_name && *mapped_name != it->first) |
460 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); | 459 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); |
461 } | 460 } |
462 } | 461 } |
463 | 462 |
464 void ProgramManager::DoCompileShader(Shader* shader, | 463 void ProgramManager::DoCompileShader( |
465 ShaderTranslator* translator, | 464 Shader* shader, |
466 FeatureInfo* feature_info) { | 465 ShaderTranslator* translator, |
| 466 ProgramManager::TranslatedShaderSourceType translated_shader_source_type) { |
467 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to | 467 // Translate GL ES 2.0 shader to Desktop GL shader and pass that to |
468 // glShaderSource and then glCompileShader. | 468 // glShaderSource and then glCompileShader. |
469 const std::string* source = shader->source(); | 469 const std::string* source = shader->source(); |
470 const char* shader_src = source ? source->c_str() : ""; | 470 const char* shader_src = source ? source->c_str() : ""; |
471 if (translator) { | 471 if (translator) { |
472 if (!translator->Translate(shader_src)) { | 472 if (!translator->Translate(shader_src)) { |
473 shader->SetStatus(false, translator->info_log(), NULL); | 473 shader->SetStatus(false, translator->info_log(), NULL); |
474 return; | 474 return; |
475 } | 475 } |
476 shader_src = translator->translated_shader(); | 476 shader_src = translator->translated_shader(); |
477 if (!feature_info->feature_flags().angle_translated_shader_source) | 477 if (translated_shader_source_type != kANGLE) |
478 shader->UpdateTranslatedSource(shader_src); | 478 shader->UpdateTranslatedSource(shader_src); |
479 } | 479 } |
480 | 480 |
481 glShaderSource(shader->service_id(), 1, &shader_src, NULL); | 481 glShaderSource(shader->service_id(), 1, &shader_src, NULL); |
482 glCompileShader(shader->service_id()); | 482 glCompileShader(shader->service_id()); |
483 if (feature_info->feature_flags().angle_translated_shader_source) { | 483 if (translated_shader_source_type == kANGLE) { |
484 GLint max_len = 0; | 484 GLint max_len = 0; |
485 glGetShaderiv(shader->service_id(), | 485 glGetShaderiv(shader->service_id(), |
486 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, | 486 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, |
487 &max_len); | 487 &max_len); |
488 scoped_ptr<char[]> temp(new char[max_len]); | 488 scoped_ptr<char[]> temp(new char[max_len]); |
489 GLint len = 0; | 489 GLint len = 0; |
490 glGetTranslatedShaderSourceANGLE( | 490 glGetTranslatedShaderSourceANGLE( |
491 shader->service_id(), max_len, &len, temp.get()); | 491 shader->service_id(), max_len, &len, temp.get()); |
492 DCHECK(max_len == 0 || len < max_len); | 492 DCHECK(max_len == 0 || len < max_len); |
493 DCHECK(len == 0 || temp[len] == '\0'); | 493 DCHECK(len == 0 || temp[len] == '\0'); |
(...skipping 21 matching lines...) Expand all Loading... |
515 << "unless the driver is buggy:" | 515 << "unless the driver is buggy:" |
516 << "\n--original-shader--\n" << (source ? *source : std::string()) | 516 << "\n--original-shader--\n" << (source ? *source : std::string()) |
517 << "\n--translated-shader--\n" << shader_src << "\n--info-log--\n" | 517 << "\n--translated-shader--\n" << shader_src << "\n--info-log--\n" |
518 << *shader->log_info(); | 518 << *shader->log_info(); |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 bool Program::Link(ShaderManager* manager, | 522 bool Program::Link(ShaderManager* manager, |
523 ShaderTranslator* vertex_translator, | 523 ShaderTranslator* vertex_translator, |
524 ShaderTranslator* fragment_translator, | 524 ShaderTranslator* fragment_translator, |
525 FeatureInfo* feature_info, | |
526 const ShaderCacheCallback& shader_callback) { | 525 const ShaderCacheCallback& shader_callback) { |
527 ClearLinkStatus(); | 526 ClearLinkStatus(); |
528 if (!CanLink()) { | 527 if (!CanLink()) { |
529 set_log_info("missing shaders"); | 528 set_log_info("missing shaders"); |
530 return false; | 529 return false; |
531 } | 530 } |
532 if (DetectAttribLocationBindingConflicts()) { | 531 if (DetectAttribLocationBindingConflicts()) { |
533 set_log_info("glBindAttribLocation() conflicts"); | 532 set_log_info("glBindAttribLocation() conflicts"); |
534 return false; | 533 return false; |
535 } | 534 } |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 manager_->StopTracking(this); | 1243 manager_->StopTracking(this); |
1245 manager_ = NULL; | 1244 manager_ = NULL; |
1246 } | 1245 } |
1247 } | 1246 } |
1248 | 1247 |
1249 | 1248 |
1250 ProgramManager::ProgramManager(ProgramCache* program_cache, | 1249 ProgramManager::ProgramManager(ProgramCache* program_cache, |
1251 uint32 max_varying_vectors) | 1250 uint32 max_varying_vectors) |
1252 : program_count_(0), | 1251 : program_count_(0), |
1253 have_context_(true), | 1252 have_context_(true), |
1254 disable_workarounds_( | |
1255 CommandLine::ForCurrentProcess()->HasSwitch( | |
1256 switches::kDisableGpuDriverBugWorkarounds)), | |
1257 program_cache_(program_cache), | 1253 program_cache_(program_cache), |
1258 max_varying_vectors_(max_varying_vectors) { } | 1254 max_varying_vectors_(max_varying_vectors) { } |
1259 | 1255 |
1260 ProgramManager::~ProgramManager() { | 1256 ProgramManager::~ProgramManager() { |
1261 DCHECK(programs_.empty()); | 1257 DCHECK(programs_.empty()); |
1262 } | 1258 } |
1263 | 1259 |
1264 void ProgramManager::Destroy(bool have_context) { | 1260 void ProgramManager::Destroy(bool have_context) { |
1265 have_context_ = have_context; | 1261 have_context_ = have_context; |
1266 programs_.clear(); | 1262 programs_.clear(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 DCHECK(program); | 1337 DCHECK(program); |
1342 DCHECK(IsOwned(program)); | 1338 DCHECK(IsOwned(program)); |
1343 program->MarkAsDeleted(); | 1339 program->MarkAsDeleted(); |
1344 RemoveProgramInfoIfUnused(shader_manager, program); | 1340 RemoveProgramInfoIfUnused(shader_manager, program); |
1345 } | 1341 } |
1346 | 1342 |
1347 void ProgramManager::UseProgram(Program* program) { | 1343 void ProgramManager::UseProgram(Program* program) { |
1348 DCHECK(program); | 1344 DCHECK(program); |
1349 DCHECK(IsOwned(program)); | 1345 DCHECK(IsOwned(program)); |
1350 program->IncUseCount(); | 1346 program->IncUseCount(); |
1351 ClearUniforms(program); | |
1352 } | 1347 } |
1353 | 1348 |
1354 void ProgramManager::UnuseProgram( | 1349 void ProgramManager::UnuseProgram( |
1355 ShaderManager* shader_manager, | 1350 ShaderManager* shader_manager, |
1356 Program* program) { | 1351 Program* program) { |
1357 DCHECK(shader_manager); | 1352 DCHECK(shader_manager); |
1358 DCHECK(program); | 1353 DCHECK(program); |
1359 DCHECK(IsOwned(program)); | 1354 DCHECK(IsOwned(program)); |
1360 program->DecUseCount(); | 1355 program->DecUseCount(); |
1361 RemoveProgramInfoIfUnused(shader_manager, program); | 1356 RemoveProgramInfoIfUnused(shader_manager, program); |
1362 } | 1357 } |
1363 | 1358 |
1364 void ProgramManager::ClearUniforms(Program* program) { | 1359 void ProgramManager::ClearUniforms(Program* program) { |
1365 DCHECK(program); | 1360 DCHECK(program); |
1366 if (!disable_workarounds_) { | 1361 program->ClearUniforms(&zero_); |
1367 program->ClearUniforms(&zero_); | |
1368 } | |
1369 } | 1362 } |
1370 | 1363 |
1371 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1364 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1372 return index + element * 0x10000; | 1365 return index + element * 0x10000; |
1373 } | 1366 } |
1374 | 1367 |
1375 } // namespace gles2 | 1368 } // namespace gles2 |
1376 } // namespace gpu | 1369 } // namespace gpu |
OLD | NEW |