From 7cb7bb68a99c62b8d02738757de47828b82b2b51 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Sun, 26 Jan 2025 15:58:45 -0700 Subject: [PATCH] nv2a: Multiversion [un]swizzle to optimize for common bpp --- hw/xbox/nv2a/pgraph/swizzle.c | 38 +++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/hw/xbox/nv2a/pgraph/swizzle.c b/hw/xbox/nv2a/pgraph/swizzle.c index 1bdecd41f5..fe71bc4704 100644 --- a/hw/xbox/nv2a/pgraph/swizzle.c +++ b/hw/xbox/nv2a/pgraph/swizzle.c @@ -4,6 +4,7 @@ * Copyright (c) 2015 Jannik Vogel * Copyright (c) 2013 espes * Copyright (c) 2007-2010 The Nouveau Project. + * Copyright (c) 2025 Matt Borgerson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -68,7 +69,7 @@ static void generate_swizzle_masks(unsigned int width, *mask_z = z; } -void swizzle_box( +static inline void swizzle_box_internal( const uint8_t *src_buf, unsigned int width, unsigned int height, @@ -114,7 +115,7 @@ void swizzle_box( } } -void unswizzle_box( +static inline void unswizzle_box_internal( const uint8_t *src_buf, unsigned int width, unsigned int height, @@ -148,3 +149,36 @@ void unswizzle_box( off_z = (off_z - mask_z) & mask_z; } } + +/* Multiversioned to optimize for common bytes_per_pixel */ \ +#define C(m, bpp) \ + m##_internal(src_buf, width, height, depth, dst_buf, row_pitch, \ + slice_pitch, bpp) +#define MULTIVERSION(m) \ + void m(const uint8_t *src_buf, unsigned int width, unsigned int height, \ + unsigned int depth, uint8_t *dst_buf, unsigned int row_pitch, \ + unsigned int slice_pitch, unsigned int bytes_per_pixel) \ + { \ + switch (bytes_per_pixel) { \ + case 1: \ + C(m, 1); \ + break; \ + case 2: \ + C(m, 2); \ + break; \ + case 3: \ + C(m, 3); \ + break; \ + case 4: \ + C(m, 4); \ + break; \ + default: \ + C(m, bytes_per_pixel); \ + } \ + } + +MULTIVERSION(swizzle_box) +MULTIVERSION(unswizzle_box) + +#undef C +#undef MULTIVERSION