Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
../../../flutter/impeller/geometry/trig_unittests.cc
../../../flutter/impeller/golden_tests/README.md
../../../flutter/impeller/playground
../../../flutter/impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc
../../../flutter/impeller/renderer/backend/gles/test
../../../flutter/impeller/renderer/backend/metal/allocator_mtl_unittests.mm
../../../flutter/impeller/renderer/backend/metal/texture_mtl_unittests.mm
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/backend/gles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ config("gles_config") {
impeller_component("gles_unittests") {
testonly = true
sources = [
"buffer_bindings_gles_unittests.cc",
"test/capabilities_unittests.cc",
"test/formats_gles_unittests.cc",
"test/gpu_tracer_gles_unittests.cc",
Expand Down Expand Up @@ -104,5 +105,6 @@ impeller_component("gles") {
"../../:renderer",
"../../../shader_archive",
"//flutter/fml",
"//flutter/third_party/abseil-cpp/absl/container:flat_hash_map",
]
}
8 changes: 3 additions & 5 deletions impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,15 @@ bool BufferBindingsGLES::BindVertexAttributes(const ProcTableGLES& gl,
}

bool BufferBindingsGLES::BindUniformData(const ProcTableGLES& gl,
Allocator& transients_allocator,
const Bindings& vertex_bindings,
const Bindings& fragment_bindings) {
for (const auto& buffer : vertex_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
if (!BindUniformBuffer(gl, buffer.view)) {
return false;
}
}
for (const auto& buffer : fragment_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
if (!BindUniformBuffer(gl, buffer.view)) {
return false;
}
}
Expand Down Expand Up @@ -262,7 +261,7 @@ const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
size_t element_count = member.array_elements.value_or(1);
const std::string member_key =
CreateUniformMemberKey(metadata->name, member.name, element_count > 1);
const std::unordered_map<std::string, GLint>::iterator computed_location =
const absl::flat_hash_map<std::string, GLint>::iterator computed_location =
uniform_locations_.find(member_key);
if (computed_location == uniform_locations_.end()) {
// Uniform was not active.
Expand All @@ -275,7 +274,6 @@ const std::vector<GLint>& BufferBindingsGLES::ComputeUniformLocations(
}

bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
Allocator& transients_allocator,
const BufferResource& buffer) {
const ShaderMetadata* metadata = buffer.GetMetadata();
const DeviceBuffer* device_buffer = buffer.resource.GetBuffer();
Expand Down
21 changes: 15 additions & 6 deletions impeller/renderer/backend/gles/buffer_bindings_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include <unordered_map>
#include <vector>

#include "flutter/third_party/abseil-cpp/absl/container/flat_hash_map.h"
#include "impeller/core/shader_types.h"
#include "impeller/renderer/backend/gles/gles.h"
#include "impeller/renderer/backend/gles/proc_table_gles.h"
#include "impeller/renderer/command.h"

namespace impeller {

namespace testing {
FML_TEST_CLASS(BufferBindingsGLESTest, BindUniformData);
} // namespace testing

//------------------------------------------------------------------------------
/// @brief Sets up stage bindings for single draw call in the OpenGLES
/// backend.
Expand All @@ -37,13 +42,13 @@ class BufferBindingsGLES {
size_t vertex_offset);

bool BindUniformData(const ProcTableGLES& gl,
Allocator& transients_allocator,
const Bindings& vertex_bindings,
const Bindings& fragment_bindings);

bool UnbindVertexAttributes(const ProcTableGLES& gl);

private:
FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindUniformData);
//----------------------------------------------------------------------------
/// @brief The arguments to glVertexAttribPointer.
///
Expand All @@ -57,9 +62,9 @@ class BufferBindingsGLES {
};
std::vector<std::vector<VertexAttribPointer>> vertex_attrib_arrays_;

std::unordered_map<std::string, GLint> uniform_locations_;
absl::flat_hash_map<std::string, GLint> uniform_locations_;

using BindingMap = std::unordered_map<std::string, std::vector<GLint>>;
using BindingMap = absl::flat_hash_map<std::string, std::vector<GLint>>;
BindingMap binding_map_ = {};
GLuint vertex_array_object_ = 0;

Expand All @@ -68,9 +73,7 @@ class BufferBindingsGLES {

GLint ComputeTextureLocation(const ShaderMetadata* metadata);

bool BindUniformBuffer(const ProcTableGLES& gl,
Allocator& transients_allocator,
const BufferResource& buffer);
bool BindUniformBuffer(const ProcTableGLES& gl, const BufferResource& buffer);

std::optional<size_t> BindTextures(const ProcTableGLES& gl,
const Bindings& bindings,
Expand All @@ -80,6 +83,12 @@ class BufferBindingsGLES {
BufferBindingsGLES(const BufferBindingsGLES&) = delete;

BufferBindingsGLES& operator=(const BufferBindingsGLES&) = delete;

// For testing.
void SetUniformBindings(
absl::flat_hash_map<std::string, GLint> uniform_locations) {
uniform_locations_ = std::move(uniform_locations);
}
};

} // namespace impeller
Expand Down
50 changes: 50 additions & 0 deletions impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/testing/testing.h" // IWYU pragma: keep
#include "gtest/gtest.h"
#include "impeller/renderer/backend/gles/buffer_bindings_gles.h"
#include "impeller/renderer/backend/gles/device_buffer_gles.h"
#include "impeller/renderer/backend/gles/test/mock_gles.h"
#include "impeller/renderer/testing/mocks.h"

namespace impeller {
namespace testing {

TEST(BufferBindingsGLESTest, BindUniformData) {
BufferBindingsGLES bindings;
absl::flat_hash_map<std::string, GLint> uniform_bindings;
uniform_bindings["SHADERMETADATA.FOOBAR"] = 1;
bindings.SetUniformBindings(std::move(uniform_bindings));
std::shared_ptr<MockGLES> mock_gl = MockGLES::Init();
Bindings vertex_bindings;

ShaderMetadata shader_metadata = {
.name = "shader_metadata",
.members = {ShaderStructMemberMetadata{.type = ShaderType::kFloat,
.name = "foobar",
.offset = 0,
.size = sizeof(float),
.byte_length = sizeof(float)}}};
std::shared_ptr<ReactorGLES> reactor;
std::shared_ptr<Allocation> backing_store = std::make_shared<Allocation>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're using a real allocator here I would use this in place of the mock allocator above. In fact, the transients_allocator arg is actually unused so you could also just delete it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

ASSERT_TRUE(backing_store->Truncate(Bytes{sizeof(float)}));
DeviceBufferGLES device_buffer(DeviceBufferDescriptor{.size = sizeof(float)},
reactor, backing_store);
BufferView buffer_view(&device_buffer, Range(0, sizeof(float)));
vertex_bindings.buffers.push_back(BufferAndUniformSlot{
.slot =
ShaderUniformSlot{
.name = "foobar", .ext_res_0 = 0, .set = 0, .binding = 0},
.view = BufferResource(&shader_metadata, buffer_view)});
Bindings fragment_bindings;
EXPECT_TRUE(bindings.BindUniformData(mock_gl->GetProcTable(), vertex_bindings,
fragment_bindings));
std::vector<std::string> captured_calls = mock_gl->GetCapturedCalls();
EXPECT_TRUE(std::find(captured_calls.begin(), captured_calls.end(),
"glUniform1fv") != captured_calls.end());
}

} // namespace testing
} // namespace impeller
1 change: 0 additions & 1 deletion impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ void RenderPassGLES::ResetGLState(const ProcTableGLES& gl) {
/// Bind uniform data.
///
if (!vertex_desc_gles->BindUniformData(gl, //
*transients_allocator, //
command.vertex_bindings, //
command.fragment_bindings //
)) {
Expand Down
9 changes: 9 additions & 0 deletions impeller/renderer/backend/gles/test/mock_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ void mockDeleteTextures(GLsizei size, const GLuint* queries) {
static_assert(CheckSameSignature<decltype(mockDeleteQueriesEXT), //
decltype(glDeleteQueriesEXT)>::value);

void mockUniform1fv(GLint location, GLsizei count, const GLfloat* value) {
RecordGLCall("glUniform1fv");
}

static_assert(CheckSameSignature<decltype(mockUniform1fv), //
decltype(glUniform1fv)>::value);

std::shared_ptr<MockGLES> MockGLES::Init(
const std::optional<std::vector<const unsigned char*>>& extensions,
const char* version_string,
Expand Down Expand Up @@ -208,6 +215,8 @@ const ProcTableGLES::Resolver kMockResolverGLES = [](const char* name) {
return reinterpret_cast<void*>(mockGetQueryObjectui64vEXT);
} else if (strcmp(name, "glGetQueryObjectuivEXT") == 0) {
return reinterpret_cast<void*>(mockGetQueryObjectuivEXT);
} else if (strcmp(name, "glUniform1fv") == 0) {
return reinterpret_cast<void*>(mockUniform1fv);
} else {
return reinterpret_cast<void*>(&doNothing);
}
Expand Down
Loading