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
--- /dev/null
+#
+# Copyright (C) 2019 Vasily Khoruzhick <anarsoul@gmail.com>
+#
+# 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()
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
*/
[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,
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);
'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