Home | History | Annotate | Download | only in translator
      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 #ifndef _BASICTYPES_INCLUDED_
      8 #define _BASICTYPES_INCLUDED_
      9 
     10 #include <assert.h>
     11 
     12 //
     13 // Precision qualifiers
     14 //
     15 enum TPrecision
     16 {
     17     // These need to be kept sorted
     18     EbpUndefined,
     19     EbpLow,
     20     EbpMedium,
     21     EbpHigh
     22 };
     23 
     24 inline const char* getPrecisionString(TPrecision p)
     25 {
     26     switch(p)
     27     {
     28     case EbpHigh:		return "highp";		break;
     29     case EbpMedium:		return "mediump";	break;
     30     case EbpLow:		return "lowp";		break;
     31     default:			return "mediump";   break;   // Safest fallback
     32     }
     33 }
     34 
     35 //
     36 // Basic type.  Arrays, vectors, etc., are orthogonal to this.
     37 //
     38 enum TBasicType
     39 {
     40     EbtVoid,
     41     EbtFloat,
     42     EbtInt,
     43     EbtUInt,
     44     EbtBool,
     45     EbtGVec4,              // non type: represents vec4, ivec4 and uvec4
     46     EbtGuardSamplerBegin,  // non type: see implementation of IsSampler()
     47     EbtSampler2D,
     48     EbtSampler3D,
     49     EbtSamplerCube,
     50     EbtSampler2DArray,
     51     EbtSamplerExternalOES,  // Only valid if OES_EGL_image_external exists.
     52     EbtSampler2DRect,       // Only valid if GL_ARB_texture_rectangle exists.
     53     EbtISampler2D,
     54     EbtISampler3D,
     55     EbtISamplerCube,
     56     EbtISampler2DArray,
     57     EbtUSampler2D,
     58     EbtUSampler3D,
     59     EbtUSamplerCube,
     60     EbtUSampler2DArray,
     61     EbtSampler2DShadow,
     62     EbtSamplerCubeShadow,
     63     EbtSampler2DArrayShadow,
     64     EbtGuardSamplerEnd,    // non type: see implementation of IsSampler()
     65     EbtGSampler2D,         // non type: represents sampler2D, isampler2D and usampler2D
     66     EbtGSampler3D,         // non type: represents sampler3D, isampler3D and usampler3D
     67     EbtGSamplerCube,       // non type: represents samplerCube, isamplerCube and usamplerCube
     68     EbtGSampler2DArray,    // non type: represents sampler2DArray, isampler2DArray and usampler2DArray
     69     EbtStruct,
     70     EbtInterfaceBlock,
     71     EbtAddress,            // should be deprecated??
     72 };
     73 
     74 const char* getBasicString(TBasicType t);
     75 
     76 inline bool IsSampler(TBasicType type)
     77 {
     78     return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
     79 }
     80 
     81 inline bool IsIntegerSampler(TBasicType type)
     82 {
     83     switch (type)
     84     {
     85       case EbtISampler2D:
     86       case EbtISampler3D:
     87       case EbtISamplerCube:
     88       case EbtISampler2DArray:
     89       case EbtUSampler2D:
     90       case EbtUSampler3D:
     91       case EbtUSamplerCube:
     92       case EbtUSampler2DArray:
     93         return true;
     94       case EbtSampler2D:
     95       case EbtSampler3D:
     96       case EbtSamplerCube:
     97       case EbtSamplerExternalOES:
     98       case EbtSampler2DRect:
     99       case EbtSampler2DArray:
    100       case EbtSampler2DShadow:
    101       case EbtSamplerCubeShadow:
    102       case EbtSampler2DArrayShadow:
    103         return false;
    104       default:
    105         assert(!IsSampler(type));
    106     }
    107 
    108     return false;
    109 }
    110 
    111 inline bool IsSampler2D(TBasicType type)
    112 {
    113     switch (type)
    114     {
    115       case EbtSampler2D:
    116       case EbtISampler2D:
    117       case EbtUSampler2D:
    118       case EbtSampler2DArray:
    119       case EbtISampler2DArray:
    120       case EbtUSampler2DArray:
    121       case EbtSampler2DRect:
    122       case EbtSamplerExternalOES:
    123       case EbtSampler2DShadow:
    124       case EbtSampler2DArrayShadow:
    125         return true;
    126       case EbtSampler3D:
    127       case EbtISampler3D:
    128       case EbtUSampler3D:
    129       case EbtISamplerCube:
    130       case EbtUSamplerCube:
    131       case EbtSamplerCube:
    132       case EbtSamplerCubeShadow:
    133         return false;
    134       default:
    135         assert(!IsSampler(type));
    136     }
    137 
    138     return false;
    139 }
    140 
    141 inline bool IsSamplerCube(TBasicType type)
    142 {
    143     switch (type)
    144     {
    145       case EbtSamplerCube:
    146       case EbtISamplerCube:
    147       case EbtUSamplerCube:
    148       case EbtSamplerCubeShadow:
    149         return true;
    150       case EbtSampler2D:
    151       case EbtSampler3D:
    152       case EbtSamplerExternalOES:
    153       case EbtSampler2DRect:
    154       case EbtSampler2DArray:
    155       case EbtISampler2D:
    156       case EbtISampler3D:
    157       case EbtISampler2DArray:
    158       case EbtUSampler2D:
    159       case EbtUSampler3D:
    160       case EbtUSampler2DArray:
    161       case EbtSampler2DShadow:
    162       case EbtSampler2DArrayShadow:
    163         return false;
    164       default:
    165         assert(!IsSampler(type));
    166     }
    167 
    168     return false;
    169 }
    170 
    171 inline bool IsSampler3D(TBasicType type)
    172 {
    173     switch (type)
    174     {
    175       case EbtSampler3D:
    176       case EbtISampler3D:
    177       case EbtUSampler3D:
    178         return true;
    179       case EbtSampler2D:
    180       case EbtSamplerCube:
    181       case EbtSamplerExternalOES:
    182       case EbtSampler2DRect:
    183       case EbtSampler2DArray:
    184       case EbtISampler2D:
    185       case EbtISamplerCube:
    186       case EbtISampler2DArray:
    187       case EbtUSampler2D:
    188       case EbtUSamplerCube:
    189       case EbtUSampler2DArray:
    190       case EbtSampler2DShadow:
    191       case EbtSamplerCubeShadow:
    192       case EbtSampler2DArrayShadow:
    193         return false;
    194       default:
    195         assert(!IsSampler(type));
    196     }
    197 
    198     return false;
    199 }
    200 
    201 inline bool IsSamplerArray(TBasicType type)
    202 {
    203     switch (type)
    204     {
    205       case EbtSampler2DArray:
    206       case EbtISampler2DArray:
    207       case EbtUSampler2DArray:
    208       case EbtSampler2DArrayShadow:
    209         return true;
    210       case EbtSampler2D:
    211       case EbtISampler2D:
    212       case EbtUSampler2D:
    213       case EbtSampler2DRect:
    214       case EbtSamplerExternalOES:
    215       case EbtSampler3D:
    216       case EbtISampler3D:
    217       case EbtUSampler3D:
    218       case EbtISamplerCube:
    219       case EbtUSamplerCube:
    220       case EbtSamplerCube:
    221       case EbtSampler2DShadow:
    222       case EbtSamplerCubeShadow:
    223         return false;
    224       default:
    225         assert(!IsSampler(type));
    226     }
    227 
    228     return false;
    229 }
    230 
    231 inline bool IsShadowSampler(TBasicType type)
    232 {
    233     switch (type)
    234     {
    235       case EbtSampler2DShadow:
    236       case EbtSamplerCubeShadow:
    237       case EbtSampler2DArrayShadow:
    238         return true;
    239       case EbtISampler2D:
    240       case EbtISampler3D:
    241       case EbtISamplerCube:
    242       case EbtISampler2DArray:
    243       case EbtUSampler2D:
    244       case EbtUSampler3D:
    245       case EbtUSamplerCube:
    246       case EbtUSampler2DArray:
    247       case EbtSampler2D:
    248       case EbtSampler3D:
    249       case EbtSamplerCube:
    250       case EbtSamplerExternalOES:
    251       case EbtSampler2DRect:
    252       case EbtSampler2DArray:
    253         return false;
    254       default:
    255         assert(!IsSampler(type));
    256     }
    257 
    258     return false;
    259 }
    260 
    261 inline bool SupportsPrecision(TBasicType type)
    262 {
    263     return type == EbtFloat || type == EbtInt || type == EbtUInt || IsSampler(type);
    264 }
    265 
    266 //
    267 // Qualifiers and built-ins.  These are mainly used to see what can be read
    268 // or written, and by the machine dependent translator to know which registers
    269 // to allocate variables in.  Since built-ins tend to go to different registers
    270 // than varying or uniform, it makes sense they are peers, not sub-classes.
    271 //
    272 enum TQualifier
    273 {
    274     EvqTemporary,     // For temporaries (within a function), read/write
    275     EvqGlobal,        // For globals read/write
    276     EvqInternal,      // For internal use, not visible to the user
    277     EvqConst,         // User defined constants and non-output parameters in functions
    278     EvqAttribute,     // Readonly
    279     EvqVaryingIn,     // readonly, fragment shaders only
    280     EvqVaryingOut,    // vertex shaders only  read/write
    281     EvqInvariantVaryingIn,     // readonly, fragment shaders only
    282     EvqInvariantVaryingOut,    // vertex shaders only  read/write
    283     EvqUniform,       // Readonly, vertex and fragment
    284 
    285     EvqVertexIn,      // Vertex shader input
    286     EvqFragmentOut,   // Fragment shader output
    287     EvqVertexOut,     // Vertex shader output
    288     EvqFragmentIn,    // Fragment shader input
    289 
    290     // parameters
    291     EvqIn,
    292     EvqOut,
    293     EvqInOut,
    294     EvqConstReadOnly,
    295 
    296     // built-ins written by vertex shader
    297     EvqPosition,
    298     EvqPointSize,
    299 
    300     // built-ins read by fragment shader
    301     EvqFragCoord,
    302     EvqFrontFacing,
    303     EvqPointCoord,
    304 
    305     // built-ins written by fragment shader
    306     EvqFragColor,
    307     EvqFragData,
    308     EvqFragDepth,
    309 
    310     // GLSL ES 3.0 vertex output and fragment input
    311     EvqSmooth,        // Incomplete qualifier, smooth is the default
    312     EvqFlat,          // Incomplete qualifier
    313     EvqSmoothOut = EvqSmooth,
    314     EvqFlatOut = EvqFlat,
    315     EvqCentroidOut,   // Implies smooth
    316     EvqSmoothIn,
    317     EvqFlatIn,
    318     EvqCentroidIn,    // Implies smooth
    319 
    320     // end of list
    321     EvqLast
    322 };
    323 
    324 enum TLayoutMatrixPacking
    325 {
    326     EmpUnspecified,
    327     EmpRowMajor,
    328     EmpColumnMajor
    329 };
    330 
    331 enum TLayoutBlockStorage
    332 {
    333     EbsUnspecified,
    334     EbsShared,
    335     EbsPacked,
    336     EbsStd140
    337 };
    338 
    339 struct TLayoutQualifier
    340 {
    341     int location;
    342     TLayoutMatrixPacking matrixPacking;
    343     TLayoutBlockStorage blockStorage;
    344 
    345     static TLayoutQualifier create()
    346     {
    347         TLayoutQualifier layoutQualifier;
    348 
    349         layoutQualifier.location = -1;
    350         layoutQualifier.matrixPacking = EmpUnspecified;
    351         layoutQualifier.blockStorage = EbsUnspecified;
    352 
    353         return layoutQualifier;
    354     }
    355 
    356     bool isEmpty() const
    357     {
    358         return location == -1 && matrixPacking == EmpUnspecified && blockStorage == EbsUnspecified;
    359     }
    360 };
    361 
    362 //
    363 // This is just for debug print out, carried along with the definitions above.
    364 //
    365 inline const char* getQualifierString(TQualifier q)
    366 {
    367     switch(q)
    368     {
    369     case EvqTemporary:      return "Temporary";      break;
    370     case EvqGlobal:         return "Global";         break;
    371     case EvqConst:          return "const";          break;
    372     case EvqConstReadOnly:  return "const";          break;
    373     case EvqAttribute:      return "attribute";      break;
    374     case EvqVaryingIn:      return "varying";        break;
    375     case EvqVaryingOut:     return "varying";        break;
    376     case EvqInvariantVaryingIn: return "invariant varying";	break;
    377     case EvqInvariantVaryingOut:return "invariant varying";	break;
    378     case EvqUniform:        return "uniform";        break;
    379     case EvqVertexIn:       return "in";             break;
    380     case EvqFragmentOut:    return "out";            break;
    381     case EvqVertexOut:      return "out";            break;
    382     case EvqFragmentIn:     return "in";             break;
    383     case EvqIn:             return "in";             break;
    384     case EvqOut:            return "out";            break;
    385     case EvqInOut:          return "inout";          break;
    386     case EvqPosition:       return "Position";       break;
    387     case EvqPointSize:      return "PointSize";      break;
    388     case EvqFragCoord:      return "FragCoord";      break;
    389     case EvqFrontFacing:    return "FrontFacing";    break;
    390     case EvqFragColor:      return "FragColor";      break;
    391     case EvqFragData:       return "FragData";       break;
    392     case EvqFragDepth:      return "FragDepth";      break;
    393     case EvqSmoothOut:      return "smooth out";     break;
    394     case EvqCentroidOut:    return "centroid out";   break;
    395     case EvqFlatOut:        return "flat out";       break;
    396     case EvqSmoothIn:       return "smooth in";      break;
    397     case EvqCentroidIn:     return "centroid in";    break;
    398     case EvqFlatIn:         return "flat in";        break;
    399     default:                return "unknown qualifier";
    400     }
    401 }
    402 
    403 inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq)
    404 {
    405     switch (mpq)
    406     {
    407     case EmpUnspecified:    return "mp_unspecified";
    408     case EmpRowMajor:       return "row_major";
    409     case EmpColumnMajor:    return "column_major";
    410     default:                return "unknown matrix packing";
    411     }
    412 }
    413 
    414 inline const char* getBlockStorageString(TLayoutBlockStorage bsq)
    415 {
    416     switch (bsq)
    417     {
    418     case EbsUnspecified:    return "bs_unspecified";
    419     case EbsShared:         return "shared";
    420     case EbsPacked:         return "packed";
    421     case EbsStd140:         return "std140";
    422     default:                return "unknown block storage";
    423     }
    424 }
    425 
    426 inline const char* getInterpolationString(TQualifier q)
    427 {
    428     switch(q)
    429     {
    430     case EvqSmoothOut:      return "smooth";   break;
    431     case EvqCentroidOut:    return "centroid"; break;
    432     case EvqFlatOut:        return "flat";     break;
    433     case EvqSmoothIn:       return "smooth";   break;
    434     case EvqCentroidIn:     return "centroid"; break;
    435     case EvqFlatIn:         return "flat";     break;
    436     default:                return "unknown interpolation";
    437     }
    438 }
    439 
    440 #endif // _BASICTYPES_INCLUDED_
    441