From 22acb7aba28a7df5ec3ce42ef2b17e86bfaf2a1c Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sat, 9 Mar 2024 17:59:52 +0100 Subject: [PATCH 01/17] Better error types --- Cargo.toml | 2 + src/lib.rs | 53 ++++++++++++++++++-------- src/shaders.rs | 8 ++-- src/util.rs | 15 ++++++-- src/wgpu_engine.rs | 94 +++++++++++++++++++++++++--------------------- 5 files changed, 105 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8072f7f1b..eee729172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,6 +64,7 @@ raw-window-handle = { workspace = true } static_assertions = { workspace = true } futures-intrusive = { workspace = true } wgpu-profiler = { workspace = true, optional = true } +thiserror = { workspace = true } [workspace.lints] clippy.doc_markdown = "warn" @@ -80,6 +81,7 @@ futures-intrusive = "0.5.0" raw-window-handle = "0.6.1" smallvec = "1.13.2" static_assertions = "1.1.0" +thiserror = "1.0.57" # NOTE: Make sure to keep this in sync with the version badge in README.md # as well as examples/simple/Cargo.toml diff --git a/src/lib.rs b/src/lib.rs index 53af574bd..159c1ea2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,7 @@ pub mod util; pub use render::Render; pub use scene::{DrawGlyphs, Scene}; +use thiserror::Error; #[cfg(feature = "wgpu")] pub use util::block_on_wgpu; @@ -117,7 +118,7 @@ pub use shaders::FullShaders; #[cfg(feature = "wgpu")] use vello_encoding::Resolver; #[cfg(feature = "wgpu")] -use wgpu_engine::{ExternalResource, WgpuEngine}; +use wgpu_engine::{ExternalResource, WgpuEngine, WgpuRecordingError}; /// Temporary export, used in `with_winit` for stats pub use vello_encoding::BumpAllocators; @@ -126,12 +127,6 @@ use wgpu::{Device, PipelineCompilationOptions, Queue, SurfaceTexture, TextureFor #[cfg(all(feature = "wgpu", feature = "wgpu-profiler"))] use wgpu_profiler::{GpuProfiler, GpuProfilerSettings}; -/// Catch-all error type. -pub type Error = Box; - -/// Specialization of `Result` for our catch-all error type. -pub type Result = std::result::Result; - /// Represents the antialiasing method to use during a render pass. #[derive(Copy, Clone, PartialEq, Eq)] pub enum AaConfig { @@ -183,6 +178,32 @@ impl FromIterator for AaSupport { } } +#[cfg(feature = "wgpu")] +#[derive(Error, Debug)] +pub enum RendererError { + #[cfg(feature = "wgpu-profiler")] + #[error("couldn't create wgpu profiler")] + ProfilerCreationError(#[from] wgpu_profiler::CreationError), +} + +#[cfg(feature = "wgpu")] +#[derive(Error, Debug)] +pub enum RenderError { + #[error("error while run recording")] + WgpuRecordingError(#[from] WgpuRecordingError), +} + +#[cfg(feature = "wgpu")] +#[derive(Error, Debug)] +pub enum AsyncRenderError { + #[error("error while run recording")] + WgpuRecordingError(#[from] WgpuRecordingError), + #[error(transparent)] + BufferAsyncError(#[from] wgpu::BufferAsyncError), + #[error("channel was closed")] + ChannelWasClosed, +} + /// Renders a scene into a texture or surface. #[cfg(feature = "wgpu")] pub struct Renderer { @@ -250,14 +271,14 @@ pub struct RendererOptions { #[cfg(feature = "wgpu")] impl Renderer { /// Creates a new renderer for the specified device. - pub fn new(device: &Device, options: RendererOptions) -> Result { + pub fn new(device: &Device, options: RendererOptions) -> Result { let mut engine = WgpuEngine::new(options.use_cpu); // If we are running in parallel (i.e. the number of threads is not 1) if options.num_init_threads != NonZeroUsize::new(1) { #[cfg(not(target_arch = "wasm32"))] engine.use_parallel_initialisation(); } - let shaders = shaders::full_shaders(device, &mut engine, &options)?; + let shaders = shaders::full_shaders(device, &mut engine, &options); #[cfg(not(target_arch = "wasm32"))] engine.build_shaders_if_needed(device, options.num_init_threads); let blit = options @@ -293,7 +314,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> Result<()> { + ) -> Result<(), RenderError> { let (recording, target) = render::render_full(scene, &mut self.resolver, &self.shaders, params); let external_resources = [ExternalResource::Image( @@ -327,7 +348,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> Result<()> { + ) -> Result<(), RenderError> { let width = params.width; let height = params.height; let mut target = self @@ -399,11 +420,11 @@ impl Renderer { /// Reload the shaders. This should only be used during `vello` development #[cfg(feature = "hot_reload")] - pub async fn reload_shaders(&mut self, device: &Device) -> Result<()> { + pub async fn reload_shaders(&mut self, device: &Device) -> Result<(), wgpu::Error> { device.push_error_scope(wgpu::ErrorFilter::Validation); let mut engine = WgpuEngine::new(self.options.use_cpu); // We choose not to initialise these shaders in parallel, to ensure the error scope works correctly - let shaders = shaders::full_shaders(device, &mut engine, &self.options)?; + let shaders = shaders::full_shaders(device, &mut engine, &self.options); let error = device.pop_error_scope().await; if let Some(error) = error { return Err(error.into()); @@ -431,7 +452,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> Result> { + ) -> Result, AsyncRenderError> { let mut render = Render::new(); let encoding = scene.encoding(); // TODO: turn this on; the download feature interacts with CPU dispatch @@ -463,7 +484,7 @@ impl Renderer { if let Some(recv_result) = receiver.receive().await { recv_result?; } else { - return Err("channel was closed".into()); + return Err(AsyncRenderError::ChannelWasClosed); } let mapped = buf_slice.get_mapped_range(); bump = Some(bytemuck::pod_read_unaligned(&mapped)); @@ -495,7 +516,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> Result> { + ) -> Result, AsyncRenderError> { let width = params.width; let height = params.height; let mut target = self diff --git a/src/shaders.rs b/src/shaders.rs index 7b9cdb972..e844595be 100644 --- a/src/shaders.rs +++ b/src/shaders.rs @@ -12,7 +12,7 @@ use crate::ShaderId; use crate::{ recording::{BindType, ImageFormat}, wgpu_engine::WgpuEngine, - Error, RendererOptions, + RendererOptions, }; // Shaders for the full pipeline @@ -49,7 +49,7 @@ pub fn full_shaders( device: &Device, engine: &mut WgpuEngine, options: &RendererOptions, -) -> Result { +) -> FullShaders { use crate::wgpu_engine::CpuShaderType; use BindType::*; @@ -250,7 +250,7 @@ pub fn full_shaders( None }; - Ok(FullShaders { + FullShaders { pathtag_reduce, pathtag_reduce2, pathtag_scan, @@ -274,5 +274,5 @@ pub fn full_shaders( fine_msaa8, fine_msaa16, pathtag_is_cpu: options.use_cpu, - }) + } } diff --git a/src/util.rs b/src/util.rs index ae97aab11..c887e20b5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,8 +5,7 @@ use std::future::Future; -use super::Result; - +use thiserror::Error; use wgpu::{ Adapter, Device, Instance, Limits, Queue, Surface, SurfaceConfiguration, SurfaceTarget, TextureFormat, @@ -24,6 +23,14 @@ pub struct DeviceHandle { pub queue: Queue, } +#[derive(Error, Debug)] +pub enum SurfaceCreationError { + #[error("Error creating device")] + CantCreateDevice, + #[error(transparent)] + WgpuSurface(#[from] wgpu::CreateSurfaceError), +} + impl RenderContext { #[allow(clippy::new_without_default)] pub fn new() -> Self { @@ -45,12 +52,12 @@ impl RenderContext { width: u32, height: u32, present_mode: wgpu::PresentMode, - ) -> Result> { + ) -> Result, SurfaceCreationError> { let surface = self.instance.create_surface(window.into())?; let dev_id = self .device(Some(&surface)) .await - .ok_or("Error creating device")?; + .ok_or(SurfaceCreationError::CantCreateDevice)?; let device_handle = &self.devices[dev_id]; let capabilities = surface.get_capabilities(&device_handle.adapter); diff --git a/src/wgpu_engine.rs b/src/wgpu_engine.rs index f743d12c3..1e1f41eb3 100644 --- a/src/wgpu_engine.rs +++ b/src/wgpu_engine.rs @@ -8,6 +8,7 @@ use std::collections::{HashMap, HashSet}; use vello_shaders::cpu::CpuBinding; +use thiserror::Error; use wgpu::{ BindGroup, BindGroupLayout, Buffer, BufferUsages, CommandEncoder, CommandEncoderDescriptor, ComputePipeline, Device, PipelineCompilationOptions, Queue, Texture, TextureAspect, @@ -16,7 +17,8 @@ use wgpu::{ use crate::recording::BindType; use crate::{ - BufferProxy, Command, Error, ImageProxy, Recording, ResourceId, ResourceProxy, ShaderId, + cpu_dispatch::CpuBinding, recording::BindType, BufferProxy, Command, Error, ImageProxy, + Recording, ResourceId, ResourceProxy, ShaderId, }; #[cfg(not(target_arch = "wasm32"))] @@ -132,6 +134,14 @@ enum TransientBuf<'a> { Gpu(&'a Buffer), } +#[derive(Error, Debug)] +pub enum WgpuRecordingError { + #[error("buffer for indirect dispatch not in map")] + IndirectDispatchBufferNotInMap, + #[error("buffer for download not in map")] + DownloadBufferNotInMap, +} + impl WgpuEngine { pub fn new(use_cpu: bool) -> WgpuEngine { Self { @@ -345,7 +355,7 @@ impl WgpuEngine { external_resources: &[ExternalResource], label: &'static str, #[cfg(feature = "wgpu-profiler")] profiler: &mut wgpu_profiler::GpuProfiler, - ) -> Result<(), Error> { + ) -> Result<(), WgpuRecordingError> { let mut free_bufs: HashSet = Default::default(); let mut free_images: HashSet = Default::default(); let mut transient_map = TransientBindMap::new(external_resources); @@ -434,31 +444,30 @@ impl WgpuEngine { .insert_image(image_proxy.id, texture, texture_view); } Command::WriteImage(proxy, [x, y, width, height], data) => { - if let Ok((texture, _)) = self.bind_map.get_or_create_image(*proxy, device) { - let format = proxy.format.to_wgpu(); - let block_size = format - .block_copy_size(None) - .expect("ImageFormat must have a valid block size"); - queue.write_texture( - wgpu::ImageCopyTexture { - texture, - mip_level: 0, - origin: wgpu::Origin3d { x: *x, y: *y, z: 0 }, - aspect: TextureAspect::All, - }, - &data[..], - wgpu::ImageDataLayout { - offset: 0, - bytes_per_row: Some(*width * block_size), - rows_per_image: None, - }, - wgpu::Extent3d { - width: *width, - height: *height, - depth_or_array_layers: 1, - }, - ); - } + let (texture, _) = self.bind_map.get_or_create_image(*proxy, device); + let format = proxy.format.to_wgpu(); + let block_size = format + .block_copy_size(None) + .expect("ImageFormat must have a valid block size"); + queue.write_texture( + wgpu::ImageCopyTexture { + texture, + mip_level: 0, + origin: wgpu::Origin3d { x: *x, y: *y, z: 0 }, + aspect: TextureAspect::All, + }, + &data[..], + wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some(*width * block_size), + rows_per_image: None, + }, + wgpu::Extent3d { + width: *width, + height: *height, + depth_or_array_layers: 1, + }, + ); } Command::Dispatch(shader_id, wg_size, bindings) => { // println!("dispatching {:?} with {} bindings", wg_size, bindings.len()); @@ -486,7 +495,7 @@ impl WgpuEngine { &mut encoder, &wgpu_shader.bind_group_layout, bindings, - )?; + ); let mut cpass = encoder.begin_compute_pass(&Default::default()); #[cfg(feature = "wgpu-profiler")] let query = profiler @@ -526,7 +535,7 @@ impl WgpuEngine { &mut encoder, &wgpu_shader.bind_group_layout, bindings, - )?; + ); transient_map.materialize_gpu_buf_for_indirect( &mut self.bind_map, &mut self.pool, @@ -544,7 +553,7 @@ impl WgpuEngine { let buf = self .bind_map .get_gpu_buf(proxy.id) - .ok_or("buffer for indirect dispatch not in map")?; + .ok_or(WgpuRecordingError::IndirectDispatchBufferNotInMap)?; cpass.dispatch_workgroups_indirect(buf, *offset); #[cfg(feature = "wgpu-profiler")] profiler.end_query(&mut cpass, query); @@ -555,7 +564,7 @@ impl WgpuEngine { let src_buf = self .bind_map .get_gpu_buf(proxy.id) - .ok_or("buffer not in map")?; + .ok_or(WgpuRecordingError::DownloadBufferNotInMap)?; let usage = BufferUsages::MAP_READ | BufferUsages::COPY_DST; let buf = self.pool.get_buf(proxy.size, "download", usage, device); encoder.copy_buffer_to_buffer(src_buf, 0, &buf, 0, proxy.size); @@ -708,9 +717,9 @@ impl BindMap { &mut self, proxy: ImageProxy, device: &Device, - ) -> Result<&(Texture, TextureView), Error> { + ) -> &(Texture, TextureView) { match self.image_map.entry(proxy.id) { - Entry::Occupied(occupied) => Ok(occupied.into_mut()), + Entry::Occupied(occupied) => occupied.into_mut(), Entry::Vacant(vacant) => { let format = proxy.format.to_wgpu(); let texture = device.create_texture(&wgpu::TextureDescriptor { @@ -737,7 +746,7 @@ impl BindMap { array_layer_count: None, format: Some(proxy.format.to_wgpu()), }); - Ok(vacant.insert((texture, texture_view))) + vacant.insert((texture, texture_view)) } } } @@ -857,7 +866,7 @@ impl<'a> TransientBindMap<'a> { encoder: &mut CommandEncoder, layout: &BindGroupLayout, bindings: &[ResourceProxy], - ) -> Result { + ) -> BindGroup { for proxy in bindings { match proxy { ResourceProxy::Buffer(proxy) => { @@ -929,10 +938,10 @@ impl<'a> TransientBindMap<'a> { Some(TransientBuf::Gpu(b)) => b, _ => bind_map.get_gpu_buf(proxy.id).unwrap(), }; - Ok(wgpu::BindGroupEntry { + wgpu::BindGroupEntry { binding: i as u32, resource: buf.as_entire_binding(), - }) + } } ResourceProxy::Image(proxy) => { let view = self @@ -941,19 +950,18 @@ impl<'a> TransientBindMap<'a> { .copied() .or_else(|| bind_map.image_map.get(&proxy.id).map(|v| &v.1)) .unwrap(); - Ok(wgpu::BindGroupEntry { + wgpu::BindGroupEntry { binding: i as u32, resource: wgpu::BindingResource::TextureView(view), - }) + } } }) - .collect::, Error>>()?; - let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + .collect::>(); + device.create_bind_group(&wgpu::BindGroupDescriptor { label: None, layout, entries: &entries, - }); - Ok(bind_group) + }) } fn create_cpu_resources( From 973cf6900e4c4bd3f87532ab789c6da2e7e71502 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sat, 9 Mar 2024 18:14:07 +0100 Subject: [PATCH 02/17] Add `Default` for `RenderContext` --- src/util.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util.rs b/src/util.rs index c887e20b5..c70d48f04 100644 --- a/src/util.rs +++ b/src/util.rs @@ -31,6 +31,12 @@ pub enum SurfaceCreationError { WgpuSurface(#[from] wgpu::CreateSurfaceError), } +impl Default for RenderContext { + fn default() -> Self { + Self::new() + } +} + impl RenderContext { #[allow(clippy::new_without_default)] pub fn new() -> Self { From 9ce0072e67c5f6328f35d7c3b8bcb4db3ccfd43a Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sat, 9 Mar 2024 18:21:33 +0100 Subject: [PATCH 03/17] Fix imports for non-`wgpu`-feature --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 159c1ea2a..a68b45bb9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,6 +106,7 @@ pub mod util; pub use render::Render; pub use scene::{DrawGlyphs, Scene}; +#[cfg(feature = "wgpu")] use thiserror::Error; #[cfg(feature = "wgpu")] pub use util::block_on_wgpu; From a4df4b603f545fc9dd83227a43cfdedeec016d87 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sat, 9 Mar 2024 18:25:22 +0100 Subject: [PATCH 04/17] clippy --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a68b45bb9..8e7cf45a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -428,7 +428,7 @@ impl Renderer { let shaders = shaders::full_shaders(device, &mut engine, &self.options); let error = device.pop_error_scope().await; if let Some(error) = error { - return Err(error.into()); + return Err(error); } self.engine = engine; self.shaders = shaders; From 5d8d7265f51a90243198efc11553055967e15145 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sun, 10 Mar 2024 11:53:18 +0100 Subject: [PATCH 05/17] One big `VelloError` --- src/lib.rs | 70 ++++++++++++++++++++++++++-------------------- src/util.rs | 17 ++++------- src/wgpu_engine.rs | 24 +++++----------- 3 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8e7cf45a3..ca0035fc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,7 +119,7 @@ pub use shaders::FullShaders; #[cfg(feature = "wgpu")] use vello_encoding::Resolver; #[cfg(feature = "wgpu")] -use wgpu_engine::{ExternalResource, WgpuEngine, WgpuRecordingError}; +use wgpu_engine::{ExternalResource, WgpuEngine}; /// Temporary export, used in `with_winit` for stats pub use vello_encoding::BumpAllocators; @@ -179,31 +179,43 @@ impl FromIterator for AaSupport { } } -#[cfg(feature = "wgpu")] +/// Errors that can occur in vello. #[derive(Error, Debug)] -pub enum RendererError { +pub enum VelloError { + /// Error when vello couldn't find a wgpu device with suitable features. + #[cfg(feature = "wgpu")] + #[error("Couldn't find suitable device")] + CouldntFindSuitableDevice, + /// Error when wgpu failed to create a surface. + /// See [`wgpu::CreateSurfaceError`] for more information. + #[cfg(feature = "wgpu")] + #[error("Couldn't create wgpu surface")] + WgpuCreateSurfaceError(#[from] wgpu::CreateSurfaceError), + /// Error when vello couldn't find [`TextureFormat::Rgba8Unorm`] or [`TextureFormat::Bgra8Unorm`] for your surface. + /// Make sure that you have a surface which provides one of those texture formats. + #[cfg(feature = "wgpu")] + #[error("Couldn't find `Rgba8Unorm` or `Bgra8Unorm` texture formats for surface")] + UnsupportedSurfaceFormat, + + /// Error when using a buffer inside a recording while it's not available. + /// Check if you have created it and not freed before its last usage. + #[cfg(feature = "wgpu")] + #[error("Buffer '{0}' is not available but used for {1}")] + UnavailableBufferUsed(&'static str, &'static str), + /// Error when trying to async map a buffer. + /// See [`wgpu::BufferAsyncError`] for more information. + #[cfg(feature = "wgpu")] + #[error(transparent)] + BufferAsyncError(#[from] wgpu::BufferAsyncError), + + /// Error when creating [`GpuProfiler`]. + /// See [`wgpu_profiler::CreationError`] for more information. #[cfg(feature = "wgpu-profiler")] - #[error("couldn't create wgpu profiler")] + #[error("Couldn't create wgpu profiler")] ProfilerCreationError(#[from] wgpu_profiler::CreationError), } -#[cfg(feature = "wgpu")] -#[derive(Error, Debug)] -pub enum RenderError { - #[error("error while run recording")] - WgpuRecordingError(#[from] WgpuRecordingError), -} - -#[cfg(feature = "wgpu")] -#[derive(Error, Debug)] -pub enum AsyncRenderError { - #[error("error while run recording")] - WgpuRecordingError(#[from] WgpuRecordingError), - #[error(transparent)] - BufferAsyncError(#[from] wgpu::BufferAsyncError), - #[error("channel was closed")] - ChannelWasClosed, -} +pub(crate) type VResult = Result; /// Renders a scene into a texture or surface. #[cfg(feature = "wgpu")] @@ -272,7 +284,7 @@ pub struct RendererOptions { #[cfg(feature = "wgpu")] impl Renderer { /// Creates a new renderer for the specified device. - pub fn new(device: &Device, options: RendererOptions) -> Result { + pub fn new(device: &Device, options: RendererOptions) -> VResult { let mut engine = WgpuEngine::new(options.use_cpu); // If we are running in parallel (i.e. the number of threads is not 1) if options.num_init_threads != NonZeroUsize::new(1) { @@ -315,7 +327,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> Result<(), RenderError> { + ) -> VResult<()> { let (recording, target) = render::render_full(scene, &mut self.resolver, &self.shaders, params); let external_resources = [ExternalResource::Image( @@ -349,7 +361,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> Result<(), RenderError> { + ) -> VResult<()> { let width = params.width; let height = params.height; let mut target = self @@ -453,7 +465,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> Result, AsyncRenderError> { + ) -> VResult> { let mut render = Render::new(); let encoding = scene.encoding(); // TODO: turn this on; the download feature interacts with CPU dispatch @@ -482,11 +494,7 @@ impl Renderer { let buf_slice = bump_buf.slice(..); let (sender, receiver) = futures_intrusive::channel::shared::oneshot_channel(); buf_slice.map_async(wgpu::MapMode::Read, move |v| sender.send(v).unwrap()); - if let Some(recv_result) = receiver.receive().await { - recv_result?; - } else { - return Err(AsyncRenderError::ChannelWasClosed); - } + receiver.receive().await.expect("channel was closed")?; let mapped = buf_slice.get_mapped_range(); bump = Some(bytemuck::pod_read_unaligned(&mapped)); } @@ -517,7 +525,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> Result, AsyncRenderError> { + ) -> VResult> { let width = params.width; let height = params.height; let mut target = self diff --git a/src/util.rs b/src/util.rs index c70d48f04..7572ddeb0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -5,12 +5,13 @@ use std::future::Future; -use thiserror::Error; use wgpu::{ Adapter, Device, Instance, Limits, Queue, Surface, SurfaceConfiguration, SurfaceTarget, TextureFormat, }; +use crate::{VResult, VelloError}; + /// Simple render context that maintains wgpu state for rendering the pipeline. pub struct RenderContext { pub instance: Instance, @@ -23,14 +24,6 @@ pub struct DeviceHandle { pub queue: Queue, } -#[derive(Error, Debug)] -pub enum SurfaceCreationError { - #[error("Error creating device")] - CantCreateDevice, - #[error(transparent)] - WgpuSurface(#[from] wgpu::CreateSurfaceError), -} - impl Default for RenderContext { fn default() -> Self { Self::new() @@ -58,12 +51,12 @@ impl RenderContext { width: u32, height: u32, present_mode: wgpu::PresentMode, - ) -> Result, SurfaceCreationError> { + ) -> VResult> { let surface = self.instance.create_surface(window.into())?; let dev_id = self .device(Some(&surface)) .await - .ok_or(SurfaceCreationError::CantCreateDevice)?; + .ok_or(VelloError::CouldntFindSuitableDevice)?; let device_handle = &self.devices[dev_id]; let capabilities = surface.get_capabilities(&device_handle.adapter); @@ -71,7 +64,7 @@ impl RenderContext { .formats .into_iter() .find(|it| matches!(it, TextureFormat::Rgba8Unorm | TextureFormat::Bgra8Unorm)) - .expect("surface should support Rgba8Unorm or Bgra8Unorm"); + .ok_or(VelloError::UnsupportedSurfaceFormat)?; let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, diff --git a/src/wgpu_engine.rs b/src/wgpu_engine.rs index 1e1f41eb3..baf26100b 100644 --- a/src/wgpu_engine.rs +++ b/src/wgpu_engine.rs @@ -8,7 +8,6 @@ use std::collections::{HashMap, HashSet}; use vello_shaders::cpu::CpuBinding; -use thiserror::Error; use wgpu::{ BindGroup, BindGroupLayout, Buffer, BufferUsages, CommandEncoder, CommandEncoderDescriptor, ComputePipeline, Device, PipelineCompilationOptions, Queue, Texture, TextureAspect, @@ -17,8 +16,8 @@ use wgpu::{ use crate::recording::BindType; use crate::{ - cpu_dispatch::CpuBinding, recording::BindType, BufferProxy, Command, Error, ImageProxy, - Recording, ResourceId, ResourceProxy, ShaderId, + recording::BindType, BufferProxy, Command, ImageProxy, + Recording, ResourceId, ResourceProxy, ShaderId, VResult, VelloError, }; #[cfg(not(target_arch = "wasm32"))] @@ -134,14 +133,6 @@ enum TransientBuf<'a> { Gpu(&'a Buffer), } -#[derive(Error, Debug)] -pub enum WgpuRecordingError { - #[error("buffer for indirect dispatch not in map")] - IndirectDispatchBufferNotInMap, - #[error("buffer for download not in map")] - DownloadBufferNotInMap, -} - impl WgpuEngine { pub fn new(use_cpu: bool) -> WgpuEngine { Self { @@ -355,7 +346,7 @@ impl WgpuEngine { external_resources: &[ExternalResource], label: &'static str, #[cfg(feature = "wgpu-profiler")] profiler: &mut wgpu_profiler::GpuProfiler, - ) -> Result<(), WgpuRecordingError> { + ) -> VResult<()> { let mut free_bufs: HashSet = Default::default(); let mut free_images: HashSet = Default::default(); let mut transient_map = TransientBindMap::new(external_resources); @@ -550,10 +541,9 @@ impl WgpuEngine { .with_parent(Some(&query)); cpass.set_pipeline(&wgpu_shader.pipeline); cpass.set_bind_group(0, &bind_group, &[]); - let buf = self - .bind_map - .get_gpu_buf(proxy.id) - .ok_or(WgpuRecordingError::IndirectDispatchBufferNotInMap)?; + let buf = self.bind_map.get_gpu_buf(proxy.id).ok_or( + VelloError::UnavailableBufferUsed(proxy.name, "indirect dispatch"), + )?; cpass.dispatch_workgroups_indirect(buf, *offset); #[cfg(feature = "wgpu-profiler")] profiler.end_query(&mut cpass, query); @@ -564,7 +554,7 @@ impl WgpuEngine { let src_buf = self .bind_map .get_gpu_buf(proxy.id) - .ok_or(WgpuRecordingError::DownloadBufferNotInMap)?; + .ok_or(VelloError::UnavailableBufferUsed(proxy.name, "download"))?; let usage = BufferUsages::MAP_READ | BufferUsages::COPY_DST; let buf = self.pool.get_buf(proxy.size, "download", usage, device); encoder.copy_buffer_to_buffer(src_buf, 0, &buf, 0, proxy.size); From 4a625c800793352d1660596a9fa35c042dd35294 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sun, 10 Mar 2024 11:54:29 +0100 Subject: [PATCH 06/17] don't put `thiserror::Error` behind feature flag --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ca0035fc2..ed109cdee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,6 @@ pub mod util; pub use render::Render; pub use scene::{DrawGlyphs, Scene}; -#[cfg(feature = "wgpu")] use thiserror::Error; #[cfg(feature = "wgpu")] pub use util::block_on_wgpu; From 7cf372c8e53fba641e0916259299cfca823ed630 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Sun, 10 Mar 2024 11:59:50 +0100 Subject: [PATCH 07/17] make `VResult` allow dead code --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index ed109cdee..3bcc37065 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,6 +214,7 @@ pub enum VelloError { ProfilerCreationError(#[from] wgpu_profiler::CreationError), } +#[allow(dead_code)] pub(crate) type VResult = Result; /// Renders a scene into a texture or surface. From d4c78e0b32ac68837d2522461bf8d2e5c376c56b Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 11 Mar 2024 15:15:39 +0100 Subject: [PATCH 08/17] rename `VResult` to `Result` --- src/lib.rs | 12 ++++++------ src/util.rs | 4 ++-- src/wgpu_engine.rs | 7 +++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3bcc37065..fe1325d82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,7 +215,7 @@ pub enum VelloError { } #[allow(dead_code)] -pub(crate) type VResult = Result; +pub(crate) type Result = std::result::Result; /// Renders a scene into a texture or surface. #[cfg(feature = "wgpu")] @@ -284,7 +284,7 @@ pub struct RendererOptions { #[cfg(feature = "wgpu")] impl Renderer { /// Creates a new renderer for the specified device. - pub fn new(device: &Device, options: RendererOptions) -> VResult { + pub fn new(device: &Device, options: RendererOptions) -> Result { let mut engine = WgpuEngine::new(options.use_cpu); // If we are running in parallel (i.e. the number of threads is not 1) if options.num_init_threads != NonZeroUsize::new(1) { @@ -327,7 +327,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> VResult<()> { + ) -> Result<()> { let (recording, target) = render::render_full(scene, &mut self.resolver, &self.shaders, params); let external_resources = [ExternalResource::Image( @@ -361,7 +361,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> VResult<()> { + ) -> Result<()> { let width = params.width; let height = params.height; let mut target = self @@ -465,7 +465,7 @@ impl Renderer { scene: &Scene, texture: &TextureView, params: &RenderParams, - ) -> VResult> { + ) -> Result> { let mut render = Render::new(); let encoding = scene.encoding(); // TODO: turn this on; the download feature interacts with CPU dispatch @@ -525,7 +525,7 @@ impl Renderer { scene: &Scene, surface: &SurfaceTexture, params: &RenderParams, - ) -> VResult> { + ) -> Result> { let width = params.width; let height = params.height; let mut target = self diff --git a/src/util.rs b/src/util.rs index 7572ddeb0..9804b1e0b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,7 @@ use wgpu::{ TextureFormat, }; -use crate::{VResult, VelloError}; +use crate::{Result, VelloError}; /// Simple render context that maintains wgpu state for rendering the pipeline. pub struct RenderContext { @@ -51,7 +51,7 @@ impl RenderContext { width: u32, height: u32, present_mode: wgpu::PresentMode, - ) -> VResult> { + ) -> Result> { let surface = self.instance.create_surface(window.into())?; let dev_id = self .device(Some(&surface)) diff --git a/src/wgpu_engine.rs b/src/wgpu_engine.rs index baf26100b..627065222 100644 --- a/src/wgpu_engine.rs +++ b/src/wgpu_engine.rs @@ -14,10 +14,9 @@ use wgpu::{ TextureUsages, TextureView, TextureViewDimension, }; -use crate::recording::BindType; use crate::{ - recording::BindType, BufferProxy, Command, ImageProxy, - Recording, ResourceId, ResourceProxy, ShaderId, VResult, VelloError, + recording::BindType, BufferProxy, Command, ImageProxy, Recording, ResourceId, + ResourceProxy, Result, ShaderId, VelloError, }; #[cfg(not(target_arch = "wasm32"))] @@ -346,7 +345,7 @@ impl WgpuEngine { external_resources: &[ExternalResource], label: &'static str, #[cfg(feature = "wgpu-profiler")] profiler: &mut wgpu_profiler::GpuProfiler, - ) -> VResult<()> { + ) -> Result<()> { let mut free_bufs: HashSet = Default::default(); let mut free_images: HashSet = Default::default(); let mut transient_map = TransientBindMap::new(external_resources); From 30353a16870cd6018f8738deb05240f9df47e9f3 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 16:09:41 +0200 Subject: [PATCH 09/17] Update Cargo.lock --- Cargo.lock | 81 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 837d8284b..f40f4a41b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arrayref" @@ -296,7 +296,7 @@ checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -351,9 +351,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" dependencies = [ "jobserver", "libc", @@ -415,7 +415,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -561,18 +561,18 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.12" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crossterm" @@ -792,7 +792,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -1149,9 +1149,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if", "js-sys", @@ -1272,9 +1272,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -1309,9 +1309,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "litrs" @@ -1376,9 +1376,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", "simd-adler32", @@ -1521,7 +1521,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -1681,7 +1681,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -1753,9 +1753,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" dependencies = [ "unicode-ident", ] @@ -1777,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -1836,9 +1836,9 @@ checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" [[package]] name = "raw-window-handle" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc3bcbdb1ddfc11e700e62968e6b4cc9c75bb466464ad28fb61c5b2c964418b" +checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" [[package]] name = "read-fonts" @@ -1978,9 +1978,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" -version = "0.102.3" +version = "0.102.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3bce581c0dd41bce533ce695a1437fa16a7ab5ac3ccfa99fe1a620a7885eabf" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" dependencies = [ "ring", "rustls-pki-types", @@ -2061,7 +2061,7 @@ checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -2263,9 +2263,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" dependencies = [ "proc-macro2", "quote", @@ -2295,22 +2295,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -2400,7 +2400,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] @@ -2547,6 +2547,7 @@ dependencies = [ "raw-window-handle", "skrifa", "static_assertions", + "thiserror", "vello_encoding", "vello_shaders", "wgpu", @@ -2657,7 +2658,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", "wasm-bindgen-shared", ] @@ -2723,7 +2724,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3478,7 +3479,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.65", ] [[package]] From c743fb278f960afbf083eaac6aa9a97f09a1d0cd Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 16:33:32 +0200 Subject: [PATCH 10/17] better docs --- src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe1325d82..8102592b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,33 +181,34 @@ impl FromIterator for AaSupport { /// Errors that can occur in vello. #[derive(Error, Debug)] pub enum VelloError { - /// Error when vello couldn't find a wgpu device with suitable features. + /// There is no available device with the features required by Vello. #[cfg(feature = "wgpu")] #[error("Couldn't find suitable device")] CouldntFindSuitableDevice, - /// Error when wgpu failed to create a surface. + /// Failed to create surface. /// See [`wgpu::CreateSurfaceError`] for more information. #[cfg(feature = "wgpu")] #[error("Couldn't create wgpu surface")] WgpuCreateSurfaceError(#[from] wgpu::CreateSurfaceError), - /// Error when vello couldn't find [`TextureFormat::Rgba8Unorm`] or [`TextureFormat::Bgra8Unorm`] for your surface. - /// Make sure that you have a surface which provides one of those texture formats. + /// Surface doesn't support the required texture formats. + /// Make sure that you have a surface which provides one of + /// [`TextureFormat::Rgba8Unorm`] or [`TextureFormat::Bgra8Unorm`] as texture formats. #[cfg(feature = "wgpu")] #[error("Couldn't find `Rgba8Unorm` or `Bgra8Unorm` texture formats for surface")] UnsupportedSurfaceFormat, - /// Error when using a buffer inside a recording while it's not available. + /// Used a buffer inside a recording while it was not available. /// Check if you have created it and not freed before its last usage. #[cfg(feature = "wgpu")] #[error("Buffer '{0}' is not available but used for {1}")] UnavailableBufferUsed(&'static str, &'static str), - /// Error when trying to async map a buffer. + /// Failed to async map a buffer. /// See [`wgpu::BufferAsyncError`] for more information. #[cfg(feature = "wgpu")] - #[error(transparent)] + #[error("Failed to async map a buffer")] BufferAsyncError(#[from] wgpu::BufferAsyncError), - /// Error when creating [`GpuProfiler`]. + /// Failed to create [`GpuProfiler`]. /// See [`wgpu_profiler::CreationError`] for more information. #[cfg(feature = "wgpu-profiler")] #[error("Couldn't create wgpu profiler")] From f51e0c988dd22d95002dd764088e1d6cd8554535 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 16:34:14 +0200 Subject: [PATCH 11/17] Rename to `NoCompatibleDevice` --- src/lib.rs | 2 +- src/util.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8102592b7..3f6b660a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,7 +184,7 @@ pub enum VelloError { /// There is no available device with the features required by Vello. #[cfg(feature = "wgpu")] #[error("Couldn't find suitable device")] - CouldntFindSuitableDevice, + NoCompatibleDevice, /// Failed to create surface. /// See [`wgpu::CreateSurfaceError`] for more information. #[cfg(feature = "wgpu")] diff --git a/src/util.rs b/src/util.rs index 9804b1e0b..1a77cc755 100644 --- a/src/util.rs +++ b/src/util.rs @@ -56,7 +56,7 @@ impl RenderContext { let dev_id = self .device(Some(&surface)) .await - .ok_or(VelloError::CouldntFindSuitableDevice)?; + .ok_or(VelloError::NoCompatibleDevice)?; let device_handle = &self.devices[dev_id]; let capabilities = surface.get_capabilities(&device_handle.adapter); From 07c3e4c5aa8a2a0ff7dfb0ff256d362a5d41640a Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 16:36:23 +0200 Subject: [PATCH 12/17] make fmt happy --- src/wgpu_engine.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wgpu_engine.rs b/src/wgpu_engine.rs index 627065222..2b14d5ff1 100644 --- a/src/wgpu_engine.rs +++ b/src/wgpu_engine.rs @@ -15,8 +15,8 @@ use wgpu::{ }; use crate::{ - recording::BindType, BufferProxy, Command, ImageProxy, Recording, ResourceId, - ResourceProxy, Result, ShaderId, VelloError, + recording::BindType, BufferProxy, Command, ImageProxy, Recording, ResourceId, ResourceProxy, + Result, ShaderId, VelloError, }; #[cfg(not(target_arch = "wasm32"))] From 44c6d2e8f8e7f8d7d621d3146e577de53f827245 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 20:14:36 +0200 Subject: [PATCH 13/17] cleanup --- src/lib.rs | 1 - src/util.rs | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3f6b660a1..ebb7caf3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,7 +215,6 @@ pub enum VelloError { ProfilerCreationError(#[from] wgpu_profiler::CreationError), } -#[allow(dead_code)] pub(crate) type Result = std::result::Result; /// Renders a scene into a texture or surface. diff --git a/src/util.rs b/src/util.rs index 1a77cc755..6fb45ee5e 100644 --- a/src/util.rs +++ b/src/util.rs @@ -24,12 +24,6 @@ pub struct DeviceHandle { pub queue: Queue, } -impl Default for RenderContext { - fn default() -> Self { - Self::new() - } -} - impl RenderContext { #[allow(clippy::new_without_default)] pub fn new() -> Self { From 67139bd63bdfab218157ea0c7a0acc39810b891e Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 13 May 2024 20:25:16 +0200 Subject: [PATCH 14/17] fix clippy --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index ebb7caf3a..768c12bfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,6 +215,7 @@ pub enum VelloError { ProfilerCreationError(#[from] wgpu_profiler::CreationError), } +#[allow(dead_code)] // this can be unused when wgpu feature is not used pub(crate) type Result = std::result::Result; /// Renders a scene into a texture or surface. From f21cefbeabb7f6c775b166ed8c3e7ab5bd681a74 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 20 May 2024 09:49:23 +0200 Subject: [PATCH 15/17] Make `VelloError` non-exhaustive --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 768c12bfc..aec4d26c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,6 +180,7 @@ impl FromIterator for AaSupport { /// Errors that can occur in vello. #[derive(Error, Debug)] +#[non_exhaustive] pub enum VelloError { /// There is no available device with the features required by Vello. #[cfg(feature = "wgpu")] From 8922d818902e817c3a8136a9aec86eaedbf0fc37 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Thu, 30 May 2024 19:27:47 +0300 Subject: [PATCH 16/17] Fix broken `Cargo.lock`. --- Cargo.lock | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89ad95e5e..782e1dd42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1831,37 +1831,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" - -[[package]] -name = "rustls-webpki" -version = "0.102.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - [[package]] name = "ryu" version = "1.0.18" From f1a72816032d66d83d202e3f057409c1c111983e Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Thu, 30 May 2024 19:39:11 +0300 Subject: [PATCH 17/17] Rename `VelloError` to `Error`. --- src/lib.rs | 6 +++--- src/util.rs | 6 +++--- src/wgpu_engine.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aec4d26c4..43bf435b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -178,10 +178,10 @@ impl FromIterator for AaSupport { } } -/// Errors that can occur in vello. +/// Errors that can occur in Vello. #[derive(Error, Debug)] #[non_exhaustive] -pub enum VelloError { +pub enum Error { /// There is no available device with the features required by Vello. #[cfg(feature = "wgpu")] #[error("Couldn't find suitable device")] @@ -217,7 +217,7 @@ pub enum VelloError { } #[allow(dead_code)] // this can be unused when wgpu feature is not used -pub(crate) type Result = std::result::Result; +pub(crate) type Result = std::result::Result; /// Renders a scene into a texture or surface. #[cfg(feature = "wgpu")] diff --git a/src/util.rs b/src/util.rs index 6fb45ee5e..0ae8e2c4f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,7 @@ use wgpu::{ TextureFormat, }; -use crate::{Result, VelloError}; +use crate::{Error, Result}; /// Simple render context that maintains wgpu state for rendering the pipeline. pub struct RenderContext { @@ -50,7 +50,7 @@ impl RenderContext { let dev_id = self .device(Some(&surface)) .await - .ok_or(VelloError::NoCompatibleDevice)?; + .ok_or(Error::NoCompatibleDevice)?; let device_handle = &self.devices[dev_id]; let capabilities = surface.get_capabilities(&device_handle.adapter); @@ -58,7 +58,7 @@ impl RenderContext { .formats .into_iter() .find(|it| matches!(it, TextureFormat::Rgba8Unorm | TextureFormat::Bgra8Unorm)) - .ok_or(VelloError::UnsupportedSurfaceFormat)?; + .ok_or(Error::UnsupportedSurfaceFormat)?; let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, diff --git a/src/wgpu_engine.rs b/src/wgpu_engine.rs index 2b14d5ff1..c175f0d7a 100644 --- a/src/wgpu_engine.rs +++ b/src/wgpu_engine.rs @@ -15,8 +15,8 @@ use wgpu::{ }; use crate::{ - recording::BindType, BufferProxy, Command, ImageProxy, Recording, ResourceId, ResourceProxy, - Result, ShaderId, VelloError, + recording::BindType, BufferProxy, Command, Error, ImageProxy, Recording, ResourceId, + ResourceProxy, Result, ShaderId, }; #[cfg(not(target_arch = "wasm32"))] @@ -541,7 +541,7 @@ impl WgpuEngine { cpass.set_pipeline(&wgpu_shader.pipeline); cpass.set_bind_group(0, &bind_group, &[]); let buf = self.bind_map.get_gpu_buf(proxy.id).ok_or( - VelloError::UnavailableBufferUsed(proxy.name, "indirect dispatch"), + Error::UnavailableBufferUsed(proxy.name, "indirect dispatch"), )?; cpass.dispatch_workgroups_indirect(buf, *offset); #[cfg(feature = "wgpu-profiler")] @@ -553,7 +553,7 @@ impl WgpuEngine { let src_buf = self .bind_map .get_gpu_buf(proxy.id) - .ok_or(VelloError::UnavailableBufferUsed(proxy.name, "download"))?; + .ok_or(Error::UnavailableBufferUsed(proxy.name, "download"))?; let usage = BufferUsages::MAP_READ | BufferUsages::COPY_DST; let buf = self.pool.get_buf(proxy.size, "download", usage, device); encoder.copy_buffer_to_buffer(src_buf, 0, &buf, 0, proxy.size);