util/format: add helper to check if a format is scaled.
authorDave Airlie <airlied@redhat.com>
Mon, 8 Feb 2021 04:58:50 +0000 (14:58 +1000)
committerMarge Bot <eric+marge@anholt.net>
Tue, 16 Feb 2021 05:31:11 +0000 (05:31 +0000)
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 <ajax@redhat.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8907>

src/util/format/u_format.c
src/util/format/u_format.h

index b5cb27de3d9a1fc0b1014b70c1c9ff0cfef29d83..078b5ed8accf77465e53ee99f269464f06b0d1f6 100644 (file)
@@ -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)
 {
index d0fa84194ebbad9b001d261df2e8c854834193d7..250489bcd571d7bcf98dc5e39b16b8325964c324 100644 (file)
@@ -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