+/**
+ * Determine the name of the interface block field
+ *
+ * This is the name of the specific member as it would appear in the
+ * \c gl_uniform_buffer_variable::Name field in the shader's
+ * \c UniformBlocks array.
+ */
+static const char *
+interface_field_name(void *mem_ctx, char *base_name, ir_dereference *d)
+{
+ ir_constant *previous_index = NULL;
+
+ while (d != NULL) {
+ switch (d->ir_type) {
+ case ir_type_dereference_variable: {
+ ir_dereference_variable *v = (ir_dereference_variable *) d;
+ if (previous_index
+ && v->var->is_interface_instance()
+ && v->var->type->is_array())
+ return ralloc_asprintf(mem_ctx,
+ "%s[%d]",
+ base_name,
+ previous_index->get_uint_component(0));
+ else
+ return base_name;
+
+ break;
+ }
+
+ case ir_type_dereference_record: {
+ ir_dereference_record *r = (ir_dereference_record *) d;
+
+ d = r->record->as_dereference();
+ break;
+ }
+
+ case ir_type_dereference_array: {
+ ir_dereference_array *a = (ir_dereference_array *) d;
+
+ d = a->array->as_dereference();
+ previous_index = a->array_index->as_constant();
+ break;
+ }
+
+ default:
+ assert(!"Should not get here.");
+ break;
+ }
+ }
+
+ assert(!"Should not get here.");
+ return NULL;
+}
+