1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2017 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 #-------------------------------------------------------------------------
28 DATA_TYPES = ["float", "vec4"]
29 ARRAY_SIZES = [16, 32, 64, 128]
31 s_largeArrayCaseTemplate = """
41 precision mediump float;
58 class LargeConstantArrayCase(ShaderCase):
59 def __init__(self, name, array, inputs, outputs):
63 self.outputs = outputs
64 self.op = "out0 = array[in0];"
69 "VALUES": genValues(self.inputs, self.outputs),
70 "ARRAY_DECL": self.array,
73 return fillTemplate(s_largeArrayCaseTemplate, params)
76 def genArray(dataType, size):
78 for i in xrange(size):
79 if dataType == "float":
80 elements.append(Scalar(round(random.uniform(-1.0, 1.0), 6)))
81 if dataType == "vec4":
82 elements.append(Vec4(*[round(random.uniform(-1.0, 1.0), 6) for x in range(4)]))
87 def arrayToString(elements):
88 array = ('const {TYPE} array[{LENGTH}] = {TYPE}[](\n'
89 .format(TYPE=elements[0].typeString(), LENGTH=len(elements)))
91 array += "\n".join(str(e) + ',' for e in elements[:-1])
92 array += "\n" + str(elements[-1])
98 largeConstantArrayCases = []
100 for dataType in DATA_TYPES:
101 for arraySize in ARRAY_SIZES:
102 indexes = random.sample(range(arraySize-1), 10)
103 array = genArray(dataType, arraySize)
104 outputs = [array[index] for index in indexes]
105 outType = outputs[0].typeString()
106 caseName = "%s_%s" % (dataType, arraySize)
108 case = LargeConstantArrayCase(caseName,
109 arrayToString(array),
110 [("int in0", indexes)],
111 [("%s out0" % outType, outputs)])
113 largeConstantArrayCases.append(case)
115 allCases.append(CaseGroup("indexing", "Large constant array indexing", largeConstantArrayCases))
117 if __name__ == "__main__":
118 print "Generating shader case files."
119 writeAllCases("large_constant_arrays.test", allCases)