• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
3 // 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 symbols 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/translator/Initialize.h"
14 
15 #include "compiler/translator/intermediate.h"
16 
InsertBuiltInFunctions(ShShaderType type,ShShaderSpec spec,const ShBuiltInResources & resources,TSymbolTable & symbolTable)17 void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
18 {
19     TType *float1 = new TType(EbtFloat);
20     TType *float2 = new TType(EbtFloat, 2);
21     TType *float3 = new TType(EbtFloat, 3);
22     TType *float4 = new TType(EbtFloat, 4);
23 
24     TType *int1 = new TType(EbtInt);
25     TType *int2 = new TType(EbtInt, 2);
26     TType *int3 = new TType(EbtInt, 3);
27     TType *int4 = new TType(EbtInt, 4);
28 
29     //
30     // Angle and Trigonometric Functions.
31     //
32     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "radians", float1);
33     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "radians", float2);
34     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "radians", float3);
35     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "radians", float4);
36 
37     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "degrees", float1);
38     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "degrees", float2);
39     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "degrees", float3);
40     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "degrees", float4);
41 
42     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sin", float1);
43     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sin", float2);
44     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sin", float3);
45     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sin", float4);
46 
47     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "cos", float1);
48     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "cos", float2);
49     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cos", float3);
50     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "cos", float4);
51 
52     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "tan", float1);
53     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "tan", float2);
54     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "tan", float3);
55     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "tan", float4);
56 
57     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "asin", float1);
58     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "asin", float2);
59     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "asin", float3);
60     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "asin", float4);
61 
62     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "acos", float1);
63     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "acos", float2);
64     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "acos", float3);
65     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "acos", float4);
66 
67     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1, float1);
68     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2, float2);
69     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3, float3);
70     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4, float4);
71 
72     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1);
73     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2);
74     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3);
75     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4);
76 
77     //
78     // Exponential Functions.
79     //
80     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1);
81     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2);
82     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3);
83     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4);
84 
85     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1);
86     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2);
87     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3);
88     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4);
89 
90     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1);
91     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2);
92     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3);
93     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4);
94 
95     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1);
96     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2);
97     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3);
98     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4);
99 
100     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1);
101     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2);
102     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3);
103     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4);
104 
105     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1);
106     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2);
107     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3);
108     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4);
109 
110     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1);
111     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2);
112     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3);
113     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4);
114 
115     //
116     // Common Functions.
117     //
118     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1);
119     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2);
120     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3);
121     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4);
122 
123     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1);
124     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2);
125     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3);
126     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4);
127 
128     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1);
129     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2);
130     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3);
131     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4);
132 
133     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1);
134     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2);
135     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3);
136     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4);
137 
138     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1);
139     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2);
140     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3);
141     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4);
142 
143     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1);
144     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1);
145     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1);
146     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1);
147     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2);
148     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3);
149     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4);
150 
151     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1);
152     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1);
153     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1);
154     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1);
155     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2);
156     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3);
157     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4);
158 
159     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1);
160     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1);
161     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1);
162     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1);
163     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2);
164     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3);
165     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4);
166 
167     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1);
168     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1);
169     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1);
170     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1);
171     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2);
172     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3);
173     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4);
174 
175     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1);
176     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1);
177     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1);
178     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1);
179     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2);
180     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3);
181     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4);
182 
183     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1);
184     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2);
185     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3);
186     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4);
187     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2);
188     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3);
189     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4);
190 
191     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1);
192     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2);
193     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3);
194     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4);
195     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2);
196     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3);
197     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4);
198 
199     //
200     // Geometric Functions.
201     //
202     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1);
203     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2);
204     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3);
205     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4);
206 
207     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1);
208     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2);
209     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3);
210     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4);
211 
212     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1);
213     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2);
214     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3);
215     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4);
216 
217     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3);
218     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1);
219     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2);
220     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3);
221     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4);
222 
223     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1);
224     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2);
225     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3);
226     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4);
227 
228     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1);
229     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2);
230     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3);
231     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4);
232 
233     symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1);
234     symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1);
235     symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1);
236     symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1);
237 
238     TType *mat2 = new TType(EbtFloat, 2, 2);
239     TType *mat3 = new TType(EbtFloat, 3, 3);
240     TType *mat4 = new TType(EbtFloat, 4, 4);
241 
242     //
243     // Matrix Functions.
244     //
245     symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2);
246     symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3);
247     symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4);
248 
249     TType *bool1 = new TType(EbtBool);
250     TType *bool2 = new TType(EbtBool, 2);
251     TType *bool3 = new TType(EbtBool, 3);
252     TType *bool4 = new TType(EbtBool, 4);
253 
254     //
255     // Vector relational functions.
256     //
257     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2);
258     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3);
259     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4);
260 
261     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2);
262     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3);
263     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4);
264 
265     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2);
266     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3);
267     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4);
268 
269     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2);
270     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3);
271     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4);
272 
273     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2);
274     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3);
275     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4);
276 
277     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2);
278     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3);
279     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4);
280 
281     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2);
282     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3);
283     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4);
284 
285     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2);
286     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3);
287     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4);
288 
289     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2);
290     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3);
291     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4);
292 
293     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2);
294     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3);
295     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4);
296 
297     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2);
298     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3);
299     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4);
300 
301     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2);
302     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3);
303     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4);
304 
305     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2);
306     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3);
307     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4);
308 
309     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2);
310     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3);
311     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4);
312 
313     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2);
314     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3);
315     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4);
316 
317     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2);
318     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3);
319     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4);
320 
321     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2);
322     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3);
323     symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4);
324 
325     TType *sampler2D = new TType(EbtSampler2D);
326     TType *samplerCube = new TType(EbtSamplerCube);
327 
328     //
329     // Texture Functions for GLSL ES 1.0
330     //
331     symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
332     symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
333     symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
334     symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
335 
336     if (resources.OES_EGL_image_external)
337     {
338         TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
339 
340         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
341         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
342         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
343     }
344 
345     if (resources.ARB_texture_rectangle)
346     {
347         TType *sampler2DRect = new TType(EbtSampler2DRect);
348 
349         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
350         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
351         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
352     }
353 
354     if (resources.EXT_shader_texture_lod)
355     {
356         /* The *Grad* variants are new to both vertex and fragment shaders; the fragment
357          * shader specific pieces are added separately below.
358          */
359         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DGradEXT", sampler2D, float2, float2, float2);
360         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2);
361         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2);
362         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeGradEXT", samplerCube, float3, float3, float3);
363     }
364 
365     if (type == SH_FRAGMENT_SHADER)
366     {
367         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
368         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
369         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
370         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
371 
372         if (resources.OES_standard_derivatives)
373         {
374             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1);
375             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2);
376             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3);
377             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4);
378 
379             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1);
380             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2);
381             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3);
382             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4);
383 
384             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1);
385             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2);
386             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3);
387             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4);
388         }
389 
390         if (resources.EXT_shader_texture_lod)
391         {
392             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLodEXT", sampler2D, float2, float1);
393             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float3, float1);
394             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float4, float1);
395             symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLodEXT", samplerCube, float3, float1);
396         }
397     }
398 
399     if(type == SH_VERTEX_SHADER)
400     {
401         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
402         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
403         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
404         symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
405     }
406 
407     TType *gvec4 = new TType(EbtGVec4);
408 
409     TType *gsampler2D = new TType(EbtGSampler2D);
410     TType *gsamplerCube = new TType(EbtGSamplerCube);
411     TType *gsampler3D = new TType(EbtGSampler3D);
412     TType *gsampler2DArray = new TType(EbtGSampler2DArray);
413 
414     //
415     // Texture Functions for GLSL ES 3.0
416     //
417     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
418     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
419     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
420     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
421     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
422     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
423     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
424     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
425     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
426     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
427     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
428 
429     if (type == SH_FRAGMENT_SHADER)
430     {
431         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
432         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
433         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
434         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
435         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
436         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
437         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
438     }
439 
440     TType *sampler2DShadow = new TType(EbtSampler2DShadow);
441     TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
442     TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
443 
444     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
445     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
446     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
447     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
448     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
449 
450     if (type == SH_FRAGMENT_SHADER)
451     {
452         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
453         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
454         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
455     }
456 
457     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
458     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
459     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
460     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
461     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
462     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
463     symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
464 
465     if(type == SH_FRAGMENT_SHADER)
466     {
467         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdx", float1);
468         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdx", float2);
469         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdx", float3);
470         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdx", float4);
471 
472         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdy", float1);
473         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdy", float2);
474         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdy", float3);
475         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdy", float4);
476 
477         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "fwidth", float1);
478         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "fwidth", float2);
479         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "fwidth", float3);
480         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "fwidth", float4);
481     }
482 
483     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
484     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
485     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
486     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
487 
488     if(type == SH_FRAGMENT_SHADER)
489     {
490         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
491         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
492         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
493         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
494     }
495 
496     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
497     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
498     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
499     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
500 
501     if(type == SH_FRAGMENT_SHADER)
502     {
503         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
504         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
505         symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
506         symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
507     }
508 
509     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
510     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
511     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
512     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
513 
514     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
515     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
516     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
517     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
518 
519     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
520     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
521     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
522     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
523 
524     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
525     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
526     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
527 
528     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
529     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
530     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
531 
532     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
533     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
534     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
535     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
536     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
537     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
538     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
539 
540     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
541     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
542     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
543     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
544     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
545 
546     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
547     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
548     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
549     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
550 
551     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
552     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
553     symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
554     symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
555 
556     //
557     // Depth range in window coordinates
558     //
559     TFieldList *fields = NewPoolTFieldList();
560     TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
561     TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
562     TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
563     TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
564     fields->push_back(near);
565     fields->push_back(far);
566     fields->push_back(diff);
567     TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
568     TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
569     symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
570     TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
571     depthRange->setQualifier(EvqUniform);
572     symbolTable.insert(COMMON_BUILTINS, *depthRange);
573 
574     //
575     // Implementation dependent built-in constants.
576     //
577     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
578     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
579     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
580     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
581     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
582     symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
583 
584     symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
585 
586     if (spec != SH_CSS_SHADERS_SPEC)
587     {
588         symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
589     }
590 
591     symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
592     symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
593     symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
594     symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
595 }
596 
IdentifyBuiltIns(ShShaderType type,ShShaderSpec spec,const ShBuiltInResources & resources,TSymbolTable & symbolTable)597 void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
598                       const ShBuiltInResources &resources,
599                       TSymbolTable &symbolTable)
600 {
601     //
602     // First, insert some special built-in variables that are not in
603     // the built-in header files.
604     //
605     switch(type) {
606     case SH_FRAGMENT_SHADER:
607         symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord,   4)));
608         symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool,  EbpUndefined, EvqFrontFacing, 1)));
609         symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord,  2)));
610 
611         //
612         // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
613         // Instead, css_MixColor and css_ColorMatrix are available.
614         //
615         if (spec != SH_CSS_SHADERS_SPEC) {
616             symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor,   4)));
617             symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData,    4)));
618             if (resources.EXT_frag_depth) {
619                 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
620                 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
621             }
622         } else {
623             symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal,      4)));
624             symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal,      4, 4)));
625         }
626 
627         break;
628 
629     case SH_VERTEX_SHADER:
630         symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition,    4)));
631         symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize,   1)));
632         break;
633 
634     default: assert(false && "Language not supported");
635     }
636 
637     //
638     // Next, identify which built-ins from the already loaded headers have
639     // a mapping to an operator.  Those that are not identified as such are
640     // expected to be resolved through a library of functions, versus as
641     // operations.
642     //
643     symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult",   EOpMul);
644 
645     symbolTable.relateToOperator(COMMON_BUILTINS, "equal",            EOpVectorEqual);
646     symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual",         EOpVectorNotEqual);
647     symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan",         EOpLessThan);
648     symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan",      EOpGreaterThan);
649     symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual",    EOpLessThanEqual);
650     symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual);
651 
652     symbolTable.relateToOperator(COMMON_BUILTINS, "radians",      EOpRadians);
653     symbolTable.relateToOperator(COMMON_BUILTINS, "degrees",      EOpDegrees);
654     symbolTable.relateToOperator(COMMON_BUILTINS, "sin",          EOpSin);
655     symbolTable.relateToOperator(COMMON_BUILTINS, "cos",          EOpCos);
656     symbolTable.relateToOperator(COMMON_BUILTINS, "tan",          EOpTan);
657     symbolTable.relateToOperator(COMMON_BUILTINS, "asin",         EOpAsin);
658     symbolTable.relateToOperator(COMMON_BUILTINS, "acos",         EOpAcos);
659     symbolTable.relateToOperator(COMMON_BUILTINS, "atan",         EOpAtan);
660 
661     symbolTable.relateToOperator(COMMON_BUILTINS, "pow",          EOpPow);
662     symbolTable.relateToOperator(COMMON_BUILTINS, "exp2",         EOpExp2);
663     symbolTable.relateToOperator(COMMON_BUILTINS, "log",          EOpLog);
664     symbolTable.relateToOperator(COMMON_BUILTINS, "exp",          EOpExp);
665     symbolTable.relateToOperator(COMMON_BUILTINS, "log2",         EOpLog2);
666     symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt",         EOpSqrt);
667     symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt",  EOpInverseSqrt);
668 
669     symbolTable.relateToOperator(COMMON_BUILTINS, "abs",          EOpAbs);
670     symbolTable.relateToOperator(COMMON_BUILTINS, "sign",         EOpSign);
671     symbolTable.relateToOperator(COMMON_BUILTINS, "floor",        EOpFloor);
672     symbolTable.relateToOperator(COMMON_BUILTINS, "ceil",         EOpCeil);
673     symbolTable.relateToOperator(COMMON_BUILTINS, "fract",        EOpFract);
674     symbolTable.relateToOperator(COMMON_BUILTINS, "mod",          EOpMod);
675     symbolTable.relateToOperator(COMMON_BUILTINS, "min",          EOpMin);
676     symbolTable.relateToOperator(COMMON_BUILTINS, "max",          EOpMax);
677     symbolTable.relateToOperator(COMMON_BUILTINS, "clamp",        EOpClamp);
678     symbolTable.relateToOperator(COMMON_BUILTINS, "mix",          EOpMix);
679     symbolTable.relateToOperator(COMMON_BUILTINS, "step",         EOpStep);
680     symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep",   EOpSmoothStep);
681 
682     symbolTable.relateToOperator(COMMON_BUILTINS, "length",       EOpLength);
683     symbolTable.relateToOperator(COMMON_BUILTINS, "distance",     EOpDistance);
684     symbolTable.relateToOperator(COMMON_BUILTINS, "dot",          EOpDot);
685     symbolTable.relateToOperator(COMMON_BUILTINS, "cross",        EOpCross);
686     symbolTable.relateToOperator(COMMON_BUILTINS, "normalize",    EOpNormalize);
687     symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward",  EOpFaceForward);
688     symbolTable.relateToOperator(COMMON_BUILTINS, "reflect",      EOpReflect);
689     symbolTable.relateToOperator(COMMON_BUILTINS, "refract",      EOpRefract);
690 
691     symbolTable.relateToOperator(COMMON_BUILTINS, "any",          EOpAny);
692     symbolTable.relateToOperator(COMMON_BUILTINS, "all",          EOpAll);
693     symbolTable.relateToOperator(COMMON_BUILTINS, "not",          EOpVectorLogicalNot);
694 
695     // Map language-specific operators.
696     switch(type) {
697     case SH_VERTEX_SHADER:
698         break;
699     case SH_FRAGMENT_SHADER:
700         if (resources.OES_standard_derivatives)
701         {
702             symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx",   EOpDFdx);
703             symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy",   EOpDFdy);
704             symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
705 
706             symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
707             symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
708             symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
709         }
710         if (resources.EXT_shader_texture_lod)
711         {
712             symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DLodEXT", "GL_EXT_shader_texture_lod");
713             symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjLodEXT", "GL_EXT_shader_texture_lod");
714             symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeLodEXT", "GL_EXT_shader_texture_lod");
715         }
716         break;
717     default: break;
718     }
719 
720     symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx",   EOpDFdx);
721     symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy",   EOpDFdy);
722     symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth);
723 
724     if (resources.EXT_shader_texture_lod)
725     {
726         symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DGradEXT", "GL_EXT_shader_texture_lod");
727         symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjGradEXT", "GL_EXT_shader_texture_lod");
728         symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeGradEXT", "GL_EXT_shader_texture_lod");
729     }
730 
731     // Finally add resource-specific variables.
732     switch(type) {
733     case SH_FRAGMENT_SHADER:
734         if (spec != SH_CSS_SHADERS_SPEC) {
735             // Set up gl_FragData.  The array size.
736             TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
737             fragData.setArraySize(resources.MaxDrawBuffers);
738             symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
739         }
740         break;
741     default: break;
742     }
743 }
744 
InitExtensionBehavior(const ShBuiltInResources & resources,TExtensionBehavior & extBehavior)745 void InitExtensionBehavior(const ShBuiltInResources& resources,
746                            TExtensionBehavior& extBehavior)
747 {
748     if (resources.OES_standard_derivatives)
749         extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
750     if (resources.OES_EGL_image_external)
751         extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
752     if (resources.ARB_texture_rectangle)
753         extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
754     if (resources.EXT_draw_buffers)
755         extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
756     if (resources.EXT_frag_depth)
757         extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
758     if (resources.EXT_shader_texture_lod)
759         extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined;
760 }
761