gen_const_builtin_equal_tests.py 3.79 KB
Newer Older
1
# Copyright (c) 2010, 2014 Intel Corporation
2

3
4
5
6
7
8
# 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:
9

10
11
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
12

13
14
15
16
17
18
19
# 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.
20

21
""" Generate tests for builtin const equality tests """
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import print_function
import re
import os
import textwrap
import mako.template

TEMPLATE = mako.template.Template(textwrap.dedent("""
    [require]
    GLSL >= 1.20

    [vertex shader]
    void main()
    {
      gl_Position = gl_Vertex;
    }

    [fragment shader]
    void main()
    {
      const ${expected.split('(')[0]} res = ${func}(${input[0]}, ${input[1]});
      gl_FragColor = (res == ${expected})
        ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
    }

    [test]
    draw rect -1 -1 2 2
    probe all rgb 0.0 1.0 0.0"""))
50

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
TEST_VECTORS = [
    ["vec2(3.0, 3.14)",
     "vec2(-6.0, 7.88)",
     "bvec2(false, false)"
    ],
    ["vec3(13.4, -0.9, 12.55)",
     "vec3(13.4, 12.0, -55.3)",
     "bvec3(true, false, false)"
    ],
    ["vec4(-2.0, 0.0, 0.123, -1000.5)",
     "vec4(-2.4, 0.0, 0.456, 12.5)",
     "bvec4(false, true, false, false)"
    ],
    ["ivec2(-8, 12)",
     "ivec2(-19, 12)",
     "bvec2(false, true)"
    ],
    ["ivec3(0, 8, 89)",
     "ivec3(4, -7, 33)",
     "bvec3(false, false, false)"
    ],
    ["ivec4(11, 1000, 1, -18)",
     "ivec4(55, 1000, -21, -17)",
     "bvec4(false, true, false, false)"
    ],
    ["bvec2(true, false)",
     "bvec2(true, true)",
     "bvec2(true, false)"
    ],
    ["bvec3(false, true, false)",
     "bvec3(false, false, true)",
     "bvec3(true, false, false)"
    ],
    ["bvec4(true, false, false, true)",
     "bvec4(true, true, false, false)",
     "bvec4(true, false, true, false)"
    ],
]
89

90

91
92
def main():
    """ Main function """
93
94
95
96
    dirname = os.path.join('spec', 'glsl-1.20', 'execution',
                           'built-in-functions')
    if not os.path.exists(dirname):
        os.makedirs(dirname)
97

98
    for test_id, x in enumerate(TEST_VECTORS, start=2):
99
        # make equal tests
100
101
102
103
        name = os.path.join(
            dirname,
            "glsl-const-builtin-equal-{0:02d}.shader_test".format(test_id))

104
        print(name)
105

106
107
108
        with open(name, 'w') as f:
            f.write(TEMPLATE.render_unicode(
                func='equal', input=x[0:2], expected=x[2]))
109

110
        # make notEqual tests
111
112
113
        name = os.path.join(
            dirname,
            "glsl-const-builtin-notEqual-{0:02d}.shader_test".format(test_id))
114

115
116
117
118
119
        # When generating the notEqual tests, each of the values in the
        # expected result vector need to be inverted
        expected = re.sub("true", "FALSE", x[2])
        expected = re.sub("false", "TRUE", expected)
        expected = expected.lower()
120

121
        print(name)
122

123
124
125
        with open(name, 'w') as f:
            f.write(TEMPLATE.render_unicode(
                func='notEqual', input=x[0:2], expected=expected))
126

127

128
129
if __name__ == "__main__":
    main()