From 34075d4133f83e6fec31a62ee4b1b3c565abda56 Mon Sep 17 00:00:00 2001 From: James Benton Date: Fri, 18 May 2012 17:27:19 +0100 Subject: util: Added util_format_is_array. This function checks whether a format description is in a simple array format. Reviewed-by: Jose Fonseca --- src/gallium/auxiliary/util/u_format.c | 32 ++++++++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_format.h | 7 +++++++ 2 files changed, 39 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index cfc4a17a062..6f452983592 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -158,6 +158,38 @@ util_format_is_pure_uint(enum pipe_format format) return (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED && desc->channel[i].pure_integer) ? TRUE : FALSE; } +boolean +util_format_is_array(const struct util_format_description *desc) +{ + unsigned chan; + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || + desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB || + desc->block.width != 1 || + desc->block.height != 1) { + return FALSE; + } + + for (chan = 0; chan < desc->nr_channels; ++chan) { + if (desc->swizzle[chan] != chan) + return FALSE; + + if (desc->channel[chan].type != desc->channel[0].type) + return FALSE; + + if (desc->channel[chan].normalized != desc->channel[0].normalized) + return FALSE; + + if (desc->channel[chan].pure_integer != desc->channel[0].pure_integer) + return FALSE; + + if (desc->channel[chan].size != desc->channel[0].size) + return FALSE; + } + + return TRUE; +} + boolean util_format_is_luminance_alpha(enum pipe_format format) { diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 1718fb5e240..e35e164b43d 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -590,6 +590,13 @@ util_format_is_pure_sint(enum pipe_format format); boolean util_format_is_pure_uint(enum pipe_format format); +/** + * Whether the format is a simple array format where all channels + * are of the same type and can be loaded from memory as a vector + */ +boolean +util_format_is_array(const struct util_format_description *desc); + /** * Check if the src format can be blitted to the destination format with * a simple memcpy. For example, blitting from RGBA to RGBx is OK, but not -- cgit v1.2.3