Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 00b6b63

Browse files
authored
[Impeller] started std::moving Commands instead of copying (#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: flutter/flutter#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
1 parent 82292b8 commit 00b6b63

10 files changed

+17
-17
lines changed

impeller/entity/contents/checkerboard_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool CheckerboardContents::Render(const ContentContext& renderer,
4949
frag_info.square_size = square_size_;
5050
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
5151

52-
pass.AddCommand(cmd);
52+
pass.AddCommand(std::move(cmd));
5353

5454
return true;
5555
}

impeller/entity/contents/clip_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool ClipContents::Render(const ContentContext& renderer,
107107

108108
options.primitive_type = PrimitiveType::kTriangleStrip;
109109
cmd.pipeline = renderer.GetClipPipeline(options);
110-
pass.AddCommand(cmd);
110+
pass.AddCommand(Command(cmd));
111111
}
112112

113113
{

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static std::optional<Entity> AdvancedBlend(
180180

181181
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
182182
VS::BindFrameInfo(cmd, uniform_view);
183-
pass.AddCommand(cmd);
183+
pass.AddCommand(std::move(cmd));
184184

185185
return true;
186186
};
@@ -336,7 +336,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
336336
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
337337
VS::BindFrameInfo(cmd, uniform_view);
338338

339-
return pass.AddCommand(cmd);
339+
return pass.AddCommand(std::move(cmd));
340340
};
341341
CoverageProc coverage_proc =
342342
[coverage](const Entity& entity) -> std::optional<Rect> {
@@ -476,7 +476,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
476476
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
477477
VS::BindFrameInfo(cmd, uniform_view);
478478

479-
return pass.AddCommand(cmd);
479+
return pass.AddCommand(std::move(cmd));
480480
};
481481

482482
CoverageProc coverage_proc =
@@ -573,7 +573,7 @@ static std::optional<Entity> PipelineBlend(
573573
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
574574
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
575575

576-
pass.AddCommand(cmd);
576+
pass.AddCommand(std::move(cmd));
577577
return true;
578578
};
579579

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
303303
FS::BindMaskInfo(cmd, host_buffer.EmplaceUniform(mask_info));
304304
}
305305

306-
return pass.AddCommand(cmd);
306+
return pass.AddCommand(std::move(cmd));
307307
};
308308

309309
Vector2 scale;

impeller/entity/contents/filters/morphology_filter_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
135135
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
136136
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
137137

138-
return pass.AddCommand(cmd);
138+
return pass.AddCommand(std::move(cmd));
139139
};
140140

141141
auto out_texture = renderer.MakeSubpass("Directional Morphology Filter",

impeller/entity/contents/framebuffer_blend_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
154154
frag_info.src_input_alpha = src_snapshot->opacity;
155155
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
156156

157-
return pass.AddCommand(cmd);
157+
return pass.AddCommand(std::move(cmd));
158158
}
159159

160160
} // namespace impeller

impeller/entity/contents/text_contents.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ bool TextContents::Render(const ContentContext& renderer,
212212
.index_type = IndexType::kNone,
213213
});
214214

215-
return pass.AddCommand(cmd);
215+
return pass.AddCommand(std::move(cmd));
216216
}
217217

218218
} // namespace impeller

impeller/renderer/render_pass.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void RenderPass::SetLabel(std::string label) {
4343
OnSetLabel(std::move(label));
4444
}
4545

46-
bool RenderPass::AddCommand(Command command) {
46+
bool RenderPass::AddCommand(Command&& command) {
4747
if (!command) {
4848
VALIDATION_LOG << "Attempted to add an invalid command to the render pass.";
4949
return false;

impeller/renderer/render_pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RenderPass {
4747
///
4848
/// @return If the command was valid for subsequent commitment.
4949
///
50-
bool AddCommand(Command command);
50+
bool AddCommand(Command&& command);
5151

5252
//----------------------------------------------------------------------------
5353
/// @brief Encode the recorded commands to the underlying command buffer.

impeller/renderer/renderer_unittests.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) {
270270
Matrix::MakeTranslation({i * 50.0f, j * 50.0f, 0.0f});
271271
VS::BindUniformBuffer(
272272
cmd, pass.GetTransientsBuffer().EmplaceUniform(uniforms));
273-
if (!pass.AddCommand(cmd)) {
273+
if (!pass.AddCommand(std::move(cmd))) {
274274
return false;
275275
}
276276
}
@@ -445,7 +445,7 @@ TEST_P(RendererTest, CanRenderInstanced) {
445445
cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer()));
446446

447447
cmd.instance_count = kInstancesCount;
448-
pass.AddCommand(cmd);
448+
pass.AddCommand(std::move(cmd));
449449
return true;
450450
}));
451451
}
@@ -863,7 +863,7 @@ TEST_P(RendererTest, TheImpeller) {
863863
FS::BindBlueNoise(cmd, blue_noise, noise_sampler);
864864
FS::BindCubeMap(cmd, cube_map, cube_map_sampler);
865865

866-
pass.AddCommand(cmd);
866+
pass.AddCommand(std::move(cmd));
867867
return true;
868868
};
869869
OpenPlaygroundHere(callback);
@@ -919,7 +919,7 @@ TEST_P(RendererTest, ArrayUniforms) {
919919
FS::BindFragInfo(cmd,
920920
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
921921

922-
pass.AddCommand(cmd);
922+
pass.AddCommand(std::move(cmd));
923923
return true;
924924
};
925925
OpenPlaygroundHere(callback);
@@ -964,7 +964,7 @@ TEST_P(RendererTest, InactiveUniforms) {
964964
FS::BindFragInfo(cmd,
965965
pass.GetTransientsBuffer().EmplaceUniform(fs_uniform));
966966

967-
pass.AddCommand(cmd);
967+
pass.AddCommand(std::move(cmd));
968968
return true;
969969
};
970970
OpenPlaygroundHere(callback);

0 commit comments

Comments
 (0)