Module: Mesa Branch: master Commit: 435800e75028b7fd1c11a667e5421206b190c2be URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=435800e75028b7fd1c11a667e5421206b190c2be
Author: Alyssa Rosenzweig <[email protected]> Date: Tue Feb 23 23:46:43 2021 +0000 pan/bi: Lower swizzles Signed-off-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10065> --- src/panfrost/Makefile.sources | 1 + src/panfrost/bifrost/bi_lower_swizzle.c | 85 +++++++++++++++++++++++++++++++++ src/panfrost/bifrost/bifrost_compile.c | 2 + src/panfrost/bifrost/compiler.h | 1 + src/panfrost/bifrost/meson.build | 1 + 5 files changed, 90 insertions(+) diff --git a/src/panfrost/Makefile.sources b/src/panfrost/Makefile.sources index 2901efceb70..d573ab6070f 100644 --- a/src/panfrost/Makefile.sources +++ b/src/panfrost/Makefile.sources @@ -4,6 +4,7 @@ bifrost_FILES := \ bifrost/bifrost_compile.h \ bifrost/bi_layout.c \ bifrost/bi_liveness.c \ + bifrost/bi_lower_swizzle.c \ bifrost/bi_schedule.c \ bifrost/bi_scoreboard.c \ bifrost/bi_pack.c \ diff --git a/src/panfrost/bifrost/bi_lower_swizzle.c b/src/panfrost/bifrost/bi_lower_swizzle.c new file mode 100644 index 00000000000..ed03d4c2c0c --- /dev/null +++ b/src/panfrost/bifrost/bi_lower_swizzle.c @@ -0,0 +1,85 @@ +/* + * 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. + */ + +#include "compiler.h" +#include "bi_builder.h" + +/* Not all 8-bit and 16-bit instructions support all swizzles on all sources. + * These passes, intended to run after NIR->BIR but before scheduling/RA, lower + * away swizzles that cannot be represented. In the future, we should try to + * recombine swizzles where we can as an optimization. + */ + +static void +bi_lower_swizzle_16(bi_context *ctx, bi_instr *ins, unsigned src) +{ + /* TODO: Use the opcode table and be a lot more methodical about this... */ + switch (ins->op) { + case BI_OPCODE_CSEL_V2F16: + case BI_OPCODE_CSEL_V2I16: + case BI_OPCODE_CSEL_V2S16: + case BI_OPCODE_CSEL_V2U16: + break; + case BI_OPCODE_IADD_V2S16: + case BI_OPCODE_IADD_V2U16: + case BI_OPCODE_ISUB_V2S16: + case BI_OPCODE_ISUB_V2U16: + if (src == 0 && ins->src[src].swizzle != BI_SWIZZLE_H10) + break; + else + return; + case BI_OPCODE_LSHIFT_AND_V2I16: + case BI_OPCODE_LSHIFT_OR_V2I16: + case BI_OPCODE_LSHIFT_XOR_V2I16: + case BI_OPCODE_RSHIFT_AND_V2I16: + case BI_OPCODE_RSHIFT_OR_V2I16: + case BI_OPCODE_RSHIFT_XOR_V2I16: + if (src == 2) + return; + else + break; + default: + return; + } + + /* Identity is ok (TODO: what about replicate only?) */ + if (ins->src[src].swizzle == BI_SWIZZLE_H01) + return; + + /* Lower it away */ + bi_builder b = bi_init_builder(ctx, bi_before_instr(ins)); + ins->src[src] = bi_replace_index(ins->src[src], + bi_swz_v2i16(&b, ins->src[src])); + ins->src[src].swizzle = BI_SWIZZLE_H01; +} + +void +bi_lower_swizzle(bi_context *ctx) +{ + bi_foreach_instr_global_safe(ctx, ins) { + bi_foreach_src(ins, s) { + if (!bi_is_null(ins->src[s])) + bi_lower_swizzle_16(ctx, ins, s); + } + } +} diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index fa94bcf89c9..e12a8ab3cb0 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -3084,6 +3084,8 @@ bifrost_compile_shader_nir(nir_shader *nir, bi_lower_branch(block); } + bi_lower_swizzle(ctx); + if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal) bi_print_shader(ctx, stdout); bi_schedule(ctx); diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 7d01e3db015..88c0285af9f 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -753,6 +753,7 @@ void bi_print_shader(bi_context *ctx, FILE *fp); void bi_opt_copy_prop(bi_context *ctx); void bi_opt_dead_code_eliminate(bi_context *ctx, bool soft); void bi_opt_push_ubo(bi_context *ctx); +void bi_lower_swizzle(bi_context *ctx); void bi_schedule(bi_context *ctx); void bi_assign_scoreboard(bi_context *ctx); void bi_register_allocate(bi_context *ctx); diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index d99961a80af..4ac0ced1947 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -22,6 +22,7 @@ libpanfrost_bifrost_files = files( 'bi_layout.c', 'bi_liveness.c', + 'bi_lower_swizzle.c', 'bi_print.c', 'bi_opt_copy_prop.c', 'bi_opt_dce.c', _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
