blob: 2fc517f9b3f9cb1099e04aa9b8466adf15f0eac5 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
John Baumand4ae8632014-05-06 16:18:33 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7//
8// Create strings that declare built-in definitions, add built-ins that
Nicolas Capensc66f0e32016-04-18 14:34:24 -04009// cannot be expressed in the files, and establish mappings between
John Bauman66b8ab22014-05-06 15:57:45 -040010// built-in functions and operators.
11//
12
Nicolas Capenscc863da2015-01-21 15:50:55 -050013#include "Initialize.h"
John Bauman66b8ab22014-05-06 15:57:45 -040014
Nicolas Capenscc863da2015-01-21 15:50:55 -050015#include "intermediate.h"
John Bauman66b8ab22014-05-06 15:57:45 -040016
Nicolas Capens08ca3c62015-02-13 16:06:45 -050017void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -040018{
Nicolas Capens70da3d42015-02-18 16:58:10 -050019 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);
Nicolas Capens8fa9d232015-02-19 15:53:16 -050023 TType *genType = new TType(EbtGenType);
John Bauman66b8ab22014-05-06 15:57:45 -040024
Alexis Hetu2205c202015-04-16 10:38:41 -040025 TType *int1 = new TType(EbtInt);
Alexis Hetub5332c52015-06-04 13:04:17 -040026 TType *int2 = new TType(EbtInt, 2);
27 TType *int3 = new TType(EbtInt, 3);
Alexis Hetu2205c202015-04-16 10:38:41 -040028 TType *uint1 = new TType(EbtUInt);
29 TType *genIType = new TType(EbtGenIType);
30 TType *genUType = new TType(EbtGenUType);
31 TType *genBType = new TType(EbtGenBType);
32
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050033 //
34 // Angle and Trigonometric Functions.
35 //
Nicolas Capens33cda112015-02-24 17:35:47 -050036 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType);
37 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType);
38 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType);
39 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType);
40 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType);
41 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType);
42 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType);
43 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType);
44 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040045 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType);
46 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType);
47 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType);
48 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType);
49 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType);
50 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050051
52 //
53 // Exponential Functions.
54 //
Nicolas Capens33cda112015-02-24 17:35:47 -050055 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType);
56 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType);
57 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType);
58 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType);
59 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType);
60 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType);
61 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050062
63 //
64 // Common Functions.
65 //
Nicolas Capens33cda112015-02-24 17:35:47 -050066 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040067 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType);
Nicolas Capens33cda112015-02-24 17:35:47 -050068 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040069 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType);
Nicolas Capens33cda112015-02-24 17:35:47 -050070 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040071 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType);
72 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType);
73 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType);
Nicolas Capens33cda112015-02-24 17:35:47 -050074 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType);
75 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType);
76 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1);
77 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType);
78 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1);
79 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040080 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType);
81 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1);
82 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType);
83 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1);
Nicolas Capens33cda112015-02-24 17:35:47 -050084 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1);
85 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040086 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType);
87 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1);
88 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType);
89 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1);
Nicolas Capens33cda112015-02-24 17:35:47 -050090 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1);
91 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType);
Alexis Hetu2205c202015-04-16 10:38:41 -040092 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1);
93 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType);
94 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1);
95 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType);
Nicolas Capens33cda112015-02-24 17:35:47 -050096 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1);
97 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType);
98 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType);
99 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType);
100 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType);
101 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500102
Alexis Hetu7d6b34d2016-05-03 11:30:57 -0400103 TType *outFloat1 = new TType(EbtFloat, EbpUndefined, EvqOut);
104 TType *outFloat2 = new TType(EbtFloat, EbpUndefined, EvqOut, 2);
105 TType *outFloat3 = new TType(EbtFloat, EbpUndefined, EvqOut, 3);
106 TType *outFloat4 = new TType(EbtFloat, EbpUndefined, EvqOut, 4);
107
108 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1);
109 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2);
110 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float3, "modf", float3, outFloat3);
111 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float4, "modf", float4, outFloat4);
112
Alexis Hetu2205c202015-04-16 10:38:41 -0400113 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType);
114 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType);
115 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType);
116 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType);
117 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400118 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
119
Alexis Hetu2205c202015-04-16 10:38:41 -0400120 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2);
121 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2);
122 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2);
123 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1);
124 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1);
125 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1);
126
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500127 //
128 // Geometric Functions.
129 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500130 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType);
131 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType);
132 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType);
133 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3);
134 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType);
135 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType);
136 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
137 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400138
Alexis Hetub14178b2015-04-13 13:23:20 -0400139 TType *mat2 = new TType(EbtFloat, 2, 2);
Alexis Hetu2205c202015-04-16 10:38:41 -0400140 TType *mat2x3 = new TType(EbtFloat, 2, 3);
141 TType *mat2x4 = new TType(EbtFloat, 2, 4);
142 TType *mat3x2 = new TType(EbtFloat, 3, 2);
Alexis Hetub14178b2015-04-13 13:23:20 -0400143 TType *mat3 = new TType(EbtFloat, 3, 3);
Alexis Hetu2205c202015-04-16 10:38:41 -0400144 TType *mat3x4 = new TType(EbtFloat, 3, 4);
145 TType *mat4x2 = new TType(EbtFloat, 4, 2);
146 TType *mat4x3 = new TType(EbtFloat, 4, 3);
Alexis Hetub14178b2015-04-13 13:23:20 -0400147 TType *mat4 = new TType(EbtFloat, 4, 4);
John Bauman66b8ab22014-05-06 15:57:45 -0400148
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500149 //
150 // Matrix Functions.
151 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500152 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2);
153 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3);
154 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4);
Alexis Hetu2205c202015-04-16 10:38:41 -0400155 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3);
156 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2);
157 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4);
158 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2);
159 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400160 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
161
Alexis Hetu2205c202015-04-16 10:38:41 -0400162 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2);
163 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3);
164 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4);
165 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2);
166 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3);
167 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2);
168 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4);
169 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400170 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
171
Alexis Hetu2205c202015-04-16 10:38:41 -0400172 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2);
173 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3);
174 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4);
175 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2);
176 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3);
177 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2);
178 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4);
179 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400180 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
181
Alexis Hetu2205c202015-04-16 10:38:41 -0400182 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2);
183 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400184 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
185
Alexis Hetu2205c202015-04-16 10:38:41 -0400186 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2);
187 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400188 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
Alexis Hetu2205c202015-04-16 10:38:41 -0400189
John Bauman66b8ab22014-05-06 15:57:45 -0400190
Nicolas Capens70da3d42015-02-18 16:58:10 -0500191 TType *bool1 = new TType(EbtBool);
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500192 TType *vec = new TType(EbtVec);
193 TType *ivec = new TType(EbtIVec);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400194 TType *uvec = new TType(EbtUVec);
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500195 TType *bvec = new TType(EbtBVec);
John Bauman66b8ab22014-05-06 15:57:45 -0400196
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500197 //
198 // Vector relational functions.
199 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500200 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec);
201 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400202 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500203 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec);
204 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400205 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500206 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec);
207 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400208 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500209 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec);
210 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400211 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500212 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec);
213 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400214 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500215 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec);
216 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec);
217 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400218 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500219 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec);
220 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec);
221 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
222 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
John Bauman66b8ab22014-05-06 15:57:45 -0400223
Nicolas Capens70da3d42015-02-18 16:58:10 -0500224 TType *sampler2D = new TType(EbtSampler2D);
225 TType *samplerCube = new TType(EbtSamplerCube);
226 TType *sampler3D = new TType(EbtSampler3D);
John Bauman66b8ab22014-05-06 15:57:45 -0400227
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500228 //
229 // Texture Functions for GLSL ES 1.0
230 //
231 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
232 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
233 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
234 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
235 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3);
236
237 if(resources.OES_EGL_image_external)
238 {
Nicolas Capens70da3d42015-02-18 16:58:10 -0500239 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500240
241 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
242 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
243 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
244 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3);
245 }
John Bauman66b8ab22014-05-06 15:57:45 -0400246
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500247 if(type == GL_FRAGMENT_SHADER)
John Bauman66b8ab22014-05-06 15:57:45 -0400248 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500249 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
250 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
251 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
252 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400253
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500254 if(resources.OES_standard_derivatives)
John Baumand4ae8632014-05-06 16:18:33 -0400255 {
Nicolas Capens18d5ef92015-02-24 17:38:08 -0500256 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType);
257 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType);
258 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth,"GL_OES_standard_derivatives", genType, "fwidth", genType);
John Baumand4ae8632014-05-06 16:18:33 -0400259 }
260 }
John Bauman66b8ab22014-05-06 15:57:45 -0400261
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500262 if(type == GL_VERTEX_SHADER)
John Baumand4ae8632014-05-06 16:18:33 -0400263 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500264 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
265 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
266 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
267 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
268 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1);
John Baumand4ae8632014-05-06 16:18:33 -0400269 }
John Bauman66b8ab22014-05-06 15:57:45 -0400270
Nicolas Capens82cd6d82015-02-18 17:53:39 -0500271 TType *gvec4 = new TType(EbtGVec4);
272
273 TType *gsampler2D = new TType(EbtGSampler2D);
274 TType *gsamplerCube = new TType(EbtGSamplerCube);
275 TType *gsampler3D = new TType(EbtGSampler3D);
276 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
277
278 //
279 // Texture Functions for GLSL ES 3.0
280 //
281 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
282 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
283 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
284 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
285 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
286 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
287 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
288 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
289 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
290 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
291 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
292
293 if(type == GL_FRAGMENT_SHADER)
294 {
295 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
296 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
297 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
298 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
299 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
300 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
301 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
302 }
303
Alexis Hetub5332c52015-06-04 13:04:17 -0400304 TType *sampler2DShadow = new TType(EbtSampler2DShadow);
305 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
306 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
307
308 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
309 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
310 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
311 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
312 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
313
314 if(type == GL_FRAGMENT_SHADER)
315 {
316 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
317 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
318 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
319 }
320
321 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
322 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
323 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
324 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
325 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
326 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
327 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
328
329 if(type == GL_FRAGMENT_SHADER)
330 {
331 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType);
332 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType);
333 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType);
334 }
335
336 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
337 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
338 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
339 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
340
341 if(type == GL_FRAGMENT_SHADER)
342 {
343 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
344 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
345 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
346 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
347 }
348
349 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
350 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
351 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
352 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
353
354 if(type == GL_FRAGMENT_SHADER)
355 {
356 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
357 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
358 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
359 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
360 }
361
362 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
363 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
364 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
365 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
366
367 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
368 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
369 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
370 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
371
372 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
373 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
374 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
375 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
376
377 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
378 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
379 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
380
381 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
382 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
383 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
384
385 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
386 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
387 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
388 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
389 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
390 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
391 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
392
393 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
394 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
395 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
396 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
397 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
398
399 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
400 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
401 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
402 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
403
404 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
405 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
406 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
407 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
408
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500409 //
410 // Depth range in window coordinates
411 //
Alexis Hetua8b364b2015-06-10 11:48:40 -0400412 TFieldList *fields = NewPoolTFieldList();
Alexis Hetu253fdd12015-07-07 15:12:46 -0400413 TSourceLoc zeroSourceLoc = { 0, 0, 0, 0 };
414 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
415 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
416 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
Alexis Hetua8b364b2015-06-10 11:48:40 -0400417 fields->push_back(near);
418 fields->push_back(far);
419 fields->push_back(diff);
420 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
421 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capense2858652015-02-18 15:30:51 -0500422 symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
Alexis Hetua8b364b2015-06-10 11:48:40 -0400423 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
John Baumand4ae8632014-05-06 16:18:33 -0400424 depthRange->setQualifier(EvqUniform);
Nicolas Capense2858652015-02-18 15:30:51 -0500425 symbolTable.insert(COMMON_BUILTINS, *depthRange);
John Bauman66b8ab22014-05-06 15:57:45 -0400426
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500427 //
428 // Implementation dependent built-in constants.
429 //
430 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
Nicolas Capense2858652015-02-18 15:30:51 -0500431 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
Nicolas Capense2858652015-02-18 15:30:51 -0500432 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
433 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
434 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
435 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500436 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
437 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
Alexis Hetu6743bbf2015-04-21 17:06:14 -0400438 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
439 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
440 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
441 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
John Bauman66b8ab22014-05-06 15:57:45 -0400442}
443
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500444void IdentifyBuiltIns(GLenum shaderType,
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500445 const ShBuiltInResources &resources,
John Baumand4ae8632014-05-06 16:18:33 -0400446 TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -0400447{
448 //
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400449 // First, insert some special built-in variables that are not in
John Bauman66b8ab22014-05-06 15:57:45 -0400450 // the built-in header files.
451 //
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500452 switch(shaderType)
453 {
454 case GL_FRAGMENT_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500455 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
456 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
457 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
458 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
459 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
Alexis Hetufe30f672015-09-21 08:03:54 -0400460 symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepth"), TType(EbtFloat, EbpHigh, EvqFragDepth, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400461 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500462 case GL_VERTEX_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500463 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
464 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
Alexis Hetu6743bbf2015-04-21 17:06:14 -0400465 symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EbpHigh, EvqInstanceID, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400466 break;
467 default: assert(false && "Language not supported");
468 }
469
John Bauman66b8ab22014-05-06 15:57:45 -0400470 // Finally add resource-specific variables.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500471 switch(shaderType)
John Bauman66b8ab22014-05-06 15:57:45 -0400472 {
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500473 case GL_FRAGMENT_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400474 {
475 // Set up gl_FragData. The array size.
Alexis Hetub14178b2015-04-13 13:23:20 -0400476 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
John Bauman66b8ab22014-05-06 15:57:45 -0400477 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500478 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
John Bauman66b8ab22014-05-06 15:57:45 -0400479 }
480 break;
481 default: break;
482 }
483}
484
485void InitExtensionBehavior(const ShBuiltInResources& resources,
486 TExtensionBehavior& extBehavior)
487{
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500488 if(resources.OES_standard_derivatives)
John Bauman66b8ab22014-05-06 15:57:45 -0400489 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500490 if(resources.OES_fragment_precision_high)
John Baumand4ae8632014-05-06 16:18:33 -0400491 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500492 if(resources.OES_EGL_image_external)
493 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400494 if(resources.EXT_draw_buffers)
495 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
John Bauman66b8ab22014-05-06 15:57:45 -0400496}