blob: cd0ef81a590dfe80e7829d5d4edb28099e22cceb [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens1fbc2872014-01-03 14:12:09 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7//
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -05008// Create symbols that declare built-in definitions, add built-ins that
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009// cannot be expressed in the files, and establish mappings between
10// built-in functions and operators.
11//
12
Geoff Lang17732822013-08-29 13:46:49 -040013#include "compiler/translator/Initialize.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014
Jamie Madillb1a85f42014-08-19 15:23:24 -040015#include "compiler/translator/IntermNode.h"
Jamie Madill183bde52014-07-02 15:31:19 -040016#include "angle_gl.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000017
Jamie Madill183bde52014-07-02 15:31:19 -040018void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000019{
Nicolas Capensc9508842014-02-14 17:48:50 -050020 TType *float1 = new TType(EbtFloat);
21 TType *float2 = new TType(EbtFloat, 2);
22 TType *float3 = new TType(EbtFloat, 3);
23 TType *float4 = new TType(EbtFloat, 4);
Nicolas Capens49a88872013-06-20 09:54:03 -040024
Nicolas Capensc9508842014-02-14 17:48:50 -050025 TType *int1 = new TType(EbtInt);
26 TType *int2 = new TType(EbtInt, 2);
27 TType *int3 = new TType(EbtInt, 3);
28 TType *int4 = new TType(EbtInt, 4);
alokp@chromium.orge4249f02010-07-26 18:13:52 +000029
daniel@transgaming.com0578f812010-05-17 09:58:39 +000030 //
alokp@chromium.orge4249f02010-07-26 18:13:52 +000031 // Angle and Trigonometric Functions.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000032 //
Nicolas Capens8f80e022013-07-11 11:20:50 -040033 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "radians", float1);
34 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "radians", float2);
35 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "radians", float3);
36 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "radians", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000037
Nicolas Capens8f80e022013-07-11 11:20:50 -040038 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "degrees", float1);
39 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "degrees", float2);
40 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "degrees", float3);
41 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "degrees", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000042
Nicolas Capens8f80e022013-07-11 11:20:50 -040043 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sin", float1);
44 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sin", float2);
45 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sin", float3);
46 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sin", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047
Nicolas Capens8f80e022013-07-11 11:20:50 -040048 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "cos", float1);
49 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "cos", float2);
50 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cos", float3);
51 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "cos", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052
Nicolas Capens8f80e022013-07-11 11:20:50 -040053 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "tan", float1);
54 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "tan", float2);
55 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "tan", float3);
56 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "tan", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000057
Nicolas Capens8f80e022013-07-11 11:20:50 -040058 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "asin", float1);
59 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "asin", float2);
60 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "asin", float3);
61 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "asin", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062
Nicolas Capens8f80e022013-07-11 11:20:50 -040063 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "acos", float1);
64 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "acos", float2);
65 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "acos", float3);
66 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "acos", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000067
Nicolas Capens8f80e022013-07-11 11:20:50 -040068 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1, float1);
69 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2, float2);
70 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3, float3);
71 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072
Nicolas Capens8f80e022013-07-11 11:20:50 -040073 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1);
74 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2);
75 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3);
76 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000077
Olli Etuaho5c9cd3d2014-12-18 13:04:25 +020078 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "sinh", float1);
79 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "sinh", float2);
80 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "sinh", float3);
81 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "sinh", float4);
82
83 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "cosh", float1);
84 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "cosh", float2);
85 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "cosh", float3);
86 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "cosh", float4);
87
88 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "tanh", float1);
89 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "tanh", float2);
90 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "tanh", float3);
91 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "tanh", float4);
92
93 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "asinh", float1);
94 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "asinh", float2);
95 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "asinh", float3);
96 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "asinh", float4);
97
98 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "acosh", float1);
99 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "acosh", float2);
100 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "acosh", float3);
101 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "acosh", float4);
102
103 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "atanh", float1);
104 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "atanh", float2);
105 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "atanh", float3);
106 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "atanh", float4);
107
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000108 //
109 // Exponential Functions.
110 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400111 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1);
112 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2);
113 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3);
114 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115
Nicolas Capens8f80e022013-07-11 11:20:50 -0400116 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1);
117 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2);
118 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3);
119 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000120
Nicolas Capens8f80e022013-07-11 11:20:50 -0400121 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1);
122 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2);
123 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3);
124 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000125
Nicolas Capens8f80e022013-07-11 11:20:50 -0400126 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1);
127 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2);
128 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3);
129 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000130
Nicolas Capens8f80e022013-07-11 11:20:50 -0400131 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1);
132 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2);
133 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3);
134 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
Nicolas Capens8f80e022013-07-11 11:20:50 -0400136 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1);
137 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2);
138 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3);
139 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140
Nicolas Capens8f80e022013-07-11 11:20:50 -0400141 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1);
142 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2);
143 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3);
144 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000145
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000146 //
147 // Common Functions.
148 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400149 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1);
150 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2);
151 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3);
152 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000153
Nicolas Capens8f80e022013-07-11 11:20:50 -0400154 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1);
155 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2);
156 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3);
157 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158
Nicolas Capens8f80e022013-07-11 11:20:50 -0400159 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1);
160 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2);
161 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3);
162 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000163
Nicolas Capens8f80e022013-07-11 11:20:50 -0400164 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1);
165 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2);
166 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3);
167 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000168
Nicolas Capens8f80e022013-07-11 11:20:50 -0400169 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1);
170 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2);
171 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3);
172 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000173
Nicolas Capens8f80e022013-07-11 11:20:50 -0400174 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1);
175 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1);
176 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1);
177 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1);
178 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2);
179 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3);
180 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000181
Nicolas Capens8f80e022013-07-11 11:20:50 -0400182 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1);
183 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1);
184 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1);
185 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1);
186 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2);
187 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3);
188 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000189
Nicolas Capens8f80e022013-07-11 11:20:50 -0400190 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1);
191 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1);
192 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1);
193 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1);
194 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2);
195 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3);
196 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000197
Nicolas Capens8f80e022013-07-11 11:20:50 -0400198 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1);
199 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1);
200 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1);
201 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1);
202 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2);
203 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3);
204 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000205
Nicolas Capens8f80e022013-07-11 11:20:50 -0400206 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1);
207 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1);
208 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1);
209 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1);
210 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2);
211 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3);
212 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000213
Nicolas Capens8f80e022013-07-11 11:20:50 -0400214 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1);
215 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2);
216 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3);
217 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4);
218 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2);
219 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3);
220 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000221
Nicolas Capens8f80e022013-07-11 11:20:50 -0400222 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1);
223 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2);
224 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3);
225 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4);
226 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2);
227 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3);
228 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000229
Olli Etuahoe8d2c072015-01-08 16:33:54 +0200230 TType *uint1 = new TType(EbtUInt);
231 TType *uint2 = new TType(EbtUInt, 2);
232 TType *uint3 = new TType(EbtUInt, 3);
233 TType *uint4 = new TType(EbtUInt, 4);
234
235 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int1, "floatBitsToInt", float1);
236 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "floatBitsToInt", float2);
237 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "floatBitsToInt", float3);
238 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "floatBitsToInt", float4);
239
240 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint1, "floatBitsToUint", float1);
241 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint2, "floatBitsToUint", float2);
242 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint3, "floatBitsToUint", float3);
243 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "floatBitsToUint", float4);
244
245 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "intBitsToFloat", int1);
246 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "intBitsToFloat", int2);
247 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "intBitsToFloat", int3);
248 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "intBitsToFloat", int4);
249
250 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "uintBitsToFloat", uint1);
251 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "uintBitsToFloat", uint2);
252 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "uintBitsToFloat", uint3);
253 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "uintBitsToFloat", uint4);
254
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000255 //
256 // Geometric Functions.
257 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400258 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1);
259 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2);
260 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3);
261 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000262
Nicolas Capens8f80e022013-07-11 11:20:50 -0400263 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1);
264 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2);
265 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3);
266 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000267
Nicolas Capens8f80e022013-07-11 11:20:50 -0400268 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1);
269 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2);
270 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3);
271 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000272
Nicolas Capens8f80e022013-07-11 11:20:50 -0400273 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3);
274 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1);
275 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2);
276 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3);
277 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000278
Nicolas Capens8f80e022013-07-11 11:20:50 -0400279 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1);
280 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2);
281 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3);
282 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000283
Nicolas Capens8f80e022013-07-11 11:20:50 -0400284 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1);
285 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2);
286 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3);
287 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288
Nicolas Capens8f80e022013-07-11 11:20:50 -0400289 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1);
290 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1);
291 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1);
292 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400293
Nicolas Capensc9508842014-02-14 17:48:50 -0500294 TType *mat2 = new TType(EbtFloat, 2, 2);
295 TType *mat3 = new TType(EbtFloat, 3, 3);
296 TType *mat4 = new TType(EbtFloat, 4, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000297
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000298 //
299 // Matrix Functions.
300 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400301 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2);
302 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3);
303 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400304
Nicolas Capensc9508842014-02-14 17:48:50 -0500305 TType *bool1 = new TType(EbtBool);
306 TType *bool2 = new TType(EbtBool, 2);
307 TType *bool3 = new TType(EbtBool, 3);
308 TType *bool4 = new TType(EbtBool, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000309
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000310 //
311 // Vector relational functions.
312 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400313 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2);
314 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3);
315 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316
Nicolas Capens8f80e022013-07-11 11:20:50 -0400317 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2);
318 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3);
319 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000320
Nicolas Capens8f80e022013-07-11 11:20:50 -0400321 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2);
322 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3);
323 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000324
Nicolas Capens8f80e022013-07-11 11:20:50 -0400325 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2);
326 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3);
327 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328
Nicolas Capens8f80e022013-07-11 11:20:50 -0400329 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2);
330 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3);
331 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000332
Nicolas Capens8f80e022013-07-11 11:20:50 -0400333 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2);
334 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3);
335 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336
Nicolas Capens8f80e022013-07-11 11:20:50 -0400337 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2);
338 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3);
339 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000340
Nicolas Capens8f80e022013-07-11 11:20:50 -0400341 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2);
342 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3);
343 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000344
Nicolas Capens8f80e022013-07-11 11:20:50 -0400345 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2);
346 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3);
347 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000348
Nicolas Capens8f80e022013-07-11 11:20:50 -0400349 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2);
350 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3);
351 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000352
Nicolas Capens8f80e022013-07-11 11:20:50 -0400353 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2);
354 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3);
355 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000356
Nicolas Capens8f80e022013-07-11 11:20:50 -0400357 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2);
358 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3);
359 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000360
Nicolas Capens8f80e022013-07-11 11:20:50 -0400361 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2);
362 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3);
363 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000364
Nicolas Capens8f80e022013-07-11 11:20:50 -0400365 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2);
366 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3);
367 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000368
Nicolas Capens8f80e022013-07-11 11:20:50 -0400369 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2);
370 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3);
371 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000372
Nicolas Capens8f80e022013-07-11 11:20:50 -0400373 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2);
374 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3);
375 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000376
Nicolas Capens8f80e022013-07-11 11:20:50 -0400377 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2);
378 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3);
379 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000380
Nicolas Capensc9508842014-02-14 17:48:50 -0500381 TType *sampler2D = new TType(EbtSampler2D);
382 TType *samplerCube = new TType(EbtSamplerCube);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000383
384 //
385 // Texture Functions for GLSL ES 1.0
386 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400387 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
388 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
389 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
390 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000391
Nicolas Capens49a88872013-06-20 09:54:03 -0400392 if (resources.OES_EGL_image_external)
393 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500394 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens49a88872013-06-20 09:54:03 -0400395
Nicolas Capens8f80e022013-07-11 11:20:50 -0400396 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
397 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
398 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000399 }
400
Nicolas Capens49a88872013-06-20 09:54:03 -0400401 if (resources.ARB_texture_rectangle)
402 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500403 TType *sampler2DRect = new TType(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400404
Nicolas Capens8f80e022013-07-11 11:20:50 -0400405 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
406 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
407 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000408 }
409
Nicolas Capens46485082014-04-15 13:12:50 -0400410 if (resources.EXT_shader_texture_lod)
411 {
412 /* The *Grad* variants are new to both vertex and fragment shaders; the fragment
413 * shader specific pieces are added separately below.
414 */
415 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DGradEXT", sampler2D, float2, float2, float2);
416 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2);
417 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2);
418 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeGradEXT", samplerCube, float3, float3, float3);
419 }
420
Jamie Madill183bde52014-07-02 15:31:19 -0400421 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400422 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400423 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
424 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
425 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
426 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000427
Nicolas Capens49a88872013-06-20 09:54:03 -0400428 if (resources.OES_standard_derivatives)
429 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400430 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1);
431 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2);
432 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3);
433 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4);
Nicolas Capens46485082014-04-15 13:12:50 -0400434
Nicolas Capens8f80e022013-07-11 11:20:50 -0400435 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1);
436 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2);
437 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3);
438 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400439
Nicolas Capens8f80e022013-07-11 11:20:50 -0400440 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1);
441 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2);
442 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3);
443 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400444 }
Nicolas Capens46485082014-04-15 13:12:50 -0400445
446 if (resources.EXT_shader_texture_lod)
447 {
448 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLodEXT", sampler2D, float2, float1);
449 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float3, float1);
450 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float4, float1);
451 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLodEXT", samplerCube, float3, float1);
452 }
Nicolas Capens49a88872013-06-20 09:54:03 -0400453 }
454
Jamie Madill183bde52014-07-02 15:31:19 -0400455 if(type == GL_VERTEX_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400456 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400457 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
458 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
459 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
460 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400461 }
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000462
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500463 TType *gvec4 = new TType(EbtGVec4);
464
465 TType *gsampler2D = new TType(EbtGSampler2D);
466 TType *gsamplerCube = new TType(EbtGSamplerCube);
467 TType *gsampler3D = new TType(EbtGSampler3D);
468 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400469
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000470 //
471 // Texture Functions for GLSL ES 3.0
472 //
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500473 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
474 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
475 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
476 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
477 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
478 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
479 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
480 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
481 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
482 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
483 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000484
Jamie Madill183bde52014-07-02 15:31:19 -0400485 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens67a819f2013-07-09 12:08:58 -0400486 {
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500487 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
488 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
489 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
490 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
491 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
492 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
493 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400494 }
495
Nicolas Capensc9508842014-02-14 17:48:50 -0500496 TType *sampler2DShadow = new TType(EbtSampler2DShadow);
497 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
498 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400499
Nicolas Capens8f80e022013-07-11 11:20:50 -0400500 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
501 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
502 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
503 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400504 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400505
Jamie Madill183bde52014-07-02 15:31:19 -0400506 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400507 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400508 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
509 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400510 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400511 }
512
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500513 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
514 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
515 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
516 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400517 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
518 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
519 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
Nicolas Capens75fb4752013-07-10 15:14:47 -0400520
Jamie Madill183bde52014-07-02 15:31:19 -0400521 if(type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400522 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400523 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdx", float1);
524 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdx", float2);
525 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdx", float3);
526 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdx", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400527
Nicolas Capens8f80e022013-07-11 11:20:50 -0400528 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdy", float1);
529 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdy", float2);
530 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdy", float3);
531 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdy", float4);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000532
Nicolas Capens8f80e022013-07-11 11:20:50 -0400533 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "fwidth", float1);
534 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "fwidth", float2);
535 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "fwidth", float3);
536 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "fwidth", float4);
alokp@chromium.org06098892010-08-26 19:36:42 +0000537 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000538
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500539 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
540 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
541 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
542 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
543
Jamie Madill183bde52014-07-02 15:31:19 -0400544 if(type == GL_FRAGMENT_SHADER)
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500545 {
546 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
547 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
548 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
549 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
550 }
Nicolas Capens1fbc2872014-01-03 14:12:09 -0500551
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500552 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
553 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
554 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
555 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
556
Jamie Madill183bde52014-07-02 15:31:19 -0400557 if(type == GL_FRAGMENT_SHADER)
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500558 {
559 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
560 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
561 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
562 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
563 }
564
565 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
566 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
567 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
568 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
569
Nicolas Capens2adc2562014-02-14 23:50:59 -0500570 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
571 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
572 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
573 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
574
575 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
576 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
577 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
578 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
579
Nicolas Capensfc014542014-02-18 14:47:13 -0500580 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
581 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
582 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
583
584 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
585 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
586 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
587
Nicolas Capensd11d5492014-02-19 17:06:10 -0500588 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
589 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
590 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
591 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
592 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
593 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
594 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
595
Nicolas Capensbf7db102014-02-19 17:20:28 -0500596 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
597 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
598 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
599 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
600 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
601
Nicolas Capensf7378e32014-02-19 17:29:32 -0500602 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
603 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
604 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
605 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
606
607 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
608 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
609 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
610 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
611
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000612 //
613 // Depth range in window coordinates
614 //
Jamie Madill98493dd2013-07-08 14:39:03 -0400615 TFieldList *fields = NewPoolTFieldList();
Jamie Madill37f77d22014-04-30 16:10:13 -0400616 TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
Jamie Madill98493dd2013-07-08 14:39:03 -0400617 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
618 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
619 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
620 fields->push_back(near);
621 fields->push_back(far);
622 fields->push_back(diff);
623 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
624 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400625 symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
Jamie Madill98493dd2013-07-08 14:39:03 -0400626 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
Nicolas Capens49a88872013-06-20 09:54:03 -0400627 depthRange->setQualifier(EvqUniform);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400628 symbolTable.insert(COMMON_BUILTINS, depthRange);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000629
Nicolas Capens49a88872013-06-20 09:54:03 -0400630 //
631 // Implementation dependent built-in constants.
632 //
633 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
634 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
635 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
636 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
637 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
638 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000639
Nicolas Capens49a88872013-06-20 09:54:03 -0400640 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000641
642 if (spec != SH_CSS_SHADERS_SPEC)
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000643 {
Jamie Madill455a6f52013-10-17 10:45:46 -0400644 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000645 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000646
Nicolas Capens49a88872013-06-20 09:54:03 -0400647 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
648 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
649 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
650 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000651}
652
Jamie Madill183bde52014-07-02 15:31:19 -0400653void IdentifyBuiltIns(sh::GLenum type, ShShaderSpec spec,
Nicolas Capens49a88872013-06-20 09:54:03 -0400654 const ShBuiltInResources &resources,
655 TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000656{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000657 //
658 // First, insert some special built-in variables that are not in
659 // the built-in header files.
660 //
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000661 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400662 case GL_FRAGMENT_SHADER:
Nicolas Capensadfffe42014-06-17 02:13:36 -0400663 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
664 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
665 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000666
667 //
668 // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
669 // Instead, css_MixColor and css_ColorMatrix are available.
670 //
671 if (spec != SH_CSS_SHADERS_SPEC) {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400672 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
673 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400674 if (resources.EXT_frag_depth) {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400675 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400676 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
677 }
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100678 if (resources.EXT_shader_framebuffer_fetch)
679 {
680 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
681 }
682 else if (resources.NV_shader_framebuffer_fetch)
683 {
684 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragColor"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
685 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
686 }
687 else if (resources.ARM_shader_framebuffer_fetch)
688 {
689 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragColorARM"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
690 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000691 } else {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400692 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
693 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000694 }
695
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000696 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000697
Jamie Madill183bde52014-07-02 15:31:19 -0400698 case GL_VERTEX_SHADER:
Nicolas Capensadfffe42014-06-17 02:13:36 -0400699 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
700 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000701 break;
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000702
703 default: assert(false && "Language not supported");
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000704 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000705
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000706 //
707 // Next, identify which built-ins from the already loaded headers have
708 // a mapping to an operator. Those that are not identified as such are
709 // expected to be resolved through a library of functions, versus as
710 // operations.
711 //
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000712 symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000713
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000714 symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual);
715 symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual);
716 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan);
717 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan);
718 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual);
719 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual);
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000720
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000721 symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians);
722 symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees);
723 symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin);
724 symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos);
725 symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan);
726 symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin);
727 symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos);
728 symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000729
Olli Etuaho5c9cd3d2014-12-18 13:04:25 +0200730 symbolTable.relateToOperator(ESSL3_BUILTINS, "sinh", EOpSinh);
731 symbolTable.relateToOperator(ESSL3_BUILTINS, "cosh", EOpCosh);
732 symbolTable.relateToOperator(ESSL3_BUILTINS, "tanh", EOpTanh);
733 symbolTable.relateToOperator(ESSL3_BUILTINS, "asinh", EOpAsinh);
734 symbolTable.relateToOperator(ESSL3_BUILTINS, "acosh", EOpAcosh);
735 symbolTable.relateToOperator(ESSL3_BUILTINS, "atanh", EOpAtanh);
736
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000737 symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow);
738 symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2);
739 symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog);
740 symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp);
741 symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2);
742 symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt);
743 symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000744
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000745 symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs);
746 symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign);
747 symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor);
748 symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil);
749 symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract);
750 symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod);
751 symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin);
752 symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax);
753 symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp);
754 symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix);
755 symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep);
756 symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000757
Olli Etuahoe8d2c072015-01-08 16:33:54 +0200758 symbolTable.relateToOperator(ESSL3_BUILTINS, "floatBitsToInt", EOpFloatBitsToInt);
759 symbolTable.relateToOperator(ESSL3_BUILTINS, "floatBitsToUint", EOpFloatBitsToUint);
760 symbolTable.relateToOperator(ESSL3_BUILTINS, "intBitsToFloat", EOpIntBitsToFloat);
761 symbolTable.relateToOperator(ESSL3_BUILTINS, "uintBitsToFloat", EOpUintBitsToFloat);
762
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000763 symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength);
764 symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance);
765 symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot);
766 symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross);
767 symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize);
768 symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward);
769 symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect);
770 symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract);
Nicolas Capens46485082014-04-15 13:12:50 -0400771
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000772 symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny);
773 symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll);
774 symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000775
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000776 // Map language-specific operators.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000777 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400778 case GL_VERTEX_SHADER:
alokp@chromium.org58e54292010-08-24 21:40:03 +0000779 break;
Jamie Madill183bde52014-07-02 15:31:19 -0400780 case GL_FRAGMENT_SHADER:
Nicolas Capens46485082014-04-15 13:12:50 -0400781 if (resources.OES_standard_derivatives)
782 {
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000783 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx);
784 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy);
785 symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000786
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000787 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
788 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
789 symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
alokp@chromium.org06098892010-08-26 19:36:42 +0000790 }
Nicolas Capens46485082014-04-15 13:12:50 -0400791 if (resources.EXT_shader_texture_lod)
792 {
793 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DLodEXT", "GL_EXT_shader_texture_lod");
794 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjLodEXT", "GL_EXT_shader_texture_lod");
795 symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeLodEXT", "GL_EXT_shader_texture_lod");
796 }
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100797 if (resources.NV_shader_framebuffer_fetch)
798 {
799 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragColor", "GL_NV_shader_framebuffer_fetch");
800 }
801 else if (resources.ARM_shader_framebuffer_fetch)
802 {
803 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragColorARM", "GL_ARM_shader_framebuffer_fetch");
804 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000805 break;
806 default: break;
807 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000808
Nicolas Capensf4cb0e12013-06-24 16:11:36 -0400809 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx", EOpDFdx);
810 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy", EOpDFdy);
811 symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth);
812
Nicolas Capens46485082014-04-15 13:12:50 -0400813 if (resources.EXT_shader_texture_lod)
814 {
815 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DGradEXT", "GL_EXT_shader_texture_lod");
816 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjGradEXT", "GL_EXT_shader_texture_lod");
817 symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeGradEXT", "GL_EXT_shader_texture_lod");
818 }
819
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000820 // Finally add resource-specific variables.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000821 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400822 case GL_FRAGMENT_SHADER:
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000823 if (spec != SH_CSS_SHADERS_SPEC) {
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000824 // Set up gl_FragData. The array size.
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000825 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000826 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400827 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100828
829 if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) {
830 // Set up gl_LastFragData. The array size.
831 TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
832 lastFragData.setArraySize(resources.MaxDrawBuffers);
833 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
834
835 if (resources.EXT_shader_framebuffer_fetch)
836 {
837 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragData", "GL_EXT_shader_framebuffer_fetch");
838 }
839 else if (resources.NV_shader_framebuffer_fetch)
840 {
841 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragData", "GL_NV_shader_framebuffer_fetch");
842 }
843 }
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000844 }
845 break;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000846 default: break;
847 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000848}
849
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000850void InitExtensionBehavior(const ShBuiltInResources& resources,
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000851 TExtensionBehavior& extBehavior)
852{
853 if (resources.OES_standard_derivatives)
zmo@google.com09c323a2011-08-12 18:22:25 +0000854 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
855 if (resources.OES_EGL_image_external)
856 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
kbr@chromium.org205fef32011-11-22 20:50:02 +0000857 if (resources.ARB_texture_rectangle)
858 extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
shannon.woods@transgaming.com550cd092013-02-28 23:19:54 +0000859 if (resources.EXT_draw_buffers)
860 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400861 if (resources.EXT_frag_depth)
862 extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
Nicolas Capens46485082014-04-15 13:12:50 -0400863 if (resources.EXT_shader_texture_lod)
864 extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined;
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100865 if (resources.EXT_shader_framebuffer_fetch)
866 extBehavior["GL_EXT_shader_framebuffer_fetch"] = EBhUndefined;
867 if (resources.NV_shader_framebuffer_fetch)
868 extBehavior["GL_NV_shader_framebuffer_fetch"] = EBhUndefined;
869 if (resources.ARM_shader_framebuffer_fetch)
870 extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000871}