blob: 0219e4ebcd81680c3f09bc0f6c0e69379fba4dea [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens1fbc2872014-01-03 14:12:09 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7//
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -05008// Create symbols that declare built-in definitions, add built-ins that
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009// cannot be expressed in the files, and establish mappings between
10// built-in functions and operators.
11//
12
Geoff Lang17732822013-08-29 13:46:49 -040013#include "compiler/translator/Initialize.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014
Jamie Madillb1a85f42014-08-19 15:23:24 -040015#include "compiler/translator/IntermNode.h"
Jamie Madill183bde52014-07-02 15:31:19 -040016#include "angle_gl.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017
Jamie Madill183bde52014-07-02 15:31:19 -040018void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019{
Nicolas Capensc9508842014-02-14 17:48:50 -050020 TType *float1 = new TType(EbtFloat);
21 TType *float2 = new TType(EbtFloat, 2);
22 TType *float3 = new TType(EbtFloat, 3);
23 TType *float4 = new TType(EbtFloat, 4);
Nicolas Capensc9508842014-02-14 17:48:50 -050024 TType *int1 = new TType(EbtInt);
25 TType *int2 = new TType(EbtInt, 2);
26 TType *int3 = new TType(EbtInt, 3);
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -050027 TType *uint1 = new TType(EbtUInt);
28 TType *bool1 = new TType(EbtBool);
29 TType *genType = new TType(EbtGenType);
30 TType *genIType = new TType(EbtGenIType);
31 TType *genUType = new TType(EbtGenUType);
32 TType *genBType = new TType(EbtGenBType);
alokp@chromium.orge4249f02010-07-26 18:13:52 +000033
daniel@transgaming.com0578f812010-05-17 09:58:39 +000034 //
alokp@chromium.orge4249f02010-07-26 18:13:52 +000035 // Angle and Trigonometric Functions.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000036 //
Nicolas Capens482907e2015-02-23 16:56:33 -050037 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType);
38 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType);
39 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType);
40 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType);
41 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType);
42 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType);
43 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType);
44 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType);
45 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType);
46 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType);
47 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType);
48 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType);
49 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType);
50 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType);
51 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType);
Olli Etuaho5c9cd3d2014-12-18 13:04:25 +020052
alokp@chromium.orge4249f02010-07-26 18:13:52 +000053 //
54 // Exponential Functions.
55 //
Nicolas Capens482907e2015-02-23 16:56:33 -050056 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType);
57 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType);
58 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType);
59 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType);
60 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType);
61 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType);
62 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063
alokp@chromium.orge4249f02010-07-26 18:13:52 +000064 //
65 // Common Functions.
66 //
Nicolas Capens482907e2015-02-23 16:56:33 -050067 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType);
68 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType);
69 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType);
70 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType);
71 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType);
Qingqing Deng5dbece52015-02-27 20:35:38 -080072 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType);
73 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType);
74 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType);
Nicolas Capens482907e2015-02-23 16:56:33 -050075 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType);
76 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType);
77 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1);
78 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType);
79 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1);
80 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType);
81 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType);
82 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1);
Arun Patole77490052015-03-03 18:36:05 +053083 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType);
Nicolas Capens482907e2015-02-23 16:56:33 -050084 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1);
85 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1);
86 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType);
87 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType);
88 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1);
89 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType);
90 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1);
91 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1);
92 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType);
93 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1);
94 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType);
95 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1);
96 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType);
97 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1);
98 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType);
Arun Patoled94f6642015-05-18 16:25:12 +053099 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMix, genType, "mix", genType, genType, genBType);
Nicolas Capens482907e2015-02-23 16:56:33 -0500100 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType);
101 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType);
102 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType);
103 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000104
Olli Etuahob6e07a62015-02-16 12:22:10 +0200105 TType *outFloat1 = new TType(EbtFloat);
106 TType *outFloat2 = new TType(EbtFloat, 2);
107 TType *outFloat3 = new TType(EbtFloat, 3);
108 TType *outFloat4 = new TType(EbtFloat, 4);
109 outFloat1->setQualifier(EvqOut);
110 outFloat2->setQualifier(EvqOut);
111 outFloat3->setQualifier(EvqOut);
112 outFloat4->setQualifier(EvqOut);
113
Nicolas Capens482907e2015-02-23 16:56:33 -0500114 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1);
115 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2);
116 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float3, "modf", float3, outFloat3);
117 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float4, "modf", float4, outFloat4);
Olli Etuahob6e07a62015-02-16 12:22:10 +0200118
Nicolas Capens482907e2015-02-23 16:56:33 -0500119 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType);
120 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType);
121 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType);
122 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType);
123 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType);
124 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
Olli Etuahoe8d2c072015-01-08 16:33:54 +0200125
Nicolas Capens482907e2015-02-23 16:56:33 -0500126 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2);
127 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2);
128 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2);
129 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1);
130 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1);
131 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1);
Olli Etuaho7700ff62015-01-15 12:16:29 +0200132
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000133 //
134 // Geometric Functions.
135 //
Nicolas Capens482907e2015-02-23 16:56:33 -0500136 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType);
137 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType);
138 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType);
139 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3);
140 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType);
141 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType);
142 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
143 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400144
Nicolas Capensc9508842014-02-14 17:48:50 -0500145 TType *mat2 = new TType(EbtFloat, 2, 2);
146 TType *mat3 = new TType(EbtFloat, 3, 3);
147 TType *mat4 = new TType(EbtFloat, 4, 4);
Olli Etuahoe39706d2014-12-30 16:40:36 +0200148 TType *mat2x3 = new TType(EbtFloat, 2, 3);
149 TType *mat3x2 = new TType(EbtFloat, 3, 2);
150 TType *mat2x4 = new TType(EbtFloat, 2, 4);
151 TType *mat4x2 = new TType(EbtFloat, 4, 2);
152 TType *mat3x4 = new TType(EbtFloat, 3, 4);
153 TType *mat4x3 = new TType(EbtFloat, 4, 3);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000154
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000155 //
156 // Matrix Functions.
157 //
Nicolas Capens482907e2015-02-23 16:56:33 -0500158 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2);
159 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3);
160 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4);
161 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3);
162 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2);
163 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4);
164 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2);
165 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4);
166 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
Olli Etuahoe39706d2014-12-30 16:40:36 +0200167
Nicolas Capens482907e2015-02-23 16:56:33 -0500168 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2);
169 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3);
170 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4);
171 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2);
172 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3);
173 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2);
174 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4);
175 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3);
176 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
Olli Etuahoe39706d2014-12-30 16:40:36 +0200177
Nicolas Capens482907e2015-02-23 16:56:33 -0500178 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2);
179 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3);
180 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4);
181 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2);
182 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3);
183 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2);
184 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4);
185 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3);
186 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
Olli Etuahoe39706d2014-12-30 16:40:36 +0200187
Nicolas Capens482907e2015-02-23 16:56:33 -0500188 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2);
189 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3);
190 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400191
Nicolas Capens482907e2015-02-23 16:56:33 -0500192 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2);
193 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
194 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
Olli Etuahoabf6dad2015-01-14 14:45:16 +0200195
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500196 TType *vec = new TType(EbtVec);
197 TType *ivec = new TType(EbtIVec);
198 TType *uvec = new TType(EbtUVec);
199 TType *bvec = new TType(EbtBVec);
200
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000201 //
202 // Vector relational functions.
203 //
Nicolas Capens482907e2015-02-23 16:56:33 -0500204 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec);
205 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec);
206 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec);
207 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec);
208 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec);
209 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec);
210 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec);
211 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec);
212 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec);
213 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec);
214 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec);
215 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec);
216 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec);
217 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec);
218 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec);
219 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec);
220 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec);
221 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec);
222 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec);
223 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec);
224 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec);
225 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
226 symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227
Nicolas Capensc9508842014-02-14 17:48:50 -0500228 TType *sampler2D = new TType(EbtSampler2D);
229 TType *samplerCube = new TType(EbtSamplerCube);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000230
231 //
232 // Texture Functions for GLSL ES 1.0
233 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400234 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
235 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
236 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
237 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000238
Nicolas Capens49a88872013-06-20 09:54:03 -0400239 if (resources.OES_EGL_image_external)
240 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500241 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens49a88872013-06-20 09:54:03 -0400242
Nicolas Capens8f80e022013-07-11 11:20:50 -0400243 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
244 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
245 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000246 }
247
Nicolas Capens49a88872013-06-20 09:54:03 -0400248 if (resources.ARB_texture_rectangle)
249 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500250 TType *sampler2DRect = new TType(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400251
Nicolas Capens8f80e022013-07-11 11:20:50 -0400252 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
253 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
254 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000255 }
256
Nicolas Capens46485082014-04-15 13:12:50 -0400257 if (resources.EXT_shader_texture_lod)
258 {
259 /* The *Grad* variants are new to both vertex and fragment shaders; the fragment
260 * shader specific pieces are added separately below.
261 */
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500262 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DGradEXT", sampler2D, float2, float2, float2);
263 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2);
264 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2);
265 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeGradEXT", samplerCube, float3, float3, float3);
Nicolas Capens46485082014-04-15 13:12:50 -0400266 }
267
Jamie Madill183bde52014-07-02 15:31:19 -0400268 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400269 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400270 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
271 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
272 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
273 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000274
Nicolas Capens49a88872013-06-20 09:54:03 -0400275 if (resources.OES_standard_derivatives)
276 {
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500277 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType);
278 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType);
279 symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth, "GL_OES_standard_derivatives", genType, "fwidth", genType);
Nicolas Capens49a88872013-06-20 09:54:03 -0400280 }
Nicolas Capens46485082014-04-15 13:12:50 -0400281
282 if (resources.EXT_shader_texture_lod)
283 {
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500284 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DLodEXT", sampler2D, float2, float1);
285 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float3, float1);
286 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float4, float1);
287 symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeLodEXT", samplerCube, float3, float1);
Nicolas Capens46485082014-04-15 13:12:50 -0400288 }
Nicolas Capens49a88872013-06-20 09:54:03 -0400289 }
290
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500291 if (type == GL_VERTEX_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400292 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400293 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
294 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
295 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
296 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400297 }
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000298
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500299 TType *gvec4 = new TType(EbtGVec4);
300
301 TType *gsampler2D = new TType(EbtGSampler2D);
302 TType *gsamplerCube = new TType(EbtGSamplerCube);
303 TType *gsampler3D = new TType(EbtGSampler3D);
304 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400305
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000306 //
307 // Texture Functions for GLSL ES 3.0
308 //
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500309 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
310 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
311 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
312 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
313 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
314 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
315 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
316 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
317 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
318 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
319 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000320
Jamie Madill183bde52014-07-02 15:31:19 -0400321 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens67a819f2013-07-09 12:08:58 -0400322 {
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500323 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
324 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
325 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
326 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
327 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
328 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
329 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400330 }
331
Nicolas Capensc9508842014-02-14 17:48:50 -0500332 TType *sampler2DShadow = new TType(EbtSampler2DShadow);
333 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
334 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400335
Nicolas Capens8f80e022013-07-11 11:20:50 -0400336 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
337 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
338 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
339 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400340 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400341
Jamie Madill183bde52014-07-02 15:31:19 -0400342 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400343 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400344 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
345 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400346 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400347 }
348
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500349 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
350 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
351 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
352 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400353 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
354 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
355 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
Nicolas Capens75fb4752013-07-10 15:14:47 -0400356
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500357 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400358 {
Olli Etuaho687ef222015-03-03 10:58:05 +0200359 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType);
360 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType);
361 symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType);
alokp@chromium.org06098892010-08-26 19:36:42 +0000362 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000363
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500364 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
365 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
366 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
367 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
368
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500369 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500370 {
371 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
372 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
373 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
374 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
375 }
Nicolas Capens1fbc2872014-01-03 14:12:09 -0500376
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500377 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
378 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
379 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
380 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
381
Nicolas Capensf3cc4ae2015-02-23 13:51:25 -0500382 if (type == GL_FRAGMENT_SHADER)
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500383 {
384 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
385 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
386 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
387 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
388 }
389
390 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
391 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
392 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
393 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
394
Nicolas Capens2adc2562014-02-14 23:50:59 -0500395 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
396 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
397 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
398 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
399
400 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
401 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
402 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
403 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
404
Nicolas Capensfc014542014-02-18 14:47:13 -0500405 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
406 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
407 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
408
409 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
410 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
411 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
412
Nicolas Capensd11d5492014-02-19 17:06:10 -0500413 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
414 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
415 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
416 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
417 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
418 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
419 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
420
Nicolas Capensbf7db102014-02-19 17:20:28 -0500421 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
422 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
423 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
424 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
425 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
426
Nicolas Capensf7378e32014-02-19 17:29:32 -0500427 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
428 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
429 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
430 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
431
432 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
433 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
434 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
435 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
436
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000437 //
438 // Depth range in window coordinates
439 //
Jamie Madill98493dd2013-07-08 14:39:03 -0400440 TFieldList *fields = NewPoolTFieldList();
Jamie Madill37f77d22014-04-30 16:10:13 -0400441 TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
Jamie Madill98493dd2013-07-08 14:39:03 -0400442 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
443 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
444 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
445 fields->push_back(near);
446 fields->push_back(far);
447 fields->push_back(diff);
448 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
449 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400450 symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
Jamie Madill98493dd2013-07-08 14:39:03 -0400451 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
Nicolas Capens49a88872013-06-20 09:54:03 -0400452 depthRange->setQualifier(EvqUniform);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400453 symbolTable.insert(COMMON_BUILTINS, depthRange);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000454
Nicolas Capens49a88872013-06-20 09:54:03 -0400455 //
456 // Implementation dependent built-in constants.
457 //
458 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
459 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
460 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
461 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
462 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
463 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000464
Nicolas Capens49a88872013-06-20 09:54:03 -0400465 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000466
467 if (spec != SH_CSS_SHADERS_SPEC)
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000468 {
Jamie Madill455a6f52013-10-17 10:45:46 -0400469 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000470 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000471
Nicolas Capens49a88872013-06-20 09:54:03 -0400472 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
473 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
474 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
475 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000476}
477
Jamie Madill183bde52014-07-02 15:31:19 -0400478void IdentifyBuiltIns(sh::GLenum type, ShShaderSpec spec,
Nicolas Capens49a88872013-06-20 09:54:03 -0400479 const ShBuiltInResources &resources,
480 TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000481{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000482 //
Olli Etuaho4f52da42015-03-11 10:48:41 +0200483 // Insert some special built-in variables that are not in
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000484 // the built-in header files.
485 //
Olli Etuaho61ffec82015-03-11 10:35:01 +0200486 switch (type)
487 {
488 case GL_FRAGMENT_SHADER:
489 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"),
490 TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
491 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"),
492 TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
493 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"),
494 TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000495
496 //
497 // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
498 // Instead, css_MixColor and css_ColorMatrix are available.
499 //
Olli Etuaho61ffec82015-03-11 10:35:01 +0200500 if (spec != SH_CSS_SHADERS_SPEC)
501 {
502 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"),
503 TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
Olli Etuaho4f52da42015-03-11 10:48:41 +0200504 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
505 fragData.setArraySize(resources.MaxDrawBuffers);
506 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
507
Olli Etuaho61ffec82015-03-11 10:35:01 +0200508 if (resources.EXT_frag_depth)
509 {
510 symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_frag_depth", new TVariable(NewPoolTString("gl_FragDepthEXT"),
511 TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400512 }
Olli Etuaho4f52da42015-03-11 10:48:41 +0200513
514 if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch)
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100515 {
Olli Etuaho4f52da42015-03-11 10:48:41 +0200516 TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
517 lastFragData.setArraySize(resources.MaxDrawBuffers);
518
519 if (resources.EXT_shader_framebuffer_fetch)
520 {
521 symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch",
522 new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
523 }
524 else if (resources.NV_shader_framebuffer_fetch)
525 {
526 symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
527 new TVariable(NewPoolTString("gl_LastFragColor"),
528 TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
529 symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
530 new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
531 }
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100532 }
533 else if (resources.ARM_shader_framebuffer_fetch)
534 {
Olli Etuaho61ffec82015-03-11 10:35:01 +0200535 symbolTable.insert(ESSL1_BUILTINS, "GL_ARM_shader_framebuffer_fetch",
536 new TVariable(NewPoolTString("gl_LastFragColorARM"),
537 TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100538 }
Olli Etuaho61ffec82015-03-11 10:35:01 +0200539 }
540 else
541 {
542 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_MixColor"),
543 TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
544 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"),
545 TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000546 }
547
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000548 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000549
Olli Etuaho61ffec82015-03-11 10:35:01 +0200550 case GL_VERTEX_SHADER:
551 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"),
552 TType(EbtFloat, EbpHigh, EvqPosition, 4)));
553 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"),
554 TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
555 symbolTable.insert(ESSL3_BUILTINS, new TVariable(NewPoolTString("gl_InstanceID"),
556 TType(EbtInt, EbpHigh, EvqInstanceID, 1)));
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000557 break;
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000558
Olli Etuaho61ffec82015-03-11 10:35:01 +0200559 default:
560 assert(false && "Language not supported");
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000561 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000562}
563
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000564void InitExtensionBehavior(const ShBuiltInResources& resources,
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000565 TExtensionBehavior& extBehavior)
566{
567 if (resources.OES_standard_derivatives)
zmo@google.com09c323a2011-08-12 18:22:25 +0000568 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
569 if (resources.OES_EGL_image_external)
570 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
kbr@chromium.org205fef32011-11-22 20:50:02 +0000571 if (resources.ARB_texture_rectangle)
572 extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
shannon.woods@transgaming.com550cd092013-02-28 23:19:54 +0000573 if (resources.EXT_draw_buffers)
574 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400575 if (resources.EXT_frag_depth)
576 extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
Nicolas Capens46485082014-04-15 13:12:50 -0400577 if (resources.EXT_shader_texture_lod)
578 extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined;
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100579 if (resources.EXT_shader_framebuffer_fetch)
580 extBehavior["GL_EXT_shader_framebuffer_fetch"] = EBhUndefined;
581 if (resources.NV_shader_framebuffer_fetch)
582 extBehavior["GL_NV_shader_framebuffer_fetch"] = EBhUndefined;
583 if (resources.ARM_shader_framebuffer_fetch)
584 extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000585}
David Yen0fbd1282015-02-02 14:46:09 -0800586
587void ResetExtensionBehavior(TExtensionBehavior &extBehavior)
588{
589 for (auto ext_iter = extBehavior.begin();
590 ext_iter != extBehavior.end();
591 ++ext_iter)
592 {
593 ext_iter->second = EBhUndefined;
594 }
595}