More tweaks
diff --git a/sparse_strips/vello_common/src/encode.rs b/sparse_strips/vello_common/src/encode.rs index 5161fe0..d9160ce 100644 --- a/sparse_strips/vello_common/src/encode.rs +++ b/sparse_strips/vello_common/src/encode.rs
@@ -985,6 +985,7 @@ impl FromF32Color for f32 { const ZERO: Self = 0.0; + #[inline(always)] fn from_f32<S: Simd>(color: f32x4<S>) -> [Self; 4] { color.into() } @@ -993,6 +994,7 @@ impl FromF32Color for u8 { const ZERO: Self = 0; + #[inline(always)] fn from_f32<S: Simd>(mut color: f32x4<S>) -> [Self; 4] { let simd = color.simd; color = color.mul_add(f32x4::splat(simd, 255.0), f32x4::splat(simd, 0.5)); @@ -1016,6 +1018,14 @@ impl<T: FromF32Color> GradientLut<T> { /// Create a new lookup table. fn new<S: Simd>(simd: S, ranges: &[GradientRange]) -> Self { + simd.vectorize( + #[inline(always)] + || Self::new_inner(simd, ranges), + ) + } + + #[inline(always)] + fn new_inner<S: Simd>(simd: S, ranges: &[GradientRange]) -> Self { let lut_size = determine_lut_size(ranges); let mut lut = vec![[T::ZERO; 4]; lut_size];
diff --git a/sparse_strips/vello_cpu/src/fine/highp/mod.rs b/sparse_strips/vello_cpu/src/fine/highp/mod.rs index eb2236a..eac28ca 100644 --- a/sparse_strips/vello_cpu/src/fine/highp/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/highp/mod.rs
@@ -162,28 +162,30 @@ painter.paint_f32(dest); } - #[inline(always)] fn apply_tint(simd: S, dest: &mut [Self::Numeric], tint: &Tint) { let premul = tint.color.premultiply(); let [r, g, b, a] = premul.components; - let tint_v = f32x16::block_splat(f32x4::from_slice(simd, &[r, g, b, a])); simd.vectorize( #[inline(always)] - || match tint.mode { - TintMode::AlphaMask => { - for chunk in dest.chunks_exact_mut(16) { - let pixel = f32x16::from_slice(simd, chunk); - let alphas = pixel.splat_4th(); - let tinted = tint_v * alphas; - tinted.store_slice(chunk); + || { + let tint_v = f32x16::block_splat(f32x4::from_slice(simd, &[r, g, b, a])); + + match tint.mode { + TintMode::AlphaMask => { + for chunk in dest.chunks_exact_mut(16) { + let pixel = f32x16::from_slice(simd, chunk); + let alphas = pixel.splat_4th(); + let tinted = tint_v * alphas; + tinted.store_slice(chunk); + } } - } - TintMode::Multiply => { - for chunk in dest.chunks_exact_mut(16) { - let pixel = f32x16::from_slice(simd, chunk); - let tinted = pixel * tint_v; - tinted.store_slice(chunk); + TintMode::Multiply => { + for chunk in dest.chunks_exact_mut(16) { + let pixel = f32x16::from_slice(simd, chunk); + let tinted = pixel * tint_v; + tinted.store_slice(chunk); + } } } },
diff --git a/sparse_strips/vello_cpu/src/fine/lowp/mod.rs b/sparse_strips/vello_cpu/src/fine/lowp/mod.rs index 3e9e88b..e6e8981 100644 --- a/sparse_strips/vello_cpu/src/fine/lowp/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/lowp/mod.rs
@@ -203,24 +203,27 @@ let [r, g, b, a] = premul.components; let to_u8 = |v: f32| (v * 255.0 + 0.5) as u8; let color = u32::from_ne_bytes([to_u8(r), to_u8(g), to_u8(b), to_u8(a)]); - let tint_v = u32x8::block_splat(u32x4::splat(simd, color)).to_bytes(); simd.vectorize( #[inline(always)] - || match tint.mode { - TintMode::AlphaMask => { - for chunk in dest.chunks_exact_mut(32) { - let pixel = u8x32::from_slice(simd, chunk); - let alphas = pixel.splat_4th(); - let tinted = tint_v.normalized_mul(alphas); - tinted.store_slice(chunk); + || { + let tint_v = u32x8::block_splat(u32x4::splat(simd, color)).to_bytes(); + + match tint.mode { + TintMode::AlphaMask => { + for chunk in dest.chunks_exact_mut(32) { + let pixel = u8x32::from_slice(simd, chunk); + let alphas = pixel.splat_4th(); + let tinted = tint_v.normalized_mul(alphas); + tinted.store_slice(chunk); + } } - } - TintMode::Multiply => { - for chunk in dest.chunks_exact_mut(32) { - let pixel = u8x32::from_slice(simd, chunk); - let tinted = pixel.normalized_mul(tint_v); - tinted.store_slice(chunk); + TintMode::Multiply => { + for chunk in dest.chunks_exact_mut(32) { + let pixel = u8x32::from_slice(simd, chunk); + let tinted = pixel.normalized_mul(tint_v); + tinted.store_slice(chunk); + } } } },
diff --git a/sparse_strips/vello_cpu/src/fine/mod.rs b/sparse_strips/vello_cpu/src/fine/mod.rs index c16c828..0a87abf 100644 --- a/sparse_strips/vello_cpu/src/fine/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/mod.rs
@@ -641,15 +641,12 @@ Cmd::Opacity(o) => { if *o != 1.0 { let blend_buf = self.blend_buf.last_mut().unwrap(); - - T::apply_mask( - self.simd, - blend_buf, - iter::repeat(T::NumericVec::from_f32( - self.simd, - f32x16::splat(self.simd, *o), - )), + let opacity = self.simd.vectorize( + #[inline(always)] + || T::NumericVec::from_f32(self.simd, f32x16::splat(self.simd, *o)), ); + + T::apply_mask(self.simd, blend_buf, iter::repeat(opacity)); } } Cmd::PushZeroClip(_) | Cmd::PopZeroClip => { @@ -704,13 +701,17 @@ } else { let start_x = self.wide_coords.0 * WideTile::WIDTH + x as u16; let start_y = self.wide_coords.1 * Tile::HEIGHT; + let src = self.simd.vectorize( + #[inline(always)] + || T::Composite::from_color(self.simd, color), + ); T::blend( self.simd, blend_buf, start_x, start_y, - iter::repeat(T::Composite::from_color(self.simd, color)), + iter::repeat(src), blend_mode, alphas, mask,