From: Alejandro PiƱeiro Date: Wed, 6 Feb 2019 17:11:19 +0000 (+0100) Subject: glsl_types: add type::bit_size and glsl_base_type_bit_size helpers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c23522add233301f10cd7ca2d2570f10b1184815;p=mesa.git 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 --- 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) @@ -828,6 +863,15 @@ public: return size; } + /** + * 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. */