blob: 6b3feff91f9944073946336ffeec2e2b659c8027 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
John Baumand4ae8632014-05-06 16:18:33 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7//
8// Create strings that declare built-in definitions, add built-ins that
9// cannot be expressed in the files, and establish mappings between
10// built-in functions and operators.
11//
12
Nicolas Capenscc863da2015-01-21 15:50:55 -050013#include "Initialize.h"
John Bauman66b8ab22014-05-06 15:57:45 -040014
Nicolas Capenscc863da2015-01-21 15:50:55 -050015#include "intermediate.h"
John Bauman66b8ab22014-05-06 15:57:45 -040016
Nicolas Capens08ca3c62015-02-13 16:06:45 -050017void InsertBuiltInFunctions(GLenum type, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -040018{
Nicolas Capens70da3d42015-02-18 16:58:10 -050019 TType *float1 = new TType(EbtFloat);
20 TType *float2 = new TType(EbtFloat, 2);
21 TType *float3 = new TType(EbtFloat, 3);
22 TType *float4 = new TType(EbtFloat, 4);
Nicolas Capens8fa9d232015-02-19 15:53:16 -050023 TType *genType = new TType(EbtGenType);
John Bauman66b8ab22014-05-06 15:57:45 -040024
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050025 //
26 // Angle and Trigonometric Functions.
27 //
Nicolas Capens8fa9d232015-02-19 15:53:16 -050028 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "radians", genType);
29 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "degrees", genType);
30 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "sin", genType);
31 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "cos", genType);
32 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "tan", genType);
33 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "asin", genType);
34 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "acos", genType);
35 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "atan", genType, genType);
36 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "atan", genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050037
38 //
39 // Exponential Functions.
40 //
Nicolas Capens8fa9d232015-02-19 15:53:16 -050041 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "pow", genType, genType);
42 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "exp", genType);
43 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "log", genType);
44 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "exp2", genType);
45 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "log2", genType);
46 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "sqrt", genType);
47 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "inversesqrt", genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050048
49 //
50 // Common Functions.
51 //
Nicolas Capens8fa9d232015-02-19 15:53:16 -050052 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "abs", genType);
53 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "sign", genType);
54 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "floor", genType);
55 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "ceil", genType);
56 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "fract", genType);
57 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "mod", genType, float1);
58 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "mod", genType, genType);
59 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "min", genType, float1);
60 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "min", genType, genType);
61 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "max", genType, float1);
62 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "max", genType, genType);
63 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "clamp", genType, float1, float1);
64 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "clamp", genType, genType, genType);
65 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "mix", genType, genType, float1);
66 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "mix", genType, genType, genType);
67 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "step", genType, genType);
68 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "step", float1, genType);
69 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "smoothstep", genType, genType, genType);
70 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "smoothstep", float1, float1, genType);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050071
72 //
73 // Geometric Functions.
74 //
Nicolas Capens8fa9d232015-02-19 15:53:16 -050075 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", genType);
76 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", genType, genType);
77 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", genType, genType);
Nicolas Capense2858652015-02-18 15:30:51 -050078 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3);
Nicolas Capens8fa9d232015-02-19 15:53:16 -050079 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "normalize", genType);
80 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "faceforward", genType, genType, genType);
81 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "reflect", genType, genType);
82 symbolTable.insertBuiltIn(COMMON_BUILTINS, genType, "refract", genType, genType, float1);
John Bauman66b8ab22014-05-06 15:57:45 -040083
Nicolas Capens70da3d42015-02-18 16:58:10 -050084 TType *mat2 = new TType(EbtFloat, 2, true);
85 TType *mat3 = new TType(EbtFloat, 3, true);
86 TType *mat4 = new TType(EbtFloat, 4, true);
John Bauman66b8ab22014-05-06 15:57:45 -040087
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -050088 //
89 // Matrix Functions.
90 //
Nicolas Capense2858652015-02-18 15:30:51 -050091 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2);
92 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3);
93 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4);
John Bauman66b8ab22014-05-06 15:57:45 -040094
Nicolas Capens70da3d42015-02-18 16:58:10 -050095 TType *bool1 = new TType(EbtBool);
Nicolas Capens8fa9d232015-02-19 15:53:16 -050096 TType *vec = new TType(EbtVec);
97 TType *ivec = new TType(EbtIVec);
98 TType *bvec = new TType(EbtBVec);
John Bauman66b8ab22014-05-06 15:57:45 -040099
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500100 //
101 // Vector relational functions.
102 //
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500103 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "lessThan", vec, vec);
104 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "lessThan", ivec, ivec);
105 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "lessThanEqual", vec, vec);
106 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "lessThanEqual", ivec, ivec);
107 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "greaterThan", vec, vec);
108 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "greaterThan", ivec, ivec);
109 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "greaterThanEqual", vec, vec);
110 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "greaterThanEqual", ivec, ivec);
111 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "equal", vec, vec);
112 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "equal", ivec, ivec);
113 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "equal", bvec, bvec);
114 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "notEqual", vec, vec);
115 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "notEqual", ivec, ivec);
116 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "notEqual", bvec, bvec);
117 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bvec);
118 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bvec);
119 symbolTable.insertBuiltIn(COMMON_BUILTINS, bvec, "not", bvec);
John Bauman66b8ab22014-05-06 15:57:45 -0400120
Nicolas Capens70da3d42015-02-18 16:58:10 -0500121 TType *sampler2D = new TType(EbtSampler2D);
122 TType *samplerCube = new TType(EbtSamplerCube);
123 TType *sampler3D = new TType(EbtSampler3D);
John Bauman66b8ab22014-05-06 15:57:45 -0400124
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500125 //
126 // Texture Functions for GLSL ES 1.0
127 //
128 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
129 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
130 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
131 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
132 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", sampler3D, float3);
133
134 if(resources.OES_EGL_image_external)
135 {
Nicolas Capens70da3d42015-02-18 16:58:10 -0500136 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500137
138 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
139 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
140 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
141 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3D", samplerExternalOES, float3);
142 }
John Bauman66b8ab22014-05-06 15:57:45 -0400143
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500144 if(type == GL_FRAGMENT_SHADER)
John Bauman66b8ab22014-05-06 15:57:45 -0400145 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500146 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
147 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
148 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
149 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400150
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500151 if(resources.OES_standard_derivatives)
John Baumand4ae8632014-05-06 16:18:33 -0400152 {
Nicolas Capens8fa9d232015-02-19 15:53:16 -0500153 symbolTable.insertBuiltIn(ESSL1_BUILTINS, genType, "dFdx", genType);
154 symbolTable.insertBuiltIn(ESSL1_BUILTINS, genType, "dFdy", genType);
155 symbolTable.insertBuiltIn(ESSL1_BUILTINS, genType, "fwidth", genType);
John Baumand4ae8632014-05-06 16:18:33 -0400156 }
157 }
John Bauman66b8ab22014-05-06 15:57:45 -0400158
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500159 if(type == GL_VERTEX_SHADER)
John Baumand4ae8632014-05-06 16:18:33 -0400160 {
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500161 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
162 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
163 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
164 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
165 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture3DLod", sampler3D, float3, float1);
John Baumand4ae8632014-05-06 16:18:33 -0400166 }
John Bauman66b8ab22014-05-06 15:57:45 -0400167
Nicolas Capens82cd6d82015-02-18 17:53:39 -0500168 TType *gvec4 = new TType(EbtGVec4);
169
170 TType *gsampler2D = new TType(EbtGSampler2D);
171 TType *gsamplerCube = new TType(EbtGSamplerCube);
172 TType *gsampler3D = new TType(EbtGSampler3D);
173 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
174
175 //
176 // Texture Functions for GLSL ES 3.0
177 //
178 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
179 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
180 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
181 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
182 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
183 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
184 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
185 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
186 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
187 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
188 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
189
190 if(type == GL_FRAGMENT_SHADER)
191 {
192 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
193 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
194 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
195 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
196 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
197 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
198 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
199 }
200
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500201 //
202 // Depth range in window coordinates
203 //
John Baumand4ae8632014-05-06 16:18:33 -0400204 TTypeList *members = NewPoolTTypeList();
205 TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
206 TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
207 TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
208 near.type->setFieldName("near");
209 far.type->setFieldName("far");
210 diff.type->setFieldName("diff");
211 members->push_back(near);
212 members->push_back(far);
213 members->push_back(diff);
214 TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true);
Nicolas Capense2858652015-02-18 15:30:51 -0500215 symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
John Baumand4ae8632014-05-06 16:18:33 -0400216 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters"));
217 depthRange->setQualifier(EvqUniform);
Nicolas Capense2858652015-02-18 15:30:51 -0500218 symbolTable.insert(COMMON_BUILTINS, *depthRange);
John Bauman66b8ab22014-05-06 15:57:45 -0400219
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500220 //
221 // Implementation dependent built-in constants.
222 //
223 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
Nicolas Capense2858652015-02-18 15:30:51 -0500224 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
Nicolas Capense2858652015-02-18 15:30:51 -0500225 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
226 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
227 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
228 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500229 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
230 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
John Bauman66b8ab22014-05-06 15:57:45 -0400231}
232
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500233void IdentifyBuiltIns(GLenum shaderType,
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500234 const ShBuiltInResources &resources,
John Baumand4ae8632014-05-06 16:18:33 -0400235 TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -0400236{
237 //
238 // First, insert some special built-in variables that are not in
239 // the built-in header files.
240 //
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500241 switch(shaderType)
242 {
243 case GL_FRAGMENT_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500244 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
245 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
246 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
247 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
248 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
John Bauman66b8ab22014-05-06 15:57:45 -0400249 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500250 case GL_VERTEX_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500251 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
252 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400253 break;
254 default: assert(false && "Language not supported");
255 }
256
257 //
258 // Next, identify which built-ins from the already loaded headers have
259 // a mapping to an operator. Those that are not identified as such are
260 // expected to be resolved through a library of functions, versus as
261 // operations.
262 //
Nicolas Capense2858652015-02-18 15:30:51 -0500263 symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul);
John Bauman66b8ab22014-05-06 15:57:45 -0400264
Nicolas Capense2858652015-02-18 15:30:51 -0500265 symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual);
266 symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual);
267 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan);
268 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan);
269 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual);
270 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual);
John Bauman66b8ab22014-05-06 15:57:45 -0400271
Nicolas Capense2858652015-02-18 15:30:51 -0500272 symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians);
273 symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees);
274 symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin);
275 symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos);
276 symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan);
277 symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin);
278 symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos);
279 symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan);
John Bauman66b8ab22014-05-06 15:57:45 -0400280
Nicolas Capense2858652015-02-18 15:30:51 -0500281 symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow);
282 symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2);
283 symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog);
284 symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp);
285 symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2);
286 symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt);
287 symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt);
John Bauman66b8ab22014-05-06 15:57:45 -0400288
Nicolas Capense2858652015-02-18 15:30:51 -0500289 symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs);
290 symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign);
291 symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor);
292 symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil);
293 symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract);
294 symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod);
295 symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin);
296 symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax);
297 symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp);
298 symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix);
299 symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep);
300 symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep);
John Bauman66b8ab22014-05-06 15:57:45 -0400301
Nicolas Capense2858652015-02-18 15:30:51 -0500302 symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength);
303 symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance);
304 symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot);
305 symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross);
306 symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize);
307 symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward);
308 symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect);
309 symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract);
John Bauman66b8ab22014-05-06 15:57:45 -0400310
Nicolas Capense2858652015-02-18 15:30:51 -0500311 symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny);
312 symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500313 symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot);
John Bauman66b8ab22014-05-06 15:57:45 -0400314
315 // Map language-specific operators.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500316 switch(shaderType)
317 {
318 case GL_VERTEX_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400319 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500320 case GL_FRAGMENT_SHADER:
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500321 if(resources.OES_standard_derivatives)
322 {
323 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx);
324 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy);
325 symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
John Bauman66b8ab22014-05-06 15:57:45 -0400326
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500327 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
328 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
329 symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
John Bauman66b8ab22014-05-06 15:57:45 -0400330 }
331 break;
332 default: break;
333 }
334
335 // Finally add resource-specific variables.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500336 switch(shaderType)
John Bauman66b8ab22014-05-06 15:57:45 -0400337 {
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500338 case GL_FRAGMENT_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400339 {
340 // Set up gl_FragData. The array size.
341 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true);
342 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500343 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
John Bauman66b8ab22014-05-06 15:57:45 -0400344 }
345 break;
346 default: break;
347 }
348}
349
350void InitExtensionBehavior(const ShBuiltInResources& resources,
351 TExtensionBehavior& extBehavior)
352{
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500353 if(resources.OES_standard_derivatives)
John Bauman66b8ab22014-05-06 15:57:45 -0400354 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500355 if(resources.OES_fragment_precision_high)
John Baumand4ae8632014-05-06 16:18:33 -0400356 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
Nicolas Capens3d7f6ed2015-02-18 16:34:50 -0500357 if(resources.OES_EGL_image_external)
358 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
John Bauman66b8ab22014-05-06 15:57:45 -0400359}