Skip to content

Commit 730b4f1

Browse files
LaurenzVtomcur
andauthored
Add the code for vello_api (#827)
It`s possible I later on realize there is something else missing, but I think for now this should cover most of what is needed for that crate, based on my current version. One thing that will need to be added later on is the render context trait. --------- Co-authored-by: Tom Churchman <[email protected]>
1 parent 1c312e3 commit 730b4f1

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ clippy.wildcard_dependencies = "warn"
8686

8787
[workspace.dependencies]
8888
vello = { version = "0.4.0", path = "vello" }
89+
vello_api = { path = "sparse_strips/vello_api" }
8990
vello_encoding = { version = "0.4.0", path = "vello_encoding" }
9091
vello_shaders = { version = "0.4.0", path = "vello_shaders" }
9192
bytemuck = { version = "1.21.0", features = ["derive"] }

sparse_strips/vello_api/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ repository.workspace = true
1212
publish = false
1313

1414
[dependencies]
15+
peniko = { workspace = true }
16+
17+
[features]
18+
simd = []
1519

1620
[lints]
1721
workspace = true
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2025 the Vello Authors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! Different execution modes for kernels.
5+
6+
#[derive(Copy, Clone, Debug)]
7+
/// The execution mode used for the rendering process.
8+
pub enum ExecutionMode {
9+
/// Only use scalar execution. This is recommended if you want to have
10+
/// consistent results across different platforms and want to avoid unsafe code,
11+
/// and is the only option if you disabled the `simd` feature. Performance will be
12+
/// worse, though.
13+
Scalar,
14+
/// Select the best execution mode according to what is available on the host system.
15+
/// This is the recommended option for highest performance.
16+
#[cfg(feature = "simd")]
17+
Auto,
18+
/// Force the usage of neon SIMD instructions. This will lead to panics in case
19+
/// the CPU doesn't support the target feature `neon`.
20+
#[cfg(all(target_arch = "aarch64", feature = "simd"))]
21+
Neon,
22+
/// Force the usage of AVX2 SIMD instructions. This will lead to panics in case
23+
/// the CPU doesn't support the target features `avx2` and `fma`.
24+
#[cfg(all(target_arch = "x86_64", feature = "simd"))]
25+
Avx2,
26+
}
27+
28+
#[cfg(feature = "simd")]
29+
impl Default for ExecutionMode {
30+
fn default() -> Self {
31+
Self::Auto
32+
}
33+
}
34+
35+
#[cfg(not(feature = "simd"))]
36+
impl Default for ExecutionMode {
37+
fn default() -> Self {
38+
Self::Scalar
39+
}
40+
}
41+
42+
/// Scalar execution mode.
43+
#[derive(Debug)]
44+
pub struct Scalar;
45+
46+
#[cfg(all(target_arch = "aarch64", feature = "simd"))]
47+
#[derive(Debug)]
48+
/// Execute using NEON intrinsics.
49+
pub struct Neon;
50+
51+
#[cfg(all(target_arch = "x86_64", feature = "simd"))]
52+
#[derive(Debug)]
53+
/// Execute using AVX2 intrinsics.
54+
pub struct Avx2;

sparse_strips/vello_api/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@
44
//! This crate defines the public API types, providing a stable interface for CPU and hybrid
55
//! CPU/GPU rendering implementations. It provides common interfaces and data structures used
66
//! across different implementations
7+
8+
#![forbid(unsafe_code)]
9+
10+
pub use peniko;
11+
pub use peniko::color;
12+
pub use peniko::kurbo;
13+
pub mod execute;
14+
pub mod paint;

sparse_strips/vello_api/src/paint.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2025 the Vello Authors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! Types for paints.
5+
6+
use peniko::color::{AlphaColor, Srgb};
7+
8+
// TODO: This will probably turn into a generic type where
9+
// vello-hybrid and vello-cpu provide their own instantiations for
10+
// a `Pattern` type.
11+
/// A paint used for filling or stroking paths.
12+
#[derive(Debug, Clone)]
13+
pub enum Paint {
14+
/// A solid color.
15+
Solid(AlphaColor<Srgb>),
16+
/// A gradient.
17+
Gradient(()),
18+
/// A pattern.
19+
Pattern(()),
20+
}
21+
22+
impl From<AlphaColor<Srgb>> for Paint {
23+
fn from(value: AlphaColor<Srgb>) -> Self {
24+
Self::Solid(value)
25+
}
26+
}

0 commit comments

Comments
 (0)