summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl
diff options
context:
space:
mode:
authorTimothy Arceri <[email protected]>2017-08-09 13:34:04 +1000
committerTimothy Arceri <[email protected]>2017-08-11 10:43:21 +1000
commit49d9286a3f79800a94ddcffbe96a8894273db6d9 (patch)
tree1e5c6ee3530eeb1458f687d58c9b0db96510cb59 /src/compiler/glsl
parent43cbcbfee9ab4a6aa1fbb51a1af7fd9619d3b7f5 (diff)
glsl: stop copying struct and interface member names
We are currently copying the name for each member dereference but we can just share a single instance of the string provided by the type. This change also stops us recalculating the field index repeatedly. Reviewed-by: Thomas Helland <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r--src/compiler/glsl/ast_array_index.cpp14
-rw-r--r--src/compiler/glsl/glsl_to_nir.cpp2
-rw-r--r--src/compiler/glsl/ir.cpp8
-rw-r--r--src/compiler/glsl/ir.h4
-rw-r--r--src/compiler/glsl/ir_clone.cpp4
-rw-r--r--src/compiler/glsl/ir_constant_expression.cpp4
-rw-r--r--src/compiler/glsl/ir_print_visitor.cpp5
-rw-r--r--src/compiler/glsl/linker.cpp9
-rw-r--r--src/compiler/glsl/lower_buffer_access.cpp6
-rw-r--r--src/compiler/glsl/lower_named_interface_blocks.cpp3
-rw-r--r--src/compiler/glsl/opt_structure_splitting.cpp10
11 files changed, 31 insertions, 38 deletions
diff --git a/src/compiler/glsl/ast_array_index.cpp b/src/compiler/glsl/ast_array_index.cpp
index f6b7a64a281..efddbed6ea3 100644
--- a/src/compiler/glsl/ast_array_index.cpp
+++ b/src/compiler/glsl/ast_array_index.cpp
@@ -88,23 +88,23 @@ update_max_array_access(ir_rvalue *ir, int idx, YYLTYPE *loc,
if (deref_var != NULL) {
if (deref_var->var->is_interface_instance()) {
- unsigned field_index =
- deref_record->record->type->field_index(deref_record->field);
- assert(field_index < deref_var->var->get_interface_type()->length);
+ unsigned field_idx = deref_record->field_idx;
+ assert(field_idx < deref_var->var->get_interface_type()->length);
int *const max_ifc_array_access =
deref_var->var->get_max_ifc_array_access();
assert(max_ifc_array_access != NULL);
- if (idx > max_ifc_array_access[field_index]) {
- max_ifc_array_access[field_index] = idx;
+ if (idx > max_ifc_array_access[field_idx]) {
+ max_ifc_array_access[field_idx] = idx;
/* Check whether this access will, as a side effect, implicitly
* cause the size of a built-in array to be too large.
*/
- check_builtin_array_max_size(deref_record->field, idx+1, *loc,
- state);
+ const char *field_name =
+ deref_record->record->type->fields.structure[field_idx].name;
+ check_builtin_array_max_size(field_name, idx+1, *loc, state);
}
}
}
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index e5166855e81..bb2ba17b220 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -2205,7 +2205,7 @@ nir_visitor::visit(ir_dereference_record *ir)
{
ir->record->accept(this);
- int field_index = this->deref_tail->type->field_index(ir->field);
+ int field_index = ir->field_idx;
assert(field_index >= 0);
nir_deref_struct *deref = nir_deref_struct_create(this->deref_tail, field_index);
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 98bbd915396..52ca83689e8 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -1104,10 +1104,8 @@ ir_constant::get_array_element(unsigned i) const
}
ir_constant *
-ir_constant::get_record_field(const char *name)
+ir_constant::get_record_field(int idx)
{
- int idx = this->type->field_index(name);
-
if (idx < 0)
return NULL;
@@ -1452,8 +1450,8 @@ ir_dereference_record::ir_dereference_record(ir_rvalue *value,
assert(value != NULL);
this->record = value;
- this->field = ralloc_strdup(this, field);
this->type = this->record->type->field_type(field);
+ this->field_idx = this->record->type->field_index(field);
}
@@ -1464,8 +1462,8 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
void *ctx = ralloc_parent(var);
this->record = new(ctx) ir_dereference_variable(var);
- this->field = ralloc_strdup(this, field);
this->type = this->record->type->field_type(field);
+ this->field_idx = this->record->type->field_index(field);
}
bool
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index d53b44304d8..ce4ade9e80a 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -2108,7 +2108,7 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
ir_rvalue *record;
- const char *field;
+ int field_idx;
};
@@ -2192,7 +2192,7 @@ public:
ir_constant *get_array_element(unsigned i) const;
- ir_constant *get_record_field(const char *name);
+ ir_constant *get_record_field(int idx);
/**
* Copy the values on another constant at a given offset.
diff --git a/src/compiler/glsl/ir_clone.cpp b/src/compiler/glsl/ir_clone.cpp
index 941e0865cb5..4fb9fa31f9b 100644
--- a/src/compiler/glsl/ir_clone.cpp
+++ b/src/compiler/glsl/ir_clone.cpp
@@ -194,8 +194,10 @@ ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const
ir_dereference_record *
ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const
{
+ const char *field_name =
+ this->record->type->fields.structure[this->field_idx].name;
return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht),
- this->field);
+ field_name);
}
ir_texture *
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index d4a8b7d020c..a493657d35c 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -485,7 +485,7 @@ constant_referenced(const ir_dereference *deref,
*/
assert(suboffset == 0);
- store = substore->get_record_field(dr->field);
+ store = substore->get_record_field(dr->field_idx);
break;
}
@@ -828,7 +828,7 @@ ir_dereference_record::constant_expression_value(struct hash_table *)
{
ir_constant *v = this->record->constant_expression_value();
- return (v != NULL) ? v->get_record_field(this->field) : NULL;
+ return (v != NULL) ? v->get_record_field(this->field_idx) : NULL;
}
diff --git a/src/compiler/glsl/ir_print_visitor.cpp b/src/compiler/glsl/ir_print_visitor.cpp
index a32a4109190..64aeaee2869 100644
--- a/src/compiler/glsl/ir_print_visitor.cpp
+++ b/src/compiler/glsl/ir_print_visitor.cpp
@@ -423,7 +423,10 @@ void ir_print_visitor::visit(ir_dereference_record *ir)
{
fprintf(f, "(record_ref ");
ir->record->accept(this);
- fprintf(f, " %s) ", ir->field);
+
+ const char *field_name =
+ ir->record->type->fields.structure[ir->field_idx].name;
+ fprintf(f, " %s) ", field_name);
}
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index b4784c51199..5f22eb36ae6 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -248,14 +248,7 @@ public:
virtual ir_visitor_status visit_leave(ir_dereference_record *ir)
{
- for (unsigned i = 0; i < ir->record->type->length; i++) {
- const struct glsl_struct_field *field =
- &ir->record->type->fields.structure[i];
- if (strcmp(field->name, ir->field) == 0) {
- ir->type = field->type;
- break;
- }
- }
+ ir->type = ir->record->type->fields.structure[ir->field_idx].type;
return visit_continue;
}
};
diff --git a/src/compiler/glsl/lower_buffer_access.cpp b/src/compiler/glsl/lower_buffer_access.cpp
index 24a96e2fba4..76d366c4b96 100644
--- a/src/compiler/glsl/lower_buffer_access.cpp
+++ b/src/compiler/glsl/lower_buffer_access.cpp
@@ -252,7 +252,7 @@ lower_buffer_access::is_dereferenced_thing_row_major(const ir_rvalue *deref)
ir = record_deref->record;
- const int idx = ir->type->field_index(record_deref->field);
+ const int idx = record_deref->field_idx;
assert(idx >= 0);
const enum glsl_matrix_layout matrix_layout =
@@ -445,8 +445,8 @@ lower_buffer_access::setup_buffer_access(void *mem_ctx,
intra_struct_offset = glsl_align(intra_struct_offset, field_align);
- if (strcmp(struct_type->fields.structure[i].name,
- deref_record->field) == 0) {
+ assert(deref_record->field_idx >= 0);
+ if (i == (unsigned) deref_record->field_idx) {
if (struct_field)
*struct_field = &struct_type->fields.structure[i];
break;
diff --git a/src/compiler/glsl/lower_named_interface_blocks.cpp b/src/compiler/glsl/lower_named_interface_blocks.cpp
index a00e60dd771..064694128bf 100644
--- a/src/compiler/glsl/lower_named_interface_blocks.cpp
+++ b/src/compiler/glsl/lower_named_interface_blocks.cpp
@@ -267,7 +267,8 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue)
ralloc_asprintf(mem_ctx, "%s %s.%s.%s",
var->data.mode == ir_var_shader_in ? "in" : "out",
var->get_interface_type()->name,
- var->name, ir->field);
+ var->name,
+ ir->record->type->fields.structure[ir->field_idx].name);
/* Find the variable in the set of flattened interface blocks */
hash_entry *entry = _mesa_hash_table_search(interface_namespace,
diff --git a/src/compiler/glsl/opt_structure_splitting.cpp b/src/compiler/glsl/opt_structure_splitting.cpp
index 84394303874..a015d6d7c93 100644
--- a/src/compiler/glsl/opt_structure_splitting.cpp
+++ b/src/compiler/glsl/opt_structure_splitting.cpp
@@ -233,13 +233,9 @@ ir_structure_splitting_visitor::split_deref(ir_dereference **deref)
if (!entry)
return;
- unsigned int i;
- for (i = 0; i < entry->var->type->length; i++) {
- if (strcmp(deref_record->field,
- entry->var->type->fields.structure[i].name) == 0)
- break;
- }
- assert(i != entry->var->type->length);
+ int i = deref_record->field_idx;
+ assert(i >= 0);
+ assert((unsigned) i < entry->var->type->length);
*deref = new(entry->mem_ctx) ir_dereference_variable(entry->components[i]);
}