diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-05-14 12:34:35 -0400 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-05-26 22:31:31 +0000 |
commit | 35938c15e22e3021f7693425f0d2134845c81f6b (patch) | |
tree | bbdf867fd5f7386ef109de8f5028874c11d85e5a | |
parent | 8cc7711924fd0f3c76e22e527e21d8f8368e5395 (diff) |
util: Add SATURATE macro
Equivalent to clamp(x, 0.0, 1.0) or fsat in NIR. Useful for format
packing, among other uses given the variety of substituions in-tree.
v2: Drop brackets (Eric).
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5100>
-rw-r--r-- | src/util/macros.h | 3 | ||||
-rw-r--r-- | src/util/u_math.h | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/util/macros.h b/src/util/macros.h index fcace4e351d..57beaf72fae 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -291,6 +291,9 @@ do { \ /** Clamp X to [MIN,MAX]. Turn NaN into MIN, arbitrarily. */ #define CLAMP( X, MIN, MAX ) ( (X)>(MIN) ? ((X)>(MAX) ? (MAX) : (X)) : (MIN) ) +/* Syntax sugar occuring frequently in graphics code */ +#define SATURATE( X ) CLAMP(X, 0.0f, 1.0f) + /** Minimum of two values: */ #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) diff --git a/src/util/u_math.h b/src/util/u_math.h index 59266c16922..b725489b520 100644 --- a/src/util/u_math.h +++ b/src/util/u_math.h @@ -667,6 +667,9 @@ util_memcpy_cpu_to_le32(void * restrict dest, const void * restrict src, size_t */ #define CLAMP( X, MIN, MAX ) ( (X)>(MIN) ? ((X)>(MAX) ? (MAX) : (X)) : (MIN) ) +/* Syntax sugar occuring frequently in graphics code */ +#define SATURATE( X ) CLAMP(X, 0.0f, 1.0f) + #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) #define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) |