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 <marek.olsak@amd.com>
This commit is contained in:
Eric Anholt 2019-09-06 14:09:37 -07:00
parent 6b1c250245
commit d27dda907a
6 changed files with 29 additions and 4 deletions

View File

@ -217,6 +217,8 @@ intel_screen_init_surface_formats(struct intel_screen *screen)
gen += 5;
for (format = MESA_FORMAT_NONE + 1; format < MESA_FORMAT_COUNT; format++) {
if (!_mesa_get_format_name(format))
continue;
enum isl_format texture, render;
bool is_integer = _mesa_is_format_integer_color(format);

View File

@ -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()))

View File

@ -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;
}
}
}
/**

View File

@ -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);

View File

@ -2435,6 +2435,9 @@ st_choose_matching_format(struct st_context *st, unsigned bind,
mesa_format mesa_format;
for (mesa_format = 1; mesa_format < MESA_FORMAT_COUNT; mesa_format++) {
if (!_mesa_get_format_name(mesa_format))
continue;
if (_mesa_is_format_srgb(mesa_format)) {
continue;
}

View File

@ -66,6 +66,9 @@ int main(int argc, char **argv)
/* test all Mesa formats */
for (i = 1; i < MESA_FORMAT_COUNT; i++) {
if (!_mesa_get_format_name(i))
continue;
enum pipe_format pf;
assert(!st_compressed_format_fallback(st, i));