[Mesa-dev] [PATCH 18/21] glsl: Squish ir_variable::max_ifc_array_access and ::state_slots together
Ian Romanick
idr at freedesktop.org
Tue May 27 19:49:13 PDT 2014
From: Ian Romanick <ian.d.romanick at intel.com>
At least one of these pointers must be NULL, and we can determine which
will be NULL by looking at other fields. Use this information to store
both pointers in the same location.
If anyone can think of a better name for the union than "u", I'm all
ears.
Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
by 204KiB on 64-bit.
Before: IR MEM: variable usage / name / total: 5746368 1121441 6867809
After: IR MEM: variable usage / name / total: 5537064 1121441 6658505
Reduces the peak ir_variable memory usage in a trimmed apitrace of dota2
by 102KiB on 32-bit.
Before: IR MEM: variable usage / name / total: 4327584 787727 5115311
After: IR MEM: variable usage / name / total: 4222932 787727 5010659
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/glsl/ir.cpp | 4 ++-
src/glsl/ir.h | 78 ++++++++++++++++++++++++++++++---------------------
src/glsl/ir_clone.cpp | 4 +--
3 files changed, 51 insertions(+), 35 deletions(-)
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 69a0345..50660ac 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1533,7 +1533,7 @@ ir_swizzle::variable_referenced() const
ir_variable::ir_variable(const struct glsl_type *type, const char *name,
ir_variable_mode mode)
- : ir_instruction(ir_type_variable), max_ifc_array_access(NULL)
+ : ir_instruction(ir_type_variable)
{
this->type = type;
@@ -1546,6 +1546,8 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
this->name = ralloc_strdup(this, name);
}
+ this->u.max_ifc_array_access = NULL;
+
this->data.explicit_location = false;
this->data.has_initializer = false;
this->data.location = -1;
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index ab9f27b..95182fb 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -476,7 +476,7 @@ public:
assert(this->interface_type == NULL);
this->interface_type = type;
if (this->is_interface_instance()) {
- this->max_ifc_array_access =
+ this->u.max_ifc_array_access =
rzalloc_array(this, unsigned, type->length);
}
}
@@ -488,7 +488,7 @@ public:
*/
void change_interface_type(const struct glsl_type *type)
{
- if (this->max_ifc_array_access != NULL) {
+ if (this->u.max_ifc_array_access != NULL) {
/* max_ifc_array_access has already been allocated, so make sure the
* new interface has the same number of fields as the old one.
*/
@@ -505,7 +505,7 @@ public:
*/
void reinit_interface_type(const struct glsl_type *type)
{
- if (this->max_ifc_array_access != NULL) {
+ if (this->u.max_ifc_array_access != NULL) {
#ifndef NDEBUG
/* Redeclaring gl_PerVertex is only allowed if none of the built-ins
* it defines have been accessed yet; so it's safe to throw away the
@@ -513,10 +513,10 @@ public:
* zero.
*/
for (unsigned i = 0; i < this->interface_type->length; i++)
- assert(this->max_ifc_array_access[i] == 0);
+ assert(this->u.max_ifc_array_access[i] == 0);
#endif
- ralloc_free(this->max_ifc_array_access);
- this->max_ifc_array_access = NULL;
+ ralloc_free(this->u.max_ifc_array_access);
+ this->u.max_ifc_array_access = NULL;
}
this->interface_type = NULL;
init_interface_type(type);
@@ -535,33 +535,45 @@ public:
*/
inline unsigned *get_max_ifc_array_access()
{
- return this->max_ifc_array_access;
+ assert(this->data._num_state_slots == 0);
+ return this->u.max_ifc_array_access;
}
inline unsigned get_num_state_slots() const
{
+ assert(!this->is_interface_instance()
+ || this->data._num_state_slots == 0);
return this->data._num_state_slots;
}
inline void set_num_state_slots(unsigned n)
{
+ assert(!this->is_interface_instance()
+ || n == 0);
this->data._num_state_slots = n;
}
inline ir_state_slot *get_state_slots()
{
- return this->state_slots;
+ return this->is_interface_instance() ? NULL : this->u.state_slots;
+ }
+
+ inline const ir_state_slot *get_state_slots() const
+ {
+ return this->is_interface_instance() ? NULL : this->u.state_slots;
}
inline ir_state_slot *allocate_state_slots(unsigned n)
{
- this->state_slots = ralloc_array(this, ir_state_slot, n);
+ assert(!this->is_interface_instance());
+
+ this->u.state_slots = ralloc_array(this, ir_state_slot, n);
this->data._num_state_slots = 0;
- if (this->state_slots != NULL)
+ if (this->u.state_slots != NULL)
this->data._num_state_slots = n;
- return this->state_slots;
+ return this->u.state_slots;
}
/**
@@ -818,28 +830,30 @@ public:
private:
static const char *const warn_extension_table[];
- /**
- * For variables which satisfy the is_interface_instance() predicate, this
- * points to an array of integers such that if the ith member of the
- * interface block is an array, max_ifc_array_access[i] is the maximum
- * array element of that member that has been accessed. If the ith member
- * of the interface block is not an array, max_ifc_array_access[i] is
- * unused.
- *
- * For variables whose type is not an interface block, this pointer is
- * NULL.
- */
- unsigned *max_ifc_array_access;
+ union {
+ /**
+ * For variables which satisfy the is_interface_instance() predicate,
+ * this points to an array of integers such that if the ith member of
+ * the interface block is an array, max_ifc_array_access[i] is the
+ * maximum array element of that member that has been accessed. If the
+ * ith member of the interface block is not an array,
+ * max_ifc_array_access[i] is unused.
+ *
+ * For variables whose type is not an interface block, this pointer is
+ * NULL.
+ */
+ unsigned *max_ifc_array_access;
- /**
- * Built-in state that backs this uniform
- *
- * Once set at variable creation, \c state_slots must remain invariant.
- *
- * If the variable is not a uniform, \c _num_state_slots will be zero and
- * \c state_slots will be \c NULL.
- */
- ir_state_slot *state_slots;
+ /**
+ * Built-in state that backs this uniform
+ *
+ * Once set at variable creation, \c state_slots must remain invariant.
+ *
+ * If the variable is not a uniform, \c _num_state_slots will be zero
+ * and \c state_slots will be \c NULL.
+ */
+ ir_state_slot *state_slots;
+ } u;
/**
* For variables that are in an interface block or are an instance of an
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 0cd35f0..6448367 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -45,9 +45,9 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
var->data.max_array_access = this->data.max_array_access;
if (this->is_interface_instance()) {
- var->max_ifc_array_access =
+ var->u.max_ifc_array_access =
rzalloc_array(var, unsigned, this->interface_type->length);
- memcpy(var->max_ifc_array_access, this->max_ifc_array_access,
+ memcpy(var->u.max_ifc_array_access, this->u.max_ifc_array_access,
this->interface_type->length * sizeof(unsigned));
}
--
1.8.1.4
More information about the mesa-dev
mailing list