From b7fd3bc50722b1effe3be43d7d8356da2d2d6e8f Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 21 Aug 2024 20:11:22 -0400 Subject: [PATCH] runtime: fix image swizzle for remainder --- librashader-runtime/src/image.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/librashader-runtime/src/image.rs b/librashader-runtime/src/image.rs index 834e215..9794a40 100644 --- a/librashader-runtime/src/image.rs +++ b/librashader-runtime/src/image.rs @@ -92,6 +92,8 @@ impl Image

{ } } +// load-bearing #[inline(always)], without it llvm will not vectorize. +#[inline(always)] fn swizzle_pixels(pixels: &mut Vec, swizzle: &'static [usize; 32]) { assert!(pixels.len() % 4 == 0); let mut chunks = pixels.chunks_exact_mut(32); @@ -104,7 +106,12 @@ fn swizzle_pixels(pixels: &mut Vec, swizzle: &'static [usize; 32]) { let remainder = chunks.into_remainder(); for chunk in remainder.chunks_exact_mut(4) { - let argb = [chunk[3], chunk[0], chunk[1], chunk[2]]; + let argb = [ + chunk[swizzle[0]], + chunk[swizzle[1]], + chunk[swizzle[2]], + chunk[swizzle[3]], + ]; chunk.copy_from_slice(&argb[..]) } }