[Mesa-dev] [PATCH 09/19] glsl: add helper for calculating size of AoA

Timothy Arceri t_arceri at yahoo.com.au
Sat Jun 20 05:33:06 PDT 2015


---
 src/glsl/glsl_types.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index f54a939..c48977c 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -537,6 +537,25 @@ struct glsl_type {
    }
 
    /**
+    * Return the total number of elements in an array including the elements
+    * in arrays of arrays.
+    */
+   unsigned arrays_of_arrays_size() const
+   {
+      if (!is_array())
+         return -1;
+
+      unsigned size = length;
+      const glsl_type *base_type = fields.array;
+
+      while (base_type->is_array()) {
+         size = size * base_type->length;
+         base_type = base_type->fields.array;
+      }
+      return size;
+   }
+
+   /**
     * Return the amount of atomic counter storage required for a type.
     */
    unsigned atomic_size() const
-- 
2.1.0



More information about the mesa-dev mailing list