1*35238bceSAndroid Build Coastguard Worker# -*- coding: utf-8 -*- 2*35238bceSAndroid Build Coastguard Worker 3*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker# drawElements Quality Program utilities 5*35238bceSAndroid Build Coastguard Worker# -------------------------------------- 6*35238bceSAndroid Build Coastguard Worker# 7*35238bceSAndroid Build Coastguard Worker# Copyright 2015 The Android Open Source Project 8*35238bceSAndroid Build Coastguard Worker# 9*35238bceSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 10*35238bceSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 11*35238bceSAndroid Build Coastguard Worker# You may obtain a copy of the License at 12*35238bceSAndroid Build Coastguard Worker# 13*35238bceSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 14*35238bceSAndroid Build Coastguard Worker# 15*35238bceSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 16*35238bceSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 17*35238bceSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18*35238bceSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 19*35238bceSAndroid Build Coastguard Worker# limitations under the License. 20*35238bceSAndroid Build Coastguard Worker# 21*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 22*35238bceSAndroid Build Coastguard Worker 23*35238bceSAndroid Build Coastguard Workerimport sys 24*35238bceSAndroid Build Coastguard Workerimport random 25*35238bceSAndroid Build Coastguard Workerimport operator 26*35238bceSAndroid Build Coastguard Workerimport itertools 27*35238bceSAndroid Build Coastguard Worker 28*35238bceSAndroid Build Coastguard Workerfrom genutil import * 29*35238bceSAndroid Build Coastguard Worker 30*35238bceSAndroid Build Coastguard Workerrandom.seed(1234567) 31*35238bceSAndroid Build Coastguard Workerindices = xrange(sys.maxint) 32*35238bceSAndroid Build Coastguard Worker 33*35238bceSAndroid Build Coastguard Worker# Constructors: 34*35238bceSAndroid Build Coastguard Worker# 35*35238bceSAndroid Build Coastguard Worker# - scalars types 36*35238bceSAndroid Build Coastguard Worker# * int <-> float <-> bool (also float(float) etc.) 37*35238bceSAndroid Build Coastguard Worker# * to bool: zero means false, others true 38*35238bceSAndroid Build Coastguard Worker# * from bool: false==0, true==1 39*35238bceSAndroid Build Coastguard Worker# * \todo [petri] float<->int rounding rules? 40*35238bceSAndroid Build Coastguard Worker# - scalar type from vector 41*35238bceSAndroid Build Coastguard Worker# * choose the first component 42*35238bceSAndroid Build Coastguard Worker# - vectors & matrices 43*35238bceSAndroid Build Coastguard Worker# * vector from scalar: broadcast to all components 44*35238bceSAndroid Build Coastguard Worker# * matrix from scalar: broadcast scalar to diagonal, other components zero 45*35238bceSAndroid Build Coastguard Worker# * vector from vector: copy existing components 46*35238bceSAndroid Build Coastguard Worker# + illegal: vector from smaller vector 47*35238bceSAndroid Build Coastguard Worker# * mat from mat: copy existing components, other components from identity matrix 48*35238bceSAndroid Build Coastguard Worker# * from components: consumed by-component in column-major order, must have same 49*35238bceSAndroid Build Coastguard Worker# number of components, 50*35238bceSAndroid Build Coastguard Worker# + note: vec4(mat2) valid 51*35238bceSAndroid Build Coastguard Worker# \todo [petri] Implement! 52*35238bceSAndroid Build Coastguard Worker# - notes: 53*35238bceSAndroid Build Coastguard Worker# * type conversions are always allowed: mat3(ivec3, bvec3, bool, int, float) is valid! 54*35238bceSAndroid Build Coastguard Worker# 55*35238bceSAndroid Build Coastguard Worker# Accessors: 56*35238bceSAndroid Build Coastguard Worker# 57*35238bceSAndroid Build Coastguard Worker# - vector components 58*35238bceSAndroid Build Coastguard Worker# * .xyzw, .rgba, .stpq 59*35238bceSAndroid Build Coastguard Worker# * illegal to mix 60*35238bceSAndroid Build Coastguard Worker# * now allowed for scalar types 61*35238bceSAndroid Build Coastguard Worker# * legal to chain: vec4.rgba.xyzw.stpq 62*35238bceSAndroid Build Coastguard Worker# * illegal to select more than 4 components 63*35238bceSAndroid Build Coastguard Worker# * array indexing with [] operator 64*35238bceSAndroid Build Coastguard Worker# * can also write! 65*35238bceSAndroid Build Coastguard Worker# - matrix columns 66*35238bceSAndroid Build Coastguard Worker# * [] accessor 67*35238bceSAndroid Build Coastguard Worker# * note: mat4[0].x = 1.0; vs mat4[0][0] = 1.0; ?? 68*35238bceSAndroid Build Coastguard Worker# * out-of-bounds accesses 69*35238bceSAndroid Build Coastguard Worker# 70*35238bceSAndroid Build Coastguard Worker# \todo [petri] Accessors! 71*35238bceSAndroid Build Coastguard Worker# 72*35238bceSAndroid Build Coastguard Worker# Spec issues: 73*35238bceSAndroid Build Coastguard Worker# 74*35238bceSAndroid Build Coastguard Worker# - constructing larger vector from smaller: vec3(vec2) ? 75*35238bceSAndroid Build Coastguard Worker# - base type and size conversion at same time: vec4(bool), int(vec3) allowed? 76*35238bceSAndroid Build Coastguard Worker 77*35238bceSAndroid Build Coastguard Workerdef combineVec(comps): 78*35238bceSAndroid Build Coastguard Worker res = [] 79*35238bceSAndroid Build Coastguard Worker for ndx in range(len(comps[0])): 80*35238bceSAndroid Build Coastguard Worker# for x in comps: 81*35238bceSAndroid Build Coastguard Worker# print x[ndx].toFloat().getScalars() , 82*35238bceSAndroid Build Coastguard Worker scalars = reduce(operator.add, [x[ndx].toFloat().getScalars() for x in comps]) 83*35238bceSAndroid Build Coastguard Worker# print "->", scalars 84*35238bceSAndroid Build Coastguard Worker res.append(Vec.fromScalarList(scalars)) 85*35238bceSAndroid Build Coastguard Worker return res 86*35238bceSAndroid Build Coastguard Worker 87*35238bceSAndroid Build Coastguard Workerdef combineIVec(comps): 88*35238bceSAndroid Build Coastguard Worker res = [] 89*35238bceSAndroid Build Coastguard Worker for ndx in range(len(comps[0])): 90*35238bceSAndroid Build Coastguard Worker res.append(Vec.fromScalarList(reduce(operator.add, [x[ndx].toInt().getScalars() for x in comps]))) 91*35238bceSAndroid Build Coastguard Worker return res 92*35238bceSAndroid Build Coastguard Worker 93*35238bceSAndroid Build Coastguard Workerdef combineUVec(comps): 94*35238bceSAndroid Build Coastguard Worker return [x.toUint() for x in combineIVec(comps)] 95*35238bceSAndroid Build Coastguard Worker 96*35238bceSAndroid Build Coastguard Workerdef combineBVec(comps): 97*35238bceSAndroid Build Coastguard Worker res = [] 98*35238bceSAndroid Build Coastguard Worker for ndx in range(len(comps[0])): 99*35238bceSAndroid Build Coastguard Worker res.append(Vec.fromScalarList(reduce(operator.add, [x[ndx].toBool().getScalars() for x in comps]))) 100*35238bceSAndroid Build Coastguard Worker return res 101*35238bceSAndroid Build Coastguard Worker 102*35238bceSAndroid Build Coastguard Workerdef combineMat(numCols, numRows, comps): 103*35238bceSAndroid Build Coastguard Worker res = [] 104*35238bceSAndroid Build Coastguard Worker for ndx in range(len(comps[0])): 105*35238bceSAndroid Build Coastguard Worker scalars = reduce(operator.add, [x[ndx].toFloat().getScalars() for x in comps]) 106*35238bceSAndroid Build Coastguard Worker res.append(Mat(numCols, numRows, scalars)) 107*35238bceSAndroid Build Coastguard Worker return res 108*35238bceSAndroid Build Coastguard Worker 109*35238bceSAndroid Build Coastguard Workerdef combineMat2(comps): return combineMat(2, 2, comps) 110*35238bceSAndroid Build Coastguard Workerdef combineMat2x3(comps): return combineMat(2, 3, comps) 111*35238bceSAndroid Build Coastguard Workerdef combineMat2x4(comps): return combineMat(2, 4, comps) 112*35238bceSAndroid Build Coastguard Workerdef combineMat3x2(comps): return combineMat(3, 2, comps) 113*35238bceSAndroid Build Coastguard Workerdef combineMat3(comps): return combineMat(3, 3, comps) 114*35238bceSAndroid Build Coastguard Workerdef combineMat3x4(comps): return combineMat(3, 4, comps) 115*35238bceSAndroid Build Coastguard Workerdef combineMat4x2(comps): return combineMat(4, 2, comps) 116*35238bceSAndroid Build Coastguard Workerdef combineMat4x3(comps): return combineMat(4, 3, comps) 117*35238bceSAndroid Build Coastguard Workerdef combineMat4(comps): return combineMat(4, 4, comps) 118*35238bceSAndroid Build Coastguard Worker 119*35238bceSAndroid Build Coastguard Worker# 0 \+ [f*f for f in lst] 120*35238bceSAndroid Build Coastguard Worker# r = 0 \+ [f in lst -> f*f] 121*35238bceSAndroid Build Coastguard Worker# r = 0 \+ lst 122*35238bceSAndroid Build Coastguard Worker 123*35238bceSAndroid Build Coastguard Worker# Templates. 124*35238bceSAndroid Build Coastguard Worker 125*35238bceSAndroid Build Coastguard Workers_simpleCaseTemplate = """ 126*35238bceSAndroid Build Coastguard Workercase ${{NAME}} 127*35238bceSAndroid Build Coastguard Worker version 300 es 128*35238bceSAndroid Build Coastguard Worker values 129*35238bceSAndroid Build Coastguard Worker { 130*35238bceSAndroid Build Coastguard Worker ${{VALUES}} 131*35238bceSAndroid Build Coastguard Worker } 132*35238bceSAndroid Build Coastguard Worker 133*35238bceSAndroid Build Coastguard Worker both "" 134*35238bceSAndroid Build Coastguard Worker #version 300 es 135*35238bceSAndroid Build Coastguard Worker precision mediump float; 136*35238bceSAndroid Build Coastguard Worker precision mediump int; 137*35238bceSAndroid Build Coastguard Worker 138*35238bceSAndroid Build Coastguard Worker ${DECLARATIONS} 139*35238bceSAndroid Build Coastguard Worker 140*35238bceSAndroid Build Coastguard Worker void main() 141*35238bceSAndroid Build Coastguard Worker { 142*35238bceSAndroid Build Coastguard Worker ${SETUP} 143*35238bceSAndroid Build Coastguard Worker ${{OP}} 144*35238bceSAndroid Build Coastguard Worker ${OUTPUT} 145*35238bceSAndroid Build Coastguard Worker } 146*35238bceSAndroid Build Coastguard Worker "" 147*35238bceSAndroid Build Coastguard Workerend 148*35238bceSAndroid Build Coastguard Worker"""[1:] 149*35238bceSAndroid Build Coastguard Worker 150*35238bceSAndroid Build Coastguard Workers_simpleIllegalCaseTemplate = """ 151*35238bceSAndroid Build Coastguard Workercase ${{NAME}} 152*35238bceSAndroid Build Coastguard Worker version 300 es 153*35238bceSAndroid Build Coastguard Worker expect compile_fail 154*35238bceSAndroid Build Coastguard Worker values {} 155*35238bceSAndroid Build Coastguard Worker 156*35238bceSAndroid Build Coastguard Worker both "" 157*35238bceSAndroid Build Coastguard Worker #version 300 es 158*35238bceSAndroid Build Coastguard Worker precision mediump float; 159*35238bceSAndroid Build Coastguard Worker precision mediump int; 160*35238bceSAndroid Build Coastguard Worker 161*35238bceSAndroid Build Coastguard Worker ${DECLARATIONS} 162*35238bceSAndroid Build Coastguard Worker 163*35238bceSAndroid Build Coastguard Worker void main() 164*35238bceSAndroid Build Coastguard Worker { 165*35238bceSAndroid Build Coastguard Worker ${SETUP} 166*35238bceSAndroid Build Coastguard Worker ${{OP}} 167*35238bceSAndroid Build Coastguard Worker ${OUTPUT} 168*35238bceSAndroid Build Coastguard Worker } 169*35238bceSAndroid Build Coastguard Worker "" 170*35238bceSAndroid Build Coastguard Workerend 171*35238bceSAndroid Build Coastguard Worker"""[1:] 172*35238bceSAndroid Build Coastguard Worker 173*35238bceSAndroid Build Coastguard Workerclass SimpleCase(ShaderCase): 174*35238bceSAndroid Build Coastguard Worker def __init__(self, name, inputs, outputs, op): 175*35238bceSAndroid Build Coastguard Worker self.name = name 176*35238bceSAndroid Build Coastguard Worker self.inputs = inputs 177*35238bceSAndroid Build Coastguard Worker self.outputs = outputs 178*35238bceSAndroid Build Coastguard Worker self.op = op 179*35238bceSAndroid Build Coastguard Worker 180*35238bceSAndroid Build Coastguard Worker def __str__(self): 181*35238bceSAndroid Build Coastguard Worker params = { 182*35238bceSAndroid Build Coastguard Worker "NAME": self.name, 183*35238bceSAndroid Build Coastguard Worker "VALUES": genValues(self.inputs, self.outputs), 184*35238bceSAndroid Build Coastguard Worker "OP": self.op 185*35238bceSAndroid Build Coastguard Worker } 186*35238bceSAndroid Build Coastguard Worker return fillTemplate(s_simpleCaseTemplate, params) 187*35238bceSAndroid Build Coastguard Worker 188*35238bceSAndroid Build Coastguard Workerclass ConversionCase(ShaderCase): 189*35238bceSAndroid Build Coastguard Worker def __init__(self, inValues, convFunc): 190*35238bceSAndroid Build Coastguard Worker outValues = convFunc(inValues) 191*35238bceSAndroid Build Coastguard Worker inType = inValues[0].typeString() 192*35238bceSAndroid Build Coastguard Worker outType = outValues[0].typeString() 193*35238bceSAndroid Build Coastguard Worker self.name = "%s_to_%s" % (inType, outType) 194*35238bceSAndroid Build Coastguard Worker self.op = "out0 = %s(in0);" % outType 195*35238bceSAndroid Build Coastguard Worker self.inputs = [("%s in0" % inType, inValues)] 196*35238bceSAndroid Build Coastguard Worker self.outputs = [("%s out0" % outType, outValues)] 197*35238bceSAndroid Build Coastguard Worker 198*35238bceSAndroid Build Coastguard Worker def __str__(self): 199*35238bceSAndroid Build Coastguard Worker params = { 200*35238bceSAndroid Build Coastguard Worker "NAME": self.name, 201*35238bceSAndroid Build Coastguard Worker "VALUES": genValues(self.inputs, self.outputs), 202*35238bceSAndroid Build Coastguard Worker "OP": self.op 203*35238bceSAndroid Build Coastguard Worker } 204*35238bceSAndroid Build Coastguard Worker return fillTemplate(s_simpleCaseTemplate, params) 205*35238bceSAndroid Build Coastguard Worker 206*35238bceSAndroid Build Coastguard Workerclass IllegalConversionCase(ShaderCase): 207*35238bceSAndroid Build Coastguard Worker def __init__(self, inValue, outValue): 208*35238bceSAndroid Build Coastguard Worker inType = inValue.typeString() 209*35238bceSAndroid Build Coastguard Worker outType = outValue.typeString() 210*35238bceSAndroid Build Coastguard Worker self.name = "%s_to_%s" % (inType, outType) 211*35238bceSAndroid Build Coastguard Worker self.op = "%s in0 = %s;\n%s out0 = %s(in0);" % (inType, str(inValue), outType, outType) 212*35238bceSAndroid Build Coastguard Worker self.inType = inType 213*35238bceSAndroid Build Coastguard Worker self.outType = outType 214*35238bceSAndroid Build Coastguard Worker 215*35238bceSAndroid Build Coastguard Worker def __str__(self): 216*35238bceSAndroid Build Coastguard Worker params = { 217*35238bceSAndroid Build Coastguard Worker "NAME": self.name, 218*35238bceSAndroid Build Coastguard Worker "OP": self.op 219*35238bceSAndroid Build Coastguard Worker } 220*35238bceSAndroid Build Coastguard Worker return fillTemplate(s_simpleIllegalCaseTemplate, params) 221*35238bceSAndroid Build Coastguard Worker 222*35238bceSAndroid Build Coastguard Workerclass CombineCase(ShaderCase): 223*35238bceSAndroid Build Coastguard Worker def __init__(self, inComps, combFunc): 224*35238bceSAndroid Build Coastguard Worker self.inComps = inComps 225*35238bceSAndroid Build Coastguard Worker self.outValues = combFunc(inComps) 226*35238bceSAndroid Build Coastguard Worker self.outType = self.outValues[0].typeString() 227*35238bceSAndroid Build Coastguard Worker inTypes = [values[0].typeString() for values in inComps] 228*35238bceSAndroid Build Coastguard Worker self.name = "%s_to_%s" % ("_".join(inTypes), self.outType) 229*35238bceSAndroid Build Coastguard Worker self.inputs = [("%s in%s" % (comp[0].typeString(), ndx), comp) for (comp, ndx) in zip(inComps, indices)] 230*35238bceSAndroid Build Coastguard Worker self.outputs = [("%s out0" % self.outType, self.outValues)] 231*35238bceSAndroid Build Coastguard Worker self.op = "out0 = %s(%s);" % (self.outType, ", ".join(["in%d" % x for x in range(len(inComps))])) 232*35238bceSAndroid Build Coastguard Worker 233*35238bceSAndroid Build Coastguard Worker def __str__(self): 234*35238bceSAndroid Build Coastguard Worker params = { 235*35238bceSAndroid Build Coastguard Worker "NAME": self.name, 236*35238bceSAndroid Build Coastguard Worker "VALUES": genValues(self.inputs, self.outputs), 237*35238bceSAndroid Build Coastguard Worker "OP": self.op 238*35238bceSAndroid Build Coastguard Worker } 239*35238bceSAndroid Build Coastguard Worker return fillTemplate(s_simpleCaseTemplate, params) 240*35238bceSAndroid Build Coastguard Worker 241*35238bceSAndroid Build Coastguard Worker# CASE DECLARATIONS 242*35238bceSAndroid Build Coastguard Worker 243*35238bceSAndroid Build Coastguard Workerdef toPos (value): 244*35238bceSAndroid Build Coastguard Worker if isinstance(value, list): 245*35238bceSAndroid Build Coastguard Worker return [toPos(x) for x in value] 246*35238bceSAndroid Build Coastguard Worker else: 247*35238bceSAndroid Build Coastguard Worker return GenMath.abs(value) 248*35238bceSAndroid Build Coastguard Worker 249*35238bceSAndroid Build Coastguard WorkerinFloat = [Scalar(x) for x in [0.0, 1.0, 2.0, 3.5, -0.5, -8.25, -20.125, 36.8125]] 250*35238bceSAndroid Build Coastguard WorkerinInt = [Scalar(x) for x in [0, 1, 2, 5, 8, 11, -12, -66, -192, 255]] 251*35238bceSAndroid Build Coastguard WorkerinUint = [Uint(x) for x in [0, 2, 3, 8, 9, 12, 10, 45, 193, 255]] 252*35238bceSAndroid Build Coastguard WorkerinBool = [Scalar(x) for x in [True, False]] 253*35238bceSAndroid Build Coastguard Worker 254*35238bceSAndroid Build Coastguard WorkerinVec4 = [Vec4(0.0, 0.5, 0.75, 0.825), Vec4(1.0, 1.25, 1.125, 1.75), 255*35238bceSAndroid Build Coastguard Worker Vec4(-0.5, -2.25, -4.875, 9.0), Vec4(-32.0, 64.0, -51.0, 24.0), 256*35238bceSAndroid Build Coastguard Worker Vec4(-0.75, -1.0/31.0, 1.0/19.0, 1.0/4.0)] 257*35238bceSAndroid Build Coastguard WorkerinVec3 = toVec3(inVec4) 258*35238bceSAndroid Build Coastguard WorkerinVec2 = toVec2(inVec4) 259*35238bceSAndroid Build Coastguard WorkerinIVec4 = toIVec4(inVec4) 260*35238bceSAndroid Build Coastguard WorkerinIVec3 = toIVec3(inVec4) 261*35238bceSAndroid Build Coastguard WorkerinIVec2 = toIVec2(inVec4) 262*35238bceSAndroid Build Coastguard WorkerinBVec4 = [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)] 263*35238bceSAndroid Build Coastguard WorkerinBVec3 = toBVec3(inBVec4) 264*35238bceSAndroid Build Coastguard WorkerinBVec2 = toBVec2(inBVec4) 265*35238bceSAndroid Build Coastguard WorkerinUVec4 = toUVec4(toPos(inVec4)) 266*35238bceSAndroid Build Coastguard WorkerinUVec3 = toUVec3(toPos(inVec3)) 267*35238bceSAndroid Build Coastguard WorkerinUVec2 = toUVec2(toPos(inVec2)) 268*35238bceSAndroid Build Coastguard Worker 269*35238bceSAndroid Build Coastguard Worker# \todo [petri] Enable large values when epsilon adapts to the values. 270*35238bceSAndroid Build Coastguard WorkerinMat4 = [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), 271*35238bceSAndroid Build Coastguard Worker 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), 272*35238bceSAndroid Build Coastguard Worker #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) 273*35238bceSAndroid Build Coastguard Worker ] 274*35238bceSAndroid Build Coastguard WorkerinMat2 = [Mat2(1.0, 0.0, 0.0, 1.0), 275*35238bceSAndroid Build Coastguard Worker Mat2(6.5, 12.5, -0.75, 9.975), 276*35238bceSAndroid Build Coastguard Worker Mat2(6.5, 12.5, -0.75, 9.975), 277*35238bceSAndroid Build Coastguard Worker Mat2(8.0, 16.0, -24.0, -16.0), 278*35238bceSAndroid Build Coastguard Worker Mat2(1.0/8.0, 1.0/16.0, 1.0/32.0, 1.0/64.0), 279*35238bceSAndroid Build Coastguard Worker Mat2(-18.725, -0.5, -0.0125, 19.975), 280*35238bceSAndroid Build Coastguard Worker #Mat2(128.0, -4096.0, 192.0, -1536.0), 281*35238bceSAndroid Build Coastguard Worker #Mat2(-1536.0, 8192.0, 6144.0, -6144.0) 282*35238bceSAndroid Build Coastguard Worker ] 283*35238bceSAndroid Build Coastguard Worker 284*35238bceSAndroid Build Coastguard WorkerinMat4x3 = toMat4x3(inMat4) 285*35238bceSAndroid Build Coastguard WorkerinMat4x2 = toMat4x2(inMat4) 286*35238bceSAndroid Build Coastguard WorkerinMat3x4 = toMat3x4(inMat4) 287*35238bceSAndroid Build Coastguard WorkerinMat3 = toMat3(inMat4) 288*35238bceSAndroid Build Coastguard WorkerinMat3x2 = toMat3x2(inMat4) 289*35238bceSAndroid Build Coastguard WorkerinMat2x4 = toMat2x4(inMat4) 290*35238bceSAndroid Build Coastguard WorkerinMat2x3 = toMat2x3(inMat4) 291*35238bceSAndroid Build Coastguard Worker 292*35238bceSAndroid Build Coastguard Workerdef genConversionCases(inValueList, convFuncList): 293*35238bceSAndroid Build Coastguard Worker combinations = list(itertools.product(inValueList, convFuncList)) 294*35238bceSAndroid Build Coastguard Worker return [ConversionCase(inValues, convFunc) for (inValues, convFunc) in combinations] 295*35238bceSAndroid Build Coastguard Worker 296*35238bceSAndroid Build Coastguard Workerdef genIllegalConversionCases(inValueList, outValueList): 297*35238bceSAndroid Build Coastguard Worker inValues = [x[0] for x in inValueList] 298*35238bceSAndroid Build Coastguard Worker outValues = [x[0] for x in outValueList] 299*35238bceSAndroid Build Coastguard Worker combinations = list(itertools.product(inValues, outValues)) 300*35238bceSAndroid Build Coastguard Worker return [IllegalConversionCase(inVal, outVal) for (inVal, outVal) in combinations] 301*35238bceSAndroid Build Coastguard Worker 302*35238bceSAndroid Build Coastguard Workerdef shuffleSubLists(outer): 303*35238bceSAndroid Build Coastguard Worker return [shuffled(inner) for inner in outer] 304*35238bceSAndroid Build Coastguard Worker 305*35238bceSAndroid Build Coastguard Worker# Generate all combinations of CombineCases. 306*35238bceSAndroid Build Coastguard Worker# inTupleList a list of tuples of value-lists 307*35238bceSAndroid Build Coastguard Worker# combFuncList a list of comb* functions to combine 308*35238bceSAndroid Build Coastguard Workerdef genComponentCases(inCompLists, combFuncList): 309*35238bceSAndroid Build Coastguard Worker res = [] 310*35238bceSAndroid Build Coastguard Worker for comps in inCompLists: 311*35238bceSAndroid Build Coastguard Worker maxLen = reduce(max, [len(values) for values in comps]) 312*35238bceSAndroid Build Coastguard Worker comps = [repeatToLength(values, maxLen) for values in comps] 313*35238bceSAndroid Build Coastguard Worker comps = [shuffled(values) for values in comps] 314*35238bceSAndroid Build Coastguard Worker for combFunc in combFuncList: 315*35238bceSAndroid Build Coastguard Worker res += [CombineCase(comps, combFunc)] 316*35238bceSAndroid Build Coastguard Worker return res 317*35238bceSAndroid Build Coastguard Worker 318*35238bceSAndroid Build Coastguard WorkerallConversionCases = [] 319*35238bceSAndroid Build Coastguard Worker 320*35238bceSAndroid Build Coastguard Worker# Scalar-to-scalar conversions. 321*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("scalar_to_scalar", "Scalar to Scalar Conversions", 322*35238bceSAndroid Build Coastguard Worker genConversionCases([inFloat, inInt, inUint, inBool], [toFloat, toInt, toBool]) +\ 323*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inFloat), toPos(inInt), inUint, inBool], [toUint]))) 324*35238bceSAndroid Build Coastguard Worker 325*35238bceSAndroid Build Coastguard Worker# Scalar-to-vector conversions. 326*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("scalar_to_vector", "Scalar to Vector Conversions", 327*35238bceSAndroid Build Coastguard Worker genConversionCases([inFloat, inInt, inUint, inBool], [toVec2, toVec3, toVec4, toIVec2, toIVec3, toIVec4, toBVec2, toBVec3, toBVec4]) +\ 328*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inFloat), toPos(inInt), inUint, inBool], [toUVec2, toUVec3, toUVec4]))) 329*35238bceSAndroid Build Coastguard Worker 330*35238bceSAndroid Build Coastguard Worker# Vector-to-scalar conversions. 331*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("vector_to_scalar", "Vector to Scalar Conversions", 332*35238bceSAndroid Build Coastguard Worker genConversionCases([inVec2, inVec3, inVec4, inIVec2, inIVec3, inIVec4, inUVec2, inUVec3, inUVec4, inBVec2, inBVec3, inBVec4], [toFloat, toInt, toBool]) +\ 333*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inVec2), toPos(inVec3), toPos(inVec4), toPos(inIVec2), toPos(inIVec3), toPos(inIVec4), inUVec2, inUVec3, inUVec4, inBVec2, inBVec3, inBVec4], [toUint]))) 334*35238bceSAndroid Build Coastguard Worker 335*35238bceSAndroid Build Coastguard Worker# Illegal vector-to-vector conversions (to longer vec). 336*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("vector_illegal", "Illegal Vector Conversions", 337*35238bceSAndroid Build Coastguard Worker genIllegalConversionCases([inVec2, inIVec2, inUVec2, inBVec2], [inVec3, inIVec3, inUVec3, inBVec3, inVec4, inIVec4, inUVec4, inBVec4]) +\ 338*35238bceSAndroid Build Coastguard Worker genIllegalConversionCases([inVec3, inIVec3, inUVec3, inBVec3], [inVec4, inIVec4, inUVec4, inBVec4]))) 339*35238bceSAndroid Build Coastguard Worker 340*35238bceSAndroid Build Coastguard Worker# Vector-to-vector conversions (type conversions, downcasts). 341*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("vector_to_vector", "Vector to Vector Conversions", 342*35238bceSAndroid Build Coastguard Worker genConversionCases([inVec4, inIVec4, inUVec4, inBVec4], [toVec4, toVec3, toVec2, toIVec4, toIVec3, toIVec2, toBVec4, toBVec3, toBVec2]) +\ 343*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inVec4), toPos(inIVec4), inUVec4, inBVec4], [toUVec4, toUVec3, toUVec2]) +\ 344*35238bceSAndroid Build Coastguard Worker genConversionCases([inVec3, inIVec3, inUVec3, inBVec3], [toVec3, toVec2, toIVec3, toIVec2, toBVec3, toBVec2]) +\ 345*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inVec3), toPos(inIVec3), inUVec3, inBVec3], [toUVec3, toUVec2]) +\ 346*35238bceSAndroid Build Coastguard Worker genConversionCases([inVec2, inIVec2, inUVec2, inBVec2], [toVec2, toIVec2, toBVec2]) +\ 347*35238bceSAndroid Build Coastguard Worker genConversionCases([toPos(inVec2), toPos(inIVec2), inUVec2, inBVec2], [toUVec2]))) 348*35238bceSAndroid Build Coastguard Worker 349*35238bceSAndroid Build Coastguard Worker# Scalar-to-matrix. 350*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("scalar_to_matrix", "Scalar to Matrix Conversions", 351*35238bceSAndroid Build Coastguard Worker genConversionCases([inFloat, inInt, inUint, inBool], [toMat4, toMat4x3, toMat4x2, toMat3x4, toMat3, toMat3x2, toMat2x4, toMat2x3, toMat2]))) 352*35238bceSAndroid Build Coastguard Worker 353*35238bceSAndroid Build Coastguard Worker# Vector-to-matrix. 354*35238bceSAndroid Build Coastguard Worker#allConversionCases += genConversionCases([inVec4, inIVec4, inBVec4], [toMat4]) 355*35238bceSAndroid Build Coastguard Worker#allConversionCases += genConversionCases([inVec3, inIVec3, inBVec3], [toMat3]) 356*35238bceSAndroid Build Coastguard Worker#allConversionCases += genConversionCases([inVec2, inIVec2, inBVec2], [toMat2]) 357*35238bceSAndroid Build Coastguard Worker 358*35238bceSAndroid Build Coastguard Worker# Matrix-to-matrix. 359*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("matrix_to_matrix", "Matrix to Matrix Conversions", 360*35238bceSAndroid Build Coastguard Worker genConversionCases([inMat4, inMat4x3, inMat4x2, inMat3x4, inMat3, inMat3x2, inMat2x4, inMat2x3, inMat2], [toMat4, toMat4x3, toMat4x2, toMat3x4, toMat3, toMat3x2, toMat2x4, toMat2x3, toMat2]))) 361*35238bceSAndroid Build Coastguard Worker 362*35238bceSAndroid Build Coastguard Worker# Vector-from-components, matrix-from-components. 363*35238bceSAndroid Build Coastguard Workerin2Comp = [[inFloat, inFloat], [inInt, inInt], [inUint, inUint], [inBool, inBool], [inFloat, inInt], [inFloat, inBool], [inInt, inBool], [inInt, inUint], [inUint, inFloat]] 364*35238bceSAndroid Build Coastguard Workerin3Comp = [[inFloat, inFloat, inFloat], [inInt, inInt, inInt], [inUint, inUint, inUint], [inBool, inBool, inBool], [inBool, inFloat, inInt], [inVec2, inBool], [inBVec2, inFloat], [inBVec2, inInt], [inBool, inIVec2], [inFloat, inUVec2]] 365*35238bceSAndroid Build Coastguard Workerin4Comp = [[inVec2, inVec2], [inBVec2, inBVec2], [inFloat, inFloat, inFloat, inFloat], [inInt, inInt, inInt, inInt], [inUint, inUint, inUint, inUint], [inBool, inBool, inBool, inBool], [inBool, inFloat, inInt, inBool], [inVec2, inIVec2], [inVec2, inBVec2], [inBVec3, inFloat], [inVec3, inFloat], [inInt, inIVec2, inInt], [inBool, inFloat, inIVec2], [inFloat, inUVec3], [inInt, inUVec2, inBool]] 366*35238bceSAndroid Build Coastguard Workerin6Comp = [[inVec3, inVec3], [inBVec3, inBVec3], [inFloat, inFloat, inFloat, inFloat, inFloat, inFloat], [inInt, inInt, inInt, inInt, inInt, inInt], [inBool, inBool, inBool, inBool, inBool, inBool], [inBool, inFloat, inInt, inBool, inFloat, inInt], [inVec3, inIVec3], [inVec2, inBVec4], [inBVec3, inFloat, inIVec2], [inVec3, inFloat, inBVec2]] 367*35238bceSAndroid Build Coastguard Workerin8Comp = [[inVec3, inVec3, inVec2], [inIVec3, inIVec3, inIVec2], [inVec2, inIVec2, inFloat, inFloat, inInt, inBool], [inBool, inFloat, inInt, inVec2, inBool, inBVec2], [inBool, inBVec2, inInt, inVec4], [inFloat, inBVec4, inIVec2, inBool]] 368*35238bceSAndroid Build Coastguard Workerin9Comp = [[inVec3, inVec3, inVec3], [inIVec3, inIVec3, inIVec3], [inVec2, inIVec2, inFloat, inFloat, inInt, inBool, inBool], [inBool, inFloat, inInt, inVec2, inBool, inBVec2, inFloat], [inBool, inBVec2, inInt, inVec4, inBool], [inFloat, inBVec4, inIVec2, inBool, inBool]] 369*35238bceSAndroid Build Coastguard Workerin12Comp = [[inVec4, inVec4, inVec4], [inIVec4, inIVec4, inIVec4], [inVec2, inIVec2, inFloat, inFloat, inFloat, inInt, inInt, inBool, inBool, inBool], [inBool, inFloat, inInt, inVec3, inBool, inBVec3, inFloat, inBool], [inBool, inBVec4, inInt, inVec4, inBool, inFloat], [inFloat, inBVec4, inIVec4, inBool, inBool, inInt]] 370*35238bceSAndroid Build Coastguard Workerin16Comp = [[inVec4, inVec4, inVec4, inVec4], [inIVec4, inIVec4, inIVec4, inIVec4], [inBVec4, inBVec4, inBVec4, inBVec4], [inFloat, inIVec3, inBVec3, inVec4, inIVec2, inFloat, inVec2]] 371*35238bceSAndroid Build Coastguard Worker 372*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("vector_combine", "Vector Combine Constructors", 373*35238bceSAndroid Build Coastguard Worker genComponentCases(in4Comp, [combineVec, combineIVec, combineBVec]) +\ 374*35238bceSAndroid Build Coastguard Worker genComponentCases(toPos(in4Comp), [combineUVec]) +\ 375*35238bceSAndroid Build Coastguard Worker genComponentCases(in3Comp, [combineVec, combineIVec, combineBVec]) +\ 376*35238bceSAndroid Build Coastguard Worker genComponentCases(toPos(in3Comp), [combineUVec]) +\ 377*35238bceSAndroid Build Coastguard Worker genComponentCases(in2Comp, [combineVec, combineIVec, combineBVec]) +\ 378*35238bceSAndroid Build Coastguard Worker genComponentCases(toPos(in2Comp), [combineUVec]))) 379*35238bceSAndroid Build Coastguard Worker 380*35238bceSAndroid Build Coastguard WorkerallConversionCases.append(CaseGroup("matrix_combine", "Matrix Combine Constructors", 381*35238bceSAndroid Build Coastguard Worker genComponentCases(in4Comp, [combineMat2]) +\ 382*35238bceSAndroid Build Coastguard Worker genComponentCases(in6Comp, [combineMat2x3]) +\ 383*35238bceSAndroid Build Coastguard Worker genComponentCases(in8Comp, [combineMat2x4]) +\ 384*35238bceSAndroid Build Coastguard Worker genComponentCases(in6Comp, [combineMat3x2]) +\ 385*35238bceSAndroid Build Coastguard Worker genComponentCases(in9Comp, [combineMat3]) +\ 386*35238bceSAndroid Build Coastguard Worker genComponentCases(in12Comp, [combineMat3x4]) +\ 387*35238bceSAndroid Build Coastguard Worker genComponentCases(in8Comp, [combineMat4x2]) +\ 388*35238bceSAndroid Build Coastguard Worker genComponentCases(in12Comp, [combineMat4x3]) +\ 389*35238bceSAndroid Build Coastguard Worker genComponentCases(in16Comp, [combineMat4]) 390*35238bceSAndroid Build Coastguard Worker )) 391*35238bceSAndroid Build Coastguard Worker 392*35238bceSAndroid Build Coastguard Worker# Main program. 393*35238bceSAndroid Build Coastguard Worker 394*35238bceSAndroid Build Coastguard Workerif __name__ == "__main__": 395*35238bceSAndroid Build Coastguard Worker print("Generating shader case files.") 396*35238bceSAndroid Build Coastguard Worker writeAllCases("conversions.test", allConversionCases) 397