[Mesa-dev] [PATCH 6/8] nir: Allow nir_lower_io() to only lower one type of variable.

Kenneth Graunke kenneth at whitecape.org
Mon Aug 17 16:07:48 PDT 2015


We may want to use different type_size functions for (e.g.) inputs
vs. uniforms.  Passing in -1 for mode ignores this, handling all
modes as before.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/nir.h                  |  1 +
 src/glsl/nir/nir_lower_io.c         | 21 +++++++++++++++++----
 src/mesa/drivers/dri/i965/brw_nir.c |  4 ++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 8df0de9..3813b44 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1647,6 +1647,7 @@ void nir_assign_var_locations_direct_first(nir_shader *shader,
                                            int (*type_size)(const struct glsl_type *));
 
 void nir_lower_io(nir_shader *shader,
+                  nir_variable_mode mode,
                   int (*type_size)(const struct glsl_type *));
 void nir_lower_vars_to_ssa(nir_shader *shader);
 
diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
index 15a4edc..77f62e5 100644
--- a/src/glsl/nir/nir_lower_io.c
+++ b/src/glsl/nir/nir_lower_io.c
@@ -38,6 +38,7 @@ struct lower_io_state {
    nir_builder builder;
    void *mem_ctx;
    int (*type_size)(const struct glsl_type *type);
+   nir_variable_mode mode;
 };
 
 void
@@ -228,9 +229,17 @@ nir_lower_io_block(nir_block *block, void *void_state)
 
       nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
 
+      if (intrin->intrinsic != nir_intrinsic_load_var &&
+          intrin->intrinsic != nir_intrinsic_store_var)
+         continue;
+
+      nir_variable_mode mode = intrin->variables[0]->var->data.mode;
+
+      if (state->mode != -1 && state->mode != mode)
+         continue;
+
       switch (intrin->intrinsic) {
       case nir_intrinsic_load_var: {
-         nir_variable_mode mode = intrin->variables[0]->var->data.mode;
          if (mode != nir_var_shader_in && mode != nir_var_uniform)
             continue;
 
@@ -309,12 +318,15 @@ nir_lower_io_block(nir_block *block, void *void_state)
 }
 
 static void
-nir_lower_io_impl(nir_function_impl *impl, int(*type_size)(const struct glsl_type *))
+nir_lower_io_impl(nir_function_impl *impl,
+                  nir_variable_mode mode,
+                  int(*type_size)(const struct glsl_type *))
 {
    struct lower_io_state state;
 
    nir_builder_init(&state.builder, impl);
    state.mem_ctx = ralloc_parent(impl);
+   state.mode = mode;
    state.type_size = type_size;
 
    nir_foreach_block(impl, nir_lower_io_block, &state);
@@ -324,10 +336,11 @@ nir_lower_io_impl(nir_function_impl *impl, int(*type_size)(const struct glsl_typ
 }
 
 void
-nir_lower_io(nir_shader *shader, int(*type_size)(const struct glsl_type *))
+nir_lower_io(nir_shader *shader, nir_variable_mode mode,
+             int(*type_size)(const struct glsl_type *))
 {
    nir_foreach_overload(shader, overload) {
       if (overload->impl)
-         nir_lower_io_impl(overload->impl, type_size);
+         nir_lower_io_impl(overload->impl, mode, type_size);
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c
index 12f67b3..224c207 100644
--- a/src/mesa/drivers/dri/i965/brw_nir.c
+++ b/src/mesa/drivers/dri/i965/brw_nir.c
@@ -36,7 +36,7 @@ brw_lower_nir_io_scalar(nir_shader *nir, gl_shader_stage stage)
                                          type_size_scalar);
    nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_scalar);
    nir_assign_var_locations(&nir->outputs, &nir->num_outputs, type_size_scalar);
-   nir_lower_io(nir, type_size_scalar);
+   nir_lower_io(nir, -1, type_size_scalar);
 }
 
 static void
@@ -51,7 +51,7 @@ brw_lower_nir_io_vec4(nir_shader *nir, gl_shader_stage stage)
    foreach_list_typed(nir_variable, var, node, &nir->outputs)
       var->data.driver_location = var->data.location;
 
-   nir_lower_io(nir, type_size_vec4);
+   nir_lower_io(nir, -1, type_size_vec4);
 }
 
 static void
-- 
2.5.0



More information about the mesa-dev mailing list