From 9bad7afbc2ca6003da9a19c486b81d6ed0b8b0df Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 27 May 2015 21:31:59 +1000 Subject: glsl: add helper for calculating size of AoA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V2: return 0 if not array rather than -1 Reviewed-by: Tapani Pälli Reviewed-by: Ian Romanick --- 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 23ada15b854..3ec764219de 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -577,6 +577,25 @@ struct glsl_type { return t; } + /** + * 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 0; + + 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. */ -- cgit v1.2.3