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_};
91 path.EnumerateComponents(
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();
119 PathPolylinePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
121 auto compute_pipeline =
122 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
125 pass->SetPipeline(compute_pipeline);
126 pass->SetCommandLabel(
"Generate Polyline");
135 if (!pass->Compute(
ISize(line_count, 1)).
ok()) {
143 StrokePipelineBuilder::MakeDefaultPipelineDescriptor(*context);
145 auto compute_pipeline =
146 context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
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()) {
Status Tessellate(const Path &path, HostBuffer &host_buffer, 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,...
static const uint8_t buffer[]