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

Commit 35336ad

Browse files
[Impeller] finish migration to new render pass API. (#49740)
Part of flutter/flutter#140804 Migrate the rest of the commands in impeller to use the new API. Hide RenderPass::AddCommand. On subsequent changes I will be able to begin making some of these methods virtual so we can add more direct pass through. Though the vulkan backend will be blocked on changes to descriptor sets: #49686
1 parent 80cfd35 commit 35336ad

27 files changed

+460
-484
lines changed

impeller/entity/contents/atlas_contents.cc

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ bool AtlasContents::Render(const ContentContext& renderer,
235235
}
236236
}
237237

238-
Command cmd;
239-
DEBUG_COMMAND_INFO(
240-
cmd, SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
241-
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
242-
cmd.stencil_reference = entity.GetClipDepth();
243-
auto options = OptionsFromPass(pass);
244-
cmd.pipeline = renderer.GetPorterDuffBlendPipeline(options);
238+
#ifdef IMPELLER_DEBUG
239+
pass.SetCommandLabel(
240+
SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
241+
#endif // IMPELLER_DEBUG
242+
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
243+
pass.SetStencilReference(entity.GetClipDepth());
244+
pass.SetPipeline(
245+
renderer.GetPorterDuffBlendPipeline(OptionsFromPass(pass)));
245246

246247
FS::FragInfo frag_info;
247248
VS::FrameInfo frame_info;
@@ -253,7 +254,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
253254
}
254255
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
255256
dst_sampler_descriptor);
256-
FS::BindTextureSamplerDst(cmd, texture_, dst_sampler);
257+
FS::BindTextureSamplerDst(pass, texture_, dst_sampler);
257258
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();
258259

259260
frag_info.output_alpha = alpha_;
@@ -269,14 +270,14 @@ bool AtlasContents::Render(const ContentContext& renderer,
269270
frag_info.dst_coeff_src_alpha = blend_coefficients[3];
270271
frag_info.dst_coeff_src_color = blend_coefficients[4];
271272

272-
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
273+
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
273274

274275
frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform();
275276

276277
auto uniform_view = host_buffer.EmplaceUniform(frame_info);
277-
VS::BindFrameInfo(cmd, uniform_view);
278+
VS::BindFrameInfo(pass, uniform_view);
278279

279-
return pass.AddCommand(std::move(cmd));
280+
return pass.Draw().ok();
280281
}
281282

282283
// Advanced blends.
@@ -396,8 +397,7 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
396397
return true;
397398
}
398399

399-
Command cmd;
400-
DEBUG_COMMAND_INFO(cmd, "AtlasTexture");
400+
pass.SetCommandLabel("AtlasTexture");
401401

402402
auto& host_buffer = renderer.GetTransientsBuffer();
403403

@@ -407,14 +407,14 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
407407
frame_info.alpha = alpha_;
408408

409409
auto options = OptionsFromPassAndEntity(pass, entity);
410-
cmd.pipeline = renderer.GetTexturePipeline(options);
411-
cmd.stencil_reference = entity.GetClipDepth();
412-
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
413-
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
414-
FS::BindTextureSampler(cmd, texture,
410+
pass.SetPipeline(renderer.GetTexturePipeline(options));
411+
pass.SetStencilReference(entity.GetClipDepth());
412+
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
413+
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
414+
FS::BindTextureSampler(pass, texture,
415415
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
416416
parent_.GetSamplerDescriptor()));
417-
return pass.AddCommand(std::move(cmd));
417+
return pass.Draw().ok();
418418
}
419419

420420
// AtlasColorContents
@@ -483,8 +483,7 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
483483
return true;
484484
}
485485

486-
Command cmd;
487-
DEBUG_COMMAND_INFO(cmd, "AtlasColors");
486+
pass.SetCommandLabel("AtlasColors");
488487

489488
auto& host_buffer = renderer.GetTransientsBuffer();
490489

@@ -496,12 +495,12 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
496495

497496
auto opts = OptionsFromPassAndEntity(pass, entity);
498497
opts.blend_mode = BlendMode::kSourceOver;
499-
cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
500-
cmd.stencil_reference = entity.GetClipDepth();
501-
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
502-
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
503-
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
504-
return pass.AddCommand(std::move(cmd));
498+
pass.SetPipeline(renderer.GetGeometryColorPipeline(opts));
499+
pass.SetStencilReference(entity.GetClipDepth());
500+
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
501+
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
502+
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
503+
return pass.Draw().ok();
505504
}
506505

507506
} // namespace impeller

impeller/entity/contents/clip_contents.cc

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,59 +80,58 @@ bool ClipContents::Render(const ContentContext& renderer,
8080

8181
VS::FrameInfo info;
8282

83-
Command cmd;
84-
8583
auto options = OptionsFromPass(pass);
8684
options.blend_mode = BlendMode::kDestination;
87-
cmd.stencil_reference = entity.GetClipDepth();
85+
pass.SetStencilReference(entity.GetClipDepth());
8886
options.stencil_compare = CompareFunction::kEqual;
8987
options.stencil_operation = StencilOperation::kIncrementClamp;
9088

9189
if (clip_op_ == Entity::ClipOperation::kDifference) {
9290
{
93-
DEBUG_COMMAND_INFO(cmd, "Difference Clip (Increment)");
91+
pass.SetCommandLabel("Difference Clip (Increment)");
9492

9593
auto points = Rect::MakeSize(pass.GetRenderTargetSize()).GetPoints();
9694
auto vertices =
9795
VertexBufferBuilder<VS::PerVertexData>{}
9896
.AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}})
9997
.CreateVertexBuffer(renderer.GetTransientsBuffer());
100-
cmd.BindVertices(std::move(vertices));
98+
99+
pass.SetVertexBuffer(std::move(vertices));
101100

102101
info.mvp = pass.GetOrthographicTransform();
103-
VS::BindFrameInfo(cmd,
102+
VS::BindFrameInfo(pass,
104103
renderer.GetTransientsBuffer().EmplaceUniform(info));
105104

106105
options.primitive_type = PrimitiveType::kTriangleStrip;
107-
cmd.pipeline = renderer.GetClipPipeline(options);
108-
pass.AddCommand(Command(cmd));
106+
pass.SetPipeline(renderer.GetClipPipeline(options));
107+
pass.Draw();
109108
}
110109

111110
{
112-
DEBUG_COMMAND_INFO(cmd, "Difference Clip (Punch)");
111+
pass.SetCommandLabel("Difference Clip (Punch)");
112+
pass.SetStencilReference(entity.GetClipDepth() + 1);
113113

114-
cmd.stencil_reference = entity.GetClipDepth() + 1;
115114
options.stencil_compare = CompareFunction::kEqual;
116115
options.stencil_operation = StencilOperation::kDecrementClamp;
117116
}
118117
} else {
119-
DEBUG_COMMAND_INFO(cmd, "Intersect Clip");
118+
pass.SetCommandLabel("Intersect Clip");
119+
120120
options.stencil_compare = CompareFunction::kEqual;
121121
options.stencil_operation = StencilOperation::kIncrementClamp;
122122
}
123123

124124
auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
125125
options.primitive_type = geometry_result.type;
126-
cmd.pipeline = renderer.GetClipPipeline(options);
126+
pass.SetPipeline(renderer.GetClipPipeline(options));
127127

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

131131
info.mvp = geometry_result.transform;
132-
VS::BindFrameInfo(cmd, renderer.GetTransientsBuffer().EmplaceUniform(info));
132+
VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
133133

134-
pass.AddCommand(std::move(cmd));
135-
return true;
134+
return pass.Draw().ok();
136135
}
137136

138137
/*******************************************************************************
@@ -176,15 +175,14 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
176175
RenderPass& pass) const {
177176
using VS = ClipPipeline::VertexShader;
178177

179-
Command cmd;
180-
DEBUG_COMMAND_INFO(cmd, "Restore Clip");
178+
pass.SetCommandLabel("Restore Clip");
181179
auto options = OptionsFromPass(pass);
182180
options.blend_mode = BlendMode::kDestination;
183181
options.stencil_compare = CompareFunction::kLess;
184182
options.stencil_operation = StencilOperation::kSetToReferenceValue;
185183
options.primitive_type = PrimitiveType::kTriangleStrip;
186-
cmd.pipeline = renderer.GetClipPipeline(options);
187-
cmd.stencil_reference = entity.GetClipDepth();
184+
pass.SetPipeline(renderer.GetClipPipeline(options));
185+
pass.SetStencilReference(entity.GetClipDepth());
188186

189187
// Create a rect that covers either the given restore area, or the whole
190188
// render target texture.
@@ -198,15 +196,14 @@ bool ClipRestoreContents::Render(const ContentContext& renderer,
198196
{Point(ltrb[0], ltrb[3])},
199197
{Point(ltrb[2], ltrb[3])},
200198
});
201-
cmd.BindVertices(
199+
pass.SetVertexBuffer(
202200
vtx_builder.CreateVertexBuffer(renderer.GetTransientsBuffer()));
203201

204202
VS::FrameInfo info;
205203
info.mvp = pass.GetOrthographicTransform();
206-
VS::BindFrameInfo(cmd, renderer.GetTransientsBuffer().EmplaceUniform(info));
204+
VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
207205

208-
pass.AddCommand(std::move(cmd));
209-
return true;
206+
return pass.Draw().ok();
210207
}
211208

212209
}; // namespace impeller

impeller/entity/contents/conical_gradient_contents.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,31 +158,30 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
158158
frame_info.mvp = geometry_result.transform;
159159
frame_info.matrix = GetInverseEffectTransform();
160160

161-
Command cmd;
162-
DEBUG_COMMAND_INFO(cmd, "ConicalGradientFill");
163-
cmd.stencil_reference = entity.GetClipDepth();
161+
pass.SetCommandLabel("ConicalGradientFill");
162+
pass.SetStencilReference(entity.GetClipDepth());
164163

165164
auto options = OptionsFromPassAndEntity(pass, entity);
166165
if (geometry_result.prevent_overdraw) {
167166
options.stencil_compare = CompareFunction::kEqual;
168167
options.stencil_operation = StencilOperation::kIncrementClamp;
169168
}
170169
options.primitive_type = geometry_result.type;
171-
cmd.pipeline = renderer.GetConicalGradientFillPipeline(options);
170+
pass.SetPipeline(renderer.GetConicalGradientFillPipeline(options));
172171

173-
cmd.BindVertices(std::move(geometry_result.vertex_buffer));
174-
FS::BindFragInfo(cmd,
172+
pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
173+
FS::BindFragInfo(pass,
175174
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
176175
SamplerDescriptor sampler_desc;
177176
sampler_desc.min_filter = MinMagFilter::kLinear;
178177
sampler_desc.mag_filter = MinMagFilter::kLinear;
179178
FS::BindTextureSampler(
180-
cmd, gradient_texture,
179+
pass, gradient_texture,
181180
renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
182-
VS::BindFrameInfo(cmd,
181+
VS::BindFrameInfo(pass,
183182
renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
184183

185-
if (!pass.AddCommand(std::move(cmd))) {
184+
if (!pass.Draw().ok()) {
186185
return false;
187186
}
188187

0 commit comments

Comments
 (0)