Mesa (master): util/format: add helper to check if a format is scaled.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Feb 16 05:47:48 UTC 2021


Module: Mesa
Branch: master
Commit: 8258726d904061fd82b3503eab312ff81117c0d2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8258726d904061fd82b3503eab312ff81117c0d2

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb  8 14:58:50 2021 +1000

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 <ajax at redhat.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8907>

---

 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 b5cb27de3d9..078b5ed8acc 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 d0fa84194eb..250489bcd57 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



More information about the mesa-commit mailing list