Vello CPU
CPU-based renderer
Vello CPU is a 2D graphics rendering engine written in Rust, for devices with no or underpowered GPUs.
We also develop Vello, which makes use of the GPU for 2D rendering and has higher performance than Vello CPU. Vello CPU is being developed as part of work to address shortcomings in Vello.
Usage
To use Vello CPU, you need to:
- Create a
RenderContext, a 2D drawing context for a fixed-size target area. - For each object in your scene:
- Set how the object will be painted, using
set_paint. - Set the shape to be drawn for that object, using methods like
fill_path,stroke_path, orglyph_run.
- Set how the object will be painted, using
- Render it to an image using
RenderContext::render_to_pixmap.
use ;
use ;
let width = 10;
let height = 5;
let mut context = new;
context.set_paint;
context.fill_rect;
let mut target = new;
// While calling `flush` is only strictly necessary if you are rendering using
// multiple threads, it is recommended to always do this.
context.flush;
context.render_to_pixmap;
let expected_render = b"\
0000000000\
0001111000\
0001111000\
0001111000\
0000000000";
let magenta = MAGENTA.premultiply.to_rgba8;
let transparent = PremulRgba8 ;
let mut result = Vecnew;
for pixel in target.data
assert_eq!;
Feel free to take a look at some further examples to better understand how to interact with Vello CPU's API,
Features
std(enabled by default): Get floating point functions from the standard library (likely using your target's libc).libm: Use floating point implementations fromlibm.png(enabled by default): Allow loadingPixmaps from PNG images. Also required for rendering glyphs with an embedded PNG.multithreading: Enable multi-threaded rendering.
At least one of std and libm is required; std overrides libm.
Caveats
Overall, Vello CPU is already very feature-rich and should be ready for production use cases. The main caveat at the moment is that the API is still likely to change and not stable yet. For example, we have known plans to change the API around how image resources are used.
Additionally, there are certain APIs that are still very much experimental, including for example support for filters. This will be reflected in the documentation of those APIs.
Another caveat is that multi-threading with large thread counts (more than 4) might give diminishing returns, especially when making heavy use of layers and clip paths.
Performance
Performance benchmarks can be found here, As can be seen, Vello CPU achieves compelling performance on both, aarch64 and x86 platforms. We also have SIMD optimizations for WASM SIMD, meaning that you can expect good performance there as well.
Implementation
If you want to gain a better understanding of Vello CPU and the sparse strips paradigm, you can take a look at the accompanying master's thesis that was written on the topic. Note that parts of the descriptions might become outdated as the implementation changes, but it should give a good overview nevertheless.
Minimum supported Rust Version (MSRV)
This version of Vello CPU has been verified to compile with Rust 1.88 and later.
Future versions of Vello CPU might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
As time has passed, some of Vello CPU's dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.
# Use the problematic dependency's name and version
Community
Discussion of Vello CPU development happens in the Linebender Zulip, specifically the #vello channel. All public content can be read without logging in.
Contributions are welcome by pull request. The Rust code of conduct applies.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.