diff options
author | Rob Clark <robclark@freedesktop.org> | 2015-12-22 16:50:23 -0500 |
---|---|---|
committer | Rob Clark <robclark@freedesktop.org> | 2015-12-23 00:28:01 -0500 |
commit | dc21747838c866daccdb932caeca90ed91b29b7f (patch) | |
tree | cc818f8946b5945253b8a5abd255fc890c47df2e /src/glsl/nir | |
parent | 65248976065900190899f221cff3ef7c45de1569 (diff) | |
download | external_mesa3d-dc21747838c866daccdb932caeca90ed91b29b7f.zip external_mesa3d-dc21747838c866daccdb932caeca90ed91b29b7f.tar.gz external_mesa3d-dc21747838c866daccdb932caeca90ed91b29b7f.tar.bz2 |
nir/print: print variable constant-initializers
Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Diffstat (limited to 'src/glsl/nir')
-rw-r--r-- | src/glsl/nir/nir_print.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c index 1a4cc69..56e5705 100644 --- a/src/glsl/nir/nir_print.c +++ b/src/glsl/nir/nir_print.c @@ -220,6 +220,53 @@ print_alu_instr(nir_alu_instr *instr, print_state *state) } static void +print_constant(nir_constant *c, const struct glsl_type *type, print_state *state) +{ + FILE *fp = state->fp; + unsigned total_elems = glsl_get_components(type); + unsigned i; + + switch (glsl_get_base_type(type)) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_BOOL: + for (i = 0; i < total_elems; i++) { + if (i > 0) fprintf(fp, ", "); + fprintf(fp, "0x%08x", c->value.u[i]); + } + break; + + case GLSL_TYPE_FLOAT: + for (i = 0; i < total_elems; i++) { + if (i > 0) fprintf(fp, ", "); + fprintf(fp, "%f", c->value.f[i]); + } + break; + + case GLSL_TYPE_STRUCT: + for (i = 0; i < c->num_elements; i++) { + if (i > 0) fprintf(fp, ", "); + fprintf(fp, "{ "); + print_constant(c->elements[i], glsl_get_struct_field(type, i), state); + fprintf(fp, " }"); + } + break; + + case GLSL_TYPE_ARRAY: + for (i = 0; i < c->num_elements; i++) { + if (i > 0) fprintf(fp, ", "); + fprintf(fp, "{ "); + print_constant(c->elements[i], glsl_get_array_element(type), state); + fprintf(fp, " }"); + } + break; + + default: + unreachable("not reached"); + } +} + +static void print_var_decl(nir_variable *var, print_state *state) { FILE *fp = state->fp; @@ -295,6 +342,12 @@ print_var_decl(nir_variable *var, print_state *state) fprintf(fp, " (%s, %u)", loc, var->data.driver_location); } + if (var->constant_initializer) { + fprintf(fp, " = { "); + print_constant(var->constant_initializer, var->type, state); + fprintf(fp, " }"); + } + fprintf(fp, "\n"); if (state->syms) { |