1 // 2 //Copyright (C) 2002-2005 3Dlabs Inc. Ltd. 3 //Copyright (C) 2012-2016 LunarG, Inc. 4 //Copyright (C) 2015-2016 Google, Inc. 5 // 6 //All rights reserved. 7 // 8 //Redistribution and use in source and binary forms, with or without 9 //modification, are permitted provided that the following conditions 10 //are met: 11 // 12 // Redistributions of source code must retain the above copyright 13 // notice, this list of conditions and the following disclaimer. 14 // 15 // Redistributions in binary form must reproduce the above 16 // copyright notice, this list of conditions and the following 17 // disclaimer in the documentation and/or other materials provided 18 // with the distribution. 19 // 20 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its 21 // contributors may be used to endorse or promote products derived 22 // from this software without specific prior written permission. 23 // 24 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 //"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 //COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 //CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 //LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 //POSSIBILITY OF SUCH DAMAGE. 36 // 37 38 // 39 // Create strings that declare built-in definitions, add built-ins programmatically 40 // that cannot be expressed in the strings, and establish mappings between 41 // built-in functions and operators. 42 // 43 // Where to put a built-in: 44 // TBuiltIns::initialize(version,profile) context-independent textual built-ins; add them to the right string 45 // TBuiltIns::initialize(resources,...) context-dependent textual built-ins; add them to the right string 46 // TBuiltIns::identifyBuiltIns(...,symbolTable) context-independent programmatic additions/mappings to the symbol table, 47 // including identifying what extensions are needed if a version does not allow a symbol 48 // TBuiltIns::identifyBuiltIns(...,symbolTable, resources) context-dependent programmatic additions/mappings to the symbol table, 49 // including identifying what extensions are needed if a version does not allow a symbol 50 // 51 52 #include "../Include/intermediate.h" 53 #include "Initialize.h" 54 55 namespace glslang { 56 57 // TODO: ARB_Compatability: do full extension support 58 const bool ARBCompatibility = true; 59 60 const bool ForwardCompatibility = false; 61 62 // change this back to false if depending on textual spellings of texturing calls when consuming the AST 63 // Using PureOperatorBuiltins=false is deprecated. 64 bool PureOperatorBuiltins = true; 65 66 inline bool IncludeLegacy(int version, EProfile profile, const SpvVersion& spvVersion) 67 { 68 return profile != EEsProfile && (version <= 130 || (spvVersion.spv == 0 && ARBCompatibility) || profile == ECompatibilityProfile); 69 } 70 71 // Construct TBuiltInParseables base class. This can be used for language-common constructs. 72 TBuiltInParseables::TBuiltInParseables() 73 { 74 } 75 76 // Destroy TBuiltInParseables. 77 TBuiltInParseables::~TBuiltInParseables() 78 { 79 } 80 81 TBuiltIns::TBuiltIns() 82 { 83 // Set up textual representations for making all the permutations 84 // of texturing/imaging functions. 85 prefixes[EbtFloat] = ""; 86 prefixes[EbtInt] = "i"; 87 prefixes[EbtUint] = "u"; 88 prefixes[EbtInt64] = "i64"; 89 prefixes[EbtUint64] = "u64"; 90 postfixes[2] = "2"; 91 postfixes[3] = "3"; 92 postfixes[4] = "4"; 93 94 // Map from symbolic class of texturing dimension to numeric dimensions. 95 dimMap[Esd1D] = 1; 96 dimMap[Esd2D] = 2; 97 dimMap[EsdRect] = 2; 98 dimMap[Esd3D] = 3; 99 dimMap[EsdCube] = 3; 100 dimMap[EsdBuffer] = 1; 101 dimMap[EsdSubpass] = 2; // potientially unused for now 102 } 103 104 TBuiltIns::~TBuiltIns() 105 { 106 } 107 108 109 // 110 // Add all context-independent built-in functions and variables that are present 111 // for the given version and profile. Share common ones across stages, otherwise 112 // make stage-specific entries. 113 // 114 // Most built-ins variables can be added as simple text strings. Some need to 115 // be added programmatically, which is done later in IdentifyBuiltIns() below. 116 // 117 void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvVersion) 118 { 119 //============================================================================ 120 // 121 // Prototypes for built-in functions seen by both vertex and fragment shaders. 122 // 123 //============================================================================ 124 125 // 126 // Angle and Trigonometric Functions. 127 // 128 commonBuiltins.append( 129 "float radians(float degrees);" 130 "vec2 radians(vec2 degrees);" 131 "vec3 radians(vec3 degrees);" 132 "vec4 radians(vec4 degrees);" 133 134 "float degrees(float radians);" 135 "vec2 degrees(vec2 radians);" 136 "vec3 degrees(vec3 radians);" 137 "vec4 degrees(vec4 radians);" 138 139 "float sin(float angle);" 140 "vec2 sin(vec2 angle);" 141 "vec3 sin(vec3 angle);" 142 "vec4 sin(vec4 angle);" 143 144 "float cos(float angle);" 145 "vec2 cos(vec2 angle);" 146 "vec3 cos(vec3 angle);" 147 "vec4 cos(vec4 angle);" 148 149 "float tan(float angle);" 150 "vec2 tan(vec2 angle);" 151 "vec3 tan(vec3 angle);" 152 "vec4 tan(vec4 angle);" 153 154 "float asin(float x);" 155 "vec2 asin(vec2 x);" 156 "vec3 asin(vec3 x);" 157 "vec4 asin(vec4 x);" 158 159 "float acos(float x);" 160 "vec2 acos(vec2 x);" 161 "vec3 acos(vec3 x);" 162 "vec4 acos(vec4 x);" 163 164 "float atan(float y, float x);" 165 "vec2 atan(vec2 y, vec2 x);" 166 "vec3 atan(vec3 y, vec3 x);" 167 "vec4 atan(vec4 y, vec4 x);" 168 169 "float atan(float y_over_x);" 170 "vec2 atan(vec2 y_over_x);" 171 "vec3 atan(vec3 y_over_x);" 172 "vec4 atan(vec4 y_over_x);" 173 174 "\n"); 175 176 if (version >= 130) { 177 commonBuiltins.append( 178 "float sinh(float angle);" 179 "vec2 sinh(vec2 angle);" 180 "vec3 sinh(vec3 angle);" 181 "vec4 sinh(vec4 angle);" 182 183 "float cosh(float angle);" 184 "vec2 cosh(vec2 angle);" 185 "vec3 cosh(vec3 angle);" 186 "vec4 cosh(vec4 angle);" 187 188 "float tanh(float angle);" 189 "vec2 tanh(vec2 angle);" 190 "vec3 tanh(vec3 angle);" 191 "vec4 tanh(vec4 angle);" 192 193 "float asinh(float x);" 194 "vec2 asinh(vec2 x);" 195 "vec3 asinh(vec3 x);" 196 "vec4 asinh(vec4 x);" 197 198 "float acosh(float x);" 199 "vec2 acosh(vec2 x);" 200 "vec3 acosh(vec3 x);" 201 "vec4 acosh(vec4 x);" 202 203 "float atanh(float y_over_x);" 204 "vec2 atanh(vec2 y_over_x);" 205 "vec3 atanh(vec3 y_over_x);" 206 "vec4 atanh(vec4 y_over_x);" 207 208 "\n"); 209 } 210 211 // 212 // Exponential Functions. 213 // 214 commonBuiltins.append( 215 "float pow(float x, float y);" 216 "vec2 pow(vec2 x, vec2 y);" 217 "vec3 pow(vec3 x, vec3 y);" 218 "vec4 pow(vec4 x, vec4 y);" 219 220 "float exp(float x);" 221 "vec2 exp(vec2 x);" 222 "vec3 exp(vec3 x);" 223 "vec4 exp(vec4 x);" 224 225 "float log(float x);" 226 "vec2 log(vec2 x);" 227 "vec3 log(vec3 x);" 228 "vec4 log(vec4 x);" 229 230 "float exp2(float x);" 231 "vec2 exp2(vec2 x);" 232 "vec3 exp2(vec3 x);" 233 "vec4 exp2(vec4 x);" 234 235 "float log2(float x);" 236 "vec2 log2(vec2 x);" 237 "vec3 log2(vec3 x);" 238 "vec4 log2(vec4 x);" 239 240 "float sqrt(float x);" 241 "vec2 sqrt(vec2 x);" 242 "vec3 sqrt(vec3 x);" 243 "vec4 sqrt(vec4 x);" 244 245 "float inversesqrt(float x);" 246 "vec2 inversesqrt(vec2 x);" 247 "vec3 inversesqrt(vec3 x);" 248 "vec4 inversesqrt(vec4 x);" 249 250 "\n"); 251 252 // 253 // Common Functions. 254 // 255 commonBuiltins.append( 256 "float abs(float x);" 257 "vec2 abs(vec2 x);" 258 "vec3 abs(vec3 x);" 259 "vec4 abs(vec4 x);" 260 261 "float sign(float x);" 262 "vec2 sign(vec2 x);" 263 "vec3 sign(vec3 x);" 264 "vec4 sign(vec4 x);" 265 266 "float floor(float x);" 267 "vec2 floor(vec2 x);" 268 "vec3 floor(vec3 x);" 269 "vec4 floor(vec4 x);" 270 271 "float ceil(float x);" 272 "vec2 ceil(vec2 x);" 273 "vec3 ceil(vec3 x);" 274 "vec4 ceil(vec4 x);" 275 276 "float fract(float x);" 277 "vec2 fract(vec2 x);" 278 "vec3 fract(vec3 x);" 279 "vec4 fract(vec4 x);" 280 281 "float mod(float x, float y);" 282 "vec2 mod(vec2 x, float y);" 283 "vec3 mod(vec3 x, float y);" 284 "vec4 mod(vec4 x, float y);" 285 "vec2 mod(vec2 x, vec2 y);" 286 "vec3 mod(vec3 x, vec3 y);" 287 "vec4 mod(vec4 x, vec4 y);" 288 289 "float min(float x, float y);" 290 "vec2 min(vec2 x, float y);" 291 "vec3 min(vec3 x, float y);" 292 "vec4 min(vec4 x, float y);" 293 "vec2 min(vec2 x, vec2 y);" 294 "vec3 min(vec3 x, vec3 y);" 295 "vec4 min(vec4 x, vec4 y);" 296 297 "float max(float x, float y);" 298 "vec2 max(vec2 x, float y);" 299 "vec3 max(vec3 x, float y);" 300 "vec4 max(vec4 x, float y);" 301 "vec2 max(vec2 x, vec2 y);" 302 "vec3 max(vec3 x, vec3 y);" 303 "vec4 max(vec4 x, vec4 y);" 304 305 "float clamp(float x, float minVal, float maxVal);" 306 "vec2 clamp(vec2 x, float minVal, float maxVal);" 307 "vec3 clamp(vec3 x, float minVal, float maxVal);" 308 "vec4 clamp(vec4 x, float minVal, float maxVal);" 309 "vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal);" 310 "vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal);" 311 "vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);" 312 313 "float mix(float x, float y, float a);" 314 "vec2 mix(vec2 x, vec2 y, float a);" 315 "vec3 mix(vec3 x, vec3 y, float a);" 316 "vec4 mix(vec4 x, vec4 y, float a);" 317 "vec2 mix(vec2 x, vec2 y, vec2 a);" 318 "vec3 mix(vec3 x, vec3 y, vec3 a);" 319 "vec4 mix(vec4 x, vec4 y, vec4 a);" 320 321 "float step(float edge, float x);" 322 "vec2 step(vec2 edge, vec2 x);" 323 "vec3 step(vec3 edge, vec3 x);" 324 "vec4 step(vec4 edge, vec4 x);" 325 "vec2 step(float edge, vec2 x);" 326 "vec3 step(float edge, vec3 x);" 327 "vec4 step(float edge, vec4 x);" 328 329 "float smoothstep(float edge0, float edge1, float x);" 330 "vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x);" 331 "vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x);" 332 "vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x);" 333 "vec2 smoothstep(float edge0, float edge1, vec2 x);" 334 "vec3 smoothstep(float edge0, float edge1, vec3 x);" 335 "vec4 smoothstep(float edge0, float edge1, vec4 x);" 336 337 "\n"); 338 339 if (version >= 130) { 340 commonBuiltins.append( 341 " int abs( int x);" 342 "ivec2 abs(ivec2 x);" 343 "ivec3 abs(ivec3 x);" 344 "ivec4 abs(ivec4 x);" 345 346 " int sign( int x);" 347 "ivec2 sign(ivec2 x);" 348 "ivec3 sign(ivec3 x);" 349 "ivec4 sign(ivec4 x);" 350 351 "float trunc(float x);" 352 "vec2 trunc(vec2 x);" 353 "vec3 trunc(vec3 x);" 354 "vec4 trunc(vec4 x);" 355 356 "float round(float x);" 357 "vec2 round(vec2 x);" 358 "vec3 round(vec3 x);" 359 "vec4 round(vec4 x);" 360 361 "float roundEven(float x);" 362 "vec2 roundEven(vec2 x);" 363 "vec3 roundEven(vec3 x);" 364 "vec4 roundEven(vec4 x);" 365 366 "float modf(float, out float);" 367 "vec2 modf(vec2, out vec2 );" 368 "vec3 modf(vec3, out vec3 );" 369 "vec4 modf(vec4, out vec4 );" 370 371 " int min(int x, int y);" 372 "ivec2 min(ivec2 x, int y);" 373 "ivec3 min(ivec3 x, int y);" 374 "ivec4 min(ivec4 x, int y);" 375 "ivec2 min(ivec2 x, ivec2 y);" 376 "ivec3 min(ivec3 x, ivec3 y);" 377 "ivec4 min(ivec4 x, ivec4 y);" 378 379 " uint min(uint x, uint y);" 380 "uvec2 min(uvec2 x, uint y);" 381 "uvec3 min(uvec3 x, uint y);" 382 "uvec4 min(uvec4 x, uint y);" 383 "uvec2 min(uvec2 x, uvec2 y);" 384 "uvec3 min(uvec3 x, uvec3 y);" 385 "uvec4 min(uvec4 x, uvec4 y);" 386 387 " int max(int x, int y);" 388 "ivec2 max(ivec2 x, int y);" 389 "ivec3 max(ivec3 x, int y);" 390 "ivec4 max(ivec4 x, int y);" 391 "ivec2 max(ivec2 x, ivec2 y);" 392 "ivec3 max(ivec3 x, ivec3 y);" 393 "ivec4 max(ivec4 x, ivec4 y);" 394 395 " uint max(uint x, uint y);" 396 "uvec2 max(uvec2 x, uint y);" 397 "uvec3 max(uvec3 x, uint y);" 398 "uvec4 max(uvec4 x, uint y);" 399 "uvec2 max(uvec2 x, uvec2 y);" 400 "uvec3 max(uvec3 x, uvec3 y);" 401 "uvec4 max(uvec4 x, uvec4 y);" 402 403 "int clamp(int x, int minVal, int maxVal);" 404 "ivec2 clamp(ivec2 x, int minVal, int maxVal);" 405 "ivec3 clamp(ivec3 x, int minVal, int maxVal);" 406 "ivec4 clamp(ivec4 x, int minVal, int maxVal);" 407 "ivec2 clamp(ivec2 x, ivec2 minVal, ivec2 maxVal);" 408 "ivec3 clamp(ivec3 x, ivec3 minVal, ivec3 maxVal);" 409 "ivec4 clamp(ivec4 x, ivec4 minVal, ivec4 maxVal);" 410 411 "uint clamp(uint x, uint minVal, uint maxVal);" 412 "uvec2 clamp(uvec2 x, uint minVal, uint maxVal);" 413 "uvec3 clamp(uvec3 x, uint minVal, uint maxVal);" 414 "uvec4 clamp(uvec4 x, uint minVal, uint maxVal);" 415 "uvec2 clamp(uvec2 x, uvec2 minVal, uvec2 maxVal);" 416 "uvec3 clamp(uvec3 x, uvec3 minVal, uvec3 maxVal);" 417 "uvec4 clamp(uvec4 x, uvec4 minVal, uvec4 maxVal);" 418 419 "float mix(float x, float y, bool a);" 420 "vec2 mix(vec2 x, vec2 y, bvec2 a);" 421 "vec3 mix(vec3 x, vec3 y, bvec3 a);" 422 "vec4 mix(vec4 x, vec4 y, bvec4 a);" 423 424 "bool isnan(float x);" 425 "bvec2 isnan(vec2 x);" 426 "bvec3 isnan(vec3 x);" 427 "bvec4 isnan(vec4 x);" 428 429 "bool isinf(float x);" 430 "bvec2 isinf(vec2 x);" 431 "bvec3 isinf(vec3 x);" 432 "bvec4 isinf(vec4 x);" 433 434 "\n"); 435 } 436 437 // 438 // double functions added to desktop 4.00, but not fma, frexp, ldexp, or pack/unpack 439 // 440 if (profile != EEsProfile && version >= 400) { 441 commonBuiltins.append( 442 443 "double sqrt(double);" 444 "dvec2 sqrt(dvec2);" 445 "dvec3 sqrt(dvec3);" 446 "dvec4 sqrt(dvec4);" 447 448 "double inversesqrt(double);" 449 "dvec2 inversesqrt(dvec2);" 450 "dvec3 inversesqrt(dvec3);" 451 "dvec4 inversesqrt(dvec4);" 452 453 "double abs(double);" 454 "dvec2 abs(dvec2);" 455 "dvec3 abs(dvec3);" 456 "dvec4 abs(dvec4);" 457 458 "double sign(double);" 459 "dvec2 sign(dvec2);" 460 "dvec3 sign(dvec3);" 461 "dvec4 sign(dvec4);" 462 463 "double floor(double);" 464 "dvec2 floor(dvec2);" 465 "dvec3 floor(dvec3);" 466 "dvec4 floor(dvec4);" 467 468 "double trunc(double);" 469 "dvec2 trunc(dvec2);" 470 "dvec3 trunc(dvec3);" 471 "dvec4 trunc(dvec4);" 472 473 "double round(double);" 474 "dvec2 round(dvec2);" 475 "dvec3 round(dvec3);" 476 "dvec4 round(dvec4);" 477 478 "double roundEven(double);" 479 "dvec2 roundEven(dvec2);" 480 "dvec3 roundEven(dvec3);" 481 "dvec4 roundEven(dvec4);" 482 483 "double ceil(double);" 484 "dvec2 ceil(dvec2);" 485 "dvec3 ceil(dvec3);" 486 "dvec4 ceil(dvec4);" 487 488 "double fract(double);" 489 "dvec2 fract(dvec2);" 490 "dvec3 fract(dvec3);" 491 "dvec4 fract(dvec4);" 492 493 "double mod(double, double);" 494 "dvec2 mod(dvec2 , double);" 495 "dvec3 mod(dvec3 , double);" 496 "dvec4 mod(dvec4 , double);" 497 "dvec2 mod(dvec2 , dvec2);" 498 "dvec3 mod(dvec3 , dvec3);" 499 "dvec4 mod(dvec4 , dvec4);" 500 501 "double modf(double, out double);" 502 "dvec2 modf(dvec2, out dvec2);" 503 "dvec3 modf(dvec3, out dvec3);" 504 "dvec4 modf(dvec4, out dvec4);" 505 506 "double min(double, double);" 507 "dvec2 min(dvec2, double);" 508 "dvec3 min(dvec3, double);" 509 "dvec4 min(dvec4, double);" 510 "dvec2 min(dvec2, dvec2);" 511 "dvec3 min(dvec3, dvec3);" 512 "dvec4 min(dvec4, dvec4);" 513 514 "double max(double, double);" 515 "dvec2 max(dvec2 , double);" 516 "dvec3 max(dvec3 , double);" 517 "dvec4 max(dvec4 , double);" 518 "dvec2 max(dvec2 , dvec2);" 519 "dvec3 max(dvec3 , dvec3);" 520 "dvec4 max(dvec4 , dvec4);" 521 522 "double clamp(double, double, double);" 523 "dvec2 clamp(dvec2 , double, double);" 524 "dvec3 clamp(dvec3 , double, double);" 525 "dvec4 clamp(dvec4 , double, double);" 526 "dvec2 clamp(dvec2 , dvec2 , dvec2);" 527 "dvec3 clamp(dvec3 , dvec3 , dvec3);" 528 "dvec4 clamp(dvec4 , dvec4 , dvec4);" 529 530 "double mix(double, double, double);" 531 "dvec2 mix(dvec2, dvec2, double);" 532 "dvec3 mix(dvec3, dvec3, double);" 533 "dvec4 mix(dvec4, dvec4, double);" 534 "dvec2 mix(dvec2, dvec2, dvec2);" 535 "dvec3 mix(dvec3, dvec3, dvec3);" 536 "dvec4 mix(dvec4, dvec4, dvec4);" 537 "double mix(double, double, bool);" 538 "dvec2 mix(dvec2, dvec2, bvec2);" 539 "dvec3 mix(dvec3, dvec3, bvec3);" 540 "dvec4 mix(dvec4, dvec4, bvec4);" 541 542 "double step(double, double);" 543 "dvec2 step(dvec2 , dvec2);" 544 "dvec3 step(dvec3 , dvec3);" 545 "dvec4 step(dvec4 , dvec4);" 546 "dvec2 step(double, dvec2);" 547 "dvec3 step(double, dvec3);" 548 "dvec4 step(double, dvec4);" 549 550 "double smoothstep(double, double, double);" 551 "dvec2 smoothstep(dvec2 , dvec2 , dvec2);" 552 "dvec3 smoothstep(dvec3 , dvec3 , dvec3);" 553 "dvec4 smoothstep(dvec4 , dvec4 , dvec4);" 554 "dvec2 smoothstep(double, double, dvec2);" 555 "dvec3 smoothstep(double, double, dvec3);" 556 "dvec4 smoothstep(double, double, dvec4);" 557 558 "bool isnan(double);" 559 "bvec2 isnan(dvec2);" 560 "bvec3 isnan(dvec3);" 561 "bvec4 isnan(dvec4);" 562 563 "bool isinf(double);" 564 "bvec2 isinf(dvec2);" 565 "bvec3 isinf(dvec3);" 566 "bvec4 isinf(dvec4);" 567 568 "double length(double);" 569 "double length(dvec2);" 570 "double length(dvec3);" 571 "double length(dvec4);" 572 573 "double distance(double, double);" 574 "double distance(dvec2 , dvec2);" 575 "double distance(dvec3 , dvec3);" 576 "double distance(dvec4 , dvec4);" 577 578 "double dot(double, double);" 579 "double dot(dvec2 , dvec2);" 580 "double dot(dvec3 , dvec3);" 581 "double dot(dvec4 , dvec4);" 582 583 "dvec3 cross(dvec3, dvec3);" 584 585 "double normalize(double);" 586 "dvec2 normalize(dvec2);" 587 "dvec3 normalize(dvec3);" 588 "dvec4 normalize(dvec4);" 589 590 "double faceforward(double, double, double);" 591 "dvec2 faceforward(dvec2, dvec2, dvec2);" 592 "dvec3 faceforward(dvec3, dvec3, dvec3);" 593 "dvec4 faceforward(dvec4, dvec4, dvec4);" 594 595 "double reflect(double, double);" 596 "dvec2 reflect(dvec2 , dvec2 );" 597 "dvec3 reflect(dvec3 , dvec3 );" 598 "dvec4 reflect(dvec4 , dvec4 );" 599 600 "double refract(double, double, double);" 601 "dvec2 refract(dvec2 , dvec2 , double);" 602 "dvec3 refract(dvec3 , dvec3 , double);" 603 "dvec4 refract(dvec4 , dvec4 , double);" 604 605 "dmat2 matrixCompMult(dmat2, dmat2);" 606 "dmat3 matrixCompMult(dmat3, dmat3);" 607 "dmat4 matrixCompMult(dmat4, dmat4);" 608 "dmat2x3 matrixCompMult(dmat2x3, dmat2x3);" 609 "dmat2x4 matrixCompMult(dmat2x4, dmat2x4);" 610 "dmat3x2 matrixCompMult(dmat3x2, dmat3x2);" 611 "dmat3x4 matrixCompMult(dmat3x4, dmat3x4);" 612 "dmat4x2 matrixCompMult(dmat4x2, dmat4x2);" 613 "dmat4x3 matrixCompMult(dmat4x3, dmat4x3);" 614 615 "dmat2 outerProduct(dvec2, dvec2);" 616 "dmat3 outerProduct(dvec3, dvec3);" 617 "dmat4 outerProduct(dvec4, dvec4);" 618 "dmat2x3 outerProduct(dvec3, dvec2);" 619 "dmat3x2 outerProduct(dvec2, dvec3);" 620 "dmat2x4 outerProduct(dvec4, dvec2);" 621 "dmat4x2 outerProduct(dvec2, dvec4);" 622 "dmat3x4 outerProduct(dvec4, dvec3);" 623 "dmat4x3 outerProduct(dvec3, dvec4);" 624 625 "dmat2 transpose(dmat2);" 626 "dmat3 transpose(dmat3);" 627 "dmat4 transpose(dmat4);" 628 "dmat2x3 transpose(dmat3x2);" 629 "dmat3x2 transpose(dmat2x3);" 630 "dmat2x4 transpose(dmat4x2);" 631 "dmat4x2 transpose(dmat2x4);" 632 "dmat3x4 transpose(dmat4x3);" 633 "dmat4x3 transpose(dmat3x4);" 634 635 "double determinant(dmat2);" 636 "double determinant(dmat3);" 637 "double determinant(dmat4);" 638 639 "dmat2 inverse(dmat2);" 640 "dmat3 inverse(dmat3);" 641 "dmat4 inverse(dmat4);" 642 643 "bvec2 lessThan(dvec2, dvec2);" 644 "bvec3 lessThan(dvec3, dvec3);" 645 "bvec4 lessThan(dvec4, dvec4);" 646 647 "bvec2 lessThanEqual(dvec2, dvec2);" 648 "bvec3 lessThanEqual(dvec3, dvec3);" 649 "bvec4 lessThanEqual(dvec4, dvec4);" 650 651 "bvec2 greaterThan(dvec2, dvec2);" 652 "bvec3 greaterThan(dvec3, dvec3);" 653 "bvec4 greaterThan(dvec4, dvec4);" 654 655 "bvec2 greaterThanEqual(dvec2, dvec2);" 656 "bvec3 greaterThanEqual(dvec3, dvec3);" 657 "bvec4 greaterThanEqual(dvec4, dvec4);" 658 659 "bvec2 equal(dvec2, dvec2);" 660 "bvec3 equal(dvec3, dvec3);" 661 "bvec4 equal(dvec4, dvec4);" 662 663 "bvec2 notEqual(dvec2, dvec2);" 664 "bvec3 notEqual(dvec3, dvec3);" 665 "bvec4 notEqual(dvec4, dvec4);" 666 667 "\n"); 668 } 669 670 if (profile != EEsProfile && version >= 450) { 671 commonBuiltins.append( 672 673 "int64_t abs(int64_t);" 674 "i64vec2 abs(i64vec2);" 675 "i64vec3 abs(i64vec3);" 676 "i64vec4 abs(i64vec4);" 677 678 "int64_t sign(int64_t);" 679 "i64vec2 sign(i64vec2);" 680 "i64vec3 sign(i64vec3);" 681 "i64vec4 sign(i64vec4);" 682 683 "int64_t min(int64_t, int64_t);" 684 "i64vec2 min(i64vec2, int64_t);" 685 "i64vec3 min(i64vec3, int64_t);" 686 "i64vec4 min(i64vec4, int64_t);" 687 "i64vec2 min(i64vec2, i64vec2);" 688 "i64vec3 min(i64vec3, i64vec3);" 689 "i64vec4 min(i64vec4, i64vec4);" 690 "uint64_t min(uint64_t, uint64_t);" 691 "u64vec2 min(u64vec2, uint64_t);" 692 "u64vec3 min(u64vec3, uint64_t);" 693 "u64vec4 min(u64vec4, uint64_t);" 694 "u64vec2 min(u64vec2, u64vec2);" 695 "u64vec3 min(u64vec3, u64vec3);" 696 "u64vec4 min(u64vec4, u64vec4);" 697 698 "int64_t max(int64_t, int64_t);" 699 "i64vec2 max(i64vec2, int64_t);" 700 "i64vec3 max(i64vec3, int64_t);" 701 "i64vec4 max(i64vec4, int64_t);" 702 "i64vec2 max(i64vec2, i64vec2);" 703 "i64vec3 max(i64vec3, i64vec3);" 704 "i64vec4 max(i64vec4, i64vec4);" 705 "uint64_t max(uint64_t, uint64_t);" 706 "u64vec2 max(u64vec2, uint64_t);" 707 "u64vec3 max(u64vec3, uint64_t);" 708 "u64vec4 max(u64vec4, uint64_t);" 709 "u64vec2 max(u64vec2, u64vec2);" 710 "u64vec3 max(u64vec3, u64vec3);" 711 "u64vec4 max(u64vec4, u64vec4);" 712 713 "int64_t clamp(int64_t, int64_t, int64_t);" 714 "i64vec2 clamp(i64vec2, int64_t, int64_t);" 715 "i64vec3 clamp(i64vec3, int64_t, int64_t);" 716 "i64vec4 clamp(i64vec4, int64_t, int64_t);" 717 "i64vec2 clamp(i64vec2, i64vec2, i64vec2);" 718 "i64vec3 clamp(i64vec3, i64vec3, i64vec3);" 719 "i64vec4 clamp(i64vec4, i64vec4, i64vec4);" 720 "uint64_t clamp(uint64_t, uint64_t, uint64_t);" 721 "u64vec2 clamp(u64vec2, uint64_t, uint64_t);" 722 "u64vec3 clamp(u64vec3, uint64_t, uint64_t);" 723 "u64vec4 clamp(u64vec4, uint64_t, uint64_t);" 724 "u64vec2 clamp(u64vec2, u64vec2, u64vec2);" 725 "u64vec3 clamp(u64vec3, u64vec3, u64vec3);" 726 "u64vec4 clamp(u64vec4, u64vec4, u64vec4);" 727 728 "int64_t mix(int64_t, int64_t, bool);" 729 "i64vec2 mix(i64vec2, i64vec2, bvec2);" 730 "i64vec3 mix(i64vec3, i64vec3, bvec3);" 731 "i64vec4 mix(i64vec4, i64vec4, bvec4);" 732 "uint64_t mix(uint64_t, uint64_t, bool);" 733 "u64vec2 mix(u64vec2, u64vec2, bvec2);" 734 "u64vec3 mix(u64vec3, u64vec3, bvec3);" 735 "u64vec4 mix(u64vec4, u64vec4, bvec4);" 736 737 "int64_t doubleBitsToInt64(double);" 738 "i64vec2 doubleBitsToInt64(dvec2);" 739 "i64vec3 doubleBitsToInt64(dvec3);" 740 "i64vec4 doubleBitsToInt64(dvec4);" 741 742 "uint64_t doubleBitsToUint64(double);" 743 "u64vec2 doubleBitsToUint64(dvec2);" 744 "u64vec3 doubleBitsToUint64(dvec3);" 745 "u64vec4 doubleBitsToUint64(dvec4);" 746 747 "double int64BitsToDouble(int64_t);" 748 "dvec2 int64BitsToDouble(i64vec2);" 749 "dvec3 int64BitsToDouble(i64vec3);" 750 "dvec4 int64BitsToDouble(i64vec4);" 751 752 "double uint64BitsToDouble(uint64_t);" 753 "dvec2 uint64BitsToDouble(u64vec2);" 754 "dvec3 uint64BitsToDouble(u64vec3);" 755 "dvec4 uint64BitsToDouble(u64vec4);" 756 757 "int64_t packInt2x32(ivec2);" 758 "uint64_t packUint2x32(uvec2);" 759 "ivec2 unpackInt2x32(int64_t);" 760 "uvec2 unpackUint2x32(uint64_t);" 761 762 "bvec2 lessThan(i64vec2, i64vec2);" 763 "bvec3 lessThan(i64vec3, i64vec3);" 764 "bvec4 lessThan(i64vec4, i64vec4);" 765 "bvec2 lessThan(u64vec2, u64vec2);" 766 "bvec3 lessThan(u64vec3, u64vec3);" 767 "bvec4 lessThan(u64vec4, u64vec4);" 768 769 "bvec2 lessThanEqual(i64vec2, i64vec2);" 770 "bvec3 lessThanEqual(i64vec3, i64vec3);" 771 "bvec4 lessThanEqual(i64vec4, i64vec4);" 772 "bvec2 lessThanEqual(u64vec2, u64vec2);" 773 "bvec3 lessThanEqual(u64vec3, u64vec3);" 774 "bvec4 lessThanEqual(u64vec4, u64vec4);" 775 776 "bvec2 greaterThan(i64vec2, i64vec2);" 777 "bvec3 greaterThan(i64vec3, i64vec3);" 778 "bvec4 greaterThan(i64vec4, i64vec4);" 779 "bvec2 greaterThan(u64vec2, u64vec2);" 780 "bvec3 greaterThan(u64vec3, u64vec3);" 781 "bvec4 greaterThan(u64vec4, u64vec4);" 782 783 "bvec2 greaterThanEqual(i64vec2, i64vec2);" 784 "bvec3 greaterThanEqual(i64vec3, i64vec3);" 785 "bvec4 greaterThanEqual(i64vec4, i64vec4);" 786 "bvec2 greaterThanEqual(u64vec2, u64vec2);" 787 "bvec3 greaterThanEqual(u64vec3, u64vec3);" 788 "bvec4 greaterThanEqual(u64vec4, u64vec4);" 789 790 "bvec2 equal(i64vec2, i64vec2);" 791 "bvec3 equal(i64vec3, i64vec3);" 792 "bvec4 equal(i64vec4, i64vec4);" 793 "bvec2 equal(u64vec2, u64vec2);" 794 "bvec3 equal(u64vec3, u64vec3);" 795 "bvec4 equal(u64vec4, u64vec4);" 796 797 "bvec2 notEqual(i64vec2, i64vec2);" 798 "bvec3 notEqual(i64vec3, i64vec3);" 799 "bvec4 notEqual(i64vec4, i64vec4);" 800 "bvec2 notEqual(u64vec2, u64vec2);" 801 "bvec3 notEqual(u64vec3, u64vec3);" 802 "bvec4 notEqual(u64vec4, u64vec4);" 803 804 "\n" 805 ); 806 } 807 808 if ((profile == EEsProfile && version >= 310) || 809 (profile != EEsProfile && version >= 430)) { 810 commonBuiltins.append( 811 "uint atomicAdd(coherent volatile inout uint, uint);" 812 " int atomicAdd(coherent volatile inout int, int);" 813 814 "uint atomicMin(coherent volatile inout uint, uint);" 815 " int atomicMin(coherent volatile inout int, int);" 816 817 "uint atomicMax(coherent volatile inout uint, uint);" 818 " int atomicMax(coherent volatile inout int, int);" 819 820 "uint atomicAnd(coherent volatile inout uint, uint);" 821 " int atomicAnd(coherent volatile inout int, int);" 822 823 "uint atomicOr (coherent volatile inout uint, uint);" 824 " int atomicOr (coherent volatile inout int, int);" 825 826 "uint atomicXor(coherent volatile inout uint, uint);" 827 " int atomicXor(coherent volatile inout int, int);" 828 829 "uint atomicExchange(coherent volatile inout uint, uint);" 830 " int atomicExchange(coherent volatile inout int, int);" 831 832 "uint atomicCompSwap(coherent volatile inout uint, uint, uint);" 833 " int atomicCompSwap(coherent volatile inout int, int, int);" 834 835 "\n"); 836 } 837 838 if ((profile == EEsProfile && version >= 310) || 839 (profile != EEsProfile && version >= 450)) { 840 commonBuiltins.append( 841 "int mix(int x, int y, bool a);" 842 "ivec2 mix(ivec2 x, ivec2 y, bvec2 a);" 843 "ivec3 mix(ivec3 x, ivec3 y, bvec3 a);" 844 "ivec4 mix(ivec4 x, ivec4 y, bvec4 a);" 845 846 "uint mix(uint x, uint y, bool a);" 847 "uvec2 mix(uvec2 x, uvec2 y, bvec2 a);" 848 "uvec3 mix(uvec3 x, uvec3 y, bvec3 a);" 849 "uvec4 mix(uvec4 x, uvec4 y, bvec4 a);" 850 851 "bool mix(bool x, bool y, bool a);" 852 "bvec2 mix(bvec2 x, bvec2 y, bvec2 a);" 853 "bvec3 mix(bvec3 x, bvec3 y, bvec3 a);" 854 "bvec4 mix(bvec4 x, bvec4 y, bvec4 a);" 855 856 "\n"); 857 } 858 859 if ((profile == EEsProfile && version >= 300) || 860 (profile != EEsProfile && version >= 330)) { 861 commonBuiltins.append( 862 "highp int floatBitsToInt(highp float value);" 863 "highp ivec2 floatBitsToInt(highp vec2 value);" 864 "highp ivec3 floatBitsToInt(highp vec3 value);" 865 "highp ivec4 floatBitsToInt(highp vec4 value);" 866 867 "highp uint floatBitsToUint(highp float value);" 868 "highp uvec2 floatBitsToUint(highp vec2 value);" 869 "highp uvec3 floatBitsToUint(highp vec3 value);" 870 "highp uvec4 floatBitsToUint(highp vec4 value);" 871 872 "highp float intBitsToFloat(highp int value);" 873 "highp vec2 intBitsToFloat(highp ivec2 value);" 874 "highp vec3 intBitsToFloat(highp ivec3 value);" 875 "highp vec4 intBitsToFloat(highp ivec4 value);" 876 877 "highp float uintBitsToFloat(highp uint value);" 878 "highp vec2 uintBitsToFloat(highp uvec2 value);" 879 "highp vec3 uintBitsToFloat(highp uvec3 value);" 880 "highp vec4 uintBitsToFloat(highp uvec4 value);" 881 882 "\n"); 883 } 884 885 if ((profile != EEsProfile && version >= 400) || 886 (profile == EEsProfile && version >= 310)) { // GL_OES_gpu_shader5 887 888 commonBuiltins.append( 889 "float fma(float, float, float );" 890 "vec2 fma(vec2, vec2, vec2 );" 891 "vec3 fma(vec3, vec3, vec3 );" 892 "vec4 fma(vec4, vec4, vec4 );" 893 "\n"); 894 895 if (profile != EEsProfile) { 896 commonBuiltins.append( 897 "double fma(double, double, double);" 898 "dvec2 fma(dvec2, dvec2, dvec2 );" 899 "dvec3 fma(dvec3, dvec3, dvec3 );" 900 "dvec4 fma(dvec4, dvec4, dvec4 );" 901 "\n"); 902 } 903 } 904 905 if ((profile == EEsProfile && version >= 310) || 906 (profile != EEsProfile && version >= 400)) { 907 commonBuiltins.append( 908 "highp float frexp(highp float, out highp int);" 909 "highp vec2 frexp(highp vec2, out highp ivec2);" 910 "highp vec3 frexp(highp vec3, out highp ivec3);" 911 "highp vec4 frexp(highp vec4, out highp ivec4);" 912 913 "highp float ldexp(highp float, highp int);" 914 "highp vec2 ldexp(highp vec2, highp ivec2);" 915 "highp vec3 ldexp(highp vec3, highp ivec3);" 916 "highp vec4 ldexp(highp vec4, highp ivec4);" 917 918 "\n"); 919 } 920 921 if (profile != EEsProfile && version >= 400) { 922 commonBuiltins.append( 923 "double frexp(double, out int);" 924 "dvec2 frexp( dvec2, out ivec2);" 925 "dvec3 frexp( dvec3, out ivec3);" 926 "dvec4 frexp( dvec4, out ivec4);" 927 928 "double ldexp(double, int);" 929 "dvec2 ldexp( dvec2, ivec2);" 930 "dvec3 ldexp( dvec3, ivec3);" 931 "dvec4 ldexp( dvec4, ivec4);" 932 933 "double packDouble2x32(uvec2);" 934 "uvec2 unpackDouble2x32(double);" 935 936 "\n"); 937 } 938 939 if ((profile == EEsProfile && version >= 300) || 940 (profile != EEsProfile && version >= 400)) { 941 commonBuiltins.append( 942 "highp uint packUnorm2x16(vec2);" 943 "highp vec2 unpackUnorm2x16(highp uint);" 944 "\n"); 945 } 946 947 if ((profile == EEsProfile && version >= 300) || 948 (profile != EEsProfile && version >= 420)) { 949 commonBuiltins.append( 950 "highp uint packSnorm2x16(vec2);" 951 " vec2 unpackSnorm2x16(highp uint);" 952 "highp uint packHalf2x16(mediump vec2);" 953 " vec2 unpackHalf2x16(highp uint);" 954 "\n"); 955 } 956 957 if ((profile == EEsProfile && version >= 310) || 958 (profile != EEsProfile && version >= 400)) { 959 commonBuiltins.append( 960 "highp uint packSnorm4x8 (mediump vec4);" 961 " vec4 unpackSnorm4x8(highp uint);" 962 "highp uint packUnorm4x8 (mediump vec4);" 963 " vec4 unpackUnorm4x8(highp uint);" 964 "\n"); 965 } 966 967 // 968 // Geometric Functions. 969 // 970 commonBuiltins.append( 971 "float length(float x);" 972 "float length(vec2 x);" 973 "float length(vec3 x);" 974 "float length(vec4 x);" 975 976 "float distance(float p0, float p1);" 977 "float distance(vec2 p0, vec2 p1);" 978 "float distance(vec3 p0, vec3 p1);" 979 "float distance(vec4 p0, vec4 p1);" 980 981 "float dot(float x, float y);" 982 "float dot(vec2 x, vec2 y);" 983 "float dot(vec3 x, vec3 y);" 984 "float dot(vec4 x, vec4 y);" 985 986 "vec3 cross(vec3 x, vec3 y);" 987 "float normalize(float x);" 988 "vec2 normalize(vec2 x);" 989 "vec3 normalize(vec3 x);" 990 "vec4 normalize(vec4 x);" 991 992 "float faceforward(float N, float I, float Nref);" 993 "vec2 faceforward(vec2 N, vec2 I, vec2 Nref);" 994 "vec3 faceforward(vec3 N, vec3 I, vec3 Nref);" 995 "vec4 faceforward(vec4 N, vec4 I, vec4 Nref);" 996 997 "float reflect(float I, float N);" 998 "vec2 reflect(vec2 I, vec2 N);" 999 "vec3 reflect(vec3 I, vec3 N);" 1000 "vec4 reflect(vec4 I, vec4 N);" 1001 1002 "float refract(float I, float N, float eta);" 1003 "vec2 refract(vec2 I, vec2 N, float eta);" 1004 "vec3 refract(vec3 I, vec3 N, float eta);" 1005 "vec4 refract(vec4 I, vec4 N, float eta);" 1006 1007 "\n"); 1008 1009 // 1010 // Matrix Functions. 1011 // 1012 commonBuiltins.append( 1013 "mat2 matrixCompMult(mat2 x, mat2 y);" 1014 "mat3 matrixCompMult(mat3 x, mat3 y);" 1015 "mat4 matrixCompMult(mat4 x, mat4 y);" 1016 1017 "\n"); 1018 1019 // 120 is correct for both ES and desktop 1020 if (version >= 120) { 1021 commonBuiltins.append( 1022 "mat2 outerProduct(vec2 c, vec2 r);" 1023 "mat3 outerProduct(vec3 c, vec3 r);" 1024 "mat4 outerProduct(vec4 c, vec4 r);" 1025 "mat2x3 outerProduct(vec3 c, vec2 r);" 1026 "mat3x2 outerProduct(vec2 c, vec3 r);" 1027 "mat2x4 outerProduct(vec4 c, vec2 r);" 1028 "mat4x2 outerProduct(vec2 c, vec4 r);" 1029 "mat3x4 outerProduct(vec4 c, vec3 r);" 1030 "mat4x3 outerProduct(vec3 c, vec4 r);" 1031 1032 "mat2 transpose(mat2 m);" 1033 "mat3 transpose(mat3 m);" 1034 "mat4 transpose(mat4 m);" 1035 "mat2x3 transpose(mat3x2 m);" 1036 "mat3x2 transpose(mat2x3 m);" 1037 "mat2x4 transpose(mat4x2 m);" 1038 "mat4x2 transpose(mat2x4 m);" 1039 "mat3x4 transpose(mat4x3 m);" 1040 "mat4x3 transpose(mat3x4 m);" 1041 1042 "mat2x3 matrixCompMult(mat2x3, mat2x3);" 1043 "mat2x4 matrixCompMult(mat2x4, mat2x4);" 1044 "mat3x2 matrixCompMult(mat3x2, mat3x2);" 1045 "mat3x4 matrixCompMult(mat3x4, mat3x4);" 1046 "mat4x2 matrixCompMult(mat4x2, mat4x2);" 1047 "mat4x3 matrixCompMult(mat4x3, mat4x3);" 1048 1049 "\n"); 1050 1051 // 150 is correct for both ES and desktop 1052 if (version >= 150) { 1053 commonBuiltins.append( 1054 "float determinant(mat2 m);" 1055 "float determinant(mat3 m);" 1056 "float determinant(mat4 m);" 1057 1058 "mat2 inverse(mat2 m);" 1059 "mat3 inverse(mat3 m);" 1060 "mat4 inverse(mat4 m);" 1061 1062 "\n"); 1063 } 1064 } 1065 1066 // 1067 // Vector relational functions. 1068 // 1069 commonBuiltins.append( 1070 "bvec2 lessThan(vec2 x, vec2 y);" 1071 "bvec3 lessThan(vec3 x, vec3 y);" 1072 "bvec4 lessThan(vec4 x, vec4 y);" 1073 1074 "bvec2 lessThan(ivec2 x, ivec2 y);" 1075 "bvec3 lessThan(ivec3 x, ivec3 y);" 1076 "bvec4 lessThan(ivec4 x, ivec4 y);" 1077 1078 "bvec2 lessThanEqual(vec2 x, vec2 y);" 1079 "bvec3 lessThanEqual(vec3 x, vec3 y);" 1080 "bvec4 lessThanEqual(vec4 x, vec4 y);" 1081 1082 "bvec2 lessThanEqual(ivec2 x, ivec2 y);" 1083 "bvec3 lessThanEqual(ivec3 x, ivec3 y);" 1084 "bvec4 lessThanEqual(ivec4 x, ivec4 y);" 1085 1086 "bvec2 greaterThan(vec2 x, vec2 y);" 1087 "bvec3 greaterThan(vec3 x, vec3 y);" 1088 "bvec4 greaterThan(vec4 x, vec4 y);" 1089 1090 "bvec2 greaterThan(ivec2 x, ivec2 y);" 1091 "bvec3 greaterThan(ivec3 x, ivec3 y);" 1092 "bvec4 greaterThan(ivec4 x, ivec4 y);" 1093 1094 "bvec2 greaterThanEqual(vec2 x, vec2 y);" 1095 "bvec3 greaterThanEqual(vec3 x, vec3 y);" 1096 "bvec4 greaterThanEqual(vec4 x, vec4 y);" 1097 1098 "bvec2 greaterThanEqual(ivec2 x, ivec2 y);" 1099 "bvec3 greaterThanEqual(ivec3 x, ivec3 y);" 1100 "bvec4 greaterThanEqual(ivec4 x, ivec4 y);" 1101 1102 "bvec2 equal(vec2 x, vec2 y);" 1103 "bvec3 equal(vec3 x, vec3 y);" 1104 "bvec4 equal(vec4 x, vec4 y);" 1105 1106 "bvec2 equal(ivec2 x, ivec2 y);" 1107 "bvec3 equal(ivec3 x, ivec3 y);" 1108 "bvec4 equal(ivec4 x, ivec4 y);" 1109 1110 "bvec2 equal(bvec2 x, bvec2 y);" 1111 "bvec3 equal(bvec3 x, bvec3 y);" 1112 "bvec4 equal(bvec4 x, bvec4 y);" 1113 1114 "bvec2 notEqual(vec2 x, vec2 y);" 1115 "bvec3 notEqual(vec3 x, vec3 y);" 1116 "bvec4 notEqual(vec4 x, vec4 y);" 1117 1118 "bvec2 notEqual(ivec2 x, ivec2 y);" 1119 "bvec3 notEqual(ivec3 x, ivec3 y);" 1120 "bvec4 notEqual(ivec4 x, ivec4 y);" 1121 1122 "bvec2 notEqual(bvec2 x, bvec2 y);" 1123 "bvec3 notEqual(bvec3 x, bvec3 y);" 1124 "bvec4 notEqual(bvec4 x, bvec4 y);" 1125 1126 "bool any(bvec2 x);" 1127 "bool any(bvec3 x);" 1128 "bool any(bvec4 x);" 1129 1130 "bool all(bvec2 x);" 1131 "bool all(bvec3 x);" 1132 "bool all(bvec4 x);" 1133 1134 "bvec2 not(bvec2 x);" 1135 "bvec3 not(bvec3 x);" 1136 "bvec4 not(bvec4 x);" 1137 1138 "\n"); 1139 1140 if (version >= 130) { 1141 commonBuiltins.append( 1142 "bvec2 lessThan(uvec2 x, uvec2 y);" 1143 "bvec3 lessThan(uvec3 x, uvec3 y);" 1144 "bvec4 lessThan(uvec4 x, uvec4 y);" 1145 1146 "bvec2 lessThanEqual(uvec2 x, uvec2 y);" 1147 "bvec3 lessThanEqual(uvec3 x, uvec3 y);" 1148 "bvec4 lessThanEqual(uvec4 x, uvec4 y);" 1149 1150 "bvec2 greaterThan(uvec2 x, uvec2 y);" 1151 "bvec3 greaterThan(uvec3 x, uvec3 y);" 1152 "bvec4 greaterThan(uvec4 x, uvec4 y);" 1153 1154 "bvec2 greaterThanEqual(uvec2 x, uvec2 y);" 1155 "bvec3 greaterThanEqual(uvec3 x, uvec3 y);" 1156 "bvec4 greaterThanEqual(uvec4 x, uvec4 y);" 1157 1158 "bvec2 equal(uvec2 x, uvec2 y);" 1159 "bvec3 equal(uvec3 x, uvec3 y);" 1160 "bvec4 equal(uvec4 x, uvec4 y);" 1161 1162 "bvec2 notEqual(uvec2 x, uvec2 y);" 1163 "bvec3 notEqual(uvec3 x, uvec3 y);" 1164 "bvec4 notEqual(uvec4 x, uvec4 y);" 1165 1166 "\n"); 1167 } 1168 1169 // 1170 // Original-style texture functions existing in all stages. 1171 // (Per-stage functions below.) 1172 // 1173 if ((profile == EEsProfile && version == 100) || 1174 profile == ECompatibilityProfile || 1175 (profile == ECoreProfile && version < 420) || 1176 profile == ENoProfile) { 1177 if (spvVersion.spv == 0) { 1178 commonBuiltins.append( 1179 "vec4 texture2D(sampler2D, vec2);" 1180 1181 "vec4 texture2DProj(sampler2D, vec3);" 1182 "vec4 texture2DProj(sampler2D, vec4);" 1183 1184 "vec4 texture3D(sampler3D, vec3);" // OES_texture_3D, but caught by keyword check 1185 "vec4 texture3DProj(sampler3D, vec4);" // OES_texture_3D, but caught by keyword check 1186 1187 "vec4 textureCube(samplerCube, vec3);" 1188 1189 "\n"); 1190 } 1191 } 1192 1193 if ( profile == ECompatibilityProfile || 1194 (profile == ECoreProfile && version < 420) || 1195 profile == ENoProfile) { 1196 if (spvVersion.spv == 0) { 1197 commonBuiltins.append( 1198 "vec4 texture1D(sampler1D, float);" 1199 1200 "vec4 texture1DProj(sampler1D, vec2);" 1201 "vec4 texture1DProj(sampler1D, vec4);" 1202 1203 "vec4 shadow1D(sampler1DShadow, vec3);" 1204 "vec4 shadow2D(sampler2DShadow, vec3);" 1205 "vec4 shadow1DProj(sampler1DShadow, vec4);" 1206 "vec4 shadow2DProj(sampler2DShadow, vec4);" 1207 1208 "vec4 texture2DRect(sampler2DRect, vec2);" // GL_ARB_texture_rectangle, caught by keyword check 1209 "vec4 texture2DRectProj(sampler2DRect, vec3);" // GL_ARB_texture_rectangle, caught by keyword check 1210 "vec4 texture2DRectProj(sampler2DRect, vec4);" // GL_ARB_texture_rectangle, caught by keyword check 1211 "vec4 shadow2DRect(sampler2DRectShadow, vec3);" // GL_ARB_texture_rectangle, caught by keyword check 1212 "vec4 shadow2DRectProj(sampler2DRectShadow, vec4);" // GL_ARB_texture_rectangle, caught by keyword check 1213 1214 "\n"); 1215 } 1216 } 1217 1218 if (profile == EEsProfile) { 1219 if (spvVersion.spv == 0) { 1220 commonBuiltins.append( 1221 "vec4 texture2D(samplerExternalOES, vec2 coord);" // GL_OES_EGL_image_external, caught by keyword check 1222 "vec4 texture2DProj(samplerExternalOES, vec3);" // GL_OES_EGL_image_external, caught by keyword check 1223 "vec4 texture2DProj(samplerExternalOES, vec4);" // GL_OES_EGL_image_external, caught by keyword check 1224 "vec4 texture2DGradEXT(sampler2D, vec2, vec2, vec2);" // GL_EXT_shader_texture_lod 1225 "vec4 texture2DProjGradEXT(sampler2D, vec3, vec2, vec2);" // GL_EXT_shader_texture_lod 1226 "vec4 texture2DProjGradEXT(sampler2D, vec4, vec2, vec2);" // GL_EXT_shader_texture_lod 1227 "vec4 textureCubeGradEXT(samplerCube, vec3, vec3, vec3);" // GL_EXT_shader_texture_lod 1228 1229 "\n"); 1230 } 1231 } 1232 1233 // 1234 // Noise functions. 1235 // 1236 if (profile != EEsProfile) { 1237 commonBuiltins.append( 1238 "float noise1(float x);" 1239 "float noise1(vec2 x);" 1240 "float noise1(vec3 x);" 1241 "float noise1(vec4 x);" 1242 1243 "vec2 noise2(float x);" 1244 "vec2 noise2(vec2 x);" 1245 "vec2 noise2(vec3 x);" 1246 "vec2 noise2(vec4 x);" 1247 1248 "vec3 noise3(float x);" 1249 "vec3 noise3(vec2 x);" 1250 "vec3 noise3(vec3 x);" 1251 "vec3 noise3(vec4 x);" 1252 1253 "vec4 noise4(float x);" 1254 "vec4 noise4(vec2 x);" 1255 "vec4 noise4(vec3 x);" 1256 "vec4 noise4(vec4 x);" 1257 1258 "\n"); 1259 } 1260 1261 if (spvVersion.vulkan == 0) { 1262 // 1263 // Atomic counter functions. 1264 // 1265 if ((profile != EEsProfile && version >= 300) || 1266 (profile == EEsProfile && version >= 310)) { 1267 commonBuiltins.append( 1268 "uint atomicCounterIncrement(atomic_uint x);" 1269 "uint atomicCounterDecrement(atomic_uint x);" 1270 "uint atomicCounter(atomic_uint x);" 1271 1272 "\n"); 1273 } 1274 } 1275 1276 // Bitfield 1277 if ((profile == EEsProfile && version >= 310) || 1278 (profile != EEsProfile && version >= 400)) { 1279 commonBuiltins.append( 1280 " int bitfieldExtract( int, int, int);" 1281 "ivec2 bitfieldExtract(ivec2, int, int);" 1282 "ivec3 bitfieldExtract(ivec3, int, int);" 1283 "ivec4 bitfieldExtract(ivec4, int, int);" 1284 1285 " uint bitfieldExtract( uint, int, int);" 1286 "uvec2 bitfieldExtract(uvec2, int, int);" 1287 "uvec3 bitfieldExtract(uvec3, int, int);" 1288 "uvec4 bitfieldExtract(uvec4, int, int);" 1289 1290 " int bitfieldInsert( int base, int, int, int);" 1291 "ivec2 bitfieldInsert(ivec2 base, ivec2, int, int);" 1292 "ivec3 bitfieldInsert(ivec3 base, ivec3, int, int);" 1293 "ivec4 bitfieldInsert(ivec4 base, ivec4, int, int);" 1294 1295 " uint bitfieldInsert( uint base, uint, int, int);" 1296 "uvec2 bitfieldInsert(uvec2 base, uvec2, int, int);" 1297 "uvec3 bitfieldInsert(uvec3 base, uvec3, int, int);" 1298 "uvec4 bitfieldInsert(uvec4 base, uvec4, int, int);" 1299 1300 " int findLSB( int);" 1301 "ivec2 findLSB(ivec2);" 1302 "ivec3 findLSB(ivec3);" 1303 "ivec4 findLSB(ivec4);" 1304 1305 " int findLSB( uint);" 1306 "ivec2 findLSB(uvec2);" 1307 "ivec3 findLSB(uvec3);" 1308 "ivec4 findLSB(uvec4);" 1309 1310 "\n"); 1311 } 1312 1313 if (profile != EEsProfile && version >= 400) { 1314 commonBuiltins.append( 1315 " uint uaddCarry( uint, uint, out uint carry);" 1316 "uvec2 uaddCarry(uvec2, uvec2, out uvec2 carry);" 1317 "uvec3 uaddCarry(uvec3, uvec3, out uvec3 carry);" 1318 "uvec4 uaddCarry(uvec4, uvec4, out uvec4 carry);" 1319 1320 " uint usubBorrow( uint, uint, out uint borrow);" 1321 "uvec2 usubBorrow(uvec2, uvec2, out uvec2 borrow);" 1322 "uvec3 usubBorrow(uvec3, uvec3, out uvec3 borrow);" 1323 "uvec4 usubBorrow(uvec4, uvec4, out uvec4 borrow);" 1324 1325 "void umulExtended( uint, uint, out uint, out uint lsb);" 1326 "void umulExtended(uvec2, uvec2, out uvec2, out uvec2 lsb);" 1327 "void umulExtended(uvec3, uvec3, out uvec3, out uvec3 lsb);" 1328 "void umulExtended(uvec4, uvec4, out uvec4, out uvec4 lsb);" 1329 1330 "void imulExtended( int, int, out int, out int lsb);" 1331 "void imulExtended(ivec2, ivec2, out ivec2, out ivec2 lsb);" 1332 "void imulExtended(ivec3, ivec3, out ivec3, out ivec3 lsb);" 1333 "void imulExtended(ivec4, ivec4, out ivec4, out ivec4 lsb);" 1334 1335 " int bitfieldReverse( int);" 1336 "ivec2 bitfieldReverse(ivec2);" 1337 "ivec3 bitfieldReverse(ivec3);" 1338 "ivec4 bitfieldReverse(ivec4);" 1339 1340 " uint bitfieldReverse( uint);" 1341 "uvec2 bitfieldReverse(uvec2);" 1342 "uvec3 bitfieldReverse(uvec3);" 1343 "uvec4 bitfieldReverse(uvec4);" 1344 1345 " int bitCount( int);" 1346 "ivec2 bitCount(ivec2);" 1347 "ivec3 bitCount(ivec3);" 1348 "ivec4 bitCount(ivec4);" 1349 1350 " int bitCount( uint);" 1351 "ivec2 bitCount(uvec2);" 1352 "ivec3 bitCount(uvec3);" 1353 "ivec4 bitCount(uvec4);" 1354 1355 " int findMSB( int);" 1356 "ivec2 findMSB(ivec2);" 1357 "ivec3 findMSB(ivec3);" 1358 "ivec4 findMSB(ivec4);" 1359 1360 " int findMSB( uint);" 1361 "ivec2 findMSB(uvec2);" 1362 "ivec3 findMSB(uvec3);" 1363 "ivec4 findMSB(uvec4);" 1364 1365 "\n"); 1366 } 1367 1368 if (profile == EEsProfile && version >= 310) { 1369 commonBuiltins.append( 1370 "highp uint uaddCarry(highp uint, highp uint, out lowp uint carry);" 1371 "highp uvec2 uaddCarry(highp uvec2, highp uvec2, out lowp uvec2 carry);" 1372 "highp uvec3 uaddCarry(highp uvec3, highp uvec3, out lowp uvec3 carry);" 1373 "highp uvec4 uaddCarry(highp uvec4, highp uvec4, out lowp uvec4 carry);" 1374 1375 "highp uint usubBorrow(highp uint, highp uint, out lowp uint borrow);" 1376 "highp uvec2 usubBorrow(highp uvec2, highp uvec2, out lowp uvec2 borrow);" 1377 "highp uvec3 usubBorrow(highp uvec3, highp uvec3, out lowp uvec3 borrow);" 1378 "highp uvec4 usubBorrow(highp uvec4, highp uvec4, out lowp uvec4 borrow);" 1379 1380 "void umulExtended(highp uint, highp uint, highp out uint, out highp uint lsb);" 1381 "void umulExtended(highp uvec2, highp uvec2, highp out uvec2, out highp uvec2 lsb);" 1382 "void umulExtended(highp uvec3, highp uvec3, highp out uvec3, out highp uvec3 lsb);" 1383 "void umulExtended(highp uvec4, highp uvec4, highp out uvec4, out highp uvec4 lsb);" 1384 1385 "void imulExtended(highp int, highp int, highp out int, out highp int lsb);" 1386 "void imulExtended(highp ivec2, highp ivec2, highp out ivec2, out highp ivec2 lsb);" 1387 "void imulExtended(highp ivec3, highp ivec3, highp out ivec3, out highp ivec3 lsb);" 1388 "void imulExtended(highp ivec4, highp ivec4, highp out ivec4, out highp ivec4 lsb);" 1389 1390 "highp int bitfieldReverse(highp int);" 1391 "highp ivec2 bitfieldReverse(highp ivec2);" 1392 "highp ivec3 bitfieldReverse(highp ivec3);" 1393 "highp ivec4 bitfieldReverse(highp ivec4);" 1394 1395 "highp uint bitfieldReverse(highp uint);" 1396 "highp uvec2 bitfieldReverse(highp uvec2);" 1397 "highp uvec3 bitfieldReverse(highp uvec3);" 1398 "highp uvec4 bitfieldReverse(highp uvec4);" 1399 1400 " int bitCount( int);" 1401 "ivec2 bitCount(ivec2);" 1402 "ivec3 bitCount(ivec3);" 1403 "ivec4 bitCount(ivec4);" 1404 1405 " int bitCount( uint);" 1406 "ivec2 bitCount(uvec2);" 1407 "ivec3 bitCount(uvec3);" 1408 "ivec4 bitCount(uvec4);" 1409 1410 " int findMSB(highp int);" 1411 "ivec2 findMSB(highp ivec2);" 1412 "ivec3 findMSB(highp ivec3);" 1413 "ivec4 findMSB(highp ivec4);" 1414 1415 " int findMSB(highp uint);" 1416 "ivec2 findMSB(highp uvec2);" 1417 "ivec3 findMSB(highp uvec3);" 1418 "ivec4 findMSB(highp uvec4);" 1419 1420 "\n"); 1421 } 1422 1423 // GL_ARB_shader_ballot 1424 if (profile != EEsProfile && version >= 450) { 1425 commonBuiltins.append( 1426 "uint64_t ballotARB(bool);" 1427 1428 "float readInvocationARB(float, uint);" 1429 "vec2 readInvocationARB(vec2, uint);" 1430 "vec3 readInvocationARB(vec3, uint);" 1431 "vec4 readInvocationARB(vec4, uint);" 1432 1433 "int readInvocationARB(int, uint);" 1434 "ivec2 readInvocationARB(ivec2, uint);" 1435 "ivec3 readInvocationARB(ivec3, uint);" 1436 "ivec4 readInvocationARB(ivec4, uint);" 1437 1438 "uint readInvocationARB(uint, uint);" 1439 "uvec2 readInvocationARB(uvec2, uint);" 1440 "uvec3 readInvocationARB(uvec3, uint);" 1441 "uvec4 readInvocationARB(uvec4, uint);" 1442 1443 "float readFirstInvocationARB(float);" 1444 "vec2 readFirstInvocationARB(vec2);" 1445 "vec3 readFirstInvocationARB(vec3);" 1446 "vec4 readFirstInvocationARB(vec4);" 1447 1448 "int readFirstInvocationARB(int);" 1449 "ivec2 readFirstInvocationARB(ivec2);" 1450 "ivec3 readFirstInvocationARB(ivec3);" 1451 "ivec4 readFirstInvocationARB(ivec4);" 1452 1453 "uint readFirstInvocationARB(uint);" 1454 "uvec2 readFirstInvocationARB(uvec2);" 1455 "uvec3 readFirstInvocationARB(uvec3);" 1456 "uvec4 readFirstInvocationARB(uvec4);" 1457 1458 "\n"); 1459 } 1460 1461 // GL_ARB_shader_group_vote 1462 if (profile != EEsProfile && version >= 430) { 1463 commonBuiltins.append( 1464 "bool anyInvocationARB(bool);" 1465 "bool allInvocationsARB(bool);" 1466 "bool allInvocationsEqualARB(bool);" 1467 1468 "\n"); 1469 } 1470 1471 //============================================================================ 1472 // 1473 // Prototypes for built-in functions seen by vertex shaders only. 1474 // (Except legacy lod functions, where it depends which release they are 1475 // vertex only.) 1476 // 1477 //============================================================================ 1478 1479 // 1480 // Geometric Functions. 1481 // 1482 if (IncludeLegacy(version, profile, spvVersion)) 1483 stageBuiltins[EShLangVertex].append("vec4 ftransform();"); 1484 1485 // 1486 // Original-style texture Functions with lod. 1487 // 1488 TString* s; 1489 if (version == 100) 1490 s = &stageBuiltins[EShLangVertex]; 1491 else 1492 s = &commonBuiltins; 1493 if ((profile == EEsProfile && version == 100) || 1494 profile == ECompatibilityProfile || 1495 (profile == ECoreProfile && version < 420) || 1496 profile == ENoProfile) { 1497 if (spvVersion.spv == 0) { 1498 s->append( 1499 "vec4 texture2DLod(sampler2D, vec2, float);" // GL_ARB_shader_texture_lod 1500 "vec4 texture2DProjLod(sampler2D, vec3, float);" // GL_ARB_shader_texture_lod 1501 "vec4 texture2DProjLod(sampler2D, vec4, float);" // GL_ARB_shader_texture_lod 1502 "vec4 texture3DLod(sampler3D, vec3, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check 1503 "vec4 texture3DProjLod(sampler3D, vec4, float);" // GL_ARB_shader_texture_lod // OES_texture_3D, but caught by keyword check 1504 "vec4 textureCubeLod(samplerCube, vec3, float);" // GL_ARB_shader_texture_lod 1505 1506 "\n"); 1507 } 1508 } 1509 if ( profile == ECompatibilityProfile || 1510 (profile == ECoreProfile && version < 420) || 1511 profile == ENoProfile) { 1512 if (spvVersion.spv == 0) { 1513 s->append( 1514 "vec4 texture1DLod(sampler1D, float, float);" // GL_ARB_shader_texture_lod 1515 "vec4 texture1DProjLod(sampler1D, vec2, float);" // GL_ARB_shader_texture_lod 1516 "vec4 texture1DProjLod(sampler1D, vec4, float);" // GL_ARB_shader_texture_lod 1517 "vec4 shadow1DLod(sampler1DShadow, vec3, float);" // GL_ARB_shader_texture_lod 1518 "vec4 shadow2DLod(sampler2DShadow, vec3, float);" // GL_ARB_shader_texture_lod 1519 "vec4 shadow1DProjLod(sampler1DShadow, vec4, float);" // GL_ARB_shader_texture_lod 1520 "vec4 shadow2DProjLod(sampler2DShadow, vec4, float);" // GL_ARB_shader_texture_lod 1521 1522 "vec4 texture1DGradARB(sampler1D, float, float, float);" // GL_ARB_shader_texture_lod 1523 "vec4 texture1DProjGradARB(sampler1D, vec2, float, float);" // GL_ARB_shader_texture_lod 1524 "vec4 texture1DProjGradARB(sampler1D, vec4, float, float);" // GL_ARB_shader_texture_lod 1525 "vec4 texture2DGradARB(sampler2D, vec2, vec2, vec2);" // GL_ARB_shader_texture_lod 1526 "vec4 texture2DProjGradARB(sampler2D, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod 1527 "vec4 texture2DProjGradARB(sampler2D, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod 1528 "vec4 texture3DGradARB(sampler3D, vec3, vec3, vec3);" // GL_ARB_shader_texture_lod 1529 "vec4 texture3DProjGradARB(sampler3D, vec4, vec3, vec3);" // GL_ARB_shader_texture_lod 1530 "vec4 textureCubeGradARB(samplerCube, vec3, vec3, vec3);" // GL_ARB_shader_texture_lod 1531 "vec4 shadow1DGradARB(sampler1DShadow, vec3, float, float);" // GL_ARB_shader_texture_lod 1532 "vec4 shadow1DProjGradARB( sampler1DShadow, vec4, float, float);" // GL_ARB_shader_texture_lod 1533 "vec4 shadow2DGradARB(sampler2DShadow, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod 1534 "vec4 shadow2DProjGradARB( sampler2DShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod 1535 "vec4 texture2DRectGradARB(sampler2DRect, vec2, vec2, vec2);" // GL_ARB_shader_texture_lod 1536 "vec4 texture2DRectProjGradARB( sampler2DRect, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod 1537 "vec4 texture2DRectProjGradARB( sampler2DRect, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod 1538 "vec4 shadow2DRectGradARB( sampler2DRectShadow, vec3, vec2, vec2);" // GL_ARB_shader_texture_lod 1539 "vec4 shadow2DRectProjGradARB(sampler2DRectShadow, vec4, vec2, vec2);" // GL_ARB_shader_texture_lod 1540 1541 "\n"); 1542 } 1543 } 1544 1545 if ((profile != EEsProfile && version >= 150) || 1546 (profile == EEsProfile && version >= 310)) { 1547 //============================================================================ 1548 // 1549 // Prototypes for built-in functions seen by geometry shaders only. 1550 // 1551 //============================================================================ 1552 1553 if (profile != EEsProfile && version >= 400) { 1554 stageBuiltins[EShLangGeometry].append( 1555 "void EmitStreamVertex(int);" 1556 "void EndStreamPrimitive(int);" 1557 ); 1558 } 1559 stageBuiltins[EShLangGeometry].append( 1560 "void EmitVertex();" 1561 "void EndPrimitive();" 1562 "\n"); 1563 } 1564 1565 //============================================================================ 1566 // 1567 // Prototypes for all control functions. 1568 // 1569 //============================================================================ 1570 bool esBarrier = (profile == EEsProfile && version >= 310); 1571 if ((profile != EEsProfile && version >= 150) || esBarrier) 1572 stageBuiltins[EShLangTessControl].append( 1573 "void barrier();" 1574 ); 1575 if ((profile != EEsProfile && version >= 420) || esBarrier) 1576 stageBuiltins[EShLangCompute].append( 1577 "void barrier();" 1578 ); 1579 if ((profile != EEsProfile && version >= 130) || esBarrier) 1580 commonBuiltins.append( 1581 "void memoryBarrier();" 1582 ); 1583 if ((profile != EEsProfile && version >= 420) || esBarrier) { 1584 commonBuiltins.append( 1585 "void memoryBarrierAtomicCounter();" 1586 "void memoryBarrierBuffer();" 1587 "void memoryBarrierImage();" 1588 ); 1589 stageBuiltins[EShLangCompute].append( 1590 "void memoryBarrierShared();" 1591 "void groupMemoryBarrier();" 1592 ); 1593 } 1594 1595 //============================================================================ 1596 // 1597 // Prototypes for built-in functions seen by fragment shaders only. 1598 // 1599 //============================================================================ 1600 1601 // 1602 // Original-style texture Functions with bias. 1603 // 1604 if (spvVersion.spv == 0 && (profile != EEsProfile || version == 100)) { 1605 stageBuiltins[EShLangFragment].append( 1606 "vec4 texture2D(sampler2D, vec2, float);" 1607 "vec4 texture2DProj(sampler2D, vec3, float);" 1608 "vec4 texture2DProj(sampler2D, vec4, float);" 1609 "vec4 texture3D(sampler3D, vec3, float);" // OES_texture_3D 1610 "vec4 texture3DProj(sampler3D, vec4, float);" // OES_texture_3D 1611 "vec4 textureCube(samplerCube, vec3, float);" 1612 1613 "\n"); 1614 } 1615 if (spvVersion.spv == 0 && (profile != EEsProfile && version > 100)) { 1616 stageBuiltins[EShLangFragment].append( 1617 "vec4 texture1D(sampler1D, float, float);" 1618 "vec4 texture1DProj(sampler1D, vec2, float);" 1619 "vec4 texture1DProj(sampler1D, vec4, float);" 1620 "vec4 shadow1D(sampler1DShadow, vec3, float);" 1621 "vec4 shadow2D(sampler2DShadow, vec3, float);" 1622 "vec4 shadow1DProj(sampler1DShadow, vec4, float);" 1623 "vec4 shadow2DProj(sampler2DShadow, vec4, float);" 1624 1625 "\n"); 1626 } 1627 if (spvVersion.spv == 0 && profile == EEsProfile) { 1628 stageBuiltins[EShLangFragment].append( 1629 "vec4 texture2DLodEXT(sampler2D, vec2, float);" // GL_EXT_shader_texture_lod 1630 "vec4 texture2DProjLodEXT(sampler2D, vec3, float);" // GL_EXT_shader_texture_lod 1631 "vec4 texture2DProjLodEXT(sampler2D, vec4, float);" // GL_EXT_shader_texture_lod 1632 "vec4 textureCubeLodEXT(samplerCube, vec3, float);" // GL_EXT_shader_texture_lod 1633 1634 "\n"); 1635 } 1636 1637 stageBuiltins[EShLangFragment].append( 1638 "float dFdx(float p);" 1639 "vec2 dFdx(vec2 p);" 1640 "vec3 dFdx(vec3 p);" 1641 "vec4 dFdx(vec4 p);" 1642 1643 "float dFdy(float p);" 1644 "vec2 dFdy(vec2 p);" 1645 "vec3 dFdy(vec3 p);" 1646 "vec4 dFdy(vec4 p);" 1647 1648 "float fwidth(float p);" 1649 "vec2 fwidth(vec2 p);" 1650 "vec3 fwidth(vec3 p);" 1651 "vec4 fwidth(vec4 p);" 1652 1653 "\n"); 1654 1655 // GL_ARB_derivative_control 1656 if (profile != EEsProfile && version >= 400) { 1657 stageBuiltins[EShLangFragment].append( 1658 "float dFdxFine(float p);" 1659 "vec2 dFdxFine(vec2 p);" 1660 "vec3 dFdxFine(vec3 p);" 1661 "vec4 dFdxFine(vec4 p);" 1662 1663 "float dFdyFine(float p);" 1664 "vec2 dFdyFine(vec2 p);" 1665 "vec3 dFdyFine(vec3 p);" 1666 "vec4 dFdyFine(vec4 p);" 1667 1668 "float fwidthFine(float p);" 1669 "vec2 fwidthFine(vec2 p);" 1670 "vec3 fwidthFine(vec3 p);" 1671 "vec4 fwidthFine(vec4 p);" 1672 1673 "\n"); 1674 1675 stageBuiltins[EShLangFragment].append( 1676 "float dFdxCoarse(float p);" 1677 "vec2 dFdxCoarse(vec2 p);" 1678 "vec3 dFdxCoarse(vec3 p);" 1679 "vec4 dFdxCoarse(vec4 p);" 1680 1681 "float dFdyCoarse(float p);" 1682 "vec2 dFdyCoarse(vec2 p);" 1683 "vec3 dFdyCoarse(vec3 p);" 1684 "vec4 dFdyCoarse(vec4 p);" 1685 1686 "float fwidthCoarse(float p);" 1687 "vec2 fwidthCoarse(vec2 p);" 1688 "vec3 fwidthCoarse(vec3 p);" 1689 "vec4 fwidthCoarse(vec4 p);" 1690 1691 "\n"); 1692 } 1693 1694 // GL_OES_shader_multisample_interpolation 1695 if ((profile == EEsProfile && version >= 310) || 1696 (profile != EEsProfile && version >= 400)) { 1697 stageBuiltins[EShLangFragment].append( 1698 "float interpolateAtCentroid(float);" 1699 "vec2 interpolateAtCentroid(vec2);" 1700 "vec3 interpolateAtCentroid(vec3);" 1701 "vec4 interpolateAtCentroid(vec4);" 1702 1703 "float interpolateAtSample(float, int);" 1704 "vec2 interpolateAtSample(vec2, int);" 1705 "vec3 interpolateAtSample(vec3, int);" 1706 "vec4 interpolateAtSample(vec4, int);" 1707 1708 "float interpolateAtOffset(float, vec2);" 1709 "vec2 interpolateAtOffset(vec2, vec2);" 1710 "vec3 interpolateAtOffset(vec3, vec2);" 1711 "vec4 interpolateAtOffset(vec4, vec2);" 1712 1713 "\n"); 1714 } 1715 1716 //============================================================================ 1717 // 1718 // Standard Uniforms 1719 // 1720 //============================================================================ 1721 1722 // 1723 // Depth range in window coordinates, p. 33 1724 // 1725 if (spvVersion.spv == 0) { 1726 commonBuiltins.append( 1727 "struct gl_DepthRangeParameters {" 1728 ); 1729 if (profile == EEsProfile) { 1730 commonBuiltins.append( 1731 "highp float near;" // n 1732 "highp float far;" // f 1733 "highp float diff;" // f - n 1734 ); 1735 } else { 1736 commonBuiltins.append( 1737 "float near;" // n 1738 "float far;" // f 1739 "float diff;" // f - n 1740 ); 1741 } 1742 1743 commonBuiltins.append( 1744 "};" 1745 "uniform gl_DepthRangeParameters gl_DepthRange;" 1746 "\n"); 1747 } 1748 1749 if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) { 1750 // 1751 // Matrix state. p. 31, 32, 37, 39, 40. 1752 // 1753 commonBuiltins.append( 1754 "uniform mat4 gl_ModelViewMatrix;" 1755 "uniform mat4 gl_ProjectionMatrix;" 1756 "uniform mat4 gl_ModelViewProjectionMatrix;" 1757 1758 // 1759 // Derived matrix state that provides inverse and transposed versions 1760 // of the matrices above. 1761 // 1762 "uniform mat3 gl_NormalMatrix;" 1763 1764 "uniform mat4 gl_ModelViewMatrixInverse;" 1765 "uniform mat4 gl_ProjectionMatrixInverse;" 1766 "uniform mat4 gl_ModelViewProjectionMatrixInverse;" 1767 1768 "uniform mat4 gl_ModelViewMatrixTranspose;" 1769 "uniform mat4 gl_ProjectionMatrixTranspose;" 1770 "uniform mat4 gl_ModelViewProjectionMatrixTranspose;" 1771 1772 "uniform mat4 gl_ModelViewMatrixInverseTranspose;" 1773 "uniform mat4 gl_ProjectionMatrixInverseTranspose;" 1774 "uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose;" 1775 1776 // 1777 // Normal scaling p. 39. 1778 // 1779 "uniform float gl_NormalScale;" 1780 1781 // 1782 // Point Size, p. 66, 67. 1783 // 1784 "struct gl_PointParameters {" 1785 "float size;" 1786 "float sizeMin;" 1787 "float sizeMax;" 1788 "float fadeThresholdSize;" 1789 "float distanceConstantAttenuation;" 1790 "float distanceLinearAttenuation;" 1791 "float distanceQuadraticAttenuation;" 1792 "};" 1793 1794 "uniform gl_PointParameters gl_Point;" 1795 1796 // 1797 // Material State p. 50, 55. 1798 // 1799 "struct gl_MaterialParameters {" 1800 "vec4 emission;" // Ecm 1801 "vec4 ambient;" // Acm 1802 "vec4 diffuse;" // Dcm 1803 "vec4 specular;" // Scm 1804 "float shininess;" // Srm 1805 "};" 1806 "uniform gl_MaterialParameters gl_FrontMaterial;" 1807 "uniform gl_MaterialParameters gl_BackMaterial;" 1808 1809 // 1810 // Light State p 50, 53, 55. 1811 // 1812 "struct gl_LightSourceParameters {" 1813 "vec4 ambient;" // Acli 1814 "vec4 diffuse;" // Dcli 1815 "vec4 specular;" // Scli 1816 "vec4 position;" // Ppli 1817 "vec4 halfVector;" // Derived: Hi 1818 "vec3 spotDirection;" // Sdli 1819 "float spotExponent;" // Srli 1820 "float spotCutoff;" // Crli 1821 // (range: [0.0,90.0], 180.0) 1822 "float spotCosCutoff;" // Derived: cos(Crli) 1823 // (range: [1.0,0.0],-1.0) 1824 "float constantAttenuation;" // K0 1825 "float linearAttenuation;" // K1 1826 "float quadraticAttenuation;"// K2 1827 "};" 1828 1829 1830 "struct gl_LightModelParameters {" 1831 "vec4 ambient;" // Acs 1832 "};" 1833 1834 "uniform gl_LightModelParameters gl_LightModel;" 1835 1836 // 1837 // Derived state from products of light and material. 1838 // 1839 "struct gl_LightModelProducts {" 1840 "vec4 sceneColor;" // Derived. Ecm + Acm * Acs 1841 "};" 1842 1843 "uniform gl_LightModelProducts gl_FrontLightModelProduct;" 1844 "uniform gl_LightModelProducts gl_BackLightModelProduct;" 1845 1846 "struct gl_LightProducts {" 1847 "vec4 ambient;" // Acm * Acli 1848 "vec4 diffuse;" // Dcm * Dcli 1849 "vec4 specular;" // Scm * Scli 1850 "};" 1851 1852 // 1853 // Fog p. 161 1854 // 1855 "struct gl_FogParameters {" 1856 "vec4 color;" 1857 "float density;" 1858 "float start;" 1859 "float end;" 1860 "float scale;" // 1 / (gl_FogEnd - gl_FogStart) 1861 "};" 1862 1863 "uniform gl_FogParameters gl_Fog;" 1864 1865 "\n"); 1866 } 1867 1868 //============================================================================ 1869 // 1870 // Define the interface to the compute shader. 1871 // 1872 //============================================================================ 1873 1874 if ((profile != EEsProfile && version >= 420) || 1875 (profile == EEsProfile && version >= 310)) { 1876 stageBuiltins[EShLangCompute].append( 1877 "in highp uvec3 gl_NumWorkGroups;" 1878 "const highp uvec3 gl_WorkGroupSize = uvec3(1,1,1);" 1879 1880 "in highp uvec3 gl_WorkGroupID;" 1881 "in highp uvec3 gl_LocalInvocationID;" 1882 1883 "in highp uvec3 gl_GlobalInvocationID;" 1884 "in highp uint gl_LocalInvocationIndex;" 1885 1886 "\n"); 1887 } 1888 1889 //============================================================================ 1890 // 1891 // Define the interface to the vertex shader. 1892 // 1893 //============================================================================ 1894 1895 if (profile != EEsProfile) { 1896 if (version < 130) { 1897 stageBuiltins[EShLangVertex].append( 1898 "attribute vec4 gl_Color;" 1899 "attribute vec4 gl_SecondaryColor;" 1900 "attribute vec3 gl_Normal;" 1901 "attribute vec4 gl_Vertex;" 1902 "attribute vec4 gl_MultiTexCoord0;" 1903 "attribute vec4 gl_MultiTexCoord1;" 1904 "attribute vec4 gl_MultiTexCoord2;" 1905 "attribute vec4 gl_MultiTexCoord3;" 1906 "attribute vec4 gl_MultiTexCoord4;" 1907 "attribute vec4 gl_MultiTexCoord5;" 1908 "attribute vec4 gl_MultiTexCoord6;" 1909 "attribute vec4 gl_MultiTexCoord7;" 1910 "attribute float gl_FogCoord;" 1911 "\n"); 1912 } else if (IncludeLegacy(version, profile, spvVersion)) { 1913 stageBuiltins[EShLangVertex].append( 1914 "in vec4 gl_Color;" 1915 "in vec4 gl_SecondaryColor;" 1916 "in vec3 gl_Normal;" 1917 "in vec4 gl_Vertex;" 1918 "in vec4 gl_MultiTexCoord0;" 1919 "in vec4 gl_MultiTexCoord1;" 1920 "in vec4 gl_MultiTexCoord2;" 1921 "in vec4 gl_MultiTexCoord3;" 1922 "in vec4 gl_MultiTexCoord4;" 1923 "in vec4 gl_MultiTexCoord5;" 1924 "in vec4 gl_MultiTexCoord6;" 1925 "in vec4 gl_MultiTexCoord7;" 1926 "in float gl_FogCoord;" 1927 "\n"); 1928 } 1929 1930 if (version < 150) { 1931 if (version < 130) { 1932 stageBuiltins[EShLangVertex].append( 1933 " vec4 gl_ClipVertex;" // needs qualifier fixed later 1934 "varying vec4 gl_FrontColor;" 1935 "varying vec4 gl_BackColor;" 1936 "varying vec4 gl_FrontSecondaryColor;" 1937 "varying vec4 gl_BackSecondaryColor;" 1938 "varying vec4 gl_TexCoord[];" 1939 "varying float gl_FogFragCoord;" 1940 "\n"); 1941 } else if (IncludeLegacy(version, profile, spvVersion)) { 1942 stageBuiltins[EShLangVertex].append( 1943 " vec4 gl_ClipVertex;" // needs qualifier fixed later 1944 "out vec4 gl_FrontColor;" 1945 "out vec4 gl_BackColor;" 1946 "out vec4 gl_FrontSecondaryColor;" 1947 "out vec4 gl_BackSecondaryColor;" 1948 "out vec4 gl_TexCoord[];" 1949 "out float gl_FogFragCoord;" 1950 "\n"); 1951 } 1952 stageBuiltins[EShLangVertex].append( 1953 "vec4 gl_Position;" // needs qualifier fixed later 1954 "float gl_PointSize;" // needs qualifier fixed later 1955 ); 1956 1957 if (version == 130 || version == 140) 1958 stageBuiltins[EShLangVertex].append( 1959 "out float gl_ClipDistance[];" 1960 ); 1961 } else { 1962 // version >= 150 1963 stageBuiltins[EShLangVertex].append( 1964 "out gl_PerVertex {" 1965 "vec4 gl_Position;" // needs qualifier fixed later 1966 "float gl_PointSize;" // needs qualifier fixed later 1967 "float gl_ClipDistance[];" 1968 ); 1969 if (IncludeLegacy(version, profile, spvVersion)) 1970 stageBuiltins[EShLangVertex].append( 1971 "vec4 gl_ClipVertex;" // needs qualifier fixed later 1972 "vec4 gl_FrontColor;" 1973 "vec4 gl_BackColor;" 1974 "vec4 gl_FrontSecondaryColor;" 1975 "vec4 gl_BackSecondaryColor;" 1976 "vec4 gl_TexCoord[];" 1977 "float gl_FogFragCoord;" 1978 ); 1979 if (version >= 450) 1980 stageBuiltins[EShLangVertex].append( 1981 "float gl_CullDistance[];" 1982 ); 1983 stageBuiltins[EShLangVertex].append( 1984 "};" 1985 "\n"); 1986 } 1987 if (version >= 130 && spvVersion.vulkan == 0) 1988 stageBuiltins[EShLangVertex].append( 1989 "int gl_VertexID;" // needs qualifier fixed later 1990 ); 1991 if (version >= 140 && spvVersion.vulkan == 0) 1992 stageBuiltins[EShLangVertex].append( 1993 "int gl_InstanceID;" // needs qualifier fixed later 1994 ); 1995 if (spvVersion.vulkan >= 100 && version >= 140) 1996 stageBuiltins[EShLangVertex].append( 1997 "in int gl_VertexIndex;" 1998 "in int gl_InstanceIndex;" 1999 ); 2000 if (version >= 440) { 2001 stageBuiltins[EShLangVertex].append( 2002 "in int gl_BaseVertexARB;" 2003 "in int gl_BaseInstanceARB;" 2004 "in int gl_DrawIDARB;" 2005 ); 2006 } 2007 } else { 2008 // ES profile 2009 if (version == 100) { 2010 stageBuiltins[EShLangVertex].append( 2011 "highp vec4 gl_Position;" // needs qualifier fixed later 2012 "mediump float gl_PointSize;" // needs qualifier fixed later 2013 ); 2014 } else { 2015 if (spvVersion.vulkan == 0) 2016 stageBuiltins[EShLangVertex].append( 2017 "in highp int gl_VertexID;" // needs qualifier fixed later 2018 "in highp int gl_InstanceID;" // needs qualifier fixed later 2019 ); 2020 if (spvVersion.vulkan >= 100) 2021 stageBuiltins[EShLangVertex].append( 2022 "in highp int gl_VertexIndex;" 2023 "in highp int gl_InstanceIndex;" 2024 ); 2025 if (version < 310) 2026 stageBuiltins[EShLangVertex].append( 2027 "highp vec4 gl_Position;" // needs qualifier fixed later 2028 "highp float gl_PointSize;" // needs qualifier fixed later 2029 ); 2030 else 2031 stageBuiltins[EShLangVertex].append( 2032 "out gl_PerVertex {" 2033 "highp vec4 gl_Position;" // needs qualifier fixed later 2034 "highp float gl_PointSize;" // needs qualifier fixed later 2035 "};" 2036 ); 2037 } 2038 } 2039 2040 //============================================================================ 2041 // 2042 // Define the interface to the geometry shader. 2043 // 2044 //============================================================================ 2045 2046 if (profile == ECoreProfile || profile == ECompatibilityProfile) { 2047 stageBuiltins[EShLangGeometry].append( 2048 "in gl_PerVertex {" 2049 "vec4 gl_Position;" 2050 "float gl_PointSize;" 2051 "float gl_ClipDistance[];" 2052 ); 2053 if (profile == ECompatibilityProfile) 2054 stageBuiltins[EShLangGeometry].append( 2055 "vec4 gl_ClipVertex;" 2056 "vec4 gl_FrontColor;" 2057 "vec4 gl_BackColor;" 2058 "vec4 gl_FrontSecondaryColor;" 2059 "vec4 gl_BackSecondaryColor;" 2060 "vec4 gl_TexCoord[];" 2061 "float gl_FogFragCoord;" 2062 ); 2063 if (version >= 450) 2064 stageBuiltins[EShLangGeometry].append( 2065 "float gl_CullDistance[];" 2066 ); 2067 stageBuiltins[EShLangGeometry].append( 2068 "} gl_in[];" 2069 2070 "in int gl_PrimitiveIDIn;" 2071 "out gl_PerVertex {" 2072 "vec4 gl_Position;" 2073 "float gl_PointSize;" 2074 "float gl_ClipDistance[];" 2075 "\n"); 2076 if (profile == ECompatibilityProfile && version >= 400) 2077 stageBuiltins[EShLangGeometry].append( 2078 "vec4 gl_ClipVertex;" 2079 "vec4 gl_FrontColor;" 2080 "vec4 gl_BackColor;" 2081 "vec4 gl_FrontSecondaryColor;" 2082 "vec4 gl_BackSecondaryColor;" 2083 "vec4 gl_TexCoord[];" 2084 "float gl_FogFragCoord;" 2085 ); 2086 if (version >= 450) 2087 stageBuiltins[EShLangGeometry].append( 2088 "float gl_CullDistance[];" 2089 ); 2090 stageBuiltins[EShLangGeometry].append( 2091 "};" 2092 2093 "out int gl_PrimitiveID;" 2094 "out int gl_Layer;"); 2095 2096 if (profile == ECompatibilityProfile && version < 400) 2097 stageBuiltins[EShLangGeometry].append( 2098 "out vec4 gl_ClipVertex;" 2099 ); 2100 2101 if (version >= 400) 2102 stageBuiltins[EShLangGeometry].append( 2103 "in int gl_InvocationID;" 2104 ); 2105 // GL_ARB_viewport_array 2106 if (version >= 150) 2107 stageBuiltins[EShLangGeometry].append( 2108 "out int gl_ViewportIndex;" 2109 ); 2110 stageBuiltins[EShLangGeometry].append("\n"); 2111 } else if (profile == EEsProfile && version >= 310) { 2112 stageBuiltins[EShLangGeometry].append( 2113 "in gl_PerVertex {" 2114 "highp vec4 gl_Position;" 2115 "highp float gl_PointSize;" 2116 "} gl_in[];" 2117 "\n" 2118 "in highp int gl_PrimitiveIDIn;" 2119 "in highp int gl_InvocationID;" 2120 "\n" 2121 "out gl_PerVertex {" 2122 "highp vec4 gl_Position;" 2123 "highp float gl_PointSize;" 2124 "};" 2125 "\n" 2126 "out highp int gl_PrimitiveID;" 2127 "out highp int gl_Layer;" 2128 "\n" 2129 ); 2130 } 2131 2132 2133 //============================================================================ 2134 // 2135 // Define the interface to the tessellation control shader. 2136 // 2137 //============================================================================ 2138 2139 if (profile != EEsProfile && version >= 150) { 2140 // Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below, 2141 // as it depends on the resource sizing of gl_MaxPatchVertices. 2142 2143 stageBuiltins[EShLangTessControl].append( 2144 "in int gl_PatchVerticesIn;" 2145 "in int gl_PrimitiveID;" 2146 "in int gl_InvocationID;" 2147 2148 "out gl_PerVertex {" 2149 "vec4 gl_Position;" 2150 "float gl_PointSize;" 2151 "float gl_ClipDistance[];" 2152 ); 2153 if (profile == ECompatibilityProfile) 2154 stageBuiltins[EShLangTessControl].append( 2155 "vec4 gl_ClipVertex;" 2156 "vec4 gl_FrontColor;" 2157 "vec4 gl_BackColor;" 2158 "vec4 gl_FrontSecondaryColor;" 2159 "vec4 gl_BackSecondaryColor;" 2160 "vec4 gl_TexCoord[];" 2161 "float gl_FogFragCoord;" 2162 ); 2163 if (version >= 450) 2164 stageBuiltins[EShLangTessControl].append( 2165 "float gl_CullDistance[];" 2166 ); 2167 stageBuiltins[EShLangTessControl].append( 2168 "} gl_out[];" 2169 2170 "patch out float gl_TessLevelOuter[4];" 2171 "patch out float gl_TessLevelInner[2];" 2172 "\n"); 2173 } else { 2174 // Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below, 2175 // as it depends on the resource sizing of gl_MaxPatchVertices. 2176 2177 stageBuiltins[EShLangTessControl].append( 2178 "in highp int gl_PatchVerticesIn;" 2179 "in highp int gl_PrimitiveID;" 2180 "in highp int gl_InvocationID;" 2181 2182 "out gl_PerVertex {" 2183 "highp vec4 gl_Position;" 2184 "highp float gl_PointSize;" 2185 ); 2186 stageBuiltins[EShLangTessControl].append( 2187 "} gl_out[];" 2188 2189 "patch out highp float gl_TessLevelOuter[4];" 2190 "patch out highp float gl_TessLevelInner[2];" 2191 "patch out highp vec4 gl_BoundingBoxOES[2];" 2192 "\n"); 2193 } 2194 2195 //============================================================================ 2196 // 2197 // Define the interface to the tessellation evaluation shader. 2198 // 2199 //============================================================================ 2200 2201 if (profile != EEsProfile && version >= 150) { 2202 // Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below, 2203 // as it depends on the resource sizing of gl_MaxPatchVertices. 2204 2205 stageBuiltins[EShLangTessEvaluation].append( 2206 "in int gl_PatchVerticesIn;" 2207 "in int gl_PrimitiveID;" 2208 "in vec3 gl_TessCoord;" 2209 2210 "patch in float gl_TessLevelOuter[4];" 2211 "patch in float gl_TessLevelInner[2];" 2212 2213 "out gl_PerVertex {" 2214 "vec4 gl_Position;" 2215 "float gl_PointSize;" 2216 "float gl_ClipDistance[];" 2217 ); 2218 if (version >= 400 && profile == ECompatibilityProfile) 2219 stageBuiltins[EShLangTessEvaluation].append( 2220 "vec4 gl_ClipVertex;" 2221 "vec4 gl_FrontColor;" 2222 "vec4 gl_BackColor;" 2223 "vec4 gl_FrontSecondaryColor;" 2224 "vec4 gl_BackSecondaryColor;" 2225 "vec4 gl_TexCoord[];" 2226 "float gl_FogFragCoord;" 2227 ); 2228 if (version >= 450) 2229 stageBuiltins[EShLangTessEvaluation].append( 2230 "float gl_CullDistance[];" 2231 ); 2232 stageBuiltins[EShLangTessEvaluation].append( 2233 "};" 2234 "\n"); 2235 } else if (profile == EEsProfile && version >= 310) { 2236 // Note: "in gl_PerVertex {...} gl_in[gl_MaxPatchVertices];" is declared in initialize() below, 2237 // as it depends on the resource sizing of gl_MaxPatchVertices. 2238 2239 stageBuiltins[EShLangTessEvaluation].append( 2240 "in highp int gl_PatchVerticesIn;" 2241 "in highp int gl_PrimitiveID;" 2242 "in highp vec3 gl_TessCoord;" 2243 2244 "patch in highp float gl_TessLevelOuter[4];" 2245 "patch in highp float gl_TessLevelInner[2];" 2246 2247 "out gl_PerVertex {" 2248 "highp vec4 gl_Position;" 2249 "highp float gl_PointSize;" 2250 ); 2251 stageBuiltins[EShLangTessEvaluation].append( 2252 "};" 2253 "\n"); 2254 } 2255 2256 //============================================================================ 2257 // 2258 // Define the interface to the fragment shader. 2259 // 2260 //============================================================================ 2261 2262 if (profile != EEsProfile) { 2263 2264 stageBuiltins[EShLangFragment].append( 2265 "vec4 gl_FragCoord;" // needs qualifier fixed later 2266 "bool gl_FrontFacing;" // needs qualifier fixed later 2267 "float gl_FragDepth;" // needs qualifier fixed later 2268 ); 2269 if (version >= 120) 2270 stageBuiltins[EShLangFragment].append( 2271 "vec2 gl_PointCoord;" // needs qualifier fixed later 2272 ); 2273 if (IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && version < 420)) 2274 stageBuiltins[EShLangFragment].append( 2275 "vec4 gl_FragColor;" // needs qualifier fixed later 2276 ); 2277 2278 if (version < 130) { 2279 stageBuiltins[EShLangFragment].append( 2280 "varying vec4 gl_Color;" 2281 "varying vec4 gl_SecondaryColor;" 2282 "varying vec4 gl_TexCoord[];" 2283 "varying float gl_FogFragCoord;" 2284 ); 2285 } else { 2286 stageBuiltins[EShLangFragment].append( 2287 "in float gl_ClipDistance[];" 2288 ); 2289 2290 if (IncludeLegacy(version, profile, spvVersion)) { 2291 if (version < 150) 2292 stageBuiltins[EShLangFragment].append( 2293 "in float gl_FogFragCoord;" 2294 "in vec4 gl_TexCoord[];" 2295 "in vec4 gl_Color;" 2296 "in vec4 gl_SecondaryColor;" 2297 ); 2298 else 2299 stageBuiltins[EShLangFragment].append( 2300 "in gl_PerFragment {" 2301 "in float gl_FogFragCoord;" 2302 "in vec4 gl_TexCoord[];" 2303 "in vec4 gl_Color;" 2304 "in vec4 gl_SecondaryColor;" 2305 "};" 2306 ); 2307 } 2308 } 2309 2310 if (version >= 150) 2311 stageBuiltins[EShLangFragment].append( 2312 "flat in int gl_PrimitiveID;" 2313 ); 2314 2315 if (version >= 400) 2316 stageBuiltins[EShLangFragment].append( 2317 "flat in int gl_SampleID;" 2318 " in vec2 gl_SamplePosition;" 2319 "flat in int gl_SampleMaskIn[];" 2320 " out int gl_SampleMask[];" 2321 "uniform int gl_NumSamples;" 2322 ); 2323 2324 if (version >= 430) 2325 stageBuiltins[EShLangFragment].append( 2326 "flat in int gl_Layer;" 2327 "flat in int gl_ViewportIndex;" 2328 ); 2329 2330 if (version >= 450) 2331 stageBuiltins[EShLangFragment].append( 2332 "in float gl_CullDistance[];" 2333 "bool gl_HelperInvocation;" // needs qualifier fixed later 2334 ); 2335 } else { 2336 // ES profile 2337 2338 if (version == 100) { 2339 stageBuiltins[EShLangFragment].append( 2340 "mediump vec4 gl_FragCoord;" // needs qualifier fixed later 2341 " bool gl_FrontFacing;" // needs qualifier fixed later 2342 "mediump vec4 gl_FragColor;" // needs qualifier fixed later 2343 "mediump vec2 gl_PointCoord;" // needs qualifier fixed later 2344 ); 2345 } 2346 if (version >= 300) { 2347 stageBuiltins[EShLangFragment].append( 2348 "highp vec4 gl_FragCoord;" // needs qualifier fixed later 2349 " bool gl_FrontFacing;" // needs qualifier fixed later 2350 "mediump vec2 gl_PointCoord;" // needs qualifier fixed later 2351 "highp float gl_FragDepth;" // needs qualifier fixed later 2352 ); 2353 } 2354 if (version >= 310) { 2355 stageBuiltins[EShLangFragment].append( 2356 "bool gl_HelperInvocation;" // needs qualifier fixed later 2357 "flat in highp int gl_PrimitiveID;" // needs qualifier fixed later 2358 "flat in highp int gl_Layer;" // needs qualifier fixed later 2359 ); 2360 2361 stageBuiltins[EShLangFragment].append( // GL_OES_sample_variables 2362 "flat lowp in int gl_SampleID;" 2363 " mediump in vec2 gl_SamplePosition;" 2364 "flat highp in int gl_SampleMaskIn[];" 2365 " highp out int gl_SampleMask[];" 2366 "uniform lowp int gl_NumSamples;" 2367 ); 2368 } 2369 stageBuiltins[EShLangFragment].append( 2370 "highp float gl_FragDepthEXT;" // GL_EXT_frag_depth 2371 ); 2372 } 2373 stageBuiltins[EShLangFragment].append("\n"); 2374 2375 if (version >= 130) 2376 add2ndGenerationSamplingImaging(version, profile, spvVersion); 2377 2378 // GL_ARB_shader_ballot 2379 if (profile != EEsProfile && version >= 450) { 2380 commonBuiltins.append( 2381 "uniform uint gl_SubGroupSizeARB;" 2382 2383 "in uint gl_SubGroupInvocationARB;" 2384 "in uint64_t gl_SubGroupEqMaskARB;" 2385 "in uint64_t gl_SubGroupGeMaskARB;" 2386 "in uint64_t gl_SubGroupGtMaskARB;" 2387 "in uint64_t gl_SubGroupLeMaskARB;" 2388 "in uint64_t gl_SubGroupLtMaskARB;" 2389 2390 "\n"); 2391 } 2392 2393 //printf("%s\n", commonBuiltins.c_str()); 2394 //printf("%s\n", stageBuiltins[EShLangFragment].c_str()); 2395 } 2396 2397 // 2398 // Helper function for initialize(), to add the second set of names for texturing, 2399 // when adding context-independent built-in functions. 2400 // 2401 void TBuiltIns::add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion) 2402 { 2403 // 2404 // In this function proper, enumerate the types, then calls the next set of functions 2405 // to enumerate all the uses for that type. 2406 // 2407 2408 TBasicType bTypes[3] = { EbtFloat, EbtInt, EbtUint }; 2409 bool skipBuffer = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 140); 2410 bool skipCubeArrayed = (profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 130); 2411 2412 // enumerate all the types 2413 for (int image = 0; image <= 1; ++image) { // loop over "bool" image vs sampler 2414 2415 for (int shadow = 0; shadow <= 1; ++shadow) { // loop over "bool" shadow or not 2416 for (int ms = 0; ms <=1; ++ms) { 2417 if ((ms || image) && shadow) 2418 continue; 2419 if (ms && profile != EEsProfile && version < 150) 2420 continue; 2421 if (ms && image && profile == EEsProfile) 2422 continue; 2423 if (ms && profile == EEsProfile && version < 310) 2424 continue; 2425 2426 for (int arrayed = 0; arrayed <= 1; ++arrayed) { // loop over "bool" arrayed or not 2427 for (int dim = Esd1D; dim < EsdNumDims; ++dim) { // 1D, 2D, ..., buffer 2428 if (dim == EsdSubpass && spvVersion.vulkan == 0) 2429 continue; 2430 if (dim == EsdSubpass && (image || shadow || arrayed)) 2431 continue; 2432 if ((dim == Esd1D || dim == EsdRect) && profile == EEsProfile) 2433 continue; 2434 if (dim != Esd2D && dim != EsdSubpass && ms) 2435 continue; 2436 if ((dim == Esd3D || dim == EsdRect) && arrayed) 2437 continue; 2438 if (dim == Esd3D && shadow) 2439 continue; 2440 if (dim == EsdCube && arrayed && skipCubeArrayed) 2441 continue; 2442 if (dim == EsdBuffer && skipBuffer) 2443 continue; 2444 if (dim == EsdBuffer && (shadow || arrayed || ms)) 2445 continue; 2446 if (ms && arrayed && profile == EEsProfile && version < 310) 2447 continue; 2448 2449 for (int bType = 0; bType < 3; ++bType) { // float, int, uint results 2450 2451 if (shadow && bType > 0) 2452 continue; 2453 2454 if (dim == EsdRect && version < 140 && bType > 0) 2455 continue; 2456 2457 // 2458 // Now, make all the function prototypes for the type we just built... 2459 // 2460 2461 TSampler sampler; 2462 if (dim == EsdSubpass) { 2463 sampler.setSubpass(bTypes[bType], ms ? true : false); 2464 } else if (image) { 2465 sampler.setImage(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false, 2466 shadow ? true : false, 2467 ms ? true : false); 2468 } else { 2469 sampler.set(bTypes[bType], (TSamplerDim)dim, arrayed ? true : false, 2470 shadow ? true : false, 2471 ms ? true : false); 2472 } 2473 2474 TString typeName = sampler.getString(); 2475 2476 if (dim == EsdSubpass) { 2477 addSubpassSampling(sampler, typeName, version, profile); 2478 continue; 2479 } 2480 2481 addQueryFunctions(sampler, typeName, version, profile); 2482 2483 if (image) 2484 addImageFunctions(sampler, typeName, version, profile); 2485 else { 2486 addSamplingFunctions(sampler, typeName, version, profile); 2487 addGatherFunctions(sampler, typeName, version, profile); 2488 } 2489 } 2490 } 2491 } 2492 } 2493 } 2494 } 2495 2496 // 2497 // sparseTexelsResidentARB() 2498 // 2499 2500 if (profile != EEsProfile && version >= 450) { 2501 commonBuiltins.append("bool sparseTexelsResidentARB(int code);\n"); 2502 } 2503 } 2504 2505 // 2506 // Helper function for add2ndGenerationSamplingImaging(), 2507 // when adding context-independent built-in functions. 2508 // 2509 // Add all the query functions for the given type. 2510 // 2511 void TBuiltIns::addQueryFunctions(TSampler sampler, TString& typeName, int version, EProfile profile) 2512 { 2513 if (sampler.image && ((profile == EEsProfile && version < 310) || (profile != EEsProfile && version < 430))) 2514 return; 2515 2516 // 2517 // textureSize() and imageSize() 2518 // 2519 2520 int sizeDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0) - (sampler.dim == EsdCube ? 1 : 0); 2521 if (profile == EEsProfile) 2522 commonBuiltins.append("highp "); 2523 if (sizeDims == 1) 2524 commonBuiltins.append("int"); 2525 else { 2526 commonBuiltins.append("ivec"); 2527 commonBuiltins.append(postfixes[sizeDims]); 2528 } 2529 if (sampler.image) 2530 commonBuiltins.append(" imageSize(readonly writeonly volatile coherent "); 2531 else 2532 commonBuiltins.append(" textureSize("); 2533 commonBuiltins.append(typeName); 2534 if (! sampler.image && sampler.dim != EsdRect && sampler.dim != EsdBuffer && ! sampler.ms) 2535 commonBuiltins.append(",int);\n"); 2536 else 2537 commonBuiltins.append(");\n"); 2538 2539 // 2540 // textureSamples() and imageSamples() 2541 // 2542 2543 // GL_ARB_shader_texture_image_samples 2544 // TODO: spec issue? there are no memory qualifiers; how to query a writeonly/readonly image, etc? 2545 if (profile != EEsProfile && version >= 430 && sampler.ms) { 2546 commonBuiltins.append("int "); 2547 if (sampler.image) 2548 commonBuiltins.append("imageSamples(readonly writeonly volatile coherent "); 2549 else 2550 commonBuiltins.append("textureSamples("); 2551 commonBuiltins.append(typeName); 2552 commonBuiltins.append(");\n"); 2553 } 2554 2555 // 2556 // textureQueryLod(), fragment stage only 2557 // 2558 2559 if (profile != EEsProfile && version >= 400 && ! sampler.image && sampler.dim != EsdRect && ! sampler.ms && sampler.dim != EsdBuffer) { 2560 stageBuiltins[EShLangFragment].append("vec2 textureQueryLod("); 2561 stageBuiltins[EShLangFragment].append(typeName); 2562 if (dimMap[sampler.dim] == 1) 2563 stageBuiltins[EShLangFragment].append(", float"); 2564 else { 2565 stageBuiltins[EShLangFragment].append(", vec"); 2566 stageBuiltins[EShLangFragment].append(postfixes[dimMap[sampler.dim]]); 2567 } 2568 stageBuiltins[EShLangFragment].append(");\n"); 2569 } 2570 2571 // 2572 // textureQueryLevels() 2573 // 2574 2575 if (profile != EEsProfile && version >= 430 && ! sampler.image && sampler.dim != EsdRect && ! sampler.ms && sampler.dim != EsdBuffer) { 2576 commonBuiltins.append("int textureQueryLevels("); 2577 commonBuiltins.append(typeName); 2578 commonBuiltins.append(");\n"); 2579 } 2580 } 2581 2582 // 2583 // Helper function for add2ndGenerationSamplingImaging(), 2584 // when adding context-independent built-in functions. 2585 // 2586 // Add all the image access functions for the given type. 2587 // 2588 void TBuiltIns::addImageFunctions(TSampler sampler, TString& typeName, int version, EProfile profile) 2589 { 2590 int dims = dimMap[sampler.dim]; 2591 // most things with an array add a dimension, except for cubemaps 2592 if (sampler.arrayed && sampler.dim != EsdCube) 2593 ++dims; 2594 2595 TString imageParams = typeName; 2596 if (dims == 1) 2597 imageParams.append(", int"); 2598 else { 2599 imageParams.append(", ivec"); 2600 imageParams.append(postfixes[dims]); 2601 } 2602 if (sampler.ms) 2603 imageParams.append(", int"); 2604 2605 if (profile == EEsProfile) 2606 commonBuiltins.append("highp "); 2607 commonBuiltins.append(prefixes[sampler.type]); 2608 commonBuiltins.append("vec4 imageLoad(readonly volatile coherent "); 2609 commonBuiltins.append(imageParams); 2610 commonBuiltins.append(");\n"); 2611 2612 commonBuiltins.append("void imageStore(writeonly volatile coherent "); 2613 commonBuiltins.append(imageParams); 2614 commonBuiltins.append(", "); 2615 commonBuiltins.append(prefixes[sampler.type]); 2616 commonBuiltins.append("vec4);\n"); 2617 2618 if (sampler.dim != Esd1D && sampler.dim != EsdBuffer && profile != EEsProfile && version >= 450) { 2619 commonBuiltins.append("int sparseImageLoadARB(readonly volatile coherent "); 2620 commonBuiltins.append(imageParams); 2621 commonBuiltins.append(", out "); 2622 commonBuiltins.append(prefixes[sampler.type]); 2623 commonBuiltins.append("vec4"); 2624 commonBuiltins.append(");\n"); 2625 } 2626 2627 if ( profile != EEsProfile || 2628 (profile == EEsProfile && version >= 310)) { 2629 if (sampler.type == EbtInt || sampler.type == EbtUint) { 2630 const char* dataType = sampler.type == EbtInt ? "highp int" : "highp uint"; 2631 2632 const int numBuiltins = 7; 2633 2634 static const char* atomicFunc[numBuiltins] = { 2635 " imageAtomicAdd(volatile coherent ", 2636 " imageAtomicMin(volatile coherent ", 2637 " imageAtomicMax(volatile coherent ", 2638 " imageAtomicAnd(volatile coherent ", 2639 " imageAtomicOr(volatile coherent ", 2640 " imageAtomicXor(volatile coherent ", 2641 " imageAtomicExchange(volatile coherent " 2642 }; 2643 2644 for (size_t i = 0; i < numBuiltins; ++i) { 2645 commonBuiltins.append(dataType); 2646 commonBuiltins.append(atomicFunc[i]); 2647 commonBuiltins.append(imageParams); 2648 commonBuiltins.append(", "); 2649 commonBuiltins.append(dataType); 2650 commonBuiltins.append(");\n"); 2651 } 2652 2653 commonBuiltins.append(dataType); 2654 commonBuiltins.append(" imageAtomicCompSwap(volatile coherent "); 2655 commonBuiltins.append(imageParams); 2656 commonBuiltins.append(", "); 2657 commonBuiltins.append(dataType); 2658 commonBuiltins.append(", "); 2659 commonBuiltins.append(dataType); 2660 commonBuiltins.append(");\n"); 2661 } else { 2662 // not int or uint 2663 // GL_ARB_ES3_1_compatibility 2664 // TODO: spec issue: are there restrictions on the kind of layout() that can be used? what about dropping memory qualifiers? 2665 if ((profile != EEsProfile && version >= 450) || 2666 (profile == EEsProfile && version >= 310)) { 2667 commonBuiltins.append("float imageAtomicExchange(volatile coherent "); 2668 commonBuiltins.append(imageParams); 2669 commonBuiltins.append(", float);\n"); 2670 } 2671 } 2672 } 2673 } 2674 2675 // 2676 // Helper function for initialize(), 2677 // when adding context-independent built-in functions. 2678 // 2679 // Add all the subpass access functions for the given type. 2680 // 2681 void TBuiltIns::addSubpassSampling(TSampler sampler, TString& typeName, int /*version*/, EProfile /*profile*/) 2682 { 2683 stageBuiltins[EShLangFragment].append(prefixes[sampler.type]); 2684 stageBuiltins[EShLangFragment].append("vec4 subpassLoad"); 2685 stageBuiltins[EShLangFragment].append("("); 2686 stageBuiltins[EShLangFragment].append(typeName.c_str()); 2687 if (sampler.ms) 2688 stageBuiltins[EShLangFragment].append(", int"); 2689 stageBuiltins[EShLangFragment].append(");\n"); 2690 } 2691 2692 // 2693 // Helper function for add2ndGenerationSamplingImaging(), 2694 // when adding context-independent built-in functions. 2695 // 2696 // Add all the texture lookup functions for the given type. 2697 // 2698 void TBuiltIns::addSamplingFunctions(TSampler sampler, TString& typeName, int version, EProfile profile) 2699 { 2700 // 2701 // texturing 2702 // 2703 for (int proj = 0; proj <= 1; ++proj) { // loop over "bool" projective or not 2704 2705 if (proj && (sampler.dim == EsdCube || sampler.dim == EsdBuffer || sampler.arrayed || sampler.ms)) 2706 continue; 2707 2708 for (int lod = 0; lod <= 1; ++lod) { 2709 2710 if (lod && (sampler.dim == EsdBuffer || sampler.dim == EsdRect || sampler.ms)) 2711 continue; 2712 if (lod && sampler.dim == Esd2D && sampler.arrayed && sampler.shadow) 2713 continue; 2714 if (lod && sampler.dim == EsdCube && sampler.shadow) 2715 continue; 2716 2717 for (int bias = 0; bias <= 1; ++bias) { 2718 2719 if (bias && (lod || sampler.ms)) 2720 continue; 2721 if (bias && sampler.dim == Esd2D && sampler.shadow && sampler.arrayed) 2722 continue; 2723 if (bias && (sampler.dim == EsdRect || sampler.dim == EsdBuffer)) 2724 continue; 2725 2726 for (int offset = 0; offset <= 1; ++offset) { // loop over "bool" offset or not 2727 2728 if (proj + offset + bias + lod > 3) 2729 continue; 2730 if (offset && (sampler.dim == EsdCube || sampler.dim == EsdBuffer || sampler.ms)) 2731 continue; 2732 2733 for (int fetch = 0; fetch <= 1; ++fetch) { // loop over "bool" fetch or not 2734 2735 if (proj + offset + fetch + bias + lod > 3) 2736 continue; 2737 if (fetch && (lod || bias)) 2738 continue; 2739 if (fetch && (sampler.shadow || sampler.dim == EsdCube)) 2740 continue; 2741 if (fetch == 0 && (sampler.ms || sampler.dim == EsdBuffer)) 2742 continue; 2743 2744 for (int grad = 0; grad <= 1; ++grad) { // loop over "bool" grad or not 2745 2746 if (grad && (lod || bias || sampler.ms)) 2747 continue; 2748 if (grad && sampler.dim == EsdBuffer) 2749 continue; 2750 if (proj + offset + fetch + grad + bias + lod > 3) 2751 continue; 2752 2753 for (int extraProj = 0; extraProj <= 1; ++extraProj) { 2754 bool compare = false; 2755 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0); 2756 // skip dummy unused second component for 1D non-array shadows 2757 if (sampler.shadow && totalDims < 2) 2758 totalDims = 2; 2759 totalDims += (sampler.shadow ? 1 : 0) + proj; 2760 if (totalDims > 4 && sampler.shadow) { 2761 compare = true; 2762 totalDims = 4; 2763 } 2764 assert(totalDims <= 4); 2765 2766 if (extraProj && ! proj) 2767 continue; 2768 if (extraProj && (sampler.dim == Esd3D || sampler.shadow)) 2769 continue; 2770 2771 for (int lodClamp = 0; lodClamp <= 1 ;++lodClamp) { // loop over "bool" lod clamp 2772 2773 if (lodClamp && (profile == EEsProfile || version < 450)) 2774 continue; 2775 if (lodClamp && (proj || lod || fetch)) 2776 continue; 2777 2778 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not 2779 2780 if (sparse && (profile == EEsProfile || version < 450)) 2781 continue; 2782 // Sparse sampling is not for 1D/1D array texture, buffer texture, and projective texture 2783 if (sparse && (sampler.dim == Esd1D || sampler.dim == EsdBuffer || proj)) 2784 continue; 2785 2786 TString s; 2787 2788 // return type 2789 if (sparse) 2790 s.append("int "); 2791 else { 2792 if (sampler.shadow) 2793 s.append("float "); 2794 else { 2795 s.append(prefixes[sampler.type]); 2796 s.append("vec4 "); 2797 } 2798 } 2799 2800 // name 2801 if (sparse) { 2802 if (fetch) 2803 s.append("sparseTexel"); 2804 else 2805 s.append("sparseTexture"); 2806 } else { 2807 if (fetch) 2808 s.append("texel"); 2809 else 2810 s.append("texture"); 2811 } 2812 if (proj) 2813 s.append("Proj"); 2814 if (lod) 2815 s.append("Lod"); 2816 if (grad) 2817 s.append("Grad"); 2818 if (fetch) 2819 s.append("Fetch"); 2820 if (offset) 2821 s.append("Offset"); 2822 if (lodClamp) 2823 s.append("Clamp"); 2824 if (lodClamp || sparse) 2825 s.append("ARB"); 2826 s.append("("); 2827 2828 // sampler type 2829 s.append(typeName); 2830 2831 // P coordinate 2832 if (extraProj) 2833 s.append(",vec4"); 2834 else { 2835 s.append(","); 2836 TBasicType t = fetch ? EbtInt : EbtFloat; 2837 if (totalDims == 1) 2838 s.append(TType::getBasicString(t)); 2839 else { 2840 s.append(prefixes[t]); 2841 s.append("vec"); 2842 s.append(postfixes[totalDims]); 2843 } 2844 } 2845 2846 if (bias && compare) 2847 continue; 2848 2849 // non-optional lod argument (lod that's not driven by lod loop) or sample 2850 if ((fetch && sampler.dim != EsdBuffer && sampler.dim != EsdRect && !sampler.ms) || 2851 (sampler.ms && fetch)) 2852 s.append(",int"); 2853 2854 // non-optional lod 2855 if (lod) 2856 s.append(",float"); 2857 2858 // gradient arguments 2859 if (grad) { 2860 if (dimMap[sampler.dim] == 1) 2861 s.append(",float,float"); 2862 else { 2863 s.append(",vec"); 2864 s.append(postfixes[dimMap[sampler.dim]]); 2865 s.append(",vec"); 2866 s.append(postfixes[dimMap[sampler.dim]]); 2867 } 2868 } 2869 2870 // offset 2871 if (offset) { 2872 if (dimMap[sampler.dim] == 1) 2873 s.append(",int"); 2874 else { 2875 s.append(",ivec"); 2876 s.append(postfixes[dimMap[sampler.dim]]); 2877 } 2878 } 2879 2880 // non-optional compare 2881 if (compare) 2882 s.append(",float"); 2883 2884 // lod clamp 2885 if (lodClamp) 2886 s.append(",float"); 2887 2888 // texel out (for sparse texture) 2889 if (sparse) { 2890 s.append(",out "); 2891 if (sampler.shadow) 2892 s.append("float "); 2893 else { 2894 s.append(prefixes[sampler.type]); 2895 s.append("vec4 "); 2896 } 2897 } 2898 2899 // optional bias 2900 if (bias) 2901 s.append(",float"); 2902 2903 s.append(");\n"); 2904 2905 // Add to the per-language set of built-ins 2906 2907 if (bias) 2908 stageBuiltins[EShLangFragment].append(s); 2909 else 2910 commonBuiltins.append(s); 2911 } 2912 } 2913 } 2914 } 2915 } 2916 } 2917 } 2918 } 2919 } 2920 } 2921 2922 2923 // 2924 // Helper function for add2ndGenerationSamplingImaging(), 2925 // when adding context-independent built-in functions. 2926 // 2927 // Add all the texture gather functions for the given type. 2928 // 2929 void TBuiltIns::addGatherFunctions(TSampler sampler, TString& typeName, int version, EProfile profile) 2930 { 2931 switch (sampler.dim) { 2932 case Esd2D: 2933 case EsdRect: 2934 case EsdCube: 2935 break; 2936 default: 2937 return; 2938 } 2939 2940 if (sampler.ms) 2941 return; 2942 2943 if (version < 140 && sampler.dim == EsdRect && sampler.type != EbtFloat) 2944 return; 2945 2946 for (int offset = 0; offset < 3; ++offset) { // loop over three forms of offset in the call name: none, Offset, and Offsets 2947 2948 for (int comp = 0; comp < 2; ++comp) { // loop over presence of comp argument 2949 2950 if (comp > 0 && sampler.shadow) 2951 continue; 2952 2953 if (offset > 0 && sampler.dim == EsdCube) 2954 continue; 2955 2956 for (int sparse = 0; sparse <= 1; ++sparse) { // loop over "bool" sparse or not 2957 if (sparse && (profile == EEsProfile || version < 450)) 2958 continue; 2959 2960 TString s; 2961 2962 // return type 2963 if (sparse) 2964 s.append("int "); 2965 else { 2966 s.append(prefixes[sampler.type]); 2967 s.append("vec4 "); 2968 } 2969 2970 // name 2971 if (sparse) 2972 s.append("sparseTextureGather"); 2973 else 2974 s.append("textureGather"); 2975 switch (offset) { 2976 case 1: 2977 s.append("Offset"); 2978 break; 2979 case 2: 2980 s.append("Offsets"); 2981 default: 2982 break; 2983 } 2984 if (sparse) 2985 s.append("ARB"); 2986 s.append("("); 2987 2988 // sampler type argument 2989 s.append(typeName); 2990 2991 // P coordinate argument 2992 s.append(",vec"); 2993 int totalDims = dimMap[sampler.dim] + (sampler.arrayed ? 1 : 0); 2994 s.append(postfixes[totalDims]); 2995 2996 // refZ argument 2997 if (sampler.shadow) 2998 s.append(",float"); 2999 3000 // offset argument 3001 if (offset > 0) { 3002 s.append(",ivec2"); 3003 if (offset == 2) 3004 s.append("[4]"); 3005 } 3006 3007 // texel out (for sparse texture) 3008 if (sparse) { 3009 s.append(",out "); 3010 s.append(prefixes[sampler.type]); 3011 s.append("vec4 "); 3012 } 3013 3014 // comp argument 3015 if (comp) 3016 s.append(",int"); 3017 3018 s.append(");\n"); 3019 commonBuiltins.append(s); 3020 } 3021 } 3022 } 3023 } 3024 3025 // 3026 // Add context-dependent built-in functions and variables that are present 3027 // for the given version and profile. All the results are put into just the 3028 // commonBuiltins, because it is called for just a specific stage. So, 3029 // add stage-specific entries to the commonBuiltins, and only if that stage 3030 // was requested. 3031 // 3032 void TBuiltIns::initialize(const TBuiltInResource &resources, int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language) 3033 { 3034 // 3035 // Initialize the context-dependent (resource-dependent) built-in strings for parsing. 3036 // 3037 3038 //============================================================================ 3039 // 3040 // Standard Uniforms 3041 // 3042 //============================================================================ 3043 3044 TString& s = commonBuiltins; 3045 const int maxSize = 80; 3046 char builtInConstant[maxSize]; 3047 3048 // 3049 // Build string of implementation dependent constants. 3050 // 3051 3052 if (profile == EEsProfile) { 3053 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs); 3054 s.append(builtInConstant); 3055 3056 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexUniformVectors = %d;", resources.maxVertexUniformVectors); 3057 s.append(builtInConstant); 3058 3059 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits); 3060 s.append(builtInConstant); 3061 3062 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits); 3063 s.append(builtInConstant); 3064 3065 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits); 3066 s.append(builtInConstant); 3067 3068 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxFragmentUniformVectors = %d;", resources.maxFragmentUniformVectors); 3069 s.append(builtInConstant); 3070 3071 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers); 3072 s.append(builtInConstant); 3073 3074 if (version == 100) { 3075 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVaryingVectors = %d;", resources.maxVaryingVectors); 3076 s.append(builtInConstant); 3077 } else { 3078 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxVertexOutputVectors = %d;", resources.maxVertexOutputVectors); 3079 s.append(builtInConstant); 3080 3081 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxFragmentInputVectors = %d;", resources.maxFragmentInputVectors); 3082 s.append(builtInConstant); 3083 3084 snprintf(builtInConstant, maxSize, "const mediump int gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset); 3085 s.append(builtInConstant); 3086 3087 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset); 3088 s.append(builtInConstant); 3089 } 3090 3091 if (version >= 310) { 3092 // geometry 3093 3094 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents); 3095 s.append(builtInConstant); 3096 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents); 3097 s.append(builtInConstant); 3098 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms); 3099 s.append(builtInConstant); 3100 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits); 3101 s.append(builtInConstant); 3102 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices); 3103 s.append(builtInConstant); 3104 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents); 3105 s.append(builtInConstant); 3106 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents); 3107 s.append(builtInConstant); 3108 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources.maxGeometryAtomicCounters); 3109 s.append(builtInConstant); 3110 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources.maxGeometryAtomicCounterBuffers); 3111 s.append(builtInConstant); 3112 3113 // tessellation 3114 3115 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents); 3116 s.append(builtInConstant); 3117 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents); 3118 s.append(builtInConstant); 3119 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits); 3120 s.append(builtInConstant); 3121 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents); 3122 s.append(builtInConstant); 3123 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents); 3124 s.append(builtInConstant); 3125 3126 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents); 3127 s.append(builtInConstant); 3128 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents); 3129 s.append(builtInConstant); 3130 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits); 3131 s.append(builtInConstant); 3132 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents); 3133 s.append(builtInConstant); 3134 3135 snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents); 3136 s.append(builtInConstant); 3137 3138 snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices); 3139 s.append(builtInConstant); 3140 snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel); 3141 s.append(builtInConstant); 3142 3143 // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices 3144 if (language == EShLangTessControl || language == EShLangTessEvaluation) { 3145 s.append( 3146 "in gl_PerVertex {" 3147 "highp vec4 gl_Position;" 3148 "highp float gl_PointSize;" 3149 "} gl_in[gl_MaxPatchVertices];" 3150 "\n"); 3151 } 3152 } 3153 3154 } else { 3155 // non-ES profile 3156 3157 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAttribs = %d;", resources.maxVertexAttribs); 3158 s.append(builtInConstant); 3159 3160 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexTextureImageUnits = %d;", resources.maxVertexTextureImageUnits); 3161 s.append(builtInConstant); 3162 3163 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedTextureImageUnits = %d;", resources.maxCombinedTextureImageUnits); 3164 s.append(builtInConstant); 3165 3166 snprintf(builtInConstant, maxSize, "const int gl_MaxTextureImageUnits = %d;", resources.maxTextureImageUnits); 3167 s.append(builtInConstant); 3168 3169 snprintf(builtInConstant, maxSize, "const int gl_MaxDrawBuffers = %d;", resources.maxDrawBuffers); 3170 s.append(builtInConstant); 3171 3172 snprintf(builtInConstant, maxSize, "const int gl_MaxLights = %d;", resources.maxLights); 3173 s.append(builtInConstant); 3174 3175 snprintf(builtInConstant, maxSize, "const int gl_MaxClipPlanes = %d;", resources.maxClipPlanes); 3176 s.append(builtInConstant); 3177 3178 snprintf(builtInConstant, maxSize, "const int gl_MaxTextureUnits = %d;", resources.maxTextureUnits); 3179 s.append(builtInConstant); 3180 3181 snprintf(builtInConstant, maxSize, "const int gl_MaxTextureCoords = %d;", resources.maxTextureCoords); 3182 s.append(builtInConstant); 3183 3184 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexUniformComponents = %d;", resources.maxVertexUniformComponents); 3185 s.append(builtInConstant); 3186 3187 if (version < 150 || ARBCompatibility) { 3188 snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingFloats = %d;", resources.maxVaryingFloats); 3189 s.append(builtInConstant); 3190 } 3191 3192 snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentUniformComponents = %d;", resources.maxFragmentUniformComponents); 3193 s.append(builtInConstant); 3194 3195 if (spvVersion.spv == 0 && IncludeLegacy(version, profile, spvVersion)) { 3196 // 3197 // OpenGL'uniform' state. Page numbers are in reference to version 3198 // 1.4 of the OpenGL specification. 3199 // 3200 3201 // 3202 // Matrix state. p. 31, 32, 37, 39, 40. 3203 // 3204 s.append("uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords];" 3205 3206 // 3207 // Derived matrix state that provides inverse and transposed versions 3208 // of the matrices above. 3209 // 3210 "uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords];" 3211 3212 "uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords];" 3213 3214 "uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords];" 3215 3216 // 3217 // Clip planes p. 42. 3218 // 3219 "uniform vec4 gl_ClipPlane[gl_MaxClipPlanes];" 3220 3221 // 3222 // Light State p 50, 53, 55. 3223 // 3224 "uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];" 3225 3226 // 3227 // Derived state from products of light. 3228 // 3229 "uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];" 3230 "uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];" 3231 3232 // 3233 // Texture Environment and Generation, p. 152, p. 40-42. 3234 // 3235 "uniform vec4 gl_TextureEnvColor[gl_MaxTextureImageUnits];" 3236 "uniform vec4 gl_EyePlaneS[gl_MaxTextureCoords];" 3237 "uniform vec4 gl_EyePlaneT[gl_MaxTextureCoords];" 3238 "uniform vec4 gl_EyePlaneR[gl_MaxTextureCoords];" 3239 "uniform vec4 gl_EyePlaneQ[gl_MaxTextureCoords];" 3240 "uniform vec4 gl_ObjectPlaneS[gl_MaxTextureCoords];" 3241 "uniform vec4 gl_ObjectPlaneT[gl_MaxTextureCoords];" 3242 "uniform vec4 gl_ObjectPlaneR[gl_MaxTextureCoords];" 3243 "uniform vec4 gl_ObjectPlaneQ[gl_MaxTextureCoords];"); 3244 } 3245 3246 if (version >= 130) { 3247 snprintf(builtInConstant, maxSize, "const int gl_MaxClipDistances = %d;", resources.maxClipDistances); 3248 s.append(builtInConstant); 3249 snprintf(builtInConstant, maxSize, "const int gl_MaxVaryingComponents = %d;", resources.maxVaryingComponents); 3250 s.append(builtInConstant); 3251 3252 // GL_ARB_shading_language_420pack 3253 snprintf(builtInConstant, maxSize, "const mediump int gl_MinProgramTexelOffset = %d;", resources.minProgramTexelOffset); 3254 s.append(builtInConstant); 3255 snprintf(builtInConstant, maxSize, "const mediump int gl_MaxProgramTexelOffset = %d;", resources.maxProgramTexelOffset); 3256 s.append(builtInConstant); 3257 } 3258 3259 // geometry 3260 if (version >= 150) { 3261 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryInputComponents = %d;", resources.maxGeometryInputComponents); 3262 s.append(builtInConstant); 3263 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputComponents = %d;", resources.maxGeometryOutputComponents); 3264 s.append(builtInConstant); 3265 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTextureImageUnits = %d;", resources.maxGeometryTextureImageUnits); 3266 s.append(builtInConstant); 3267 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryOutputVertices = %d;", resources.maxGeometryOutputVertices); 3268 s.append(builtInConstant); 3269 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryTotalOutputComponents = %d;", resources.maxGeometryTotalOutputComponents); 3270 s.append(builtInConstant); 3271 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryUniformComponents = %d;", resources.maxGeometryUniformComponents); 3272 s.append(builtInConstant); 3273 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryVaryingComponents = %d;", resources.maxGeometryVaryingComponents); 3274 s.append(builtInConstant); 3275 3276 } 3277 3278 if (version >= 150) { 3279 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexOutputComponents = %d;", resources.maxVertexOutputComponents); 3280 s.append(builtInConstant); 3281 snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentInputComponents = %d;", resources.maxFragmentInputComponents); 3282 s.append(builtInConstant); 3283 } 3284 3285 // tessellation 3286 if (version >= 150) { 3287 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlInputComponents = %d;", resources.maxTessControlInputComponents); 3288 s.append(builtInConstant); 3289 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlOutputComponents = %d;", resources.maxTessControlOutputComponents); 3290 s.append(builtInConstant); 3291 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTextureImageUnits = %d;", resources.maxTessControlTextureImageUnits); 3292 s.append(builtInConstant); 3293 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlUniformComponents = %d;", resources.maxTessControlUniformComponents); 3294 s.append(builtInConstant); 3295 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlTotalOutputComponents = %d;", resources.maxTessControlTotalOutputComponents); 3296 s.append(builtInConstant); 3297 3298 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationInputComponents = %d;", resources.maxTessEvaluationInputComponents); 3299 s.append(builtInConstant); 3300 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationOutputComponents = %d;", resources.maxTessEvaluationOutputComponents); 3301 s.append(builtInConstant); 3302 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationTextureImageUnits = %d;", resources.maxTessEvaluationTextureImageUnits); 3303 s.append(builtInConstant); 3304 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationUniformComponents = %d;", resources.maxTessEvaluationUniformComponents); 3305 s.append(builtInConstant); 3306 3307 snprintf(builtInConstant, maxSize, "const int gl_MaxTessPatchComponents = %d;", resources.maxTessPatchComponents); 3308 s.append(builtInConstant); 3309 snprintf(builtInConstant, maxSize, "const int gl_MaxTessGenLevel = %d;", resources.maxTessGenLevel); 3310 s.append(builtInConstant); 3311 snprintf(builtInConstant, maxSize, "const int gl_MaxPatchVertices = %d;", resources.maxPatchVertices); 3312 s.append(builtInConstant); 3313 3314 // this is here instead of with the others in initialize(version, profile) due to the dependence on gl_MaxPatchVertices 3315 if (language == EShLangTessControl || language == EShLangTessEvaluation) { 3316 s.append( 3317 "in gl_PerVertex {" 3318 "vec4 gl_Position;" 3319 "float gl_PointSize;" 3320 "float gl_ClipDistance[];" 3321 ); 3322 if (profile == ECompatibilityProfile) 3323 s.append( 3324 "vec4 gl_ClipVertex;" 3325 "vec4 gl_FrontColor;" 3326 "vec4 gl_BackColor;" 3327 "vec4 gl_FrontSecondaryColor;" 3328 "vec4 gl_BackSecondaryColor;" 3329 "vec4 gl_TexCoord[];" 3330 "float gl_FogFragCoord;" 3331 ); 3332 if (profile != EEsProfile && version >= 450) 3333 s.append( 3334 "float gl_CullDistance[];" 3335 ); 3336 s.append( 3337 "} gl_in[gl_MaxPatchVertices];" 3338 "\n"); 3339 } 3340 } 3341 3342 if (version >= 150) { 3343 snprintf(builtInConstant, maxSize, "const int gl_MaxViewports = %d;", resources.maxViewports); 3344 s.append(builtInConstant); 3345 } 3346 3347 // images 3348 if (version >= 130) { 3349 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUnitsAndFragmentOutputs = %d;", resources.maxCombinedImageUnitsAndFragmentOutputs); 3350 s.append(builtInConstant); 3351 snprintf(builtInConstant, maxSize, "const int gl_MaxImageSamples = %d;", resources.maxImageSamples); 3352 s.append(builtInConstant); 3353 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlImageUniforms = %d;", resources.maxTessControlImageUniforms); 3354 s.append(builtInConstant); 3355 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationImageUniforms = %d;", resources.maxTessEvaluationImageUniforms); 3356 s.append(builtInConstant); 3357 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryImageUniforms = %d;", resources.maxGeometryImageUniforms); 3358 s.append(builtInConstant); 3359 } 3360 3361 // enhanced layouts 3362 if (version >= 430) { 3363 snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackBuffers = %d;", resources.maxTransformFeedbackBuffers); 3364 s.append(builtInConstant); 3365 snprintf(builtInConstant, maxSize, "const int gl_MaxTransformFeedbackInterleavedComponents = %d;", resources.maxTransformFeedbackInterleavedComponents); 3366 s.append(builtInConstant); 3367 } 3368 } 3369 3370 // images (some in compute below) 3371 if ((profile == EEsProfile && version >= 310) || 3372 (profile != EEsProfile && version >= 130)) { 3373 snprintf(builtInConstant, maxSize, "const int gl_MaxImageUnits = %d;", resources.maxImageUnits); 3374 s.append(builtInConstant); 3375 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedShaderOutputResources = %d;", resources.maxCombinedShaderOutputResources); 3376 s.append(builtInConstant); 3377 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexImageUniforms = %d;", resources.maxVertexImageUniforms); 3378 s.append(builtInConstant); 3379 snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentImageUniforms = %d;", resources.maxFragmentImageUniforms); 3380 s.append(builtInConstant); 3381 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedImageUniforms = %d;", resources.maxCombinedImageUniforms); 3382 s.append(builtInConstant); 3383 } 3384 3385 // atomic counters (some in compute below) 3386 if ((profile == EEsProfile && version >= 310) || 3387 (profile != EEsProfile && version >= 420)) { 3388 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounters = %d;", resources. maxVertexAtomicCounters); 3389 s.append(builtInConstant); 3390 snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounters = %d;", resources. maxFragmentAtomicCounters); 3391 s.append(builtInConstant); 3392 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounters = %d;", resources. maxCombinedAtomicCounters); 3393 s.append(builtInConstant); 3394 snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBindings = %d;", resources. maxAtomicCounterBindings); 3395 s.append(builtInConstant); 3396 snprintf(builtInConstant, maxSize, "const int gl_MaxVertexAtomicCounterBuffers = %d;", resources. maxVertexAtomicCounterBuffers); 3397 s.append(builtInConstant); 3398 snprintf(builtInConstant, maxSize, "const int gl_MaxFragmentAtomicCounterBuffers = %d;", resources. maxFragmentAtomicCounterBuffers); 3399 s.append(builtInConstant); 3400 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedAtomicCounterBuffers = %d;", resources. maxCombinedAtomicCounterBuffers); 3401 s.append(builtInConstant); 3402 snprintf(builtInConstant, maxSize, "const int gl_MaxAtomicCounterBufferSize = %d;", resources. maxAtomicCounterBufferSize); 3403 s.append(builtInConstant); 3404 } 3405 if (profile != EEsProfile && version >= 420) { 3406 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounters = %d;", resources. maxTessControlAtomicCounters); 3407 s.append(builtInConstant); 3408 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounters = %d;", resources. maxTessEvaluationAtomicCounters); 3409 s.append(builtInConstant); 3410 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounters = %d;", resources. maxGeometryAtomicCounters); 3411 s.append(builtInConstant); 3412 snprintf(builtInConstant, maxSize, "const int gl_MaxTessControlAtomicCounterBuffers = %d;", resources. maxTessControlAtomicCounterBuffers); 3413 s.append(builtInConstant); 3414 snprintf(builtInConstant, maxSize, "const int gl_MaxTessEvaluationAtomicCounterBuffers = %d;", resources. maxTessEvaluationAtomicCounterBuffers); 3415 s.append(builtInConstant); 3416 snprintf(builtInConstant, maxSize, "const int gl_MaxGeometryAtomicCounterBuffers = %d;", resources. maxGeometryAtomicCounterBuffers); 3417 s.append(builtInConstant); 3418 3419 s.append("\n"); 3420 } 3421 3422 3423 // compute 3424 if ((profile == EEsProfile && version >= 310) || (profile != EEsProfile && version >= 420)) { 3425 snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupCount = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupCountX, 3426 resources.maxComputeWorkGroupCountY, 3427 resources.maxComputeWorkGroupCountZ); 3428 s.append(builtInConstant); 3429 snprintf(builtInConstant, maxSize, "const ivec3 gl_MaxComputeWorkGroupSize = ivec3(%d,%d,%d);", resources.maxComputeWorkGroupSizeX, 3430 resources.maxComputeWorkGroupSizeY, 3431 resources.maxComputeWorkGroupSizeZ); 3432 s.append(builtInConstant); 3433 3434 snprintf(builtInConstant, maxSize, "const int gl_MaxComputeUniformComponents = %d;", resources.maxComputeUniformComponents); 3435 s.append(builtInConstant); 3436 snprintf(builtInConstant, maxSize, "const int gl_MaxComputeTextureImageUnits = %d;", resources.maxComputeTextureImageUnits); 3437 s.append(builtInConstant); 3438 snprintf(builtInConstant, maxSize, "const int gl_MaxComputeImageUniforms = %d;", resources.maxComputeImageUniforms); 3439 s.append(builtInConstant); 3440 snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounters = %d;", resources.maxComputeAtomicCounters); 3441 s.append(builtInConstant); 3442 snprintf(builtInConstant, maxSize, "const int gl_MaxComputeAtomicCounterBuffers = %d;", resources.maxComputeAtomicCounterBuffers); 3443 s.append(builtInConstant); 3444 3445 s.append("\n"); 3446 } 3447 3448 // GL_ARB_cull_distance 3449 if (profile != EEsProfile && version >= 450) { 3450 snprintf(builtInConstant, maxSize, "const int gl_MaxCullDistances = %d;", resources.maxCullDistances); 3451 s.append(builtInConstant); 3452 snprintf(builtInConstant, maxSize, "const int gl_MaxCombinedClipAndCullDistances = %d;", resources.maxCombinedClipAndCullDistances); 3453 s.append(builtInConstant); 3454 } 3455 3456 // GL_ARB_ES3_1_compatibility 3457 if ((profile != EEsProfile && version >= 450) || 3458 (profile == EEsProfile && version >= 310)) { 3459 snprintf(builtInConstant, maxSize, "const int gl_MaxSamples = %d;", resources.maxSamples); 3460 s.append(builtInConstant); 3461 } 3462 3463 s.append("\n"); 3464 } 3465 3466 // 3467 // To support special built-ins that have a special qualifier that cannot be declared textually 3468 // in a shader, like gl_Position. 3469 // 3470 // This lets the type of the built-in be declared textually, and then have just its qualifier be 3471 // updated afterward. 3472 // 3473 // Safe to call even if name is not present. 3474 // 3475 // Only use this for built-in variables that have a special qualifier in TStorageQualifier. 3476 // New built-in variables should use a generic (textually declarable) qualifier in 3477 // TStoraregQualifier and only call BuiltInVariable(). 3478 // 3479 static void SpecialQualifier(const char* name, TStorageQualifier qualifier, TBuiltInVariable builtIn, TSymbolTable& symbolTable) 3480 { 3481 TSymbol* symbol = symbolTable.find(name); 3482 if (symbol) { 3483 TQualifier& symQualifier = symbol->getWritableType().getQualifier(); 3484 symQualifier.storage = qualifier; 3485 symQualifier.builtIn = builtIn; 3486 } 3487 } 3488 3489 // 3490 // To tag built-in variables with their TBuiltInVariable enum. Use this when the 3491 // normal declaration text already gets the qualifier right, and all that's needed 3492 // is setting the builtIn field. This should be the normal way for all new 3493 // built-in variables. 3494 // 3495 // If SpecialQualifier() was called, this does not need to be called. 3496 // 3497 // Safe to call even if name is not present. 3498 // 3499 static void BuiltInVariable(const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable) 3500 { 3501 TSymbol* symbol = symbolTable.find(name); 3502 if (! symbol) 3503 return; 3504 3505 TQualifier& symQualifier = symbol->getWritableType().getQualifier(); 3506 symQualifier.builtIn = builtIn; 3507 } 3508 3509 // 3510 // For built-in variables inside a named block. 3511 // SpecialQualifier() won't ever go inside a block; their member's qualifier come 3512 // from the qualification of the block. 3513 // 3514 // See comments above for other detail. 3515 // 3516 static void BuiltInVariable(const char* blockName, const char* name, TBuiltInVariable builtIn, TSymbolTable& symbolTable) 3517 { 3518 TSymbol* symbol = symbolTable.find(blockName); 3519 if (! symbol) 3520 return; 3521 3522 TTypeList& structure = *symbol->getWritableType().getWritableStruct(); 3523 for (int i = 0; i < (int)structure.size(); ++i) { 3524 if (structure[i].type->getFieldName().compare(name) == 0) { 3525 structure[i].type->getQualifier().builtIn = builtIn; 3526 return; 3527 } 3528 } 3529 } 3530 3531 // 3532 // Finish adding/processing context-independent built-in symbols. 3533 // 1) Programmatically add symbols that could not be added by simple text strings above. 3534 // 2) Map built-in functions to operators, for those that will turn into an operation node 3535 // instead of remaining a function call. 3536 // 3) Tag extension-related symbols added to their base version with their extensions, so 3537 // that if an early version has the extension turned off, there is an error reported on use. 3538 // 3539 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable) 3540 { 3541 // 3542 // Tag built-in variables and functions with additional qualifier and extension information 3543 // that cannot be declared with the text strings. 3544 // 3545 3546 // N.B.: a symbol should only be tagged once, and this function is called multiple times, once 3547 // per stage that's used for this profile. So 3548 // - generally, stick common ones in the fragment stage to ensure they are tagged exactly once 3549 // - for ES, which has different precisions for different stages, the coarsest-grained tagging 3550 // for a built-in used in many stages needs to be once for the fragment stage and once for 3551 // the vertex stage 3552 3553 switch(language) { 3554 case EShLangVertex: 3555 if (profile != EEsProfile) { 3556 symbolTable.setVariableExtensions("gl_BaseVertexARB", 1, &E_GL_ARB_shader_draw_parameters); 3557 symbolTable.setVariableExtensions("gl_BaseInstanceARB", 1, &E_GL_ARB_shader_draw_parameters); 3558 symbolTable.setVariableExtensions("gl_DrawIDARB", 1, &E_GL_ARB_shader_draw_parameters); 3559 3560 BuiltInVariable("gl_BaseVertexARB", EbvBaseVertex, symbolTable); 3561 BuiltInVariable("gl_BaseInstanceARB", EbvBaseInstance, symbolTable); 3562 BuiltInVariable("gl_DrawIDARB", EbvDrawId, symbolTable); 3563 } 3564 3565 if (profile != EEsProfile) { 3566 symbolTable.setVariableExtensions("gl_SubGroupSizeARB", 1, &E_GL_ARB_shader_ballot); 3567 symbolTable.setVariableExtensions("gl_SubGroupInvocationARB", 1, &E_GL_ARB_shader_ballot); 3568 symbolTable.setVariableExtensions("gl_SubGroupEqMaskARB", 1, &E_GL_ARB_shader_ballot); 3569 symbolTable.setVariableExtensions("gl_SubGroupGeMaskARB", 1, &E_GL_ARB_shader_ballot); 3570 symbolTable.setVariableExtensions("gl_SubGroupGtMaskARB", 1, &E_GL_ARB_shader_ballot); 3571 symbolTable.setVariableExtensions("gl_SubGroupLeMaskARB", 1, &E_GL_ARB_shader_ballot); 3572 symbolTable.setVariableExtensions("gl_SubGroupLtMaskARB", 1, &E_GL_ARB_shader_ballot); 3573 3574 symbolTable.setFunctionExtensions("ballotARB", 1, &E_GL_ARB_shader_ballot); 3575 symbolTable.setFunctionExtensions("readInvocationARB", 1, &E_GL_ARB_shader_ballot); 3576 symbolTable.setFunctionExtensions("readFirstInvocationARB", 1, &E_GL_ARB_shader_ballot); 3577 3578 BuiltInVariable("gl_SubGroupSizeARB", EbvSubGroupSize, symbolTable); 3579 BuiltInVariable("gl_SubGroupInvocationARB", EbvSubGroupInvocation, symbolTable); 3580 BuiltInVariable("gl_SubGroupEqMaskARB", EbvSubGroupEqMask, symbolTable); 3581 BuiltInVariable("gl_SubGroupGeMaskARB", EbvSubGroupGeMask, symbolTable); 3582 BuiltInVariable("gl_SubGroupGtMaskARB", EbvSubGroupGtMask, symbolTable); 3583 BuiltInVariable("gl_SubGroupLeMaskARB", EbvSubGroupLeMask, symbolTable); 3584 BuiltInVariable("gl_SubGroupLtMaskARB", EbvSubGroupLtMask, symbolTable); 3585 3586 symbolTable.setFunctionExtensions("anyInvocationARB", 1, &E_GL_ARB_shader_group_vote); 3587 symbolTable.setFunctionExtensions("allInvocationsARB", 1, &E_GL_ARB_shader_group_vote); 3588 symbolTable.setFunctionExtensions("allInvocationsEqualARB", 1, &E_GL_ARB_shader_group_vote); 3589 } 3590 3591 // Compatibility variables, vertex only 3592 if (spvVersion.spv == 0) { 3593 BuiltInVariable("gl_Color", EbvColor, symbolTable); 3594 BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable); 3595 BuiltInVariable("gl_Normal", EbvNormal, symbolTable); 3596 BuiltInVariable("gl_Vertex", EbvVertex, symbolTable); 3597 BuiltInVariable("gl_MultiTexCoord0", EbvMultiTexCoord0, symbolTable); 3598 BuiltInVariable("gl_MultiTexCoord1", EbvMultiTexCoord1, symbolTable); 3599 BuiltInVariable("gl_MultiTexCoord2", EbvMultiTexCoord2, symbolTable); 3600 BuiltInVariable("gl_MultiTexCoord3", EbvMultiTexCoord3, symbolTable); 3601 BuiltInVariable("gl_MultiTexCoord4", EbvMultiTexCoord4, symbolTable); 3602 BuiltInVariable("gl_MultiTexCoord5", EbvMultiTexCoord5, symbolTable); 3603 BuiltInVariable("gl_MultiTexCoord6", EbvMultiTexCoord6, symbolTable); 3604 BuiltInVariable("gl_MultiTexCoord7", EbvMultiTexCoord7, symbolTable); 3605 BuiltInVariable("gl_FogCoord", EbvFogFragCoord, symbolTable); 3606 } 3607 3608 if (profile == EEsProfile) { 3609 if (spvVersion.spv == 0) { 3610 symbolTable.setFunctionExtensions("texture2DGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3611 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3612 symbolTable.setFunctionExtensions("textureCubeGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3613 symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5); 3614 } 3615 if (version >= 310) 3616 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5); 3617 } 3618 3619 if (profile == EEsProfile) { 3620 symbolTable.setFunctionExtensions("imageAtomicAdd", 1, &E_GL_OES_shader_image_atomic); 3621 symbolTable.setFunctionExtensions("imageAtomicMin", 1, &E_GL_OES_shader_image_atomic); 3622 symbolTable.setFunctionExtensions("imageAtomicMax", 1, &E_GL_OES_shader_image_atomic); 3623 symbolTable.setFunctionExtensions("imageAtomicAnd", 1, &E_GL_OES_shader_image_atomic); 3624 symbolTable.setFunctionExtensions("imageAtomicOr", 1, &E_GL_OES_shader_image_atomic); 3625 symbolTable.setFunctionExtensions("imageAtomicXor", 1, &E_GL_OES_shader_image_atomic); 3626 symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic); 3627 symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic); 3628 } 3629 3630 if (spvVersion.vulkan == 0) { 3631 SpecialQualifier("gl_VertexID", EvqVertexId, EbvVertexId, symbolTable); 3632 SpecialQualifier("gl_InstanceID", EvqInstanceId, EbvInstanceId, symbolTable); 3633 } 3634 3635 if (spvVersion.vulkan >= 100) { 3636 BuiltInVariable("gl_VertexIndex", EbvVertexIndex, symbolTable); 3637 BuiltInVariable("gl_InstanceIndex", EbvInstanceIndex, symbolTable); 3638 } 3639 3640 // Fall through 3641 3642 case EShLangTessControl: 3643 if (profile == EEsProfile && version >= 310) { 3644 symbolTable.setVariableExtensions("gl_BoundingBoxOES", Num_AEP_primitive_bounding_box, AEP_primitive_bounding_box); 3645 BuiltInVariable("gl_BoundingBoxOES", EbvBoundingBox, symbolTable); 3646 } 3647 3648 // Fall through 3649 3650 case EShLangTessEvaluation: 3651 case EShLangGeometry: 3652 SpecialQualifier("gl_Position", EvqPosition, EbvPosition, symbolTable); 3653 SpecialQualifier("gl_PointSize", EvqPointSize, EbvPointSize, symbolTable); 3654 SpecialQualifier("gl_ClipVertex", EvqClipVertex, EbvClipVertex, symbolTable); 3655 3656 BuiltInVariable("gl_in", "gl_Position", EbvPosition, symbolTable); 3657 BuiltInVariable("gl_in", "gl_PointSize", EbvPointSize, symbolTable); 3658 BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable); 3659 BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable); 3660 3661 BuiltInVariable("gl_out", "gl_Position", EbvPosition, symbolTable); 3662 BuiltInVariable("gl_out", "gl_PointSize", EbvPointSize, symbolTable); 3663 BuiltInVariable("gl_out", "gl_ClipDistance", EbvClipDistance, symbolTable); 3664 BuiltInVariable("gl_out", "gl_CullDistance", EbvCullDistance, symbolTable); 3665 3666 BuiltInVariable("gl_ClipDistance", EbvClipDistance, symbolTable); 3667 BuiltInVariable("gl_CullDistance", EbvCullDistance, symbolTable); 3668 BuiltInVariable("gl_PrimitiveIDIn", EbvPrimitiveId, symbolTable); 3669 BuiltInVariable("gl_PrimitiveID", EbvPrimitiveId, symbolTable); 3670 BuiltInVariable("gl_InvocationID", EbvInvocationId, symbolTable); 3671 BuiltInVariable("gl_Layer", EbvLayer, symbolTable); 3672 BuiltInVariable("gl_ViewportIndex", EbvViewportIndex, symbolTable); 3673 BuiltInVariable("gl_PatchVerticesIn", EbvPatchVertices, symbolTable); 3674 BuiltInVariable("gl_TessLevelOuter", EbvTessLevelOuter, symbolTable); 3675 BuiltInVariable("gl_TessLevelInner", EbvTessLevelInner, symbolTable); 3676 BuiltInVariable("gl_TessCoord", EbvTessCoord, symbolTable); 3677 3678 if (version < 410) 3679 symbolTable.setVariableExtensions("gl_ViewportIndex", 1, &E_GL_ARB_viewport_array); 3680 3681 // Compatibility variables 3682 3683 BuiltInVariable("gl_in", "gl_ClipVertex", EbvClipVertex, symbolTable); 3684 BuiltInVariable("gl_in", "gl_FrontColor", EbvFrontColor, symbolTable); 3685 BuiltInVariable("gl_in", "gl_BackColor", EbvBackColor, symbolTable); 3686 BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable); 3687 BuiltInVariable("gl_in", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable); 3688 BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable); 3689 BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable); 3690 3691 BuiltInVariable("gl_out", "gl_ClipVertex", EbvClipVertex, symbolTable); 3692 BuiltInVariable("gl_out", "gl_FrontColor", EbvFrontColor, symbolTable); 3693 BuiltInVariable("gl_out", "gl_BackColor", EbvBackColor, symbolTable); 3694 BuiltInVariable("gl_out", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable); 3695 BuiltInVariable("gl_out", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable); 3696 BuiltInVariable("gl_out", "gl_TexCoord", EbvTexCoord, symbolTable); 3697 BuiltInVariable("gl_out", "gl_FogFragCoord", EbvFogFragCoord, symbolTable); 3698 3699 BuiltInVariable("gl_ClipVertex", EbvClipVertex, symbolTable); 3700 BuiltInVariable("gl_FrontColor", EbvFrontColor, symbolTable); 3701 BuiltInVariable("gl_BackColor", EbvBackColor, symbolTable); 3702 BuiltInVariable("gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable); 3703 BuiltInVariable("gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable); 3704 BuiltInVariable("gl_TexCoord", EbvTexCoord, symbolTable); 3705 BuiltInVariable("gl_FogFragCoord", EbvFogFragCoord, symbolTable); 3706 3707 // gl_PointSize, when it needs to be tied to an extension, is always a member of a block. 3708 // (Sometimes with an instance name, sometimes anonymous). 3709 // However, the current automatic extension scheme does not work per block member, 3710 // so for now check when parsing. 3711 // 3712 //if (profile == EEsProfile) { 3713 // if (language == EShLangGeometry) 3714 // symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_geometry_point_size, AEP_geometry_point_size); 3715 // else if (language == EShLangTessEvaluation || language == EShLangTessControl) 3716 // symbolTable.setVariableExtensions("gl_PointSize", Num_AEP_tessellation_point_size, AEP_tessellation_point_size); 3717 //} 3718 3719 break; 3720 3721 case EShLangFragment: 3722 SpecialQualifier("gl_FrontFacing", EvqFace, EbvFace, symbolTable); 3723 SpecialQualifier("gl_FragCoord", EvqFragCoord, EbvFragCoord, symbolTable); 3724 SpecialQualifier("gl_PointCoord", EvqPointCoord, EbvPointCoord, symbolTable); 3725 SpecialQualifier("gl_FragColor", EvqFragColor, EbvFragColor, symbolTable); 3726 SpecialQualifier("gl_FragDepth", EvqFragDepth, EbvFragDepth, symbolTable); 3727 SpecialQualifier("gl_FragDepthEXT", EvqFragDepth, EbvFragDepth, symbolTable); 3728 SpecialQualifier("gl_HelperInvocation", EvqVaryingIn, EbvHelperInvocation, symbolTable); 3729 3730 BuiltInVariable("gl_ClipDistance", EbvClipDistance, symbolTable); 3731 BuiltInVariable("gl_CullDistance", EbvCullDistance, symbolTable); 3732 BuiltInVariable("gl_PrimitiveID", EbvPrimitiveId, symbolTable); 3733 3734 if ((profile != EEsProfile && version >= 400) || 3735 (profile == EEsProfile && version >= 310)) { 3736 BuiltInVariable("gl_SampleID", EbvSampleId, symbolTable); 3737 BuiltInVariable("gl_SamplePosition", EbvSamplePosition, symbolTable); 3738 BuiltInVariable("gl_SampleMaskIn", EbvSampleMask, symbolTable); 3739 BuiltInVariable("gl_SampleMask", EbvSampleMask, symbolTable); 3740 if (profile == EEsProfile) { 3741 symbolTable.setVariableExtensions("gl_SampleID", 1, &E_GL_OES_sample_variables); 3742 symbolTable.setVariableExtensions("gl_SamplePosition", 1, &E_GL_OES_sample_variables); 3743 symbolTable.setVariableExtensions("gl_SampleMaskIn", 1, &E_GL_OES_sample_variables); 3744 symbolTable.setVariableExtensions("gl_SampleMask", 1, &E_GL_OES_sample_variables); 3745 symbolTable.setVariableExtensions("gl_NumSamples", 1, &E_GL_OES_sample_variables); 3746 } 3747 } 3748 3749 BuiltInVariable("gl_Layer", EbvLayer, symbolTable); 3750 BuiltInVariable("gl_ViewportIndex", EbvViewportIndex, symbolTable); 3751 3752 // Compatibility variables 3753 3754 BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable); 3755 BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable); 3756 BuiltInVariable("gl_in", "gl_Color", EbvColor, symbolTable); 3757 BuiltInVariable("gl_in", "gl_SecondaryColor", EbvSecondaryColor, symbolTable); 3758 3759 BuiltInVariable("gl_FogFragCoord", EbvFogFragCoord, symbolTable); 3760 BuiltInVariable("gl_TexCoord", EbvTexCoord, symbolTable); 3761 BuiltInVariable("gl_Color", EbvColor, symbolTable); 3762 BuiltInVariable("gl_SecondaryColor", EbvSecondaryColor, symbolTable); 3763 3764 // built-in functions 3765 3766 if (profile == EEsProfile) { 3767 if (spvVersion.spv == 0) { 3768 symbolTable.setFunctionExtensions("texture2DLodEXT", 1, &E_GL_EXT_shader_texture_lod); 3769 symbolTable.setFunctionExtensions("texture2DProjLodEXT", 1, &E_GL_EXT_shader_texture_lod); 3770 symbolTable.setFunctionExtensions("textureCubeLodEXT", 1, &E_GL_EXT_shader_texture_lod); 3771 symbolTable.setFunctionExtensions("texture2DGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3772 symbolTable.setFunctionExtensions("texture2DProjGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3773 symbolTable.setFunctionExtensions("textureCubeGradEXT", 1, &E_GL_EXT_shader_texture_lod); 3774 symbolTable.setFunctionExtensions("textureGatherOffsets", Num_AEP_gpu_shader5, AEP_gpu_shader5); 3775 } 3776 if (version == 100) { 3777 symbolTable.setFunctionExtensions("dFdx", 1, &E_GL_OES_standard_derivatives); 3778 symbolTable.setFunctionExtensions("dFdy", 1, &E_GL_OES_standard_derivatives); 3779 symbolTable.setFunctionExtensions("fwidth", 1, &E_GL_OES_standard_derivatives); 3780 } 3781 if (version >= 310) { 3782 symbolTable.setFunctionExtensions("fma", Num_AEP_gpu_shader5, AEP_gpu_shader5); 3783 symbolTable.setFunctionExtensions("interpolateAtCentroid", 1, &E_GL_OES_shader_multisample_interpolation); 3784 symbolTable.setFunctionExtensions("interpolateAtSample", 1, &E_GL_OES_shader_multisample_interpolation); 3785 symbolTable.setFunctionExtensions("interpolateAtOffset", 1, &E_GL_OES_shader_multisample_interpolation); 3786 } 3787 } else if (version < 130) { 3788 if (spvVersion.spv == 0) { 3789 symbolTable.setFunctionExtensions("texture1DLod", 1, &E_GL_ARB_shader_texture_lod); 3790 symbolTable.setFunctionExtensions("texture2DLod", 1, &E_GL_ARB_shader_texture_lod); 3791 symbolTable.setFunctionExtensions("texture3DLod", 1, &E_GL_ARB_shader_texture_lod); 3792 symbolTable.setFunctionExtensions("textureCubeLod", 1, &E_GL_ARB_shader_texture_lod); 3793 symbolTable.setFunctionExtensions("texture1DProjLod", 1, &E_GL_ARB_shader_texture_lod); 3794 symbolTable.setFunctionExtensions("texture2DProjLod", 1, &E_GL_ARB_shader_texture_lod); 3795 symbolTable.setFunctionExtensions("texture3DProjLod", 1, &E_GL_ARB_shader_texture_lod); 3796 symbolTable.setFunctionExtensions("shadow1DLod", 1, &E_GL_ARB_shader_texture_lod); 3797 symbolTable.setFunctionExtensions("shadow2DLod", 1, &E_GL_ARB_shader_texture_lod); 3798 symbolTable.setFunctionExtensions("shadow1DProjLod", 1, &E_GL_ARB_shader_texture_lod); 3799 symbolTable.setFunctionExtensions("shadow2DProjLod", 1, &E_GL_ARB_shader_texture_lod); 3800 } 3801 } 3802 3803 // E_GL_ARB_shader_texture_lod functions usable only with the extension enabled 3804 if (profile != EEsProfile && spvVersion.spv == 0) { 3805 symbolTable.setFunctionExtensions("texture1DGradARB", 1, &E_GL_ARB_shader_texture_lod); 3806 symbolTable.setFunctionExtensions("texture1DProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3807 symbolTable.setFunctionExtensions("texture2DGradARB", 1, &E_GL_ARB_shader_texture_lod); 3808 symbolTable.setFunctionExtensions("texture2DProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3809 symbolTable.setFunctionExtensions("texture3DGradARB", 1, &E_GL_ARB_shader_texture_lod); 3810 symbolTable.setFunctionExtensions("texture3DProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3811 symbolTable.setFunctionExtensions("textureCubeGradARB", 1, &E_GL_ARB_shader_texture_lod); 3812 symbolTable.setFunctionExtensions("shadow1DGradARB", 1, &E_GL_ARB_shader_texture_lod); 3813 symbolTable.setFunctionExtensions("shadow1DProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3814 symbolTable.setFunctionExtensions("shadow2DGradARB", 1, &E_GL_ARB_shader_texture_lod); 3815 symbolTable.setFunctionExtensions("shadow2DProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3816 symbolTable.setFunctionExtensions("texture2DRectGradARB", 1, &E_GL_ARB_shader_texture_lod); 3817 symbolTable.setFunctionExtensions("texture2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3818 symbolTable.setFunctionExtensions("shadow2DRectGradARB", 1, &E_GL_ARB_shader_texture_lod); 3819 symbolTable.setFunctionExtensions("shadow2DRectProjGradARB", 1, &E_GL_ARB_shader_texture_lod); 3820 } 3821 3822 // E_GL_ARB_shader_image_load_store 3823 if (profile != EEsProfile && version < 420) 3824 symbolTable.setFunctionExtensions("memoryBarrier", 1, &E_GL_ARB_shader_image_load_store); 3825 // All the image access functions are protected by checks on the type of the first argument. 3826 3827 // E_GL_ARB_shader_atomic_counters 3828 if (profile != EEsProfile && version < 420) { 3829 symbolTable.setFunctionExtensions("atomicCounterIncrement", 1, &E_GL_ARB_shader_atomic_counters); 3830 symbolTable.setFunctionExtensions("atomicCounterDecrement", 1, &E_GL_ARB_shader_atomic_counters); 3831 symbolTable.setFunctionExtensions("atomicCounter" , 1, &E_GL_ARB_shader_atomic_counters); 3832 } 3833 3834 // E_GL_ARB_derivative_control 3835 if (profile != EEsProfile && version < 450) { 3836 symbolTable.setFunctionExtensions("dFdxFine", 1, &E_GL_ARB_derivative_control); 3837 symbolTable.setFunctionExtensions("dFdyFine", 1, &E_GL_ARB_derivative_control); 3838 symbolTable.setFunctionExtensions("fwidthFine", 1, &E_GL_ARB_derivative_control); 3839 symbolTable.setFunctionExtensions("dFdxCoarse", 1, &E_GL_ARB_derivative_control); 3840 symbolTable.setFunctionExtensions("dFdyCoarse", 1, &E_GL_ARB_derivative_control); 3841 symbolTable.setFunctionExtensions("fwidthCoarse", 1, &E_GL_ARB_derivative_control); 3842 } 3843 3844 // E_GL_ARB_sparse_texture2 3845 if (profile != EEsProfile) 3846 { 3847 symbolTable.setFunctionExtensions("sparseTextureARB", 1, &E_GL_ARB_sparse_texture2); 3848 symbolTable.setFunctionExtensions("sparseTextureLodARB", 1, &E_GL_ARB_sparse_texture2); 3849 symbolTable.setFunctionExtensions("sparseTextureOffsetARB", 1, &E_GL_ARB_sparse_texture2); 3850 symbolTable.setFunctionExtensions("sparseTexelFetchARB", 1, &E_GL_ARB_sparse_texture2); 3851 symbolTable.setFunctionExtensions("sparseTexelFetchOffsetARB", 1, &E_GL_ARB_sparse_texture2); 3852 symbolTable.setFunctionExtensions("sparseTextureLodOffsetARB", 1, &E_GL_ARB_sparse_texture2); 3853 symbolTable.setFunctionExtensions("sparseTextureGradARB", 1, &E_GL_ARB_sparse_texture2); 3854 symbolTable.setFunctionExtensions("sparseTextureGradOffsetARB", 1, &E_GL_ARB_sparse_texture2); 3855 symbolTable.setFunctionExtensions("sparseTextureGatherARB", 1, &E_GL_ARB_sparse_texture2); 3856 symbolTable.setFunctionExtensions("sparseTextureGatherOffsetARB", 1, &E_GL_ARB_sparse_texture2); 3857 symbolTable.setFunctionExtensions("sparseTextureGatherOffsetsARB", 1, &E_GL_ARB_sparse_texture2); 3858 symbolTable.setFunctionExtensions("sparseImageLoadARB", 1, &E_GL_ARB_sparse_texture2); 3859 symbolTable.setFunctionExtensions("sparseTexelsResident", 1, &E_GL_ARB_sparse_texture2); 3860 } 3861 3862 // E_GL_ARB_sparse_texture_clamp 3863 if (profile != EEsProfile) 3864 { 3865 symbolTable.setFunctionExtensions("sparseTextureClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3866 symbolTable.setFunctionExtensions("sparseTextureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3867 symbolTable.setFunctionExtensions("sparseTextureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3868 symbolTable.setFunctionExtensions("sparseTextureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3869 symbolTable.setFunctionExtensions("textureClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3870 symbolTable.setFunctionExtensions("textureOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3871 symbolTable.setFunctionExtensions("textureGradClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3872 symbolTable.setFunctionExtensions("textureGradOffsetClampARB", 1, &E_GL_ARB_sparse_texture_clamp); 3873 } 3874 3875 symbolTable.setVariableExtensions("gl_FragDepthEXT", 1, &E_GL_EXT_frag_depth); 3876 3877 if (profile == EEsProfile) { 3878 symbolTable.setVariableExtensions("gl_PrimitiveID", Num_AEP_geometry_shader, AEP_geometry_shader); 3879 symbolTable.setVariableExtensions("gl_Layer", Num_AEP_geometry_shader, AEP_geometry_shader); 3880 } 3881 3882 if (profile == EEsProfile) { 3883 symbolTable.setFunctionExtensions("imageAtomicAdd", 1, &E_GL_OES_shader_image_atomic); 3884 symbolTable.setFunctionExtensions("imageAtomicMin", 1, &E_GL_OES_shader_image_atomic); 3885 symbolTable.setFunctionExtensions("imageAtomicMax", 1, &E_GL_OES_shader_image_atomic); 3886 symbolTable.setFunctionExtensions("imageAtomicAnd", 1, &E_GL_OES_shader_image_atomic); 3887 symbolTable.setFunctionExtensions("imageAtomicOr", 1, &E_GL_OES_shader_image_atomic); 3888 symbolTable.setFunctionExtensions("imageAtomicXor", 1, &E_GL_OES_shader_image_atomic); 3889 symbolTable.setFunctionExtensions("imageAtomicExchange", 1, &E_GL_OES_shader_image_atomic); 3890 symbolTable.setFunctionExtensions("imageAtomicCompSwap", 1, &E_GL_OES_shader_image_atomic); 3891 } 3892 break; 3893 3894 case EShLangCompute: 3895 BuiltInVariable("gl_NumWorkGroups", EbvNumWorkGroups, symbolTable); 3896 BuiltInVariable("gl_WorkGroupSize", EbvWorkGroupSize, symbolTable); 3897 BuiltInVariable("gl_WorkGroupID", EbvWorkGroupId, symbolTable); 3898 BuiltInVariable("gl_LocalInvocationID", EbvLocalInvocationId, symbolTable); 3899 BuiltInVariable("gl_GlobalInvocationID", EbvGlobalInvocationId, symbolTable); 3900 BuiltInVariable("gl_LocalInvocationIndex", EbvLocalInvocationIndex, symbolTable); 3901 3902 if (profile != EEsProfile && version < 430) { 3903 symbolTable.setVariableExtensions("gl_NumWorkGroups", 1, &E_GL_ARB_compute_shader); 3904 symbolTable.setVariableExtensions("gl_WorkGroupSize", 1, &E_GL_ARB_compute_shader); 3905 symbolTable.setVariableExtensions("gl_WorkGroupID", 1, &E_GL_ARB_compute_shader); 3906 symbolTable.setVariableExtensions("gl_LocalInvocationID", 1, &E_GL_ARB_compute_shader); 3907 symbolTable.setVariableExtensions("gl_GlobalInvocationID", 1, &E_GL_ARB_compute_shader); 3908 symbolTable.setVariableExtensions("gl_LocalInvocationIndex", 1, &E_GL_ARB_compute_shader); 3909 3910 symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupCount", 1, &E_GL_ARB_compute_shader); 3911 symbolTable.setVariableExtensions("gl_MaxComputeWorkGroupSize", 1, &E_GL_ARB_compute_shader); 3912 symbolTable.setVariableExtensions("gl_MaxComputeUniformComponents", 1, &E_GL_ARB_compute_shader); 3913 symbolTable.setVariableExtensions("gl_MaxComputeTextureImageUnits", 1, &E_GL_ARB_compute_shader); 3914 symbolTable.setVariableExtensions("gl_MaxComputeImageUniforms", 1, &E_GL_ARB_compute_shader); 3915 symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounters", 1, &E_GL_ARB_compute_shader); 3916 symbolTable.setVariableExtensions("gl_MaxComputeAtomicCounterBuffers", 1, &E_GL_ARB_compute_shader); 3917 3918 symbolTable.setFunctionExtensions("barrier", 1, &E_GL_ARB_compute_shader); 3919 symbolTable.setFunctionExtensions("memoryBarrierAtomicCounter", 1, &E_GL_ARB_compute_shader); 3920 symbolTable.setFunctionExtensions("memoryBarrierBuffer", 1, &E_GL_ARB_compute_shader); 3921 symbolTable.setFunctionExtensions("memoryBarrierImage", 1, &E_GL_ARB_compute_shader); 3922 symbolTable.setFunctionExtensions("memoryBarrierShared", 1, &E_GL_ARB_compute_shader); 3923 symbolTable.setFunctionExtensions("groupMemoryBarrier", 1, &E_GL_ARB_compute_shader); 3924 } 3925 break; 3926 3927 default: 3928 assert(false && "Language not supported"); 3929 break; 3930 } 3931 3932 // 3933 // Next, identify which built-ins have a mapping to an operator. 3934 // If PureOperatorBuiltins is false, those that are not identified as such are 3935 // expected to be resolved through a library of functions, versus as 3936 // operations. 3937 // 3938 symbolTable.relateToOperator("not", EOpVectorLogicalNot); 3939 3940 symbolTable.relateToOperator("matrixCompMult", EOpMul); 3941 // 120 and 150 are correct for both ES and desktop 3942 if (version >= 120) { 3943 symbolTable.relateToOperator("outerProduct", EOpOuterProduct); 3944 symbolTable.relateToOperator("transpose", EOpTranspose); 3945 if (version >= 150) { 3946 symbolTable.relateToOperator("determinant", EOpDeterminant); 3947 symbolTable.relateToOperator("inverse", EOpMatrixInverse); 3948 } 3949 } 3950 3951 symbolTable.relateToOperator("mod", EOpMod); 3952 symbolTable.relateToOperator("modf", EOpModf); 3953 3954 symbolTable.relateToOperator("equal", EOpVectorEqual); 3955 symbolTable.relateToOperator("notEqual", EOpVectorNotEqual); 3956 symbolTable.relateToOperator("lessThan", EOpLessThan); 3957 symbolTable.relateToOperator("greaterThan", EOpGreaterThan); 3958 symbolTable.relateToOperator("lessThanEqual", EOpLessThanEqual); 3959 symbolTable.relateToOperator("greaterThanEqual", EOpGreaterThanEqual); 3960 3961 symbolTable.relateToOperator("radians", EOpRadians); 3962 symbolTable.relateToOperator("degrees", EOpDegrees); 3963 symbolTable.relateToOperator("sin", EOpSin); 3964 symbolTable.relateToOperator("cos", EOpCos); 3965 symbolTable.relateToOperator("tan", EOpTan); 3966 symbolTable.relateToOperator("asin", EOpAsin); 3967 symbolTable.relateToOperator("acos", EOpAcos); 3968 symbolTable.relateToOperator("atan", EOpAtan); 3969 symbolTable.relateToOperator("sinh", EOpSinh); 3970 symbolTable.relateToOperator("cosh", EOpCosh); 3971 symbolTable.relateToOperator("tanh", EOpTanh); 3972 symbolTable.relateToOperator("asinh", EOpAsinh); 3973 symbolTable.relateToOperator("acosh", EOpAcosh); 3974 symbolTable.relateToOperator("atanh", EOpAtanh); 3975 3976 symbolTable.relateToOperator("pow", EOpPow); 3977 symbolTable.relateToOperator("exp2", EOpExp2); 3978 symbolTable.relateToOperator("log", EOpLog); 3979 symbolTable.relateToOperator("exp", EOpExp); 3980 symbolTable.relateToOperator("log2", EOpLog2); 3981 symbolTable.relateToOperator("sqrt", EOpSqrt); 3982 symbolTable.relateToOperator("inversesqrt", EOpInverseSqrt); 3983 3984 symbolTable.relateToOperator("abs", EOpAbs); 3985 symbolTable.relateToOperator("sign", EOpSign); 3986 symbolTable.relateToOperator("floor", EOpFloor); 3987 symbolTable.relateToOperator("trunc", EOpTrunc); 3988 symbolTable.relateToOperator("round", EOpRound); 3989 symbolTable.relateToOperator("roundEven", EOpRoundEven); 3990 symbolTable.relateToOperator("ceil", EOpCeil); 3991 symbolTable.relateToOperator("fract", EOpFract); 3992 symbolTable.relateToOperator("min", EOpMin); 3993 symbolTable.relateToOperator("max", EOpMax); 3994 symbolTable.relateToOperator("clamp", EOpClamp); 3995 symbolTable.relateToOperator("mix", EOpMix); 3996 symbolTable.relateToOperator("step", EOpStep); 3997 symbolTable.relateToOperator("smoothstep", EOpSmoothStep); 3998 3999 symbolTable.relateToOperator("isnan", EOpIsNan); 4000 symbolTable.relateToOperator("isinf", EOpIsInf); 4001 4002 symbolTable.relateToOperator("floatBitsToInt", EOpFloatBitsToInt); 4003 symbolTable.relateToOperator("floatBitsToUint", EOpFloatBitsToUint); 4004 symbolTable.relateToOperator("intBitsToFloat", EOpIntBitsToFloat); 4005 symbolTable.relateToOperator("uintBitsToFloat", EOpUintBitsToFloat); 4006 symbolTable.relateToOperator("doubleBitsToInt64", EOpDoubleBitsToInt64); 4007 symbolTable.relateToOperator("doubleBitsToUint64", EOpDoubleBitsToUint64); 4008 symbolTable.relateToOperator("int64BitsToDouble", EOpInt64BitsToDouble); 4009 symbolTable.relateToOperator("uint64BitsToDouble", EOpUint64BitsToDouble); 4010 4011 symbolTable.relateToOperator("packSnorm2x16", EOpPackSnorm2x16); 4012 symbolTable.relateToOperator("unpackSnorm2x16", EOpUnpackSnorm2x16); 4013 symbolTable.relateToOperator("packUnorm2x16", EOpPackUnorm2x16); 4014 symbolTable.relateToOperator("unpackUnorm2x16", EOpUnpackUnorm2x16); 4015 4016 symbolTable.relateToOperator("packSnorm4x8", EOpPackSnorm4x8); 4017 symbolTable.relateToOperator("unpackSnorm4x8", EOpUnpackSnorm4x8); 4018 symbolTable.relateToOperator("packUnorm4x8", EOpPackUnorm4x8); 4019 symbolTable.relateToOperator("unpackUnorm4x8", EOpUnpackUnorm4x8); 4020 4021 symbolTable.relateToOperator("packDouble2x32", EOpPackDouble2x32); 4022 symbolTable.relateToOperator("unpackDouble2x32", EOpUnpackDouble2x32); 4023 4024 symbolTable.relateToOperator("packHalf2x16", EOpPackHalf2x16); 4025 symbolTable.relateToOperator("unpackHalf2x16", EOpUnpackHalf2x16); 4026 4027 symbolTable.relateToOperator("packInt2x32", EOpPackInt2x32); 4028 symbolTable.relateToOperator("unpackInt2x32", EOpUnpackInt2x32); 4029 symbolTable.relateToOperator("packUint2x32", EOpPackUint2x32); 4030 symbolTable.relateToOperator("unpackUint2x32", EOpUnpackUint2x32); 4031 4032 symbolTable.relateToOperator("length", EOpLength); 4033 symbolTable.relateToOperator("distance", EOpDistance); 4034 symbolTable.relateToOperator("dot", EOpDot); 4035 symbolTable.relateToOperator("cross", EOpCross); 4036 symbolTable.relateToOperator("normalize", EOpNormalize); 4037 symbolTable.relateToOperator("faceforward", EOpFaceForward); 4038 symbolTable.relateToOperator("reflect", EOpReflect); 4039 symbolTable.relateToOperator("refract", EOpRefract); 4040 4041 symbolTable.relateToOperator("any", EOpAny); 4042 symbolTable.relateToOperator("all", EOpAll); 4043 4044 symbolTable.relateToOperator("barrier", EOpBarrier); 4045 symbolTable.relateToOperator("memoryBarrier", EOpMemoryBarrier); 4046 symbolTable.relateToOperator("memoryBarrierAtomicCounter", EOpMemoryBarrierAtomicCounter); 4047 symbolTable.relateToOperator("memoryBarrierBuffer", EOpMemoryBarrierBuffer); 4048 symbolTable.relateToOperator("memoryBarrierImage", EOpMemoryBarrierImage); 4049 4050 symbolTable.relateToOperator("atomicAdd", EOpAtomicAdd); 4051 symbolTable.relateToOperator("atomicMin", EOpAtomicMin); 4052 symbolTable.relateToOperator("atomicMax", EOpAtomicMax); 4053 symbolTable.relateToOperator("atomicAnd", EOpAtomicAnd); 4054 symbolTable.relateToOperator("atomicOr", EOpAtomicOr); 4055 symbolTable.relateToOperator("atomicXor", EOpAtomicXor); 4056 symbolTable.relateToOperator("atomicExchange", EOpAtomicExchange); 4057 symbolTable.relateToOperator("atomicCompSwap", EOpAtomicCompSwap); 4058 4059 symbolTable.relateToOperator("atomicCounterIncrement", EOpAtomicCounterIncrement); 4060 symbolTable.relateToOperator("atomicCounterDecrement", EOpAtomicCounterDecrement); 4061 symbolTable.relateToOperator("atomicCounter", EOpAtomicCounter); 4062 4063 symbolTable.relateToOperator("fma", EOpFma); 4064 symbolTable.relateToOperator("frexp", EOpFrexp); 4065 symbolTable.relateToOperator("ldexp", EOpLdexp); 4066 symbolTable.relateToOperator("uaddCarry", EOpAddCarry); 4067 symbolTable.relateToOperator("usubBorrow", EOpSubBorrow); 4068 symbolTable.relateToOperator("umulExtended", EOpUMulExtended); 4069 symbolTable.relateToOperator("imulExtended", EOpIMulExtended); 4070 symbolTable.relateToOperator("bitfieldExtract", EOpBitfieldExtract); 4071 symbolTable.relateToOperator("bitfieldInsert", EOpBitfieldInsert); 4072 symbolTable.relateToOperator("bitfieldReverse", EOpBitFieldReverse); 4073 symbolTable.relateToOperator("bitCount", EOpBitCount); 4074 symbolTable.relateToOperator("findLSB", EOpFindLSB); 4075 symbolTable.relateToOperator("findMSB", EOpFindMSB); 4076 4077 if (PureOperatorBuiltins) { 4078 symbolTable.relateToOperator("imageSize", EOpImageQuerySize); 4079 symbolTable.relateToOperator("imageSamples", EOpImageQuerySamples); 4080 symbolTable.relateToOperator("imageLoad", EOpImageLoad); 4081 symbolTable.relateToOperator("imageStore", EOpImageStore); 4082 symbolTable.relateToOperator("imageAtomicAdd", EOpImageAtomicAdd); 4083 symbolTable.relateToOperator("imageAtomicMin", EOpImageAtomicMin); 4084 symbolTable.relateToOperator("imageAtomicMax", EOpImageAtomicMax); 4085 symbolTable.relateToOperator("imageAtomicAnd", EOpImageAtomicAnd); 4086 symbolTable.relateToOperator("imageAtomicOr", EOpImageAtomicOr); 4087 symbolTable.relateToOperator("imageAtomicXor", EOpImageAtomicXor); 4088 symbolTable.relateToOperator("imageAtomicExchange", EOpImageAtomicExchange); 4089 symbolTable.relateToOperator("imageAtomicCompSwap", EOpImageAtomicCompSwap); 4090 4091 symbolTable.relateToOperator("subpassLoad", EOpSubpassLoad); 4092 symbolTable.relateToOperator("subpassLoadMS", EOpSubpassLoadMS); 4093 4094 symbolTable.relateToOperator("textureSize", EOpTextureQuerySize); 4095 symbolTable.relateToOperator("textureQueryLod", EOpTextureQueryLod); 4096 symbolTable.relateToOperator("textureQueryLevels", EOpTextureQueryLevels); 4097 symbolTable.relateToOperator("textureSamples", EOpTextureQuerySamples); 4098 symbolTable.relateToOperator("texture", EOpTexture); 4099 symbolTable.relateToOperator("textureProj", EOpTextureProj); 4100 symbolTable.relateToOperator("textureLod", EOpTextureLod); 4101 symbolTable.relateToOperator("textureOffset", EOpTextureOffset); 4102 symbolTable.relateToOperator("texelFetch", EOpTextureFetch); 4103 symbolTable.relateToOperator("texelFetchOffset", EOpTextureFetchOffset); 4104 symbolTable.relateToOperator("textureProjOffset", EOpTextureProjOffset); 4105 symbolTable.relateToOperator("textureLodOffset", EOpTextureLodOffset); 4106 symbolTable.relateToOperator("textureProjLod", EOpTextureProjLod); 4107 symbolTable.relateToOperator("textureProjLodOffset", EOpTextureProjLodOffset); 4108 symbolTable.relateToOperator("textureGrad", EOpTextureGrad); 4109 symbolTable.relateToOperator("textureGradOffset", EOpTextureGradOffset); 4110 symbolTable.relateToOperator("textureProjGrad", EOpTextureProjGrad); 4111 symbolTable.relateToOperator("textureProjGradOffset", EOpTextureProjGradOffset); 4112 symbolTable.relateToOperator("textureGather", EOpTextureGather); 4113 symbolTable.relateToOperator("textureGatherOffset", EOpTextureGatherOffset); 4114 symbolTable.relateToOperator("textureGatherOffsets", EOpTextureGatherOffsets); 4115 4116 symbolTable.relateToOperator("noise1", EOpNoise); 4117 symbolTable.relateToOperator("noise2", EOpNoise); 4118 symbolTable.relateToOperator("noise3", EOpNoise); 4119 symbolTable.relateToOperator("noise4", EOpNoise); 4120 4121 if (spvVersion.spv == 0 && (IncludeLegacy(version, profile, spvVersion) || 4122 (profile == EEsProfile && version == 100))) { 4123 symbolTable.relateToOperator("ftransform", EOpFtransform); 4124 4125 symbolTable.relateToOperator("texture1D", EOpTexture); 4126 symbolTable.relateToOperator("texture1DGradARB", EOpTextureGrad); 4127 symbolTable.relateToOperator("texture1DProj", EOpTextureProj); 4128 symbolTable.relateToOperator("texture1DProjGradARB", EOpTextureProjGrad); 4129 symbolTable.relateToOperator("texture1DLod", EOpTextureLod); 4130 symbolTable.relateToOperator("texture1DProjLod", EOpTextureProjLod); 4131 4132 symbolTable.relateToOperator("texture2DRect", EOpTexture); 4133 symbolTable.relateToOperator("texture2DRectProj", EOpTextureProj); 4134 symbolTable.relateToOperator("texture2DRectGradARB", EOpTextureGrad); 4135 symbolTable.relateToOperator("texture2DRectProjGradARB", EOpTextureProjGrad); 4136 symbolTable.relateToOperator("shadow2DRect", EOpTexture); 4137 symbolTable.relateToOperator("shadow2DRectProj", EOpTextureProj); 4138 symbolTable.relateToOperator("shadow2DRectGradARB", EOpTextureGrad); 4139 symbolTable.relateToOperator("shadow2DRectProjGradARB", EOpTextureProjGrad); 4140 4141 symbolTable.relateToOperator("texture2D", EOpTexture); 4142 symbolTable.relateToOperator("texture2DProj", EOpTextureProj); 4143 symbolTable.relateToOperator("texture2DGradEXT", EOpTextureGrad); 4144 symbolTable.relateToOperator("texture2DGradARB", EOpTextureGrad); 4145 symbolTable.relateToOperator("texture2DProjGradEXT", EOpTextureProjGrad); 4146 symbolTable.relateToOperator("texture2DProjGradARB", EOpTextureProjGrad); 4147 symbolTable.relateToOperator("texture2DLod", EOpTextureLod); 4148 symbolTable.relateToOperator("texture2DLodEXT", EOpTextureLod); 4149 symbolTable.relateToOperator("texture2DProjLod", EOpTextureProjLod); 4150 symbolTable.relateToOperator("texture2DProjLodEXT", EOpTextureProjLod); 4151 4152 symbolTable.relateToOperator("texture3D", EOpTexture); 4153 symbolTable.relateToOperator("texture3DGradARB", EOpTextureGrad); 4154 symbolTable.relateToOperator("texture3DProj", EOpTextureProj); 4155 symbolTable.relateToOperator("texture3DProjGradARB", EOpTextureProjGrad); 4156 symbolTable.relateToOperator("texture3DLod", EOpTextureLod); 4157 symbolTable.relateToOperator("texture3DProjLod", EOpTextureProjLod); 4158 symbolTable.relateToOperator("textureCube", EOpTexture); 4159 symbolTable.relateToOperator("textureCubeGradEXT", EOpTextureGrad); 4160 symbolTable.relateToOperator("textureCubeGradARB", EOpTextureGrad); 4161 symbolTable.relateToOperator("textureCubeLod", EOpTextureLod); 4162 symbolTable.relateToOperator("textureCubeLodEXT", EOpTextureLod); 4163 symbolTable.relateToOperator("shadow1D", EOpTexture); 4164 symbolTable.relateToOperator("shadow1DGradARB", EOpTextureGrad); 4165 symbolTable.relateToOperator("shadow2D", EOpTexture); 4166 symbolTable.relateToOperator("shadow2DGradARB", EOpTextureGrad); 4167 symbolTable.relateToOperator("shadow1DProj", EOpTextureProj); 4168 symbolTable.relateToOperator("shadow2DProj", EOpTextureProj); 4169 symbolTable.relateToOperator("shadow1DProjGradARB", EOpTextureProjGrad); 4170 symbolTable.relateToOperator("shadow2DProjGradARB", EOpTextureProjGrad); 4171 symbolTable.relateToOperator("shadow1DLod", EOpTextureLod); 4172 symbolTable.relateToOperator("shadow2DLod", EOpTextureLod); 4173 symbolTable.relateToOperator("shadow1DProjLod", EOpTextureProjLod); 4174 symbolTable.relateToOperator("shadow2DProjLod", EOpTextureProjLod); 4175 } 4176 4177 if (profile != EEsProfile) { 4178 symbolTable.relateToOperator("sparseTextureARB", EOpSparseTexture); 4179 symbolTable.relateToOperator("sparseTextureLodARB", EOpSparseTextureLod); 4180 symbolTable.relateToOperator("sparseTextureOffsetARB", EOpSparseTextureOffset); 4181 symbolTable.relateToOperator("sparseTexelFetchARB", EOpSparseTextureFetch); 4182 symbolTable.relateToOperator("sparseTexelFetchOffsetARB", EOpSparseTextureFetchOffset); 4183 symbolTable.relateToOperator("sparseTextureLodOffsetARB", EOpSparseTextureLodOffset); 4184 symbolTable.relateToOperator("sparseTextureGradARB", EOpSparseTextureGrad); 4185 symbolTable.relateToOperator("sparseTextureGradOffsetARB", EOpSparseTextureGradOffset); 4186 symbolTable.relateToOperator("sparseTextureGatherARB", EOpSparseTextureGather); 4187 symbolTable.relateToOperator("sparseTextureGatherOffsetARB", EOpSparseTextureGatherOffset); 4188 symbolTable.relateToOperator("sparseTextureGatherOffsetsARB", EOpSparseTextureGatherOffsets); 4189 symbolTable.relateToOperator("sparseImageLoadARB", EOpSparseImageLoad); 4190 symbolTable.relateToOperator("sparseTexelsResidentARB", EOpSparseTexelsResident); 4191 4192 symbolTable.relateToOperator("sparseTextureClampARB", EOpSparseTextureClamp); 4193 symbolTable.relateToOperator("sparseTextureOffsetClampARB", EOpSparseTextureOffsetClamp); 4194 symbolTable.relateToOperator("sparseTextureGradClampARB", EOpSparseTextureGradClamp); 4195 symbolTable.relateToOperator("sparseTextureGradOffsetClampARB", EOpSparseTextureGradOffsetClamp); 4196 symbolTable.relateToOperator("textureClampARB", EOpTextureClamp); 4197 symbolTable.relateToOperator("textureOffsetClampARB", EOpTextureOffsetClamp); 4198 symbolTable.relateToOperator("textureGradClampARB", EOpTextureGradClamp); 4199 symbolTable.relateToOperator("textureGradOffsetClampARB", EOpTextureGradOffsetClamp); 4200 4201 symbolTable.relateToOperator("ballotARB", EOpBallot); 4202 symbolTable.relateToOperator("readInvocationARB", EOpReadInvocation); 4203 symbolTable.relateToOperator("readFirstInvocationARB", EOpReadFirstInvocation); 4204 4205 symbolTable.relateToOperator("anyInvocationARB", EOpAnyInvocation); 4206 symbolTable.relateToOperator("allInvocationsARB", EOpAllInvocations); 4207 symbolTable.relateToOperator("allInvocationsEqualARB", EOpAllInvocationsEqual); 4208 } 4209 } 4210 4211 switch(language) { 4212 case EShLangVertex: 4213 break; 4214 4215 case EShLangTessControl: 4216 case EShLangTessEvaluation: 4217 break; 4218 4219 case EShLangGeometry: 4220 symbolTable.relateToOperator("EmitStreamVertex", EOpEmitStreamVertex); 4221 symbolTable.relateToOperator("EndStreamPrimitive", EOpEndStreamPrimitive); 4222 symbolTable.relateToOperator("EmitVertex", EOpEmitVertex); 4223 symbolTable.relateToOperator("EndPrimitive", EOpEndPrimitive); 4224 break; 4225 4226 case EShLangFragment: 4227 symbolTable.relateToOperator("dFdx", EOpDPdx); 4228 symbolTable.relateToOperator("dFdy", EOpDPdy); 4229 symbolTable.relateToOperator("fwidth", EOpFwidth); 4230 if (profile != EEsProfile && version >= 400) { 4231 symbolTable.relateToOperator("dFdxFine", EOpDPdxFine); 4232 symbolTable.relateToOperator("dFdyFine", EOpDPdyFine); 4233 symbolTable.relateToOperator("fwidthFine", EOpFwidthFine); 4234 symbolTable.relateToOperator("dFdxCoarse", EOpDPdxCoarse); 4235 symbolTable.relateToOperator("dFdyCoarse", EOpDPdyCoarse); 4236 symbolTable.relateToOperator("fwidthCoarse", EOpFwidthCoarse); 4237 } 4238 symbolTable.relateToOperator("interpolateAtCentroid", EOpInterpolateAtCentroid); 4239 symbolTable.relateToOperator("interpolateAtSample", EOpInterpolateAtSample); 4240 symbolTable.relateToOperator("interpolateAtOffset", EOpInterpolateAtOffset); 4241 break; 4242 4243 case EShLangCompute: 4244 symbolTable.relateToOperator("memoryBarrierShared", EOpMemoryBarrierShared); 4245 symbolTable.relateToOperator("groupMemoryBarrier", EOpGroupMemoryBarrier); 4246 break; 4247 4248 default: 4249 assert(false && "Language not supported"); 4250 } 4251 } 4252 4253 // 4254 // Add context-dependent (resource-specific) built-ins not handled by the above. These 4255 // would be ones that need to be programmatically added because they cannot 4256 // be added by simple text strings. For these, also 4257 // 1) Map built-in functions to operators, for those that will turn into an operation node 4258 // instead of remaining a function call. 4259 // 2) Tag extension-related symbols added to their base version with their extensions, so 4260 // that if an early version has the extension turned off, there is an error reported on use. 4261 // 4262 void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) 4263 { 4264 if (profile != EEsProfile && version >= 430 && version < 440) { 4265 symbolTable.setVariableExtensions("gl_MaxTransformFeedbackBuffers", 1, &E_GL_ARB_enhanced_layouts); 4266 symbolTable.setVariableExtensions("gl_MaxTransformFeedbackInterleavedComponents", 1, &E_GL_ARB_enhanced_layouts); 4267 } 4268 if (profile != EEsProfile && version >= 130 && version < 420) { 4269 symbolTable.setVariableExtensions("gl_MinProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack); 4270 symbolTable.setVariableExtensions("gl_MaxProgramTexelOffset", 1, &E_GL_ARB_shading_language_420pack); 4271 } 4272 if (profile != EEsProfile && version >= 150 && version < 410) 4273 symbolTable.setVariableExtensions("gl_MaxViewports", 1, &E_GL_ARB_viewport_array); 4274 4275 switch(language) { 4276 case EShLangFragment: 4277 // Set up gl_FragData based on current array size. 4278 if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) { 4279 TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone; 4280 TType fragData(EbtFloat, EvqFragColor, pq, 4); 4281 TArraySizes& arraySizes = *new TArraySizes; 4282 arraySizes.addInnerSize(resources.maxDrawBuffers); 4283 fragData.newArraySizes(arraySizes); 4284 symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); 4285 SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable); 4286 } 4287 break; 4288 4289 case EShLangTessControl: 4290 case EShLangTessEvaluation: 4291 // Because of the context-dependent array size (gl_MaxPatchVertices), 4292 // these variables were added later than the others and need to be mapped now. 4293 4294 // standard members 4295 BuiltInVariable("gl_in", "gl_Position", EbvPosition, symbolTable); 4296 BuiltInVariable("gl_in", "gl_PointSize", EbvPointSize, symbolTable); 4297 BuiltInVariable("gl_in", "gl_ClipDistance", EbvClipDistance, symbolTable); 4298 BuiltInVariable("gl_in", "gl_CullDistance", EbvCullDistance, symbolTable); 4299 4300 // compatibility members 4301 BuiltInVariable("gl_in", "gl_ClipVertex", EbvClipVertex, symbolTable); 4302 BuiltInVariable("gl_in", "gl_FrontColor", EbvFrontColor, symbolTable); 4303 BuiltInVariable("gl_in", "gl_BackColor", EbvBackColor, symbolTable); 4304 BuiltInVariable("gl_in", "gl_FrontSecondaryColor", EbvFrontSecondaryColor, symbolTable); 4305 BuiltInVariable("gl_in", "gl_BackSecondaryColor", EbvBackSecondaryColor, symbolTable); 4306 BuiltInVariable("gl_in", "gl_TexCoord", EbvTexCoord, symbolTable); 4307 BuiltInVariable("gl_in", "gl_FogFragCoord", EbvFogFragCoord, symbolTable); 4308 break; 4309 4310 default: 4311 break; 4312 } 4313 } 4314 4315 } // end namespace glslang 4316