blob: 63088a3f8f412b32e036e77381a9e0b732ae1936 [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 Hetu2205c202015-04-16 10:38:41 -0400103 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType);
104 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType);
105 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType);
106 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType);
107 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400108 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
109
Alexis Hetu2205c202015-04-16 10:38:41 -0400110 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2);
111 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2);
112 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2);
113 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1);
114 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1);
115 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1);
116
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500117 //
118 // Geometric Functions.
119 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500120 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType);
121 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType);
122 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType);
123 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3);
124 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType);
125 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType);
126 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
127 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400128
Alexis Hetub14178b2015-04-13 13:23:20 -0400129 TType *mat2 = new TType(EbtFloat, 2, 2);
Alexis Hetu2205c202015-04-16 10:38:41 -0400130 TType *mat2x3 = new TType(EbtFloat, 2, 3);
131 TType *mat2x4 = new TType(EbtFloat, 2, 4);
132 TType *mat3x2 = new TType(EbtFloat, 3, 2);
Alexis Hetub14178b2015-04-13 13:23:20 -0400133 TType *mat3 = new TType(EbtFloat, 3, 3);
Alexis Hetu2205c202015-04-16 10:38:41 -0400134 TType *mat3x4 = new TType(EbtFloat, 3, 4);
135 TType *mat4x2 = new TType(EbtFloat, 4, 2);
136 TType *mat4x3 = new TType(EbtFloat, 4, 3);
Alexis Hetub14178b2015-04-13 13:23:20 -0400137 TType *mat4 = new TType(EbtFloat, 4, 4);
John Bauman66b8ab22014-05-06 15:57:45 -0400138
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500139 //
140 // Matrix Functions.
141 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500142 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2);
143 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3);
144 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4);
Alexis Hetu2205c202015-04-16 10:38:41 -0400145 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3);
146 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2);
147 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4);
148 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2);
149 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400150 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
151
Alexis Hetu2205c202015-04-16 10:38:41 -0400152 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2);
153 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3);
154 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4);
155 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2);
156 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3);
157 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2);
158 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4);
159 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400160 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
161
Alexis Hetu2205c202015-04-16 10:38:41 -0400162 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2);
163 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3);
164 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4);
165 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2);
166 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3);
167 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2);
168 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4);
169 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400170 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
171
Alexis Hetu2205c202015-04-16 10:38:41 -0400172 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2);
173 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400174 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
175
Alexis Hetu2205c202015-04-16 10:38:41 -0400176 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2);
177 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400178 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
Alexis Hetu2205c202015-04-16 10:38:41 -0400179
John Bauman66b8ab22014-05-06 15:57:45 -0400180
Nicolas Capens70da3d42015-02-18 16:58:10 -0500181 TType *bool1 = new TType(EbtBool);
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500182 TType *vec = new TType(EbtVec);
183 TType *ivec = new TType(EbtIVec);
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400184 TType *uvec = new TType(EbtUVec);
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500185 TType *bvec = new TType(EbtBVec);
John Bauman66b8ab22014-05-06 15:57:45 -0400186
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500187 //
188 // Vector relational functions.
189 //
Nicolas Capens33cda112015-02-24 17:35:47 -0500190 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec);
191 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400192 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500193 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec);
194 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400195 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500196 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec);
197 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400198 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500199 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec);
200 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400201 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500202 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec);
203 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400204 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500205 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec);
206 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec);
207 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec);
Alexis Hetu2205c202015-04-16 10:38:41 -0400208 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec);
Nicolas Capens33cda112015-02-24 17:35:47 -0500209 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec);
210 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec);
211 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
212 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
John Bauman66b8ab22014-05-06 15:57:45 -0400213
Nicolas Capens70da3d42015-02-18 16:58:10 -0500214 TType *sampler2D = new TType(EbtSampler2D);
215 TType *samplerCube = new TType(EbtSamplerCube);
216 TType *sampler3D = new TType(EbtSampler3D);
John Bauman66b8ab22014-05-06 15:57:45 -0400217
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500218 //
219 // Texture Functions for GLSL ES 1.0
220 //
221 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
222 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
223 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
224 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
225 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3);
226
227 if(resources.OES_EGL_image_external)
228 {
Nicolas Capens70da3d42015-02-18 16:58:10 -0500229 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500230
231 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
232 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
233 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
234 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3);
235 }
John Bauman66b8ab22014-05-06 15:57:45 -0400236
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500237 if(type == GL_FRAGMENT_SHADER)
John Bauman66b8ab22014-05-06 15:57:45 -0400238 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500239 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
240 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
241 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
242 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400243
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500244 if(resources.OES_standard_derivatives)
John Baumand4ae8632014-05-06 16:18:33 -0400245 {
Nicolas Capens18d5ef92015-02-24 17:38:08 -0500246 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType);
247 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType);
248 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth,"GL_OES_standard_derivatives", genType, "fwidth", genType);
John Baumand4ae8632014-05-06 16:18:33 -0400249 }
250 }
John Bauman66b8ab22014-05-06 15:57:45 -0400251
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500252 if(type == GL_VERTEX_SHADER)
John Baumand4ae8632014-05-06 16:18:33 -0400253 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500254 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
255 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
256 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
257 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
258 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1);
John Baumand4ae8632014-05-06 16:18:33 -0400259 }
John Bauman66b8ab22014-05-06 15:57:45 -0400260
Nicolas Capens82cd6d82015-02-18 17:53:39 -0500261 TType *gvec4 = new TType(EbtGVec4);
262
263 TType *gsampler2D = new TType(EbtGSampler2D);
264 TType *gsamplerCube = new TType(EbtGSamplerCube);
265 TType *gsampler3D = new TType(EbtGSampler3D);
266 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
267
268 //
269 // Texture Functions for GLSL ES 3.0
270 //
271 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
272 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
273 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
274 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
275 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
276 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
277 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
278 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
279 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
280 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
281 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
282
283 if(type == GL_FRAGMENT_SHADER)
284 {
285 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
286 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
287 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
288 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
289 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
290 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
291 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
292 }
293
Alexis Hetub5332c52015-06-04 13:04:17 -0400294 TType *sampler2DShadow = new TType(EbtSampler2DShadow);
295 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
296 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
297
298 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
299 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
300 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
301 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
302 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
303
304 if(type == GL_FRAGMENT_SHADER)
305 {
306 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
307 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
308 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
309 }
310
311 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
312 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
313 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
314 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
315 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
316 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
317 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
318
319 if(type == GL_FRAGMENT_SHADER)
320 {
321 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType);
322 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType);
323 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType);
324 }
325
326 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
327 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
328 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
329 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
330
331 if(type == GL_FRAGMENT_SHADER)
332 {
333 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
334 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
335 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
336 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
337 }
338
339 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
340 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
341 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
342 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
343
344 if(type == GL_FRAGMENT_SHADER)
345 {
346 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
347 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
348 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
349 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
350 }
351
352 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
353 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
354 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
355 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
356
357 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
358 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
359 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
360 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
361
362 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
363 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
364 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
365 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
366
367 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
368 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
369 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
370
371 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
372 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
373 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
374
375 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
376 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
377 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
378 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
379 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
380 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
381 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
382
383 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
384 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
385 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
386 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
387 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
388
389 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
390 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
391 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
392 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
393
394 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
395 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
396 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
397 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
398
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500399 //
400 // Depth range in window coordinates
401 //
Alexis Hetua8b364b2015-06-10 11:48:40 -0400402 TFieldList *fields = NewPoolTFieldList();
Alexis Hetu253fdd12015-07-07 15:12:46 -0400403 TSourceLoc zeroSourceLoc = { 0, 0, 0, 0 };
404 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
405 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
406 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
Alexis Hetua8b364b2015-06-10 11:48:40 -0400407 fields->push_back(near);
408 fields->push_back(far);
409 fields->push_back(diff);
410 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
411 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capense2858652015-02-18 15:30:51 -0500412 symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
Alexis Hetua8b364b2015-06-10 11:48:40 -0400413 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
John Baumand4ae8632014-05-06 16:18:33 -0400414 depthRange->setQualifier(EvqUniform);
Nicolas Capense2858652015-02-18 15:30:51 -0500415 symbolTable.insert(COMMON_BUILTINS, *depthRange);
John Bauman66b8ab22014-05-06 15:57:45 -0400416
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500417 //
418 // Implementation dependent built-in constants.
419 //
420 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
Nicolas Capense2858652015-02-18 15:30:51 -0500421 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
Nicolas Capense2858652015-02-18 15:30:51 -0500422 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
423 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
424 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
425 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500426 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
427 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
Alexis Hetu6743bbf2015-04-21 17:06:14 -0400428 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
429 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
430 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
431 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
John Bauman66b8ab22014-05-06 15:57:45 -0400432}
433
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500434void IdentifyBuiltIns(GLenum shaderType,
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500435 const ShBuiltInResources &resources,
John Baumand4ae8632014-05-06 16:18:33 -0400436 TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -0400437{
438 //
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400439 // First, insert some special built-in variables that are not in
John Bauman66b8ab22014-05-06 15:57:45 -0400440 // the built-in header files.
441 //
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500442 switch(shaderType)
443 {
444 case GL_FRAGMENT_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500445 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
446 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
447 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
448 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
449 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
Alexis Hetufe30f672015-09-21 08:03:54 -0400450 symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepth"), TType(EbtFloat, EbpHigh, EvqFragDepth, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400451 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500452 case GL_VERTEX_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500453 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
454 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
Alexis Hetu6743bbf2015-04-21 17:06:14 -0400455 symbolTable.insert(ESSL3_BUILTINS, *new TVariable(NewPoolTString("gl_InstanceID"), TType(EbtInt, EbpHigh, EvqInstanceID, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400456 break;
457 default: assert(false && "Language not supported");
458 }
459
John Bauman66b8ab22014-05-06 15:57:45 -0400460 // Finally add resource-specific variables.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500461 switch(shaderType)
John Bauman66b8ab22014-05-06 15:57:45 -0400462 {
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500463 case GL_FRAGMENT_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400464 {
465 // Set up gl_FragData. The array size.
Alexis Hetub14178b2015-04-13 13:23:20 -0400466 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
John Bauman66b8ab22014-05-06 15:57:45 -0400467 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500468 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
John Bauman66b8ab22014-05-06 15:57:45 -0400469 }
470 break;
471 default: break;
472 }
473}
474
475void InitExtensionBehavior(const ShBuiltInResources& resources,
476 TExtensionBehavior& extBehavior)
477{
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500478 if(resources.OES_standard_derivatives)
John Bauman66b8ab22014-05-06 15:57:45 -0400479 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500480 if(resources.OES_fragment_precision_high)
John Baumand4ae8632014-05-06 16:18:33 -0400481 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500482 if(resources.OES_EGL_image_external)
483 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
Nicolas Capensc66f0e32016-04-18 14:34:24 -0400484 if(resources.EXT_draw_buffers)
485 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
John Bauman66b8ab22014-05-06 15:57:45 -0400486}