glsl: Optimize the SoftFP64 shader when first creating it.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 8 Aug 2019 08:44:52 +0000 (01:44 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 12 Aug 2019 17:42:32 +0000 (10:42 -0700)
By optimizing the shader before inlining, we avoid having to redo this
work for each inlined copy of a function.  It should also reduce the
memory consumption a bit.

This cuts the KHR-GL46.arrays_of_arrays_gl.SubroutineFunctionCalls2
runtime by 25% on my Icelake.  That test compiles many shaders, which
contain large types (dmat4) and division (expensive operations).

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/compiler/glsl/glsl_to_nir.cpp

index 8cf571a29f90e3ca3e20155e0a7d160dbef2bcd0..3166bf2c4e94d815a8cec58ce494d49bd6101922 100644 (file)
@@ -2688,5 +2688,18 @@ glsl_float64_funcs_to_nir(struct gl_context *ctx,
    NIR_PASS_V(nir, nir_inline_functions);
    NIR_PASS_V(nir, nir_opt_deref);
 
+   /* Do some optimizations to clean up the shader now.  By optimizing the
+    * functions in the library, we avoid having to re-do that work every
+    * time we inline a copy of a function.  Reducing basic blocks also helps
+    * with compile times.
+    */
+   NIR_PASS_V(nir, nir_lower_vars_to_ssa);
+   NIR_PASS_V(nir, nir_copy_prop);
+   NIR_PASS_V(nir, nir_opt_dce);
+   NIR_PASS_V(nir, nir_opt_cse);
+   NIR_PASS_V(nir, nir_opt_gcm, true);
+   NIR_PASS_V(nir, nir_opt_peephole_select, 1, false, false);
+   NIR_PASS_V(nir, nir_opt_dce);
+
    return nir;
 }