blob: 6cdea3c3e3c16e512d1bf9f6b863b7d829b6aeed [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//
8// Create strings that declare built-in definitions, add built-ins that
9// cannot be expressed in the files, and establish mappings between
10// built-in functions and operators.
11//
12
Geoff Lang17732822013-08-29 13:46:49 -040013#include "compiler/translator/Initialize.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000014
Geoff Lang17732822013-08-29 13:46:49 -040015#include "compiler/translator/intermediate.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000016
Jamie Madill1b452142013-07-12 14:51:11 -040017void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018{
Nicolas Capens49a88872013-06-20 09:54:03 -040019 TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1);
20 TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2);
21 TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3);
22 TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4);
23
Nicolas Capens75fb4752013-07-10 15:14:47 -040024 TType *int1 = new TType(EbtInt, EbpUndefined, EvqGlobal, 1);
Nicolas Capens49a88872013-06-20 09:54:03 -040025 TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2);
26 TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3);
27 TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4);
alokp@chromium.orge4249f02010-07-26 18:13:52 +000028
daniel@transgaming.com0578f812010-05-17 09:58:39 +000029 //
alokp@chromium.orge4249f02010-07-26 18:13:52 +000030 // Angle and Trigonometric Functions.
daniel@transgaming.com0578f812010-05-17 09:58:39 +000031 //
Nicolas Capens8f80e022013-07-11 11:20:50 -040032 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "radians", float1);
33 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "radians", float2);
34 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "radians", float3);
35 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "radians", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000036
Nicolas Capens8f80e022013-07-11 11:20:50 -040037 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "degrees", float1);
38 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "degrees", float2);
39 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "degrees", float3);
40 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "degrees", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000041
Nicolas Capens8f80e022013-07-11 11:20:50 -040042 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sin", float1);
43 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sin", float2);
44 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sin", float3);
45 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sin", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000046
Nicolas Capens8f80e022013-07-11 11:20:50 -040047 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "cos", float1);
48 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "cos", float2);
49 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cos", float3);
50 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "cos", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000051
Nicolas Capens8f80e022013-07-11 11:20:50 -040052 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "tan", float1);
53 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "tan", float2);
54 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "tan", float3);
55 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "tan", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056
Nicolas Capens8f80e022013-07-11 11:20:50 -040057 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "asin", float1);
58 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "asin", float2);
59 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "asin", float3);
60 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "asin", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000061
Nicolas Capens8f80e022013-07-11 11:20:50 -040062 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "acos", float1);
63 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "acos", float2);
64 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "acos", float3);
65 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "acos", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000066
Nicolas Capens8f80e022013-07-11 11:20:50 -040067 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1, float1);
68 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2, float2);
69 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3, float3);
70 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000071
Nicolas Capens8f80e022013-07-11 11:20:50 -040072 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "atan", float1);
73 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "atan", float2);
74 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "atan", float3);
75 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "atan", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000076
alokp@chromium.orge4249f02010-07-26 18:13:52 +000077 //
78 // Exponential Functions.
79 //
Nicolas Capens8f80e022013-07-11 11:20:50 -040080 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "pow", float1, float1);
81 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "pow", float2, float2);
82 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "pow", float3, float3);
83 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "pow", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000084
Nicolas Capens8f80e022013-07-11 11:20:50 -040085 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp", float1);
86 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp", float2);
87 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp", float3);
88 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000089
Nicolas Capens8f80e022013-07-11 11:20:50 -040090 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log", float1);
91 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log", float2);
92 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log", float3);
93 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094
Nicolas Capens8f80e022013-07-11 11:20:50 -040095 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "exp2", float1);
96 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "exp2", float2);
97 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "exp2", float3);
98 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "exp2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099
Nicolas Capens8f80e022013-07-11 11:20:50 -0400100 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "log2", float1);
101 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "log2", float2);
102 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "log2", float3);
103 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "log2", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000104
Nicolas Capens8f80e022013-07-11 11:20:50 -0400105 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sqrt", float1);
106 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sqrt", float2);
107 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sqrt", float3);
108 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109
Nicolas Capens8f80e022013-07-11 11:20:50 -0400110 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "inversesqrt", float1);
111 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "inversesqrt", float2);
112 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "inversesqrt", float3);
113 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "inversesqrt", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000114
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000115 //
116 // Common Functions.
117 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400118 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "abs", float1);
119 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "abs", float2);
120 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "abs", float3);
121 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "abs", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000122
Nicolas Capens8f80e022013-07-11 11:20:50 -0400123 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "sign", float1);
124 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "sign", float2);
125 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "sign", float3);
126 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "sign", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
Nicolas Capens8f80e022013-07-11 11:20:50 -0400128 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "floor", float1);
129 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "floor", float2);
130 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "floor", float3);
131 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "floor", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132
Nicolas Capens8f80e022013-07-11 11:20:50 -0400133 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "ceil", float1);
134 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "ceil", float2);
135 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "ceil", float3);
136 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "ceil", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000137
Nicolas Capens8f80e022013-07-11 11:20:50 -0400138 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "fract", float1);
139 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "fract", float2);
140 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "fract", float3);
141 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "fract", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000142
Nicolas Capens8f80e022013-07-11 11:20:50 -0400143 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mod", float1, float1);
144 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float1);
145 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float1);
146 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float1);
147 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mod", float2, float2);
148 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mod", float3, float3);
149 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mod", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150
Nicolas Capens8f80e022013-07-11 11:20:50 -0400151 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "min", float1, float1);
152 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float1);
153 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float1);
154 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float1);
155 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "min", float2, float2);
156 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "min", float3, float3);
157 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "min", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000158
Nicolas Capens8f80e022013-07-11 11:20:50 -0400159 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "max", float1, float1);
160 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float1);
161 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float1);
162 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float1);
163 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "max", float2, float2);
164 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "max", float3, float3);
165 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "max", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000166
Nicolas Capens8f80e022013-07-11 11:20:50 -0400167 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "clamp", float1, float1, float1);
168 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float1, float1);
169 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float1, float1);
170 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float1, float1);
171 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "clamp", float2, float2, float2);
172 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "clamp", float3, float3, float3);
173 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "clamp", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000174
Nicolas Capens8f80e022013-07-11 11:20:50 -0400175 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "mix", float1, float1, float1);
176 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float1);
177 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float1);
178 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float1);
179 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "mix", float2, float2, float2);
180 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "mix", float3, float3, float3);
181 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "mix", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000182
Nicolas Capens8f80e022013-07-11 11:20:50 -0400183 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "step", float1, float1);
184 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float2, float2);
185 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float3, float3);
186 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float4, float4);
187 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "step", float1, float2);
188 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "step", float1, float3);
189 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "step", float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000190
Nicolas Capens8f80e022013-07-11 11:20:50 -0400191 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "smoothstep", float1, float1, float1);
192 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float2, float2, float2);
193 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float3, float3, float3);
194 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float4, float4, float4);
195 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "smoothstep", float1, float1, float2);
196 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "smoothstep", float1, float1, float3);
197 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "smoothstep", float1, float1, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000198
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000199 //
200 // Geometric Functions.
201 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400202 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float1);
203 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float2);
204 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float3);
205 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "length", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000206
Nicolas Capens8f80e022013-07-11 11:20:50 -0400207 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float1, float1);
208 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float2, float2);
209 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float3, float3);
210 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "distance", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000211
Nicolas Capens8f80e022013-07-11 11:20:50 -0400212 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float1, float1);
213 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float2, float2);
214 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float3, float3);
215 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "dot", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216
Nicolas Capens8f80e022013-07-11 11:20:50 -0400217 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "cross", float3, float3);
218 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "normalize", float1);
219 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "normalize", float2);
220 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "normalize", float3);
221 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "normalize", float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000222
Nicolas Capens8f80e022013-07-11 11:20:50 -0400223 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "faceforward", float1, float1, float1);
224 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "faceforward", float2, float2, float2);
225 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "faceforward", float3, float3, float3);
226 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "faceforward", float4, float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000227
Nicolas Capens8f80e022013-07-11 11:20:50 -0400228 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "reflect", float1, float1);
229 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "reflect", float2, float2);
230 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "reflect", float3, float3);
231 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "reflect", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000232
Nicolas Capens8f80e022013-07-11 11:20:50 -0400233 symbolTable.insertBuiltIn(COMMON_BUILTINS, float1, "refract", float1, float1, float1);
234 symbolTable.insertBuiltIn(COMMON_BUILTINS, float2, "refract", float2, float2, float1);
235 symbolTable.insertBuiltIn(COMMON_BUILTINS, float3, "refract", float3, float3, float1);
236 symbolTable.insertBuiltIn(COMMON_BUILTINS, float4, "refract", float4, float4, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400237
238 TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, 2);
239 TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, 3);
240 TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000241
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000242 //
243 // Matrix Functions.
244 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400245 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat2, "matrixCompMult", mat2, mat2);
246 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat3, "matrixCompMult", mat3, mat3);
247 symbolTable.insertBuiltIn(COMMON_BUILTINS, mat4, "matrixCompMult", mat4, mat4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400248
249 TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1);
250 TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2);
251 TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3);
252 TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000253
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000254 //
255 // Vector relational functions.
256 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400257 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", float2, float2);
258 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", float3, float3);
259 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000260
Nicolas Capens8f80e022013-07-11 11:20:50 -0400261 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThan", int2, int2);
262 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThan", int3, int3);
263 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000264
Nicolas Capens8f80e022013-07-11 11:20:50 -0400265 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", float2, float2);
266 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", float3, float3);
267 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000268
Nicolas Capens8f80e022013-07-11 11:20:50 -0400269 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "lessThanEqual", int2, int2);
270 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "lessThanEqual", int3, int3);
271 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "lessThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000272
Nicolas Capens8f80e022013-07-11 11:20:50 -0400273 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", float2, float2);
274 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", float3, float3);
275 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000276
Nicolas Capens8f80e022013-07-11 11:20:50 -0400277 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThan", int2, int2);
278 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThan", int3, int3);
279 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThan", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000280
Nicolas Capens8f80e022013-07-11 11:20:50 -0400281 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", float2, float2);
282 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", float3, float3);
283 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284
Nicolas Capens8f80e022013-07-11 11:20:50 -0400285 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "greaterThanEqual", int2, int2);
286 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "greaterThanEqual", int3, int3);
287 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "greaterThanEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000288
Nicolas Capens8f80e022013-07-11 11:20:50 -0400289 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", float2, float2);
290 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", float3, float3);
291 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000292
Nicolas Capens8f80e022013-07-11 11:20:50 -0400293 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", int2, int2);
294 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", int3, int3);
295 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000296
Nicolas Capens8f80e022013-07-11 11:20:50 -0400297 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "equal", bool2, bool2);
298 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "equal", bool3, bool3);
299 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "equal", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000300
Nicolas Capens8f80e022013-07-11 11:20:50 -0400301 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", float2, float2);
302 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", float3, float3);
303 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", float4, float4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000304
Nicolas Capens8f80e022013-07-11 11:20:50 -0400305 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", int2, int2);
306 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", int3, int3);
307 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", int4, int4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000308
Nicolas Capens8f80e022013-07-11 11:20:50 -0400309 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "notEqual", bool2, bool2);
310 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "notEqual", bool3, bool3);
311 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "notEqual", bool4, bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000312
Nicolas Capens8f80e022013-07-11 11:20:50 -0400313 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool2);
314 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool3);
315 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "any", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000316
Nicolas Capens8f80e022013-07-11 11:20:50 -0400317 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool2);
318 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool3);
319 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool1, "all", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000320
Nicolas Capens8f80e022013-07-11 11:20:50 -0400321 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool2, "not", bool2);
322 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool3, "not", bool3);
323 symbolTable.insertBuiltIn(COMMON_BUILTINS, bool4, "not", bool4);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000324
Nicolas Capens49a88872013-06-20 09:54:03 -0400325 TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1);
326 TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000327
328 //
329 // Texture Functions for GLSL ES 1.0
330 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400331 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2);
332 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3);
333 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4);
334 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000335
Nicolas Capens49a88872013-06-20 09:54:03 -0400336 if (resources.OES_EGL_image_external)
337 {
338 TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1);
339
Nicolas Capens8f80e022013-07-11 11:20:50 -0400340 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
341 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
342 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000343 }
344
Nicolas Capens49a88872013-06-20 09:54:03 -0400345 if (resources.ARB_texture_rectangle)
346 {
347 TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1);
348
Nicolas Capens8f80e022013-07-11 11:20:50 -0400349 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
350 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
351 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float4);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000352 }
353
Nicolas Capens67a819f2013-07-09 12:08:58 -0400354 if (type == SH_FRAGMENT_SHADER)
Nicolas Capens49a88872013-06-20 09:54:03 -0400355 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400356 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", sampler2D, float2, float1);
357 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float3, float1);
358 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", sampler2D, float4, float1);
359 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCube", samplerCube, float3, float1);
shannonwoods@chromium.org2ac0be92013-05-30 00:02:27 +0000360
Nicolas Capens49a88872013-06-20 09:54:03 -0400361 if (resources.OES_standard_derivatives)
362 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400363 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdx", float1);
364 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdx", float2);
365 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdx", float3);
366 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdx", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400367
Nicolas Capens8f80e022013-07-11 11:20:50 -0400368 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "dFdy", float1);
369 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "dFdy", float2);
370 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "dFdy", float3);
371 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "dFdy", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400372
Nicolas Capens8f80e022013-07-11 11:20:50 -0400373 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float1, "fwidth", float1);
374 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float2, "fwidth", float2);
375 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float3, "fwidth", float3);
376 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "fwidth", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400377 }
378 }
379
380 if(type == SH_VERTEX_SHADER)
381 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400382 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DLod", sampler2D, float2, float1);
383 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float3, float1);
384 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProjLod", sampler2D, float4, float1);
385 symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
Nicolas Capens49a88872013-06-20 09:54:03 -0400386 }
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000387
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400388 TType *sampler3D = new TType(EbtSampler3D, EbpUndefined, EvqGlobal, 1);
Nicolas Capenseceb50d2013-06-19 13:37:17 -0400389 TType *sampler2DArray = new TType(EbtSampler2DArray, EbpUndefined, EvqGlobal, 1);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400390
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000391 //
392 // Texture Functions for GLSL ES 3.0
393 //
Nicolas Capens8f80e022013-07-11 11:20:50 -0400394 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler2D, float2);
395 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler3D, float3);
396 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerCube, float3);
397 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler2DArray, float3);
398 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler2D, float3);
399 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler2D, float4);
400 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler3D, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400401 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureLod", sampler2D, float2, float1);
402 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureLod", sampler3D, float3, float1);
403 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureLod", samplerCube, float3, float1);
404 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureLod", sampler2DArray, float3, float1);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000405
Nicolas Capens67a819f2013-07-09 12:08:58 -0400406 if (type == SH_FRAGMENT_SHADER)
407 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400408 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler2D, float2, float1);
409 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler3D, float3, float1);
410 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", samplerCube, float3, float1);
411 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "texture", sampler2DArray, float3, float1);
412 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler2D, float3, float1);
413 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler2D, float4, float1);
414 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureProj", sampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400415 }
416
Nicolas Capens93632462013-06-17 14:10:38 -0400417 TType *isampler2D = new TType(EbtISampler2D, EbpUndefined, EvqGlobal, 1);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400418 TType *isampler3D = new TType(EbtISampler3D, EbpUndefined, EvqGlobal, 1);
Nicolas Capens93632462013-06-17 14:10:38 -0400419 TType *isamplerCube = new TType(EbtISamplerCube, EbpUndefined, EvqGlobal, 1);
Nicolas Capenseceb50d2013-06-19 13:37:17 -0400420 TType *isampler2DArray = new TType(EbtISampler2DArray, EbpUndefined, EvqGlobal, 1);
Nicolas Capens93632462013-06-17 14:10:38 -0400421
Nicolas Capens8f80e022013-07-11 11:20:50 -0400422 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler2D, float2);
423 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler3D, float3);
424 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isamplerCube, float3);
425 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler2DArray, float3);
426 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler2D, float3);
427 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler2D, float4);
428 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler3D, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400429 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureLod", isampler2D, float2, float1);
430 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureLod", isampler3D, float3, float1);
431 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureLod", isamplerCube, float3, float1);
432 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureLod", isampler2DArray, float3, float1);
Nicolas Capens93632462013-06-17 14:10:38 -0400433
Nicolas Capens67a819f2013-07-09 12:08:58 -0400434 if (type == SH_FRAGMENT_SHADER)
435 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400436 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler2D, float2, float1);
437 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler3D, float3, float1);
438 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isamplerCube, float3, float1);
439 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "texture", isampler2DArray, float3, float1);
440 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler2D, float3, float1);
441 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler2D, float4, float1);
442 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureProj", isampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400443 }
444
Nicolas Capens86132292013-06-17 15:50:23 -0400445 TType *usampler2D = new TType(EbtUSampler2D, EbpUndefined, EvqGlobal, 1);
Nicolas Capens73f5bf62013-06-17 16:13:33 -0400446 TType *usampler3D = new TType(EbtUSampler3D, EbpUndefined, EvqGlobal, 1);
Nicolas Capens86132292013-06-17 15:50:23 -0400447 TType *usamplerCube = new TType(EbtUSamplerCube, EbpUndefined, EvqGlobal, 1);
Nicolas Capenseceb50d2013-06-19 13:37:17 -0400448 TType *usampler2DArray = new TType(EbtUSampler2DArray, EbpUndefined, EvqGlobal, 1);
Nicolas Capens86132292013-06-17 15:50:23 -0400449 TType *uint4 = new TType(EbtUInt, EbpUndefined, EvqGlobal, 4);
450
Nicolas Capens8f80e022013-07-11 11:20:50 -0400451 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler2D, float2);
452 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler3D, float3);
453 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usamplerCube, float3);
454 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler2DArray, float3);
455 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler2D, float3);
456 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler2D, float4);
457 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler3D, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400458 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureLod", usampler2D, float2, float1);
459 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureLod", usampler3D, float3, float1);
460 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureLod", usamplerCube, float3, float1);
461 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureLod", usampler2DArray, float3, float1);
Nicolas Capens86132292013-06-17 15:50:23 -0400462
Nicolas Capens67a819f2013-07-09 12:08:58 -0400463 if (type == SH_FRAGMENT_SHADER)
464 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400465 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler2D, float2, float1);
466 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler3D, float3, float1);
467 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usamplerCube, float3, float1);
468 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "texture", usampler2DArray, float3, float1);
469 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler2D, float3, float1);
470 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler2D, float4, float1);
471 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureProj", usampler3D, float4, float1);
Nicolas Capens67a819f2013-07-09 12:08:58 -0400472 }
473
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400474 TType *sampler2DShadow = new TType(EbtSampler2DShadow, EbpUndefined, EvqGlobal, 1);
475 TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow, EbpUndefined, EvqGlobal, 1);
476 TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow, EbpUndefined, EvqGlobal, 1);
477
Nicolas Capens8f80e022013-07-11 11:20:50 -0400478 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
479 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
480 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4);
481 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4);
Jamie Madill16a1c072013-10-22 15:42:15 -0400482 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureLod", sampler2DShadow, float3, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400483
484 if (type == SH_FRAGMENT_SHADER)
485 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400486 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3, float1);
487 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4, float1);
488 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DArrayShadow, float4, float1);
489 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureProj", sampler2DShadow, float4, float1);
Nicolas Capens77c9d1a2013-07-11 11:10:34 -0400490 }
491
Nicolas Capens8f80e022013-07-11 11:20:50 -0400492 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2D, int1);
493 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", isampler2D, int1);
494 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", usampler2D, int1);
495 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler3D, int1);
496 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", isampler3D, int1);
497 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", usampler3D, int1);
498 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCube, int1);
499 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", isamplerCube, int1);
500 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", usamplerCube, int1);
501 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArray, int1);
502 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", isampler2DArray, int1);
503 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", usampler2DArray, int1);
504 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", sampler2DShadow, int1);
505 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int2, "textureSize", samplerCubeShadow, int1);
506 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int3, "textureSize", sampler2DArrayShadow, int1);
Nicolas Capens75fb4752013-07-10 15:14:47 -0400507
Nicolas Capens49a88872013-06-20 09:54:03 -0400508 if(type == SH_FRAGMENT_SHADER)
509 {
Nicolas Capens8f80e022013-07-11 11:20:50 -0400510 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdx", float1);
511 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdx", float2);
512 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdx", float3);
513 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdx", float4);
Nicolas Capens49a88872013-06-20 09:54:03 -0400514
Nicolas Capens8f80e022013-07-11 11:20:50 -0400515 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "dFdy", float1);
516 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "dFdy", float2);
517 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "dFdy", float3);
518 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "dFdy", float4);
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000519
Nicolas Capens8f80e022013-07-11 11:20:50 -0400520 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "fwidth", float1);
521 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float2, "fwidth", float2);
522 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float3, "fwidth", float3);
523 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "fwidth", float4);
alokp@chromium.org06098892010-08-26 19:36:42 +0000524 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000525
Nicolas Capens1fbc2872014-01-03 14:12:09 -0500526 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler2D, float2, int2);
527 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler2D, float2, int2, float1);
528 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler2D, float2, int2);
529 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler2D, float2, int2, float1);
530 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler2D, float2, int2);
531 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler2D, float2, int2, float1);
532 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler3D, float3, int3);
533 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler3D, float3, int3, float1);
534 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler3D, float3, int3);
535 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler3D, float3, int3, float1);
536 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler3D, float3, int3);
537 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler3D, float3, int3, float1);
538 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int3);
539 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "textureOffset", sampler2DShadow, float3, int3, float1);
540 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler2DArray, float3, int2);
541 symbolTable.insertBuiltIn(ESSL3_BUILTINS, float4, "textureOffset", sampler2DArray, float3, int2, float1);
542 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler2DArray, float3, int2);
543 symbolTable.insertBuiltIn(ESSL3_BUILTINS, int4, "textureOffset", isampler2DArray, float3, int2, float1);
544 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler2DArray, float3, int2);
545 symbolTable.insertBuiltIn(ESSL3_BUILTINS, uint4, "textureOffset", usampler2DArray, float3, int2, float1);
546
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000547 //
548 // Depth range in window coordinates
549 //
Jamie Madill98493dd2013-07-08 14:39:03 -0400550 TFieldList *fields = NewPoolTFieldList();
551 TSourceLoc zeroSourceLoc = {0};
552 TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near"), zeroSourceLoc);
553 TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far"), zeroSourceLoc);
554 TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff"), zeroSourceLoc);
555 fields->push_back(near);
556 fields->push_back(far);
557 fields->push_back(diff);
558 TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
559 TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
Nicolas Capens49a88872013-06-20 09:54:03 -0400560 symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
Jamie Madill98493dd2013-07-08 14:39:03 -0400561 TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
Nicolas Capens49a88872013-06-20 09:54:03 -0400562 depthRange->setQualifier(EvqUniform);
563 symbolTable.insert(COMMON_BUILTINS, *depthRange);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000564
Nicolas Capens49a88872013-06-20 09:54:03 -0400565 //
566 // Implementation dependent built-in constants.
567 //
568 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexAttribs", resources.MaxVertexAttribs);
569 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors);
570 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits);
571 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits);
572 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxTextureImageUnits", resources.MaxTextureImageUnits);
573 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000574
Nicolas Capens49a88872013-06-20 09:54:03 -0400575 symbolTable.insertConstInt(ESSL1_BUILTINS, "gl_MaxVaryingVectors", resources.MaxVaryingVectors);
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000576
577 if (spec != SH_CSS_SHADERS_SPEC)
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000578 {
Jamie Madill455a6f52013-10-17 10:45:46 -0400579 symbolTable.insertConstInt(COMMON_BUILTINS, "gl_MaxDrawBuffers", resources.MaxDrawBuffers);
shannon.woods%transgaming.com@gtempaccount.com5209de82013-04-13 03:41:53 +0000580 }
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000581
Nicolas Capens49a88872013-06-20 09:54:03 -0400582 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxVertexOutputVectors", resources.MaxVertexOutputVectors);
583 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxFragmentInputVectors", resources.MaxFragmentInputVectors);
584 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MinProgramTexelOffset", resources.MinProgramTexelOffset);
585 symbolTable.insertConstInt(ESSL3_BUILTINS, "gl_MaxProgramTexelOffset", resources.MaxProgramTexelOffset);
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000586}
587
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000588void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
Nicolas Capens49a88872013-06-20 09:54:03 -0400589 const ShBuiltInResources &resources,
590 TSymbolTable &symbolTable)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000591{
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000592 //
593 // First, insert some special built-in variables that are not in
594 // the built-in header files.
595 //
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000596 switch(type) {
597 case SH_FRAGMENT_SHADER:
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000598 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
599 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
600 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000601
602 //
603 // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
604 // Instead, css_MixColor and css_ColorMatrix are available.
605 //
606 if (spec != SH_CSS_SHADERS_SPEC) {
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000607 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
608 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400609 if (resources.EXT_frag_depth) {
610 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
611 symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
612 }
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000613 } else {
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000614 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000615 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000616 }
617
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000618 break;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000619
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000620 case SH_VERTEX_SHADER:
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000621 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
622 symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000623 break;
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000624
625 default: assert(false && "Language not supported");
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000626 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000627
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000628 //
629 // Next, identify which built-ins from the already loaded headers have
630 // a mapping to an operator. Those that are not identified as such are
631 // expected to be resolved through a library of functions, versus as
632 // operations.
633 //
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000634 symbolTable.relateToOperator(COMMON_BUILTINS, "matrixCompMult", EOpMul);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000635
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000636 symbolTable.relateToOperator(COMMON_BUILTINS, "equal", EOpVectorEqual);
637 symbolTable.relateToOperator(COMMON_BUILTINS, "notEqual", EOpVectorNotEqual);
638 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThan", EOpLessThan);
639 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThan", EOpGreaterThan);
640 symbolTable.relateToOperator(COMMON_BUILTINS, "lessThanEqual", EOpLessThanEqual);
641 symbolTable.relateToOperator(COMMON_BUILTINS, "greaterThanEqual", EOpGreaterThanEqual);
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000642
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000643 symbolTable.relateToOperator(COMMON_BUILTINS, "radians", EOpRadians);
644 symbolTable.relateToOperator(COMMON_BUILTINS, "degrees", EOpDegrees);
645 symbolTable.relateToOperator(COMMON_BUILTINS, "sin", EOpSin);
646 symbolTable.relateToOperator(COMMON_BUILTINS, "cos", EOpCos);
647 symbolTable.relateToOperator(COMMON_BUILTINS, "tan", EOpTan);
648 symbolTable.relateToOperator(COMMON_BUILTINS, "asin", EOpAsin);
649 symbolTable.relateToOperator(COMMON_BUILTINS, "acos", EOpAcos);
650 symbolTable.relateToOperator(COMMON_BUILTINS, "atan", EOpAtan);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000651
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000652 symbolTable.relateToOperator(COMMON_BUILTINS, "pow", EOpPow);
653 symbolTable.relateToOperator(COMMON_BUILTINS, "exp2", EOpExp2);
654 symbolTable.relateToOperator(COMMON_BUILTINS, "log", EOpLog);
655 symbolTable.relateToOperator(COMMON_BUILTINS, "exp", EOpExp);
656 symbolTable.relateToOperator(COMMON_BUILTINS, "log2", EOpLog2);
657 symbolTable.relateToOperator(COMMON_BUILTINS, "sqrt", EOpSqrt);
658 symbolTable.relateToOperator(COMMON_BUILTINS, "inversesqrt", EOpInverseSqrt);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000659
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000660 symbolTable.relateToOperator(COMMON_BUILTINS, "abs", EOpAbs);
661 symbolTable.relateToOperator(COMMON_BUILTINS, "sign", EOpSign);
662 symbolTable.relateToOperator(COMMON_BUILTINS, "floor", EOpFloor);
663 symbolTable.relateToOperator(COMMON_BUILTINS, "ceil", EOpCeil);
664 symbolTable.relateToOperator(COMMON_BUILTINS, "fract", EOpFract);
665 symbolTable.relateToOperator(COMMON_BUILTINS, "mod", EOpMod);
666 symbolTable.relateToOperator(COMMON_BUILTINS, "min", EOpMin);
667 symbolTable.relateToOperator(COMMON_BUILTINS, "max", EOpMax);
668 symbolTable.relateToOperator(COMMON_BUILTINS, "clamp", EOpClamp);
669 symbolTable.relateToOperator(COMMON_BUILTINS, "mix", EOpMix);
670 symbolTable.relateToOperator(COMMON_BUILTINS, "step", EOpStep);
671 symbolTable.relateToOperator(COMMON_BUILTINS, "smoothstep", EOpSmoothStep);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000672
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000673 symbolTable.relateToOperator(COMMON_BUILTINS, "length", EOpLength);
674 symbolTable.relateToOperator(COMMON_BUILTINS, "distance", EOpDistance);
675 symbolTable.relateToOperator(COMMON_BUILTINS, "dot", EOpDot);
676 symbolTable.relateToOperator(COMMON_BUILTINS, "cross", EOpCross);
677 symbolTable.relateToOperator(COMMON_BUILTINS, "normalize", EOpNormalize);
678 symbolTable.relateToOperator(COMMON_BUILTINS, "faceforward", EOpFaceForward);
679 symbolTable.relateToOperator(COMMON_BUILTINS, "reflect", EOpReflect);
680 symbolTable.relateToOperator(COMMON_BUILTINS, "refract", EOpRefract);
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000681
shannonwoods@chromium.org89992b52013-05-30 00:02:20 +0000682 symbolTable.relateToOperator(COMMON_BUILTINS, "any", EOpAny);
683 symbolTable.relateToOperator(COMMON_BUILTINS, "all", EOpAll);
684 symbolTable.relateToOperator(COMMON_BUILTINS, "not", EOpVectorLogicalNot);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000685
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000686 // Map language-specific operators.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000687 switch(type) {
688 case SH_VERTEX_SHADER:
alokp@chromium.org58e54292010-08-24 21:40:03 +0000689 break;
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000690 case SH_FRAGMENT_SHADER:
alokp@chromium.org06098892010-08-26 19:36:42 +0000691 if (resources.OES_standard_derivatives) {
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000692 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdx", EOpDFdx);
693 symbolTable.relateToOperator(ESSL1_BUILTINS, "dFdy", EOpDFdy);
694 symbolTable.relateToOperator(ESSL1_BUILTINS, "fwidth", EOpFwidth);
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000695
shannonwoods@chromium.orgc6ac65f2013-05-30 00:02:50 +0000696 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdx", "GL_OES_standard_derivatives");
697 symbolTable.relateToExtension(ESSL1_BUILTINS, "dFdy", "GL_OES_standard_derivatives");
698 symbolTable.relateToExtension(ESSL1_BUILTINS, "fwidth", "GL_OES_standard_derivatives");
alokp@chromium.org06098892010-08-26 19:36:42 +0000699 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000700 break;
701 default: break;
702 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000703
Nicolas Capensf4cb0e12013-06-24 16:11:36 -0400704 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdx", EOpDFdx);
705 symbolTable.relateToOperator(ESSL3_BUILTINS, "dFdy", EOpDFdy);
706 symbolTable.relateToOperator(ESSL3_BUILTINS, "fwidth", EOpFwidth);
707
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000708 // Finally add resource-specific variables.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000709 switch(type) {
maxvujovic@gmail.com430f5e02012-06-08 17:47:59 +0000710 case SH_FRAGMENT_SHADER:
711 if (spec != SH_CSS_SHADERS_SPEC) {
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000712 // Set up gl_FragData. The array size.
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000713 TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
alokp@chromium.org94a86ad2010-08-25 20:02:11 +0000714 fragData.setArraySize(resources.MaxDrawBuffers);
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000715 symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000716 }
717 break;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000718 default: break;
719 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000720}
721
alokp@chromium.org4888ceb2010-10-01 21:13:12 +0000722void InitExtensionBehavior(const ShBuiltInResources& resources,
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000723 TExtensionBehavior& extBehavior)
724{
725 if (resources.OES_standard_derivatives)
zmo@google.com09c323a2011-08-12 18:22:25 +0000726 extBehavior["GL_OES_standard_derivatives"] = EBhUndefined;
727 if (resources.OES_EGL_image_external)
728 extBehavior["GL_OES_EGL_image_external"] = EBhUndefined;
kbr@chromium.org205fef32011-11-22 20:50:02 +0000729 if (resources.ARB_texture_rectangle)
730 extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
shannon.woods@transgaming.com550cd092013-02-28 23:19:54 +0000731 if (resources.EXT_draw_buffers)
732 extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
Jamie Madill2aeb26a2013-07-08 14:02:55 -0400733 if (resources.EXT_frag_depth)
734 extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +0000735}