summaryrefslogtreecommitdiffstats
path: root/src/glsl/nir/nir_print.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-11-25 21:36:25 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:19:02 -0800
commit829aa98320fcd529407d16991b476b71af017479 (patch)
tree5ff603507c7cded684a6ee460126b64c1e02f112 /src/glsl/nir/nir_print.c
parent4f8230e247a222314ab124e348482628adb5af32 (diff)
nir: Use an integer index for specifying structure fields
Previously, we used a string name. It was nice for translating out of GLSL IR (which also does that) but cumbersome the rest of the time. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/glsl/nir/nir_print.c')
-rw-r--r--src/glsl/nir/nir_print.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index ec60981b548..9ad2849d376 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -282,33 +282,42 @@ print_deref_array(nir_deref_array *deref, print_var_state *state, FILE *fp)
}
static void
-print_deref_struct(nir_deref_struct *deref, print_var_state *state, FILE *fp)
+print_deref_struct(nir_deref_struct *deref, const struct glsl_type *parent_type,
+ print_var_state *state, FILE *fp)
{
- fprintf(fp, ".%s", deref->elem);
+ fprintf(fp, ".%s", glsl_get_struct_elem_name(parent_type, deref->index));
}
static void
-print_deref(nir_deref *deref, print_var_state *state, FILE *fp)
+print_deref(nir_deref_var *deref, print_var_state *state, FILE *fp)
{
- while (deref != NULL) {
- switch (deref->deref_type) {
+ nir_deref *tail = &deref->deref;
+ nir_deref *pretail = NULL;
+ while (tail != NULL) {
+ switch (tail->deref_type) {
case nir_deref_type_var:
- print_deref_var(nir_deref_as_var(deref), state, fp);
+ assert(pretail == NULL);
+ assert(tail == &deref->deref);
+ print_deref_var(deref, state, fp);
break;
case nir_deref_type_array:
- print_deref_array(nir_deref_as_array(deref), state, fp);
+ assert(pretail != NULL);
+ print_deref_array(nir_deref_as_array(tail), state, fp);
break;
case nir_deref_type_struct:
- print_deref_struct(nir_deref_as_struct(deref), state, fp);
+ assert(pretail != NULL);
+ print_deref_struct(nir_deref_as_struct(tail),
+ pretail->type, state, fp);
break;
default:
unreachable("Invalid deref type");
}
- deref = deref->child;
+ pretail = tail;
+ tail = pretail->child;
}
}
@@ -350,7 +359,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_var_state *state,
if (!first)
fprintf(fp, ", ");
- print_deref(&instr->variables[i]->deref, state, fp);
+ print_deref(instr->variables[i], state, fp);
first = false;
}
@@ -485,7 +494,7 @@ print_tex_instr(nir_tex_instr *instr, print_var_state *state, FILE *fp)
}
if (instr->sampler) {
- print_deref(&instr->sampler->deref, state, fp);
+ print_deref(instr->sampler, state, fp);
} else {
fprintf(fp, "%u", instr->sampler_index);
}
@@ -508,14 +517,14 @@ print_call_instr(nir_call_instr *instr, print_var_state *state, FILE *fp)
if (i != 0)
fprintf(fp, ", ");
- print_deref(&instr->params[i]->deref, state, fp);
+ print_deref(instr->params[i], state, fp);
}
if (instr->return_deref != NULL) {
if (instr->num_params != 0)
fprintf(fp, ", ");
fprintf(fp, "returning ");
- print_deref(&instr->return_deref->deref, state, fp);
+ print_deref(instr->return_deref, state, fp);
}
}