nir: support lowering clipdist to arrays
[mesa.git] / src / freedreno / ir3 / ir3_nir.c
index 50a961f2bad56d108f16a94473cf9769b030d0e8..dbf25926ac5a7d73819ce58770d2ec427f63f2c3 100644 (file)
@@ -56,6 +56,7 @@ static const nir_shader_compiler_options options = {
                .lower_bitfield_extract_to_shifts = true,
                .use_interpolated_input_intrinsics = true,
                .lower_rotate = true,
+               .lower_to_scalar = true,
 };
 
 /* we don't want to lower vertex_id to _zero_based on newer gpus: */
@@ -81,6 +82,8 @@ static const nir_shader_compiler_options options_a6xx = {
                .lower_bitfield_extract_to_shifts = true,
                .use_interpolated_input_intrinsics = true,
                .lower_rotate = true,
+               .vectorize_io = true,
+               .lower_to_scalar = true,
 };
 
 const nir_shader_compiler_options *
@@ -220,11 +223,11 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
 
        if (key) {
                if (s->info.stage == MESA_SHADER_VERTEX) {
-                       OPT_V(s, nir_lower_clip_vs, key->ucp_enables, false);
+                       OPT_V(s, nir_lower_clip_vs, key->ucp_enables, false, false);
                        if (key->vclamp_color)
                                OPT_V(s, nir_lower_clamp_color_outputs);
                } else if (s->info.stage == MESA_SHADER_FRAGMENT) {
-                       OPT_V(s, nir_lower_clip_fs, key->ucp_enables);
+                       OPT_V(s, nir_lower_clip_fs, key->ucp_enables, false);
                        if (key->fclamp_color)
                                OPT_V(s, nir_lower_clamp_color_outputs);
                }
@@ -262,6 +265,20 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
        if (ubo_progress || idiv_progress)
                ir3_optimize_loop(s);
 
+       /* Do late algebraic optimization to turn add(a, neg(b)) back into
+       * subs, then the mandatory cleanup after algebraic.  Note that it may
+       * produce fnegs, and if so then we need to keep running to squash
+       * fneg(fneg(a)).
+       */
+       bool more_late_algebraic = true;
+       while (more_late_algebraic) {
+               more_late_algebraic = OPT(s, nir_opt_algebraic_late);
+               OPT_V(s, nir_opt_constant_folding);
+               OPT_V(s, nir_copy_prop);
+               OPT_V(s, nir_opt_dce);
+               OPT_V(s, nir_opt_cse);
+       }
+
        OPT_V(s, nir_remove_dead_variables, nir_var_function_temp);
 
        OPT_V(s, nir_opt_sink, nir_move_const_undef);