blob: c3390869771ffa2f24297c623be89aca0974850d [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{
John Baumand4ae8632014-05-06 16:18:33 -040019 TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1);
20 TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2);
21 TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3);
22 TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -040023
John Baumand4ae8632014-05-06 16:18:33 -040024 TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2);
25 TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3);
26 TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -040027
Nicolas Capens434311c2014-05-28 19:23:55 -040028 symbolTable.insertBuiltIn(float1, "radians", float1);
29 symbolTable.insertBuiltIn(float2, "radians", float2);
30 symbolTable.insertBuiltIn(float3, "radians", float3);
31 symbolTable.insertBuiltIn(float4, "radians", float4);
32 symbolTable.insertBuiltIn(float1, "degrees", float1);
33 symbolTable.insertBuiltIn(float2, "degrees", float2);
34 symbolTable.insertBuiltIn(float3, "degrees", float3);
35 symbolTable.insertBuiltIn(float4, "degrees", float4);
36 symbolTable.insertBuiltIn(float1, "sin", float1);
37 symbolTable.insertBuiltIn(float2, "sin", float2);
38 symbolTable.insertBuiltIn(float3, "sin", float3);
39 symbolTable.insertBuiltIn(float4, "sin", float4);
40 symbolTable.insertBuiltIn(float1, "cos", float1);
41 symbolTable.insertBuiltIn(float2, "cos", float2);
42 symbolTable.insertBuiltIn(float3, "cos", float3);
43 symbolTable.insertBuiltIn(float4, "cos", float4);
44 symbolTable.insertBuiltIn(float1, "tan", float1);
45 symbolTable.insertBuiltIn(float2, "tan", float2);
46 symbolTable.insertBuiltIn(float3, "tan", float3);
47 symbolTable.insertBuiltIn(float4, "tan", float4);
48 symbolTable.insertBuiltIn(float1, "asin", float1);
49 symbolTable.insertBuiltIn(float2, "asin", float2);
50 symbolTable.insertBuiltIn(float3, "asin", float3);
51 symbolTable.insertBuiltIn(float4, "asin", float4);
52 symbolTable.insertBuiltIn(float1, "acos", float1);
53 symbolTable.insertBuiltIn(float2, "acos", float2);
54 symbolTable.insertBuiltIn(float3, "acos", float3);
55 symbolTable.insertBuiltIn(float4, "acos", float4);
56 symbolTable.insertBuiltIn(float1, "atan", float1, float1);
57 symbolTable.insertBuiltIn(float2, "atan", float2, float2);
58 symbolTable.insertBuiltIn(float3, "atan", float3, float3);
59 symbolTable.insertBuiltIn(float4, "atan", float4, float4);
60 symbolTable.insertBuiltIn(float1, "atan", float1);
61 symbolTable.insertBuiltIn(float2, "atan", float2);
62 symbolTable.insertBuiltIn(float3, "atan", float3);
63 symbolTable.insertBuiltIn(float4, "atan", float4);
64 symbolTable.insertBuiltIn(float1, "pow", float1, float1);
65 symbolTable.insertBuiltIn(float2, "pow", float2, float2);
66 symbolTable.insertBuiltIn(float3, "pow", float3, float3);
67 symbolTable.insertBuiltIn(float4, "pow", float4, float4);
68 symbolTable.insertBuiltIn(float1, "exp", float1);
69 symbolTable.insertBuiltIn(float2, "exp", float2);
70 symbolTable.insertBuiltIn(float3, "exp", float3);
71 symbolTable.insertBuiltIn(float4, "exp", float4);
72 symbolTable.insertBuiltIn(float1, "log", float1);
73 symbolTable.insertBuiltIn(float2, "log", float2);
74 symbolTable.insertBuiltIn(float3, "log", float3);
75 symbolTable.insertBuiltIn(float4, "log", float4);
76 symbolTable.insertBuiltIn(float1, "exp2", float1);
77 symbolTable.insertBuiltIn(float2, "exp2", float2);
78 symbolTable.insertBuiltIn(float3, "exp2", float3);
79 symbolTable.insertBuiltIn(float4, "exp2", float4);
80 symbolTable.insertBuiltIn(float1, "log2", float1);
81 symbolTable.insertBuiltIn(float2, "log2", float2);
82 symbolTable.insertBuiltIn(float3, "log2", float3);
83 symbolTable.insertBuiltIn(float4, "log2", float4);
84 symbolTable.insertBuiltIn(float1, "sqrt", float1);
85 symbolTable.insertBuiltIn(float2, "sqrt", float2);
86 symbolTable.insertBuiltIn(float3, "sqrt", float3);
87 symbolTable.insertBuiltIn(float4, "sqrt", float4);
88 symbolTable.insertBuiltIn(float1, "inversesqrt", float1);
89 symbolTable.insertBuiltIn(float2, "inversesqrt", float2);
90 symbolTable.insertBuiltIn(float3, "inversesqrt", float3);
91 symbolTable.insertBuiltIn(float4, "inversesqrt", float4);
92 symbolTable.insertBuiltIn(float1, "abs", float1);
93 symbolTable.insertBuiltIn(float2, "abs", float2);
94 symbolTable.insertBuiltIn(float3, "abs", float3);
95 symbolTable.insertBuiltIn(float4, "abs", float4);
96 symbolTable.insertBuiltIn(float1, "sign", float1);
97 symbolTable.insertBuiltIn(float2, "sign", float2);
98 symbolTable.insertBuiltIn(float3, "sign", float3);
99 symbolTable.insertBuiltIn(float4, "sign", float4);
100 symbolTable.insertBuiltIn(float1, "floor", float1);
101 symbolTable.insertBuiltIn(float2, "floor", float2);
102 symbolTable.insertBuiltIn(float3, "floor", float3);
103 symbolTable.insertBuiltIn(float4, "floor", float4);
104 symbolTable.insertBuiltIn(float1, "ceil", float1);
105 symbolTable.insertBuiltIn(float2, "ceil", float2);
106 symbolTable.insertBuiltIn(float3, "ceil", float3);
107 symbolTable.insertBuiltIn(float4, "ceil", float4);
108 symbolTable.insertBuiltIn(float1, "fract", float1);
109 symbolTable.insertBuiltIn(float2, "fract", float2);
110 symbolTable.insertBuiltIn(float3, "fract", float3);
111 symbolTable.insertBuiltIn(float4, "fract", float4);
112 symbolTable.insertBuiltIn(float1, "mod", float1, float1);
113 symbolTable.insertBuiltIn(float2, "mod", float2, float1);
114 symbolTable.insertBuiltIn(float3, "mod", float3, float1);
115 symbolTable.insertBuiltIn(float4, "mod", float4, float1);
116 symbolTable.insertBuiltIn(float2, "mod", float2, float2);
117 symbolTable.insertBuiltIn(float3, "mod", float3, float3);
118 symbolTable.insertBuiltIn(float4, "mod", float4, float4);
119 symbolTable.insertBuiltIn(float1, "min", float1, float1);
120 symbolTable.insertBuiltIn(float2, "min", float2, float1);
121 symbolTable.insertBuiltIn(float3, "min", float3, float1);
122 symbolTable.insertBuiltIn(float4, "min", float4, float1);
123 symbolTable.insertBuiltIn(float2, "min", float2, float2);
124 symbolTable.insertBuiltIn(float3, "min", float3, float3);
125 symbolTable.insertBuiltIn(float4, "min", float4, float4);
126 symbolTable.insertBuiltIn(float1, "max", float1, float1);
127 symbolTable.insertBuiltIn(float2, "max", float2, float1);
128 symbolTable.insertBuiltIn(float3, "max", float3, float1);
129 symbolTable.insertBuiltIn(float4, "max", float4, float1);
130 symbolTable.insertBuiltIn(float2, "max", float2, float2);
131 symbolTable.insertBuiltIn(float3, "max", float3, float3);
132 symbolTable.insertBuiltIn(float4, "max", float4, float4);
133 symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1);
134 symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1);
135 symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1);
136 symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1);
137 symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2);
138 symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3);
139 symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4);
140 symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1);
141 symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1);
142 symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1);
143 symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1);
144 symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2);
145 symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3);
146 symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4);
147 symbolTable.insertBuiltIn(float1, "step", float1, float1);
148 symbolTable.insertBuiltIn(float2, "step", float2, float2);
149 symbolTable.insertBuiltIn(float3, "step", float3, float3);
150 symbolTable.insertBuiltIn(float4, "step", float4, float4);
151 symbolTable.insertBuiltIn(float2, "step", float1, float2);
152 symbolTable.insertBuiltIn(float3, "step", float1, float3);
153 symbolTable.insertBuiltIn(float4, "step", float1, float4);
154 symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1);
155 symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2);
156 symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3);
157 symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4);
158 symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2);
159 symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3);
160 symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4);
161 symbolTable.insertBuiltIn(float1, "length", float1);
162 symbolTable.insertBuiltIn(float1, "length", float2);
163 symbolTable.insertBuiltIn(float1, "length", float3);
164 symbolTable.insertBuiltIn(float1, "length", float4);
165 symbolTable.insertBuiltIn(float1, "distance", float1, float1);
166 symbolTable.insertBuiltIn(float1, "distance", float2, float2);
167 symbolTable.insertBuiltIn(float1, "distance", float3, float3);
168 symbolTable.insertBuiltIn(float1, "distance", float4, float4);
169 symbolTable.insertBuiltIn(float1, "dot", float1, float1);
170 symbolTable.insertBuiltIn(float1, "dot", float2, float2);
171 symbolTable.insertBuiltIn(float1, "dot", float3, float3);
172 symbolTable.insertBuiltIn(float1, "dot", float4, float4);
173 symbolTable.insertBuiltIn(float3, "cross", float3, float3);
174 symbolTable.insertBuiltIn(float1, "normalize", float1);
175 symbolTable.insertBuiltIn(float2, "normalize", float2);
176 symbolTable.insertBuiltIn(float3, "normalize", float3);
177 symbolTable.insertBuiltIn(float4, "normalize", float4);
178 symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1);
179 symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2);
180 symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3);
181 symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4);
182 symbolTable.insertBuiltIn(float1, "reflect", float1, float1);
183 symbolTable.insertBuiltIn(float2, "reflect", float2, float2);
184 symbolTable.insertBuiltIn(float3, "reflect", float3, float3);
185 symbolTable.insertBuiltIn(float4, "reflect", float4, float4);
186 symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1);
187 symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1);
188 symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1);
189 symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400190
John Baumand4ae8632014-05-06 16:18:33 -0400191 TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true);
192 TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true);
193 TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true);
John Bauman66b8ab22014-05-06 15:57:45 -0400194
Nicolas Capens434311c2014-05-28 19:23:55 -0400195 symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2);
196 symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3);
197 symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4);
John Bauman66b8ab22014-05-06 15:57:45 -0400198
John Baumand4ae8632014-05-06 16:18:33 -0400199 TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1);
200 TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2);
201 TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3);
202 TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4);
John Bauman66b8ab22014-05-06 15:57:45 -0400203
Nicolas Capens434311c2014-05-28 19:23:55 -0400204 symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2);
205 symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3);
206 symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4);
207 symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2);
208 symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3);
209 symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4);
210 symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2);
211 symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3);
212 symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4);
213 symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2);
214 symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3);
215 symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4);
216 symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2);
217 symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3);
218 symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4);
219 symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2);
220 symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3);
221 symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4);
222 symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2);
223 symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3);
224 symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4);
225 symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2);
226 symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3);
227 symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4);
228 symbolTable.insertBuiltIn(bool2, "equal", float2, float2);
229 symbolTable.insertBuiltIn(bool3, "equal", float3, float3);
230 symbolTable.insertBuiltIn(bool4, "equal", float4, float4);
231 symbolTable.insertBuiltIn(bool2, "equal", int2, int2);
232 symbolTable.insertBuiltIn(bool3, "equal", int3, int3);
233 symbolTable.insertBuiltIn(bool4, "equal", int4, int4);
234 symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2);
235 symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3);
236 symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4);
237 symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2);
238 symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3);
239 symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4);
240 symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2);
241 symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3);
242 symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4);
243 symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2);
244 symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3);
245 symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4);
246 symbolTable.insertBuiltIn(bool1, "any", bool2);
247 symbolTable.insertBuiltIn(bool1, "any", bool3);
248 symbolTable.insertBuiltIn(bool1, "any", bool4);
249 symbolTable.insertBuiltIn(bool1, "all", bool2);
250 symbolTable.insertBuiltIn(bool1, "all", bool3);
251 symbolTable.insertBuiltIn(bool1, "all", bool4);
252 symbolTable.insertBuiltIn(bool2, "not", bool2);
253 symbolTable.insertBuiltIn(bool3, "not", bool3);
254 symbolTable.insertBuiltIn(bool4, "not", bool4);
John Bauman66b8ab22014-05-06 15:57:45 -0400255
John Baumand4ae8632014-05-06 16:18:33 -0400256 TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1);
257 TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1);
Alexis Hetub027aa92015-01-19 15:56:12 -0500258 TType *sampler3D = new TType(EbtSampler3D, EbpUndefined, EvqGlobal, 1);
John Bauman66b8ab22014-05-06 15:57:45 -0400259
Nicolas Capens434311c2014-05-28 19:23:55 -0400260 symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2);
261 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3);
262 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4);
263 symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3);
Alexis Hetub027aa92015-01-19 15:56:12 -0500264 symbolTable.insertBuiltIn(float4, "texture3D", sampler3D, float3);
John Bauman66b8ab22014-05-06 15:57:45 -0400265
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500266 if(type == GL_FRAGMENT_SHADER)
John Bauman66b8ab22014-05-06 15:57:45 -0400267 {
Nicolas Capens434311c2014-05-28 19:23:55 -0400268 symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1);
269 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1);
270 symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1);
271 symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1);
Alexis Hetub027aa92015-01-19 15:56:12 -0500272 symbolTable.insertBuiltIn(float4, "texture3D", sampler3D, float3, float1);
John Bauman66b8ab22014-05-06 15:57:45 -0400273
John Baumand4ae8632014-05-06 16:18:33 -0400274 if (resources.OES_standard_derivatives)
275 {
Nicolas Capens434311c2014-05-28 19:23:55 -0400276 symbolTable.insertBuiltIn(float1, "dFdx", float1);
277 symbolTable.insertBuiltIn(float2, "dFdx", float2);
278 symbolTable.insertBuiltIn(float3, "dFdx", float3);
279 symbolTable.insertBuiltIn(float4, "dFdx", float4);
John Baumand4ae8632014-05-06 16:18:33 -0400280
Nicolas Capens434311c2014-05-28 19:23:55 -0400281 symbolTable.insertBuiltIn(float1, "dFdy", float1);
282 symbolTable.insertBuiltIn(float2, "dFdy", float2);
283 symbolTable.insertBuiltIn(float3, "dFdy", float3);
284 symbolTable.insertBuiltIn(float4, "dFdy", float4);
John Bauman66b8ab22014-05-06 15:57:45 -0400285
Nicolas Capens434311c2014-05-28 19:23:55 -0400286 symbolTable.insertBuiltIn(float1, "fwidth", float1);
287 symbolTable.insertBuiltIn(float2, "fwidth", float2);
288 symbolTable.insertBuiltIn(float3, "fwidth", float3);
289 symbolTable.insertBuiltIn(float4, "fwidth", float4);
John Baumand4ae8632014-05-06 16:18:33 -0400290 }
291 }
John Bauman66b8ab22014-05-06 15:57:45 -0400292
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500293 if(type == GL_VERTEX_SHADER)
John Baumand4ae8632014-05-06 16:18:33 -0400294 {
Nicolas Capens434311c2014-05-28 19:23:55 -0400295 symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1);
296 symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1);
297 symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1);
298 symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1);
Alexis Hetub027aa92015-01-19 15:56:12 -0500299 symbolTable.insertBuiltIn(float4, "texture3DLod", sampler3D, float3, float1);
John Baumand4ae8632014-05-06 16:18:33 -0400300 }
John Bauman66b8ab22014-05-06 15:57:45 -0400301
Nicolas Capense9c5e4f2014-05-28 22:46:43 -0400302 TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1);
303
304 if(resources.OES_EGL_image_external)
305 {
306 symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2);
307 symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3);
308 symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4);
Alexis Hetub027aa92015-01-19 15:56:12 -0500309 symbolTable.insertBuiltIn(float4, "texture3D", samplerExternalOES, float3);
Nicolas Capense9c5e4f2014-05-28 22:46:43 -0400310 }
311
John Baumand4ae8632014-05-06 16:18:33 -0400312 TTypeList *members = NewPoolTTypeList();
313 TTypeLine near = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
314 TTypeLine far = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
315 TTypeLine diff = {new TType(EbtFloat, EbpHigh, EvqGlobal, 1), 0};
316 near.type->setFieldName("near");
317 far.type->setFieldName("far");
318 diff.type->setFieldName("diff");
319 members->push_back(near);
320 members->push_back(far);
321 members->push_back(diff);
322 TVariable *depthRangeParameters = new TVariable(NewPoolTString("gl_DepthRangeParameters"), TType(members, "gl_DepthRangeParameters"), true);
Nicolas Capensd603ecd2015-02-18 14:52:21 -0500323 symbolTable.insert(0, *depthRangeParameters);
John Baumand4ae8632014-05-06 16:18:33 -0400324 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(members, "gl_DepthRangeParameters"));
325 depthRange->setQualifier(EvqUniform);
Nicolas Capensd603ecd2015-02-18 14:52:21 -0500326 symbolTable.insert(0, *depthRange);
John Bauman66b8ab22014-05-06 15:57:45 -0400327
John Baumand4ae8632014-05-06 16:18:33 -0400328 symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs);
329 symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
330 symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors);
331 symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
332 symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
333 symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
334 symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
335 symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers);
John Bauman66b8ab22014-05-06 15:57:45 -0400336}
337
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500338void IdentifyBuiltIns(GLenum shaderType,
John Bauman66b8ab22014-05-06 15:57:45 -0400339 const ShBuiltInResources& resources,
John Baumand4ae8632014-05-06 16:18:33 -0400340 TSymbolTable &symbolTable)
John Bauman66b8ab22014-05-06 15:57:45 -0400341{
342 //
343 // First, insert some special built-in variables that are not in
344 // the built-in header files.
345 //
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500346 switch(shaderType)
347 {
348 case GL_FRAGMENT_SHADER:
Nicolas Capensd603ecd2015-02-18 14:52:21 -0500349 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
350 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
351 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
352 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
353 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
John Bauman66b8ab22014-05-06 15:57:45 -0400354 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500355 case GL_VERTEX_SHADER:
Nicolas Capensd603ecd2015-02-18 14:52:21 -0500356 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
357 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
John Bauman66b8ab22014-05-06 15:57:45 -0400358 break;
359 default: assert(false && "Language not supported");
360 }
361
362 //
363 // Next, identify which built-ins from the already loaded headers have
364 // a mapping to an operator. Those that are not identified as such are
365 // expected to be resolved through a library of functions, versus as
366 // operations.
367 //
368 symbolTable.relateToOperator("not", EOpVectorLogicalNot);
369
370 symbolTable.relateToOperator("matrixCompMult", EOpMul);
371
372 symbolTable.relateToOperator("equal", EOpVectorEqual);
373 symbolTable.relateToOperator("notEqual", EOpVectorNotEqual);
374 symbolTable.relateToOperator("lessThan", EOpLessThan);
375 symbolTable.relateToOperator("greaterThan", EOpGreaterThan);
376 symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual);
377 symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual);
378
379 symbolTable.relateToOperator("radians", EOpRadians);
380 symbolTable.relateToOperator("degrees", EOpDegrees);
381 symbolTable.relateToOperator("sin", EOpSin);
382 symbolTable.relateToOperator("cos", EOpCos);
383 symbolTable.relateToOperator("tan", EOpTan);
384 symbolTable.relateToOperator("asin", EOpAsin);
385 symbolTable.relateToOperator("acos", EOpAcos);
386 symbolTable.relateToOperator("atan", EOpAtan);
387
388 symbolTable.relateToOperator("pow", EOpPow);
389 symbolTable.relateToOperator("exp2", EOpExp2);
390 symbolTable.relateToOperator("log", EOpLog);
391 symbolTable.relateToOperator("exp", EOpExp);
392 symbolTable.relateToOperator("log2", EOpLog2);
393 symbolTable.relateToOperator("sqrt", EOpSqrt);
394 symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt);
395
396 symbolTable.relateToOperator("abs", EOpAbs);
397 symbolTable.relateToOperator("sign", EOpSign);
398 symbolTable.relateToOperator("floor", EOpFloor);
399 symbolTable.relateToOperator("ceil", EOpCeil);
400 symbolTable.relateToOperator("fract", EOpFract);
401 symbolTable.relateToOperator("mod", EOpMod);
402 symbolTable.relateToOperator("min", EOpMin);
403 symbolTable.relateToOperator("max", EOpMax);
404 symbolTable.relateToOperator("clamp", EOpClamp);
405 symbolTable.relateToOperator("mix", EOpMix);
406 symbolTable.relateToOperator("step", EOpStep);
407 symbolTable.relateToOperator("smoothstep", EOpSmoothStep);
408
409 symbolTable.relateToOperator("length", EOpLength);
410 symbolTable.relateToOperator("distance", EOpDistance);
411 symbolTable.relateToOperator("dot", EOpDot);
412 symbolTable.relateToOperator("cross", EOpCross);
413 symbolTable.relateToOperator("normalize", EOpNormalize);
414 symbolTable.relateToOperator("faceforward", EOpFaceForward);
415 symbolTable.relateToOperator("reflect", EOpReflect);
416 symbolTable.relateToOperator("refract", EOpRefract);
417
418 symbolTable.relateToOperator("any", EOpAny);
419 symbolTable.relateToOperator("all", EOpAll);
420
421 // Map language-specific operators.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500422 switch(shaderType)
423 {
424 case GL_VERTEX_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400425 break;
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500426 case GL_FRAGMENT_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400427 if (resources.OES_standard_derivatives) {
428 symbolTable.relateToOperator("dFdx", EOpDFdx);
429 symbolTable.relateToOperator("dFdy", EOpDFdy);
430 symbolTable.relateToOperator("fwidth", EOpFwidth);
431
432 symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives");
433 symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives");
434 symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives");
435 }
436 break;
437 default: break;
438 }
439
440 // Finally add resource-specific variables.
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500441 switch(shaderType)
John Bauman66b8ab22014-05-06 15:57:45 -0400442 {
Nicolas Capens08ca3c62015-02-13 16:06:45 -0500443 case GL_FRAGMENT_SHADER:
John Bauman66b8ab22014-05-06 15:57:45 -0400444 {
445 // Set up gl_FragData. The array size.
446 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true);
447 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capensd603ecd2015-02-18 14:52:21 -0500448 symbolTable.insert(0, *new TVariable(NewPoolTString("gl_FragData"), fragData));
John Bauman66b8ab22014-05-06 15:57:45 -0400449 }
450 break;
451 default: break;
452 }
453}
454
455void InitExtensionBehavior(const ShBuiltInResources& resources,
456 TExtensionBehavior& extBehavior)
457{
458 if (resources.OES_standard_derivatives)
459 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
John Baumand4ae8632014-05-06 16:18:33 -0400460 if (resources.OES_fragment_precision_high)
461 extBehavior["GL_FRAGMENT_PRECISION_HIGH"] = EBhUndefined;
John Bauman66b8ab22014-05-06 15:57:45 -0400462}