sso: test program pipeline with atomic counters
[piglit.git] / generated_tests / gen_variable_index_read_tests.py
blobcc6f49bdb1f8428211b0aae9f2100437dd34d883
1 # Copyright (c) 2015 Intel Corporation
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
21 """Generate tests for glsl 1.10 and 1.20 variable index reads."""
23 from __future__ import print_function, absolute_import, division
24 import os
25 import itertools
27 from six.moves import range
29 from templates import template_dir
30 from modules.utils import lazy_property, safe_makedirs
32 TEMPLATES = template_dir(os.path.basename(os.path.splitext(__file__)[0]))
33 FS_TEMPLATE = TEMPLATES.get_template('fs.shader_test.mako')
34 VS_TEMPLATE = TEMPLATES.get_template('vs.shader_test.mako')
35 DIRNAME = os.path.join('spec', 'glsl-{}', 'execution', 'variable-indexing')
38 class TestParams(object):
39 """Parameters for a single test.
41 This is all of the non-formatting logic of the test. Each property is
42 wrapped with a lazy_property decorator, which means the data is cached
43 after it is calculated once.
45 """
46 def __init__(self, matrix_dim, array_dim, mode, index_value, col,
47 expect_type, glsl_version):
48 self.matrix_dim = matrix_dim
49 self.array_dim = array_dim
50 self.mode = mode
51 self.index_value = index_value
52 self.__col = col
53 self.expect_type = expect_type
55 assert glsl_version in [110, 120]
56 self.glsl_version = glsl_version
58 @lazy_property
59 def idx(self):
60 if self.array_dim != 0:
61 return '[{}]'.format(self.index_value)
62 else:
63 return ''
65 @lazy_property
66 def cxr_type(self):
67 return 'mat{0}x{0}'.format(self.matrix_dim)
69 @lazy_property
70 def base_type(self):
71 if self.glsl_version == 120:
72 return self.cxr_type
73 else:
74 return 'mat{}'.format(self.matrix_dim)
76 @lazy_property
77 def type(self):
78 if self.array_dim != 0 and self.glsl_version == 120:
79 return '{}[{}]'.format(self.base_type, self.array_dim)
80 else:
81 return self.base_type
83 @lazy_property
84 def dim(self):
85 if self.array_dim != 0 and self.glsl_version == 110:
86 return '[{}]'.format(self.array_dim)
87 else:
88 # XXX: should this be an error?
89 return ''
91 @lazy_property
92 def row(self):
93 if self.expect_type == 'float':
94 return '[row]'
95 else:
96 # XXX: Should this be an error?
97 return ''
99 @lazy_property
100 def col(self):
101 return '[{}]'.format(self.__col)
103 @lazy_property
104 def test_sizes(self):
105 if self.array_dim == 0:
106 return [1]
107 elif self.index_value == 'index':
108 return list(range(1, 1 + self.array_dim))
109 else:
110 return [2]
112 @lazy_property
113 def test_columns(self):
114 if self.col == '[col]':
115 return list(range(1, 1 + self.matrix_dim))
116 else:
117 return [2]
119 @lazy_property
120 def test_rows(self):
121 if self.expect_type == 'float':
122 return list(range(1, 1 + self.matrix_dim))
123 else:
124 return [1]
126 @lazy_property
127 def test_array_dim(self):
128 if (self.mode == 'uniform' and
129 self.glsl_version == 110 and
130 self.array_dim != 0 and
131 self.index_value != 'index'):
132 return self.index_value + 1
133 else:
134 return self.array_dim
136 @lazy_property
137 def varying_comps(self):
138 if self.array_dim != 0:
139 return 4 + self.matrix_dim**2 * self.array_dim
140 else:
141 return 4 + self.matrix_dim**2
143 @lazy_property
144 def formated_version(self):
145 return '{:.2f}'.format(float(self.glsl_version) / 100)
148 def make_fs(name, params):
149 """Generate a fragment shader test."""
150 dirname = DIRNAME.format(params.formated_version)
151 safe_makedirs(dirname)
152 with open(os.path.join(dirname, name), 'w') as f:
153 f.write(FS_TEMPLATE.render_unicode(params=params))
154 print(name)
157 def make_vs(name, params):
158 """Generate a vertex shader test."""
159 dirname = DIRNAME.format(params.formated_version)
160 safe_makedirs(dirname)
161 with open(os.path.join(dirname, name), 'w') as f:
162 f.write(VS_TEMPLATE.render_unicode(params=params))
163 print(name)
166 def main():
167 """Generate the tests."""
168 modes = ['temp', 'uniform', 'varying']
169 array_dims = [0, 3]
170 matrix_dims = [2, 3, 4]
171 glsl_versions = [110, 120]
172 cols = [1, 'col']
173 stages = ['fs', 'vs']
174 iter_ = itertools.product(stages, modes, array_dims, matrix_dims,
175 glsl_versions, cols)
176 for stage, mode, array_dim, matrix_dim, glsl_version, col in iter_:
177 if stage == 'vs':
178 func = make_vs
179 else:
180 func = make_fs
182 for expect in ['float', 'vec{}'.format(matrix_dim)]:
183 if array_dim != 0:
184 arr = 'array-'
185 idx_text = 'index-'
187 func(
188 '{stage}-{mode}-{arr}mat{matrix_dim}-{col}{row}rd.shader_test'.format(
189 stage=stage,
190 mode=mode,
191 arr=arr,
192 matrix_dim=matrix_dim,
193 col='col-' if col == 'col' else '',
194 row='row-' if expect == 'float' else ''),
195 TestParams(matrix_dim, array_dim, mode, 1, col, expect,
196 glsl_version))
197 else:
198 arr = ''
199 idx_text = ''
201 func(
202 '{stage}-{mode}-{arr}mat{matrix_dim}-{idx_text}{col}{row}rd.shader_test'.format(
203 stage=stage,
204 mode=mode,
205 arr=arr,
206 matrix_dim=matrix_dim,
207 idx_text=idx_text,
208 col='col-' if col == 'col' else '',
209 row='row-' if expect == 'float' else ''),
210 TestParams(matrix_dim, array_dim, mode, 'index', col, expect,
211 glsl_version))
214 if __name__ == '__main__':
215 main()