aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2014-05-14 19:47:28 -0700
committerIan Romanick <[email protected]>2014-09-30 13:34:42 -0700
commit5aa8d8194c4975876276a9c57cdd672978a491ad (patch)
tree700e5fdf988b1b1e0125c0ab2cc19da39e527db0 /src/glsl
parent21df0169028d600b17ab73795da2838e92ba9038 (diff)
glsl: Make ir_variable::num_state_slots and ir_variable::state_slots private
Also move num_state_slots inside ir_variable_data for better packing. The payoff for this will come in a few more patches. No change Valgrind massif results for a trimmed apitrace of dota2. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]> Reviewed-by: Tapani Pälli <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/builtin_variables.cpp5
-rw-r--r--src/glsl/ir.h61
-rw-r--r--src/glsl/ir_clone.cpp13
-rw-r--r--src/glsl/ir_validate.cpp2
-rw-r--r--src/glsl/linker.cpp7
5 files changed, 55 insertions, 33 deletions
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index ddfdc1227c9..c36d19831f8 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -478,12 +478,9 @@ builtin_variable_generator::add_uniform(const glsl_type *type,
&_mesa_builtin_uniform_desc[i];
const unsigned array_count = type->is_array() ? type->length : 1;
- uni->num_state_slots = array_count * statevar->num_elements;
ir_state_slot *slots =
- ralloc_array(uni, ir_state_slot, uni->num_state_slots);
-
- uni->state_slots = slots;
+ uni->allocate_state_slots(array_count * statevar->num_elements);
for (unsigned a = 0; a < array_count; a++) {
for (unsigned j = 0; j < statevar->num_elements; j++) {
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 6b953ee0563..722df0baa13 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -537,6 +537,37 @@ public:
return this->max_ifc_array_access;
}
+ inline unsigned get_num_state_slots() const
+ {
+ return this->data._num_state_slots;
+ }
+
+ inline void set_num_state_slots(unsigned n)
+ {
+ this->data._num_state_slots = n;
+ }
+
+ inline ir_state_slot *get_state_slots()
+ {
+ return this->state_slots;
+ }
+
+ inline const ir_state_slot *get_state_slots() const
+ {
+ return this->state_slots;
+ }
+
+ inline ir_state_slot *allocate_state_slots(unsigned n)
+ {
+ this->state_slots = ralloc_array(this, ir_state_slot, n);
+ this->data._num_state_slots = 0;
+
+ if (this->state_slots != NULL)
+ this->data._num_state_slots = n;
+
+ return this->state_slots;
+ }
+
/**
* Enable emitting extension warnings for this variable
*/
@@ -734,6 +765,10 @@ public:
/** Image internal format if specified explicitly, otherwise GL_NONE. */
uint16_t image_format;
+ private:
+ unsigned _num_state_slots; /**< Number of state slots used */
+
+ public:
/**
* Storage location of the base of this variable
*
@@ -787,22 +822,6 @@ public:
} data;
/**
- * Built-in state that backs this uniform
- *
- * Once set at variable creation, \c state_slots must remain invariant.
- * This is because, ideally, this array would be shared by all clones of
- * this variable in the IR tree. In other words, we'd really like for it
- * to be a fly-weight.
- *
- * If the variable is not a uniform, \c num_state_slots will be zero and
- * \c state_slots will be \c NULL.
- */
- /*@{*/
- unsigned num_state_slots; /**< Number of state slots used */
- ir_state_slot *state_slots; /**< State descriptors. */
- /*@}*/
-
- /**
* Value assigned in the initializer of a variable declared "const"
*/
ir_constant *constant_value;
@@ -834,6 +853,16 @@ private:
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;
+
+ /**
* For variables that are in an interface block or are an instance of an
* interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
*
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 86c0e3166d5..64019fe68ae 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -53,15 +53,10 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
memcpy(&var->data, &this->data, sizeof(var->data));
- var->num_state_slots = this->num_state_slots;
- if (this->state_slots) {
- /* FINISHME: This really wants to use something like talloc_reference, but
- * FINISHME: ralloc doesn't have any similar function.
- */
- var->state_slots = ralloc_array(var, ir_state_slot,
- this->num_state_slots);
- memcpy(var->state_slots, this->state_slots,
- sizeof(this->state_slots[0]) * var->num_state_slots);
+ if (this->get_state_slots()) {
+ ir_state_slot *s = var->allocate_state_slots(this->get_num_state_slots());
+ memcpy(s, this->get_state_slots(),
+ sizeof(s[0]) * var->get_num_state_slots());
}
if (this->constant_value)
diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp
index 96dd7bd9599..51598629117 100644
--- a/src/glsl/ir_validate.cpp
+++ b/src/glsl/ir_validate.cpp
@@ -707,7 +707,7 @@ ir_validate::visit(ir_variable *ir)
if (ir->data.mode == ir_var_uniform
&& strncmp(ir->name, "gl_", 3) == 0
- && ir->state_slots == NULL) {
+ && ir->get_state_slots() == NULL) {
printf("built-in uniform has no state\n");
ir->print();
abort();
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 2fece74d552..dbcc5b4578f 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1832,9 +1832,10 @@ update_array_sizes(struct gl_shader_program *prog)
* Determine the number of slots per array element by dividing by
* the old (total) size.
*/
- if (var->num_state_slots > 0) {
- var->num_state_slots = (size + 1)
- * (var->num_state_slots / var->type->length);
+ const unsigned num_slots = var->get_num_state_slots();
+ if (num_slots > 0) {
+ var->set_num_state_slots((size + 1)
+ * (num_slots / var->type->length));
}
var->type = glsl_type::get_array_instance(var->type->fields.array,