Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // |
michael@0 | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // |
michael@0 | 8 | // Create strings that declare built-in definitions, add built-ins that |
michael@0 | 9 | // cannot be expressed in the files, and establish mappings between |
michael@0 | 10 | // built-in functions and operators. |
michael@0 | 11 | // |
michael@0 | 12 | |
michael@0 | 13 | #include "compiler/Initialize.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "compiler/intermediate.h" |
michael@0 | 16 | |
michael@0 | 17 | void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) |
michael@0 | 18 | { |
michael@0 | 19 | TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1); |
michael@0 | 20 | TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2); |
michael@0 | 21 | TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3); |
michael@0 | 22 | TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4); |
michael@0 | 23 | |
michael@0 | 24 | TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2); |
michael@0 | 25 | TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3); |
michael@0 | 26 | TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4); |
michael@0 | 27 | |
michael@0 | 28 | // |
michael@0 | 29 | // Angle and Trigonometric Functions. |
michael@0 | 30 | // |
michael@0 | 31 | symbolTable.insertBuiltIn(float1, "radians", float1); |
michael@0 | 32 | symbolTable.insertBuiltIn(float2, "radians", float2); |
michael@0 | 33 | symbolTable.insertBuiltIn(float3, "radians", float3); |
michael@0 | 34 | symbolTable.insertBuiltIn(float4, "radians", float4); |
michael@0 | 35 | |
michael@0 | 36 | symbolTable.insertBuiltIn(float1, "degrees", float1); |
michael@0 | 37 | symbolTable.insertBuiltIn(float2, "degrees", float2); |
michael@0 | 38 | symbolTable.insertBuiltIn(float3, "degrees", float3); |
michael@0 | 39 | symbolTable.insertBuiltIn(float4, "degrees", float4); |
michael@0 | 40 | |
michael@0 | 41 | symbolTable.insertBuiltIn(float1, "sin", float1); |
michael@0 | 42 | symbolTable.insertBuiltIn(float2, "sin", float2); |
michael@0 | 43 | symbolTable.insertBuiltIn(float3, "sin", float3); |
michael@0 | 44 | symbolTable.insertBuiltIn(float4, "sin", float4); |
michael@0 | 45 | |
michael@0 | 46 | symbolTable.insertBuiltIn(float1, "cos", float1); |
michael@0 | 47 | symbolTable.insertBuiltIn(float2, "cos", float2); |
michael@0 | 48 | symbolTable.insertBuiltIn(float3, "cos", float3); |
michael@0 | 49 | symbolTable.insertBuiltIn(float4, "cos", float4); |
michael@0 | 50 | |
michael@0 | 51 | symbolTable.insertBuiltIn(float1, "tan", float1); |
michael@0 | 52 | symbolTable.insertBuiltIn(float2, "tan", float2); |
michael@0 | 53 | symbolTable.insertBuiltIn(float3, "tan", float3); |
michael@0 | 54 | symbolTable.insertBuiltIn(float4, "tan", float4); |
michael@0 | 55 | |
michael@0 | 56 | symbolTable.insertBuiltIn(float1, "asin", float1); |
michael@0 | 57 | symbolTable.insertBuiltIn(float2, "asin", float2); |
michael@0 | 58 | symbolTable.insertBuiltIn(float3, "asin", float3); |
michael@0 | 59 | symbolTable.insertBuiltIn(float4, "asin", float4); |
michael@0 | 60 | |
michael@0 | 61 | symbolTable.insertBuiltIn(float1, "acos", float1); |
michael@0 | 62 | symbolTable.insertBuiltIn(float2, "acos", float2); |
michael@0 | 63 | symbolTable.insertBuiltIn(float3, "acos", float3); |
michael@0 | 64 | symbolTable.insertBuiltIn(float4, "acos", float4); |
michael@0 | 65 | |
michael@0 | 66 | symbolTable.insertBuiltIn(float1, "atan", float1, float1); |
michael@0 | 67 | symbolTable.insertBuiltIn(float2, "atan", float2, float2); |
michael@0 | 68 | symbolTable.insertBuiltIn(float3, "atan", float3, float3); |
michael@0 | 69 | symbolTable.insertBuiltIn(float4, "atan", float4, float4); |
michael@0 | 70 | |
michael@0 | 71 | symbolTable.insertBuiltIn(float1, "atan", float1); |
michael@0 | 72 | symbolTable.insertBuiltIn(float2, "atan", float2); |
michael@0 | 73 | symbolTable.insertBuiltIn(float3, "atan", float3); |
michael@0 | 74 | symbolTable.insertBuiltIn(float4, "atan", float4); |
michael@0 | 75 | |
michael@0 | 76 | // |
michael@0 | 77 | // Exponential Functions. |
michael@0 | 78 | // |
michael@0 | 79 | symbolTable.insertBuiltIn(float1, "pow", float1, float1); |
michael@0 | 80 | symbolTable.insertBuiltIn(float2, "pow", float2, float2); |
michael@0 | 81 | symbolTable.insertBuiltIn(float3, "pow", float3, float3); |
michael@0 | 82 | symbolTable.insertBuiltIn(float4, "pow", float4, float4); |
michael@0 | 83 | |
michael@0 | 84 | symbolTable.insertBuiltIn(float1, "exp", float1); |
michael@0 | 85 | symbolTable.insertBuiltIn(float2, "exp", float2); |
michael@0 | 86 | symbolTable.insertBuiltIn(float3, "exp", float3); |
michael@0 | 87 | symbolTable.insertBuiltIn(float4, "exp", float4); |
michael@0 | 88 | |
michael@0 | 89 | symbolTable.insertBuiltIn(float1, "log", float1); |
michael@0 | 90 | symbolTable.insertBuiltIn(float2, "log", float2); |
michael@0 | 91 | symbolTable.insertBuiltIn(float3, "log", float3); |
michael@0 | 92 | symbolTable.insertBuiltIn(float4, "log", float4); |
michael@0 | 93 | |
michael@0 | 94 | symbolTable.insertBuiltIn(float1, "exp2", float1); |
michael@0 | 95 | symbolTable.insertBuiltIn(float2, "exp2", float2); |
michael@0 | 96 | symbolTable.insertBuiltIn(float3, "exp2", float3); |
michael@0 | 97 | symbolTable.insertBuiltIn(float4, "exp2", float4); |
michael@0 | 98 | |
michael@0 | 99 | symbolTable.insertBuiltIn(float1, "log2", float1); |
michael@0 | 100 | symbolTable.insertBuiltIn(float2, "log2", float2); |
michael@0 | 101 | symbolTable.insertBuiltIn(float3, "log2", float3); |
michael@0 | 102 | symbolTable.insertBuiltIn(float4, "log2", float4); |
michael@0 | 103 | |
michael@0 | 104 | symbolTable.insertBuiltIn(float1, "sqrt", float1); |
michael@0 | 105 | symbolTable.insertBuiltIn(float2, "sqrt", float2); |
michael@0 | 106 | symbolTable.insertBuiltIn(float3, "sqrt", float3); |
michael@0 | 107 | symbolTable.insertBuiltIn(float4, "sqrt", float4); |
michael@0 | 108 | |
michael@0 | 109 | symbolTable.insertBuiltIn(float1, "inversesqrt", float1); |
michael@0 | 110 | symbolTable.insertBuiltIn(float2, "inversesqrt", float2); |
michael@0 | 111 | symbolTable.insertBuiltIn(float3, "inversesqrt", float3); |
michael@0 | 112 | symbolTable.insertBuiltIn(float4, "inversesqrt", float4); |
michael@0 | 113 | |
michael@0 | 114 | // |
michael@0 | 115 | // Common Functions. |
michael@0 | 116 | // |
michael@0 | 117 | symbolTable.insertBuiltIn(float1, "abs", float1); |
michael@0 | 118 | symbolTable.insertBuiltIn(float2, "abs", float2); |
michael@0 | 119 | symbolTable.insertBuiltIn(float3, "abs", float3); |
michael@0 | 120 | symbolTable.insertBuiltIn(float4, "abs", float4); |
michael@0 | 121 | |
michael@0 | 122 | symbolTable.insertBuiltIn(float1, "sign", float1); |
michael@0 | 123 | symbolTable.insertBuiltIn(float2, "sign", float2); |
michael@0 | 124 | symbolTable.insertBuiltIn(float3, "sign", float3); |
michael@0 | 125 | symbolTable.insertBuiltIn(float4, "sign", float4); |
michael@0 | 126 | |
michael@0 | 127 | symbolTable.insertBuiltIn(float1, "floor", float1); |
michael@0 | 128 | symbolTable.insertBuiltIn(float2, "floor", float2); |
michael@0 | 129 | symbolTable.insertBuiltIn(float3, "floor", float3); |
michael@0 | 130 | symbolTable.insertBuiltIn(float4, "floor", float4); |
michael@0 | 131 | |
michael@0 | 132 | symbolTable.insertBuiltIn(float1, "ceil", float1); |
michael@0 | 133 | symbolTable.insertBuiltIn(float2, "ceil", float2); |
michael@0 | 134 | symbolTable.insertBuiltIn(float3, "ceil", float3); |
michael@0 | 135 | symbolTable.insertBuiltIn(float4, "ceil", float4); |
michael@0 | 136 | |
michael@0 | 137 | symbolTable.insertBuiltIn(float1, "fract", float1); |
michael@0 | 138 | symbolTable.insertBuiltIn(float2, "fract", float2); |
michael@0 | 139 | symbolTable.insertBuiltIn(float3, "fract", float3); |
michael@0 | 140 | symbolTable.insertBuiltIn(float4, "fract", float4); |
michael@0 | 141 | |
michael@0 | 142 | symbolTable.insertBuiltIn(float1, "mod", float1, float1); |
michael@0 | 143 | symbolTable.insertBuiltIn(float2, "mod", float2, float1); |
michael@0 | 144 | symbolTable.insertBuiltIn(float3, "mod", float3, float1); |
michael@0 | 145 | symbolTable.insertBuiltIn(float4, "mod", float4, float1); |
michael@0 | 146 | symbolTable.insertBuiltIn(float2, "mod", float2, float2); |
michael@0 | 147 | symbolTable.insertBuiltIn(float3, "mod", float3, float3); |
michael@0 | 148 | symbolTable.insertBuiltIn(float4, "mod", float4, float4); |
michael@0 | 149 | |
michael@0 | 150 | symbolTable.insertBuiltIn(float1, "min", float1, float1); |
michael@0 | 151 | symbolTable.insertBuiltIn(float2, "min", float2, float1); |
michael@0 | 152 | symbolTable.insertBuiltIn(float3, "min", float3, float1); |
michael@0 | 153 | symbolTable.insertBuiltIn(float4, "min", float4, float1); |
michael@0 | 154 | symbolTable.insertBuiltIn(float2, "min", float2, float2); |
michael@0 | 155 | symbolTable.insertBuiltIn(float3, "min", float3, float3); |
michael@0 | 156 | symbolTable.insertBuiltIn(float4, "min", float4, float4); |
michael@0 | 157 | |
michael@0 | 158 | symbolTable.insertBuiltIn(float1, "max", float1, float1); |
michael@0 | 159 | symbolTable.insertBuiltIn(float2, "max", float2, float1); |
michael@0 | 160 | symbolTable.insertBuiltIn(float3, "max", float3, float1); |
michael@0 | 161 | symbolTable.insertBuiltIn(float4, "max", float4, float1); |
michael@0 | 162 | symbolTable.insertBuiltIn(float2, "max", float2, float2); |
michael@0 | 163 | symbolTable.insertBuiltIn(float3, "max", float3, float3); |
michael@0 | 164 | symbolTable.insertBuiltIn(float4, "max", float4, float4); |
michael@0 | 165 | |
michael@0 | 166 | symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1); |
michael@0 | 167 | symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1); |
michael@0 | 168 | symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1); |
michael@0 | 169 | symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1); |
michael@0 | 170 | symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2); |
michael@0 | 171 | symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3); |
michael@0 | 172 | symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4); |
michael@0 | 173 | |
michael@0 | 174 | symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1); |
michael@0 | 175 | symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1); |
michael@0 | 176 | symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1); |
michael@0 | 177 | symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1); |
michael@0 | 178 | symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2); |
michael@0 | 179 | symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3); |
michael@0 | 180 | symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4); |
michael@0 | 181 | |
michael@0 | 182 | symbolTable.insertBuiltIn(float1, "step", float1, float1); |
michael@0 | 183 | symbolTable.insertBuiltIn(float2, "step", float2, float2); |
michael@0 | 184 | symbolTable.insertBuiltIn(float3, "step", float3, float3); |
michael@0 | 185 | symbolTable.insertBuiltIn(float4, "step", float4, float4); |
michael@0 | 186 | symbolTable.insertBuiltIn(float2, "step", float1, float2); |
michael@0 | 187 | symbolTable.insertBuiltIn(float3, "step", float1, float3); |
michael@0 | 188 | symbolTable.insertBuiltIn(float4, "step", float1, float4); |
michael@0 | 189 | |
michael@0 | 190 | symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1); |
michael@0 | 191 | symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2); |
michael@0 | 192 | symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3); |
michael@0 | 193 | symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4); |
michael@0 | 194 | symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2); |
michael@0 | 195 | symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3); |
michael@0 | 196 | symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4); |
michael@0 | 197 | |
michael@0 | 198 | // |
michael@0 | 199 | // Geometric Functions. |
michael@0 | 200 | // |
michael@0 | 201 | symbolTable.insertBuiltIn(float1, "length", float1); |
michael@0 | 202 | symbolTable.insertBuiltIn(float1, "length", float2); |
michael@0 | 203 | symbolTable.insertBuiltIn(float1, "length", float3); |
michael@0 | 204 | symbolTable.insertBuiltIn(float1, "length", float4); |
michael@0 | 205 | |
michael@0 | 206 | symbolTable.insertBuiltIn(float1, "distance", float1, float1); |
michael@0 | 207 | symbolTable.insertBuiltIn(float1, "distance", float2, float2); |
michael@0 | 208 | symbolTable.insertBuiltIn(float1, "distance", float3, float3); |
michael@0 | 209 | symbolTable.insertBuiltIn(float1, "distance", float4, float4); |
michael@0 | 210 | |
michael@0 | 211 | symbolTable.insertBuiltIn(float1, "dot", float1, float1); |
michael@0 | 212 | symbolTable.insertBuiltIn(float1, "dot", float2, float2); |
michael@0 | 213 | symbolTable.insertBuiltIn(float1, "dot", float3, float3); |
michael@0 | 214 | symbolTable.insertBuiltIn(float1, "dot", float4, float4); |
michael@0 | 215 | |
michael@0 | 216 | symbolTable.insertBuiltIn(float3, "cross", float3, float3); |
michael@0 | 217 | symbolTable.insertBuiltIn(float1, "normalize", float1); |
michael@0 | 218 | symbolTable.insertBuiltIn(float2, "normalize", float2); |
michael@0 | 219 | symbolTable.insertBuiltIn(float3, "normalize", float3); |
michael@0 | 220 | symbolTable.insertBuiltIn(float4, "normalize", float4); |
michael@0 | 221 | |
michael@0 | 222 | symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1); |
michael@0 | 223 | symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2); |
michael@0 | 224 | symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3); |
michael@0 | 225 | symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4); |
michael@0 | 226 | |
michael@0 | 227 | symbolTable.insertBuiltIn(float1, "reflect", float1, float1); |
michael@0 | 228 | symbolTable.insertBuiltIn(float2, "reflect", float2, float2); |
michael@0 | 229 | symbolTable.insertBuiltIn(float3, "reflect", float3, float3); |
michael@0 | 230 | symbolTable.insertBuiltIn(float4, "reflect", float4, float4); |
michael@0 | 231 | |
michael@0 | 232 | symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1); |
michael@0 | 233 | symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1); |
michael@0 | 234 | symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1); |
michael@0 | 235 | symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1); |
michael@0 | 236 | |
michael@0 | 237 | TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true); |
michael@0 | 238 | TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true); |
michael@0 | 239 | TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true); |
michael@0 | 240 | |
michael@0 | 241 | // |
michael@0 | 242 | // Matrix Functions. |
michael@0 | 243 | // |
michael@0 | 244 | symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2); |
michael@0 | 245 | symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3); |
michael@0 | 246 | symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4); |
michael@0 | 247 | |
michael@0 | 248 | TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1); |
michael@0 | 249 | TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2); |
michael@0 | 250 | TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3); |
michael@0 | 251 | TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4); |
michael@0 | 252 | |
michael@0 | 253 | // |
michael@0 | 254 | // Vector relational functions. |
michael@0 | 255 | // |
michael@0 | 256 | symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2); |
michael@0 | 257 | symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3); |
michael@0 | 258 | symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4); |
michael@0 | 259 | |
michael@0 | 260 | symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2); |
michael@0 | 261 | symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3); |
michael@0 | 262 | symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4); |
michael@0 | 263 | |
michael@0 | 264 | symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2); |
michael@0 | 265 | symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3); |
michael@0 | 266 | symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4); |
michael@0 | 267 | |
michael@0 | 268 | symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2); |
michael@0 | 269 | symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3); |
michael@0 | 270 | symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4); |
michael@0 | 271 | |
michael@0 | 272 | symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2); |
michael@0 | 273 | symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3); |
michael@0 | 274 | symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4); |
michael@0 | 275 | |
michael@0 | 276 | symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2); |
michael@0 | 277 | symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3); |
michael@0 | 278 | symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4); |
michael@0 | 279 | |
michael@0 | 280 | symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2); |
michael@0 | 281 | symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3); |
michael@0 | 282 | symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4); |
michael@0 | 283 | |
michael@0 | 284 | symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2); |
michael@0 | 285 | symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3); |
michael@0 | 286 | symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4); |
michael@0 | 287 | |
michael@0 | 288 | symbolTable.insertBuiltIn(bool2, "equal", float2, float2); |
michael@0 | 289 | symbolTable.insertBuiltIn(bool3, "equal", float3, float3); |
michael@0 | 290 | symbolTable.insertBuiltIn(bool4, "equal", float4, float4); |
michael@0 | 291 | |
michael@0 | 292 | symbolTable.insertBuiltIn(bool2, "equal", int2, int2); |
michael@0 | 293 | symbolTable.insertBuiltIn(bool3, "equal", int3, int3); |
michael@0 | 294 | symbolTable.insertBuiltIn(bool4, "equal", int4, int4); |
michael@0 | 295 | |
michael@0 | 296 | symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2); |
michael@0 | 297 | symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3); |
michael@0 | 298 | symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4); |
michael@0 | 299 | |
michael@0 | 300 | symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2); |
michael@0 | 301 | symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3); |
michael@0 | 302 | symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4); |
michael@0 | 303 | |
michael@0 | 304 | symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2); |
michael@0 | 305 | symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3); |
michael@0 | 306 | symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4); |
michael@0 | 307 | |
michael@0 | 308 | symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2); |
michael@0 | 309 | symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3); |
michael@0 | 310 | symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4); |
michael@0 | 311 | |
michael@0 | 312 | symbolTable.insertBuiltIn(bool1, "any", bool2); |
michael@0 | 313 | symbolTable.insertBuiltIn(bool1, "any", bool3); |
michael@0 | 314 | symbolTable.insertBuiltIn(bool1, "any", bool4); |
michael@0 | 315 | |
michael@0 | 316 | symbolTable.insertBuiltIn(bool1, "all", bool2); |
michael@0 | 317 | symbolTable.insertBuiltIn(bool1, "all", bool3); |
michael@0 | 318 | symbolTable.insertBuiltIn(bool1, "all", bool4); |
michael@0 | 319 | |
michael@0 | 320 | symbolTable.insertBuiltIn(bool2, "not", bool2); |
michael@0 | 321 | symbolTable.insertBuiltIn(bool3, "not", bool3); |
michael@0 | 322 | symbolTable.insertBuiltIn(bool4, "not", bool4); |
michael@0 | 323 | |
michael@0 | 324 | TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1); |
michael@0 | 325 | TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1); |
michael@0 | 326 | |
michael@0 | 327 | // |
michael@0 | 328 | // Texture Functions for GLSL ES 1.0 |
michael@0 | 329 | // |
michael@0 | 330 | symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2); |
michael@0 | 331 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3); |
michael@0 | 332 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4); |
michael@0 | 333 | symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3); |
michael@0 | 334 | |
michael@0 | 335 | if (resources.OES_EGL_image_external) |
michael@0 | 336 | { |
michael@0 | 337 | TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1); |
michael@0 | 338 | |
michael@0 | 339 | symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2); |
michael@0 | 340 | symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3); |
michael@0 | 341 | symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4); |
michael@0 | 342 | } |
michael@0 | 343 | |
michael@0 | 344 | if (resources.ARB_texture_rectangle) |
michael@0 | 345 | { |
michael@0 | 346 | TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1); |
michael@0 | 347 | |
michael@0 | 348 | symbolTable.insertBuiltIn(float4, "texture2DRect", sampler2DRect, float2); |
michael@0 | 349 | symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float3); |
michael@0 | 350 | symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float4); |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | if (type == SH_FRAGMENT_SHADER) |
michael@0 | 354 | { |
michael@0 | 355 | symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1); |
michael@0 | 356 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1); |
michael@0 | 357 | symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1); |
michael@0 | 358 | symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1); |
michael@0 | 359 | |
michael@0 | 360 | if (resources.OES_standard_derivatives) |
michael@0 | 361 | { |
michael@0 | 362 | symbolTable.insertBuiltIn(float1, "dFdx", float1); |
michael@0 | 363 | symbolTable.insertBuiltIn(float2, "dFdx", float2); |
michael@0 | 364 | symbolTable.insertBuiltIn(float3, "dFdx", float3); |
michael@0 | 365 | symbolTable.insertBuiltIn(float4, "dFdx", float4); |
michael@0 | 366 | |
michael@0 | 367 | symbolTable.insertBuiltIn(float1, "dFdy", float1); |
michael@0 | 368 | symbolTable.insertBuiltIn(float2, "dFdy", float2); |
michael@0 | 369 | symbolTable.insertBuiltIn(float3, "dFdy", float3); |
michael@0 | 370 | symbolTable.insertBuiltIn(float4, "dFdy", float4); |
michael@0 | 371 | |
michael@0 | 372 | symbolTable.insertBuiltIn(float1, "fwidth", float1); |
michael@0 | 373 | symbolTable.insertBuiltIn(float2, "fwidth", float2); |
michael@0 | 374 | symbolTable.insertBuiltIn(float3, "fwidth", float3); |
michael@0 | 375 | symbolTable.insertBuiltIn(float4, "fwidth", float4); |
michael@0 | 376 | } |
michael@0 | 377 | } |
michael@0 | 378 | |
michael@0 | 379 | if(type == SH_VERTEX_SHADER) |
michael@0 | 380 | { |
michael@0 | 381 | symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1); |
michael@0 | 382 | symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1); |
michael@0 | 383 | symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1); |
michael@0 | 384 | symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); |
michael@0 | 385 | } |
michael@0 | 386 | |
michael@0 | 387 | // |
michael@0 | 388 | // Depth range in window coordinates |
michael@0 | 389 | // |
michael@0 | 390 | TFieldList *fields = NewPoolTFieldList(); |
michael@0 | 391 | TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near")); |
michael@0 | 392 | TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far")); |
michael@0 | 393 | TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff")); |
michael@0 | 394 | fields->push_back(near); |
michael@0 | 395 | fields->push_back(far); |
michael@0 | 396 | fields->push_back(diff); |
michael@0 | 397 | TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); |
michael@0 | 398 | TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); |
michael@0 | 399 | symbolTable.insert(*depthRangeParameters); |
michael@0 | 400 | TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); |
michael@0 | 401 | depthRange->setQualifier(EvqUniform); |
michael@0 | 402 | symbolTable.insert(*depthRange); |
michael@0 | 403 | |
michael@0 | 404 | // |
michael@0 | 405 | // Implementation dependent built-in constants. |
michael@0 | 406 | // |
michael@0 | 407 | symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs); |
michael@0 | 408 | symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); |
michael@0 | 409 | symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors); |
michael@0 | 410 | symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); |
michael@0 | 411 | symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); |
michael@0 | 412 | symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); |
michael@0 | 413 | symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); |
michael@0 | 414 | |
michael@0 | 415 | if (spec != SH_CSS_SHADERS_SPEC) |
michael@0 | 416 | { |
michael@0 | 417 | symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers); |
michael@0 | 418 | } |
michael@0 | 419 | } |
michael@0 | 420 | |
michael@0 | 421 | void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, |
michael@0 | 422 | const ShBuiltInResources &resources, |
michael@0 | 423 | TSymbolTable &symbolTable) |
michael@0 | 424 | { |
michael@0 | 425 | // |
michael@0 | 426 | // First, insert some special built-in variables that are not in |
michael@0 | 427 | // the built-in header files. |
michael@0 | 428 | // |
michael@0 | 429 | switch(type) { |
michael@0 | 430 | case SH_FRAGMENT_SHADER: |
michael@0 | 431 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); |
michael@0 | 432 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); |
michael@0 | 433 | symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); |
michael@0 | 434 | |
michael@0 | 435 | // |
michael@0 | 436 | // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available. |
michael@0 | 437 | // Instead, css_MixColor and css_ColorMatrix are available. |
michael@0 | 438 | // |
michael@0 | 439 | if (spec != SH_CSS_SHADERS_SPEC) { |
michael@0 | 440 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); |
michael@0 | 441 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); |
michael@0 | 442 | if (resources.EXT_frag_depth) { |
michael@0 | 443 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1))); |
michael@0 | 444 | symbolTable.relateToExtension("gl_FragDepthEXT", "GL_EXT_frag_depth"); |
michael@0 | 445 | } |
michael@0 | 446 | } else { |
michael@0 | 447 | symbolTable.insert(*new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4))); |
michael@0 | 448 | symbolTable.insert(*new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, true))); |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | break; |
michael@0 | 452 | |
michael@0 | 453 | case SH_VERTEX_SHADER: |
michael@0 | 454 | symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); |
michael@0 | 455 | symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); |
michael@0 | 456 | break; |
michael@0 | 457 | |
michael@0 | 458 | default: assert(false && "Language not supported"); |
michael@0 | 459 | } |
michael@0 | 460 | |
michael@0 | 461 | // |
michael@0 | 462 | // Next, identify which built-ins from the already loaded headers have |
michael@0 | 463 | // a mapping to an operator. Those that are not identified as such are |
michael@0 | 464 | // expected to be resolved through a library of functions, versus as |
michael@0 | 465 | // operations. |
michael@0 | 466 | // |
michael@0 | 467 | symbolTable.relateToOperator("matrixCompMult", EOpMul); |
michael@0 | 468 | |
michael@0 | 469 | symbolTable.relateToOperator("equal", EOpVectorEqual); |
michael@0 | 470 | symbolTable.relateToOperator("notEqual", EOpVectorNotEqual); |
michael@0 | 471 | symbolTable.relateToOperator("lessThan", EOpLessThan); |
michael@0 | 472 | symbolTable.relateToOperator("greaterThan", EOpGreaterThan); |
michael@0 | 473 | symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual); |
michael@0 | 474 | symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual); |
michael@0 | 475 | |
michael@0 | 476 | symbolTable.relateToOperator("radians", EOpRadians); |
michael@0 | 477 | symbolTable.relateToOperator("degrees", EOpDegrees); |
michael@0 | 478 | symbolTable.relateToOperator("sin", EOpSin); |
michael@0 | 479 | symbolTable.relateToOperator("cos", EOpCos); |
michael@0 | 480 | symbolTable.relateToOperator("tan", EOpTan); |
michael@0 | 481 | symbolTable.relateToOperator("asin", EOpAsin); |
michael@0 | 482 | symbolTable.relateToOperator("acos", EOpAcos); |
michael@0 | 483 | symbolTable.relateToOperator("atan", EOpAtan); |
michael@0 | 484 | |
michael@0 | 485 | symbolTable.relateToOperator("pow", EOpPow); |
michael@0 | 486 | symbolTable.relateToOperator("exp2", EOpExp2); |
michael@0 | 487 | symbolTable.relateToOperator("log", EOpLog); |
michael@0 | 488 | symbolTable.relateToOperator("exp", EOpExp); |
michael@0 | 489 | symbolTable.relateToOperator("log2", EOpLog2); |
michael@0 | 490 | symbolTable.relateToOperator("sqrt", EOpSqrt); |
michael@0 | 491 | symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt); |
michael@0 | 492 | |
michael@0 | 493 | symbolTable.relateToOperator("abs", EOpAbs); |
michael@0 | 494 | symbolTable.relateToOperator("sign", EOpSign); |
michael@0 | 495 | symbolTable.relateToOperator("floor", EOpFloor); |
michael@0 | 496 | symbolTable.relateToOperator("ceil", EOpCeil); |
michael@0 | 497 | symbolTable.relateToOperator("fract", EOpFract); |
michael@0 | 498 | symbolTable.relateToOperator("mod", EOpMod); |
michael@0 | 499 | symbolTable.relateToOperator("min", EOpMin); |
michael@0 | 500 | symbolTable.relateToOperator("max", EOpMax); |
michael@0 | 501 | symbolTable.relateToOperator("clamp", EOpClamp); |
michael@0 | 502 | symbolTable.relateToOperator("mix", EOpMix); |
michael@0 | 503 | symbolTable.relateToOperator("step", EOpStep); |
michael@0 | 504 | symbolTable.relateToOperator("smoothstep", EOpSmoothStep); |
michael@0 | 505 | |
michael@0 | 506 | symbolTable.relateToOperator("length", EOpLength); |
michael@0 | 507 | symbolTable.relateToOperator("distance", EOpDistance); |
michael@0 | 508 | symbolTable.relateToOperator("dot", EOpDot); |
michael@0 | 509 | symbolTable.relateToOperator("cross", EOpCross); |
michael@0 | 510 | symbolTable.relateToOperator("normalize", EOpNormalize); |
michael@0 | 511 | symbolTable.relateToOperator("faceforward", EOpFaceForward); |
michael@0 | 512 | symbolTable.relateToOperator("reflect", EOpReflect); |
michael@0 | 513 | symbolTable.relateToOperator("refract", EOpRefract); |
michael@0 | 514 | |
michael@0 | 515 | symbolTable.relateToOperator("any", EOpAny); |
michael@0 | 516 | symbolTable.relateToOperator("all", EOpAll); |
michael@0 | 517 | symbolTable.relateToOperator("not", EOpVectorLogicalNot); |
michael@0 | 518 | |
michael@0 | 519 | // Map language-specific operators. |
michael@0 | 520 | switch(type) { |
michael@0 | 521 | case SH_VERTEX_SHADER: |
michael@0 | 522 | break; |
michael@0 | 523 | case SH_FRAGMENT_SHADER: |
michael@0 | 524 | if (resources.OES_standard_derivatives) { |
michael@0 | 525 | symbolTable.relateToOperator("dFdx", EOpDFdx); |
michael@0 | 526 | symbolTable.relateToOperator("dFdy", EOpDFdy); |
michael@0 | 527 | symbolTable.relateToOperator("fwidth", EOpFwidth); |
michael@0 | 528 | |
michael@0 | 529 | symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives"); |
michael@0 | 530 | symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives"); |
michael@0 | 531 | symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives"); |
michael@0 | 532 | } |
michael@0 | 533 | break; |
michael@0 | 534 | default: break; |
michael@0 | 535 | } |
michael@0 | 536 | |
michael@0 | 537 | // Finally add resource-specific variables. |
michael@0 | 538 | switch(type) { |
michael@0 | 539 | case SH_FRAGMENT_SHADER: |
michael@0 | 540 | if (spec != SH_CSS_SHADERS_SPEC) { |
michael@0 | 541 | // Set up gl_FragData. The array size. |
michael@0 | 542 | TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); |
michael@0 | 543 | fragData.setArraySize(resources.MaxDrawBuffers); |
michael@0 | 544 | symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); |
michael@0 | 545 | } |
michael@0 | 546 | break; |
michael@0 | 547 | default: break; |
michael@0 | 548 | } |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | void InitExtensionBehavior(const ShBuiltInResources& resources, |
michael@0 | 552 | TExtensionBehavior& extBehavior) |
michael@0 | 553 | { |
michael@0 | 554 | if (resources.OES_standard_derivatives) |
michael@0 | 555 | extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; |
michael@0 | 556 | if (resources.OES_EGL_image_external) |
michael@0 | 557 | extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; |
michael@0 | 558 | if (resources.ARB_texture_rectangle) |
michael@0 | 559 | extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined; |
michael@0 | 560 | if (resources.EXT_draw_buffers) |
michael@0 | 561 | extBehavior["GL_EXT_draw_buffers"] = EBhUndefined; |
michael@0 | 562 | if (resources.EXT_frag_depth) |
michael@0 | 563 | extBehavior["GL_EXT_frag_depth"] = EBhUndefined; |
michael@0 | 564 | } |