pan/bi: Use nir_lower_to_bit_size

Last holdout of the backend algebraic pass. Delete it.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10627>
This commit is contained in:
Alyssa Rosenzweig 2021-05-03 19:39:59 -04:00 committed by Marge Bot
parent 2db8048aaa
commit a67347d496
3 changed files with 23 additions and 72 deletions

View file

@ -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,

View file

@ -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()

View file

@ -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],