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.
34 from textwrap
import dedent
36 from mako
.template
import Template
38 from modules
import utils
40 def gen_header(status
, gl_api
, shader_stage
):
42 Generate a GLSL program header.
44 Generate header code for INTEL_conservative_rasterization GLSL parser
45 tests that are expected to give status as result.
48 if shader_stage
!= 'frag':
50 print("%s - %s" % (shader_stage
, status
))
53 glsl_version
= ("3.20 es", "320 es")
55 glsl_version
= ("4.20", "420")
62 * require_extensions: GL_INTEL_conservative_rasterization
66 #extension GL_INTEL_conservative_rasterization : enable
67 """.format(status
, glsl_version
[0], glsl_version
[1]))
70 def gen(name
, src
, tests
):
72 Expand a source template for the provided list of test definitions.
74 Generate a GLSL parser test for each of the elements of the
75 'tests' iterable, each of them should be a dictionary of
76 definitions that will be used as environment to render the source
79 The file name of each test will be the concatenation of the 'name'
80 argument with the 'name' item from the respective test dictionary.
82 template
= Template(dedent(src
))
84 for t
in product([{'name': name
}], tests
):
85 filename
= os
.path
.join('spec',
86 'intel_conservative_rasterization',
88 '{0}.{1}.{2}'.format(t
['name'],
93 dirname
= os
.path
.dirname(filename
)
94 utils
.safe_makedirs(dirname
)
96 with
open(filename
, 'w') as f
:
97 f
.write(template
.render(header
=gen_header
, **t
))
101 {'shader_stage': 'frag'},
102 {'shader_stage': 'vert'}
112 def product(ps
, *qss
):
114 Generate the cartesian product of a number of lists of dictionaries.
116 Each generated element will be the union of some combination of
117 elements from the iterable arguments. The resulting value of each
118 'name' item will be the concatenation of names of the respective
119 element combination separated with dashes.
121 for q
in (product(*qss
) if qss
else [{}]):
124 r
['name'] = '-'.join(s
['name'] for s
in (p
, q
) if s
.get('name'))
133 # Test inner_coverage layout qualifier.
135 gen('inner_coverage', """
136 ${header('pass', gl_api, shader_stage)}
138 layout(inner_coverage) in;
143 """, product(gl_apis
, shader_stages
))
146 # Test depth_coverage layout qualifier.
148 gen('post_depth_coverage', """
149 ${header('pass', gl_api, shader_stage)}
151 layout(post_depth_coverage) in;
156 """, product(gl_apis
, shader_stages
))
159 # Test depth_coverage layout qualifier.
161 gen('inner_post_depth_coverage', """
162 ${header('fail', gl_api, shader_stage)}
164 layout(inner_coverage) in;
165 layout(post_depth_coverage) in;
170 """, product(gl_apis
, shader_stages
))
172 if __name__
== '__main__':