10 #include "impeller/renderer/path_polyline.comp.h"
12 #include "impeller/renderer/stroke.comp.h"
21 const std::shared_ptr<Context>& context,
22 const std::string& label,
26 desc.
size =
sizeof(T);
27 auto buffer = context->GetResourceAllocator()->CreateBuffer(desc);
28 buffer->SetLabel(label);
38 stroke_width_ = value;
55 cubic_accuracy_ = value;
59 quad_tolerance_ = value;
65 const std::shared_ptr<Context>& context,
70 using PS = PathPolylineComputeShader;
71 using SS = StrokeComputeShader;
82 PS::Cubics<kMaxCubicCount> cubics{.count = 0};
83 PS::Quads<kMaxQuadCount> quads{.count = 0};
84 PS::Lines<kMaxLineCount> lines{.count = 0};
85 PS::Components<kMaxComponentCount> components{.count = 0};
86 PS::Config config{.cubic_accuracy = cubic_accuracy_,
87 .quad_tolerance = quad_tolerance_};
91 ::memcpy(&lines.data[lines.count], &linear,
93 components.data[components.count++] = {lines.count++, 2};
96 ::memcpy(&quads.data[quads.count], &quad,
98 components.data[components.count++] = {quads.count++, 3};
101 ::memcpy(&cubics.data[cubics.count], &cubic,
103 components.data[components.count++] = {cubics.count++, 4};
107 auto polyline_buffer =
108 CreateDeviceBuffer<PS::Polyline<2048>>(context,
"Polyline");
110 auto cmd_buffer = context->CreateCommandBuffer();
111 auto pass = cmd_buffer->CreateComputePass();
112 FML_DCHECK(pass && pass->IsValid());
117 PathPolylinePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
118 FML_DCHECK(pipeline_desc.has_value());
119 auto compute_pipeline =
120 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
121 FML_DCHECK(compute_pipeline);
123 pass->SetGridSize(
ISize(line_count, 1));
124 pass->SetThreadGroupSize(
ISize(line_count, 1));
130 PS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
132 pass->GetTransientsBuffer().EmplaceStorageBuffer(cubics));
133 PS::BindQuads(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(quads));
134 PS::BindLines(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(lines));
136 cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(components));
137 PS::BindPolyline(cmd, polyline_buffer->AsBufferView());
139 if (!pass->AddCommand(std::move(cmd))) {
147 StrokePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
148 FML_DCHECK(pipeline_desc.has_value());
149 auto compute_pipeline =
150 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
151 FML_DCHECK(compute_pipeline);
153 pass->SetGridSize(
ISize(line_count, 1));
154 pass->SetThreadGroupSize(
ISize(line_count, 1));
161 .width = stroke_width_,
162 .cap =
static_cast<uint32_t
>(stroke_cap_),
163 .join =
static_cast<uint32_t
>(stroke_join_),
164 .miter_limit = miter_limit_,
166 SS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
168 SS::BindPolyline(cmd, polyline_buffer->AsBufferView());
169 SS::BindVertexBufferCount(cmd, std::move(vertex_buffer_count));
170 SS::BindVertexBuffer(cmd, std::move(vertex_buffer));
172 if (!pass->AddCommand(std::move(cmd))) {
177 if (!pass->EncodeCommands()) {
181 if (!cmd_buffer->SubmitCommands(callback)) {