vello_gpu: Tidy up the shared renderer core
diff --git a/vello_gpu/src/render/common/core.rs b/vello_gpu/src/render/common/core.rs index a194bef..7f6fd96 100644 --- a/vello_gpu/src/render/common/core.rs +++ b/vello_gpu/src/render/common/core.rs
@@ -3,10 +3,10 @@ //! Renderer state and steps shared by all backends. -use super::{ - DeviceLimits, GpuEncodedPaint, GpuLinearGradient, ScratchBuffers, - encode_blurred_rounded_rect_paint, encode_gradient_paint, encode_image_paint, +use super::paint::{ + GpuEncodedPaint, encode_blurred_rounded_rect_paint, encode_gradient_paint, encode_image_paint, }; +use super::{DeviceLimits, ScratchBuffers}; use crate::{ LayersConfig, RenderError, RenderSettings, Resources, gradient_cache::GradientRampCache, @@ -22,17 +22,10 @@ use vello_common::image_cache::ImageCache; use vello_common::paint::{ImageSource, TextureRegion}; -/// Placeholder value for uninitialized GPU encoded paints. -const GPU_PAINT_PLACEHOLDER: GpuEncodedPaint = GpuEncodedPaint::LinearGradient(GpuLinearGradient { - texture_width_and_extend_mode: 0, - gradient_start: 0, - transform: [0.0; 6], -}); - /// Renderer state that doesn't depend on the backend. #[derive(Debug)] pub(crate) struct Core { - /// Encoded paints for storing encoded paints. + /// GPU encodings of the scene's encoded paints, in the same order. pub(crate) encoded_paints: Vec<GpuEncodedPaint>, /// Stores the index (offset) of the encoded paints in the encoded paints texture. pub(crate) paint_idxs: Vec<u32>, @@ -75,19 +68,19 @@ /// Encodes `encoded_paints` for the GPU. /// /// `encode_external_texture` encodes image paints that sample an external texture, given the - /// image, the texture and the sampled region of it. + /// texture, the image and the sampled region of the texture. pub(crate) fn prepare_paints( &mut self, encoded_paints: &[EncodedPaint], image_cache: &ImageCache, mut encode_external_texture: impl FnMut( - &EncodedImage, TextureId, + &EncodedImage, TextureRegion, ) -> Result<GpuEncodedPaint, RenderError>, ) -> Result<(), RenderError> { self.encoded_paints - .resize_with(encoded_paints.len(), || GPU_PAINT_PLACEHOLDER); + .resize_with(encoded_paints.len(), || GpuEncodedPaint::PLACEHOLDER); self.paint_idxs.resize(encoded_paints.len() + 1, 0); let mut current_idx = 0; @@ -102,7 +95,7 @@ } ImageSource::ExternalTexture { id, source_region, .. - } => encode_external_texture(img, *id, *source_region)?, + } => encode_external_texture(*id, img, *source_region)?, ImageSource::Pixmap(_) => { panic!("pixmap image sources are not supported by Vello GPU") }
diff --git a/vello_gpu/src/render/common/mod.rs b/vello_gpu/src/render/common/mod.rs index 201b8a1..863d9f5 100644 --- a/vello_gpu/src/render/common/mod.rs +++ b/vello_gpu/src/render/common/mod.rs
@@ -9,10 +9,7 @@ pub(crate) use self::core::Core; #[cfg(all(feature = "wgpu", feature = "wgpu_external_texture"))] pub(crate) use paint::encode_wgpu_external_texture_paint; -pub(crate) use paint::{ - GpuEncodedPaint, GpuLinearGradient, encode_blurred_rounded_rect_paint, - encode_external_texture_paint, encode_gradient_paint, encode_image_paint, -}; +pub(crate) use paint::{GpuEncodedPaint, encode_external_texture_paint}; use crate::IntermediateTextureError; use crate::blend::GpuBlendInstance;
diff --git a/vello_gpu/src/render/common/paint.rs b/vello_gpu/src/render/common/paint.rs index 73482b3..eedf3ae 100644 --- a/vello_gpu/src/render/common/paint.rs +++ b/vello_gpu/src/render/common/paint.rs
@@ -49,6 +49,13 @@ } impl GpuEncodedPaint { + /// Placeholder value for uninitialized GPU encoded paints. + pub(crate) const PLACEHOLDER: Self = Self::LinearGradient(GpuLinearGradient { + texture_width_and_extend_mode: 0, + gradient_start: 0, + transform: [0.0; 6], + }); + const IMAGE_TEXELS: u32 = texels::<GpuEncodedImage>(); const NATIVE_IMAGE_TEXELS: u32 = texels::<GpuNativeImage>(); const LINEAR_TEXELS: u32 = texels::<GpuLinearGradient>();
diff --git a/vello_gpu/src/render/webgl/mod.rs b/vello_gpu/src/render/webgl/mod.rs index 01b03fe..997d366 100644 --- a/vello_gpu/src/render/webgl/mod.rs +++ b/vello_gpu/src/render/webgl/mod.rs
@@ -72,6 +72,7 @@ WebGlFragmentShader, WebGlVertexShader, }; use vello_common::color::{AlphaColor, Srgb}; +use vello_common::encode::EncodedImage; use vello_common::image_cache::ImageCache; use vello_common::multi_atlas::{AtlasConfig, AtlasId}; use vello_common::{ @@ -112,10 +113,6 @@ /// Result of polling WebGL renderer initialization. #[derive(Debug)] -#[allow( - clippy::large_enum_variant, - reason = "both variants are one-shot ownership transfers; boxing would add unnecessary allocation" -)] pub enum WebGlRendererInitStatus { /// Shader compilation or program linking is still in progress. Pending(WebGlRendererInit), @@ -227,7 +224,7 @@ fn encode_paint( &self, texture_id: TextureId, - image: &vello_common::encode::EncodedImage, + image: &EncodedImage, source_region: TextureRegion, render_target: Option<&WebGlTexture>, ) -> Result<GpuEncodedPaint, RenderError> { @@ -845,7 +842,7 @@ let use_depth_buffer = self.programs.resources.root_uses_depth_buffer(); self.core - .prepare_paints(&scene.encoded_paints, image_cache, |image, id, region| { + .prepare_paints(&scene.encoded_paints, image_cache, |id, image, region| { texture_bindings.encode_paint(id, image, region, render_target_texture) })?; let current_allocations = self.current_allocations();
diff --git a/vello_gpu/src/render/wgpu/mod.rs b/vello_gpu/src/render/wgpu/mod.rs index 9722ef5..de38f95 100644 --- a/vello_gpu/src/render/wgpu/mod.rs +++ b/vello_gpu/src/render/wgpu/mod.rs
@@ -47,6 +47,7 @@ use glifo::PendingClearRect; use hashbrown::{HashMap, hash_map::Entry}; use vello_common::color::{AlphaColor, Srgb}; +use vello_common::encode::EncodedImage; use vello_common::image_cache::ImageCache; use vello_common::multi_atlas::{AtlasConfig, AtlasId}; use vello_common::{ @@ -194,7 +195,7 @@ fn encode_paint( &self, texture_id: TextureId, - image: &vello_common::encode::EncodedImage, + image: &EncodedImage, source_region: TextureRegion, render_target: &Texture, ) -> Result<GpuEncodedPaint, RenderError> { @@ -510,7 +511,7 @@ ) -> Result<(), RenderError> { self.programs.depth_cleared_this_frame = false; self.core - .prepare_paints(&scene.encoded_paints, image_cache, |image, id, region| { + .prepare_paints(&scene.encoded_paints, image_cache, |id, image, region| { texture_bindings.encode_paint(id, image, region, view.texture()) })?; let current_allocations = self.current_allocations();