Home | History | Annotate | Download | only in Include
      1 //
      2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
      3 // Copyright (C) 2012-2013 LunarG, Inc.
      4 //
      5 // All rights reserved.
      6 //
      7 // Redistribution and use in source and binary forms, with or without
      8 // modification, are permitted provided that the following conditions
      9 // are met:
     10 //
     11 //    Redistributions of source code must retain the above copyright
     12 //    notice, this list of conditions and the following disclaimer.
     13 //
     14 //    Redistributions in binary form must reproduce the above
     15 //    copyright notice, this list of conditions and the following
     16 //    disclaimer in the documentation and/or other materials provided
     17 //    with the distribution.
     18 //
     19 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
     20 //    contributors may be used to endorse or promote products derived
     21 //    from this software without specific prior written permission.
     22 //
     23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34 // POSSIBILITY OF SUCH DAMAGE.
     35 //
     36 
     37 #ifndef _BASICTYPES_INCLUDED_
     38 #define _BASICTYPES_INCLUDED_
     39 
     40 namespace glslang {
     41 
     42 //
     43 // Basic type.  Arrays, vectors, sampler details, etc., are orthogonal to this.
     44 //
     45 enum TBasicType {
     46     EbtVoid,
     47     EbtFloat,
     48     EbtDouble,
     49 #ifdef AMD_EXTENSIONS
     50     EbtFloat16,
     51 #endif
     52     EbtInt,
     53     EbtUint,
     54     EbtInt64,
     55     EbtUint64,
     56 #ifdef AMD_EXTENSIONS
     57     EbtInt16,
     58     EbtUint16,
     59 #endif
     60     EbtBool,
     61     EbtAtomicUint,
     62     EbtSampler,
     63     EbtStruct,
     64     EbtBlock,
     65 
     66     // HLSL types that live only temporarily.
     67     EbtString,
     68 
     69     EbtNumTypes
     70 };
     71 
     72 //
     73 // Storage qualifiers.  Should align with different kinds of storage or
     74 // resource or GLSL storage qualifier.  Expansion is deprecated.
     75 //
     76 // N.B.: You probably DON'T want to add anything here, but rather just add it
     77 // to the built-in variables.  See the comment above TBuiltInVariable.
     78 //
     79 // A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
     80 // DO NOT follow the design pattern of, say EvqInstanceId, etc.
     81 //
     82 enum TStorageQualifier {
     83     EvqTemporary,     // For temporaries (within a function), read/write
     84     EvqGlobal,        // For globals read/write
     85     EvqConst,         // User-defined constant values, will be semantically constant and constant folded
     86     EvqVaryingIn,     // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
     87     EvqVaryingOut,    // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
     88     EvqUniform,       // read only, shared with app
     89     EvqBuffer,        // read/write, shared with app
     90     EvqShared,        // compute shader's read/write 'shared' qualifier
     91 
     92     // parameters
     93     EvqIn,            // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
     94     EvqOut,           // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
     95     EvqInOut,
     96     EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
     97 
     98     // built-ins read by vertex shader
     99     EvqVertexId,
    100     EvqInstanceId,
    101 
    102     // built-ins written by vertex shader
    103     EvqPosition,
    104     EvqPointSize,
    105     EvqClipVertex,
    106 
    107     // built-ins read by fragment shader
    108     EvqFace,
    109     EvqFragCoord,
    110     EvqPointCoord,
    111 
    112     // built-ins written by fragment shader
    113     EvqFragColor,
    114     EvqFragDepth,
    115 
    116     // end of list
    117     EvqLast
    118 };
    119 
    120 //
    121 // Subcategories of the TStorageQualifier, simply to give a direct mapping
    122 // between built-in variable names and an numerical value (the enum).
    123 //
    124 // For backward compatibility, there is some redundancy between the
    125 // TStorageQualifier and these.  Existing members should both be maintained accurately.
    126 // However, any new built-in variable (and any existing non-redundant one)
    127 // must follow the pattern that the specific built-in is here, and only its
    128 // general qualifier is in TStorageQualifier.
    129 //
    130 // Something like gl_Position, which is sometimes 'in' and sometimes 'out'
    131 // shows up as two different built-in variables in a single stage, but
    132 // only has a single enum in TBuiltInVariable, so both the
    133 // TStorageQualifier and the TBuitinVariable are needed to distinguish
    134 // between them.
    135 //
    136 enum TBuiltInVariable {
    137     EbvNone,
    138     EbvNumWorkGroups,
    139     EbvWorkGroupSize,
    140     EbvWorkGroupId,
    141     EbvLocalInvocationId,
    142     EbvGlobalInvocationId,
    143     EbvLocalInvocationIndex,
    144     EbvSubGroupSize,
    145     EbvSubGroupInvocation,
    146     EbvSubGroupEqMask,
    147     EbvSubGroupGeMask,
    148     EbvSubGroupGtMask,
    149     EbvSubGroupLeMask,
    150     EbvSubGroupLtMask,
    151     EbvVertexId,
    152     EbvInstanceId,
    153     EbvVertexIndex,
    154     EbvInstanceIndex,
    155     EbvBaseVertex,
    156     EbvBaseInstance,
    157     EbvDrawId,
    158     EbvPosition,
    159     EbvPointSize,
    160     EbvClipVertex,
    161     EbvClipDistance,
    162     EbvCullDistance,
    163     EbvNormal,
    164     EbvVertex,
    165     EbvMultiTexCoord0,
    166     EbvMultiTexCoord1,
    167     EbvMultiTexCoord2,
    168     EbvMultiTexCoord3,
    169     EbvMultiTexCoord4,
    170     EbvMultiTexCoord5,
    171     EbvMultiTexCoord6,
    172     EbvMultiTexCoord7,
    173     EbvFrontColor,
    174     EbvBackColor,
    175     EbvFrontSecondaryColor,
    176     EbvBackSecondaryColor,
    177     EbvTexCoord,
    178     EbvFogFragCoord,
    179     EbvInvocationId,
    180     EbvPrimitiveId,
    181     EbvLayer,
    182     EbvViewportIndex,
    183     EbvPatchVertices,
    184     EbvTessLevelOuter,
    185     EbvTessLevelInner,
    186     EbvBoundingBox,
    187     EbvTessCoord,
    188     EbvColor,
    189     EbvSecondaryColor,
    190     EbvFace,
    191     EbvFragCoord,
    192     EbvPointCoord,
    193     EbvFragColor,
    194     EbvFragData,
    195     EbvFragDepth,
    196     EbvFragStencilRef,
    197     EbvSampleId,
    198     EbvSamplePosition,
    199     EbvSampleMask,
    200     EbvHelperInvocation,
    201 #ifdef AMD_EXTENSIONS
    202     EbvBaryCoordNoPersp,
    203     EbvBaryCoordNoPerspCentroid,
    204     EbvBaryCoordNoPerspSample,
    205     EbvBaryCoordSmooth,
    206     EbvBaryCoordSmoothCentroid,
    207     EbvBaryCoordSmoothSample,
    208     EbvBaryCoordPullModel,
    209 #endif
    210 
    211     EbvViewIndex,
    212     EbvDeviceIndex,
    213 
    214 #ifdef NV_EXTENSIONS
    215     EbvViewportMaskNV,
    216     EbvSecondaryPositionNV,
    217     EbvSecondaryViewportMaskNV,
    218     EbvPositionPerViewNV,
    219     EbvViewportMaskPerViewNV,
    220 #endif
    221 
    222     // HLSL built-ins that live only temporarily, until they get remapped
    223     // to one of the above.
    224     EbvFragDepthGreater,
    225     EbvFragDepthLesser,
    226     EbvGsOutputStream,
    227     EbvOutputPatch,
    228     EbvInputPatch,
    229 
    230     // structbuffer types
    231     EbvAppendConsume, // no need to differentiate append and consume
    232     EbvRWStructuredBuffer,
    233     EbvStructuredBuffer,
    234     EbvByteAddressBuffer,
    235     EbvRWByteAddressBuffer,
    236 
    237     EbvLast
    238 };
    239 
    240 // These will show up in error messages
    241 __inline const char* GetStorageQualifierString(TStorageQualifier q)
    242 {
    243     switch (q) {
    244     case EvqTemporary:      return "temp";           break;
    245     case EvqGlobal:         return "global";         break;
    246     case EvqConst:          return "const";          break;
    247     case EvqConstReadOnly:  return "const (read only)"; break;
    248     case EvqVaryingIn:      return "in";             break;
    249     case EvqVaryingOut:     return "out";            break;
    250     case EvqUniform:        return "uniform";        break;
    251     case EvqBuffer:         return "buffer";         break;
    252     case EvqShared:         return "shared";         break;
    253     case EvqIn:             return "in";             break;
    254     case EvqOut:            return "out";            break;
    255     case EvqInOut:          return "inout";          break;
    256     case EvqVertexId:       return "gl_VertexId";    break;
    257     case EvqInstanceId:     return "gl_InstanceId";  break;
    258     case EvqPosition:       return "gl_Position";    break;
    259     case EvqPointSize:      return "gl_PointSize";   break;
    260     case EvqClipVertex:     return "gl_ClipVertex";  break;
    261     case EvqFace:           return "gl_FrontFacing"; break;
    262     case EvqFragCoord:      return "gl_FragCoord";   break;
    263     case EvqPointCoord:     return "gl_PointCoord";  break;
    264     case EvqFragColor:      return "fragColor";      break;
    265     case EvqFragDepth:      return "gl_FragDepth";   break;
    266     default:                return "unknown qualifier";
    267     }
    268 }
    269 
    270 __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
    271 {
    272     switch (v) {
    273     case EbvNone:                 return "";
    274     case EbvNumWorkGroups:        return "NumWorkGroups";
    275     case EbvWorkGroupSize:        return "WorkGroupSize";
    276     case EbvWorkGroupId:          return "WorkGroupID";
    277     case EbvLocalInvocationId:    return "LocalInvocationID";
    278     case EbvGlobalInvocationId:   return "GlobalInvocationID";
    279     case EbvLocalInvocationIndex: return "LocalInvocationIndex";
    280     case EbvSubGroupSize:         return "SubGroupSize";
    281     case EbvSubGroupInvocation:   return "SubGroupInvocation";
    282     case EbvSubGroupEqMask:       return "SubGroupEqMask";
    283     case EbvSubGroupGeMask:       return "SubGroupGeMask";
    284     case EbvSubGroupGtMask:       return "SubGroupGtMask";
    285     case EbvSubGroupLeMask:       return "SubGroupLeMask";
    286     case EbvSubGroupLtMask:       return "SubGroupLtMask";
    287     case EbvVertexId:             return "VertexId";
    288     case EbvInstanceId:           return "InstanceId";
    289     case EbvVertexIndex:          return "VertexIndex";
    290     case EbvInstanceIndex:        return "InstanceIndex";
    291     case EbvBaseVertex:           return "BaseVertex";
    292     case EbvBaseInstance:         return "BaseInstance";
    293     case EbvDrawId:               return "DrawId";
    294     case EbvPosition:             return "Position";
    295     case EbvPointSize:            return "PointSize";
    296     case EbvClipVertex:           return "ClipVertex";
    297     case EbvClipDistance:         return "ClipDistance";
    298     case EbvCullDistance:         return "CullDistance";
    299     case EbvNormal:               return "Normal";
    300     case EbvVertex:               return "Vertex";
    301     case EbvMultiTexCoord0:       return "MultiTexCoord0";
    302     case EbvMultiTexCoord1:       return "MultiTexCoord1";
    303     case EbvMultiTexCoord2:       return "MultiTexCoord2";
    304     case EbvMultiTexCoord3:       return "MultiTexCoord3";
    305     case EbvMultiTexCoord4:       return "MultiTexCoord4";
    306     case EbvMultiTexCoord5:       return "MultiTexCoord5";
    307     case EbvMultiTexCoord6:       return "MultiTexCoord6";
    308     case EbvMultiTexCoord7:       return "MultiTexCoord7";
    309     case EbvFrontColor:           return "FrontColor";
    310     case EbvBackColor:            return "BackColor";
    311     case EbvFrontSecondaryColor:  return "FrontSecondaryColor";
    312     case EbvBackSecondaryColor:   return "BackSecondaryColor";
    313     case EbvTexCoord:             return "TexCoord";
    314     case EbvFogFragCoord:         return "FogFragCoord";
    315     case EbvInvocationId:         return "InvocationID";
    316     case EbvPrimitiveId:          return "PrimitiveID";
    317     case EbvLayer:                return "Layer";
    318     case EbvViewportIndex:        return "ViewportIndex";
    319     case EbvPatchVertices:        return "PatchVertices";
    320     case EbvTessLevelOuter:       return "TessLevelOuter";
    321     case EbvTessLevelInner:       return "TessLevelInner";
    322     case EbvBoundingBox:          return "BoundingBox";
    323     case EbvTessCoord:            return "TessCoord";
    324     case EbvColor:                return "Color";
    325     case EbvSecondaryColor:       return "SecondaryColor";
    326     case EbvFace:                 return "Face";
    327     case EbvFragCoord:            return "FragCoord";
    328     case EbvPointCoord:           return "PointCoord";
    329     case EbvFragColor:            return "FragColor";
    330     case EbvFragData:             return "FragData";
    331     case EbvFragDepth:            return "FragDepth";
    332     case EbvFragStencilRef:       return "FragStencilRef";
    333     case EbvSampleId:             return "SampleId";
    334     case EbvSamplePosition:       return "SamplePosition";
    335     case EbvSampleMask:           return "SampleMaskIn";
    336     case EbvHelperInvocation:     return "HelperInvocation";
    337 #ifdef AMD_EXTENSIONS
    338     case EbvBaryCoordNoPersp:           return "BaryCoordNoPersp";
    339     case EbvBaryCoordNoPerspCentroid:   return "BaryCoordNoPerspCentroid";
    340     case EbvBaryCoordNoPerspSample:     return "BaryCoordNoPerspSample";
    341     case EbvBaryCoordSmooth:            return "BaryCoordSmooth";
    342     case EbvBaryCoordSmoothCentroid:    return "BaryCoordSmoothCentroid";
    343     case EbvBaryCoordSmoothSample:      return "BaryCoordSmoothSample";
    344     case EbvBaryCoordPullModel:         return "BaryCoordPullModel";
    345 #endif
    346 
    347     case EbvViewIndex:                  return "ViewIndex";
    348     case EbvDeviceIndex:                return "DeviceIndex";
    349 
    350 #ifdef NV_EXTENSIONS
    351     case EbvViewportMaskNV:             return "ViewportMaskNV";
    352     case EbvSecondaryPositionNV:        return "SecondaryPositionNV";
    353     case EbvSecondaryViewportMaskNV:    return "SecondaryViewportMaskNV";
    354     case EbvPositionPerViewNV:          return "PositionPerViewNV";
    355     case EbvViewportMaskPerViewNV:      return "ViewportMaskPerViewNV";
    356 #endif
    357     default:                      return "unknown built-in variable";
    358     }
    359 }
    360 
    361 // In this enum, order matters; users can assume higher precision is a bigger value
    362 // and EpqNone is 0.
    363 enum TPrecisionQualifier {
    364     EpqNone = 0,
    365     EpqLow,
    366     EpqMedium,
    367     EpqHigh
    368 };
    369 
    370 __inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
    371 {
    372     switch(p) {
    373     case EpqNone:   return "";        break;
    374     case EpqLow:    return "lowp";    break;
    375     case EpqMedium: return "mediump"; break;
    376     case EpqHigh:   return "highp";   break;
    377     default:        return "unknown precision qualifier";
    378     }
    379 }
    380 
    381 } // end namespace glslang
    382 
    383 #endif // _BASICTYPES_INCLUDED_
    384