From: Eric Anholt Date: Fri, 6 Sep 2019 21:09:37 +0000 (-0700) Subject: mesa: Prepare for the MESA_FORMAT_* enum to be sparse. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d27dda907aca8d7b92b7330c498958e01eb962ae;p=mesa.git 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 --- diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c b/src/mesa/drivers/dri/i965/brw_surface_formats.c index b42bbf870b6..570122e2d1d 100644 --- a/src/mesa/drivers/dri/i965/brw_surface_formats.c +++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c @@ -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); 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); diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index f4efb31524c..a65e4952755 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -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; } diff --git a/src/mesa/state_tracker/tests/st_format.c b/src/mesa/state_tracker/tests/st_format.c index 69191015b11..837b43b1f82 100644 --- a/src/mesa/state_tracker/tests/st_format.c +++ b/src/mesa/state_tracker/tests/st_format.c @@ -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));