summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2017-06-23 19:13:34 +0200
committerNicolai Hähnle <nicolai.haehnle@amd.com>2017-07-13 13:27:43 +0200
commit9fef8af8aa2c60c59069b1c3faf723b4b9526410 (patch)
tree3cfa73213d017fdb2e057a1670f65ce050b70e19
parente9e63254b21afebc8a9acf49754025997864dd43 (diff)
mesa/glspirv: perform common lowering and optimization at specialization
-rw-r--r--src/mesa/main/glspirv.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c
index 5d4834a332..8571aa583c 100644
--- a/src/mesa/main/glspirv.c
+++ b/src/mesa/main/glspirv.c
@@ -180,7 +180,47 @@ _mesa_SpecializeShaderARB(GLuint shader,
/* TODO: Perform some common optimizations already here, to avoid re-doing
* them each time the shader is linked.
+ *
+ * TODO: How to control which ones to run?
*/
+ NIR_PASS_V(nir, nir_lower_returns);
+ NIR_PASS_V(nir, nir_inline_functions);
+ NIR_PASS_V(nir, nir_lower_global_vars_to_local);
+
+ NIR_PASS_V(nir, nir_lower_vars_to_ssa);
+ NIR_PASS_V(nir, nir_lower_var_copies);
+ NIR_PASS_V(nir, nir_lower_alu_to_scalar);
+ NIR_PASS_V(nir, nir_lower_phis_to_scalar);
+
+ {
+ 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, 0);
+ }
+ } while (progress);
+ }
+
+ NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_local);
/* TODO: Clone to cleanup memory (can only be done after inlining). */
sh->nir = nir;