diff options
author | Eric Anholt <[email protected]> | 2019-07-16 11:09:39 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2019-07-18 11:28:56 -0700 |
commit | 61098baf42fc0026900a67b86336ad90fc0966a2 (patch) | |
tree | c7c63c099a2bc5fd991c61730ab5158681cf4e7d /src/freedreno | |
parent | cdc359c58e282b3f0c169eb6ba72c3c992dcf3c2 (diff) |
freedreno: Convert load_barycentric_at_offset to the NIR lowering helper.
Cuts out a ton of boilerplate.
Reviewed-by: Kristian H. Kristensen <[email protected]>
Diffstat (limited to 'src/freedreno')
-rw-r--r-- | src/freedreno/ir3/ir3_nir_lower_load_barycentric_at_offset.c | 58 |
1 files changed, 19 insertions, 39 deletions
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); } |