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 #-------------------------------------------------------------------------
31 indices = xrange(sys.maxint)
35 # * int, float, bool vectors
36 # * .xyzw, .rgba, .stpq
38 # * not allowed for scalar types
39 # * legal to chain: vec4.rgba.xyzw.stpq
40 # * illegal to select more than 4 components
43 # - array-like indexing with [] operator
46 # - vectors components
50 # * note: mat4[0].x = 1.0; vs mat4[0][0] = 1.0; ??
51 # * out-of-bounds accesses
55 # * all vector types (bvec2..4, ivec2..4, vec2..4)
56 # * all precisions (lowp, mediump, highp)
57 # * all component names (xyzw, rgba, stpq)
58 # * broadcast each, reverse, N random
59 # - component-masked writes
60 # * all vector types (bvec2..4, ivec2..4, vec2..4)
61 # * all precisions (lowp, mediump, highp)
62 # * all component names (xyzw, rgba, stpq)
63 # * all possible subsets
64 # * all input types (attribute, varying, uniform, tmp)
65 # -> a few hundred cases
66 # - concatenated swizzles
69 VECTOR_TYPES = [ "vec2", "vec3", "vec4", "ivec2", "ivec3", "ivec4", "bvec2", "bvec3", "bvec4" ]
70 PRECISION_TYPES = [ "lowp", "mediump", "highp" ]
71 INPUT_TYPES = [ "uniform", "varying", "attribute", "tmp" ]
72 SWIZZLE_NAMES = [ "xyzw", "stpq", "rgba" ]
74 def getDataTypeScalarSize (dt):
95 def __init__(self, *args):
96 self.lists = list(args)
97 self.numLists = len(args)
98 self.numCombinations = reduce(operator.mul, map(len, self.lists), 1)
100 print self.numCombinations
103 return [tuple(map(lambda x: x[0], self.lists))]
105 combinations = Combinations(INPUT_TYPES, VECTOR_TYPES, PRECISION_TYPES)
106 print combinations.iterate()
107 for (inputType, dataType, precision) in combinations.iterate():
108 scalarSize = getDataTypeScalarSize(dataType)
109 print inputType, precision, dataType
111 def getSwizzlesForWidth(width):
113 return [(0,), (0,0), (0,1), (1,0), (1,0,1), (0,1,0,0), (1,1,1,1)]
115 return [(0,), (2,), (0,2), (2,2), (0,1,2), (2,1,0), (0,0,0), (2,2,2), (2,2,1), (1,0,1), (0,2,0), (0,1,1,0), (2,2,2,2)]
117 return [(0,), (3,), (3,0), (3,2), (3,3,3), (1,1,3), (3,2,1), (0,1,2,3), (3,2,1,0), (0,0,0,0), (1,1,1,1), (3,3,3,3), (3,2,2,3), (3,3,3,1), (0,1,0,0), (2,2,3,2)]
123 s_swizzleCaseTemplate = """
131 precision mediump float;
145 s_simpleIllegalCaseTemplate = """
151 precision mediump float;
152 precision mediump int;
166 class SwizzleCase(ShaderCase):
167 def __init__(self, name, precision, dataType, swizzle, inputs, outputs):
169 self.precision = precision
170 self.dataType = dataType
171 self.swizzle = swizzle
173 self.outputs = outputs
174 self.op = "out0 = in0.%s;" % swizzle
179 "VALUES": genValues(self.inputs, self.outputs),
182 return fillTemplate(s_swizzleCaseTemplate, params)
186 inFloat = [Scalar(x) for x in [0.0, 1.0, 2.0, 3.5, -0.5, -20.125, 36.8125]]
187 inInt = [Scalar(x) for x in [0, 1, 2, 5, 8, 11, -12, -66, -192, 255]]
188 inBool = [Scalar(x) for x in [True, False]]
190 inVec4 = [Vec4(0.0, 0.5, 0.75, 0.825), Vec4(1.0, 1.25, 1.125, 1.75),
191 Vec4(-0.5, -2.25, -4.875, 9.0), Vec4(-32.0, 64.0, -51.0, 24.0),
192 Vec4(-0.75, -1.0/31.0, 1.0/19.0, 1.0/4.0)]
193 inVec3 = toVec3(inVec4)
194 inVec2 = toVec2(inVec4)
195 inIVec4 = toIVec4(inVec4)
196 inIVec3 = toIVec3(inVec4)
197 inIVec2 = toIVec2(inVec4)
198 inBVec4 = [Vec4(True, False, False, True), Vec4(False, False, False, True), Vec4(False, True, False, False), Vec4(True, True, True, True), Vec4(False, False, False, False)]
199 inBVec3 = toBVec3(inBVec4)
200 inBVec2 = toBVec2(inBVec4)
202 # \todo [petri] Enable large values when epsilon adapts to the values.
203 inMat4 = [Mat4(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0),
204 Mat4(6.5, 12.5, -0.75, 9.975, 32.0, 1.0/48.0, -8.425, -6.542, 1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0, -6.725, -0.5, -0.0125, 9.975),
205 #Mat4(128.0, 256.0, -512.0, -1024.0, 2048.0, -4096.0, 8192.0, -8192.0, 192.0, -384.0, 768.0, -1536.0, 8192.0, -8192.0, 6144.0, -6144.0)
207 inMat3 = [Mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
208 Mat3(6.5, 12.5, -0.75, 32.0, 1.0/32.0, 1.0/64.0, 1.0/8.0, 1.0/16.0, 1.0/32.0),
209 #Mat3(-18.725, -0.5, -0.0125, 19.975, -0.25, -17.75, 9.25, 65.125, -21.425),
210 #Mat3(128.0, -4096.0, -8192.0, 192.0, 768.0, -1536.0, 8192.0, 6144.0, -6144.0)
212 inMat2 = [Mat2(1.0, 0.0, 0.0, 1.0),
213 Mat2(6.5, 12.5, -0.75, 9.975),
214 Mat2(6.5, 12.5, -0.75, 9.975),
215 Mat2(8.0, 16.0, -24.0, -16.0),
216 Mat2(1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0),
217 Mat2(-18.725, -0.5, -0.0125, 19.975),
218 #Mat2(128.0, -4096.0, 192.0, -1536.0),
219 #Mat2(-1536.0, 8192.0, 6144.0, -6144.0)
240 def genConversionCases(inValueList, convFuncList):
241 combinations = list(itertools.product(inValueList, convFuncList))
242 return [ConversionCase(inValues, convFunc) for (inValues, convFunc) in combinations]
248 vectorSwizzleCases = []
250 # \todo [petri] Uses fixed precision.
251 for dataType in VECTOR_TYPES:
252 scalarSize = getDataTypeScalarSize(dataType)
253 precision = "mediump"
254 for swizzleComponents in SWIZZLE_NAMES:
255 for swizzleIndices in getSwizzlesForWidth(scalarSize):
256 swizzle = "".join(map(lambda x: swizzleComponents[x], swizzleIndices))
257 #print "%s %s .%s" % (precision, dataType, swizzle)
258 caseName = "%s_%s_%s" % (precision, dataType, swizzle)
259 inputs = INPUTS[dataType]
260 outputs = map(lambda x: x.swizzle(swizzleIndices), inputs)
261 outType = outputs[0].typeString()
262 vectorSwizzleCases.append(SwizzleCase(caseName, precision, dataType, swizzle, [("%s in0" % dataType, inputs)], [("%s out0" % outType, outputs)]))
265 #for dataType in VECTOR_TYPES:
266 # scalarSize = getDataTypeScalarSize(dataType)
267 # for precision in PRECISION_TYPES:
268 # for swizzleIndices in getSwizzlesForWidth(scalarSize):
269 # swizzle = "".join(map(lambda x: "xyzw"[x], swizzleIndices))
270 # #print "%s %s .%s" % (precision, dataType, swizzle)
271 # caseName = "%s_%s_%s" % (precision, dataType, swizzle)
272 # inputs = INPUTS[dataType]
273 # outputs = map(lambda x: x.swizzle(swizzleIndices), inputs)
274 # vectorSwizzleCases.append(SwizzleCase(caseName, precision, dataType, swizzle, [("in0", inputs)], [("out0", outputs)]))
276 allCases.append(CaseGroup("vector_swizzles", "Vector Swizzles", vectorSwizzleCases))
279 # - vector components
280 # * int, float, bool vectors
281 # * .xyzw, .rgba, .stpq
283 # * not allowed for scalar types
284 # * legal to chain: vec4.rgba.xyzw.stpq
285 # * illegal to select more than 4 components
289 #allCases.append(CaseGroup("vector_swizzles", "Vector Swizzles",
290 # genSwizzleCase([inVec2, inVec3, inVec4],
294 if __name__ == "__main__":
295 print "Generating shader case files."
296 writeAllCases("swizzles.test", allCases)