intermediate.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. //
  2. // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
  3. // Copyright (C) 2012-2016 LunarG, Inc.
  4. // Copyright (C) 2017 ARM Limited.
  5. // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
  6. //
  7. // All rights reserved.
  8. //
  9. // Redistribution and use in source and binary forms, with or without
  10. // modification, are permitted provided that the following conditions
  11. // are met:
  12. //
  13. // Redistributions of source code must retain the above copyright
  14. // notice, this list of conditions and the following disclaimer.
  15. //
  16. // Redistributions in binary form must reproduce the above
  17. // copyright notice, this list of conditions and the following
  18. // disclaimer in the documentation and/or other materials provided
  19. // with the distribution.
  20. //
  21. // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  22. // contributors may be used to endorse or promote products derived
  23. // from this software without specific prior written permission.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  28. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  29. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  30. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  31. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  32. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. // POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //
  39. // Definition of the in-memory high-level intermediate representation
  40. // of shaders. This is a tree that parser creates.
  41. //
  42. // Nodes in the tree are defined as a hierarchy of classes derived from
  43. // TIntermNode. Each is a node in a tree. There is no preset branching factor;
  44. // each node can have it's own type of list of children.
  45. //
  46. #ifndef __INTERMEDIATE_H
  47. #define __INTERMEDIATE_H
  48. #include "Common.h"
  49. #include "Types.h"
  50. #include "ConstantUnion.h"
  51. namespace glslang {
  52. class TIntermediate;
  53. //
  54. // Operators used by the high-level (parse tree) representation.
  55. //
  56. enum TOperator {
  57. EOpNull, // if in a node, should only mean a node is still being built
  58. EOpSequence, // denotes a list of statements, or parameters, etc.
  59. EOpScope, // Used by debugging to denote a scoped list of statements
  60. EOpLinkerObjects, // for aggregate node of objects the linker may need, if not reference by the rest of the AST
  61. EOpFunctionCall,
  62. EOpFunction, // For function definition
  63. EOpParameters, // an aggregate listing the parameters to a function
  64. EOpSpirvInst,
  65. //
  66. // Unary operators
  67. //
  68. EOpNegative,
  69. EOpLogicalNot,
  70. EOpVectorLogicalNot,
  71. EOpBitwiseNot,
  72. EOpPostIncrement,
  73. EOpPostDecrement,
  74. EOpPreIncrement,
  75. EOpPreDecrement,
  76. EOpCopyObject,
  77. EOpDeclare, // Used by debugging to force declaration of variable in correct scope
  78. // (u)int* -> bool
  79. EOpConvInt8ToBool,
  80. EOpConvUint8ToBool,
  81. EOpConvInt16ToBool,
  82. EOpConvUint16ToBool,
  83. EOpConvIntToBool,
  84. EOpConvUintToBool,
  85. EOpConvInt64ToBool,
  86. EOpConvUint64ToBool,
  87. // float* -> bool
  88. EOpConvFloat16ToBool,
  89. EOpConvFloatToBool,
  90. EOpConvDoubleToBool,
  91. // bool -> (u)int*
  92. EOpConvBoolToInt8,
  93. EOpConvBoolToUint8,
  94. EOpConvBoolToInt16,
  95. EOpConvBoolToUint16,
  96. EOpConvBoolToInt,
  97. EOpConvBoolToUint,
  98. EOpConvBoolToInt64,
  99. EOpConvBoolToUint64,
  100. // bool -> float*
  101. EOpConvBoolToFloat16,
  102. EOpConvBoolToFloat,
  103. EOpConvBoolToDouble,
  104. // int8_t -> (u)int*
  105. EOpConvInt8ToInt16,
  106. EOpConvInt8ToInt,
  107. EOpConvInt8ToInt64,
  108. EOpConvInt8ToUint8,
  109. EOpConvInt8ToUint16,
  110. EOpConvInt8ToUint,
  111. EOpConvInt8ToUint64,
  112. // uint8_t -> (u)int*
  113. EOpConvUint8ToInt8,
  114. EOpConvUint8ToInt16,
  115. EOpConvUint8ToInt,
  116. EOpConvUint8ToInt64,
  117. EOpConvUint8ToUint16,
  118. EOpConvUint8ToUint,
  119. EOpConvUint8ToUint64,
  120. // int8_t -> float*
  121. EOpConvInt8ToFloat16,
  122. EOpConvInt8ToFloat,
  123. EOpConvInt8ToDouble,
  124. // uint8_t -> float*
  125. EOpConvUint8ToFloat16,
  126. EOpConvUint8ToFloat,
  127. EOpConvUint8ToDouble,
  128. // int16_t -> (u)int*
  129. EOpConvInt16ToInt8,
  130. EOpConvInt16ToInt,
  131. EOpConvInt16ToInt64,
  132. EOpConvInt16ToUint8,
  133. EOpConvInt16ToUint16,
  134. EOpConvInt16ToUint,
  135. EOpConvInt16ToUint64,
  136. // uint16_t -> (u)int*
  137. EOpConvUint16ToInt8,
  138. EOpConvUint16ToInt16,
  139. EOpConvUint16ToInt,
  140. EOpConvUint16ToInt64,
  141. EOpConvUint16ToUint8,
  142. EOpConvUint16ToUint,
  143. EOpConvUint16ToUint64,
  144. // int16_t -> float*
  145. EOpConvInt16ToFloat16,
  146. EOpConvInt16ToFloat,
  147. EOpConvInt16ToDouble,
  148. // uint16_t -> float*
  149. EOpConvUint16ToFloat16,
  150. EOpConvUint16ToFloat,
  151. EOpConvUint16ToDouble,
  152. // int32_t -> (u)int*
  153. EOpConvIntToInt8,
  154. EOpConvIntToInt16,
  155. EOpConvIntToInt64,
  156. EOpConvIntToUint8,
  157. EOpConvIntToUint16,
  158. EOpConvIntToUint,
  159. EOpConvIntToUint64,
  160. // uint32_t -> (u)int*
  161. EOpConvUintToInt8,
  162. EOpConvUintToInt16,
  163. EOpConvUintToInt,
  164. EOpConvUintToInt64,
  165. EOpConvUintToUint8,
  166. EOpConvUintToUint16,
  167. EOpConvUintToUint64,
  168. // int32_t -> float*
  169. EOpConvIntToFloat16,
  170. EOpConvIntToFloat,
  171. EOpConvIntToDouble,
  172. // uint32_t -> float*
  173. EOpConvUintToFloat16,
  174. EOpConvUintToFloat,
  175. EOpConvUintToDouble,
  176. // int64_t -> (u)int*
  177. EOpConvInt64ToInt8,
  178. EOpConvInt64ToInt16,
  179. EOpConvInt64ToInt,
  180. EOpConvInt64ToUint8,
  181. EOpConvInt64ToUint16,
  182. EOpConvInt64ToUint,
  183. EOpConvInt64ToUint64,
  184. // uint64_t -> (u)int*
  185. EOpConvUint64ToInt8,
  186. EOpConvUint64ToInt16,
  187. EOpConvUint64ToInt,
  188. EOpConvUint64ToInt64,
  189. EOpConvUint64ToUint8,
  190. EOpConvUint64ToUint16,
  191. EOpConvUint64ToUint,
  192. // int64_t -> float*
  193. EOpConvInt64ToFloat16,
  194. EOpConvInt64ToFloat,
  195. EOpConvInt64ToDouble,
  196. // uint64_t -> float*
  197. EOpConvUint64ToFloat16,
  198. EOpConvUint64ToFloat,
  199. EOpConvUint64ToDouble,
  200. // float16_t -> (u)int*
  201. EOpConvFloat16ToInt8,
  202. EOpConvFloat16ToInt16,
  203. EOpConvFloat16ToInt,
  204. EOpConvFloat16ToInt64,
  205. EOpConvFloat16ToUint8,
  206. EOpConvFloat16ToUint16,
  207. EOpConvFloat16ToUint,
  208. EOpConvFloat16ToUint64,
  209. // float16_t -> float*
  210. EOpConvFloat16ToFloat,
  211. EOpConvFloat16ToDouble,
  212. // float -> (u)int*
  213. EOpConvFloatToInt8,
  214. EOpConvFloatToInt16,
  215. EOpConvFloatToInt,
  216. EOpConvFloatToInt64,
  217. EOpConvFloatToUint8,
  218. EOpConvFloatToUint16,
  219. EOpConvFloatToUint,
  220. EOpConvFloatToUint64,
  221. // float -> float*
  222. EOpConvFloatToFloat16,
  223. EOpConvFloatToDouble,
  224. // float64 _t-> (u)int*
  225. EOpConvDoubleToInt8,
  226. EOpConvDoubleToInt16,
  227. EOpConvDoubleToInt,
  228. EOpConvDoubleToInt64,
  229. EOpConvDoubleToUint8,
  230. EOpConvDoubleToUint16,
  231. EOpConvDoubleToUint,
  232. EOpConvDoubleToUint64,
  233. // float64_t -> float*
  234. EOpConvDoubleToFloat16,
  235. EOpConvDoubleToFloat,
  236. // uint64_t <-> pointer
  237. EOpConvUint64ToPtr,
  238. EOpConvPtrToUint64,
  239. // uvec2 <-> pointer
  240. EOpConvUvec2ToPtr,
  241. EOpConvPtrToUvec2,
  242. // uint64_t -> accelerationStructureEXT
  243. EOpConvUint64ToAccStruct,
  244. // uvec2 -> accelerationStructureEXT
  245. EOpConvUvec2ToAccStruct,
  246. //
  247. // binary operations
  248. //
  249. EOpAdd,
  250. EOpSub,
  251. EOpMul,
  252. EOpDiv,
  253. EOpMod,
  254. EOpRightShift,
  255. EOpLeftShift,
  256. EOpAnd,
  257. EOpInclusiveOr,
  258. EOpExclusiveOr,
  259. EOpEqual,
  260. EOpNotEqual,
  261. EOpVectorEqual,
  262. EOpVectorNotEqual,
  263. EOpLessThan,
  264. EOpGreaterThan,
  265. EOpLessThanEqual,
  266. EOpGreaterThanEqual,
  267. EOpComma,
  268. EOpVectorTimesScalar,
  269. EOpVectorTimesMatrix,
  270. EOpMatrixTimesVector,
  271. EOpMatrixTimesScalar,
  272. EOpLogicalOr,
  273. EOpLogicalXor,
  274. EOpLogicalAnd,
  275. EOpIndexDirect,
  276. EOpIndexIndirect,
  277. EOpIndexDirectStruct,
  278. EOpVectorSwizzle,
  279. EOpMethod,
  280. EOpScoping,
  281. //
  282. // Built-in functions mapped to operators
  283. //
  284. EOpRadians,
  285. EOpDegrees,
  286. EOpSin,
  287. EOpCos,
  288. EOpTan,
  289. EOpAsin,
  290. EOpAcos,
  291. EOpAtan,
  292. EOpSinh,
  293. EOpCosh,
  294. EOpTanh,
  295. EOpAsinh,
  296. EOpAcosh,
  297. EOpAtanh,
  298. EOpPow,
  299. EOpExp,
  300. EOpLog,
  301. EOpExp2,
  302. EOpLog2,
  303. EOpSqrt,
  304. EOpInverseSqrt,
  305. EOpAbs,
  306. EOpSign,
  307. EOpFloor,
  308. EOpTrunc,
  309. EOpRound,
  310. EOpRoundEven,
  311. EOpCeil,
  312. EOpFract,
  313. EOpModf,
  314. EOpMin,
  315. EOpMax,
  316. EOpClamp,
  317. EOpMix,
  318. EOpStep,
  319. EOpSmoothStep,
  320. EOpIsNan,
  321. EOpIsInf,
  322. EOpFma,
  323. EOpFrexp,
  324. EOpLdexp,
  325. EOpFloatBitsToInt,
  326. EOpFloatBitsToUint,
  327. EOpIntBitsToFloat,
  328. EOpUintBitsToFloat,
  329. EOpDoubleBitsToInt64,
  330. EOpDoubleBitsToUint64,
  331. EOpInt64BitsToDouble,
  332. EOpUint64BitsToDouble,
  333. EOpFloat16BitsToInt16,
  334. EOpFloat16BitsToUint16,
  335. EOpInt16BitsToFloat16,
  336. EOpUint16BitsToFloat16,
  337. EOpPackSnorm2x16,
  338. EOpUnpackSnorm2x16,
  339. EOpPackUnorm2x16,
  340. EOpUnpackUnorm2x16,
  341. EOpPackSnorm4x8,
  342. EOpUnpackSnorm4x8,
  343. EOpPackUnorm4x8,
  344. EOpUnpackUnorm4x8,
  345. EOpPackHalf2x16,
  346. EOpUnpackHalf2x16,
  347. EOpPackDouble2x32,
  348. EOpUnpackDouble2x32,
  349. EOpPackInt2x32,
  350. EOpUnpackInt2x32,
  351. EOpPackUint2x32,
  352. EOpUnpackUint2x32,
  353. EOpPackFloat2x16,
  354. EOpUnpackFloat2x16,
  355. EOpPackInt2x16,
  356. EOpUnpackInt2x16,
  357. EOpPackUint2x16,
  358. EOpUnpackUint2x16,
  359. EOpPackInt4x16,
  360. EOpUnpackInt4x16,
  361. EOpPackUint4x16,
  362. EOpUnpackUint4x16,
  363. EOpPack16,
  364. EOpPack32,
  365. EOpPack64,
  366. EOpUnpack32,
  367. EOpUnpack16,
  368. EOpUnpack8,
  369. EOpLength,
  370. EOpDistance,
  371. EOpDot,
  372. EOpCross,
  373. EOpNormalize,
  374. EOpFaceForward,
  375. EOpReflect,
  376. EOpRefract,
  377. EOpMin3,
  378. EOpMax3,
  379. EOpMid3,
  380. EOpDPdx, // Fragment only
  381. EOpDPdy, // Fragment only
  382. EOpFwidth, // Fragment only
  383. EOpDPdxFine, // Fragment only
  384. EOpDPdyFine, // Fragment only
  385. EOpFwidthFine, // Fragment only
  386. EOpDPdxCoarse, // Fragment only
  387. EOpDPdyCoarse, // Fragment only
  388. EOpFwidthCoarse, // Fragment only
  389. EOpInterpolateAtCentroid, // Fragment only
  390. EOpInterpolateAtSample, // Fragment only
  391. EOpInterpolateAtOffset, // Fragment only
  392. EOpInterpolateAtVertex,
  393. EOpMatrixTimesMatrix,
  394. EOpOuterProduct,
  395. EOpDeterminant,
  396. EOpMatrixInverse,
  397. EOpTranspose,
  398. EOpFtransform,
  399. EOpNoise,
  400. EOpEmitVertex, // geometry only
  401. EOpEndPrimitive, // geometry only
  402. EOpEmitStreamVertex, // geometry only
  403. EOpEndStreamPrimitive, // geometry only
  404. EOpBarrier,
  405. EOpMemoryBarrier,
  406. EOpMemoryBarrierAtomicCounter,
  407. EOpMemoryBarrierBuffer,
  408. EOpMemoryBarrierImage,
  409. EOpMemoryBarrierShared, // compute only
  410. EOpGroupMemoryBarrier, // compute only
  411. EOpBallot,
  412. EOpReadInvocation,
  413. EOpReadFirstInvocation,
  414. EOpAnyInvocation,
  415. EOpAllInvocations,
  416. EOpAllInvocationsEqual,
  417. EOpSubgroupGuardStart,
  418. EOpSubgroupBarrier,
  419. EOpSubgroupMemoryBarrier,
  420. EOpSubgroupMemoryBarrierBuffer,
  421. EOpSubgroupMemoryBarrierImage,
  422. EOpSubgroupMemoryBarrierShared, // compute only
  423. EOpSubgroupElect,
  424. EOpSubgroupAll,
  425. EOpSubgroupAny,
  426. EOpSubgroupAllEqual,
  427. EOpSubgroupBroadcast,
  428. EOpSubgroupBroadcastFirst,
  429. EOpSubgroupBallot,
  430. EOpSubgroupInverseBallot,
  431. EOpSubgroupBallotBitExtract,
  432. EOpSubgroupBallotBitCount,
  433. EOpSubgroupBallotInclusiveBitCount,
  434. EOpSubgroupBallotExclusiveBitCount,
  435. EOpSubgroupBallotFindLSB,
  436. EOpSubgroupBallotFindMSB,
  437. EOpSubgroupShuffle,
  438. EOpSubgroupShuffleXor,
  439. EOpSubgroupShuffleUp,
  440. EOpSubgroupShuffleDown,
  441. EOpSubgroupAdd,
  442. EOpSubgroupMul,
  443. EOpSubgroupMin,
  444. EOpSubgroupMax,
  445. EOpSubgroupAnd,
  446. EOpSubgroupOr,
  447. EOpSubgroupXor,
  448. EOpSubgroupInclusiveAdd,
  449. EOpSubgroupInclusiveMul,
  450. EOpSubgroupInclusiveMin,
  451. EOpSubgroupInclusiveMax,
  452. EOpSubgroupInclusiveAnd,
  453. EOpSubgroupInclusiveOr,
  454. EOpSubgroupInclusiveXor,
  455. EOpSubgroupExclusiveAdd,
  456. EOpSubgroupExclusiveMul,
  457. EOpSubgroupExclusiveMin,
  458. EOpSubgroupExclusiveMax,
  459. EOpSubgroupExclusiveAnd,
  460. EOpSubgroupExclusiveOr,
  461. EOpSubgroupExclusiveXor,
  462. EOpSubgroupClusteredAdd,
  463. EOpSubgroupClusteredMul,
  464. EOpSubgroupClusteredMin,
  465. EOpSubgroupClusteredMax,
  466. EOpSubgroupClusteredAnd,
  467. EOpSubgroupClusteredOr,
  468. EOpSubgroupClusteredXor,
  469. EOpSubgroupQuadBroadcast,
  470. EOpSubgroupQuadSwapHorizontal,
  471. EOpSubgroupQuadSwapVertical,
  472. EOpSubgroupQuadSwapDiagonal,
  473. EOpSubgroupPartition,
  474. EOpSubgroupPartitionedAdd,
  475. EOpSubgroupPartitionedMul,
  476. EOpSubgroupPartitionedMin,
  477. EOpSubgroupPartitionedMax,
  478. EOpSubgroupPartitionedAnd,
  479. EOpSubgroupPartitionedOr,
  480. EOpSubgroupPartitionedXor,
  481. EOpSubgroupPartitionedInclusiveAdd,
  482. EOpSubgroupPartitionedInclusiveMul,
  483. EOpSubgroupPartitionedInclusiveMin,
  484. EOpSubgroupPartitionedInclusiveMax,
  485. EOpSubgroupPartitionedInclusiveAnd,
  486. EOpSubgroupPartitionedInclusiveOr,
  487. EOpSubgroupPartitionedInclusiveXor,
  488. EOpSubgroupPartitionedExclusiveAdd,
  489. EOpSubgroupPartitionedExclusiveMul,
  490. EOpSubgroupPartitionedExclusiveMin,
  491. EOpSubgroupPartitionedExclusiveMax,
  492. EOpSubgroupPartitionedExclusiveAnd,
  493. EOpSubgroupPartitionedExclusiveOr,
  494. EOpSubgroupPartitionedExclusiveXor,
  495. EOpSubgroupGuardStop,
  496. EOpMinInvocations,
  497. EOpMaxInvocations,
  498. EOpAddInvocations,
  499. EOpMinInvocationsNonUniform,
  500. EOpMaxInvocationsNonUniform,
  501. EOpAddInvocationsNonUniform,
  502. EOpMinInvocationsInclusiveScan,
  503. EOpMaxInvocationsInclusiveScan,
  504. EOpAddInvocationsInclusiveScan,
  505. EOpMinInvocationsInclusiveScanNonUniform,
  506. EOpMaxInvocationsInclusiveScanNonUniform,
  507. EOpAddInvocationsInclusiveScanNonUniform,
  508. EOpMinInvocationsExclusiveScan,
  509. EOpMaxInvocationsExclusiveScan,
  510. EOpAddInvocationsExclusiveScan,
  511. EOpMinInvocationsExclusiveScanNonUniform,
  512. EOpMaxInvocationsExclusiveScanNonUniform,
  513. EOpAddInvocationsExclusiveScanNonUniform,
  514. EOpSwizzleInvocations,
  515. EOpSwizzleInvocationsMasked,
  516. EOpWriteInvocation,
  517. EOpMbcnt,
  518. EOpCubeFaceIndex,
  519. EOpCubeFaceCoord,
  520. EOpTime,
  521. EOpAtomicAdd,
  522. EOpAtomicSubtract,
  523. EOpAtomicMin,
  524. EOpAtomicMax,
  525. EOpAtomicAnd,
  526. EOpAtomicOr,
  527. EOpAtomicXor,
  528. EOpAtomicExchange,
  529. EOpAtomicCompSwap,
  530. EOpAtomicLoad,
  531. EOpAtomicStore,
  532. EOpAtomicCounterIncrement, // results in pre-increment value
  533. EOpAtomicCounterDecrement, // results in post-decrement value
  534. EOpAtomicCounter,
  535. EOpAtomicCounterAdd,
  536. EOpAtomicCounterSubtract,
  537. EOpAtomicCounterMin,
  538. EOpAtomicCounterMax,
  539. EOpAtomicCounterAnd,
  540. EOpAtomicCounterOr,
  541. EOpAtomicCounterXor,
  542. EOpAtomicCounterExchange,
  543. EOpAtomicCounterCompSwap,
  544. EOpAny,
  545. EOpAll,
  546. EOpCooperativeMatrixLoad,
  547. EOpCooperativeMatrixStore,
  548. EOpCooperativeMatrixMulAdd,
  549. EOpCooperativeMatrixLoadNV,
  550. EOpCooperativeMatrixStoreNV,
  551. EOpCooperativeMatrixMulAddNV,
  552. EOpBeginInvocationInterlock, // Fragment only
  553. EOpEndInvocationInterlock, // Fragment only
  554. EOpIsHelperInvocation,
  555. EOpDebugPrintf,
  556. //
  557. // Branch
  558. //
  559. EOpKill, // Fragment only
  560. EOpTerminateInvocation, // Fragment only
  561. EOpDemote, // Fragment only
  562. EOpTerminateRayKHR, // Any-hit only
  563. EOpIgnoreIntersectionKHR, // Any-hit only
  564. EOpReturn,
  565. EOpBreak,
  566. EOpContinue,
  567. EOpCase,
  568. EOpDefault,
  569. //
  570. // Constructors
  571. //
  572. EOpConstructGuardStart,
  573. EOpConstructInt, // these first scalar forms also identify what implicit conversion is needed
  574. EOpConstructUint,
  575. EOpConstructInt8,
  576. EOpConstructUint8,
  577. EOpConstructInt16,
  578. EOpConstructUint16,
  579. EOpConstructInt64,
  580. EOpConstructUint64,
  581. EOpConstructBool,
  582. EOpConstructFloat,
  583. EOpConstructDouble,
  584. // Keep vector and matrix constructors in a consistent relative order for
  585. // TParseContext::constructBuiltIn, which converts between 8/16/32 bit
  586. // vector constructors
  587. EOpConstructVec2,
  588. EOpConstructVec3,
  589. EOpConstructVec4,
  590. EOpConstructMat2x2,
  591. EOpConstructMat2x3,
  592. EOpConstructMat2x4,
  593. EOpConstructMat3x2,
  594. EOpConstructMat3x3,
  595. EOpConstructMat3x4,
  596. EOpConstructMat4x2,
  597. EOpConstructMat4x3,
  598. EOpConstructMat4x4,
  599. EOpConstructDVec2,
  600. EOpConstructDVec3,
  601. EOpConstructDVec4,
  602. EOpConstructBVec2,
  603. EOpConstructBVec3,
  604. EOpConstructBVec4,
  605. EOpConstructI8Vec2,
  606. EOpConstructI8Vec3,
  607. EOpConstructI8Vec4,
  608. EOpConstructU8Vec2,
  609. EOpConstructU8Vec3,
  610. EOpConstructU8Vec4,
  611. EOpConstructI16Vec2,
  612. EOpConstructI16Vec3,
  613. EOpConstructI16Vec4,
  614. EOpConstructU16Vec2,
  615. EOpConstructU16Vec3,
  616. EOpConstructU16Vec4,
  617. EOpConstructIVec2,
  618. EOpConstructIVec3,
  619. EOpConstructIVec4,
  620. EOpConstructUVec2,
  621. EOpConstructUVec3,
  622. EOpConstructUVec4,
  623. EOpConstructI64Vec2,
  624. EOpConstructI64Vec3,
  625. EOpConstructI64Vec4,
  626. EOpConstructU64Vec2,
  627. EOpConstructU64Vec3,
  628. EOpConstructU64Vec4,
  629. EOpConstructDMat2x2,
  630. EOpConstructDMat2x3,
  631. EOpConstructDMat2x4,
  632. EOpConstructDMat3x2,
  633. EOpConstructDMat3x3,
  634. EOpConstructDMat3x4,
  635. EOpConstructDMat4x2,
  636. EOpConstructDMat4x3,
  637. EOpConstructDMat4x4,
  638. EOpConstructIMat2x2,
  639. EOpConstructIMat2x3,
  640. EOpConstructIMat2x4,
  641. EOpConstructIMat3x2,
  642. EOpConstructIMat3x3,
  643. EOpConstructIMat3x4,
  644. EOpConstructIMat4x2,
  645. EOpConstructIMat4x3,
  646. EOpConstructIMat4x4,
  647. EOpConstructUMat2x2,
  648. EOpConstructUMat2x3,
  649. EOpConstructUMat2x4,
  650. EOpConstructUMat3x2,
  651. EOpConstructUMat3x3,
  652. EOpConstructUMat3x4,
  653. EOpConstructUMat4x2,
  654. EOpConstructUMat4x3,
  655. EOpConstructUMat4x4,
  656. EOpConstructBMat2x2,
  657. EOpConstructBMat2x3,
  658. EOpConstructBMat2x4,
  659. EOpConstructBMat3x2,
  660. EOpConstructBMat3x3,
  661. EOpConstructBMat3x4,
  662. EOpConstructBMat4x2,
  663. EOpConstructBMat4x3,
  664. EOpConstructBMat4x4,
  665. EOpConstructFloat16,
  666. EOpConstructF16Vec2,
  667. EOpConstructF16Vec3,
  668. EOpConstructF16Vec4,
  669. EOpConstructF16Mat2x2,
  670. EOpConstructF16Mat2x3,
  671. EOpConstructF16Mat2x4,
  672. EOpConstructF16Mat3x2,
  673. EOpConstructF16Mat3x3,
  674. EOpConstructF16Mat3x4,
  675. EOpConstructF16Mat4x2,
  676. EOpConstructF16Mat4x3,
  677. EOpConstructF16Mat4x4,
  678. EOpConstructStruct,
  679. EOpConstructTextureSampler,
  680. EOpConstructNonuniform, // expected to be transformed away, not present in final AST
  681. EOpConstructReference,
  682. EOpConstructCooperativeMatrixNV,
  683. EOpConstructCooperativeMatrixKHR,
  684. EOpConstructAccStruct,
  685. EOpConstructGuardEnd,
  686. //
  687. // moves
  688. //
  689. EOpAssign,
  690. EOpAddAssign,
  691. EOpSubAssign,
  692. EOpMulAssign,
  693. EOpVectorTimesMatrixAssign,
  694. EOpVectorTimesScalarAssign,
  695. EOpMatrixTimesScalarAssign,
  696. EOpMatrixTimesMatrixAssign,
  697. EOpDivAssign,
  698. EOpModAssign,
  699. EOpAndAssign,
  700. EOpInclusiveOrAssign,
  701. EOpExclusiveOrAssign,
  702. EOpLeftShiftAssign,
  703. EOpRightShiftAssign,
  704. //
  705. // Array operators
  706. //
  707. // Can apply to arrays, vectors, or matrices.
  708. // Can be decomposed to a constant at compile time, but this does not always happen,
  709. // due to link-time effects. So, consumer can expect either a link-time sized or
  710. // run-time sized array.
  711. EOpArrayLength,
  712. //
  713. // Image operations
  714. //
  715. EOpImageGuardBegin,
  716. EOpImageQuerySize,
  717. EOpImageQuerySamples,
  718. EOpImageLoad,
  719. EOpImageStore,
  720. EOpImageLoadLod,
  721. EOpImageStoreLod,
  722. EOpImageAtomicAdd,
  723. EOpImageAtomicMin,
  724. EOpImageAtomicMax,
  725. EOpImageAtomicAnd,
  726. EOpImageAtomicOr,
  727. EOpImageAtomicXor,
  728. EOpImageAtomicExchange,
  729. EOpImageAtomicCompSwap,
  730. EOpImageAtomicLoad,
  731. EOpImageAtomicStore,
  732. EOpSubpassLoad,
  733. EOpSubpassLoadMS,
  734. EOpSparseImageLoad,
  735. EOpSparseImageLoadLod,
  736. EOpColorAttachmentReadEXT, // Fragment only
  737. EOpImageGuardEnd,
  738. //
  739. // Texture operations
  740. //
  741. EOpTextureGuardBegin,
  742. EOpTextureQuerySize,
  743. EOpTextureQueryLod,
  744. EOpTextureQueryLevels,
  745. EOpTextureQuerySamples,
  746. EOpSamplingGuardBegin,
  747. EOpTexture,
  748. EOpTextureProj,
  749. EOpTextureLod,
  750. EOpTextureOffset,
  751. EOpTextureFetch,
  752. EOpTextureFetchOffset,
  753. EOpTextureProjOffset,
  754. EOpTextureLodOffset,
  755. EOpTextureProjLod,
  756. EOpTextureProjLodOffset,
  757. EOpTextureGrad,
  758. EOpTextureGradOffset,
  759. EOpTextureProjGrad,
  760. EOpTextureProjGradOffset,
  761. EOpTextureGather,
  762. EOpTextureGatherOffset,
  763. EOpTextureGatherOffsets,
  764. EOpTextureClamp,
  765. EOpTextureOffsetClamp,
  766. EOpTextureGradClamp,
  767. EOpTextureGradOffsetClamp,
  768. EOpTextureGatherLod,
  769. EOpTextureGatherLodOffset,
  770. EOpTextureGatherLodOffsets,
  771. EOpFragmentMaskFetch,
  772. EOpFragmentFetch,
  773. EOpSparseTextureGuardBegin,
  774. EOpSparseTexture,
  775. EOpSparseTextureLod,
  776. EOpSparseTextureOffset,
  777. EOpSparseTextureFetch,
  778. EOpSparseTextureFetchOffset,
  779. EOpSparseTextureLodOffset,
  780. EOpSparseTextureGrad,
  781. EOpSparseTextureGradOffset,
  782. EOpSparseTextureGather,
  783. EOpSparseTextureGatherOffset,
  784. EOpSparseTextureGatherOffsets,
  785. EOpSparseTexelsResident,
  786. EOpSparseTextureClamp,
  787. EOpSparseTextureOffsetClamp,
  788. EOpSparseTextureGradClamp,
  789. EOpSparseTextureGradOffsetClamp,
  790. EOpSparseTextureGatherLod,
  791. EOpSparseTextureGatherLodOffset,
  792. EOpSparseTextureGatherLodOffsets,
  793. EOpSparseTextureGuardEnd,
  794. EOpImageFootprintGuardBegin,
  795. EOpImageSampleFootprintNV,
  796. EOpImageSampleFootprintClampNV,
  797. EOpImageSampleFootprintLodNV,
  798. EOpImageSampleFootprintGradNV,
  799. EOpImageSampleFootprintGradClampNV,
  800. EOpImageFootprintGuardEnd,
  801. EOpSamplingGuardEnd,
  802. EOpTextureGuardEnd,
  803. //
  804. // Integer operations
  805. //
  806. EOpAddCarry,
  807. EOpSubBorrow,
  808. EOpUMulExtended,
  809. EOpIMulExtended,
  810. EOpBitfieldExtract,
  811. EOpBitfieldInsert,
  812. EOpBitFieldReverse,
  813. EOpBitCount,
  814. EOpFindLSB,
  815. EOpFindMSB,
  816. EOpCountLeadingZeros,
  817. EOpCountTrailingZeros,
  818. EOpAbsDifference,
  819. EOpAddSaturate,
  820. EOpSubSaturate,
  821. EOpAverage,
  822. EOpAverageRounded,
  823. EOpMul32x16,
  824. EOpTraceNV,
  825. EOpTraceRayMotionNV,
  826. EOpTraceKHR,
  827. EOpReportIntersection,
  828. EOpIgnoreIntersectionNV,
  829. EOpTerminateRayNV,
  830. EOpExecuteCallableNV,
  831. EOpExecuteCallableKHR,
  832. EOpWritePackedPrimitiveIndices4x8NV,
  833. EOpEmitMeshTasksEXT,
  834. EOpSetMeshOutputsEXT,
  835. //
  836. // GL_EXT_ray_query operations
  837. //
  838. EOpRayQueryInitialize,
  839. EOpRayQueryTerminate,
  840. EOpRayQueryGenerateIntersection,
  841. EOpRayQueryConfirmIntersection,
  842. EOpRayQueryProceed,
  843. EOpRayQueryGetIntersectionType,
  844. EOpRayQueryGetRayTMin,
  845. EOpRayQueryGetRayFlags,
  846. EOpRayQueryGetIntersectionT,
  847. EOpRayQueryGetIntersectionInstanceCustomIndex,
  848. EOpRayQueryGetIntersectionInstanceId,
  849. EOpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffset,
  850. EOpRayQueryGetIntersectionGeometryIndex,
  851. EOpRayQueryGetIntersectionPrimitiveIndex,
  852. EOpRayQueryGetIntersectionBarycentrics,
  853. EOpRayQueryGetIntersectionFrontFace,
  854. EOpRayQueryGetIntersectionCandidateAABBOpaque,
  855. EOpRayQueryGetIntersectionObjectRayDirection,
  856. EOpRayQueryGetIntersectionObjectRayOrigin,
  857. EOpRayQueryGetWorldRayDirection,
  858. EOpRayQueryGetWorldRayOrigin,
  859. EOpRayQueryGetIntersectionObjectToWorld,
  860. EOpRayQueryGetIntersectionWorldToObject,
  861. //
  862. // GL_NV_shader_invocation_reorder
  863. //
  864. EOpHitObjectTraceRayNV,
  865. EOpHitObjectTraceRayMotionNV,
  866. EOpHitObjectRecordHitNV,
  867. EOpHitObjectRecordHitMotionNV,
  868. EOpHitObjectRecordHitWithIndexNV,
  869. EOpHitObjectRecordHitWithIndexMotionNV,
  870. EOpHitObjectRecordMissNV,
  871. EOpHitObjectRecordMissMotionNV,
  872. EOpHitObjectRecordEmptyNV,
  873. EOpHitObjectExecuteShaderNV,
  874. EOpHitObjectIsEmptyNV,
  875. EOpHitObjectIsMissNV,
  876. EOpHitObjectIsHitNV,
  877. EOpHitObjectGetRayTMinNV,
  878. EOpHitObjectGetRayTMaxNV,
  879. EOpHitObjectGetObjectRayOriginNV,
  880. EOpHitObjectGetObjectRayDirectionNV,
  881. EOpHitObjectGetWorldRayOriginNV,
  882. EOpHitObjectGetWorldRayDirectionNV,
  883. EOpHitObjectGetWorldToObjectNV,
  884. EOpHitObjectGetObjectToWorldNV,
  885. EOpHitObjectGetInstanceCustomIndexNV,
  886. EOpHitObjectGetInstanceIdNV,
  887. EOpHitObjectGetGeometryIndexNV,
  888. EOpHitObjectGetPrimitiveIndexNV,
  889. EOpHitObjectGetHitKindNV,
  890. EOpHitObjectGetShaderBindingTableRecordIndexNV,
  891. EOpHitObjectGetShaderRecordBufferHandleNV,
  892. EOpHitObjectGetAttributesNV,
  893. EOpHitObjectGetCurrentTimeNV,
  894. EOpReorderThreadNV,
  895. EOpFetchMicroTriangleVertexPositionNV,
  896. EOpFetchMicroTriangleVertexBarycentricNV,
  897. // HLSL operations
  898. //
  899. EOpClip, // discard if input value < 0
  900. EOpIsFinite,
  901. EOpLog10, // base 10 log
  902. EOpRcp, // 1/x
  903. EOpSaturate, // clamp from 0 to 1
  904. EOpSinCos, // sin and cos in out parameters
  905. EOpGenMul, // mul(x,y) on any of mat/vec/scalars
  906. EOpDst, // x = 1, y=src0.y * src1.y, z=src0.z, w=src1.w
  907. EOpInterlockedAdd, // atomic ops, but uses [optional] out arg instead of return
  908. EOpInterlockedAnd, // ...
  909. EOpInterlockedCompareExchange, // ...
  910. EOpInterlockedCompareStore, // ...
  911. EOpInterlockedExchange, // ...
  912. EOpInterlockedMax, // ...
  913. EOpInterlockedMin, // ...
  914. EOpInterlockedOr, // ...
  915. EOpInterlockedXor, // ...
  916. EOpAllMemoryBarrierWithGroupSync, // memory barriers without non-hlsl AST equivalents
  917. EOpDeviceMemoryBarrier, // ...
  918. EOpDeviceMemoryBarrierWithGroupSync, // ...
  919. EOpWorkgroupMemoryBarrier, // ...
  920. EOpWorkgroupMemoryBarrierWithGroupSync, // ...
  921. EOpEvaluateAttributeSnapped, // InterpolateAtOffset with int position on 16x16 grid
  922. EOpF32tof16, // HLSL conversion: half of a PackHalf2x16
  923. EOpF16tof32, // HLSL conversion: half of an UnpackHalf2x16
  924. EOpLit, // HLSL lighting coefficient vector
  925. EOpTextureBias, // HLSL texture bias: will be lowered to EOpTexture
  926. EOpAsDouble, // slightly different from EOpUint64BitsToDouble
  927. EOpD3DCOLORtoUBYTE4, // convert and swizzle 4-component color to UBYTE4 range
  928. EOpMethodSample, // Texture object methods. These are translated to existing
  929. EOpMethodSampleBias, // AST methods, and exist to represent HLSL semantics until that
  930. EOpMethodSampleCmp, // translation is performed. See HlslParseContext::decomposeSampleMethods().
  931. EOpMethodSampleCmpLevelZero, // ...
  932. EOpMethodSampleGrad, // ...
  933. EOpMethodSampleLevel, // ...
  934. EOpMethodLoad, // ...
  935. EOpMethodGetDimensions, // ...
  936. EOpMethodGetSamplePosition, // ...
  937. EOpMethodGather, // ...
  938. EOpMethodCalculateLevelOfDetail, // ...
  939. EOpMethodCalculateLevelOfDetailUnclamped, // ...
  940. // Load already defined above for textures
  941. EOpMethodLoad2, // Structure buffer object methods. These are translated to existing
  942. EOpMethodLoad3, // AST methods, and exist to represent HLSL semantics until that
  943. EOpMethodLoad4, // translation is performed. See HlslParseContext::decomposeSampleMethods().
  944. EOpMethodStore, // ...
  945. EOpMethodStore2, // ...
  946. EOpMethodStore3, // ...
  947. EOpMethodStore4, // ...
  948. EOpMethodIncrementCounter, // ...
  949. EOpMethodDecrementCounter, // ...
  950. // EOpMethodAppend is defined for geo shaders below
  951. EOpMethodConsume,
  952. // SM5 texture methods
  953. EOpMethodGatherRed, // These are covered under the above EOpMethodSample comment about
  954. EOpMethodGatherGreen, // translation to existing AST opcodes. They exist temporarily
  955. EOpMethodGatherBlue, // because HLSL arguments are slightly different.
  956. EOpMethodGatherAlpha, // ...
  957. EOpMethodGatherCmp, // ...
  958. EOpMethodGatherCmpRed, // ...
  959. EOpMethodGatherCmpGreen, // ...
  960. EOpMethodGatherCmpBlue, // ...
  961. EOpMethodGatherCmpAlpha, // ...
  962. // geometry methods
  963. EOpMethodAppend, // Geometry shader methods
  964. EOpMethodRestartStrip, // ...
  965. // matrix
  966. EOpMatrixSwizzle, // select multiple matrix components (non-column)
  967. // SM6 wave ops
  968. EOpWaveGetLaneCount, // Will decompose to gl_SubgroupSize.
  969. EOpWaveGetLaneIndex, // Will decompose to gl_SubgroupInvocationID.
  970. EOpWaveActiveCountBits, // Will decompose to subgroupBallotBitCount(subgroupBallot()).
  971. EOpWavePrefixCountBits, // Will decompose to subgroupBallotInclusiveBitCount(subgroupBallot()).
  972. // Shader Clock Ops
  973. EOpReadClockSubgroupKHR,
  974. EOpReadClockDeviceKHR,
  975. // GL_EXT_ray_tracing_position_fetch
  976. EOpRayQueryGetIntersectionTriangleVertexPositionsEXT,
  977. // Shader tile image ops
  978. EOpStencilAttachmentReadEXT, // Fragment only
  979. EOpDepthAttachmentReadEXT, // Fragment only
  980. // Image processing
  981. EOpImageSampleWeightedQCOM,
  982. EOpImageBoxFilterQCOM,
  983. EOpImageBlockMatchSADQCOM,
  984. EOpImageBlockMatchSSDQCOM,
  985. };
  986. enum TLinkType {
  987. ELinkNone,
  988. ELinkExport,
  989. };
  990. class TIntermTraverser;
  991. class TIntermOperator;
  992. class TIntermAggregate;
  993. class TIntermUnary;
  994. class TIntermBinary;
  995. class TIntermConstantUnion;
  996. class TIntermSelection;
  997. class TIntermSwitch;
  998. class TIntermBranch;
  999. class TIntermTyped;
  1000. class TIntermMethod;
  1001. class TIntermSymbol;
  1002. class TIntermLoop;
  1003. } // end namespace glslang
  1004. //
  1005. // Base class for the tree nodes
  1006. //
  1007. // (Put outside the glslang namespace, as it's used as part of the external interface.)
  1008. //
  1009. class TIntermNode {
  1010. public:
  1011. POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
  1012. TIntermNode() { loc.init(); }
  1013. virtual const glslang::TSourceLoc& getLoc() const { return loc; }
  1014. virtual void setLoc(const glslang::TSourceLoc& l) { loc = l; }
  1015. virtual void traverse(glslang::TIntermTraverser*) = 0;
  1016. virtual glslang::TIntermTyped* getAsTyped() { return nullptr; }
  1017. virtual glslang::TIntermOperator* getAsOperator() { return nullptr; }
  1018. virtual glslang::TIntermConstantUnion* getAsConstantUnion() { return nullptr; }
  1019. virtual glslang::TIntermAggregate* getAsAggregate() { return nullptr; }
  1020. virtual glslang::TIntermUnary* getAsUnaryNode() { return nullptr; }
  1021. virtual glslang::TIntermBinary* getAsBinaryNode() { return nullptr; }
  1022. virtual glslang::TIntermSelection* getAsSelectionNode() { return nullptr; }
  1023. virtual glslang::TIntermSwitch* getAsSwitchNode() { return nullptr; }
  1024. virtual glslang::TIntermMethod* getAsMethodNode() { return nullptr; }
  1025. virtual glslang::TIntermSymbol* getAsSymbolNode() { return nullptr; }
  1026. virtual glslang::TIntermBranch* getAsBranchNode() { return nullptr; }
  1027. virtual glslang::TIntermLoop* getAsLoopNode() { return nullptr; }
  1028. virtual const glslang::TIntermTyped* getAsTyped() const { return nullptr; }
  1029. virtual const glslang::TIntermOperator* getAsOperator() const { return nullptr; }
  1030. virtual const glslang::TIntermConstantUnion* getAsConstantUnion() const { return nullptr; }
  1031. virtual const glslang::TIntermAggregate* getAsAggregate() const { return nullptr; }
  1032. virtual const glslang::TIntermUnary* getAsUnaryNode() const { return nullptr; }
  1033. virtual const glslang::TIntermBinary* getAsBinaryNode() const { return nullptr; }
  1034. virtual const glslang::TIntermSelection* getAsSelectionNode() const { return nullptr; }
  1035. virtual const glslang::TIntermSwitch* getAsSwitchNode() const { return nullptr; }
  1036. virtual const glslang::TIntermMethod* getAsMethodNode() const { return nullptr; }
  1037. virtual const glslang::TIntermSymbol* getAsSymbolNode() const { return nullptr; }
  1038. virtual const glslang::TIntermBranch* getAsBranchNode() const { return nullptr; }
  1039. virtual const glslang::TIntermLoop* getAsLoopNode() const { return nullptr; }
  1040. virtual ~TIntermNode() { }
  1041. protected:
  1042. TIntermNode(const TIntermNode&);
  1043. TIntermNode& operator=(const TIntermNode&);
  1044. glslang::TSourceLoc loc;
  1045. };
  1046. namespace glslang {
  1047. //
  1048. // This is just to help yacc.
  1049. //
  1050. struct TIntermNodePair {
  1051. TIntermNode* node1;
  1052. TIntermNode* node2;
  1053. };
  1054. //
  1055. // Intermediate class for nodes that have a type.
  1056. //
  1057. class TIntermTyped : public TIntermNode {
  1058. public:
  1059. TIntermTyped(const TType& t) { type.shallowCopy(t); }
  1060. TIntermTyped(TBasicType basicType) { TType bt(basicType); type.shallowCopy(bt); }
  1061. virtual TIntermTyped* getAsTyped() { return this; }
  1062. virtual const TIntermTyped* getAsTyped() const { return this; }
  1063. virtual void setType(const TType& t) { type.shallowCopy(t); }
  1064. virtual const TType& getType() const { return type; }
  1065. virtual TType& getWritableType() { return type; }
  1066. virtual TBasicType getBasicType() const { return type.getBasicType(); }
  1067. virtual TQualifier& getQualifier() { return type.getQualifier(); }
  1068. virtual const TQualifier& getQualifier() const { return type.getQualifier(); }
  1069. virtual TArraySizes* getArraySizes() { return type.getArraySizes(); }
  1070. virtual const TArraySizes* getArraySizes() const { return type.getArraySizes(); }
  1071. virtual void propagatePrecision(TPrecisionQualifier);
  1072. virtual int getVectorSize() const { return type.getVectorSize(); }
  1073. virtual int getMatrixCols() const { return type.getMatrixCols(); }
  1074. virtual int getMatrixRows() const { return type.getMatrixRows(); }
  1075. virtual bool isMatrix() const { return type.isMatrix(); }
  1076. virtual bool isArray() const { return type.isArray(); }
  1077. virtual bool isVector() const { return type.isVector(); }
  1078. virtual bool isScalar() const { return type.isScalar(); }
  1079. virtual bool isStruct() const { return type.isStruct(); }
  1080. virtual bool isFloatingDomain() const { return type.isFloatingDomain(); }
  1081. virtual bool isIntegerDomain() const { return type.isIntegerDomain(); }
  1082. bool isAtomic() const { return type.isAtomic(); }
  1083. bool isReference() const { return type.isReference(); }
  1084. TString getCompleteString(bool enhanced = false) const { return type.getCompleteString(enhanced); }
  1085. protected:
  1086. TIntermTyped& operator=(const TIntermTyped&);
  1087. TType type;
  1088. };
  1089. //
  1090. // Handle for, do-while, and while loops.
  1091. //
  1092. class TIntermLoop : public TIntermNode {
  1093. public:
  1094. TIntermLoop(TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) :
  1095. body(aBody),
  1096. test(aTest),
  1097. terminal(aTerminal),
  1098. first(testFirst),
  1099. unroll(false),
  1100. dontUnroll(false),
  1101. dependency(0),
  1102. minIterations(0),
  1103. maxIterations(iterationsInfinite),
  1104. iterationMultiple(1),
  1105. peelCount(0),
  1106. partialCount(0)
  1107. { }
  1108. virtual TIntermLoop* getAsLoopNode() { return this; }
  1109. virtual const TIntermLoop* getAsLoopNode() const { return this; }
  1110. virtual void traverse(TIntermTraverser*);
  1111. TIntermNode* getBody() const { return body; }
  1112. TIntermTyped* getTest() const { return test; }
  1113. TIntermTyped* getTerminal() const { return terminal; }
  1114. bool testFirst() const { return first; }
  1115. void setUnroll() { unroll = true; }
  1116. void setDontUnroll() {
  1117. dontUnroll = true;
  1118. peelCount = 0;
  1119. partialCount = 0;
  1120. }
  1121. bool getUnroll() const { return unroll; }
  1122. bool getDontUnroll() const { return dontUnroll; }
  1123. static const unsigned int dependencyInfinite = 0xFFFFFFFF;
  1124. static const unsigned int iterationsInfinite = 0xFFFFFFFF;
  1125. void setLoopDependency(int d) { dependency = d; }
  1126. int getLoopDependency() const { return dependency; }
  1127. void setMinIterations(unsigned int v) { minIterations = v; }
  1128. unsigned int getMinIterations() const { return minIterations; }
  1129. void setMaxIterations(unsigned int v) { maxIterations = v; }
  1130. unsigned int getMaxIterations() const { return maxIterations; }
  1131. void setIterationMultiple(unsigned int v) { iterationMultiple = v; }
  1132. unsigned int getIterationMultiple() const { return iterationMultiple; }
  1133. void setPeelCount(unsigned int v) {
  1134. peelCount = v;
  1135. dontUnroll = false;
  1136. }
  1137. unsigned int getPeelCount() const { return peelCount; }
  1138. void setPartialCount(unsigned int v) {
  1139. partialCount = v;
  1140. dontUnroll = false;
  1141. }
  1142. unsigned int getPartialCount() const { return partialCount; }
  1143. protected:
  1144. TIntermNode* body; // code to loop over
  1145. TIntermTyped* test; // exit condition associated with loop, could be 0 for 'for' loops
  1146. TIntermTyped* terminal; // exists for for-loops
  1147. bool first; // true for while and for, not for do-while
  1148. bool unroll; // true if unroll requested
  1149. bool dontUnroll; // true if request to not unroll
  1150. unsigned int dependency; // loop dependency hint; 0 means not set or unknown
  1151. unsigned int minIterations; // as per the SPIR-V specification
  1152. unsigned int maxIterations; // as per the SPIR-V specification
  1153. unsigned int iterationMultiple; // as per the SPIR-V specification
  1154. unsigned int peelCount; // as per the SPIR-V specification
  1155. unsigned int partialCount; // as per the SPIR-V specification
  1156. };
  1157. //
  1158. // Handle case, break, continue, return, and kill.
  1159. //
  1160. class TIntermBranch : public TIntermNode {
  1161. public:
  1162. TIntermBranch(TOperator op, TIntermTyped* e) :
  1163. flowOp(op),
  1164. expression(e) { }
  1165. virtual TIntermBranch* getAsBranchNode() { return this; }
  1166. virtual const TIntermBranch* getAsBranchNode() const { return this; }
  1167. virtual void traverse(TIntermTraverser*);
  1168. TOperator getFlowOp() const { return flowOp; }
  1169. TIntermTyped* getExpression() const { return expression; }
  1170. void setExpression(TIntermTyped* pExpression) { expression = pExpression; }
  1171. void updatePrecision(TPrecisionQualifier parentPrecision);
  1172. protected:
  1173. TOperator flowOp;
  1174. TIntermTyped* expression;
  1175. };
  1176. //
  1177. // Represent method names before seeing their calling signature
  1178. // or resolving them to operations. Just an expression as the base object
  1179. // and a textural name.
  1180. //
  1181. class TIntermMethod : public TIntermTyped {
  1182. public:
  1183. TIntermMethod(TIntermTyped* o, const TType& t, const TString& m) : TIntermTyped(t), object(o), method(m) { }
  1184. virtual TIntermMethod* getAsMethodNode() { return this; }
  1185. virtual const TIntermMethod* getAsMethodNode() const { return this; }
  1186. virtual const TString& getMethodName() const { return method; }
  1187. virtual TIntermTyped* getObject() const { return object; }
  1188. virtual void traverse(TIntermTraverser*);
  1189. void setExport() { linkType = ELinkExport; }
  1190. protected:
  1191. TIntermTyped* object;
  1192. TString method;
  1193. TLinkType linkType;
  1194. };
  1195. //
  1196. // Nodes that correspond to symbols or constants in the source code.
  1197. //
  1198. class TIntermSymbol : public TIntermTyped {
  1199. public:
  1200. // if symbol is initialized as symbol(sym), the memory comes from the pool allocator of sym. If sym comes from
  1201. // per process threadPoolAllocator, then it causes increased memory usage per compile
  1202. // it is essential to use "symbol = sym" to assign to symbol
  1203. TIntermSymbol(long long i, const TString& n, const TType& t)
  1204. : TIntermTyped(t), id(i), flattenSubset(-1), constSubtree(nullptr) { name = n; }
  1205. virtual long long getId() const { return id; }
  1206. virtual void changeId(long long i) { id = i; }
  1207. virtual const TString& getName() const { return name; }
  1208. virtual void traverse(TIntermTraverser*);
  1209. virtual TIntermSymbol* getAsSymbolNode() { return this; }
  1210. virtual const TIntermSymbol* getAsSymbolNode() const { return this; }
  1211. void setConstArray(const TConstUnionArray& c) { constArray = c; }
  1212. const TConstUnionArray& getConstArray() const { return constArray; }
  1213. void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
  1214. TIntermTyped* getConstSubtree() const { return constSubtree; }
  1215. void setFlattenSubset(int subset) { flattenSubset = subset; }
  1216. virtual const TString& getAccessName() const;
  1217. int getFlattenSubset() const { return flattenSubset; } // -1 means full object
  1218. // This is meant for cases where a node has already been constructed, and
  1219. // later on, it becomes necessary to switch to a different symbol.
  1220. virtual void switchId(long long newId) { id = newId; }
  1221. protected:
  1222. long long id; // the unique id of the symbol this node represents
  1223. int flattenSubset; // how deeply the flattened object rooted at id has been dereferenced
  1224. TString name; // the name of the symbol this node represents
  1225. TConstUnionArray constArray; // if the symbol is a front-end compile-time constant, this is its value
  1226. TIntermTyped* constSubtree;
  1227. };
  1228. class TIntermConstantUnion : public TIntermTyped {
  1229. public:
  1230. TIntermConstantUnion(const TConstUnionArray& ua, const TType& t) : TIntermTyped(t), constArray(ua), literal(false) { }
  1231. const TConstUnionArray& getConstArray() const { return constArray; }
  1232. virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
  1233. virtual const TIntermConstantUnion* getAsConstantUnion() const { return this; }
  1234. virtual void traverse(TIntermTraverser*);
  1235. virtual TIntermTyped* fold(TOperator, const TIntermTyped*) const;
  1236. virtual TIntermTyped* fold(TOperator, const TType&) const;
  1237. void setLiteral() { literal = true; }
  1238. void setExpression() { literal = false; }
  1239. bool isLiteral() const { return literal; }
  1240. protected:
  1241. TIntermConstantUnion& operator=(const TIntermConstantUnion&);
  1242. const TConstUnionArray constArray;
  1243. bool literal; // true if node represents a literal in the source code
  1244. };
  1245. // Represent the independent aspects of a texturing TOperator
  1246. struct TCrackedTextureOp {
  1247. bool query;
  1248. bool proj;
  1249. bool lod;
  1250. bool fetch;
  1251. bool offset;
  1252. bool offsets;
  1253. bool gather;
  1254. bool grad;
  1255. bool subpass;
  1256. bool lodClamp;
  1257. bool fragMask;
  1258. bool attachmentEXT;
  1259. };
  1260. //
  1261. // Intermediate class for node types that hold operators.
  1262. //
  1263. class TIntermOperator : public TIntermTyped {
  1264. public:
  1265. virtual TIntermOperator* getAsOperator() { return this; }
  1266. virtual const TIntermOperator* getAsOperator() const { return this; }
  1267. TOperator getOp() const { return op; }
  1268. void setOp(TOperator newOp) { op = newOp; }
  1269. bool modifiesState() const;
  1270. bool isConstructor() const;
  1271. bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
  1272. bool isSampling() const { return op > EOpSamplingGuardBegin && op < EOpSamplingGuardEnd; }
  1273. bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; }
  1274. bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; }
  1275. bool isImageFootprint() const { return op > EOpImageFootprintGuardBegin && op < EOpImageFootprintGuardEnd; }
  1276. bool isSparseImage() const { return op == EOpSparseImageLoad; }
  1277. bool isSubgroup() const { return op > EOpSubgroupGuardStart && op < EOpSubgroupGuardStop; }
  1278. void setOperationPrecision(TPrecisionQualifier p) { operationPrecision = p; }
  1279. TPrecisionQualifier getOperationPrecision() const { return operationPrecision != EpqNone ?
  1280. operationPrecision :
  1281. type.getQualifier().precision; }
  1282. TString getCompleteString() const
  1283. {
  1284. TString cs = type.getCompleteString();
  1285. if (getOperationPrecision() != type.getQualifier().precision) {
  1286. cs += ", operation at ";
  1287. cs += GetPrecisionQualifierString(getOperationPrecision());
  1288. }
  1289. return cs;
  1290. }
  1291. // Crack the op into the individual dimensions of texturing operation.
  1292. void crackTexture(TSampler sampler, TCrackedTextureOp& cracked) const
  1293. {
  1294. cracked.query = false;
  1295. cracked.proj = false;
  1296. cracked.lod = false;
  1297. cracked.fetch = false;
  1298. cracked.offset = false;
  1299. cracked.offsets = false;
  1300. cracked.gather = false;
  1301. cracked.grad = false;
  1302. cracked.subpass = false;
  1303. cracked.attachmentEXT = false;
  1304. cracked.lodClamp = false;
  1305. cracked.fragMask = false;
  1306. switch (op) {
  1307. case EOpImageQuerySize:
  1308. case EOpImageQuerySamples:
  1309. case EOpTextureQuerySize:
  1310. case EOpTextureQueryLod:
  1311. case EOpTextureQueryLevels:
  1312. case EOpTextureQuerySamples:
  1313. case EOpSparseTexelsResident:
  1314. cracked.query = true;
  1315. break;
  1316. case EOpTexture:
  1317. case EOpSparseTexture:
  1318. break;
  1319. case EOpTextureProj:
  1320. cracked.proj = true;
  1321. break;
  1322. case EOpTextureLod:
  1323. case EOpSparseTextureLod:
  1324. cracked.lod = true;
  1325. break;
  1326. case EOpTextureOffset:
  1327. case EOpSparseTextureOffset:
  1328. cracked.offset = true;
  1329. break;
  1330. case EOpTextureFetch:
  1331. case EOpSparseTextureFetch:
  1332. cracked.fetch = true;
  1333. if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
  1334. cracked.lod = true;
  1335. break;
  1336. case EOpTextureFetchOffset:
  1337. case EOpSparseTextureFetchOffset:
  1338. cracked.fetch = true;
  1339. cracked.offset = true;
  1340. if (sampler.is1D() || (sampler.dim == Esd2D && ! sampler.isMultiSample()) || sampler.dim == Esd3D)
  1341. cracked.lod = true;
  1342. break;
  1343. case EOpTextureProjOffset:
  1344. cracked.offset = true;
  1345. cracked.proj = true;
  1346. break;
  1347. case EOpTextureLodOffset:
  1348. case EOpSparseTextureLodOffset:
  1349. cracked.offset = true;
  1350. cracked.lod = true;
  1351. break;
  1352. case EOpTextureProjLod:
  1353. cracked.lod = true;
  1354. cracked.proj = true;
  1355. break;
  1356. case EOpTextureProjLodOffset:
  1357. cracked.offset = true;
  1358. cracked.lod = true;
  1359. cracked.proj = true;
  1360. break;
  1361. case EOpTextureGrad:
  1362. case EOpSparseTextureGrad:
  1363. cracked.grad = true;
  1364. break;
  1365. case EOpTextureGradOffset:
  1366. case EOpSparseTextureGradOffset:
  1367. cracked.grad = true;
  1368. cracked.offset = true;
  1369. break;
  1370. case EOpTextureProjGrad:
  1371. cracked.grad = true;
  1372. cracked.proj = true;
  1373. break;
  1374. case EOpTextureProjGradOffset:
  1375. cracked.grad = true;
  1376. cracked.offset = true;
  1377. cracked.proj = true;
  1378. break;
  1379. case EOpTextureClamp:
  1380. case EOpSparseTextureClamp:
  1381. cracked.lodClamp = true;
  1382. break;
  1383. case EOpTextureOffsetClamp:
  1384. case EOpSparseTextureOffsetClamp:
  1385. cracked.offset = true;
  1386. cracked.lodClamp = true;
  1387. break;
  1388. case EOpTextureGradClamp:
  1389. case EOpSparseTextureGradClamp:
  1390. cracked.grad = true;
  1391. cracked.lodClamp = true;
  1392. break;
  1393. case EOpTextureGradOffsetClamp:
  1394. case EOpSparseTextureGradOffsetClamp:
  1395. cracked.grad = true;
  1396. cracked.offset = true;
  1397. cracked.lodClamp = true;
  1398. break;
  1399. case EOpTextureGather:
  1400. case EOpSparseTextureGather:
  1401. cracked.gather = true;
  1402. break;
  1403. case EOpTextureGatherOffset:
  1404. case EOpSparseTextureGatherOffset:
  1405. cracked.gather = true;
  1406. cracked.offset = true;
  1407. break;
  1408. case EOpTextureGatherOffsets:
  1409. case EOpSparseTextureGatherOffsets:
  1410. cracked.gather = true;
  1411. cracked.offsets = true;
  1412. break;
  1413. case EOpTextureGatherLod:
  1414. case EOpSparseTextureGatherLod:
  1415. cracked.gather = true;
  1416. cracked.lod = true;
  1417. break;
  1418. case EOpTextureGatherLodOffset:
  1419. case EOpSparseTextureGatherLodOffset:
  1420. cracked.gather = true;
  1421. cracked.offset = true;
  1422. cracked.lod = true;
  1423. break;
  1424. case EOpTextureGatherLodOffsets:
  1425. case EOpSparseTextureGatherLodOffsets:
  1426. cracked.gather = true;
  1427. cracked.offsets = true;
  1428. cracked.lod = true;
  1429. break;
  1430. case EOpImageLoadLod:
  1431. case EOpImageStoreLod:
  1432. case EOpSparseImageLoadLod:
  1433. cracked.lod = true;
  1434. break;
  1435. case EOpFragmentMaskFetch:
  1436. cracked.subpass = sampler.dim == EsdSubpass;
  1437. cracked.fragMask = true;
  1438. break;
  1439. case EOpFragmentFetch:
  1440. cracked.subpass = sampler.dim == EsdSubpass;
  1441. cracked.fragMask = true;
  1442. break;
  1443. case EOpImageSampleFootprintNV:
  1444. break;
  1445. case EOpImageSampleFootprintClampNV:
  1446. cracked.lodClamp = true;
  1447. break;
  1448. case EOpImageSampleFootprintLodNV:
  1449. cracked.lod = true;
  1450. break;
  1451. case EOpImageSampleFootprintGradNV:
  1452. cracked.grad = true;
  1453. break;
  1454. case EOpImageSampleFootprintGradClampNV:
  1455. cracked.lodClamp = true;
  1456. cracked.grad = true;
  1457. break;
  1458. case EOpSubpassLoad:
  1459. case EOpSubpassLoadMS:
  1460. cracked.subpass = true;
  1461. break;
  1462. case EOpColorAttachmentReadEXT:
  1463. cracked.attachmentEXT = true;
  1464. break;
  1465. default:
  1466. break;
  1467. }
  1468. }
  1469. protected:
  1470. TIntermOperator(TOperator o) : TIntermTyped(EbtFloat), op(o), operationPrecision(EpqNone) {}
  1471. TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o), operationPrecision(EpqNone) {}
  1472. TOperator op;
  1473. // The result precision is in the inherited TType, and is usually meant to be both
  1474. // the operation precision and the result precision. However, some more complex things,
  1475. // like built-in function calls, distinguish between the two, in which case non-EqpNone
  1476. // 'operationPrecision' overrides the result precision as far as operation precision
  1477. // is concerned.
  1478. TPrecisionQualifier operationPrecision;
  1479. };
  1480. //
  1481. // Nodes for all the basic binary math operators.
  1482. //
  1483. class TIntermBinary : public TIntermOperator {
  1484. public:
  1485. TIntermBinary(TOperator o) : TIntermOperator(o) {}
  1486. virtual void traverse(TIntermTraverser*);
  1487. virtual void setLeft(TIntermTyped* n) { left = n; }
  1488. virtual void setRight(TIntermTyped* n) { right = n; }
  1489. virtual TIntermTyped* getLeft() const { return left; }
  1490. virtual TIntermTyped* getRight() const { return right; }
  1491. virtual TIntermBinary* getAsBinaryNode() { return this; }
  1492. virtual const TIntermBinary* getAsBinaryNode() const { return this; }
  1493. virtual void updatePrecision();
  1494. protected:
  1495. TIntermTyped* left;
  1496. TIntermTyped* right;
  1497. };
  1498. //
  1499. // Nodes for unary math operators.
  1500. //
  1501. class TIntermUnary : public TIntermOperator {
  1502. public:
  1503. TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(nullptr) {}
  1504. TIntermUnary(TOperator o) : TIntermOperator(o), operand(nullptr) {}
  1505. virtual void traverse(TIntermTraverser*);
  1506. virtual void setOperand(TIntermTyped* o) { operand = o; }
  1507. virtual TIntermTyped* getOperand() { return operand; }
  1508. virtual const TIntermTyped* getOperand() const { return operand; }
  1509. virtual TIntermUnary* getAsUnaryNode() { return this; }
  1510. virtual const TIntermUnary* getAsUnaryNode() const { return this; }
  1511. virtual void updatePrecision();
  1512. void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
  1513. const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
  1514. protected:
  1515. TIntermTyped* operand;
  1516. TSpirvInstruction spirvInst;
  1517. };
  1518. typedef TVector<TIntermNode*> TIntermSequence;
  1519. typedef TVector<TStorageQualifier> TQualifierList;
  1520. //
  1521. // Nodes that operate on an arbitrary sized set of children.
  1522. //
  1523. class TIntermAggregate : public TIntermOperator {
  1524. public:
  1525. TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(nullptr) { }
  1526. TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(nullptr) { }
  1527. ~TIntermAggregate() { delete pragmaTable; }
  1528. virtual TIntermAggregate* getAsAggregate() { return this; }
  1529. virtual const TIntermAggregate* getAsAggregate() const { return this; }
  1530. virtual void updatePrecision();
  1531. virtual void setOperator(TOperator o) { op = o; }
  1532. virtual TIntermSequence& getSequence() { return sequence; }
  1533. virtual const TIntermSequence& getSequence() const { return sequence; }
  1534. virtual void setName(const TString& n) { name = n; }
  1535. virtual const TString& getName() const { return name; }
  1536. virtual void traverse(TIntermTraverser*);
  1537. virtual void setUserDefined() { userDefined = true; }
  1538. virtual bool isUserDefined() { return userDefined; }
  1539. virtual TQualifierList& getQualifierList() { return qualifier; }
  1540. virtual const TQualifierList& getQualifierList() const { return qualifier; }
  1541. void setOptimize(bool o) { optimize = o; }
  1542. void setDebug(bool d) { debug = d; }
  1543. bool getOptimize() const { return optimize; }
  1544. bool getDebug() const { return debug; }
  1545. void setPragmaTable(const TPragmaTable& pTable);
  1546. const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
  1547. void setSpirvInstruction(const TSpirvInstruction& inst) { spirvInst = inst; }
  1548. const TSpirvInstruction& getSpirvInstruction() const { return spirvInst; }
  1549. void setLinkType(TLinkType l) { linkType = l; }
  1550. TLinkType getLinkType() const { return linkType; }
  1551. protected:
  1552. TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
  1553. TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
  1554. TIntermSequence sequence;
  1555. TQualifierList qualifier;
  1556. TString name;
  1557. bool userDefined; // used for user defined function names
  1558. bool optimize;
  1559. bool debug;
  1560. TPragmaTable* pragmaTable;
  1561. TSpirvInstruction spirvInst;
  1562. TLinkType linkType = ELinkNone;
  1563. };
  1564. //
  1565. // For if tests.
  1566. //
  1567. class TIntermSelection : public TIntermTyped {
  1568. public:
  1569. TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
  1570. TIntermTyped(EbtVoid), condition(cond), trueBlock(trueB), falseBlock(falseB),
  1571. shortCircuit(true),
  1572. flatten(false), dontFlatten(false) {}
  1573. TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
  1574. TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB),
  1575. shortCircuit(true),
  1576. flatten(false), dontFlatten(false) {}
  1577. virtual void traverse(TIntermTraverser*);
  1578. virtual TIntermTyped* getCondition() const { return condition; }
  1579. virtual void setCondition(TIntermTyped* c) { condition = c; }
  1580. virtual TIntermNode* getTrueBlock() const { return trueBlock; }
  1581. virtual void setTrueBlock(TIntermTyped* tb) { trueBlock = tb; }
  1582. virtual TIntermNode* getFalseBlock() const { return falseBlock; }
  1583. virtual void setFalseBlock(TIntermTyped* fb) { falseBlock = fb; }
  1584. virtual TIntermSelection* getAsSelectionNode() { return this; }
  1585. virtual const TIntermSelection* getAsSelectionNode() const { return this; }
  1586. void setNoShortCircuit() { shortCircuit = false; }
  1587. bool getShortCircuit() const { return shortCircuit; }
  1588. void setFlatten() { flatten = true; }
  1589. void setDontFlatten() { dontFlatten = true; }
  1590. bool getFlatten() const { return flatten; }
  1591. bool getDontFlatten() const { return dontFlatten; }
  1592. protected:
  1593. TIntermTyped* condition;
  1594. TIntermNode* trueBlock;
  1595. TIntermNode* falseBlock;
  1596. bool shortCircuit; // normally all if-then-else and all GLSL ?: short-circuit, but HLSL ?: does not
  1597. bool flatten; // true if flatten requested
  1598. bool dontFlatten; // true if requested to not flatten
  1599. };
  1600. //
  1601. // For switch statements. Designed use is that a switch will have sequence of nodes
  1602. // that are either case/default nodes or a *single* node that represents all the code
  1603. // in between (if any) consecutive case/defaults. So, a traversal need only deal with
  1604. // 0 or 1 nodes per case/default statement.
  1605. //
  1606. class TIntermSwitch : public TIntermNode {
  1607. public:
  1608. TIntermSwitch(TIntermTyped* cond, TIntermAggregate* b) : condition(cond), body(b),
  1609. flatten(false), dontFlatten(false) {}
  1610. virtual void traverse(TIntermTraverser*);
  1611. virtual TIntermNode* getCondition() const { return condition; }
  1612. virtual TIntermAggregate* getBody() const { return body; }
  1613. virtual TIntermSwitch* getAsSwitchNode() { return this; }
  1614. virtual const TIntermSwitch* getAsSwitchNode() const { return this; }
  1615. void setFlatten() { flatten = true; }
  1616. void setDontFlatten() { dontFlatten = true; }
  1617. bool getFlatten() const { return flatten; }
  1618. bool getDontFlatten() const { return dontFlatten; }
  1619. protected:
  1620. TIntermTyped* condition;
  1621. TIntermAggregate* body;
  1622. bool flatten; // true if flatten requested
  1623. bool dontFlatten; // true if requested to not flatten
  1624. };
  1625. enum TVisit
  1626. {
  1627. EvPreVisit,
  1628. EvInVisit,
  1629. EvPostVisit
  1630. };
  1631. //
  1632. // For traversing the tree. User should derive from this,
  1633. // put their traversal specific data in it, and then pass
  1634. // it to a Traverse method.
  1635. //
  1636. // When using this, just fill in the methods for nodes you want visited.
  1637. // Return false from a pre-visit to skip visiting that node's subtree.
  1638. //
  1639. // Explicitly set postVisit to true if you want post visiting, otherwise,
  1640. // filled in methods will only be called at pre-visit time (before processing
  1641. // the subtree). Similarly for inVisit for in-order visiting of nodes with
  1642. // multiple children.
  1643. //
  1644. // If you only want post-visits, explicitly turn off preVisit (and inVisit)
  1645. // and turn on postVisit.
  1646. //
  1647. // In general, for the visit*() methods, return true from interior nodes
  1648. // to have the traversal continue on to children.
  1649. //
  1650. // If you process children yourself, or don't want them processed, return false.
  1651. //
  1652. class TIntermTraverser {
  1653. public:
  1654. POOL_ALLOCATOR_NEW_DELETE(glslang::GetThreadPoolAllocator())
  1655. TIntermTraverser(bool preVisit = true, bool inVisit = false, bool postVisit = false, bool rightToLeft = false) :
  1656. preVisit(preVisit),
  1657. inVisit(inVisit),
  1658. postVisit(postVisit),
  1659. rightToLeft(rightToLeft),
  1660. depth(0),
  1661. maxDepth(0) { }
  1662. virtual ~TIntermTraverser() { }
  1663. virtual void visitSymbol(TIntermSymbol*) { }
  1664. virtual void visitConstantUnion(TIntermConstantUnion*) { }
  1665. virtual bool visitBinary(TVisit, TIntermBinary*) { return true; }
  1666. virtual bool visitUnary(TVisit, TIntermUnary*) { return true; }
  1667. virtual bool visitSelection(TVisit, TIntermSelection*) { return true; }
  1668. virtual bool visitAggregate(TVisit, TIntermAggregate*) { return true; }
  1669. virtual bool visitLoop(TVisit, TIntermLoop*) { return true; }
  1670. virtual bool visitBranch(TVisit, TIntermBranch*) { return true; }
  1671. virtual bool visitSwitch(TVisit, TIntermSwitch*) { return true; }
  1672. int getMaxDepth() const { return maxDepth; }
  1673. void incrementDepth(TIntermNode *current)
  1674. {
  1675. depth++;
  1676. maxDepth = (std::max)(maxDepth, depth);
  1677. path.push_back(current);
  1678. }
  1679. void decrementDepth()
  1680. {
  1681. depth--;
  1682. path.pop_back();
  1683. }
  1684. TIntermNode *getParentNode()
  1685. {
  1686. return path.size() == 0 ? nullptr : path.back();
  1687. }
  1688. const bool preVisit;
  1689. const bool inVisit;
  1690. const bool postVisit;
  1691. const bool rightToLeft;
  1692. protected:
  1693. TIntermTraverser& operator=(TIntermTraverser&);
  1694. int depth;
  1695. int maxDepth;
  1696. // All the nodes from root to the current node's parent during traversing.
  1697. TVector<TIntermNode *> path;
  1698. };
  1699. // KHR_vulkan_glsl says "Two arrays sized with specialization constants are the same type only if
  1700. // sized with the same symbol, involving no operations"
  1701. inline bool SameSpecializationConstants(TIntermTyped* node1, TIntermTyped* node2)
  1702. {
  1703. return node1->getAsSymbolNode() && node2->getAsSymbolNode() &&
  1704. node1->getAsSymbolNode()->getId() == node2->getAsSymbolNode()->getId();
  1705. }
  1706. } // end namespace glslang
  1707. #endif // __INTERMEDIATE_H