From: Vasily Khoruzhick Date: Mon, 5 Aug 2019 19:33:09 +0000 (-0700) Subject: lima/ppir: move sin/cos input scaling into NIR X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5adfc8602c639827af0ba9a1059bd165a3ae49e7;p=mesa.git lima/ppir: move sin/cos input scaling into NIR Reviewed-by: Erico Nunes Signed-off-by: Vasily Khoruzhick --- diff --git a/src/gallium/drivers/lima/ir/lima_ir.h b/src/gallium/drivers/lima/ir/lima_ir.h index 8685b5db300..70b81e468a3 100644 --- a/src/gallium/drivers/lima/ir/lima_ir.h +++ b/src/gallium/drivers/lima/ir/lima_ir.h @@ -64,5 +64,6 @@ bool ppir_compile_nir(struct lima_fs_shader_state *prog, struct nir_shader *nir, struct ra_regs *ppir_regalloc_init(void *mem_ctx); void lima_nir_lower_uniform_to_scalar(nir_shader *shader); +bool lima_nir_scale_trig(nir_shader *shader); #endif diff --git a/src/gallium/drivers/lima/ir/lima_nir_algebraic.py b/src/gallium/drivers/lima/ir/lima_nir_algebraic.py new file mode 100644 index 00000000000..86f769587aa --- /dev/null +++ b/src/gallium/drivers/lima/ir/lima_nir_algebraic.py @@ -0,0 +1,52 @@ +# +# Copyright (C) 2019 Vasily Khoruzhick +# +# 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 +from math import pi + +# Utgard scales fsin/fcos arguments by 2*pi. +# Pass must be run only once, after the main loop + +scale_trig = [ + (('fsin', 'a'), ('fsin', ('fmul', 'a', 1.0 / (2.0 * pi)))), + (('fcos', 'a'), ('fcos', ('fmul', 'a', 1.0 / (2.0 * pi)))), +] + +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 "ir/lima_ir.h"') + + print(nir_algebraic.AlgebraicPass("lima_nir_scale_trig", + scale_trig).render()) + +if __name__ == '__main__': + main() diff --git a/src/gallium/drivers/lima/ir/pp/lower.c b/src/gallium/drivers/lima/ir/pp/lower.c index 2244fc7dc31..d52644b98b1 100644 --- a/src/gallium/drivers/lima/ir/pp/lower.c +++ b/src/gallium/drivers/lima/ir/pp/lower.c @@ -166,61 +166,6 @@ static bool ppir_lower_texture(ppir_block *block, ppir_node *node) return true; } -static bool ppir_lower_sin_cos(ppir_block *block, ppir_node *node) -{ - ppir_alu_node *alu = ppir_node_to_alu(node); - - ppir_node *inv_2pi_node = ppir_node_create(block, ppir_op_const, -1, 0); - if (!inv_2pi_node) - return false; - list_addtail(&inv_2pi_node->list, &node->list); - - /* For sin and cos, the input has to multiplied by the constant - * 1/(2*pi), presumably to simplify the hardware. */ - ppir_const_node *inv_2pi_const = ppir_node_to_const(inv_2pi_node); - inv_2pi_const->constant.num = 1; - inv_2pi_const->constant.value[0].f = (1.0f/(2.0f * M_PI)); - - inv_2pi_const->dest.type = ppir_target_ssa; - inv_2pi_const->dest.ssa.num_components = 1; - inv_2pi_const->dest.ssa.live_in = INT_MAX; - inv_2pi_const->dest.ssa.live_out = 0; - inv_2pi_const->dest.write_mask = 0x01; - - ppir_node *mul_node = ppir_node_create(block, ppir_op_mul, -1, 0); - if (!mul_node) - return false; - list_addtail(&mul_node->list, &node->list); - - ppir_alu_node *mul_alu = ppir_node_to_alu(mul_node); - mul_alu->num_src = 2; - mul_alu->src[0] = alu->src[0]; - mul_alu->src[1].type = ppir_target_ssa; - mul_alu->src[1].ssa = &inv_2pi_const->dest.ssa; - - int num_components = alu->src[0].ssa->num_components; - mul_alu->dest.type = ppir_target_ssa; - mul_alu->dest.ssa.num_components = num_components; - mul_alu->dest.ssa.live_in = INT_MAX; - mul_alu->dest.ssa.live_out = 0; - mul_alu->dest.write_mask = u_bit_consecutive(0, num_components); - - alu->src[0].type = ppir_target_ssa; - alu->src[0].ssa = &mul_alu->dest.ssa; - for (int i = 0; i < 4; i++) - alu->src->swizzle[i] = i; - - ppir_node_foreach_pred_safe(node, dep) { - ppir_node *pred = dep->pred; - ppir_node_remove_dep(dep); - ppir_node_add_dep(mul_node, pred); - } - ppir_node_add_dep(node, mul_node); - ppir_node_add_dep(mul_node, inv_2pi_node); - - return true; -} - /* insert a move as the select condition to make sure it can * be inserted to select instr float mul slot */ @@ -354,8 +299,6 @@ static bool (*ppir_lower_funcs[ppir_op_num])(ppir_block *, ppir_node *) = { [ppir_op_abs] = ppir_lower_abs, [ppir_op_neg] = ppir_lower_neg, [ppir_op_const] = ppir_lower_const, - [ppir_op_sin] = ppir_lower_sin_cos, - [ppir_op_cos] = ppir_lower_sin_cos, [ppir_op_lt] = ppir_lower_swap_args, [ppir_op_le] = ppir_lower_swap_args, [ppir_op_load_texture] = ppir_lower_texture, diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index 367ccb8a4e0..5695730c323 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -195,6 +195,9 @@ lima_program_optimize_fs_nir(struct nir_shader *s) NIR_PASS(progress, s, nir_opt_algebraic); } while (progress); + /* Must be run after optimization loop */ + NIR_PASS_V(s, lima_nir_scale_trig); + /* Lower modifiers */ NIR_PASS_V(s, nir_lower_to_source_mods, nir_lower_all_source_mods); NIR_PASS_V(s, nir_copy_prop); diff --git a/src/gallium/drivers/lima/meson.build b/src/gallium/drivers/lima/meson.build index 36788ddf0dd..2ab2b2ae118 100644 --- a/src/gallium/drivers/lima/meson.build +++ b/src/gallium/drivers/lima/meson.build @@ -70,9 +70,21 @@ files_lima = files( 'lima_fence.h', ) +lima_nir_algebraic_c = custom_target( + 'ir/lima_nir_algebraic.c', + input : 'ir/lima_nir_algebraic.py', + output : 'lima_nir_algebraic.c', + command : [ + prog_python, '@INPUT@', + '-p', join_paths(meson.source_root(), 'src/compiler/nir/'), + ], + capture : true, + depend_files : nir_algebraic_py, +) + liblima = static_library( 'lima', - files_lima, + files_lima, lima_nir_algebraic_c, include_directories : [ inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_gallium_drivers, inc_panfrost