diff --git a/Cargo.lock b/Cargo.lock index cf700bbdae..d213d27318 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2595,6 +2595,9 @@ dependencies = [ [[package]] name = "vello_api" version = "0.4.0" +dependencies = [ + "peniko", +] [[package]] name = "vello_common" diff --git a/Cargo.toml b/Cargo.toml index 6661c3c92f..d363e224e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ clippy.wildcard_dependencies = "warn" [workspace.dependencies] vello = { version = "0.4.0", path = "vello" } +vello_api = { path = "sparse_strips/vello_api" } vello_encoding = { version = "0.4.0", path = "vello_encoding" } vello_shaders = { version = "0.4.0", path = "vello_shaders" } bytemuck = { version = "1.21.0", features = ["derive"] } diff --git a/sparse_strips/vello_api/Cargo.toml b/sparse_strips/vello_api/Cargo.toml index 0af7b11dd4..72ed9858d9 100644 --- a/sparse_strips/vello_api/Cargo.toml +++ b/sparse_strips/vello_api/Cargo.toml @@ -12,6 +12,10 @@ repository.workspace = true publish = false [dependencies] +peniko = { workspace = true } + +[features] +simd = [] [lints] workspace = true diff --git a/sparse_strips/vello_api/src/execute.rs b/sparse_strips/vello_api/src/execute.rs new file mode 100644 index 0000000000..cac9043b14 --- /dev/null +++ b/sparse_strips/vello_api/src/execute.rs @@ -0,0 +1,54 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +//! Different execution modes for kernels. + +#[derive(Copy, Clone, Debug)] +/// The execution mode used for the rendering process. +pub enum ExecutionMode { + /// Only use scalar execution. This is recommended if you want to have + /// consistent results across different platforms and want to avoid unsafe code, + /// and is the only option if you disabled the `simd` feature. Performance will be + /// worse, though. + Scalar, + /// Select the best execution mode according to what is available on the host system. + /// This is the recommended option for highest performance. + #[cfg(feature = "simd")] + Auto, + /// Force the usage of neon SIMD instructions. This will lead to panics in case + /// the CPU doesn't support the target feature `neon`. + #[cfg(all(target_arch = "aarch64", feature = "simd"))] + Neon, + /// Force the usage of AVX2 SIMD instructions. This will lead to panics in case + /// the CPU doesn't support the target features `avx2` and `fma`. + #[cfg(all(target_arch = "x86_64", feature = "simd"))] + Avx2, +} + +#[cfg(feature = "simd")] +impl Default for ExecutionMode { + fn default() -> Self { + Self::Auto + } +} + +#[cfg(not(feature = "simd"))] +impl Default for ExecutionMode { + fn default() -> Self { + Self::Scalar + } +} + +/// Scalar execution mode. +#[derive(Debug)] +pub struct Scalar; + +#[cfg(all(target_arch = "aarch64", feature = "simd"))] +#[derive(Debug)] +/// Execute using NEON intrinsics. +pub struct Neon; + +#[cfg(all(target_arch = "x86_64", feature = "simd"))] +#[derive(Debug)] +/// Execute using AVX2 intrinsics. +pub struct Avx2; diff --git a/sparse_strips/vello_api/src/lib.rs b/sparse_strips/vello_api/src/lib.rs index 4050b450fe..c7ea3ff656 100644 --- a/sparse_strips/vello_api/src/lib.rs +++ b/sparse_strips/vello_api/src/lib.rs @@ -4,3 +4,11 @@ //! This crate defines the public API types, providing a stable interface for CPU and hybrid //! CPU/GPU rendering implementations. It provides common interfaces and data structures used //! across different implementations + +#![forbid(unsafe_code)] + +pub use peniko; +pub use peniko::color; +pub use peniko::kurbo; +pub mod execute; +pub mod paint; diff --git a/sparse_strips/vello_api/src/paint.rs b/sparse_strips/vello_api/src/paint.rs new file mode 100644 index 0000000000..9ac3ccceda --- /dev/null +++ b/sparse_strips/vello_api/src/paint.rs @@ -0,0 +1,26 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +//! Types for paints. + +use peniko::color::{AlphaColor, Srgb}; + +// TODO: This will probably turn into a generic type where +// vello-hybrid and vello-cpu provide their own instantiations for +// a `Pattern` type. +/// A paint used for filling or stroking paths. +#[derive(Debug, Clone)] +pub enum Paint { + /// A solid color. + Solid(AlphaColor), + /// A gradient. + Gradient(()), + /// A pattern. + Pattern(()), +} + +impl From> for Paint { + fn from(value: AlphaColor) -> Self { + Self::Solid(value) + } +}