Home | History | Annotate | Download | only in Include
      1 //
      2 // Copyright (C) 2002-2005  3Dlabs Inc. Ltd.
      3 // Copyright (C) 2012-2013 LunarG, Inc.
      4 // Copyright (C) 2017 ARM Limited.
      5 //
      6 // All rights reserved.
      7 //
      8 // Redistribution and use in source and binary forms, with or without
      9 // modification, are permitted provided that the following conditions
     10 // are met:
     11 //
     12 //    Redistributions of source code must retain the above copyright
     13 //    notice, this list of conditions and the following disclaimer.
     14 //
     15 //    Redistributions in binary form must reproduce the above
     16 //    copyright notice, this list of conditions and the following
     17 //    disclaimer in the documentation and/or other materials provided
     18 //    with the distribution.
     19 //
     20 //    Neither the name of 3Dlabs Inc. Ltd. nor the names of its
     21 //    contributors may be used to endorse or promote products derived
     22 //    from this software without specific prior written permission.
     23 //
     24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     27 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     28 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     29 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     31 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     32 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     34 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35 // POSSIBILITY OF SUCH DAMAGE.
     36 //
     37 
     38 #ifndef _BASICTYPES_INCLUDED_
     39 #define _BASICTYPES_INCLUDED_
     40 
     41 namespace glslang {
     42 
     43 //
     44 // Basic type.  Arrays, vectors, sampler details, etc., are orthogonal to this.
     45 //
     46 enum TBasicType {
     47     EbtVoid,
     48     EbtFloat,
     49     EbtDouble,
     50     EbtFloat16,
     51     EbtInt8,
     52     EbtUint8,
     53     EbtInt16,
     54     EbtUint16,
     55     EbtInt,
     56     EbtUint,
     57     EbtInt64,
     58     EbtUint64,
     59     EbtBool,
     60     EbtAtomicUint,
     61     EbtSampler,
     62     EbtStruct,
     63     EbtBlock,
     64 
     65 #ifdef NV_EXTENSIONS
     66     EbtAccStructNV,
     67 #endif
     68 
     69     EbtReference,
     70 
     71     // HLSL types that live only temporarily.
     72     EbtString,
     73 
     74     EbtNumTypes
     75 };
     76 
     77 //
     78 // Storage qualifiers.  Should align with different kinds of storage or
     79 // resource or GLSL storage qualifier.  Expansion is deprecated.
     80 //
     81 // N.B.: You probably DON'T want to add anything here, but rather just add it
     82 // to the built-in variables.  See the comment above TBuiltInVariable.
     83 //
     84 // A new built-in variable will normally be an existing qualifier, like 'in', 'out', etc.
     85 // DO NOT follow the design pattern of, say EvqInstanceId, etc.
     86 //
     87 enum TStorageQualifier {
     88     EvqTemporary,     // For temporaries (within a function), read/write
     89     EvqGlobal,        // For globals read/write
     90     EvqConst,         // User-defined constant values, will be semantically constant and constant folded
     91     EvqVaryingIn,     // pipeline input, read only, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
     92     EvqVaryingOut,    // pipeline output, read/write, also supercategory for all built-ins not included in this enum (see TBuiltInVariable)
     93     EvqUniform,       // read only, shared with app
     94     EvqBuffer,        // read/write, shared with app
     95     EvqShared,        // compute shader's read/write 'shared' qualifier
     96 
     97 #ifdef NV_EXTENSIONS
     98     EvqPayloadNV,
     99     EvqPayloadInNV,
    100     EvqHitAttrNV,
    101     EvqCallableDataNV,
    102     EvqCallableDataInNV,
    103 #endif
    104 
    105     // parameters
    106     EvqIn,            // also, for 'in' in the grammar before we know if it's a pipeline input or an 'in' parameter
    107     EvqOut,           // also, for 'out' in the grammar before we know if it's a pipeline output or an 'out' parameter
    108     EvqInOut,
    109     EvqConstReadOnly, // input; also other read-only types having neither a constant value nor constant-value semantics
    110 
    111     // built-ins read by vertex shader
    112     EvqVertexId,
    113     EvqInstanceId,
    114 
    115     // built-ins written by vertex shader
    116     EvqPosition,
    117     EvqPointSize,
    118     EvqClipVertex,
    119 
    120     // built-ins read by fragment shader
    121     EvqFace,
    122     EvqFragCoord,
    123     EvqPointCoord,
    124 
    125     // built-ins written by fragment shader
    126     EvqFragColor,
    127     EvqFragDepth,
    128 
    129     // end of list
    130     EvqLast
    131 };
    132 
    133 //
    134 // Subcategories of the TStorageQualifier, simply to give a direct mapping
    135 // between built-in variable names and an numerical value (the enum).
    136 //
    137 // For backward compatibility, there is some redundancy between the
    138 // TStorageQualifier and these.  Existing members should both be maintained accurately.
    139 // However, any new built-in variable (and any existing non-redundant one)
    140 // must follow the pattern that the specific built-in is here, and only its
    141 // general qualifier is in TStorageQualifier.
    142 //
    143 // Something like gl_Position, which is sometimes 'in' and sometimes 'out'
    144 // shows up as two different built-in variables in a single stage, but
    145 // only has a single enum in TBuiltInVariable, so both the
    146 // TStorageQualifier and the TBuitinVariable are needed to distinguish
    147 // between them.
    148 //
    149 enum TBuiltInVariable {
    150     EbvNone,
    151     EbvNumWorkGroups,
    152     EbvWorkGroupSize,
    153     EbvWorkGroupId,
    154     EbvLocalInvocationId,
    155     EbvGlobalInvocationId,
    156     EbvLocalInvocationIndex,
    157     EbvNumSubgroups,
    158     EbvSubgroupID,
    159     EbvSubGroupSize,
    160     EbvSubGroupInvocation,
    161     EbvSubGroupEqMask,
    162     EbvSubGroupGeMask,
    163     EbvSubGroupGtMask,
    164     EbvSubGroupLeMask,
    165     EbvSubGroupLtMask,
    166     EbvSubgroupSize2,
    167     EbvSubgroupInvocation2,
    168     EbvSubgroupEqMask2,
    169     EbvSubgroupGeMask2,
    170     EbvSubgroupGtMask2,
    171     EbvSubgroupLeMask2,
    172     EbvSubgroupLtMask2,
    173     EbvVertexId,
    174     EbvInstanceId,
    175     EbvVertexIndex,
    176     EbvInstanceIndex,
    177     EbvBaseVertex,
    178     EbvBaseInstance,
    179     EbvDrawId,
    180     EbvPosition,
    181     EbvPointSize,
    182     EbvClipVertex,
    183     EbvClipDistance,
    184     EbvCullDistance,
    185     EbvNormal,
    186     EbvVertex,
    187     EbvMultiTexCoord0,
    188     EbvMultiTexCoord1,
    189     EbvMultiTexCoord2,
    190     EbvMultiTexCoord3,
    191     EbvMultiTexCoord4,
    192     EbvMultiTexCoord5,
    193     EbvMultiTexCoord6,
    194     EbvMultiTexCoord7,
    195     EbvFrontColor,
    196     EbvBackColor,
    197     EbvFrontSecondaryColor,
    198     EbvBackSecondaryColor,
    199     EbvTexCoord,
    200     EbvFogFragCoord,
    201     EbvInvocationId,
    202     EbvPrimitiveId,
    203     EbvLayer,
    204     EbvViewportIndex,
    205     EbvPatchVertices,
    206     EbvTessLevelOuter,
    207     EbvTessLevelInner,
    208     EbvBoundingBox,
    209     EbvTessCoord,
    210     EbvColor,
    211     EbvSecondaryColor,
    212     EbvFace,
    213     EbvFragCoord,
    214     EbvPointCoord,
    215     EbvFragColor,
    216     EbvFragData,
    217     EbvFragDepth,
    218     EbvFragStencilRef,
    219     EbvSampleId,
    220     EbvSamplePosition,
    221     EbvSampleMask,
    222     EbvHelperInvocation,
    223 
    224 #ifdef AMD_EXTENSIONS
    225     EbvBaryCoordNoPersp,
    226     EbvBaryCoordNoPerspCentroid,
    227     EbvBaryCoordNoPerspSample,
    228     EbvBaryCoordSmooth,
    229     EbvBaryCoordSmoothCentroid,
    230     EbvBaryCoordSmoothSample,
    231     EbvBaryCoordPullModel,
    232 #endif
    233 
    234     EbvViewIndex,
    235     EbvDeviceIndex,
    236 
    237     EbvFragSizeEXT,
    238     EbvFragInvocationCountEXT,
    239 
    240 #ifdef NV_EXTENSIONS
    241     EbvViewportMaskNV,
    242     EbvSecondaryPositionNV,
    243     EbvSecondaryViewportMaskNV,
    244     EbvPositionPerViewNV,
    245     EbvViewportMaskPerViewNV,
    246     EbvFragFullyCoveredNV,
    247     EbvFragmentSizeNV,
    248     EbvInvocationsPerPixelNV,
    249     // raytracing
    250     EbvLaunchIdNV,
    251     EbvLaunchSizeNV,
    252     EbvInstanceCustomIndexNV,
    253     EbvWorldRayOriginNV,
    254     EbvWorldRayDirectionNV,
    255     EbvObjectRayOriginNV,
    256     EbvObjectRayDirectionNV,
    257     EbvRayTminNV,
    258     EbvRayTmaxNV,
    259     EbvHitTNV,
    260     EbvHitKindNV,
    261     EbvObjectToWorldNV,
    262     EbvWorldToObjectNV,
    263     EbvIncomingRayFlagsNV,
    264     EbvBaryCoordNV,
    265     EbvBaryCoordNoPerspNV,
    266     EbvTaskCountNV,
    267     EbvPrimitiveCountNV,
    268     EbvPrimitiveIndicesNV,
    269     EbvClipDistancePerViewNV,
    270     EbvCullDistancePerViewNV,
    271     EbvLayerPerViewNV,
    272     EbvMeshViewCountNV,
    273     EbvMeshViewIndicesNV,
    274 #endif
    275 
    276     // HLSL built-ins that live only temporarily, until they get remapped
    277     // to one of the above.
    278     EbvFragDepthGreater,
    279     EbvFragDepthLesser,
    280     EbvGsOutputStream,
    281     EbvOutputPatch,
    282     EbvInputPatch,
    283 
    284     // structbuffer types
    285     EbvAppendConsume, // no need to differentiate append and consume
    286     EbvRWStructuredBuffer,
    287     EbvStructuredBuffer,
    288     EbvByteAddressBuffer,
    289     EbvRWByteAddressBuffer,
    290 
    291     EbvLast
    292 };
    293 
    294 // These will show up in error messages
    295 __inline const char* GetStorageQualifierString(TStorageQualifier q)
    296 {
    297     switch (q) {
    298     case EvqTemporary:      return "temp";           break;
    299     case EvqGlobal:         return "global";         break;
    300     case EvqConst:          return "const";          break;
    301     case EvqConstReadOnly:  return "const (read only)"; break;
    302     case EvqVaryingIn:      return "in";             break;
    303     case EvqVaryingOut:     return "out";            break;
    304     case EvqUniform:        return "uniform";        break;
    305     case EvqBuffer:         return "buffer";         break;
    306     case EvqShared:         return "shared";         break;
    307     case EvqIn:             return "in";             break;
    308     case EvqOut:            return "out";            break;
    309     case EvqInOut:          return "inout";          break;
    310     case EvqVertexId:       return "gl_VertexId";    break;
    311     case EvqInstanceId:     return "gl_InstanceId";  break;
    312     case EvqPosition:       return "gl_Position";    break;
    313     case EvqPointSize:      return "gl_PointSize";   break;
    314     case EvqClipVertex:     return "gl_ClipVertex";  break;
    315     case EvqFace:           return "gl_FrontFacing"; break;
    316     case EvqFragCoord:      return "gl_FragCoord";   break;
    317     case EvqPointCoord:     return "gl_PointCoord";  break;
    318     case EvqFragColor:      return "fragColor";      break;
    319     case EvqFragDepth:      return "gl_FragDepth";   break;
    320 #ifdef NV_EXTENSIONS
    321     case EvqPayloadNV:        return "rayPayloadNV";     break;
    322     case EvqPayloadInNV:      return "rayPayloadInNV";   break;
    323     case EvqHitAttrNV:        return "hitAttributeNV";   break;
    324     case EvqCallableDataNV:   return "callableDataNV";   break;
    325     case EvqCallableDataInNV: return "callableDataInNV"; break;
    326 #endif
    327     default:                return "unknown qualifier";
    328     }
    329 }
    330 
    331 __inline const char* GetBuiltInVariableString(TBuiltInVariable v)
    332 {
    333     switch (v) {
    334     case EbvNone:                 return "";
    335     case EbvNumWorkGroups:        return "NumWorkGroups";
    336     case EbvWorkGroupSize:        return "WorkGroupSize";
    337     case EbvWorkGroupId:          return "WorkGroupID";
    338     case EbvLocalInvocationId:    return "LocalInvocationID";
    339     case EbvGlobalInvocationId:   return "GlobalInvocationID";
    340     case EbvLocalInvocationIndex: return "LocalInvocationIndex";
    341     case EbvSubGroupSize:         return "SubGroupSize";
    342     case EbvSubGroupInvocation:   return "SubGroupInvocation";
    343     case EbvSubGroupEqMask:       return "SubGroupEqMask";
    344     case EbvSubGroupGeMask:       return "SubGroupGeMask";
    345     case EbvSubGroupGtMask:       return "SubGroupGtMask";
    346     case EbvSubGroupLeMask:       return "SubGroupLeMask";
    347     case EbvSubGroupLtMask:       return "SubGroupLtMask";
    348     case EbvVertexId:             return "VertexId";
    349     case EbvInstanceId:           return "InstanceId";
    350     case EbvVertexIndex:          return "VertexIndex";
    351     case EbvInstanceIndex:        return "InstanceIndex";
    352     case EbvBaseVertex:           return "BaseVertex";
    353     case EbvBaseInstance:         return "BaseInstance";
    354     case EbvDrawId:               return "DrawId";
    355     case EbvPosition:             return "Position";
    356     case EbvPointSize:            return "PointSize";
    357     case EbvClipVertex:           return "ClipVertex";
    358     case EbvClipDistance:         return "ClipDistance";
    359     case EbvCullDistance:         return "CullDistance";
    360     case EbvNormal:               return "Normal";
    361     case EbvVertex:               return "Vertex";
    362     case EbvMultiTexCoord0:       return "MultiTexCoord0";
    363     case EbvMultiTexCoord1:       return "MultiTexCoord1";
    364     case EbvMultiTexCoord2:       return "MultiTexCoord2";
    365     case EbvMultiTexCoord3:       return "MultiTexCoord3";
    366     case EbvMultiTexCoord4:       return "MultiTexCoord4";
    367     case EbvMultiTexCoord5:       return "MultiTexCoord5";
    368     case EbvMultiTexCoord6:       return "MultiTexCoord6";
    369     case EbvMultiTexCoord7:       return "MultiTexCoord7";
    370     case EbvFrontColor:           return "FrontColor";
    371     case EbvBackColor:            return "BackColor";
    372     case EbvFrontSecondaryColor:  return "FrontSecondaryColor";
    373     case EbvBackSecondaryColor:   return "BackSecondaryColor";
    374     case EbvTexCoord:             return "TexCoord";
    375     case EbvFogFragCoord:         return "FogFragCoord";
    376     case EbvInvocationId:         return "InvocationID";
    377     case EbvPrimitiveId:          return "PrimitiveID";
    378     case EbvLayer:                return "Layer";
    379     case EbvViewportIndex:        return "ViewportIndex";
    380     case EbvPatchVertices:        return "PatchVertices";
    381     case EbvTessLevelOuter:       return "TessLevelOuter";
    382     case EbvTessLevelInner:       return "TessLevelInner";
    383     case EbvBoundingBox:          return "BoundingBox";
    384     case EbvTessCoord:            return "TessCoord";
    385     case EbvColor:                return "Color";
    386     case EbvSecondaryColor:       return "SecondaryColor";
    387     case EbvFace:                 return "Face";
    388     case EbvFragCoord:            return "FragCoord";
    389     case EbvPointCoord:           return "PointCoord";
    390     case EbvFragColor:            return "FragColor";
    391     case EbvFragData:             return "FragData";
    392     case EbvFragDepth:            return "FragDepth";
    393     case EbvFragStencilRef:       return "FragStencilRef";
    394     case EbvSampleId:             return "SampleId";
    395     case EbvSamplePosition:       return "SamplePosition";
    396     case EbvSampleMask:           return "SampleMaskIn";
    397     case EbvHelperInvocation:     return "HelperInvocation";
    398 
    399 #ifdef AMD_EXTENSIONS
    400     case EbvBaryCoordNoPersp:           return "BaryCoordNoPersp";
    401     case EbvBaryCoordNoPerspCentroid:   return "BaryCoordNoPerspCentroid";
    402     case EbvBaryCoordNoPerspSample:     return "BaryCoordNoPerspSample";
    403     case EbvBaryCoordSmooth:            return "BaryCoordSmooth";
    404     case EbvBaryCoordSmoothCentroid:    return "BaryCoordSmoothCentroid";
    405     case EbvBaryCoordSmoothSample:      return "BaryCoordSmoothSample";
    406     case EbvBaryCoordPullModel:         return "BaryCoordPullModel";
    407 #endif
    408 
    409     case EbvViewIndex:                  return "ViewIndex";
    410     case EbvDeviceIndex:                return "DeviceIndex";
    411 
    412     case EbvFragSizeEXT:                return "FragSizeEXT";
    413     case EbvFragInvocationCountEXT:     return "FragInvocationCountEXT";
    414 
    415 #ifdef NV_EXTENSIONS
    416     case EbvViewportMaskNV:             return "ViewportMaskNV";
    417     case EbvSecondaryPositionNV:        return "SecondaryPositionNV";
    418     case EbvSecondaryViewportMaskNV:    return "SecondaryViewportMaskNV";
    419     case EbvPositionPerViewNV:          return "PositionPerViewNV";
    420     case EbvViewportMaskPerViewNV:      return "ViewportMaskPerViewNV";
    421     case EbvFragFullyCoveredNV:         return "FragFullyCoveredNV";
    422     case EbvFragmentSizeNV:             return "FragmentSizeNV";
    423     case EbvInvocationsPerPixelNV:      return "InvocationsPerPixelNV";
    424     case EbvLaunchIdNV:                 return "LaunchIdNV";
    425     case EbvLaunchSizeNV:               return "LaunchSizeNV";
    426     case EbvInstanceCustomIndexNV:      return "InstanceCustomIndexNV";
    427     case EbvWorldRayOriginNV:           return "WorldRayOriginNV";
    428     case EbvWorldRayDirectionNV:        return "WorldRayDirectionNV";
    429     case EbvObjectRayOriginNV:          return "ObjectRayOriginNV";
    430     case EbvObjectRayDirectionNV:       return "ObjectRayDirectionNV";
    431     case EbvRayTminNV:                  return "ObjectRayTminNV";
    432     case EbvRayTmaxNV:                  return "ObjectRayTmaxNV";
    433     case EbvHitTNV:                     return "HitTNV";
    434     case EbvHitKindNV:                  return "HitKindNV";
    435     case EbvIncomingRayFlagsNV:         return "IncomingRayFlagsNV";
    436     case EbvObjectToWorldNV:            return "ObjectToWorldNV";
    437     case EbvWorldToObjectNV:            return "WorldToObjectNV";
    438 
    439     case EbvBaryCoordNV:                return "BaryCoordNV";
    440     case EbvBaryCoordNoPerspNV:         return "BaryCoordNoPerspNV";
    441     case EbvTaskCountNV:                return "TaskCountNV";
    442     case EbvPrimitiveCountNV:           return "PrimitiveCountNV";
    443     case EbvPrimitiveIndicesNV:         return "PrimitiveIndicesNV";
    444     case EbvClipDistancePerViewNV:      return "ClipDistancePerViewNV";
    445     case EbvCullDistancePerViewNV:      return "CullDistancePerViewNV";
    446     case EbvLayerPerViewNV:             return "LayerPerViewNV";
    447     case EbvMeshViewCountNV:            return "MeshViewCountNV";
    448     case EbvMeshViewIndicesNV:          return "MeshViewIndicesNV";
    449 #endif
    450     default:                      return "unknown built-in variable";
    451     }
    452 }
    453 
    454 // In this enum, order matters; users can assume higher precision is a bigger value
    455 // and EpqNone is 0.
    456 enum TPrecisionQualifier {
    457     EpqNone = 0,
    458     EpqLow,
    459     EpqMedium,
    460     EpqHigh
    461 };
    462 
    463 __inline const char* GetPrecisionQualifierString(TPrecisionQualifier p)
    464 {
    465     switch (p) {
    466     case EpqNone:   return "";        break;
    467     case EpqLow:    return "lowp";    break;
    468     case EpqMedium: return "mediump"; break;
    469     case EpqHigh:   return "highp";   break;
    470     default:        return "unknown precision qualifier";
    471     }
    472 }
    473 
    474 __inline bool isTypeSignedInt(TBasicType type)
    475 {
    476     switch (type) {
    477     case EbtInt8:
    478     case EbtInt16:
    479     case EbtInt:
    480     case EbtInt64:
    481         return true;
    482     default:
    483         return false;
    484     }
    485 }
    486 
    487 __inline bool isTypeUnsignedInt(TBasicType type)
    488 {
    489     switch (type) {
    490     case EbtUint8:
    491     case EbtUint16:
    492     case EbtUint:
    493     case EbtUint64:
    494         return true;
    495     default:
    496         return false;
    497     }
    498 }
    499 
    500 __inline bool isTypeInt(TBasicType type)
    501 {
    502     return isTypeSignedInt(type) || isTypeUnsignedInt(type);
    503 }
    504 
    505 __inline bool isTypeFloat(TBasicType type)
    506 {
    507     switch (type) {
    508     case EbtFloat:
    509     case EbtDouble:
    510     case EbtFloat16:
    511         return true;
    512     default:
    513         return false;
    514     }
    515 }
    516 
    517 __inline int getTypeRank(TBasicType type) {
    518     int res = -1;
    519     switch(type) {
    520     case EbtInt8:
    521     case EbtUint8:
    522         res = 0;
    523         break;
    524     case EbtInt16:
    525     case EbtUint16:
    526         res = 1;
    527         break;
    528     case EbtInt:
    529     case EbtUint:
    530         res = 2;
    531         break;
    532     case EbtInt64:
    533     case EbtUint64:
    534         res = 3;
    535         break;
    536     default:
    537         assert(false);
    538         break;
    539     }
    540     return res;
    541 }
    542 
    543 } // end namespace glslang
    544 
    545 #endif // _BASICTYPES_INCLUDED_
    546