summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2011-10-08 17:41:33 +0100
committerDave Airlie <[email protected]>2011-10-08 17:44:58 +0100
commit61285c6cfa9ce6086d62fa08bc9e3813f0b30d3d (patch)
tree7cbc2984288ac45a20e3a1ccfa6c3a70e43399aa
parentb861479f83ea140bfe24357d09f18a6d026d97b5 (diff)
u_format: add inline helper to find first non void channel
This is used in a few places in drivers as well, also the integer support can use it as well. Signed-off-by: Dave Airlie <[email protected]>
-rw-r--r--src/gallium/auxiliary/util/u_format.c10
-rw-r--r--src/gallium/auxiliary/util/u_format.h20
2 files changed, 22 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
index 9bf42583eec..129b8e93ed3 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -52,14 +52,8 @@ util_format_is_float(enum pipe_format format)
return FALSE;
}
- /* Find the first non-void channel. */
- for (i = 0; i < 4; i++) {
- if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
- break;
- }
- }
-
- if (i == 4) {
+ i = util_format_get_first_non_void_channel(format);
+ if (i == -1) {
return FALSE;
}
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 98528ea595f..96066532631 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -806,6 +806,26 @@ util_format_get_nr_components(enum pipe_format format)
return desc->nr_channels;
}
+/**
+ * Return the index of the first non-void channel
+ * -1 if no non-void channels
+ */
+static INLINE int
+util_format_get_first_non_void_channel(enum pipe_format format)
+{
+ const struct util_format_description *desc = util_format_description(format);
+ int i;
+
+ for (i = 0; i < 4; i++)
+ if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
+ break;
+
+ if (i == 4)
+ return -1;
+
+ return i;
+}
+
/*
* Format access functions.
*/