Skip to content

Commit 7261ed4

Browse files
author
Jonah Williams
authored
[Impeller] Prefer moving vertex buffer, place on command instead of binding object. (flutter#48630)
Placing the vertex buffer on the binding object meant that we were actually paying 2x the size cost for it (one for vertex bindings, one for fragment bindings). By moving this object onto command itself, we reduce the size and avoid spliting up the command state in a weird way. Also updates most of the contents to prefer moving the VertexBuffer.
1 parent 99e7496 commit 7261ed4

35 files changed

+125
-179
lines changed

impeller/core/vertex_buffer.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ namespace impeller {
1111

1212
struct VertexBuffer {
1313
BufferView vertex_buffer;
14+
15+
//----------------------------------------------------------------------------
16+
/// The index buffer binding used by the vertex shader stage.
1417
BufferView index_buffer;
15-
// The total count of vertices, either in the vertex_buffer if the
16-
// index_type is IndexType::kNone or in the index_buffer otherwise.
18+
19+
//----------------------------------------------------------------------------
20+
/// The total count of vertices, either in the vertex_buffer if the
21+
/// index_type is IndexType::kNone or in the index_buffer otherwise.
1722
size_t vertex_count = 0u;
23+
24+
//----------------------------------------------------------------------------
25+
/// The type of indices in the index buffer. The indices must be tightly
26+
/// packed in the index buffer.
27+
///
1828
IndexType index_type = IndexType::kUnknown;
1929

2030
constexpr explicit operator bool() const {

impeller/entity/contents/atlas_contents.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,10 @@ bool AtlasContents::Render(const ContentContext& renderer,
244244
}
245245
}
246246

247-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
248-
249247
Command cmd;
250248
DEBUG_COMMAND_INFO(
251249
cmd, SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
252-
cmd.BindVertices(vtx_buffer);
250+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
253251
cmd.stencil_reference = entity.GetClipDepth();
254252
auto options = OptionsFromPass(pass);
255253
cmd.pipeline = renderer.GetPorterDuffBlendPipeline(options);

impeller/entity/contents/clip_contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool ClipContents::Render(const ContentContext& renderer,
9898
VertexBufferBuilder<VS::PerVertexData>{}
9999
.AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}})
100100
.CreateVertexBuffer(pass.GetTransientsBuffer());
101-
cmd.BindVertices(vertices);
101+
cmd.BindVertices(std::move(vertices));
102102

103103
info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize());
104104
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));
@@ -126,7 +126,7 @@ bool ClipContents::Render(const ContentContext& renderer,
126126
cmd.pipeline = renderer.GetClipPipeline(options);
127127

128128
auto allocator = renderer.GetContext()->GetResourceAllocator();
129-
cmd.BindVertices(geometry_result.vertex_buffer);
129+
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
130130

131131
info.mvp = geometry_result.transform;
132132
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info));

impeller/entity/contents/conical_gradient_contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer,
107107
options.primitive_type = geometry_result.type;
108108
cmd.pipeline = renderer.GetConicalGradientSSBOFillPipeline(options);
109109

110-
cmd.BindVertices(geometry_result.vertex_buffer);
110+
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
111111
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
112112
FS::BindColorData(cmd, color_buffer);
113113
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));
@@ -173,7 +173,7 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
173173
options.primitive_type = geometry_result.type;
174174
cmd.pipeline = renderer.GetConicalGradientFillPipeline(options);
175175

176-
cmd.BindVertices(geometry_result.vertex_buffer);
176+
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
177177
FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info));
178178
SamplerDescriptor sampler_desc;
179179
sampler_desc.min_filter = MinMagFilter::kLinear;

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static std::optional<Entity> AdvancedBlend(
169169
Command cmd;
170170
DEBUG_COMMAND_INFO(cmd, SPrintF("Advanced Blend Filter (%s)",
171171
BlendModeToString(blend_mode)));
172-
cmd.BindVertices(vtx_buffer);
172+
cmd.BindVertices(std::move(vtx_buffer));
173173
cmd.pipeline = std::move(pipeline);
174174

175175
typename FS::BlendInfo blend_info;
@@ -289,7 +289,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
289289
Command cmd;
290290
DEBUG_COMMAND_INFO(cmd, SPrintF("Foreground Advanced Blend Filter (%s)",
291291
BlendModeToString(blend_mode)));
292-
cmd.BindVertices(vtx_buffer);
292+
cmd.BindVertices(std::move(vtx_buffer));
293293
cmd.stencil_reference = entity.GetClipDepth();
294294
auto options = OptionsFromPass(pass);
295295
options.primitive_type = PrimitiveType::kTriangleStrip;
@@ -460,7 +460,7 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
460460
Command cmd;
461461
DEBUG_COMMAND_INFO(cmd, SPrintF("Foreground PorterDuff Blend Filter (%s)",
462462
BlendModeToString(blend_mode)));
463-
cmd.BindVertices(vtx_buffer);
463+
cmd.BindVertices(std::move(vtx_buffer));
464464
cmd.stencil_reference = entity.GetClipDepth();
465465
auto options = OptionsFromPass(pass);
466466
options.primitive_type = PrimitiveType::kTriangleStrip;
@@ -583,8 +583,7 @@ static std::optional<Entity> PipelineBlend(
583583
{Point(0, size.height), Point(0, 1)},
584584
{Point(size.width, size.height), Point(1, 1)},
585585
});
586-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
587-
cmd.BindVertices(vtx_buffer);
586+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
588587

589588
VS::FrameInfo frame_info;
590589
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *

impeller/entity/contents/filters/border_mask_blur_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,14 @@ std::optional<Entity> BorderMaskBlurFilterContents::RenderFilter(
102102
coverage.origin.y + coverage.size.height},
103103
input_uvs[3]},
104104
});
105-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
106105

107106
Command cmd;
108107
DEBUG_COMMAND_INFO(cmd, "Border Mask Blur Filter");
109108
auto options = OptionsFromPassAndEntity(pass, entity);
110109
options.primitive_type = PrimitiveType::kTriangleStrip;
111110

112111
cmd.pipeline = renderer.GetBorderMaskBlurPipeline(options);
113-
cmd.BindVertices(vtx_buffer);
112+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
114113
cmd.stencil_reference = entity.GetClipDepth();
115114

116115
VS::FrameInfo frame_info;

impeller/entity/contents/filters/color_matrix_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ std::optional<Entity> ColorMatrixFilterContents::RenderFilter(
7373
{Point(1, 1)},
7474
});
7575
auto& host_buffer = pass.GetTransientsBuffer();
76-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
77-
cmd.BindVertices(vtx_buffer);
76+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
7877

7978
VS::FrameInfo frame_info;
8079
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *

impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
174174
{Point(0, 1), input_uvs[2]},
175175
{Point(1, 1), input_uvs[3]},
176176
});
177-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
178177

179178
VS::FrameInfo frame_info;
180179
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
@@ -195,7 +194,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
195194
Command cmd;
196195
DEBUG_COMMAND_INFO(cmd, SPrintF("Gaussian Blur Filter (Radius=%.2f)",
197196
transformed_blur_radius_length));
198-
cmd.BindVertices(vtx_buffer);
197+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
199198

200199
auto options = OptionsFromPass(pass);
201200
options.primitive_type = PrimitiveType::kTriangleStrip;

impeller/entity/contents/filters/gaussian_blur_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void BindVertices(Command& cmd,
4444
std::initializer_list<typename T::PerVertexData>&& vertices) {
4545
VertexBufferBuilder<typename T::PerVertexData> vtx_builder;
4646
vtx_builder.AddVertices(vertices);
47-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
48-
cmd.BindVertices(vtx_buffer);
47+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
4948
}
5049

5150
Matrix MakeAnchorScale(const Point& anchor, Vector2 scale) {

impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ std::optional<Entity> LinearToSrgbFilterContents::RenderFilter(
6464
});
6565

6666
auto& host_buffer = pass.GetTransientsBuffer();
67-
auto vtx_buffer = vtx_builder.CreateVertexBuffer(host_buffer);
68-
cmd.BindVertices(vtx_buffer);
67+
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
6968

7069
VS::FrameInfo frame_info;
7170
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *

0 commit comments

Comments
 (0)