[Mesa-dev] [PATCH 08/22] glsl: add glsl_base_get_byte_size

Karol Herbst kherbst at redhat.com
Tue Nov 13 15:48:12 UTC 2018


Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
 src/compiler/glsl_types.h | 34 ++++++++++++++++++++++++++++++++++
 src/compiler/nir_types.h  | 30 +-----------------------------
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index f2163728610..efcbc70af26 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -1089,4 +1089,38 @@ glsl_align(unsigned int a, unsigned int align)
    return (a + align - 1) / align * align;
 }
 
+static inline unsigned
+glsl_base_get_byte_size(const enum glsl_base_type base_type)
+{
+   switch (base_type) {
+   case GLSL_TYPE_INT:
+   case GLSL_TYPE_UINT:
+   case GLSL_TYPE_BOOL:
+   case GLSL_TYPE_FLOAT: /* TODO handle mediump */
+   case GLSL_TYPE_SUBROUTINE:
+      return 4;
+
+   case GLSL_TYPE_FLOAT16:
+   case GLSL_TYPE_UINT16:
+   case GLSL_TYPE_INT16:
+      return 2;
+
+   case GLSL_TYPE_UINT8:
+   case GLSL_TYPE_INT8:
+      return 1;
+
+   case GLSL_TYPE_DOUBLE:
+   case GLSL_TYPE_INT64:
+   case GLSL_TYPE_UINT64:
+   case GLSL_TYPE_IMAGE:
+   case GLSL_TYPE_SAMPLER:
+      return 8;
+
+   default:
+      unreachable("unknown base type");
+   }
+
+   return 0;
+}
+
 #endif /* GLSL_TYPES_H */
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index 7080a23e1cc..c06d227e45a 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -94,35 +94,7 @@ unsigned glsl_atomic_size(const struct glsl_type *type);
 static inline unsigned
 glsl_get_bit_size(const struct glsl_type *type)
 {
-   switch (glsl_get_base_type(type)) {
-   case GLSL_TYPE_INT:
-   case GLSL_TYPE_UINT:
-   case GLSL_TYPE_BOOL:
-   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:
-      unreachable("unknown base type");
-   }
-
-   return 0;
+   return glsl_base_get_byte_size(glsl_get_base_type(type)) * 8;
 }
 
 bool glsl_type_is_16bit(const struct glsl_type *type);
-- 
2.19.1



More information about the mesa-dev mailing list