Skip to content

Commit

Permalink
runtime: fix image swizzle for remainder
Browse files Browse the repository at this point in the history
  • Loading branch information
chyyran committed Aug 22, 2024
1 parent af05cc5 commit b7fd3bc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion librashader-runtime/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl<P: PixelFormat> Image<P> {
}
}

// load-bearing #[inline(always)], without it llvm will not vectorize.
#[inline(always)]
fn swizzle_pixels(pixels: &mut Vec<u8>, swizzle: &'static [usize; 32]) {
assert!(pixels.len() % 4 == 0);
let mut chunks = pixels.chunks_exact_mut(32);
Expand All @@ -104,7 +106,12 @@ fn swizzle_pixels(pixels: &mut Vec<u8>, 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[..])
}
}
Expand Down

0 comments on commit b7fd3bc

Please sign in to comment.