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