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);
}
}
}
{
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);
}
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;
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);
}
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
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
ir_rvalue *record;
- const char *field;
+ int field_idx;
};
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.
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 *
*/
assert(suboffset == 0);
- store = substore->get_record_field(dr->field);
+ store = substore->get_record_field(dr->field_idx);
break;
}
{
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;
}
{
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);
}
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;
}
};
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 =
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;
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,
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]);
}
ir->record->accept(this);
+ assert(ir->field_idx >= 0);
for (i = 0; i < struct_type->length; i++) {
- if (strcmp(struct_type->fields.structure[i].name, ir->field) == 0)
+ if (i == (unsigned) ir->field_idx)
break;
offset += type_size(struct_type->fields.structure[i].type);
}
case ir_type_dereference_record: {
ir_dereference_record *deref_record = deref->as_dereference_record();
- unsigned field_index =
- deref_record->record->type->field_index(deref_record->field);
+ unsigned field_index = deref_record->field_idx;
*location +=
deref_record->record->type->record_location_offset(field_index);
calc_sampler_offsets(prog, deref_record->record->as_dereference(),
ir->record->accept(this);
+ assert(ir->field_idx >= 0);
for (i = 0; i < struct_type->length; i++) {
- if (strcmp(struct_type->fields.structure[i].name, ir->field) == 0)
+ if (i == (unsigned) ir->field_idx)
break;
offset += type_size(struct_type->fields.structure[i].type);
}
switch (ir->ir_type) {
case ir_type_dereference_record: {
ir_dereference_record *deref_record = ir->as_dereference_record();
- const glsl_type *struct_type = deref_record->record->type;
- for (unsigned i = 0; i < struct_type->length; i++) {
- if (!strcmp(struct_type->fields.structure[i].name,
- deref_record->field)) {
- *type = struct_type->fields.structure[i].type->without_array();
- *memory_coherent =
- struct_type->fields.structure[i].memory_coherent;
- *memory_volatile =
- struct_type->fields.structure[i].memory_volatile;
- *memory_restrict =
- struct_type->fields.structure[i].memory_restrict;
- *image_format =
- struct_type->fields.structure[i].image_format;
- break;
- }
- }
+ *type = deref_record->type;
+
+ const glsl_type *struct_type =
+ deref_record->record->type->without_array();
+ int fild_idx = deref_record->field_idx;
+ *memory_coherent =
+ struct_type->fields.structure[fild_idx].memory_coherent;
+ *memory_volatile =
+ struct_type->fields.structure[fild_idx].memory_volatile;
+ *memory_restrict =
+ struct_type->fields.structure[fild_idx].memory_restrict;
+ *image_format =
+ struct_type->fields.structure[fild_idx].image_format;
break;
}
case ir_type_dereference_record: {
ir_dereference_record *deref_record = tail->as_dereference_record();
const glsl_type *struct_type = deref_record->record->type;
- int field_index = deref_record->record->type->field_index(deref_record->field);
+ int field_index = deref_record->field_idx;
calc_deref_offsets(deref_record->record->as_dereference(), array_elements, index, indirect, location);