1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/Initialize.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,564 @@ 1.4 +// 1.5 +// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +// 1.11 +// Create strings that declare built-in definitions, add built-ins that 1.12 +// cannot be expressed in the files, and establish mappings between 1.13 +// built-in functions and operators. 1.14 +// 1.15 + 1.16 +#include "compiler/Initialize.h" 1.17 + 1.18 +#include "compiler/intermediate.h" 1.19 + 1.20 +void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) 1.21 +{ 1.22 + TType *float1 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 1); 1.23 + TType *float2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2); 1.24 + TType *float3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3); 1.25 + TType *float4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4); 1.26 + 1.27 + TType *int2 = new TType(EbtInt, EbpUndefined, EvqGlobal, 2); 1.28 + TType *int3 = new TType(EbtInt, EbpUndefined, EvqGlobal, 3); 1.29 + TType *int4 = new TType(EbtInt, EbpUndefined, EvqGlobal, 4); 1.30 + 1.31 + // 1.32 + // Angle and Trigonometric Functions. 1.33 + // 1.34 + symbolTable.insertBuiltIn(float1, "radians", float1); 1.35 + symbolTable.insertBuiltIn(float2, "radians", float2); 1.36 + symbolTable.insertBuiltIn(float3, "radians", float3); 1.37 + symbolTable.insertBuiltIn(float4, "radians", float4); 1.38 + 1.39 + symbolTable.insertBuiltIn(float1, "degrees", float1); 1.40 + symbolTable.insertBuiltIn(float2, "degrees", float2); 1.41 + symbolTable.insertBuiltIn(float3, "degrees", float3); 1.42 + symbolTable.insertBuiltIn(float4, "degrees", float4); 1.43 + 1.44 + symbolTable.insertBuiltIn(float1, "sin", float1); 1.45 + symbolTable.insertBuiltIn(float2, "sin", float2); 1.46 + symbolTable.insertBuiltIn(float3, "sin", float3); 1.47 + symbolTable.insertBuiltIn(float4, "sin", float4); 1.48 + 1.49 + symbolTable.insertBuiltIn(float1, "cos", float1); 1.50 + symbolTable.insertBuiltIn(float2, "cos", float2); 1.51 + symbolTable.insertBuiltIn(float3, "cos", float3); 1.52 + symbolTable.insertBuiltIn(float4, "cos", float4); 1.53 + 1.54 + symbolTable.insertBuiltIn(float1, "tan", float1); 1.55 + symbolTable.insertBuiltIn(float2, "tan", float2); 1.56 + symbolTable.insertBuiltIn(float3, "tan", float3); 1.57 + symbolTable.insertBuiltIn(float4, "tan", float4); 1.58 + 1.59 + symbolTable.insertBuiltIn(float1, "asin", float1); 1.60 + symbolTable.insertBuiltIn(float2, "asin", float2); 1.61 + symbolTable.insertBuiltIn(float3, "asin", float3); 1.62 + symbolTable.insertBuiltIn(float4, "asin", float4); 1.63 + 1.64 + symbolTable.insertBuiltIn(float1, "acos", float1); 1.65 + symbolTable.insertBuiltIn(float2, "acos", float2); 1.66 + symbolTable.insertBuiltIn(float3, "acos", float3); 1.67 + symbolTable.insertBuiltIn(float4, "acos", float4); 1.68 + 1.69 + symbolTable.insertBuiltIn(float1, "atan", float1, float1); 1.70 + symbolTable.insertBuiltIn(float2, "atan", float2, float2); 1.71 + symbolTable.insertBuiltIn(float3, "atan", float3, float3); 1.72 + symbolTable.insertBuiltIn(float4, "atan", float4, float4); 1.73 + 1.74 + symbolTable.insertBuiltIn(float1, "atan", float1); 1.75 + symbolTable.insertBuiltIn(float2, "atan", float2); 1.76 + symbolTable.insertBuiltIn(float3, "atan", float3); 1.77 + symbolTable.insertBuiltIn(float4, "atan", float4); 1.78 + 1.79 + // 1.80 + // Exponential Functions. 1.81 + // 1.82 + symbolTable.insertBuiltIn(float1, "pow", float1, float1); 1.83 + symbolTable.insertBuiltIn(float2, "pow", float2, float2); 1.84 + symbolTable.insertBuiltIn(float3, "pow", float3, float3); 1.85 + symbolTable.insertBuiltIn(float4, "pow", float4, float4); 1.86 + 1.87 + symbolTable.insertBuiltIn(float1, "exp", float1); 1.88 + symbolTable.insertBuiltIn(float2, "exp", float2); 1.89 + symbolTable.insertBuiltIn(float3, "exp", float3); 1.90 + symbolTable.insertBuiltIn(float4, "exp", float4); 1.91 + 1.92 + symbolTable.insertBuiltIn(float1, "log", float1); 1.93 + symbolTable.insertBuiltIn(float2, "log", float2); 1.94 + symbolTable.insertBuiltIn(float3, "log", float3); 1.95 + symbolTable.insertBuiltIn(float4, "log", float4); 1.96 + 1.97 + symbolTable.insertBuiltIn(float1, "exp2", float1); 1.98 + symbolTable.insertBuiltIn(float2, "exp2", float2); 1.99 + symbolTable.insertBuiltIn(float3, "exp2", float3); 1.100 + symbolTable.insertBuiltIn(float4, "exp2", float4); 1.101 + 1.102 + symbolTable.insertBuiltIn(float1, "log2", float1); 1.103 + symbolTable.insertBuiltIn(float2, "log2", float2); 1.104 + symbolTable.insertBuiltIn(float3, "log2", float3); 1.105 + symbolTable.insertBuiltIn(float4, "log2", float4); 1.106 + 1.107 + symbolTable.insertBuiltIn(float1, "sqrt", float1); 1.108 + symbolTable.insertBuiltIn(float2, "sqrt", float2); 1.109 + symbolTable.insertBuiltIn(float3, "sqrt", float3); 1.110 + symbolTable.insertBuiltIn(float4, "sqrt", float4); 1.111 + 1.112 + symbolTable.insertBuiltIn(float1, "inversesqrt", float1); 1.113 + symbolTable.insertBuiltIn(float2, "inversesqrt", float2); 1.114 + symbolTable.insertBuiltIn(float3, "inversesqrt", float3); 1.115 + symbolTable.insertBuiltIn(float4, "inversesqrt", float4); 1.116 + 1.117 + // 1.118 + // Common Functions. 1.119 + // 1.120 + symbolTable.insertBuiltIn(float1, "abs", float1); 1.121 + symbolTable.insertBuiltIn(float2, "abs", float2); 1.122 + symbolTable.insertBuiltIn(float3, "abs", float3); 1.123 + symbolTable.insertBuiltIn(float4, "abs", float4); 1.124 + 1.125 + symbolTable.insertBuiltIn(float1, "sign", float1); 1.126 + symbolTable.insertBuiltIn(float2, "sign", float2); 1.127 + symbolTable.insertBuiltIn(float3, "sign", float3); 1.128 + symbolTable.insertBuiltIn(float4, "sign", float4); 1.129 + 1.130 + symbolTable.insertBuiltIn(float1, "floor", float1); 1.131 + symbolTable.insertBuiltIn(float2, "floor", float2); 1.132 + symbolTable.insertBuiltIn(float3, "floor", float3); 1.133 + symbolTable.insertBuiltIn(float4, "floor", float4); 1.134 + 1.135 + symbolTable.insertBuiltIn(float1, "ceil", float1); 1.136 + symbolTable.insertBuiltIn(float2, "ceil", float2); 1.137 + symbolTable.insertBuiltIn(float3, "ceil", float3); 1.138 + symbolTable.insertBuiltIn(float4, "ceil", float4); 1.139 + 1.140 + symbolTable.insertBuiltIn(float1, "fract", float1); 1.141 + symbolTable.insertBuiltIn(float2, "fract", float2); 1.142 + symbolTable.insertBuiltIn(float3, "fract", float3); 1.143 + symbolTable.insertBuiltIn(float4, "fract", float4); 1.144 + 1.145 + symbolTable.insertBuiltIn(float1, "mod", float1, float1); 1.146 + symbolTable.insertBuiltIn(float2, "mod", float2, float1); 1.147 + symbolTable.insertBuiltIn(float3, "mod", float3, float1); 1.148 + symbolTable.insertBuiltIn(float4, "mod", float4, float1); 1.149 + symbolTable.insertBuiltIn(float2, "mod", float2, float2); 1.150 + symbolTable.insertBuiltIn(float3, "mod", float3, float3); 1.151 + symbolTable.insertBuiltIn(float4, "mod", float4, float4); 1.152 + 1.153 + symbolTable.insertBuiltIn(float1, "min", float1, float1); 1.154 + symbolTable.insertBuiltIn(float2, "min", float2, float1); 1.155 + symbolTable.insertBuiltIn(float3, "min", float3, float1); 1.156 + symbolTable.insertBuiltIn(float4, "min", float4, float1); 1.157 + symbolTable.insertBuiltIn(float2, "min", float2, float2); 1.158 + symbolTable.insertBuiltIn(float3, "min", float3, float3); 1.159 + symbolTable.insertBuiltIn(float4, "min", float4, float4); 1.160 + 1.161 + symbolTable.insertBuiltIn(float1, "max", float1, float1); 1.162 + symbolTable.insertBuiltIn(float2, "max", float2, float1); 1.163 + symbolTable.insertBuiltIn(float3, "max", float3, float1); 1.164 + symbolTable.insertBuiltIn(float4, "max", float4, float1); 1.165 + symbolTable.insertBuiltIn(float2, "max", float2, float2); 1.166 + symbolTable.insertBuiltIn(float3, "max", float3, float3); 1.167 + symbolTable.insertBuiltIn(float4, "max", float4, float4); 1.168 + 1.169 + symbolTable.insertBuiltIn(float1, "clamp", float1, float1, float1); 1.170 + symbolTable.insertBuiltIn(float2, "clamp", float2, float1, float1); 1.171 + symbolTable.insertBuiltIn(float3, "clamp", float3, float1, float1); 1.172 + symbolTable.insertBuiltIn(float4, "clamp", float4, float1, float1); 1.173 + symbolTable.insertBuiltIn(float2, "clamp", float2, float2, float2); 1.174 + symbolTable.insertBuiltIn(float3, "clamp", float3, float3, float3); 1.175 + symbolTable.insertBuiltIn(float4, "clamp", float4, float4, float4); 1.176 + 1.177 + symbolTable.insertBuiltIn(float1, "mix", float1, float1, float1); 1.178 + symbolTable.insertBuiltIn(float2, "mix", float2, float2, float1); 1.179 + symbolTable.insertBuiltIn(float3, "mix", float3, float3, float1); 1.180 + symbolTable.insertBuiltIn(float4, "mix", float4, float4, float1); 1.181 + symbolTable.insertBuiltIn(float2, "mix", float2, float2, float2); 1.182 + symbolTable.insertBuiltIn(float3, "mix", float3, float3, float3); 1.183 + symbolTable.insertBuiltIn(float4, "mix", float4, float4, float4); 1.184 + 1.185 + symbolTable.insertBuiltIn(float1, "step", float1, float1); 1.186 + symbolTable.insertBuiltIn(float2, "step", float2, float2); 1.187 + symbolTable.insertBuiltIn(float3, "step", float3, float3); 1.188 + symbolTable.insertBuiltIn(float4, "step", float4, float4); 1.189 + symbolTable.insertBuiltIn(float2, "step", float1, float2); 1.190 + symbolTable.insertBuiltIn(float3, "step", float1, float3); 1.191 + symbolTable.insertBuiltIn(float4, "step", float1, float4); 1.192 + 1.193 + symbolTable.insertBuiltIn(float1, "smoothstep", float1, float1, float1); 1.194 + symbolTable.insertBuiltIn(float2, "smoothstep", float2, float2, float2); 1.195 + symbolTable.insertBuiltIn(float3, "smoothstep", float3, float3, float3); 1.196 + symbolTable.insertBuiltIn(float4, "smoothstep", float4, float4, float4); 1.197 + symbolTable.insertBuiltIn(float2, "smoothstep", float1, float1, float2); 1.198 + symbolTable.insertBuiltIn(float3, "smoothstep", float1, float1, float3); 1.199 + symbolTable.insertBuiltIn(float4, "smoothstep", float1, float1, float4); 1.200 + 1.201 + // 1.202 + // Geometric Functions. 1.203 + // 1.204 + symbolTable.insertBuiltIn(float1, "length", float1); 1.205 + symbolTable.insertBuiltIn(float1, "length", float2); 1.206 + symbolTable.insertBuiltIn(float1, "length", float3); 1.207 + symbolTable.insertBuiltIn(float1, "length", float4); 1.208 + 1.209 + symbolTable.insertBuiltIn(float1, "distance", float1, float1); 1.210 + symbolTable.insertBuiltIn(float1, "distance", float2, float2); 1.211 + symbolTable.insertBuiltIn(float1, "distance", float3, float3); 1.212 + symbolTable.insertBuiltIn(float1, "distance", float4, float4); 1.213 + 1.214 + symbolTable.insertBuiltIn(float1, "dot", float1, float1); 1.215 + symbolTable.insertBuiltIn(float1, "dot", float2, float2); 1.216 + symbolTable.insertBuiltIn(float1, "dot", float3, float3); 1.217 + symbolTable.insertBuiltIn(float1, "dot", float4, float4); 1.218 + 1.219 + symbolTable.insertBuiltIn(float3, "cross", float3, float3); 1.220 + symbolTable.insertBuiltIn(float1, "normalize", float1); 1.221 + symbolTable.insertBuiltIn(float2, "normalize", float2); 1.222 + symbolTable.insertBuiltIn(float3, "normalize", float3); 1.223 + symbolTable.insertBuiltIn(float4, "normalize", float4); 1.224 + 1.225 + symbolTable.insertBuiltIn(float1, "faceforward", float1, float1, float1); 1.226 + symbolTable.insertBuiltIn(float2, "faceforward", float2, float2, float2); 1.227 + symbolTable.insertBuiltIn(float3, "faceforward", float3, float3, float3); 1.228 + symbolTable.insertBuiltIn(float4, "faceforward", float4, float4, float4); 1.229 + 1.230 + symbolTable.insertBuiltIn(float1, "reflect", float1, float1); 1.231 + symbolTable.insertBuiltIn(float2, "reflect", float2, float2); 1.232 + symbolTable.insertBuiltIn(float3, "reflect", float3, float3); 1.233 + symbolTable.insertBuiltIn(float4, "reflect", float4, float4); 1.234 + 1.235 + symbolTable.insertBuiltIn(float1, "refract", float1, float1, float1); 1.236 + symbolTable.insertBuiltIn(float2, "refract", float2, float2, float1); 1.237 + symbolTable.insertBuiltIn(float3, "refract", float3, float3, float1); 1.238 + symbolTable.insertBuiltIn(float4, "refract", float4, float4, float1); 1.239 + 1.240 + TType *mat2 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 2, true); 1.241 + TType *mat3 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 3, true); 1.242 + TType *mat4 = new TType(EbtFloat, EbpUndefined, EvqGlobal, 4, true); 1.243 + 1.244 + // 1.245 + // Matrix Functions. 1.246 + // 1.247 + symbolTable.insertBuiltIn(mat2, "matrixCompMult", mat2, mat2); 1.248 + symbolTable.insertBuiltIn(mat3, "matrixCompMult", mat3, mat3); 1.249 + symbolTable.insertBuiltIn(mat4, "matrixCompMult", mat4, mat4); 1.250 + 1.251 + TType *bool1 = new TType(EbtBool, EbpUndefined, EvqGlobal, 1); 1.252 + TType *bool2 = new TType(EbtBool, EbpUndefined, EvqGlobal, 2); 1.253 + TType *bool3 = new TType(EbtBool, EbpUndefined, EvqGlobal, 3); 1.254 + TType *bool4 = new TType(EbtBool, EbpUndefined, EvqGlobal, 4); 1.255 + 1.256 + // 1.257 + // Vector relational functions. 1.258 + // 1.259 + symbolTable.insertBuiltIn(bool2, "lessThan", float2, float2); 1.260 + symbolTable.insertBuiltIn(bool3, "lessThan", float3, float3); 1.261 + symbolTable.insertBuiltIn(bool4, "lessThan", float4, float4); 1.262 + 1.263 + symbolTable.insertBuiltIn(bool2, "lessThan", int2, int2); 1.264 + symbolTable.insertBuiltIn(bool3, "lessThan", int3, int3); 1.265 + symbolTable.insertBuiltIn(bool4, "lessThan", int4, int4); 1.266 + 1.267 + symbolTable.insertBuiltIn(bool2, "lessThanEqual", float2, float2); 1.268 + symbolTable.insertBuiltIn(bool3, "lessThanEqual", float3, float3); 1.269 + symbolTable.insertBuiltIn(bool4, "lessThanEqual", float4, float4); 1.270 + 1.271 + symbolTable.insertBuiltIn(bool2, "lessThanEqual", int2, int2); 1.272 + symbolTable.insertBuiltIn(bool3, "lessThanEqual", int3, int3); 1.273 + symbolTable.insertBuiltIn(bool4, "lessThanEqual", int4, int4); 1.274 + 1.275 + symbolTable.insertBuiltIn(bool2, "greaterThan", float2, float2); 1.276 + symbolTable.insertBuiltIn(bool3, "greaterThan", float3, float3); 1.277 + symbolTable.insertBuiltIn(bool4, "greaterThan", float4, float4); 1.278 + 1.279 + symbolTable.insertBuiltIn(bool2, "greaterThan", int2, int2); 1.280 + symbolTable.insertBuiltIn(bool3, "greaterThan", int3, int3); 1.281 + symbolTable.insertBuiltIn(bool4, "greaterThan", int4, int4); 1.282 + 1.283 + symbolTable.insertBuiltIn(bool2, "greaterThanEqual", float2, float2); 1.284 + symbolTable.insertBuiltIn(bool3, "greaterThanEqual", float3, float3); 1.285 + symbolTable.insertBuiltIn(bool4, "greaterThanEqual", float4, float4); 1.286 + 1.287 + symbolTable.insertBuiltIn(bool2, "greaterThanEqual", int2, int2); 1.288 + symbolTable.insertBuiltIn(bool3, "greaterThanEqual", int3, int3); 1.289 + symbolTable.insertBuiltIn(bool4, "greaterThanEqual", int4, int4); 1.290 + 1.291 + symbolTable.insertBuiltIn(bool2, "equal", float2, float2); 1.292 + symbolTable.insertBuiltIn(bool3, "equal", float3, float3); 1.293 + symbolTable.insertBuiltIn(bool4, "equal", float4, float4); 1.294 + 1.295 + symbolTable.insertBuiltIn(bool2, "equal", int2, int2); 1.296 + symbolTable.insertBuiltIn(bool3, "equal", int3, int3); 1.297 + symbolTable.insertBuiltIn(bool4, "equal", int4, int4); 1.298 + 1.299 + symbolTable.insertBuiltIn(bool2, "equal", bool2, bool2); 1.300 + symbolTable.insertBuiltIn(bool3, "equal", bool3, bool3); 1.301 + symbolTable.insertBuiltIn(bool4, "equal", bool4, bool4); 1.302 + 1.303 + symbolTable.insertBuiltIn(bool2, "notEqual", float2, float2); 1.304 + symbolTable.insertBuiltIn(bool3, "notEqual", float3, float3); 1.305 + symbolTable.insertBuiltIn(bool4, "notEqual", float4, float4); 1.306 + 1.307 + symbolTable.insertBuiltIn(bool2, "notEqual", int2, int2); 1.308 + symbolTable.insertBuiltIn(bool3, "notEqual", int3, int3); 1.309 + symbolTable.insertBuiltIn(bool4, "notEqual", int4, int4); 1.310 + 1.311 + symbolTable.insertBuiltIn(bool2, "notEqual", bool2, bool2); 1.312 + symbolTable.insertBuiltIn(bool3, "notEqual", bool3, bool3); 1.313 + symbolTable.insertBuiltIn(bool4, "notEqual", bool4, bool4); 1.314 + 1.315 + symbolTable.insertBuiltIn(bool1, "any", bool2); 1.316 + symbolTable.insertBuiltIn(bool1, "any", bool3); 1.317 + symbolTable.insertBuiltIn(bool1, "any", bool4); 1.318 + 1.319 + symbolTable.insertBuiltIn(bool1, "all", bool2); 1.320 + symbolTable.insertBuiltIn(bool1, "all", bool3); 1.321 + symbolTable.insertBuiltIn(bool1, "all", bool4); 1.322 + 1.323 + symbolTable.insertBuiltIn(bool2, "not", bool2); 1.324 + symbolTable.insertBuiltIn(bool3, "not", bool3); 1.325 + symbolTable.insertBuiltIn(bool4, "not", bool4); 1.326 + 1.327 + TType *sampler2D = new TType(EbtSampler2D, EbpUndefined, EvqGlobal, 1); 1.328 + TType *samplerCube = new TType(EbtSamplerCube, EbpUndefined, EvqGlobal, 1); 1.329 + 1.330 + // 1.331 + // Texture Functions for GLSL ES 1.0 1.332 + // 1.333 + symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2); 1.334 + symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3); 1.335 + symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4); 1.336 + symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3); 1.337 + 1.338 + if (resources.OES_EGL_image_external) 1.339 + { 1.340 + TType *samplerExternalOES = new TType(EbtSamplerExternalOES, EbpUndefined, EvqGlobal, 1); 1.341 + 1.342 + symbolTable.insertBuiltIn(float4, "texture2D", samplerExternalOES, float2); 1.343 + symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float3); 1.344 + symbolTable.insertBuiltIn(float4, "texture2DProj", samplerExternalOES, float4); 1.345 + } 1.346 + 1.347 + if (resources.ARB_texture_rectangle) 1.348 + { 1.349 + TType *sampler2DRect = new TType(EbtSampler2DRect, EbpUndefined, EvqGlobal, 1); 1.350 + 1.351 + symbolTable.insertBuiltIn(float4, "texture2DRect", sampler2DRect, float2); 1.352 + symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float3); 1.353 + symbolTable.insertBuiltIn(float4, "texture2DRectProj", sampler2DRect, float4); 1.354 + } 1.355 + 1.356 + if (type == SH_FRAGMENT_SHADER) 1.357 + { 1.358 + symbolTable.insertBuiltIn(float4, "texture2D", sampler2D, float2, float1); 1.359 + symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float3, float1); 1.360 + symbolTable.insertBuiltIn(float4, "texture2DProj", sampler2D, float4, float1); 1.361 + symbolTable.insertBuiltIn(float4, "textureCube", samplerCube, float3, float1); 1.362 + 1.363 + if (resources.OES_standard_derivatives) 1.364 + { 1.365 + symbolTable.insertBuiltIn(float1, "dFdx", float1); 1.366 + symbolTable.insertBuiltIn(float2, "dFdx", float2); 1.367 + symbolTable.insertBuiltIn(float3, "dFdx", float3); 1.368 + symbolTable.insertBuiltIn(float4, "dFdx", float4); 1.369 + 1.370 + symbolTable.insertBuiltIn(float1, "dFdy", float1); 1.371 + symbolTable.insertBuiltIn(float2, "dFdy", float2); 1.372 + symbolTable.insertBuiltIn(float3, "dFdy", float3); 1.373 + symbolTable.insertBuiltIn(float4, "dFdy", float4); 1.374 + 1.375 + symbolTable.insertBuiltIn(float1, "fwidth", float1); 1.376 + symbolTable.insertBuiltIn(float2, "fwidth", float2); 1.377 + symbolTable.insertBuiltIn(float3, "fwidth", float3); 1.378 + symbolTable.insertBuiltIn(float4, "fwidth", float4); 1.379 + } 1.380 + } 1.381 + 1.382 + if(type == SH_VERTEX_SHADER) 1.383 + { 1.384 + symbolTable.insertBuiltIn(float4, "texture2DLod", sampler2D, float2, float1); 1.385 + symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float3, float1); 1.386 + symbolTable.insertBuiltIn(float4, "texture2DProjLod", sampler2D, float4, float1); 1.387 + symbolTable.insertBuiltIn(float4, "textureCubeLod", samplerCube, float3, float1); 1.388 + } 1.389 + 1.390 + // 1.391 + // Depth range in window coordinates 1.392 + // 1.393 + TFieldList *fields = NewPoolTFieldList(); 1.394 + TField *near = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("near")); 1.395 + TField *far = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("far")); 1.396 + TField *diff = new TField(new TType(EbtFloat, EbpHigh, EvqGlobal, 1), NewPoolTString("diff")); 1.397 + fields->push_back(near); 1.398 + fields->push_back(far); 1.399 + fields->push_back(diff); 1.400 + TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields); 1.401 + TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true); 1.402 + symbolTable.insert(*depthRangeParameters); 1.403 + TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct)); 1.404 + depthRange->setQualifier(EvqUniform); 1.405 + symbolTable.insert(*depthRange); 1.406 + 1.407 + // 1.408 + // Implementation dependent built-in constants. 1.409 + // 1.410 + symbolTable.insertConstInt("gl_MaxVertexAttribs", resources.MaxVertexAttribs); 1.411 + symbolTable.insertConstInt("gl_MaxVertexUniformVectors", resources.MaxVertexUniformVectors); 1.412 + symbolTable.insertConstInt("gl_MaxVaryingVectors", resources.MaxVaryingVectors); 1.413 + symbolTable.insertConstInt("gl_MaxVertexTextureImageUnits", resources.MaxVertexTextureImageUnits); 1.414 + symbolTable.insertConstInt("gl_MaxCombinedTextureImageUnits", resources.MaxCombinedTextureImageUnits); 1.415 + symbolTable.insertConstInt("gl_MaxTextureImageUnits", resources.MaxTextureImageUnits); 1.416 + symbolTable.insertConstInt("gl_MaxFragmentUniformVectors", resources.MaxFragmentUniformVectors); 1.417 + 1.418 + if (spec != SH_CSS_SHADERS_SPEC) 1.419 + { 1.420 + symbolTable.insertConstInt("gl_MaxDrawBuffers", resources.MaxDrawBuffers); 1.421 + } 1.422 +} 1.423 + 1.424 +void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, 1.425 + const ShBuiltInResources &resources, 1.426 + TSymbolTable &symbolTable) 1.427 +{ 1.428 + // 1.429 + // First, insert some special built-in variables that are not in 1.430 + // the built-in header files. 1.431 + // 1.432 + switch(type) { 1.433 + case SH_FRAGMENT_SHADER: 1.434 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4))); 1.435 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1))); 1.436 + symbolTable.insert(*new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2))); 1.437 + 1.438 + // 1.439 + // In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available. 1.440 + // Instead, css_MixColor and css_ColorMatrix are available. 1.441 + // 1.442 + if (spec != SH_CSS_SHADERS_SPEC) { 1.443 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4))); 1.444 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4))); 1.445 + if (resources.EXT_frag_depth) { 1.446 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1))); 1.447 + symbolTable.relateToExtension("gl_FragDepthEXT", "GL_EXT_frag_depth"); 1.448 + } 1.449 + } else { 1.450 + symbolTable.insert(*new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4))); 1.451 + symbolTable.insert(*new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, true))); 1.452 + } 1.453 + 1.454 + break; 1.455 + 1.456 + case SH_VERTEX_SHADER: 1.457 + symbolTable.insert(*new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4))); 1.458 + symbolTable.insert(*new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1))); 1.459 + break; 1.460 + 1.461 + default: assert(false && "Language not supported"); 1.462 + } 1.463 + 1.464 + // 1.465 + // Next, identify which built-ins from the already loaded headers have 1.466 + // a mapping to an operator. Those that are not identified as such are 1.467 + // expected to be resolved through a library of functions, versus as 1.468 + // operations. 1.469 + // 1.470 + symbolTable.relateToOperator("matrixCompMult", EOpMul); 1.471 + 1.472 + symbolTable.relateToOperator("equal", EOpVectorEqual); 1.473 + symbolTable.relateToOperator("notEqual", EOpVectorNotEqual); 1.474 + symbolTable.relateToOperator("lessThan", EOpLessThan); 1.475 + symbolTable.relateToOperator("greaterThan", EOpGreaterThan); 1.476 + symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual); 1.477 + symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual); 1.478 + 1.479 + symbolTable.relateToOperator("radians", EOpRadians); 1.480 + symbolTable.relateToOperator("degrees", EOpDegrees); 1.481 + symbolTable.relateToOperator("sin", EOpSin); 1.482 + symbolTable.relateToOperator("cos", EOpCos); 1.483 + symbolTable.relateToOperator("tan", EOpTan); 1.484 + symbolTable.relateToOperator("asin", EOpAsin); 1.485 + symbolTable.relateToOperator("acos", EOpAcos); 1.486 + symbolTable.relateToOperator("atan", EOpAtan); 1.487 + 1.488 + symbolTable.relateToOperator("pow", EOpPow); 1.489 + symbolTable.relateToOperator("exp2", EOpExp2); 1.490 + symbolTable.relateToOperator("log", EOpLog); 1.491 + symbolTable.relateToOperator("exp", EOpExp); 1.492 + symbolTable.relateToOperator("log2", EOpLog2); 1.493 + symbolTable.relateToOperator("sqrt", EOpSqrt); 1.494 + symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt); 1.495 + 1.496 + symbolTable.relateToOperator("abs", EOpAbs); 1.497 + symbolTable.relateToOperator("sign", EOpSign); 1.498 + symbolTable.relateToOperator("floor", EOpFloor); 1.499 + symbolTable.relateToOperator("ceil", EOpCeil); 1.500 + symbolTable.relateToOperator("fract", EOpFract); 1.501 + symbolTable.relateToOperator("mod", EOpMod); 1.502 + symbolTable.relateToOperator("min", EOpMin); 1.503 + symbolTable.relateToOperator("max", EOpMax); 1.504 + symbolTable.relateToOperator("clamp", EOpClamp); 1.505 + symbolTable.relateToOperator("mix", EOpMix); 1.506 + symbolTable.relateToOperator("step", EOpStep); 1.507 + symbolTable.relateToOperator("smoothstep", EOpSmoothStep); 1.508 + 1.509 + symbolTable.relateToOperator("length", EOpLength); 1.510 + symbolTable.relateToOperator("distance", EOpDistance); 1.511 + symbolTable.relateToOperator("dot", EOpDot); 1.512 + symbolTable.relateToOperator("cross", EOpCross); 1.513 + symbolTable.relateToOperator("normalize", EOpNormalize); 1.514 + symbolTable.relateToOperator("faceforward", EOpFaceForward); 1.515 + symbolTable.relateToOperator("reflect", EOpReflect); 1.516 + symbolTable.relateToOperator("refract", EOpRefract); 1.517 + 1.518 + symbolTable.relateToOperator("any", EOpAny); 1.519 + symbolTable.relateToOperator("all", EOpAll); 1.520 + symbolTable.relateToOperator("not", EOpVectorLogicalNot); 1.521 + 1.522 + // Map language-specific operators. 1.523 + switch(type) { 1.524 + case SH_VERTEX_SHADER: 1.525 + break; 1.526 + case SH_FRAGMENT_SHADER: 1.527 + if (resources.OES_standard_derivatives) { 1.528 + symbolTable.relateToOperator("dFdx", EOpDFdx); 1.529 + symbolTable.relateToOperator("dFdy", EOpDFdy); 1.530 + symbolTable.relateToOperator("fwidth", EOpFwidth); 1.531 + 1.532 + symbolTable.relateToExtension("dFdx", "GL_OES_standard_derivatives"); 1.533 + symbolTable.relateToExtension("dFdy", "GL_OES_standard_derivatives"); 1.534 + symbolTable.relateToExtension("fwidth", "GL_OES_standard_derivatives"); 1.535 + } 1.536 + break; 1.537 + default: break; 1.538 + } 1.539 + 1.540 + // Finally add resource-specific variables. 1.541 + switch(type) { 1.542 + case SH_FRAGMENT_SHADER: 1.543 + if (spec != SH_CSS_SHADERS_SPEC) { 1.544 + // Set up gl_FragData. The array size. 1.545 + TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, false, true); 1.546 + fragData.setArraySize(resources.MaxDrawBuffers); 1.547 + symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); 1.548 + } 1.549 + break; 1.550 + default: break; 1.551 + } 1.552 +} 1.553 + 1.554 +void InitExtensionBehavior(const ShBuiltInResources& resources, 1.555 + TExtensionBehavior& extBehavior) 1.556 +{ 1.557 + if (resources.OES_standard_derivatives) 1.558 + extBehavior["GL_OES_standard_derivatives"] = EBhUndefined; 1.559 + if (resources.OES_EGL_image_external) 1.560 + extBehavior["GL_OES_EGL_image_external"] = EBhUndefined; 1.561 + if (resources.ARB_texture_rectangle) 1.562 + extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined; 1.563 + if (resources.EXT_draw_buffers) 1.564 + extBehavior["GL_EXT_draw_buffers"] = EBhUndefined; 1.565 + if (resources.EXT_frag_depth) 1.566 + extBehavior["GL_EXT_frag_depth"] = EBhUndefined; 1.567 +}