123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887 |
- //
- // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
- // Copyright (C) 2012-2016 LunarG, Inc.
- // Copyright (C) 2017 ARM Limited.
- // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
- //
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions
- // are met:
- //
- // Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following
- // disclaimer in the documentation and/or other materials provided
- // with the distribution.
- //
- // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
- // contributors may be used to endorse or promote products derived
- // from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- // POSSIBILITY OF SUCH DAMAGE.
- //
- //
- // Definition of the in-memory high-level intermediate representation
- // of shaders. This is a tree that parser creates.
- //
- // Nodes in the tree are defined as a hierarchy of classes derived from
- // TIntermNode. Each is a node in a tree. There is no preset branching factor;
- // each node can have it's own type of list of children.
- //
- #ifndef __INTERMEDIATE_H
- #define __INTERMEDIATE_H
- #include "Common.h"
- #include "Types.h"
- #include "ConstantUnion.h"
- namespace glslang {
- class TIntermediate;
- //
- // Operators used by the high-level (parse tree) representation.
- //
- enum TOperator {
- EOpNull, // if in a node, should only mean a node is still being built
- EOpSequence, // denotes a list of statements, or parameters, etc.
- EOpScope, // Used by debugging to denote a scoped list of statements
- EOpLinkerObjects, // for aggregate node of objects the linker may need, if not reference by the rest of the AST
- EOpFunctionCall,
- EOpFunction, // For function definition
- EOpParameters, // an aggregate listing the parameters to a function
- EOpSpirvInst,
- //
- // Unary operators
- //
- EOpNegative,
- EOpLogicalNot,
- EOpVectorLogicalNot,
- EOpBitwiseNot,
- EOpPostIncrement,
- EOpPostDecrement,
- EOpPreIncrement,
- EOpPreDecrement,
- EOpCopyObject,
- EOpDeclare, // Used by debugging to force declaration of variable in correct scope
- // (u)int* -> bool
- EOpConvInt8ToBool,
- EOpConvUint8ToBool,
- EOpConvInt16ToBool,
- EOpConvUint16ToBool,
- EOpConvIntToBool,
- EOpConvUintToBool,
- EOpConvInt64ToBool,
- EOpConvUint64ToBool,
- // float* -> bool
- EOpConvFloat16ToBool,
- EOpConvFloatToBool,
- EOpConvDoubleToBool,
- // bool -> (u)int*
- EOpConvBoolToInt8,
- EOpConvBoolToUint8,
- EOpConvBoolToInt16,
- EOpConvBoolToUint16,
- EOpConvBoolToInt,
- EOpConvBoolToUint,
- EOpConvBoolToInt64,
- EOpConvBoolToUint64,
- // bool -> float*
- EOpConvBoolToFloat16,
- EOpConvBoolToFloat,
- EOpConvBoolToDouble,
- // int8_t -> (u)int*
- EOpConvInt8ToInt16,
- EOpConvInt8ToInt,
- EOpConvInt8ToInt64,
- EOpConvInt8ToUint8,
- EOpConvInt8ToUint16,
- EOpConvInt8ToUint,
- EOpConvInt8ToUint64,
- // uint8_t -> (u)int*
- EOpConvUint8ToInt8,
- EOpConvUint8ToInt16,
- EOpConvUint8ToInt,
- EOpConvUint8ToInt64,
- EOpConvUint8ToUint16,
- EOpConvUint8ToUint,
- EOpConvUint8ToUint64,
- // int8_t -> float*
- EOpConvInt8ToFloat16,
- EOpConvInt8ToFloat,
- EOpConvInt8ToDouble,
- // uint8_t -> float*
- EOpConvUint8ToFloat16,
- EOpConvUint8ToFloat,
- EOpConvUint8ToDouble,
- // int16_t -> (u)int*
- EOpConvInt16ToInt8,
- EOpConvInt16ToInt,
- EOpConvInt16ToInt64,
- EOpConvInt16ToUint8,
- EOpConvInt16ToUint16,
- EOpConvInt16ToUint,
- EOpConvInt16ToUint64,
- // uint16_t -> (u)int*
- EOpConvUint16ToInt8,
- EOpConvUint16ToInt16,
- EOpConvUint16ToInt,
- EOpConvUint16ToInt64,
- EOpConvUint16ToUint8,
- EOpConvUint16ToUint,
- EOpConvUint16ToUint64,
- // int16_t -> float*
- EOpConvInt16ToFloat16,
- EOpConvInt16ToFloat,
- EOpConvInt16ToDouble,
- // uint16_t -> float*
- EOpConvUint16ToFloat16,
- EOpConvUint16ToFloat,
- EOpConvUint16ToDouble,
- // int32_t -> (u)int*
- EOpConvIntToInt8,
- EOpConvIntToInt16,
- EOpConvIntToInt64,
- EOpConvIntToUint8,
- EOpConvIntToUint16,
- EOpConvIntToUint,
- EOpConvIntToUint64,
- // uint32_t -> (u)int*
- EOpConvUintToInt8,
- EOpConvUintToInt16,
- EOpConvUintToInt,
- EOpConvUintToInt64,
- EOpConvUintToUint8,
- EOpConvUintToUint16,
- EOpConvUintToUint64,
- // int32_t -> float*
- EOpConvIntToFloat16,
- EOpConvIntToFloat,
- EOpConvIntToDouble,
- // uint32_t -> float*
- EOpConvUintToFloat16,
- EOpConvUintToFloat,
- EOpConvUintToDouble,
- // int64_t -> (u)int*
- EOpConvInt64ToInt8,
- EOpConvInt64ToInt16,
- EOpConvInt64ToInt,
- EOpConvInt64ToUint8,
- EOpConvInt64ToUint16,
- EOpConvInt64ToUint,
- EOpConvInt64ToUint64,
- // uint64_t -> (u)int*
- EOpConvUint64ToInt8,
- EOpConvUint64ToInt16,
- EOpConvUint64ToInt,
- EOpConvUint64ToInt64,
- EOpConvUint64ToUint8,
- EOpConvUint64ToUint16,
- EOpConvUint64ToUint,
- // int64_t -> float*
- EOpConvInt64ToFloat16,
- EOpConvInt64ToFloat,
- EOpConvInt64ToDouble,
- // uint64_t -> float*
- EOpConvUint64ToFloat16,
- EOpConvUint64ToFloat,
- EOpConvUint64ToDouble,
- // float16_t -> (u)int*
- EOpConvFloat16ToInt8,
- EOpConvFloat16ToInt16,
- EOpConvFloat16ToInt,
- EOpConvFloat16ToInt64,
- EOpConvFloat16ToUint8,
- EOpConvFloat16ToUint16,
- EOpConvFloat16ToUint,
- EOpConvFloat16ToUint64,
- // float16_t -> float*
- EOpConvFloat16ToFloat,
- EOpConvFloat16ToDouble,
- // float -> (u)int*
- EOpConvFloatToInt8,
- EOpConvFloatToInt16,
- EOpConvFloatToInt,
- EOpConvFloatToInt64,
- EOpConvFloatToUint8,
- EOpConvFloatToUint16,
- EOpConvFloatToUint,
- EOpConvFloatToUint64,
- // float -> float*
- EOpConvFloatToFloat16,
- EOpConvFloatToDouble,
- // float64 _t-> (u)int*
- EOpConvDoubleToInt8,
- EOpConvDoubleToInt16,
- EOpConvDoubleToInt,
- EOpConvDoubleToInt64,
- EOpConvDoubleToUint8,
- EOpConvDoubleToUint16,
- EOpConvDoubleToUint,
- EOpConvDoubleToUint64,
- // float64_t -> float*
- EOpConvDoubleToFloat16,
- EOpConvDoubleToFloat,
- // uint64_t <-> pointer
- EOpConvUint64ToPtr,
- EOpConvPtrToUint64,
- // uvec2 <-> pointer
- EOpConvUvec2ToPtr,
- EOpConvPtrToUvec2,
- // uint64_t -> accelerationStructureEXT
- EOpConvUint64ToAccStruct,
- // uvec2 -> accelerationStructureEXT
- EOpConvUvec2ToAccStruct,
- //
- // binary operations
- //
- EOpAdd,
- EOpSub,
- EOpMul,
- EOpDiv,
- EOpMod,
- EOpRightShift,
- EOpLeftShift,
- EOpAnd,
- EOpInclusiveOr,
- EOpExclusiveOr,
- EOpEqual,
- EOpNotEqual,
- EOpVectorEqual,
- EOpVectorNotEqual,
- EOpLessThan,
- EOpGreaterThan,
- EOpLessThanEqual,
- EOpGreaterThanEqual,
- EOpComma,
- EOpVectorTimesScalar,
- EOpVectorTimesMatrix,
- EOpMatrixTimesVector,
- EOpMatrixTimesScalar,
- EOpLogicalOr,
- EOpLogicalXor,
- EOpLogicalAnd,
- EOpIndexDirect,
- EOpIndexIndirect,
- EOpIndexDirectStruct,
- EOpVectorSwizzle,
- EOpMethod,
- EOpScoping,
- //
- // Built-in functions mapped to operators
- //
- EOpRadians,
- EOpDegrees,
- EOpSin,
- EOpCos,
- EOpTan,
- EOpAsin,
- EOpAcos,
- EOpAtan,
- EOpSinh,
- EOpCosh,
- EOpTanh,
- EOpAsinh,
- EOpAcosh,
- EOpAtanh,
- EOpPow,
- EOpExp,
- EOpLog,
- EOpExp2,
- EOpLog2,
- EOpSqrt,
- EOpInverseSqrt,
- EOpAbs,
- EOpSign,
- EOpFloor,
- EOpTrunc,
- EOpRound,
- EOpRoundEven,
- EOpCeil,
- EOpFract,
- EOpModf,
- EOpMin,
- EOpMax,
- EOpClamp,
- EOpMix,
- EOpStep,
- EOpSmoothStep,
- EOpIsNan,
- EOpIsInf,
- EOpFma,
- EOpFrexp,
- EOpLdexp,
- EOpFloatBitsToInt,
- EOpFloatBitsToUint,
- EOpIntBitsToFloat,
- EOpUintBitsToFloat,
- EOpDoubleBitsToInt64,
- EOpDoubleBitsToUint64,
- EOpInt64BitsToDouble,
- EOpUint64BitsToDouble,
- EOpFloat16BitsToInt16,
- EOpFloat16BitsToUint16,
- EOpInt16BitsToFloat16,
- EOpUint16BitsToFloat16,
- EOpPackSnorm2x16,
- EOpUnpackSnorm2x16,
- EOpPackUnorm2x16,
- EOpUnpackUnorm2x16,
- EOpPackSnorm4x8,
- EOpUnpackSnorm4x8,
- EOpPackUnorm4x8,
- EOpUnpackUnorm4x8,
- EOpPackHalf2x16,
- EOpUnpackHalf2x16,
- EOpPackDouble2x32,
- EOpUnpackDouble2x32,
- EOpPackInt2x32,
- EOpUnpackInt2x32,
- EOpPackUint2x32,
- EOpUnpackUint2x32,
- EOpPackFloat2x16,
- EOpUnpackFloat2x16,
- EOpPackInt2x16,
- EOpUnpackInt2x16,
- EOpPackUint2x16,
- EOpUnpackUint2x16,
- EOpPackInt4x16,
- EOpUnpackInt4x16,
- EOpPackUint4x16,
- EOpUnpackUint4x16,
- EOpPack16,
- EOpPack32,
- EOpPack64,
- EOpUnpack32,
- EOpUnpack16,
- EOpUnpack8,
- EOpLength,
- EOpDistance,
- EOpDot,
- EOpCross,
- EOpNormalize,
- EOpFaceForward,
- EOpReflect,
- EOpRefract,
- EOpMin3,
- EOpMax3,
- EOpMid3,
- EOpDPdx, // Fragment only
- EOpDPdy, // Fragment only
- EOpFwidth, // Fragment only
- EOpDPdxFine, // Fragment only
- EOpDPdyFine, // Fragment only
- EOpFwidthFine, // Fragment only
- EOpDPdxCoarse, // Fragment only
- EOpDPdyCoarse, // Fragment only
- EOpFwidthCoarse, // Fragment only
- EOpInterpolateAtCentroid, // Fragment only
- EOpInterpolateAtSample, // Fragment only
- EOpInterpolateAtOffset, // Fragment only
- EOpInterpolateAtVertex,
- EOpMatrixTimesMatrix,
- EOpOuterProduct,
- EOpDeterminant,
- EOpMatrixInverse,
- EOpTranspose,
- EOpFtransform,
- EOpNoise,
- EOpEmitVertex, // geometry only
- EOpEndPrimitive, // geometry only
- EOpEmitStreamVertex, // geometry only
- EOpEndStreamPrimitive, // geometry only
- EOpBarrier,
- EOpMemoryBarrier,
- EOpMemoryBarrierAtomicCounter,
- EOpMemoryBarrierBuffer,
- EOpMemoryBarrierImage,
- EOpMemoryBarrierShared, // compute only
- EOpGroupMemoryBarrier, // compute only
- EOpBallot,
- EOpReadInvocation,
- EOpReadFirstInvocation,
- EOpAnyInvocation,
- EOpAllInvocations,
- EOpAllInvocationsEqual,
- EOpSubgroupGuardStart,
- EOpSubgroupBarrier,
- EOpSubgroupMemoryBarrier,
- EOpSubgroupMemoryBarrierBuffer,
- EOpSubgroupMemoryBarrierImage,
- EOpSubgroupMemoryBarrierShared, // compute only
- EOpSubgroupElect,
- EOpSubgroupAll,
- EOpSubgroupAny,
- EOpSubgroupAllEqual,
- EOpSubgroupBroadcast,
- EOpSubgroupBroadcastFirst,
- EOpSubgroupBallot,
- EOpSubgroupInverseBallot,
- EOpSubgroupBallotBitExtract,
- EOpSubgroupBallotBitCount,
- EOpSubgroupBallotInclusiveBitCount,
- EOpSubgroupBallotExclusiveBitCount,
- EOpSubgroupBallotFindLSB,
- EOpSubgroupBallotFindMSB,
- EOpSubgroupShuffle,
- EOpSubgroupShuffleXor,
- EOpSubgroupShuffleUp,
- EOpSubgroupShuffleDown,
- EOpSubgroupAdd,
- EOpSubgroupMul,
- EOpSubgroupMin,
- EOpSubgroupMax,
- EOpSubgroupAnd,
- EOpSubgroupOr,
- EOpSubgroupXor,
- EOpSubgroupInclusiveAdd,
- EOpSubgroupInclusiveMul,
- EOpSubgroupInclusiveMin,
- EOpSubgroupInclusiveMax,
- EOpSubgroupInclusiveAnd,
- EOpSubgroupInclusiveOr,
- EOpSubgroupInclusiveXor,
- EOpSubgroupExclusiveAdd,
- EOpSubgroupExclusiveMul,
- EOpSubgroupExclusiveMin,
- EOpSubgroupExclusiveMax,
- EOpSubgroupExclusiveAnd,
- EOpSubgroupExclusiveOr,
- EOpSubgroupExclusiveXor,
- EOpSubgroupClusteredAdd,
- EOpSubgroupClusteredMul,
- EOpSubgroupClusteredMin,
- EOpSubgroupClusteredMax,
- EOpSubgroupClusteredAnd,
- EOpSubgroupClusteredOr,
- EOpSubgroupClusteredXor,
- EOpSubgroupQuadBroadcast,
- EOpSubgroupQuadSwapHorizontal,
- EOpSubgroupQuadSwapVertical,
- EOpSubgroupQuadSwapDiagonal,
- EOpSubgroupPartition,
- EOpSubgroupPartitionedAdd,
- EOpSubgroupPartitionedMul,
- EOpSubgroupPartitionedMin,
- EOpSubgroupPartitionedMax,
- EOpSubgroupPartitionedAnd,
- EOpSubgroupPartitionedOr,
- EOpSubgroupPartitionedXor,
- EOpSubgroupPartitionedInclusiveAdd,
- EOpSubgroupPartitionedInclusiveMul,
- EOpSubgroupPartitionedInclusiveMin,
- EOpSubgroupPartitionedInclusiveMax,
- EOpSubgroupPartitionedInclusiveAnd,
- EOpSubgroupPartitionedInclusiveOr,
- EOpSubgroupPartitionedInclusiveXor,
- EOpSubgroupPartitionedExclusiveAdd,
- EOpSubgroupPartitionedExclusiveMul,
- EOpSubgroupPartitionedExclusiveMin,
- EOpSubgroupPartitionedExclusiveMax,
- EOpSubgroupPartitionedExclusiveAnd,
- EOpSubgroupPartitionedExclusiveOr,
- EOpSubgroupPartitionedExclusiveXor,
- EOpSubgroupGuardStop,
- EOpMinInvocations,
- EOpMaxInvocations,
- EOpAddInvocations,
- EOpMinInvocationsNonUniform,
- EOpMaxInvocationsNonUniform,
- EOpAddInvocationsNonUniform,
- EOpMinInvocationsInclusiveScan,
- EOpMaxInvocationsInclusiveScan,
- EOpAddInvocationsInclusiveScan,
- EOpMinInvocationsInclusiveScanNonUniform,
- EOpMaxInvocationsInclusiveScanNonUniform,
- EOpAddInvocationsInclusiveScanNonUniform,
- EOpMinInvocationsExclusiveScan,
- EOpMaxInvocationsExclusiveScan,
- EOpAddInvocationsExclusiveScan,
- EOpMinInvocationsExclusiveScanNonUniform,
- EOpMaxInvocationsExclusiveScanNonUniform,
- EOpAddInvocationsExclusiveScanNonUniform,
- EOpSwizzleInvocations,
- EOpSwizzleInvocationsMasked,
- EOpWriteInvocation,
- EOpMbcnt,
- EOpCubeFaceIndex,
- EOpCubeFaceCoord,
- EOpTime,
- EOpAtomicAdd,
- EOpAtomicSubtract,
- EOpAtomicMin,
- EOpAtomicMax,
- EOpAtomicAnd,
- EOpAtomicOr,
- EOpAtomicXor,
- EOpAtomicExchange,
- EOpAtomicCompSwap,
- EOpAtomicLoad,
- EOpAtomicStore,
- EOpAtomicCounterIncrement, // results in pre-increment value
- EOpAtomicCounterDecrement, // results in post-decrement value
- EOpAtomicCounter,
- EOpAtomicCounterAdd,
- EOpAtomicCounterSubtract,
- EOpAtomicCounterMin,
- EOpAtomicCounterMax,
- EOpAtomicCounterAnd,
- EOpAtomicCounterOr,
- EOpAtomicCounterXor,
- EOpAtomicCounterExchange,
- EOpAtomicCounterCompSwap,
- EOpAny,
- EOpAll,
- EOpCooperativeMatrixLoad,
- EOpCooperativeMatrixStore,
- EOpCooperativeMatrixMulAdd,
- EOpCooperativeMatrixLoadNV,
- EOpCooperativeMatrixStoreNV,
- EOpCooperativeMatrixMulAddNV,
- EOpBeginInvocationInterlock, // Fragment only
- EOpEndInvocationInterlock, // Fragment only
- EOpIsHelperInvocation,
- EOpDebugPrintf,
- //
- // Branch
- //
- EOpKill, // Fragment only
- EOpTerminateInvocation, // Fragment only
- EOpDemote, // Fragment only
- EOpTerminateRayKHR, // Any-hit only
- EOpIgnoreIntersectionKHR, // Any-hit only
- EOpReturn,
- EOpBreak,
- EOpContinue,
- EOpCase,
- EOpDefault,
- //
- // Constructors
- //
- EOpConstructGuardStart,
- EOpConstructInt, // these first scalar forms also identify what implicit conversion is needed
- EOpConstructUint,
- EOpConstructInt8,
- EOpConstructUint8,
- EOpConstructInt16,
- EOpConstructUint16,
- EOpConstructInt64,
- EOpConstructUint64,
- EOpConstructBool,
- EOpConstructFloat,
- EOpConstructDouble,
- // Keep vector and matrix constructors in a consistent relative order for
- // TParseContext::constructBuiltIn, which converts between 8/16/32 bit
- // vector constructors
- EOpConstructVec2,
- EOpConstructVec3,
- EOpConstructVec4,
- EOpConstructMat2x2,
- EOpConstructMat2x3,
- EOpConstructMat2x4,
- EOpConstructMat3x2,
- EOpConstructMat3x3,
- EOpConstructMat3x4,
- EOpConstructMat4x2,
- EOpConstructMat4x3,
- EOpConstructMat4x4,
- EOpConstructDVec2,
- EOpConstructDVec3,
- EOpConstructDVec4,
- EOpConstructBVec2,
- EOpConstructBVec3,
- EOpConstructBVec4,
- EOpConstructI8Vec2,
- EOpConstructI8Vec3,
- EOpConstructI8Vec4,
- EOpConstructU8Vec2,
- EOpConstructU8Vec3,
- EOpConstructU8Vec4,
- EOpConstructI16Vec2,
- EOpConstructI16Vec3,
- EOpConstructI16Vec4,
- EOpConstructU16Vec2,
- EOpConstructU16Vec3,
- EOpConstructU16Vec4,
- EOpConstructIVec2,
- EOpConstructIVec3,
- EOpConstructIVec4,
- EOpConstructUVec2,
- EOpConstructUVec3,
- EOpConstructUVec4,
- EOpConstructI64Vec2,
- EOpConstructI64Vec3,
- EOpConstructI64Vec4,
- EOpConstructU64Vec2,
- EOpConstructU64Vec3,
- EOpConstructU64Vec4,
- EOpConstructDMat2x2,
- EOpConstructDMat2x3,
- EOpConstructDMat2x4,
- EOpConstructDMat3x2,
- EOpConstructDMat3x3,
- EOpConstructDMat3x4,
- EOpConstructDMat4x2,
- EOpConstructDMat4x3,
- EOpConstructDMat4x4,
- EOpConstructIMat2x2,
- EOpConstructIMat2x3,
- EOpConstructIMat2x4,
- EOpConstructIMat3x2,
- EOpConstructIMat3x3,
- EOpConstructIMat3x4,
- EOpConstructIMat4x2,
- EOpConstructIMat4x3,
- EOpConstructIMat4x4,
- EOpConstructUMat2x2,
- EOpConstructUMat2x3,
- EOpConstructUMat2x4,
- EOpConstructUMat3x2,
- EOpConstructUMat3x3,
- EOpConstructUMat3x4,
- EOpConstructUMat4x2,
- EOpConstructUMat4x3,
- EOpConstructUMat4x4,
- EOpConstructBMat2x2,
- EOpConstructBMat2x3,
- EOpConstructBMat2x4,
- EOpConstructBMat3x2,
- EOpConstructBMat3x3,
- EOpConstructBMat3x4,
- EOpConstructBMat4x2,
- EOpConstructBMat4x3,
- EOpConstructBMat4x4,
- EOpConstructFloat16,
- EOpConstructF16Vec2,
- EOpConstructF16Vec3,
- EOpConstructF16Vec4,
- EOpConstructF16Mat2x2,
- EOpConstructF16Mat2x3,
- EOpConstructF16Mat2x4,
- EOpConstructF16Mat3x2,
- EOpConstructF16Mat3x3,
- EOpConstructF16Mat3x4,
- EOpConstructF16Mat4x2,
- EOpConstructF16Mat4x3,
- EOpConstructF16Mat4x4,
- EOpConstructStruct,
- EOpConstructTextureSampler,
- EOpConstructNonuniform, // expected to be transformed away, not present in final AST
- EOpConstructReference,
- EOpConstructCooperativeMatrixNV,
- EOpConstructCooperativeMatrixKHR,
- EOpConstructAccStruct,
- EOpConstructGuardEnd,
- //
- // moves
- //
- EOpAssign,
- EOpAddAssign,
- EOpSubAssign,
- EOpMulAssign,
- EOpVectorTimesMatrixAssign,
- EOpVectorTimesScalarAssign,
- EOpMatrixTimesScalarAssign,
- EOpMatrixTimesMatrixAssign,
- EOpDivAssign,
- EOpModAssign,
- EOpAndAssign,
- EOpInclusiveOrAssign,
- EOpExclusiveOrAssign,
- EOpLeftShiftAssign,
- EOpRightShiftAssign,
- //
- // Array operators
- //
- // Can apply to arrays, vectors, or matrices.
- // Can be decomposed to a constant at compile time, but this does not always happen,
- // due to link-time effects. So, consumer can expect either a link-time sized or
- // run-time sized array.
- EOpArrayLength,
- //
- // Image operations
- //
- EOpImageGuardBegin,
- EOpImageQuerySize,
- EOpImageQuerySamples,
- EOpImageLoad,
- EOpImageStore,
- EOpImageLoadLod,
- EOpImageStoreLod,
- EOpImageAtomicAdd,
- EOpImageAtomicMin,
- EOpImageAtomicMax,
- EOpImageAtomicAnd,
- EOpImageAtomicOr,
- EOpImageAtomicXor,
- EOpImageAtomicExchange,
- EOpImageAtomicCompSwap,
- EOpImageAtomicLoad,
- EOpImageAtomicStore,
- EOpSubpassLoad,
- EOpSubpassLoadMS,
- EOpSparseImageLoad,
- EOpSparseImageLoadLod,
- EOpColorAttachmentReadEXT, // Fragment only
- EOpImageGuardEnd,
- //
- // Texture operations
- //
- EOpTextureGuardBegin,
- EOpTextureQuerySize,
- EOpTextureQueryLod,
- EOpTextureQueryLevels,
- EOpTextureQuerySamples,
- EOpSamplingGuardBegin,
- EOpTexture,
- EOpTextureProj,
- EOpTextureLod,
- EOpTextureOffset,
- EOpTextureFetch,
- EOpTextureFetchOffset,
- EOpTextureProjOffset,
- EOpTextureLodOffset,
- EOpTextureProjLod,
- EOpTextureProjLodOffset,
- EOpTextureGrad,
- EOpTextureGradOffset,
- EOpTextureProjGrad,
- EOpTextureProjGradOffset,
- EOpTextureGather,
- EOpTextureGatherOffset,
- EOpTextureGatherOffsets,
- EOpTextureClamp,
- EOpTextureOffsetClamp,
- EOpTextureGradClamp,
- EOpTextureGradOffsetClamp,
- EOpTextureGatherLod,
- EOpTextureGatherLodOffset,
- EOpTextureGatherLodOffsets,
- EOpFragmentMaskFetch,
- EOpFragmentFetch,
- EOpSparseTextureGuardBegin,
- EOpSparseTexture,
- EOpSparseTextureLod,
- EOpSparseTextureOffset,
- EOpSparseTextureFetch,
- EOpSparseTextureFetchOffset,
- EOpSparseTextureLodOffset,
- EOpSparseTextureGrad,
- EOpSparseTextureGradOffset,
- EOpSparseTextureGather,
- EOpSparseTextureGatherOffset,
- EOpSparseTextureGatherOffsets,
- EOpSparseTexelsResident,
- EOpSparseTextureClamp,
- EOpSparseTextureOffsetClamp,
- EOpSparseTextureGradClamp,
- EOpSparseTextureGradOffsetClamp,
- EOpSparseTextureGatherLod,
- EOpSparseTextureGatherLodOffset,
- EOpSparseTextureGatherLodOffsets,
- EOpSparseTextureGuardEnd,
- EOpImageFootprintGuardBegin,
- EOpImageSampleFootprintNV,
- EOpImageSampleFootprintClampNV,
- EOpImageSampleFootprintLodNV,
- EOpImageSampleFootprintGradNV,
- EOpImageSampleFootprintGradClampNV,
- EOpImageFootprintGuardEnd,
- EOpSamplingGuardEnd,
- EOpTextureGuardEnd,
- //
- // Integer operations
- //
- EOpAddCarry,
- EOpSubBorrow,
- EOpUMulExtended,
- EOpIMulExtended,
- EOpBitfieldExtract,
- EOpBitfieldInsert,
- EOpBitFieldReverse,
- EOpBitCount,
- EOpFindLSB,
- EOpFindMSB,
- EOpCountLeadingZeros,
- EOpCountTrailingZeros,
- EOpAbsDifference,
- EOpAddSaturate,
- EOpSubSaturate,
- EOpAverage,
- EOpAverageRounded,
- EOpMul32x16,
- EOpTraceNV,
- EOpTraceRayMotionNV,
- EOpTraceKHR,
- EOpReportIntersection,
- EOpIgnoreIntersectionNV,
- EOpTerminateRayNV,
- EOpExecuteCallableNV,
- EOpExecuteCallableKHR,
- EOpWritePackedPrimitiveIndices4x8NV,
- EOpEmitMeshTasksEXT,
- EOpSetMeshOutputsEXT,
- //
- // GL_EXT_ray_query operations
- //
- EOpRayQueryInitialize,
- EOpRayQueryTerminate,
- EOpRayQueryGenerateIntersection,
- EOpRayQueryConfirmIntersection,
- EOpRayQueryProceed,
- EOpRayQueryGetIntersectionType,
- EOpRayQueryGetRayTMin,
- EOpRayQueryGetRayFlags,
- EOpRayQueryGetIntersectionT,
- EOpRayQueryGetIntersectionInstanceCustomIndex,
- EOpRayQueryGetIntersectionInstanceId,
- EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset,
- EOpRayQueryGetIntersectionGeometryIndex,
- EOpRayQueryGetIntersectionPrimitiveIndex,
- EOpRayQueryGetIntersectionBarycentrics,
- EOpRayQueryGetIntersectionFrontFace,
- EOpRayQueryGetIntersectionCandidateAABBOpaque,
- EOpRayQueryGetIntersectionObjectRayDirection,
- EOpRayQueryGetIntersectionObjectRayOrigin,
- EOpRayQueryGetWorldRayDirection,
- EOpRayQueryGetWorldRayOrigin,
- EOpRayQueryGetIntersectionObjectToWorld,
- EOpRayQueryGetIntersectionWorldToObject,
- //
- // GL_NV_shader_invocation_reorder
- //
- EOpHitObjectTraceRayNV,
- EOpHitObjectTraceRayMotionNV,
- EOpHitObjectRecordHitNV,
- EOpHitObjectRecordHitMotionNV,
- EOpHitObjectRecordHitWithIndexNV,
- EOpHitObjectRecordHitWithIndexMotionNV,
- EOpHitObjectRecordMissNV,
- EOpHitObjectRecordMissMotionNV,
- EOpHitObjectRecordEmptyNV,
- EOpHitObjectExecuteShaderNV,
- EOpHitObjectIsEmptyNV,
- EOpHitObjectIsMissNV,
- EOpHitObjectIsHitNV,
- EOpHitObjectGetRayTMinNV,
- EOpHitObjectGetRayTMaxNV,
- EOpHitObjectGetObjectRayOriginNV,
- EOpHitObjectGetObjectRayDirectionNV,
- EOpHitObjectGetWorldRayOriginNV,
- EOpHitObjectGetWorldRayDirectionNV,
- EOpHitObjectGetWorldToObjectNV,
- EOpHitObjectGetObjectToWorldNV,
- EOpHitObjectGetInstanceCustomIndexNV,
- EOpHitObjectGetInstanceIdNV,
- EOpHitObjectGetGeometryIndexNV,
- EOpHitObjectGetPrimitiveIndexNV,
- EOpHitObjectGetHitKindNV,
- EOpHitObjectGetShaderBindingTableRecordIndexNV,
- EOpHitObjectGetShaderRecordBufferHandleNV,
- EOpHitObjectGetAttributesNV,
- EOpHitObjectGetCurrentTimeNV,
- EOpReorderThreadNV,
- EOpFetchMicroTriangleVertexPositionNV,
- EOpFetchMicroTriangleVertexBarycentricNV,
- // HLSL operations
- //
- EOpClip, // discard if input value < 0
- EOpIsFinite,
- EOpLog10, // base 10 log
- EOpRcp, // 1/x
- EOpSaturate, // clamp from 0 to 1
- EOpSinCos, // sin and cos in out parameters
- EOpGenMul, // mul(x,y) on any of mat/vec/scalars
- EOpDst, // x = 1, y=src0.y * src1.y, z=src0.z, w=src1.w
- EOpInterlockedAdd, // atomic ops, but uses [optional] out arg instead of return
- EOpInterlockedAnd, // ...
- EOpInterlockedCompareExchange, // ...
- EOpInterlockedCompareStore, // ...
- EOpInterlockedExchange, // ...
- EOpInterlockedMax, // ...
- EOpInterlockedMin, // ...
- EOpInterlockedOr, // ...
- EOpInterlockedXor, // ...
- EOpAllMemoryBarrierWithGroupSync, // memory barriers without non-hlsl AST equivalents
- EOpDeviceMemoryBarrier, // ...
- EOpDeviceMemoryBarrierWithGroupSync, // ...
- EOpWorkgroupMemoryBarrier, // ...
- EOpWorkgroupMemoryBarrierWithGroupSync, // ...
- EOpEvaluateAttributeSnapped, // InterpolateAtOffset with int position on 16x16 grid
- EOpF32tof16, // HLSL conversion: half of a PackHalf2x16
- EOpF16tof32, // HLSL conversion: half of an UnpackHalf2x16
- EOpLit, // HLSL lighting coefficient vector
- EOpTextureBias, // HLSL texture bias: will be lowered to EOpTexture
- EOpAsDouble, // slightly different from EOpUint64BitsToDouble
- EOpD3DCOLORtoUBYTE4, // convert and swizzle 4-component color to UBYTE4 range
- EOpMethodSample, // Texture object methods. These are translated to existing
- EOpMethodSampleBias, // AST methods, and exist to represent HLSL semantics until that
- EOpMethodSampleCmp, // translation is performed. See HlslParseContext::decomposeSampleMethods().
- EOpMethodSampleCmpLevelZero, // ...
- EOpMethodSampleGrad, // ...
- EOpMethodSampleLevel, // ...
- EOpMethodLoad, // ...
- EOpMethodGetDimensions, // ...
- EOpMethodGetSamplePosition, // ...
- EOpMethodGather, // ...
- EOpMethodCalculateLevelOfDetail, // ...
- EOpMethodCalculateLevelOfDetailUnclamped, // ...
- // Load already defined above for textures
- EOpMethodLoad2, // Structure buffer object methods. These are translated to existing
- EOpMethodLoad3, // AST methods, and exist to represent HLSL semantics until that
- EOpMethodLoad4, // translation is performed. See HlslParseContext::decomposeSampleMethods().
- EOpMethodStore, // ...
- EOpMethodStore2, // ...
- EOpMethodStore3, // ...
- EOpMethodStore4, // ...
- EOpMethodIncrementCounter, // ...
- EOpMethodDecrementCounter, // ...
- // EOpMethodAppend is defined for geo shaders below
- EOpMethodConsume,
- // SM5 texture methods
- EOpMethodGatherRed, // These are covered under the above EOpMethodSample comment about
- EOpMethodGatherGreen, // translation to existing AST opcodes. They exist temporarily
- EOpMethodGatherBlue, // because HLSL arguments are slightly different.
- EOpMethodGatherAlpha, // ...
- EOpMethodGatherCmp, // ...
- EOpMethodGatherCmpRed, // ...
- EOpMethodGatherCmpGreen, // ...
- EOpMethodGatherCmpBlue, // ...
- EOpMethodGatherCmpAlpha, // ...
- // geometry methods
- EOpMethodAppend, // Geometry shader methods
- EOpMethodRestartStrip, // ...
- // matrix
- EOpMatrixSwizzle, // select multiple matrix components (non-column)
- // SM6 wave ops
- EOpWaveGetLaneCount, // Will decompose to gl_SubgroupSize.
- EOpWaveGetLaneIndex, // Will decompose to gl_SubgroupInvocationID.
- EOpWaveActiveCountBits, // Will decompose to subgroupBallotBitCount(subgroupBallot()).
- EOpWavePrefixCountBits, // Will decompose to subgroupBallotInclusiveBitCount(subgroupBallot()).
- // Shader Clock Ops
- EOpReadClockSubgroupKHR,
- EOpReadClockDeviceKHR,
- // GL_EXT_ray_tracing_position_fetch
- EOpRayQueryGetIntersectionTriangleVertexPositionsEXT,
- // Shader tile image ops
- EOpStencilAttachmentReadEXT, // Fragment only
- EOpDepthAttachmentReadEXT, // Fragment only
- // Image processing
- EOpImageSampleWeightedQCOM,
- EOpImageBoxFilterQCOM,
- EOpImageBlockMatchSADQCOM,
- EOpImageBlockMatchSSDQCOM,
- };
- enum TLinkType {
- ELinkNone,
- ELinkExport,
- };
- class TIntermTraverser;
- class TIntermOperator;
- class TIntermAggregate;
- class TIntermUnary;
- class TIntermBinary;
- class TIntermConstantUnion;
- class TIntermSelection;
- class TIntermSwitch;
- class TIntermBranch;
- class TIntermTyped;
- class TIntermMethod;
- class TIntermSymbol;
- class TIntermLoop;
- } // end namespace glslang
- //
- // Base class for the tree nodes
- //
- // (Put outside the glslang namespace, as it's used as part of the external interface.)
- //
- class TIntermNode {
- public:
- POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
- TIntermNode() { loc.init(); }
- virtual const glslang::TSourceLoc& getLoc() const { return loc; }
- virtual void setLoc(const glslang::TSourceLoc& l) { loc = l; }
- virtual void traverse(glslang::TIntermTraverser*) = 0;
- virtual glslang::TIntermTyped* getAsTyped() { return nullptr; }
- virtual glslang::TIntermOperator* getAsOperator() { return nullptr; }
- virtual glslang::TIntermConstantUnion* getAsConstantUnion() { return nullptr; }
- virtual glslang::TIntermAggregate* getAsAggregate() { return nullptr; }
- virtual glslang::TIntermUnary* getAsUnaryNode() { return nullptr; }
- virtual glslang::TIntermBinary* getAsBinaryNode() { return nullptr; }
- virtual glslang::TIntermSelection* getAsSelectionNode() { return nullptr; }
- virtual glslang::TIntermSwitch* getAsSwitchNode() { return nullptr; }
- virtual glslang::TIntermMethod* getAsMethodNode() { return nullptr; }
- virtual glslang::TIntermSymbol* getAsSymbolNode() { return nullptr; }
- virtual glslang::TIntermBranch* getAsBranchNode() { return nullptr; }
- virtual glslang::TIntermLoop* getAsLoopNode() { return nullptr; }
- virtual const glslang::TIntermTyped* getAsTyped() const { return nullptr; }
- virtual const glslang::TIntermOperator* getAsOperator() const { return nullptr; }
- virtual const glslang::TIntermConstantUnion* getAsConstantUnion() const { return nullptr; }
- virtual const glslang::TIntermAggregate* getAsAggregate() const { return nullptr; }
- virtual const glslang::TIntermUnary* getAsUnaryNode() const { return nullptr; }
- virtual const glslang::TIntermBinary* getAsBinaryNode() const { return nullptr; }
- virtual const glslang::TIntermSelection* getAsSelectionNode() const { return nullptr; }
- virtual const glslang::TIntermSwitch* getAsSwitchNode() const { return nullptr; }
- virtual const glslang::TIntermMethod* getAsMethodNode() const { return nullptr; }
- virtual const glslang::TIntermSymbol* getAsSymbolNode() const { return nullptr; }
- virtual const glslang::TIntermBranch* getAsBranchNode() const { return nullptr; }
- virtual const glslang::TIntermLoop* getAsLoopNode() const { return nullptr; }
- virtual ~TIntermNode() { }
- protected:
- TIntermNode(const TIntermNode&);
- TIntermNode& operator=(const TIntermNode&);
- glslang::TSourceLoc loc;
- };
- namespace glslang {
- //
- // This is just to help yacc.
- //
- struct TIntermNodePair {
- TIntermNode* node1;
- TIntermNode* node2;
- };
- //
- // Intermediate class for nodes that have a type.
- //
- class TIntermTyped : public TIntermNode {
- public:
- TIntermTyped(const TType& t) { type.shallowCopy(t); }
- TIntermTyped(TBasicType basicType) { TType bt(basicType); type.shallowCopy(bt); }
- virtual TIntermTyped* getAsTyped() { return this; }
- virtual const TIntermTyped* getAsTyped() const { return this; }
- virtual void setType(const TType& t) { type.shallowCopy(t); }
- virtual const TType& getType() const { return type; }
- virtual TType& getWritableType() { return type; }
- virtual TBasicType getBasicType() const { return type.getBasicType(); }
- virtual TQualifier& getQualifier() { return type.getQualifier(); }
- virtual const TQualifier& getQualifier() const { return type.getQualifier(); }
- virtual TArraySizes* getArraySizes() { return type.getArraySizes(); }
- virtual const TArraySizes* getArraySizes() const { return type.getArraySizes(); }
- virtual void propagatePrecision(TPrecisionQualifier);
- virtual int getVectorSize() const { return type.getVectorSize(); }
- virtual int getMatrixCols() const { return type.getMatrixCols(); }
- virtual int getMatrixRows() const { return type.getMatrixRows(); }
- virtual bool isMatrix() const { return type.isMatrix(); }
- virtual bool isArray() const { return type.isArray(); }
- virtual bool isVector() const { return type.isVector(); }
- virtual bool isScalar() const { return type.isScalar(); }
- virtual bool isStruct() const { return type.isStruct(); }
- virtual bool isFloatingDomain() const { return type.isFloatingDomain(); }
- virtual bool isIntegerDomain() const { return type.isIntegerDomain(); }
- bool isAtomic() const { return type.isAtomic(); }
- bool isReference() const { return type.isReference(); }
- TString getCompleteString(bool enhanced = false) const { return type.getCompleteString(enhanced); }
- protected:
- TIntermTyped& operator=(const TIntermTyped&);
- TType type;
- };
- //
- // Handle for, do-while, and while loops.
- //
- class TIntermLoop : public TIntermNode {
- public:
- TIntermLoop(TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) :
- body(aBody),
- test(aTest),
- terminal(aTerminal),
- first(testFirst),
- unroll(false),
- dontUnroll(false),
- dependency(0),
- minIterations(0),
- maxIterations(iterationsInfinite),
- iterationMultiple(1),
- peelCount(0),
- partialCount(0)
- { }
- virtual TIntermLoop* getAsLoopNode() { return this; }
- virtual const TIntermLoop* getAsLoopNode() const { return this; }
- virtual void traverse(TIntermTraverser*);
- TIntermNode* getBody() const { return body; }
- TIntermTyped* getTest() const { return test; }
- TIntermTyped* getTerminal() const { return terminal; }
- bool testFirst() const { return first; }
- void setUnroll() { unroll = true; }
- void setDontUnroll() {
- dontUnroll = true;
- peelCount = 0;
- partialCount = 0;
- }
- bool getUnroll() const { return unroll; }
- bool getDontUnroll() const { return dontUnroll; }
- static const unsigned int dependencyInfinite = 0xFFFFFFFF;
- static const unsigned int iterationsInfinite = 0xFFFFFFFF;
- void setLoopDependency(int d) { dependency = d; }
- int getLoopDependency() const { return dependency; }
- void setMinIterations(unsigned int v) { minIterations = v; }
- unsigned int getMinIterations() const { return minIterations; }
- void setMaxIterations(unsigned int v) { maxIterations = v; }
- unsigned int getMaxIterations() const { return maxIterations; }
- void setIterationMultiple(unsigned int v) { iterationMultiple = v; }
- unsigned int getIterationMultiple() const { return iterationMultiple; }
- void setPeelCount(unsigned int v) {
- peelCount = v;
- dontUnroll = false;
- }
- unsigned int getPeelCount() const { return peelCount; }
- void setPartialCount(unsigned int v) {
- partialCount = v;
- dontUnroll = false;
- }
- unsigned int getPartialCount() const { return partialCount; }
- protected:
- TIntermNode* body; // code to loop over
- TIntermTyped* test; // exit condition associated with loop, could be 0 for 'for' loops
- TIntermTyped* terminal; // exists for for-loops
- bool first; // true for while and for, not for do-while
- bool unroll; // true if unroll requested
- bool dontUnroll; // true if request to not unroll
- unsigned int dependency; // loop dependency hint; 0 means not set or unknown
- unsigned int minIterations; // as per the SPIR-V specification
- unsigned int maxIterations; // as per the SPIR-V specification
- unsigned int iterationMultiple; // as per the SPIR-V specification
- unsigned int peelCount; // as per the SPIR-V specification
- unsigned int partialCount; // as per the SPIR-V specification
- };
- //
- // Handle case, break, continue, return, and kill.
- //
- class TIntermBranch : public TIntermNode {
- public:
- TIntermBranch(TOperator op, TIntermTyped* e) :
- flowOp(op),
- expression(e) { }
- virtual TIntermBranch* getAsBranchNode() { return this; }
- virtual const TIntermBranch* getAsBranchNode() const { return this; }
- virtual void traverse(TIntermTraverser*);
- TOperator getFlowOp() const { return flowOp; }
- TIntermTyped* getExpression() const { return expression; }
- void setExpression(TIntermTyped* pExpression) { expression = pExpression; }
- void updatePrecision(TPrecisionQualifier parentPrecision);
- protected:
- TOperator flowOp;
- TIntermTyped* expression;
- };
- //
- // Represent method names before seeing their calling signature
- // or resolving them to operations. Just an expression as the base object
- // and a textural name.
- //
- class TIntermMethod : public TIntermTyped {
- public:
- TIntermMethod(TIntermTyped* o, const TType& t, const TString& m) : TIntermTyped(t), object(o), method(m) { }
- virtual TIntermMethod* getAsMethodNode() { return this; }
- virtual const TIntermMethod* getAsMethodNode() const { return this; }
- virtual const TString& getMethodName() const { return method; }
- virtual TIntermTyped* getObject() const { return object; }
- virtual void traverse(TIntermTraverser*);
- void setExport() { linkType = ELinkExport; }
- protected:
- TIntermTyped* object;
- TString method;
- TLinkType linkType;
- };
- //
- // Nodes that correspond to symbols or constants in the source code.
- //
- class TIntermSymbol : public TIntermTyped {
- public:
- // if symbol is initialized as symbol(sym), the memory comes from the pool allocator of sym. If sym comes from
- // per process threadPoolAllocator, then it causes increased memory usage per compile
- // it is essential to use "symbol = sym" to assign to symbol
- TIntermSymbol(long long i, const TString& n, const TType& t)
- : TIntermTyped(t), id(i), flattenSubset(-1), constSubtree(nullptr) { name = n; }
- virtual long long getId() const { return id; }
- virtual void changeId(long long i) { id = i; }
- virtual const TString& getName() const { return name; }
- virtual void traverse(TIntermTraverser*);
- virtual TIntermSymbol* getAsSymbolNode() { return this; }
- virtual const TIntermSymbol* getAsSymbolNode() const { return this; }
- void setConstArray(const TConstUnionArray& c) { constArray = c; }
- const TConstUnionArray& getConstArray() const { return constArray; }
- void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
- TIntermTyped* getConstSubtree() const { return constSubtree; }
- void setFlattenSubset(int subset) { flattenSubset = subset; }
- virtual const TString& getAccessName() const;
- int getFlattenSubset() const { return flattenSubset; } // -1 means full object
- // This is meant for cases where a node has already been constructed, and
- // later on, it becomes necessary to switch to a different symbol.
- virtual void switchId(long long newId) { id = newId; }
- protected:
- long long id; // the unique id of the symbol this node represents
- int flattenSubset; // how deeply the flattened object rooted at id has been dereferenced
- TString name; // the name of the symbol this node represents
- TConstUnionArray constArray; // if the symbol is a front-end compile-time constant, this is its value
- TIntermTyped* constSubtree;
- };
- class TIntermConstantUnion : public TIntermTyped {
- public:
- TIntermConstantUnion(const TConstUnionArray& ua, const TType& t) : TIntermTyped(t), constArray(ua), literal(false) { }
- const TConstUnionArray& getConstArray() const { return constArray; }
- virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
- virtual const TIntermConstantUnion* getAsConstantUnion() const { return this; }
- virtual void traverse(TIntermTraverser*);
- virtual TIntermTyped* fold(TOperator, const TIntermTyped*) const;
- virtual TIntermTyped* fold(TOperator, const TType&) const;
- void setLiteral() { literal = true; }
- void setExpression() { literal = false; }
- bool isLiteral() const { return literal; }
- protected:
- TIntermConstantUnion& operator=(const TIntermConstantUnion&);
- const TConstUnionArray constArray;
- bool literal; // true if node represents a literal in the source code
- };
- // Represent the independent aspects of a texturing TOperator
- struct TCrackedTextureOp {
- bool query;
- bool proj;
- bool lod;
- bool fetch;
- bool offset;
- bool offsets;
- bool gather;
- bool grad;
- bool subpass;
- bool lodClamp;
- bool fragMask;
- bool attachmentEXT;
- };
- //
- // Intermediate class for node types that hold operators.
- //
- class TIntermOperator : public TIntermTyped {
- public:
- virtual TIntermOperator* getAsOperator() { return this; }
- virtual const TIntermOperator* getAsOperator() const { return this; }
- TOperator getOp() const { return op; }
- void setOp(TOperator newOp) { op = newOp; }
- bool modifiesState() const;
- bool isConstructor() const;
- bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
- bool isSampling() const { return op > EOpSamplingGuardBegin && op < EOpSamplingGuardEnd; }
- bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; }
- bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; }
- bool isImageFootprint() const { return op > EOpImageFootprintGuardBegin && op < EOpImageFootprintGuardEnd; }
- bool isSparseImage() const { return op == EOpSparseImageLoad; }
- bool isSubgroup() const { return op > EOpSubgroupGuardStart && op < EOpSubgroupGuardStop; }
- void setOperationPrecision(TPrecisionQualifier p) { operationPrecision = p; }
- TPrecisionQualifier getOperationPrecision() const { return operationPrecision != EpqNone ?
- operationPrecision :
- type.getQualifier().precision; }
- TString getCompleteString() const
- {
- TString cs = type.getCompleteString();
- if (getOperationPrecision() != type.getQualifier().precision) {
- cs += ", operation at ";
- cs += GetPrecisionQualifierString(getOperationPrecision());
- }
- return cs;
- }
- // Crack the op into the individual dimensions of texturing operation.
- void crackTexture(TSampler sampler, TCrackedTextureOp& cracked) const
- {
- cracked.query = false;
- cracked.proj = false;
- cracked.lod = false;
- cracked.fetch = false;
- cracked.offset = false;
- cracked.offsets = false;
- cracked.gather = false;
- cracked.grad = false;
- cracked.subpass = false;
- cracked.attachmentEXT = false;
- cracked.lodClamp = false;
- cracked.fragMask = false;
- switch (op) {
- case EOpImageQuerySize:
- case EOpImageQuerySamples:
- case EOpTextureQuerySize:
- case EOpTextureQueryLod:
- case EOpTextureQueryLevels:
- case EOpTextureQuerySamples:
- case EOpSparseTexelsResident:
- cracked.query = true;
- break;
- case EOpTexture:
- case EOpSparseTexture:
- break;
- case EOpTextureProj:
- cracked.proj = true;
- break;
- case EOpTextureLod:
- case EOpSparseTextureLod:
- cracked.lod = true;
- break;
- case EOpTextureOffset:
- case EOpSparseTextureOffset:
- cracked.offset = true;
- break;
- case EOpTextureFetch:
- case EOpSparseTextureFetch:
- cracked.fetch = true;
- if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
- cracked.lod = true;
- break;
- case EOpTextureFetchOffset:
- case EOpSparseTextureFetchOffset:
- cracked.fetch = true;
- cracked.offset = true;
- if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
- cracked.lod = true;
- break;
- case EOpTextureProjOffset:
- cracked.offset = true;
- cracked.proj = true;
- break;
- case EOpTextureLodOffset:
- case EOpSparseTextureLodOffset:
- cracked.offset = true;
- cracked.lod = true;
- break;
- case EOpTextureProjLod:
- cracked.lod = true;
- cracked.proj = true;
- break;
- case EOpTextureProjLodOffset:
- cracked.offset = true;
- cracked.lod = true;
- cracked.proj = true;
- break;
- case EOpTextureGrad:
- case EOpSparseTextureGrad:
- cracked.grad = true;
- break;
- case EOpTextureGradOffset:
- case EOpSparseTextureGradOffset:
- cracked.grad = true;
- cracked.offset = true;
- break;
- case EOpTextureProjGrad:
- cracked.grad = true;
- cracked.proj = true;
- break;
- case EOpTextureProjGradOffset:
- cracked.grad = true;
- cracked.offset = true;
- cracked.proj = true;
- break;
- case EOpTextureClamp:
- case EOpSparseTextureClamp:
- cracked.lodClamp = true;
- break;
- case EOpTextureOffsetClamp:
- case EOpSparseTextureOffsetClamp:
- cracked.offset = true;
- cracked.lodClamp = true;
- break;
- case EOpTextureGradClamp:
- case EOpSparseTextureGradClamp:
- cracked.grad = true;
- cracked.lodClamp = true;
- break;
- case EOpTextureGradOffsetClamp:
- case EOpSparseTextureGradOffsetClamp:
- cracked.grad = true;
- cracked.offset = true;
- cracked.lodClamp = true;
- break;
- case EOpTextureGather:
- case EOpSparseTextureGather:
- cracked.gather = true;
- break;
- case EOpTextureGatherOffset:
- case EOpSparseTextureGatherOffset:
- cracked.gather = true;
- cracked.offset = true;
- break;
- case EOpTextureGatherOffsets:
- case EOpSparseTextureGatherOffsets:
- cracked.gather = true;
- cracked.offsets = true;
- break;
- case EOpTextureGatherLod:
- case EOpSparseTextureGatherLod:
- cracked.gather = true;
- cracked.lod = true;
- break;
- case EOpTextureGatherLodOffset:
- case EOpSparseTextureGatherLodOffset:
- cracked.gather = true;
- cracked.offset = true;
- cracked.lod = true;
- break;
- case EOpTextureGatherLodOffsets:
- case EOpSparseTextureGatherLodOffsets:
- cracked.gather = true;
- cracked.offsets = true;
- cracked.lod = true;
- break;
- case EOpImageLoadLod:
- case EOpImageStoreLod:
- case EOpSparseImageLoadLod:
- cracked.lod = true;
- break;
- case EOpFragmentMaskFetch:
- cracked.subpass = sampler.dim == EsdSubpass;
- cracked.fragMask = true;
- break;
- case EOpFragmentFetch:
- cracked.subpass = sampler.dim == EsdSubpass;
- cracked.fragMask = true;
- break;
- case EOpImageSampleFootprintNV:
- break;
- case EOpImageSampleFootprintClampNV:
- cracked.lodClamp = true;
- break;
- case EOpImageSampleFootprintLodNV:
- cracked.lod = true;
- break;
- case EOpImageSampleFootprintGradNV:
- cracked.grad = true;
- break;
- case EOpImageSampleFootprintGradClampNV:
- cracked.lodClamp = true;
- cracked.grad = true;
- break;
- case EOpSubpassLoad:
- case EOpSubpassLoadMS:
- cracked.subpass = true;
- break;
- case EOpColorAttachmentReadEXT:
- cracked.attachmentEXT = true;
- break;
- default:
- break;
- }
- }
- protected:
- TIntermOperator(TOperator o) : TIntermTyped(EbtFloat), op(o), operationPrecision(EpqNone) {}
- TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o), operationPrecision(EpqNone) {}
- TOperator op;
- // The result precision is in the inherited TType, and is usually meant to be both
- // the operation precision and the result precision. However, some more complex things,
- // like built-in function calls, distinguish between the two, in which case non-EqpNone
- // 'operationPrecision' overrides the result precision as far as operation precision
- // is concerned.
- TPrecisionQualifier operationPrecision;
- };
- //
- // Nodes for all the basic binary math operators.
- //
- class TIntermBinary : public TIntermOperator {
- public:
- TIntermBinary(TOperator o) : TIntermOperator(o) {}
- virtual void traverse(TIntermTraverser*);
- virtual void setLeft(TIntermTyped* n) { left = n; }
- virtual void setRight(TIntermTyped* n) { right = n; }
- virtual TIntermTyped* getLeft() const { return left; }
- virtual TIntermTyped* getRight() const { return right; }
- virtual TIntermBinary* getAsBinaryNode() { return this; }
- virtual const TIntermBinary* getAsBinaryNode() const { return this; }
- virtual void updatePrecision();
- protected:
- TIntermTyped* left;
- TIntermTyped* right;
- };
- //
- // Nodes for unary math operators.
- //
- class TIntermUnary : public TIntermOperator {
- public:
- TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(nullptr) {}
- TIntermUnary(TOperator o) : TIntermOperator(o), operand(nullptr) {}
- virtual void traverse(TIntermTraverser*);
- virtual void setOperand(TIntermTyped* o) { operand = o; }
- virtual TIntermTyped* getOperand() { return operand; }
- virtual const TIntermTyped* getOperand() const { return operand; }
- virtual TIntermUnary* getAsUnaryNode() { return this; }
- virtual const TIntermUnary* getAsUnaryNode() const { return this; }
- virtual void updatePrecision();
- void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
- const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
- protected:
- TIntermTyped* operand;
- TSpirvInstruction spirvInst;
- };
- typedef TVector<TIntermNode*> TIntermSequence;
- typedef TVector<TStorageQualifier> TQualifierList;
- //
- // Nodes that operate on an arbitrary sized set of children.
- //
- class TIntermAggregate : public TIntermOperator {
- public:
- TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(nullptr) { }
- TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(nullptr) { }
- ~TIntermAggregate() { delete pragmaTable; }
- virtual TIntermAggregate* getAsAggregate() { return this; }
- virtual const TIntermAggregate* getAsAggregate() const { return this; }
- virtual void updatePrecision();
- virtual void setOperator(TOperator o) { op = o; }
- virtual TIntermSequence& getSequence() { return sequence; }
- virtual const TIntermSequence& getSequence() const { return sequence; }
- virtual void setName(const TString& n) { name = n; }
- virtual const TString& getName() const { return name; }
- virtual void traverse(TIntermTraverser*);
- virtual void setUserDefined() { userDefined = true; }
- virtual bool isUserDefined() { return userDefined; }
- virtual TQualifierList& getQualifierList() { return qualifier; }
- virtual const TQualifierList& getQualifierList() const { return qualifier; }
- void setOptimize(bool o) { optimize = o; }
- void setDebug(bool d) { debug = d; }
- bool getOptimize() const { return optimize; }
- bool getDebug() const { return debug; }
- void setPragmaTable(const TPragmaTable& pTable);
- const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
- void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
- const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
- void setLinkType(TLinkType l) { linkType = l; }
- TLinkType getLinkType() const { return linkType; }
- protected:
- TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
- TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
- TIntermSequence sequence;
- TQualifierList qualifier;
- TString name;
- bool userDefined; // used for user defined function names
- bool optimize;
- bool debug;
- TPragmaTable* pragmaTable;
- TSpirvInstruction spirvInst;
- TLinkType linkType = ELinkNone;
- };
- //
- // For if tests.
- //
- class TIntermSelection : public TIntermTyped {
- public:
- TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
- TIntermTyped(EbtVoid), condition(cond), trueBlock(trueB), falseBlock(falseB),
- shortCircuit(true),
- flatten(false), dontFlatten(false) {}
- TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
- TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB),
- shortCircuit(true),
- flatten(false), dontFlatten(false) {}
- virtual void traverse(TIntermTraverser*);
- virtual TIntermTyped* getCondition() const { return condition; }
- virtual void setCondition(TIntermTyped* c) { condition = c; }
- virtual TIntermNode* getTrueBlock() const { return trueBlock; }
- virtual void setTrueBlock(TIntermTyped* tb) { trueBlock = tb; }
- virtual TIntermNode* getFalseBlock() const { return falseBlock; }
- virtual void setFalseBlock(TIntermTyped* fb) { falseBlock = fb; }
- virtual TIntermSelection* getAsSelectionNode() { return this; }
- virtual const TIntermSelection* getAsSelectionNode() const { return this; }
- void setNoShortCircuit() { shortCircuit = false; }
- bool getShortCircuit() const { return shortCircuit; }
- void setFlatten() { flatten = true; }
- void setDontFlatten() { dontFlatten = true; }
- bool getFlatten() const { return flatten; }
- bool getDontFlatten() const { return dontFlatten; }
- protected:
- TIntermTyped* condition;
- TIntermNode* trueBlock;
- TIntermNode* falseBlock;
- bool shortCircuit; // normally all if-then-else and all GLSL ?: short-circuit, but HLSL ?: does not
- bool flatten; // true if flatten requested
- bool dontFlatten; // true if requested to not flatten
- };
- //
- // For switch statements. Designed use is that a switch will have sequence of nodes
- // that are either case/default nodes or a *single* node that represents all the code
- // in between (if any) consecutive case/defaults. So, a traversal need only deal with
- // 0 or 1 nodes per case/default statement.
- //
- class TIntermSwitch : public TIntermNode {
- public:
- TIntermSwitch(TIntermTyped* cond, TIntermAggregate* b) : condition(cond), body(b),
- flatten(false), dontFlatten(false) {}
- virtual void traverse(TIntermTraverser*);
- virtual TIntermNode* getCondition() const { return condition; }
- virtual TIntermAggregate* getBody() const { return body; }
- virtual TIntermSwitch* getAsSwitchNode() { return this; }
- virtual const TIntermSwitch* getAsSwitchNode() const { return this; }
- void setFlatten() { flatten = true; }
- void setDontFlatten() { dontFlatten = true; }
- bool getFlatten() const { return flatten; }
- bool getDontFlatten() const { return dontFlatten; }
- protected:
- TIntermTyped* condition;
- TIntermAggregate* body;
- bool flatten; // true if flatten requested
- bool dontFlatten; // true if requested to not flatten
- };
- enum TVisit
- {
- EvPreVisit,
- EvInVisit,
- EvPostVisit
- };
- //
- // For traversing the tree. User should derive from this,
- // put their traversal specific data in it, and then pass
- // it to a Traverse method.
- //
- // When using this, just fill in the methods for nodes you want visited.
- // Return false from a pre-visit to skip visiting that node's subtree.
- //
- // Explicitly set postVisit to true if you want post visiting, otherwise,
- // filled in methods will only be called at pre-visit time (before processing
- // the subtree). Similarly for inVisit for in-order visiting of nodes with
- // multiple children.
- //
- // If you only want post-visits, explicitly turn off preVisit (and inVisit)
- // and turn on postVisit.
- //
- // In general, for the visit*() methods, return true from interior nodes
- // to have the traversal continue on to children.
- //
- // If you process children yourself, or don't want them processed, return false.
- //
- class TIntermTraverser {
- public:
- POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
- TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) :
- preVisit(preVisit),
- inVisit(inVisit),
- postVisit(postVisit),
- rightToLeft(rightToLeft),
- depth(0),
- maxDepth(0) { }
- virtual ~TIntermTraverser() { }
- virtual void visitSymbol(TIntermSymbol*) { }
- virtual void visitConstantUnion(TIntermConstantUnion*) { }
- virtual bool visitBinary(TVisit, TIntermBinary*) { return true; }
- virtual bool visitUnary(TVisit, TIntermUnary*) { return true; }
- virtual bool visitSelection(TVisit, TIntermSelection*) { return true; }
- virtual bool visitAggregate(TVisit, TIntermAggregate*) { return true; }
- virtual bool visitLoop(TVisit, TIntermLoop*) { return true; }
- virtual bool visitBranch(TVisit, TIntermBranch*) { return true; }
- virtual bool visitSwitch(TVisit, TIntermSwitch*) { return true; }
- int getMaxDepth() const { return maxDepth; }
- void incrementDepth(TIntermNode *current)
- {
- depth++;
- maxDepth = (std::max)(maxDepth, depth);
- path.push_back(current);
- }
- void decrementDepth()
- {
- depth--;
- path.pop_back();
- }
- TIntermNode *getParentNode()
- {
- return path.size() == 0 ? nullptr : path.back();
- }
- const bool preVisit;
- const bool inVisit;
- const bool postVisit;
- const bool rightToLeft;
- protected:
- TIntermTraverser& operator=(TIntermTraverser&);
- int depth;
- int maxDepth;
- // All the nodes from root to the current node's parent during traversing.
- TVector<TIntermNode *> path;
- };
- // KHR_vulkan_glsl says "Two arrays sized with specialization constants are the same type only if
- // sized with the same symbol, involving no operations"
- inline bool SameSpecializationConstants(TIntermTyped* node1, TIntermTyped* node2)
- {
- return node1->getAsSymbolNode() && node2->getAsSymbolNode() &&
- node1->getAsSymbolNode()->getId() == node2->getAsSymbolNode()->getId();
- }
- } // end namespace glslang
- #endif // __INTERMEDIATE_H
|