summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2019-08-19 15:17:58 -0700
committerEric Anholt <[email protected]>2019-10-17 21:07:29 +0000
commit75c601b6cf63c077dbfbb5f2f64f683dcf5524b4 (patch)
tree1862ee5f747d8f7b4b1e501a75c74984926bafba /src/mesa/main
parentd77c77936b3956e8925504ad980acbff74422e7c (diff)
mesa: Refactor the entirety of _mesa_format_matches_format_and_type().
This function was difficult to implement for new formats due to the combination of endianness and swapbytes support. Since it's mostly used for fast paths, bugs in it were often missed during testing. Just reimplement it on top of the recent _mesa_format_from_format_and_type() which can give us a canonical MESA_FORMAT for a format and type enum (while respecting endianness). Fixes: - R4G4B4A4_UNORM, B4G4R4_UINT, R4G4B4A4_UINT incorrectly matched with swapBytes (you can't just reverse the channels if the channels aren't bytes) - A4R4G4B4_UNORM and A4R4G4B4_UINT missing BGRA/4444_REV matches - failing to match RGB/BGR unorm8 array formats on BE - 2101010 formats incorrectly matching with swapBytes set. - UINT/SINT byte formats failed to match with swapBytes set. This deletes the part of tests/mesa_formats.cpp that called _mesa_format_matches_format_and_type() to make sure it didn't assertion fail, as it now would assertion fail due to the fact that we were passing an invalid format (GL_RG) for most types. Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/format_fallback.py32
-rw-r--r--src/mesa/main/formats.c652
-rw-r--r--src/mesa/main/formats.h3
-rw-r--r--src/mesa/main/glformats.c30
-rw-r--r--src/mesa/main/glformats.h3
-rw-r--r--src/mesa/main/tests/mesa_formats.cpp33
6 files changed, 111 insertions, 642 deletions
diff --git a/src/mesa/main/format_fallback.py b/src/mesa/main/format_fallback.py
index 4a2b85cecb3..cc388274e75 100644
--- a/src/mesa/main/format_fallback.py
+++ b/src/mesa/main/format_fallback.py
@@ -85,6 +85,20 @@ def get_rgbx_to_rgba_map(formats):
yield rgbx_name, rgba_name
+def get_intensity_to_red_map(formats):
+ names = set(fmt.name for fmt in formats)
+
+ for fmt in formats:
+ if str(fmt.swizzle) != 'xxxx':
+ continue
+
+ i_name = fmt.name
+ r_name = i_name.replace("_I_", "_R_")
+
+ assert r_name in names
+
+ yield i_name, r_name
+
TEMPLATE = Template(COPYRIGHT + """
#include "formats.h"
#include "util/macros.h"
@@ -129,6 +143,23 @@ _mesa_get_linear_format_srgb(mesa_format format)
}
/**
+ * For an intensity format, return the corresponding red format. For other
+ * formats, return the format as-is.
+ */
+mesa_format
+_mesa_get_intensity_format_red(mesa_format format)
+{
+ switch (format) {
+%for i, r in intensity_to_red_map:
+ case ${i}:
+ return ${r};
+%endfor
+ default:
+ return format;
+ }
+}
+
+/**
* If the format has an alpha channel, and there exists a non-alpha
* variant of the format with an identical bit layout, then return
* the non-alpha format. Otherwise return the original format.
@@ -164,6 +195,7 @@ def main():
template_env = {
'unorm_to_srgb_map': list(get_unorm_to_srgb_map(formats)),
'rgbx_to_rgba_map': list(get_rgbx_to_rgba_map(formats)),
+ 'intensity_to_red_map': list(get_intensity_to_red_map(formats)),
}
with open(pargs.out, 'w') as f:
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index b40b275f497..aba12fc9f0b 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -1451,655 +1451,37 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
* \return true if the formats match, false otherwise.
*/
bool
-_mesa_format_matches_format_and_type(mesa_format mesa_format,
+_mesa_format_matches_format_and_type(mesa_format mformat,
GLenum format, GLenum type,
bool swapBytes, GLenum *error)
{
- const bool littleEndian = _mesa_little_endian();
if (error)
*error = GL_NO_ERROR;
- /* Note: When reading a GL format/type combination, the format lists channel
- * assignments from most significant channel in the type to least
- * significant. A type with _REV indicates that the assignments are
- * swapped, so they are listed from least significant to most significant.
- *
- * Compressed formats will fall through and return false.
- *
- * For sanity, please keep this switch statement ordered the same as the
- * enums in formats.h.
- */
-
- switch (mesa_format) {
-
- case MESA_FORMAT_NONE:
- case MESA_FORMAT_COUNT:
- return false;
-
- case MESA_FORMAT_A8B8G8R8_UNORM:
- case MESA_FORMAT_A8B8G8R8_SRGB:
- if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV
- && !swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8
- && swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_R8G8B8A8_UNORM:
- case MESA_FORMAT_R8G8B8A8_SRGB:
- if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- !swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && littleEndian)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 &&
- !swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_B8G8R8A8_UNORM:
- case MESA_FORMAT_B8G8R8A8_SRGB:
- if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- !swapBytes)
- return true;
-
- if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
- return true;
-
- if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_A8R8G8B8_UNORM:
- case MESA_FORMAT_A8R8G8B8_SRGB:
- if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
- return true;
-
- if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- swapBytes)
- return true;
-
- if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_X8B8G8R8_UNORM:
- case MESA_FORMAT_R8G8B8X8_UNORM:
- return false;
-
- case MESA_FORMAT_B8G8R8X8_UNORM:
- case MESA_FORMAT_X8R8G8B8_UNORM:
- return false;
-
- case MESA_FORMAT_BGR_UNORM8:
- case MESA_FORMAT_BGR_SRGB8:
- return format == GL_BGR && type == GL_UNSIGNED_BYTE && littleEndian;
-
- case MESA_FORMAT_RGB_UNORM8:
- return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;
-
- case MESA_FORMAT_B5G6R5_UNORM:
- return ((format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) ||
- (format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&
- !swapBytes;
-
- case MESA_FORMAT_R5G6B5_UNORM:
- return ((format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5) ||
- (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&
- !swapBytes;
-
- case MESA_FORMAT_B4G4R4A4_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&
- !swapBytes;
-
- case MESA_FORMAT_A4R4G4B4_UNORM:
- return false;
-
- case MESA_FORMAT_A1B5G5R5_UNORM:
- return format == GL_RGBA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
- !swapBytes;
-
- case MESA_FORMAT_X1B5G5R5_UNORM:
- return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
- !swapBytes;
-
- case MESA_FORMAT_B5G5R5A1_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV &&
- !swapBytes;
-
- case MESA_FORMAT_A1R5G5B5_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
- !swapBytes;
-
- case MESA_FORMAT_L4A4_UNORM:
- return false;
- case MESA_FORMAT_L8A8_UNORM:
- case MESA_FORMAT_L8A8_SRGB:
- return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian;
- case MESA_FORMAT_A8L8_UNORM:
- case MESA_FORMAT_A8L8_SRGB:
- return false;
-
- case MESA_FORMAT_L16A16_UNORM:
- return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian && !swapBytes;
- case MESA_FORMAT_A16L16_UNORM:
- return false;
-
- case MESA_FORMAT_B2G3R3_UNORM:
- return format == GL_RGB && type == GL_UNSIGNED_BYTE_3_3_2;
-
- case MESA_FORMAT_R3G3B2_UNORM:
- return format == GL_RGB && type == GL_UNSIGNED_BYTE_2_3_3_REV;
-
- case MESA_FORMAT_A4B4G4R4_UNORM:
- if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4 && !swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && !swapBytes)
- return true;
-
- return false;
-
- case MESA_FORMAT_R4G4B4A4_UNORM:
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4 && !swapBytes)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && !swapBytes)
- return true;
-
- if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4 && swapBytes)
- return true;
-
- return false;
-
- case MESA_FORMAT_R5G5B5A1_UNORM:
- return format == GL_RGBA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV;
-
- case MESA_FORMAT_A2B10G10R10_UNORM:
- return format == GL_RGBA && type == GL_UNSIGNED_INT_10_10_10_2;
-
- case MESA_FORMAT_A2B10G10R10_UINT:
- return format == GL_RGBA_INTEGER_EXT && type == GL_UNSIGNED_INT_10_10_10_2;
-
- case MESA_FORMAT_A2R10G10B10_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_INT_10_10_10_2;
-
- case MESA_FORMAT_A2R10G10B10_UINT:
- return format == GL_BGRA_INTEGER_EXT && type == GL_UNSIGNED_INT_10_10_10_2;
-
- case MESA_FORMAT_A_UNORM8:
- return format == GL_ALPHA && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_A_UNORM16:
- return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && !swapBytes;
- case MESA_FORMAT_L_UNORM8:
- case MESA_FORMAT_L_SRGB8:
- return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_L_UNORM16:
- return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes;
- case MESA_FORMAT_I_UNORM8:
- return format == GL_RED && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_I_UNORM16:
- return format == GL_RED && type == GL_UNSIGNED_SHORT && !swapBytes;
-
- 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));
- 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));
-
- 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;
- case MESA_FORMAT_G8R8_UNORM:
- return false;
-
- case MESA_FORMAT_R_UNORM16:
- return format == GL_RED && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_R16G16_UNORM:
- return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
- !swapBytes;
- case MESA_FORMAT_G16R16_UNORM:
- return false;
-
- case MESA_FORMAT_B10G10R10A2_UNORM:
- return format == GL_BGRA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
- !swapBytes;
-
- case MESA_FORMAT_S8_UINT_Z24_UNORM:
- return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8 &&
- !swapBytes;
- case MESA_FORMAT_X8_UINT_Z24_UNORM:
- case MESA_FORMAT_Z24_UNORM_S8_UINT:
- return false;
-
- case MESA_FORMAT_Z_UNORM16:
- return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
-
- case MESA_FORMAT_Z24_UNORM_X8_UINT:
- return false;
-
- case MESA_FORMAT_Z_UNORM32:
- return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT &&
- !swapBytes;
-
- case MESA_FORMAT_S_UINT8:
- return format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE;
-
- case MESA_FORMAT_RGBA_FLOAT32:
- return format == GL_RGBA && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_RGBA_FLOAT16:
- return format == GL_RGBA && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_RGB_FLOAT32:
- return format == GL_RGB && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_RGB_FLOAT16:
- return format == GL_RGB && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_A_FLOAT32:
- return format == GL_ALPHA && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_A_FLOAT16:
- return format == GL_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_L_FLOAT32:
- return format == GL_LUMINANCE && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_L_FLOAT16:
- return format == GL_LUMINANCE && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_LA_FLOAT32:
- return format == GL_LUMINANCE_ALPHA && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_LA_FLOAT16:
- return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_I_FLOAT32:
- return format == GL_RED && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_I_FLOAT16:
- return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_R_FLOAT32:
- return format == GL_RED && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_R_FLOAT16:
- return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_RG_FLOAT32:
- return format == GL_RG && type == GL_FLOAT && !swapBytes;
- case MESA_FORMAT_RG_FLOAT16:
- return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes;
-
- case MESA_FORMAT_A_UINT8:
- return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_A_UINT16:
- return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_A_UINT32:
- return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_INT &&
- !swapBytes;
- case MESA_FORMAT_A_SINT8:
- return format == GL_ALPHA_INTEGER && type == GL_BYTE;
- case MESA_FORMAT_A_SINT16:
- return format == GL_ALPHA_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_A_SINT32:
- return format == GL_ALPHA_INTEGER && type == GL_INT && !swapBytes;
-
- case MESA_FORMAT_I_UINT8:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_I_UINT16:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes;
- case MESA_FORMAT_I_UINT32:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
- case MESA_FORMAT_I_SINT8:
- return format == GL_RED_INTEGER && type == GL_BYTE;
- case MESA_FORMAT_I_SINT16:
- return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_I_SINT32:
- return format == GL_RED_INTEGER && type == GL_INT && !swapBytes;
-
- case MESA_FORMAT_L_UINT8:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_L_UINT16:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_L_UINT32:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_INT &&
- !swapBytes;
- case MESA_FORMAT_L_SINT8:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE;
- case MESA_FORMAT_L_SINT16:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_SHORT &&
- !swapBytes;
- case MESA_FORMAT_L_SINT32:
- return format == GL_LUMINANCE_INTEGER_EXT && type == GL_INT && !swapBytes;
-
- case MESA_FORMAT_LA_UINT8:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
- type == GL_UNSIGNED_BYTE && !swapBytes;
- case MESA_FORMAT_LA_UINT16:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
- type == GL_UNSIGNED_SHORT && !swapBytes;
- case MESA_FORMAT_LA_UINT32:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT &&
- type == GL_UNSIGNED_INT && !swapBytes;
- case MESA_FORMAT_LA_SINT8:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_BYTE &&
- !swapBytes;
- case MESA_FORMAT_LA_SINT16:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_SHORT &&
- !swapBytes;
- case MESA_FORMAT_LA_SINT32:
- return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_INT &&
- !swapBytes;
-
- case MESA_FORMAT_R_SINT8:
- return format == GL_RED_INTEGER && type == GL_BYTE;
- case MESA_FORMAT_RG_SINT8:
- return format == GL_RG_INTEGER && type == GL_BYTE && !swapBytes;
- case MESA_FORMAT_RGB_SINT8:
- return format == GL_RGB_INTEGER && type == GL_BYTE && !swapBytes;
- case MESA_FORMAT_RGBA_SINT8:
- return format == GL_RGBA_INTEGER && type == GL_BYTE && !swapBytes;
- case MESA_FORMAT_R_SINT16:
- return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_RG_SINT16:
- return format == GL_RG_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_RGB_SINT16:
- return format == GL_RGB_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_RGBA_SINT16:
- return format == GL_RGBA_INTEGER && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_R_SINT32:
- return format == GL_RED_INTEGER && type == GL_INT && !swapBytes;
- case MESA_FORMAT_RG_SINT32:
- return format == GL_RG_INTEGER && type == GL_INT && !swapBytes;
- case MESA_FORMAT_RGB_SINT32:
- return format == GL_RGB_INTEGER && type == GL_INT && !swapBytes;
- case MESA_FORMAT_RGBA_SINT32:
- return format == GL_RGBA_INTEGER && type == GL_INT && !swapBytes;
-
- case MESA_FORMAT_R_UINT8:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE;
- case MESA_FORMAT_RG_UINT8:
- return format == GL_RG_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
- case MESA_FORMAT_RGB_UINT8:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes;
- case MESA_FORMAT_RGBA_UINT8:
- return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_BYTE &&
- !swapBytes;
- case MESA_FORMAT_R_UINT16:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_RG_UINT16:
- return format == GL_RG_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes;
- case MESA_FORMAT_RGB_UINT16:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_RGBA_UINT16:
- return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
- case MESA_FORMAT_R_UINT32:
- return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
- case MESA_FORMAT_RG_UINT32:
- return format == GL_RG_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
- case MESA_FORMAT_RGB_UINT32:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
- case MESA_FORMAT_RGBA_UINT32:
- return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT && !swapBytes;
-
- 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 &&
- !swapBytes;
- case MESA_FORMAT_X8B8G8R8_SNORM:
- return false;
-
- case MESA_FORMAT_A8B8G8R8_SNORM:
- if (format == GL_RGBA && type == GL_BYTE && !littleEndian)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_BYTE && littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_R8G8B8A8_SNORM:
- if (format == GL_RGBA && type == GL_BYTE && littleEndian)
- return true;
-
- if (format == GL_ABGR_EXT && type == GL_BYTE && !littleEndian)
- return true;
-
- return false;
-
- case MESA_FORMAT_R_SNORM16:
- return format == GL_RED && type == GL_SHORT &&
- !swapBytes;
- case MESA_FORMAT_R16G16_SNORM:
- return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes;
- case MESA_FORMAT_RGB_SNORM16:
- return format == GL_RGB && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_RGBA_SNORM16:
- return format == GL_RGBA && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_RGBA_UNORM16:
- return format == GL_RGBA && type == GL_UNSIGNED_SHORT &&
- !swapBytes;
-
- case MESA_FORMAT_A_SNORM8:
- return format == GL_ALPHA && type == GL_BYTE;
- case MESA_FORMAT_L_SNORM8:
- return format == GL_LUMINANCE && type == GL_BYTE;
- case MESA_FORMAT_L8A8_SNORM:
- return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
- littleEndian && !swapBytes;
- case MESA_FORMAT_A8L8_SNORM:
- return format == GL_LUMINANCE_ALPHA && type == GL_BYTE &&
- !littleEndian && !swapBytes;
- case MESA_FORMAT_I_SNORM8:
- return format == GL_RED && type == GL_BYTE;
- case MESA_FORMAT_A_SNORM16:
- return format == GL_ALPHA && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_L_SNORM16:
- return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes;
- case MESA_FORMAT_LA_SNORM16:
- return format == GL_LUMINANCE_ALPHA && type == GL_SHORT &&
- littleEndian && !swapBytes;
- case MESA_FORMAT_I_SNORM16:
- return format == GL_RED && type == GL_SHORT && littleEndian &&
- !swapBytes;
-
- case MESA_FORMAT_B10G10R10A2_UINT:
- return (format == GL_BGRA_INTEGER_EXT &&
- type == GL_UNSIGNED_INT_2_10_10_10_REV &&
- !swapBytes);
-
- case MESA_FORMAT_R10G10B10A2_UINT:
- return (format == GL_RGBA_INTEGER_EXT &&
- type == GL_UNSIGNED_INT_2_10_10_10_REV &&
- !swapBytes);
-
- case MESA_FORMAT_B5G6R5_UINT:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_SHORT_5_6_5;
-
- case MESA_FORMAT_R5G6B5_UINT:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_SHORT_5_6_5_REV;
-
- case MESA_FORMAT_B2G3R3_UINT:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_BYTE_3_3_2;
-
- case MESA_FORMAT_R3G3B2_UINT:
- return format == GL_RGB_INTEGER && type == GL_UNSIGNED_BYTE_2_3_3_REV;
-
- case MESA_FORMAT_A4B4G4R4_UINT:
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_4_4_4_4 && !swapBytes)
- return true;
-
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && swapBytes)
- return true;
- return false;
-
- case MESA_FORMAT_R4G4B4A4_UINT:
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && !swapBytes)
- return true;
-
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_4_4_4_4 && swapBytes)
- return true;
-
- return false;
-
- case MESA_FORMAT_B4G4R4A4_UINT:
- return format == GL_BGRA_INTEGER && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&
- !swapBytes;
-
- case MESA_FORMAT_A4R4G4B4_UINT:
- return false;
-
- case MESA_FORMAT_A1B5G5R5_UINT:
- return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
- !swapBytes;
-
- case MESA_FORMAT_B5G5R5A1_UINT:
- return format == GL_BGRA_INTEGER && type == GL_UNSIGNED_SHORT_1_5_5_5_REV &&
- !swapBytes;
-
- case MESA_FORMAT_A1R5G5B5_UINT:
- return format == GL_BGRA_INTEGER && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
- !swapBytes;
-
- case MESA_FORMAT_R5G5B5A1_UINT:
- return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT_1_5_5_5_REV;
-
- case MESA_FORMAT_A8B8G8R8_UINT:
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
- return true;
-
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes)
- return true;
- return false;
-
- case MESA_FORMAT_A8R8G8B8_UINT:
- if (format == GL_BGRA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8 &&
- !swapBytes)
- return true;
-
- if (format == GL_BGRA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- swapBytes)
- return true;
-
- return false;
-
- case MESA_FORMAT_R8G8B8A8_UINT:
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- !swapBytes)
- return true;
-
- if (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
- return true;
-
+ if (_mesa_is_format_compressed(mformat)) {
+ if (error)
+ *error = GL_INVALID_ENUM;
return false;
+ }
- case MESA_FORMAT_B8G8R8A8_UINT:
- if (format == GL_BGRA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
- !swapBytes)
- return true;
-
- if (format == GL_BGRA_INTEGER && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
- return true;
-
+ if (swapBytes && !_mesa_swap_bytes_in_type_enum(&type))
return false;
- case MESA_FORMAT_R9G9B9E5_FLOAT:
- return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV &&
- !swapBytes;
-
- case MESA_FORMAT_R11G11B10_FLOAT:
- return format == GL_RGB && type == GL_UNSIGNED_INT_10F_11F_11F_REV &&
- !swapBytes;
-
- case MESA_FORMAT_Z_FLOAT32:
- return format == GL_DEPTH_COMPONENT && type == GL_FLOAT && !swapBytes;
+ /* format/type don't include srgb and should match regardless of it. */
+ mformat = _mesa_get_srgb_format_linear(mformat);
- case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
- return format == GL_DEPTH_STENCIL &&
- type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV && !swapBytes;
+ /* intensity formats are uploaded with GL_RED, and we want to find
+ * memcpy matches for them.
+ */
+ mformat = _mesa_get_intensity_format_red(mformat);
- case MESA_FORMAT_B4G4R4X4_UNORM:
- case MESA_FORMAT_B5G5R5X1_UNORM:
- case MESA_FORMAT_R8G8B8X8_SNORM:
- case MESA_FORMAT_R8G8B8X8_SRGB:
- case MESA_FORMAT_X8B8G8R8_SRGB:
- case MESA_FORMAT_RGBX_UINT8:
- case MESA_FORMAT_RGBX_SINT8:
- case MESA_FORMAT_B10G10R10X2_UNORM:
- case MESA_FORMAT_RGBX_UNORM16:
- case MESA_FORMAT_RGBX_SNORM16:
- case MESA_FORMAT_RGBX_FLOAT16:
- case MESA_FORMAT_RGBX_UINT16:
- case MESA_FORMAT_RGBX_SINT16:
- case MESA_FORMAT_RGBX_FLOAT32:
- case MESA_FORMAT_RGBX_UINT32:
- case MESA_FORMAT_RGBX_SINT32:
+ if (format == GL_COLOR_INDEX)
return false;
- case MESA_FORMAT_R10G10B10X2_UNORM:
- return format == GL_RGB && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
- !swapBytes;
- case MESA_FORMAT_R10G10B10A2_UNORM:
- return format == GL_RGBA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
- !swapBytes;
+ mesa_format other_format = _mesa_format_from_format_and_type(format, type);
+ if (_mesa_format_is_mesa_array_format(other_format))
+ other_format = _mesa_format_from_array_format(other_format);
- case MESA_FORMAT_G8R8_SNORM:
- return format == GL_RG && type == GL_BYTE && !littleEndian &&
- !swapBytes;
-
- case MESA_FORMAT_G16R16_SNORM:
- return format == GL_RG && type == GL_SHORT && !littleEndian &&
- !swapBytes;
-
- case MESA_FORMAT_B8G8R8X8_SRGB:
- case MESA_FORMAT_X8R8G8B8_SRGB:
- return false;
- default:
- assert(_mesa_is_format_compressed(mesa_format));
- if (error)
- *error = GL_INVALID_ENUM;
- }
- return false;
+ return other_format == mformat;
}
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 92d0c341df4..cbeb237fba0 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -779,6 +779,9 @@ extern mesa_format
_mesa_get_linear_format_srgb(mesa_format format);
extern mesa_format
+_mesa_get_intensity_format_red(mesa_format format);
+
+extern mesa_format
_mesa_get_uncompressed_format(mesa_format format);
extern unsigned int
diff --git a/src/mesa/main/glformats.c b/src/mesa/main/glformats.c
index 41becd47d8b..c450ffc8ed7 100644
--- a/src/mesa/main/glformats.c
+++ b/src/mesa/main/glformats.c
@@ -3512,6 +3512,36 @@ get_swizzle_from_gl_format(GLenum format, uint8_t *swizzle)
}
}
+bool
+_mesa_swap_bytes_in_type_enum(GLenum *type)
+{
+ switch (*type) {
+ case GL_UNSIGNED_INT_8_8_8_8:
+ *type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ return true;
+ case GL_UNSIGNED_INT_8_8_8_8_REV:
+ *type = GL_UNSIGNED_INT_8_8_8_8;
+ return true;
+ case GL_UNSIGNED_SHORT_8_8_MESA:
+ *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
+ return true;
+ case GL_UNSIGNED_SHORT_8_8_REV_MESA:
+ *type = GL_UNSIGNED_SHORT_8_8_MESA;
+ return true;
+ case GL_BYTE:
+ case GL_UNSIGNED_BYTE:
+ /* format/types that are arrays of 8-bit values are unaffected by
+ * swapBytes.
+ */
+ return true;
+ default:
+ /* swapping bytes on 4444, 1555, or >8 bit per channel types etc. will
+ * never match a Mesa format.
+ */
+ return false;
+ }
+}
+
/**
* Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
* GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
diff --git a/src/mesa/main/glformats.h b/src/mesa/main/glformats.h
index 487e7fe80e8..0a65ef6cace 100644
--- a/src/mesa/main/glformats.h
+++ b/src/mesa/main/glformats.h
@@ -147,6 +147,9 @@ _mesa_base_tex_format(const struct gl_context *ctx, GLint internalFormat );
extern uint32_t
_mesa_format_from_format_and_type(GLenum format, GLenum type);
+bool
+_mesa_swap_bytes_in_type_enum(GLenum *type);
+
extern uint32_t
_mesa_tex_format_from_format_and_type(const struct gl_context *ctx,
GLenum gl_format, GLenum type);
diff --git a/src/mesa/main/tests/mesa_formats.cpp b/src/mesa/main/tests/mesa_formats.cpp
index e4f95163c28..b7f036bb3c2 100644
--- a/src/mesa/main/tests/mesa_formats.cpp
+++ b/src/mesa/main/tests/mesa_formats.cpp
@@ -50,18 +50,11 @@ TEST(MesaFormatsTest, FormatTypeAndComps)
*/
if (!_mesa_is_format_compressed(f)) {
GLenum datatype = 0;
- GLenum error = 0;
GLuint comps = 0;
/* If the datatype is zero, the format was not handled */
_mesa_uncompressed_format_to_type_and_comps(f, &datatype, &comps);
EXPECT_NE(datatype, (GLenum)0);
-
- /* If the error isn't NO_ERROR, the format was not handled.
- * Use an arbitrary GLenum format. */
- _mesa_format_matches_format_and_type(f, GL_RG, datatype,
- GL_FALSE, &error);
- EXPECT_EQ((GLenum)GL_NO_ERROR, error);
}
}
@@ -138,6 +131,16 @@ TEST(MesaFormatsTest, FormatSanity)
}
}
+TEST(MesaFormatsTest, IntensityToRed)
+{
+ EXPECT_EQ(_mesa_get_intensity_format_red(MESA_FORMAT_I_UNORM8),
+ MESA_FORMAT_R_UNORM8);
+ EXPECT_EQ(_mesa_get_intensity_format_red(MESA_FORMAT_I_SINT32),
+ MESA_FORMAT_R_SINT32);
+ EXPECT_EQ(_mesa_get_intensity_format_red(MESA_FORMAT_R8G8B8A8_UNORM),
+ MESA_FORMAT_R8G8B8A8_UNORM);
+}
+
static mesa_format fffat_wrap(GLenum format, GLenum type)
{
uint32_t f = _mesa_format_from_format_and_type(format, type);
@@ -159,3 +162,19 @@ TEST(MesaFormatsTest, FormatFromFormatAndType)
EXPECT_TRUE(_mesa_format_is_mesa_array_format(_mesa_format_from_format_and_type(GL_DEPTH_COMPONENT,
GL_BYTE)));
}
+
+TEST(MesaFormatsTest, FormatMatchesFormatAndType)
+{
+ EXPECT_TRUE(_mesa_format_matches_format_and_type(MESA_FORMAT_RGBA_UNORM16,
+ GL_RGBA,
+ GL_UNSIGNED_SHORT, false,
+ NULL));
+ EXPECT_TRUE(_mesa_format_matches_format_and_type(MESA_FORMAT_S_UINT8,
+ GL_STENCIL_INDEX,
+ GL_UNSIGNED_BYTE, false,
+ NULL));
+ EXPECT_TRUE(_mesa_format_matches_format_and_type(MESA_FORMAT_Z_UNORM16,
+ GL_DEPTH_COMPONENT,
+ GL_UNSIGNED_SHORT, false,
+ NULL));
+}