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