[Mesa-dev] [PATCH 3/3] nir/print: print symbolic names from shader-enum

Rob Clark robdclark at gmail.com
Tue Sep 15 16:33:15 PDT 2015


From: Rob Clark <robclark at freedesktop.org>

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 at freedesktop.org>
---
 src/glsl/nir/nir_print.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index 405dbf3..8f568eb 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -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;
 
@@ -218,10 +220,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);
 
@@ -244,7 +246,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");
@@ -855,6 +891,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,
@@ -875,6 +912,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);
    }
-- 
2.4.3



More information about the mesa-dev mailing list