hlslParseables.cpp 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  1. //
  2. // Copyright (C) 2016 LunarG, Inc.
  3. //
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions
  8. // are met:
  9. //
  10. // Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. //
  13. // Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following
  15. // disclaimer in the documentation and/or other materials provided
  16. // with the distribution.
  17. //
  18. // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
  19. // contributors may be used to endorse or promote products derived
  20. // from this software without specific prior written permission.
  21. //
  22. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  30. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. // POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. //
  36. // Create strings that declare built-in definitions, add built-ins programmatically
  37. // that cannot be expressed in the strings, and establish mappings between
  38. // built-in functions and operators.
  39. //
  40. // Where to put a built-in:
  41. // TBuiltInParseablesHlsl::initialize(version,profile) context-independent textual built-ins; add them to the right string
  42. // TBuiltInParseablesHlsl::initialize(resources,...) context-dependent textual built-ins; add them to the right string
  43. // TBuiltInParseablesHlsl::identifyBuiltIns(...,symbolTable) context-independent programmatic additions/mappings to the symbol table,
  44. // including identifying what extensions are needed if a version does not allow a symbol
  45. // TBuiltInParseablesHlsl::identifyBuiltIns(...,symbolTable, resources) context-dependent programmatic additions/mappings to the
  46. // symbol table, including identifying what extensions are needed if a version does
  47. // not allow a symbol
  48. //
  49. #include "hlslParseables.h"
  50. #include "hlslParseHelper.h"
  51. #include <cctype>
  52. #include <utility>
  53. #include <algorithm>
  54. namespace { // anonymous namespace functions
  55. // arg order queries
  56. bool IsSamplerType(const char argType) { return argType == 'S' || argType == 's'; }
  57. bool IsArrayed(const char argOrder) { return argOrder == '@' || argOrder == '&' || argOrder == '#'; }
  58. bool IsTextureNonMS(const char argOrder) { return argOrder == '%'; }
  59. bool IsSubpassInput(const char argOrder) { return argOrder == '[' || argOrder == ']'; }
  60. bool IsArrayedTexture(const char argOrder) { return argOrder == '@'; }
  61. bool IsTextureMS(const char argOrder) { return argOrder == '$' || argOrder == '&'; }
  62. bool IsMS(const char argOrder) { return IsTextureMS(argOrder) || argOrder == ']'; }
  63. bool IsBuffer(const char argOrder) { return argOrder == '*' || argOrder == '~'; }
  64. bool IsImage(const char argOrder) { return argOrder == '!' || argOrder == '#' || argOrder == '~'; }
  65. bool IsTextureType(const char argOrder)
  66. {
  67. return IsTextureNonMS(argOrder) || IsArrayedTexture(argOrder) ||
  68. IsTextureMS(argOrder) || IsBuffer(argOrder) || IsImage(argOrder);
  69. }
  70. // Reject certain combinations that are illegal sample methods. For example,
  71. // 3D arrays.
  72. bool IsIllegalSample(const glslang::TString& name, const char* argOrder, int dim0)
  73. {
  74. const bool isArrayed = IsArrayed(*argOrder);
  75. const bool isMS = IsTextureMS(*argOrder);
  76. const bool isBuffer = IsBuffer(*argOrder);
  77. // there are no 3D arrayed textures, or 3D SampleCmp(LevelZero)
  78. if (dim0 == 3 && (isArrayed || name == "SampleCmp" || name == "SampleCmpLevelZero"))
  79. return true;
  80. const int numArgs = int(std::count(argOrder, argOrder + strlen(argOrder), ',')) + 1;
  81. // Reject invalid offset forms with cubemaps
  82. if (dim0 == 4) {
  83. if ((name == "Sample" && numArgs >= 4) ||
  84. (name == "SampleBias" && numArgs >= 5) ||
  85. (name == "SampleCmp" && numArgs >= 5) ||
  86. (name == "SampleCmpLevelZero" && numArgs >= 5) ||
  87. (name == "SampleGrad" && numArgs >= 6) ||
  88. (name == "SampleLevel" && numArgs >= 5))
  89. return true;
  90. }
  91. const bool isGather =
  92. (name == "Gather" ||
  93. name == "GatherRed" ||
  94. name == "GatherGreen" ||
  95. name == "GatherBlue" ||
  96. name == "GatherAlpha");
  97. const bool isGatherCmp =
  98. (name == "GatherCmp" ||
  99. name == "GatherCmpRed" ||
  100. name == "GatherCmpGreen" ||
  101. name == "GatherCmpBlue" ||
  102. name == "GatherCmpAlpha");
  103. // Reject invalid Gathers
  104. if (isGather || isGatherCmp) {
  105. if (dim0 == 1 || dim0 == 3) // there are no 1D or 3D gathers
  106. return true;
  107. // no offset on cube or cube array gathers
  108. if (dim0 == 4) {
  109. if ((isGather && numArgs > 3) || (isGatherCmp && numArgs > 4))
  110. return true;
  111. }
  112. }
  113. // Reject invalid Loads
  114. if (name == "Load" && dim0 == 4)
  115. return true; // Load does not support any cubemaps, arrayed or not.
  116. // Multisample formats are only 2D and 2Darray
  117. if (isMS && dim0 != 2)
  118. return true;
  119. // Buffer are only 1D
  120. if (isBuffer && dim0 != 1)
  121. return true;
  122. return false;
  123. }
  124. // Return the number of the coordinate arg, if any
  125. int CoordinateArgPos(const glslang::TString& name, bool isTexture)
  126. {
  127. if (!isTexture || (name == "GetDimensions"))
  128. return -1; // has none
  129. else if (name == "Load")
  130. return 1;
  131. else
  132. return 2; // other texture methods are 2
  133. }
  134. // Some texture methods use an addition coordinate dimension for the mip
  135. bool HasMipInCoord(const glslang::TString& name, bool isMS, bool isBuffer, bool isImage)
  136. {
  137. return name == "Load" && !isMS && !isBuffer && !isImage;
  138. }
  139. // LOD calculations don't pass the array level in the coordinate.
  140. bool NoArrayCoord(const glslang::TString& name)
  141. {
  142. return name == "CalculateLevelOfDetail" || name == "CalculateLevelOfDetailUnclamped";
  143. }
  144. // Handle IO params marked with > or <
  145. const char* IoParam(glslang::TString& s, const char* nthArgOrder)
  146. {
  147. if (*nthArgOrder == '>') { // output params
  148. ++nthArgOrder;
  149. s.append("out ");
  150. } else if (*nthArgOrder == '<') { // input params
  151. ++nthArgOrder;
  152. s.append("in ");
  153. }
  154. return nthArgOrder;
  155. }
  156. // Handle repeated args
  157. void HandleRepeatArg(const char*& arg, const char*& prev, const char* current)
  158. {
  159. if (*arg == ',' || *arg == '\0')
  160. arg = prev;
  161. else
  162. prev = current;
  163. }
  164. // Return true for the end of a single argument key, which can be the end of the string, or
  165. // the comma separator.
  166. inline bool IsEndOfArg(const char* arg)
  167. {
  168. return arg == nullptr || *arg == '\0' || *arg == ',';
  169. }
  170. // If this is a fixed vector size, such as V3, return the size. Else return 0.
  171. int FixedVecSize(const char* arg)
  172. {
  173. while (!IsEndOfArg(arg)) {
  174. if (isdigit(*arg))
  175. return *arg - '0';
  176. ++arg;
  177. }
  178. return 0; // none found.
  179. }
  180. // Create and return a type name, using HLSL type conventions.
  181. //
  182. // order: S = scalar, V = vector, M = matrix
  183. // argType: F = float, D = double, I = int, U = uint, B = bool, S = sampler
  184. // dim0 = vector dimension, or matrix 1st dimension
  185. // dim1 = matrix 2nd dimension
  186. glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, const char* argType, int dim0, int dim1)
  187. {
  188. const bool isTranspose = (argOrder[0] == '^');
  189. const bool isTexture = IsTextureType(argOrder[0]);
  190. const bool isArrayed = IsArrayed(argOrder[0]);
  191. const bool isSampler = IsSamplerType(argType[0]);
  192. const bool isMS = IsMS(argOrder[0]);
  193. const bool isBuffer = IsBuffer(argOrder[0]);
  194. const bool isImage = IsImage(argOrder[0]);
  195. const bool isSubpass = IsSubpassInput(argOrder[0]);
  196. char type = *argType;
  197. if (isTranspose) { // Take transpose of matrix dimensions
  198. std::swap(dim0, dim1);
  199. } else if (isTexture || isSubpass) {
  200. if (type == 'F') // map base type to texture of that type.
  201. type = 'T'; // e.g, int -> itexture, uint -> utexture, etc.
  202. else if (type == 'I')
  203. type = 'i';
  204. else if (type == 'U')
  205. type = 'u';
  206. }
  207. if (isTranspose)
  208. ++argOrder;
  209. char order = *argOrder;
  210. switch (type) {
  211. case '-': s += "void"; break;
  212. case 'F': s += "float"; break;
  213. case 'D': s += "double"; break;
  214. case 'I': s += "int"; break;
  215. case 'U': s += "uint"; break;
  216. case 'L': s += "int64_t"; break;
  217. case 'M': s += "uint64_t"; break;
  218. case 'B': s += "bool"; break;
  219. case 'S': s += "sampler"; break;
  220. case 's': s += "SamplerComparisonState"; break;
  221. case 'T': s += ((isBuffer && isImage) ? "RWBuffer" :
  222. isSubpass ? "SubpassInput" :
  223. isBuffer ? "Buffer" :
  224. isImage ? "RWTexture" : "Texture"); break;
  225. case 'i': s += ((isBuffer && isImage) ? "RWBuffer" :
  226. isSubpass ? "SubpassInput" :
  227. isBuffer ? "Buffer" :
  228. isImage ? "RWTexture" : "Texture"); break;
  229. case 'u': s += ((isBuffer && isImage) ? "RWBuffer" :
  230. isSubpass ? "SubpassInput" :
  231. isBuffer ? "Buffer" :
  232. isImage ? "RWTexture" : "Texture"); break;
  233. default: s += "UNKNOWN_TYPE"; break;
  234. }
  235. if (isSubpass && isMS)
  236. s += "MS";
  237. // handle fixed vector sizes, such as float3, and only ever 3.
  238. const int fixedVecSize = FixedVecSize(argOrder);
  239. if (fixedVecSize != 0)
  240. dim0 = dim1 = fixedVecSize;
  241. const char dim0Char = ('0' + char(dim0));
  242. const char dim1Char = ('0' + char(dim1));
  243. // Add sampler dimensions
  244. if (isSampler || isTexture) {
  245. if ((order == 'V' || isTexture) && !isBuffer) {
  246. switch (dim0) {
  247. case 1: s += "1D"; break;
  248. case 2: s += (isMS ? "2DMS" : "2D"); break;
  249. case 3: s += "3D"; break;
  250. case 4: s += (type == 'S'? "CUBE" : "Cube"); break;
  251. default: s += "UNKNOWN_SAMPLER"; break;
  252. }
  253. }
  254. } else {
  255. // Non-sampler type:
  256. // verify dimensions
  257. if (((order == 'V' || order == 'M') && (dim0 < 1 || dim0 > 4)) ||
  258. (order == 'M' && (dim1 < 1 || dim1 > 4))) {
  259. s += "UNKNOWN_DIMENSION";
  260. return s;
  261. }
  262. switch (order) {
  263. case '-': break; // no dimensions for voids
  264. case 'S': break; // no dimensions on scalars
  265. case 'V':
  266. s += dim0Char;
  267. break;
  268. case 'M':
  269. s += dim0Char;
  270. s += 'x';
  271. s += dim1Char;
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. // handle arrayed textures
  278. if (isArrayed)
  279. s += "Array";
  280. switch (type) {
  281. case 'i': s += "<int"; s += dim0Char; s += ">"; break;
  282. case 'u': s += "<uint"; s += dim0Char; s += ">"; break;
  283. case 'T': s += "<float"; s += dim0Char; s += ">"; break;
  284. default: break;
  285. }
  286. return s;
  287. }
  288. // This rejects prototypes not normally valid for GLSL and it's way of finding
  289. // overloaded built-ins under implicit type conversion.
  290. //
  291. // It is possible that this is not needed, but that would require some tweaking
  292. // of other rules to get the same results.
  293. inline bool IsValid(const char* cname, char /* retOrder */, char /* retType */, char argOrder, char /* argType */, int dim0, int /* dim1 */)
  294. {
  295. const bool isVec = (argOrder == 'V');
  296. const std::string name(cname);
  297. // these do not have vec1 versions
  298. if (dim0 == 1 && (name == "normalize" || name == "reflect" || name == "refract"))
  299. return false;
  300. if (!IsTextureType(argOrder) && (isVec && dim0 == 1)) // avoid vec1
  301. return false;
  302. return true;
  303. }
  304. // return position of end of argument specifier
  305. inline const char* FindEndOfArg(const char* arg)
  306. {
  307. while (!IsEndOfArg(arg))
  308. ++arg;
  309. return *arg == '\0' ? nullptr : arg;
  310. }
  311. // Return pointer to beginning of Nth argument specifier in the string.
  312. inline const char* NthArg(const char* arg, int n)
  313. {
  314. for (int x=0; x<n && arg; ++x)
  315. if ((arg = FindEndOfArg(arg)) != nullptr)
  316. ++arg; // skip arg separator
  317. return arg;
  318. }
  319. inline void FindVectorMatrixBounds(const char* argOrder, int fixedVecSize, int& dim0Min, int& dim0Max, int& /*dim1Min*/, int& dim1Max)
  320. {
  321. for (int arg = 0; ; ++arg) {
  322. const char* nthArgOrder(NthArg(argOrder, arg));
  323. if (nthArgOrder == nullptr)
  324. break;
  325. else if (*nthArgOrder == 'V' || IsSubpassInput(*nthArgOrder))
  326. dim0Max = 4;
  327. else if (*nthArgOrder == 'M')
  328. dim0Max = dim1Max = 4;
  329. }
  330. if (fixedVecSize > 0) // handle fixed sized vectors
  331. dim0Min = dim0Max = fixedVecSize;
  332. }
  333. } // end anonymous namespace
  334. namespace glslang {
  335. TBuiltInParseablesHlsl::TBuiltInParseablesHlsl()
  336. {
  337. }
  338. //
  339. // Handle creation of mat*mat specially, since it doesn't fall conveniently out of
  340. // the generic prototype creation code below.
  341. //
  342. void TBuiltInParseablesHlsl::createMatTimesMat()
  343. {
  344. TString& s = commonBuiltins;
  345. for (int xRows = 1; xRows <=4; xRows++) {
  346. for (int xCols = 1; xCols <=4; xCols++) {
  347. const int yRows = xCols;
  348. for (int yCols = 1; yCols <=4; yCols++) {
  349. const int retRows = xRows;
  350. const int retCols = yCols;
  351. // Create a mat * mat of the appropriate dimensions
  352. AppendTypeName(s, "M", "F", retRows, retCols); // add return type
  353. s.append(" "); // space between type and name
  354. s.append("mul"); // intrinsic name
  355. s.append("("); // open paren
  356. AppendTypeName(s, "M", "F", xRows, xCols); // add X input
  357. s.append(", ");
  358. AppendTypeName(s, "M", "F", yRows, yCols); // add Y input
  359. s.append(");\n"); // close paren
  360. }
  361. // Create M*V
  362. AppendTypeName(s, "V", "F", xRows, 1); // add return type
  363. s.append(" "); // space between type and name
  364. s.append("mul"); // intrinsic name
  365. s.append("("); // open paren
  366. AppendTypeName(s, "M", "F", xRows, xCols); // add X input
  367. s.append(", ");
  368. AppendTypeName(s, "V", "F", xCols, 1); // add Y input
  369. s.append(");\n"); // close paren
  370. // Create V*M
  371. AppendTypeName(s, "V", "F", xCols, 1); // add return type
  372. s.append(" "); // space between type and name
  373. s.append("mul"); // intrinsic name
  374. s.append("("); // open paren
  375. AppendTypeName(s, "V", "F", xRows, 1); // add Y input
  376. s.append(", ");
  377. AppendTypeName(s, "M", "F", xRows, xCols); // add X input
  378. s.append(");\n"); // close paren
  379. }
  380. }
  381. }
  382. //
  383. // Add all context-independent built-in functions and variables that are present
  384. // for the given version and profile. Share common ones across stages, otherwise
  385. // make stage-specific entries.
  386. //
  387. // Most built-ins variables can be added as simple text strings. Some need to
  388. // be added programmatically, which is done later in IdentifyBuiltIns() below.
  389. //
  390. void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/)
  391. {
  392. static const EShLanguageMask EShLangAll = EShLanguageMask(EShLangCount - 1);
  393. // These are the actual stage masks defined in the documentation, in case they are
  394. // needed for future validation. For now, they are commented out, and set below
  395. // to EShLangAll, to allow any intrinsic to be used in any shader, which is legal
  396. // if it is not called.
  397. //
  398. // static const EShLanguageMask EShLangPSCS = EShLanguageMask(EShLangFragmentMask | EShLangComputeMask);
  399. // static const EShLanguageMask EShLangVSPSGS = EShLanguageMask(EShLangVertexMask | EShLangFragmentMask | EShLangGeometryMask);
  400. // static const EShLanguageMask EShLangCS = EShLangComputeMask;
  401. // static const EShLanguageMask EShLangPS = EShLangFragmentMask;
  402. // static const EShLanguageMask EShLangHS = EShLangTessControlMask;
  403. // This set uses EShLangAll for everything.
  404. static const EShLanguageMask EShLangPSCS = EShLangAll;
  405. static const EShLanguageMask EShLangVSPSGS = EShLangAll;
  406. static const EShLanguageMask EShLangCS = EShLangAll;
  407. static const EShLanguageMask EShLangPS = EShLangAll;
  408. static const EShLanguageMask EShLangHS = EShLangAll;
  409. static const EShLanguageMask EShLangGS = EShLangAll;
  410. // This structure encodes the prototype information for each HLSL intrinsic.
  411. // Because explicit enumeration would be cumbersome, it's procedurally generated.
  412. // orderKey can be:
  413. // S = scalar, V = vector, M = matrix, - = void
  414. // typekey can be:
  415. // D = double, F = float, U = uint, I = int, B = bool, S = sampler, s = shadowSampler, M = uint64_t, L = int64_t
  416. // An empty order or type key repeats the first one. E.g: SVM,, means 3 args each of SVM.
  417. // '>' as first letter of order creates an output parameter
  418. // '<' as first letter of order creates an input parameter
  419. // '^' as first letter of order takes transpose dimensions
  420. // '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc)
  421. // '@' as first letter of order creates arrayed texture of given type
  422. // '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures
  423. // '*' as first letter of order creates buffer object
  424. // '!' as first letter of order creates image object
  425. // '#' as first letter of order creates arrayed image object
  426. // '~' as first letter of order creates an image buffer object
  427. // '[' / ']' as first letter of order creates a SubpassInput/SubpassInputMS object
  428. static const struct {
  429. const char* name; // intrinsic name
  430. const char* retOrder; // return type key: empty matches order of 1st argument
  431. const char* retType; // return type key: empty matches type of 1st argument
  432. const char* argOrder; // argument order key
  433. const char* argType; // argument type key
  434. unsigned int stage; // stage mask
  435. bool method; // true if it's a method.
  436. } hlslIntrinsics[] = {
  437. // name retOrd retType argOrder argType stage mask method
  438. // ----------------------------------------------------------------------------------------------------------------
  439. { "abort", nullptr, nullptr, "-", "-", EShLangAll, false },
  440. { "abs", nullptr, nullptr, "SVM", "DFUI", EShLangAll, false },
  441. { "acos", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  442. { "all", "S", "B", "SVM", "BFIU", EShLangAll, false },
  443. { "AllMemoryBarrier", nullptr, nullptr, "-", "-", EShLangCS, false },
  444. { "AllMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
  445. { "any", "S", "B", "SVM", "BFIU", EShLangAll, false },
  446. { "asdouble", "S", "D", "S,", "UI,", EShLangAll, false },
  447. { "asdouble", "V2", "D", "V2,", "UI,", EShLangAll, false },
  448. { "asfloat", nullptr, "F", "SVM", "BFIU", EShLangAll, false },
  449. { "asin", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  450. { "asint", nullptr, "I", "SVM", "FIU", EShLangAll, false },
  451. { "asuint", nullptr, "U", "SVM", "FIU", EShLangAll, false },
  452. { "atan", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  453. { "atan2", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  454. { "ceil", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  455. { "CheckAccessFullyMapped", "S", "B" , "S", "U", EShLangPSCS, false },
  456. { "clamp", nullptr, nullptr, "SVM,,", "FUI,,", EShLangAll, false },
  457. { "clip", "-", "-", "SVM", "FUI", EShLangPS, false },
  458. { "cos", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  459. { "cosh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  460. { "countbits", nullptr, nullptr, "SV", "UI", EShLangAll, false },
  461. { "cross", nullptr, nullptr, "V3,", "F,", EShLangAll, false },
  462. { "D3DCOLORtoUBYTE4", "V4", "I", "V4", "F", EShLangAll, false },
  463. { "ddx", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  464. { "ddx_coarse", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  465. { "ddx_fine", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  466. { "ddy", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  467. { "ddy_coarse", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  468. { "ddy_fine", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  469. { "degrees", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  470. { "determinant", "S", "F", "M", "F", EShLangAll, false },
  471. { "DeviceMemoryBarrier", nullptr, nullptr, "-", "-", EShLangPSCS, false },
  472. { "DeviceMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
  473. { "distance", "S", "F", "SV,", "F,", EShLangAll, false },
  474. { "dot", "S", nullptr, "SV,", "FI,", EShLangAll, false },
  475. { "dst", nullptr, nullptr, "V4,", "F,", EShLangAll, false },
  476. // { "errorf", "-", "-", "", "", EShLangAll, false }, TODO: varargs
  477. { "EvaluateAttributeAtCentroid", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  478. { "EvaluateAttributeAtSample", nullptr, nullptr, "SVM,S", "F,U", EShLangPS, false },
  479. { "EvaluateAttributeSnapped", nullptr, nullptr, "SVM,V2", "F,I", EShLangPS, false },
  480. { "exp", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  481. { "exp2", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  482. { "f16tof32", nullptr, "F", "SV", "U", EShLangAll, false },
  483. { "f32tof16", nullptr, "U", "SV", "F", EShLangAll, false },
  484. { "faceforward", nullptr, nullptr, "V,,", "F,,", EShLangAll, false },
  485. { "firstbithigh", nullptr, nullptr, "SV", "UI", EShLangAll, false },
  486. { "firstbitlow", nullptr, nullptr, "SV", "UI", EShLangAll, false },
  487. { "floor", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  488. { "fma", nullptr, nullptr, "SVM,,", "D,,", EShLangAll, false },
  489. { "fmod", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  490. { "frac", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  491. { "frexp", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  492. { "fwidth", nullptr, nullptr, "SVM", "F", EShLangPS, false },
  493. { "GetRenderTargetSampleCount", "S", "U", "-", "-", EShLangAll, false },
  494. { "GetRenderTargetSamplePosition", "V2", "F", "V1", "I", EShLangAll, false },
  495. { "GroupMemoryBarrier", nullptr, nullptr, "-", "-", EShLangCS, false },
  496. { "GroupMemoryBarrierWithGroupSync", nullptr, nullptr, "-", "-", EShLangCS, false },
  497. { "InterlockedAdd", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  498. { "InterlockedAdd", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  499. { "InterlockedAnd", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  500. { "InterlockedAnd", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  501. { "InterlockedCompareExchange", "-", "-", "SVM,,,>", "UI,,,", EShLangPSCS, false },
  502. { "InterlockedCompareStore", "-", "-", "SVM,,", "UI,,", EShLangPSCS, false },
  503. { "InterlockedExchange", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  504. { "InterlockedMax", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  505. { "InterlockedMax", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  506. { "InterlockedMin", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  507. { "InterlockedMin", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  508. { "InterlockedOr", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  509. { "InterlockedOr", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  510. { "InterlockedXor", "-", "-", "SVM,,>", "UI,,", EShLangPSCS, false },
  511. { "InterlockedXor", "-", "-", "SVM,", "UI,", EShLangPSCS, false },
  512. { "isfinite", nullptr, "B" , "SVM", "F", EShLangAll, false },
  513. { "isinf", nullptr, "B" , "SVM", "F", EShLangAll, false },
  514. { "isnan", nullptr, "B" , "SVM", "F", EShLangAll, false },
  515. { "ldexp", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  516. { "length", "S", "F", "SV", "F", EShLangAll, false },
  517. { "lerp", nullptr, nullptr, "VM,,", "F,,", EShLangAll, false },
  518. { "lerp", nullptr, nullptr, "SVM,,S", "F,,", EShLangAll, false },
  519. { "lit", "V4", "F", "S,,", "F,,", EShLangAll, false },
  520. { "log", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  521. { "log10", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  522. { "log2", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  523. { "mad", nullptr, nullptr, "SVM,,", "DFUI,,", EShLangAll, false },
  524. { "max", nullptr, nullptr, "SVM,", "FIU,", EShLangAll, false },
  525. { "min", nullptr, nullptr, "SVM,", "FIU,", EShLangAll, false },
  526. { "modf", nullptr, nullptr, "SVM,>", "FIU,", EShLangAll, false },
  527. { "msad4", "V4", "U", "S,V2,V4", "U,,", EShLangAll, false },
  528. { "mul", "S", nullptr, "S,S", "FI,", EShLangAll, false },
  529. { "mul", "V", nullptr, "S,V", "FI,", EShLangAll, false },
  530. { "mul", "M", nullptr, "S,M", "FI,", EShLangAll, false },
  531. { "mul", "V", nullptr, "V,S", "FI,", EShLangAll, false },
  532. { "mul", "S", nullptr, "V,V", "FI,", EShLangAll, false },
  533. { "mul", "M", nullptr, "M,S", "FI,", EShLangAll, false },
  534. // mat*mat form of mul is handled in createMatTimesMat()
  535. { "noise", "S", "F", "V", "F", EShLangPS, false },
  536. { "normalize", nullptr, nullptr, "V", "F", EShLangAll, false },
  537. { "pow", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  538. { "printf", nullptr, nullptr, "-", "-", EShLangAll, false },
  539. { "Process2DQuadTessFactorsAvg", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
  540. { "Process2DQuadTessFactorsMax", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
  541. { "Process2DQuadTessFactorsMin", "-", "-", "V4,V2,>V4,>V2,", "F,,,,", EShLangHS, false },
  542. { "ProcessIsolineTessFactors", "-", "-", "S,,>,>", "F,,,", EShLangHS, false },
  543. { "ProcessQuadTessFactorsAvg", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
  544. { "ProcessQuadTessFactorsMax", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
  545. { "ProcessQuadTessFactorsMin", "-", "-", "V4,S,>V4,>V2,", "F,,,,", EShLangHS, false },
  546. { "ProcessTriTessFactorsAvg", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
  547. { "ProcessTriTessFactorsMax", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
  548. { "ProcessTriTessFactorsMin", "-", "-", "V3,S,>V3,>S,", "F,,,,", EShLangHS, false },
  549. { "radians", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  550. { "rcp", nullptr, nullptr, "SVM", "FD", EShLangAll, false },
  551. { "reflect", nullptr, nullptr, "V,", "F,", EShLangAll, false },
  552. { "refract", nullptr, nullptr, "V,V,S", "F,,", EShLangAll, false },
  553. { "reversebits", nullptr, nullptr, "SV", "UI", EShLangAll, false },
  554. { "round", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  555. { "rsqrt", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  556. { "saturate", nullptr, nullptr , "SVM", "F", EShLangAll, false },
  557. { "sign", nullptr, nullptr, "SVM", "FI", EShLangAll, false },
  558. { "sin", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  559. { "sincos", "-", "-", "SVM,>,>", "F,,", EShLangAll, false },
  560. { "sinh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  561. { "smoothstep", nullptr, nullptr, "SVM,,", "F,,", EShLangAll, false },
  562. { "sqrt", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  563. { "step", nullptr, nullptr, "SVM,", "F,", EShLangAll, false },
  564. { "tan", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  565. { "tanh", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  566. { "tex1D", "V4", "F", "S,S", "S,F", EShLangPS, false },
  567. { "tex1D", "V4", "F", "S,S,V1,", "S,F,,", EShLangPS, false },
  568. { "tex1Dbias", "V4", "F", "S,V4", "S,F", EShLangPS, false },
  569. { "tex1Dgrad", "V4", "F", "S,,,", "S,F,,", EShLangPS, false },
  570. { "tex1Dlod", "V4", "F", "S,V4", "S,F", EShLangPS, false },
  571. { "tex1Dproj", "V4", "F", "S,V4", "S,F", EShLangPS, false },
  572. { "tex2D", "V4", "F", "V2,", "S,F", EShLangPS, false },
  573. { "tex2D", "V4", "F", "V2,,,", "S,F,,", EShLangPS, false },
  574. { "tex2Dbias", "V4", "F", "V2,V4", "S,F", EShLangPS, false },
  575. { "tex2Dgrad", "V4", "F", "V2,,,", "S,F,,", EShLangPS, false },
  576. { "tex2Dlod", "V4", "F", "V2,V4", "S,F", EShLangAll, false },
  577. { "tex2Dproj", "V4", "F", "V2,V4", "S,F", EShLangPS, false },
  578. { "tex3D", "V4", "F", "V3,", "S,F", EShLangPS, false },
  579. { "tex3D", "V4", "F", "V3,,,", "S,F,,", EShLangPS, false },
  580. { "tex3Dbias", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
  581. { "tex3Dgrad", "V4", "F", "V3,,,", "S,F,,", EShLangPS, false },
  582. { "tex3Dlod", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
  583. { "tex3Dproj", "V4", "F", "V3,V4", "S,F", EShLangPS, false },
  584. { "texCUBE", "V4", "F", "V4,V3", "S,F", EShLangPS, false },
  585. { "texCUBE", "V4", "F", "V4,V3,,", "S,F,,", EShLangPS, false },
  586. { "texCUBEbias", "V4", "F", "V4,", "S,F", EShLangPS, false },
  587. { "texCUBEgrad", "V4", "F", "V4,V3,,", "S,F,,", EShLangPS, false },
  588. { "texCUBElod", "V4", "F", "V4,", "S,F", EShLangPS, false },
  589. { "texCUBEproj", "V4", "F", "V4,", "S,F", EShLangPS, false },
  590. { "transpose", "^M", nullptr, "M", "FUIB", EShLangAll, false },
  591. { "trunc", nullptr, nullptr, "SVM", "F", EShLangAll, false },
  592. // Texture object methods. Return type can be overridden by shader declaration.
  593. // !O = no offset, O = offset
  594. { "Sample", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangPS, true },
  595. { "Sample", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangPS, true },
  596. { "SampleBias", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,S,F,", EShLangPS, true },
  597. { "SampleBias", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,S,F,,I", EShLangPS, true },
  598. // TODO: FXC accepts int/uint samplers here. unclear what that means.
  599. { "SampleCmp", /*!O*/ "S", "F", "%@,S,V,S", "FIU,s,F,", EShLangPS, true },
  600. { "SampleCmp", /* O*/ "S", "F", "%@,S,V,S,V", "FIU,s,F,,I", EShLangPS, true },
  601. // TODO: FXC accepts int/uint samplers here. unclear what that means.
  602. { "SampleCmpLevelZero", /*!O*/ "S", "F", "%@,S,V,S", "FIU,s,F,F", EShLangPS, true },
  603. { "SampleCmpLevelZero", /* O*/ "S", "F", "%@,S,V,S,V", "FIU,s,F,F,I", EShLangPS, true },
  604. { "SampleGrad", /*!O*/ "V4", nullptr, "%@,S,V,,", "FIU,S,F,,", EShLangAll, true },
  605. { "SampleGrad", /* O*/ "V4", nullptr, "%@,S,V,,,", "FIU,S,F,,,I", EShLangAll, true },
  606. { "SampleLevel", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,S,F,", EShLangAll, true },
  607. { "SampleLevel", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,S,F,,I", EShLangAll, true },
  608. { "Load", /*!O*/ "V4", nullptr, "%@,V", "FIU,I", EShLangAll, true },
  609. { "Load", /* O*/ "V4", nullptr, "%@,V,V", "FIU,I,I", EShLangAll, true },
  610. { "Load", /* +sampleidex*/ "V4", nullptr, "$&,V,S", "FIU,I,I", EShLangAll, true },
  611. { "Load", /* +samplindex, offset*/ "V4", nullptr, "$&,V,S,V", "FIU,I,I,I", EShLangAll, true },
  612. // RWTexture loads
  613. { "Load", "V4", nullptr, "!#,V", "FIU,I", EShLangAll, true },
  614. // (RW)Buffer loads
  615. { "Load", "V4", nullptr, "~*1,V", "FIU,I", EShLangAll, true },
  616. { "Gather", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
  617. { "Gather", /* O*/ "V4", nullptr, "%@,S,V,V", "FIU,S,F,I", EShLangAll, true },
  618. { "CalculateLevelOfDetail", "S", "F", "%@,S,V", "FUI,S,F", EShLangPS, true },
  619. { "CalculateLevelOfDetailUnclamped", "S", "F", "%@,S,V", "FUI,S,F", EShLangPS, true },
  620. { "GetSamplePosition", "V2", "F", "$&2,S", "FUI,I", EShLangVSPSGS,true },
  621. //
  622. // UINT Width
  623. // UINT MipLevel, UINT Width, UINT NumberOfLevels
  624. { "GetDimensions", /* 1D */ "-", "-", "%!~1,>S", "FUI,U", EShLangAll, true },
  625. { "GetDimensions", /* 1D */ "-", "-", "%!~1,>S", "FUI,F", EShLangAll, true },
  626. { "GetDimensions", /* 1D */ "-", "-", "%1,S,>S,", "FUI,U,,", EShLangAll, true },
  627. { "GetDimensions", /* 1D */ "-", "-", "%1,S,>S,", "FUI,U,F,", EShLangAll, true },
  628. // UINT Width, UINT Elements
  629. // UINT MipLevel, UINT Width, UINT Elements, UINT NumberOfLevels
  630. { "GetDimensions", /* 1DArray */ "-", "-", "@#1,>S,", "FUI,U,", EShLangAll, true },
  631. { "GetDimensions", /* 1DArray */ "-", "-", "@#1,>S,", "FUI,F,", EShLangAll, true },
  632. { "GetDimensions", /* 1DArray */ "-", "-", "@1,S,>S,,", "FUI,U,,,", EShLangAll, true },
  633. { "GetDimensions", /* 1DArray */ "-", "-", "@1,S,>S,,", "FUI,U,F,,", EShLangAll, true },
  634. // UINT Width, UINT Height
  635. // UINT MipLevel, UINT Width, UINT Height, UINT NumberOfLevels
  636. { "GetDimensions", /* 2D */ "-", "-", "%!2,>S,", "FUI,U,", EShLangAll, true },
  637. { "GetDimensions", /* 2D */ "-", "-", "%!2,>S,", "FUI,F,", EShLangAll, true },
  638. { "GetDimensions", /* 2D */ "-", "-", "%2,S,>S,,", "FUI,U,,,", EShLangAll, true },
  639. { "GetDimensions", /* 2D */ "-", "-", "%2,S,>S,,", "FUI,U,F,,", EShLangAll, true },
  640. // UINT Width, UINT Height, UINT Elements
  641. // UINT MipLevel, UINT Width, UINT Height, UINT Elements, UINT NumberOfLevels
  642. { "GetDimensions", /* 2DArray */ "-", "-", "@#2,>S,,", "FUI,U,,", EShLangAll, true },
  643. { "GetDimensions", /* 2DArray */ "-", "-", "@#2,>S,,", "FUI,F,F,F", EShLangAll, true },
  644. { "GetDimensions", /* 2DArray */ "-", "-", "@2,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
  645. { "GetDimensions", /* 2DArray */ "-", "-", "@2,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
  646. // UINT Width, UINT Height, UINT Depth
  647. // UINT MipLevel, UINT Width, UINT Height, UINT Depth, UINT NumberOfLevels
  648. { "GetDimensions", /* 3D */ "-", "-", "%!3,>S,,", "FUI,U,,", EShLangAll, true },
  649. { "GetDimensions", /* 3D */ "-", "-", "%!3,>S,,", "FUI,F,,", EShLangAll, true },
  650. { "GetDimensions", /* 3D */ "-", "-", "%3,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
  651. { "GetDimensions", /* 3D */ "-", "-", "%3,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
  652. // UINT Width, UINT Height
  653. // UINT MipLevel, UINT Width, UINT Height, UINT NumberOfLevels
  654. { "GetDimensions", /* Cube */ "-", "-", "%4,>S,", "FUI,U,", EShLangAll, true },
  655. { "GetDimensions", /* Cube */ "-", "-", "%4,>S,", "FUI,F,", EShLangAll, true },
  656. { "GetDimensions", /* Cube */ "-", "-", "%4,S,>S,,", "FUI,U,,,", EShLangAll, true },
  657. { "GetDimensions", /* Cube */ "-", "-", "%4,S,>S,,", "FUI,U,F,,", EShLangAll, true },
  658. // UINT Width, UINT Height, UINT Elements
  659. // UINT MipLevel, UINT Width, UINT Height, UINT Elements, UINT NumberOfLevels
  660. { "GetDimensions", /* CubeArray */ "-", "-", "@4,>S,,", "FUI,U,,", EShLangAll, true },
  661. { "GetDimensions", /* CubeArray */ "-", "-", "@4,>S,,", "FUI,F,,", EShLangAll, true },
  662. { "GetDimensions", /* CubeArray */ "-", "-", "@4,S,>S,,,", "FUI,U,,,,", EShLangAll, true },
  663. { "GetDimensions", /* CubeArray */ "-", "-", "@4,S,>S,,,", "FUI,U,F,,,", EShLangAll, true },
  664. // UINT Width, UINT Height, UINT Samples
  665. // UINT Width, UINT Height, UINT Elements, UINT Samples
  666. { "GetDimensions", /* 2DMS */ "-", "-", "$2,>S,,", "FUI,U,,", EShLangAll, true },
  667. { "GetDimensions", /* 2DMS */ "-", "-", "$2,>S,,", "FUI,U,,", EShLangAll, true },
  668. { "GetDimensions", /* 2DMSArray */ "-", "-", "&2,>S,,,", "FUI,U,,,", EShLangAll, true },
  669. { "GetDimensions", /* 2DMSArray */ "-", "-", "&2,>S,,,", "FUI,U,,,", EShLangAll, true },
  670. // SM5 texture methods
  671. { "GatherRed", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
  672. { "GatherRed", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
  673. { "GatherRed", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
  674. { "GatherRed", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
  675. { "GatherRed", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
  676. { "GatherGreen", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
  677. { "GatherGreen", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
  678. { "GatherGreen", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
  679. { "GatherGreen", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
  680. { "GatherGreen", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
  681. { "GatherBlue", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
  682. { "GatherBlue", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
  683. { "GatherBlue", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
  684. { "GatherBlue", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
  685. { "GatherBlue", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
  686. { "GatherAlpha", /*!O*/ "V4", nullptr, "%@,S,V", "FIU,S,F", EShLangAll, true },
  687. { "GatherAlpha", /* O*/ "V4", nullptr, "%@,S,V,", "FIU,S,F,I", EShLangAll, true },
  688. { "GatherAlpha", /* O, status*/ "V4", nullptr, "%@,S,V,,>S", "FIU,S,F,I,U", EShLangAll, true },
  689. { "GatherAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,,,,", "FIU,S,F,I,,,", EShLangAll, true },
  690. { "GatherAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,,,,,S", "FIU,S,F,I,,,,U", EShLangAll, true },
  691. { "GatherCmp", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
  692. { "GatherCmp", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
  693. { "GatherCmp", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
  694. { "GatherCmp", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
  695. { "GatherCmp", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,V,S","FIU,s,F,,I,,,,U",EShLangAll, true },
  696. { "GatherCmpRed", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
  697. { "GatherCmpRed", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
  698. { "GatherCmpRed", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
  699. { "GatherCmpRed", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
  700. { "GatherCmpRed", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,V,S","FIU,s,F,,I,,,,U",EShLangAll, true },
  701. { "GatherCmpGreen", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
  702. { "GatherCmpGreen", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
  703. { "GatherCmpGreen", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
  704. { "GatherCmpGreen", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
  705. { "GatherCmpGreen", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
  706. { "GatherCmpBlue", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
  707. { "GatherCmpBlue", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
  708. { "GatherCmpBlue", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
  709. { "GatherCmpBlue", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
  710. { "GatherCmpBlue", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
  711. { "GatherCmpAlpha", /*!O*/ "V4", nullptr, "%@,S,V,S", "FIU,s,F,", EShLangAll, true },
  712. { "GatherCmpAlpha", /* O*/ "V4", nullptr, "%@,S,V,S,V", "FIU,s,F,,I", EShLangAll, true },
  713. { "GatherCmpAlpha", /* O, status*/ "V4", nullptr, "%@,S,V,S,V,>S", "FIU,s,F,,I,U", EShLangAll, true },
  714. { "GatherCmpAlpha", /* O-4 */ "V4", nullptr, "%@,S,V,S,V,,,", "FIU,s,F,,I,,,", EShLangAll, true },
  715. { "GatherCmpAlpha", /* O-4, status */"V4", nullptr, "%@,S,V,S,V,,,,S","FIU,s,F,,I,,,,U",EShLangAll, true },
  716. // geometry methods
  717. { "Append", "-", "-", "-", "-", EShLangGS , true },
  718. { "RestartStrip", "-", "-", "-", "-", EShLangGS , true },
  719. // Methods for structurebuffers. TODO: wildcard type matching.
  720. { "Load", nullptr, nullptr, "-", "-", EShLangAll, true },
  721. { "Load2", nullptr, nullptr, "-", "-", EShLangAll, true },
  722. { "Load3", nullptr, nullptr, "-", "-", EShLangAll, true },
  723. { "Load4", nullptr, nullptr, "-", "-", EShLangAll, true },
  724. { "Store", nullptr, nullptr, "-", "-", EShLangAll, true },
  725. { "Store2", nullptr, nullptr, "-", "-", EShLangAll, true },
  726. { "Store3", nullptr, nullptr, "-", "-", EShLangAll, true },
  727. { "Store4", nullptr, nullptr, "-", "-", EShLangAll, true },
  728. { "GetDimensions", nullptr, nullptr, "-", "-", EShLangAll, true },
  729. { "InterlockedAdd", nullptr, nullptr, "-", "-", EShLangAll, true },
  730. { "InterlockedAnd", nullptr, nullptr, "-", "-", EShLangAll, true },
  731. { "InterlockedCompareExchange", nullptr, nullptr, "-", "-", EShLangAll, true },
  732. { "InterlockedCompareStore", nullptr, nullptr, "-", "-", EShLangAll, true },
  733. { "InterlockedExchange", nullptr, nullptr, "-", "-", EShLangAll, true },
  734. { "InterlockedMax", nullptr, nullptr, "-", "-", EShLangAll, true },
  735. { "InterlockedMin", nullptr, nullptr, "-", "-", EShLangAll, true },
  736. { "InterlockedOr", nullptr, nullptr, "-", "-", EShLangAll, true },
  737. { "InterlockedXor", nullptr, nullptr, "-", "-", EShLangAll, true },
  738. { "IncrementCounter", nullptr, nullptr, "-", "-", EShLangAll, true },
  739. { "DecrementCounter", nullptr, nullptr, "-", "-", EShLangAll, true },
  740. { "Consume", nullptr, nullptr, "-", "-", EShLangAll, true },
  741. // SM 6.0
  742. { "WaveIsFirstLane", "S", "B", "-", "-", EShLangPSCS, false},
  743. { "WaveGetLaneCount", "S", "U", "-", "-", EShLangPSCS, false},
  744. { "WaveGetLaneIndex", "S", "U", "-", "-", EShLangPSCS, false},
  745. { "WaveActiveAnyTrue", "S", "B", "S", "B", EShLangPSCS, false},
  746. { "WaveActiveAllTrue", "S", "B", "S", "B", EShLangPSCS, false},
  747. { "WaveActiveBallot", "V4", "U", "S", "B", EShLangPSCS, false},
  748. { "WaveReadLaneAt", nullptr, nullptr, "SV,S", "DFUI,U", EShLangPSCS, false},
  749. { "WaveReadLaneFirst", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  750. { "WaveActiveAllEqual", "S", "B", "SV", "DFUI", EShLangPSCS, false},
  751. { "WaveActiveAllEqualBool", "S", "B", "S", "B", EShLangPSCS, false},
  752. { "WaveActiveCountBits", "S", "U", "S", "B", EShLangPSCS, false},
  753. { "WaveActiveSum", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  754. { "WaveActiveProduct", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  755. { "WaveActiveBitAnd", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  756. { "WaveActiveBitOr", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  757. { "WaveActiveBitXor", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  758. { "WaveActiveMin", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  759. { "WaveActiveMax", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  760. { "WavePrefixSum", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  761. { "WavePrefixProduct", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  762. { "WavePrefixCountBits", "S", "U", "S", "B", EShLangPSCS, false},
  763. { "QuadReadAcrossX", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  764. { "QuadReadAcrossY", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  765. { "QuadReadAcrossDiagonal", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
  766. { "QuadReadLaneAt", nullptr, nullptr, "SV,S", "DFUI,U", EShLangPSCS, false},
  767. // Methods for subpass input objects
  768. { "SubpassLoad", "V4", nullptr, "[", "FIU", EShLangPS, true },
  769. { "SubpassLoad", "V4", nullptr, "],S", "FIU,I", EShLangPS, true },
  770. // Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet.
  771. { nullptr, nullptr, nullptr, nullptr, nullptr, 0, false },
  772. };
  773. // Create prototypes for the intrinsics. TODO: Avoid ranged based for until all compilers can handle it.
  774. for (int icount = 0; hlslIntrinsics[icount].name; ++icount) {
  775. const auto& intrinsic = hlslIntrinsics[icount];
  776. for (int stage = 0; stage < EShLangCount; ++stage) { // for each stage...
  777. if ((intrinsic.stage & (1<<stage)) == 0) // skip inapplicable stages
  778. continue;
  779. // reference to either the common builtins, or stage specific builtins.
  780. TString& s = (intrinsic.stage == EShLangAll) ? commonBuiltins : stageBuiltins[stage];
  781. for (const char* argOrder = intrinsic.argOrder; !IsEndOfArg(argOrder); ++argOrder) { // for each order...
  782. const bool isTexture = IsTextureType(*argOrder);
  783. const bool isArrayed = IsArrayed(*argOrder);
  784. const bool isMS = IsTextureMS(*argOrder);
  785. const bool isBuffer = IsBuffer(*argOrder);
  786. const bool isImage = IsImage(*argOrder);
  787. const bool mipInCoord = HasMipInCoord(intrinsic.name, isMS, isBuffer, isImage);
  788. const int fixedVecSize = FixedVecSize(argOrder);
  789. const int coordArg = CoordinateArgPos(intrinsic.name, isTexture);
  790. // calculate min and max vector and matrix dimensions
  791. int dim0Min = 1;
  792. int dim0Max = 1;
  793. int dim1Min = 1;
  794. int dim1Max = 1;
  795. FindVectorMatrixBounds(argOrder, fixedVecSize, dim0Min, dim0Max, dim1Min, dim1Max);
  796. for (const char* argType = intrinsic.argType; !IsEndOfArg(argType); ++argType) { // for each type...
  797. for (int dim0 = dim0Min; dim0 <= dim0Max; ++dim0) { // for each dim 0...
  798. for (int dim1 = dim1Min; dim1 <= dim1Max; ++dim1) { // for each dim 1...
  799. const char* retOrder = intrinsic.retOrder ? intrinsic.retOrder : argOrder;
  800. const char* retType = intrinsic.retType ? intrinsic.retType : argType;
  801. if (!IsValid(intrinsic.name, *retOrder, *retType, *argOrder, *argType, dim0, dim1))
  802. continue;
  803. // Reject some forms of sample methods that don't exist.
  804. if (isTexture && IsIllegalSample(intrinsic.name, argOrder, dim0))
  805. continue;
  806. AppendTypeName(s, retOrder, retType, dim0, dim1); // add return type
  807. s.append(" "); // space between type and name
  808. // methods have a prefix. TODO: it would be better as an invalid identifier character,
  809. // but that requires a scanner change.
  810. if (intrinsic.method)
  811. s.append(BUILTIN_PREFIX);
  812. s.append(intrinsic.name); // intrinsic name
  813. s.append("("); // open paren
  814. const char* prevArgOrder = nullptr;
  815. const char* prevArgType = nullptr;
  816. // Append argument types, if any.
  817. for (int arg = 0; ; ++arg) {
  818. const char* nthArgOrder(NthArg(argOrder, arg));
  819. const char* nthArgType(NthArg(argType, arg));
  820. if (nthArgOrder == nullptr || nthArgType == nullptr)
  821. break;
  822. // cube textures use vec3 coordinates
  823. int argDim0 = isTexture && arg > 0 ? std::min(dim0, 3) : dim0;
  824. s.append(arg > 0 ? ", ": ""); // comma separator if needed
  825. const char* orderBegin = nthArgOrder;
  826. nthArgOrder = IoParam(s, nthArgOrder);
  827. // Comma means use the previous argument order and type.
  828. HandleRepeatArg(nthArgOrder, prevArgOrder, orderBegin);
  829. HandleRepeatArg(nthArgType, prevArgType, nthArgType);
  830. // In case the repeated arg has its own I/O marker
  831. nthArgOrder = IoParam(s, nthArgOrder);
  832. // arrayed textures have one extra coordinate dimension, except for
  833. // the CalculateLevelOfDetail family.
  834. if (isArrayed && arg == coordArg && !NoArrayCoord(intrinsic.name))
  835. argDim0++;
  836. // Some texture methods use an addition arg dimension to hold mip
  837. if (arg == coordArg && mipInCoord)
  838. argDim0++;
  839. // For textures, the 1D case isn't a 1-vector, but a scalar.
  840. if (isTexture && argDim0 == 1 && arg > 0 && *nthArgOrder == 'V')
  841. nthArgOrder = "S";
  842. AppendTypeName(s, nthArgOrder, nthArgType, argDim0, dim1); // Add arguments
  843. }
  844. s.append(");\n"); // close paren and trailing semicolon
  845. } // dim 1 loop
  846. } // dim 0 loop
  847. } // arg type loop
  848. // skip over special characters
  849. if (isTexture && isalpha(argOrder[1]))
  850. ++argOrder;
  851. if (isdigit(argOrder[1]))
  852. ++argOrder;
  853. } // arg order loop
  854. if (intrinsic.stage == EShLangAll) // common builtins are only added once.
  855. break;
  856. }
  857. }
  858. createMatTimesMat(); // handle this case separately, for convenience
  859. // printf("Common:\n%s\n", getCommonString().c_str());
  860. // printf("Frag:\n%s\n", getStageString(EShLangFragment).c_str());
  861. // printf("Vertex:\n%s\n", getStageString(EShLangVertex).c_str());
  862. // printf("Geo:\n%s\n", getStageString(EShLangGeometry).c_str());
  863. // printf("TessCtrl:\n%s\n", getStageString(EShLangTessControl).c_str());
  864. // printf("TessEval:\n%s\n", getStageString(EShLangTessEvaluation).c_str());
  865. // printf("Compute:\n%s\n", getStageString(EShLangCompute).c_str());
  866. }
  867. //
  868. // Add context-dependent built-in functions and variables that are present
  869. // for the given version and profile. All the results are put into just the
  870. // commonBuiltins, because it is called for just a specific stage. So,
  871. // add stage-specific entries to the commonBuiltins, and only if that stage
  872. // was requested.
  873. //
  874. void TBuiltInParseablesHlsl::initialize(const TBuiltInResource& /*resources*/, int /*version*/, EProfile /*profile*/,
  875. const SpvVersion& /*spvVersion*/, EShLanguage /*language*/)
  876. {
  877. }
  878. //
  879. // Finish adding/processing context-independent built-in symbols.
  880. // 1) Programmatically add symbols that could not be added by simple text strings above.
  881. // 2) Map built-in functions to operators, for those that will turn into an operation node
  882. // instead of remaining a function call.
  883. // 3) Tag extension-related symbols added to their base version with their extensions, so
  884. // that if an early version has the extension turned off, there is an error reported on use.
  885. //
  886. void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/, EShLanguage /*language*/,
  887. TSymbolTable& symbolTable)
  888. {
  889. // symbolTable.relateToOperator("abort", EOpAbort);
  890. symbolTable.relateToOperator("abs", EOpAbs);
  891. symbolTable.relateToOperator("acos", EOpAcos);
  892. symbolTable.relateToOperator("all", EOpAll);
  893. symbolTable.relateToOperator("AllMemoryBarrier", EOpMemoryBarrier);
  894. symbolTable.relateToOperator("AllMemoryBarrierWithGroupSync", EOpAllMemoryBarrierWithGroupSync);
  895. symbolTable.relateToOperator("any", EOpAny);
  896. symbolTable.relateToOperator("asdouble", EOpAsDouble);
  897. symbolTable.relateToOperator("asfloat", EOpIntBitsToFloat);
  898. symbolTable.relateToOperator("asin", EOpAsin);
  899. symbolTable.relateToOperator("asint", EOpFloatBitsToInt);
  900. symbolTable.relateToOperator("asuint", EOpFloatBitsToUint);
  901. symbolTable.relateToOperator("atan", EOpAtan);
  902. symbolTable.relateToOperator("atan2", EOpAtan);
  903. symbolTable.relateToOperator("ceil", EOpCeil);
  904. // symbolTable.relateToOperator("CheckAccessFullyMapped");
  905. symbolTable.relateToOperator("clamp", EOpClamp);
  906. symbolTable.relateToOperator("clip", EOpClip);
  907. symbolTable.relateToOperator("cos", EOpCos);
  908. symbolTable.relateToOperator("cosh", EOpCosh);
  909. symbolTable.relateToOperator("countbits", EOpBitCount);
  910. symbolTable.relateToOperator("cross", EOpCross);
  911. symbolTable.relateToOperator("D3DCOLORtoUBYTE4", EOpD3DCOLORtoUBYTE4);
  912. symbolTable.relateToOperator("ddx", EOpDPdx);
  913. symbolTable.relateToOperator("ddx_coarse", EOpDPdxCoarse);
  914. symbolTable.relateToOperator("ddx_fine", EOpDPdxFine);
  915. symbolTable.relateToOperator("ddy", EOpDPdy);
  916. symbolTable.relateToOperator("ddy_coarse", EOpDPdyCoarse);
  917. symbolTable.relateToOperator("ddy_fine", EOpDPdyFine);
  918. symbolTable.relateToOperator("degrees", EOpDegrees);
  919. symbolTable.relateToOperator("determinant", EOpDeterminant);
  920. symbolTable.relateToOperator("DeviceMemoryBarrier", EOpDeviceMemoryBarrier);
  921. symbolTable.relateToOperator("DeviceMemoryBarrierWithGroupSync", EOpDeviceMemoryBarrierWithGroupSync);
  922. symbolTable.relateToOperator("distance", EOpDistance);
  923. symbolTable.relateToOperator("dot", EOpDot);
  924. symbolTable.relateToOperator("dst", EOpDst);
  925. // symbolTable.relateToOperator("errorf", EOpErrorf);
  926. symbolTable.relateToOperator("EvaluateAttributeAtCentroid", EOpInterpolateAtCentroid);
  927. symbolTable.relateToOperator("EvaluateAttributeAtSample", EOpInterpolateAtSample);
  928. symbolTable.relateToOperator("EvaluateAttributeSnapped", EOpEvaluateAttributeSnapped);
  929. symbolTable.relateToOperator("exp", EOpExp);
  930. symbolTable.relateToOperator("exp2", EOpExp2);
  931. symbolTable.relateToOperator("f16tof32", EOpF16tof32);
  932. symbolTable.relateToOperator("f32tof16", EOpF32tof16);
  933. symbolTable.relateToOperator("faceforward", EOpFaceForward);
  934. symbolTable.relateToOperator("firstbithigh", EOpFindMSB);
  935. symbolTable.relateToOperator("firstbitlow", EOpFindLSB);
  936. symbolTable.relateToOperator("floor", EOpFloor);
  937. symbolTable.relateToOperator("fma", EOpFma);
  938. symbolTable.relateToOperator("fmod", EOpMod);
  939. symbolTable.relateToOperator("frac", EOpFract);
  940. symbolTable.relateToOperator("frexp", EOpFrexp);
  941. symbolTable.relateToOperator("fwidth", EOpFwidth);
  942. // symbolTable.relateToOperator("GetRenderTargetSampleCount");
  943. // symbolTable.relateToOperator("GetRenderTargetSamplePosition");
  944. symbolTable.relateToOperator("GroupMemoryBarrier", EOpWorkgroupMemoryBarrier);
  945. symbolTable.relateToOperator("GroupMemoryBarrierWithGroupSync", EOpWorkgroupMemoryBarrierWithGroupSync);
  946. symbolTable.relateToOperator("InterlockedAdd", EOpInterlockedAdd);
  947. symbolTable.relateToOperator("InterlockedAnd", EOpInterlockedAnd);
  948. symbolTable.relateToOperator("InterlockedCompareExchange", EOpInterlockedCompareExchange);
  949. symbolTable.relateToOperator("InterlockedCompareStore", EOpInterlockedCompareStore);
  950. symbolTable.relateToOperator("InterlockedExchange", EOpInterlockedExchange);
  951. symbolTable.relateToOperator("InterlockedMax", EOpInterlockedMax);
  952. symbolTable.relateToOperator("InterlockedMin", EOpInterlockedMin);
  953. symbolTable.relateToOperator("InterlockedOr", EOpInterlockedOr);
  954. symbolTable.relateToOperator("InterlockedXor", EOpInterlockedXor);
  955. symbolTable.relateToOperator("isfinite", EOpIsFinite);
  956. symbolTable.relateToOperator("isinf", EOpIsInf);
  957. symbolTable.relateToOperator("isnan", EOpIsNan);
  958. symbolTable.relateToOperator("ldexp", EOpLdexp);
  959. symbolTable.relateToOperator("length", EOpLength);
  960. symbolTable.relateToOperator("lerp", EOpMix);
  961. symbolTable.relateToOperator("lit", EOpLit);
  962. symbolTable.relateToOperator("log", EOpLog);
  963. symbolTable.relateToOperator("log10", EOpLog10);
  964. symbolTable.relateToOperator("log2", EOpLog2);
  965. symbolTable.relateToOperator("mad", EOpFma);
  966. symbolTable.relateToOperator("max", EOpMax);
  967. symbolTable.relateToOperator("min", EOpMin);
  968. symbolTable.relateToOperator("modf", EOpModf);
  969. // symbolTable.relateToOperator("msad4", EOpMsad4);
  970. symbolTable.relateToOperator("mul", EOpGenMul);
  971. // symbolTable.relateToOperator("noise", EOpNoise); // TODO: check return type
  972. symbolTable.relateToOperator("normalize", EOpNormalize);
  973. symbolTable.relateToOperator("pow", EOpPow);
  974. symbolTable.relateToOperator("printf", EOpDebugPrintf);
  975. // symbolTable.relateToOperator("Process2DQuadTessFactorsAvg");
  976. // symbolTable.relateToOperator("Process2DQuadTessFactorsMax");
  977. // symbolTable.relateToOperator("Process2DQuadTessFactorsMin");
  978. // symbolTable.relateToOperator("ProcessIsolineTessFactors");
  979. // symbolTable.relateToOperator("ProcessQuadTessFactorsAvg");
  980. // symbolTable.relateToOperator("ProcessQuadTessFactorsMax");
  981. // symbolTable.relateToOperator("ProcessQuadTessFactorsMin");
  982. // symbolTable.relateToOperator("ProcessTriTessFactorsAvg");
  983. // symbolTable.relateToOperator("ProcessTriTessFactorsMax");
  984. // symbolTable.relateToOperator("ProcessTriTessFactorsMin");
  985. symbolTable.relateToOperator("radians", EOpRadians);
  986. symbolTable.relateToOperator("rcp", EOpRcp);
  987. symbolTable.relateToOperator("reflect", EOpReflect);
  988. symbolTable.relateToOperator("refract", EOpRefract);
  989. symbolTable.relateToOperator("reversebits", EOpBitFieldReverse);
  990. symbolTable.relateToOperator("round", EOpRound);
  991. symbolTable.relateToOperator("rsqrt", EOpInverseSqrt);
  992. symbolTable.relateToOperator("saturate", EOpSaturate);
  993. symbolTable.relateToOperator("sign", EOpSign);
  994. symbolTable.relateToOperator("sin", EOpSin);
  995. symbolTable.relateToOperator("sincos", EOpSinCos);
  996. symbolTable.relateToOperator("sinh", EOpSinh);
  997. symbolTable.relateToOperator("smoothstep", EOpSmoothStep);
  998. symbolTable.relateToOperator("sqrt", EOpSqrt);
  999. symbolTable.relateToOperator("step", EOpStep);
  1000. symbolTable.relateToOperator("tan", EOpTan);
  1001. symbolTable.relateToOperator("tanh", EOpTanh);
  1002. symbolTable.relateToOperator("tex1D", EOpTexture);
  1003. symbolTable.relateToOperator("tex1Dbias", EOpTextureBias);
  1004. symbolTable.relateToOperator("tex1Dgrad", EOpTextureGrad);
  1005. symbolTable.relateToOperator("tex1Dlod", EOpTextureLod);
  1006. symbolTable.relateToOperator("tex1Dproj", EOpTextureProj);
  1007. symbolTable.relateToOperator("tex2D", EOpTexture);
  1008. symbolTable.relateToOperator("tex2Dbias", EOpTextureBias);
  1009. symbolTable.relateToOperator("tex2Dgrad", EOpTextureGrad);
  1010. symbolTable.relateToOperator("tex2Dlod", EOpTextureLod);
  1011. symbolTable.relateToOperator("tex2Dproj", EOpTextureProj);
  1012. symbolTable.relateToOperator("tex3D", EOpTexture);
  1013. symbolTable.relateToOperator("tex3Dbias", EOpTextureBias);
  1014. symbolTable.relateToOperator("tex3Dgrad", EOpTextureGrad);
  1015. symbolTable.relateToOperator("tex3Dlod", EOpTextureLod);
  1016. symbolTable.relateToOperator("tex3Dproj", EOpTextureProj);
  1017. symbolTable.relateToOperator("texCUBE", EOpTexture);
  1018. symbolTable.relateToOperator("texCUBEbias", EOpTextureBias);
  1019. symbolTable.relateToOperator("texCUBEgrad", EOpTextureGrad);
  1020. symbolTable.relateToOperator("texCUBElod", EOpTextureLod);
  1021. symbolTable.relateToOperator("texCUBEproj", EOpTextureProj);
  1022. symbolTable.relateToOperator("transpose", EOpTranspose);
  1023. symbolTable.relateToOperator("trunc", EOpTrunc);
  1024. // Texture methods
  1025. symbolTable.relateToOperator(BUILTIN_PREFIX "Sample", EOpMethodSample);
  1026. symbolTable.relateToOperator(BUILTIN_PREFIX "SampleBias", EOpMethodSampleBias);
  1027. symbolTable.relateToOperator(BUILTIN_PREFIX "SampleCmp", EOpMethodSampleCmp);
  1028. symbolTable.relateToOperator(BUILTIN_PREFIX "SampleCmpLevelZero", EOpMethodSampleCmpLevelZero);
  1029. symbolTable.relateToOperator(BUILTIN_PREFIX "SampleGrad", EOpMethodSampleGrad);
  1030. symbolTable.relateToOperator(BUILTIN_PREFIX "SampleLevel", EOpMethodSampleLevel);
  1031. symbolTable.relateToOperator(BUILTIN_PREFIX "Load", EOpMethodLoad);
  1032. symbolTable.relateToOperator(BUILTIN_PREFIX "GetDimensions", EOpMethodGetDimensions);
  1033. symbolTable.relateToOperator(BUILTIN_PREFIX "GetSamplePosition", EOpMethodGetSamplePosition);
  1034. symbolTable.relateToOperator(BUILTIN_PREFIX "Gather", EOpMethodGather);
  1035. symbolTable.relateToOperator(BUILTIN_PREFIX "CalculateLevelOfDetail", EOpMethodCalculateLevelOfDetail);
  1036. symbolTable.relateToOperator(BUILTIN_PREFIX "CalculateLevelOfDetailUnclamped", EOpMethodCalculateLevelOfDetailUnclamped);
  1037. // Structure buffer methods (excluding associations already made above for texture methods w/ same name)
  1038. symbolTable.relateToOperator(BUILTIN_PREFIX "Load2", EOpMethodLoad2);
  1039. symbolTable.relateToOperator(BUILTIN_PREFIX "Load3", EOpMethodLoad3);
  1040. symbolTable.relateToOperator(BUILTIN_PREFIX "Load4", EOpMethodLoad4);
  1041. symbolTable.relateToOperator(BUILTIN_PREFIX "Store", EOpMethodStore);
  1042. symbolTable.relateToOperator(BUILTIN_PREFIX "Store2", EOpMethodStore2);
  1043. symbolTable.relateToOperator(BUILTIN_PREFIX "Store3", EOpMethodStore3);
  1044. symbolTable.relateToOperator(BUILTIN_PREFIX "Store4", EOpMethodStore4);
  1045. symbolTable.relateToOperator(BUILTIN_PREFIX "IncrementCounter", EOpMethodIncrementCounter);
  1046. symbolTable.relateToOperator(BUILTIN_PREFIX "DecrementCounter", EOpMethodDecrementCounter);
  1047. // Append is also a GS method: we don't add it twice
  1048. symbolTable.relateToOperator(BUILTIN_PREFIX "Consume", EOpMethodConsume);
  1049. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedAdd", EOpInterlockedAdd);
  1050. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedAnd", EOpInterlockedAnd);
  1051. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedCompareExchange", EOpInterlockedCompareExchange);
  1052. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedCompareStore", EOpInterlockedCompareStore);
  1053. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedExchange", EOpInterlockedExchange);
  1054. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedMax", EOpInterlockedMax);
  1055. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedMin", EOpInterlockedMin);
  1056. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedOr", EOpInterlockedOr);
  1057. symbolTable.relateToOperator(BUILTIN_PREFIX "InterlockedXor", EOpInterlockedXor);
  1058. // SM5 Texture methods
  1059. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherRed", EOpMethodGatherRed);
  1060. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherGreen", EOpMethodGatherGreen);
  1061. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherBlue", EOpMethodGatherBlue);
  1062. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherAlpha", EOpMethodGatherAlpha);
  1063. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmp", EOpMethodGatherCmpRed); // alias
  1064. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpRed", EOpMethodGatherCmpRed);
  1065. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpGreen", EOpMethodGatherCmpGreen);
  1066. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpBlue", EOpMethodGatherCmpBlue);
  1067. symbolTable.relateToOperator(BUILTIN_PREFIX "GatherCmpAlpha", EOpMethodGatherCmpAlpha);
  1068. // GS methods
  1069. symbolTable.relateToOperator(BUILTIN_PREFIX "Append", EOpMethodAppend);
  1070. symbolTable.relateToOperator(BUILTIN_PREFIX "RestartStrip", EOpMethodRestartStrip);
  1071. // Wave ops
  1072. symbolTable.relateToOperator("WaveIsFirstLane", EOpSubgroupElect);
  1073. symbolTable.relateToOperator("WaveGetLaneCount", EOpWaveGetLaneCount);
  1074. symbolTable.relateToOperator("WaveGetLaneIndex", EOpWaveGetLaneIndex);
  1075. symbolTable.relateToOperator("WaveActiveAnyTrue", EOpSubgroupAny);
  1076. symbolTable.relateToOperator("WaveActiveAllTrue", EOpSubgroupAll);
  1077. symbolTable.relateToOperator("WaveActiveBallot", EOpSubgroupBallot);
  1078. symbolTable.relateToOperator("WaveReadLaneFirst", EOpSubgroupBroadcastFirst);
  1079. symbolTable.relateToOperator("WaveReadLaneAt", EOpSubgroupShuffle);
  1080. symbolTable.relateToOperator("WaveActiveAllEqual", EOpSubgroupAllEqual);
  1081. symbolTable.relateToOperator("WaveActiveAllEqualBool", EOpSubgroupAllEqual);
  1082. symbolTable.relateToOperator("WaveActiveCountBits", EOpWaveActiveCountBits);
  1083. symbolTable.relateToOperator("WaveActiveSum", EOpSubgroupAdd);
  1084. symbolTable.relateToOperator("WaveActiveProduct", EOpSubgroupMul);
  1085. symbolTable.relateToOperator("WaveActiveBitAnd", EOpSubgroupAnd);
  1086. symbolTable.relateToOperator("WaveActiveBitOr", EOpSubgroupOr);
  1087. symbolTable.relateToOperator("WaveActiveBitXor", EOpSubgroupXor);
  1088. symbolTable.relateToOperator("WaveActiveMin", EOpSubgroupMin);
  1089. symbolTable.relateToOperator("WaveActiveMax", EOpSubgroupMax);
  1090. symbolTable.relateToOperator("WavePrefixSum", EOpSubgroupInclusiveAdd);
  1091. symbolTable.relateToOperator("WavePrefixProduct", EOpSubgroupInclusiveMul);
  1092. symbolTable.relateToOperator("WavePrefixCountBits", EOpWavePrefixCountBits);
  1093. symbolTable.relateToOperator("QuadReadAcrossX", EOpSubgroupQuadSwapHorizontal);
  1094. symbolTable.relateToOperator("QuadReadAcrossY", EOpSubgroupQuadSwapVertical);
  1095. symbolTable.relateToOperator("QuadReadAcrossDiagonal", EOpSubgroupQuadSwapDiagonal);
  1096. symbolTable.relateToOperator("QuadReadLaneAt", EOpSubgroupQuadBroadcast);
  1097. // Subpass input methods
  1098. symbolTable.relateToOperator(BUILTIN_PREFIX "SubpassLoad", EOpSubpassLoad);
  1099. symbolTable.relateToOperator(BUILTIN_PREFIX "SubpassLoadMS", EOpSubpassLoadMS);
  1100. }
  1101. //
  1102. // Add context-dependent (resource-specific) built-ins not handled by the above. These
  1103. // would be ones that need to be programmatically added because they cannot
  1104. // be added by simple text strings. For these, also
  1105. // 1) Map built-in functions to operators, for those that will turn into an operation node
  1106. // instead of remaining a function call.
  1107. // 2) Tag extension-related symbols added to their base version with their extensions, so
  1108. // that if an early version has the extension turned off, there is an error reported on use.
  1109. //
  1110. void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profile*/, const SpvVersion& /*spvVersion*/, EShLanguage /*language*/,
  1111. TSymbolTable& /*symbolTable*/, const TBuiltInResource& /*resources*/)
  1112. {
  1113. }
  1114. } // end namespace glslang