• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2017 The Android Open Source Project
8#
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
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
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.
20#
21#-------------------------------------------------------------------------
22
23import random
24from genutil import *
25
26random.seed(0x1234)
27
28DATA_TYPES	= ["float", "vec4"]
29ARRAY_SIZES	= [16, 32, 64, 128]
30
31s_largeArrayCaseTemplate = """
32case ${{NAME}}
33	version 300 es
34	values
35	{
36		${{VALUES}}
37	}
38
39	both ""
40		#version 300 es
41		precision mediump float;
42
43		${DECLARATIONS}
44
45		void main()
46		{
47			${{ARRAY_DECL}}
48
49			${SETUP}
50			${{OP}}
51			${OUTPUT}
52		}
53	""
54end
55"""[1:]
56
57
58class LargeConstantArrayCase(ShaderCase):
59	def __init__(self, name, array, inputs, outputs):
60		self.name	= name
61		self.array	= array
62		self.inputs	= inputs
63		self.outputs	= outputs
64		self.op		= "out0 = array[in0];"
65
66	def __str__(self):
67		params = {
68			"NAME":		self.name,
69			"VALUES":	genValues(self.inputs, self.outputs),
70			"ARRAY_DECL":	self.array,
71			"OP":		self.op
72		}
73		return fillTemplate(s_largeArrayCaseTemplate, params)
74
75
76def genArray(dataType, size):
77	elements = []
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)]))
83
84	return elements
85
86
87def arrayToString(elements):
88	array = ('const {TYPE} array[{LENGTH}] = {TYPE}[](\n'
89		.format(TYPE=elements[0].typeString(), LENGTH=len(elements)))
90
91	array += "\n".join(str(e) + ',' for e in elements[:-1])
92	array += "\n" + str(elements[-1])
93	array += ");"
94
95	return array
96
97allCases = []
98largeConstantArrayCases = []
99
100for 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)
107
108		case = LargeConstantArrayCase(caseName,
109					      arrayToString(array),
110					      [("int in0", indexes)],
111					      [("%s out0" % outType, outputs)])
112
113		largeConstantArrayCases.append(case)
114
115allCases.append(CaseGroup("indexing", "Large constant array indexing", largeConstantArrayCases))
116
117if __name__ == "__main__":
118	print("Generating shader case files.")
119	writeAllCases("large_constant_arrays.test", allCases)
120