[Mesa-dev] [PATCH 08/14] st/glsl_to_nir: add basic NIR opt loop helper

Timothy Arceri tarceri at itsqueeze.com
Tue Nov 21 03:37:29 UTC 2017


We need to be able to do these NIR opts in the state tracker
rather than the driver in order for the NIR linking opts to
be useful.
---
 src/mesa/state_tracker/st_glsl_to_nir.cpp | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index a4a30a4199..7d66a85a10 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -240,20 +240,51 @@ st_nir_assign_uniform_locations(struct gl_program *prog,
          loc = st_nir_lookup_parameter_index(prog->Parameters, uniform->name);
       }
 
       uniform->data.driver_location = loc;
 
       max = MAX2(max, loc + type_size(uniform->type));
    }
    *size = max;
 }
 
+static void
+st_nir_opts(nir_shader *nir)
+{
+   bool progress;
+   do {
+      progress = false;
+
+      NIR_PASS(progress, nir, nir_copy_prop);
+      NIR_PASS(progress, nir, nir_opt_remove_phis);
+      NIR_PASS(progress, nir, nir_opt_dce);
+      if (nir_opt_trivial_continues(nir)) {
+         progress = true;
+         NIR_PASS(progress, nir, nir_copy_prop);
+         NIR_PASS(progress, nir, nir_opt_dce);
+      }
+      NIR_PASS(progress, nir, nir_opt_if);
+      NIR_PASS(progress, nir, nir_opt_dead_cf);
+      NIR_PASS(progress, nir, nir_opt_cse);
+      NIR_PASS(progress, nir, nir_opt_peephole_select, 8);
+
+      NIR_PASS(progress, nir, nir_opt_algebraic);
+      NIR_PASS(progress, nir, nir_opt_constant_folding);
+
+      NIR_PASS(progress, nir, nir_opt_undef);
+      NIR_PASS(progress, nir, nir_opt_conditional_discard);
+      if (nir->options->max_unroll_iterations) {
+         NIR_PASS(progress, nir, nir_opt_loop_unroll, (nir_variable_mode)0);
+      }
+   } while (progress);
+}
+
 /* First third of converting glsl_to_nir.. this leaves things in a pre-
  * nir_lower_io state, so that shader variants can more easily insert/
  * replace variables, etc.
  */
 static nir_shader *
 st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
                struct gl_shader_program *shader_program,
                gl_shader_stage stage)
 {
    struct pipe_screen *pscreen = st->pipe->screen;
-- 
2.14.3



More information about the mesa-dev mailing list