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

Iago Toral itoral at igalia.com
Tue Sep 15 00:18:40 PDT 2015


On Sun, 2015-09-13 at 11:51 -0400, Rob Clark wrote:
> From: Rob Clark <robclark at freedesktop.org>
> 
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---
>  src/glsl/nir/nir_print.c | 73 ++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 59 insertions(+), 14 deletions(-)
> 
> diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
> index 69cadba..6c9bd4b 100644
> --- a/src/glsl/nir/nir_print.c
> +++ b/src/glsl/nir/nir_print.c
> @@ -26,6 +26,7 @@
>   */
>  
>  #include "nir.h"
> +#include "glsl/shader_enums.h"

I think you don't need the "glsl/" prefix for this include.

>  #include <stdio.h>
>  #include <stdlib.h>
>  
> @@ -37,6 +38,9 @@ print_tabs(unsigned num_tabs, FILE *fp)
>  }
>  
>  typedef struct {
> +   FILE *fp;
> +
> +   nir_shader *shader;
>     /** map from nir_variable -> printable name */
>     struct hash_table *ht;
>  
> @@ -206,8 +210,10 @@ print_alu_instr(nir_alu_instr *instr, FILE *fp)
>  }
>  
>  static void
> -print_var_decl(nir_variable *var, print_var_state *state, FILE *fp)
> +print_var_decl(nir_variable *var, print_var_state *state)
>  {
> +   FILE *fp = state->fp;
> +
>     fprintf(fp, "decl_var ");
>  
>     const char *const cent = (var->data.centroid) ? "centroid " : "";
> @@ -215,10 +221,10 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp)
>     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);
>  
> @@ -241,7 +247,41 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp)
>         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_vert_attrib_name(var->data.location);

Mmm... shouldn't this be the same as in the case of a vertex shader?
that is, use gl_varying_slot_name for GS outputs.

> +         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");
> @@ -772,7 +812,7 @@ print_function_impl(nir_function_impl *impl, print_var_state *state, FILE *fp)
>  
>     foreach_list_typed(nir_variable, var, node, &impl->locals) {
>        fprintf(fp, "\t");
> -      print_var_decl(var, state, fp);
> +      print_var_decl(var, state);
>     }
>  
>     foreach_list_typed(nir_register, reg, node, &impl->registers) {
> @@ -832,16 +872,19 @@ print_function_overload(nir_function_overload *overload,
>  }
>  
>  static void
> -print_function(nir_function *func, print_var_state *state, FILE *fp)
> +print_function(nir_function *func, print_var_state *state)
>  {
> +   FILE *fp = state->fp;
>     foreach_list_typed(nir_function_overload, overload, node, &func->overload_list) {
>        print_function_overload(overload, state, fp);
>     }
>  }
>  
>  static void
> -init_print_state(print_var_state *state)
> +init_print_state(print_var_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,
> @@ -860,26 +903,28 @@ void
>  nir_print_shader(nir_shader *shader, FILE *fp)
>  {
>     print_var_state state;
> -   init_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, fp);
> +      print_var_decl(var, &state);
>     }
>  
>     foreach_list_typed(nir_variable, var, node, &shader->inputs) {
> -      print_var_decl(var, &state, fp);
> +      print_var_decl(var, &state);
>     }
>  
>     foreach_list_typed(nir_variable, var, node, &shader->outputs) {
> -      print_var_decl(var, &state, fp);
> +      print_var_decl(var, &state);
>     }
>  
>     foreach_list_typed(nir_variable, var, node, &shader->globals) {
> -      print_var_decl(var, &state, fp);
> +      print_var_decl(var, &state);
>     }
>  
>     foreach_list_typed(nir_variable, var, node, &shader->system_values) {
> -      print_var_decl(var, &state, fp);
> +      print_var_decl(var, &state);
>     }
>  
>     foreach_list_typed(nir_register, reg, node, &shader->registers) {
> @@ -887,7 +932,7 @@ nir_print_shader(nir_shader *shader, FILE *fp)
>     }
>  
>     foreach_list_typed(nir_function, func, node, &shader->functions) {
> -      print_function(func, &state, fp);
> +      print_function(func, &state);
>     }
>  
>     destroy_print_state(&state);




More information about the mesa-dev mailing list