| Flutter Impeller |

Public Types | Public Member Functions | Static Public Attributes | List of all members
impeller::ComputeTessellator Class Reference

A utility that generates triangles of the specified fill type given a path. More...

`#include <compute_tessellator.h>`

## Public Types
enum | Status { Status::kCommandInvalid, Status::kTooManyComponents, Status::kOk }
enum | Style { Style::kStroke }

## Public Member Functions
| ComputeTessellator ()
| ~ComputeTessellator ()
ComputeTessellator & | SetStyle (Style value)
ComputeTessellator & | SetStrokeWidth (Scalar value)
ComputeTessellator & | SetStrokeJoin (Join value)
ComputeTessellator & | SetStrokeCap (Cap value)
ComputeTessellator & | SetMiterLimit (Scalar value)
ComputeTessellator & | SetCubicAccuracy (Scalar value)
ComputeTessellator & | SetQuadraticTolerance (Scalar value)
Status | Tessellate (const Path &path, const std::shared_ptr< Context > &context, BufferView vertex_buffer, BufferView vertex_buffer_count, const CommandBuffer::CompletionCallback &callback=nullptr) const
| Generates triangles from the path. If the data needs to be synchronized back to the CPU, e.g. because one of the buffer views are host visible and will be used without creating a blit pass to copy them back, the callback is used to determine when the GPU calculation is complete and its status. On Metal, no additional synchronization is needed as long as the buffers are not heap allocated, so no additional synchronization mechanism is provided. More...

## Static Public Attributes
static constexpr size_t | kMaxCubicCount = 512
static constexpr size_t | kMaxQuadCount = 2048
static constexpr size_t | kMaxLineCount = 4096
static constexpr size_t | kMaxComponentCount

## Detailed Description

A utility that generates triangles of the specified fill type given a path.

Definition at line 19 of file compute_tessellator.h.

## Member Enumeration Documentation

## ◆ Status

enum impeller::ComputeTessellator::Status
| strong

Enumerator
kCommandInvalid |
kTooManyComponents |
kOk |

Definition at line 31 of file compute_tessellator.h.

31 {
32 kCommandInvalid,
33 kTooManyComponents,
34 kOk,
35 };

## ◆ Style

enum impeller::ComputeTessellator::Style
| strong

Enumerator
kStroke |

Definition at line 37 of file compute_tessellator.h.

37 {
38 kStroke,
39 // TODO(dnfield): Implement kFill.
40 };

## Constructor & Destructor Documentation

## ◆ ComputeTessellator()

impeller::ComputeTessellator::ComputeTessellator | ( |  | ) |
| default

## ◆ ~ComputeTessellator()

impeller::ComputeTessellator::~ComputeTessellator | ( |  | ) |
| default

## Member Function Documentation

## ◆ SetCubicAccuracy()

ComputeTessellator & impeller::ComputeTessellator::SetCubicAccuracy | ( | Scalar | value | ) |

Definition at line 52 of file compute_tessellator.cc.

52 {
53 cubic_accuracy_ = value;
54 return *this;
55 }

## ◆ SetMiterLimit()

ComputeTessellator & impeller::ComputeTessellator::SetMiterLimit | ( | Scalar | value | ) |

Definition at line 48 of file compute_tessellator.cc.

48 {
49 miter_limit_ = value;
50 return *this;
51 }

## ◆ SetQuadraticTolerance()

ComputeTessellator & impeller::ComputeTessellator::SetQuadraticTolerance | ( | Scalar | value | ) |

Definition at line 56 of file compute_tessellator.cc.

56 {
57 quad_tolerance_ = value;
58 return *this;
59 }

## ◆ SetStrokeCap()

ComputeTessellator & impeller::ComputeTessellator::SetStrokeCap | ( | Cap | value | ) |

Definition at line 44 of file compute_tessellator.cc.

44 {
45 stroke_cap_ = value;
46 return *this;
47 }

## ◆ SetStrokeJoin()

ComputeTessellator & impeller::ComputeTessellator::SetStrokeJoin | ( | Join | value | ) |

Definition at line 40 of file compute_tessellator.cc.

40 {
41 stroke_join_ = value;
42 return *this;
43 }

## ◆ SetStrokeWidth()

ComputeTessellator & impeller::ComputeTessellator::SetStrokeWidth | ( | Scalar | value | ) |

Definition at line 35 of file compute_tessellator.cc.

35 {
36 stroke_width_ = value;
37 return *this;
38 }

Referenced by impeller::testing::TEST_P().

## ◆ SetStyle()

ComputeTessellator & impeller::ComputeTessellator::SetStyle | ( | Style | value | ) |

Definition at line 30 of file compute_tessellator.cc.

30 {
31 style_ = value;
32 return *this;
33 }

## ◆ Tessellate()

ComputeTessellator::Status impeller::ComputeTessellator::Tessellate | ( | const Path & | path,
|  | const std::shared_ptr< Context > & | context,
|  | BufferView | vertex_buffer,
|  | BufferView | vertex_buffer_count,
|  | const CommandBuffer::CompletionCallback & | callback = `nullptr`
| ) |  | const

Generates triangles from the path. If the data needs to be synchronized back to the CPU, e.g. because one of the buffer views are host visible and will be used without creating a blit pass to copy them back, the callback is used to determine when the GPU calculation is complete and its status. On Metal, no additional synchronization is needed as long as the buffers are not heap allocated, so no additional synchronization mechanism is provided.

Returns
  A |Status| value indicating success or failure of the submission.

Definition at line 61 of file compute_tessellator.cc.

66 {
67 FML_DCHECK(style_ == Style::kStroke);
68 using PS = PathPolylineComputeShader;
69 using SS = StrokeComputeShader;
70
71 auto cubic_count = path.GetComponentCount(Path::ComponentType::kCubic);
72 auto quad_count = path.GetComponentCount(Path::ComponentType::kQuadratic) +
73 (cubic_count * 6);
74 auto line_count =
75 path.GetComponentCount(Path::ComponentType::kLinear) + (quad_count * 6);
76 if (cubic_count > kMaxCubicCount || quad_count > kMaxQuadCount ||
77 line_count > kMaxLineCount) {
78 return Status::kTooManyComponents;
79 }
80 PS::Cubics<kMaxCubicCount> cubics{.count = 0};
81 PS::Quads<kMaxQuadCount> quads{.count = 0};
82 PS::Lines<kMaxLineCount> lines{.count = 0};
83 PS::Components<kMaxComponentCount> components{.count = 0};
84 PS::Config config{.cubic_accuracy = cubic_accuracy_,
85 .quad_tolerance = quad_tolerance_};
86
87 path.EnumerateComponents(
88 [&lines, &components](size_t index, const LinearPathComponent& linear) {
89 ::memcpy(&lines.data[lines.count], &linear,
90 sizeof(LinearPathComponent));
91 components.data[components.count++] = {lines.count++, 2};
92 },
93 [&quads, &components](size_t index, const QuadraticPathComponent& quad) {
94 ::memcpy(&quads.data[quads.count], &quad,
95 sizeof(QuadraticPathComponent));
96 components.data[components.count++] = {quads.count++, 3};
97 },
98 [&cubics, &components](size_t index, const CubicPathComponent& cubic) {
99 ::memcpy(&cubics.data[cubics.count], &cubic,
100 sizeof(CubicPathComponent));
101 components.data[components.count++] = {cubics.count++, 4};
102 },
103 [](size_t index, const ContourComponent& contour) {});
104
105 auto polyline_buffer =
106 CreateDeviceBuffer<PS::Polyline<2048>>(context, "Polyline");
107
108 auto cmd_buffer = context->CreateCommandBuffer();
109 auto pass = cmd_buffer->CreateComputePass();
110 FML_DCHECK(pass && pass->IsValid());
111
112 {
113 using PathPolylinePipelineBuilder = ComputePipelineBuilder<PS>;
114 auto pipeline_desc =
115 PathPolylinePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
116 FML_DCHECK(pipeline_desc.has_value());
117 auto compute_pipeline =
118 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
119 FML_DCHECK(compute_pipeline);
120
121 pass->SetGridSize(ISize(line_count, 1));
122 pass->SetThreadGroupSize(ISize(line_count, 1));
123
124 ComputeCommand cmd;
125 DEBUG_COMMAND_INFO(cmd, "Generate Polyline");
126 cmd.pipeline = compute_pipeline;
127
128 PS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
129 PS::BindCubics(cmd,
130 pass->GetTransientsBuffer().EmplaceStorageBuffer(cubics));
131 PS::BindQuads(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(quads));
132 PS::BindLines(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(lines));
133 PS::BindComponents(
134 cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(components));
135 PS::BindPolyline(cmd, polyline_buffer->AsBufferView());
136
137 if (!pass->AddCommand(std::move(cmd))) {
138 return Status::kCommandInvalid;
139 }
140 }
141
142 {
143 using StrokePipelineBuilder = ComputePipelineBuilder<SS>;
144 auto pipeline_desc =
145 StrokePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
146 FML_DCHECK(pipeline_desc.has_value());
147 auto compute_pipeline =
148 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
149 FML_DCHECK(compute_pipeline);
150
151 pass->SetGridSize(ISize(line_count, 1));
152 pass->SetThreadGroupSize(ISize(line_count, 1));
153
154 ComputeCommand cmd;
155 DEBUG_COMMAND_INFO(cmd, "Compute Stroke");
156 cmd.pipeline = compute_pipeline;
157
158 SS::Config config{
159 .width = stroke_width_,
160 .cap = static_cast<uint32_t>(stroke_cap_),
161 .join = static_cast<uint32_t>(stroke_join_),
162 .miter_limit = miter_limit_,
163 };
164 SS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
165
166 SS::BindPolyline(cmd, polyline_buffer->AsBufferView());
167 SS::BindVertexBufferCount(cmd, std::move(vertex_buffer_count));
168 SS::BindVertexBuffer(cmd, std::move(vertex_buffer));
169
170 if (!pass->AddCommand(std::move(cmd))) {
171 return Status::kCommandInvalid;
172 }
173 }
174
175 if (!pass->EncodeCommands()) {
176 return Status::kCommandInvalid;
177 }
178
179 if (!cmd_buffer->SubmitCommands(callback)) {
180 return Status::kCommandInvalid;
181 }
182
183 return Status::kOk;
184 }

References DEBUG_COMMAND_INFO, impeller::Path::EnumerateComponents(), impeller::Path::GetComponentCount(), kCommandInvalid, impeller::Path::kCubic, impeller::Path::kLinear, kMaxCubicCount, kMaxLineCount, kMaxQuadCount, kOk, impeller::Path::kQuadratic, kStroke, kTooManyComponents, and impeller::ComputeCommand::pipeline.

Referenced by impeller::testing::TEST_P().

## Member Data Documentation

## ◆ kMaxComponentCount

constexpr size_t impeller::ComputeTessellator::kMaxComponentCount
| static constexpr

Initial value:
=
kMaxCubicCount + kMaxQuadCount + kMaxLineCount

Definition at line 28 of file compute_tessellator.h.

## ◆ kMaxCubicCount

constexpr size_t impeller::ComputeTessellator::kMaxCubicCount = 512
| static constexpr

Definition at line 25 of file compute_tessellator.h.

Referenced by Tessellate().

## ◆ kMaxLineCount

constexpr size_t impeller::ComputeTessellator::kMaxLineCount = 4096
| static constexpr

Definition at line 27 of file compute_tessellator.h.

Referenced by Tessellate().

## ◆ kMaxQuadCount

constexpr size_t impeller::ComputeTessellator::kMaxQuadCount = 2048
| static constexpr

Definition at line 26 of file compute_tessellator.h.

Referenced by Tessellate().

The documentation for this class was generated from the following files:

- impeller/renderer/compute_tessellator.h
- impeller/renderer/compute_tessellator.cc

impeller::ComputeTessellator::Status::kCommandInvalid
@ kCommandInvalid
DEBUG_COMMAND_INFO
#define DEBUG_COMMAND_INFO(obj, arg)
Definition: command.h:31
impeller::ComputeTessellator::Status::kTooManyComponents
@ kTooManyComponents
impeller::Path::ComponentType::kLinear
@ kLinear
impeller::Path::ComponentType::kCubic
@ kCubic
impeller::Path::ComponentType::kQuadratic
@ kQuadratic
impeller::ComputeTessellator::kMaxCubicCount
static constexpr size_t kMaxCubicCount
Definition: compute_tessellator.h:25
impeller::ComputeTessellator::Style::kStroke
@ kStroke
impeller::ComputeTessellator::Status::kOk
@ kOk
impeller::ComputeTessellator::kMaxQuadCount
static constexpr size_t kMaxQuadCount
Definition: compute_tessellator.h:26
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:136
impeller::ComputeTessellator::kMaxLineCount
static constexpr size_t kMaxLineCount
Definition: compute_tessellator.h:27