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 = """
133 precision mediump float;
147 s_simpleIllegalCaseTemplate = """
155 precision mediump float;
156 precision mediump int;
170 class SwizzleCase(ShaderCase):
171 def __init__(self, name, precision, dataType, swizzle, inputs, outputs):
173 self.precision = precision
174 self.dataType = dataType
175 self.swizzle = swizzle
177 self.outputs = outputs
178 self.op = "out0 = in0.%s;" % swizzle
183 "VALUES": genValues(self.inputs, self.outputs),
186 return fillTemplate(s_swizzleCaseTemplate, params)
190 inFloat = [Scalar(x) for x in [0.0, 1.0, 2.0, 3.5, -0.5, -20.125, 36.8125]]
191 inInt = [Scalar(x) for x in [0, 1, 2, 5, 8, 11, -12, -66, -192, 255]]
192 inBool = [Scalar(x) for x in [True, False]]
194 inVec4 = [Vec4(0.0, 0.5, 0.75, 0.825), Vec4(1.0, 1.25, 1.125, 1.75),
195 Vec4(-0.5, -2.25, -4.875, 9.0), Vec4(-32.0, 64.0, -51.0, 24.0),
196 Vec4(-0.75, -1.0/31.0, 1.0/19.0, 1.0/4.0)]
197 inVec3 = toVec3(inVec4)
198 inVec2 = toVec2(inVec4)
199 inIVec4 = toIVec4(inVec4)
200 inIVec3 = toIVec3(inVec4)
201 inIVec2 = toIVec2(inVec4)
202 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)]
203 inBVec3 = toBVec3(inBVec4)
204 inBVec2 = toBVec2(inBVec4)
206 # \todo [petri] Enable large values when epsilon adapts to the values.
207 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),
208 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),
209 #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)
211 inMat3 = [Mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0),
212 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),
213 #Mat3(-18.725, -0.5, -0.0125, 19.975, -0.25, -17.75, 9.25, 65.125, -21.425),
214 #Mat3(128.0, -4096.0, -8192.0, 192.0, 768.0, -1536.0, 8192.0, 6144.0, -6144.0)
216 inMat2 = [Mat2(1.0, 0.0, 0.0, 1.0),
217 Mat2(6.5, 12.5, -0.75, 9.975),
218 Mat2(6.5, 12.5, -0.75, 9.975),
219 Mat2(8.0, 16.0, -24.0, -16.0),
220 Mat2(1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0),
221 Mat2(-18.725, -0.5, -0.0125, 19.975),
222 #Mat2(128.0, -4096.0, 192.0, -1536.0),
223 #Mat2(-1536.0, 8192.0, 6144.0, -6144.0)
244 def genConversionCases(inValueList, convFuncList):
245 combinations = list(itertools.product(inValueList, convFuncList))
246 return [ConversionCase(inValues, convFunc) for (inValues, convFunc) in combinations]
252 vectorSwizzleCases = []
254 # \todo [petri] Uses fixed precision.
255 for dataType in VECTOR_TYPES:
256 scalarSize = getDataTypeScalarSize(dataType)
257 precision = "mediump"
258 for swizzleComponents in SWIZZLE_NAMES:
259 for swizzleIndices in getSwizzlesForWidth(scalarSize):
260 swizzle = "".join(map(lambda x: swizzleComponents[x], swizzleIndices))
261 #print "%s %s .%s" % (precision, dataType, swizzle)
262 caseName = "%s_%s_%s" % (precision, dataType, swizzle)
263 inputs = INPUTS[dataType]
264 outputs = map(lambda x: x.swizzle(swizzleIndices), inputs)
265 outType = outputs[0].typeString()
266 vectorSwizzleCases.append(SwizzleCase(caseName, precision, dataType, swizzle, [("%s in0" % dataType, inputs)], [("%s out0" % outType, outputs)]))
269 #for dataType in VECTOR_TYPES:
270 # scalarSize = getDataTypeScalarSize(dataType)
271 # for precision in PRECISION_TYPES:
272 # for swizzleIndices in getSwizzlesForWidth(scalarSize):
273 # swizzle = "".join(map(lambda x: "xyzw"[x], swizzleIndices))
274 # #print "%s %s .%s" % (precision, dataType, swizzle)
275 # caseName = "%s_%s_%s" % (precision, dataType, swizzle)
276 # inputs = INPUTS[dataType]
277 # outputs = map(lambda x: x.swizzle(swizzleIndices), inputs)
278 # vectorSwizzleCases.append(SwizzleCase(caseName, precision, dataType, swizzle, [("in0", inputs)], [("out0", outputs)]))
280 allCases.append(CaseGroup("vector_swizzles", "Vector Swizzles", vectorSwizzleCases))
283 # - vector components
284 # * int, float, bool vectors
285 # * .xyzw, .rgba, .stpq
287 # * not allowed for scalar types
288 # * legal to chain: vec4.rgba.xyzw.stpq
289 # * illegal to select more than 4 components
293 #allCases.append(CaseGroup("vector_swizzles", "Vector Swizzles",
294 # genSwizzleCase([inVec2, inVec3, inVec4],
298 if __name__ == "__main__":
299 print "Generating shader case files."
300 writeAllCases("swizzles.test", allCases)