Mesa (master): glsl_types: add type::bit_size and glsl_base_type_bit_size helpers
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jul 1 10:29:26 UTC 2019
Module: Mesa
Branch: master
Commit: c23522add233301f10cd7ca2d2570f10b1184815
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c23522add233301f10cd7ca2d2570f10b1184815
Author: Alejandro Piñeiro <apinheiro at igalia.com>
Date: Wed Feb 6 18:11:19 2019 +0100
glsl_types: add type::bit_size and glsl_base_type_bit_size helpers
Note that the nir_types glsl_get_bit_size is not a wrapper of this
one, because for bools at the nir level, we want to return size 1, but
at the glsl_types we want to return 32.
v2: reuse the new method in order to simplify is_16bit and is_32bit
helpers (Timothy)
v3: add a comment clarifying the difference between
glsl_base_type_bit_size and glsl_get_bit_size.
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
---
src/compiler/glsl_types.h | 60 ++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 52 insertions(+), 8 deletions(-)
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index e986b51d523..1e550986e47 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -91,20 +91,55 @@ enum glsl_base_type {
GLSL_TYPE_ERROR
};
+/* Return the bit size of a type. Note that this differs from
+ * glsl_get_bit_size in that it returns 32 bits for bools, whereas at
+ * the NIR level we would want to return 1 bit for bools.
+ */
+static unsigned glsl_base_type_bit_size(enum glsl_base_type type)
+{
+ switch (type) {
+ case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_FLOAT: /* TODO handle mediump */
+ case GLSL_TYPE_SUBROUTINE:
+ return 32;
+
+ case GLSL_TYPE_FLOAT16:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
+ return 16;
+
+ case GLSL_TYPE_UINT8:
+ case GLSL_TYPE_INT8:
+ return 8;
+
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_SAMPLER:
+ return 64;
+
+ default:
+ /* For GLSL_TYPE_STRUCT etc, it should be ok to return 0. This usually
+ * happens when calling this method through is_64bit and is_16bit
+ * methods
+ */
+ return 0;
+ }
+
+ return 0;
+}
+
static inline bool glsl_base_type_is_16bit(enum glsl_base_type type)
{
- return type == GLSL_TYPE_FLOAT16 ||
- type == GLSL_TYPE_UINT16 ||
- type == GLSL_TYPE_INT16;
+ return glsl_base_type_bit_size(type) == 16;
}
static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
{
- return type == GLSL_TYPE_DOUBLE ||
- type == GLSL_TYPE_UINT64 ||
- type == GLSL_TYPE_INT64 ||
- type == GLSL_TYPE_IMAGE ||
- type == GLSL_TYPE_SAMPLER;
+ return glsl_base_type_bit_size(type) == 64;
}
static inline bool glsl_base_type_is_integer(enum glsl_base_type type)
@@ -829,6 +864,15 @@ public:
}
/**
+ * Return bit size for this type.
+ */
+ unsigned bit_size() const
+ {
+ return glsl_base_type_bit_size(this->base_type);
+ }
+
+
+ /**
* Query whether or not a type is an atomic_uint.
*/
bool is_atomic_uint() const
More information about the mesa-commit
mailing list