Cleaned up BufferBindingsGLES::BindUniformBuffer (flutter/engine#56777)
* removes usages of auto * adds a std::vector::reserve * renames improperly named local variable ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -242,15 +242,16 @@ GLint BufferBindingsGLES::ComputeTextureLocation(
|
||||
|
||||
const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
|
||||
const ShaderMetadata* metadata) {
|
||||
auto location = binding_map_.find(metadata->name);
|
||||
BindingMap::iterator location = binding_map_.find(metadata->name);
|
||||
if (location != binding_map_.end()) {
|
||||
return location->second;
|
||||
}
|
||||
|
||||
// For each metadata member, look up the binding location and record
|
||||
// it in the binding map.
|
||||
auto& locations = binding_map_[metadata->name] = {};
|
||||
for (const auto& member : metadata->members) {
|
||||
std::vector<GLint>& locations = binding_map_[metadata->name] = {};
|
||||
locations.reserve(metadata->members.size());
|
||||
for (const ShaderStructMemberMetadata& member : metadata->members) {
|
||||
if (member.type == ShaderType::kVoid) {
|
||||
// Void types are used for padding. We are obviously not going to find
|
||||
// mappings for these. Keep going.
|
||||
@@ -259,9 +260,10 @@ const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
|
||||
}
|
||||
|
||||
size_t element_count = member.array_elements.value_or(1);
|
||||
const auto member_key =
|
||||
const std::string member_key =
|
||||
CreateUniformMemberKey(metadata->name, member.name, element_count > 1);
|
||||
const auto computed_location = uniform_locations_.find(member_key);
|
||||
const std::unordered_map<std::string, GLint>::iterator computed_location =
|
||||
uniform_locations_.find(member_key);
|
||||
if (computed_location == uniform_locations_.end()) {
|
||||
// Uniform was not active.
|
||||
locations.push_back(-1);
|
||||
@@ -275,13 +277,14 @@ const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
|
||||
bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
|
||||
Allocator& transients_allocator,
|
||||
const BufferResource& buffer) {
|
||||
const auto* metadata = buffer.GetMetadata();
|
||||
auto device_buffer = buffer.resource.GetBuffer();
|
||||
const ShaderMetadata* metadata = buffer.GetMetadata();
|
||||
const DeviceBuffer* device_buffer = buffer.resource.GetBuffer();
|
||||
if (!device_buffer) {
|
||||
VALIDATION_LOG << "Device buffer not found.";
|
||||
return false;
|
||||
}
|
||||
const auto& device_buffer_gles = DeviceBufferGLES::Cast(*device_buffer);
|
||||
const DeviceBufferGLES& device_buffer_gles =
|
||||
DeviceBufferGLES::Cast(*device_buffer);
|
||||
const uint8_t* buffer_ptr =
|
||||
device_buffer_gles.GetBufferData() + buffer.resource.GetRange().offset;
|
||||
|
||||
@@ -292,10 +295,10 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& locations = ComputeUniformLocations(metadata);
|
||||
for (auto i = 0u; i < metadata->members.size(); i++) {
|
||||
const auto& member = metadata->members[i];
|
||||
auto location = locations[i];
|
||||
const std::vector<GLint>& locations = ComputeUniformLocations(metadata);
|
||||
for (size_t i = 0u; i < metadata->members.size(); i++) {
|
||||
const ShaderStructMemberMetadata& member = metadata->members[i];
|
||||
GLint location = locations[i];
|
||||
// Void type or inactive uniform.
|
||||
if (location == -1 || member.type == ShaderType::kVoid) {
|
||||
continue;
|
||||
@@ -309,17 +312,17 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
|
||||
// When binding uniform arrays, the elements must be contiguous. Copy
|
||||
// the uniforms to a temp buffer to eliminate any padding needed by the
|
||||
// other backends if the array elements have padding.
|
||||
std::vector<uint8_t> array_element_buffer_;
|
||||
std::vector<uint8_t> array_element_buffer;
|
||||
if (element_count > 1 && element_stride != member.size) {
|
||||
array_element_buffer_.resize(member.size * element_count);
|
||||
array_element_buffer.resize(member.size * element_count);
|
||||
for (size_t element_i = 0; element_i < element_count; element_i++) {
|
||||
std::memcpy(array_element_buffer_.data() + element_i * member.size,
|
||||
std::memcpy(array_element_buffer.data() + element_i * member.size,
|
||||
reinterpret_cast<const char*>(buffer_data) +
|
||||
element_i * element_stride,
|
||||
member.size);
|
||||
}
|
||||
buffer_data =
|
||||
reinterpret_cast<const GLfloat*>(array_element_buffer_.data());
|
||||
reinterpret_cast<const GLfloat*>(array_element_buffer.data());
|
||||
}
|
||||
|
||||
switch (member.type) {
|
||||
|
||||
Reference in New Issue
Block a user