[Mesa-dev] [PATCH 2/5] nir: Add a nir_foreach_variable macro

Jason Ekstrand jason at jlekstrand.net
Fri Oct 2 19:48:48 PDT 2015


This is a common enough operation that it's nice to not have to think about
the arguments to foreach_list_typed every time.
---
 src/glsl/nir/nir.h                              |  3 +++
 src/glsl/nir/nir_lower_clip.c                   |  4 ++--
 src/glsl/nir/nir_lower_io.c                     |  2 +-
 src/glsl/nir/nir_lower_outputs_to_temporaries.c |  2 +-
 src/glsl/nir/nir_lower_two_sided_color.c        |  2 +-
 src/glsl/nir/nir_print.c                        | 14 +++++++-------
 src/glsl/nir/nir_validate.c                     | 12 ++++++------
 7 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index c83ef50..268fbc2 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -365,6 +365,9 @@ typedef struct {
    const struct glsl_type *interface_type;
 } nir_variable;
 
+#define nir_foreach_variable(var, var_list) \
+   foreach_list_typed(nir_variable, var, node, var_list)
+
 typedef struct {
    struct exec_node node;
 
diff --git a/src/glsl/nir/nir_lower_clip.c b/src/glsl/nir/nir_lower_clip.c
index 94d12b7..31ccfb2 100644
--- a/src/glsl/nir/nir_lower_clip.c
+++ b/src/glsl/nir/nir_lower_clip.c
@@ -218,7 +218,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables)
       return;
 
    /* find clipvertex/position outputs: */
-   foreach_list_typed(nir_variable, var, node, &shader->outputs) {
+   nir_foreach_variable(var, &shader->outputs) {
       int loc = var->data.driver_location;
 
       /* keep track of last used driver-location.. we'll be
@@ -310,7 +310,7 @@ nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables)
    if (!ucp_enables)
       return;
 
-   foreach_list_typed(nir_variable, var, node, &shader->inputs) {
+   nir_foreach_variable(var, &shader->inputs) {
       int loc = var->data.driver_location;
 
       /* keep track of last used driver-location.. we'll be
diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
index f32c09d..30fad85 100644
--- a/src/glsl/nir/nir_lower_io.c
+++ b/src/glsl/nir/nir_lower_io.c
@@ -47,7 +47,7 @@ nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
 {
    unsigned location = 0;
 
-   foreach_list_typed(nir_variable, var, node, var_list) {
+   nir_foreach_variable(var, var_list) {
       /*
        * UBO's have their own address spaces, so don't count them towards the
        * number of global uniforms
diff --git a/src/glsl/nir/nir_lower_outputs_to_temporaries.c b/src/glsl/nir/nir_lower_outputs_to_temporaries.c
index 4ea5fd4..80f4395 100644
--- a/src/glsl/nir/nir_lower_outputs_to_temporaries.c
+++ b/src/glsl/nir/nir_lower_outputs_to_temporaries.c
@@ -84,7 +84,7 @@ nir_lower_outputs_to_temporaries(nir_shader *shader)
    /* Walk over all of the outputs turn each output into a temporary and
     * make a new variable for the actual output.
     */
-   foreach_list_typed(nir_variable, var, node, &state.old_outputs) {
+   nir_foreach_variable(var, &state.old_outputs) {
       nir_variable *output = ralloc(shader, nir_variable);
       memcpy(output, var, sizeof *output);
 
diff --git a/src/glsl/nir/nir_lower_two_sided_color.c b/src/glsl/nir/nir_lower_two_sided_color.c
index 131feef..db519bf 100644
--- a/src/glsl/nir/nir_lower_two_sided_color.c
+++ b/src/glsl/nir/nir_lower_two_sided_color.c
@@ -83,7 +83,7 @@ setup_inputs(lower_2side_state *state)
    int maxloc = -1;
 
    /* find color/face inputs: */
-   foreach_list_typed(nir_variable, var, node, &state->shader->inputs) {
+   nir_foreach_variable(var, &state->shader->inputs) {
       int loc = var->data.driver_location;
 
       /* keep track of last used driver-location.. we'll be
diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c
index a19aa8b..3936bae 100644
--- a/src/glsl/nir/nir_print.c
+++ b/src/glsl/nir/nir_print.c
@@ -453,7 +453,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
       return;
    }
 
-   foreach_list_typed(nir_variable, var, node, var_list) {
+   nir_foreach_variable(var, var_list) {
       if ((var->data.driver_location == instr->const_index[0]) &&
           var->name) {
          fprintf(fp, "\t/* %s */", var->name);
@@ -872,7 +872,7 @@ print_function_impl(nir_function_impl *impl, print_state *state)
 
    fprintf(fp, "{\n");
 
-   foreach_list_typed(nir_variable, var, node, &impl->locals) {
+   nir_foreach_variable(var, &impl->locals) {
       fprintf(fp, "\t");
       print_var_decl(var, state);
    }
@@ -970,23 +970,23 @@ nir_print_shader(nir_shader *shader, FILE *fp)
 
    fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->stage));
 
-   foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
+   nir_foreach_variable(var, &shader->uniforms) {
       print_var_decl(var, &state);
    }
 
-   foreach_list_typed(nir_variable, var, node, &shader->inputs) {
+   nir_foreach_variable(var, &shader->inputs) {
       print_var_decl(var, &state);
    }
 
-   foreach_list_typed(nir_variable, var, node, &shader->outputs) {
+   nir_foreach_variable(var, &shader->outputs) {
       print_var_decl(var, &state);
    }
 
-   foreach_list_typed(nir_variable, var, node, &shader->globals) {
+   nir_foreach_variable(var, &shader->globals) {
       print_var_decl(var, &state);
    }
 
-   foreach_list_typed(nir_variable, var, node, &shader->system_values) {
+   nir_foreach_variable(var, &shader->system_values) {
       print_var_decl(var, &state);
    }
 
diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c
index 1c9993a..c6fedf9 100644
--- a/src/glsl/nir/nir_validate.c
+++ b/src/glsl/nir/nir_validate.c
@@ -934,7 +934,7 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
    state->parent_node = &impl->cf_node;
 
    exec_list_validate(&impl->locals);
-   foreach_list_typed(nir_variable, var, node, &impl->locals) {
+   nir_foreach_variable(var, &impl->locals) {
       validate_var_decl(var, false, state);
    }
 
@@ -1016,27 +1016,27 @@ nir_validate_shader(nir_shader *shader)
    state.shader = shader;
 
    exec_list_validate(&shader->uniforms);
-   foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
+   nir_foreach_variable(var, &shader->uniforms) {
       validate_var_decl(var, true, &state);
    }
 
    exec_list_validate(&shader->inputs);
-   foreach_list_typed(nir_variable, var, node, &shader->inputs) {
+   nir_foreach_variable(var, &shader->inputs) {
      validate_var_decl(var, true, &state);
    }
 
    exec_list_validate(&shader->outputs);
-   foreach_list_typed(nir_variable, var, node, &shader->outputs) {
+   nir_foreach_variable(var, &shader->outputs) {
      validate_var_decl(var, true, &state);
    }
 
    exec_list_validate(&shader->globals);
-   foreach_list_typed(nir_variable, var, node, &shader->globals) {
+   nir_foreach_variable(var, &shader->globals) {
      validate_var_decl(var, true, &state);
    }
 
    exec_list_validate(&shader->system_values);
-   foreach_list_typed(nir_variable, var, node, &shader->system_values) {
+   nir_foreach_variable(var, &shader->system_values) {
      validate_var_decl(var, true, &state);
    }
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list