blob: 180ca146abc8a1e352a53c69d686f5febd244e0a [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
John Baumand4ae8632014-05-06 16:18:33 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7//
8// Create strings that declare built-in definitions, add built-ins that
9// cannot be expressed in the files, and establish mappings between
10// built-in functions and operators.
11//
12
13#include "compiler/Initialize.h"
14
15#include "compiler/intermediate.h"
16
John Baumand4ae8632014-05-06 16:18:33 -040017void InsertBuiltInFunctions(ShShaderType type, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -040018{
John Baumand4ae8632014-05-06 16:18:33 -040019 TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1);
20 TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2);
21 TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3);
22 TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -040023
John Baumand4ae8632014-05-06 16:18:33 -040024 TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2);
25 TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3);
26 TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -040027
John Baumand4ae8632014-05-06 16:18:33 -040028 symbolTable.insertBuiltIn(float1, "radians", float1, "degrees");
29 symbolTable.insertBuiltIn(float2, "radians", float2, "degrees");
30 symbolTable.insertBuiltIn(float3, "radians", float3, "degrees");
31 symbolTable.insertBuiltIn(float4, "radians", float4, "degrees");
32 symbolTable.insertBuiltIn(float1, "degrees", float1, "radians");
33 symbolTable.insertBuiltIn(float2, "degrees", float2, "radians");
34 symbolTable.insertBuiltIn(float3, "degrees", float3, "radians");
35 symbolTable.insertBuiltIn(float4, "degrees", float4, "radians");
36 symbolTable.insertBuiltIn(float1, "sin", float1, "angle");
37 symbolTable.insertBuiltIn(float2, "sin", float2, "angle");
38 symbolTable.insertBuiltIn(float3, "sin", float3, "angle");
39 symbolTable.insertBuiltIn(float4, "sin", float4, "angle");
40 symbolTable.insertBuiltIn(float1, "cos", float1, "angle");
41 symbolTable.insertBuiltIn(float2, "cos", float2, "angle");
42 symbolTable.insertBuiltIn(float3, "cos", float3, "angle");
43 symbolTable.insertBuiltIn(float4, "cos", float4, "angle");
44 symbolTable.insertBuiltIn(float1, "tan", float1, "angle");
45 symbolTable.insertBuiltIn(float2, "tan", float2, "angle");
46 symbolTable.insertBuiltIn(float3, "tan", float3, "angle");
47 symbolTable.insertBuiltIn(float4, "tan", float4, "angle");
48 symbolTable.insertBuiltIn(float1, "asin", float1, "x");
49 symbolTable.insertBuiltIn(float2, "asin", float2, "x");
50 symbolTable.insertBuiltIn(float3, "asin", float3, "x");
51 symbolTable.insertBuiltIn(float4, "asin", float4, "x");
52 symbolTable.insertBuiltIn(float1, "acos", float1, "x");
53 symbolTable.insertBuiltIn(float2, "acos", float2, "x");
54 symbolTable.insertBuiltIn(float3, "acos", float3, "x");
55 symbolTable.insertBuiltIn(float4, "acos", float4, "x");
56 symbolTable.insertBuiltIn(float1, "atan", float1, "y", float1, "x");
57 symbolTable.insertBuiltIn(float2, "atan", float2, "y", float2, "x");
58 symbolTable.insertBuiltIn(float3, "atan", float3, "y", float3, "x");
59 symbolTable.insertBuiltIn(float4, "atan", float4, "y", float4, "x");
60 symbolTable.insertBuiltIn(float1, "atan", float1, "y_over_x");
61 symbolTable.insertBuiltIn(float2, "atan", float2, "y_over_x");
62 symbolTable.insertBuiltIn(float3, "atan", float3, "y_over_x");
63 symbolTable.insertBuiltIn(float4, "atan", float4, "y_over_x");
64 symbolTable.insertBuiltIn(float1, "pow", float1, "x", float1, "y");
65 symbolTable.insertBuiltIn(float2, "pow", float2, "x", float2, "y");
66 symbolTable.insertBuiltIn(float3, "pow", float3, "x", float3, "y");
67 symbolTable.insertBuiltIn(float4, "pow", float4, "x", float4, "y");
68 symbolTable.insertBuiltIn(float1, "exp", float1, "x");
69 symbolTable.insertBuiltIn(float2, "exp", float2, "x");
70 symbolTable.insertBuiltIn(float3, "exp", float3, "x");
71 symbolTable.insertBuiltIn(float4, "exp", float4, "x");
72 symbolTable.insertBuiltIn(float1, "log", float1, "x");
73 symbolTable.insertBuiltIn(float2, "log", float2, "x");
74 symbolTable.insertBuiltIn(float3, "log", float3, "x");
75 symbolTable.insertBuiltIn(float4, "log", float4, "x");
76 symbolTable.insertBuiltIn(float1, "exp2", float1, "x");
77 symbolTable.insertBuiltIn(float2, "exp2", float2, "x");
78 symbolTable.insertBuiltIn(float3, "exp2", float3, "x");
79 symbolTable.insertBuiltIn(float4, "exp2", float4, "x");
80 symbolTable.insertBuiltIn(float1, "log2", float1, "x");
81 symbolTable.insertBuiltIn(float2, "log2", float2, "x");
82 symbolTable.insertBuiltIn(float3, "log2", float3, "x");
83 symbolTable.insertBuiltIn(float4, "log2", float4, "x");
84 symbolTable.insertBuiltIn(float1, "sqrt", float1, "x");
85 symbolTable.insertBuiltIn(float2, "sqrt", float2, "x");
86 symbolTable.insertBuiltIn(float3, "sqrt", float3, "x");
87 symbolTable.insertBuiltIn(float4, "sqrt", float4, "x");
88 symbolTable.insertBuiltIn(float1, "inversesqrt", float1, "x");
89 symbolTable.insertBuiltIn(float2, "inversesqrt", float2, "x");
90 symbolTable.insertBuiltIn(float3, "inversesqrt", float3, "x");
91 symbolTable.insertBuiltIn(float4, "inversesqrt", float4, "x");
92 symbolTable.insertBuiltIn(float1, "abs", float1, "x");
93 symbolTable.insertBuiltIn(float2, "abs", float2, "x");
94 symbolTable.insertBuiltIn(float3, "abs", float3, "x");
95 symbolTable.insertBuiltIn(float4, "abs", float4, "x");
96 symbolTable.insertBuiltIn(float1, "sign", float1, "x");
97 symbolTable.insertBuiltIn(float2, "sign", float2, "x");
98 symbolTable.insertBuiltIn(float3, "sign", float3, "x");
99 symbolTable.insertBuiltIn(float4, "sign", float4, "x");
100 symbolTable.insertBuiltIn(float1, "floor", float1, "x");
101 symbolTable.insertBuiltIn(float2, "floor", float2, "x");
102 symbolTable.insertBuiltIn(float3, "floor", float3, "x");
103 symbolTable.insertBuiltIn(float4, "floor", float4, "x");
104 symbolTable.insertBuiltIn(float1, "ceil", float1, "x");
105 symbolTable.insertBuiltIn(float2, "ceil", float2, "x");
106 symbolTable.insertBuiltIn(float3, "ceil", float3, "x");
107 symbolTable.insertBuiltIn(float4, "ceil", float4, "x");
108 symbolTable.insertBuiltIn(float1, "fract", float1, "x");
109 symbolTable.insertBuiltIn(float2, "fract", float2, "x");
110 symbolTable.insertBuiltIn(float3, "fract", float3, "x");
111 symbolTable.insertBuiltIn(float4, "fract", float4, "x");
112 symbolTable.insertBuiltIn(float1, "mod", float1, "x", float1, "y");
113 symbolTable.insertBuiltIn(float2, "mod", float2, "x", float1, "y");
114 symbolTable.insertBuiltIn(float3, "mod", float3, "x", float1, "y");
115 symbolTable.insertBuiltIn(float4, "mod", float4, "x", float1, "y");
116 symbolTable.insertBuiltIn(float2, "mod", float2, "x", float2, "y");
117 symbolTable.insertBuiltIn(float3, "mod", float3, "x", float3, "y");
118 symbolTable.insertBuiltIn(float4, "mod", float4, "x", float4, "y");
119 symbolTable.insertBuiltIn(float1, "min", float1, "x", float1, "y");
120 symbolTable.insertBuiltIn(float2, "min", float2, "x", float1, "y");
121 symbolTable.insertBuiltIn(float3, "min", float3, "x", float1, "y");
122 symbolTable.insertBuiltIn(float4, "min", float4, "x", float1, "y");
123 symbolTable.insertBuiltIn(float2, "min", float2, "x", float2, "y");
124 symbolTable.insertBuiltIn(float3, "min", float3, "x", float3, "y");
125 symbolTable.insertBuiltIn(float4, "min", float4, "x", float4, "y");
126 symbolTable.insertBuiltIn(float1, "max", float1, "x", float1, "y");
127 symbolTable.insertBuiltIn(float2, "max", float2, "x", float1, "y");
128 symbolTable.insertBuiltIn(float3, "max", float3, "x", float1, "y");
129 symbolTable.insertBuiltIn(float4, "max", float4, "x", float1, "y");
130 symbolTable.insertBuiltIn(float2, "max", float2, "x", float2, "y");
131 symbolTable.insertBuiltIn(float3, "max", float3, "x", float3, "y");
132 symbolTable.insertBuiltIn(float4, "max", float4, "x", float4, "y");
133 symbolTable.insertBuiltIn(float1, "clamp", float1, "x", float1, "minVal", float1, "maxVal");
134 symbolTable.insertBuiltIn(float2, "clamp", float2, "x", float1, "minVal", float1, "maxVal");
135 symbolTable.insertBuiltIn(float3, "clamp", float3, "x", float1, "minVal", float1, "maxVal");
136 symbolTable.insertBuiltIn(float4, "clamp", float4, "x", float1, "minVal", float1, "maxVal");
137 symbolTable.insertBuiltIn(float2, "clamp", float2, "x", float2, "minVal", float2, "maxVal");
138 symbolTable.insertBuiltIn(float3, "clamp", float3, "x", float3, "minVal", float3, "maxVal");
139 symbolTable.insertBuiltIn(float4, "clamp", float4, "x", float4, "minVal", float4, "maxVal");
140 symbolTable.insertBuiltIn(float1, "mix", float1, "x", float1, "y", float1, "a");
141 symbolTable.insertBuiltIn(float2, "mix", float2, "x", float2, "y", float1, "a");
142 symbolTable.insertBuiltIn(float3, "mix", float3, "x", float3, "y", float1, "a");
143 symbolTable.insertBuiltIn(float4, "mix", float4, "x", float4, "y", float1, "a");
144 symbolTable.insertBuiltIn(float2, "mix", float2, "x", float2, "y", float2, "a");
145 symbolTable.insertBuiltIn(float3, "mix", float3, "x", float3, "y", float3, "a");
146 symbolTable.insertBuiltIn(float4, "mix", float4, "x", float4, "y", float4, "a");
147 symbolTable.insertBuiltIn(float1, "step", float1, "edge", float1, "x");
148 symbolTable.insertBuiltIn(float2, "step", float2, "edge", float2, "x");
149 symbolTable.insertBuiltIn(float3, "step", float3, "edge", float3, "x");
150 symbolTable.insertBuiltIn(float4, "step", float4, "edge", float4, "x");
151 symbolTable.insertBuiltIn(float2, "step", float1, "edge", float2, "x");
152 symbolTable.insertBuiltIn(float3, "step", float1, "edge", float3, "x");
153 symbolTable.insertBuiltIn(float4, "step", float1, "edge", float4, "x");
154 symbolTable.insertBuiltIn(float1, "smoothstep", float1, "edge0", float1, "edge1", float1, "x");
155 symbolTable.insertBuiltIn(float2, "smoothstep", float2, "edge0", float2, "edge1", float2, "x");
156 symbolTable.insertBuiltIn(float3, "smoothstep", float3, "edge0", float3, "edge1", float3, "x");
157 symbolTable.insertBuiltIn(float4, "smoothstep", float4, "edge0", float4, "edge1", float4, "x");
158 symbolTable.insertBuiltIn(float2, "smoothstep", float1, "edge0", float1, "edge1", float2, "x");
159 symbolTable.insertBuiltIn(float3, "smoothstep", float1, "edge0", float1, "edge1", float3, "x");
160 symbolTable.insertBuiltIn(float4, "smoothstep", float1, "edge0", float1, "edge1", float4, "x");
161 symbolTable.insertBuiltIn(float1, "length", float1, "x");
162 symbolTable.insertBuiltIn(float1, "length", float2, "x");
163 symbolTable.insertBuiltIn(float1, "length", float3, "x");
164 symbolTable.insertBuiltIn(float1, "length", float4, "x");
165 symbolTable.insertBuiltIn(float1, "distance", float1, "p0", float1, "p1");
166 symbolTable.insertBuiltIn(float1, "distance", float2, "p0", float2, "p1");
167 symbolTable.insertBuiltIn(float1, "distance", float3, "p0", float3, "p1");
168 symbolTable.insertBuiltIn(float1, "distance", float4, "p0", float4, "p1");
169 symbolTable.insertBuiltIn(float1, "dot", float1, "x", float1, "y");
170 symbolTable.insertBuiltIn(float1, "dot", float2, "x", float2, "y");
171 symbolTable.insertBuiltIn(float1, "dot", float3, "x", float3, "y");
172 symbolTable.insertBuiltIn(float1, "dot", float4, "x", float4, "y");
173 symbolTable.insertBuiltIn(float3, "cross", float3, "x", float3, "y");
174 symbolTable.insertBuiltIn(float1, "normalize", float1, "x");
175 symbolTable.insertBuiltIn(float2, "normalize", float2, "x");
176 symbolTable.insertBuiltIn(float3, "normalize", float3, "x");
177 symbolTable.insertBuiltIn(float4, "normalize", float4, "x");
178 symbolTable.insertBuiltIn(float1, "faceforward", float1, "N", float1, "I", float1, "Nref");
179 symbolTable.insertBuiltIn(float2, "faceforward", float2, "N", float2, "I", float2, "Nref");
180 symbolTable.insertBuiltIn(float3, "faceforward", float3, "N", float3, "I", float3, "Nref");
181 symbolTable.insertBuiltIn(float4, "faceforward", float4, "N", float4, "I", float4, "Nref");
182 symbolTable.insertBuiltIn(float1, "reflect", float1, "I", float1, "N");
183 symbolTable.insertBuiltIn(float2, "reflect", float2, "I", float2, "N");
184 symbolTable.insertBuiltIn(float3, "reflect", float3, "I", float3, "N");
185 symbolTable.insertBuiltIn(float4, "reflect", float4, "I", float4, "N");
186 symbolTable.insertBuiltIn(float1, "refract", float1, "I", float1, "N", float1, "eta");
187 symbolTable.insertBuiltIn(float2, "refract", float2, "I", float2, "N", float1, "eta");
188 symbolTable.insertBuiltIn(float3, "refract", float3, "I", float3, "N", float1, "eta");
189 symbolTable.insertBuiltIn(float4, "refract", float4, "I", float4, "N", float1, "eta");
John Bauman66b8ab22014-05-06 15:57:45 -0400190
John Baumand4ae8632014-05-06 16:18:33 -0400191 TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true);
192 TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true);
193 TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true);
John Bauman66b8ab22014-05-06 15:57:45 -0400194
John Baumand4ae8632014-05-06 16:18:33 -0400195 symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, "x", mat2, "y");
196 symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, "x", mat3, "y");
197 symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, "x", mat4, "y");
John Bauman66b8ab22014-05-06 15:57:45 -0400198
John Baumand4ae8632014-05-06 16:18:33 -0400199 TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1);
200 TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2);
201 TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3);
202 TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -0400203
John Baumand4ae8632014-05-06 16:18:33 -0400204 symbolTable.insertBuiltIn(bool2, "lessThan", float2, "x", float2, "y");
205 symbolTable.insertBuiltIn(bool3, "lessThan", float3, "x", float3, "y");
206 symbolTable.insertBuiltIn(bool4, "lessThan", float4, "x", float4, "y");
207 symbolTable.insertBuiltIn(bool2, "lessThan", int2, "x", int2, "y");
208 symbolTable.insertBuiltIn(bool3, "lessThan", int3, "x", int3, "y");
209 symbolTable.insertBuiltIn(bool4, "lessThan", int4, "x", int4, "y");
210 symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, "x", float2, "y");
211 symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, "x", float3, "y");
212 symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, "x", float4, "y");
213 symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, "x", int2, "y");
214 symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, "x", int3, "y");
215 symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, "x", int4, "y");
216 symbolTable.insertBuiltIn(bool2, "greaterThan", float2, "x", float2, "y");
217 symbolTable.insertBuiltIn(bool3, "greaterThan", float3, "x", float3, "y");
218 symbolTable.insertBuiltIn(bool4, "greaterThan", float4, "x", float4, "y");
219 symbolTable.insertBuiltIn(bool2, "greaterThan", int2, "x", int2, "y");
220 symbolTable.insertBuiltIn(bool3, "greaterThan", int3, "x", int3, "y");
221 symbolTable.insertBuiltIn(bool4, "greaterThan", int4, "x", int4, "y");
222 symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, "x", float2, "y");
223 symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, "x", float3, "y");
224 symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, "x", float4, "y");
225 symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, "x", int2, "y");
226 symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, "x", int3, "y");
227 symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, "x", int4, "y");
228 symbolTable.insertBuiltIn(bool2, "equal", float2, "x", float2, "y");
229 symbolTable.insertBuiltIn(bool3, "equal", float3, "x", float3, "y");
230 symbolTable.insertBuiltIn(bool4, "equal", float4, "x", float4, "y");
231 symbolTable.insertBuiltIn(bool2, "equal", int2, "x", int2, "y");
232 symbolTable.insertBuiltIn(bool3, "equal", int3, "x", int3, "y");
233 symbolTable.insertBuiltIn(bool4, "equal", int4, "x", int4, "y");
234 symbolTable.insertBuiltIn(bool2, "equal", bool2, "x", bool2, "y");
235 symbolTable.insertBuiltIn(bool3, "equal", bool3, "x", bool3, "y");
236 symbolTable.insertBuiltIn(bool4, "equal", bool4, "x", bool4, "y");
237 symbolTable.insertBuiltIn(bool2, "notEqual", float2, "x", float2, "y");
238 symbolTable.insertBuiltIn(bool3, "notEqual", float3, "x", float3, "y");
239 symbolTable.insertBuiltIn(bool4, "notEqual", float4, "x", float4, "y");
240 symbolTable.insertBuiltIn(bool2, "notEqual", int2, "x", int2, "y");
241 symbolTable.insertBuiltIn(bool3, "notEqual", int3, "x", int3, "y");
242 symbolTable.insertBuiltIn(bool4, "notEqual", int4, "x", int4, "y");
243 symbolTable.insertBuiltIn(bool2, "notEqual", bool2, "x", bool2, "y");
244 symbolTable.insertBuiltIn(bool3, "notEqual", bool3, "x", bool3, "y");
245 symbolTable.insertBuiltIn(bool4, "notEqual", bool4, "x", bool4, "y");
246 symbolTable.insertBuiltIn(bool1, "any", bool2, "x");
247 symbolTable.insertBuiltIn(bool1, "any", bool3, "x");
248 symbolTable.insertBuiltIn(bool1, "any", bool4, "x");
249 symbolTable.insertBuiltIn(bool1, "all", bool2, "x");
250 symbolTable.insertBuiltIn(bool1, "all", bool3, "x");
251 symbolTable.insertBuiltIn(bool1, "all", bool4, "x");
252 symbolTable.insertBuiltIn(bool2, "not", bool2, "x");
253 symbolTable.insertBuiltIn(bool3, "not", bool3, "x");
254 symbolTable.insertBuiltIn(bool4, "not", bool4, "x");
John Bauman66b8ab22014-05-06 15:57:45 -0400255
John Baumand4ae8632014-05-06 16:18:33 -0400256 TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1);
257 TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1);
John Bauman66b8ab22014-05-06 15:57:45 -0400258
John Baumand4ae8632014-05-06 16:18:33 -0400259 symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, "sampler", float2, "coord");
260 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float3, "coord");
261 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float4, "coord");
262 symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, "sampler", float3, "coord");
John Bauman66b8ab22014-05-06 15:57:45 -0400263
John Baumand4ae8632014-05-06 16:18:33 -0400264 if(type == SH_FRAGMENT_SHADER)
John Bauman66b8ab22014-05-06 15:57:45 -0400265 {
John Baumand4ae8632014-05-06 16:18:33 -0400266 symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, "sampler", float2, "coord", float1, "bias");
267 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float3, "coord", float1, "bias");
268 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, "sampler", float4, "coord", float1, "bias");
269 symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, "sampler", float3, "coord", float1, "bias");
John Bauman66b8ab22014-05-06 15:57:45 -0400270
John Baumand4ae8632014-05-06 16:18:33 -0400271 if (resources.OES_standard_derivatives)
272 {
273 symbolTable.insertBuiltIn(float1, "dFdx", float1, "p");
274 symbolTable.insertBuiltIn(float2, "dFdx", float2, "p");
275 symbolTable.insertBuiltIn(float3, "dFdx", float3, "p");
276 symbolTable.insertBuiltIn(float4, "dFdx", float4, "p");
277
278 symbolTable.insertBuiltIn(float1, "dFdy", float1, "p");
279 symbolTable.insertBuiltIn(float2, "dFdy", float2, "p");
280 symbolTable.insertBuiltIn(float3, "dFdy", float3, "p");
281 symbolTable.insertBuiltIn(float4, "dFdy", float4, "p");
John Bauman66b8ab22014-05-06 15:57:45 -0400282
John Baumand4ae8632014-05-06 16:18:33 -0400283 symbolTable.insertBuiltIn(float1, "fwidth", float1, "p");
284 symbolTable.insertBuiltIn(float2, "fwidth", float2, "p");
285 symbolTable.insertBuiltIn(float3, "fwidth", float3, "p");
286 symbolTable.insertBuiltIn(float4, "fwidth", float4, "p");
287 }
288 }
John Bauman66b8ab22014-05-06 15:57:45 -0400289
John Baumand4ae8632014-05-06 16:18:33 -0400290 if(type == SH_VERTEX_SHADER)
291 {
292 symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, "sampler", float2, "coord", float1, "lod");
293 symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, "sampler", float3, "coord", float1, "lod");
294 symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, "sampler", float4, "coord", float1, "lod");
295 symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, "sampler", float3, "coord", float1, "lod");
296 }
John Bauman66b8ab22014-05-06 15:57:45 -0400297
John Baumand4ae8632014-05-06 16:18:33 -0400298 TTypeList *members = NewPoolTTypeList();
299 TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
300 TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
301 TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
302 near.type->setFieldName("near");
303 far.type->setFieldName("far");
304 diff.type->setFieldName("diff");
305 members->push_back(near);
306 members->push_back(far);
307 members->push_back(diff);
308 TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true);
309 symbolTable.insert(*depthRangeParameters);
310 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters"));
311 depthRange->setQualifier(EvqUniform);
312 symbolTable.insert(*depthRange);
John Bauman66b8ab22014-05-06 15:57:45 -0400313
John Baumand4ae8632014-05-06 16:18:33 -0400314 symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs);
315 symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
316 symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors);
317 symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
318 symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
319 symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
320 symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
321 symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers);
John Bauman66b8ab22014-05-06 15:57:45 -0400322}
323
324void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
325 const ShBuiltInResources& resources,
John Baumand4ae8632014-05-06 16:18:33 -0400326 TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -0400327{
328 //
329 // First, insert some special built-in variables that are not in
330 // the built-in header files.
331 //
332 switch(type) {
333 case SH_FRAGMENT_SHADER:
334 symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
335 symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
336 symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
337 symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
338 symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
339 break;
340 case SH_VERTEX_SHADER:
341 symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
342 symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
343 break;
344 default: assert(false && "Language not supported");
345 }
346
347 //
348 // Next, identify which built-ins from the already loaded headers have
349 // a mapping to an operator. Those that are not identified as such are
350 // expected to be resolved through a library of functions, versus as
351 // operations.
352 //
353 symbolTable.relateToOperator("not", EOpVectorLogicalNot);
354
355 symbolTable.relateToOperator("matrixCompMult", EOpMul);
356
357 symbolTable.relateToOperator("equal", EOpVectorEqual);
358 symbolTable.relateToOperator("notEqual", EOpVectorNotEqual);
359 symbolTable.relateToOperator("lessThan", EOpLessThan);
360 symbolTable.relateToOperator("greaterThan", EOpGreaterThan);
361 symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual);
362 symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual);
363
364 symbolTable.relateToOperator("radians", EOpRadians);
365 symbolTable.relateToOperator("degrees", EOpDegrees);
366 symbolTable.relateToOperator("sin", EOpSin);
367 symbolTable.relateToOperator("cos", EOpCos);
368 symbolTable.relateToOperator("tan", EOpTan);
369 symbolTable.relateToOperator("asin", EOpAsin);
370 symbolTable.relateToOperator("acos", EOpAcos);
371 symbolTable.relateToOperator("atan", EOpAtan);
372
373 symbolTable.relateToOperator("pow", EOpPow);
374 symbolTable.relateToOperator("exp2", EOpExp2);
375 symbolTable.relateToOperator("log", EOpLog);
376 symbolTable.relateToOperator("exp", EOpExp);
377 symbolTable.relateToOperator("log2", EOpLog2);
378 symbolTable.relateToOperator("sqrt", EOpSqrt);
379 symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt);
380
381 symbolTable.relateToOperator("abs", EOpAbs);
382 symbolTable.relateToOperator("sign", EOpSign);
383 symbolTable.relateToOperator("floor", EOpFloor);
384 symbolTable.relateToOperator("ceil", EOpCeil);
385 symbolTable.relateToOperator("fract", EOpFract);
386 symbolTable.relateToOperator("mod", EOpMod);
387 symbolTable.relateToOperator("min", EOpMin);
388 symbolTable.relateToOperator("max", EOpMax);
389 symbolTable.relateToOperator("clamp", EOpClamp);
390 symbolTable.relateToOperator("mix", EOpMix);
391 symbolTable.relateToOperator("step", EOpStep);
392 symbolTable.relateToOperator("smoothstep", EOpSmoothStep);
393
394 symbolTable.relateToOperator("length", EOpLength);
395 symbolTable.relateToOperator("distance", EOpDistance);
396 symbolTable.relateToOperator("dot", EOpDot);
397 symbolTable.relateToOperator("cross", EOpCross);
398 symbolTable.relateToOperator("normalize", EOpNormalize);
399 symbolTable.relateToOperator("faceforward", EOpFaceForward);
400 symbolTable.relateToOperator("reflect", EOpReflect);
401 symbolTable.relateToOperator("refract", EOpRefract);
402
403 symbolTable.relateToOperator("any", EOpAny);
404 symbolTable.relateToOperator("all", EOpAll);
405
406 // Map language-specific operators.
407 switch(type) {
408 case SH_VERTEX_SHADER:
409 break;
410 case SH_FRAGMENT_SHADER:
411 if (resources.OES_standard_derivatives) {
412 symbolTable.relateToOperator("dFdx", EOpDFdx);
413 symbolTable.relateToOperator("dFdy", EOpDFdy);
414 symbolTable.relateToOperator("fwidth", EOpFwidth);
415
416 symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives");
417 symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives");
418 symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives");
419 }
420 break;
421 default: break;
422 }
423
424 // Finally add resource-specific variables.
425 switch(type)
426 {
427 case SH_FRAGMENT_SHADER:
428 {
429 // Set up gl_FragData. The array size.
430 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true);
431 fragData.setArraySize(resources.MaxDrawBuffers);
432 symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
433 }
434 break;
435 default: break;
436 }
437}
438
439void InitExtensionBehavior(const ShBuiltInResources& resources,
440 TExtensionBehavior& extBehavior)
441{
442 if (resources.OES_standard_derivatives)
443 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
John Baumand4ae8632014-05-06 16:18:33 -0400444 if (resources.OES_fragment_precision_high)
445 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
John Bauman66b8ab22014-05-06 15:57:45 -0400446}