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)["terminateInvocation"] = TERMINATE_INVOCATION;
369 (*KeywordMap)["return"] = RETURN;
370 (*KeywordMap)["void"] = VOID;
371 (*KeywordMap)["bool"] = BOOL;
372 (*KeywordMap)["float"] = FLOAT;
373 (*KeywordMap)["int"] = INT;
374 (*KeywordMap)["bvec2"] = BVEC2;
375 (*KeywordMap)["bvec3"] = BVEC3;
376 (*KeywordMap)["bvec4"] = BVEC4;
377 (*KeywordMap)["vec2"] = VEC2;
378 (*KeywordMap)["vec3"] = VEC3;
379 (*KeywordMap)["vec4"] = VEC4;
380 (*KeywordMap)["ivec2"] = IVEC2;
381 (*KeywordMap)["ivec3"] = IVEC3;
382 (*KeywordMap)["ivec4"] = IVEC4;
383 (*KeywordMap)["mat2"] = MAT2;
384 (*KeywordMap)["mat3"] = MAT3;
385 (*KeywordMap)["mat4"] = MAT4;
386 (*KeywordMap)["true"] = BOOLCONSTANT;
387 (*KeywordMap)["false"] = BOOLCONSTANT;
388 (*KeywordMap)["layout"] = LAYOUT;
389 (*KeywordMap)["shared"] = SHARED;
390 (*KeywordMap)["highp"] = HIGH_PRECISION;
391 (*KeywordMap)["mediump"] = MEDIUM_PRECISION;
392 (*KeywordMap)["lowp"] = LOW_PRECISION;
393 (*KeywordMap)["superp"] = SUPERP;
394 (*KeywordMap)["precision"] = PRECISION;
395 (*KeywordMap)["mat2x2"] = MAT2X2;
396 (*KeywordMap)["mat2x3"] = MAT2X3;
397 (*KeywordMap)["mat2x4"] = MAT2X4;
398 (*KeywordMap)["mat3x2"] = MAT3X2;
399 (*KeywordMap)["mat3x3"] = MAT3X3;
400 (*KeywordMap)["mat3x4"] = MAT3X4;
401 (*KeywordMap)["mat4x2"] = MAT4X2;
402 (*KeywordMap)["mat4x3"] = MAT4X3;
403 (*KeywordMap)["mat4x4"] = MAT4X4;
404 (*KeywordMap)["uint"] = UINT;
405 (*KeywordMap)["uvec2"] = UVEC2;
406 (*KeywordMap)["uvec3"] = UVEC3;
407 (*KeywordMap)["uvec4"] = UVEC4;
410 (*KeywordMap)["nonuniformEXT"] = NONUNIFORM;
411 (*KeywordMap)["demote"] = DEMOTE;
412 (*KeywordMap)["attribute"] = ATTRIBUTE;
413 (*KeywordMap)["varying"] = VARYING;
414 (*KeywordMap)["noperspective"] = NOPERSPECTIVE;
415 (*KeywordMap)["coherent"] = COHERENT;
416 (*KeywordMap)["devicecoherent"] = DEVICECOHERENT;
417 (*KeywordMap)["queuefamilycoherent"] = QUEUEFAMILYCOHERENT;
418 (*KeywordMap)["workgroupcoherent"] = WORKGROUPCOHERENT;
419 (*KeywordMap)["subgroupcoherent"] = SUBGROUPCOHERENT;
420 (*KeywordMap)["shadercallcoherent"] = SHADERCALLCOHERENT;
421 (*KeywordMap)["nonprivate"] = NONPRIVATE;
422 (*KeywordMap)["restrict"] = RESTRICT;
423 (*KeywordMap)["readonly"] = READONLY;
424 (*KeywordMap)["writeonly"] = WRITEONLY;
425 (*KeywordMap)["atomic_uint"] = ATOMIC_UINT;
426 (*KeywordMap)["volatile"] = VOLATILE;
427 (*KeywordMap)["patch"] = PATCH;
428 (*KeywordMap)["sample"] = SAMPLE;
429 (*KeywordMap)["subroutine"] = SUBROUTINE;
430 (*KeywordMap)["dmat2"] = DMAT2;
431 (*KeywordMap)["dmat3"] = DMAT3;
432 (*KeywordMap)["dmat4"] = DMAT4;
433 (*KeywordMap)["dmat2x2"] = DMAT2X2;
434 (*KeywordMap)["dmat2x3"] = DMAT2X3;
435 (*KeywordMap)["dmat2x4"] = DMAT2X4;
436 (*KeywordMap)["dmat3x2"] = DMAT3X2;
437 (*KeywordMap)["dmat3x3"] = DMAT3X3;
438 (*KeywordMap)["dmat3x4"] = DMAT3X4;
439 (*KeywordMap)["dmat4x2"] = DMAT4X2;
440 (*KeywordMap)["dmat4x3"] = DMAT4X3;
441 (*KeywordMap)["dmat4x4"] = DMAT4X4;
442 (*KeywordMap)["image1D"] = IMAGE1D;
443 (*KeywordMap)["iimage1D"] = IIMAGE1D;
444 (*KeywordMap)["uimage1D"] = UIMAGE1D;
445 (*KeywordMap)["image2D"] = IMAGE2D;
446 (*KeywordMap)["iimage2D"] = IIMAGE2D;
447 (*KeywordMap)["uimage2D"] = UIMAGE2D;
448 (*KeywordMap)["image3D"] = IMAGE3D;
449 (*KeywordMap)["iimage3D"] = IIMAGE3D;
450 (*KeywordMap)["uimage3D"] = UIMAGE3D;
451 (*KeywordMap)["image2DRect"] = IMAGE2DRECT;
452 (*KeywordMap)["iimage2DRect"] = IIMAGE2DRECT;
453 (*KeywordMap)["uimage2DRect"] = UIMAGE2DRECT;
454 (*KeywordMap)["imageCube"] = IMAGECUBE;
455 (*KeywordMap)["iimageCube"] = IIMAGECUBE;
456 (*KeywordMap)["uimageCube"] = UIMAGECUBE;
457 (*KeywordMap)["imageBuffer"] = IMAGEBUFFER;
458 (*KeywordMap)["iimageBuffer"] = IIMAGEBUFFER;
459 (*KeywordMap)["uimageBuffer"] = UIMAGEBUFFER;
460 (*KeywordMap)["image1DArray"] = IMAGE1DARRAY;
461 (*KeywordMap)["iimage1DArray"] = IIMAGE1DARRAY;
462 (*KeywordMap)["uimage1DArray"] = UIMAGE1DARRAY;
463 (*KeywordMap)["image2DArray"] = IMAGE2DARRAY;
464 (*KeywordMap)["iimage2DArray"] = IIMAGE2DARRAY;
465 (*KeywordMap)["uimage2DArray"] = UIMAGE2DARRAY;
466 (*KeywordMap)["imageCubeArray"] = IMAGECUBEARRAY;
467 (*KeywordMap)["iimageCubeArray"] = IIMAGECUBEARRAY;
468 (*KeywordMap)["uimageCubeArray"] = UIMAGECUBEARRAY;
469 (*KeywordMap)["image2DMS"] = IMAGE2DMS;
470 (*KeywordMap)["iimage2DMS"] = IIMAGE2DMS;
471 (*KeywordMap)["uimage2DMS"] = UIMAGE2DMS;
472 (*KeywordMap)["image2DMSArray"] = IMAGE2DMSARRAY;
473 (*KeywordMap)["iimage2DMSArray"] = IIMAGE2DMSARRAY;
474 (*KeywordMap)["uimage2DMSArray"] = UIMAGE2DMSARRAY;
475 (*KeywordMap)["i64image1D"] = I64IMAGE1D;
476 (*KeywordMap)["u64image1D"] = U64IMAGE1D;
477 (*KeywordMap)["i64image2D"] = I64IMAGE2D;
478 (*KeywordMap)["u64image2D"] = U64IMAGE2D;
479 (*KeywordMap)["i64image3D"] = I64IMAGE3D;
480 (*KeywordMap)["u64image3D"] = U64IMAGE3D;
481 (*KeywordMap)["i64image2DRect"] = I64IMAGE2DRECT;
482 (*KeywordMap)["u64image2DRect"] = U64IMAGE2DRECT;
483 (*KeywordMap)["i64imageCube"] = I64IMAGECUBE;
484 (*KeywordMap)["u64imageCube"] = U64IMAGECUBE;
485 (*KeywordMap)["i64imageBuffer"] = I64IMAGEBUFFER;
486 (*KeywordMap)["u64imageBuffer"] = U64IMAGEBUFFER;
487 (*KeywordMap)["i64image1DArray"] = I64IMAGE1DARRAY;
488 (*KeywordMap)["u64image1DArray"] = U64IMAGE1DARRAY;
489 (*KeywordMap)["i64image2DArray"] = I64IMAGE2DARRAY;
490 (*KeywordMap)["u64image2DArray"] = U64IMAGE2DARRAY;
491 (*KeywordMap)["i64imageCubeArray"] = I64IMAGECUBEARRAY;
492 (*KeywordMap)["u64imageCubeArray"] = U64IMAGECUBEARRAY;
493 (*KeywordMap)["i64image2DMS"] = I64IMAGE2DMS;
494 (*KeywordMap)["u64image2DMS"] = U64IMAGE2DMS;
495 (*KeywordMap)["i64image2DMSArray"] = I64IMAGE2DMSARRAY;
496 (*KeywordMap)["u64image2DMSArray"] = U64IMAGE2DMSARRAY;
497 (*KeywordMap)["double"] = DOUBLE;
498 (*KeywordMap)["dvec2"] = DVEC2;
499 (*KeywordMap)["dvec3"] = DVEC3;
500 (*KeywordMap)["dvec4"] = DVEC4;
501 (*KeywordMap)["int64_t"] = INT64_T;
502 (*KeywordMap)["uint64_t"] = UINT64_T;
503 (*KeywordMap)["i64vec2"] = I64VEC2;
504 (*KeywordMap)["i64vec3"] = I64VEC3;
505 (*KeywordMap)["i64vec4"] = I64VEC4;
506 (*KeywordMap)["u64vec2"] = U64VEC2;
507 (*KeywordMap)["u64vec3"] = U64VEC3;
508 (*KeywordMap)["u64vec4"] = U64VEC4;
510 // GL_EXT_shader_explicit_arithmetic_types
511 (*KeywordMap)["int8_t"] = INT8_T;
512 (*KeywordMap)["i8vec2"] = I8VEC2;
513 (*KeywordMap)["i8vec3"] = I8VEC3;
514 (*KeywordMap)["i8vec4"] = I8VEC4;
515 (*KeywordMap)["uint8_t"] = UINT8_T;
516 (*KeywordMap)["u8vec2"] = U8VEC2;
517 (*KeywordMap)["u8vec3"] = U8VEC3;
518 (*KeywordMap)["u8vec4"] = U8VEC4;
520 (*KeywordMap)["int16_t"] = INT16_T;
521 (*KeywordMap)["i16vec2"] = I16VEC2;
522 (*KeywordMap)["i16vec3"] = I16VEC3;
523 (*KeywordMap)["i16vec4"] = I16VEC4;
524 (*KeywordMap)["uint16_t"] = UINT16_T;
525 (*KeywordMap)["u16vec2"] = U16VEC2;
526 (*KeywordMap)["u16vec3"] = U16VEC3;
527 (*KeywordMap)["u16vec4"] = U16VEC4;
529 (*KeywordMap)["int32_t"] = INT32_T;
530 (*KeywordMap)["i32vec2"] = I32VEC2;
531 (*KeywordMap)["i32vec3"] = I32VEC3;
532 (*KeywordMap)["i32vec4"] = I32VEC4;
533 (*KeywordMap)["uint32_t"] = UINT32_T;
534 (*KeywordMap)["u32vec2"] = U32VEC2;
535 (*KeywordMap)["u32vec3"] = U32VEC3;
536 (*KeywordMap)["u32vec4"] = U32VEC4;
538 (*KeywordMap)["float16_t"] = FLOAT16_T;
539 (*KeywordMap)["f16vec2"] = F16VEC2;
540 (*KeywordMap)["f16vec3"] = F16VEC3;
541 (*KeywordMap)["f16vec4"] = F16VEC4;
542 (*KeywordMap)["f16mat2"] = F16MAT2;
543 (*KeywordMap)["f16mat3"] = F16MAT3;
544 (*KeywordMap)["f16mat4"] = F16MAT4;
545 (*KeywordMap)["f16mat2x2"] = F16MAT2X2;
546 (*KeywordMap)["f16mat2x3"] = F16MAT2X3;
547 (*KeywordMap)["f16mat2x4"] = F16MAT2X4;
548 (*KeywordMap)["f16mat3x2"] = F16MAT3X2;
549 (*KeywordMap)["f16mat3x3"] = F16MAT3X3;
550 (*KeywordMap)["f16mat3x4"] = F16MAT3X4;
551 (*KeywordMap)["f16mat4x2"] = F16MAT4X2;
552 (*KeywordMap)["f16mat4x3"] = F16MAT4X3;
553 (*KeywordMap)["f16mat4x4"] = F16MAT4X4;
555 (*KeywordMap)["float32_t"] = FLOAT32_T;
556 (*KeywordMap)["f32vec2"] = F32VEC2;
557 (*KeywordMap)["f32vec3"] = F32VEC3;
558 (*KeywordMap)["f32vec4"] = F32VEC4;
559 (*KeywordMap)["f32mat2"] = F32MAT2;
560 (*KeywordMap)["f32mat3"] = F32MAT3;
561 (*KeywordMap)["f32mat4"] = F32MAT4;
562 (*KeywordMap)["f32mat2x2"] = F32MAT2X2;
563 (*KeywordMap)["f32mat2x3"] = F32MAT2X3;
564 (*KeywordMap)["f32mat2x4"] = F32MAT2X4;
565 (*KeywordMap)["f32mat3x2"] = F32MAT3X2;
566 (*KeywordMap)["f32mat3x3"] = F32MAT3X3;
567 (*KeywordMap)["f32mat3x4"] = F32MAT3X4;
568 (*KeywordMap)["f32mat4x2"] = F32MAT4X2;
569 (*KeywordMap)["f32mat4x3"] = F32MAT4X3;
570 (*KeywordMap)["f32mat4x4"] = F32MAT4X4;
571 (*KeywordMap)["float64_t"] = FLOAT64_T;
572 (*KeywordMap)["f64vec2"] = F64VEC2;
573 (*KeywordMap)["f64vec3"] = F64VEC3;
574 (*KeywordMap)["f64vec4"] = F64VEC4;
575 (*KeywordMap)["f64mat2"] = F64MAT2;
576 (*KeywordMap)["f64mat3"] = F64MAT3;
577 (*KeywordMap)["f64mat4"] = F64MAT4;
578 (*KeywordMap)["f64mat2x2"] = F64MAT2X2;
579 (*KeywordMap)["f64mat2x3"] = F64MAT2X3;
580 (*KeywordMap)["f64mat2x4"] = F64MAT2X4;
581 (*KeywordMap)["f64mat3x2"] = F64MAT3X2;
582 (*KeywordMap)["f64mat3x3"] = F64MAT3X3;
583 (*KeywordMap)["f64mat3x4"] = F64MAT3X4;
584 (*KeywordMap)["f64mat4x2"] = F64MAT4X2;
585 (*KeywordMap)["f64mat4x3"] = F64MAT4X3;
586 (*KeywordMap)["f64mat4x4"] = F64MAT4X4;
589 (*KeywordMap)["sampler2D"] = SAMPLER2D;
590 (*KeywordMap)["samplerCube"] = SAMPLERCUBE;
591 (*KeywordMap)["samplerCubeShadow"] = SAMPLERCUBESHADOW;
592 (*KeywordMap)["sampler2DArray"] = SAMPLER2DARRAY;
593 (*KeywordMap)["sampler2DArrayShadow"] = SAMPLER2DARRAYSHADOW;
594 (*KeywordMap)["isampler2D"] = ISAMPLER2D;
595 (*KeywordMap)["isampler3D"] = ISAMPLER3D;
596 (*KeywordMap)["isamplerCube"] = ISAMPLERCUBE;
597 (*KeywordMap)["isampler2DArray"] = ISAMPLER2DARRAY;
598 (*KeywordMap)["usampler2D"] = USAMPLER2D;
599 (*KeywordMap)["usampler3D"] = USAMPLER3D;
600 (*KeywordMap)["usamplerCube"] = USAMPLERCUBE;
601 (*KeywordMap)["usampler2DArray"] = USAMPLER2DARRAY;
602 (*KeywordMap)["sampler3D"] = SAMPLER3D;
603 (*KeywordMap)["sampler2DShadow"] = SAMPLER2DSHADOW;
605 (*KeywordMap)["texture2D"] = TEXTURE2D;
606 (*KeywordMap)["textureCube"] = TEXTURECUBE;
607 (*KeywordMap)["texture2DArray"] = TEXTURE2DARRAY;
608 (*KeywordMap)["itexture2D"] = ITEXTURE2D;
609 (*KeywordMap)["itexture3D"] = ITEXTURE3D;
610 (*KeywordMap)["itextureCube"] = ITEXTURECUBE;
611 (*KeywordMap)["itexture2DArray"] = ITEXTURE2DARRAY;
612 (*KeywordMap)["utexture2D"] = UTEXTURE2D;
613 (*KeywordMap)["utexture3D"] = UTEXTURE3D;
614 (*KeywordMap)["utextureCube"] = UTEXTURECUBE;
615 (*KeywordMap)["utexture2DArray"] = UTEXTURE2DARRAY;
616 (*KeywordMap)["texture3D"] = TEXTURE3D;
618 (*KeywordMap)["sampler"] = SAMPLER;
619 (*KeywordMap)["samplerShadow"] = SAMPLERSHADOW;
622 (*KeywordMap)["textureCubeArray"] = TEXTURECUBEARRAY;
623 (*KeywordMap)["itextureCubeArray"] = ITEXTURECUBEARRAY;
624 (*KeywordMap)["utextureCubeArray"] = UTEXTURECUBEARRAY;
625 (*KeywordMap)["samplerCubeArray"] = SAMPLERCUBEARRAY;
626 (*KeywordMap)["samplerCubeArrayShadow"] = SAMPLERCUBEARRAYSHADOW;
627 (*KeywordMap)["isamplerCubeArray"] = ISAMPLERCUBEARRAY;
628 (*KeywordMap)["usamplerCubeArray"] = USAMPLERCUBEARRAY;
629 (*KeywordMap)["sampler1DArrayShadow"] = SAMPLER1DARRAYSHADOW;
630 (*KeywordMap)["isampler1DArray"] = ISAMPLER1DARRAY;
631 (*KeywordMap)["usampler1D"] = USAMPLER1D;
632 (*KeywordMap)["isampler1D"] = ISAMPLER1D;
633 (*KeywordMap)["usampler1DArray"] = USAMPLER1DARRAY;
634 (*KeywordMap)["samplerBuffer"] = SAMPLERBUFFER;
635 (*KeywordMap)["isampler2DRect"] = ISAMPLER2DRECT;
636 (*KeywordMap)["usampler2DRect"] = USAMPLER2DRECT;
637 (*KeywordMap)["isamplerBuffer"] = ISAMPLERBUFFER;
638 (*KeywordMap)["usamplerBuffer"] = USAMPLERBUFFER;
639 (*KeywordMap)["sampler2DMS"] = SAMPLER2DMS;
640 (*KeywordMap)["isampler2DMS"] = ISAMPLER2DMS;
641 (*KeywordMap)["usampler2DMS"] = USAMPLER2DMS;
642 (*KeywordMap)["sampler2DMSArray"] = SAMPLER2DMSARRAY;
643 (*KeywordMap)["isampler2DMSArray"] = ISAMPLER2DMSARRAY;
644 (*KeywordMap)["usampler2DMSArray"] = USAMPLER2DMSARRAY;
645 (*KeywordMap)["sampler1D"] = SAMPLER1D;
646 (*KeywordMap)["sampler1DShadow"] = SAMPLER1DSHADOW;
647 (*KeywordMap)["sampler2DRect"] = SAMPLER2DRECT;
648 (*KeywordMap)["sampler2DRectShadow"] = SAMPLER2DRECTSHADOW;
649 (*KeywordMap)["sampler1DArray"] = SAMPLER1DARRAY;
651 (*KeywordMap)["samplerExternalOES"] = SAMPLEREXTERNALOES; // GL_OES_EGL_image_external
653 (*KeywordMap)["__samplerExternal2DY2YEXT"] = SAMPLEREXTERNAL2DY2YEXT; // GL_EXT_YUV_target
655 (*KeywordMap)["itexture1DArray"] = ITEXTURE1DARRAY;
656 (*KeywordMap)["utexture1D"] = UTEXTURE1D;
657 (*KeywordMap)["itexture1D"] = ITEXTURE1D;
658 (*KeywordMap)["utexture1DArray"] = UTEXTURE1DARRAY;
659 (*KeywordMap)["textureBuffer"] = TEXTUREBUFFER;
660 (*KeywordMap)["itexture2DRect"] = ITEXTURE2DRECT;
661 (*KeywordMap)["utexture2DRect"] = UTEXTURE2DRECT;
662 (*KeywordMap)["itextureBuffer"] = ITEXTUREBUFFER;
663 (*KeywordMap)["utextureBuffer"] = UTEXTUREBUFFER;
664 (*KeywordMap)["texture2DMS"] = TEXTURE2DMS;
665 (*KeywordMap)["itexture2DMS"] = ITEXTURE2DMS;
666 (*KeywordMap)["utexture2DMS"] = UTEXTURE2DMS;
667 (*KeywordMap)["texture2DMSArray"] = TEXTURE2DMSARRAY;
668 (*KeywordMap)["itexture2DMSArray"] = ITEXTURE2DMSARRAY;
669 (*KeywordMap)["utexture2DMSArray"] = UTEXTURE2DMSARRAY;
670 (*KeywordMap)["texture1D"] = TEXTURE1D;
671 (*KeywordMap)["texture2DRect"] = TEXTURE2DRECT;
672 (*KeywordMap)["texture1DArray"] = TEXTURE1DARRAY;
674 (*KeywordMap)["subpassInput"] = SUBPASSINPUT;
675 (*KeywordMap)["subpassInputMS"] = SUBPASSINPUTMS;
676 (*KeywordMap)["isubpassInput"] = ISUBPASSINPUT;
677 (*KeywordMap)["isubpassInputMS"] = ISUBPASSINPUTMS;
678 (*KeywordMap)["usubpassInput"] = USUBPASSINPUT;
679 (*KeywordMap)["usubpassInputMS"] = USUBPASSINPUTMS;
681 (*KeywordMap)["f16sampler1D"] = F16SAMPLER1D;
682 (*KeywordMap)["f16sampler2D"] = F16SAMPLER2D;
683 (*KeywordMap)["f16sampler3D"] = F16SAMPLER3D;
684 (*KeywordMap)["f16sampler2DRect"] = F16SAMPLER2DRECT;
685 (*KeywordMap)["f16samplerCube"] = F16SAMPLERCUBE;
686 (*KeywordMap)["f16sampler1DArray"] = F16SAMPLER1DARRAY;
687 (*KeywordMap)["f16sampler2DArray"] = F16SAMPLER2DARRAY;
688 (*KeywordMap)["f16samplerCubeArray"] = F16SAMPLERCUBEARRAY;
689 (*KeywordMap)["f16samplerBuffer"] = F16SAMPLERBUFFER;
690 (*KeywordMap)["f16sampler2DMS"] = F16SAMPLER2DMS;
691 (*KeywordMap)["f16sampler2DMSArray"] = F16SAMPLER2DMSARRAY;
692 (*KeywordMap)["f16sampler1DShadow"] = F16SAMPLER1DSHADOW;
693 (*KeywordMap)["f16sampler2DShadow"] = F16SAMPLER2DSHADOW;
694 (*KeywordMap)["f16sampler2DRectShadow"] = F16SAMPLER2DRECTSHADOW;
695 (*KeywordMap)["f16samplerCubeShadow"] = F16SAMPLERCUBESHADOW;
696 (*KeywordMap)["f16sampler1DArrayShadow"] = F16SAMPLER1DARRAYSHADOW;
697 (*KeywordMap)["f16sampler2DArrayShadow"] = F16SAMPLER2DARRAYSHADOW;
698 (*KeywordMap)["f16samplerCubeArrayShadow"] = F16SAMPLERCUBEARRAYSHADOW;
700 (*KeywordMap)["f16image1D"] = F16IMAGE1D;
701 (*KeywordMap)["f16image2D"] = F16IMAGE2D;
702 (*KeywordMap)["f16image3D"] = F16IMAGE3D;
703 (*KeywordMap)["f16image2DRect"] = F16IMAGE2DRECT;
704 (*KeywordMap)["f16imageCube"] = F16IMAGECUBE;
705 (*KeywordMap)["f16image1DArray"] = F16IMAGE1DARRAY;
706 (*KeywordMap)["f16image2DArray"] = F16IMAGE2DARRAY;
707 (*KeywordMap)["f16imageCubeArray"] = F16IMAGECUBEARRAY;
708 (*KeywordMap)["f16imageBuffer"] = F16IMAGEBUFFER;
709 (*KeywordMap)["f16image2DMS"] = F16IMAGE2DMS;
710 (*KeywordMap)["f16image2DMSArray"] = F16IMAGE2DMSARRAY;
712 (*KeywordMap)["f16texture1D"] = F16TEXTURE1D;
713 (*KeywordMap)["f16texture2D"] = F16TEXTURE2D;
714 (*KeywordMap)["f16texture3D"] = F16TEXTURE3D;
715 (*KeywordMap)["f16texture2DRect"] = F16TEXTURE2DRECT;
716 (*KeywordMap)["f16textureCube"] = F16TEXTURECUBE;
717 (*KeywordMap)["f16texture1DArray"] = F16TEXTURE1DARRAY;
718 (*KeywordMap)["f16texture2DArray"] = F16TEXTURE2DARRAY;
719 (*KeywordMap)["f16textureCubeArray"] = F16TEXTURECUBEARRAY;
720 (*KeywordMap)["f16textureBuffer"] = F16TEXTUREBUFFER;
721 (*KeywordMap)["f16texture2DMS"] = F16TEXTURE2DMS;
722 (*KeywordMap)["f16texture2DMSArray"] = F16TEXTURE2DMSARRAY;
724 (*KeywordMap)["f16subpassInput"] = F16SUBPASSINPUT;
725 (*KeywordMap)["f16subpassInputMS"] = F16SUBPASSINPUTMS;
726 (*KeywordMap)["__explicitInterpAMD"] = EXPLICITINTERPAMD;
727 (*KeywordMap)["pervertexNV"] = PERVERTEXNV;
728 (*KeywordMap)["precise"] = PRECISE;
730 (*KeywordMap)["rayPayloadNV"] = PAYLOADNV;
731 (*KeywordMap)["rayPayloadEXT"] = PAYLOADEXT;
732 (*KeywordMap)["rayPayloadInNV"] = PAYLOADINNV;
733 (*KeywordMap)["rayPayloadInEXT"] = PAYLOADINEXT;
734 (*KeywordMap)["hitAttributeNV"] = HITATTRNV;
735 (*KeywordMap)["hitAttributeEXT"] = HITATTREXT;
736 (*KeywordMap)["callableDataNV"] = CALLDATANV;
737 (*KeywordMap)["callableDataEXT"] = CALLDATAEXT;
738 (*KeywordMap)["callableDataInNV"] = CALLDATAINNV;
739 (*KeywordMap)["callableDataInEXT"] = CALLDATAINEXT;
740 (*KeywordMap)["accelerationStructureNV"] = ACCSTRUCTNV;
741 (*KeywordMap)["accelerationStructureEXT"] = ACCSTRUCTEXT;
742 (*KeywordMap)["rayQueryEXT"] = RAYQUERYEXT;
743 (*KeywordMap)["perprimitiveNV"] = PERPRIMITIVENV;
744 (*KeywordMap)["perviewNV"] = PERVIEWNV;
745 (*KeywordMap)["taskNV"] = PERTASKNV;
747 (*KeywordMap)["fcoopmatNV"] = FCOOPMATNV;
748 (*KeywordMap)["icoopmatNV"] = ICOOPMATNV;
749 (*KeywordMap)["ucoopmatNV"] = UCOOPMATNV;
751 ReservedSet = new std::unordered_set<const char*, str_hash, str_eq>;
753 ReservedSet->insert("common");
754 ReservedSet->insert("partition");
755 ReservedSet->insert("active");
756 ReservedSet->insert("asm");
757 ReservedSet->insert("class");
758 ReservedSet->insert("union");
759 ReservedSet->insert("enum");
760 ReservedSet->insert("typedef");
761 ReservedSet->insert("template");
762 ReservedSet->insert("this");
763 ReservedSet->insert("goto");
764 ReservedSet->insert("inline");
765 ReservedSet->insert("noinline");
766 ReservedSet->insert("public");
767 ReservedSet->insert("static");
768 ReservedSet->insert("extern");
769 ReservedSet->insert("external");
770 ReservedSet->insert("interface");
771 ReservedSet->insert("long");
772 ReservedSet->insert("short");
773 ReservedSet->insert("half");
774 ReservedSet->insert("fixed");
775 ReservedSet->insert("unsigned");
776 ReservedSet->insert("input");
777 ReservedSet->insert("output");
778 ReservedSet->insert("hvec2");
779 ReservedSet->insert("hvec3");
780 ReservedSet->insert("hvec4");
781 ReservedSet->insert("fvec2");
782 ReservedSet->insert("fvec3");
783 ReservedSet->insert("fvec4");
784 ReservedSet->insert("sampler3DRect");
785 ReservedSet->insert("filter");
786 ReservedSet->insert("sizeof");
787 ReservedSet->insert("cast");
788 ReservedSet->insert("namespace");
789 ReservedSet->insert("using");
793 void TScanContext::deleteKeywordMap()
796 KeywordMap = nullptr;
799 ReservedSet = nullptr;
803 // Called by yylex to get the next token.
804 // Returning 0 implies end of input.
805 int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
808 parserToken = &token;
810 int token = pp->tokenize(ppToken);
811 if (token == EndOfInput)
814 tokenText = ppToken.name;
816 parserToken->sType.lex.loc = loc;
818 case ';': afterType = false; afterBuffer = false; return SEMICOLON;
819 case ',': afterType = false; return COMMA;
820 case ':': return COLON;
821 case '=': afterType = false; return EQUAL;
822 case '(': afterType = false; return LEFT_PAREN;
823 case ')': afterType = false; return RIGHT_PAREN;
824 case '.': field = true; return DOT;
825 case '!': return BANG;
826 case '-': return DASH;
827 case '~': return TILDE;
828 case '+': return PLUS;
829 case '*': return STAR;
830 case '/': return SLASH;
831 case '%': return PERCENT;
832 case '<': return LEFT_ANGLE;
833 case '>': return RIGHT_ANGLE;
834 case '|': return VERTICAL_BAR;
835 case '^': return CARET;
836 case '&': return AMPERSAND;
837 case '?': return QUESTION;
838 case '[': return LEFT_BRACKET;
839 case ']': return RIGHT_BRACKET;
840 case '{': afterStruct = false; afterBuffer = false; return LEFT_BRACE;
841 case '}': return RIGHT_BRACE;
843 parseContext.error(loc, "illegal use of escape character", "\\", "");
846 case PPAtomAddAssign: return ADD_ASSIGN;
847 case PPAtomSubAssign: return SUB_ASSIGN;
848 case PPAtomMulAssign: return MUL_ASSIGN;
849 case PPAtomDivAssign: return DIV_ASSIGN;
850 case PPAtomModAssign: return MOD_ASSIGN;
852 case PpAtomRight: return RIGHT_OP;
853 case PpAtomLeft: return LEFT_OP;
855 case PpAtomRightAssign: return RIGHT_ASSIGN;
856 case PpAtomLeftAssign: return LEFT_ASSIGN;
857 case PpAtomAndAssign: return AND_ASSIGN;
858 case PpAtomOrAssign: return OR_ASSIGN;
859 case PpAtomXorAssign: return XOR_ASSIGN;
861 case PpAtomAnd: return AND_OP;
862 case PpAtomOr: return OR_OP;
863 case PpAtomXor: return XOR_OP;
865 case PpAtomEQ: return EQ_OP;
866 case PpAtomGE: return GE_OP;
867 case PpAtomNE: return NE_OP;
868 case PpAtomLE: return LE_OP;
870 case PpAtomDecrement: return DEC_OP;
871 case PpAtomIncrement: return INC_OP;
873 case PpAtomColonColon:
874 parseContext.error(loc, "not supported", "::", "");
877 case PpAtomConstString: parserToken->sType.lex.string = NewPoolTString(tokenText); return STRING_LITERAL;
878 case PpAtomConstInt: parserToken->sType.lex.i = ppToken.ival; return INTCONSTANT;
879 case PpAtomConstUint: parserToken->sType.lex.i = ppToken.ival; return UINTCONSTANT;
880 case PpAtomConstFloat: parserToken->sType.lex.d = ppToken.dval; return FLOATCONSTANT;
882 case PpAtomConstInt16: parserToken->sType.lex.i = ppToken.ival; return INT16CONSTANT;
883 case PpAtomConstUint16: parserToken->sType.lex.i = ppToken.ival; return UINT16CONSTANT;
884 case PpAtomConstInt64: parserToken->sType.lex.i64 = ppToken.i64val; return INT64CONSTANT;
885 case PpAtomConstUint64: parserToken->sType.lex.i64 = ppToken.i64val; return UINT64CONSTANT;
886 case PpAtomConstDouble: parserToken->sType.lex.d = ppToken.dval; return DOUBLECONSTANT;
887 case PpAtomConstFloat16: parserToken->sType.lex.d = ppToken.dval; return FLOAT16CONSTANT;
889 case PpAtomIdentifier:
891 int token = tokenizeIdentifier();
896 case EndOfInput: return 0;
900 buf[0] = (char)token;
902 parseContext.error(loc, "unexpected token", buf, "");
908 int TScanContext::tokenizeIdentifier()
911 if (ReservedSet->find(tokenText) != ReservedSet->end())
912 return reservedWord();
915 auto it = KeywordMap->find(tokenText);
916 if (it == KeywordMap->end()) {
917 // Should have an identifier of some sort
918 return identifierOrType();
920 keyword = it->second;
940 case TERMINATE_INVOCATION:
941 if (!parseContext.extensionTurnedOn(E_GL_EXT_terminate_invocation))
942 return identifierOrType();
947 if ((parseContext.isEsProfile() && parseContext.version < 310) ||
948 (!parseContext.isEsProfile() && (parseContext.version < 430 &&
949 !parseContext.extensionTurnedOn(E_GL_ARB_shader_storage_buffer_object))))
950 return identifierOrType();
959 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
960 (!parseContext.isEsProfile() && parseContext.version < 130))
986 if (strcmp("true", tokenText) == 0)
987 parserToken->sType.lex.b = true;
989 parserToken->sType.lex.b = false;
993 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
994 (!parseContext.isEsProfile() && parseContext.version < 130))
995 return identifierOrType();
998 if (parseContext.isEsProfile() && parseContext.version < 300)
1000 else if (!parseContext.isEsProfile() && parseContext.version < 130)
1001 return identifierOrType();
1004 if (parseContext.version < 120)
1005 return identifierOrType();
1008 if (!parseContext.isEsProfile() && parseContext.version < 120)
1009 return identifierOrType();
1012 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1013 (!parseContext.isEsProfile() && parseContext.version < 140))
1014 return reservedWord();
1015 return identifierOrType();
1019 bool reserved = (parseContext.isEsProfile() && parseContext.version >= 300) ||
1020 (!parseContext.isEsProfile() && parseContext.version >= 420);
1021 return identifierOrReserved(reserved);
1025 bool reserved = parseContext.isEsProfile() || parseContext.version >= 130;
1026 return identifierOrReserved(reserved);
1031 if (parseContext.extensionTurnedOn(E_GL_NV_shader_noperspective_interpolation))
1033 return es30ReservedFromGLSL(130);
1036 if (parseContext.extensionTurnedOn(E_GL_EXT_nonuniform_qualifier))
1039 return identifierOrType();
1042 if (parseContext.isEsProfile() && parseContext.version >= 300)
1051 if (parseContext.symbolTable.atBuiltInLevel() ||
1052 parseContext.extensionTurnedOn(E_GL_NV_ray_tracing))
1054 return identifierOrType();
1061 if (parseContext.symbolTable.atBuiltInLevel() ||
1062 parseContext.extensionTurnedOn(E_GL_EXT_ray_tracing) ||
1063 parseContext.extensionTurnedOn(E_GL_EXT_ray_query))
1065 return identifierOrType();
1067 if (parseContext.symbolTable.atBuiltInLevel() ||
1068 (!parseContext.isEsProfile() && parseContext.version >= 460
1069 && parseContext.extensionTurnedOn(E_GL_EXT_ray_query)))
1071 return identifierOrType();
1073 if ((parseContext.isEsProfile() && parseContext.version >= 310) ||
1074 parseContext.extensionTurnedOn(E_GL_ARB_shader_atomic_counters))
1076 return es30ReservedFromGLSL(420);
1079 case DEVICECOHERENT:
1080 case QUEUEFAMILYCOHERENT:
1081 case WORKGROUPCOHERENT:
1082 case SUBGROUPCOHERENT:
1083 case SHADERCALLCOHERENT:
1088 if (parseContext.isEsProfile() && parseContext.version >= 310)
1090 return es30ReservedFromGLSL(parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store) ? 130 : 420);
1092 if (parseContext.isEsProfile() && parseContext.version >= 310)
1094 if (! parseContext.symbolTable.atBuiltInLevel() && (parseContext.isEsProfile() ||
1095 (parseContext.version < 420 && ! parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1099 if (parseContext.symbolTable.atBuiltInLevel() ||
1100 (parseContext.isEsProfile() &&
1101 (parseContext.version >= 320 ||
1102 parseContext.extensionsTurnedOn(Num_AEP_tessellation_shader, AEP_tessellation_shader))) ||
1103 (!parseContext.isEsProfile() && parseContext.extensionTurnedOn(E_GL_ARB_tessellation_shader)))
1106 return es30ReservedFromGLSL(400);
1109 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1110 parseContext.extensionsTurnedOn(1, &E_GL_OES_shader_multisample_interpolation))
1112 return es30ReservedFromGLSL(400);
1115 return es30ReservedFromGLSL(400);
1118 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1119 (!parseContext.isEsProfile() && parseContext.version < 140))
1120 return identifierOrType();
1124 const int numLayoutExts = 2;
1125 const char* layoutExts[numLayoutExts] = { E_GL_ARB_shading_language_420pack,
1126 E_GL_ARB_explicit_attrib_location };
1127 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1128 (!parseContext.isEsProfile() && parseContext.version < 140 &&
1129 ! parseContext.extensionsTurnedOn(numLayoutExts, layoutExts)))
1130 return identifierOrType();
1134 case HIGH_PRECISION:
1135 case MEDIUM_PRECISION:
1138 return precisionKeyword();
1176 return firstGenerationImage(false);
1180 case I64IMAGE1DARRAY:
1181 case U64IMAGE1DARRAY:
1182 case I64IMAGE2DRECT:
1183 case U64IMAGE2DRECT:
1185 if (parseContext.symbolTable.atBuiltInLevel() ||
1186 parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
1187 return firstGenerationImage(false);
1189 return identifierOrType();
1195 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1196 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1198 return firstGenerationImage(false);
1200 case I64IMAGEBUFFER:
1201 case U64IMAGEBUFFER:
1203 if (parseContext.symbolTable.atBuiltInLevel() ||
1204 parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
1205 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1206 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1208 return firstGenerationImage(false);
1210 return identifierOrType();
1225 return firstGenerationImage(true);
1233 case I64IMAGE2DARRAY:
1234 case U64IMAGE2DARRAY:
1236 if (parseContext.symbolTable.atBuiltInLevel() ||
1237 parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64))
1238 return firstGenerationImage(true);
1239 return identifierOrType();
1241 case IMAGECUBEARRAY:
1242 case IIMAGECUBEARRAY:
1243 case UIMAGECUBEARRAY:
1245 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1246 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1248 return secondGenerationImage();
1250 case I64IMAGECUBEARRAY:
1251 case U64IMAGECUBEARRAY:
1253 if (parseContext.symbolTable.atBuiltInLevel() ||
1254 parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
1255 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1256 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1258 return secondGenerationImage();
1260 return identifierOrType();
1265 case IMAGE2DMSARRAY:
1266 case IIMAGE2DMSARRAY:
1267 case UIMAGE2DMSARRAY:
1269 return secondGenerationImage();
1273 case I64IMAGE2DMSARRAY:
1274 case U64IMAGE2DMSARRAY:
1276 if (parseContext.symbolTable.atBuiltInLevel() ||
1277 parseContext.extensionTurnedOn(E_GL_EXT_shader_image_int64)) {
1278 return secondGenerationImage();
1280 return identifierOrType();
1287 if (parseContext.isEsProfile() || parseContext.version < 150 ||
1288 (!parseContext.symbolTable.atBuiltInLevel() &&
1289 (parseContext.version < 400 && !parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64) &&
1290 (parseContext.version < 410 && !parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)))))
1303 if (parseContext.symbolTable.atBuiltInLevel() ||
1304 parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_int64) ||
1305 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1306 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int64))
1308 return identifierOrType();
1319 if (parseContext.symbolTable.atBuiltInLevel() ||
1320 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1321 parseContext.extensionTurnedOn(E_GL_EXT_shader_8bit_storage) ||
1322 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int8))
1324 return identifierOrType();
1335 if (parseContext.symbolTable.atBuiltInLevel() ||
1336 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_int16) ||
1337 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1338 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1339 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int16))
1341 return identifierOrType();
1351 if (parseContext.symbolTable.atBuiltInLevel() ||
1352 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1353 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_int32))
1355 return identifierOrType();
1373 if (parseContext.symbolTable.atBuiltInLevel() ||
1374 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1375 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float32))
1377 return identifierOrType();
1396 if (parseContext.symbolTable.atBuiltInLevel() ||
1397 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1398 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float64))
1400 return identifierOrType();
1407 if (parseContext.symbolTable.atBuiltInLevel() ||
1408 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1409 parseContext.extensionTurnedOn(E_GL_EXT_shader_16bit_storage) ||
1410 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1411 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1414 return identifierOrType();
1429 if (parseContext.symbolTable.atBuiltInLevel() ||
1430 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float) ||
1431 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types) ||
1432 parseContext.extensionTurnedOn(E_GL_EXT_shader_explicit_arithmetic_types_float16))
1435 return identifierOrType();
1437 case SAMPLERCUBEARRAY:
1438 case SAMPLERCUBEARRAYSHADOW:
1439 case ISAMPLERCUBEARRAY:
1440 case USAMPLERCUBEARRAY:
1442 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1443 parseContext.extensionsTurnedOn(Num_AEP_texture_cube_map_array, AEP_texture_cube_map_array))
1445 if (parseContext.isEsProfile() || (parseContext.version < 400 && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_cube_map_array)))
1449 case TEXTURECUBEARRAY:
1450 case ITEXTURECUBEARRAY:
1451 case UTEXTURECUBEARRAY:
1452 if (parseContext.spvVersion.vulkan > 0)
1455 return identifierOrType();
1462 case SAMPLERCUBESHADOW:
1463 case SAMPLER2DARRAY:
1464 case SAMPLER2DARRAYSHADOW:
1468 case ISAMPLER2DARRAY:
1472 case USAMPLER2DARRAY:
1474 return nonreservedKeyword(300, 130);
1478 if (parseContext.isEsProfile() && parseContext.version < 300) {
1479 if (!parseContext.extensionTurnedOn(E_GL_OES_texture_3D))
1484 case SAMPLER2DSHADOW:
1486 if (parseContext.isEsProfile() && parseContext.version < 300) {
1487 if (!parseContext.extensionTurnedOn(E_GL_EXT_shadow_samplers))
1494 case TEXTURE2DARRAY:
1498 case ITEXTURE2DARRAY:
1502 case UTEXTURE2DARRAY:
1506 if (parseContext.spvVersion.vulkan > 0)
1509 return identifierOrType();
1513 case ISAMPLER1DARRAY:
1514 case SAMPLER1DARRAYSHADOW:
1516 case USAMPLER1DARRAY:
1518 return es30ReservedFromGLSL(130);
1519 case ISAMPLER2DRECT:
1520 case USAMPLER2DRECT:
1522 return es30ReservedFromGLSL(140);
1526 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1527 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1529 return es30ReservedFromGLSL(130);
1531 case ISAMPLERBUFFER:
1532 case USAMPLERBUFFER:
1534 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1535 parseContext.extensionsTurnedOn(Num_AEP_texture_buffer, AEP_texture_buffer))
1537 return es30ReservedFromGLSL(140);
1543 if (parseContext.isEsProfile() && parseContext.version >= 310)
1545 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1546 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1548 return es30ReservedFromGLSL(150);
1550 case SAMPLER2DMSARRAY:
1551 case ISAMPLER2DMSARRAY:
1552 case USAMPLER2DMSARRAY:
1554 if ((parseContext.isEsProfile() && parseContext.version >= 320) ||
1555 parseContext.extensionsTurnedOn(1, &E_GL_OES_texture_storage_multisample_2d_array))
1557 if (!parseContext.isEsProfile() && (parseContext.version > 140 ||
1558 (parseContext.version == 140 && parseContext.extensionsTurnedOn(1, &E_GL_ARB_texture_multisample))))
1560 return es30ReservedFromGLSL(150);
1563 case SAMPLER1DSHADOW:
1565 if (parseContext.isEsProfile())
1570 case SAMPLER2DRECTSHADOW:
1572 if (parseContext.isEsProfile())
1574 else if (parseContext.version < 140 && ! parseContext.symbolTable.atBuiltInLevel() && ! parseContext.extensionTurnedOn(E_GL_ARB_texture_rectangle)) {
1575 if (parseContext.relaxedErrors())
1576 parseContext.requireExtensions(loc, 1, &E_GL_ARB_texture_rectangle, "texture-rectangle sampler keyword");
1582 case SAMPLER1DARRAY:
1584 if (parseContext.isEsProfile() && parseContext.version == 300)
1586 else if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1587 (!parseContext.isEsProfile() && parseContext.version < 130))
1588 return identifierOrType();
1591 case SAMPLEREXTERNALOES:
1593 if (parseContext.symbolTable.atBuiltInLevel() ||
1594 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external) ||
1595 parseContext.extensionTurnedOn(E_GL_OES_EGL_image_external_essl3))
1597 return identifierOrType();
1599 case SAMPLEREXTERNAL2DY2YEXT:
1601 if (parseContext.symbolTable.atBuiltInLevel() ||
1602 parseContext.extensionTurnedOn(E_GL_EXT_YUV_target))
1604 return identifierOrType();
1606 case ITEXTURE1DARRAY:
1609 case UTEXTURE1DARRAY:
1611 case ITEXTURE2DRECT:
1612 case UTEXTURE2DRECT:
1613 case ITEXTUREBUFFER:
1614 case UTEXTUREBUFFER:
1618 case TEXTURE2DMSARRAY:
1619 case ITEXTURE2DMSARRAY:
1620 case UTEXTURE2DMSARRAY:
1623 case TEXTURE1DARRAY:
1624 if (parseContext.spvVersion.vulkan > 0)
1627 return identifierOrType();
1630 case SUBPASSINPUTMS:
1632 case ISUBPASSINPUTMS:
1634 case USUBPASSINPUTMS:
1635 if (parseContext.spvVersion.vulkan > 0)
1638 return identifierOrType();
1643 case F16SAMPLER2DRECT:
1644 case F16SAMPLERCUBE:
1645 case F16SAMPLER1DARRAY:
1646 case F16SAMPLER2DARRAY:
1647 case F16SAMPLERCUBEARRAY:
1648 case F16SAMPLERBUFFER:
1649 case F16SAMPLER2DMS:
1650 case F16SAMPLER2DMSARRAY:
1651 case F16SAMPLER1DSHADOW:
1652 case F16SAMPLER2DSHADOW:
1653 case F16SAMPLER1DARRAYSHADOW:
1654 case F16SAMPLER2DARRAYSHADOW:
1655 case F16SAMPLER2DRECTSHADOW:
1656 case F16SAMPLERCUBESHADOW:
1657 case F16SAMPLERCUBEARRAYSHADOW:
1662 case F16IMAGE2DRECT:
1664 case F16IMAGE1DARRAY:
1665 case F16IMAGE2DARRAY:
1666 case F16IMAGECUBEARRAY:
1667 case F16IMAGEBUFFER:
1669 case F16IMAGE2DMSARRAY:
1674 case F16TEXTURE2DRECT:
1675 case F16TEXTURECUBE:
1676 case F16TEXTURE1DARRAY:
1677 case F16TEXTURE2DARRAY:
1678 case F16TEXTURECUBEARRAY:
1679 case F16TEXTUREBUFFER:
1680 case F16TEXTURE2DMS:
1681 case F16TEXTURE2DMSARRAY:
1683 case F16SUBPASSINPUT:
1684 case F16SUBPASSINPUTMS:
1686 if (parseContext.symbolTable.atBuiltInLevel() ||
1687 parseContext.extensionTurnedOn(E_GL_AMD_gpu_shader_half_float_fetch))
1689 return identifierOrType();
1691 case EXPLICITINTERPAMD:
1692 if (parseContext.extensionTurnedOn(E_GL_AMD_shader_explicit_vertex_parameter))
1694 return identifierOrType();
1697 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1698 parseContext.extensionTurnedOn(E_GL_NV_fragment_shader_barycentric))
1700 return identifierOrType();
1703 if ((parseContext.isEsProfile() &&
1704 (parseContext.version >= 320 || parseContext.extensionsTurnedOn(Num_AEP_gpu_shader5, AEP_gpu_shader5))) ||
1705 (!parseContext.isEsProfile() && parseContext.version >= 400))
1707 if (parseContext.isEsProfile() && parseContext.version == 310) {
1711 return identifierOrType();
1713 case PERPRIMITIVENV:
1716 if ((!parseContext.isEsProfile() && parseContext.version >= 450) ||
1717 (parseContext.isEsProfile() && parseContext.version >= 320) ||
1718 parseContext.extensionTurnedOn(E_GL_NV_mesh_shader))
1720 return identifierOrType();
1724 if (parseContext.symbolTable.atBuiltInLevel() ||
1725 parseContext.extensionTurnedOn(E_GL_NV_cooperative_matrix))
1727 return identifierOrType();
1732 if (parseContext.symbolTable.atBuiltInLevel() ||
1733 parseContext.extensionTurnedOn(E_GL_NV_integer_cooperative_matrix))
1735 return identifierOrType();
1738 if (parseContext.extensionTurnedOn(E_GL_EXT_demote_to_helper_invocation))
1741 return identifierOrType();
1745 parseContext.infoSink.info.message(EPrefixInternalError, "Unknown glslang keyword", loc);
1750 int TScanContext::identifierOrType()
1752 parserToken->sType.lex.string = NewPoolTString(tokenText);
1756 parserToken->sType.lex.symbol = parseContext.symbolTable.find(*parserToken->sType.lex.string);
1757 if ((afterType == false && afterStruct == false) && parserToken->sType.lex.symbol != nullptr) {
1758 if (const TVariable* variable = parserToken->sType.lex.symbol->getAsVariable()) {
1759 if (variable->isUserType() &&
1760 // treat redeclaration of forward-declared buffer/uniform reference as an identifier
1761 !(variable->getType().isReference() && afterBuffer)) {
1772 // Give an error for use of a reserved symbol.
1773 // However, allow built-in declarations to use reserved words, to allow
1774 // extension support before the extension is enabled.
1775 int TScanContext::reservedWord()
1777 if (! parseContext.symbolTable.atBuiltInLevel())
1778 parseContext.error(loc, "Reserved word.", tokenText, "", "");
1783 int TScanContext::identifierOrReserved(bool reserved)
1791 if (parseContext.isForwardCompatible())
1792 parseContext.warn(loc, "using future reserved keyword", tokenText, "");
1794 return identifierOrType();
1797 // For keywords that suddenly showed up on non-ES (not previously reserved)
1798 // but then got reserved by ES 3.0.
1799 int TScanContext::es30ReservedFromGLSL(int version)
1801 if (parseContext.symbolTable.atBuiltInLevel())
1804 if ((parseContext.isEsProfile() && parseContext.version < 300) ||
1805 (!parseContext.isEsProfile() && parseContext.version < version)) {
1806 if (parseContext.isForwardCompatible())
1807 parseContext.warn(loc, "future reserved word in ES 300 and keyword in GLSL", tokenText, "");
1809 return identifierOrType();
1810 } else if (parseContext.isEsProfile() && parseContext.version >= 300)
1816 // For a keyword that was never reserved, until it suddenly
1817 // showed up, both in an es version and a non-ES version.
1818 int TScanContext::nonreservedKeyword(int esVersion, int nonEsVersion)
1820 if ((parseContext.isEsProfile() && parseContext.version < esVersion) ||
1821 (!parseContext.isEsProfile() && parseContext.version < nonEsVersion)) {
1822 if (parseContext.isForwardCompatible())
1823 parseContext.warn(loc, "using future keyword", tokenText, "");
1825 return identifierOrType();
1831 int TScanContext::precisionKeyword()
1833 if (parseContext.isEsProfile() || parseContext.version >= 130)
1836 if (parseContext.isForwardCompatible())
1837 parseContext.warn(loc, "using ES precision qualifier keyword", tokenText, "");
1839 return identifierOrType();
1842 int TScanContext::matNxM()
1846 if (parseContext.version > 110)
1849 if (parseContext.isForwardCompatible())
1850 parseContext.warn(loc, "using future non-square matrix type keyword", tokenText, "");
1852 return identifierOrType();
1855 int TScanContext::dMat()
1859 if (parseContext.isEsProfile() && parseContext.version >= 300) {
1865 if (!parseContext.isEsProfile() && (parseContext.version >= 400 ||
1866 parseContext.symbolTable.atBuiltInLevel() ||
1867 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_gpu_shader_fp64)) ||
1868 (parseContext.version >= 150 && parseContext.extensionTurnedOn(E_GL_ARB_vertex_attrib_64bit)
1869 && parseContext.language == EShLangVertex)))
1872 if (parseContext.isForwardCompatible())
1873 parseContext.warn(loc, "using future type keyword", tokenText, "");
1875 return identifierOrType();
1878 int TScanContext::firstGenerationImage(bool inEs310)
1880 if (parseContext.symbolTable.atBuiltInLevel() ||
1881 (!parseContext.isEsProfile() && (parseContext.version >= 420 ||
1882 parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))) ||
1883 (inEs310 && parseContext.isEsProfile() && parseContext.version >= 310))
1886 if ((parseContext.isEsProfile() && parseContext.version >= 300) ||
1887 (!parseContext.isEsProfile() && parseContext.version >= 130)) {
1893 if (parseContext.isForwardCompatible())
1894 parseContext.warn(loc, "using future type keyword", tokenText, "");
1896 return identifierOrType();
1899 int TScanContext::secondGenerationImage()
1901 if (parseContext.isEsProfile() && parseContext.version >= 310) {
1906 if (parseContext.symbolTable.atBuiltInLevel() ||
1907 (!parseContext.isEsProfile() &&
1908 (parseContext.version >= 420 || parseContext.extensionTurnedOn(E_GL_ARB_shader_image_load_store))))
1911 if (parseContext.isForwardCompatible())
1912 parseContext.warn(loc, "using future type keyword", tokenText, "");
1914 return identifierOrType();
1917 } // end namespace glslang