Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added ifdefs where we do runtime string creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the macro style we had previously. Did you find the string creation wasn't getting stripped out?

FWIW this could be transformed to a static string too since we only have so many blend modes. I did that at some point but the PR got caught up and dropped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings were still getting formatted, then dropped. We could add more static strings for these, I wouldn't be opposed. Feedback I got on the macro approach was that everyone hated it 😆

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is still incurring a copy because the parameter takes a std::string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderPass::OnSetLabel takes an std::string, it doesn't hit that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderPass label vs Command label

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename SetCommandLabel at some point since the concept of Command has been eliminated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that it would be better if the RenderPass label was provided during construction instead of via a Setter. Then we just need "SetLabel"


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