11 #include "impeller/renderer/path_polyline.comp.h"
13 #include "impeller/renderer/stroke.comp.h"
22 const std::shared_ptr<Context>& context,
23 const std::string& label,
27 desc.
size =
sizeof(T);
28 auto buffer = context->GetResourceAllocator()->CreateBuffer(desc);
29 buffer->SetLabel(label);
39 stroke_width_ = value;
56 cubic_accuracy_ = value;
60 quad_tolerance_ = value;
67 const std::shared_ptr<Context>& context,
72 using PS = PathPolylineComputeShader;
73 using SS = StrokeComputeShader;
84 PS::Cubics<kMaxCubicCount> cubics{.count = 0};
85 PS::Quads<kMaxQuadCount> quads{.count = 0};
86 PS::Lines<kMaxLineCount> lines{.count = 0};
87 PS::Components<kMaxComponentCount> components{.count = 0};
88 PS::Config config{.cubic_accuracy = cubic_accuracy_,
89 .quad_tolerance = quad_tolerance_};
93 ::memcpy(&lines.data[lines.count], &linear,
95 components.data[components.count++] = {lines.count++, 2};
98 ::memcpy(&quads.data[quads.count], &quad,
100 components.data[components.count++] = {quads.count++, 3};
103 ::memcpy(&cubics.data[cubics.count], &cubic,
105 components.data[components.count++] = {cubics.count++, 4};
109 auto polyline_buffer =
110 CreateDeviceBuffer<PS::Polyline<2048>>(context,
"Polyline");
112 auto cmd_buffer = context->CreateCommandBuffer();
113 auto pass = cmd_buffer->CreateComputePass();
114 FML_DCHECK(pass && pass->IsValid());
119 PathPolylinePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
120 FML_DCHECK(pipeline_desc.has_value());
121 auto compute_pipeline =
122 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
123 FML_DCHECK(compute_pipeline);
125 pass->SetPipeline(compute_pipeline);
126 pass->SetCommandLabel(
"Generate Polyline");
135 if (!pass->Compute(
ISize(line_count, 1)).ok()) {
143 StrokePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
144 FML_DCHECK(pipeline_desc.has_value());
145 auto compute_pipeline =
146 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
147 FML_DCHECK(compute_pipeline);
149 pass->AddBufferMemoryBarrier();
150 pass->SetPipeline(compute_pipeline);
151 pass->SetCommandLabel(
"Compute Stroke");
154 .width = stroke_width_,
155 .cap =
static_cast<uint32_t
>(stroke_cap_),
156 .join =
static_cast<uint32_t
>(stroke_join_),
157 .miter_limit = miter_limit_,
162 SS::BindVertexBufferCount(*pass, std::move(vertex_buffer_count));
163 SS::BindVertexBuffer(*pass, std::move(vertex_buffer));
165 if (!pass->Compute(
ISize(line_count, 1)).ok()) {
170 if (!pass->EncodeCommands()) {
174 if (!context->GetCommandQueue()->Submit({cmd_buffer}, callback).ok()) {