During the last couple of weeks I got some free time and as a fun programming exercise I decided to write a CPU-based, multithreaded vector graphics r

Parallel vector graphics rasterization on CPU.

submited by
Style Pass
2023-05-25 11:00:05

During the last couple of weeks I got some free time and as a fun programming exercise I decided to write a CPU-based, multithreaded vector graphics rasterizer. The goal was to outperform rasterizers of all publicly available vector graphics libraries. And today I’m sharing what I came up with.

I called the project Blaze, its source is available here. There is a web-based demo here. The demo runs on WebAssembly and uses WebGL2 to display the final image. GPU is not involved in generating pixels in any way. Be sure to use a decent web browser for best performance.

Traditional scanline rasterizers follow path outline, update some sort of edge list for each scanline, then convert this edge list to arrays of spans for final composition on the destination surface. While there are methods to optimize this process quite well, it suffers from being bound to a single CPU core. The biggest contributor to the problem is the fact that any segment in the path can affect how it covers any particular pixel. You cannot examine a few segments of an entire path and decide if pixel X is covered or not, like it is with triangle meshes, for example. For this reason it is a challenge to find a way to distribute workload equally across multiple threads.

Input for the rasterizer is a list of classic Bézier paths. Each path is encoded as an array of path commands indicating the types of segments and an array of points describing these segments. Only color fill and source over blending mode is supported at this time which is enough to demonstrate the concept.

Leave a Comment