Skip to content

Commit

Permalink
[Impeller] finish migration to new render pass API. (flutter#49740)
Browse files Browse the repository at this point in the history
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: flutter#49686
  • Loading branch information
jonahwilliams authored Jan 12, 2024
1 parent 80cfd35 commit 35336ad
Show file tree
Hide file tree
Showing 27 changed files with 460 additions and 484 deletions.
53 changes: 26 additions & 27 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ bool AtlasContents::Render(const ContentContext& renderer,
}
}

Command cmd;
DEBUG_COMMAND_INFO(
cmd, SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer));
cmd.stencil_reference = entity.GetClipDepth();
auto options = OptionsFromPass(pass);
cmd.pipeline = renderer.GetPorterDuffBlendPipeline(options);
#ifdef IMPELLER_DEBUG
pass.SetCommandLabel(
SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode_)));
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetPipeline(
renderer.GetPorterDuffBlendPipeline(OptionsFromPass(pass)));

FS::FragInfo frag_info;
VS::FrameInfo frame_info;
Expand All @@ -253,7 +254,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
}
auto dst_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler(
dst_sampler_descriptor);
FS::BindTextureSamplerDst(cmd, texture_, dst_sampler);
FS::BindTextureSamplerDst(pass, texture_, dst_sampler);
frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale();

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

FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));

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

auto uniform_view = host_buffer.EmplaceUniform(frame_info);
VS::BindFrameInfo(cmd, uniform_view);
VS::BindFrameInfo(pass, uniform_view);

return pass.AddCommand(std::move(cmd));
return pass.Draw().ok();
}

// Advanced blends.
Expand Down Expand Up @@ -396,8 +397,7 @@ bool AtlasTextureContents::Render(const ContentContext& renderer,
return true;
}

Command cmd;
DEBUG_COMMAND_INFO(cmd, "AtlasTexture");
pass.SetCommandLabel("AtlasTexture");

auto& host_buffer = renderer.GetTransientsBuffer();

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

auto options = OptionsFromPassAndEntity(pass, entity);
cmd.pipeline = renderer.GetTexturePipeline(options);
cmd.stencil_reference = entity.GetClipDepth();
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindTextureSampler(cmd, texture,
pass.SetPipeline(renderer.GetTexturePipeline(options));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
FS::BindTextureSampler(pass, texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(
parent_.GetSamplerDescriptor()));
return pass.AddCommand(std::move(cmd));
return pass.Draw().ok();
}

// AtlasColorContents
Expand Down Expand Up @@ -483,8 +483,7 @@ bool AtlasColorContents::Render(const ContentContext& renderer,
return true;
}

Command cmd;
DEBUG_COMMAND_INFO(cmd, "AtlasColors");
pass.SetCommandLabel("AtlasColors");

auto& host_buffer = renderer.GetTransientsBuffer();

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

auto opts = OptionsFromPassAndEntity(pass, entity);
opts.blend_mode = BlendMode::kSourceOver;
cmd.pipeline = renderer.GetGeometryColorPipeline(opts);
cmd.stencil_reference = entity.GetClipDepth();
cmd.BindVertices(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
return pass.AddCommand(std::move(cmd));
pass.SetPipeline(renderer.GetGeometryColorPipeline(opts));
pass.SetStencilReference(entity.GetClipDepth());
pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer));
VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
return pass.Draw().ok();
}

} // namespace impeller
45 changes: 21 additions & 24 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,59 +80,58 @@ bool ClipContents::Render(const ContentContext& renderer,

VS::FrameInfo info;

Command cmd;

auto options = OptionsFromPass(pass);
options.blend_mode = BlendMode::kDestination;
cmd.stencil_reference = entity.GetClipDepth();
pass.SetStencilReference(entity.GetClipDepth());
options.stencil_compare = CompareFunction::kEqual;
options.stencil_operation = StencilOperation::kIncrementClamp;

if (clip_op_ == Entity::ClipOperation::kDifference) {
{
DEBUG_COMMAND_INFO(cmd, "Difference Clip (Increment)");
pass.SetCommandLabel("Difference Clip (Increment)");

auto points = Rect::MakeSize(pass.GetRenderTargetSize()).GetPoints();
auto vertices =
VertexBufferBuilder<VS::PerVertexData>{}
.AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}})
.CreateVertexBuffer(renderer.GetTransientsBuffer());
cmd.BindVertices(std::move(vertices));

pass.SetVertexBuffer(std::move(vertices));

info.mvp = pass.GetOrthographicTransform();
VS::BindFrameInfo(cmd,
VS::BindFrameInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(info));

options.primitive_type = PrimitiveType::kTriangleStrip;
cmd.pipeline = renderer.GetClipPipeline(options);
pass.AddCommand(Command(cmd));
pass.SetPipeline(renderer.GetClipPipeline(options));
pass.Draw();
}

{
DEBUG_COMMAND_INFO(cmd, "Difference Clip (Punch)");
pass.SetCommandLabel("Difference Clip (Punch)");
pass.SetStencilReference(entity.GetClipDepth() + 1);

cmd.stencil_reference = entity.GetClipDepth() + 1;
options.stencil_compare = CompareFunction::kEqual;
options.stencil_operation = StencilOperation::kDecrementClamp;
}
} else {
DEBUG_COMMAND_INFO(cmd, "Intersect Clip");
pass.SetCommandLabel("Intersect Clip");

options.stencil_compare = CompareFunction::kEqual;
options.stencil_operation = StencilOperation::kIncrementClamp;
}

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

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

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

pass.AddCommand(std::move(cmd));
return true;
return pass.Draw().ok();
}

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

Command cmd;
DEBUG_COMMAND_INFO(cmd, "Restore Clip");
pass.SetCommandLabel("Restore Clip");
auto options = OptionsFromPass(pass);
options.blend_mode = BlendMode::kDestination;
options.stencil_compare = CompareFunction::kLess;
options.stencil_operation = StencilOperation::kSetToReferenceValue;
options.primitive_type = PrimitiveType::kTriangleStrip;
cmd.pipeline = renderer.GetClipPipeline(options);
cmd.stencil_reference = entity.GetClipDepth();
pass.SetPipeline(renderer.GetClipPipeline(options));
pass.SetStencilReference(entity.GetClipDepth());

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

VS::FrameInfo info;
info.mvp = pass.GetOrthographicTransform();
VS::BindFrameInfo(cmd, renderer.GetTransientsBuffer().EmplaceUniform(info));
VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));

pass.AddCommand(std::move(cmd));
return true;
return pass.Draw().ok();
}

}; // namespace impeller
17 changes: 8 additions & 9 deletions impeller/entity/contents/conical_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,30 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer,
frame_info.mvp = geometry_result.transform;
frame_info.matrix = GetInverseEffectTransform();

Command cmd;
DEBUG_COMMAND_INFO(cmd, "ConicalGradientFill");
cmd.stencil_reference = entity.GetClipDepth();
pass.SetCommandLabel("ConicalGradientFill");
pass.SetStencilReference(entity.GetClipDepth());

auto options = OptionsFromPassAndEntity(pass, entity);
if (geometry_result.prevent_overdraw) {
options.stencil_compare = CompareFunction::kEqual;
options.stencil_operation = StencilOperation::kIncrementClamp;
}
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetConicalGradientFillPipeline(options);
pass.SetPipeline(renderer.GetConicalGradientFillPipeline(options));

cmd.BindVertices(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(cmd,
pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
FS::BindFragInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frag_info));
SamplerDescriptor sampler_desc;
sampler_desc.min_filter = MinMagFilter::kLinear;
sampler_desc.mag_filter = MinMagFilter::kLinear;
FS::BindTextureSampler(
cmd, gradient_texture,
pass, gradient_texture,
renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc));
VS::BindFrameInfo(cmd,
VS::BindFrameInfo(pass,
renderer.GetTransientsBuffer().EmplaceUniform(frame_info));

if (!pass.AddCommand(std::move(cmd))) {
if (!pass.Draw().ok()) {
return false;
}

Expand Down
Loading

0 comments on commit 35336ad

Please sign in to comment.