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 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 memcpy(entries, &varyings[0], entry_size); | 1522 memcpy(entries, &varyings[0], entry_size); |
1523 | 1523 |
1524 for (uint32_t ii = 0; ii < num_transform_feedback_varyings; ++ii) { | 1524 for (uint32_t ii = 0; ii < num_transform_feedback_varyings; ++ii) { |
1525 memcpy(data, names[ii].c_str(), names[ii].length() + 1); | 1525 memcpy(data, names[ii].c_str(), names[ii].length() + 1); |
1526 data += names[ii].length() + 1; | 1526 data += names[ii].length() + 1; |
1527 } | 1527 } |
1528 DCHECK_EQ(ComputeOffset(header, data), total_size); | 1528 DCHECK_EQ(ComputeOffset(header, data), total_size); |
1529 return true; | 1529 return true; |
1530 } | 1530 } |
1531 | 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, ¶m); |
| 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], ¶ms[0]); |
| 1599 for (GLsizei ii = 0; ii < count; ++ii) { |
| 1600 entries[kStride * ii + pname_index] = params[ii]; |
| 1601 } |
| 1602 } |
| 1603 return true; |
| 1604 } |
| 1605 |
1532 Program::~Program() { | 1606 Program::~Program() { |
1533 if (manager_) { | 1607 if (manager_) { |
1534 if (manager_->have_context_) { | 1608 if (manager_->have_context_) { |
1535 glDeleteProgram(service_id()); | 1609 glDeleteProgram(service_id()); |
1536 } | 1610 } |
1537 manager_->StopTracking(this); | 1611 manager_->StopTracking(this); |
1538 manager_ = NULL; | 1612 manager_ = NULL; |
1539 } | 1613 } |
1540 } | 1614 } |
1541 | 1615 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 DCHECK(program); | 1728 DCHECK(program); |
1655 program->ClearUniforms(&zero_); | 1729 program->ClearUniforms(&zero_); |
1656 } | 1730 } |
1657 | 1731 |
1658 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { | 1732 int32 ProgramManager::MakeFakeLocation(int32 index, int32 element) { |
1659 return index + element * 0x10000; | 1733 return index + element * 0x10000; |
1660 } | 1734 } |
1661 | 1735 |
1662 } // namespace gles2 | 1736 } // namespace gles2 |
1663 } // namespace gpu | 1737 } // namespace gpu |
OLD | NEW |