2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 // Copyright (C) 2020 Google, Inc.
6 // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
8 // All rights reserved.
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
14 // Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
17 // Redistributions in binary form must reproduce the above
18 // copyright notice, this list of conditions and the following
19 // disclaimer in the documentation and/or other materials provided
20 // with the distribution.
22 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
23 // contributors may be used to endorse or promote products derived
24 // from this software without specific prior written permission.
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 // POSSIBILITY OF SUCH DAMAGE.
41 // GLSL scanning, leveraging the scanning done by the preprocessor.
45 #include <unordered_map>
46 #include <unordered_set>
48 #include "../Include/Types.h"
49 #include "SymbolTable.h"
50 #include "ParseHelper.h"
51 #include "attribute.h"
52 #include "glslang_tab.cpp.h"
53 #include "ScanContext.h"
56 // preprocessor includes
57 #include "preprocessor/PpContext.h"
58 #include "preprocessor/PpTokens.h"
60 // Required to avoid missing prototype warnings for some compilers
61 int yylex(YYSTYPE*, glslang::TParseContext&);
65 // read past any white space
66 void TInputScanner::consumeWhiteSpace(bool& foundNonSpaceTab)
68 int c = peek(); // don't accidentally consume anything other than whitespace
69 while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
70 if (c == '\r' || c == '\n')
71 foundNonSpaceTab = true;
77 // return true if a comment was actually consumed
78 bool TInputScanner::consumeComment()
83 get(); // consume the '/'
87 // a '//' style comment
88 get(); // consume the second '/'
91 while (c != EndOfInput && c != '\\' && c != '\r' && c != '\n')
94 if (c == EndOfInput || c == '\r' || c == '\n') {
95 while (c == '\r' || c == '\n')
98 // we reached the end of the comment
101 // it's a '\', so we need to keep going, after skipping what's escaped
103 // read the skipped character
106 // if it's a two-character newline, skip both characters
107 if (c == '\r' && peek() == '\n')
113 // put back the last non-comment character
118 } else if (c == '*') {
120 // a '/*' style comment
121 get(); // consume the '*'
124 while (c != EndOfInput && c != '*')
129 break; // end of comment
130 // not end of comment
131 } else // end of input
137 // it's not a comment, put the '/' back
144 // skip whitespace, then skip a comment, rinse, repeat
145 void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
148 consumeWhiteSpace(foundNonSpaceTab);
150 // if not starting a comment now, then done
152 if (c != '/' || c == EndOfInput)
155 // skip potential comment
156 foundNonSpaceTab = true;
157 if (! consumeComment())
163 // Returns true if there was non-white space (e.g., a comment, newline) before the #version
164 // or no #version was found; otherwise, returns false. There is no error case, it always
165 // succeeds, but will leave version == 0 if no #version was found.
167 // Sets notFirstToken based on whether tokens (beyond white space and comments)
168 // appeared before the #version.
170 // N.B. does not attempt to leave input in any particular known state. The assumption
171 // is that scanning will start anew, following the rules for the chosen version/profile,
172 // and with a corresponding parsing context.
174 bool TInputScanner::scanVersion(int& version, EProfile& profile, bool& notFirstToken)
176 // This function doesn't have to get all the semantics correct,
177 // just find the #version if there is a correct one present.
178 // The preprocessor will have the responsibility of getting all the semantics right.
180 bool versionNotFirst = false; // means not first WRT comments and white space, nothing more
181 notFirstToken = false; // means not first WRT to real tokens
182 version = 0; // means not found
183 profile = ENoProfile;
185 bool foundNonSpaceTab = false;
186 bool lookingInMiddle = false;
189 if (lookingInMiddle) {
190 notFirstToken = true;
191 // make forward progress by finishing off the current line plus extra new lines
192 if (peek() != '\n' && peek() != '\r') {
195 } while (c != EndOfInput && c != '\n' && c != '\r');
197 while (peek() == '\n' || peek() == '\r')
199 if (peek() == EndOfInput)
202 lookingInMiddle = true;
204 // Nominal start, skipping the desktop allowed comments and white space, but tracking if
205 // something else was found for ES:
206 consumeWhitespaceComment(foundNonSpaceTab);
207 if (foundNonSpaceTab)
208 versionNotFirst = true;
212 versionNotFirst = true;
219 } while (c == ' ' || c == '\t');
229 versionNotFirst = true;
236 } while (c == ' ' || c == '\t');
239 while (c >= '0' && c <= '9') {
240 version = 10 * version + (c - '0');
244 versionNotFirst = true;
249 while (c == ' ' || c == '\t')
253 const int maxProfileLength = 13; // not including any 0
254 char profileString[maxProfileLength];
256 for (profileLength = 0; profileLength < maxProfileLength; ++profileLength) {
257 if (c == EndOfInput || c == ' ' || c == '\t' || c == '\n' || c == '\r')
259 profileString[profileLength] = (char)c;
262 if (c != EndOfInput && c != ' ' && c != '\t' && c != '\n' && c != '\r') {
263 versionNotFirst = true;
267 if (profileLength == 2 && strncmp(profileString, "es", profileLength) == 0)
268 profile = EEsProfile;
269 else if (profileLength == 4 && strncmp(profileString, "core", profileLength) == 0)
270 profile = ECoreProfile;
271 else if (profileLength == 13 && strncmp(profileString, "compatibility", profileLength) == 0)
272 profile = ECompatibilityProfile;
274 return versionNotFirst;
278 // Fill this in when doing glslang-level scanning, to hand back to the parser.
281 explicit TParserToken(YYSTYPE& b) : sType(b) { }
285 TParserToken(TParserToken&);
286 TParserToken& operator=(TParserToken&);
289 } // end namespace glslang
291 // This is the function the glslang parser (i.e., bison) calls to get its next token
292 int yylex(YYSTYPE* glslangTokenDesc, glslang::TParseContext& parseContext)
294 glslang::TParserToken token(*glslangTokenDesc);
296 return parseContext.getScanContext()->tokenize(parseContext.getPpContext(), token);
303 bool operator()(const char* lhs, const char* rhs) const
305 return strcmp(lhs, rhs) == 0;
311 size_t operator()(const char* str) const
314 unsigned long hash = 5381;
317 while ((c = *str++) != 0)
318 hash = ((hash << 5) + hash) + c;
324 // A single global usable by all threads, by all versions, by all languages.
325 // After a single process-level initialization, this is read only and thread safe
326 std::unordered_map<const char*, int, str_hash, str_eq>* KeywordMap = nullptr;
328 std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr;
335 void TScanContext::fillInKeywordMap()
337 if (KeywordMap != nullptr) {
338 // this is really an error, as this should called only once per process
339 // but, the only risk is if two threads called simultaneously
342 KeywordMap = new std::unordered_map<const char*, int, str_hash, str_eq>;
344 (*KeywordMap)["const"] = CONST;
345 (*KeywordMap)["uniform"] = UNIFORM;
346 (*KeywordMap)["buffer"] = BUFFER;
347 (*KeywordMap)["in"] = IN;
348 (*KeywordMap)["out"] = OUT;
349 (*KeywordMap)["smooth"] = SMOOTH;
350 (*KeywordMap)["flat"] = FLAT;
351 (*KeywordMap)["centroid"] = CENTROID;
352 (*KeywordMap)["invariant"] = INVARIANT;
353 (*KeywordMap)["packed"] = PACKED;
354 (*KeywordMap)["resource"] = RESOURCE;
355 (*KeywordMap)["inout"] = INOUT;
356 (*KeywordMap)["struct"] = STRUCT;
357 (*KeywordMap)["break"] = BREAK;
358 (*KeywordMap)["continue"] = CONTINUE;
359 (*KeywordMap)["do"] = DO;
360 (*KeywordMap)["for"] = FOR;
361 (*KeywordMap)["while"] = WHILE;
362 (*KeywordMap)["switch"] = SWITCH;
363 (*KeywordMap)["case"] = CASE;
364 (*KeywordMap)["default"] = DEFAULT;
365 (*KeywordMap)["if"] = IF;
366 (*KeywordMap)["else"] = ELSE;
367 (*KeywordMap)["discard"] = DISCARD;
368 (*KeywordMap)["return"] = RETURN;
369 (*KeywordMap)["void"] = VOID;
370 (*KeywordMap)["bool"] = BOOL;
371 (*KeywordMap)["float"] = FLOAT;
372 (*KeywordMap)["int"] = INT;
373 (*KeywordMap)["bvec2"] = BVEC2;
374 (*KeywordMap)["bvec3"] = BVEC3;
375 (*KeywordMap)["bvec4"] = BVEC4;
376 (*KeywordMap)["vec2"] = VEC2;
377 (*KeywordMap)["vec3"] = VEC3;
378 (*KeywordMap)["vec4"] = VEC4;
379 (*KeywordMap)["ivec2"] = IVEC2;
380 (*KeywordMap)["ivec3"] = IVEC3;
381 (*KeywordMap)["ivec4"] = IVEC4;
382 (*KeywordMap)["mat2"] = MAT2;
383 (*KeywordMap)["mat3"] = MAT3;
384 (*KeywordMap)["mat4"] = MAT4;
385 (*KeywordMap)["true"] = BOOLCONSTANT;
386 (*KeywordMap)["false"] = BOOLCONSTANT;
387 (*KeywordMap)["layout"] = LAYOUT;
388 (*KeywordMap)["shared"] = SHARED;
389 (*KeywordMap)["highp"] = HIGH_PRECISION;
390 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
391 (*KeywordMap)["lowp"] = LOW_PRECISION;
392 (*KeywordMap)["superp"] = SUPERP;
393 (*KeywordMap)["precision"] = PRECISION;
394 (*KeywordMap)["mat2x2"] = MAT2X2;
395 (*KeywordMap)["mat2x3"] = MAT2X3;
396 (*KeywordMap)["mat2x4"] = MAT2X4;
397 (*KeywordMap)["mat3x2"] = MAT3X2;
398 (*KeywordMap)["mat3x3"] = MAT3X3;
399 (*KeywordMap)["mat3x4"] = MAT3X4;
400 (*KeywordMap)["mat4x2"] = MAT4X2;
401 (*KeywordMap)["mat4x3"] = MAT4X3;
402 (*KeywordMap)["mat4x4"] = MAT4X4;
403 (*KeywordMap)["uint"] = UINT;
404 (*KeywordMap)["uvec2"] = UVEC2;
405 (*KeywordMap)["uvec3"] = UVEC3;
406 (*KeywordMap)["uvec4"] = UVEC4;
409 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
410 (*KeywordMap)["demote"] = DEMOTE;
411 (*KeywordMap)["attribute"] = ATTRIBUTE;
412 (*KeywordMap)["varying"] = VARYING;
413 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
414 (*KeywordMap)["coherent"] = COHERENT;
415 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
416 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
417 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
418 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
419 (*KeywordMap)["shadercallcoherent"] = SHADERCALLCOHERENT;
420 (*KeywordMap)["nonprivate"] = NONPRIVATE;
421 (*KeywordMap)["restrict"] = RESTRICT;
422 (*KeywordMap)["readonly"] = READONLY;
423 (*KeywordMap)["writeonly"] = WRITEONLY;
424 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
425 (*KeywordMap)["volatile"] = VOLATILE;
426 (*KeywordMap)["patch"] = PATCH;
427 (*KeywordMap)["sample"] = SAMPLE;
428 (*KeywordMap)["subroutine"] = SUBROUTINE;
429 (*KeywordMap)["dmat2"] = DMAT2;
430 (*KeywordMap)["dmat3"] = DMAT3;
431 (*KeywordMap)["dmat4"] = DMAT4;
432 (*KeywordMap)["dmat2x2"] = DMAT2X2;
433 (*KeywordMap)["dmat2x3"] = DMAT2X3;
434 (*KeywordMap)["dmat2x4"] = DMAT2X4;
435 (*KeywordMap)["dmat3x2"] = DMAT3X2;
436 (*KeywordMap)["dmat3x3"] = DMAT3X3;
437 (*KeywordMap)["dmat3x4"] = DMAT3X4;
438 (*KeywordMap)["dmat4x2"] = DMAT4X2;
439 (*KeywordMap)["dmat4x3"] = DMAT4X3;
440 (*KeywordMap)["dmat4x4"] = DMAT4X4;
441 (*KeywordMap)["image1D"] = IMAGE1D;
442 (*KeywordMap)["iimage1D"] = IIMAGE1D;
443 (*KeywordMap)["uimage1D"] = UIMAGE1D;
444 (*KeywordMap)["image2D"] = IMAGE2D;
445 (*KeywordMap)["iimage2D"] = IIMAGE2D;
446 (*KeywordMap)["uimage2D"] = UIMAGE2D;
447 (*KeywordMap)["image3D"] = IMAGE3D;
448 (*KeywordMap)["iimage3D"] = IIMAGE3D;
449 (*KeywordMap)["uimage3D"] = UIMAGE3D;
450 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
451 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
452 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
453 (*KeywordMap)["imageCube"] = IMAGECUBE;
454 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
455 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
456 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
457 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
458 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
459 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
460 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
461 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
462 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
463 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
464 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
465 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
466 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
467 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
468 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
469 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
470 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
471 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
472 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
473 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
474 (*KeywordMap)["double"] = DOUBLE;
475 (*KeywordMap)["dvec2"] = DVEC2;
476 (*KeywordMap)["dvec3"] = DVEC3;
477 (*KeywordMap)["dvec4"] = DVEC4;
478 (*KeywordMap)["int64_t"] = INT64_T;
479 (*KeywordMap)["uint64_t"] = UINT64_T;
480 (*KeywordMap)["i64vec2"] = I64VEC2;
481 (*KeywordMap)["i64vec3"] = I64VEC3;
482 (*KeywordMap)["i64vec4"] = I64VEC4;
483 (*KeywordMap)["u64vec2"] = U64VEC2;
484 (*KeywordMap)["u64vec3"] = U64VEC3;
485 (*KeywordMap)["u64vec4"] = U64VEC4;
487 // GL_EXT_shader_explicit_arithmetic_types
488 (*KeywordMap)["int8_t"] = INT8_T;
489 (*KeywordMap)["i8vec2"] = I8VEC2;
490 (*KeywordMap)["i8vec3"] = I8VEC3;
491 (*KeywordMap)["i8vec4"] = I8VEC4;
492 (*KeywordMap)["uint8_t"] = UINT8_T;
493 (*KeywordMap)["u8vec2"] = U8VEC2;
494 (*KeywordMap)["u8vec3"] = U8VEC3;
495 (*KeywordMap)["u8vec4"] = U8VEC4;
497 (*KeywordMap)["int16_t"] = INT16_T;
498 (*KeywordMap)["i16vec2"] = I16VEC2;
499 (*KeywordMap)["i16vec3"] = I16VEC3;
500 (*KeywordMap)["i16vec4"] = I16VEC4;
501 (*KeywordMap)["uint16_t"] = UINT16_T;
502 (*KeywordMap)["u16vec2"] = U16VEC2;
503 (*KeywordMap)["u16vec3"] = U16VEC3;
504 (*KeywordMap)["u16vec4"] = U16VEC4;
506 (*KeywordMap)["int32_t"] = INT32_T;
507 (*KeywordMap)["i32vec2"] = I32VEC2;
508 (*KeywordMap)["i32vec3"] = I32VEC3;
509 (*KeywordMap)["i32vec4"] = I32VEC4;
510 (*KeywordMap)["uint32_t"] = UINT32_T;
511 (*KeywordMap)["u32vec2"] = U32VEC2;
512 (*KeywordMap)["u32vec3"] = U32VEC3;
513 (*KeywordMap)["u32vec4"] = U32VEC4;
515 (*KeywordMap)["float16_t"] = FLOAT16_T;
516 (*KeywordMap)["f16vec2"] = F16VEC2;
517 (*KeywordMap)["f16vec3"] = F16VEC3;
518 (*KeywordMap)["f16vec4"] = F16VEC4;
519 (*KeywordMap)["f16mat2"] = F16MAT2;
520 (*KeywordMap)["f16mat3"] = F16MAT3;
521 (*KeywordMap)["f16mat4"] = F16MAT4;
522 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
523 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
524 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
525 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
526 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
527 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
528 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
529 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
530 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
532 (*KeywordMap)["float32_t"] = FLOAT32_T;
533 (*KeywordMap)["f32vec2"] = F32VEC2;
534 (*KeywordMap)["f32vec3"] = F32VEC3;
535 (*KeywordMap)["f32vec4"] = F32VEC4;
536 (*KeywordMap)["f32mat2"] = F32MAT2;
537 (*KeywordMap)["f32mat3"] = F32MAT3;
538 (*KeywordMap)["f32mat4"] = F32MAT4;
539 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
540 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
541 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
542 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
543 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
544 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
545 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
546 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
547 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
548 (*KeywordMap)["float64_t"] = FLOAT64_T;
549 (*KeywordMap)["f64vec2"] = F64VEC2;
550 (*KeywordMap)["f64vec3"] = F64VEC3;
551 (*KeywordMap)["f64vec4"] = F64VEC4;
552 (*KeywordMap)["f64mat2"] = F64MAT2;
553 (*KeywordMap)["f64mat3"] = F64MAT3;
554 (*KeywordMap)["f64mat4"] = F64MAT4;
555 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
556 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
557 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
558 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
559 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
560 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
561 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
562 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
563 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
566 (*KeywordMap)["sampler2D"] = SAMPLER2D;
567 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
568 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
569 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
570 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
571 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
572 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
573 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
574 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
575 (*KeywordMap)["usampler2D"] = USAMPLER2D;
576 (*KeywordMap)["usampler3D"] = USAMPLER3D;
577 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
578 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
579 (*KeywordMap)["sampler3D"] = SAMPLER3D;
580 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
582 (*KeywordMap)["texture2D"] = TEXTURE2D;
583 (*KeywordMap)["textureCube"] = TEXTURECUBE;
584 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
585 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
586 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
587 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
588 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
589 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
590 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
591 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
592 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
593 (*KeywordMap)["texture3D"] = TEXTURE3D;
595 (*KeywordMap)["sampler"] = SAMPLER;
596 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
599 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
600 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
601 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
602 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
603 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
604 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
605 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
606 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
607 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
608 (*KeywordMap)["usampler1D"] = USAMPLER1D;
609 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
610 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
611 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
612 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
613 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
614 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
615 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
616 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
617 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
618 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
619 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
620 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
621 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
622 (*KeywordMap)["sampler1D"] = SAMPLER1D;
623 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
624 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
625 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
626 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
628 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
630 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
632 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
633 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
634 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
635 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
636 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
637 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
638 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
639 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
640 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
641 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
642 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
643 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
644 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
645 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
646 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
647 (*KeywordMap)["texture1D"] = TEXTURE1D;
648 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
649 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
651 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
652 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
653 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
654 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
655 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
656 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
658 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
659 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
660 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
661 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
662 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
663 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
664 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
665 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
666 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
667 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
668 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
669 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
670 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
671 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
672 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
673 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
674 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
675 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
677 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
678 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
679 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
680 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
681 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
682 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
683 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
684 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
685 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
686 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
687 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
689 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
690 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
691 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
692 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
693 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
694 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
695 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
696 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
697 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
698 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
699 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
701 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
702 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
703 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
704 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
705 (*KeywordMap)["precise"] = PRECISE;
707 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
708 (*KeywordMap)["rayPayloadEXT"] = PAYLOADEXT;
709 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
710 (*KeywordMap)["rayPayloadInEXT"] = PAYLOADINEXT;
711 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
712 (*KeywordMap)["hitAttributeEXT"] = HITATTREXT;
713 (*KeywordMap)["callableDataNV"] = CALLDATANV;
714 (*KeywordMap)["callableDataEXT"] = CALLDATAEXT;
715 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
716 (*KeywordMap)["callableDataInEXT"] = CALLDATAINEXT;
717 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
718 (*KeywordMap)["accelerationStructureEXT"] = ACCSTRUCTEXT;
719 (*KeywordMap)["rayQueryEXT"] = RAYQUERYEXT;
720 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
721 (*KeywordMap)["perviewNV"] = PERVIEWNV;
722 (*KeywordMap)["taskNV"] = PERTASKNV;
724 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
725 (*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
726 (*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
728 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
730 ReservedSet->insert("common");
731 ReservedSet->insert("partition");
732 ReservedSet->insert("active");
733 ReservedSet->insert("asm");
734 ReservedSet->insert("class");
735 ReservedSet->insert("union");
736 ReservedSet->insert("enum");
737 ReservedSet->insert("typedef");
738 ReservedSet->insert("template");
739 ReservedSet->insert("this");
740 ReservedSet->insert("goto");
741 ReservedSet->insert("inline");
742 ReservedSet->insert("noinline");
743 ReservedSet->insert("public");
744 ReservedSet->insert("static");
745 ReservedSet->insert("extern");
746 ReservedSet->insert("external");
747 ReservedSet->insert("interface");
748 ReservedSet->insert("long");
749 ReservedSet->insert("short");
750 ReservedSet->insert("half");
751 ReservedSet->insert("fixed");
752 ReservedSet->insert("unsigned");
753 ReservedSet->insert("input");
754 ReservedSet->insert("output");
755 ReservedSet->insert("hvec2");
756 ReservedSet->insert("hvec3");
757 ReservedSet->insert("hvec4");
758 ReservedSet->insert("fvec2");
759 ReservedSet->insert("fvec3");
760 ReservedSet->insert("fvec4");
761 ReservedSet->insert("sampler3DRect");
762 ReservedSet->insert("filter");
763 ReservedSet->insert("sizeof");
764 ReservedSet->insert("cast");
765 ReservedSet->insert("namespace");
766 ReservedSet->insert("using");
770 void TScanContext::deleteKeywordMap()
773 KeywordMap = nullptr;
776 ReservedSet = nullptr;
780 // Called by yylex to get the next token.
781 // Returning 0 implies end of input.
782 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
785 parserToken = &token;
787 int token = pp->tokenize(ppToken);
788 if (token == EndOfInput)
791 tokenText = ppToken.name;
793 parserToken->sType.lex.loc = loc;
795 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
796 case ',': afterType = false; return COMMA;
797 case ':': return COLON;
798 case '=': afterType = false; return EQUAL;
799 case '(': afterType = false; return LEFT_PAREN;
800 case ')': afterType = false; return RIGHT_PAREN;
801 case '.': field = true; return DOT;
802 case '!': return BANG;
803 case '-': return DASH;
804 case '~': return TILDE;
805 case '+': return PLUS;
806 case '*': return STAR;
807 case '/': return SLASH;
808 case '%': return PERCENT;
809 case '<': return LEFT_ANGLE;
810 case '>': return RIGHT_ANGLE;
811 case '|': return VERTICAL_BAR;
812 case '^': return CARET;
813 case '&': return AMPERSAND;
814 case '?': return QUESTION;
815 case '[': return LEFT_BRACKET;
816 case ']': return RIGHT_BRACKET;
817 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
818 case '}': return RIGHT_BRACE;
820 parseContext.error(loc, "illegal use of escape character", "\\", "");
823 case PPAtomAddAssign: return ADD_ASSIGN;
824 case PPAtomSubAssign: return SUB_ASSIGN;
825 case PPAtomMulAssign: return MUL_ASSIGN;
826 case PPAtomDivAssign: return DIV_ASSIGN;
827 case PPAtomModAssign: return MOD_ASSIGN;
829 case PpAtomRight: return RIGHT_OP;
830 case PpAtomLeft: return LEFT_OP;
832 case PpAtomRightAssign: return RIGHT_ASSIGN;
833 case PpAtomLeftAssign: return LEFT_ASSIGN;
834 case PpAtomAndAssign: return AND_ASSIGN;
835 case PpAtomOrAssign: return OR_ASSIGN;
836 case PpAtomXorAssign: return XOR_ASSIGN;
838 case PpAtomAnd: return AND_OP;
839 case PpAtomOr: return OR_OP;
840 case PpAtomXor: return XOR_OP;
842 case PpAtomEQ: return EQ_OP;
843 case PpAtomGE: return GE_OP;
844 case PpAtomNE: return NE_OP;
845 case PpAtomLE: return LE_OP;
847 case PpAtomDecrement: return DEC_OP;
848 case PpAtomIncrement: return INC_OP;
850 case PpAtomColonColon:
851 parseContext.error(loc, "not supported", "::", "");
854 case PpAtomConstString: parserToken->sType.lex.string = NewPoolTString(tokenText); return STRING_LITERAL;
855 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
856 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
857 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
859 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
860 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
861 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
862 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
863 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
864 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
866 case PpAtomIdentifier:
868 int token = tokenizeIdentifier();
873 case EndOfInput: return 0;
877 buf[0] = (char)token;
879 parseContext.error(loc, "unexpected token", buf, "");
885 int TScanContext::tokenizeIdentifier()
888 if (ReservedSet->find(tokenText) != ReservedSet->end())
889 return reservedWord();
892 auto it = KeywordMap->find(tokenText);
893 if (it == KeywordMap->end()) {
894 // Should have an identifier of some sort
895 return identifierOrType();
897 keyword = it->second;
919 if ((parseContext.isEsProfile() && parseContext.version < 310) ||
920 (!parseContext.isEsProfile() && parseContext.version < 430))
921 return identifierOrType();
930 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
931 (!parseContext.isEsProfile() && parseContext.version < 130))
957 if (strcmp("true", tokenText) == 0)
958 parserToken->sType.lex.b = true;
960 parserToken->sType.lex.b = false;
964 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
965 (!parseContext.isEsProfile() && parseContext.version < 130))
966 return identifierOrType();
969 if (parseContext.isEsProfile() && parseContext.version < 300)
971 else if (!parseContext.isEsProfile() && parseContext.version < 130)
972 return identifierOrType();
975 if (parseContext.version < 120)
976 return identifierOrType();
979 if (!parseContext.isEsProfile() && parseContext.version < 120)
980 return identifierOrType();
983 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
984 (!parseContext.isEsProfile() && parseContext.version < 330))
985 return reservedWord();
986 return identifierOrType();
990 bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
991 (!parseContext.isEsProfile() && parseContext.version >= 420);
992 return identifierOrReserved(reserved);
996 bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
997 return identifierOrReserved(reserved);
1002 if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1004 return es30ReservedFromGLSL(130);
1007 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
1010 return identifierOrType();
1013 if (parseContext.isEsProfile() && parseContext.version >= 300)
1022 if (parseContext.symbolTable.atBuiltInLevel() ||
1023 parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
1025 return identifierOrType();
1032 if (parseContext.symbolTable.atBuiltInLevel() ||
1033 parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing))
1035 return identifierOrType();
1037 if (parseContext.symbolTable.atBuiltInLevel() ||
1038 (!parseContext.isEsProfile() && parseContext.version >= 460
1039 && parseContext.extensionTurnedOn(E_GL_EXT_ray_query)))
1041 return identifierOrType();
1043 if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
1044 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
1046 return es30ReservedFromGLSL(420);
1049 case DEVICECOHERENT:
1050 case QUEUEFAMILYCOHERENT:
1051 case WORKGROUPCOHERENT:
1052 case SUBGROUPCOHERENT:
1053 case SHADERCALLCOHERENT:
1058 if (parseContext.isEsProfile() && parseContext.version >= 310)
1060 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
1062 if (parseContext.isEsProfile() && parseContext.version >= 310)
1064 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
1065 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1069 if (parseContext.symbolTable.atBuiltInLevel() ||
1070 (parseContext.isEsProfile() &&
1071 (parseContext.version >= 320 ||
1072 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1073 (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1076 return es30ReservedFromGLSL(400);
1079 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1080 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1082 return es30ReservedFromGLSL(400);
1085 return es30ReservedFromGLSL(400);
1088 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1089 (!parseContext.isEsProfile() && parseContext.version < 140))
1090 return identifierOrType();
1094 const int numLayoutExts = 2;
1095 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1096 E_GL_ARB_explicit_attrib_location };
1097 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1098 (!parseContext.isEsProfile() && parseContext.version < 140 &&
1099 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1100 return identifierOrType();
1104 case HIGH_PRECISION:
1105 case MEDIUM_PRECISION:
1108 return precisionKeyword();
1146 return firstGenerationImage(false);
1152 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1153 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1155 return firstGenerationImage(false);
1170 return firstGenerationImage(true);
1172 case IMAGECUBEARRAY:
1173 case IIMAGECUBEARRAY:
1174 case UIMAGECUBEARRAY:
1176 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1177 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1179 return secondGenerationImage();
1184 case IMAGE2DMSARRAY:
1185 case IIMAGE2DMSARRAY:
1186 case UIMAGE2DMSARRAY:
1188 return secondGenerationImage();
1195 if (parseContext.isEsProfile() || parseContext.version < 150 ||
1196 (!parseContext.symbolTable.atBuiltInLevel() &&
1197 parseContext.version < 400 &&
1198 !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)))
1211 if (parseContext.symbolTable.atBuiltInLevel() ||
1212 parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1213 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1214 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
1216 return identifierOrType();
1227 if (parseContext.symbolTable.atBuiltInLevel() ||
1228 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1229 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1230 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
1232 return identifierOrType();
1243 if (parseContext.symbolTable.atBuiltInLevel() ||
1244 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1245 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1246 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1247 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
1249 return identifierOrType();
1259 if (parseContext.symbolTable.atBuiltInLevel() ||
1260 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1261 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
1263 return identifierOrType();
1281 if (parseContext.symbolTable.atBuiltInLevel() ||
1282 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1283 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
1285 return identifierOrType();
1304 if (parseContext.symbolTable.atBuiltInLevel() ||
1305 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1306 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
1308 return identifierOrType();
1315 if (parseContext.symbolTable.atBuiltInLevel() ||
1316 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1317 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1318 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1319 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1322 return identifierOrType();
1337 if (parseContext.symbolTable.atBuiltInLevel() ||
1338 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1339 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1340 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1343 return identifierOrType();
1345 case SAMPLERCUBEARRAY:
1346 case SAMPLERCUBEARRAYSHADOW:
1347 case ISAMPLERCUBEARRAY:
1348 case USAMPLERCUBEARRAY:
1350 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1351 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1353 if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1357 case TEXTURECUBEARRAY:
1358 case ITEXTURECUBEARRAY:
1359 case UTEXTURECUBEARRAY:
1360 if (parseContext.spvVersion.vulkan > 0)
1363 return identifierOrType();
1370 case SAMPLERCUBESHADOW:
1371 case SAMPLER2DARRAY:
1372 case SAMPLER2DARRAYSHADOW:
1376 case ISAMPLER2DARRAY:
1380 case USAMPLER2DARRAY:
1382 return nonreservedKeyword(300, 130);
1386 if (parseContext.isEsProfile() && parseContext.version < 300) {
1387 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1392 case SAMPLER2DSHADOW:
1394 if (parseContext.isEsProfile() && parseContext.version < 300) {
1395 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1402 case TEXTURE2DARRAY:
1406 case ITEXTURE2DARRAY:
1410 case UTEXTURE2DARRAY:
1414 if (parseContext.spvVersion.vulkan > 0)
1417 return identifierOrType();
1421 case ISAMPLER1DARRAY:
1422 case SAMPLER1DARRAYSHADOW:
1424 case USAMPLER1DARRAY:
1426 return es30ReservedFromGLSL(130);
1427 case ISAMPLER2DRECT:
1428 case USAMPLER2DRECT:
1430 return es30ReservedFromGLSL(140);
1434 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1435 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1437 return es30ReservedFromGLSL(130);
1439 case ISAMPLERBUFFER:
1440 case USAMPLERBUFFER:
1442 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1443 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1445 return es30ReservedFromGLSL(140);
1451 if (parseContext.isEsProfile() && parseContext.version >= 310)
1453 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1454 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1456 return es30ReservedFromGLSL(150);
1458 case SAMPLER2DMSARRAY:
1459 case ISAMPLER2DMSARRAY:
1460 case USAMPLER2DMSARRAY:
1462 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1463 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1465 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1466 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1468 return es30ReservedFromGLSL(150);
1471 case SAMPLER1DSHADOW:
1473 if (parseContext.isEsProfile())
1478 case SAMPLER2DRECTSHADOW:
1480 if (parseContext.isEsProfile())
1482 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1483 if (parseContext.relaxedErrors())
1484 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1490 case SAMPLER1DARRAY:
1492 if (parseContext.isEsProfile() && parseContext.version == 300)
1494 else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1495 (!parseContext.isEsProfile() && parseContext.version < 130))
1496 return identifierOrType();
1499 case SAMPLEREXTERNALOES:
1501 if (parseContext.symbolTable.atBuiltInLevel() ||
1502 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1503 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1505 return identifierOrType();
1507 case SAMPLEREXTERNAL2DY2YEXT:
1509 if (parseContext.symbolTable.atBuiltInLevel() ||
1510 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1512 return identifierOrType();
1514 case ITEXTURE1DARRAY:
1517 case UTEXTURE1DARRAY:
1519 case ITEXTURE2DRECT:
1520 case UTEXTURE2DRECT:
1521 case ITEXTUREBUFFER:
1522 case UTEXTUREBUFFER:
1526 case TEXTURE2DMSARRAY:
1527 case ITEXTURE2DMSARRAY:
1528 case UTEXTURE2DMSARRAY:
1531 case TEXTURE1DARRAY:
1532 if (parseContext.spvVersion.vulkan > 0)
1535 return identifierOrType();
1538 case SUBPASSINPUTMS:
1540 case ISUBPASSINPUTMS:
1542 case USUBPASSINPUTMS:
1543 if (parseContext.spvVersion.vulkan > 0)
1546 return identifierOrType();
1551 case F16SAMPLER2DRECT:
1552 case F16SAMPLERCUBE:
1553 case F16SAMPLER1DARRAY:
1554 case F16SAMPLER2DARRAY:
1555 case F16SAMPLERCUBEARRAY:
1556 case F16SAMPLERBUFFER:
1557 case F16SAMPLER2DMS:
1558 case F16SAMPLER2DMSARRAY:
1559 case F16SAMPLER1DSHADOW:
1560 case F16SAMPLER2DSHADOW:
1561 case F16SAMPLER1DARRAYSHADOW:
1562 case F16SAMPLER2DARRAYSHADOW:
1563 case F16SAMPLER2DRECTSHADOW:
1564 case F16SAMPLERCUBESHADOW:
1565 case F16SAMPLERCUBEARRAYSHADOW:
1570 case F16IMAGE2DRECT:
1572 case F16IMAGE1DARRAY:
1573 case F16IMAGE2DARRAY:
1574 case F16IMAGECUBEARRAY:
1575 case F16IMAGEBUFFER:
1577 case F16IMAGE2DMSARRAY:
1582 case F16TEXTURE2DRECT:
1583 case F16TEXTURECUBE:
1584 case F16TEXTURE1DARRAY:
1585 case F16TEXTURE2DARRAY:
1586 case F16TEXTURECUBEARRAY:
1587 case F16TEXTUREBUFFER:
1588 case F16TEXTURE2DMS:
1589 case F16TEXTURE2DMSARRAY:
1591 case F16SUBPASSINPUT:
1592 case F16SUBPASSINPUTMS:
1594 if (parseContext.symbolTable.atBuiltInLevel() ||
1595 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
1597 return identifierOrType();
1599 case EXPLICITINTERPAMD:
1600 if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1602 return identifierOrType();
1605 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1606 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1608 return identifierOrType();
1611 if ((parseContext.isEsProfile() &&
1612 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1613 (!parseContext.isEsProfile() && parseContext.version >= 400))
1615 if (parseContext.isEsProfile() && parseContext.version == 310) {
1619 return identifierOrType();
1621 case PERPRIMITIVENV:
1624 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1625 (parseContext.isEsProfile() && parseContext.version >= 320) ||
1626 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1628 return identifierOrType();
1632 if (parseContext.symbolTable.atBuiltInLevel() ||
1633 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1635 return identifierOrType();
1640 if (parseContext.symbolTable.atBuiltInLevel() ||
1641 parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
1643 return identifierOrType();
1646 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1649 return identifierOrType();
1653 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1658 int TScanContext::identifierOrType()
1660 parserToken->sType.lex.string = NewPoolTString(tokenText);
1664 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1665 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1666 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1667 if (variable->isUserType() &&
1668 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1669 !(variable->getType().isReference() && afterBuffer)) {
1680 // Give an error for use of a reserved symbol.
1681 // However, allow built-in declarations to use reserved words, to allow
1682 // extension support before the extension is enabled.
1683 int TScanContext::reservedWord()
1685 if (! parseContext.symbolTable.atBuiltInLevel())
1686 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1691 int TScanContext::identifierOrReserved(bool reserved)
1699 if (parseContext.isForwardCompatible())
1700 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1702 return identifierOrType();
1705 // For keywords that suddenly showed up on non-ES (not previously reserved)
1706 // but then got reserved by ES 3.0.
1707 int TScanContext::es30ReservedFromGLSL(int version)
1709 if (parseContext.symbolTable.atBuiltInLevel())
1712 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1713 (!parseContext.isEsProfile() && parseContext.version < version)) {
1714 if (parseContext.isForwardCompatible())
1715 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1717 return identifierOrType();
1718 } else if (parseContext.isEsProfile() && parseContext.version >= 300)
1724 // For a keyword that was never reserved, until it suddenly
1725 // showed up, both in an es version and a non-ES version.
1726 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1728 if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
1729 (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
1730 if (parseContext.isForwardCompatible())
1731 parseContext.warn(loc, "using future keyword", tokenText, "");
1733 return identifierOrType();
1739 int TScanContext::precisionKeyword()
1741 if (parseContext.isEsProfile() || parseContext.version >= 130)
1744 if (parseContext.isForwardCompatible())
1745 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1747 return identifierOrType();
1750 int TScanContext::matNxM()
1754 if (parseContext.version > 110)
1757 if (parseContext.isForwardCompatible())
1758 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1760 return identifierOrType();
1763 int TScanContext::dMat()
1767 if (parseContext.isEsProfile() && parseContext.version >= 300) {
1773 if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
1774 parseContext.symbolTable.atBuiltInLevel() ||
1775 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64))))
1778 if (parseContext.isForwardCompatible())
1779 parseContext.warn(loc, "using future type keyword", tokenText, "");
1781 return identifierOrType();
1784 int TScanContext::firstGenerationImage(bool inEs310)
1786 if (parseContext.symbolTable.atBuiltInLevel() ||
1787 (!parseContext.isEsProfile() && (parseContext.version >= 420 ||
1788 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1789 (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
1792 if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
1793 (!parseContext.isEsProfile() && parseContext.version >= 130)) {
1799 if (parseContext.isForwardCompatible())
1800 parseContext.warn(loc, "using future type keyword", tokenText, "");
1802 return identifierOrType();
1805 int TScanContext::secondGenerationImage()
1807 if (parseContext.isEsProfile() && parseContext.version >= 310) {
1812 if (parseContext.symbolTable.atBuiltInLevel() ||
1813 (!parseContext.isEsProfile() &&
1814 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1817 if (parseContext.isForwardCompatible())
1818 parseContext.warn(loc, "using future type keyword", tokenText, "");
1820 return identifierOrType();
1823 } // end namespace glslang