Mesa (master): glsl: calculate AoA uniform offset correctly for structs

Timothy Arceri tarceri at kemper.freedesktop.org
Thu Oct 15 09:44:42 UTC 2015


Module: Mesa
Branch: master
Commit: be822b89ac81e1fa66dfa16d108bf1deb29d4db2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=be822b89ac81e1fa66dfa16d108bf1deb29d4db2

Author: Timothy Arceri <t_arceri at yahoo.com.au>
Date:   Thu Sep 17 14:17:17 2015 +1000

glsl: calculate AoA uniform offset correctly for structs

This allows the correct offset to be calculated for use in indirect
indexing of samplers.

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>

---

 src/glsl/glsl_types.cpp |   17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index b9cb97c..575ff0e 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -1071,7 +1071,22 @@ glsl_type::record_location_offset(unsigned length) const
          const glsl_type *wa = st->without_array();
          if (wa->is_record()) {
             unsigned r_offset = wa->record_location_offset(wa->length);
-            offset += st->is_array() ? st->length * r_offset : r_offset;
+            offset += st->is_array() ?
+               st->arrays_of_arrays_size() * r_offset : r_offset;
+         } else if (st->is_array() && st->fields.array->is_array()) {
+            unsigned outer_array_size = st->length;
+            const glsl_type *base_type = st->fields.array;
+
+            /* For arrays of arrays the outer arrays take up a uniform
+             * slot for each element. The innermost array elements share a
+             * single slot so we ignore the innermost array when calculating
+             * the offset.
+             */
+            while (base_type->fields.array->is_array()) {
+               outer_array_size = outer_array_size * base_type->length;
+               base_type = base_type->fields.array;
+            }
+            offset += outer_array_size;
          } else {
             /* We dont worry about arrays here because unless the array
              * contains a structure or another array it only takes up a single




More information about the mesa-commit mailing list