From: Eric Anholt Date: Tue, 16 Jul 2019 18:09:39 +0000 (-0700) Subject: freedreno: Convert load_barycentric_at_offset to the NIR lowering helper. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=61098baf42fc0026900a67b86336ad90fc0966a2;p=mesa.git freedreno: Convert load_barycentric_at_offset to the NIR lowering helper. Cuts out a ton of boilerplate. Reviewed-by: Kristian H. Kristensen --- diff --git a/src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c b/src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c index 0277e2b3851..903bb8ee8b3 100644 --- a/src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c +++ b/src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c @@ -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); }