[Mesa-dev] [PATCH 08/18] compiler: utility to get the depth of multidimensional array
Alejandro PiƱeiro
apinheiro at igalia.com
Fri Jun 29 14:28:54 UTC 2018
From: Antia Puentes <apuentes at igalia.com>
---
src/compiler/glsl_types.h | 15 +++++++++++++++
src/compiler/nir_types.cpp | 6 ++++++
src/compiler/nir_types.h | 3 +++
3 files changed, 24 insertions(+)
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index efc63248656..e5dcd39180e 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -675,6 +675,21 @@ public:
return t;
}
+ /**
+ * Returns the depth of a multidimensional array
+ */
+ unsigned array_depth() const
+ {
+ const glsl_type *t = this;
+ unsigned depth = 0;
+ while (t->is_array()) {
+ depth++;
+ t = t->fields.array;
+ }
+
+ return depth;
+ }
+
/**
* Return the total number of elements in an array including the elements
* in arrays of arrays.
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 1fc6bfa7175..a3c39d11383 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -483,3 +483,9 @@ glsl_atomic_uint_type(void)
{
return glsl_type::atomic_uint_type;
}
+
+unsigned
+glsl_array_depth(const struct glsl_type *type)
+{
+ return type->array_depth();
+}
diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h
index 18af1e17aba..4519ab617c4 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -85,6 +85,9 @@ unsigned glsl_get_sampler_target(const struct glsl_type *type);
unsigned glsl_get_record_location_offset(const struct glsl_type *type,
unsigned length);
+
+unsigned glsl_array_depth(const struct glsl_type *type);
+
static inline unsigned
glsl_get_bit_size(const struct glsl_type *type)
{
--
2.14.1
More information about the mesa-dev
mailing list