Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/anyrender_vello/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Configurable composite alpha mode and base color via `VelloRendererOptions`, with builder-pattern methods (#71).
- `pipeline_cache` on `VelloRendererOptions`, and `VelloImageRenderer::with_pipeline_cache`, so a `wgpu::PipelineCache` can reach Vello (#73).

### Changed

- Marked `VelloRendererOptions` as `#[non_exhaustive]` (#71).
- `VelloRendererOptions`' builder methods are no longer `const`, because the options now hold a type with a destructor (#73).

## [0.12.0] - 2026-06-23

Expand Down
31 changes: 22 additions & 9 deletions crates/anyrender_vello/src/image_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ pub struct VelloImageRenderer {
texture_handles: FxHashMap<ResourceId, ImageData>,
}

impl RenderContext for VelloImageRenderer {}
impl ImageRenderer for VelloImageRenderer {
type ScenePainter<'a>
= VelloScenePainter<'a, 'a>
where
Self: 'a;

fn new(width: u32, height: u32) -> Self {
impl VelloImageRenderer {
/// Like [`ImageRenderer::new`], but reusing compiled pipelines from a cache
/// wgpu built earlier. Creating the cache, persisting its data and deciding
/// when it is stale are all the caller's responsibility.
pub fn with_pipeline_cache(
width: u32,
height: u32,
pipeline_cache: Option<wgpu::PipelineCache>,
) -> Self {
// Create WGPUContext
let mut context = WGPUContext::new();

Expand All @@ -41,7 +42,7 @@ impl ImageRenderer for VelloImageRenderer {
use_cpu: false,
num_init_threads: DEFAULT_THREADS,
antialiasing_support: vello::AaSupport::area_only(),
pipeline_cache: None,
pipeline_cache,
},
)
.expect("Got non-Send/Sync error from creating renderer");
Expand All @@ -53,6 +54,18 @@ impl ImageRenderer for VelloImageRenderer {
texture_handles: FxHashMap::default(),
}
}
}

impl RenderContext for VelloImageRenderer {}
impl ImageRenderer for VelloImageRenderer {
type ScenePainter<'a>
= VelloScenePainter<'a, 'a>
where
Self: 'a;

fn new(width: u32, height: u32) -> Self {
Self::with_pipeline_cache(width, height, None)
}

fn resize(&mut self, width: u32, height: u32) {
self.buffer_renderer.resize(width, height);
Expand Down
28 changes: 21 additions & 7 deletions crates/anyrender_vello/src/window_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use vello::{
Scene as VelloScene,
};
use wgpu::{
CompositeAlphaMode, Features, Limits, PresentMode, Texture, TextureFormat, TextureUsages,
CompositeAlphaMode, Features, Limits, PipelineCache, PresentMode, Texture, TextureFormat,
TextureUsages,
};
use wgpu_context::{
AlphaConversion, DeviceHandle, SurfaceRenderer, SurfaceRendererConfiguration,
Expand Down Expand Up @@ -64,6 +65,10 @@ pub struct VelloRendererOptions {
pub antialiasing_method: AaConfig,
/// Alpha mode used when compositing the window surface.
pub composite_alpha_mode: anyrender::CompositeAlphaMode,
/// Cache that wgpu may reuse compiled pipelines from, avoiding shader
/// compilation on start-up. Creating it, persisting its data and deciding
/// when it is stale are all the caller's responsibility.
pub pipeline_cache: Option<PipelineCache>,
}

impl Default for VelloRendererOptions {
Expand All @@ -80,35 +85,36 @@ impl VelloRendererOptions {
base_color: Color::WHITE,
antialiasing_method: AaConfig::Msaa16,
composite_alpha_mode: anyrender::CompositeAlphaMode::Auto,
pipeline_cache: None,
}
}

pub const fn features(self, features: Features) -> Self {
pub fn features(self, features: Features) -> Self {
Self {
features: Some(features),
..self
}
}

pub const fn limits(self, limits: Limits) -> Self {
pub fn limits(self, limits: Limits) -> Self {
Self {
limits: Some(limits),
..self
}
}

pub const fn base_color(self, base_color: Color) -> Self {
pub fn base_color(self, base_color: Color) -> Self {
Self { base_color, ..self }
}

pub const fn antialiasing_method(self, antialiasing_method: AaConfig) -> Self {
pub fn antialiasing_method(self, antialiasing_method: AaConfig) -> Self {
Self {
antialiasing_method,
..self
}
}

pub const fn composite_alpha_mode(
pub fn composite_alpha_mode(
self,
composite_alpha_mode: anyrender::types::CompositeAlphaMode,
) -> Self {
Expand All @@ -117,6 +123,13 @@ impl VelloRendererOptions {
..self
}
}

pub fn pipeline_cache(self, pipeline_cache: PipelineCache) -> Self {
Self {
pipeline_cache: Some(pipeline_cache),
..self
}
}
}

impl From<anyrender::RendererConfig> for VelloRendererOptions {
Expand Down Expand Up @@ -273,6 +286,7 @@ impl WindowRenderer for VelloWindowRenderer {
}
}
};
let pipeline_cache = self.config.pipeline_cache.clone();
let existing_device_handle = self
.wgpu_context
.find_compatible_device_handle(Some(&surface));
Expand Down Expand Up @@ -360,7 +374,7 @@ impl WindowRenderer for VelloWindowRenderer {
antialiasing_support: AaSupport::all(),
use_cpu: false,
num_init_threads: DEFAULT_THREADS,
pipeline_cache: None,
pipeline_cache,
},
)
.unwrap();
Expand Down