From 8258726d904061fd82b3503eab312ff81117c0d2 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 8 Feb 2021 14:58:50 +1000 Subject: [PATCH] util/format: add helper to check if a format is scaled. lavapipe/llvmpipe need this to rule out scaled formats for non-vertex format usage. Note NONE is defined as scaled in u_format, but for the purposes of this helper I don't want it to be considered scaled. Reviewed-by: Adam Jackson Reviewed-by: Roland Scheidegger Part-of: --- src/util/format/u_format.c | 23 +++++++++++++++++++++++ src/util/format/u_format.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/util/format/u_format.c b/src/util/format/u_format.c index b5cb27d..078b5ed 100644 --- a/src/util/format/u_format.c +++ b/src/util/format/u_format.c @@ -234,6 +234,29 @@ util_format_is_unorm(enum pipe_format format) return desc->is_unorm; } +/** + * Returns true if the format contains scaled integer format channels. + */ +boolean +util_format_is_scaled(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + int i; + + /* format none is described as scaled but not for this check */ + if (format == PIPE_FORMAT_NONE) + return FALSE; + + /* Find the first non-void channel. */ + i = util_format_get_first_non_void_channel(format); + if (i == -1) + return FALSE; + + return !desc->channel[i].pure_integer && !desc->channel[i].normalized && + (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED || + desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED); +} + boolean util_format_is_snorm8(enum pipe_format format) { diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index d0fa841..250489b 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -729,6 +729,8 @@ util_format_is_unorm(enum pipe_format format) ATTRIBUTE_CONST; boolean util_format_is_snorm8(enum pipe_format format) ATTRIBUTE_CONST; +boolean +util_format_is_scaled(enum pipe_format format) ATTRIBUTE_CONST; /** * 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 -- 2.7.4