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