From 351bb6d01918e639299a74051b4a12d5429f8994 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 3 Nov 2021 13:55:20 -0700 Subject: [PATCH] More doc updates. --- .../src/flutter/impeller/entity/contents.mm | 13 ++++---- .../impeller/entity/entity_renderer_impl.mm | 2 +- engine/src/flutter/impeller/fixtures/BUILD.gn | 2 ++ engine/src/flutter/impeller/geometry/path.cc | 2 +- engine/src/flutter/impeller/geometry/path.h | 2 +- .../src/flutter/impeller/renderer/command.h | 31 +++++++++++++++++++ .../src/flutter/impeller/renderer/pipeline.h | 14 +++++++++ .../impeller/renderer/renderer_unittests.cc | 2 +- .../flutter/impeller/renderer/tessellator.h | 19 ++++++++++-- 9 files changed, 74 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents.mm b/engine/src/flutter/impeller/entity/contents.mm index a7879e1386..41f468aa44 100644 --- a/engine/src/flutter/impeller/entity/contents.mm +++ b/engine/src/flutter/impeller/entity/contents.mm @@ -51,13 +51,12 @@ bool LinearGradientContents::Render(const ContentRenderer& renderer, auto vertices_builder = VertexBufferBuilder(); { - auto result = - Tessellator{}.Tessellate(entity.GetPath().SubdivideAdaptively(), - [&vertices_builder](Point point) { - VS::PerVertexData vtx; - vtx.vertices = point; - vertices_builder.AppendVertex(vtx); - }); + auto result = Tessellator{}.Tessellate(entity.GetPath().CreatePolyline(), + [&vertices_builder](Point point) { + VS::PerVertexData vtx; + vtx.vertices = point; + vertices_builder.AppendVertex(vtx); + }); if (!result) { return false; } diff --git a/engine/src/flutter/impeller/entity/entity_renderer_impl.mm b/engine/src/flutter/impeller/entity/entity_renderer_impl.mm index 2f0c1e831f..9ff3410a89 100644 --- a/engine/src/flutter/impeller/entity/entity_renderer_impl.mm +++ b/engine/src/flutter/impeller/entity/entity_renderer_impl.mm @@ -53,7 +53,7 @@ EntityRendererImpl::RenderResult EntityRendererImpl::RenderEntity( VertexBufferBuilder vtx_builder; { auto tesselation_result = Tessellator{}.Tessellate( - entity.GetPath().SubdivideAdaptively(), [&vtx_builder](auto point) { + entity.GetPath().CreatePolyline(), [&vtx_builder](auto point) { VS::PerVertexData vtx; vtx.vertices = point; vtx_builder.AppendVertex(vtx); diff --git a/engine/src/flutter/impeller/fixtures/BUILD.gn b/engine/src/flutter/impeller/fixtures/BUILD.gn index 3bbffb6091..9f6dba1e4d 100644 --- a/engine/src/flutter/impeller/fixtures/BUILD.gn +++ b/engine/src/flutter/impeller/fixtures/BUILD.gn @@ -12,6 +12,8 @@ impeller_shaders("shader_fixtures") { shaders = [ "box_fade.vert", "box_fade.frag", + "sandbox.vert", + "sandbox.frag", ] } diff --git a/engine/src/flutter/impeller/geometry/path.cc b/engine/src/flutter/impeller/geometry/path.cc index 1d444b5fb6..61a8d4c99d 100644 --- a/engine/src/flutter/impeller/geometry/path.cc +++ b/engine/src/flutter/impeller/geometry/path.cc @@ -149,7 +149,7 @@ static void AddPoints(std::vector& dest, const std::vector& src) { dest.insert(dest.end(), src.begin(), src.end()); } -std::vector Path::SubdivideAdaptively( +std::vector Path::CreatePolyline( const SmoothingApproximation& approximation) const { std::vector points; for (const auto& component : components_) { diff --git a/engine/src/flutter/impeller/geometry/path.h b/engine/src/flutter/impeller/geometry/path.h index 4952ecab16..8ae91753ff 100644 --- a/engine/src/flutter/impeller/geometry/path.h +++ b/engine/src/flutter/impeller/geometry/path.h @@ -53,7 +53,7 @@ class Path { bool UpdateCubicComponentAtIndex(size_t index, CubicPathComponent& cubic); - std::vector SubdivideAdaptively( + std::vector CreatePolyline( const SmoothingApproximation& approximation = {}) const; Rect GetBoundingBox() const; diff --git a/engine/src/flutter/impeller/renderer/command.h b/engine/src/flutter/impeller/renderer/command.h index 0b9ed1ffe6..a54cfc34d8 100644 --- a/engine/src/flutter/impeller/renderer/command.h +++ b/engine/src/flutter/impeller/renderer/command.h @@ -26,10 +26,41 @@ struct Bindings { std::map> samplers; }; +//------------------------------------------------------------------------------ +/// @brief An object used to specify work to the GPU along with references +/// to resources the GPU will used when doing said work. +/// +/// To construct a valid command, follow these steps: +/// * Specify a valid pipeline. +/// * Specify vertex information via a call `BindVertices` +/// * Specify any stage bindings. +/// * (Optional) Specify a debug label. +/// +/// Command are very lightweight objects and can be created +/// frequently and on demand. The resources referenced in commands +/// views into buffers managed by other allocators and resource +/// managers. +/// struct Command { + //---------------------------------------------------------------------------- + /// The pipeline to use for this command. + /// std::shared_ptr pipeline; + //---------------------------------------------------------------------------- + /// The buffer, texture, and sampler bindings used by the vertex pipeline + /// stage. + /// Bindings vertex_bindings; + //---------------------------------------------------------------------------- + /// The buffer, texture, and sampler bindings used by the fragment pipeline + /// stage. + /// Bindings fragment_bindings; + //---------------------------------------------------------------------------- + /// The index buffer binding used by the vertex shader stage. Instead of + /// setting this directly, it usually easier to specify the vertex and index + /// buffer bindings directly via a single call to `BindVertices`. + /// BufferView index_buffer; size_t index_count = 0u; std::string label; diff --git a/engine/src/flutter/impeller/renderer/pipeline.h b/engine/src/flutter/impeller/renderer/pipeline.h index bfb0f649e3..8a5e172366 100644 --- a/engine/src/flutter/impeller/renderer/pipeline.h +++ b/engine/src/flutter/impeller/renderer/pipeline.h @@ -17,6 +17,20 @@ class Pipeline; using PipelineFuture = std::future>; +//------------------------------------------------------------------------------ +/// @brief Describes the fixed function and programmable aspects of +/// rendering and compute operations performed by commands submitted +/// to the GPU via a command buffer. +/// +/// A pipeline handle must be allocated upfront and kept alive for +/// as long as possible. Do not create a pipeline object within a +/// frame workload. +/// +/// This pipeline object is almost never used directly as it is +/// untyped. Use reflected shader information generated by the +/// Impeller offline shader compiler to generate a typed pipeline +/// object. +/// class Pipeline { public: enum class Type { diff --git a/engine/src/flutter/impeller/renderer/renderer_unittests.cc b/engine/src/flutter/impeller/renderer/renderer_unittests.cc index 148b6f43e4..496637f822 100644 --- a/engine/src/flutter/impeller/renderer/renderer_unittests.cc +++ b/engine/src/flutter/impeller/renderer/renderer_unittests.cc @@ -269,7 +269,7 @@ TEST_F(RendererTest, CanRenderPath) { Tessellator tessellator; ASSERT_TRUE(tessellator.Tessellate( - path.SubdivideAdaptively({}), [&vertex_builder](Point point) { + path.CreatePolyline({}), [&vertex_builder](Point point) { VS::PerVertexData vtx; vtx.vertex_position = {point.x, point.y, 0.0}; vtx.texture_coordinates = {0.5, 0.5}; diff --git a/engine/src/flutter/impeller/renderer/tessellator.h b/engine/src/flutter/impeller/renderer/tessellator.h index fcc04dff68..0ca17608b6 100644 --- a/engine/src/flutter/impeller/renderer/tessellator.h +++ b/engine/src/flutter/impeller/renderer/tessellator.h @@ -13,6 +13,12 @@ namespace impeller { +//------------------------------------------------------------------------------ +/// @brief A utility that generates triangles of the specified fill type +/// given a polyline. This happens on the CPU. +/// +/// @bug This should just be called a triangulator. +/// class Tessellator { public: enum class FillType { @@ -34,8 +40,17 @@ class Tessellator { WindingOrder GetFrontFaceWinding() const; using VertexCallback = std::function; - [[nodiscard]] bool Tessellate(const std::vector& vertices, - VertexCallback callback) const; + //---------------------------------------------------------------------------- + /// @brief Generates triangles from the polyline. A callback is invoked + /// for each vertex of the triangle. + /// + /// @param[in] polyline The polyline + /// @param[in] callback The callback + /// + /// @return If tessellation was successful. + /// + bool Tessellate(const std::vector& polyline, + VertexCallback callback) const; private: FillType fill_type_ = FillType::kNonZero;