freedreno: Convert load_barycentric_at_offset to the NIR lowering helper.
authorEric Anholt <eric@anholt.net>
Tue, 16 Jul 2019 18:09:39 +0000 (11:09 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 18 Jul 2019 18:28:56 +0000 (11:28 -0700)
Cuts out a ton of boilerplate.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c

index 0277e2b3851aeb78d01157bff118dae3d9b183b3..903bb8ee8b32a49c2e72128a168e0941008368c4 100644 (file)
@@ -40,9 +40,12 @@ load(nir_builder *b, unsigned ncomp, nir_intrinsic_op op)
        return &load_size->dest.ssa;
 }
 
-static void
-lower_load_barycentric_at_offset(nir_builder *b, nir_intrinsic_instr *intr)
+static nir_ssa_def *
+ir3_nir_lower_load_barycentric_at_offset_instr(nir_builder *b,
+          nir_instr *instr, void *data)
 {
+       nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+
 #define chan(var, c) nir_channel(b, var, c)
 
        nir_ssa_def *off = intr->src[0].ssa;
@@ -77,48 +80,25 @@ lower_load_barycentric_at_offset(nir_builder *b, nir_intrinsic_instr *intr)
 
        ij = nir_vec2(b, i, j);
 
-       nir_ssa_def_rewrite_uses(&intr->dest.ssa, nir_src_for_ssa(ij));
+       return ij;
+}
+
+static bool
+ir3_nir_lower_load_barycentric_at_offset_filter(const nir_instr *instr,
+               const void *data)
+{
+       return (instr->type == nir_instr_type_intrinsic &&
+                       nir_instr_as_intrinsic(instr)->intrinsic ==
+                       nir_intrinsic_load_barycentric_at_offset);
 }
 
 bool
 ir3_nir_lower_load_barycentric_at_offset(nir_shader *shader)
 {
-       bool progress = false;
-
        debug_assert(shader->info.stage == MESA_SHADER_FRAGMENT);
 
-       nir_foreach_function (function, shader) {
-               if (!function->impl)
-                       continue;
-
-               nir_builder b;
-               nir_builder_init(&b, function->impl);
-
-               nir_foreach_block (block, function->impl) {
-                       nir_foreach_instr_safe(instr, block) {
-                               if (instr->type != nir_instr_type_intrinsic)
-                                       continue;
-
-                               nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
-
-                               if (intr->intrinsic != nir_intrinsic_load_barycentric_at_offset)
-                                       continue;
-
-                               debug_assert(intr->src[0].is_ssa);
-                               debug_assert(intr->dest.is_ssa);
-
-                               b.cursor = nir_before_instr(instr);
-                               lower_load_barycentric_at_offset(&b, intr);
-
-                               progress = true;
-                       }
-               }
-
-               if (progress) {
-                       nir_metadata_preserve(function->impl,
-                               nir_metadata_block_index | nir_metadata_dominance);
-               }
-       }
-
-       return progress;
+       return nir_shader_lower_instructions(shader,
+                       ir3_nir_lower_load_barycentric_at_offset_filter,
+                       ir3_nir_lower_load_barycentric_at_offset_instr,
+                       NULL);
 }