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
10 changes: 10 additions & 0 deletions impeller/renderer/backend/gles/context_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ void ContextGLES::ResetThreadLocalState() const {
});
}

bool ContextGLES::EnqueueCommandBuffer(
std::shared_ptr<CommandBuffer> command_buffer) {
return true;
}

// |Context|
[[nodiscard]] bool ContextGLES::FlushCommandBuffers() {
return reactor_->React();
}

// |Context|
bool ContextGLES::AddTrackingFence(
const std::shared_ptr<Texture>& texture) const {
Expand Down
7 changes: 7 additions & 0 deletions impeller/renderer/backend/gles/context_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class ContextGLES final : public Context,
// |Context|
void ResetThreadLocalState() const override;

// |Context|
[[nodiscard]] bool EnqueueCommandBuffer(
std::shared_ptr<CommandBuffer> command_buffer) override;

// |Context|
[[nodiscard]] bool FlushCommandBuffers() override;

ContextGLES(const ContextGLES&) = delete;

ContextGLES& operator=(const ContextGLES&) = delete;
Expand Down
6 changes: 4 additions & 2 deletions impeller/renderer/backend/gles/reactor_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ std::optional<GLsync> ReactorGLES::GetGLFence(const HandleGLES& handle) const {
return std::nullopt;
}

bool ReactorGLES::AddOperation(Operation operation) {
bool ReactorGLES::AddOperation(Operation operation, bool defer) {
if (!operation) {
return false;
}
Expand All @@ -176,7 +176,9 @@ bool ReactorGLES::AddOperation(Operation operation) {
ops_[thread_id].emplace_back(std::move(operation));
}
// Attempt a reaction if able but it is not an error if this isn't possible.
[[maybe_unused]] auto result = React();
if (!defer) {
[[maybe_unused]] auto result = React();
}
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion impeller/renderer/backend/gles/reactor_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,12 @@ class ReactorGLES {
/// torn down.
///
/// @param[in] operation The operation
/// @param[in] defer If false, the reactor attempts to React after
/// adding this operation.
///
/// @return If the operation was successfully queued for completion.
///
[[nodiscard]] bool AddOperation(Operation operation);
[[nodiscard]] bool AddOperation(Operation operation, bool defer = false);

//----------------------------------------------------------------------------
/// @brief Register a cleanup callback that will be invokved with the
Expand Down
17 changes: 9 additions & 8 deletions impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,15 @@ bool RenderPassGLES::OnEncodeCommands(const Context& context) const {

std::shared_ptr<const RenderPassGLES> shared_this = shared_from_this();
auto tracer = ContextGLES::Cast(context).GetGPUTracer();
return reactor_->AddOperation([pass_data,
allocator = context.GetResourceAllocator(),
render_pass = std::move(shared_this),
tracer](const auto& reactor) {
auto result = EncodeCommandsInReactor(*pass_data, allocator, reactor,
render_pass->commands_, tracer);
FML_CHECK(result) << "Must be able to encode GL commands without error.";
});
return reactor_->AddOperation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats the operation that finally enqueues a non-deferred operation? Is there guaranteed to be one? Otherwise, these operations will be pending in the reactor for a potentially long time.

I'm thinking of texture, pipeline, and perhaps blits also adding non-deferred operations. But nothing jumps out at being always present no matter what.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[pass_data, allocator = context.GetResourceAllocator(),
render_pass = std::move(shared_this), tracer](const auto& reactor) {
auto result = EncodeCommandsInReactor(*pass_data, allocator, reactor,
render_pass->commands_, tracer);
FML_CHECK(result)
<< "Must be able to encode GL commands without error.";
},
/*defer=*/true);
}

} // namespace impeller
24 changes: 24 additions & 0 deletions impeller/renderer/backend/gles/test/reactor_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,29 @@ TEST(ReactorGLES, PerThreadOperationQueues) {
EXPECT_TRUE(op2_called);
}

TEST(ReactorGLES, CanDeferOperations) {
auto mock_gles = MockGLES::Init();
ProcTableGLES::Resolver resolver = kMockResolverGLES;
auto proc_table = std::make_unique<ProcTableGLES>(resolver);
auto worker = std::make_shared<TestWorker>();
auto reactor = std::make_shared<ReactorGLES>(std::move(proc_table));
reactor->AddWorker(worker);

// Add operation executes tasks as long as the reactor can run tasks on
// the current thread.
bool did_run = false;
EXPECT_TRUE(
reactor->AddOperation([&](const ReactorGLES&) { did_run = true; }));
EXPECT_TRUE(did_run);

//...unless defer=true is specified, which only enqueues in the reactor.
did_run = false;
EXPECT_TRUE(reactor->AddOperation([&](const ReactorGLES&) { did_run = true; },
/*defer=*/true));
EXPECT_FALSE(did_run);
EXPECT_TRUE(reactor->React());
EXPECT_TRUE(did_run);
}

} // namespace testing
} // namespace impeller