aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2019-09-06 14:09:37 -0700
committerEric Anholt <[email protected]>2019-11-07 19:43:41 +0000
commitd27dda907aca8d7b92b7330c498958e01eb962ae (patch)
tree50ad3fd44eac9aaa455a6ee5043ed2b7df76c606 /src/mesa/main
parent6b1c250245e4e29ea42e853ee094a8d6e9d1b665 (diff)
mesa: Prepare for the MESA_FORMAT_* enum to be sparse.
To redefine MESA_FORMAT in terms of PIPE_FORMAT enums, we need to fix places where we iterated up to MESA_FORMAT_COUNT. I use _mesa_get_format_name(f) == NULL as the signal that it's not an enum value with a MESA_FORMAT. Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/format_info.py2
-rw-r--r--src/mesa/main/formats.c17
-rw-r--r--src/mesa/main/tests/mesa_formats.cpp6
3 files changed, 21 insertions, 4 deletions
diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py
index d3ec486f155..42c236c7a6a 100644
--- a/src/mesa/main/format_info.py
+++ b/src/mesa/main/format_info.py
@@ -182,7 +182,7 @@ bf_map = {
}
for fmat in formats:
- print(' {')
+ print(' [{0}] = {{'.format(fmat.name))
print(' .Name = {0},'.format(fmat.name))
print(' .StrName = "{0}",'.format(fmat.name))
print(' .Layout = {0},'.format('MESA_FORMAT_LAYOUT_' + fmat.layout.upper()))
diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index 9c65e7decc7..5b420bf59de 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -85,6 +85,13 @@ _mesa_get_format_info(mesa_format format)
{
const struct mesa_format_info *info = &format_info[format];
STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT);
+
+ /* The MESA_FORMAT_* enums are sparse, don't return a format info
+ * for empty entries.
+ */
+ if (info->Name == MESA_FORMAT_NONE && format != MESA_FORMAT_NONE)
+ return NULL;
+
assert(info->Name == format);
return info;
}
@@ -95,6 +102,8 @@ const char *
_mesa_get_format_name(mesa_format format)
{
const struct mesa_format_info *info = _mesa_get_format_info(format);
+ if (!info)
+ return NULL;
return info->StrName;
}
@@ -465,7 +474,7 @@ format_array_format_table_init(void)
for (f = 1; f < MESA_FORMAT_COUNT; ++f) {
info = _mesa_get_format_info(f);
- if (!info->ArrayFormat)
+ if (!info || !info->ArrayFormat)
continue;
#if UTIL_ARCH_LITTLE_ENDIAN
@@ -1409,15 +1418,17 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,
case MESA_FORMAT_COUNT:
assert(0);
return;
- default:
+ default: {
+ const char *name = _mesa_get_format_name(format);
/* Warn if any formats are not handled */
_mesa_problem(NULL, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",
- _mesa_get_format_name(format));
+ name ? name : "???");
assert(format == MESA_FORMAT_NONE ||
_mesa_is_format_compressed(format));
*datatype = 0;
*comps = 1;
}
+ }
}
/**
diff --git a/src/mesa/main/tests/mesa_formats.cpp b/src/mesa/main/tests/mesa_formats.cpp
index b7f036bb3c2..6842d82e9cf 100644
--- a/src/mesa/main/tests/mesa_formats.cpp
+++ b/src/mesa/main/tests/mesa_formats.cpp
@@ -45,6 +45,9 @@ TEST(MesaFormatsTest, FormatTypeAndComps)
mesa_format f = (mesa_format) fi;
SCOPED_TRACE(_mesa_get_format_name(f));
+ if (!_mesa_get_format_name(f))
+ continue;
+
/* This function will emit a problem/warning if the format is
* not handled.
*/
@@ -68,6 +71,9 @@ TEST(MesaFormatsTest, FormatSanity)
for (int fi = 0; fi < MESA_FORMAT_COUNT; ++fi) {
mesa_format f = (mesa_format) fi;
SCOPED_TRACE(_mesa_get_format_name(f));
+ if (!_mesa_get_format_name(f))
+ continue;
+
GLenum datatype = _mesa_get_format_datatype(f);
GLint r = _mesa_get_format_bits(f, GL_RED_BITS);
GLint g = _mesa_get_format_bits(f, GL_GREEN_BITS);