diff --git a/engine/src/flutter/impeller/entity/contents/checkerboard_contents.cc b/engine/src/flutter/impeller/entity/contents/checkerboard_contents.cc index 91f6959bf6..80a11e4d0f 100644 --- a/engine/src/flutter/impeller/entity/contents/checkerboard_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/checkerboard_contents.cc @@ -4,11 +4,8 @@ #include "impeller/entity/contents/checkerboard_contents.h" -#include - #include "impeller/core/formats.h" #include "impeller/entity/contents/content_context.h" -#include "impeller/renderer/command.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/vertex_buffer_builder.h" @@ -26,15 +23,11 @@ bool CheckerboardContents::Render(const ContentContext& renderer, using VS = CheckerboardPipeline::VertexShader; using FS = CheckerboardPipeline::FragmentShader; - Command cmd; - DEBUG_COMMAND_INFO(cmd, "Checkerboard"); - auto options = OptionsFromPass(pass); options.blend_mode = BlendMode::kSourceOver; options.stencil_compare = CompareFunction::kAlways; // Ignore all clips. options.stencil_operation = StencilOperation::kKeep; options.primitive_type = PrimitiveType::kTriangleStrip; - cmd.pipeline = renderer.GetCheckerboardPipeline(options); VertexBufferBuilder vtx_builder; vtx_builder.AddVertices({ @@ -43,16 +36,17 @@ bool CheckerboardContents::Render(const ContentContext& renderer, {Point(-1, 1)}, {Point(1, 1)}, }); - cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); + + pass.SetCommandLabel("Checkerboard"); + pass.SetPipeline(renderer.GetCheckerboardPipeline(options)); + pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer)); FS::FragInfo frag_info; frag_info.color = color_; frag_info.square_size = square_size_; - FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info)); + FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); - pass.AddCommand(std::move(cmd)); - - return true; + return pass.Draw().ok(); } std::optional CheckerboardContents::GetCoverage( diff --git a/engine/src/flutter/impeller/entity/contents/color_source_contents.cc b/engine/src/flutter/impeller/entity/contents/color_source_contents.cc index 48731f3d3f..18bc16608a 100644 --- a/engine/src/flutter/impeller/entity/contents/color_source_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/color_source_contents.cc @@ -6,7 +6,6 @@ #include "impeller/entity/entity.h" #include "impeller/geometry/matrix.h" -#include "impeller/geometry/point.h" namespace impeller { diff --git a/engine/src/flutter/impeller/entity/contents/color_source_contents.h b/engine/src/flutter/impeller/entity/contents/color_source_contents.h index ca21097664..83fe120aed 100644 --- a/engine/src/flutter/impeller/entity/contents/color_source_contents.h +++ b/engine/src/flutter/impeller/entity/contents/color_source_contents.h @@ -5,11 +5,9 @@ #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_COLOR_SOURCE_CONTENTS_H_ #define FLUTTER_IMPELLER_ENTITY_CONTENTS_COLOR_SOURCE_CONTENTS_H_ -#include "flutter/fml/macros.h" #include "impeller/entity/contents/contents.h" #include "impeller/entity/geometry/geometry.h" #include "impeller/geometry/matrix.h" -#include "impeller/geometry/path.h" namespace impeller { diff --git a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc index 28c738ec9b..e1789f1a9f 100644 --- a/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/conical_gradient_contents.cc @@ -90,10 +90,6 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "ConicalGradientSSBOFill"); - cmd.stencil_reference = entity.GetClipDepth(); - auto geometry_result = GetGeometry()->GetPositionBuffer(renderer, entity, pass); auto options = OptionsFromPassAndEntity(pass, entity); @@ -102,16 +98,18 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, options.stencil_operation = StencilOperation::kIncrementClamp; } options.primitive_type = geometry_result.type; - cmd.pipeline = renderer.GetConicalGradientSSBOFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, + pass.SetCommandLabel("ConicalGradientSSBOFill"); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetPipeline(renderer.GetConicalGradientSSBOFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindFragInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, + FS::BindColorData(pass, color_buffer); + VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } diff --git a/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc index fddd2c3b0b..2158a0aac4 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc @@ -101,15 +101,9 @@ std::optional BorderMaskBlurFilterContents::RenderFilter( {{origin.x + size.width, origin.y + size.height}, input_uvs[3]}, }); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "Border Mask Blur Filter"); auto options = OptionsFromPassAndEntity(pass, entity); options.primitive_type = PrimitiveType::kTriangleStrip; - cmd.pipeline = renderer.GetBorderMaskBlurPipeline(options); - cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); - cmd.stencil_reference = entity.GetClipDepth(); - VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); frame_info.texture_sampler_y_coord_scale = @@ -121,13 +115,18 @@ std::optional BorderMaskBlurFilterContents::RenderFilter( frag_info.inner_blur_factor = inner_blur_factor; frag_info.outer_blur_factor = outer_blur_factor; - FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info)); - VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info)); + pass.SetCommandLabel("Border Mask Blur Filter"); + pass.SetPipeline(renderer.GetBorderMaskBlurPipeline(options)); + pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer)); + pass.SetStencilReference(entity.GetClipDepth()); + + FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); + VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({}); - FS::BindTextureSampler(cmd, input_snapshot->texture, sampler); + FS::BindTextureSampler(pass, input_snapshot->texture, sampler); - return pass.AddCommand(std::move(cmd)); + return pass.Draw().ok(); }; CoverageProc coverage_proc = diff --git a/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc b/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc index 91445c39c7..1f454fe0ad 100644 --- a/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/framebuffer_blend_contents.cc @@ -70,56 +70,55 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer, options.blend_mode = BlendMode::kSource; options.primitive_type = PrimitiveType::kTriangleStrip; - Command cmd; - DEBUG_COMMAND_INFO(cmd, "Framebuffer Advanced Blend Filter"); - cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); - cmd.stencil_reference = entity.GetClipDepth(); + pass.SetCommandLabel("Framebuffer Advanced Blend Filter"); + pass.SetVertexBuffer(vtx_builder.CreateVertexBuffer(host_buffer)); + pass.SetStencilReference(entity.GetClipDepth()); switch (blend_mode_) { case BlendMode::kScreen: - cmd.pipeline = renderer.GetFramebufferBlendScreenPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendScreenPipeline(options)); break; case BlendMode::kOverlay: - cmd.pipeline = renderer.GetFramebufferBlendOverlayPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendOverlayPipeline(options)); break; case BlendMode::kDarken: - cmd.pipeline = renderer.GetFramebufferBlendDarkenPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendDarkenPipeline(options)); break; case BlendMode::kLighten: - cmd.pipeline = renderer.GetFramebufferBlendLightenPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendLightenPipeline(options)); break; case BlendMode::kColorDodge: - cmd.pipeline = renderer.GetFramebufferBlendColorDodgePipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendColorDodgePipeline(options)); break; case BlendMode::kColorBurn: - cmd.pipeline = renderer.GetFramebufferBlendColorBurnPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendColorBurnPipeline(options)); break; case BlendMode::kHardLight: - cmd.pipeline = renderer.GetFramebufferBlendHardLightPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendHardLightPipeline(options)); break; case BlendMode::kSoftLight: - cmd.pipeline = renderer.GetFramebufferBlendSoftLightPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendSoftLightPipeline(options)); break; case BlendMode::kDifference: - cmd.pipeline = renderer.GetFramebufferBlendDifferencePipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendDifferencePipeline(options)); break; case BlendMode::kExclusion: - cmd.pipeline = renderer.GetFramebufferBlendExclusionPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendExclusionPipeline(options)); break; case BlendMode::kMultiply: - cmd.pipeline = renderer.GetFramebufferBlendMultiplyPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendMultiplyPipeline(options)); break; case BlendMode::kHue: - cmd.pipeline = renderer.GetFramebufferBlendHuePipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendHuePipeline(options)); break; case BlendMode::kSaturation: - cmd.pipeline = renderer.GetFramebufferBlendSaturationPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendSaturationPipeline(options)); break; case BlendMode::kColor: - cmd.pipeline = renderer.GetFramebufferBlendColorPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendColorPipeline(options)); break; case BlendMode::kLuminosity: - cmd.pipeline = renderer.GetFramebufferBlendLuminosityPipeline(options); + pass.SetPipeline(renderer.GetFramebufferBlendLuminosityPipeline(options)); break; default: return false; @@ -135,16 +134,16 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer, } auto src_sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler( src_sampler_descriptor); - FS::BindTextureSamplerSrc(cmd, src_snapshot->texture, src_sampler); + FS::BindTextureSamplerSrc(pass, src_snapshot->texture, src_sampler); frame_info.mvp = pass.GetOrthographicTransform() * src_snapshot->transform; frame_info.src_y_coord_scale = src_snapshot->texture->GetYCoordScale(); - VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info)); + VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); frag_info.src_input_alpha = src_snapshot->opacity; - FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info)); + FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); - return pass.AddCommand(std::move(cmd)); + return pass.Draw().ok(); } } // namespace impeller diff --git a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc index 60e903c81f..5c9fbadfdb 100644 --- a/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/linear_gradient_contents.cc @@ -93,31 +93,30 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer, frame_info.mvp = geometry_result.transform; frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "LinearGradientFill"); - cmd.stencil_reference = 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.GetLinearGradientFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; - FS::BindTextureSampler( - cmd, std::move(gradient_texture), - renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + pass.SetCommandLabel("LinearGradientFill"); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetPipeline(renderer.GetLinearGradientFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindTextureSampler( + pass, std::move(gradient_texture), + renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); + VS::BindFrameInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + FS::BindFragInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + + if (!pass.Draw().ok()) { return false; } @@ -154,10 +153,6 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "LinearGradientSSBOFill"); - cmd.stencil_reference = entity.GetClipDepth(); - auto geometry_result = GetGeometry()->GetPositionBuffer(renderer, entity, pass); auto options = OptionsFromPassAndEntity(pass, entity); @@ -166,16 +161,18 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, options.stencil_operation = StencilOperation::kIncrementClamp; } options.primitive_type = geometry_result.type; - cmd.pipeline = renderer.GetLinearGradientSSBOFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, + pass.SetCommandLabel("LinearGradientSSBOFill"); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetPipeline(renderer.GetLinearGradientSSBOFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindFragInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, + FS::BindColorData(pass, color_buffer); + VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } diff --git a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc index 3706ca2244..ebce82dcdc 100644 --- a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.cc @@ -89,10 +89,6 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "RadialGradientSSBOFill"); - cmd.stencil_reference = entity.GetClipDepth(); - auto geometry_result = GetGeometry()->GetPositionBuffer(renderer, entity, pass); auto options = OptionsFromPassAndEntity(pass, entity); @@ -101,16 +97,18 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, options.stencil_operation = StencilOperation::kIncrementClamp; } options.primitive_type = geometry_result.type; - cmd.pipeline = renderer.GetRadialGradientSSBOFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, + pass.SetCommandLabel("RadialGradientSSBOFill"); + pass.SetPipeline(renderer.GetRadialGradientSSBOFillPipeline(options)); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindFragInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, + FS::BindColorData(pass, color_buffer); + VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } @@ -152,31 +150,30 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer, frame_info.mvp = geometry_result.transform; frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "RadialGradientFill"); - cmd.stencil_reference = 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.GetRadialGradientFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; + + pass.SetCommandLabel("RadialGradientFill"); + pass.SetPipeline(renderer.GetRadialGradientFillPipeline(options)); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindFragInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); 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; } diff --git a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h index 87bd981942..b25f3e2c85 100644 --- a/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h +++ b/engine/src/flutter/impeller/entity/contents/radial_gradient_contents.h @@ -5,16 +5,11 @@ #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_RADIAL_GRADIENT_CONTENTS_H_ #define FLUTTER_IMPELLER_ENTITY_CONTENTS_RADIAL_GRADIENT_CONTENTS_H_ -#include -#include #include -#include "flutter/fml/macros.h" #include "impeller/entity/contents/color_source_contents.h" #include "impeller/entity/entity.h" #include "impeller/geometry/color.h" -#include "impeller/geometry/gradient.h" -#include "impeller/geometry/path.h" #include "impeller/geometry/point.h" namespace impeller { diff --git a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc index 38e19c40a1..d7c3f985a8 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/solid_color_contents.cc @@ -50,13 +50,8 @@ bool SolidColorContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { auto capture = entity.GetCapture().CreateChild("SolidColorContents"); - using VS = SolidFillPipeline::VertexShader; - Command cmd; - DEBUG_COMMAND_INFO(cmd, "Solid Fill"); - cmd.stencil_reference = entity.GetClipDepth(); - auto geometry_result = GetGeometry()->GetPositionBuffer(renderer, entity, pass); @@ -67,16 +62,19 @@ bool SolidColorContents::Render(const ContentContext& renderer, } options.primitive_type = geometry_result.type; - cmd.pipeline = renderer.GetSolidFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); + + pass.SetCommandLabel("Solid Fill"); + pass.SetPipeline(renderer.GetSolidFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + pass.SetStencilReference(entity.GetClipDepth()); VS::FrameInfo frame_info; frame_info.mvp = capture.AddMatrix("Transform", geometry_result.transform); frame_info.color = capture.AddColor("Color", GetColor()).Premultiply(); - VS::BindFrameInfo(cmd, + VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } diff --git a/engine/src/flutter/impeller/entity/contents/solid_color_contents.h b/engine/src/flutter/impeller/entity/contents/solid_color_contents.h index 8fb7fc9461..6d0b54359a 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_color_contents.h +++ b/engine/src/flutter/impeller/entity/contents/solid_color_contents.h @@ -5,14 +5,10 @@ #ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_SOLID_COLOR_CONTENTS_H_ #define FLUTTER_IMPELLER_ENTITY_CONTENTS_SOLID_COLOR_CONTENTS_H_ -#include #include -#include -#include "flutter/fml/macros.h" #include "impeller/entity/contents/color_source_contents.h" #include "impeller/entity/contents/contents.h" -#include "impeller/entity/geometry/geometry.h" #include "impeller/geometry/color.h" #include "impeller/geometry/path.h" diff --git a/engine/src/flutter/impeller/entity/contents/solid_rrect_blur_contents.cc b/engine/src/flutter/impeller/entity/contents/solid_rrect_blur_contents.cc index 4aa04d0fa6..0ebd1a1049 100644 --- a/engine/src/flutter/impeller/entity/contents/solid_rrect_blur_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/solid_rrect_blur_contents.cc @@ -9,11 +9,8 @@ #include "impeller/entity/entity.h" #include "impeller/geometry/color.h" #include "impeller/geometry/constants.h" -#include "impeller/geometry/path.h" -#include "impeller/geometry/path_builder.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/vertex_buffer_builder.h" -#include "impeller/tessellator/tessellator.h" namespace impeller { @@ -94,8 +91,6 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer, }); } - Command cmd; - DEBUG_COMMAND_INFO(cmd, "RRect Shadow"); ContentContextOptions opts = OptionsFromPassAndEntity(pass, entity); opts.primitive_type = PrimitiveType::kTriangleStrip; Color color = color_; @@ -103,17 +98,10 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer, opts.is_for_rrect_blur_clear = true; color = Color::White(); } - cmd.pipeline = renderer.GetRRectBlurPipeline(opts); - cmd.stencil_reference = entity.GetClipDepth(); - - cmd.BindVertices( - vtx_builder.CreateVertexBuffer(renderer.GetTransientsBuffer())); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform() * Matrix::MakeTranslation(positive_rect.GetOrigin()); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.color = color; @@ -122,10 +110,18 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer, frag_info.corner_radius = std::min(corner_radius_, std::min(positive_rect.GetWidth() / 2.0f, positive_rect.GetHeight() / 2.0f)); - FS::BindFragInfo(cmd, + + pass.SetCommandLabel("RRect Shadow"); + pass.SetPipeline(renderer.GetRRectBlurPipeline(opts)); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetVertexBuffer( + vtx_builder.CreateVertexBuffer(renderer.GetTransientsBuffer())); + VS::BindFrameInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + FS::BindFragInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } diff --git a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc index eda8179469..a4a3bb9879 100644 --- a/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/sweep_gradient_contents.cc @@ -96,9 +96,6 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "SweepGradientSSBOFill"); - cmd.stencil_reference = entity.GetClipDepth(); auto geometry_result = GetGeometry()->GetPositionBuffer(renderer, entity, pass); @@ -108,16 +105,18 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, options.stencil_operation = StencilOperation::kIncrementClamp; } options.primitive_type = geometry_result.type; - cmd.pipeline = renderer.GetSweepGradientSSBOFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, + pass.SetCommandLabel("SweepGradientSSBOFill"); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetPipeline(renderer.GetSweepGradientSSBOFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + FS::BindFragInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, + FS::BindColorData(pass, color_buffer); + VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } @@ -160,31 +159,31 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer, frame_info.mvp = geometry_result.transform; frame_info.matrix = GetInverseEffectTransform(); - Command cmd; - DEBUG_COMMAND_INFO(cmd, "SweepGradientFill"); - cmd.stencil_reference = 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.GetSweepGradientFillPipeline(options); - cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; + + pass.SetCommandLabel("SweepGradientFill"); + pass.SetStencilReference(entity.GetClipDepth()); + pass.SetPipeline(renderer.GetSweepGradientFillPipeline(options)); + pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); + + FS::BindFragInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + VS::BindFrameInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::BindTextureSampler( - cmd, gradient_texture, + pass, gradient_texture, renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); - if (!pass.AddCommand(std::move(cmd))) { + if (!pass.Draw().ok()) { return false; } diff --git a/engine/src/flutter/impeller/renderer/render_pass.cc b/engine/src/flutter/impeller/renderer/render_pass.cc index e8dd476d45..10c5a16556 100644 --- a/engine/src/flutter/impeller/renderer/render_pass.cc +++ b/engine/src/flutter/impeller/renderer/render_pass.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "impeller/renderer/render_pass.h" +#include "fml/status.h" namespace impeller { @@ -88,4 +89,75 @@ const std::weak_ptr& RenderPass::GetContext() const { return context_; } +void RenderPass::SetPipeline( + const std::shared_ptr>& pipeline) { + pending_.pipeline = pipeline; +} + +void RenderPass::SetCommandLabel(std::string_view label) { +#ifdef IMPELLER_DEBUG + pending_.label = std::string(label); +#endif // IMPELLER_DEBUG +} + +void RenderPass::SetStencilReference(uint32_t value) { + pending_.stencil_reference = value; +} + +void RenderPass::SetBaseVertex(uint64_t value) { + pending_.base_vertex = value; +} + +void RenderPass::SetViewport(Viewport viewport) { + pending_.viewport = viewport; +} + +void RenderPass::SetScissor(IRect scissor) { + pending_.scissor = scissor; +} + +void RenderPass::SetInstanceCount(size_t count) { + pending_.instance_count = count; +} + +bool RenderPass::SetVertexBuffer(VertexBuffer buffer) { + return pending_.BindVertices(std::move(buffer)); +} + +fml::Status RenderPass::Draw() { + auto result = AddCommand(std::move(pending_)); + pending_ = Command{}; + if (result) { + return fml::Status(); + } + return fml::Status(fml::StatusCode::kInvalidArgument, + "Failed to encode command"); +} + +// |ResourceBinder| +bool RenderPass::BindResource(ShaderStage stage, + const ShaderUniformSlot& slot, + const ShaderMetadata& metadata, + BufferView view) { + return pending_.BindResource(stage, slot, metadata, view); +} + +bool RenderPass::BindResource( + ShaderStage stage, + const ShaderUniformSlot& slot, + const std::shared_ptr& metadata, + BufferView view) { + return pending_.BindResource(stage, slot, metadata, std::move(view)); +} + +// |ResourceBinder| +bool RenderPass::BindResource(ShaderStage stage, + const SampledImageSlot& slot, + const ShaderMetadata& metadata, + std::shared_ptr texture, + std::shared_ptr sampler) { + return pending_.BindResource(stage, slot, metadata, std::move(texture), + std::move(sampler)); +} + } // namespace impeller diff --git a/engine/src/flutter/impeller/renderer/render_pass.h b/engine/src/flutter/impeller/renderer/render_pass.h index 3dc4ab943f..b09503003c 100644 --- a/engine/src/flutter/impeller/renderer/render_pass.h +++ b/engine/src/flutter/impeller/renderer/render_pass.h @@ -7,7 +7,11 @@ #include +#include "fml/status.h" #include "impeller/core/formats.h" +#include "impeller/core/resource_binder.h" +#include "impeller/core/shader_types.h" +#include "impeller/core/vertex_buffer.h" #include "impeller/renderer/command.h" #include "impeller/renderer/command_buffer.h" #include "impeller/renderer/render_target.h" @@ -26,7 +30,7 @@ class Allocator; /// /// @see `CommandBuffer` /// -class RenderPass { +class RenderPass : public ResourceBinder { public: virtual ~RenderPass(); @@ -60,6 +64,81 @@ class RenderPass { /// bool AddCommand(Command&& command); + //---------------------------------------------------------------------------- + /// The pipeline to use for this command. + void SetPipeline( + const std::shared_ptr>& pipeline); + + //---------------------------------------------------------------------------- + /// The debugging label to use for the command. + void SetCommandLabel(std::string_view label); + + //---------------------------------------------------------------------------- + /// The reference value to use in stenciling operations. Stencil configuration + /// is part of pipeline setup and can be read from the pipelines descriptor. + /// + /// @see `Pipeline` + /// @see `PipelineDescriptor` + /// + void SetStencilReference(uint32_t value); + + void SetBaseVertex(uint64_t value); + + //---------------------------------------------------------------------------- + /// The viewport coordinates that the rasterizer linearly maps normalized + /// device coordinates to. + /// If unset, the viewport is the size of the render target with a zero + /// origin, znear=0, and zfar=1. + /// + void SetViewport(Viewport viewport); + + //---------------------------------------------------------------------------- + /// The scissor rect to use for clipping writes to the render target. The + /// scissor rect must lie entirely within the render target. + /// If unset, no scissor is applied. + /// + void SetScissor(IRect scissor); + + //---------------------------------------------------------------------------- + /// The number of instances of the given set of vertices to render. Not all + /// backends support rendering more than one instance at a time. + /// + /// @warning Setting this to more than one will limit the availability of + /// backends to use with this command. + /// + void SetInstanceCount(size_t count); + + //---------------------------------------------------------------------------- + /// @brief Specify the vertex and index buffer to use for this command. + /// + /// @param[in] buffer The vertex and index buffer definition. If possible, + /// this value should be moved and not copied. + /// + /// @return returns if the binding was updated. + /// + bool SetVertexBuffer(VertexBuffer buffer); + + /// Record the currently pending command. + fml::Status Draw(); + + // |ResourceBinder| + bool BindResource(ShaderStage stage, + const ShaderUniformSlot& slot, + const ShaderMetadata& metadata, + BufferView view) override; + + bool BindResource(ShaderStage stage, + const ShaderUniformSlot& slot, + const std::shared_ptr& metadata, + BufferView view); + + // |ResourceBinder| + bool BindResource(ShaderStage stage, + const SampledImageSlot& slot, + const ShaderMetadata& metadata, + std::shared_ptr texture, + std::shared_ptr sampler) override; + //---------------------------------------------------------------------------- /// @brief Encode the recorded commands to the underlying command buffer. /// @@ -112,6 +191,8 @@ class RenderPass { RenderPass(const RenderPass&) = delete; RenderPass& operator=(const RenderPass&) = delete; + + Command pending_; }; } // namespace impeller