write-after-clear: Test clears of alternating layers
[piglit.git] / generated_tests / gen_shader_image_nv_image_formats_tests.py
blobe8826defbedd48a48ca92075c00939bbab6a1a3f
1 # coding=utf-8
3 # Copyright (C) 2016 Intel Corporation
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
24 """Generate a set of tests to verify that formats added by the
25 NV_image_formats extension for GLES 3.1 are properly accepted by the GLSL
26 compiler.
28 This also verifies that 16bits normalized formats are not accepted unless
29 EXT_texture_norm16 is available.
31 This program outputs, to stdout, the name of each file it generates.
32 """
34 import os.path
35 from textwrap import dedent
37 from mako.template import Template
39 from modules import utils
41 def gen_header(status, norm16):
42 """
43 Generate a GLSL program header.
45 Generate header code for ARB_shader_image_load_store GLSL parser
46 tests that are expected to give status as result.
47 """
49 if norm16:
50 norm16_require = "GL_EXT_texture_norm16"
51 else:
52 norm16_require = "!GL_EXT_texture_norm16"
54 return dedent("""
56 * [config]
57 * expect_result: {0}
58 * glsl_version: 3.10 es
59 * require_extensions: GL_NV_image_formats {1}
60 * [end config]
62 #version 310 es
63 #extension GL_NV_image_formats : require
64 """.format(status, norm16_require))
67 def gen(name, src, tests):
68 """
69 Expand a source template for the provided list of test definitions.
71 Generate a GLSL parser test for each of the elements of the
72 'tests' iterable, each of them should be a dictionary of
73 definitions that will be used as environment to render the source
74 template.
76 The file name of each test will be the concatenation of the 'name'
77 argument with the 'name' item from the respective test dictionary.
78 """
79 template = Template(dedent(src))
81 for t in product([{'name': name}], tests):
82 filename = os.path.join('spec',
83 'nv_image_formats',
84 'compiler',
85 '{0}.{1}'.format(t['name'],
86 t['shader_stage']))
87 print(filename)
89 dirname = os.path.dirname(filename)
90 utils.safe_makedirs(dirname)
92 with open(filename, 'w') as f:
93 f.write(template.render(header=gen_header, **t))
96 shader_stages = [
97 {'shader_stage': 'frag'},
98 {'shader_stage': 'vert'}
102 image_types = [
104 'name': '2d',
105 'image_type': 'image2D',
108 'name': '3d',
109 'image_type': 'image3D',
112 'name': '2d-array',
113 'image_type': 'image2DArray',
116 'name': 'cube',
117 'image_type': 'imageCube',
122 def product(ps, *qss):
124 Generate the cartesian product of a number of lists of dictionaries.
126 Each generated element will be the union of some combination of
127 elements from the iterable arguments. The resulting value of each
128 'name' item will be the concatenation of names of the respective
129 element combination separated with dashes.
131 for q in (product(*qss) if qss else [{}]):
132 for p in ps:
133 r = dict(p, **q)
134 r['name'] = '-'.join(s['name'] for s in (p, q) if s.get('name'))
135 yield r
138 def main():
139 """Main function."""
143 # Test image formats accepted with NV_image_formats &
144 # EXT_texture_norm16.
146 gen('declarations-with-norm16', """
147 ${header('pass', True)}
149 layout(rg32f) readonly uniform highp ${image_type} img_rg32f;
150 layout(rg16f) readonly uniform highp ${image_type} img_rg16f;
151 layout(r16f) readonly uniform highp ${image_type} img_r16f;
152 layout(r11f_g11f_b10f) readonly uniform highp ${image_type} img_r11g11b10f;
154 layout(rgba16) readonly uniform highp ${image_type} img_rgba16_unorm;
155 layout(rgb10_a2) readonly uniform highp ${image_type} img_rgb10_a2_unorm;
156 layout(rg16) readonly uniform highp ${image_type} img_rg16_unorm;
157 layout(rg8) readonly uniform highp ${image_type} img_rg8_unorm;
158 layout(r16) readonly uniform highp ${image_type} img_r16_unorm;
159 layout(r8) readonly uniform highp ${image_type} img_r8_unorm;
161 layout(rgba16_snorm) readonly uniform highp ${image_type} img_rgba16_snorm;
162 layout(rg16_snorm) readonly uniform highp ${image_type} img_rg16_snorm;
163 layout(rg8_snorm) readonly uniform highp ${image_type} img_rg8_snorm;
164 layout(r16_snorm) readonly uniform highp ${image_type} img_r16_snorm;
165 layout(r8_snorm) readonly uniform highp ${image_type} img_r8_snorm;
167 layout(rgb10_a2ui) readonly uniform highp u${image_type} img_rgb10_a2ui;
168 layout(rg32ui) readonly uniform highp u${image_type} img_rg32ui;
169 layout(rg16ui) readonly uniform highp u${image_type} img_rg16ui;
170 layout(rg8ui) readonly uniform highp u${image_type} img_rg8ui;
171 layout(r16ui) readonly uniform highp u${image_type} img_r16ui;
172 layout(r8ui) readonly uniform highp u${image_type} img_r8ui;
174 layout(rg32i) readonly uniform highp i${image_type} img_rg32i;
175 layout(rg16i) readonly uniform highp i${image_type} img_rg16i;
176 layout(rg8i) readonly uniform highp i${image_type} img_rg8i;
177 layout(r16i) readonly uniform highp i${image_type} img_r16i;
178 layout(r8i) readonly uniform highp i${image_type} img_r8i;
180 void main()
183 """, product(image_types, shader_stages))
187 # Test image formats accepted with only NV_image_formats.
189 gen('declarations-without-norm16', """
190 ${header('pass', False)}
192 layout(rg32f) readonly uniform highp ${image_type} img_rg32f;
193 layout(rg16f) readonly uniform highp ${image_type} img_rg16f;
194 layout(r16f) readonly uniform highp ${image_type} img_r16f;
195 layout(r11f_g11f_b10f) readonly uniform highp ${image_type} img_r11g11b10f;
197 layout(rgb10_a2) readonly uniform highp ${image_type} img_rgb10_a2_unorm;
198 layout(rg8) readonly uniform highp ${image_type} img_rg8_unorm;
199 layout(r8) readonly uniform highp ${image_type} img_r8_unorm;
201 layout(rg8_snorm) readonly uniform highp ${image_type} img_rg8_snorm;
202 layout(r8_snorm) readonly uniform highp ${image_type} img_r8_snorm;
204 layout(rgb10_a2ui) readonly uniform highp u${image_type} img_rgb10_a2ui;
205 layout(rg32ui) readonly uniform highp u${image_type} img_rg32ui;
206 layout(rg16ui) readonly uniform highp u${image_type} img_rg16ui;
207 layout(rg8ui) readonly uniform highp u${image_type} img_rg8ui;
208 layout(r16ui) readonly uniform highp u${image_type} img_r16ui;
209 layout(r8ui) readonly uniform highp u${image_type} img_r8ui;
211 layout(rg32i) readonly uniform highp i${image_type} img_rg32i;
212 layout(rg16i) readonly uniform highp i${image_type} img_rg16i;
213 layout(rg8i) readonly uniform highp i${image_type} img_rg8i;
214 layout(r16i) readonly uniform highp i${image_type} img_r16i;
215 layout(r8i) readonly uniform highp i${image_type} img_r8i;
217 void main()
220 """, product(image_types, shader_stages))
224 # Test image formats forbidden without EXT_texture_norm16.
226 gen('declaration-disallow-rgba16-unorm', """
227 ${header('fail', False)}
229 layout(rgba16) readonly uniform highp ${image_type} img_rgba16;
231 void main()
234 """, product(image_types, shader_stages))
237 gen('declaration-disallow-rg16-unorm', """
238 ${header('fail', False)}
240 layout(rg16) readonly uniform highp ${image_type} img_rg16;
242 void main()
245 """, product(image_types, shader_stages))
248 gen('declaration-disallow-r16-unorm', """
249 ${header('fail', False)}
251 layout(r16) readonly uniform highp ${image_type} img_r16;
253 void main()
256 """, product(image_types, shader_stages))
259 gen('declaration-disallow-rgba16-snorm', """
260 ${header('fail', False)}
262 layout(rgba16_snorm) readonly uniform highp ${image_type} img_rgba16_snorm;
264 void main()
267 """, product(image_types, shader_stages))
270 gen('declaration-disallow-rg16-snorm', """
271 ${header('fail', False)}
273 layout(rg16_snorm) readonly uniform highp ${image_type} img_rg16_snorm;
275 void main()
278 """, product(image_types, shader_stages))
281 gen('declaration-disallow-r16-snorm', """
282 ${header('fail', False)}
284 layout(r16_snorm) readonly uniform highp ${image_type} img_r16_snorm;
286 void main()
289 """, product(image_types, shader_stages))
291 if __name__ == '__main__':
292 main()