50 using SS = StrokeComputeShader;
52 auto context = GetContext();
54 ASSERT_TRUE(context->GetCapabilities()->SupportsComputeSubgroups());
55 char svg_path_data[16384] =
57 "C73 20 20 74 20 140 "
58 "c0 135 136 170 228 303 "
59 "88-132 229-173 229-303 "
60 "0-66-54-120-120-120 "
62 "-19-41-60-69-108-69z";
63 size_t vertex_count = 0;
66 auto vertex_buffer = CreateHostVisibleDeviceBuffer<SS::VertexBuffer<2048>>(
67 context,
"VertexBuffer");
68 auto vertex_buffer_count =
69 CreateHostVisibleDeviceBuffer<SS::VertexBufferCount>(context,
73 ::memset(vertex_buffer_count->OnGetContents(), 0,
74 sizeof(SS::VertexBufferCount));
75 ::memset(vertex_buffer->OnGetContents(), 0,
sizeof(SS::VertexBuffer<2048>));
76 const auto* main_viewport = ImGui::GetMainViewport();
77 ImGui::SetNextWindowPos(
78 ImVec2(main_viewport->WorkPos.x + 650, main_viewport->WorkPos.y + 20));
79 ImGui::Begin(
"Path data",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
80 ImGui::InputTextMultiline(
"Path", svg_path_data,
81 IM_ARRAYSIZE(svg_path_data));
82 ImGui::DragFloat(
"Stroke width", &
stroke_width, .1, 0.0, 25.0);
86 std::promise<bool> promise;
87 auto future = promise.get_future();
97 [vertex_buffer_count, &vertex_count,
100 reinterpret_cast<SS::VertexBufferCount*
>(
101 vertex_buffer_count->OnGetContents())
108 ImGui::Text(
"Failed to submit compute job (invalid command)");
111 ImGui::Text(
"Failed to submit compute job (too many components) ");
117 ImGui::Text(
"Failed to submit compute job.");
120 if (vertex_count > 0) {
121 ImGui::Text(
"Vertex count: %zu", vertex_count);
124 ImGui::Text(
"Failed to parse path data");
129 if (!renderer.IsValid()) {
135 pass.SetCommandLabel(
"Draw Stroke");
136 pass.SetStencilReference(0);
140 options.color_attachment_pixel_format =
141 pass.GetRenderTarget().GetRenderTargetPixelFormat();
142 options.has_depth_stencil_attachments =
143 pass.GetRenderTarget().GetStencilAttachment().has_value();
150 pass.SetPipeline(renderer.GetSolidFillPipeline(
options));
152 auto count =
reinterpret_cast<SS::VertexBufferCount*
>(
153 vertex_buffer_count->OnGetContents())
156 pass.SetVertexBuffer(
158 .vertex_count =
count,
161 VS::FrameInfo frame_info;
163 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
166 pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
168 return pass.Draw().ok();
170 ASSERT_TRUE(OpenPlaygroundHere(
callback));
176 using SS = StrokeComputeShader;
178 auto context = GetContext();
179 ASSERT_TRUE(context);
180 ASSERT_TRUE(context->GetCapabilities()->SupportsComputeSubgroups());
181 size_t vertex_count = 0;
184 auto vertex_buffer = CreateHostVisibleDeviceBuffer<SS::VertexBuffer<2048>>(
185 context,
"VertexBuffer");
186 auto vertex_buffer_count =
187 CreateHostVisibleDeviceBuffer<SS::VertexBufferCount>(context,
192 .
MoveTo({359.934, 96.6335})
193 .CubicCurveTo({358.189, 96.7055}, {356.436, 96.7908},
195 .CubicCurveTo({354.571, 96.8953}, {354.469, 96.9016},
197 .CubicCurveTo({352.672, 97.0038}, {350.969, 97.113},
199 .CubicCurveTo({349.048, 97.2506}, {348.836, 97.2678},
201 .CubicCurveTo({347.019, 97.4014}, {345.407, 97.5299},
203 .CubicCurveTo({343.428, 97.704}, {343.065, 97.7402},
205 .CubicCurveTo({341.221, 97.9086}, {339.736, 98.0505},
207 .CubicCurveTo({337.702, 98.2642}, {337.156, 98.3292},
209 .CubicCurveTo({335.284, 98.5356}, {333.956, 98.6837},
211 .CubicCurveTo({332.495, 98.8635}, {332.366, 98.8818},
213 .
LineTo({332.237, 102.601})
214 .
LineTo({321.778, 102.601})
215 .
LineTo({321.778, 100.382})
216 .CubicCurveTo({321.572, 100.413}, {321.367, 100.442},
218 .CubicCurveTo({319.22, 100.79}, {317.277, 101.123},
220 .CubicCurveTo({315.322, 101.481}, {315.311, 101.482},
222 .
LineTo({310.017, 105.94})
223 .
LineTo({309.779, 105.427})
224 .
LineTo({314.403, 101.651})
225 .CubicCurveTo({314.391, 101.653}, {314.379, 101.656},
227 .CubicCurveTo({312.528, 102.001}, {310.687, 102.366},
229 .CubicCurveTo({307.85, 102.955}, {306.855, 103.182}, {305.859, 103.4})
230 .CubicCurveTo({305.048, 103.579}, {304.236, 103.75},
232 .
LineTo({299.105, 107.578})
233 .
LineTo({298.867, 107.065})
234 .
LineTo({302.394, 104.185})
235 .
LineTo({302.412, 104.171})
236 .CubicCurveTo({301.388, 104.409}, {300.366, 104.67},
238 .CubicCurveTo({298.618, 105.1}, {297.89, 105.269}, {297.165, 105.455})
239 .CubicCurveTo({295.262, 105.94}, {293.36, 106.445},
241 .CubicCurveTo({291.132, 107.072}, {290.802, 107.163},
243 .CubicCurveTo({289.463, 107.544}, {288.455, 107.839},
245 .CubicCurveTo({286.476, 108.431}, {285.506, 108.73},
247 .CubicCurveTo({283.674, 109.304}, {282.812, 109.579},
249 .CubicCurveTo({281.177, 110.112}, {280.406, 110.377},
251 .CubicCurveTo({278.458, 111.037}, {277.256, 111.449},
253 .CubicCurveTo({276.76, 111.622}, {276.716, 111.637},
255 .CubicCurveTo({275.017, 112.239}, {273.365, 112.836},
257 .
LineTo({271.717, 113.449})
258 .CubicCurveTo({271.496, 113.496}, {271.238, 113.559},
260 .CubicCurveTo({270.893, 113.645}, {270.822, 113.663},
262 .CubicCurveTo({270.468, 113.755}, {270.169, 113.834},
264 .CubicCurveTo({269.789, 113.94}, {269.732, 113.957},
266 .CubicCurveTo({269.391, 114.053}, {269.081, 114.143},
268 .CubicCurveTo({268.628, 114.276}, {268.5, 114.314},
270 .CubicCurveTo({268.172, 114.412}, {267.959, 114.478},
272 .CubicCurveTo({263.349, 115.964}, {258.058, 117.695},
274 .CubicCurveTo({253.556, 119.255}, {253.547, 119.258},
276 .CubicCurveTo({251.844, 119.849}, {250.056, 120.474},
278 .CubicCurveTo({248, 121.197}, {247.812, 121.264}, {247.621, 121.331})
279 .CubicCurveTo({247.079, 121.522}, {246.531, 121.715},
281 .CubicCurveTo({245.554, 122.06}, {245.126, 122.212},
283 .CubicCurveTo({244.071, 122.586}, {243.437, 122.811},
285 .CubicCurveTo({242.189, 123.255}, {241.58, 123.472},
287 .CubicCurveTo({240.659, 123.801}, {240.357, 123.909},
289 .CubicCurveTo({239.12, 124.351}, {238.18, 124.687}, {237.22, 125.032})
290 .
LineTo({237.164, 125.003})
291 .CubicCurveTo({236.709, 125.184}, {236.262, 125.358},
293 .CubicCurveTo({235.413, 125.68}, {234.994, 125.832},
295 .CubicCurveTo({234.592, 125.977}, {234.591, 125.977},
297 .CubicCurveTo({222.206, 130.435}, {207.708, 135.753},
299 .CubicCurveTo({162.77, 151.336}, {122.17, 156.894}, {84.1123, 160})
304 .CubicCurveTo({359.978, 96.6317}, {359.956, 96.6326},
310 ::memset(vertex_buffer_count->OnGetContents(), 0,
311 sizeof(SS::VertexBufferCount));
312 ::memset(vertex_buffer->OnGetContents(), 0,
sizeof(SS::VertexBuffer<2048>));
315 if (!renderer.IsValid()) {
322 complex_path, renderer.GetTransientsBuffer(), context,
326 vertex_count = reinterpret_cast<SS::VertexBufferCount*>(
327 vertex_buffer_count->OnGetContents())
333 pass.SetCommandLabel(
"Draw Stroke");
334 pass.SetStencilReference(0);
338 options.color_attachment_pixel_format =
339 pass.GetRenderTarget().GetRenderTargetPixelFormat();
340 options.has_depth_stencil_attachments =
341 pass.GetRenderTarget().GetStencilAttachment().has_value();
348 pass.SetPipeline(renderer.GetSolidFillPipeline(
options));
350 auto count =
reinterpret_cast<SS::VertexBufferCount*
>(
351 vertex_buffer_count->OnGetContents())
354 pass.SetVertexBuffer(
356 .vertex_count =
count,
359 VS::FrameInfo frame_info;
361 frame_info.mvp = pass.GetOrthographicTransform() * world_matrix;
364 pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info));
366 return pass.Draw().ok();
368 ASSERT_TRUE(OpenPlaygroundHere(
callback));