nir/print: print symbolic names from shader-enum
authorRob Clark <robclark@freedesktop.org>
Tue, 15 Sep 2015 22:55:48 +0000 (18:55 -0400)
committerRob Clark <robclark@freedesktop.org>
Wed, 16 Sep 2015 14:15:35 +0000 (10:15 -0400)
v2: split out moving of FILE *fp into state structure into it's own
(more complete patch) to reduce the noise in this one

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/glsl/nir/nir_print.c

index bdecc3ccdf02b833a342ba2f0136bbf878cb671b..ca8059fc92035099e4c48dd9dc0f9c0bee1bbc4d 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include "nir.h"
+#include "shader_enums.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -38,6 +39,7 @@ print_tabs(unsigned num_tabs, FILE *fp)
 
 typedef struct {
    FILE *fp;
+   nir_shader *shader;
    /** map from nir_variable -> printable name */
    struct hash_table *ht;
 
@@ -229,10 +231,10 @@ print_var_decl(nir_variable *var, print_state *state)
    const char *const inv = (var->data.invariant) ? "invariant " : "";
    const char *const mode[] = { "shader_in ", "shader_out ", "", "",
                                 "uniform ", "shader_storage", "system " };
-   const char *const interp[] = { "", "smooth", "flat", "noperspective" };
 
    fprintf(fp, "%s%s%s%s%s ",
-      cent, samp, inv, mode[var->data.mode], interp[var->data.interpolation]);
+      cent, samp, inv, mode[var->data.mode],
+         glsl_interp_qualifier_name(var->data.interpolation));
 
    glsl_print_type(var->type, fp);
 
@@ -255,7 +257,41 @@ print_var_decl(nir_variable *var, print_state *state)
        var->data.mode == nir_var_shader_out ||
        var->data.mode == nir_var_uniform ||
        var->data.mode == nir_var_shader_storage) {
-      fprintf(fp, " (%u, %u)", var->data.location, var->data.driver_location);
+      const char *loc = NULL;
+      char buf[4];
+
+      switch (state->shader->stage) {
+      case MESA_SHADER_VERTEX:
+         if (var->data.mode == nir_var_shader_in)
+            loc = gl_vert_attrib_name(var->data.location);
+         else if (var->data.mode == nir_var_shader_out)
+            loc = gl_varying_slot_name(var->data.location);
+         break;
+      case MESA_SHADER_GEOMETRY:
+         if ((var->data.mode == nir_var_shader_in) ||
+             (var->data.mode == nir_var_shader_out))
+            loc = gl_varying_slot_name(var->data.location);
+         break;
+      case MESA_SHADER_FRAGMENT:
+         if (var->data.mode == nir_var_shader_in)
+            loc = gl_varying_slot_name(var->data.location);
+         else if (var->data.mode == nir_var_shader_out)
+            loc = gl_frag_result_name(var->data.location);
+         break;
+      case MESA_SHADER_TESS_CTRL:
+      case MESA_SHADER_TESS_EVAL:
+      case MESA_SHADER_COMPUTE:
+      default:
+         /* TODO */
+         break;
+      }
+
+      if (!loc) {
+         snprintf(buf, sizeof(buf), "%u", var->data.location);
+         loc = buf;
+      }
+
+      fprintf(fp, " (%s, %u)", loc, var->data.driver_location);
    }
 
    fprintf(fp, "\n");
@@ -881,6 +917,7 @@ static void
 init_print_state(print_state *state, nir_shader *shader, FILE *fp)
 {
    state->fp = fp;
+   state->shader = shader;
    state->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
                                        _mesa_key_pointer_equal);
    state->syms = _mesa_set_create(NULL, _mesa_key_hash_string,
@@ -901,6 +938,8 @@ nir_print_shader(nir_shader *shader, FILE *fp)
    print_state state;
    init_print_state(&state, shader, fp);
 
+   fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->stage));
+
    foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
       print_var_decl(var, &state);
    }