From 65cf0afb29832daf965fe48ed9a45e5b39d6ce6d Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sat, 13 Apr 2024 16:25:32 -0700 Subject: [PATCH 01/19] [Impeller] compute UVs in vertex stage. --- impeller/entity/BUILD.gn | 2 +- impeller/entity/contents/clip_contents.h | 1 - .../entity/contents/color_source_contents.h | 10 +- impeller/entity/contents/content_context.cc | 5 - impeller/entity/contents/content_context.h | 20 ++- impeller/entity/contents/texture_contents.cc | 19 ++- .../entity/contents/tiled_texture_contents.cc | 10 +- impeller/entity/contents/vertices_contents.cc | 3 +- impeller/entity/entity_unittests.cc | 5 - impeller/entity/geometry/circle_geometry.cc | 25 ---- impeller/entity/geometry/circle_geometry.h | 7 -- impeller/entity/geometry/cover_geometry.cc | 12 -- impeller/entity/geometry/cover_geometry.h | 7 -- impeller/entity/geometry/ellipse_geometry.cc | 14 --- impeller/entity/geometry/ellipse_geometry.h | 7 -- .../entity/geometry/fill_path_geometry.cc | 47 ------- impeller/entity/geometry/fill_path_geometry.h | 7 -- impeller/entity/geometry/geometry.cc | 94 -------------- impeller/entity/geometry/geometry.h | 41 ------- .../entity/geometry/geometry_unittests.cc | 104 ---------------- impeller/entity/geometry/line_geometry.cc | 52 -------- impeller/entity/geometry/line_geometry.h | 7 -- .../entity/geometry/point_field_geometry.cc | 58 +-------- .../entity/geometry/point_field_geometry.h | 16 +-- impeller/entity/geometry/rect_geometry.cc | 10 -- impeller/entity/geometry/rect_geometry.h | 7 -- .../entity/geometry/round_rect_geometry.cc | 15 --- .../entity/geometry/round_rect_geometry.h | 7 -- .../entity/geometry/stroke_path_geometry.cc | 67 ---------- .../entity/geometry/stroke_path_geometry.h | 18 --- impeller/entity/geometry/vertices_geometry.cc | 115 +++++++++--------- impeller/entity/geometry/vertices_geometry.h | 10 +- impeller/entity/shaders/geometry/uv.comp | 60 --------- impeller/entity/shaders/texture_uv_fill.vert | 30 +++++ impeller/geometry/geometry_benchmarks.cc | 49 +------- 35 files changed, 128 insertions(+), 833 deletions(-) delete mode 100644 impeller/entity/shaders/geometry/uv.comp create mode 100644 impeller/entity/shaders/texture_uv_fill.vert diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 82b208479f146..5e2cd8698171e 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -51,6 +51,7 @@ impeller_shaders("entity_shaders") { "shaders/texture_fill.vert", "shaders/texture_fill_external.frag", "shaders/texture_fill_strict_src.frag", + "shaders/texture_uv_fill.vert", "shaders/tiled_texture_fill.frag", "shaders/tiled_texture_fill_external.frag", "shaders/vertices.frag", @@ -85,7 +86,6 @@ impeller_shaders("modern_entity_shaders") { "shaders/radial_gradient_ssbo_fill.frag", "shaders/sweep_gradient_ssbo_fill.frag", "shaders/geometry/points.comp", - "shaders/geometry/uv.comp", ] } diff --git a/impeller/entity/contents/clip_contents.h b/impeller/entity/contents/clip_contents.h index 6044692c6962a..5481298a2a8b2 100644 --- a/impeller/entity/contents/clip_contents.h +++ b/impeller/entity/contents/clip_contents.h @@ -9,7 +9,6 @@ #include #include -#include "flutter/fml/macros.h" #include "impeller/entity/contents/contents.h" #include "impeller/entity/entity.h" #include "impeller/entity/geometry/geometry.h" diff --git a/impeller/entity/contents/color_source_contents.h b/impeller/entity/contents/color_source_contents.h index 3c5b932100444..84a7e9a65a437 100644 --- a/impeller/entity/contents/color_source_contents.h +++ b/impeller/entity/contents/color_source_contents.h @@ -118,10 +118,7 @@ class ColorSourceContents : public Contents { RenderPass& pass, const PipelineBuilderCallback& pipeline_callback, typename VertexShaderT::FrameInfo frame_info, - const BindFragmentCallback& bind_fragment_callback, - bool enable_uvs = false, - Rect texture_coverage = {}, - const Matrix& effect_transform = {}) const { + const BindFragmentCallback& bind_fragment_callback) const { auto options = OptionsFromPassAndEntity(pass, entity); GeometryResult::Mode geometry_mode = GetGeometry()->GetResultMode(); @@ -181,10 +178,7 @@ class ColorSourceContents : public Contents { } GeometryResult geometry_result = - enable_uvs - ? geometry.GetPositionUVBuffer(texture_coverage, effect_transform, - renderer, entity, pass) - : geometry.GetPositionBuffer(renderer, entity, pass); + geometry.GetPositionBuffer(renderer, entity, pass); if (geometry_result.vertex_buffer.vertex_count == 0u) { return true; } diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 947777105a445..8e86649020c34 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -440,11 +440,6 @@ ContentContext::ContentContext( PointsComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_); point_field_compute_pipelines_ = context_->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get(); - - auto uv_pipeline_desc = - UvComputeShaderPipeline::MakeDefaultPipelineDescriptor(*context_); - uv_compute_pipelines_ = - context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get(); } /// Setup default clip pipeline. diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 3378c30472b60..045888574c49b 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -61,6 +61,7 @@ #include "impeller/entity/texture_fill.frag.h" #include "impeller/entity/texture_fill.vert.h" #include "impeller/entity/texture_fill_strict_src.frag.h" +#include "impeller/entity/texture_uv_fill.vert.h" #include "impeller/entity/tiled_texture_fill.frag.h" #include "impeller/entity/uv.comp.h" #include "impeller/entity/vertices.frag.h" @@ -129,14 +130,14 @@ using RRectBlurPipeline = RenderPipelineT; using BlendPipeline = RenderPipelineT; using TexturePipeline = - RenderPipelineT; + RenderPipelineT; using TextureStrictSrcPipeline = - RenderPipelineT; using PositionUVPipeline = RenderPipelineT; using TiledTexturePipeline = - RenderPipelineT; + RenderPipelineT; using KernelDecalPipeline = RenderPipelineT; using KernelPipeline = @@ -259,10 +260,11 @@ using UvComputeShaderPipeline = ComputePipelineBuilder; #ifdef IMPELLER_ENABLE_OPENGLES using TextureExternalPipeline = - RenderPipelineT; + RenderPipelineT; using TiledTextureExternalPipeline = - RenderPipelineT; #endif // IMPELLER_ENABLE_OPENGLES @@ -755,12 +757,6 @@ class ContentContext { return point_field_compute_pipelines_; } - std::shared_ptr> GetUvComputePipeline() - const { - FML_DCHECK(GetDeviceCapabilities().SupportsCompute()); - return uv_compute_pipelines_; - } - std::shared_ptr GetContext() const; const Capabilities& GetDeviceCapabilities() const; @@ -1017,8 +1013,6 @@ class ContentContext { framebuffer_blend_softlight_pipelines_; mutable std::shared_ptr> point_field_compute_pipelines_; - mutable std::shared_ptr> - uv_compute_pipelines_; template std::shared_ptr> GetPipeline( diff --git a/impeller/entity/contents/texture_contents.cc b/impeller/entity/contents/texture_contents.cc index f2f10207bf4be..db74cfe2baa94 100644 --- a/impeller/entity/contents/texture_contents.cc +++ b/impeller/entity/contents/texture_contents.cc @@ -111,7 +111,7 @@ bool TextureContents::Render(const ContentContext& renderer, RenderPass& pass) const { auto capture = entity.GetCapture().CreateChild("TextureContents"); - using VS = TextureFillVertexShader; + using VS = TextureUvFillVertexShader; using FS = TextureFillFragmentShader; using FSStrictSrc = TextureFillStrictSrcFragmentShader; using FSExternal = TextureFillExternalFragmentShader; @@ -125,18 +125,15 @@ bool TextureContents::Render(const ContentContext& renderer, texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES; auto source_rect = capture.AddRect("Source rect", source_rect_); - auto texture_coords = - Rect::MakeSize(texture_->GetSize()).Project(source_rect); - - VertexBufferBuilder vertex_builder; - auto destination_rect = capture.AddRect("Destination rect", destination_rect_); + + VertexBufferBuilder vertex_builder; vertex_builder.AddVertices({ - {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()}, - {destination_rect.GetRightTop(), texture_coords.GetRightTop()}, - {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()}, - {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()}, + {destination_rect.GetLeftTop()}, + {destination_rect.GetRightTop()}, + {destination_rect.GetLeftBottom()}, + {destination_rect.GetRightBottom()}, }); auto& host_buffer = renderer.GetTransientsBuffer(); @@ -145,6 +142,8 @@ bool TextureContents::Render(const ContentContext& renderer, frame_info.mvp = entity.GetShaderTransform(pass); frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale(); frame_info.alpha = capture.AddScalar("Alpha", GetOpacity()); + // TODO: src/dst rect. + frame_info.uv_transform = destination_rect_.GetNormalizingTransform(); #ifdef IMPELLER_DEBUG if (label_.empty()) { diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index b8baa2fef8f92..c83bcc9f0f890 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -115,7 +115,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer, return true; } - using VS = TextureFillVertexShader; + using VS = TextureUvFillVertexShader; using FS = TiledTextureFillFragmentShader; using FSExternal = TiledTextureFillExternalFragmentShader; @@ -133,6 +133,9 @@ bool TiledTextureContents::Render(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale(); frame_info.alpha = GetOpacityFactor(); + frame_info.uv_transform = + Rect::MakeSize(texture_size).GetNormalizingTransform() * + GetInverseEffectTransform(); PipelineBuilderMethod pipeline_method; @@ -214,10 +217,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer, } return true; - }, - /*enable_uvs=*/true, - /*texture_coverage=*/Rect::MakeSize(texture_size), - /*effect_transform=*/GetInverseEffectTransform()); + }); } std::optional TiledTextureContents::RenderToSnapshot( diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 2db730e4e815a..93946ee561278 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -158,8 +158,7 @@ bool VerticesUVContents::Render(const ContentContext& renderer, if (!coverage.has_value()) { return false; } - auto geometry_result = geometry->GetPositionUVBuffer( - coverage.value(), Matrix(), renderer, entity, pass); + auto geometry_result = geometry->GetPositionBuffer(renderer, entity, pass); auto opts = OptionsFromPassAndEntity(pass, entity); opts.primitive_type = geometry_result.type; pass.SetPipeline(renderer.GetTexturePipeline(opts)); diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 61594bd4d2e64..2df4baaad979a 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2830,12 +2830,7 @@ TEST_P(EntityTest, CanComputeGeometryForEmptyPathsWithoutCrashing) { auto position_result = geom->GetPositionBuffer(*GetContentContext(), entity, render_pass); - auto uv_result = - geom->GetPositionUVBuffer(Rect::MakeLTRB(0, 0, 100, 100), Matrix(), - *GetContentContext(), entity, render_pass); - EXPECT_EQ(position_result.vertex_buffer.vertex_count, 0u); - EXPECT_EQ(uv_result.vertex_buffer.vertex_count, 0u); EXPECT_EQ(geom->GetResultMode(), GeometryResult::Mode::kNormal); } diff --git a/impeller/entity/geometry/circle_geometry.cc b/impeller/entity/geometry/circle_geometry.cc index bd9aa8c796378..4f782feeb1441 100644 --- a/impeller/entity/geometry/circle_geometry.cc +++ b/impeller/entity/geometry/circle_geometry.cc @@ -44,31 +44,6 @@ GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer, return ComputePositionGeometry(renderer, generator, entity, pass); } -// |Geometry| -GeometryResult CircleGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - auto& transform = entity.GetTransform(); - auto uv_transform = - texture_coverage.GetNormalizingTransform() * effect_transform; - - Scalar half_width = stroke_width_ < 0 ? 0.0 - : LineGeometry::ComputePixelHalfWidth( - transform, stroke_width_); - std::shared_ptr tessellator = renderer.GetTessellator(); - - // We call the StrokedCircle method which will simplify to a - // FilledCircleGenerator if the inner_radius is <= 0. - auto generator = - tessellator->StrokedCircle(transform, center_, radius_, half_width); - - return ComputePositionUVGeometry(renderer, generator, uv_transform, entity, - pass); -} - GeometryVertexType CircleGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/circle_geometry.h b/impeller/entity/geometry/circle_geometry.h index be75f891317d1..d715a2fc02e2e 100644 --- a/impeller/entity/geometry/circle_geometry.h +++ b/impeller/entity/geometry/circle_geometry.h @@ -39,13 +39,6 @@ class CircleGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - Point center_; Scalar radius_; Scalar stroke_width_; diff --git a/impeller/entity/geometry/cover_geometry.cc b/impeller/entity/geometry/cover_geometry.cc index 1f80687d14752..cdf64d70c7fb4 100644 --- a/impeller/entity/geometry/cover_geometry.cc +++ b/impeller/entity/geometry/cover_geometry.cc @@ -33,18 +33,6 @@ GeometryResult CoverGeometry::GetPositionBuffer(const ContentContext& renderer, }; } -// |Geometry| -GeometryResult CoverGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - auto rect = Rect::MakeSize(pass.GetRenderTargetSize()); - return ComputeUVGeometryForRect(rect, texture_coverage, effect_transform, - renderer, entity, pass); -} - GeometryVertexType CoverGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/cover_geometry.h b/impeller/entity/geometry/cover_geometry.h index e9f56530cded2..5dfe6a76e8a3b 100644 --- a/impeller/entity/geometry/cover_geometry.h +++ b/impeller/entity/geometry/cover_geometry.h @@ -34,13 +34,6 @@ class CoverGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - CoverGeometry(const CoverGeometry&) = delete; CoverGeometry& operator=(const CoverGeometry&) = delete; diff --git a/impeller/entity/geometry/ellipse_geometry.cc b/impeller/entity/geometry/ellipse_geometry.cc index b0d21324b437e..623c9a8abf8a9 100644 --- a/impeller/entity/geometry/ellipse_geometry.cc +++ b/impeller/entity/geometry/ellipse_geometry.cc @@ -22,20 +22,6 @@ GeometryResult EllipseGeometry::GetPositionBuffer( entity, pass); } -// |Geometry| -GeometryResult EllipseGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - return ComputePositionUVGeometry( - renderer, - renderer.GetTessellator()->FilledEllipse(entity.GetTransform(), bounds_), - texture_coverage.GetNormalizingTransform() * effect_transform, entity, - pass); -} - GeometryVertexType EllipseGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/ellipse_geometry.h b/impeller/entity/geometry/ellipse_geometry.h index 892d03568e6de..734899bb28619 100644 --- a/impeller/entity/geometry/ellipse_geometry.h +++ b/impeller/entity/geometry/ellipse_geometry.h @@ -37,13 +37,6 @@ class EllipseGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - Rect bounds_; EllipseGeometry(const EllipseGeometry&) = delete; diff --git a/impeller/entity/geometry/fill_path_geometry.cc b/impeller/entity/geometry/fill_path_geometry.cc index 1b3dc51813266..de2ad2c2f5f57 100644 --- a/impeller/entity/geometry/fill_path_geometry.cc +++ b/impeller/entity/geometry/fill_path_geometry.cc @@ -54,53 +54,6 @@ GeometryResult FillPathGeometry::GetPositionBuffer( }; } -// |Geometry| -GeometryResult FillPathGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - using VS = TextureFillVertexShader; - - const auto& bounding_box = path_.GetBoundingBox(); - if (bounding_box.has_value() && bounding_box->IsEmpty()) { - return GeometryResult{ - .type = PrimitiveType::kTriangle, - .vertex_buffer = - VertexBuffer{ - .vertex_buffer = {}, - .vertex_count = 0, - .index_type = IndexType::k16bit, - }, - .transform = pass.GetOrthographicTransform() * entity.GetTransform(), - }; - } - - auto uv_transform = - texture_coverage.GetNormalizingTransform() * effect_transform; - - auto points = renderer.GetTessellator()->TessellateConvex( - path_, entity.GetTransform().GetMaxBasisLength()); - - VertexBufferBuilder vertex_builder; - vertex_builder.Reserve(points.size()); - for (auto i = 0u; i < points.size(); i++) { - VS::PerVertexData data; - data.position = points[i]; - data.texture_coords = uv_transform * points[i]; - vertex_builder.AppendVertex(data); - } - - return GeometryResult{ - .type = PrimitiveType::kTriangleStrip, - .vertex_buffer = - vertex_builder.CreateVertexBuffer(renderer.GetTransientsBuffer()), - .transform = entity.GetShaderTransform(pass), - .mode = GetResultMode(), - }; -} - GeometryResult::Mode FillPathGeometry::GetResultMode() const { const auto& bounding_box = path_.GetBoundingBox(); if (path_.IsConvex() || diff --git a/impeller/entity/geometry/fill_path_geometry.h b/impeller/entity/geometry/fill_path_geometry.h index 722f7cc661c40..9127084a3384f 100644 --- a/impeller/entity/geometry/fill_path_geometry.h +++ b/impeller/entity/geometry/fill_path_geometry.h @@ -35,13 +35,6 @@ class FillPathGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - // |Geometry| GeometryResult::Mode GetResultMode() const override; diff --git a/impeller/entity/geometry/geometry.cc b/impeller/entity/geometry/geometry.cc index bc774a2a80e70..97daf73962400 100644 --- a/impeller/entity/geometry/geometry.cc +++ b/impeller/entity/geometry/geometry.cc @@ -7,7 +7,6 @@ #include #include -#include "fml/status.h" #include "impeller/entity/contents/content_context.h" #include "impeller/entity/geometry/circle_geometry.h" #include "impeller/entity/geometry/cover_geometry.h" @@ -54,41 +53,6 @@ GeometryResult Geometry::ComputePositionGeometry( }; } -GeometryResult Geometry::ComputePositionUVGeometry( - const ContentContext& renderer, - const Tessellator::VertexGenerator& generator, - const Matrix& uv_transform, - const Entity& entity, - RenderPass& pass) { - using VT = TextureFillVertexShader::PerVertexData; - - size_t count = generator.GetVertexCount(); - - return GeometryResult{ - .type = generator.GetTriangleType(), - .vertex_buffer = - { - .vertex_buffer = renderer.GetTransientsBuffer().Emplace( - count * sizeof(VT), alignof(VT), - [&generator, &uv_transform](uint8_t* buffer) { - auto vertices = reinterpret_cast(buffer); - generator.GenerateVertices( - [&vertices, &uv_transform](const Point& p) { // - *vertices++ = { - .position = p, - .texture_coords = uv_transform * p, - }; - }); - FML_DCHECK(vertices == reinterpret_cast(buffer) + - generator.GetVertexCount()); - }), - .vertex_count = count, - .index_type = IndexType::kNone, - }, - .transform = entity.GetShaderTransform(pass), - }; -} - VertexBufferBuilder ComputeUVGeometryCPU( VertexBufferBuilder& input, @@ -110,64 +74,6 @@ ComputeUVGeometryCPU( return vertex_builder; } -GeometryResult ComputeUVGeometryForRect(Rect source_rect, - Rect texture_bounds, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); - - // Calculate UV-specific transform based on texture coverage and effect. - // For example, if the texture is 100x100 and the effect transform is - // scaling by 2.0, texture_bounds.GetNormalizingTransform() will result in a - // Matrix that scales by 0.01, and then if the effect_transform is - // Matrix::MakeScale(Vector2{2, 2}), the resulting uv_transform will have x - // and y basis vectors with scale 0.02. - auto uv_transform = texture_bounds.GetNormalizingTransform() * // - effect_transform; - - // Allocate space for vertex and UV data (4 vertices) - // 0: position - // 1: UV - // 2: position - // 3: UV - // etc. - Point data[8]; - - // Get the raw points from the rect and transform them into UV space. - auto points = source_rect.GetPoints(); - for (auto i = 0u, j = 0u; i < 8; i += 2, j++) { - // Store original coordinates. - data[i] = points[j]; - - // Store transformed UV coordinates. - data[i + 1] = uv_transform * points[j]; - } - - return GeometryResult{ - .type = PrimitiveType::kTriangleStrip, - .vertex_buffer = - { - .vertex_buffer = host_buffer.Emplace( - /*buffer=*/data, - /*length=*/16 * sizeof(float), - /*align=*/alignof(float)), - .vertex_count = 4, - .index_type = IndexType::kNone, - }, - .transform = entity.GetShaderTransform(pass), - }; -} - -GeometryResult Geometry::GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - return {}; -} - GeometryResult::Mode Geometry::GetResultMode() const { return GeometryResult::Mode::kNormal; } diff --git a/impeller/entity/geometry/geometry.h b/impeller/entity/geometry/geometry.h index 5144ead7c433d..bddd43255222e 100644 --- a/impeller/entity/geometry/geometry.h +++ b/impeller/entity/geometry/geometry.h @@ -52,34 +52,6 @@ enum GeometryVertexType { kUV, }; -/// @brief Compute UV geometry for a VBB that contains only position geometry. -/// -/// texture_origin should be set to 0, 0 for stroke and stroke based geometry, -/// like the point field. -VertexBufferBuilder -ComputeUVGeometryCPU( - VertexBufferBuilder& input, - Point texture_origin, - Size texture_coverage, - Matrix effect_transform); - -/// @brief Computes geometry and UV coordinates for a rectangle to be rendered. -/// -/// UV is the horizontal and vertical coordinates within the texture. -/// -/// @param source_rect The rectangle to be rendered. -/// @param texture_bounds The local space bounding box of the geometry. -/// @param effect_transform The transform to apply to the UV coordinates. -/// @param renderer The content context to use for allocating buffers. -/// @param entity The entity to use for the transform. -/// @param pass The render pass to use for the transform. -GeometryResult ComputeUVGeometryForRect(Rect source_rect, - Rect texture_bounds, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass); - class Geometry { public: static std::shared_ptr MakeFillPath( @@ -122,12 +94,6 @@ class Geometry { const Entity& entity, RenderPass& pass) const = 0; - virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const = 0; - virtual GeometryResult::Mode GetResultMode() const; virtual GeometryVertexType GetVertexType() const = 0; @@ -156,13 +122,6 @@ class Geometry { const Tessellator::VertexGenerator& generator, const Entity& entity, RenderPass& pass); - - static GeometryResult ComputePositionUVGeometry( - const ContentContext& renderer, - const Tessellator::VertexGenerator& generator, - const Matrix& uv_transform, - const Entity& entity, - RenderPass& pass); }; } // namespace impeller diff --git a/impeller/entity/geometry/geometry_unittests.cc b/impeller/entity/geometry/geometry_unittests.cc index 990b1419659ed..09061eb2628ae 100644 --- a/impeller/entity/geometry/geometry_unittests.cc +++ b/impeller/entity/geometry/geometry_unittests.cc @@ -61,21 +61,6 @@ class ImpellerEntityUnitTestAccessor { return StrokePathGeometry::GenerateSolidStrokeVertices( polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale); } - - static std::vector - GenerateSolidStrokeVerticesUV(const Path::Polyline& polyline, - Scalar stroke_width, - Scalar miter_limit, - Join stroke_join, - Cap stroke_cap, - Scalar scale, - Point texture_origin, - Size texture_size, - const Matrix& effect_transform) { - return StrokePathGeometry::GenerateSolidStrokeVerticesUV( - polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale, - texture_origin, texture_size, effect_transform); - } }; namespace testing { @@ -142,95 +127,6 @@ TEST(EntityGeometryTest, RoundRectGeometryCoversArea) { EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 30, 99, 70))); } -TEST(EntityGeometryTest, StrokePathGeometryTransformOfLine) { - auto path = - PathBuilder().AddLine(Point(100, 100), Point(200, 100)).TakePath(); - auto points = std::make_unique>(); - auto polyline = - path.CreatePolyline(1.0f, std::move(points), - [&points](Path::Polyline::PointBufferPtr reclaimed) { - points = std::move(reclaimed); - }); - - auto vertices = ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVertices( - polyline, 10.0f, 10.0f, Join::kBevel, Cap::kButt, 1.0); - - std::vector expected = { - {.position = Point(100.0f, 105.0f)}, // - {.position = Point(100.0f, 95.0f)}, // - {.position = Point(100.0f, 105.0f)}, // - {.position = Point(100.0f, 95.0f)}, // - {.position = Point(200.0f, 105.0f)}, // - {.position = Point(200.0f, 95.0f)}, // - {.position = Point(200.0f, 105.0f)}, // - {.position = Point(200.0f, 95.0f)}, // - }; - - EXPECT_SOLID_VERTICES_NEAR(vertices, expected); - - { - auto uv_vertices = - ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVerticesUV( - polyline, 10.0f, 10.0f, Join::kBevel, Cap::kButt, 1.0, // - Point(50.0f, 40.0f), Size(20.0f, 40.0f), Matrix()); - // uvx = (x - 50) / 20 - // uvy = (y - 40) / 40 - auto uv = [](const Point& p) { - return Point((p.x - 50.0f) / 20.0f, // - (p.y - 40.0f) / 40.0f); - }; - std::vector uv_expected; - for (size_t i = 0; i < expected.size(); i++) { - auto p = expected[i].position; - uv_expected.push_back({.position = p, .texture_coords = uv(p)}); - } - - EXPECT_TEXTURE_VERTICES_NEAR(uv_vertices, uv_expected); - } - - { - auto uv_vertices = - ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVerticesUV( - polyline, 10.0f, 10.0f, Join::kBevel, Cap::kButt, 1.0, // - Point(50.0f, 40.0f), Size(20.0f, 40.0f), - Matrix::MakeScale({8.0f, 4.0f, 1.0f})); - // uvx = ((x * 8) - 50) / 20 - // uvy = ((y * 4) - 40) / 40 - auto uv = [](const Point& p) { - return Point(((p.x * 8.0f) - 50.0f) / 20.0f, - ((p.y * 4.0f) - 40.0f) / 40.0f); - }; - std::vector uv_expected; - for (size_t i = 0; i < expected.size(); i++) { - auto p = expected[i].position; - uv_expected.push_back({.position = p, .texture_coords = uv(p)}); - } - - EXPECT_TEXTURE_VERTICES_NEAR(uv_vertices, uv_expected); - } - - { - auto uv_vertices = - ImpellerEntityUnitTestAccessor::GenerateSolidStrokeVerticesUV( - polyline, 10.0f, 10.0f, Join::kBevel, Cap::kButt, 1.0, // - Point(50.0f, 40.0f), Size(20.0f, 40.0f), - Matrix::MakeTranslation({8.0f, 4.0f})); - // uvx = ((x + 8) - 50) / 20 - // uvy = ((y + 4) - 40) / 40 - auto uv = [](const Point& p) { - return Point(((p.x + 8.0f) - 50.0f) / 20.0f, - ((p.y + 4.0f) - 40.0f) / 40.0f); - }; - std::vector uv_expected; - for (size_t i = 0; i < expected.size(); i++) { - auto p = expected[i].position; - uv_expected.push_back({.position = p, .texture_coords = uv(p)}); - } - - EXPECT_TEXTURE_VERTICES_NEAR(uv_vertices, uv_expected); - } -} - TEST(EntityGeometryTest, GeometryResultHasReasonableDefaults) { GeometryResult result; EXPECT_EQ(result.type, PrimitiveType::kTriangleStrip); diff --git a/impeller/entity/geometry/line_geometry.cc b/impeller/entity/geometry/line_geometry.cc index ea5f087fb5ad7..cb4c658fca7a2 100644 --- a/impeller/entity/geometry/line_geometry.cc +++ b/impeller/entity/geometry/line_geometry.cc @@ -108,58 +108,6 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer, }; } -// |Geometry| -GeometryResult LineGeometry::GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - auto& host_buffer = renderer.GetTransientsBuffer(); - using VT = TextureFillVertexShader::PerVertexData; - - auto& transform = entity.GetTransform(); - auto radius = ComputePixelHalfWidth(transform, width_); - - auto uv_transform = - texture_coverage.GetNormalizingTransform() * effect_transform; - - if (cap_ == Cap::kRound) { - std::shared_ptr tessellator = renderer.GetTessellator(); - auto generator = tessellator->RoundCapLine(transform, p0_, p1_, radius); - return ComputePositionUVGeometry(renderer, generator, uv_transform, entity, - pass); - } - - Point corners[4]; - if (!ComputeCorners(corners, transform, cap_ == Cap::kSquare)) { - return kEmptyResult; - } - - size_t count = 4; - BufferView vertex_buffer = - host_buffer.Emplace(count * sizeof(VT), alignof(VT), - [&uv_transform, &corners](uint8_t* buffer) { - auto vertices = reinterpret_cast(buffer); - for (auto& corner : corners) { - *vertices++ = { - .position = corner, - .texture_coords = uv_transform * corner, - }; - } - }); - - return GeometryResult{ - .type = PrimitiveType::kTriangleStrip, - .vertex_buffer = - { - .vertex_buffer = vertex_buffer, - .vertex_count = count, - .index_type = IndexType::kNone, - }, - .transform = entity.GetShaderTransform(pass), - }; -} - GeometryVertexType LineGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/line_geometry.h b/impeller/entity/geometry/line_geometry.h index 58032074ed5d9..072dc7056b70b 100644 --- a/impeller/entity/geometry/line_geometry.h +++ b/impeller/entity/geometry/line_geometry.h @@ -57,13 +57,6 @@ class LineGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - Point p0_; Point p1_; Scalar width_; diff --git a/impeller/entity/geometry/point_field_geometry.cc b/impeller/entity/geometry/point_field_geometry.cc index 3aabb90176569..dd169b1823fd6 100644 --- a/impeller/entity/geometry/point_field_geometry.cc +++ b/impeller/entity/geometry/point_field_geometry.cc @@ -34,33 +34,6 @@ GeometryResult PointFieldGeometry::GetPositionBuffer( }; } -GeometryResult PointFieldGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - if (renderer.GetDeviceCapabilities().SupportsCompute()) { - return GetPositionBufferGPU(renderer, entity, pass, texture_coverage, - effect_transform); - } - - auto vtx_builder = GetPositionBufferCPU(renderer, entity, pass); - if (!vtx_builder.has_value()) { - return {}; - } - auto uv_vtx_builder = - ComputeUVGeometryCPU(vtx_builder.value(), {0, 0}, - texture_coverage.GetSize(), effect_transform); - - auto& host_buffer = renderer.GetTransientsBuffer(); - return { - .type = PrimitiveType::kTriangleStrip, - .vertex_buffer = uv_vtx_builder.CreateVertexBuffer(host_buffer), - .transform = entity.GetShaderTransform(pass), - }; -} - std::optional> PointFieldGeometry::GetPositionBufferCPU(const ContentContext& renderer, const Entity& entity, @@ -127,9 +100,7 @@ PointFieldGeometry::GetPositionBufferCPU(const ContentContext& renderer, GeometryResult PointFieldGeometry::GetPositionBufferGPU( const ContentContext& renderer, const Entity& entity, - RenderPass& pass, - std::optional texture_coverage, - std::optional effect_transform) const { + RenderPass& pass) const { FML_DCHECK(renderer.GetDeviceCapabilities().SupportsCompute()); if (radius_ < 0.0) { return {}; @@ -186,33 +157,6 @@ GeometryResult PointFieldGeometry::GetPositionBufferGPU( output = geometry_buffer; } - if (texture_coverage.has_value() && effect_transform.has_value()) { - BufferView geometry_uv_buffer = host_buffer.Emplace( - nullptr, total * sizeof(Vector4), - std::max(DefaultUniformAlignment(), alignof(Vector4))); - - using UV = UvComputeShader; - - compute_pass->AddBufferMemoryBarrier(); - compute_pass->SetCommandLabel("UV Geometry"); - compute_pass->SetPipeline(renderer.GetUvComputePipeline()); - - UV::FrameInfo frame_info; - frame_info.count = total; - frame_info.effect_transform = effect_transform.value(); - frame_info.texture_origin = {0, 0}; - frame_info.texture_size = Vector2(texture_coverage.value().GetSize()); - - UV::BindFrameInfo(*compute_pass, host_buffer.EmplaceUniform(frame_info)); - UV::BindGeometryData(*compute_pass, geometry_buffer); - UV::BindGeometryUVData(*compute_pass, geometry_uv_buffer); - - if (!compute_pass->Compute(ISize(total, 1)).ok()) { - return {}; - } - output = geometry_uv_buffer; - } - if (!compute_pass->EncodeCommands()) { return {}; } diff --git a/impeller/entity/geometry/point_field_geometry.h b/impeller/entity/geometry/point_field_geometry.h index 9d43f07cb9fbe..1c5fa1fc0212c 100644 --- a/impeller/entity/geometry/point_field_geometry.h +++ b/impeller/entity/geometry/point_field_geometry.h @@ -23,25 +23,15 @@ class PointFieldGeometry final : public Geometry { const Entity& entity, RenderPass& pass) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - // |Geometry| GeometryVertexType GetVertexType() const override; // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - GeometryResult GetPositionBufferGPU( - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass, - std::optional texture_coverage = std::nullopt, - std::optional effect_transform = std::nullopt) const; + GeometryResult GetPositionBufferGPU(const ContentContext& renderer, + const Entity& entity, + RenderPass& pass) const; std::optional> GetPositionBufferCPU(const ContentContext& renderer, diff --git a/impeller/entity/geometry/rect_geometry.cc b/impeller/entity/geometry/rect_geometry.cc index 6d72efb2f235a..f4b1dff2fde04 100644 --- a/impeller/entity/geometry/rect_geometry.cc +++ b/impeller/entity/geometry/rect_geometry.cc @@ -25,16 +25,6 @@ GeometryResult RectGeometry::GetPositionBuffer(const ContentContext& renderer, }; } -// |Geometry| -GeometryResult RectGeometry::GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - return ComputeUVGeometryForRect(rect_, texture_coverage, effect_transform, - renderer, entity, pass); -} - GeometryVertexType RectGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/rect_geometry.h b/impeller/entity/geometry/rect_geometry.h index bed8c23d6c419..57ff2fd0152a6 100644 --- a/impeller/entity/geometry/rect_geometry.h +++ b/impeller/entity/geometry/rect_geometry.h @@ -32,13 +32,6 @@ class RectGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - private: Rect rect_; diff --git a/impeller/entity/geometry/round_rect_geometry.cc b/impeller/entity/geometry/round_rect_geometry.cc index edcf12074afe6..ae95d728d8b90 100644 --- a/impeller/entity/geometry/round_rect_geometry.cc +++ b/impeller/entity/geometry/round_rect_geometry.cc @@ -19,21 +19,6 @@ GeometryResult RoundRectGeometry::GetPositionBuffer( entity, pass); } -// |Geometry| -GeometryResult RoundRectGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - return ComputePositionUVGeometry( - renderer, - renderer.GetTessellator()->FilledRoundRect(entity.GetTransform(), bounds_, - radii_), - texture_coverage.GetNormalizingTransform() * effect_transform, entity, - pass); -} - GeometryVertexType RoundRectGeometry::GetVertexType() const { return GeometryVertexType::kPosition; } diff --git a/impeller/entity/geometry/round_rect_geometry.h b/impeller/entity/geometry/round_rect_geometry.h index 78f0523a20f1f..ee55bdc258ea0 100644 --- a/impeller/entity/geometry/round_rect_geometry.h +++ b/impeller/entity/geometry/round_rect_geometry.h @@ -37,13 +37,6 @@ class RoundRectGeometry final : public Geometry { // |Geometry| std::optional GetCoverage(const Matrix& transform) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - const Rect bounds_; const Size radii_; diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 49f8ee92d0a07..0e4f8a178c80e 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -525,27 +525,6 @@ StrokePathGeometry::GenerateSolidStrokeVertices(const Path::Polyline& polyline, return vtx_builder.GetData(); } -std::vector -StrokePathGeometry::GenerateSolidStrokeVerticesUV( - const Path::Polyline& polyline, - Scalar stroke_width, - Scalar miter_limit, - Join stroke_join, - Cap stroke_cap, - Scalar scale, - Point texture_origin, - Size texture_size, - const Matrix& effect_transform) { - auto scaled_miter_limit = stroke_width * miter_limit * 0.5f; - auto join_proc = GetJoinProc(stroke_join); - auto cap_proc = GetCapProc(stroke_cap); - StrokeGenerator stroke_generator(polyline, stroke_width, scaled_miter_limit, - join_proc, cap_proc, scale); - PositionUVWriter vtx_builder(texture_origin, texture_size, effect_transform); - stroke_generator.Generate(vtx_builder); - return vtx_builder.GetData(); -} - StrokePathGeometry::StrokePathGeometry(const Path& path, Scalar stroke_width, Scalar miter_limit, @@ -619,52 +598,6 @@ GeometryResult StrokePathGeometry::GetPositionBuffer( }; } -GeometryResult StrokePathGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - if (stroke_width_ < 0.0) { - return {}; - } - auto determinant = entity.GetTransform().GetDeterminant(); - if (determinant == 0) { - return {}; - } - - Scalar min_size = 1.0f / sqrt(std::abs(determinant)); - Scalar stroke_width = std::max(stroke_width_, min_size); - - auto& host_buffer = renderer.GetTransientsBuffer(); - auto scale = entity.GetTransform().GetMaxBasisLength(); - auto polyline = renderer.GetTessellator()->CreateTempPolyline(path_, scale); - - PositionUVWriter writer(Point{0, 0}, texture_coverage.GetSize(), - effect_transform); - CreateSolidStrokeVertices(writer, polyline, stroke_width, - miter_limit_ * stroke_width_ * 0.5f, - GetJoinProc(stroke_join_), - GetCapProc(stroke_cap_), scale); - - BufferView buffer_view = host_buffer.Emplace( - writer.GetData().data(), - writer.GetData().size() * sizeof(TextureFillVertexShader::PerVertexData), - alignof(TextureFillVertexShader::PerVertexData)); - - return GeometryResult{ - .type = PrimitiveType::kTriangleStrip, - .vertex_buffer = - { - .vertex_buffer = buffer_view, - .vertex_count = writer.GetData().size(), - .index_type = IndexType::kNone, - }, - .transform = entity.GetShaderTransform(pass), - .mode = GeometryResult::Mode::kPreventOverdraw, - }; -} - GeometryResult::Mode StrokePathGeometry::GetResultMode() const { return GeometryResult::Mode::kPreventOverdraw; } diff --git a/impeller/entity/geometry/stroke_path_geometry.h b/impeller/entity/geometry/stroke_path_geometry.h index 254bcc0a03e0e..1772e8ada685d 100644 --- a/impeller/entity/geometry/stroke_path_geometry.h +++ b/impeller/entity/geometry/stroke_path_geometry.h @@ -34,13 +34,6 @@ class StrokePathGeometry final : public Geometry { const Entity& entity, RenderPass& pass) const override; - // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; - // |Geometry| GeometryResult::Mode GetResultMode() const override; @@ -59,17 +52,6 @@ class StrokePathGeometry final : public Geometry { Cap stroke_cap, Scalar scale); - static std::vector - GenerateSolidStrokeVerticesUV(const Path::Polyline& polyline, - Scalar stroke_width, - Scalar miter_limit, - Join stroke_join, - Cap stroke_cap, - Scalar scale, - Point texture_origin, - Size texture_size, - const Matrix& effect_transform); - friend class ImpellerBenchmarkAccessor; friend class ImpellerEntityUnitTestAccessor; diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc index a352a212c59d5..06b46cf95c063 100644 --- a/impeller/entity/geometry/vertices_geometry.cc +++ b/impeller/entity/geometry/vertices_geometry.cc @@ -187,62 +187,65 @@ GeometryResult VerticesGeometry::GetPositionColorBuffer( }; } -GeometryResult VerticesGeometry::GetPositionUVBuffer( - Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const { - using VS = TexturePipeline::VertexShader; - - auto index_count = indices_.size(); - auto vertex_count = vertices_.size(); - auto uv_transform = - texture_coverage.GetNormalizingTransform() * effect_transform; - auto has_texture_coordinates = HasTextureCoordinates(); - - size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData); - size_t total_idx_bytes = index_count * sizeof(uint16_t); - auto vertex_buffer = renderer.GetTransientsBuffer().Emplace( - total_vtx_bytes, alignof(VS::PerVertexData), [&](uint8_t* data) { - VS::PerVertexData* vtx_contents = - reinterpret_cast(data); - for (auto i = 0u; i < vertices_.size(); i++) { - auto vertex = vertices_[i]; - auto texture_coord = - has_texture_coordinates ? texture_coordinates_[i] : vertices_[i]; - auto uv = uv_transform * texture_coord; - // From experimentation we need to clamp these values to < 1.0 or else - // there can be flickering. - VS::PerVertexData vertex_data = { - .position = vertex, - .texture_coords = - Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough), - std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)), - }; - std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData)); - } - }); - - BufferView index_buffer = {}; - if (index_count > 0) { - index_buffer = renderer.GetTransientsBuffer().Emplace( - indices_.data(), total_idx_bytes, alignof(uint16_t)); - } - - return GeometryResult{ - .type = GetPrimitiveType(), - .vertex_buffer = - { - .vertex_buffer = vertex_buffer, - .index_buffer = index_buffer, - .vertex_count = index_count > 0 ? index_count : vertex_count, - .index_type = - index_count > 0 ? IndexType::k16bit : IndexType::kNone, - }, - .transform = entity.GetShaderTransform(pass), - }; -} +// GeometryResult VerticesGeometry::GetPositionUVBuffer( +// Rect texture_coverage, +// Matrix effect_transform, +// const ContentContext& renderer, +// const Entity& entity, +// RenderPass& pass) const { +// using VS = TexturePipeline::VertexShader; + +// auto index_count = indices_.size(); +// auto vertex_count = vertices_.size(); +// auto uv_transform = +// texture_coverage.GetNormalizingTransform() * effect_transform; +// auto has_texture_coordinates = HasTextureCoordinates(); + +// size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData); +// size_t total_idx_bytes = index_count * sizeof(uint16_t); +// auto vertex_buffer = renderer.GetTransientsBuffer().Emplace( +// total_vtx_bytes, alignof(VS::PerVertexData), [&](uint8_t* data) { +// VS::PerVertexData* vtx_contents = +// reinterpret_cast(data); +// for (auto i = 0u; i < vertices_.size(); i++) { +// auto vertex = vertices_[i]; +// auto texture_coord = +// has_texture_coordinates ? texture_coordinates_[i] : +// vertices_[i]; +// auto uv = uv_transform * texture_coord; +// // From experimentation we need to clamp these values to < 1.0 or +// else +// // there can be flickering. +// VS::PerVertexData vertex_data = { +// .position = vertex, +// .texture_coords = +// Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough), +// std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)), +// }; +// std::memcpy(vtx_contents++, &vertex_data, +// sizeof(VS::PerVertexData)); +// } +// }); + +// BufferView index_buffer = {}; +// if (index_count > 0) { +// index_buffer = renderer.GetTransientsBuffer().Emplace( +// indices_.data(), total_idx_bytes, alignof(uint16_t)); +// } + +// return GeometryResult{ +// .type = GetPrimitiveType(), +// .vertex_buffer = +// { +// .vertex_buffer = vertex_buffer, +// .index_buffer = index_buffer, +// .vertex_count = index_count > 0 ? index_count : vertex_count, +// .index_type = +// index_count > 0 ? IndexType::k16bit : IndexType::kNone, +// }, +// .transform = entity.GetShaderTransform(pass), +// }; +// } GeometryResult VerticesGeometry::GetPositionUVColorBuffer( Rect texture_coverage, diff --git a/impeller/entity/geometry/vertices_geometry.h b/impeller/entity/geometry/vertices_geometry.h index c28b4288a1b8b..b918334a1fd5f 100644 --- a/impeller/entity/geometry/vertices_geometry.h +++ b/impeller/entity/geometry/vertices_geometry.h @@ -38,11 +38,11 @@ class VerticesGeometry final : public Geometry { RenderPass& pass) const; // |Geometry| - GeometryResult GetPositionUVBuffer(Rect texture_coverage, - Matrix effect_transform, - const ContentContext& renderer, - const Entity& entity, - RenderPass& pass) const override; + // GeometryResult GetPositionUVBuffer(Rect texture_coverage, + // Matrix effect_transform, + // const ContentContext& renderer, + // const Entity& entity, + // RenderPass& pass) const override; // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, diff --git a/impeller/entity/shaders/geometry/uv.comp b/impeller/entity/shaders/geometry/uv.comp deleted file mode 100644 index de4aacc18963b..0000000000000 --- a/impeller/entity/shaders/geometry/uv.comp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include -#include - -// Unused, see See PointFieldGeometry::GetPositionBuffer -layout(local_size_x = 16) in; - -layout(std430) readonly buffer GeometryData { - // Size of this input data is frame_info.count; - vec2 points[]; -} -geometry_data; - -layout(std430) writeonly buffer GeometryUVData { - // Size of this output data is frame_info.count; - // x,y is the original geometry. - // u,v is the texture UV. - vec4 points_uv[]; -} -geometry_uv_data; - -uniform FrameInfo { - uint count; - mat4 effect_transform; - vec2 texture_origin; - vec2 texture_size; -} -frame_info; - -vec2 project_point(mat4 m, vec2 v) { - float w = v.x * m[0][3] + v.y * m[1][3] + m[3][3]; - vec2 result = vec2(v.x * m[0][0] + v.y * m[1][0] + m[3][0], - v.x * m[0][1] + v.y * m[1][1] + m[3][1]); - - // This is Skia's behavior, but it may be reasonable to allow UB for the w=0 - // case. - if (w != 0) { - w = 1 / w; - } - return result * w; -} - -void main() { - uint ident = gl_GlobalInvocationID.x; - if (ident >= frame_info.count) { - return; - } - - vec2 point = geometry_data.points[ident]; - - vec2 coverage_coords = - (point - frame_info.texture_origin) / frame_info.texture_size; - vec2 texture_coords = - project_point(frame_info.effect_transform, coverage_coords); - - geometry_uv_data.points_uv[ident] = vec4(point, texture_coords); -} diff --git a/impeller/entity/shaders/texture_uv_fill.vert b/impeller/entity/shaders/texture_uv_fill.vert new file mode 100644 index 0000000000000..f87ff05ae6849 --- /dev/null +++ b/impeller/entity/shaders/texture_uv_fill.vert @@ -0,0 +1,30 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include +#include + +// A shader that computes texture UVs from a normalizing transform. +uniform FrameInfo { + mat4 mvp; + // A normlizing transform created from the texture bounds and effect transform + mat4 uv_transform; + vec4 texture_coverage; + float texture_sampler_y_coord_scale; + float16_t alpha; +} +frame_info; + +in vec2 position; + +out vec2 v_texture_coords; +IMPELLER_MAYBE_FLAT out mediump float16_t v_alpha; + +void main() { + gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); + v_alpha = frame_info.alpha; + vec2 texture_coords = (frame_info.uv_transform * vec4(position, 0.0, 1.0)).xy; + v_texture_coords = + IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale); +} diff --git a/impeller/geometry/geometry_benchmarks.cc b/impeller/geometry/geometry_benchmarks.cc index 98d17cf7d8c15..32052c33d31b7 100644 --- a/impeller/geometry/geometry_benchmarks.cc +++ b/impeller/geometry/geometry_benchmarks.cc @@ -5,7 +5,6 @@ #include "flutter/benchmarking/benchmarking.h" #include "flutter/impeller/entity/solid_fill.vert.h" -#include "flutter/impeller/entity/texture_fill.vert.h" #include "impeller/entity/geometry/stroke_path_geometry.h" #include "impeller/geometry/path.h" @@ -26,21 +25,6 @@ class ImpellerBenchmarkAccessor { return StrokePathGeometry::GenerateSolidStrokeVertices( polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale); } - - static std::vector - GenerateSolidStrokeVerticesUV(const Path::Polyline& polyline, - Scalar stroke_width, - Scalar miter_limit, - Join stroke_join, - Cap stroke_cap, - Scalar scale, - Point texture_origin, - Size texture_size, - const Matrix& effect_transform) { - return StrokePathGeometry::GenerateSolidStrokeVerticesUV( - polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale, - texture_origin, texture_size, effect_transform); - } }; namespace { @@ -97,28 +81,16 @@ static void BM_Polyline(benchmark::State& state, Args&&... args) { state.counters["TotalPointCount"] = point_count; } -enum class UVMode { - kNoUV, - kUVRect, - kUVRectTx, -}; - template static void BM_StrokePolyline(benchmark::State& state, Args&&... args) { auto args_tuple = std::make_tuple(std::move(args)...); auto path = std::get(args_tuple); auto cap = std::get(args_tuple); auto join = std::get(args_tuple); - auto generate_uv = std::get(args_tuple); const Scalar stroke_width = 5.0f; const Scalar miter_limit = 10.0f; const Scalar scale = 1.0f; - const Point texture_origin = Point(0, 0); - const Size texture_size = Size(100, 100); - const Matrix effect_transform = (generate_uv == UVMode::kUVRectTx) - ? Matrix::MakeScale({2.0f, 2.0f, 1.0f}) - : Matrix(); auto points = std::make_unique>(); points->reserve(2048); @@ -131,16 +103,9 @@ static void BM_StrokePolyline(benchmark::State& state, Args&&... args) { size_t point_count = 0u; size_t single_point_count = 0u; while (state.KeepRunning()) { - if (generate_uv == UVMode::kNoUV) { - auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVertices( - polyline, stroke_width, miter_limit, join, cap, scale); - single_point_count = vertices.size(); - } else { - auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVerticesUV( - polyline, stroke_width, miter_limit, join, cap, scale, // - texture_origin, texture_size, effect_transform); - single_point_count = vertices.size(); - } + auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVertices( + polyline, stroke_width, miter_limit, join, cap, scale); + single_point_count = vertices.size(); point_count += single_point_count; } state.counters["SinglePointCount"] = single_point_count; @@ -167,7 +132,7 @@ static void BM_Convex(benchmark::State& state, Args&&... args) { #define MAKE_STROKE_BENCHMARK_CAPTURE(path, cap, join, closed, uvname, uvtype) \ BENCHMARK_CAPTURE(BM_StrokePolyline, stroke_##path##_##cap##_##join##uvname, \ - Create##path(closed), Cap::k##cap, Join::k##join, uvtype) + Create##path(closed), Cap::k##cap, Join::k##join) #define MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, uvname, uvtype) \ MAKE_STROKE_BENCHMARK_CAPTURE(path, Butt, Bevel, false, uvname, uvtype); \ @@ -191,7 +156,6 @@ BENCHMARK_CAPTURE(BM_Polyline, unclosed_cubic_polyline_tess, CreateCubic(false), true); -MAKE_STROKE_BENCHMARK_CAPTURE_UVS(Cubic); BENCHMARK_CAPTURE(BM_Polyline, quad_polyline, CreateQuadratic(true), false); BENCHMARK_CAPTURE(BM_Polyline, quad_polyline_tess, CreateQuadratic(true), true); @@ -203,12 +167,9 @@ BENCHMARK_CAPTURE(BM_Polyline, unclosed_quad_polyline_tess, CreateQuadratic(false), true); -MAKE_STROKE_BENCHMARK_CAPTURE_UVS(Quadratic); BENCHMARK_CAPTURE(BM_Convex, rrect_convex, CreateRRect(), true); -MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , , UVMode::kNoUV); -MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , _uv, UVMode::kUVRectTx); -MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , _uvNoTx, UVMode::kUVRect); +MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , , ); namespace { From 699fe6ad8f79dfbadbacd17d5db6589ba6703f8a Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sat, 13 Apr 2024 19:18:53 -0700 Subject: [PATCH 02/19] ++ --- impeller/entity/contents/content_context.h | 1 - impeller/tools/malioc.json | 63 ---------------------- 2 files changed, 64 deletions(-) diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 045888574c49b..c341b3a215d0a 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -63,7 +63,6 @@ #include "impeller/entity/texture_fill_strict_src.frag.h" #include "impeller/entity/texture_uv_fill.vert.h" #include "impeller/entity/tiled_texture_fill.frag.h" -#include "impeller/entity/uv.comp.h" #include "impeller/entity/vertices.frag.h" #include "impeller/entity/yuv_to_rgb_filter.frag.h" #include "impeller/entity/yuv_to_rgb_filter.vert.h" diff --git a/impeller/tools/malioc.json b/impeller/tools/malioc.json index 80ed9b3e7c840..4b06b67108b3b 100644 --- a/impeller/tools/malioc.json +++ b/impeller/tools/malioc.json @@ -10123,69 +10123,6 @@ } } }, - "flutter/impeller/entity/uv.comp.vkspv": { - "Mali-G78": { - "core": "Mali-G78", - "filename": "flutter/impeller/entity/uv.comp.vkspv", - "has_uniform_computation": true, - "type": "Compute", - "variants": { - "Main": { - "fp16_arithmetic": 0, - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "load_store" - ], - "longest_path_cycles": [ - 0.1875, - 0.1875, - 0.125, - 0.0625, - 2.0, - 0.0 - ], - "pipelines": [ - "arith_total", - "arith_fma", - "arith_cvt", - "arith_sfu", - "load_store", - "texture" - ], - "shortest_path_bound_pipelines": [ - "arith_total", - "arith_cvt" - ], - "shortest_path_cycles": [ - 0.046875, - 0.0, - 0.046875, - 0.0, - 0.0, - 0.0 - ], - "total_bound_pipelines": [ - "load_store" - ], - "total_cycles": [ - 0.1875, - 0.1875, - 0.125, - 0.0625, - 2.0, - 0.0 - ] - }, - "shared_storage_used": 0, - "stack_spill_bytes": 0, - "thread_occupancy": 100, - "uniform_registers_used": 24, - "work_registers_used": 10 - } - } - } - }, "flutter/impeller/entity/vertices.frag.vkspv": { "Mali-G78": { "core": "Mali-G78", From 0adc252d4a62423973437ba48f7f3f37558f830e Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 15:27:36 -0700 Subject: [PATCH 03/19] ++ --- impeller/entity/BUILD.gn | 1 + impeller/entity/contents/content_context.cc | 5 +- impeller/entity/contents/content_context.h | 33 +---------- impeller/entity/contents/texture_contents.cc | 58 ++++--------------- .../entity/contents/tiled_texture_contents.cc | 29 ++-------- impeller/entity/shaders/texture_uv_fill.vert | 4 -- .../entity/shaders/tiled_texture_fill.frag | 23 +++++--- impeller/tessellator/tessellator.cc | 11 ++-- impeller/tessellator/tessellator.h | 20 +++---- 9 files changed, 46 insertions(+), 138 deletions(-) diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index befa5a65975e1..6a268d224117f 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -39,6 +39,7 @@ impeller_shaders("entity_shaders") { "shaders/gradients/sweep_gradient_fill.frag", "shaders/texture_fill.frag", "shaders/texture_fill.vert", + "shaders/texture_uv_fill.vert", "shaders/tiled_texture_fill.frag", "shaders/tiled_texture_fill_external.frag", "shaders/texture_fill_strict_src.frag", diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index ac487d296b8b3..23da1f37e1196 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -260,8 +260,7 @@ ContentContext::ContentContext( ? std::make_shared( context_->GetResourceAllocator()) : std::move(render_target_allocator)), - host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())), - pending_command_buffers_(std::make_unique()) { + host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) { if (!context_ || !context_->IsValid()) { return; } @@ -423,7 +422,7 @@ ContentContext::ContentContext( rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); texture_strict_src_pipelines_.CreateDefault(*context_, options); position_uv_pipelines_.CreateDefault(*context_, options); - tiled_texture_pipelines_.CreateDefault(*context_, options); + tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal}); kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip); kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip); border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index c58ba69c23bee..2995694fe4b03 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -125,16 +125,6 @@ using SweepGradientSSBOFillPipeline = using RRectBlurPipeline = RenderPipelineHandle; using TexturePipeline = -<<<<<<< HEAD - RenderPipelineT; -using TextureStrictSrcPipeline = - RenderPipelineT; -using PositionUVPipeline = - RenderPipelineT; -using TiledTexturePipeline = - RenderPipelineT; -======= RenderPipelineHandle; using TextureStrictSrcPipeline = RenderPipelineHandle; using TiledTexturePipeline = - RenderPipelineHandle; ->>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b using KernelDecalPipeline = RenderPipelineHandle; using KernelPipeline = @@ -264,30 +253,13 @@ using FramebufferBlendSoftLightPipeline = /// Geometry Pipelines using PointsComputeShaderPipeline = ComputePipelineBuilder; -using UvComputeShaderPipeline = ComputePipelineBuilder; #ifdef IMPELLER_ENABLE_OPENGLES -<<<<<<< HEAD -using TextureExternalPipeline = - RenderPipelineT; - using TiledTextureExternalPipeline = - RenderPipelineT; -======= -using TiledTextureExternalPipeline = - RenderPipelineHandle; ->>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b #endif // IMPELLER_ENABLE_OPENGLES -// A struct used to isolate command buffer storage from the content -// context options to preserve const-ness. -struct PendingCommandBuffers { - std::vector> command_buffers; -}; - /// Pipeline state configuration. /// /// Each unique combination of these options requires a different pipeline state @@ -1071,7 +1043,6 @@ class ContentContext { #endif // IMPELLER_ENABLE_3D std::shared_ptr render_target_cache_; std::shared_ptr host_buffer_; - std::unique_ptr pending_command_buffers_; bool wireframe_ = false; ContentContext(const ContentContext&) = delete; diff --git a/impeller/entity/contents/texture_contents.cc b/impeller/entity/contents/texture_contents.cc index 34202a4a23e9a..24293e95b4aed 100644 --- a/impeller/entity/contents/texture_contents.cc +++ b/impeller/entity/contents/texture_contents.cc @@ -14,7 +14,6 @@ #include "impeller/entity/texture_fill.frag.h" #include "impeller/entity/texture_fill.vert.h" #include "impeller/entity/texture_fill_strict_src.frag.h" -#include "impeller/entity/tiled_texture_fill_external.frag.h" #include "impeller/geometry/constants.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/vertex_buffer_builder.h" @@ -112,9 +111,8 @@ bool TextureContents::Render(const ContentContext& renderer, RenderPass& pass) const { auto capture = entity.GetCapture().CreateChild("TextureContents"); - using VS = TextureUvFillVertexShader; + using VS = TextureFillVertexShader; using FS = TextureFillFragmentShader; - using FSExternal = TiledTextureFillExternalFragmentShader; using FSStrict = TextureFillStrictSrcFragmentShader; if (destination_rect_.IsEmpty() || source_rect_.IsEmpty() || @@ -124,24 +122,20 @@ bool TextureContents::Render(const ContentContext& renderer, bool is_external_texture = texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES; + FML_DCHECK(!is_external_texture); auto source_rect = capture.AddRect("Source rect", source_rect_); -<<<<<<< HEAD -======= auto texture_coords = Rect::MakeSize(texture_->GetSize()).Project(source_rect); VertexBufferBuilder vertex_builder; ->>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b auto destination_rect = capture.AddRect("Destination rect", destination_rect_); - - VertexBufferBuilder vertex_builder; vertex_builder.AddVertices({ - {destination_rect.GetLeftTop()}, - {destination_rect.GetRightTop()}, - {destination_rect.GetLeftBottom()}, - {destination_rect.GetRightBottom()}, + {destination_rect.GetLeftTop(), texture_coords.GetLeftTop()}, + {destination_rect.GetRightTop(), texture_coords.GetRightTop()}, + {destination_rect.GetLeftBottom(), texture_coords.GetLeftBottom()}, + {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()}, }); auto& host_buffer = renderer.GetTransientsBuffer(); @@ -164,46 +158,14 @@ bool TextureContents::Render(const ContentContext& renderer, } pipeline_options.primitive_type = PrimitiveType::kTriangleStrip; - std::shared_ptr> pipeline; -#ifdef IMPELLER_ENABLE_OPENGLES - if (is_external_texture) { - pipeline = renderer.GetTiledTextureExternalPipeline(pipeline_options); - } -#endif // IMPELLER_ENABLE_OPENGLES - - if (!pipeline) { - if (strict_source_rect_enabled_) { - pipeline = renderer.GetTextureStrictSrcPipeline(pipeline_options); - } else { - pipeline = renderer.GetTexturePipeline(pipeline_options); - } - } - pass.SetPipeline(pipeline); + pass.SetPipeline(strict_source_rect_enabled_ + ? renderer.GetTextureStrictSrcPipeline(pipeline_options) + : renderer.GetTexturePipeline(pipeline_options)); pass.SetVertexBuffer(vertex_builder.CreateVertexBuffer(host_buffer)); VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); - if (is_external_texture) { - FSExternal::FragInfo frag_info; - frag_info.x_tile_mode = - static_cast(sampler_descriptor_.width_address_mode); - frag_info.y_tile_mode = - static_cast(sampler_descriptor_.height_address_mode); - frag_info.alpha = capture.AddScalar("Alpha", GetOpacity()); - - auto sampler_descriptor = sampler_descriptor_; - // OES_EGL_image_external states that only CLAMP_TO_EDGE is valid, so - // we emulate all other tile modes here by remapping the texture - // coordinates. - sampler_descriptor.width_address_mode = SamplerAddressMode::kClampToEdge; - sampler_descriptor.height_address_mode = SamplerAddressMode::kClampToEdge; - - FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info))); - FSExternal::BindSAMPLEREXTERNALOESTextureSampler( - pass, texture_, - renderer.GetContext()->GetSamplerLibrary()->GetSampler( - sampler_descriptor)); - } else if (strict_source_rect_enabled_) { + if (strict_source_rect_enabled_) { // For a strict source rect, shrink the texture coordinate range by half a // texel to ensure that linear filtering does not sample anything outside // the source rect bounds. diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index f425f33419eb5..3602e52032426 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -6,8 +6,6 @@ #include "fml/logging.h" #include "impeller/entity/contents/content_context.h" -#include "impeller/entity/texture_fill.frag.h" -#include "impeller/entity/texture_fill.vert.h" #include "impeller/entity/tiled_texture_fill.frag.h" #include "impeller/entity/tiled_texture_fill_external.frag.h" #include "impeller/renderer/render_pass.h" @@ -128,18 +126,11 @@ bool TiledTextureContents::Render(const ContentContext& renderer, bool is_external_texture = texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES; - bool uses_emulated_tile_mode = - UsesEmulatedTileMode(renderer.GetDeviceCapabilities()); - VS::FrameInfo frame_info; frame_info.texture_sampler_y_coord_scale = texture_->GetYCoordScale(); -<<<<<<< HEAD - frame_info.alpha = GetOpacityFactor(); frame_info.uv_transform = Rect::MakeSize(texture_size).GetNormalizingTransform() * GetInverseEffectTransform(); -======= ->>>>>>> 55670b71eb00fbe80601b7227f68c1df4cae827b PipelineBuilderMethod pipeline_method; @@ -147,9 +138,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer, if (is_external_texture) { pipeline_method = &ContentContext::GetTiledTextureExternalPipeline; } else { - pipeline_method = uses_emulated_tile_mode - ? &ContentContext::GetTiledTexturePipeline - : &ContentContext::GetTexturePipeline; + pipeline_method = &ContentContext::GetTiledTexturePipeline; } #else pipeline_method = uses_emulated_tile_mode @@ -163,15 +152,10 @@ bool TiledTextureContents::Render(const ContentContext& renderer, }; return ColorSourceContents::DrawGeometry( renderer, entity, pass, pipeline_callback, frame_info, - [this, &renderer, &is_external_texture, - &uses_emulated_tile_mode](RenderPass& pass) { + [this, &renderer, &is_external_texture](RenderPass& pass) { auto& host_buffer = renderer.GetTransientsBuffer(); - if (uses_emulated_tile_mode) { - pass.SetCommandLabel("TiledTextureFill"); - } else { - pass.SetCommandLabel("TextureFill"); - } + pass.SetCommandLabel("TextureFill"); if (is_external_texture) { FSExternal::FragInfo frag_info; @@ -179,17 +163,12 @@ bool TiledTextureContents::Render(const ContentContext& renderer, frag_info.y_tile_mode = static_cast(y_tile_mode_); frag_info.alpha = GetOpacityFactor(); FSExternal::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); - } else if (uses_emulated_tile_mode) { + } else { FS::FragInfo frag_info; frag_info.x_tile_mode = static_cast(x_tile_mode_); frag_info.y_tile_mode = static_cast(y_tile_mode_); frag_info.alpha = GetOpacityFactor(); FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); - } else { - TextureFillFragmentShader::FragInfo frag_info; - frag_info.alpha = GetOpacityFactor(); - TextureFillFragmentShader::BindFragInfo( - pass, host_buffer.EmplaceUniform(frag_info)); } if (is_external_texture) { diff --git a/impeller/entity/shaders/texture_uv_fill.vert b/impeller/entity/shaders/texture_uv_fill.vert index f87ff05ae6849..11e91d833c7bf 100644 --- a/impeller/entity/shaders/texture_uv_fill.vert +++ b/impeller/entity/shaders/texture_uv_fill.vert @@ -10,20 +10,16 @@ uniform FrameInfo { mat4 mvp; // A normlizing transform created from the texture bounds and effect transform mat4 uv_transform; - vec4 texture_coverage; float texture_sampler_y_coord_scale; - float16_t alpha; } frame_info; in vec2 position; out vec2 v_texture_coords; -IMPELLER_MAYBE_FLAT out mediump float16_t v_alpha; void main() { gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); - v_alpha = frame_info.alpha; vec2 texture_coords = (frame_info.uv_transform * vec4(position, 0.0, 1.0)).xy; v_texture_coords = IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale); diff --git a/impeller/entity/shaders/tiled_texture_fill.frag b/impeller/entity/shaders/tiled_texture_fill.frag index 747bb646dac3d..25b2af3526ecf 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -7,6 +7,8 @@ precision mediump float; #include #include +layout(constant_id = 0) const float supports_decal = 1.0; + uniform f16sampler2D texture_sampler; uniform FragInfo { @@ -21,11 +23,18 @@ in highp vec2 v_texture_coords; out f16vec4 frag_color; void main() { - frag_color = - IPHalfSampleWithTileMode(texture_sampler, // sampler - v_texture_coords, // texture coordinates - float16_t(frag_info.x_tile_mode), // x tile mode - float16_t(frag_info.y_tile_mode) // y tile mode - ) * - float16_t(frag_info.alpha); + if (supports_decal == 1.0) { + frag_color = texture(texture_sampler, // sampler + v_texture_coords, // texture coordinates + float16_t(kDefaultMipBias)) * + float16_t(frag_info.alpha); + } else { + frag_color = IPHalfSampleWithTileMode( + texture_sampler, // sampler + v_texture_coords, // texture coordinates + float16_t(frag_info.x_tile_mode), // x tile mode + float16_t(frag_info.y_tile_mode) // y tile mode + ) * + float16_t(frag_info.alpha); + } } diff --git a/impeller/tessellator/tessellator.cc b/impeller/tessellator/tessellator.cc index ac63c66078fb9..4fba4a71f9d38 100644 --- a/impeller/tessellator/tessellator.cc +++ b/impeller/tessellator/tessellator.cc @@ -33,12 +33,10 @@ Path::Polyline Tessellator::CreateTempPolyline(const Path& path, VertexBuffer Tessellator::TessellateConvex(const Path& path, HostBuffer& host_buffer, - Scalar tolerance, - std::optional uv_transform) { + Scalar tolerance) { FML_DCHECK(point_buffer_); FML_DCHECK(index_buffer_); - TessellateConvexInternal(path, *point_buffer_, *index_buffer_, tolerance, - uv_transform); + TessellateConvexInternal(path, *point_buffer_, *index_buffer_, tolerance); if (point_buffer_->empty()) { return VertexBuffer{ @@ -68,12 +66,11 @@ VertexBuffer Tessellator::TessellateConvex(const Path& path, void Tessellator::TessellateConvexInternal(const Path& path, std::vector& point_buffer, std::vector& index_buffer, - Scalar tolerance, - std::optional uv_transform) { + Scalar tolerance) { index_buffer_->clear(); point_buffer_->clear(); - VertexWriter writer(point_buffer, index_buffer, uv_transform); + VertexWriter writer(point_buffer, index_buffer); path.WritePolyline(tolerance, writer); writer.EndContour(); diff --git a/impeller/tessellator/tessellator.h b/impeller/tessellator/tessellator.h index 013bf4dff044b..1b95336c9afc6 100644 --- a/impeller/tessellator/tessellator.h +++ b/impeller/tessellator/tessellator.h @@ -174,26 +174,20 @@ class Tessellator { /// path for rendering. /// @param[in] host_buffer The host buffer for allocation of vertices/index /// data. - /// @param[in] uv_transform If provided, then uvs are also generated into the - /// point buffer. Defaults to std::nullopt. /// /// @return A vertex buffer containing all data from the provided curve. - VertexBuffer TessellateConvex( - const Path& path, - HostBuffer& host_buffer, - Scalar tolerance, - std::optional uv_transform = std::nullopt); + VertexBuffer TessellateConvex(const Path& path, + HostBuffer& host_buffer, + Scalar tolerance); /// Visible for testing. /// /// This method only exists for the ease of benchmarking without using the /// real allocator needed by the [host_buffer]. - void TessellateConvexInternal( - const Path& path, - std::vector& point_buffer, - std::vector& index_buffer, - Scalar tolerance, - std::optional uv_transform = std::nullopt); + void TessellateConvexInternal(const Path& path, + std::vector& point_buffer, + std::vector& index_buffer, + Scalar tolerance); //---------------------------------------------------------------------------- /// @brief Create a temporary polyline. Only one per-process can exist at From 82786b26cf50d86cb815296a4f33e0d84f2daf2a Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 15:39:44 -0700 Subject: [PATCH 04/19] ++ --- impeller/entity/contents/tiled_texture_contents.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index 3602e52032426..3f6d4a3715203 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -141,9 +141,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer, pipeline_method = &ContentContext::GetTiledTexturePipeline; } #else - pipeline_method = uses_emulated_tile_mode - ? &ContentContext::GetTiledTexturePipeline - : &ContentContext::GetTexturePipeline; + pipeline_method = &ContentContext::GetTiledTexturePipeline; #endif // IMPELLER_ENABLE_OPENGLES PipelineBuilderCallback pipeline_callback = From d97e84b57c960f1f298149feb0091bd2baacc6be Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 15:48:12 -0700 Subject: [PATCH 05/19] ++ --- impeller/entity/contents/vertices_contents.cc | 9 ++++++--- impeller/entity/geometry/vertices_geometry.h | 7 ------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 8b84b128bc862..b67aee75d192b 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -133,8 +133,8 @@ void VerticesUVContents::SetAlpha(Scalar alpha) { bool VerticesUVContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - using VS = TexturePipeline::VertexShader; - using FS = TexturePipeline::FragmentShader; + using VS = TiledTexturePipeline::VertexShader; + using FS = TiledTexturePipeline::FragmentShader; auto src_contents = parent_.GetSourceContents(); @@ -161,17 +161,20 @@ bool VerticesUVContents::Render(const ContentContext& renderer, auto geometry_result = geometry->GetPositionBuffer(renderer, entity, pass); auto opts = OptionsFromPassAndEntity(pass, entity); opts.primitive_type = geometry_result.type; - pass.SetPipeline(renderer.GetTexturePipeline(opts)); + pass.SetPipeline(renderer.GetTiledTexturePipeline(opts)); pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; frame_info.texture_sampler_y_coord_scale = snapshot->texture->GetYCoordScale(); + frame_info.uv_transform = coverage.value().GetNormalizingTransform(); VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.alpha = alpha_ * snapshot->opacity; + frag_info.x_tile_mode = 0; + frag_info.y_tile_mode = 0; FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); FS::BindTextureSampler(pass, snapshot->texture, renderer.GetContext()->GetSamplerLibrary()->GetSampler( diff --git a/impeller/entity/geometry/vertices_geometry.h b/impeller/entity/geometry/vertices_geometry.h index b918334a1fd5f..b3a11223455e2 100644 --- a/impeller/entity/geometry/vertices_geometry.h +++ b/impeller/entity/geometry/vertices_geometry.h @@ -37,13 +37,6 @@ class VerticesGeometry final : public Geometry { const Entity& entity, RenderPass& pass) const; - // |Geometry| - // GeometryResult GetPositionUVBuffer(Rect texture_coverage, - // Matrix effect_transform, - // const ContentContext& renderer, - // const Entity& entity, - // RenderPass& pass) const override; - // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, From 6ef532c4880ff21d8e14ae115b2d0750d6d3b631 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 15:51:42 -0700 Subject: [PATCH 06/19] delete more uv computation. --- impeller/entity/geometry/geometry.cc | 21 ------- impeller/entity/geometry/geometry.h | 1 - .../entity/geometry/stroke_path_geometry.cc | 44 -------------- impeller/entity/geometry/vertices_geometry.cc | 60 ------------------- 4 files changed, 126 deletions(-) diff --git a/impeller/entity/geometry/geometry.cc b/impeller/entity/geometry/geometry.cc index 97daf73962400..d595317d3656a 100644 --- a/impeller/entity/geometry/geometry.cc +++ b/impeller/entity/geometry/geometry.cc @@ -53,27 +53,6 @@ GeometryResult Geometry::ComputePositionGeometry( }; } -VertexBufferBuilder -ComputeUVGeometryCPU( - VertexBufferBuilder& input, - Point texture_origin, - Size texture_coverage, - Matrix effect_transform) { - VertexBufferBuilder vertex_builder; - vertex_builder.Reserve(input.GetVertexCount()); - input.IterateVertices( - [&vertex_builder, &texture_coverage, &effect_transform, - &texture_origin](SolidFillVertexShader::PerVertexData old_vtx) { - TextureFillVertexShader::PerVertexData data; - data.position = old_vtx.position; - data.texture_coords = effect_transform * - (old_vtx.position - texture_origin) / - texture_coverage; - vertex_builder.AppendVertex(data); - }); - return vertex_builder; -} - GeometryResult::Mode Geometry::GetResultMode() const { return GeometryResult::Mode::kNormal; } diff --git a/impeller/entity/geometry/geometry.h b/impeller/entity/geometry/geometry.h index bddd43255222e..70939b8f0dc63 100644 --- a/impeller/entity/geometry/geometry.h +++ b/impeller/entity/geometry/geometry.h @@ -9,7 +9,6 @@ #include "impeller/core/vertex_buffer.h" #include "impeller/entity/contents/content_context.h" #include "impeller/entity/entity.h" -#include "impeller/entity/texture_fill.vert.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/vertex_buffer_builder.h" diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 0e4f8a178c80e..f6eb60fe2b100 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -7,7 +7,6 @@ #include "impeller/core/buffer_view.h" #include "impeller/core/formats.h" #include "impeller/entity/geometry/geometry.h" -#include "impeller/entity/texture_fill.vert.h" #include "impeller/geometry/path_builder.h" #include "impeller/geometry/path_component.h" @@ -45,49 +44,6 @@ class PositionWriter { std::vector data_ = {}; }; -class PositionUVWriter { - public: - PositionUVWriter(const Point& texture_origin, - const Size& texture_size, - const Matrix& effect_transform) - : texture_origin_(texture_origin), - texture_size_(texture_size), - effect_transform_(effect_transform) {} - - const std::vector& GetData() { - if (effect_transform_.IsIdentity()) { - auto origin = texture_origin_; - auto scale = 1.0 / texture_size_; - - for (auto& pvd : data_) { - pvd.texture_coords = (pvd.position - origin) * scale; - } - } else { - auto texture_rect = Rect::MakeOriginSize(texture_origin_, texture_size_); - Matrix uv_transform = - texture_rect.GetNormalizingTransform() * effect_transform_; - - for (auto& pvd : data_) { - pvd.texture_coords = uv_transform * pvd.position; - } - } - return data_; - } - - void AppendVertex(const Point& point) { - data_.emplace_back(TextureFillVertexShader::PerVertexData{ - .position = point, - // .texture_coords = default, will be filled in during |GetData()| - }); - } - - private: - std::vector data_ = {}; - const Point texture_origin_; - const Size texture_size_; - const Matrix effect_transform_; -}; - template class StrokeGenerator { public: diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc index 06b46cf95c063..5e6d14a6d44cd 100644 --- a/impeller/entity/geometry/vertices_geometry.cc +++ b/impeller/entity/geometry/vertices_geometry.cc @@ -187,66 +187,6 @@ GeometryResult VerticesGeometry::GetPositionColorBuffer( }; } -// GeometryResult VerticesGeometry::GetPositionUVBuffer( -// Rect texture_coverage, -// Matrix effect_transform, -// const ContentContext& renderer, -// const Entity& entity, -// RenderPass& pass) const { -// using VS = TexturePipeline::VertexShader; - -// auto index_count = indices_.size(); -// auto vertex_count = vertices_.size(); -// auto uv_transform = -// texture_coverage.GetNormalizingTransform() * effect_transform; -// auto has_texture_coordinates = HasTextureCoordinates(); - -// size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData); -// size_t total_idx_bytes = index_count * sizeof(uint16_t); -// auto vertex_buffer = renderer.GetTransientsBuffer().Emplace( -// total_vtx_bytes, alignof(VS::PerVertexData), [&](uint8_t* data) { -// VS::PerVertexData* vtx_contents = -// reinterpret_cast(data); -// for (auto i = 0u; i < vertices_.size(); i++) { -// auto vertex = vertices_[i]; -// auto texture_coord = -// has_texture_coordinates ? texture_coordinates_[i] : -// vertices_[i]; -// auto uv = uv_transform * texture_coord; -// // From experimentation we need to clamp these values to < 1.0 or -// else -// // there can be flickering. -// VS::PerVertexData vertex_data = { -// .position = vertex, -// .texture_coords = -// Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough), -// std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)), -// }; -// std::memcpy(vtx_contents++, &vertex_data, -// sizeof(VS::PerVertexData)); -// } -// }); - -// BufferView index_buffer = {}; -// if (index_count > 0) { -// index_buffer = renderer.GetTransientsBuffer().Emplace( -// indices_.data(), total_idx_bytes, alignof(uint16_t)); -// } - -// return GeometryResult{ -// .type = GetPrimitiveType(), -// .vertex_buffer = -// { -// .vertex_buffer = vertex_buffer, -// .index_buffer = index_buffer, -// .vertex_count = index_count > 0 ? index_count : vertex_count, -// .index_type = -// index_count > 0 ? IndexType::k16bit : IndexType::kNone, -// }, -// .transform = entity.GetShaderTransform(pass), -// }; -// } - GeometryResult VerticesGeometry::GetPositionUVColorBuffer( Rect texture_coverage, Matrix effect_transform, From a3ba350bd871c5bc0966b5885236ff71183c1f01 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 16:14:47 -0700 Subject: [PATCH 07/19] remove position uv pipelines --- impeller/entity/contents/content_context.cc | 1 - impeller/entity/contents/content_context.h | 8 -------- 2 files changed, 9 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 23da1f37e1196..34da4ffee1ad0 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -421,7 +421,6 @@ ContentContext::ContentContext( rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); texture_strict_src_pipelines_.CreateDefault(*context_, options); - position_uv_pipelines_.CreateDefault(*context_, options); tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal}); kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip); kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip); diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 2995694fe4b03..062649f77bd30 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -129,8 +129,6 @@ using TexturePipeline = using TextureStrictSrcPipeline = RenderPipelineHandle; -using PositionUVPipeline = RenderPipelineHandle; using TiledTexturePipeline = RenderPipelineHandle; @@ -471,11 +469,6 @@ class ContentContext { } #endif // IMPELLER_ENABLE_OPENGLES - std::shared_ptr> GetPositionUVPipeline( - ContentContextOptions opts) const { - return GetPipeline(position_uv_pipelines_, opts); - } - std::shared_ptr> GetTiledTexturePipeline( ContentContextOptions opts) const { return GetPipeline(tiled_texture_pipelines_, opts); @@ -919,7 +912,6 @@ class ContentContext { mutable Variants tiled_texture_external_pipelines_; #endif // IMPELLER_ENABLE_OPENGLES - mutable Variants position_uv_pipelines_; mutable Variants tiled_texture_pipelines_; mutable Variants kernel_decal_pipelines_; mutable Variants kernel_nodecal_pipelines_; From 63c48bf2805b698fd2582c3885fa9d445ad66397 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 16:43:12 -0700 Subject: [PATCH 08/19] add maybe unused --- impeller/entity/contents/texture_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/contents/texture_contents.cc b/impeller/entity/contents/texture_contents.cc index 24293e95b4aed..72fce8d0ff211 100644 --- a/impeller/entity/contents/texture_contents.cc +++ b/impeller/entity/contents/texture_contents.cc @@ -120,7 +120,7 @@ bool TextureContents::Render(const ContentContext& renderer, return true; // Nothing to render. } - bool is_external_texture = + [[maybe_unused]] bool is_external_texture = texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES; FML_DCHECK(!is_external_texture); From 9ac3c5d5721cad79528556e9cde4c03411cd3156 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 16:46:22 -0700 Subject: [PATCH 09/19] update licenses --- ci/licenses_golden/licenses_flutter | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index b52c469b2f816..c93f8899a759d 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -40395,7 +40395,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../ ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/uv.comp + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE @@ -40417,6 +40416,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flut ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/vertices.frag + ../../../flutter/LICENSE @@ -43275,7 +43275,6 @@ FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp -FILE: ../../../flutter/impeller/entity/shaders/geometry/uv.comp FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag @@ -43297,6 +43296,7 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag +FILE: ../../../flutter/impeller/entity/shaders/texture_uv_fill.vert FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill_external.frag FILE: ../../../flutter/impeller/entity/shaders/vertices.frag From ae7f592504977c21535723e7d004f1a9d1996f64 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 19 Apr 2024 17:22:45 -0700 Subject: [PATCH 10/19] malioc diff. --- impeller/tools/malioc.json | 343 +++++++++++++++++++++++++++++++++---- 1 file changed, 307 insertions(+), 36 deletions(-) diff --git a/impeller/tools/malioc.json b/impeller/tools/malioc.json index 0f91b79ac1d2f..3f5ff33f9a5b2 100644 --- a/impeller/tools/malioc.json +++ b/impeller/tools/malioc.json @@ -5710,12 +5710,169 @@ } } }, + "flutter/impeller/entity/gles/texture_uv_fill.vert.gles": { + "Mali-G78": { + "core": "Mali-G78", + "filename": "flutter/impeller/entity/gles/texture_uv_fill.vert.gles", + "has_uniform_computation": true, + "type": "Vertex", + "variants": { + "Position": { + "fp16_arithmetic": 0, + "has_stack_spilling": false, + "performance": { + "longest_path_bound_pipelines": [ + "load_store" + ], + "longest_path_cycles": [ + 0.140625, + 0.140625, + 0.0, + 0.0, + 2.0, + 0.0 + ], + "pipelines": [ + "arith_total", + "arith_fma", + "arith_cvt", + "arith_sfu", + "load_store", + "texture" + ], + "shortest_path_bound_pipelines": [ + "load_store" + ], + "shortest_path_cycles": [ + 0.140625, + 0.140625, + 0.0, + 0.0, + 2.0, + 0.0 + ], + "total_bound_pipelines": [ + "load_store" + ], + "total_cycles": [ + 0.140625, + 0.140625, + 0.0, + 0.0, + 2.0, + 0.0 + ] + }, + "stack_spill_bytes": 0, + "thread_occupancy": 100, + "uniform_registers_used": 28, + "work_registers_used": 32 + }, + "Varying": { + "fp16_arithmetic": 0, + "has_stack_spilling": false, + "performance": { + "longest_path_bound_pipelines": [ + "load_store" + ], + "longest_path_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ], + "pipelines": [ + "arith_total", + "arith_fma", + "arith_cvt", + "arith_sfu", + "load_store", + "texture" + ], + "shortest_path_bound_pipelines": [ + "load_store" + ], + "shortest_path_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ], + "total_bound_pipelines": [ + "load_store" + ], + "total_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ] + }, + "stack_spill_bytes": 0, + "thread_occupancy": 100, + "uniform_registers_used": 16, + "work_registers_used": 9 + } + } + }, + "Mali-T880": { + "core": "Mali-T880", + "filename": "flutter/impeller/entity/gles/texture_uv_fill.vert.gles", + "has_uniform_computation": false, + "type": "Vertex", + "variants": { + "Main": { + "has_stack_spilling": false, + "performance": { + "longest_path_bound_pipelines": [ + "load_store" + ], + "longest_path_cycles": [ + 3.299999952316284, + 4.0, + 0.0 + ], + "pipelines": [ + "arithmetic", + "load_store", + "texture" + ], + "shortest_path_bound_pipelines": [ + "load_store" + ], + "shortest_path_cycles": [ + 3.299999952316284, + 4.0, + 0.0 + ], + "total_bound_pipelines": [ + "load_store" + ], + "total_cycles": [ + 3.3333332538604736, + 4.0, + 0.0 + ] + }, + "thread_occupancy": 100, + "uniform_registers_used": 7, + "work_registers_used": 3 + } + } + } + }, "flutter/impeller/entity/gles/tiled_texture_fill.frag.gles": { "Mali-G78": { "core": "Mali-G78", "filename": "flutter/impeller/entity/gles/tiled_texture_fill.frag.gles", "has_side_effects": false, - "has_uniform_computation": true, + "has_uniform_computation": false, "modifies_coverage": false, "reads_color_buffer": false, "type": "Fragment", @@ -5723,17 +5880,17 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 33, + "fp16_arithmetic": 100, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "arith_total", - "arith_cvt" + "varying", + "texture" ], "longest_path_cycles": [ - 0.265625, + 0.046875, 0.03125, - 0.265625, + 0.046875, 0.0, 0.0, 0.25, @@ -5753,22 +5910,22 @@ "texture" ], "shortest_path_cycles": [ - 0.0625, 0.03125, - 0.0625, + 0.03125, + 0.015625, 0.0, 0.0, 0.25, 0.25 ], "total_bound_pipelines": [ - "arith_total", - "arith_cvt" + "varying", + "texture" ], "total_cycles": [ - 0.265625, + 0.046875, 0.03125, - 0.265625, + 0.046875, 0.0, 0.0, 0.25, @@ -5792,10 +5949,12 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "arithmetic" + "arithmetic", + "load_store", + "texture" ], "longest_path_cycles": [ - 3.299999952316284, + 1.0, 1.0, 1.0 ], @@ -5805,18 +5964,21 @@ "texture" ], "shortest_path_bound_pipelines": [ - "arithmetic" + "arithmetic", + "load_store", + "texture" ], "shortest_path_cycles": [ - 1.3200000524520874, 1.0, - 0.0 + 1.0, + 1.0 ], "total_bound_pipelines": [ - "arithmetic" + "load_store", + "texture" ], "total_cycles": [ - 3.6666667461395264, + 0.6666666865348816, 1.0, 1.0 ] @@ -8651,6 +8813,118 @@ } } }, + "flutter/impeller/entity/texture_uv_fill.vert.vkspv": { + "Mali-G78": { + "core": "Mali-G78", + "filename": "flutter/impeller/entity/texture_uv_fill.vert.vkspv", + "has_uniform_computation": true, + "type": "Vertex", + "variants": { + "Position": { + "fp16_arithmetic": 0, + "has_stack_spilling": false, + "performance": { + "longest_path_bound_pipelines": [ + "load_store" + ], + "longest_path_cycles": [ + 0.125, + 0.125, + 0.0, + 0.0, + 2.0, + 0.0 + ], + "pipelines": [ + "arith_total", + "arith_fma", + "arith_cvt", + "arith_sfu", + "load_store", + "texture" + ], + "shortest_path_bound_pipelines": [ + "load_store" + ], + "shortest_path_cycles": [ + 0.125, + 0.125, + 0.0, + 0.0, + 2.0, + 0.0 + ], + "total_bound_pipelines": [ + "load_store" + ], + "total_cycles": [ + 0.125, + 0.125, + 0.0, + 0.0, + 2.0, + 0.0 + ] + }, + "stack_spill_bytes": 0, + "thread_occupancy": 100, + "uniform_registers_used": 40, + "work_registers_used": 32 + }, + "Varying": { + "fp16_arithmetic": 0, + "has_stack_spilling": false, + "performance": { + "longest_path_bound_pipelines": [ + "load_store" + ], + "longest_path_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ], + "pipelines": [ + "arith_total", + "arith_fma", + "arith_cvt", + "arith_sfu", + "load_store", + "texture" + ], + "shortest_path_bound_pipelines": [ + "load_store" + ], + "shortest_path_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ], + "total_bound_pipelines": [ + "load_store" + ], + "total_cycles": [ + 0.078125, + 0.078125, + 0.015625, + 0.0, + 3.0, + 0.0 + ] + }, + "stack_spill_bytes": 0, + "thread_occupancy": 100, + "uniform_registers_used": 32, + "work_registers_used": 9 + } + } + } + }, "flutter/impeller/entity/tiled_texture_fill.frag.vkspv": { "Mali-G78": { "core": "Mali-G78", @@ -8664,20 +8938,18 @@ "uses_late_zs_update": false, "variants": { "Main": { - "fp16_arithmetic": 33, + "fp16_arithmetic": 100, "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "arith_total", - "arith_cvt", "varying", "texture" ], "longest_path_cycles": [ - 0.25, 0.03125, - 0.25, - 0.0625, + 0.03125, + 0.015625, + 0.0, 0.0, 0.25, 0.25 @@ -8692,28 +8964,27 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "varying", + "texture" ], "shortest_path_cycles": [ - 0.140625, 0.03125, - 0.140625, - 0.0625, + 0.03125, + 0.015625, + 0.0, 0.0, 0.25, - 0.0 + 0.25 ], "total_bound_pipelines": [ - "arith_total", - "arith_cvt", "varying", "texture" ], "total_cycles": [ - 0.25, 0.03125, - 0.25, - 0.0625, + 0.03125, + 0.015625, + 0.0, 0.0, 0.25, 0.25 @@ -8722,7 +8993,7 @@ "stack_spill_bytes": 0, "thread_occupancy": 100, "uniform_registers_used": 4, - "work_registers_used": 7 + "work_registers_used": 5 } } } From 7fdfd0b1b17820d4da2a1d3ab9c8ec6b9177d18a Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 22 Apr 2024 14:39:48 -0700 Subject: [PATCH 11/19] revert changes to vertices contents. --- impeller/entity/contents/vertices_contents.cc | 14 ++--- impeller/entity/geometry/vertices_geometry.cc | 57 +++++++++++++++++++ impeller/entity/geometry/vertices_geometry.h | 6 ++ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index b67aee75d192b..15297613ddc57 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -133,8 +133,8 @@ void VerticesUVContents::SetAlpha(Scalar alpha) { bool VerticesUVContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - using VS = TiledTexturePipeline::VertexShader; - using FS = TiledTexturePipeline::FragmentShader; + using VS = TexturePipeline::VertexShader; + using FS = TexturePipeline::FragmentShader; auto src_contents = parent_.GetSourceContents(); @@ -152,29 +152,27 @@ bool VerticesUVContents::Render(const ContentContext& renderer, pass.SetCommandLabel("VerticesUV"); auto& host_buffer = renderer.GetTransientsBuffer(); - const std::shared_ptr& geometry = parent_.GetGeometry(); + const std::shared_ptr& geometry = parent_.GetGeometry(); auto coverage = src_contents->GetCoverage(Entity{}); if (!coverage.has_value()) { return false; } - auto geometry_result = geometry->GetPositionBuffer(renderer, entity, pass); + auto geometry_result = geometry->GetPositionUVBuffer( + coverage.value(), Matrix(), renderer, entity, pass); auto opts = OptionsFromPassAndEntity(pass, entity); opts.primitive_type = geometry_result.type; - pass.SetPipeline(renderer.GetTiledTexturePipeline(opts)); + pass.SetPipeline(renderer.GetTexturePipeline(opts)); pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer)); VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; frame_info.texture_sampler_y_coord_scale = snapshot->texture->GetYCoordScale(); - frame_info.uv_transform = coverage.value().GetNormalizingTransform(); VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.alpha = alpha_ * snapshot->opacity; - frag_info.x_tile_mode = 0; - frag_info.y_tile_mode = 0; FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); FS::BindTextureSampler(pass, snapshot->texture, renderer.GetContext()->GetSamplerLibrary()->GetSampler( diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc index 5e6d14a6d44cd..a352a212c59d5 100644 --- a/impeller/entity/geometry/vertices_geometry.cc +++ b/impeller/entity/geometry/vertices_geometry.cc @@ -187,6 +187,63 @@ GeometryResult VerticesGeometry::GetPositionColorBuffer( }; } +GeometryResult VerticesGeometry::GetPositionUVBuffer( + Rect texture_coverage, + Matrix effect_transform, + const ContentContext& renderer, + const Entity& entity, + RenderPass& pass) const { + using VS = TexturePipeline::VertexShader; + + auto index_count = indices_.size(); + auto vertex_count = vertices_.size(); + auto uv_transform = + texture_coverage.GetNormalizingTransform() * effect_transform; + auto has_texture_coordinates = HasTextureCoordinates(); + + size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData); + size_t total_idx_bytes = index_count * sizeof(uint16_t); + auto vertex_buffer = renderer.GetTransientsBuffer().Emplace( + total_vtx_bytes, alignof(VS::PerVertexData), [&](uint8_t* data) { + VS::PerVertexData* vtx_contents = + reinterpret_cast(data); + for (auto i = 0u; i < vertices_.size(); i++) { + auto vertex = vertices_[i]; + auto texture_coord = + has_texture_coordinates ? texture_coordinates_[i] : vertices_[i]; + auto uv = uv_transform * texture_coord; + // From experimentation we need to clamp these values to < 1.0 or else + // there can be flickering. + VS::PerVertexData vertex_data = { + .position = vertex, + .texture_coords = + Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough), + std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)), + }; + std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData)); + } + }); + + BufferView index_buffer = {}; + if (index_count > 0) { + index_buffer = renderer.GetTransientsBuffer().Emplace( + indices_.data(), total_idx_bytes, alignof(uint16_t)); + } + + return GeometryResult{ + .type = GetPrimitiveType(), + .vertex_buffer = + { + .vertex_buffer = vertex_buffer, + .index_buffer = index_buffer, + .vertex_count = index_count > 0 ? index_count : vertex_count, + .index_type = + index_count > 0 ? IndexType::k16bit : IndexType::kNone, + }, + .transform = entity.GetShaderTransform(pass), + }; +} + GeometryResult VerticesGeometry::GetPositionUVColorBuffer( Rect texture_coverage, Matrix effect_transform, diff --git a/impeller/entity/geometry/vertices_geometry.h b/impeller/entity/geometry/vertices_geometry.h index b3a11223455e2..397a0ebf89c1e 100644 --- a/impeller/entity/geometry/vertices_geometry.h +++ b/impeller/entity/geometry/vertices_geometry.h @@ -37,6 +37,12 @@ class VerticesGeometry final : public Geometry { const Entity& entity, RenderPass& pass) const; + GeometryResult GetPositionUVBuffer(Rect texture_coverage, + Matrix effect_transform, + const ContentContext& renderer, + const Entity& entity, + RenderPass& pass) const; + // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, From c5f80f086d1440be0ba28c7d9cb6c7a3b828fe6e Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 22 Apr 2024 16:06:13 -0700 Subject: [PATCH 12/19] ++ --- impeller/aiks/canvas.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index efab9b302d6c4..3e1feb14ff01e 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -901,14 +901,12 @@ static bool UseColorSourceContents( const std::shared_ptr& vertices, const Paint& paint) { // If there are no vertex color or texture coordinates. Or if there - // are vertex coordinates then only if the contents are an image or - // a solid color. + // are vertex coordinates but its just a color. if (vertices->HasVertexColors()) { return false; } if (vertices->HasTextureCoordinates() && - (paint.color_source.GetType() == ColorSource::Type::kImage || - paint.color_source.GetType() == ColorSource::Type::kColor)) { + (paint.color_source.GetType() == ColorSource::Type::kColor)) { return true; } return !vertices->HasTextureCoordinates(); @@ -928,8 +926,7 @@ void Canvas::DrawVertices(const std::shared_ptr& vertices, entity.SetTransform(GetCurrentTransform()); entity.SetBlendMode(paint.blend_mode); - // If there are no vertex color or texture coordinates. Or if there - // are vertex coordinates then only if the contents are an image. + // If there are no vertex color or texture coordinates. if (UseColorSourceContents(vertices, paint)) { entity.SetContents(CreateContentsForGeometryWithFilters(paint, vertices)); AddRenderEntityToCurrentPass(std::move(entity)); From 0540cbd91d4e343ae27c71869c4d286bce9be6ce Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 22 Apr 2024 18:07:43 -0700 Subject: [PATCH 13/19] ++ --- impeller/aiks/canvas.cc | 8 ++++---- impeller/entity/contents/vertices_contents.cc | 6 ++++-- impeller/entity/geometry/vertices_geometry.cc | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index 3e1feb14ff01e..2906f2ff728c0 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -926,16 +926,16 @@ void Canvas::DrawVertices(const std::shared_ptr& vertices, entity.SetTransform(GetCurrentTransform()); entity.SetBlendMode(paint.blend_mode); - // If there are no vertex color or texture coordinates. + // If there are no vertex colors. if (UseColorSourceContents(vertices, paint)) { entity.SetContents(CreateContentsForGeometryWithFilters(paint, vertices)); AddRenderEntityToCurrentPass(std::move(entity)); return; } - // If there is are per-vertex colors, an image, and the blend mode - // is simple we can draw without a sub-renderpass. - if (blend_mode <= BlendMode::kModulate && vertices->HasVertexColors()) { + // If there is an image, and the blend mode is simple we can draw without a + // sub-renderpass. per-vertex colors aren't required but are supported. + if (blend_mode <= BlendMode::kModulate) { if (std::optional maybe_image_data = GetImageColorSourceData(paint.color_source)) { const ImageData& image_data = maybe_image_data.value(); diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 15297613ddc57..450f5ee753f83 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -275,7 +275,6 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { FML_DCHECK(texture_); - FML_DCHECK(geometry_->HasVertexColors()); // Simple Porter-Duff blends can be accomplished without a sub renderpass. using VS = PorterDuffBlendPipeline::VertexShader; @@ -319,8 +318,11 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer, frag_info.output_alpha = alpha_; frag_info.input_alpha = 1.0; - auto inverted_blend_mode = + BlendMode inverted_blend_mode = InvertPorterDuffBlend(blend_mode_).value_or(BlendMode::kSource); + if (geometry_->HasVertexColors()) { + inverted_blend_mode = BlendMode::kSource; + } auto blend_coefficients = kPorterDuffCoefficients[static_cast(inverted_blend_mode)]; frag_info.src_coeff = blend_coefficients[0]; diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc index a352a212c59d5..c7461ac1d2c9b 100644 --- a/impeller/entity/geometry/vertices_geometry.cc +++ b/impeller/entity/geometry/vertices_geometry.cc @@ -9,6 +9,7 @@ #include "impeller/core/buffer_view.h" #include "impeller/entity/contents/content_context.h" +#include "impeller/geometry/color.h" namespace impeller { @@ -256,6 +257,7 @@ GeometryResult VerticesGeometry::GetPositionUVColorBuffer( auto uv_transform = texture_coverage.GetNormalizingTransform() * effect_transform; auto has_texture_coordinates = HasTextureCoordinates(); + auto has_colors = HasVertexColors(); size_t total_vtx_bytes = vertices_.size() * sizeof(VS::PerVertexData); auto vertex_buffer = renderer.GetTransientsBuffer().Emplace( @@ -274,8 +276,7 @@ GeometryResult VerticesGeometry::GetPositionUVColorBuffer( .texture_coords = Point(std::clamp(uv.x, 0.0f, 1.0f - kEhCloseEnough), std::clamp(uv.y, 0.0f, 1.0f - kEhCloseEnough)), - .color = colors_[i], - }; + .color = has_colors ? colors_[i] : Color::BlackTransparent()}; std::memcpy(vtx_contents++, &vertex_data, sizeof(VS::PerVertexData)); } }); From 5cad475f7c1ae0e1caaef4f61f282f672dfbefd8 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 22 Apr 2024 19:52:23 -0700 Subject: [PATCH 14/19] ++ --- impeller/entity/contents/vertices_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 450f5ee753f83..59441d4e43d1b 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -320,7 +320,7 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer, BlendMode inverted_blend_mode = InvertPorterDuffBlend(blend_mode_).value_or(BlendMode::kSource); - if (geometry_->HasVertexColors()) { + if (!geometry_->HasVertexColors()) { inverted_blend_mode = BlendMode::kSource; } auto blend_coefficients = From 17591cf9a55188e4943dfb59155877f3c9c9ed7a Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 22 Apr 2024 19:56:41 -0700 Subject: [PATCH 15/19] ++ --- impeller/entity/contents/vertices_contents.cc | 4 ++++ .../entity/shaders/blending/porter_duff_blend.frag | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 59441d4e43d1b..42605208c64b6 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -331,6 +331,10 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer, frag_info.dst_coeff_src_alpha = blend_coefficients[3]; frag_info.dst_coeff_src_color = blend_coefficients[4]; + // These values are ignored if the platform supports native decal mode. + frag_info.tmx = static_cast(tile_mode_x_); + frag_info.tmy = static_cast(tile_mode_y_); + auto& host_buffer = renderer.GetTransientsBuffer(); FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info)); diff --git a/impeller/entity/shaders/blending/porter_duff_blend.frag b/impeller/entity/shaders/blending/porter_duff_blend.frag index 2b6631f9d57f7..ee8d4402c31c4 100644 --- a/impeller/entity/shaders/blending/porter_duff_blend.frag +++ b/impeller/entity/shaders/blending/porter_duff_blend.frag @@ -21,6 +21,8 @@ uniform FragInfo { float16_t dst_coeff_src_color; float16_t input_alpha; float16_t output_alpha; + float tmx; + float tmy; } frag_info; @@ -29,16 +31,20 @@ in f16vec4 v_color; out f16vec4 frag_color; -f16vec4 Sample(f16sampler2D texture_sampler, vec2 texture_coords) { +f16vec4 Sample(f16sampler2D texture_sampler, + vec2 texture_coords, + float tmx, + float tmy) { if (supports_decal > 0.0) { return texture(texture_sampler, texture_coords); } - return IPHalfSampleDecal(texture_sampler, texture_coords); + return IPHalfSampleWithTileMode(texture_sampler, texture_coords, tmx, tmy); } void main() { - f16vec4 dst = - texture(texture_sampler_dst, v_texture_coords) * frag_info.input_alpha; + f16vec4 dst = texture(texture_sampler_dst, v_texture_coords, frag_info.tmx, + frag_info.tmy) * + frag_info.input_alpha; f16vec4 src = v_color; frag_color = src * (frag_info.src_coeff + dst.a * frag_info.src_coeff_dst_alpha) + From fa9863ebcbb48d2c724f1169258fd8e719ddf2cf Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 22 Apr 2024 20:45:38 -0700 Subject: [PATCH 16/19] Update porter_duff_blend.frag --- impeller/entity/shaders/blending/porter_duff_blend.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/entity/shaders/blending/porter_duff_blend.frag b/impeller/entity/shaders/blending/porter_duff_blend.frag index ee8d4402c31c4..d5efb124d2d47 100644 --- a/impeller/entity/shaders/blending/porter_duff_blend.frag +++ b/impeller/entity/shaders/blending/porter_duff_blend.frag @@ -42,7 +42,7 @@ f16vec4 Sample(f16sampler2D texture_sampler, } void main() { - f16vec4 dst = texture(texture_sampler_dst, v_texture_coords, frag_info.tmx, + f16vec4 dst = Sample(texture_sampler_dst, v_texture_coords, frag_info.tmx, frag_info.tmy) * frag_info.input_alpha; f16vec4 src = v_color; From 40dce2813b58afb914535dc5b27440aa01eca697 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 23 Apr 2024 12:18:27 -0700 Subject: [PATCH 17/19] make it blend. --- impeller/entity/contents/content_context.cc | 2 +- impeller/entity/contents/vertices_contents.cc | 3 ++- .../entity/shaders/blending/vertices_uber.frag | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index a7dc36a35c9b8..3e263f349a76b 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -443,7 +443,7 @@ ContentContext::ContentContext( yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, {supports_decal}); - vertices_uber_shader_.CreateDefault(*context_, options); + vertices_uber_shader_.CreateDefault(*context_, options, {supports_decal}); // GLES only shader that is unsupported on macOS. #if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX) if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) { diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index fe97e3e3436fc..91872b53c83b2 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -333,7 +333,8 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer, frag_info.dst_coeff = blend_coefficients[2]; frag_info.dst_coeff_src_alpha = blend_coefficients[3]; frag_info.dst_coeff_src_color = blend_coefficients[4]; - // Only used on devices that do not natively support advanced blends. + + // These values are ignored if the platform supports native decal mode. frag_info.tmx = static_cast(tile_mode_x_); frag_info.tmy = static_cast(tile_mode_y_); diff --git a/impeller/entity/shaders/blending/vertices_uber.frag b/impeller/entity/shaders/blending/vertices_uber.frag index 472c3da377aa3..cc6147ad6851f 100644 --- a/impeller/entity/shaders/blending/vertices_uber.frag +++ b/impeller/entity/shaders/blending/vertices_uber.frag @@ -6,9 +6,13 @@ #include #include "blend_select.glsl" +layout(constant_id = 0) const float supports_decal = 1.0; + uniform FragInfo { float16_t alpha; float16_t blend_mode; + float tmx; + float tmy; } frag_info; @@ -19,13 +23,24 @@ in mediump f16vec4 v_color; out f16vec4 frag_color; +f16vec4 Sample(f16sampler2D texture_sampler, + vec2 texture_coords, + float tmx, + float tmy) { + if (supports_decal > 0.0) { + return texture(texture_sampler, texture_coords); + } + return IPHalfSampleWithTileMode(texture_sampler, texture_coords, tmx, tmy); +} + // A shader that implements the required src/dst blending for drawVertices and // drawAtlas advanced blends without requiring an offscreen render pass. This is // done in a single shader to reduce the permutations of PSO needed at runtime // for rarely used features. void main() { f16vec4 dst = IPHalfUnpremultiply(v_color); - f16vec4 src = IPHalfUnpremultiply(texture(texture_sampler, v_texture_coords)); + f16vec4 src = IPHalfUnpremultiply( + Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy)); f16vec3 blend_result = AdvancedBlend(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0)); frag_color = IPApplyBlendedColor(dst, src, blend_result); From 8ec65af626047bf6ca066012413d47acf459ddbf Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 23 Apr 2024 13:04:09 -0700 Subject: [PATCH 18/19] ++ --- impeller/entity/shaders/blending/vertices_uber.frag | 1 + 1 file changed, 1 insertion(+) diff --git a/impeller/entity/shaders/blending/vertices_uber.frag b/impeller/entity/shaders/blending/vertices_uber.frag index cc6147ad6851f..fd66cae06b3b4 100644 --- a/impeller/entity/shaders/blending/vertices_uber.frag +++ b/impeller/entity/shaders/blending/vertices_uber.frag @@ -3,6 +3,7 @@ // found in the LICENSE file. #include +#include #include #include "blend_select.glsl" From cac2d5a3985744d8382f753f066b6341305eabd4 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Tue, 23 Apr 2024 13:51:20 -0700 Subject: [PATCH 19/19] ++ --- impeller/tools/malioc.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/impeller/tools/malioc.json b/impeller/tools/malioc.json index 82ce219ce35cd..ac45ec39759f1 100644 --- a/impeller/tools/malioc.json +++ b/impeller/tools/malioc.json @@ -6247,7 +6247,7 @@ "longest_path_cycles": [ 1.2625000476837158, 1.2625000476837158, - 0.699999988079071, + 0.675000011920929, 0.3125, 0.0, 0.5, @@ -6266,10 +6266,10 @@ "varying" ], "shortest_path_cycles": [ - 0.390625, + 0.421875, + 0.421875, 0.375, - 0.390625, - 0.0, + 0.0625, 0.0, 0.5, 0.25 @@ -6281,7 +6281,7 @@ "total_cycles": [ 3.862499952316284, 3.862499952316284, - 2.825000047683716, + 2.799999952316284, 0.9375, 0.0, 0.5,