1d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Licensed under the Apache License, Version 2.0 (the "License");
4d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// you may not use this file except in compliance with the License.
5d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// You may obtain a copy of the License at
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
7d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//    http://www.apache.org/licenses/LICENSE-2.0
8d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens//
9d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// Unless required by applicable law or agreed to in writing, software
10d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// distributed under the License is distributed on an "AS IS" BASIS,
11d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// See the License for the specific language governing permissions and
13d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens// limitations under the License.
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// Create strings that declare built-in definitions, add built-ins that
17d50c160c55fc7353916a55194c538fe3b53480ebNicolas Capens// cannot be expressed in the files, and establish mappings between
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// built-in functions and operators.
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
21cc863da574ed5079b055574127fe5788a9a0fc33Nicolas Capens#include "Initialize.h"
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
23cc863da574ed5079b055574127fe5788a9a0fc33Nicolas Capens#include "intermediate.h"
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2508ca3c6e18275ed9db5515e470692e700e1a3e12Nicolas Capensvoid InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
2770da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *float1 = new TType(EbtFloat);
2870da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *float2 = new TType(EbtFloat, 2);
2970da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *float3 = new TType(EbtFloat, 3);
3070da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *float4 = new TType(EbtFloat, 4);
318fa9d23dda6436369ae1e16dbed3bf1425626ae0Nicolas Capens	TType *genType = new TType(EbtGenType);
32d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
33d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *int1 = new TType(EbtInt);
34b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	TType *int2 = new TType(EbtInt, 2);
35b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	TType *int3 = new TType(EbtInt, 3);
36d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *uint1 = new TType(EbtUInt);
37d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *genIType = new TType(EbtGenIType);
38d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *genUType = new TType(EbtGenUType);
39d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *genBType = new TType(EbtGenBType);
40d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
41d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
42d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Angle and Trigonometric Functions.
43d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
44d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType);
45d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType);
46d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType);
47d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType);
48d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType);
49d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType);
50d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType);
51d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType);
52d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType);
53d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType);
54d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType);
55d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType);
56d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType);
57d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType);
58d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType);
59d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
60d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
61d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Exponential Functions.
62d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
63d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType);
64d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType);
65d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType);
66d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType);
67d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType);
68d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType);
69d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType);
70d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
71d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
72d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Common Functions.
73d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
74d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType);
75d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType);
76d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType);
77d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType);
78d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType);
79d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType);
80d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType);
81d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType);
82d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType);
83d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType);
84d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1);
85d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType);
86d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1);
87d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType);
88d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType);
89d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1);
90d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType);
91d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1);
92d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1);
93d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType);
94d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType);
95d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1);
96d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType);
97d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1);
98d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1);
99d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType);
100d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1);
101d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType);
102d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1);
103d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType);
104d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1);
105d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType);
106d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType);
107d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType);
108d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType);
109d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType);
1103d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens
1114c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	TType *outFloat1 = new TType(EbtFloat, EbpUndefined, EvqOut);
1124c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	TType *outFloat2 = new TType(EbtFloat, EbpUndefined, EvqOut, 2);
1134c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	TType *outFloat3 = new TType(EbtFloat, EbpUndefined, EvqOut, 3);
1144c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	TType *outFloat4 = new TType(EbtFloat, EbpUndefined, EvqOut, 4);
1154c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu
1164c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1);
1174c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2);
1184c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float3, "modf", float3, outFloat3);
1194c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float4, "modf", float4, outFloat4);
1204c01ec7d8b8883fc5cdc39fc4d82298a5da8eac3Alexis Hetu
121d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType);
122d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType);
123d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType);
124d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType);
125d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType);
126d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
127d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
128d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2);
129d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2);
130d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2);
131d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1);
132d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1);
133d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1);
134d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
135d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
136d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Geometric Functions.
137d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
138d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType);
139d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType);
140d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType);
141d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3);
142d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType);
143d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType);
144d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
145d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
146d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
147b14178b68ccb44a1fca9ba4e7db7770c6b6b6fa9Alexis Hetu	TType *mat2 = new TType(EbtFloat, 2, 2);
1482205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat2x3 = new TType(EbtFloat, 2, 3);
1492205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat2x4 = new TType(EbtFloat, 2, 4);
1502205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat3x2 = new TType(EbtFloat, 3, 2);
151b14178b68ccb44a1fca9ba4e7db7770c6b6b6fa9Alexis Hetu	TType *mat3 = new TType(EbtFloat, 3, 3);
1522205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat3x4 = new TType(EbtFloat, 3, 4);
1532205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat4x2 = new TType(EbtFloat, 4, 2);
1542205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu	TType *mat4x3 = new TType(EbtFloat, 4, 3);
155b14178b68ccb44a1fca9ba4e7db7770c6b6b6fa9Alexis Hetu	TType *mat4 = new TType(EbtFloat, 4, 4);
156d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
157d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
158d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Matrix Functions.
159d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
160d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2);
161d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3);
162d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4);
163d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3);
164d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2);
165d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4);
166d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2);
167d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4);
168d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
169d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
170d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2);
171d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3);
172d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4);
173d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2);
174d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3);
175d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2);
176d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4);
177d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3);
178d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
179d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
180d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2);
181d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3);
182d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4);
183d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2);
184d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3);
185d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2);
186d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4);
187d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3);
188d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
189d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
190d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2);
191d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3);
192d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
193d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
194d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2);
195d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
196d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
1972205c2012c2c9546c7c0fd6b90c674c1486e30a3Alexis Hetu
198d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
19970da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *bool1 = new TType(EbtBool);
2008fa9d23dda6436369ae1e16dbed3bf1425626ae0Nicolas Capens	TType *vec = new TType(EbtVec);
2018fa9d23dda6436369ae1e16dbed3bf1425626ae0Nicolas Capens	TType *ivec = new TType(EbtIVec);
202d50c160c55fc7353916a55194c538fe3b53480ebNicolas Capens	TType *uvec = new TType(EbtUVec);
2038fa9d23dda6436369ae1e16dbed3bf1425626ae0Nicolas Capens	TType *bvec = new TType(EbtBVec);
204d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
205d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
206d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Vector relational functions.
207d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
208d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec);
209d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec);
210d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec);
211d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec);
212d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec);
213d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec);
214d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec);
215d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec);
216d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec);
217d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec);
218d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec);
219d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec);
220d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec);
221d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec);
222d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec);
223d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec);
224d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec);
225d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec);
226d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec);
227d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec);
228d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec);
229d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
230d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
231d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
23270da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *sampler2D = new TType(EbtSampler2D);
23370da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *samplerCube = new TType(EbtSamplerCube);
23470da3d432409368f214058c466fe0265b6b9a070Nicolas Capens	TType *sampler3D = new TType(EbtSampler3D);
235d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
236d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
237d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Texture Functions for GLSL ES 1.0
238d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
239d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
240d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
241d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
242d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
2433d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens	symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3);
2443d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens
2453d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens	if(resources.OES_EGL_image_external)
246d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	{
247d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
2483d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens
249d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
250d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
251d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
2523d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3);
253d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	}
254d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
25508ca3c6e18275ed9db5515e470692e700e1a3e12Nicolas Capens	if(type == GL_FRAGMENT_SHADER)
25666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman	{
257d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
258d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
259d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
260d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2623d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		if(resources.OES_standard_derivatives)
263d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman		{
26418d5ef97c6a5112b08c310606ef854cafae864bfNicolas Capens			symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType);
26518d5ef97c6a5112b08c310606ef854cafae864bfNicolas Capens			symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType);
26618d5ef97c6a5112b08c310606ef854cafae864bfNicolas Capens			symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth,"GL_OES_standard_derivatives", genType, "fwidth", genType);
267d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman		}
268d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman	}
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
27008ca3c6e18275ed9db5515e470692e700e1a3e12Nicolas Capens	if(type == GL_VERTEX_SHADER)
271d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman	{
2723d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
2733d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
2743d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
2753d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
2763d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens		symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1);
277d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman	}
278d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
279d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *gvec4 = new TType(EbtGVec4);
280d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
281d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *gsampler2D = new TType(EbtGSampler2D);
282d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *gsamplerCube = new TType(EbtGSamplerCube);
283d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *gsampler3D = new TType(EbtGSampler3D);
284d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	TType *gsampler2DArray = new TType(EbtGSampler2DArray);
285d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
286d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
287d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Texture Functions for GLSL ES 3.0
288d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
289d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
290d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
291d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
292d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
293d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
294d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
295d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
296d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
297d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
298d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
299d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
300d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
301d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	if(type == GL_FRAGMENT_SHADER)
302d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	{
303d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
304d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
305d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
306d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
307d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
308d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
309d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
310d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	}
31182cd6d82a079fcad71e686cc075e36186f2a8e66Nicolas Capens
312b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	TType *sampler2DShadow = new TType(EbtSampler2DShadow);
313b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
314b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
315b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
316b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
317b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
318b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
319b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
320b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
321b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
322b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	if(type == GL_FRAGMENT_SHADER)
323b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	{
324b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
325b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
326b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
327b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	}
328b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
329b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
330b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
331b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
332b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
333b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
334b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
335b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
336b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
337b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	if(type == GL_FRAGMENT_SHADER)
338b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	{
339b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType);
340b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType);
341b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType);
342b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	}
343b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
344b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
345b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
346b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
347b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
348b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
349b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	if(type == GL_FRAGMENT_SHADER)
350b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	{
351b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
352b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
353b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
354b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
355b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	}
356b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
357b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
358b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
359b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
360b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
361b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
362b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	if(type == GL_FRAGMENT_SHADER)
363b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	{
364b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
365b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
366b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
367b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu		symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
368b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	}
369b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
370b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
371b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
372b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
373b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
374b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
375b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
376b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
377b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
378b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
379b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
380b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
381b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
382b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
383b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
384b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
385b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
386b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
387b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
388b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
389b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
390b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
391b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
392b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
393b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
394b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
395b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
396b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
397b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
398b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
399b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
400b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
401b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
402b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
403b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
404b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
405b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
406b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
407b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
408b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
409b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
410b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
411b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
412b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
413b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
414b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
415b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu	symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
416b5332c54150a1d30991390f77c8a277fd2e90c21Alexis Hetu
417d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
418d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Depth range in window coordinates
419d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
420a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	TFieldList *fields = NewPoolTFieldList();
421253fdd10c2c3b428302755db0df4ca6fbb60024fAlexis Hetu	TSourceLoc zeroSourceLoc = { 0, 0, 0, 0 };
422253fdd10c2c3b428302755db0df4ca6fbb60024fAlexis Hetu	TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
423253fdd10c2c3b428302755db0df4ca6fbb60024fAlexis Hetu	TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
424253fdd10c2c3b428302755db0df4ca6fbb60024fAlexis Hetu	TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
425a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	fields->push_back(near);
426a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	fields->push_back(far);
427a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	fields->push_back(diff);
428a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
429a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
430e2858656575d8bc1f88ad3c885ab3cedf29a482eNicolas Capens	symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
431a8b364b735624da31500d0fe93ae75f8b36a59d1Alexis Hetu	TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
432d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman	depthRange->setQualifier(EvqUniform);
433e2858656575d8bc1f88ad3c885ab3cedf29a482eNicolas Capens	symbolTable.insert(COMMON_BUILTINS, *depthRange);
434d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman
435d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
436d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Implementation dependent built-in constants.
437d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
438d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
439d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
440d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
441d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
442d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
443d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
444d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
445d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
446d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
447d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
448d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
449d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
450894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
451894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
45208ca3c6e18275ed9db5515e470692e700e1a3e12Nicolas Capensvoid IdentifyBuiltIns(GLenum shaderType,
4533d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens                      const ShBuiltInResources &resources,
454d4ae863d01d5f448dbbba6be4ecc161971a2324fJohn Bauman                      TSymbolTable &symbolTable)
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
456d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
457d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// First, insert some special built-in variables that are not in
458d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// the built-in header files.
459d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	//
460d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	switch(shaderType)
46108ca3c6e18275ed9db5515e470692e700e1a3e12Nicolas Capens	{
462d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	case GL_FRAGMENT_SHADER:
463d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord,   4)));
464d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool,  EbpUndefined, EvqFrontFacing, 1)));
465d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord,  2)));
466d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor,   4)));
467d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData,    4)));
468d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepth"), TType(EbtFloat, EbpHigh, EvqFragDepth, 1)));
469d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		break;
470d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	case GL_VERTEX_SHADER:
471d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition,    4)));
472d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize,   1)));
473d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EbpHigh, EvqInstanceID, 1)));
474d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		break;
475d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	default: assert(false && "Language not supported");
476d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	}
477d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens
478d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	// Finally add resource-specific variables.
479d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	switch(shaderType)
480d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	{
481d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	case GL_FRAGMENT_SHADER:
48266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		{
483d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens			// Set up gl_FragData.  The array size.
484d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens			TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
485d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens			fragData.setArraySize(resources.MaxDrawBuffers);
486d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens			symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
48766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		}
48866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman		break;
489d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	default: break;
490d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	}
491894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
492894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
493894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid InitExtensionBehavior(const ShBuiltInResources& resources,
494894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           TExtensionBehavior& extBehavior)
495894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman{
496d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	if(resources.OES_standard_derivatives)
497d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
4983d7f6ed87f60694d52606d9338cf9483d62fa8bfNicolas Capens	if(resources.OES_fragment_precision_high)
499d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
500d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens	if(resources.OES_EGL_image_external)
501d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
502d50c160c55fc7353916a55194c538fe3b53480ebNicolas Capens	if(resources.EXT_draw_buffers)
503d999309b36cb3dceadd38217b322f0e96a06b202Nicolas Capens		extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
504894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
505