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
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
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.
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
):
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.
50 if shader_stage
!= 'frag':
52 print("%s - %s" % (shader_stage
, status
))
55 glsl_version
= ("3.20 es", "320 es")
57 glsl_version
= ("4.20", "420")
64 * require_extensions: GL_INTEL_conservative_rasterization
68 #extension GL_INTEL_conservative_rasterization : enable
69 """.format(status
, glsl_version
[0], glsl_version
[1]))
72 def gen(name
, src
, tests
):
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
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.
84 template
= Template(dedent(src
))
86 for t
in product([{'name': name
}], tests
):
87 filename
= os
.path
.join('spec',
88 'intel_conservative_rasterization',
90 '{0}.{1}.{2}'.format(t
['name'],
95 dirname
= os
.path
.dirname(filename
)
96 utils
.safe_makedirs(dirname
)
98 with
open(filename
, 'w') as f
:
100 f
.write(template
.render(header
=gen_header
, **t
))
102 print(exceptions
.text_error_template().render(), file=sys
.stderr
)
107 {'shader_stage': 'frag'},
108 {'shader_stage': 'vert'}
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 [{}]):
130 r
['name'] = '-'.join(s
['name'] for s
in (p
, q
) if s
.get('name'))
139 # Test inner_coverage layout qualifier.
141 gen('inner_coverage', """
142 ${header('pass', gl_api, shader_stage)}
144 layout(inner_coverage) in;
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;
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;
176 """, product(gl_apis
, shader_stages
))
178 if __name__
== '__main__':