tests: add ext_image_dma_buf_import-tex-modifier
[piglit.git] / generated_tests / gen_shader_intel_conservative_rasterization.py
blobaf074377281ed8525e4fbbc128f5564171148b81
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 layout qualifiers introduced
25 by INTEL_conservative_rasterization are properly parsed.
27 This also verifies the interaction with ARB_post_depth_coverage.
29 This program outputs, to stdout, the name of each file it generates.
31 """
33 import os.path
34 import sys
35 from textwrap import dedent
37 from mako import exceptions
38 from mako.template import Template
40 from modules import utils
42 def gen_header(status, gl_api, shader_stage):
43 """
44 Generate a GLSL program header.
46 Generate header code for INTEL_conservative_rasterization GLSL parser
47 tests that are expected to give status as result.
48 """
50 if shader_stage != 'frag':
51 status = 'fail'
52 print("%s - %s" % (shader_stage, status))
54 if gl_api == "gles":
55 glsl_version = ("3.20 es", "320 es")
56 else:
57 glsl_version = ("4.20", "420")
59 return dedent("""
61 * [config]
62 * expect_result: {0}
63 * glsl_version: {1}
64 * require_extensions: GL_INTEL_conservative_rasterization
65 * [end config]
67 #version {2}
68 #extension GL_INTEL_conservative_rasterization : enable
69 """.format(status, glsl_version[0], glsl_version[1]))
72 def gen(name, src, tests):
73 """
74 Expand a source template for the provided list of test definitions.
76 Generate a GLSL parser test for each of the elements of the
77 'tests' iterable, each of them should be a dictionary of
78 definitions that will be used as environment to render the source
79 template.
81 The file name of each test will be the concatenation of the 'name'
82 argument with the 'name' item from the respective test dictionary.
83 """
84 template = Template(dedent(src))
86 for t in product([{'name': name}], tests):
87 filename = os.path.join('spec',
88 'intel_conservative_rasterization',
89 'compiler',
90 '{0}.{1}.{2}'.format(t['name'],
91 t['gl_api'],
92 t['shader_stage']))
93 print(filename)
95 dirname = os.path.dirname(filename)
96 utils.safe_makedirs(dirname)
98 with open(filename, 'w') as f:
99 try:
100 f.write(template.render(header=gen_header, **t))
101 except:
102 print(exceptions.text_error_template().render(), file=sys.stderr)
103 raise
106 shader_stages = [
107 {'shader_stage': 'frag'},
108 {'shader_stage': 'vert'}
112 gl_apis = [
113 {'gl_api': 'gl'},
114 {'gl_api': 'gles'}
118 def product(ps, *qss):
120 Generate the cartesian product of a number of lists of dictionaries.
122 Each generated element will be the union of some combination of
123 elements from the iterable arguments. The resulting value of each
124 'name' item will be the concatenation of names of the respective
125 element combination separated with dashes.
127 for q in (product(*qss) if qss else [{}]):
128 for p in ps:
129 r = dict(p, **q)
130 r['name'] = '-'.join(s['name'] for s in (p, q) if s.get('name'))
131 yield r
134 def main():
135 """Main function."""
139 # Test inner_coverage layout qualifier.
141 gen('inner_coverage', """
142 ${header('pass', gl_api, shader_stage)}
144 layout(inner_coverage) in;
146 void main()
149 """, product(gl_apis, shader_stages))
152 # Test depth_coverage layout qualifier.
154 gen('post_depth_coverage', """
155 ${header('pass', gl_api, shader_stage)}
157 layout(post_depth_coverage) in;
159 void main()
162 """, product(gl_apis, shader_stages))
165 # Test depth_coverage layout qualifier.
167 gen('inner_post_depth_coverage', """
168 ${header('fail', gl_api, shader_stage)}
170 layout(inner_coverage) in;
171 layout(post_depth_coverage) in;
173 void main()
176 """, product(gl_apis, shader_stages))
178 if __name__ == '__main__':
179 main()