summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2016-03-15 17:52:06 +1100
committerTimothy Arceri <[email protected]>2016-03-31 12:51:06 +1100
commit8b6f8fe5030a0bcc6cce6bf3aae48795802b6fb6 (patch)
treefcab92453c0542088cc9a41eac3dd1bb5876d1ef /src
parentba7a7d4c39c06c6231e3f9a05f5e32378b76db6a (diff)
glsl: add helper for counting varyings
This will be used to get a count of the number of varying name strings we are required to generate for use with the query api. Reviewed-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl_types.cpp32
-rw-r--r--src/compiler/glsl_types.h6
2 files changed, 38 insertions, 0 deletions
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index c6a742e3aaf..39585bff3b9 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -1350,6 +1350,38 @@ glsl_type::uniform_locations() const
}
}
+unsigned
+glsl_type::varying_count() const
+{
+ unsigned size = 0;
+
+ switch (this->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_BOOL:
+ return 1;
+
+ case GLSL_TYPE_STRUCT:
+ case GLSL_TYPE_INTERFACE:
+ for (unsigned i = 0; i < this->length; i++)
+ size += this->fields.structure[i].type->varying_count();
+ return size;
+ case GLSL_TYPE_ARRAY:
+ /* Don't count innermost array elements */
+ if (this->without_array()->is_record() ||
+ this->without_array()->is_interface() ||
+ this->fields.array->is_array())
+ return this->length * this->fields.array->varying_count();
+ else
+ return this->fields.array->varying_count();
+ default:
+ assert(!"unsupported varying type");
+ return 0;
+ }
+}
+
bool
glsl_type::can_implicitly_convert_to(const glsl_type *desired,
_mesa_glsl_parse_state *state) const
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 4f4cfea1201..dd46479755a 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -327,6 +327,12 @@ struct glsl_type {
unsigned uniform_locations() const;
/**
+ * Used to count the number of varyings contained in the type ignoring
+ * innermost array elements.
+ */
+ unsigned varying_count() const;
+
+ /**
* Calculate the number of attribute slots required to hold this type
*
* This implements the language rules of GLSL 1.50 for counting the number