diff options
author | Alejandro PiƱeiro <[email protected]> | 2019-02-06 18:11:19 +0100 |
---|---|---|
committer | Arcady Goldmints-Orlov <[email protected]> | 2019-06-30 16:58:26 -0500 |
commit | c23522add233301f10cd7ca2d2570f10b1184815 (patch) | |
tree | 1b21260c9e48b5f699e3504737999291d9cd52c9 /src/compiler | |
parent | 12355c7e910222d97ecf23567e6f17841993acfe (diff) |
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 <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/glsl_types.h | 60 |
1 files 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 |