Skip to content

Commit

Permalink
v0.3 (#24)
Browse files Browse the repository at this point in the history
## 0.3.0

### Added

- Added `velato::Renderer::render`, which now returns a new vello scene.

### Changed

- Updated to vello 0.2
- Renamed `VelatoError` to `velato::Error`
- Renamed the existing `velato::Renderer::render` to
`velato::Renderer::append`

### Removed

- All code and related profiling (`wgpu_profiler`) used in examples.
  • Loading branch information
simbleau authored Jul 3, 2024
1 parent 631d76c commit 23353c9
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 442 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe

## Unreleased

## v0.2.0
## 0.3.0

### Added

- Added `velato::Renderer::render`, which now returns a new vello scene.

### Changed

- Updated to vello 0.2
- Renamed `VelatoError` to `velato::Error`
- Renamed the existing `velato::Renderer::render` to `velato::Renderer::append`

### Removed

- All code and related profiling (`wgpu_profiler`) used in examples.

## 0.2.0

### Changed

Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["examples/with_winit", "examples/run_wasm", "examples/scenes"]

[workspace.package]
edition = "2021"
version = "0.2.0"
version = "0.3.0"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/linebender/velato"
[package]
Expand All @@ -19,7 +19,7 @@ repository.workspace = true

[workspace.dependencies]
# NOTE: Make sure to keep this in sync with the version badge in README.md
vello = { version = "0.1.0", default-features = false }
vello = { version = "0.2.0", default-features = false }

[dependencies]
vello = { workspace = true }
Expand All @@ -28,9 +28,9 @@ once_cell = "1.19.0"
thiserror = "1.0.61"

# For the parser
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
serde_repr = "0.1.18"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.120"
serde_repr = "0.1.19"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.42"
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
[![Linebender Zulip](https://img.shields.io/badge/Linebender-%23gpu-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/197075-gpu)
[![dependency status](https://deps.rs/repo/github/linebender/velato/status.svg)](https://deps.rs/repo/github/linebender/velato)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](#license)
[![vello version](https://img.shields.io/badge/vello-v0.1.0-purple.svg)](https://crates.io/crates/vello)

[![vello version](https://img.shields.io/badge/vello-v0.2.0-purple.svg)](https://crates.io/crates/vello)\
[![Crates.io](https://img.shields.io/crates/v/velato.svg)](https://crates.io/crates/velato)
[![Docs](https://docs.rs/velato/badge.svg)](https://docs.rs/velato)
[![Build status](https://github.com/linebender/velato/workflows/CI/badge.svg)](https://github.com/linebender/velato/actions)
Expand Down
2 changes: 1 addition & 1 deletion examples/run_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ repository.workspace = true
publish = false

[dependencies]
cargo-run-wasm = "0.3.2"
cargo-run-wasm = "0.4.0"
2 changes: 1 addition & 1 deletion examples/run_wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
/// ```
fn main() {
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
cargo_run_wasm::run_wasm_cli_with_css("body { margin: 0px; }");
}
17 changes: 9 additions & 8 deletions examples/scenes/src/lottie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,22 @@ pub fn lottie_function_of<R: AsRef<str>>(
.unwrap_or_else(|e| panic!("failed to parse lottie file {name}: {e}")),
);
eprintln!("Parsed lottie {name} in {:?}", start.elapsed());
fn render_lottie_contents(lottie: &Composition, start: &Instant) -> (Scene, Vec2) {
let mut new_scene = Scene::new();
fn render_lottie_contents(
renderer: &mut velato::Renderer,
lottie: &Composition,
start: &Instant,
) -> Scene {
let frame = ((start.elapsed().as_secs_f64() * lottie.frame_rate)
% (lottie.frames.end - lottie.frames.start))
+ lottie.frames.start;
velato::Renderer::new().render(lottie, frame, Affine::IDENTITY, 1.0, &mut new_scene);
let resolution = Vec2::new(lottie.width as f64, lottie.height as f64);
(new_scene, resolution)
renderer.render(lottie, frame, Affine::IDENTITY, 1.0)
}

let started = instant::Instant::now();
let mut renderer = velato::Renderer::new();
let lottie = lottie.clone();
let resolution = Vec2::new(lottie.width as f64, lottie.height as f64);
move |scene, params| {
let (scene_frag, resolution) = render_lottie_contents(&lottie, &started);
scene.append(&scene_frag, None);
params.resolution = Some(resolution);
*scene = render_lottie_contents(&mut renderer, &lottie, &started);
}
}
6 changes: 2 additions & 4 deletions examples/with_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ name = "with_winit_bin"
path = "src/main.rs"

[dependencies]
vello = { workspace = true, features = ["buffer_labels", "wgpu", "wgpu-profiler"] }
vello = { workspace = true, features = ["buffer_labels", "wgpu"] }
scenes = { path = "../scenes" }
anyhow = "1"
clap = { version = "4.5.1", features = ["derive"] }
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
pollster = "0.3"
wgpu-profiler = "0.16"
wgpu = "0.19.3"
winit = "0.29.12"
env_logger = "0.11.2"
log = "0.4.21"

[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies]
vello = { workspace = true, features = ["hot_reload", "wgpu", "wgpu-profiler"] }
vello = { workspace = true, features = ["hot_reload", "wgpu"] }
notify-debouncer-mini = "0.3"

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
75 changes: 12 additions & 63 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 the Velato Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use instant::{Duration, Instant};
use instant::Instant;
use std::collections::HashSet;
use std::num::NonZeroUsize;
use std::sync::Arc;
Expand All @@ -12,7 +12,7 @@ use scenes::{RobotoText, SceneParams, SceneSet};
use vello::kurbo::{Affine, Vec2};
use vello::peniko::Color;
use vello::util::{RenderContext, RenderSurface};
use vello::{AaConfig, BumpAllocators, Renderer, RendererOptions, Scene};
use vello::{wgpu, AaConfig, BumpAllocators, Renderer, RendererOptions, Scene};

use winit::event_loop::{EventLoop, EventLoopBuilder};
use winit::window::Window;
Expand Down Expand Up @@ -83,7 +83,7 @@ fn run(
let mut render_state = {
renderers.resize_with(render_cx.devices.len(), || None);
let id = render_state.surface.dev_id;
let mut renderer = Renderer::new(
let renderer = Renderer::new(
&render_cx.devices[id].device,
RendererOptions {
surface_format: Some(render_state.surface.format),
Expand All @@ -95,14 +95,6 @@ fn run(
},
)
.expect("Could create renderer");
renderer
.profiler
.change_settings(wgpu_profiler::GpuProfilerSettings {
enable_timer_queries: false,
enable_debug_groups: false,
..Default::default()
})
.expect("Not setting max_num_pending_frames");
renderers[id] = Some(renderer);
Some(render_state)
};
Expand Down Expand Up @@ -145,9 +137,7 @@ fn run(
if let Some(set_scene) = args.scene {
scene_ix = set_scene;
}
let mut profile_stored = None;
let mut prev_scene_ix = scene_ix - 1;
let mut profile_taken = Instant::now();
let mut modifiers = ModifiersState::default();
event_loop
.run(move |event, event_loop| match event {
Expand Down Expand Up @@ -211,32 +201,6 @@ fn run(
aa_config_ix.saturating_add(1)
};
}
"p" => {
if let Some(renderer) = &renderers[render_state.surface.dev_id]
{
if let Some(profile_result) = &renderer
.profile_result
.as_ref()
.or(profile_stored.as_ref())
{
// There can be empty results if the required features aren't supported
if !profile_result.is_empty() {
let path = std::path::Path::new("trace.json");
match wgpu_profiler::chrometrace::write_chrometrace(
path,
profile_result,
) {
Ok(()) => {
println!("Wrote trace to path {path:?}");
}
Err(e) => {
eprintln!("Failed to write trace {e}")
}
}
}
}
}
}
"v" => {
vsync_on = !vsync_on;
render_cx.set_present_mode(
Expand Down Expand Up @@ -408,26 +372,6 @@ fn run(
vsync_on,
antialiasing_method,
);
if let Some(profiling_result) = renderers[render_state.surface.dev_id]
.as_mut()
.and_then(|it| it.profile_result.take())
{
if profile_stored.is_none()
|| profile_taken.elapsed() > Duration::from_secs(1)
{
profile_stored = Some(profiling_result);
profile_taken = Instant::now();
}
}
if let Some(profiling_result) = profile_stored.as_ref() {
stats::draw_gpu_profiling(
&mut scene,
scene_params.text,
width as f64,
height as f64,
profiling_result,
);
}
}
let surface_texture = render_state
.surface
Expand Down Expand Up @@ -533,7 +477,12 @@ fn run(
.take()
.unwrap_or_else(|| create_window(event_loop));
let size = window.inner_size();
let surface_future = render_cx.create_surface(window.clone(), size.width, size.height, wgpu::PresentMode::AutoVsync);
let surface_future = render_cx.create_surface(
window.clone(),
size.width,
size.height,
wgpu::PresentMode::AutoVsync,
);
// We need to block here, in case a Suspended event appeared
let surface =
pollster::block_on(surface_future).expect("Error creating surface");
Expand All @@ -549,7 +498,7 @@ fn run(
surface_format: Some(render_state.surface.format),
use_cpu,
antialiasing_support: vello::AaSupport::all(),
num_init_threads: NonZeroUsize::new(args.num_init_threads)
num_init_threads: NonZeroUsize::new(args.num_init_threads),
},
)
.expect("Could create renderer");
Expand Down Expand Up @@ -616,7 +565,7 @@ pub fn main() -> Result<()> {
if let Some(scenes) = scenes {
let event_loop = EventLoopBuilder::<UserEvent>::with_user_event().build()?;
#[allow(unused_mut)]
let mut render_cx = RenderContext::new().unwrap();
let mut render_cx = RenderContext::new();
#[cfg(not(target_arch = "wasm32"))]
{
#[cfg(not(target_os = "android"))]
Expand Down Expand Up @@ -700,7 +649,7 @@ fn android_main(app: AndroidApp) {
.select_scene_set(|| Args::command())
.unwrap()
.unwrap();
let render_cx = RenderContext::new().unwrap();
let render_cx = RenderContext::new();

run(event_loop, args, scenes, render_cx);
}
Loading

0 comments on commit 23353c9

Please sign in to comment.