Mesa (master): util: Updated util_format_is_array to be more accurate.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Nov 28 19:14:54 UTC 2012


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

Author: James Benton <jbenton at vmware.com>
Date:   Wed Jul 11 15:32:47 2012 +0100

util: Updated util_format_is_array to be more accurate.

Will allow formats with padding, e.g. RGBX.
Will now allow swizzled formats as long as the alpha is channel 3.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/auxiliary/util/u_format.c |   14 ++++++++++++--
 src/gallium/auxiliary/util/u_format.h |    5 ++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index f572a61..ddce956 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -147,9 +147,12 @@ util_format_is_array(const struct util_format_description *desc)
    }
 
    for (chan = 0; chan < desc->nr_channels; ++chan) {
-      if (desc->swizzle[chan] != chan)
+      if (desc->channel[chan].size != desc->channel[0].size)
          return FALSE;
 
+      if (desc->channel[chan].type == UTIL_FORMAT_TYPE_VOID && (chan + 1) == desc->nr_channels)
+         continue;
+
       if (desc->channel[chan].type != desc->channel[0].type)
          return FALSE;
 
@@ -158,9 +161,16 @@ util_format_is_array(const struct util_format_description *desc)
 
       if (desc->channel[chan].pure_integer != desc->channel[0].pure_integer)
          return FALSE;
+   }
 
-      if (desc->channel[chan].size != desc->channel[0].size)
+   if (desc->nr_channels == 4) {
+      if (desc->swizzle[3] < 3)
          return FALSE;
+   } else {
+      for (chan = 0; chan < desc->nr_channels; ++chan) {
+         if (desc->swizzle[chan] != chan)
+            return FALSE;
+      }
    }
 
    return TRUE;
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index a718389..25bfd23 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -592,7 +592,10 @@ 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
+ * are of the same type and can be loaded from memory as a vector.
+ *
+ * If format is 4 channel it can be swizzled (eg BGRA) as long
+ * as the alpha is the 3rd channel.
  */
 boolean
 util_format_is_array(const struct util_format_description *desc);




More information about the mesa-commit mailing list