blob: 93a2483e38ee0c93a498f3e2720171de8995cc0f [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
alokp@chromium.orge4249f02010-07-26 18:13:52 +000078 //
79 // Exponential Functions.
80 //
Nicolas Capens8f80e022013-07-11 11:20:50 -040081 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1);
82 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2);
83 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3);
84 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000085
Nicolas Capens8f80e022013-07-11 11:20:50 -040086 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1);
87 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2);
88 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3);
89 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090
Nicolas Capens8f80e022013-07-11 11:20:50 -040091 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1);
92 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2);
93 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3);
94 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000095
Nicolas Capens8f80e022013-07-11 11:20:50 -040096 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1);
97 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2);
98 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3);
99 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000100
Nicolas Capens8f80e022013-07-11 11:20:50 -0400101 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1);
102 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2);
103 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3);
104 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000105
Nicolas Capens8f80e022013-07-11 11:20:50 -0400106 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1);
107 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2);
108 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3);
109 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000110
Nicolas Capens8f80e022013-07-11 11:20:50 -0400111 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1);
112 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2);
113 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3);
114 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000116 //
117 // Common Functions.
118 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400119 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1);
120 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2);
121 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3);
122 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000123
Nicolas Capens8f80e022013-07-11 11:20:50 -0400124 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1);
125 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2);
126 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3);
127 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000128
Nicolas Capens8f80e022013-07-11 11:20:50 -0400129 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1);
130 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2);
131 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3);
132 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000133
Nicolas Capens8f80e022013-07-11 11:20:50 -0400134 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1);
135 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2);
136 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3);
137 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138
Nicolas Capens8f80e022013-07-11 11:20:50 -0400139 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1);
140 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2);
141 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3);
142 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143
Nicolas Capens8f80e022013-07-11 11:20:50 -0400144 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1);
145 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1);
146 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1);
147 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1);
148 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2);
149 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3);
150 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000151
Nicolas Capens8f80e022013-07-11 11:20:50 -0400152 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1);
153 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1);
154 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1);
155 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1);
156 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2);
157 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3);
158 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159
Nicolas Capens8f80e022013-07-11 11:20:50 -0400160 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1);
161 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1);
162 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1);
163 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1);
164 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2);
165 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3);
166 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000167
Nicolas Capens8f80e022013-07-11 11:20:50 -0400168 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1);
169 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1);
170 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1);
171 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1);
172 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2);
173 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3);
174 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000175
Nicolas Capens8f80e022013-07-11 11:20:50 -0400176 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1);
177 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1);
178 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1);
179 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1);
180 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2);
181 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3);
182 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000183
Nicolas Capens8f80e022013-07-11 11:20:50 -0400184 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1);
185 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2);
186 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3);
187 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4);
188 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2);
189 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3);
190 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000191
Nicolas Capens8f80e022013-07-11 11:20:50 -0400192 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1);
193 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2);
194 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3);
195 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4);
196 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2);
197 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3);
198 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000199
Olli Etuahoe8d2c072015-01-08 16:33:54 +0200200 TType *uint1 = new TType(EbtUInt);
201 TType *uint2 = new TType(EbtUInt, 2);
202 TType *uint3 = new TType(EbtUInt, 3);
203 TType *uint4 = new TType(EbtUInt, 4);
204
205 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int1, "floatBitsToInt", float1);
206 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "floatBitsToInt", float2);
207 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "floatBitsToInt", float3);
208 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "floatBitsToInt", float4);
209
210 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint1, "floatBitsToUint", float1);
211 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint2, "floatBitsToUint", float2);
212 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint3, "floatBitsToUint", float3);
213 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "floatBitsToUint", float4);
214
215 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "intBitsToFloat", int1);
216 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "intBitsToFloat", int2);
217 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "intBitsToFloat", int3);
218 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "intBitsToFloat", int4);
219
220 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "uintBitsToFloat", uint1);
221 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "uintBitsToFloat", uint2);
222 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "uintBitsToFloat", uint3);
223 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "uintBitsToFloat", uint4);
224
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000225 //
226 // Geometric Functions.
227 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400228 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1);
229 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2);
230 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3);
231 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000232
Nicolas Capens8f80e022013-07-11 11:20:50 -0400233 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1);
234 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2);
235 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3);
236 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000237
Nicolas Capens8f80e022013-07-11 11:20:50 -0400238 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1);
239 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2);
240 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3);
241 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000242
Nicolas Capens8f80e022013-07-11 11:20:50 -0400243 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3);
244 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1);
245 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2);
246 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3);
247 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000248
Nicolas Capens8f80e022013-07-11 11:20:50 -0400249 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1);
250 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2);
251 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3);
252 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
Nicolas Capens8f80e022013-07-11 11:20:50 -0400254 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1);
255 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2);
256 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3);
257 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000258
Nicolas Capens8f80e022013-07-11 11:20:50 -0400259 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1);
260 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1);
261 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1);
262 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400263
Nicolas Capensc9508842014-02-14 17:48:50 -0500264 TType *mat2 = new TType(EbtFloat, 2, 2);
265 TType *mat3 = new TType(EbtFloat, 3, 3);
266 TType *mat4 = new TType(EbtFloat, 4, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000267
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000268 //
269 // Matrix Functions.
270 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400271 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2);
272 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3);
273 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400274
Nicolas Capensc9508842014-02-14 17:48:50 -0500275 TType *bool1 = new TType(EbtBool);
276 TType *bool2 = new TType(EbtBool, 2);
277 TType *bool3 = new TType(EbtBool, 3);
278 TType *bool4 = new TType(EbtBool, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000279
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000280 //
281 // Vector relational functions.
282 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400283 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2);
284 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3);
285 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000286
Nicolas Capens8f80e022013-07-11 11:20:50 -0400287 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2);
288 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3);
289 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000290
Nicolas Capens8f80e022013-07-11 11:20:50 -0400291 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2);
292 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3);
293 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000294
Nicolas Capens8f80e022013-07-11 11:20:50 -0400295 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2);
296 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3);
297 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000298
Nicolas Capens8f80e022013-07-11 11:20:50 -0400299 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2);
300 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3);
301 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000302
Nicolas Capens8f80e022013-07-11 11:20:50 -0400303 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2);
304 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3);
305 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000306
Nicolas Capens8f80e022013-07-11 11:20:50 -0400307 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2);
308 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3);
309 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000310
Nicolas Capens8f80e022013-07-11 11:20:50 -0400311 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2);
312 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3);
313 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000314
Nicolas Capens8f80e022013-07-11 11:20:50 -0400315 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2);
316 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3);
317 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000318
Nicolas Capens8f80e022013-07-11 11:20:50 -0400319 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2);
320 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3);
321 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000322
Nicolas Capens8f80e022013-07-11 11:20:50 -0400323 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2);
324 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3);
325 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000326
Nicolas Capens8f80e022013-07-11 11:20:50 -0400327 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2);
328 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3);
329 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000330
Nicolas Capens8f80e022013-07-11 11:20:50 -0400331 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2);
332 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3);
333 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334
Nicolas Capens8f80e022013-07-11 11:20:50 -0400335 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2);
336 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3);
337 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000338
Nicolas Capens8f80e022013-07-11 11:20:50 -0400339 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2);
340 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3);
341 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000342
Nicolas Capens8f80e022013-07-11 11:20:50 -0400343 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2);
344 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3);
345 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000346
Nicolas Capens8f80e022013-07-11 11:20:50 -0400347 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2);
348 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3);
349 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000350
Nicolas Capensc9508842014-02-14 17:48:50 -0500351 TType *sampler2D = new TType(EbtSampler2D);
352 TType *samplerCube = new TType(EbtSamplerCube);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000353
354 //
355 // Texture Functions for GLSL ES 1.0
356 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400357 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
358 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
359 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
360 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000361
Nicolas Capens49a88872013-06-20 09:54:03 -0400362 if (resources.OES_EGL_image_external)
363 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500364 TType *samplerExternalOES = new TType(EbtSamplerExternalOES);
Nicolas Capens49a88872013-06-20 09:54:03 -0400365
Nicolas Capens8f80e022013-07-11 11:20:50 -0400366 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
367 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
368 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000369 }
370
Nicolas Capens49a88872013-06-20 09:54:03 -0400371 if (resources.ARB_texture_rectangle)
372 {
Nicolas Capensc9508842014-02-14 17:48:50 -0500373 TType *sampler2DRect = new TType(EbtSampler2DRect);
Nicolas Capens49a88872013-06-20 09:54:03 -0400374
Nicolas Capens8f80e022013-07-11 11:20:50 -0400375 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
376 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
377 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000378 }
379
Nicolas Capens46485082014-04-15 13:12:50 -0400380 if (resources.EXT_shader_texture_lod)
381 {
382 /* The *Grad* variants are new to both vertex and fragment shaders; the fragment
383 * shader specific pieces are added separately below.
384 */
385 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DGradEXT", sampler2D, float2, float2, float2);
386 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float3, float2, float2);
387 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjGradEXT", sampler2D, float4, float2, float2);
388 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeGradEXT", samplerCube, float3, float3, float3);
389 }
390
Jamie Madill183bde52014-07-02 15:31:19 -0400391 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400392 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400393 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
394 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
395 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
396 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000397
Nicolas Capens49a88872013-06-20 09:54:03 -0400398 if (resources.OES_standard_derivatives)
399 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400400 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1);
401 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2);
402 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3);
403 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4);
Nicolas Capens46485082014-04-15 13:12:50 -0400404
Nicolas Capens8f80e022013-07-11 11:20:50 -0400405 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1);
406 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2);
407 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3);
408 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400409
Nicolas Capens8f80e022013-07-11 11:20:50 -0400410 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1);
411 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2);
412 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3);
413 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400414 }
Nicolas Capens46485082014-04-15 13:12:50 -0400415
416 if (resources.EXT_shader_texture_lod)
417 {
418 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLodEXT", sampler2D, float2, float1);
419 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float3, float1);
420 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLodEXT", sampler2D, float4, float1);
421 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLodEXT", samplerCube, float3, float1);
422 }
Nicolas Capens49a88872013-06-20 09:54:03 -0400423 }
424
Jamie Madill183bde52014-07-02 15:31:19 -0400425 if(type == GL_VERTEX_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400426 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400427 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
428 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
429 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
430 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400431 }
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000432
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500433 TType *gvec4 = new TType(EbtGVec4);
434
435 TType *gsampler2D = new TType(EbtGSampler2D);
436 TType *gsamplerCube = new TType(EbtGSamplerCube);
437 TType *gsampler3D = new TType(EbtGSampler3D);
438 TType *gsampler2DArray = new TType(EbtGSampler2DArray);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400439
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000440 //
441 // Texture Functions for GLSL ES 3.0
442 //
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500443 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2);
444 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3);
445 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3);
446 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3);
447 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3);
448 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4);
449 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4);
450 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2D, float2, float1);
451 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler3D, float3, float1);
452 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsamplerCube, float3, float1);
453 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLod", gsampler2DArray, float3, float1);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000454
Jamie Madill183bde52014-07-02 15:31:19 -0400455 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens67a819f2013-07-09 12:08:58 -0400456 {
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500457 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2D, float2, float1);
458 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler3D, float3, float1);
459 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsamplerCube, float3, float1);
460 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texture", gsampler2DArray, float3, float1);
461 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float3, float1);
462 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler2D, float4, float1);
463 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400464 }
465
Nicolas Capensc9508842014-02-14 17:48:50 -0500466 TType *sampler2DShadow = new TType(EbtSampler2DShadow);
467 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow);
468 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400469
Nicolas Capens8f80e022013-07-11 11:20:50 -0400470 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
471 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
472 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
473 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400474 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400475
Jamie Madill183bde52014-07-02 15:31:19 -0400476 if (type == GL_FRAGMENT_SHADER)
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400477 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400478 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
479 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400480 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400481 }
482
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500483 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsampler2D, int1);
484 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler3D, int1);
485 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", gsamplerCube, int1);
486 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", gsampler2DArray, int1);
Nicolas Capens8f80e022013-07-11 11:20:50 -0400487 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
488 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
489 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
Nicolas Capens75fb4752013-07-10 15:14:47 -0400490
Jamie Madill183bde52014-07-02 15:31:19 -0400491 if(type == GL_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400492 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400493 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdx", float1);
494 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdx", float2);
495 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdx", float3);
496 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdx", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400497
Nicolas Capens8f80e022013-07-11 11:20:50 -0400498 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdy", float1);
499 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdy", float2);
500 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdy", float3);
501 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdy", float4);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000502
Nicolas Capens8f80e022013-07-11 11:20:50 -0400503 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "fwidth", float1);
504 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "fwidth", float2);
505 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "fwidth", float3);
506 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "fwidth", float4);
alokp@chromium.org06098892010-08-26 19:36:42 +0000507 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000508
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500509 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2);
510 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3);
511 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2);
512 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2);
513
Jamie Madill183bde52014-07-02 15:31:19 -0400514 if(type == GL_FRAGMENT_SHADER)
Nicolas Capens4fd5e4a2014-02-14 18:17:15 -0500515 {
516 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2D, float2, int2, float1);
517 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler3D, float3, int3, float1);
518 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int2, float1);
519 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureOffset", gsampler2DArray, float3, int2, float1);
520 }
Nicolas Capens1fbc2872014-01-03 14:12:09 -0500521
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500522 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2);
523 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2);
524 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3);
525 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2);
526
Jamie Madill183bde52014-07-02 15:31:19 -0400527 if(type == GL_FRAGMENT_SHADER)
Nicolas Capensdf86c6b2014-02-14 20:09:17 -0500528 {
529 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float3, int2, float1);
530 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler2D, float4, int2, float1);
531 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjOffset", gsampler3D, float4, int3, float1);
532 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjOffset", sampler2DShadow, float4, int2, float1);
533 }
534
535 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2D, float2, float1, int2);
536 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler3D, float3, float1, int3);
537 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLodOffset", sampler2DShadow, float3, float1, int2);
538 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureLodOffset", gsampler2DArray, float3, float1, int2);
539
Nicolas Capens2adc2562014-02-14 23:50:59 -0500540 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float3, float1);
541 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler2D, float4, float1);
542 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLod", gsampler3D, float4, float1);
543 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLod", sampler2DShadow, float4, float1);
544
545 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float3, float1, int2);
546 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler2D, float4, float1, int2);
547 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjLodOffset", gsampler3D, float4, float1, int3);
548 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjLodOffset", sampler2DShadow, float4, float1, int2);
549
Nicolas Capensfc014542014-02-18 14:47:13 -0500550 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2D, int2, int1);
551 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler3D, int3, int1);
552 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetch", gsampler2DArray, int3, int1);
553
554 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2D, int2, int1, int2);
555 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler3D, int3, int1, int3);
556 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "texelFetchOffset", gsampler2DArray, int3, int1, int2);
557
Nicolas Capensd11d5492014-02-19 17:06:10 -0500558 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2D, float2, float2, float2);
559 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler3D, float3, float3, float3);
560 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsamplerCube, float3, float3, float3);
561 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DShadow, float3, float2, float2);
562 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", samplerCubeShadow, float4, float3, float3);
563 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGrad", gsampler2DArray, float3, float2, float2);
564 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGrad", sampler2DArrayShadow, float4, float2, float2);
565
Nicolas Capensbf7db102014-02-19 17:20:28 -0500566 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2D, float2, float2, float2, int2);
567 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler3D, float3, float3, float3, int3);
568 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DShadow, float3, float2, float2, int2);
569 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureGradOffset", gsampler2DArray, float3, float2, float2, int2);
570 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureGradOffset", sampler2DArrayShadow, float4, float2, float2, int2);
571
Nicolas Capensf7378e32014-02-19 17:29:32 -0500572 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float3, float2, float2);
573 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler2D, float4, float2, float2);
574 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGrad", gsampler3D, float4, float3, float3);
575 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGrad", sampler2DShadow, float4, float2, float2);
576
577 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float3, float2, float2, int2);
578 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler2D, float4, float2, float2, int2);
579 symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProjGradOffset", gsampler3D, float4, float3, float3, int3);
580 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProjGradOffset", sampler2DShadow, float4, float2, float2, int2);
581
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000582 //
583 // Depth range in window coordinates
584 //
Jamie Madill98493dd2013-07-08 14:39:03 -0400585 TFieldList *fields = NewPoolTFieldList();
Jamie Madill37f77d22014-04-30 16:10:13 -0400586 TSourceLoc zeroSourceLoc = {0, 0, 0, 0};
Jamie Madill98493dd2013-07-08 14:39:03 -0400587 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
588 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
589 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
590 fields->push_back(near);
591 fields->push_back(far);
592 fields->push_back(diff);
593 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
594 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400595 symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
Jamie Madill98493dd2013-07-08 14:39:03 -0400596 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
Nicolas Capens49a88872013-06-20 09:54:03 -0400597 depthRange->setQualifier(EvqUniform);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400598 symbolTable.insert(COMMON_BUILTINS, depthRange);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000599
Nicolas Capens49a88872013-06-20 09:54:03 -0400600 //
601 // Implementation dependent built-in constants.
602 //
603 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
604 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
605 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
606 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
607 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
608 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000609
Nicolas Capens49a88872013-06-20 09:54:03 -0400610 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000611
612 if (spec != SH_CSS_SHADERS_SPEC)
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000613 {
Jamie Madill455a6f52013-10-17 10:45:46 -0400614 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000615 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000616
Nicolas Capens49a88872013-06-20 09:54:03 -0400617 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
618 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
619 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
620 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000621}
622
Jamie Madill183bde52014-07-02 15:31:19 -0400623void IdentifyBuiltIns(sh::GLenum type, ShShaderSpec spec,
Nicolas Capens49a88872013-06-20 09:54:03 -0400624 const ShBuiltInResources &resources,
625 TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000626{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000627 //
628 // First, insert some special built-in variables that are not in
629 // the built-in header files.
630 //
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000631 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400632 case GL_FRAGMENT_SHADER:
Nicolas Capensadfffe42014-06-17 02:13:36 -0400633 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
634 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
635 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000636
637 //
638 // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
639 // Instead, css_MixColor and css_ColorMatrix are available.
640 //
641 if (spec != SH_CSS_SHADERS_SPEC) {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400642 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
643 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400644 if (resources.EXT_frag_depth) {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400645 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400646 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
647 }
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100648 if (resources.EXT_shader_framebuffer_fetch)
649 {
650 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
651 }
652 else if (resources.NV_shader_framebuffer_fetch)
653 {
654 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragColor"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
655 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqLastFragData, 4)));
656 }
657 else if (resources.ARM_shader_framebuffer_fetch)
658 {
659 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragColorARM"), TType(EbtFloat, EbpMedium, EvqLastFragColor, 4)));
660 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000661 } else {
Nicolas Capensadfffe42014-06-17 02:13:36 -0400662 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
663 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000664 }
665
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000666 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000667
Jamie Madill183bde52014-07-02 15:31:19 -0400668 case GL_VERTEX_SHADER:
Nicolas Capensadfffe42014-06-17 02:13:36 -0400669 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
670 symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000671 break;
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000672
673 default: assert(false && "Language not supported");
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000674 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000675
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000676 //
677 // Next, identify which built-ins from the already loaded headers have
678 // a mapping to an operator. Those that are not identified as such are
679 // expected to be resolved through a library of functions, versus as
680 // operations.
681 //
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000682 symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000683
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000684 symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual);
685 symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual);
686 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan);
687 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan);
688 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual);
689 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual);
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000690
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000691 symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians);
692 symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees);
693 symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin);
694 symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos);
695 symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan);
696 symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin);
697 symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos);
698 symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000699
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000700 symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow);
701 symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2);
702 symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog);
703 symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp);
704 symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2);
705 symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt);
706 symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000707
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000708 symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs);
709 symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign);
710 symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor);
711 symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil);
712 symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract);
713 symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod);
714 symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin);
715 symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax);
716 symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp);
717 symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix);
718 symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep);
719 symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000720
Olli Etuahoe8d2c072015-01-08 16:33:54 +0200721 symbolTable.relateToOperator(ESSL3_BUILTINS, "floatBitsToInt", EOpFloatBitsToInt);
722 symbolTable.relateToOperator(ESSL3_BUILTINS, "floatBitsToUint", EOpFloatBitsToUint);
723 symbolTable.relateToOperator(ESSL3_BUILTINS, "intBitsToFloat", EOpIntBitsToFloat);
724 symbolTable.relateToOperator(ESSL3_BUILTINS, "uintBitsToFloat", EOpUintBitsToFloat);
725
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000726 symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength);
727 symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance);
728 symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot);
729 symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross);
730 symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize);
731 symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward);
732 symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect);
733 symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract);
Nicolas Capens46485082014-04-15 13:12:50 -0400734
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000735 symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny);
736 symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll);
737 symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000738
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000739 // Map language-specific operators.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000740 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400741 case GL_VERTEX_SHADER:
alokp@chromium.org58e54292010-08-24 21:40:03 +0000742 break;
Jamie Madill183bde52014-07-02 15:31:19 -0400743 case GL_FRAGMENT_SHADER:
Nicolas Capens46485082014-04-15 13:12:50 -0400744 if (resources.OES_standard_derivatives)
745 {
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000746 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx);
747 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy);
748 symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000749
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000750 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
751 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
752 symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
alokp@chromium.org06098892010-08-26 19:36:42 +0000753 }
Nicolas Capens46485082014-04-15 13:12:50 -0400754 if (resources.EXT_shader_texture_lod)
755 {
756 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DLodEXT", "GL_EXT_shader_texture_lod");
757 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjLodEXT", "GL_EXT_shader_texture_lod");
758 symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeLodEXT", "GL_EXT_shader_texture_lod");
759 }
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100760 if (resources.NV_shader_framebuffer_fetch)
761 {
762 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragColor", "GL_NV_shader_framebuffer_fetch");
763 }
764 else if (resources.ARM_shader_framebuffer_fetch)
765 {
766 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragColorARM", "GL_ARM_shader_framebuffer_fetch");
767 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000768 break;
769 default: break;
770 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000771
Nicolas Capensf4cb0e12013-06-24 16:11:36 -0400772 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx", EOpDFdx);
773 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy", EOpDFdy);
774 symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth);
775
Nicolas Capens46485082014-04-15 13:12:50 -0400776 if (resources.EXT_shader_texture_lod)
777 {
778 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DGradEXT", "GL_EXT_shader_texture_lod");
779 symbolTable.relateToExtension(ESSL1_BUILTINS, "texture2DProjGradEXT", "GL_EXT_shader_texture_lod");
780 symbolTable.relateToExtension(ESSL1_BUILTINS, "textureCubeGradEXT", "GL_EXT_shader_texture_lod");
781 }
782
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000783 // Finally add resource-specific variables.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000784 switch(type) {
Jamie Madill183bde52014-07-02 15:31:19 -0400785 case GL_FRAGMENT_SHADER:
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000786 if (spec != SH_CSS_SHADERS_SPEC) {
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000787 // Set up gl_FragData. The array size.
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000788 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000789 fragData.setArraySize(resources.MaxDrawBuffers);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400790 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100791
792 if (resources.EXT_shader_framebuffer_fetch || resources.NV_shader_framebuffer_fetch) {
793 // Set up gl_LastFragData. The array size.
794 TType lastFragData(EbtFloat, EbpMedium, EvqLastFragData, 4, 1, true);
795 lastFragData.setArraySize(resources.MaxDrawBuffers);
796 symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_LastFragData"), lastFragData));
797
798 if (resources.EXT_shader_framebuffer_fetch)
799 {
800 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragData", "GL_EXT_shader_framebuffer_fetch");
801 }
802 else if (resources.NV_shader_framebuffer_fetch)
803 {
804 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_LastFragData", "GL_NV_shader_framebuffer_fetch");
805 }
806 }
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000807 }
808 break;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000809 default: break;
810 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000811}
812
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000813void InitExtensionBehavior(const ShBuiltInResources& resources,
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000814 TExtensionBehavior& extBehavior)
815{
816 if (resources.OES_standard_derivatives)
zmo@google.com09c323a2011-08-12 18:22:25 +0000817 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
818 if (resources.OES_EGL_image_external)
819 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
kbr@chromium.org205fef32011-11-22 20:50:02 +0000820 if (resources.ARB_texture_rectangle)
821 extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
shannon.woods@transgaming.com550cd092013-02-28 23:19:54 +0000822 if (resources.EXT_draw_buffers)
823 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400824 if (resources.EXT_frag_depth)
825 extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
Nicolas Capens46485082014-04-15 13:12:50 -0400826 if (resources.EXT_shader_texture_lod)
827 extBehavior["GL_EXT_shader_texture_lod"] = EBhUndefined;
Erik Dahlströmea7a2122014-11-17 16:15:57 +0100828 if (resources.EXT_shader_framebuffer_fetch)
829 extBehavior["GL_EXT_shader_framebuffer_fetch"] = EBhUndefined;
830 if (resources.NV_shader_framebuffer_fetch)
831 extBehavior["GL_NV_shader_framebuffer_fetch"] = EBhUndefined;
832 if (resources.ARM_shader_framebuffer_fetch)
833 extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000834}