intermediate.h 57 KB

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