[Mesa-dev] [PATCH 08/28] mesa/main: replace uses of _mesa_little_endian with preprocessor
Dylan Baker
dylan at pnwbakers.com
Fri Nov 9 18:40:01 UTC 2018
---
src/mesa/main/format_utils.c | 24 ++++++++---
src/mesa/main/formats.c | 68 ++++++++++++++++----------------
src/mesa/main/texcompress_bptc.c | 7 +++-
src/mesa/main/texcompress_fxt1.c | 7 +++-
src/mesa/main/texcompress_rgtc.c | 14 +++++--
src/mesa/main/texcompress_s3tc.c | 21 +++++++---
src/mesa/main/texstore.c | 4 +-
7 files changed, 88 insertions(+), 57 deletions(-)
diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c
index 6959bf062a1..7802dbe3ff7 100644
--- a/src/mesa/main/format_utils.c
+++ b/src/mesa/main/format_utils.c
@@ -647,9 +647,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride,
}
}
-static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 };
-static const uint8_t map_3210[7] = { 3, 2, 1, 0, 4, 5, 6 };
-static const uint8_t map_1032[7] = { 1, 0, 3, 2, 4, 5, 6 };
+MAYBE_UNUSED static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 };
+MAYBE_UNUSED static const uint8_t map_3210[7] = { 3, 2, 1, 0, 4, 5, 6 };
+MAYBE_UNUSED static const uint8_t map_1032[7] = { 1, 0, 3, 2, 4, 5, 6 };
/**
* Describes a format as an array format, if possible
@@ -700,10 +700,18 @@ _mesa_format_to_array(mesa_format format, GLenum *type, int *num_components,
endian = map_identity;
break;
case 2:
- endian = _mesa_little_endian() ? map_identity : map_1032;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ endian = map_identity;
+#else
+ endian = map_1032;
+#endif
break;
case 4:
- endian = _mesa_little_endian() ? map_identity : map_3210;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ endian = map_identity;
+#else
+ endian = map_3210;
+#endif
break;
default:
endian = map_identity;
@@ -721,7 +729,11 @@ _mesa_format_to_array(mesa_format format, GLenum *type, int *num_components,
endian = map_identity;
break;
case 2:
- endian = _mesa_little_endian() ? map_identity : map_1032;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ endian = map_identity;
+#else
+ endian = map_1032;
+#endif
break;
default:
endian = map_identity;
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index cf2d2bc555a..494844c08be 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -415,10 +415,11 @@ uint32_t
_mesa_format_to_array_format(mesa_format format)
{
const struct gl_format_info *info = _mesa_get_format_info(format);
- if (info->ArrayFormat && !_mesa_little_endian() &&
- info->Layout == MESA_FORMAT_LAYOUT_PACKED)
+#ifdef PIPE_ARCH_BIG_ENDIAN
+ if (info->ArrayFormat && info->Layout == MESA_FORMAT_LAYOUT_PACKED)
return _mesa_array_format_flip_channels(info->ArrayFormat);
else
+#endif
return info->ArrayFormat;
}
@@ -451,11 +452,11 @@ format_array_format_table_init(void)
if (!info->ArrayFormat)
continue;
- if (_mesa_little_endian()) {
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
array_format = info->ArrayFormat;
- } else {
+#else
array_format = _mesa_array_format_flip_channels(info->ArrayFormat);
- }
+#endif
/* This can happen and does for some of the BGR formats. Let's take
* the first one in the list.
@@ -1442,7 +1443,6 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
GLenum format, GLenum type,
GLboolean swapBytes, GLenum *error)
{
- const GLboolean littleEndian = _mesa_little_endian();
if (error)
*error = GL_NO_ERROR;
@@ -1471,7 +1471,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes)
return GL_TRUE;
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian)
+ if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV
@@ -1482,7 +1482,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
&& swapBytes)
return GL_TRUE;
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian)
+ if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
@@ -1496,7 +1496,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
return GL_TRUE;
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && littleEndian)
+ if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 &&
@@ -1507,7 +1507,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
swapBytes)
return GL_TRUE;
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !littleEndian)
+ if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
@@ -1521,7 +1521,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
return GL_TRUE;
- if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian)
+ if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
@@ -1535,7 +1535,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
swapBytes)
return GL_TRUE;
- if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !littleEndian)
+ if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
@@ -1550,10 +1550,10 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
case MESA_FORMAT_BGR_UNORM8:
case MESA_FORMAT_BGR_SRGB8:
- return format == GL_BGR && type == GL_UNSIGNED_BYTE && littleEndian;
+ return format == GL_BGR && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN;
case MESA_FORMAT_RGB_UNORM8:
- return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;
+ return format == GL_RGB && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN;
case MESA_FORMAT_B5G6R5_UNORM:
return ((format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) ||
@@ -1592,13 +1592,13 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return GL_FALSE;
case MESA_FORMAT_L8A8_UNORM:
case MESA_FORMAT_L8A8_SRGB:
- return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian;
+ return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN;
case MESA_FORMAT_A8L8_UNORM:
case MESA_FORMAT_A8L8_SRGB:
return GL_FALSE;
case MESA_FORMAT_L16A16_UNORM:
- return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian && !swapBytes;
+ return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && PIPE_ARCH_LITTLE_ENDIAN && !swapBytes;
case MESA_FORMAT_A16L16_UNORM:
return GL_FALSE;
@@ -1663,18 +1663,18 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
case MESA_FORMAT_YCBCR:
return format == GL_YCBCR_MESA &&
- ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian != swapBytes) ||
- (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian == swapBytes));
+ ((type == GL_UNSIGNED_SHORT_8_8_MESA && PIPE_ARCH_LITTLE_ENDIAN != swapBytes) ||
+ (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && PIPE_ARCH_LITTLE_ENDIAN == swapBytes));
case MESA_FORMAT_YCBCR_REV:
return format == GL_YCBCR_MESA &&
- ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian == swapBytes) ||
- (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian != swapBytes));
+ ((type == GL_UNSIGNED_SHORT_8_8_MESA && PIPE_ARCH_LITTLE_ENDIAN == swapBytes) ||
+ (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && PIPE_ARCH_LITTLE_ENDIAN != swapBytes));
case MESA_FORMAT_R_UNORM8:
case MESA_FORMAT_R_SRGB8:
return format == GL_RED && type == GL_UNSIGNED_BYTE;
case MESA_FORMAT_R8G8_UNORM:
- return format == GL_RG && type == GL_UNSIGNED_BYTE && littleEndian;
+ return format == GL_RG && type == GL_UNSIGNED_BYTE && PIPE_ARCH_LITTLE_ENDIAN;
case MESA_FORMAT_G8R8_UNORM:
return GL_FALSE;
@@ -1682,7 +1682,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return format == GL_RED && type == GL_UNSIGNED_SHORT &&
!swapBytes;
case MESA_FORMAT_R16G16_UNORM:
- return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
+ return format == GL_RG && type == GL_UNSIGNED_SHORT && PIPE_ARCH_LITTLE_ENDIAN &&
!swapBytes;
case MESA_FORMAT_G16R16_UNORM:
return GL_FALSE;
@@ -1872,25 +1872,25 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
case MESA_FORMAT_R_SNORM8:
return format == GL_RED && type == GL_BYTE;
case MESA_FORMAT_R8G8_SNORM:
- return format == GL_RG && type == GL_BYTE && littleEndian &&
+ return format == GL_RG && type == GL_BYTE && PIPE_ARCH_LITTLE_ENDIAN &&
!swapBytes;
case MESA_FORMAT_X8B8G8R8_SNORM:
return GL_FALSE;
case MESA_FORMAT_A8B8G8R8_SNORM:
- if (format == GL_RGBA && type == GL_BYTE && !littleEndian)
+ if (format == GL_RGBA && type == GL_BYTE && !PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
- if (format == GL_ABGR_EXT && type == GL_BYTE && littleEndian)
+ if (format == GL_ABGR_EXT && type == GL_BYTE && PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
case MESA_FORMAT_R8G8B8A8_SNORM:
- if (format == GL_RGBA && type == GL_BYTE && littleEndian)
+ if (format == GL_RGBA && type == GL_BYTE && PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
- if (format == GL_ABGR_EXT && type == GL_BYTE && !littleEndian)
+ if (format == GL_ABGR_EXT && type == GL_BYTE && !PIPE_ARCH_LITTLE_ENDIAN)
return GL_TRUE;
return GL_FALSE;
@@ -1899,7 +1899,7 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return format == GL_RED && type == GL_SHORT &&
!swapBytes;
case MESA_FORMAT_R16G16_SNORM:
- return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes;
+ return format == GL_RG && type == GL_SHORT && PIPE_ARCH_LITTLE_ENDIAN && !swapBytes;
case MESA_FORMAT_RGB_SNORM16:
return format == GL_RGB && type == GL_SHORT && !swapBytes;
case MESA_FORMAT_RGBA_SNORM16:
@@ -1914,10 +1914,10 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return format == GL_LUMINANCE && type == GL_BYTE;
case MESA_FORMAT_L8A8_SNORM:
return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
- littleEndian && !swapBytes;
+ PIPE_ARCH_LITTLE_ENDIAN && !swapBytes;
case MESA_FORMAT_A8L8_SNORM:
return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
- !littleEndian && !swapBytes;
+ !PIPE_ARCH_LITTLE_ENDIAN && !swapBytes;
case MESA_FORMAT_I_SNORM8:
return format == GL_RED && type == GL_BYTE;
case MESA_FORMAT_A_SNORM16:
@@ -1926,9 +1926,9 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes;
case MESA_FORMAT_LA_SNORM16:
return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
- littleEndian && !swapBytes;
+ PIPE_ARCH_LITTLE_ENDIAN && !swapBytes;
case MESA_FORMAT_I_SNORM16:
- return format == GL_RED && type == GL_SHORT && littleEndian &&
+ return format == GL_RED && type == GL_SHORT && PIPE_ARCH_LITTLE_ENDIAN &&
!swapBytes;
case MESA_FORMAT_B10G10R10A2_UINT:
@@ -2072,11 +2072,11 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,
!swapBytes;
case MESA_FORMAT_G8R8_SNORM:
- return format == GL_RG && type == GL_BYTE && !littleEndian &&
+ return format == GL_RG && type == GL_BYTE && !PIPE_ARCH_LITTLE_ENDIAN &&
!swapBytes;
case MESA_FORMAT_G16R16_SNORM:
- return format == GL_RG && type == GL_SHORT && !littleEndian &&
+ return format == GL_RG && type == GL_SHORT && !PIPE_ARCH_LITTLE_ENDIAN &&
!swapBytes;
case MESA_FORMAT_B8G8R8X8_SRGB:
diff --git a/src/mesa/main/texcompress_bptc.c b/src/mesa/main/texcompress_bptc.c
index 46279f144ff..319096970f8 100644
--- a/src/mesa/main/texcompress_bptc.c
+++ b/src/mesa/main/texcompress_bptc.c
@@ -142,8 +142,11 @@ _mesa_texstore_bptc_rgba_unorm(TEXSTORE_PARAMS)
tempImageSlices[0] = (GLubyte *) tempImage;
_mesa_texstore(ctx, dims,
baseInternalFormat,
- _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
- : MESA_FORMAT_A8B8G8R8_UNORM,
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ MESA_FORMAT_R8G8B8A8_UNORM,
+#else
+ MESA_FORMAT_A8B8G8R8_UNORM,
+#endif
rgbaRowStride, tempImageSlices,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index 19df6baf371..61e047c2648 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -132,8 +132,11 @@ _mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
tempImageSlices[0] = (GLubyte *) tempImage;
_mesa_texstore(ctx, dims,
baseInternalFormat,
- _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
- : MESA_FORMAT_A8B8G8R8_UNORM,
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ MESA_FORMAT_R8G8B8A8_UNORM,
+#else
+ MESA_FORMAT_A8B8G8R8_UNORM,
+#endif
rgbaRowStride, tempImageSlices,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
index 843b42e54e6..eab43943512 100644
--- a/src/mesa/main/texcompress_rgtc.c
+++ b/src/mesa/main/texcompress_rgtc.c
@@ -197,11 +197,17 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS)
dstFormat == MESA_FORMAT_LA_LATC2_UNORM);
if (baseInternalFormat == GL_RG)
- tempFormat = _mesa_little_endian() ? MESA_FORMAT_R8G8_UNORM
- : MESA_FORMAT_G8R8_UNORM;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ tempFormat = MESA_FORMAT_R8G8_UNORM;
+#else
+ tempFormat = MESA_FORMAT_G8R8_UNORM;
+#endif
else
- tempFormat = _mesa_little_endian() ? MESA_FORMAT_L8A8_UNORM
- : MESA_FORMAT_A8L8_UNORM;
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ tempFormat = MESA_FORMAT_L8A8_UNORM;
+#else
+ tempFormat = MESA_FORMAT_A8L8_UNORM;
+#endif
rgRowStride = 2 * srcWidth * sizeof(GLubyte);
tempImage = malloc(srcWidth * srcHeight * 2 * sizeof(GLubyte));
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
index 1c6cbba892a..11f75e5352e 100644
--- a/src/mesa/main/texcompress_s3tc.c
+++ b/src/mesa/main/texcompress_s3tc.c
@@ -121,8 +121,11 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
tempImageSlices[0] = (GLubyte *) tempImage;
_mesa_texstore(ctx, dims,
baseInternalFormat,
- _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
- : MESA_FORMAT_A8B8G8R8_UNORM,
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ MESA_FORMAT_R8G8B8A8_UNORM,
+#else
+ MESA_FORMAT_A8B8G8R8_UNORM,
+#endif
rgbaRowStride, tempImageSlices,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
@@ -174,8 +177,11 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
tempImageSlices[0] = (GLubyte *) tempImage;
_mesa_texstore(ctx, dims,
baseInternalFormat,
- _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
- : MESA_FORMAT_A8B8G8R8_UNORM,
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ MESA_FORMAT_R8G8B8A8_UNORM,
+#else
+ MESA_FORMAT_A8B8G8R8_UNORM,
+#endif
rgbaRowStride, tempImageSlices,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
@@ -226,8 +232,11 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
tempImageSlices[0] = (GLubyte *) tempImage;
_mesa_texstore(ctx, dims,
baseInternalFormat,
- _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
- : MESA_FORMAT_A8B8G8R8_UNORM,
+#ifdef PIPE_ARCH_LITTLE_ENDIAN
+ MESA_FORMAT_R8G8B8A8_UNORM,
+#else
+ MESA_FORMAT_A8B8G8R8_UNORM,
+#endif
rgbaRowStride, tempImageSlices,
srcWidth, srcHeight, srcDepth,
srcFormat, srcType, srcAddr,
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 2913d4bc067..5cd1abfdbeb 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -280,8 +280,6 @@ _mesa_texstore_z16(TEXSTORE_PARAMS)
static GLboolean
_mesa_texstore_ycbcr(TEXSTORE_PARAMS)
{
- const GLboolean littleEndian = _mesa_little_endian();
-
(void) ctx; (void) dims; (void) baseInternalFormat;
assert((dstFormat == MESA_FORMAT_YCBCR) ||
@@ -305,7 +303,7 @@ _mesa_texstore_ycbcr(TEXSTORE_PARAMS)
if (srcPacking->SwapBytes ^
(srcType == GL_UNSIGNED_SHORT_8_8_REV_MESA) ^
(dstFormat == MESA_FORMAT_YCBCR_REV) ^
- !littleEndian) {
+ !PIPE_ARCH_LITTLE_ENDIAN) {
GLint img, row;
for (img = 0; img < srcDepth; img++) {
GLubyte *dstRow = dstSlices[img];
--
2.19.1
More information about the mesa-dev
mailing list