Line data Source code
1 : //
2 : // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
3 : // Use of this source code is governed by a BSD-style license that can be
4 : // found in the LICENSE file.
5 : //
6 :
7 : //
8 : // Create symbols that declare built-in definitions, add built-ins that
9 : // cannot be expressed in the files, and establish mappings between
10 : // built-in functions and operators.
11 : //
12 :
13 : #include "compiler/translator/Initialize.h"
14 : #include "compiler/translator/Cache.h"
15 :
16 : #include "compiler/translator/IntermNode.h"
17 : #include "angle_gl.h"
18 :
19 : namespace sh
20 : {
21 :
22 0 : void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
23 : {
24 0 : const TType *voidType = TCache::getType(EbtVoid);
25 0 : const TType *float1 = TCache::getType(EbtFloat);
26 0 : const TType *float2 = TCache::getType(EbtFloat, 2);
27 0 : const TType *float3 = TCache::getType(EbtFloat, 3);
28 0 : const TType *float4 = TCache::getType(EbtFloat, 4);
29 0 : const TType *int1 = TCache::getType(EbtInt);
30 0 : const TType *int2 = TCache::getType(EbtInt, 2);
31 0 : const TType *int3 = TCache::getType(EbtInt, 3);
32 0 : const TType *uint1 = TCache::getType(EbtUInt);
33 0 : const TType *bool1 = TCache::getType(EbtBool);
34 0 : const TType *genType = TCache::getType(EbtGenType);
35 0 : const TType *genIType = TCache::getType(EbtGenIType);
36 0 : const TType *genUType = TCache::getType(EbtGenUType);
37 0 : const TType *genBType = TCache::getType(EbtGenBType);
38 :
39 : //
40 : // Angle and Trigonometric Functions.
41 : //
42 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRadians, genType, "radians", genType);
43 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDegrees, genType, "degrees", genType);
44 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSin, genType, "sin", genType);
45 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCos, genType, "cos", genType);
46 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpTan, genType, "tan", genType);
47 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAsin, genType, "asin", genType);
48 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAcos, genType, "acos", genType);
49 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType, genType);
50 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAtan, genType, "atan", genType);
51 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSinh, genType, "sinh", genType);
52 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpCosh, genType, "cosh", genType);
53 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTanh, genType, "tanh", genType);
54 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAsinh, genType, "asinh", genType);
55 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAcosh, genType, "acosh", genType);
56 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAtanh, genType, "atanh", genType);
57 :
58 : //
59 : // Exponential Functions.
60 : //
61 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpPow, genType, "pow", genType, genType);
62 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp, genType, "exp", genType);
63 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog, genType, "log", genType);
64 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpExp2, genType, "exp2", genType);
65 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLog2, genType, "log2", genType);
66 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSqrt, genType, "sqrt", genType);
67 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpInverseSqrt, genType, "inversesqrt", genType);
68 :
69 : //
70 : // Common Functions.
71 : //
72 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAbs, genType, "abs", genType);
73 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpAbs, genIType, "abs", genIType);
74 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSign, genType, "sign", genType);
75 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpSign, genIType, "sign", genIType);
76 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFloor, genType, "floor", genType);
77 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTrunc, genType, "trunc", genType);
78 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRound, genType, "round", genType);
79 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpRoundEven, genType, "roundEven", genType);
80 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCeil, genType, "ceil", genType);
81 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFract, genType, "fract", genType);
82 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, float1);
83 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMod, genType, "mod", genType, genType);
84 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, float1);
85 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMin, genType, "min", genType, genType);
86 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, genIType);
87 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genIType, "min", genIType, int1);
88 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, genUType);
89 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMin, genUType, "min", genUType, uint1);
90 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, float1);
91 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMax, genType, "max", genType, genType);
92 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, genIType);
93 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genIType, "max", genIType, int1);
94 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, genUType);
95 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMax, genUType, "max", genUType, uint1);
96 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, float1, float1);
97 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpClamp, genType, "clamp", genType, genType, genType);
98 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, int1, int1);
99 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genIType, "clamp", genIType, genIType, genIType);
100 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, uint1, uint1);
101 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpClamp, genUType, "clamp", genUType, genUType, genUType);
102 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, float1);
103 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMix, genType, "mix", genType, genType, genType);
104 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMix, genType, "mix", genType, genType, genBType);
105 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", genType, genType);
106 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpStep, genType, "step", float1, genType);
107 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType);
108 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType);
109 :
110 0 : const TType *outFloat1 = TCache::getType(EbtFloat, EvqOut);
111 0 : const TType *outFloat2 = TCache::getType(EbtFloat, EvqOut, 2);
112 0 : const TType *outFloat3 = TCache::getType(EbtFloat, EvqOut, 3);
113 0 : const TType *outFloat4 = TCache::getType(EbtFloat, EvqOut, 4);
114 :
115 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1);
116 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2);
117 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float3, "modf", float3, outFloat3);
118 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float4, "modf", float4, outFloat4);
119 :
120 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsNan, genBType, "isnan", genType);
121 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIsInf, genBType, "isinf", genType);
122 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToInt, genIType, "floatBitsToInt", genType);
123 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFloatBitsToUint, genUType, "floatBitsToUint", genType);
124 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpIntBitsToFloat, genType, "intBitsToFloat", genIType);
125 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUintBitsToFloat, genType, "uintBitsToFloat", genUType);
126 :
127 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackSnorm2x16, uint1, "packSnorm2x16", float2);
128 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackUnorm2x16, uint1, "packUnorm2x16", float2);
129 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpPackHalf2x16, uint1, "packHalf2x16", float2);
130 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackSnorm2x16, float2, "unpackSnorm2x16", uint1);
131 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackUnorm2x16, float2, "unpackUnorm2x16", uint1);
132 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpUnpackHalf2x16, float2, "unpackHalf2x16", uint1);
133 :
134 : //
135 : // Geometric Functions.
136 : //
137 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLength, float1, "length", genType);
138 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDistance, float1, "distance", genType, genType);
139 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpDot, float1, "dot", genType, genType);
140 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpCross, float3, "cross", float3, float3);
141 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpNormalize, genType, "normalize", genType);
142 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpFaceForward, genType, "faceforward", genType, genType, genType);
143 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
144 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
145 :
146 0 : const TType *mat2 = TCache::getType(EbtFloat, 2, 2);
147 0 : const TType *mat3 = TCache::getType(EbtFloat, 3, 3);
148 0 : const TType *mat4 = TCache::getType(EbtFloat, 4, 4);
149 0 : const TType *mat2x3 = TCache::getType(EbtFloat, 2, 3);
150 0 : const TType *mat3x2 = TCache::getType(EbtFloat, 3, 2);
151 0 : const TType *mat2x4 = TCache::getType(EbtFloat, 2, 4);
152 0 : const TType *mat4x2 = TCache::getType(EbtFloat, 4, 2);
153 0 : const TType *mat3x4 = TCache::getType(EbtFloat, 3, 4);
154 0 : const TType *mat4x3 = TCache::getType(EbtFloat, 4, 3);
155 :
156 : //
157 : // Matrix Functions.
158 : //
159 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat2, "matrixCompMult", mat2, mat2);
160 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat3, "matrixCompMult", mat3, mat3);
161 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpMul, mat4, "matrixCompMult", mat4, mat4);
162 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x3, "matrixCompMult", mat2x3, mat2x3);
163 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x2, "matrixCompMult", mat3x2, mat3x2);
164 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat2x4, "matrixCompMult", mat2x4, mat2x4);
165 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x2, "matrixCompMult", mat4x2, mat4x2);
166 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat3x4, "matrixCompMult", mat3x4, mat3x4);
167 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpMul, mat4x3, "matrixCompMult", mat4x3, mat4x3);
168 :
169 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2, "outerProduct", float2, float2);
170 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3, "outerProduct", float3, float3);
171 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4, "outerProduct", float4, float4);
172 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x3, "outerProduct", float3, float2);
173 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x2, "outerProduct", float2, float3);
174 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat2x4, "outerProduct", float4, float2);
175 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x2, "outerProduct", float2, float4);
176 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat3x4, "outerProduct", float4, float3);
177 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpOuterProduct, mat4x3, "outerProduct", float3, float4);
178 :
179 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2, "transpose", mat2);
180 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3, "transpose", mat3);
181 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4, "transpose", mat4);
182 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x3, "transpose", mat3x2);
183 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x2, "transpose", mat2x3);
184 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat2x4, "transpose", mat4x2);
185 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x2, "transpose", mat2x4);
186 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat3x4, "transpose", mat4x3);
187 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpTranspose, mat4x3, "transpose", mat3x4);
188 :
189 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat2);
190 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat3);
191 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDeterminant, float1, "determinant", mat4);
192 :
193 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat2, "inverse", mat2);
194 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
195 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
196 :
197 0 : const TType *vec = TCache::getType(EbtVec);
198 0 : const TType *ivec = TCache::getType(EbtIVec);
199 0 : const TType *uvec = TCache::getType(EbtUVec);
200 0 : const TType *bvec = TCache::getType(EbtBVec);
201 :
202 : //
203 : // Vector relational functions.
204 : //
205 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", vec, vec);
206 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThan, bvec, "lessThan", ivec, ivec);
207 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThan, bvec, "lessThan", uvec, uvec);
208 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", vec, vec);
209 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", ivec, ivec);
210 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpLessThanEqual, bvec, "lessThanEqual", uvec, uvec);
211 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", vec, vec);
212 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThan, bvec, "greaterThan", ivec, ivec);
213 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThan, bvec, "greaterThan", uvec, uvec);
214 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", vec, vec);
215 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", ivec, ivec);
216 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpGreaterThanEqual, bvec, "greaterThanEqual", uvec, uvec);
217 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", vec, vec);
218 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", ivec, ivec);
219 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorEqual, bvec, "equal", uvec, uvec);
220 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorEqual, bvec, "equal", bvec, bvec);
221 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", vec, vec);
222 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", ivec, ivec);
223 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", uvec, uvec);
224 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorNotEqual, bvec, "notEqual", bvec, bvec);
225 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAny, bool1, "any", bvec);
226 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
227 0 : symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
228 :
229 0 : const TType *sampler2D = TCache::getType(EbtSampler2D);
230 0 : const TType *samplerCube = TCache::getType(EbtSamplerCube);
231 :
232 : //
233 : // Texture Functions for GLSL ES 1.0
234 : //
235 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
236 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
237 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
238 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
239 :
240 0 : if (resources.OES_EGL_image_external || resources.NV_EGL_stream_consumer_external)
241 : {
242 0 : const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
243 :
244 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
245 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
246 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
247 : }
248 :
249 0 : if (resources.ARB_texture_rectangle)
250 : {
251 0 : const TType *sampler2DRect = TCache::getType(EbtSampler2DRect);
252 :
253 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
254 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
255 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
256 : }
257 :
258 0 : if (resources.EXT_shader_texture_lod)
259 : {
260 : /* The *Grad* variants are new to both vertex and fragment shaders; the fragment
261 : * shader specific pieces are added separately below.
262 : */
263 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DGradEXT", sampler2D, float2, float2, float2);
264 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2);
265 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2);
266 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeGradEXT", samplerCube, float3, float3, float3);
267 : }
268 :
269 0 : if (type == GL_FRAGMENT_SHADER)
270 : {
271 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
272 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
273 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
274 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
275 :
276 0 : if (resources.OES_standard_derivatives)
277 : {
278 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdx, "GL_OES_standard_derivatives", genType, "dFdx", genType);
279 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpDFdy, "GL_OES_standard_derivatives", genType, "dFdy", genType);
280 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, EOpFwidth, "GL_OES_standard_derivatives", genType, "fwidth", genType);
281 : }
282 :
283 0 : if (resources.EXT_shader_texture_lod)
284 : {
285 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DLodEXT", sampler2D, float2, float1);
286 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float3, float1);
287 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "texture2DProjLodEXT", sampler2D, float4, float1);
288 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, "GL_EXT_shader_texture_lod", float4, "textureCubeLodEXT", samplerCube, float3, float1);
289 : }
290 : }
291 :
292 0 : if (type == GL_VERTEX_SHADER)
293 : {
294 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
295 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
296 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
297 0 : symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
298 : }
299 :
300 0 : const TType *gvec4 = TCache::getType(EbtGVec4);
301 :
302 0 : const TType *gsampler2D = TCache::getType(EbtGSampler2D);
303 0 : const TType *gsamplerCube = TCache::getType(EbtGSamplerCube);
304 0 : const TType *gsampler3D = TCache::getType(EbtGSampler3D);
305 0 : const TType *gsampler2DArray = TCache::getType(EbtGSampler2DArray);
306 :
307 : //
308 : // Texture Functions for GLSL ES 3.0
309 : //
310 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
311 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
312 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
313 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
314 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
315 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
316 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
317 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
318 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
319 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
320 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
321 :
322 0 : if (resources.OES_EGL_image_external_essl3)
323 : {
324 0 : const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
325 :
326 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2);
327 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES,
328 0 : float3);
329 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES,
330 0 : float4);
331 : }
332 :
333 0 : if (type == GL_FRAGMENT_SHADER)
334 : {
335 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
336 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
337 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
338 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
339 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
340 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
341 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
342 :
343 0 : if (resources.OES_EGL_image_external_essl3)
344 : {
345 0 : const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
346 :
347 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerExternalOES, float2,
348 0 : float1);
349 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES,
350 0 : float3, float1);
351 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", samplerExternalOES,
352 0 : float4, float1);
353 : }
354 : }
355 :
356 0 : const TType *sampler2DShadow = TCache::getType(EbtSampler2DShadow);
357 0 : const TType *samplerCubeShadow = TCache::getType(EbtSamplerCubeShadow);
358 0 : const TType *sampler2DArrayShadow = TCache::getType(EbtSampler2DArrayShadow);
359 :
360 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
361 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
362 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
363 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
364 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
365 :
366 0 : if (type == GL_FRAGMENT_SHADER)
367 : {
368 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
369 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
370 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
371 : }
372 :
373 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
374 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
375 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
376 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
377 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
378 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
379 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
380 :
381 0 : if (resources.OES_EGL_image_external_essl3)
382 : {
383 0 : const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
384 :
385 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerExternalOES, int1);
386 : }
387 :
388 0 : if (type == GL_FRAGMENT_SHADER)
389 : {
390 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdx, genType, "dFdx", genType);
391 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpDFdy, genType, "dFdy", genType);
392 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpFwidth, genType, "fwidth", genType);
393 : }
394 :
395 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
396 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
397 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
398 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
399 :
400 0 : if (type == GL_FRAGMENT_SHADER)
401 : {
402 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
403 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
404 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
405 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
406 : }
407 :
408 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
409 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
410 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
411 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
412 :
413 0 : if (type == GL_FRAGMENT_SHADER)
414 : {
415 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
416 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
417 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
418 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
419 : }
420 :
421 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
422 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
423 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
424 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
425 :
426 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
427 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
428 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
429 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
430 :
431 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
432 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
433 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
434 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
435 :
436 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
437 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
438 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
439 :
440 0 : if (resources.OES_EGL_image_external_essl3)
441 : {
442 0 : const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
443 :
444 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texelFetch", samplerExternalOES, int2,
445 0 : int1);
446 : }
447 :
448 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
449 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
450 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
451 :
452 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
453 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
454 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
455 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
456 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
457 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
458 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
459 :
460 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
461 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
462 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
463 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
464 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
465 :
466 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
467 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
468 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
469 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
470 :
471 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
472 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
473 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
474 0 : symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
475 :
476 0 : const TType *gimage2D = TCache::getType(EbtGImage2D);
477 0 : const TType *gimage3D = TCache::getType(EbtGImage3D);
478 0 : const TType *gimage2DArray = TCache::getType(EbtGImage2DArray);
479 0 : const TType *gimageCube = TCache::getType(EbtGImageCube);
480 :
481 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2D, int2, gvec4);
482 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage3D, int3, gvec4);
483 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimage2DArray, int3, gvec4);
484 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, voidType, "imageStore", gimageCube, int3, gvec4);
485 :
486 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2D, int2);
487 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage3D, int3);
488 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimage2DArray, int3);
489 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, gvec4, "imageLoad", gimageCube, int3);
490 :
491 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimage2D);
492 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage3D);
493 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int3, "imageSize", gimage2DArray);
494 0 : symbolTable.insertBuiltIn(ESSL3_1_BUILTINS, int2, "imageSize", gimageCube);
495 :
496 : //
497 : // Depth range in window coordinates
498 : //
499 0 : TFieldList *fields = NewPoolTFieldList();
500 0 : TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
501 0 : auto highpFloat1 = new TType(EbtFloat, EbpHigh, EvqGlobal, 1);
502 0 : TField *near = new TField(highpFloat1, NewPoolTString("near"), zeroSourceLoc);
503 0 : TField *far = new TField(highpFloat1, NewPoolTString("far"), zeroSourceLoc);
504 0 : TField *diff = new TField(highpFloat1, NewPoolTString("diff"), zeroSourceLoc);
505 0 : fields->push_back(near);
506 0 : fields->push_back(far);
507 0 : fields->push_back(diff);
508 0 : TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
509 : TVariable *depthRangeParameters =
510 0 : new TVariable(&depthRangeStruct->name(), TType(depthRangeStruct), true);
511 0 : symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
512 0 : TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
513 0 : depthRange->setQualifier(EvqUniform);
514 : // Ensure we evaluate the mangled name for depth range, so we allocate to the current scope.
515 0 : depthRangeParameters->getType().getMangledName();
516 0 : depthRange->getType().getMangledName();
517 0 : symbolTable.insert(COMMON_BUILTINS, depthRange);
518 :
519 : //
520 : // Implementation dependent built-in constants.
521 : //
522 0 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs,
523 0 : EbpMedium);
524 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors",
525 0 : resources.MaxVertexUniformVectors, EbpMedium);
526 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits",
527 0 : resources.MaxVertexTextureImageUnits, EbpMedium);
528 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits",
529 0 : resources.MaxCombinedTextureImageUnits, EbpMedium);
530 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits",
531 0 : resources.MaxTextureImageUnits, EbpMedium);
532 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors",
533 0 : resources.MaxFragmentUniformVectors, EbpMedium);
534 :
535 0 : symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors,
536 0 : EbpMedium);
537 :
538 0 : symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers,
539 0 : EbpMedium);
540 0 : if (resources.EXT_blend_func_extended)
541 : {
542 : symbolTable.insertConstIntExt(COMMON_BUILTINS, "GL_EXT_blend_func_extended",
543 : "gl_MaxDualSourceDrawBuffersEXT",
544 0 : resources.MaxDualSourceDrawBuffers);
545 : }
546 :
547 : symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors",
548 0 : resources.MaxVertexOutputVectors, EbpMedium);
549 : symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors",
550 0 : resources.MaxFragmentInputVectors, EbpMedium);
551 : symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset",
552 0 : resources.MinProgramTexelOffset, EbpMedium);
553 : symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset",
554 0 : resources.MaxProgramTexelOffset, EbpMedium);
555 :
556 0 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxImageUnits", resources.MaxImageUnits,
557 0 : EbpMedium);
558 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexImageUniforms",
559 0 : resources.MaxVertexImageUniforms, EbpMedium);
560 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentImageUniforms",
561 0 : resources.MaxFragmentImageUniforms, EbpMedium);
562 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeImageUniforms",
563 0 : resources.MaxComputeImageUniforms, EbpMedium);
564 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedImageUniforms",
565 0 : resources.MaxCombinedImageUniforms, EbpMedium);
566 :
567 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedShaderOutputResources",
568 0 : resources.MaxCombinedShaderOutputResources, EbpMedium);
569 :
570 0 : symbolTable.insertConstIvec3(ESSL3_1_BUILTINS, "gl_MaxComputeWorkGroupCount",
571 0 : resources.MaxComputeWorkGroupCount, EbpHigh);
572 0 : symbolTable.insertConstIvec3(ESSL3_1_BUILTINS, "gl_MaxComputeWorkGroupSize",
573 0 : resources.MaxComputeWorkGroupSize, EbpHigh);
574 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeUniformComponents",
575 0 : resources.MaxComputeUniformComponents, EbpMedium);
576 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeTextureImageUnits",
577 0 : resources.MaxComputeTextureImageUnits, EbpMedium);
578 :
579 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeAtomicCounters",
580 0 : resources.MaxComputeAtomicCounters, EbpMedium);
581 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxComputeAtomicCounterBuffers",
582 0 : resources.MaxComputeAtomicCounterBuffers, EbpMedium);
583 :
584 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexAtomicCounters",
585 0 : resources.MaxVertexAtomicCounters, EbpMedium);
586 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentAtomicCounters",
587 0 : resources.MaxFragmentAtomicCounters, EbpMedium);
588 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedAtomicCounters",
589 0 : resources.MaxCombinedAtomicCounters, EbpMedium);
590 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxAtomicCounterBindings",
591 0 : resources.MaxAtomicCounterBindings, EbpMedium);
592 :
593 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxVertexAtomicCounterBuffers",
594 0 : resources.MaxVertexAtomicCounterBuffers, EbpMedium);
595 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxFragmentAtomicCounterBuffers",
596 0 : resources.MaxFragmentAtomicCounterBuffers, EbpMedium);
597 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxCombinedAtomicCounterBuffers",
598 0 : resources.MaxCombinedAtomicCounterBuffers, EbpMedium);
599 : symbolTable.insertConstInt(ESSL3_1_BUILTINS, "gl_MaxAtomicCounterBufferSize",
600 0 : resources.MaxAtomicCounterBufferSize, EbpMedium);
601 0 : }
602 :
603 0 : void IdentifyBuiltIns(sh::GLenum type, ShShaderSpec spec,
604 : const ShBuiltInResources &resources,
605 : TSymbolTable &symbolTable)
606 : {
607 : //
608 : // Insert some special built-in variables that are not in
609 : // the built-in header files.
610 : //
611 0 : switch (type)
612 : {
613 : case GL_FRAGMENT_SHADER:
614 : {
615 0 : symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"),
616 0 : TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
617 0 : symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"),
618 0 : TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
619 0 : symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"),
620 0 : TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
621 :
622 0 : symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"),
623 0 : TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
624 0 : TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
625 0 : fragData.setArraySize(resources.MaxDrawBuffers);
626 0 : symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
627 :
628 0 : if (resources.EXT_blend_func_extended)
629 : {
630 0 : symbolTable.insert(
631 : ESSL1_BUILTINS, "GL_EXT_blend_func_extended",
632 0 : new TVariable(NewPoolTString("gl_SecondaryFragColorEXT"),
633 0 : TType(EbtFloat, EbpMedium, EvqSecondaryFragColorEXT, 4)));
634 0 : TType secondaryFragData(EbtFloat, EbpMedium, EvqSecondaryFragDataEXT, 4, 1, true);
635 0 : secondaryFragData.setArraySize(resources.MaxDualSourceDrawBuffers);
636 : symbolTable.insert(
637 : ESSL1_BUILTINS, "GL_EXT_blend_func_extended",
638 0 : new TVariable(NewPoolTString("gl_SecondaryFragDataEXT"), secondaryFragData));
639 : }
640 :
641 0 : if (resources.EXT_frag_depth)
642 : {
643 0 : symbolTable.insert(
644 : ESSL1_BUILTINS, "GL_EXT_frag_depth",
645 : new TVariable(
646 0 : NewPoolTString("gl_FragDepthEXT"),
647 0 : TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium,
648 0 : EvqFragDepthEXT, 1)));
649 : }
650 :
651 0 : symbolTable.insert(ESSL3_BUILTINS,
652 0 : new TVariable(NewPoolTString("gl_FragDepth"),
653 0 : TType(EbtFloat, EbpHigh, EvqFragDepth, 1)));
654 :
655 0 : if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch)
656 : {
657 0 : TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
658 0 : lastFragData.setArraySize(resources.MaxDrawBuffers);
659 :
660 0 : if (resources.EXT_shader_framebuffer_fetch)
661 : {
662 : symbolTable.insert(ESSL1_BUILTINS, "GL_EXT_shader_framebuffer_fetch",
663 0 : new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
664 : }
665 0 : else if (resources.NV_shader_framebuffer_fetch)
666 : {
667 0 : symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
668 0 : new TVariable(NewPoolTString("gl_LastFragColor"),
669 0 : TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
670 : symbolTable.insert(ESSL1_BUILTINS, "GL_NV_shader_framebuffer_fetch",
671 0 : new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
672 0 : }
673 : }
674 0 : else if (resources.ARM_shader_framebuffer_fetch)
675 : {
676 0 : symbolTable.insert(ESSL1_BUILTINS, "GL_ARM_shader_framebuffer_fetch",
677 0 : new TVariable(NewPoolTString("gl_LastFragColorARM"),
678 0 : TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
679 : }
680 : }
681 :
682 0 : break;
683 :
684 : case GL_VERTEX_SHADER:
685 0 : symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"),
686 0 : TType(EbtFloat, EbpHigh, EvqPosition, 4)));
687 0 : symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"),
688 0 : TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
689 0 : symbolTable.insert(ESSL3_BUILTINS, new TVariable(NewPoolTString("gl_InstanceID"),
690 0 : TType(EbtInt, EbpHigh, EvqInstanceID, 1)));
691 0 : symbolTable.insert(ESSL3_BUILTINS, new TVariable(NewPoolTString("gl_VertexID"),
692 0 : TType(EbtInt, EbpHigh, EvqVertexID, 1)));
693 0 : break;
694 : case GL_COMPUTE_SHADER:
695 : {
696 0 : symbolTable.insert(ESSL3_1_BUILTINS,
697 0 : new TVariable(NewPoolTString("gl_NumWorkGroups"),
698 0 : TType(EbtUInt, EbpUndefined, EvqNumWorkGroups, 3)));
699 0 : symbolTable.insert(ESSL3_1_BUILTINS,
700 0 : new TVariable(NewPoolTString("gl_WorkGroupSize"),
701 0 : TType(EbtUInt, EbpUndefined, EvqWorkGroupSize, 3)));
702 0 : symbolTable.insert(ESSL3_1_BUILTINS,
703 0 : new TVariable(NewPoolTString("gl_WorkGroupID"),
704 0 : TType(EbtUInt, EbpUndefined, EvqWorkGroupID, 3)));
705 0 : symbolTable.insert(ESSL3_1_BUILTINS,
706 0 : new TVariable(NewPoolTString("gl_LocalInvocationID"),
707 0 : TType(EbtUInt, EbpUndefined, EvqLocalInvocationID, 3)));
708 0 : symbolTable.insert(ESSL3_1_BUILTINS,
709 0 : new TVariable(NewPoolTString("gl_GlobalInvocationID"),
710 0 : TType(EbtUInt, EbpUndefined, EvqGlobalInvocationID, 3)));
711 0 : symbolTable.insert(
712 : ESSL3_1_BUILTINS,
713 0 : new TVariable(NewPoolTString("gl_LocalInvocationIndex"),
714 0 : TType(EbtUInt, EbpUndefined, EvqLocalInvocationIndex, 1)));
715 : }
716 0 : break;
717 :
718 : default:
719 0 : assert(false && "Language not supported");
720 : }
721 0 : }
722 :
723 0 : void InitExtensionBehavior(const ShBuiltInResources& resources,
724 : TExtensionBehavior& extBehavior)
725 : {
726 0 : if (resources.OES_standard_derivatives)
727 0 : extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
728 0 : if (resources.OES_EGL_image_external)
729 0 : extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
730 0 : if (resources.OES_EGL_image_external_essl3)
731 0 : extBehavior["GL_OES_EGL_image_external_essl3"] = EBhUndefined;
732 0 : if (resources.NV_EGL_stream_consumer_external)
733 0 : extBehavior["GL_NV_EGL_stream_consumer_external"] = EBhUndefined;
734 0 : if (resources.ARB_texture_rectangle)
735 0 : extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
736 0 : if (resources.EXT_blend_func_extended)
737 0 : extBehavior["GL_EXT_blend_func_extended"] = EBhUndefined;
738 0 : if (resources.EXT_draw_buffers)
739 0 : extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
740 0 : if (resources.EXT_frag_depth)
741 0 : extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
742 0 : if (resources.EXT_shader_texture_lod)
743 0 : extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined;
744 0 : if (resources.EXT_shader_framebuffer_fetch)
745 0 : extBehavior["GL_EXT_shader_framebuffer_fetch"] = EBhUndefined;
746 0 : if (resources.NV_shader_framebuffer_fetch)
747 0 : extBehavior["GL_NV_shader_framebuffer_fetch"] = EBhUndefined;
748 0 : if (resources.ARM_shader_framebuffer_fetch)
749 0 : extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined;
750 0 : }
751 :
752 0 : void ResetExtensionBehavior(TExtensionBehavior &extBehavior)
753 : {
754 0 : for (auto ext_iter = extBehavior.begin();
755 0 : ext_iter != extBehavior.end();
756 : ++ext_iter)
757 : {
758 0 : ext_iter->second = EBhUndefined;
759 : }
760 0 : }
761 :
762 : } // namespace sh
|