From: Dave Airlie Date: Sat, 8 Oct 2011 16:41:33 +0000 (+0100) Subject: u_format: add inline helper to find first non void channel X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61285c6cfa9ce6086d62fa08bc9e3813f0b30d3d;p=mesa.git u_format: add inline helper to find first non void channel This is used in a few places in drivers as well, also the integer support can use it as well. Signed-off-by: Dave Airlie --- diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 9bf42583eec..129b8e93ed3 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -52,14 +52,8 @@ util_format_is_float(enum pipe_format format) return FALSE; } - /* Find the first non-void channel. */ - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } - - if (i == 4) { + i = util_format_get_first_non_void_channel(format); + if (i == -1) { return FALSE; } diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 98528ea595f..96066532631 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -806,6 +806,26 @@ util_format_get_nr_components(enum pipe_format format) return desc->nr_channels; } +/** + * Return the index of the first non-void channel + * -1 if no non-void channels + */ +static INLINE int +util_format_get_first_non_void_channel(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + int i; + + for (i = 0; i < 4; i++) + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) + break; + + if (i == 4) + return -1; + + return i; +} + /* * Format access functions. */