Skip to content

Commit 7cb7bb6

Browse files
committed
nv2a: Multiversion [un]swizzle to optimize for common bpp
1 parent eae328d commit 7cb7bb6

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

hw/xbox/nv2a/pgraph/swizzle.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2015 Jannik Vogel
55
* Copyright (c) 2013 espes
66
* Copyright (c) 2007-2010 The Nouveau Project.
7+
* Copyright (c) 2025 Matt Borgerson
78
*
89
* This library is free software; you can redistribute it and/or
910
* modify it under the terms of the GNU Lesser General Public
@@ -68,7 +69,7 @@ static void generate_swizzle_masks(unsigned int width,
6869
*mask_z = z;
6970
}
7071

71-
void swizzle_box(
72+
static inline void swizzle_box_internal(
7273
const uint8_t *src_buf,
7374
unsigned int width,
7475
unsigned int height,
@@ -114,7 +115,7 @@ void swizzle_box(
114115
}
115116
}
116117

117-
void unswizzle_box(
118+
static inline void unswizzle_box_internal(
118119
const uint8_t *src_buf,
119120
unsigned int width,
120121
unsigned int height,
@@ -148,3 +149,36 @@ void unswizzle_box(
148149
off_z = (off_z - mask_z) & mask_z;
149150
}
150151
}
152+
153+
/* Multiversioned to optimize for common bytes_per_pixel */ \
154+
#define C(m, bpp) \
155+
m##_internal(src_buf, width, height, depth, dst_buf, row_pitch, \
156+
slice_pitch, bpp)
157+
#define MULTIVERSION(m) \
158+
void m(const uint8_t *src_buf, unsigned int width, unsigned int height, \
159+
unsigned int depth, uint8_t *dst_buf, unsigned int row_pitch, \
160+
unsigned int slice_pitch, unsigned int bytes_per_pixel) \
161+
{ \
162+
switch (bytes_per_pixel) { \
163+
case 1: \
164+
C(m, 1); \
165+
break; \
166+
case 2: \
167+
C(m, 2); \
168+
break; \
169+
case 3: \
170+
C(m, 3); \
171+
break; \
172+
case 4: \
173+
C(m, 4); \
174+
break; \
175+
default: \
176+
C(m, bytes_per_pixel); \
177+
} \
178+
}
179+
180+
MULTIVERSION(swizzle_box)
181+
MULTIVERSION(unswizzle_box)
182+
183+
#undef C
184+
#undef MULTIVERSION

0 commit comments

Comments
 (0)