diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index dbd4295303e..37c9f28f894 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2865,6 +2865,27 @@ should_split_wrmask(const nir_instr *instr, UNUSED const void *data) } } +/* Bifrost wants transcendentals as FP32 */ + +static unsigned +bi_lower_bit_size(const nir_instr *instr, UNUSED void *data) +{ + if (instr->type != nir_instr_type_alu) + return 0; + + nir_alu_instr *alu = nir_instr_as_alu(instr); + + switch (alu->op) { + case nir_op_fexp2: + case nir_op_flog2: + case nir_op_fsin: + case nir_op_fcos: + return (nir_dest_bit_size(alu->dest.dest) == 32) ? 0 : 32; + default: + return 0; + } +} + static void bi_optimize_nir(nir_shader *nir, bool is_blend) { @@ -2955,7 +2976,6 @@ bi_optimize_nir(nir_shader *nir, bool is_blend) NIR_PASS(progress, nir, nir_opt_cse); } - NIR_PASS(progress, nir, bifrost_nir_lower_algebraic_late); NIR_PASS(progress, nir, nir_lower_alu_to_scalar, NULL, NULL); /* Backend scheduler is purely local, so do some global optimizations @@ -3115,6 +3135,7 @@ bifrost_compile_shader_nir(nir_shader *nir, NIR_PASS_V(nir, nir_lower_ssbo); NIR_PASS_V(nir, pan_nir_lower_zs_store); NIR_PASS_V(nir, pan_lower_sample_pos); + NIR_PASS_V(nir, nir_lower_bit_size, bi_lower_bit_size, NULL); if (nir->info.stage == MESA_SHADER_FRAGMENT) { NIR_PASS_V(nir, nir_shader_instructions_pass, diff --git a/src/panfrost/bifrost/bifrost_nir_algebraic.py b/src/panfrost/bifrost/bifrost_nir_algebraic.py deleted file mode 100644 index cad2ffb5021..00000000000 --- a/src/panfrost/bifrost/bifrost_nir_algebraic.py +++ /dev/null @@ -1,58 +0,0 @@ -# -# Copyright (C) 2020 Collabora, Ltd. -# Copyright (C) 2018 Alyssa Rosenzweig -# Copyright (C) 2016 Intel Corporation -# -# 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. - -import argparse -import sys -import math - -a = 'a' -b = 'b' -c = 'c' - -algebraic_late = [] - -# Bifrost doesn't have fp16 for a lot of special ops -SPECIAL = ['fexp2', 'flog2', 'fsin', 'fcos'] - -for op in SPECIAL: - algebraic_late += [((op + '@16', a), ('f2f16', (op, ('f2f32', a))))] - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('-p', '--import-path', required=True) - args = parser.parse_args() - sys.path.insert(0, args.import_path) - run() - - -def run(): - import nir_algebraic # pylint: disable=import-error - - print('#include "bifrost_nir.h"') - - print(nir_algebraic.AlgebraicPass("bifrost_nir_lower_algebraic_late", - algebraic_late).render()) - -if __name__ == '__main__': - main() diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index 782810661c4..018189b8453 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -37,18 +37,6 @@ libpanfrost_bifrost_files = files( 'bifrost_compile.c', ) -bifrost_nir_algebraic_c = custom_target( - 'bifrost_nir_algebraic.c', - input : 'bifrost_nir_algebraic.py', - output : 'bifrost_nir_algebraic.c', - command : [ - prog_python, '@INPUT@', - '-p', join_paths(meson.source_root(), 'src/compiler/nir/'), - ], - capture : true, - depend_files : nir_algebraic_py, -) - bifrost_gen_disasm_c = custom_target( 'bifrost_gen_disasm.c', input : ['gen_disasm.py', 'ISA.xml'], @@ -126,7 +114,7 @@ libpanfrost_bifrost_disasm = static_library( libpanfrost_bifrost = static_library( 'panfrost_bifrost', - [libpanfrost_bifrost_files, bifrost_nir_algebraic_c, bi_opcodes_c, bi_printer_c, bi_packer_c], + [libpanfrost_bifrost_files, bi_opcodes_c, bi_printer_c, bi_packer_c], include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_panfrost_hw], dependencies: [idep_nir, idep_bi_opcodes_h, idep_bi_builder_h], link_with: [libpanfrost_util, libpanfrost_bifrost_disasm],