Crates.io | forma-render |
lib.rs | forma-render |
version | 0.1.3 |
source | src |
created_at | 2022-12-16 14:47:09.729668 |
updated_at | 2022-12-16 15:43:01.811904 |
description | An efficient vector-graphics renderer |
homepage | |
repository | https://github.com/google/forma |
max_upload_size | |
id | 738865 |
size | 574,571 |
A (thouroughly) parallelized experimental Rust vector-graphics renderer with both a software (CPU) and hardware (GPU) back-end having the following goals, in this order:
It relies on Rust's SIMD auto-vectorization/intrinsics and Rayon to have good performance on the CPU, while using WebGPU (wgpu) to take advantage of the GPU.
Add the following to your Cargo.toml
dependencies:
forma = { version = "0.1.0", package = "forma-render" }
1. Curve flattening | 2. Line segment rasterization | 3. Sorting | 4. Painting |
---|---|---|---|
Bézier curves | line segments | pixel segments | sorted pixel segments, old tiles |
⬇️⬇️⬇️ | ⬇️⬇️⬇️ | ⬇️⬇️⬇️ | ⬇️⬇️⬇️ |
line segments | pixel segments | sorted pixel segments | freshly painted tiles |
Here are a few implementation highlights that make forma stand out from commonly used vector renderers.
All higher cubic Béziers are approximated by quadratic ones, then, in parallel, flattened to line segments according to their curvature. This technique was developed by Raph Levien.
Translations and rotations can be rendered without having to re-flatten the curves, all the while maintaining full quality.
Line segments are transformed into pixel segments by intersecting them with the pixel grid. We developed a simple method that performs this computation in O(1) and which is run in parallel.
We ported crumsort to Rust and parallelized it with Rayon, delivering improved performance over its pdqsort implementation for 64-bit random data. Scattering pixel segments with a sort was inspired from Allan MacKinnon's work on Spinel.
We implemented a fail-fast per-tile optimizer that tries to skip the painting step entirely. A similar approach could also be tested on the GPU.
Animation as it appears on the screen | Updated tiles only |
---|---|
You can run the demo above with:
cargo run --release -p demo -- spaceship
forma draws heavy inspiration from the following projects:
You can use the included demo
example to render a few examples, one of which is a non-compliant & incomplete SVG renderer:
cargo run --release -p demo -- svg assets/svgs/paris-30k.svg
It renders enormous SVGs at interactive framerates, even on CPU: (compare to your web browser)
Since this project is work-in-progress, breakage in the API, while not drastic, is expected. The performance on the GPU back-end is also expected to improve especially on mobile where performance is known to be poor and where the CPU back-end is currently advised instead.
Other than that:
f16
for great mobile GPU performanceThis is not an officially supported Google product.