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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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>
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/numerics/safe_math.h" 17 #include "base/numerics/safe_math.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/time/time.h" 20 #include "base/time/time.h"
21 #include "gpu/command_buffer/common/gles2_cmd_format.h" 21 #include "gpu/command_buffer/common/gles2_cmd_format.h"
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
24 #include "gpu/command_buffer/service/gpu_switches.h" 24 #include "gpu/command_buffer/service/gpu_switches.h"
25 #include "gpu/command_buffer/service/program_cache.h" 25 #include "gpu/command_buffer/service/program_cache.h"
26 #include "gpu/command_buffer/service/shader_manager.h" 26 #include "gpu/command_buffer/service/shader_manager.h"
27 #include "gpu/command_buffer/service/shader_translator.h"
28 #include "third_party/re2/re2/re2.h" 27 #include "third_party/re2/re2/re2.h"
29 28
30 using base::TimeDelta; 29 using base::TimeDelta;
31 using base::TimeTicks; 30 using base::TimeTicks;
32 31
33 namespace gpu { 32 namespace gpu {
34 namespace gles2 { 33 namespace gles2 {
35 34
36 namespace { 35 namespace {
37 36
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 void Program::ExecuteBindAttribLocationCalls() { 507 void Program::ExecuteBindAttribLocationCalls() {
509 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin(); 508 for (LocationMap::const_iterator it = bind_attrib_location_map_.begin();
510 it != bind_attrib_location_map_.end(); ++it) { 509 it != bind_attrib_location_map_.end(); ++it) {
511 const std::string* mapped_name = GetAttribMappedName(it->first); 510 const std::string* mapped_name = GetAttribMappedName(it->first);
512 if (mapped_name) 511 if (mapped_name)
513 glBindAttribLocation(service_id_, it->second, mapped_name->c_str()); 512 glBindAttribLocation(service_id_, it->second, mapped_name->c_str());
514 } 513 }
515 } 514 }
516 515
517 bool Program::Link(ShaderManager* manager, 516 bool Program::Link(ShaderManager* manager,
518 ShaderTranslator* vertex_translator,
519 ShaderTranslator* fragment_translator,
520 Program::VaryingsPackingOption varyings_packing_option, 517 Program::VaryingsPackingOption varyings_packing_option,
521 const ShaderCacheCallback& shader_callback) { 518 const ShaderCacheCallback& shader_callback) {
522 ClearLinkStatus(); 519 ClearLinkStatus();
523 if (!CanLink()) { 520
521 if (!AttachedShadersExist()) {
524 set_log_info("missing shaders"); 522 set_log_info("missing shaders");
525 return false; 523 return false;
526 } 524 }
527 if (DetectAttribLocationBindingConflicts()) {
528 set_log_info("glBindAttribLocation() conflicts");
529 return false;
530 }
531 std::string conflicting_name;
532 if (DetectUniformsMismatch(&conflicting_name)) {
533 std::string info_log = "Uniforms with the same name but different "
534 "type/precision: " + conflicting_name;
535 set_log_info(ProcessLogInfo(info_log).c_str());
536 return false;
537 }
538 if (DetectVaryingsMismatch(&conflicting_name)) {
539 std::string info_log = "Varyings with the same name but different type, "
540 "or statically used varyings in fragment shader are "
541 "not declared in vertex shader: " + conflicting_name;
542 set_log_info(ProcessLogInfo(info_log).c_str());
543 return false;
544 }
545 if (DetectBuiltInInvariantConflicts()) {
546 set_log_info("Invariant settings for certain built-in varyings "
547 "have to match");
548 return false;
549 }
550 if (DetectGlobalNameConflicts(&conflicting_name)) {
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());
554 return false;
555 }
556 if (!CheckVaryingsPacking(varyings_packing_option)) {
557 set_log_info("Varyings over maximum register limit");
558 return false;
559 }
560 525
561 TimeTicks before_time = TimeTicks::Now(); 526 TimeTicks before_time = TimeTicks::Now();
562 bool link = true; 527 bool link = true;
563 ProgramCache* cache = manager_->program_cache_; 528 ProgramCache* cache = manager_->program_cache_;
564 if (cache) { 529 if (cache) {
565 DCHECK(!attached_shaders_[0]->last_compiled_source().empty() && 530 DCHECK(!attached_shaders_[0]->last_compiled_source().empty() &&
566 !attached_shaders_[1]->last_compiled_source().empty()); 531 !attached_shaders_[1]->last_compiled_source().empty());
567 ProgramCache::LinkedProgramStatus status = cache->GetLinkedProgramStatus( 532 ProgramCache::LinkedProgramStatus status = cache->GetLinkedProgramStatus(
568 attached_shaders_[0]->last_compiled_source(), 533 attached_shaders_[0]->last_compiled_signature(),
569 vertex_translator, 534 attached_shaders_[1]->last_compiled_signature(),
570 attached_shaders_[1]->last_compiled_source(),
571 fragment_translator,
572 &bind_attrib_location_map_); 535 &bind_attrib_location_map_);
573 536
574 if (status == ProgramCache::LINK_SUCCEEDED) { 537 if (status == ProgramCache::LINK_SUCCEEDED) {
575 ProgramCache::ProgramLoadResult success = 538 ProgramCache::ProgramLoadResult success =
576 cache->LoadLinkedProgram(service_id(), 539 cache->LoadLinkedProgram(service_id(),
577 attached_shaders_[0].get(), 540 attached_shaders_[0].get(),
578 vertex_translator,
579 attached_shaders_[1].get(), 541 attached_shaders_[1].get(),
580 fragment_translator,
581 &bind_attrib_location_map_, 542 &bind_attrib_location_map_,
582 shader_callback); 543 shader_callback);
583 link = success != ProgramCache::PROGRAM_LOAD_SUCCESS; 544 link = success != ProgramCache::PROGRAM_LOAD_SUCCESS;
584 UMA_HISTOGRAM_BOOLEAN("GPU.ProgramCache.LoadBinarySuccess", !link); 545 UMA_HISTOGRAM_BOOLEAN("GPU.ProgramCache.LoadBinarySuccess", !link);
585 } 546 }
586 } 547 }
587 548
588 if (link) { 549 if (link) {
550 CompileAttachedShaders();
551
552 if (!CanLink()) {
553 set_log_info("invalid shaders");
554 return false;
555 }
556 if (DetectAttribLocationBindingConflicts()) {
557 set_log_info("glBindAttribLocation() conflicts");
558 return false;
559 }
560 std::string conflicting_name;
561 if (DetectUniformsMismatch(&conflicting_name)) {
562 std::string info_log = "Uniforms with the same name but different "
563 "type/precision: " + conflicting_name;
564 set_log_info(ProcessLogInfo(info_log).c_str());
565 return false;
566 }
567 if (DetectVaryingsMismatch(&conflicting_name)) {
568 std::string info_log = "Varyings with the same name but different type, "
569 "or statically used varyings in fragment shader "
570 "are not declared in vertex shader: " +
571 conflicting_name;
572 set_log_info(ProcessLogInfo(info_log).c_str());
573 return false;
574 }
575 if (DetectBuiltInInvariantConflicts()) {
576 set_log_info("Invariant settings for certain built-in varyings "
577 "have to match");
578 return false;
579 }
580 if (DetectGlobalNameConflicts(&conflicting_name)) {
581 std::string info_log = "Name conflicts between an uniform and an "
582 "attribute: " + conflicting_name;
583 set_log_info(ProcessLogInfo(info_log).c_str());
584 return false;
585 }
586 if (!CheckVaryingsPacking(varyings_packing_option)) {
587 set_log_info("Varyings over maximum register limit");
588 return false;
589 }
590
589 ExecuteBindAttribLocationCalls(); 591 ExecuteBindAttribLocationCalls();
590 before_time = TimeTicks::Now(); 592 before_time = TimeTicks::Now();
591 if (cache && gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary) { 593 if (cache && gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary) {
592 glProgramParameteri(service_id(), 594 glProgramParameteri(service_id(),
593 PROGRAM_BINARY_RETRIEVABLE_HINT, 595 PROGRAM_BINARY_RETRIEVABLE_HINT,
594 GL_TRUE); 596 GL_TRUE);
595 } 597 }
596 glLinkProgram(service_id()); 598 glLinkProgram(service_id());
597 } 599 }
598 600
599 GLint success = 0; 601 GLint success = 0;
600 glGetProgramiv(service_id(), GL_LINK_STATUS, &success); 602 glGetProgramiv(service_id(), GL_LINK_STATUS, &success);
601 if (success == GL_TRUE) { 603 if (success == GL_TRUE) {
602 Update(); 604 Update();
603 if (link) { 605 if (link) {
604 if (cache) { 606 if (cache) {
605 cache->SaveLinkedProgram(service_id(), 607 cache->SaveLinkedProgram(service_id(),
606 attached_shaders_[0].get(), 608 attached_shaders_[0].get(),
607 vertex_translator,
608 attached_shaders_[1].get(), 609 attached_shaders_[1].get(),
609 fragment_translator,
610 &bind_attrib_location_map_, 610 &bind_attrib_location_map_,
611 shader_callback); 611 shader_callback);
612 } 612 }
613 UMA_HISTOGRAM_CUSTOM_COUNTS( 613 UMA_HISTOGRAM_CUSTOM_COUNTS(
614 "GPU.ProgramCache.BinaryCacheMissTime", 614 "GPU.ProgramCache.BinaryCacheMissTime",
615 static_cast<base::HistogramBase::Sample>( 615 static_cast<base::HistogramBase::Sample>(
616 (TimeTicks::Now() - before_time).InMicroseconds()), 616 (TimeTicks::Now() - before_time).InMicroseconds()),
617 0, 617 0,
618 static_cast<base::HistogramBase::Sample>( 618 static_cast<base::HistogramBase::Sample>(
619 TimeDelta::FromSeconds(10).InMicroseconds()), 619 TimeDelta::FromSeconds(10).InMicroseconds()),
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 994
995 void Program::DetachShaders(ShaderManager* shader_manager) { 995 void Program::DetachShaders(ShaderManager* shader_manager) {
996 DCHECK(shader_manager); 996 DCHECK(shader_manager);
997 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { 997 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) {
998 if (attached_shaders_[ii].get()) { 998 if (attached_shaders_[ii].get()) {
999 DetachShader(shader_manager, attached_shaders_[ii].get()); 999 DetachShader(shader_manager, attached_shaders_[ii].get());
1000 } 1000 }
1001 } 1001 }
1002 } 1002 }
1003 1003
1004 void Program::CompileAttachedShaders() {
1005 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) {
1006 Shader* shader = attached_shaders_[ii].get();
1007 if (shader) {
1008 shader->DoCompile();
1009 }
1010 }
1011 }
1012
1013 bool Program::AttachedShadersExist() const {
1014 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) {
1015 if (!attached_shaders_[ii].get())
1016 return false;
1017 }
1018 return true;
1019 }
1020
1004 bool Program::CanLink() const { 1021 bool Program::CanLink() const {
1005 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) { 1022 for (int ii = 0; ii < kMaxAttachedShaders; ++ii) {
1006 if (!attached_shaders_[ii].get() || !attached_shaders_[ii]->valid()) { 1023 if (!attached_shaders_[ii].get() || !attached_shaders_[ii]->valid()) {
1007 return false; 1024 return false;
1008 } 1025 }
1009 } 1026 }
1010 return true; 1027 return true;
1011 } 1028 }
1012 1029
1013 bool Program::DetectAttribLocationBindingConflicts() const { 1030 bool Program::DetectAttribLocationBindingConflicts() const {
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 // 2) N entries of block data (except for name and indices) 1313 // 2) N entries of block data (except for name and indices)
1297 // 3) name1, indices1, name2, indices2, ..., nameN, indicesN 1314 // 3) name1, indices1, name2, indices2, ..., nameN, indicesN
1298 // 1315 //
1299 // We query all the data directly through GL calls, assuming they are 1316 // We query all the data directly through GL calls, assuming they are
1300 // cheap through MANGLE. 1317 // cheap through MANGLE.
1301 1318
1302 DCHECK(bucket); 1319 DCHECK(bucket);
1303 GLuint program = service_id(); 1320 GLuint program = service_id();
1304 1321
1305 uint32_t header_size = sizeof(UniformBlocksHeader); 1322 uint32_t header_size = sizeof(UniformBlocksHeader);
1323 bucket->SetSize(header_size); // In case we fail.
1306 1324
1307 uint32_t num_uniform_blocks = 0; 1325 uint32_t num_uniform_blocks = 0;
1308 GLint param = GL_FALSE; 1326 GLint param = GL_FALSE;
1309 // We assume program is a valid program service id. 1327 // We assume program is a valid program service id.
1310 glGetProgramiv(program, GL_LINK_STATUS, &param); 1328 glGetProgramiv(program, GL_LINK_STATUS, &param);
1311 if (param == GL_TRUE) { 1329 if (param == GL_TRUE) {
1312 param = 0; 1330 param = 0;
1313 glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &param); 1331 glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &param);
1314 num_uniform_blocks = static_cast<uint32_t>(param); 1332 num_uniform_blocks = static_cast<uint32_t>(param);
1315 } 1333 }
1316 if (num_uniform_blocks == 0) { 1334 if (num_uniform_blocks == 0) {
1317 // Although spec allows an implementation to return uniform block info 1335 // Although spec allows an implementation to return uniform block info
1318 // even if a link fails, for consistency, we disallow that. 1336 // even if a link fails, for consistency, we disallow that.
1319 bucket->SetSize(header_size);
1320 UniformBlocksHeader* header =
1321 bucket->GetDataAs<UniformBlocksHeader*>(0, header_size);
1322 header->num_uniform_blocks = 0;
1323 return true; 1337 return true;
1324 } 1338 }
1325 1339
1326 std::vector<UniformBlockInfo> blocks(num_uniform_blocks); 1340 std::vector<UniformBlockInfo> blocks(num_uniform_blocks);
1327 base::CheckedNumeric<uint32_t> size = sizeof(UniformBlockInfo); 1341 base::CheckedNumeric<uint32_t> size = sizeof(UniformBlockInfo);
1328 size *= num_uniform_blocks; 1342 size *= num_uniform_blocks;
1329 uint32_t entry_size = size.ValueOrDefault(0); 1343 uint32_t entry_size = size.ValueOrDefault(0);
1330 size += header_size; 1344 size += header_size;
1331 std::vector<std::string> names(num_uniform_blocks); 1345 std::vector<std::string> names(num_uniform_blocks);
1332 GLint max_name_length = 0; 1346 GLint max_name_length = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 blocks[ii].referenced_by_fragment_shader = static_cast<uint32_t>(param); 1397 blocks[ii].referenced_by_fragment_shader = static_cast<uint32_t>(param);
1384 } 1398 }
1385 if (!size.IsValid()) 1399 if (!size.IsValid())
1386 return false; 1400 return false;
1387 uint32_t total_size = size.ValueOrDefault(0); 1401 uint32_t total_size = size.ValueOrDefault(0);
1388 DCHECK_LE(header_size + entry_size, total_size); 1402 DCHECK_LE(header_size + entry_size, total_size);
1389 uint32_t data_size = total_size - header_size - entry_size; 1403 uint32_t data_size = total_size - header_size - entry_size;
1390 1404
1391 bucket->SetSize(total_size); 1405 bucket->SetSize(total_size);
1392 UniformBlocksHeader* header = 1406 UniformBlocksHeader* header =
1393 bucket->GetDataAs<UniformBlocksHeader*>(0, total_size); 1407 bucket->GetDataAs<UniformBlocksHeader*>(0, header_size);
1394 UniformBlockInfo* entries = bucket->GetDataAs<UniformBlockInfo*>( 1408 UniformBlockInfo* entries = bucket->GetDataAs<UniformBlockInfo*>(
1395 header_size, entry_size); 1409 header_size, entry_size);
1396 char* data = bucket->GetDataAs<char*>(header_size + entry_size, data_size); 1410 char* data = bucket->GetDataAs<char*>(header_size + entry_size, data_size);
1397 DCHECK(header); 1411 DCHECK(header);
1398 DCHECK(entries); 1412 DCHECK(entries);
1399 DCHECK(data); 1413 DCHECK(data);
1400 1414
1401 // Copy over data for the header and entries. 1415 // Copy over data for the header and entries.
1402 header->num_uniform_blocks = num_uniform_blocks; 1416 header->num_uniform_blocks = num_uniform_blocks;
1403 memcpy(entries, &blocks[0], entry_size); 1417 memcpy(entries, &blocks[0], entry_size);
1404 1418
1405 std::vector<GLint> params; 1419 std::vector<GLint> params;
1406 for (uint32_t ii = 0; ii < num_uniform_blocks; ++ii) { 1420 for (uint32_t ii = 0; ii < num_uniform_blocks; ++ii) {
1407 // Get active uniform name. 1421 // Get active uniform name.
1408 memcpy(data, names[ii].c_str(), blocks[ii].name_length); 1422 memcpy(data, names[ii].c_str(), names[ii].length() + 1);
1409 data += blocks[ii].name_length; 1423 data += names[ii].length() + 1;
1410 1424
1411 // Get active uniform indices. 1425 // Get active uniform indices.
1412 if (params.size() < blocks[ii].active_uniforms) 1426 if (params.size() < blocks[ii].active_uniforms)
1413 params.resize(blocks[ii].active_uniforms); 1427 params.resize(blocks[ii].active_uniforms);
1414 uint32_t num_bytes = blocks[ii].active_uniforms * sizeof(GLint); 1428 uint32_t num_bytes = blocks[ii].active_uniforms * sizeof(GLint);
1415 memset(&params[0], 0, num_bytes); 1429 memset(&params[0], 0, num_bytes);
1416 glGetActiveUniformBlockiv( 1430 glGetActiveUniformBlockiv(
1417 program, ii, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &params[0]); 1431 program, ii, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &params[0]);
1418 uint32_t* indices = reinterpret_cast<uint32_t*>(data); 1432 uint32_t* indices = reinterpret_cast<uint32_t*>(data);
1419 for (uint32_t uu = 0; uu < blocks[ii].active_uniforms; ++uu) { 1433 for (uint32_t uu = 0; uu < blocks[ii].active_uniforms; ++uu) {
1420 indices[uu] = static_cast<uint32_t>(params[uu]); 1434 indices[uu] = static_cast<uint32_t>(params[uu]);
1421 } 1435 }
1422 data += num_bytes; 1436 data += num_bytes;
1423 } 1437 }
1424 DCHECK_EQ(ComputeOffset(header, data), total_size); 1438 DCHECK_EQ(ComputeOffset(header, data), total_size);
1425 return true; 1439 return true;
1426 } 1440 }
1427 1441
1442 bool Program::GetTransformFeedbackVaryings(
1443 CommonDecoder::Bucket* bucket) const {
1444 // The data is packed into the bucket in the following order
1445 // 1) header
1446 // 2) N entries of varying data (except for name)
1447 // 3) name1, name2, ..., nameN
1448 //
1449 // We query all the data directly through GL calls, assuming they are
1450 // cheap through MANGLE.
1451
1452 DCHECK(bucket);
1453 GLuint program = service_id();
1454
1455 uint32_t header_size = sizeof(TransformFeedbackVaryingsHeader);
1456 bucket->SetSize(header_size); // In case we fail.
1457
1458 uint32_t num_transform_feedback_varyings = 0;
1459 GLint param = GL_FALSE;
1460 // We assume program is a valid program service id.
1461 glGetProgramiv(program, GL_LINK_STATUS, &param);
1462 if (param == GL_TRUE) {
1463 param = 0;
1464 glGetProgramiv(program, GL_TRANSFORM_FEEDBACK_VARYINGS, &param);
1465 num_transform_feedback_varyings = static_cast<uint32_t>(param);
1466 }
1467 if (num_transform_feedback_varyings == 0) {
1468 return true;
1469 }
1470
1471 std::vector<TransformFeedbackVaryingInfo> varyings(
1472 num_transform_feedback_varyings);
1473 base::CheckedNumeric<uint32_t> size = sizeof(TransformFeedbackVaryingInfo);
1474 size *= num_transform_feedback_varyings;
1475 uint32_t entry_size = size.ValueOrDefault(0);
1476 size += header_size;
1477 std::vector<std::string> names(num_transform_feedback_varyings);
1478 GLint max_name_length = 0;
1479 glGetProgramiv(
1480 program, GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, &max_name_length);
1481 if (max_name_length < 1)
1482 max_name_length = 1;
1483 std::vector<char> buffer(max_name_length);
1484 for (uint32_t ii = 0; ii < num_transform_feedback_varyings; ++ii) {
1485 GLsizei var_size = 0;
1486 GLsizei var_name_length = 0;
1487 GLenum var_type = 0;
1488 glGetTransformFeedbackVarying(
1489 program, ii, max_name_length,
1490 &var_name_length, &var_size, &var_type, &buffer[0]);
1491 varyings[ii].size = static_cast<uint32_t>(var_size);
1492 varyings[ii].type = static_cast<uint32_t>(var_type);
1493 varyings[ii].name_offset = static_cast<uint32_t>(size.ValueOrDefault(0));
1494 DCHECK_GT(max_name_length, var_name_length);
1495 names[ii] = std::string(&buffer[0], var_name_length);
1496 // TODO(zmo): optimize the name mapping lookup.
1497 const std::string* original_name = GetOriginalNameFromHashedName(names[ii]);
1498 if (original_name)
1499 names[ii] = *original_name;
1500 varyings[ii].name_length = names[ii].size() + 1;
1501 size += names[ii].size();
1502 size += 1;
1503 }
1504 if (!size.IsValid())
1505 return false;
1506 uint32_t total_size = size.ValueOrDefault(0);
1507 DCHECK_LE(header_size + entry_size, total_size);
1508 uint32_t data_size = total_size - header_size - entry_size;
1509
1510 bucket->SetSize(total_size);
1511 TransformFeedbackVaryingsHeader* header =
1512 bucket->GetDataAs<TransformFeedbackVaryingsHeader*>(0, header_size);
1513 TransformFeedbackVaryingInfo* entries =
1514 bucket->GetDataAs<TransformFeedbackVaryingInfo*>(header_size, entry_size);
1515 char* data = bucket->GetDataAs<char*>(header_size + entry_size, data_size);
1516 DCHECK(header);
1517 DCHECK(entries);
1518 DCHECK(data);
1519
1520 // Copy over data for the header and entries.
1521 header->num_transform_feedback_varyings = num_transform_feedback_varyings;
1522 memcpy(entries, &varyings[0], entry_size);
1523
1524 for (uint32_t ii = 0; ii < num_transform_feedback_varyings; ++ii) {
1525 memcpy(data, names[ii].c_str(), names[ii].length() + 1);
1526 data += names[ii].length() + 1;
1527 }
1528 DCHECK_EQ(ComputeOffset(header, data), total_size);
1529 return true;
1530 }
1531
1532 bool Program::GetUniformsES3(CommonDecoder::Bucket* bucket) const {
1533 // The data is packed into the bucket in the following order
1534 // 1) header
1535 // 2) N entries of UniformES3Info
1536 //
1537 // We query all the data directly through GL calls, assuming they are
1538 // cheap through MANGLE.
1539
1540 DCHECK(bucket);
1541 GLuint program = service_id();
1542
1543 uint32_t header_size = sizeof(UniformsES3Header);
1544 bucket->SetSize(header_size); // In case we fail.
1545
1546 GLsizei count = 0;
1547 GLint param = GL_FALSE;
1548 // We assume program is a valid program service id.
1549 glGetProgramiv(program, GL_LINK_STATUS, &param);
1550 if (param == GL_TRUE) {
1551 param = 0;
1552 glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &count);
1553 }
1554 if (count == 0) {
1555 return true;
1556 }
1557
1558 base::CheckedNumeric<uint32_t> size = sizeof(UniformES3Info);
1559 size *= count;
1560 uint32_t entry_size = size.ValueOrDefault(0);
1561 size += header_size;
1562 if (!size.IsValid())
1563 return false;
1564 uint32_t total_size = size.ValueOrDefault(0);
1565 bucket->SetSize(total_size);
1566 UniformsES3Header* header =
1567 bucket->GetDataAs<UniformsES3Header*>(0, header_size);
1568 DCHECK(header);
1569 header->num_uniforms = static_cast<uint32_t>(count);
1570
1571 // Instead of GetDataAs<UniformES3Info*>, we do GetDataAs<int32_t>. This is
1572 // because struct UniformES3Info is defined as five int32_t.
1573 // By doing this, we can fill the structs through loops.
1574 int32_t* entries =
1575 bucket->GetDataAs<int32_t*>(header_size, entry_size);
1576 DCHECK(entries);
1577 const size_t kStride = sizeof(UniformES3Info) / sizeof(int32_t);
1578
1579 const GLenum kPname[] = {
1580 GL_UNIFORM_BLOCK_INDEX,
1581 GL_UNIFORM_OFFSET,
1582 GL_UNIFORM_ARRAY_STRIDE,
1583 GL_UNIFORM_MATRIX_STRIDE,
1584 GL_UNIFORM_IS_ROW_MAJOR,
1585 };
1586 const GLint kDefaultValue[] = { -1, -1, -1, -1, 0 };
1587 const size_t kNumPnames = arraysize(kPname);
1588 std::vector<GLuint> indices(count);
1589 for (GLsizei ii = 0; ii < count; ++ii) {
1590 indices[ii] = ii;
1591 }
1592 std::vector<GLint> params(count);
1593 for (size_t pname_index = 0; pname_index < kNumPnames; ++pname_index) {
1594 for (GLsizei ii = 0; ii < count; ++ii) {
1595 params[ii] = kDefaultValue[pname_index];
1596 }
1597 glGetActiveUniformsiv(
1598 program, count, &indices[0], kPname[pname_index], &params[0]);
1599 for (GLsizei ii = 0; ii < count; ++ii) {
1600 entries[kStride * ii + pname_index] = params[ii];
1601 }
1602 }
1603 return true;
1604 }
1605
1428 Program::~Program() { 1606 Program::~Program() {
1429 if (manager_) { 1607 if (manager_) {
1430 if (manager_->have_context_) { 1608 if (manager_->have_context_) {
1431 glDeleteProgram(service_id()); 1609 glDeleteProgram(service_id());
1432 } 1610 }
1433 manager_->StopTracking(this); 1611 manager_->StopTracking(this);
1434 manager_ = NULL; 1612 manager_ = NULL;
1435 } 1613 }
1436 } 1614 }
1437 1615
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 DCHECK(program); 1728 DCHECK(program);
1551 program->ClearUniforms(&zero_); 1729 program->ClearUniforms(&zero_);
1552 } 1730 }
1553 1731
1554 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { 1732 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) {
1555 return index + element * 0x10000; 1733 return index + element * 0x10000;
1556 } 1734 }
1557 1735
1558 } // namespace gles2 1736 } // namespace gles2
1559 } // namespace gpu 1737 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/program_manager.h ('k') | gpu/command_buffer/service/program_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698