• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright (c) 2016 The Khronos Group Inc.
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 sys
24import string
25from genutil import *
26
27# Templates
28
29INVALID_IMPLICIT_CONVESION_TEMPLATE0 = """
30case ${{NAME}}
31	expect compile_fail
32	version 300 es
33
34	both ""
35		#version 300 es
36		precision mediump float;
37		precision mediump int;
38
39		${DECLARATIONS}
40
41		void main()
42		{
43			${{TYPE0}} c;
44			${{TYPE0}} a;
45			${{TYPE1}} b;
46			${{TYPE0}} c = a ${{OPERATION}} b;
47		}
48	""
49end
50"""[1:-1]
51
52INVALID_IMPLICIT_CONVESION_TEMPLATE1 = """
53case ${{NAME}}
54	expect compile_fail
55	version 300 es
56
57	both ""
58		#version 300 es
59		precision mediump float;
60		precision mediump int;
61
62		 ${DECLARATIONS}
63
64		void main()
65		{
66			${{TYPE1}} c;
67			${{TYPE0}} a;
68			${{TYPE1}} b;
69			${{TYPE1}} c = a ${{OPERATION}} b;
70		}
71	""
72end
73"""[1:-1]
74
75arithOperations = {'+': 'add', '*':'mul', '/': 'div', '-':'sub'}
76
77class InvalidImplicitConversionCase(ShaderCase):
78	def __init__(self, operation, type0, type1):
79		self.name		= arithOperations[operation] + '_' + type0 + '_' + type1
80		self.operation	= operation
81		self.type0		= type0
82		self.type1		= type1
83
84	def __str__(self):
85
86		params0 = { "NAME": self.name + '_' + self.type0, "TYPE0": self.type0, "TYPE1": self.type1, "OPERATION": self.operation }
87		params1 = { "NAME": self.name + '_' + self.type1, "TYPE0": self.type0, "TYPE1": self.type1, "OPERATION": self.operation }
88		return fillTemplate(INVALID_IMPLICIT_CONVESION_TEMPLATE0, params0) + '\n' + fillTemplate(INVALID_IMPLICIT_CONVESION_TEMPLATE1, params1)
89
90def createCase(operation, type0, type1):
91	cases = []
92	for t0 in type0:
93		for t1 in type1:
94			case = InvalidImplicitConversionCase(operation, t0, t1)
95			cases.append(case)
96	return cases
97
98floats		= ['float', 'vec2', 'vec3', 'vec4']
99sintegers	= ['int', 'ivec2', 'ivec3', 'ivec4']
100uintegers	= ['uint', 'uvec2', 'uvec3', 'uvec4']
101cases		= []
102for op in arithOperations:
103	caseFpInt = createCase(op, floats, sintegers)
104	cases = cases + caseFpInt
105	caseFpUint = createCase(op, floats, uintegers)
106	cases = cases + caseFpUint
107	caseIntUint = createCase(op, sintegers, uintegers)
108	cases = cases + caseIntUint
109
110invalidImplicitConversionCases = [
111		CaseGroup("invalid_implicit_conversions", "Invalid Implicit Conversions", cases),
112]
113
114if __name__ == "__main__":
115	print("Generating shader case files.")
116	writeAllCases("invalid_implicit_conversions.test", invalidImplicitConversionCases)
117