diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-05-22 16:23:06 -0400 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2020-06-01 12:37:03 -0400 |
commit | 7c793a4867737d08e20557e0bf8432c9c5dfcb2a (patch) | |
tree | 74cf42cfb614e101aa280cd403206a1e3721708b /src/panfrost | |
parent | 5f8dd413bcc221424598e6330e91e16914b2987a (diff) |
pan/mdg: Fuse f2f16 into load_interpolated_input
To become a ld_vary intrinsic.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5283>
Diffstat (limited to 'src/panfrost')
-rw-r--r-- | src/panfrost/Makefile.sources | 1 | ||||
-rw-r--r-- | src/panfrost/midgard/compiler.h | 1 | ||||
-rw-r--r-- | src/panfrost/midgard/meson.build | 1 | ||||
-rw-r--r-- | src/panfrost/midgard/midgard_compile.c | 7 | ||||
-rw-r--r-- | src/panfrost/midgard/nir_fuse_io_16.c | 94 |
5 files changed, 102 insertions, 2 deletions
diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 945c8f4e042..568729887de 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -65,6 +65,7 @@ midgard_FILES := \ midgard/mir_promote_uniforms.c \ midgard/mir_squeeze.c \ midgard/nir_undef_to_zero.c \ + midgard/nir_fuse_io_16.c \ shared_FILES := \ shared/pan_minmax_cache.c \ diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index 3cb65b0a015..e8cb79ba163 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -652,6 +652,7 @@ void emit_binary_bundle( bool nir_undef_to_zero(nir_shader *shader); +bool nir_fuse_io_16(nir_shader *shader); void midgard_nir_lod_errata(nir_shader *shader); diff --git a/src/panfrost/midgard/meson.build b/src/panfrost/midgard/meson.build index d47d73fd273..43ae2d87635 100644 --- a/src/panfrost/midgard/meson.build +++ b/src/panfrost/midgard/meson.build @@ -39,6 +39,7 @@ libpanfrost_midgard_files = files( 'midgard_opt_perspective.c', 'midgard_errata_lod.c', 'nir_undef_to_zero.c', + 'nir_fuse_io_16.c', 'disassemble.c', ) diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index bc0c7b6cd44..1841e0e0be2 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -352,7 +352,7 @@ midgard_nir_lower_zs_store(nir_shader *nir) /* Flushes undefined values to zero */ static void -optimise_nir(nir_shader *nir, unsigned quirks) +optimise_nir(nir_shader *nir, unsigned quirks, bool is_blend) { bool progress; unsigned lower_flrp = @@ -385,6 +385,9 @@ optimise_nir(nir_shader *nir, unsigned quirks) NIR_PASS(progress, nir, midgard_nir_lower_algebraic_early); + if (!is_blend) + NIR_PASS(progress, nir, nir_fuse_io_16); + do { progress = false; @@ -2593,7 +2596,7 @@ midgard_compile_shader_nir(nir_shader *nir, panfrost_program *program, bool is_b /* Optimisation passes */ - optimise_nir(nir, ctx->quirks); + optimise_nir(nir, ctx->quirks, is_blend); if (midgard_debug & MIDGARD_DBG_SHADERS) { nir_print_shader(nir, stdout); diff --git a/src/panfrost/midgard/nir_fuse_io_16.c b/src/panfrost/midgard/nir_fuse_io_16.c new file mode 100644 index 00000000000..ddeb4491de4 --- /dev/null +++ b/src/panfrost/midgard/nir_fuse_io_16.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2020 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Authors (Collabora): + * Alyssa Rosenzweig <[email protected]> + */ + +/* Fuses f2f16 modifiers into loads */ + +#include "compiler/nir/nir.h" +#include "compiler/nir/nir_builder.h" +#include "panfrost/util/pan_ir.h" + +bool nir_fuse_io_16(nir_shader *shader); + +static bool +nir_src_is_f2fmp(nir_src *use) +{ + nir_instr *parent = use->parent_instr; + + if (parent->type != nir_instr_type_alu) + return false; + + nir_alu_instr *alu = nir_instr_as_alu(parent); + return (alu->op == nir_op_f2fmp); +} + +bool +nir_fuse_io_16(nir_shader *shader) +{ + bool progress = false; + + 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_interpolated_input) + continue; + + if (nir_dest_bit_size(intr->dest) != 32) + continue; + + if (!intr->dest.is_ssa) + continue; + + if (!list_is_empty(&intr->dest.ssa.if_uses)) + return false; + + bool valid = true; + + nir_foreach_use(src, &intr->dest.ssa) + valid &= nir_src_is_f2fmp(src); + + if (!valid) + continue; + + intr->dest.ssa.bit_size = 16; + progress |= true; + } + } + + nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance); + + } + + return progress; +} |