1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
25 from collections import namedtuple
30 declarationTemplate = """
37 precision mediump float;
38 in highp vec4 dEQP_Position;
46 gl_Position = dEQP_Position;
52 precision mediump float;
53 layout(location = 0) out mediump vec4 dEQP_FragColor;
59 float result = (x0 + x1 + x2) / 3.0;
60 dEQP_FragColor = vec4(result, result, result, 1.0);
66 parameterTemplate = """
74 precision mediump float;
77 float foo0 (${{PARAMETER0}})
82 void foo1 (${{PARAMETER1}})
87 float foo2 (${{PARAMETER2}})
107 class DeclarationCase(ShaderCase):
108 def __init__(self, compileFail, invariantInput, paramList):
109 self.compileFail = 'expect compile_fail' if compileFail else 'expect pass'
117 if paramList.index(p) != len(paramList)-1:
120 var0 += p.vars[0] + ' '
121 var1 += p.vars[1] + ' '
122 var2 += p.vars[2] + ' '
125 self.name += "_invariant_input"
127 var0 += 'float x0;\n'
128 var1 += 'float x1;\n'
131 variables = (var0 + var1 + var2).strip()
132 variables = variables.replace(" ", " ")
133 self.variableVtx = variables.replace("anon_centroid", "out")
134 self.variableFrg = variables.replace("anon_centroid", "in")
135 self.variableVtx = self.variableVtx.replace("centroid", "centroid out")
136 self.variableFrg = self.variableFrg.replace("centroid", "centroid in")
138 self.variableFrg = self.variableFrg.replace("invariant", "") # input variable cannot be invariant...
140 self.variableFrg = "invariant " + self.variableFrg # ...unless we are doing a negative test
145 "COMPILE_FAIL" : self.compileFail,
146 "VARIABLE_VTX" : self.variableVtx,
147 "VARIABLE_FRG" : self.variableFrg
149 return fillTemplate(declarationTemplate, params)
151 class ParameterCase(ShaderCase):
152 def __init__(self, compileFail, paramList):
153 self.compileFail = "expect compile_fail" if compileFail else "expect pass"
161 if paramList.index(p) != len(paramList)-1:
164 self.param0 += p.vars[0] + ' '
165 self.param1 += p.vars[1] + ' '
166 self.param2 += p.vars[2] + ' '
168 self.param0 += 'float x'
169 self.param1 += 'float x'
170 self.param2 += 'float x'
171 self.param0 = self.param0.replace(" ", " ")
172 self.param1 = self.param1.replace(" ", " ")
173 self.param2 = self.param2.replace(" ", " ")
178 "COMPILE_FAIL" : self.compileFail,
179 "PARAMETER0" : self.param0,
180 "PARAMETER1" : self.param1,
181 "PARAMETER2" : self.param2,
183 return fillTemplate(parameterTemplate, params)
187 CaseFormat = namedtuple('CaseFormat', 'name vars')
189 DECL_INVARIANT = CaseFormat("invariant", [ "invariant", "", "" ])
190 DECL_INTERPOLATION = CaseFormat("interp", [ "smooth", "flat", "" ])
191 DECL_STORAGE = CaseFormat("storage", [ "centroid", "anon_centroid", "uniform" ])
192 DECL_PRECISION = CaseFormat("precision", [ "lowp", "mediump", "highp" ])
194 PARAM_STORAGE = CaseFormat("storage", [ "const", "", ""])
195 PARAM_PARAMETER = CaseFormat("parameter", [ "in", "out", "inout" ])
196 PARAM_PRECISION = CaseFormat("precision", [ "lowp", "mediump", "highp" ])
198 # Order of qualification tests
200 validDeclarationCases = []
201 invalidDeclarationCases = []
202 validParameterCases = []
203 invalidParameterCases = []
206 [DECL_INVARIANT, DECL_INTERPOLATION, DECL_STORAGE, DECL_PRECISION],
207 [DECL_INTERPOLATION, DECL_STORAGE, DECL_PRECISION],
208 [DECL_INVARIANT, DECL_INTERPOLATION, DECL_STORAGE],
209 [DECL_INVARIANT, DECL_STORAGE, DECL_PRECISION],
210 [DECL_STORAGE, DECL_PRECISION],
211 [DECL_INTERPOLATION, DECL_STORAGE],
212 [DECL_INVARIANT, DECL_STORAGE]
216 [PARAM_STORAGE, PARAM_PARAMETER, PARAM_PRECISION],
217 [PARAM_STORAGE, PARAM_PARAMETER],
218 [PARAM_STORAGE, PARAM_PRECISION],
219 [PARAM_PARAMETER, PARAM_PRECISION]
221 print len(paramFormats)
223 for f in declFormats:
224 for p in itertools.permutations(f):
226 validDeclarationCases.append(DeclarationCase(False, False, p)) # Correct order
228 invalidDeclarationCases.append(DeclarationCase(True, False, p)) # Incorrect order
230 for f in declFormats:
231 invalidDeclarationCases.append(DeclarationCase(True, True, f)) # Correct order but invariant is not allowed as and input parameter
233 for f in paramFormats:
234 for p in itertools.permutations(f):
236 validParameterCases.append(ParameterCase(False, p)) # Correct order
238 invalidParameterCases.append(ParameterCase(True, p)) # Incorrect order
240 qualificationOrderCases = [
241 CaseGroup("variables", "Order of qualification in variable declarations.", children = [
242 CaseGroup("valid", "Valid orderings.", validDeclarationCases),
243 CaseGroup("invalid", "Invalid orderings.", invalidDeclarationCases)
245 CaseGroup("parameters", "Order of qualification in function parameters.", children = [
246 CaseGroup("valid", "Valid orderings.", validParameterCases),
247 CaseGroup("invalid", "Invalid orderings.", invalidParameterCases)
253 if __name__ == "__main__":
254 print "Generating shader case files."
255 writeAllCases("qualification_order.test", qualificationOrderCases)