[Impeller] started std::moving Commands instead of copying (flutter/engine#44508)

Each Command is 440 B so copying them when adding them to the RenderPass adds up.  This change represents a 36% speedup in `TextContents::Render` when scrolling around on the main screen of the of the Flutter Gallery.

issue: https://github.com/flutter/flutter/issues/131787

## before
<img width="1217" alt="Screenshot 2023-08-08 at 1 11 30 PM" src="https://github.com/flutter/engine/assets/30870216/3545f9cd-b596-4a7c-bcf0-a20c7f7c40e8">

## after

<img width="1048" alt="Screenshot 2023-08-08 at 1 10 05 PM" src="https://github.com/flutter/engine/assets/30870216/3443ec70-5d4f-4022-b3e7-41b13c25cb00">

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke
2023-08-08 14:27:49 -07:00
committed by GitHub
parent a31c651ebb
commit 025925411e
10 changed files with 17 additions and 17 deletions

View File

@@ -49,7 +49,7 @@ bool CheckerboardContents::Render(const ContentContext& renderer,
frag_info.square_size = square_size_;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
}

View File

@@ -107,7 +107,7 @@ bool ClipContents::Render(const ContentContext& renderer,
options.primitive_type = PrimitiveType::kTriangleStrip;
cmd.pipeline = renderer.GetClipPipeline(options);
pass.AddCommand(cmd);
pass.AddCommand(Command(cmd));
}
{

View File

@@ -180,7 +180,7 @@ static std::optional<Entity> AdvancedBlend(
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
};
@@ -336,7 +336,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
};
CoverageProc coverage_proc =
[coverage](const Entity& entity) -> std::optional<Rect> {
@@ -476,7 +476,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
};
CoverageProc coverage_proc =
@@ -573,7 +573,7 @@ static std::optional<Entity> PipelineBlend(
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
};

View File

@@ -303,7 +303,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
FS::BindMaskInfo(cmd, host_buffer.EmplaceUniform(mask_info));
}
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
};
Vector2 scale;

View File

@@ -135,7 +135,7 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
};
auto out_texture = renderer.MakeSubpass("Directional Morphology Filter",

View File

@@ -154,7 +154,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
frag_info.src_input_alpha = src_snapshot->opacity;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
}
} // namespace impeller

View File

@@ -212,7 +212,7 @@ bool TextContents::Render(const ContentContext& renderer,
.index_type = IndexType::kNone,
});
return pass.AddCommand(cmd);
return pass.AddCommand(std::move(cmd));
}
} // namespace impeller

View File

@@ -43,7 +43,7 @@ void RenderPass::SetLabel(std::string label) {
OnSetLabel(std::move(label));
}
bool RenderPass::AddCommand(Command command) {
bool RenderPass::AddCommand(Command&& command) {
if (!command) {
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
return false;

View File

@@ -47,7 +47,7 @@ class RenderPass {
///
/// @return If the command was valid for subsequent commitment.
///
bool AddCommand(Command command);
bool AddCommand(Command&& command);
//----------------------------------------------------------------------------
/// @brief Encode the recorded commands to the underlying command buffer.

View File

@@ -270,7 +270,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
Matrix::MakeTranslation({i * 50.0f, j * 50.0f, 0.0f});
VS::BindUniformBuffer(
cmd, pass.GetTransientsBuffer().EmplaceUniform(uniforms));
if (!pass.AddCommand(cmd)) {
if (!pass.AddCommand(std::move(cmd))) {
return false;
}
}
@@ -445,7 +445,7 @@ TEST_P(RendererTest, CanRenderInstanced) {
cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer()));
cmd.instance_count = kInstancesCount;
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
}));
}
@@ -863,7 +863,7 @@ TEST_P(RendererTest, TheImpeller) {
FS::BindBlueNoise(cmd, blue_noise, noise_sampler);
FS::BindCubeMap(cmd, cube_map, cube_map_sampler);
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
};
OpenPlaygroundHere(callback);
@@ -919,7 +919,7 @@ TEST_P(RendererTest, ArrayUniforms) {
FS::BindFragInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
};
OpenPlaygroundHere(callback);
@@ -964,7 +964,7 @@ TEST_P(RendererTest, InactiveUniforms) {
FS::BindFragInfo(cmd,
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
pass.AddCommand(cmd);
pass.AddCommand(std::move(cmd));
return true;
};
OpenPlaygroundHere(callback);