8 #include "impeller/renderer/path_polyline.comp.h"
10 #include "impeller/renderer/stroke.comp.h"
19 const std::shared_ptr<Context>& context,
20 const std::string& label,
24 desc.
size =
sizeof(T);
25 auto buffer = context->GetResourceAllocator()->CreateBuffer(desc);
26 buffer->SetLabel(label);
36 stroke_width_ = value;
53 cubic_accuracy_ = value;
57 quad_tolerance_ = value;
63 const std::shared_ptr<Context>& context,
68 using PS = PathPolylineComputeShader;
69 using SS = StrokeComputeShader;
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_};
89 ::memcpy(&lines.data[lines.count], &linear,
91 components.data[components.count++] = {lines.count++, 2};
94 ::memcpy(&quads.data[quads.count], &quad,
96 components.data[components.count++] = {quads.count++, 3};
99 ::memcpy(&cubics.data[cubics.count], &cubic,
101 components.data[components.count++] = {cubics.count++, 4};
105 auto polyline_buffer =
106 CreateDeviceBuffer<PS::Polyline<2048>>(context,
"Polyline");
108 auto cmd_buffer = context->CreateCommandBuffer();
109 auto pass = cmd_buffer->CreateComputePass();
110 FML_DCHECK(pass && pass->IsValid());
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);
121 pass->SetGridSize(
ISize(line_count, 1));
122 pass->SetThreadGroupSize(
ISize(line_count, 1));
128 PS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
130 pass->GetTransientsBuffer().EmplaceStorageBuffer(cubics));
131 PS::BindQuads(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(quads));
132 PS::BindLines(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(lines));
134 cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(components));
135 PS::BindPolyline(cmd, polyline_buffer->AsBufferView());
137 if (!pass->AddCommand(std::move(cmd))) {
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);
151 pass->SetGridSize(
ISize(line_count, 1));
152 pass->SetThreadGroupSize(
ISize(line_count, 1));
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_,
164 SS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config));
166 SS::BindPolyline(cmd, polyline_buffer->AsBufferView());
167 SS::BindVertexBufferCount(cmd, std::move(vertex_buffer_count));
168 SS::BindVertexBuffer(cmd, std::move(vertex_buffer));
170 if (!pass->AddCommand(std::move(cmd))) {
175 if (!pass->EncodeCommands()) {
179 if (!cmd_buffer->SubmitCommands(callback)) {