~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gallium/drivers/r300/compiler/r300_nir_algebraic.py

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
from math import pi
27
27
 
 
28
# Convenience variables
 
29
a = 'a'
 
30
b = 'b'
 
31
c = 'c'
 
32
d = 'd'
 
33
e = 'e'
 
34
 
28
35
# Transform input to range [-PI, PI]:
29
36
#
30
37
# y = frac(x / 2PI + 0.5) * 2PI - PI
43
50
        (('fcos', 'a'), ('fcos', ('ffract', ('fmul', 'a', 1 / (2 * pi))))),
44
51
]
45
52
 
 
53
# The is a pattern produced by wined3d for A0 register load.
 
54
# The specific pattern wined3d emits looks like this
 
55
# A0.x = (int(floor(abs(R0.x) + 0.5) * sign(R0.x)));
 
56
# however we lower both sign and floor so here we check for the already lowered
 
57
# sequence.
 
58
r300_nir_fuse_fround_d3d9 = [
 
59
        (('fmul', ('fadd', ('fadd', ('fabs', 'a') , 0.5),
 
60
                           ('fneg', ('ffract', ('fadd', ('fabs', 'a') , 0.5)))),
 
61
                  ('fadd', ('b2f', ('!flt', 0.0, 'a')),
 
62
                           ('fneg', ('b2f', ('!flt', 'a', 0.0))))),
 
63
         ('fround_even', 'a'))
 
64
]
 
65
 
46
66
def main():
47
67
    parser = argparse.ArgumentParser()
48
68
    parser.add_argument('-p', '--import-path', required=True)
51
71
    sys.path.insert(0, args.import_path)
52
72
 
53
73
    import nir_algebraic  # pylint: disable=import-error
 
74
    ignore_exact = nir_algebraic.ignore_exact
 
75
 
 
76
    r300_nir_lower_bool_to_float = [
 
77
        (('bcsel@32(is_only_used_as_float)', ignore_exact('feq', 'a@32', 'b@32'), c, d),
 
78
             ('fadd', ('fmul', c, ('seq', a, b)), ('fsub', d, ('fmul', d, ('seq', a, b)))),
 
79
             "!options->has_fused_comp_and_csel"),
 
80
        (('bcsel@32(is_only_used_as_float)', ignore_exact('fneu', 'a@32', 'b@32'), c, d),
 
81
             ('fadd', ('fmul', c, ('sne', a, b)), ('fsub', d, ('fmul', d, ('sne', a, b)))),
 
82
          "!options->has_fused_comp_and_csel"),
 
83
        (('bcsel@32(is_only_used_as_float)', ignore_exact('flt', 'a@32', 'b@32'), c, d),
 
84
             ('fadd', ('fmul', c, ('slt', a, b)), ('fsub', d, ('fmul', d, ('slt', a, b)))),
 
85
          "!options->has_fused_comp_and_csel"),
 
86
        (('bcsel@32(is_only_used_as_float)', ignore_exact('fge', 'a@32', 'b@32'), c, d),
 
87
             ('fadd', ('fmul', c, ('sge', a, b)), ('fsub', d, ('fmul', d, ('sge', a, b)))),
 
88
          "!options->has_fused_comp_and_csel"),
 
89
]
54
90
 
55
91
    with open(args.output, 'w') as f:
56
 
        f.write('#include "r300_vs.h"')
 
92
        f.write('#include "compiler/r300_nir.h"')
57
93
 
58
94
        f.write(nir_algebraic.AlgebraicPass("r300_transform_vs_trig_input",
59
95
                                            transform_trig_input_vs_r500).render())
61
97
        f.write(nir_algebraic.AlgebraicPass("r300_transform_fs_trig_input",
62
98
                                            transform_trig_input_fs_r500).render())
63
99
 
 
100
        f.write(nir_algebraic.AlgebraicPass("r300_nir_fuse_fround_d3d9",
 
101
                                            r300_nir_fuse_fround_d3d9).render())
 
102
 
 
103
        f.write(nir_algebraic.AlgebraicPass("r300_nir_lower_bool_to_float",
 
104
                                            r300_nir_lower_bool_to_float).render())
64
105
 
65
106
if __name__ == '__main__':
66
107
    main()