[Mesa-dev] [PATCH 1/2] mesa: make _mesa_swizzle_and_convert() static
Timothy Arceri
tarceri at itsqueeze.com
Thu Jun 15 05:26:16 UTC 2017
---
src/mesa/main/format_utils.c | 91 ++++++++++++++++++++++++--------------------
src/mesa/main/format_utils.h | 9 -----
2 files changed, 49 insertions(+), 51 deletions(-)
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index d16d69c..65e65d4 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -33,20 +33,27 @@ const mesa_array_format RGBA32_FLOAT =
const mesa_array_format RGBA8_UBYTE =
MESA_ARRAY_FORMAT(1, 0, 0, 1, 4, 0, 1, 2, 3);
const mesa_array_format RGBA32_UINT =
MESA_ARRAY_FORMAT(4, 0, 0, 0, 4, 0, 1, 2, 3);
const mesa_array_format RGBA32_INT =
MESA_ARRAY_FORMAT(4, 1, 0, 0, 4, 0, 1, 2, 3);
static void
+swizzle_and_convert(void *void_dst, enum mesa_array_format_datatype dst_type,
+ int num_dst_channels, const void *void_src,
+ enum mesa_array_format_datatype src_type,
+ int num_src_channels, const uint8_t swizzle[4],
+ bool normalized, int count);
+
+static void
invert_swizzle(uint8_t dst[4], const uint8_t src[4])
{
int i, j;
dst[0] = MESA_FORMAT_SWIZZLE_NONE;
dst[1] = MESA_FORMAT_SWIZZLE_NONE;
dst[2] = MESA_FORMAT_SWIZZLE_NONE;
dst[3] = MESA_FORMAT_SWIZZLE_NONE;
for (i = 0; i < 4; ++i)
@@ -408,23 +415,23 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
}
if (src_array_format && dst_array_format) {
assert(_mesa_array_format_is_normalized(src_array_format) ==
_mesa_array_format_is_normalized(dst_array_format));
compute_src2dst_component_mapping(src2rgba, rgba2dst, rebase_swizzle,
src2dst);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
- src, src_type, src_num_channels,
- src2dst, normalized, width);
+ swizzle_and_convert(dst, dst_type, dst_num_channels,
+ src, src_type, src_num_channels,
+ src2dst, normalized, width);
src += src_stride;
dst += dst_stride;
}
return;
}
/* At this point, we're fresh out of fast-paths and we need to convert
* to float, uint32, or, if we're lucky, uint8.
*/
dst_integer = false;
@@ -497,134 +504,134 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
* of the packed formats are unsigned, so we can just always use
* _mesa_swizzle_and_convert for signed formats, which is aware of the
* truncation problem.
*/
common_type = is_signed ? MESA_ARRAY_FORMAT_TYPE_INT :
MESA_ARRAY_FORMAT_TYPE_UINT;
if (src_array_format) {
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
- src, src_type, src_num_channels,
- rebased_src2rgba, normalized, width);
+ swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+ src, src_type, src_num_channels,
+ rebased_src2rgba, normalized, width);
src += src_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_unpack_uint_rgba_row(src_format, width,
src, tmp_uint + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_uint + row * width, common_type, 4,
- tmp_uint + row * width, common_type, 4,
- rebase_swizzle, false, width);
+ swizzle_and_convert(tmp_uint + row * width, common_type, 4,
+ tmp_uint + row * width, common_type, 4,
+ rebase_swizzle, false, width);
src += src_stride;
}
}
/* At this point, we have already done the truncation if the source is
* signed but the destination is unsigned, so no need to force the
* _mesa_swizzle_and_convert path.
*/
if (dst_format_is_mesa_array_format) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
- tmp_uint + row * width, common_type, 4,
- rgba2dst, normalized, width);
+ swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_uint + row * width, common_type, 4,
+ rgba2dst, normalized, width);
dst += dst_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_pack_uint_rgba_row(dst_format, width,
(const uint32_t (*)[4])tmp_uint + row * width, dst);
dst += dst_stride;
}
}
free(tmp_uint);
} else if (is_signed || bits > 8) {
tmp_float = malloc(width * height * sizeof(*tmp_float));
if (src_format_is_mesa_array_format) {
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_float + row * width,
- MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
- src, src_type, src_num_channels,
- rebased_src2rgba, normalized, width);
+ swizzle_and_convert(tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ src, src_type, src_num_channels,
+ rebased_src2rgba, normalized, width);
src += src_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_unpack_rgba_row(src_format, width,
src, tmp_float + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_float + row * width,
- MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
- tmp_float + row * width,
- MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
- rebase_swizzle, normalized, width);
+ swizzle_and_convert(tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ rebase_swizzle, normalized, width);
src += src_stride;
}
}
if (dst_format_is_mesa_array_format) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
- tmp_float + row * width,
- MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
- rgba2dst, normalized, width);
+ swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_float + row * width,
+ MESA_ARRAY_FORMAT_TYPE_FLOAT, 4,
+ rgba2dst, normalized, width);
dst += dst_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_pack_float_rgba_row(dst_format, width,
(const float (*)[4])tmp_float + row * width, dst);
dst += dst_stride;
}
}
free(tmp_float);
} else {
tmp_ubyte = malloc(width * height * sizeof(*tmp_ubyte));
if (src_format_is_mesa_array_format) {
compute_rebased_rgba_component_mapping(src2rgba, rebase_swizzle,
rebased_src2rgba);
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(tmp_ubyte + row * width,
- MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
- src, src_type, src_num_channels,
- rebased_src2rgba, normalized, width);
+ swizzle_and_convert(tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ src, src_type, src_num_channels,
+ rebased_src2rgba, normalized, width);
src += src_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_unpack_ubyte_rgba_row(src_format, width,
src, tmp_ubyte + row * width);
if (rebase_swizzle)
- _mesa_swizzle_and_convert(tmp_ubyte + row * width,
- MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
- tmp_ubyte + row * width,
- MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
- rebase_swizzle, normalized, width);
+ swizzle_and_convert(tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ rebase_swizzle, normalized, width);
src += src_stride;
}
}
if (dst_format_is_mesa_array_format) {
for (row = 0; row < height; ++row) {
- _mesa_swizzle_and_convert(dst, dst_type, dst_num_channels,
- tmp_ubyte + row * width,
- MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
- rgba2dst, normalized, width);
+ swizzle_and_convert(dst, dst_type, dst_num_channels,
+ tmp_ubyte + row * width,
+ MESA_ARRAY_FORMAT_TYPE_UBYTE, 4,
+ rgba2dst, normalized, width);
dst += dst_stride;
}
} else {
for (row = 0; row < height; ++row) {
_mesa_pack_ubyte_rgba_row(dst_format, width,
(const uint8_t (*)[4])tmp_ubyte + row * width, dst);
dst += dst_stride;
}
}
@@ -1479,24 +1486,24 @@ convert_int(void *void_dst, int num_dst_channels,
*
* \param[in] swizzle describes how to get the destination data
* from the source data.
*
* \param[in] normalized for integer types, this indicates whether
* the data should be considered as integers
* or as normalized integers;
*
* \param[in] count the number of pixels to convert
*/
-void
-_mesa_swizzle_and_convert(void *void_dst, enum mesa_array_format_datatype dst_type, int num_dst_channels,
- const void *void_src, enum mesa_array_format_datatype src_type, int num_src_channels,
- const uint8_t swizzle[4], bool normalized, int count)
+static void
+swizzle_and_convert(void *void_dst, enum mesa_array_format_datatype dst_type, int num_dst_channels,
+ const void *void_src, enum mesa_array_format_datatype src_type, int num_src_channels,
+ const uint8_t swizzle[4], bool normalized, int count)
{
if (swizzle_convert_try_memcpy(void_dst, dst_type, num_dst_channels,
void_src, src_type, num_src_channels,
swizzle, normalized, count))
return;
switch (dst_type) {
case MESA_ARRAY_FORMAT_TYPE_FLOAT:
convert_float(void_dst, num_dst_channels, void_src, src_type,
num_src_channels, swizzle, normalized, count);
diff --git a/src/mesa/main/format_utils.h b/src/mesa/main/format_utils.h
index 378997b..520e786 100644
--- a/src/mesa/main/format_utils.h
+++ b/src/mesa/main/format_utils.h
@@ -213,28 +213,19 @@ _mesa_half_to_unsigned(uint16_t src, unsigned dst_bits)
static inline unsigned
_mesa_half_to_signed(uint16_t src, unsigned dst_bits)
{
return _mesa_float_to_signed(_mesa_half_to_float(src), dst_bits);
}
bool
_mesa_format_to_array(mesa_format, GLenum *type, int *num_components,
uint8_t swizzle[4], bool *normalized);
-void
-_mesa_swizzle_and_convert(void *dst,
- enum mesa_array_format_datatype dst_type,
- int num_dst_channels,
- const void *src,
- enum mesa_array_format_datatype src_type,
- int num_src_channels,
- const uint8_t swizzle[4], bool normalized, int count);
-
bool
_mesa_compute_rgba2base2rgba_component_mapping(GLenum baseFormat, uint8_t *map);
void
_mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
void *void_src, uint32_t src_format, size_t src_stride,
size_t width, size_t height, uint8_t *rebase_swizzle);
#endif
--
2.9.4
More information about the mesa-dev
mailing list