1 # Tests todo: 2 # - inout with varyings, attributes, uniforms (and arrays of 'em) 3 # - inout with arrays, array elements 4 # - inout with array elements 5 # - inout by-value semantics (arrays & elements & structs) 6 7 # Done: 8 # - control flow: return, return in loop, etc. 9 10 group datatypes "Function Parameter Data Types" 11 12 case float_float 13 values 14 { 15 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 16 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 17 } 18 19 both "" 20 precision mediump float; 21 ${DECLARATIONS} 22 23 float func (float a) 24 { 25 return -a; 26 } 27 28 void main() 29 { 30 out0 = func(in0); 31 ${OUTPUT} 32 } 33 "" 34 end 35 36 case float_vec2 37 values 38 { 39 input vec2 in0 = [ vec2(0.0, 1.0) | vec2(2.0, 2.5) ]; 40 output float out0 = [ -1.0 | -4.5 ]; 41 } 42 43 both "" 44 precision mediump float; 45 ${DECLARATIONS} 46 47 float func (vec2 a) 48 { 49 return -(a.x + a.y); 50 } 51 52 void main() 53 { 54 out0 = func(in0); 55 ${OUTPUT} 56 } 57 "" 58 end 59 60 case float_vec3 61 values 62 { 63 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ]; 64 output float out0 = [ 1.0 | -0.5 ]; 65 } 66 67 both "" 68 precision mediump float; 69 ${DECLARATIONS} 70 71 float func (vec3 a) 72 { 73 return -(a.x + a.y + a.z); 74 } 75 76 void main() 77 { 78 out0 = func(in0); 79 ${OUTPUT} 80 } 81 "" 82 end 83 84 case float_vec4 85 values 86 { 87 input vec4 in0 = [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ]; 88 output float out0 = [ 0.5 | -1.5 ]; 89 } 90 91 both "" 92 precision mediump float; 93 ${DECLARATIONS} 94 95 float func (vec4 a) 96 { 97 return -(a.x + a.y + a.z + a.w); 98 } 99 100 void main() 101 { 102 out0 = func(in0); 103 ${OUTPUT} 104 } 105 "" 106 end 107 108 case float_mat2 109 values 110 { 111 input mat2 in0 = [ mat2(0.0, 1.0, -2.0, 0.5) | mat2(2.0, 2.5, 4.0, -7.0) ]; 112 output float out0 = [ 0.5 | -1.5 ]; 113 } 114 115 both "" 116 precision mediump float; 117 ${DECLARATIONS} 118 119 float func (mat2 a) 120 { 121 return -(a[0][0] + a[0][1] + a[1][0] + a[1][1]); 122 } 123 124 void main() 125 { 126 out0 = func(in0); 127 ${OUTPUT} 128 } 129 "" 130 end 131 132 case float_mat3 133 values 134 { 135 input mat3 in0 = [ mat3(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0) | mat3(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0) ]; 136 output float out0 = [ -4.5 | -5.0 ]; 137 } 138 139 both "" 140 precision mediump float; 141 ${DECLARATIONS} 142 143 float func (mat3 a) 144 { 145 return -(a[0][0] + a[0][1] + a[0][2] + a[1][0] + a[1][1] + a[1][2] + a[2][0] + a[2][1] + a[2][2]); 146 } 147 148 void main() 149 { 150 out0 = func(in0); 151 ${OUTPUT} 152 } 153 "" 154 end 155 156 case float_mat4 157 values 158 { 159 input mat4 in0 = [ mat4(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -2.0, -2.0) | mat4(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0, 0.0, 2.0, -1.0, 1.0, 0.0, -1.0, 3.0) ]; 160 output float out0 = [ -5.5 | -9.0 ]; 161 } 162 163 both "" 164 precision mediump float; 165 ${DECLARATIONS} 166 167 float func (mat4 a) 168 { 169 return -(a[0][0] + a[0][1] + a[0][2] + a[0][3] + a[1][0] + a[1][1] + a[1][2] + a[1][3] + a[2][0] + a[2][1] + a[2][2] + a[2][3] + a[3][0] + a[3][1] + a[3][2] + a[3][3]); 170 } 171 172 void main() 173 { 174 out0 = func(in0); 175 ${OUTPUT} 176 } 177 "" 178 end 179 180 case int_int 181 values 182 { 183 input int in0 = [ -1 | 0 | 1 | 4 ]; 184 output int out0 = [ 1 | 0 | -1 | -4 ]; 185 } 186 187 both "" 188 precision mediump float; 189 precision mediump int; 190 ${DECLARATIONS} 191 192 int func (int a) 193 { 194 return -a; 195 } 196 197 void main() 198 { 199 ${SETUP} 200 out0 = func(in0); 201 ${OUTPUT} 202 } 203 "" 204 end 205 206 case int_ivec2 207 values 208 { 209 input ivec2 in0 = [ ivec2(-1, 0) | ivec2(1, 4) ]; 210 output int out0 = [ 1 | -5 ]; 211 } 212 213 both "" 214 precision mediump float; 215 precision mediump int; 216 ${DECLARATIONS} 217 218 int func (ivec2 a) 219 { 220 return -(a.x + a.y); 221 } 222 223 void main() 224 { 225 ${SETUP} 226 out0 = func(in0); 227 ${OUTPUT} 228 } 229 "" 230 end 231 232 case int_ivec3 233 values 234 { 235 input ivec3 in0 = [ ivec3(-1, 0, 2) | ivec3(1, 4, -8) ]; 236 output int out0 = [ -1 | 3 ]; 237 } 238 239 both "" 240 precision mediump float; 241 precision mediump int; 242 ${DECLARATIONS} 243 244 int func (ivec3 a) 245 { 246 return -(a.x + a.y + a.z); 247 } 248 249 void main() 250 { 251 ${SETUP} 252 out0 = func(in0); 253 ${OUTPUT} 254 } 255 "" 256 end 257 258 case int_ivec4 259 values 260 { 261 input ivec4 in0 = [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ]; 262 output int out0 = [ -3 | 1 ]; 263 } 264 265 both "" 266 precision mediump float; 267 precision mediump int; 268 ${DECLARATIONS} 269 270 int func (ivec4 a) 271 { 272 return -(a.x + a.y + a.z + a.w); 273 } 274 275 void main() 276 { 277 ${SETUP} 278 out0 = func(in0); 279 ${OUTPUT} 280 } 281 "" 282 end 283 284 case bool_bool 285 values 286 { 287 input bool in0 = [ true | false ]; 288 output bool out0 = [ false | true ]; 289 } 290 291 both "" 292 precision mediump float; 293 ${DECLARATIONS} 294 295 bool func (bool a) 296 { 297 return !a; 298 } 299 300 void main() 301 { 302 ${SETUP} 303 out0 = func(in0); 304 ${OUTPUT} 305 } 306 "" 307 end 308 309 case bool_bvec2 310 values 311 { 312 input bvec2 in0 = [ bvec2(true, true) | bvec2(false, true) ]; 313 output bool out0 = [ false | true ]; 314 } 315 316 both "" 317 precision mediump float; 318 ${DECLARATIONS} 319 320 bool func (bvec2 a) 321 { 322 return !(a.x == a.y); 323 } 324 325 void main() 326 { 327 ${SETUP} 328 out0 = func(in0); 329 ${OUTPUT} 330 } 331 "" 332 end 333 334 case bool_bvec3 335 values 336 { 337 input bvec3 in0 = [ bvec3(true, true, false) | bvec3(true, false, false) ]; 338 output bool out0 = [ false | true ]; 339 } 340 341 both "" 342 precision mediump float; 343 ${DECLARATIONS} 344 345 bool func (bvec3 a) 346 { 347 return (a.x == a.y) == a.z; 348 } 349 350 void main() 351 { 352 ${SETUP} 353 out0 = func(in0); 354 ${OUTPUT} 355 } 356 "" 357 end 358 359 case bool_bvec4 360 values 361 { 362 input bvec4 in0 = [ bvec4(true, true, true, false) | bvec4(false, false, true, true) | bvec4(true, false, false, true) ]; 363 output bool out0 = [ false | true | true ]; 364 } 365 366 both "" 367 precision mediump float; 368 ${DECLARATIONS} 369 370 bool func (bvec4 a) 371 { 372 return ((a.x == a.y) == (a.z == a.w)); 373 } 374 375 void main() 376 { 377 ${SETUP} 378 out0 = func(in0); 379 ${OUTPUT} 380 } 381 "" 382 end 383 384 case mat2 385 values 386 { 387 input mat2 in0 = [ mat2(-2.0, 0.5, -1.0, 1.0) | mat2(1.0, -3.5, -3.5, 2.5) | mat2(-2.0, -2.0, 3.5, 0.0) ]; 388 output mat2 out0 = [ mat2(4.0, -1.0, 2.0, -2.0) | mat2(-2.0, 7.0, 7.0, -5.0) | mat2(4.0, 4.0, -7.0, -0.0) ]; 389 } 390 391 both "" 392 precision mediump float; 393 ${DECLARATIONS} 394 395 mat2 func (mat2 a) 396 { 397 return -2.0*a; 398 } 399 400 void main() 401 { 402 ${SETUP} 403 out0 = func(in0); 404 ${OUTPUT} 405 } 406 "" 407 end 408 409 410 case mat3 411 values 412 { 413 input mat3 in0 = [ mat3(2.5, 0.0, 1.0, -2.5, 1.0, 3.0, 0.0, 2.0, 1.5) | mat3(-3.5, 2.0, 0.5, -1.5, -3.5, 2.5, 0.0, 1.5, 3.0) | mat3(1.5, 3.0, -1.0, 2.5, -0.5, 3.5, 3.0, -3.0, -2.5) ]; 414 output mat3 out0 = [ mat3(-5.0, -0.0, -2.0, 5.0, -2.0, -6.0, -0.0, -4.0, -3.0) | mat3(7.0, -4.0, -1.0, 3.0, 7.0, -5.0, -0.0, -3.0, -6.0) | mat3(-3.0, -6.0, 2.0, -5.0, 1.0, -7.0, -6.0, 6.0, 5.0) ]; 415 } 416 417 both "" 418 precision mediump float; 419 ${DECLARATIONS} 420 421 mat3 func (mat3 a) 422 { 423 return -2.0*a; 424 } 425 426 void main() 427 { 428 ${SETUP} 429 out0 = func(in0); 430 ${OUTPUT} 431 } 432 "" 433 end 434 435 436 case mat4 437 values 438 { 439 input mat4 in0 = [ mat4(-2.0, 3.5, -0.5, 1.0, -1.5, 0.0, -1.0, -1.0, 0.5, 0.5, 3.0, 1.5, 3.0, 2.5, 3.5, 1.5) | mat4(-2.5, 2.5, 3.5, 3.0, 0.5, 1.5, -2.0, 2.5, 0.5, -1.5, -3.5, 2.5, 3.5, -3.0, 2.5, -0.5) | mat4(-2.5, -1.5, 2.0, 3.0, -3.5, 1.0, -3.5, 1.5, -1.5, 3.0, 3.5, 0.0, 3.5, -1.5, -3.0, 0.5) ]; 440 output mat4 out0 = [ mat4(4.0, -7.0, 1.0, -2.0, 3.0, -0.0, 2.0, 2.0, -1.0, -1.0, -6.0, -3.0, -6.0, -5.0, -7.0, -3.0) | mat4(5.0, -5.0, -7.0, -6.0, -1.0, -3.0, 4.0, -5.0, -1.0, 3.0, 7.0, -5.0, -7.0, 6.0, -5.0, 1.0) | mat4(5.0, 3.0, -4.0, -6.0, 7.0, -2.0, 7.0, -3.0, 3.0, -6.0, -7.0, -0.0, -7.0, 3.0, 6.0, -1.0) ]; 441 } 442 443 both "" 444 precision mediump float; 445 ${DECLARATIONS} 446 447 mat4 func (mat4 a) 448 { 449 return -2.0*a; 450 } 451 452 void main() 453 { 454 ${SETUP} 455 out0 = func(in0); 456 ${OUTPUT} 457 } 458 "" 459 end 460 461 case float_struct 462 values 463 { 464 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ]; 465 output float out0 = [ 1.0 | -0.5 ]; 466 } 467 468 both "" 469 precision mediump float; 470 ${DECLARATIONS} 471 472 struct Pos { float a, b, c; }; 473 474 float func (Pos p) 475 { 476 return -(p.a + p.b + p.c); 477 } 478 479 void main() 480 { 481 Pos p = Pos(in0.x, in0.y, in0.z); 482 out0 = func(p); 483 ${OUTPUT} 484 } 485 "" 486 end 487 488 case struct_struct 489 values 490 { 491 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ]; 492 output float out0 = [ 1.0 | -0.5 ]; 493 } 494 495 both "" 496 precision mediump float; 497 ${DECLARATIONS} 498 499 struct Pos { float a, b, c; }; 500 501 Pos func (Pos p) 502 { 503 return Pos(-p.a, -p.b, -p.c); 504 } 505 506 void main() 507 { 508 Pos p = Pos(in0.x, in0.y, in0.z); 509 p = func(p); 510 out0 = p.a + p.b + p.c; 511 ${OUTPUT} 512 } 513 "" 514 end 515 516 case struct_nested_struct 517 values 518 { 519 input vec3 in0 = [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ]; 520 output float out0 = [ 1.0 | -0.5 ]; 521 } 522 523 both "" 524 precision mediump float; 525 ${DECLARATIONS} 526 527 struct Pos { float a, b, c; }; 528 struct Line { Pos start, end; }; 529 530 Line func (Pos p) 531 { 532 return Line(p, Pos(-p.a, -p.b, -p.c)); 533 } 534 535 float sum (Pos p) 536 { 537 return (p.a + p.b + p.c); 538 } 539 540 void main() 541 { 542 Pos p = Pos(in0.x, in0.y, in0.z); 543 Line line = func(p); 544 out0 = sum(line.start) + (2.0 * sum(line.end)); 545 ${OUTPUT} 546 } 547 "" 548 end 549 550 case struct_constructor_highp_in_fragment 551 desc "passing highp vector to struct constructor in fragment shader yields all zeros" 552 vertex "" 553 ${VERTEX_DECLARATIONS} 554 void main() 555 { 556 ${VERTEX_OUTPUT} 557 } 558 "" 559 fragment "" 560 #ifdef GL_FRAGMENT_PRECISION_HIGH 561 #define PRECISION highp 562 #else 563 #define PRECISION mediump 564 #endif 565 struct Test { 566 PRECISION vec3 color; 567 } ; 568 void main() { 569 PRECISION vec3 color = vec3(0.2, 2.0, 0.1); 570 Test test = Test(color); 571 // Bias the color so all components are guaranteed > 1.0. 572 gl_FragColor = vec4(vec3(0.25, 0.55, 0.65) + vec3(4.0, 0.25, 4.0) * test.color, 1.0); 573 } 574 "" 575 end 576 577 end # datatypes 578 579 group qualifiers "Function Parameter Qualifiers" 580 581 case in_float 582 values 583 { 584 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 585 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 586 } 587 588 both "" 589 precision mediump float; 590 precision mediump int; 591 ${DECLARATIONS} 592 593 float func (in float a) 594 { 595 a = -a; 596 return 2.0 * a; 597 } 598 599 void main() 600 { 601 ${SETUP} 602 float f = in0; 603 float g = func(f); 604 out0 = f + g; 605 ${OUTPUT} 606 } 607 "" 608 end 609 610 case out_float 611 values 612 { 613 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 614 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 615 } 616 617 both "" 618 precision mediump float; 619 precision mediump int; 620 ${DECLARATIONS} 621 622 void func (out float a) 623 { 624 a = -1.0; 625 } 626 627 void main() 628 { 629 ${SETUP} 630 float f = 1.0; 631 func(f); 632 out0 = f * in0; 633 ${OUTPUT} 634 } 635 "" 636 end 637 638 case inout_float 639 values 640 { 641 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 642 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 643 } 644 645 both "" 646 precision mediump float; 647 precision mediump int; 648 ${DECLARATIONS} 649 650 void func (inout float a) 651 { 652 a = -a; 653 } 654 655 void main() 656 { 657 ${SETUP} 658 float f = 1.0; 659 func(f); 660 out0 = f * in0; 661 ${OUTPUT} 662 } 663 "" 664 end 665 666 case in_lowp_float 667 values 668 { 669 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 670 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 671 } 672 673 both "" 674 precision mediump float; 675 precision mediump int; 676 ${DECLARATIONS} 677 678 float func (in lowp float a) 679 { 680 a = -a; 681 return 2.0 * a; 682 } 683 684 void main() 685 { 686 ${SETUP} 687 float f = in0; 688 float g = func(f); 689 out0 = f + g; 690 ${OUTPUT} 691 } 692 "" 693 end 694 695 case out_lowp_float 696 values 697 { 698 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 699 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 700 } 701 702 both "" 703 precision mediump float; 704 precision mediump int; 705 ${DECLARATIONS} 706 707 void func (out lowp float a) 708 { 709 a = -1.0; 710 } 711 712 void main() 713 { 714 ${SETUP} 715 float f = 1.0; 716 func(f); 717 out0 = f * in0; 718 ${OUTPUT} 719 } 720 "" 721 end 722 723 case inout_lowp_float 724 values 725 { 726 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 727 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 728 } 729 730 both "" 731 precision mediump float; 732 precision mediump int; 733 ${DECLARATIONS} 734 735 void func (inout lowp float a) 736 { 737 a = -a; 738 } 739 740 void main() 741 { 742 ${SETUP} 743 float f = 1.0; 744 func(f); 745 out0 = f * in0; 746 ${OUTPUT} 747 } 748 "" 749 end 750 751 case in_highp_float 752 values 753 { 754 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 755 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 756 } 757 758 both "" 759 precision mediump float; 760 precision mediump int; 761 ${DECLARATIONS} 762 763 float func (in highp float a) 764 { 765 a = -a; 766 return 2.0 * a; 767 } 768 769 void main() 770 { 771 ${SETUP} 772 float f = in0; 773 float g = func(f); 774 out0 = f + g; 775 ${OUTPUT} 776 } 777 "" 778 end 779 780 case out_highp_float 781 values 782 { 783 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 784 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 785 } 786 787 both "" 788 precision mediump float; 789 precision mediump int; 790 ${DECLARATIONS} 791 792 void func (out highp float a) 793 { 794 a = -1.0; 795 } 796 797 void main() 798 { 799 ${SETUP} 800 float f = 1.0; 801 func(f); 802 out0 = f * in0; 803 ${OUTPUT} 804 } 805 "" 806 end 807 808 case inout_highp_float 809 values 810 { 811 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 812 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 813 } 814 815 both "" 816 precision mediump float; 817 precision mediump int; 818 ${DECLARATIONS} 819 820 void func (inout highp float a) 821 { 822 a = -a; 823 } 824 825 void main() 826 { 827 ${SETUP} 828 float f = 1.0; 829 func(f); 830 out0 = f * in0; 831 ${OUTPUT} 832 } 833 "" 834 end 835 836 case const_float 837 values 838 { 839 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 840 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 841 } 842 843 both "" 844 precision mediump float; 845 precision mediump int; 846 ${DECLARATIONS} 847 848 float func (const float a) 849 { 850 float b = -a; 851 return 2.0 * b; 852 } 853 854 void main() 855 { 856 ${SETUP} 857 float f = in0; 858 float g = func(f); 859 out0 = f + g; 860 ${OUTPUT} 861 } 862 "" 863 end 864 865 case const_in_float 866 values 867 { 868 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 869 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 870 } 871 872 both "" 873 precision mediump float; 874 precision mediump int; 875 ${DECLARATIONS} 876 877 float func (const in float a) 878 { 879 float b = -a; 880 return 2.0 * b; 881 } 882 883 void main() 884 { 885 ${SETUP} 886 float f = in0; 887 float g = func(f); 888 out0 = f + g; 889 ${OUTPUT} 890 } 891 "" 892 end 893 894 case in_int 895 values 896 { 897 input int in0 = [ 0 | 1 | -2 | 4 ]; 898 output int out0 = [ 0 | -1 | 2 | -4 ]; 899 } 900 901 both "" 902 precision mediump float; 903 precision mediump int; 904 ${DECLARATIONS} 905 906 int func (in int a) 907 { 908 a = -a; 909 return 2 * a; 910 } 911 912 void main() 913 { 914 ${SETUP} 915 int f = in0; 916 int g = func(f); 917 out0 = f + g; 918 ${OUTPUT} 919 } 920 "" 921 end 922 923 case out_int 924 values 925 { 926 input int in0 = [ 0 | 1 | -2 | 6 ]; 927 output int out0 = [ 0 | -1 | 2 | -6 ]; 928 } 929 930 both "" 931 precision mediump float; 932 precision mediump int; 933 ${DECLARATIONS} 934 935 void func (out int a) 936 { 937 a = -1; 938 } 939 940 void main() 941 { 942 ${SETUP} 943 int f = 1; 944 func(f); 945 out0 = f * in0; 946 ${OUTPUT} 947 } 948 "" 949 end 950 951 case inout_int 952 values 953 { 954 input int in0 = [ 0 | 1 | -2 | 6 ]; 955 output int out0 = [ 0 | -1 | 2 | -6 ]; 956 } 957 958 both "" 959 precision mediump float; 960 precision mediump int; 961 ${DECLARATIONS} 962 963 void func (inout int a) 964 { 965 a = -a; 966 } 967 968 void main() 969 { 970 ${SETUP} 971 int f = 1; 972 func(f); 973 out0 = f * in0; 974 ${OUTPUT} 975 } 976 "" 977 end 978 979 case in_lowp_int 980 values 981 { 982 input int in0 = [ 0 | 1 | -2 | 4 ]; 983 output int out0 = [ 0 | -1 | 2 | -4 ]; 984 } 985 986 both "" 987 precision mediump float; 988 precision mediump int; 989 ${DECLARATIONS} 990 991 int func (in lowp int a) 992 { 993 a = -a; 994 return 2 * a; 995 } 996 997 void main() 998 { 999 ${SETUP} 1000 int f = in0; 1001 int g = func(f); 1002 out0 = f + g; 1003 ${OUTPUT} 1004 } 1005 "" 1006 end 1007 1008 case out_lowp_int 1009 values 1010 { 1011 input int in0 = [ 0 | 1 | -2 | 6 ]; 1012 output int out0 = [ 0 | -1 | 2 | -6 ]; 1013 } 1014 1015 both "" 1016 precision mediump float; 1017 precision mediump int; 1018 ${DECLARATIONS} 1019 1020 void func (out lowp int a) 1021 { 1022 a = -1; 1023 } 1024 1025 void main() 1026 { 1027 ${SETUP} 1028 int f = 1; 1029 func(f); 1030 out0 = f * in0; 1031 ${OUTPUT} 1032 } 1033 "" 1034 end 1035 1036 case inout_lowp_int 1037 values 1038 { 1039 input int in0 = [ 0 | 1 | -2 | 6 ]; 1040 output int out0 = [ 0 | -1 | 2 | -6 ]; 1041 } 1042 1043 both "" 1044 precision mediump float; 1045 precision mediump int; 1046 ${DECLARATIONS} 1047 1048 void func (inout lowp int a) 1049 { 1050 a = -a; 1051 } 1052 1053 void main() 1054 { 1055 ${SETUP} 1056 int f = 1; 1057 func(f); 1058 out0 = f * in0; 1059 ${OUTPUT} 1060 } 1061 "" 1062 end 1063 1064 case in_highp_int 1065 values 1066 { 1067 input int in0 = [ 0 | 1 | -2 | 4 ]; 1068 output int out0 = [ 0 | -1 | 2 | -4 ]; 1069 } 1070 1071 both "" 1072 precision mediump float; 1073 precision mediump int; 1074 ${DECLARATIONS} 1075 1076 int func (in highp int a) 1077 { 1078 a = -a; 1079 return 2 * a; 1080 } 1081 1082 void main() 1083 { 1084 ${SETUP} 1085 int f = in0; 1086 int g = func(f); 1087 out0 = f + g; 1088 ${OUTPUT} 1089 } 1090 "" 1091 end 1092 1093 case out_highp_int 1094 values 1095 { 1096 input int in0 = [ 0 | 1 | -2 | 6 ]; 1097 output int out0 = [ 0 | -1 | 2 | -6 ]; 1098 } 1099 1100 both "" 1101 precision mediump float; 1102 precision mediump int; 1103 ${DECLARATIONS} 1104 1105 void func (out highp int a) 1106 { 1107 a = -1; 1108 } 1109 1110 void main() 1111 { 1112 ${SETUP} 1113 int f = 1; 1114 func(f); 1115 out0 = f * in0; 1116 ${OUTPUT} 1117 } 1118 "" 1119 end 1120 1121 case inout_highp_int 1122 values 1123 { 1124 input int in0 = [ 0 | 1 | -2 | 6 ]; 1125 output int out0 = [ 0 | -1 | 2 | -6 ]; 1126 } 1127 1128 both "" 1129 precision mediump float; 1130 precision mediump int; 1131 ${DECLARATIONS} 1132 1133 void func (inout highp int a) 1134 { 1135 a = -a; 1136 } 1137 1138 void main() 1139 { 1140 ${SETUP} 1141 int f = 1; 1142 func(f); 1143 out0 = f * in0; 1144 ${OUTPUT} 1145 } 1146 "" 1147 end 1148 1149 case const_int 1150 values 1151 { 1152 input int in0 = [ 0 | 1 | -2 | 4 ]; 1153 output int out0 = [ 0 | -1 | 2 | -4 ]; 1154 } 1155 1156 both "" 1157 precision mediump float; 1158 precision mediump int; 1159 ${DECLARATIONS} 1160 1161 int func (const int a) 1162 { 1163 int b = -a; 1164 return 2 * b; 1165 } 1166 1167 void main() 1168 { 1169 ${SETUP} 1170 int f = in0; 1171 int g = func(f); 1172 out0 = f + g; 1173 ${OUTPUT} 1174 } 1175 "" 1176 end 1177 1178 case const_in_int 1179 values 1180 { 1181 input int in0 = [ 0 | 1 | -2 | 4 ]; 1182 output int out0 = [ 0 | -1 | 2 | -4 ]; 1183 } 1184 1185 both "" 1186 precision mediump float; 1187 precision mediump int; 1188 ${DECLARATIONS} 1189 1190 int func (const in int a) 1191 { 1192 int b = -a; 1193 return 2 * b; 1194 } 1195 1196 void main() 1197 { 1198 ${SETUP} 1199 int f = in0; 1200 int g = func(f); 1201 out0 = f + g; 1202 ${OUTPUT} 1203 } 1204 "" 1205 end 1206 1207 case in_bool 1208 values 1209 { 1210 input bool in0 = [ true | false ]; 1211 output bool out0 = [ true | true ]; 1212 } 1213 1214 both "" 1215 precision mediump float; 1216 ${DECLARATIONS} 1217 1218 bool func (in bool a) 1219 { 1220 a = !a; 1221 return a; 1222 } 1223 1224 void main() 1225 { 1226 ${SETUP} 1227 bool f = in0; 1228 bool g = func(f); 1229 out0 = (f != g); 1230 ${OUTPUT} 1231 } 1232 "" 1233 end 1234 1235 case out_bool 1236 values 1237 { 1238 input bool in0 = [ true | false ]; 1239 output bool out0 = [ false | true ]; 1240 } 1241 1242 both "" 1243 precision mediump float; 1244 ${DECLARATIONS} 1245 1246 void func (out bool a) 1247 { 1248 a = false; 1249 } 1250 1251 void main() 1252 { 1253 ${SETUP} 1254 bool f = true; 1255 func(f); 1256 out0 = (in0 == f); 1257 ${OUTPUT} 1258 } 1259 "" 1260 end 1261 1262 case inout_bool 1263 values 1264 { 1265 input bool in0 = [ true | false ]; 1266 output bool out0 = [ false | true ]; 1267 } 1268 1269 both "" 1270 precision mediump float; 1271 ${DECLARATIONS} 1272 1273 void func (inout bool a) 1274 { 1275 a = !a; 1276 } 1277 1278 void main() 1279 { 1280 ${SETUP} 1281 bool f = true; 1282 func(f); 1283 out0 = (in0 == f); 1284 ${OUTPUT} 1285 } 1286 "" 1287 end 1288 1289 end # qualifiers 1290 1291 group declarations "Function Declarations" 1292 1293 case void_vs_no_void 1294 values 1295 { 1296 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1297 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1298 } 1299 1300 both "" 1301 precision mediump float; 1302 ${DECLARATIONS} 1303 1304 float func (); 1305 1306 void main() 1307 { 1308 out0 = func() * in0; 1309 ${OUTPUT} 1310 } 1311 1312 float func (void) 1313 { 1314 return -1.0; 1315 } 1316 "" 1317 end 1318 1319 case in_vs_no_in 1320 values 1321 { 1322 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1323 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1324 } 1325 1326 both "" 1327 precision mediump float; 1328 ${DECLARATIONS} 1329 1330 float func (float f); 1331 1332 void main() 1333 { 1334 out0 = func(in0); 1335 ${OUTPUT} 1336 } 1337 1338 float func (in float f) 1339 { 1340 return -f; 1341 } 1342 "" 1343 end 1344 1345 case default_vs_explicit_precision 1346 values 1347 { 1348 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1349 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1350 } 1351 1352 both "" 1353 precision mediump float; 1354 ${DECLARATIONS} 1355 1356 float func (float f); 1357 1358 void main() 1359 { 1360 out0 = func(in0); 1361 ${OUTPUT} 1362 } 1363 1364 float func (mediump float f) 1365 { 1366 return -f; 1367 } 1368 "" 1369 end 1370 1371 end # declarations 1372 1373 group overloading "Function Overloading" 1374 1375 case user_func_arg_type_simple 1376 values 1377 { 1378 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1379 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1380 } 1381 1382 both "" 1383 precision mediump float; 1384 precision mediump int; 1385 ${DECLARATIONS} 1386 1387 float func (float a) 1388 { 1389 return -a; 1390 } 1391 1392 int func (int a) 1393 { 1394 return -a; 1395 } 1396 1397 void main() 1398 { 1399 out0 = func(in0) * float(func(-1)); 1400 ${OUTPUT} 1401 } 1402 "" 1403 end 1404 1405 case user_func_arg_float_types 1406 values 1407 { 1408 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1409 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1410 } 1411 1412 both "" 1413 precision mediump float; 1414 precision mediump int; 1415 ${DECLARATIONS} 1416 1417 float func (float a) { return -a; } 1418 vec2 func (vec2 a) { return a.yx; } 1419 vec3 func (vec3 a) { return a.xxx; } 1420 vec4 func (vec4 a) { return a.wwww; } 1421 1422 void main() 1423 { 1424 out0 = func(func(func(func(vec4(in0)).xyz).xy).x); 1425 ${OUTPUT} 1426 } 1427 "" 1428 end 1429 1430 case user_func_arg_int_types 1431 values 1432 { 1433 input int in0 = [ 0 | 1 | -2 | 6 ]; 1434 output int out0 = [ 0 | -1 | 2 | -6 ]; 1435 } 1436 1437 both "" 1438 precision mediump float; 1439 precision mediump int; 1440 ${DECLARATIONS} 1441 1442 int func (int a) { return -a; } 1443 ivec2 func (ivec2 a) { return a.yx; } 1444 ivec3 func (ivec3 a) { return a.xxx; } 1445 ivec4 func (ivec4 a) { return a.wwww; } 1446 1447 void main() 1448 { 1449 ${SETUP} 1450 out0 = func(func(func(func(ivec4(in0)).xyz).xy).x); 1451 ${OUTPUT} 1452 } 1453 "" 1454 end 1455 1456 case user_func_arg_bool_types 1457 values 1458 { 1459 input bool in0 = [ true | false ]; 1460 output bool out0 = [ false | true ]; 1461 } 1462 1463 both "" 1464 precision mediump float; 1465 ${DECLARATIONS} 1466 1467 bool func (bool a) { return !a; } 1468 bvec2 func (bvec2 a) { return a.yx; } 1469 bvec3 func (bvec3 a) { return a.xxx; } 1470 bvec4 func (bvec4 a) { return a.wwww; } 1471 1472 void main() 1473 { 1474 ${SETUP} 1475 out0 = func(func(func(func(bvec4(in0)).xyz).xy).x); 1476 ${OUTPUT} 1477 } 1478 "" 1479 end 1480 1481 case user_func_arg_basic_types 1482 values 1483 { 1484 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1485 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1486 } 1487 1488 both "" 1489 precision mediump float; 1490 precision mediump int; 1491 ${DECLARATIONS} 1492 1493 float func (float a) { return -a; } 1494 vec2 func (vec2 a) { return a.yx; } 1495 vec3 func (vec3 a) { return a.xxx; } 1496 vec4 func (vec4 a) { return a.wwww; } 1497 int func (int a) { return -a; } 1498 ivec2 func (ivec2 a) { return a.yx; } 1499 ivec3 func (ivec3 a) { return a.xxx; } 1500 ivec4 func (ivec4 a) { return a.wwww; } 1501 bool func (bool a) { return !a; } 1502 bvec2 func (bvec2 a) { return a.yx; } 1503 bvec3 func (bvec3 a) { return a.xxx; } 1504 bvec4 func (bvec4 a) { return a.wwww; } 1505 1506 void main() 1507 { 1508 ${SETUP} 1509 if (func(func(bvec4(false)).x)) 1510 out0 = func(in0) * float(func(-1)); 1511 else 1512 out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x); 1513 ${OUTPUT} 1514 } 1515 "" 1516 end 1517 1518 case user_func_arg_complex_types 1519 values 1520 { 1521 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1522 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1523 } 1524 1525 both "" 1526 precision mediump float; 1527 precision mediump int; 1528 ${DECLARATIONS} 1529 1530 struct Pos { float a, b, c; }; 1531 struct Line { Pos start, end; }; 1532 1533 float func (float a) { return -a; } 1534 float func (float a[4]) { return a[0] + a[3]; } 1535 vec2 func (vec2 a) { return a.yx; } 1536 vec3 func (vec3 a) { return a.xxx; } 1537 vec4 func (vec4 a) { return a.wwww; } 1538 vec4 func (vec4 a[4]) { return a[1] + a[2]; } 1539 int func (int a) { return -a; } 1540 ivec2 func (ivec2 a) { return a.yx; } 1541 ivec3 func (ivec3 a) { return a.xxx; } 1542 ivec4 func (ivec4 a) { return a.wwww; } 1543 bool func (bool a) { return !a; } 1544 bvec2 func (bvec2 a) { return a.yx; } 1545 bvec3 func (bvec3 a) { return a.xxx; } 1546 bvec4 func (bvec4 a) { return a.wwww; } 1547 Pos func (Pos a) { return a; } 1548 Line func (Line a) { return Line(a.end, a.start); } 1549 1550 void main() 1551 { 1552 ${SETUP} 1553 float arr[4]; 1554 vec4 arr2[4]; 1555 out0 = func(arr) + func(arr2).x; 1556 if (func(func(bvec4(false)).x)) 1557 out0 = func(in0) * float(func(-1)); 1558 else 1559 out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x); 1560 ${OUTPUT} 1561 } 1562 "" 1563 end 1564 1565 case user_func_arguments 1566 values 1567 { 1568 input float in0 = [ 0.0 | 1.0 | -2.0 | 2.5 ]; 1569 output float out0 = [ 0.0 | -1.0 | 2.0 | -2.5 ]; 1570 } 1571 1572 both "" 1573 precision mediump float; 1574 ${DECLARATIONS} 1575 1576 float func (float a) 1577 { 1578 return -a; 1579 } 1580 1581 float func (float a, float b) 1582 { 1583 return a * b; 1584 } 1585 1586 void main() 1587 { 1588 out0 = func(in0) * func(-0.5, -2.0); 1589 ${OUTPUT} 1590 } 1591 "" 1592 end 1593 1594 case builtin_sin 1595 values 1596 { 1597 input int in0 = [ -1 | 0 | 1 | 4 ]; 1598 output int out0 = [ 1 | 0 | -1 | -4 ]; 1599 } 1600 1601 both "" 1602 precision mediump float; 1603 precision mediump int; 1604 ${DECLARATIONS} 1605 1606 int sin(int a) { return -a; } 1607 1608 void main() 1609 { 1610 ${SETUP} 1611 out0 = sin(in0); 1612 ${OUTPUT} 1613 } 1614 "" 1615 end 1616 1617 case builtin_step 1618 values 1619 { 1620 input int in0 = [ -1 | 0 | 1 | 4 ]; 1621 output int out0 = [ 1 | 0 | -1 | -4 ]; 1622 } 1623 1624 both "" 1625 precision mediump float; 1626 precision mediump int; 1627 ${DECLARATIONS} 1628 1629 int step (float i, float j, int a) { return -a; } 1630 1631 void main() 1632 { 1633 ${SETUP} 1634 out0 = step(0.0, 1.0, in0); 1635 ${OUTPUT} 1636 } 1637 "" 1638 end 1639 1640 case array_size 1641 values 1642 { 1643 output float out0 = [ 1.0 ]; 1644 } 1645 1646 both "" 1647 precision mediump float; 1648 ${DECLARATIONS} 1649 1650 float func (float f[3]) 1651 { 1652 return f[0]; 1653 } 1654 1655 float func (float f[4]) 1656 { 1657 return f[1]; 1658 } 1659 1660 void main () 1661 { 1662 ${SETUP} 1663 float x[4]; 1664 x[0] = -1.0; 1665 x[1] = 1.0; 1666 x[2] = x[3] = 0.0; 1667 out0 = func(x); 1668 ${OUTPUT} 1669 } 1670 "" 1671 end 1672 1673 end # overloading 1674 1675 group array_arguments "Arrays as Arguments" 1676 1677 case local_in_float 1678 values 1679 { 1680 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 1681 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 1682 } 1683 1684 both "" 1685 precision mediump float; 1686 ${DECLARATIONS} 1687 1688 float func (in float a[4]) 1689 { 1690 a[0] = -1.0; 1691 a[2] = -4.0; 1692 a[3] = -3.0 * a[1]; 1693 return a[0]; 1694 } 1695 1696 void main() 1697 { 1698 float arr[4]; 1699 arr[0] = in0.x; 1700 arr[1] = in0.y; 1701 arr[2] = in0.z; 1702 arr[3] = in0.w; 1703 float f = func(arr); 1704 out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]); 1705 ${OUTPUT} 1706 } 1707 "" 1708 end 1709 1710 case global_in_float 1711 values 1712 { 1713 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 1714 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 1715 } 1716 1717 both "" 1718 precision mediump float; 1719 ${DECLARATIONS} 1720 1721 float func (in float a[4]) 1722 { 1723 a[0] = -1.0; 1724 a[2] = -4.0; 1725 a[3] = -3.0 * a[1]; 1726 return a[0]; 1727 } 1728 1729 float arr[4]; 1730 1731 void main() 1732 { 1733 arr[0] = in0.x; 1734 arr[1] = in0.y; 1735 arr[2] = in0.z; 1736 arr[3] = in0.w; 1737 float f = func(arr); 1738 out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]); 1739 ${OUTPUT} 1740 } 1741 "" 1742 end 1743 1744 case local_in_int 1745 values 1746 { 1747 input ivec4 in0 = [ ivec4(0, 1, 2, -4) | ivec4(-7, -11, 13, 19) ]; 1748 output ivec4 out0 = [ ivec4(0, -1, -2, 4) | ivec4(7, 11, -13, -19) ]; 1749 } 1750 1751 both "" 1752 precision mediump float; 1753 precision mediump int; 1754 ${DECLARATIONS} 1755 1756 int func (in int a[4]) 1757 { 1758 a[0] = -1; 1759 a[2] = -4; 1760 a[3] = -3 * a[1]; 1761 return a[0]; 1762 } 1763 1764 void main() 1765 { 1766 ${SETUP} 1767 int arr[4]; 1768 arr[0] = in0.x; 1769 arr[1] = in0.y; 1770 arr[2] = in0.z; 1771 arr[3] = in0.w; 1772 int f = func(arr); 1773 out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]); 1774 ${OUTPUT} 1775 } 1776 "" 1777 end 1778 1779 case global_in_int 1780 values 1781 { 1782 input ivec4 in0 = [ ivec4(0, 1, 2, 4) | ivec4(-7, -11, 13, 19) ]; 1783 output ivec4 out0 = [ ivec4(0, -1, -2, -4) | ivec4(7, 11, -13, -19) ]; 1784 } 1785 1786 both "" 1787 precision mediump float; 1788 precision mediump int; 1789 ${DECLARATIONS} 1790 1791 int func (in int a[4]) 1792 { 1793 a[0] = -1; 1794 a[2] = -4; 1795 a[3] = -3 * a[1]; 1796 return a[0]; 1797 } 1798 1799 int arr[4]; 1800 1801 void main() 1802 { 1803 ${SETUP} 1804 arr[0] = in0.x; 1805 arr[1] = in0.y; 1806 arr[2] = in0.z; 1807 arr[3] = in0.w; 1808 int f = func(arr); 1809 out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]); 1810 ${OUTPUT} 1811 } 1812 1813 "" 1814 end 1815 1816 case local_in_bool 1817 values 1818 { 1819 input bvec4 in0 = [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ]; 1820 output bvec4 out0 = [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ]; 1821 } 1822 1823 both "" 1824 precision mediump float; 1825 ${DECLARATIONS} 1826 1827 bool func (in bool a[4]) 1828 { 1829 a[0] = false; 1830 a[2] = true; 1831 a[3] = !a[1]; 1832 return a[0]; 1833 } 1834 1835 void main() 1836 { 1837 ${SETUP} 1838 bool arr[4]; 1839 arr[0] = !in0.x; 1840 arr[1] = !in0.y; 1841 arr[2] = !in0.z; 1842 arr[3] = !in0.w; 1843 func(arr); 1844 out0 = bvec4(arr[0], arr[1], arr[2], arr[3]); 1845 ${OUTPUT} 1846 } 1847 "" 1848 end 1849 1850 case global_in_bool 1851 values 1852 { 1853 input bvec4 in0 = [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ]; 1854 output bvec4 out0 = [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ]; 1855 } 1856 1857 both "" 1858 precision mediump float; 1859 ${DECLARATIONS} 1860 1861 bool func (in bool a[4]) 1862 { 1863 a[0] = false; 1864 a[2] = true; 1865 a[3] = !a[1]; 1866 return a[0]; 1867 } 1868 1869 bool arr[4]; 1870 1871 void main() 1872 { 1873 ${SETUP} 1874 arr[0] = !in0.x; 1875 arr[1] = !in0.y; 1876 arr[2] = !in0.z; 1877 arr[3] = !in0.w; 1878 func(arr); 1879 out0 = bvec4(arr[0], arr[1], arr[2], arr[3]); 1880 ${OUTPUT} 1881 } 1882 "" 1883 end 1884 1885 case test_helpers 1886 desc "Check that helper functions are supported properly." 1887 values 1888 { 1889 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 1890 output float out0 = [ 1.0 | 1.0 ]; 1891 } 1892 1893 both "" 1894 precision mediump float; 1895 ${DECLARATIONS} 1896 1897 vec4 get (in float arr[4]); 1898 void set (out float arr[4], vec4 val); 1899 void negate (inout float arr[4]); 1900 bool test (in float arr[4], vec4 ref); 1901 bool isEqual (in float a[4], in float b[4]); 1902 1903 void main() 1904 { 1905 float arr[4]; 1906 set(arr, in0); 1907 negate(arr); 1908 out0 = float(test(arr, -in0)); 1909 ${OUTPUT} 1910 } 1911 1912 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 1913 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 1914 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 1915 void negate (inout float arr[4]) { set(arr, -get(arr)); } 1916 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 1917 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 1918 "" 1919 end 1920 1921 case copy_local_in_on_call 1922 desc "Check that local 'in' arguments are copied on call and don't alias." 1923 values 1924 { 1925 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 1926 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 1927 } 1928 1929 both "" 1930 precision mediump float; 1931 ${DECLARATIONS} 1932 1933 vec4 get (in float arr[4]); 1934 void set (out float arr[4], vec4 val); 1935 void negate (inout float arr[4]); 1936 bool test (in float arr[4], vec4 ref); 1937 bool isEqual (in float a[4], in float b[4]); 1938 1939 float func (in float a[4], in float b[4]) 1940 { 1941 a[0] = 2.123; 1942 a[2] = -4.123; 1943 return isEqual(a, b) ? 1.0 : -1.0; 1944 } 1945 1946 void main() 1947 { 1948 float arr[4]; 1949 set(arr, in0); 1950 out0 = in0 * func(arr, arr); 1951 ${OUTPUT} 1952 } 1953 1954 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 1955 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 1956 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 1957 void negate (inout float arr[4]) { set(arr, -get(arr)); } 1958 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 1959 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 1960 "" 1961 end 1962 1963 case copy_global_in_on_call 1964 desc "Check that global 'in' arguments are copied on call and don't alias." 1965 values 1966 { 1967 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 1968 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 1969 } 1970 1971 both "" 1972 precision mediump float; 1973 ${DECLARATIONS} 1974 1975 vec4 get (in float arr[4]); 1976 void set (out float arr[4], vec4 val); 1977 void negate (inout float arr[4]); 1978 bool test (in float arr[4], vec4 ref); 1979 bool isEqual (in float a[4], in float b[4]); 1980 1981 float func (in float a[4], in float b[4]) 1982 { 1983 a[0] = 2.123; 1984 a[2] = -4.123; 1985 return isEqual(a, b) ? 1.0 : -1.0; 1986 } 1987 1988 float arr[4]; 1989 1990 void main() 1991 { 1992 set(arr, in0); 1993 out0 = in0 * func(arr, arr); 1994 ${OUTPUT} 1995 } 1996 1997 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 1998 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 1999 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 2000 void negate (inout float arr[4]) { set(arr, -get(arr)); } 2001 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 2002 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 2003 "" 2004 end 2005 2006 case copy_local_inout_on_call 2007 desc "Check that local 'in' arguments are copied on call and don't alias." 2008 values 2009 { 2010 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 2011 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 2012 } 2013 2014 both "" 2015 precision mediump float; 2016 ${DECLARATIONS} 2017 2018 vec4 get (in float arr[4]); 2019 void set (out float arr[4], vec4 val); 2020 void negate (inout float arr[4]); 2021 bool test (in float arr[4], vec4 ref); 2022 bool isEqual (in float a[4], in float b[4]); 2023 2024 float func (inout float a[4], inout float b[4]) 2025 { 2026 negate(a); 2027 return isEqual(a, b) ? 1.0 : -1.0; 2028 } 2029 2030 void main() 2031 { 2032 float arr[4]; 2033 set(arr, in0); 2034 float m = func(arr, arr); // returns -1.0 2035 float n = float(test(arr, in0) || test(arr, -in0)); 2036 out0 = in0 * m * n; 2037 ${OUTPUT} 2038 } 2039 2040 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 2041 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 2042 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 2043 void negate (inout float arr[4]) { set(arr, -get(arr)); } 2044 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 2045 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 2046 "" 2047 end 2048 2049 case copy_global_inout_on_call 2050 desc "Check that global 'in' arguments are copied on call and don't alias." 2051 values 2052 { 2053 input vec4 in0 = [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ]; 2054 output vec4 out0 = [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ]; 2055 } 2056 2057 both "" 2058 precision mediump float; 2059 ${DECLARATIONS} 2060 2061 vec4 get (in float arr[4]); 2062 void set (out float arr[4], vec4 val); 2063 void negate (inout float arr[4]); 2064 bool test (in float arr[4], vec4 ref); 2065 bool isEqual (in float a[4], in float b[4]); 2066 2067 float func (in float a[4], in float b[4]) 2068 { 2069 negate(a); 2070 return isEqual(a, b) ? 1.0 : -1.0; 2071 } 2072 2073 float arr[4]; 2074 2075 void main() 2076 { 2077 set(arr, in0); 2078 float m = func(arr, arr); // returns -1.0 2079 float n = float(test(arr, in0) || test(arr, -in0)); 2080 out0 = in0 * m * n; 2081 ${OUTPUT} 2082 } 2083 2084 float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 2085 vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 2086 void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 2087 void negate (inout float arr[4]) { set(arr, -get(arr)); } 2088 bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 2089 bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 2090 "" 2091 end 2092 2093 # vec4 get (in float arr[4]); 2094 # void set (out float arr[4], vec4 val); 2095 # void negate (inout float arr[4]); 2096 # bool test (in float arr[4], vec4 ref); 2097 # bool isEqual (in float a[4], in float b[4]); 2098 2099 # float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); } 2100 # vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); } 2101 # void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; } 2102 # void negate (inout float arr[4]) { set(arr, -get(arr)); } 2103 # bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); } 2104 # bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); } 2105 2106 end # array_arguments 2107 2108 #group qualifiers "Function Parameter Qualifiers" 2109 # 2110 #end # qualifiers 2111 2112 group control_flow "Control Flow In Functions" 2113 2114 case simple_return 2115 values 2116 { 2117 input float in0 = [ -0.5 | 1.5 ]; 2118 output float out0 = [ 0.5 | -1.5 ]; 2119 } 2120 2121 both "" 2122 precision mediump float; 2123 ${DECLARATIONS} 2124 2125 float func (float a) 2126 { 2127 return -a; 2128 a = a * -1.0; 2129 return 1.0; 2130 } 2131 2132 void main() 2133 { 2134 ${SETUP} 2135 out0 = func(in0); 2136 ${OUTPUT} 2137 } 2138 "" 2139 end 2140 2141 case return_in_if 2142 values 2143 { 2144 input float in0 = [ -0.5 | 1.5 ]; 2145 output float out0 = [ 0.5 | -1.5 ]; 2146 } 2147 2148 both "" 2149 precision mediump float; 2150 ${DECLARATIONS} 2151 2152 float func (float a) 2153 { 2154 if (a != 0.0) 2155 return -a; 2156 return 1.0; 2157 } 2158 2159 void main() 2160 { 2161 ${SETUP} 2162 out0 = func(in0); 2163 ${OUTPUT} 2164 } 2165 "" 2166 end 2167 2168 case return_in_else 2169 values 2170 { 2171 input float in0 = [ -0.5 | 1.5 ]; 2172 output float out0 = [ 0.5 | -1.5 ]; 2173 } 2174 2175 both "" 2176 precision mediump float; 2177 ${DECLARATIONS} 2178 2179 float func (float a) 2180 { 2181 if (a == 0.0) 2182 return 1.0; 2183 else 2184 return -a; 2185 return 1.0; 2186 } 2187 2188 void main() 2189 { 2190 ${SETUP} 2191 out0 = func(in0); 2192 ${OUTPUT} 2193 } 2194 "" 2195 end 2196 2197 case return_in_loop 2198 values 2199 { 2200 input float in0 = [ -0.5 | 1.5 ]; 2201 output float out0 = [ 0.5 | -1.5 ]; 2202 } 2203 2204 both "" 2205 precision mediump float; 2206 ${DECLARATIONS} 2207 2208 float func (float a) 2209 { 2210 for (int i = 0; i < 1; i++) 2211 return -a; 2212 return 1.0; 2213 } 2214 2215 void main() 2216 { 2217 ${SETUP} 2218 out0 = func(in0); 2219 ${OUTPUT} 2220 } 2221 "" 2222 end 2223 2224 case return_in_loop_if 2225 values 2226 { 2227 input float in0 = [ -0.5 | 1.5 ]; 2228 output float out0 = [ 0.5 | -1.5 ]; 2229 } 2230 2231 both "" 2232 precision mediump float; 2233 ${DECLARATIONS} 2234 2235 float func (float a) 2236 { 2237 for (int i = 0; i < 3; i++) 2238 { 2239 if (i == 1) 2240 return a; 2241 else if (i > 1) 2242 return -1.0; 2243 a = -a; 2244 } 2245 return 1.0; 2246 } 2247 2248 void main() 2249 { 2250 ${SETUP} 2251 out0 = func(in0); 2252 ${OUTPUT} 2253 } 2254 "" 2255 end 2256 2257 case return_after_loop 2258 values 2259 { 2260 input float in0 = [ -0.5 | 1.5 ]; 2261 output float out0 = [ 0.5 | -1.5 ]; 2262 } 2263 2264 both "" 2265 precision mediump float; 2266 ${DECLARATIONS} 2267 2268 float func (float a) 2269 { 2270 for (int i = 0; i < 5; i++) 2271 a = -a; 2272 return a; 2273 } 2274 2275 void main() 2276 { 2277 ${SETUP} 2278 out0 = func(in0); 2279 ${OUTPUT} 2280 } 2281 "" 2282 end 2283 2284 case return_after_break 2285 values 2286 { 2287 input float in0 = [ -0.5 | 1.5 ]; 2288 output float out0 = [ 0.5 | -1.5 ]; 2289 } 2290 2291 both "" 2292 precision mediump float; 2293 ${DECLARATIONS} 2294 2295 float func (float a) 2296 { 2297 for (int i = 0; i < 6; i++) 2298 { 2299 a = -a; 2300 if (i == 4) 2301 break; 2302 } 2303 return a; 2304 } 2305 2306 void main() 2307 { 2308 ${SETUP} 2309 out0 = func(in0); 2310 ${OUTPUT} 2311 } 2312 "" 2313 end 2314 2315 case return_after_continue 2316 values 2317 { 2318 input float in0 = [ -0.5 | 1.5 ]; 2319 output float out0 = [ 0.5 | -1.5 ]; 2320 } 2321 2322 both "" 2323 precision mediump float; 2324 ${DECLARATIONS} 2325 2326 float func (float a) 2327 { 2328 for (int i = 0; i < 6; i++) 2329 { 2330 if (i == 4) 2331 continue; 2332 a = -a; 2333 } 2334 return a; 2335 } 2336 2337 void main() 2338 { 2339 ${SETUP} 2340 out0 = func(in0); 2341 ${OUTPUT} 2342 } 2343 "" 2344 end 2345 2346 case return_in_nested_loop 2347 values 2348 { 2349 input float in0 = [ -0.5 | 1.5 ]; 2350 output float out0 = [ 0.5 | -1.5 ]; 2351 } 2352 2353 both "" 2354 precision mediump float; 2355 ${DECLARATIONS} 2356 2357 float func (float a) 2358 { 2359 for (int i = 0; i < 6; i++) 2360 { 2361 a = -a; 2362 for (int j = 0; j < 4; j++) 2363 { 2364 a = -a; 2365 if (i == 1) 2366 return a; 2367 } 2368 if (i == 4) 2369 return 1.0; 2370 } 2371 return 1.0; 2372 } 2373 2374 void main() 2375 { 2376 ${SETUP} 2377 out0 = func(in0); 2378 ${OUTPUT} 2379 } 2380 "" 2381 end 2382 2383 case return_after_loop_sequence 2384 require full_glsl_es_100_support 2385 2386 values 2387 { 2388 input float in0 = [ -0.5 | 1.5 ]; 2389 output float out0 = [ 0.5 | -1.5 ]; 2390 } 2391 2392 both "" 2393 precision mediump float; 2394 ${DECLARATIONS} 2395 2396 float func (float a) 2397 { 2398 int i; 2399 for (i = 0; i < 6; i++) // negate a 2400 { 2401 a = -a; 2402 if (i == 4) 2403 a = -a; 2404 } 2405 2406 for (; i < 10; i++) // keep a 2407 { 2408 if (i == 8) 2409 continue; 2410 else if (i == 9) 2411 break; 2412 a = -a; 2413 } 2414 2415 return a; 2416 } 2417 2418 void main() 2419 { 2420 ${SETUP} 2421 out0 = func(in0); 2422 ${OUTPUT} 2423 } 2424 "" 2425 end 2426 2427 case mixed_return_break_continue 2428 values 2429 { 2430 input float in0 = [ -0.5 | 1.5 ]; 2431 output float out0 = [ 0.5 | -1.5 ]; 2432 } 2433 2434 both "" 2435 precision mediump float; 2436 ${DECLARATIONS} 2437 2438 float func (float a) 2439 { 2440 for (int i = 0; i < 6; i++) 2441 { 2442 if (i == 0) 2443 continue; 2444 else if (i == 1) 2445 { 2446 } 2447 else if (i == 3) 2448 break; 2449 else 2450 return a; 2451 a = -a; 2452 } 2453 2454 return 1.0; 2455 } 2456 2457 void main() 2458 { 2459 ${SETUP} 2460 out0 = func(in0); 2461 ${OUTPUT} 2462 } 2463 "" 2464 end 2465 2466 end # control_flow 2467 2468 group misc "Miscellaneous" 2469 2470 case multi_arg_float 2471 values 2472 { 2473 input vec4 in0 = [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ]; 2474 output float out0 = [ 0.5 | -1.5 ]; # -sum(in0) 2475 } 2476 2477 both "" 2478 precision mediump float; 2479 ${DECLARATIONS} 2480 2481 float sum(vec4 v) { return (v.x + v.y + v.z + v.w); } 2482 2483 float func (float a, vec3 b, vec2 c, vec2 d, vec4 e) 2484 { 2485 return -sum(vec4(a, b) + vec4(c, d)) + sum(e); 2486 } 2487 2488 void main() 2489 { 2490 ${SETUP} 2491 out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0); 2492 ${OUTPUT} 2493 } 2494 "" 2495 end 2496 2497 case multi_arg_int 2498 values 2499 { 2500 input ivec4 in0 = [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ]; 2501 output int out0 = [ -3 | 1 ]; 2502 } 2503 2504 both "" 2505 precision mediump float; 2506 precision mediump int; 2507 ${DECLARATIONS} 2508 2509 int sum(ivec4 v) { return (v.x + v.y + v.z + v.w); } 2510 2511 int func (int a, ivec3 b, ivec2 c, ivec2 d, ivec4 e) 2512 { 2513 return -sum(ivec4(a, b) + ivec4(c, d)) + sum(e); 2514 } 2515 2516 void main() 2517 { 2518 ${SETUP} 2519 out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0); 2520 ${OUTPUT} 2521 } 2522 "" 2523 end 2524 2525 case argument_eval_order_1 2526 values 2527 { 2528 input int in0 = [ 0 | 1 | 3 | 5 ]; 2529 output int out0 = [ -1 | 5 | 11 | 17 ]; 2530 } 2531 2532 both "" 2533 precision mediump float; 2534 ${DECLARATIONS} 2535 2536 int func (float a, int b, bool c, int d) 2537 { 2538 if (c) 2539 return b + int(a) + d; 2540 else 2541 return -1; 2542 } 2543 2544 void main () 2545 { 2546 ${SETUP} 2547 float v0 = float(in0); 2548 int v1 = in0; 2549 out0 = func((v0 += 1.0), v1++, (v0 > 1.5), v1); 2550 ${OUTPUT} 2551 } 2552 "" 2553 end 2554 2555 case argument_eval_order_2 2556 values 2557 { 2558 input int in0 = [ 0 | -1 | 3 | 5 ]; 2559 output int out0 = [ 3 | -1 | 9 | 13 ]; 2560 } 2561 2562 both "" 2563 precision mediump float; 2564 ${DECLARATIONS} 2565 2566 int g; 2567 2568 int modG (int v) 2569 { 2570 g += v; 2571 return v; 2572 } 2573 2574 int func (float a, int b, bool c, int d) 2575 { 2576 if (c) 2577 return b + int(a) + d; 2578 else 2579 return -1; 2580 } 2581 2582 void main () 2583 { 2584 ${SETUP} 2585 out0 = func(float(g = in0), modG(2), --g > 0, g); 2586 ${OUTPUT} 2587 } 2588 "" 2589 end 2590 2591 case missing_returns 2592 values 2593 { 2594 input float in0 = [ 1.0 | 2.0 | 3.0 ]; 2595 output float out0 = [ -1.0 | -2.0 | -3.0 ]; 2596 } 2597 both "" 2598 // Note specification says that returned value is undefined if no return 2599 // statement has been executed. In this case func() is called only with 2600 // positive values. 2601 precision mediump float; 2602 ${DECLARATIONS} 2603 2604 float func (float f) 2605 { 2606 if (f > 0.0) 2607 return -f; 2608 } 2609 2610 void main () 2611 { 2612 ${SETUP} 2613 out0 = func(in0); 2614 ${OUTPUT} 2615 } 2616 "" 2617 end 2618 2619 end # misc 2620 2621 group invalid "Invalid Functions" 2622 case break_in_body 2623 expect compile_fail 2624 both "" 2625 precision mediump float; 2626 2627 void func () 2628 { 2629 break; 2630 } 2631 2632 void main () 2633 { 2634 ${POSITION_FRAG_COLOR} = vec4(1.0); 2635 } 2636 "" 2637 end 2638 2639 case continue_in_body 2640 expect compile_fail 2641 both "" 2642 precision mediump float; 2643 2644 void func () 2645 { 2646 continue; 2647 } 2648 2649 void main () 2650 { 2651 ${POSITION_FRAG_COLOR} = vec4(1.0); 2652 } 2653 "" 2654 end 2655 2656 case return_value_from_void_function 2657 expect compile_fail 2658 both "" 2659 precision mediump float; 2660 2661 void func () 2662 { 2663 return 1.0; 2664 } 2665 2666 void main () 2667 { 2668 ${POSITION_FRAG_COLOR} = vec4(1.0); 2669 } 2670 "" 2671 end 2672 2673 case extra_arguments 2674 expect compile_fail 2675 both "" 2676 precision mediump float; 2677 2678 void func (float f) 2679 { 2680 } 2681 2682 void main () 2683 { 2684 func(1.0, 2.0); 2685 ${POSITION_FRAG_COLOR} = vec4(1.0); 2686 } 2687 "" 2688 end 2689 2690 case missing_arguments 2691 expect compile_fail 2692 both "" 2693 precision mediump float; 2694 2695 void func (float f) 2696 { 2697 } 2698 2699 void main () 2700 { 2701 func(); 2702 ${POSITION_FRAG_COLOR} = vec4(1.0); 2703 } 2704 "" 2705 end 2706 2707 case missing_argument_type 2708 expect compile_fail 2709 both "" 2710 precision mediump float; 2711 2712 void func (in f) 2713 { 2714 } 2715 2716 void main () 2717 { 2718 ${POSITION_FRAG_COLOR} = vec4(1.0); 2719 } 2720 "" 2721 end 2722 2723 case argument_basetype_mismatch 2724 expect compile_fail 2725 both "" 2726 precision mediump float; 2727 precision mediump int; 2728 2729 void func (float f) 2730 { 2731 } 2732 2733 void main () 2734 { 2735 func(2); 2736 ${POSITION_FRAG_COLOR} = vec4(1.0); 2737 } 2738 "" 2739 end 2740 2741 case argument_scalar_vector_mismatch 2742 expect compile_fail 2743 both "" 2744 precision mediump float; 2745 2746 void func (vec2 f) 2747 { 2748 } 2749 2750 void main () 2751 { 2752 func(2.0); 2753 ${POSITION_FRAG_COLOR} = vec4(1.0); 2754 } 2755 "" 2756 end 2757 2758 case argument_vector_size_mismatch 2759 expect compile_fail 2760 both "" 2761 precision mediump float; 2762 2763 void func (vec3 f) 2764 { 2765 } 2766 2767 void main () 2768 { 2769 func(vec2(2.0)); 2770 ${POSITION_FRAG_COLOR} = vec4(1.0); 2771 } 2772 "" 2773 end 2774 2775 case duplicate_function 2776 expect compile_fail 2777 both "" 2778 precision mediump float; 2779 2780 void func (vec3 f); 2781 2782 void func (vec3 f) 2783 { 2784 } 2785 2786 void func (vec3 f) 2787 { 2788 } 2789 2790 void main () 2791 { 2792 ${POSITION_FRAG_COLOR} = vec4(1.0); 2793 } 2794 "" 2795 end 2796 2797 case prototype_mismatch_return_type 2798 expect compile_fail 2799 both "" 2800 precision mediump float; 2801 2802 void func (vec3 f); 2803 2804 void main () 2805 { 2806 ${POSITION_FRAG_COLOR} = vec4(1.0); 2807 } 2808 2809 float func (vec3 f) 2810 { 2811 return f.x; 2812 } 2813 "" 2814 end 2815 2816 case prototype_unspecified_array_size 2817 expect compile_fail 2818 both "" 2819 precision mediump float; 2820 2821 void func (vec3 f[]); 2822 2823 void main () 2824 { 2825 ${POSITION_FRAG_COLOR} = vec4(1.0); 2826 } 2827 "" 2828 end 2829 2830 case call_mismatch_argument_array_size 2831 expect compile_fail 2832 both "" 2833 precision mediump float; 2834 2835 void func (vec3 f[3]); 2836 void func (vec3 f[3]) 2837 { 2838 } 2839 2840 void main () 2841 { 2842 vec3 array[4]; 2843 func(array); 2844 ${POSITION_FRAG_COLOR} = vec4(1.0); 2845 } 2846 "" 2847 end 2848 2849 case prototype_mismatch_argument_const 2850 expect compile_fail 2851 both "" 2852 precision mediump float; 2853 2854 void func (vec3 f); 2855 void func (const vec3 f) 2856 { 2857 } 2858 2859 void main () 2860 { 2861 ${POSITION_FRAG_COLOR} = vec4(1.0); 2862 } 2863 "" 2864 end 2865 2866 case prototype_mismatch_argument_array_const 2867 expect compile_fail 2868 both "" 2869 precision mediump float; 2870 2871 void func (vec3 f[3]); 2872 void func (const vec3 f[3]) 2873 { 2874 } 2875 2876 void main () 2877 { 2878 ${POSITION_FRAG_COLOR} = vec4(1.0); 2879 } 2880 "" 2881 end 2882 2883 case prototype_mismatch_array_inout 2884 expect compile_fail 2885 both "" 2886 precision mediump float; 2887 2888 void func (out vec3 f); 2889 void func (inout vec3 f) 2890 { 2891 } 2892 2893 void main () 2894 { 2895 ${POSITION_FRAG_COLOR} = vec4(1.0); 2896 } 2897 "" 2898 end 2899 2900 case missing_return_type 2901 expect compile_fail 2902 both "" 2903 precision mediump float; 2904 2905 func (float f); 2906 func (inout vec3 f[3]) 2907 { 2908 } 2909 2910 void main () 2911 { 2912 ${POSITION_FRAG_COLOR} = vec4(1.0); 2913 } 2914 "" 2915 end 2916 2917 case call_before_definition 2918 expect compile_fail 2919 both "" 2920 precision mediump float; 2921 2922 void main () 2923 { 2924 func(1.0); 2925 ${POSITION_FRAG_COLOR} = vec4(1.0); 2926 } 2927 2928 void func (float f) 2929 { 2930 } 2931 2932 "" 2933 end 2934 2935 case return_array_in_struct 2936 expect compile_fail 2937 both "" 2938 precision mediump float; 2939 2940 struct Foo 2941 { 2942 float f; 2943 float arr[2]; 2944 }; 2945 2946 Foo func () 2947 { 2948 Foo f; 2949 f.f = 1.0; 2950 f.arr[0] = 2.0; 2951 return f; 2952 } 2953 2954 void main () 2955 { 2956 ${POSITION_FRAG_COLOR} = vec4(1.0); 2957 } 2958 "" 2959 end 2960 2961 case argument_precision_overload 2962 expect compile_fail 2963 both "" 2964 precision mediump float; 2965 2966 float func (lowp float f) 2967 { 2968 return f; 2969 } 2970 2971 float func (mediump float f) 2972 { 2973 return f; 2974 } 2975 2976 void main () 2977 { 2978 ${POSITION_FRAG_COLOR} = vec4(1.0); 2979 } 2980 "" 2981 end 2982 2983 case argument_in_out_overload 2984 expect compile_fail 2985 both "" 2986 precision mediump float; 2987 2988 void func (in float f) 2989 { 2990 } 2991 2992 void func (out float f) 2993 { 2994 f = 1.0; 2995 } 2996 2997 void main () 2998 { 2999 ${POSITION_FRAG_COLOR} = vec4(1.0); 3000 } 3001 "" 3002 end 3003 3004 case argument_in_inout_overload 3005 expect compile_fail 3006 both "" 3007 precision mediump float; 3008 3009 void func (in float f) 3010 { 3011 } 3012 3013 void func (inout float f) 3014 { 3015 f = -f; 3016 } 3017 3018 void main () 3019 { 3020 ${POSITION_FRAG_COLOR} = vec4(1.0); 3021 } 3022 "" 3023 end 3024 3025 case argument_out_inout_overload 3026 expect compile_fail 3027 both "" 3028 precision mediump float; 3029 3030 void func (out float f) 3031 { 3032 f = -1.0; 3033 } 3034 3035 void func (inout float f) 3036 { 3037 f = -f; 3038 } 3039 3040 void main () 3041 { 3042 ${POSITION_FRAG_COLOR} = vec4(1.0); 3043 } 3044 "" 3045 end 3046 3047 case return_type_overload 3048 expect compile_fail 3049 both "" 3050 precision mediump float; 3051 3052 float func (float f) 3053 { 3054 return f; 3055 } 3056 3057 int func (float f) 3058 { 3059 return int(f); 3060 } 3061 3062 void main () 3063 { 3064 ${POSITION_FRAG_COLOR} = vec4(1.0); 3065 } 3066 "" 3067 end 3068 3069 case return_type_precision_overload 3070 expect compile_fail 3071 both "" 3072 precision mediump float; 3073 3074 lowp float func (float f) 3075 { 3076 return f; 3077 } 3078 3079 mediump float func (float f) 3080 { 3081 return f; 3082 } 3083 3084 void main () 3085 { 3086 ${POSITION_FRAG_COLOR} = vec4(1.0); 3087 } 3088 "" 3089 end 3090 3091 case return_type_const_overload 3092 expect compile_fail 3093 both "" 3094 precision mediump float; 3095 3096 float func (float f) 3097 { 3098 return f; 3099 } 3100 3101 const float func (float f) 3102 { 3103 return f; 3104 } 3105 3106 void main () 3107 { 3108 ${POSITION_FRAG_COLOR} = vec4(1.0); 3109 } 3110 "" 3111 end 3112 3113 case return_without_value 3114 expect compile_fail 3115 both "" 3116 precision mediump float; 3117 3118 float func (float f) 3119 { 3120 return; 3121 return 1.0; 3122 } 3123 3124 void main () 3125 { 3126 ${POSITION_FRAG_COLOR} = vec4(1.0); 3127 } 3128 "" 3129 end 3130 3131 case local_function_prototype 3132 expect compile_fail 3133 both "" 3134 precision mediump float; 3135 3136 void main () 3137 { 3138 float func (float f); 3139 3140 ${POSITION_FRAG_COLOR} = vec4(1.0); 3141 } 3142 "" 3143 end 3144 3145 case local_function_definition 3146 expect compile_fail 3147 both "" 3148 precision mediump float; 3149 3150 void main () 3151 { 3152 float func (float f) 3153 { 3154 return 1.0; 3155 } 3156 3157 ${POSITION_FRAG_COLOR} = vec4(1.0); 3158 } 3159 "" 3160 end 3161 3162 case name_type_conflict 3163 expect compile_fail 3164 both "" 3165 precision mediump float; 3166 3167 struct foo { float a; } 3168 3169 float foo (float f) 3170 { 3171 return 1.0; 3172 } 3173 3174 void main () 3175 { 3176 ${POSITION_FRAG_COLOR} = vec4(1.0); 3177 } 3178 "" 3179 end 3180 3181 case const_overload 3182 expect compile_fail 3183 both "" 3184 precision mediump float; 3185 3186 void func (vec3 f) 3187 { 3188 } 3189 3190 void func (const vec3 f) 3191 { 3192 } 3193 3194 void main () 3195 { 3196 ${POSITION_FRAG_COLOR} = vec4(1.0); 3197 } 3198 "" 3199 end 3200 3201 case uniform_local 3202 expect compile_fail 3203 both "" 3204 precision mediump float; 3205 3206 void func (vec3 f) 3207 { 3208 uniform float u; 3209 } 3210 3211 void main () 3212 { 3213 ${POSITION_FRAG_COLOR} = vec4(1.0); 3214 } 3215 "" 3216 end 3217 3218 case varying_local 3219 expect compile_fail 3220 both "" 3221 precision mediump float; 3222 3223 void func (vec3 f) 3224 { 3225 varying float v; 3226 } 3227 3228 void main () 3229 { 3230 ${POSITION_FRAG_COLOR} = vec4(1.0); 3231 } 3232 "" 3233 end 3234 3235 case attribute_local 3236 expect compile_fail 3237 both "" 3238 precision mediump float; 3239 3240 void func (vec3 f) 3241 { 3242 attribute float a; 3243 } 3244 3245 void main () 3246 { 3247 ${POSITION_FRAG_COLOR} = vec4(1.0); 3248 } 3249 "" 3250 end 3251 3252 case uniform_argument 3253 expect compile_fail 3254 both "" 3255 precision mediump float; 3256 3257 void func (uniform vec3 f) 3258 { 3259 } 3260 3261 void main () 3262 { 3263 ${POSITION_FRAG_COLOR} = vec4(1.0); 3264 } 3265 "" 3266 end 3267 3268 case varying_argument 3269 expect compile_fail 3270 both "" 3271 precision mediump float; 3272 3273 void func (varying vec3 f) 3274 { 3275 } 3276 3277 void main () 3278 { 3279 ${POSITION_FRAG_COLOR} = vec4(1.0); 3280 } 3281 "" 3282 end 3283 3284 case attribute_argument 3285 expect compile_fail 3286 both "" 3287 precision mediump float; 3288 3289 void func (attribute vec3 f) 3290 { 3291 } 3292 3293 void main () 3294 { 3295 ${POSITION_FRAG_COLOR} = vec4(1.0); 3296 } 3297 "" 3298 end 3299 3300 case uniform_return_type 3301 expect compile_fail 3302 both "" 3303 precision mediump float; 3304 3305 uniform float func (vec3 f) 3306 { 3307 return f.x; 3308 } 3309 3310 void main () 3311 { 3312 ${POSITION_FRAG_COLOR} = vec4(1.0); 3313 } 3314 "" 3315 end 3316 3317 case varying_return_type 3318 expect compile_fail 3319 both "" 3320 precision mediump float; 3321 3322 varying float func (vec3 f) 3323 { 3324 return f.x; 3325 } 3326 3327 void main () 3328 { 3329 ${POSITION_FRAG_COLOR} = vec4(1.0); 3330 } 3331 "" 3332 end 3333 3334 case attribute_return_type 3335 expect compile_fail 3336 both "" 3337 precision mediump float; 3338 3339 attribute float func (vec3 f) 3340 { 3341 return f.x; 3342 } 3343 3344 void main () 3345 { 3346 ${POSITION_FRAG_COLOR} = vec4(1.0); 3347 } 3348 "" 3349 end 3350 3351 case main_invalid_return_type 3352 expect compile_fail 3353 both "" 3354 precision mediump float; 3355 3356 float main () 3357 { 3358 ${POSITION_FRAG_COLOR} = vec4(1.0); 3359 } 3360 "" 3361 end 3362 3363 case main_has_arguments 3364 expect compile_fail 3365 both "" 3366 precision mediump float; 3367 3368 void main (float f) 3369 { 3370 ${POSITION_FRAG_COLOR} = vec4(1.0); 3371 } 3372 "" 3373 end 3374 3375 case main_missing_return_type 3376 expect compile_fail 3377 both "" 3378 precision mediump float; 3379 3380 main () 3381 { 3382 ${POSITION_FRAG_COLOR} = vec4(1.0); 3383 } 3384 "" 3385 end 3386 3387 case write_const_arg 3388 expect compile_fail 3389 both "" 3390 precision mediump float; 3391 3392 func (const float f) 3393 { 3394 f = 1.0; 3395 } 3396 3397 main () 3398 { 3399 ${POSITION_FRAG_COLOR} = vec4(1.0); 3400 } 3401 "" 3402 end 3403 3404 case write_const_array_arg 3405 expect compile_fail 3406 both "" 3407 precision mediump float; 3408 3409 func (const float f[3]) 3410 { 3411 f[0] = 1.0; 3412 } 3413 3414 main () 3415 { 3416 ${POSITION_FRAG_COLOR} = vec4(1.0); 3417 } 3418 "" 3419 end 3420 3421 case modify_const_arg 3422 expect compile_fail 3423 both "" 3424 precision mediump float; 3425 precision mediump int; 3426 ${DECLARATIONS} 3427 3428 int func (const int a) 3429 { 3430 a = -a; 3431 return 2 * a; 3432 } 3433 3434 void main() 3435 { 3436 ${POSITION_FRAG_COLOR} = vec4(func(3)); 3437 } 3438 "" 3439 end 3440 3441 case init_const_local_from_const_arg 3442 expect compile_fail 3443 both "" 3444 precision mediump float; 3445 precision mediump int; 3446 ${DECLARATIONS} 3447 3448 int func (const int a) 3449 { 3450 const int b = -a; 3451 return 2 * b; 3452 } 3453 3454 void main() 3455 { 3456 ${POSITION_FRAG_COLOR} = vec4(func(3)); 3457 } 3458 "" 3459 end 3460 3461 case array_size_from_const_arg 3462 expect compile_fail 3463 both "" 3464 precision mediump float; 3465 precision mediump int; 3466 ${DECLARATIONS} 3467 3468 int func (const int a) 3469 { 3470 int arr[a]; 3471 arr[1] = 3; 3472 return arr[1]; 3473 } 3474 3475 void main() 3476 { 3477 ${POSITION_FRAG_COLOR} = vec4(func(3)); 3478 } 3479 "" 3480 end 3481 3482 case double_declare 3483 expect compile_fail 3484 both "" 3485 precision mediump float; 3486 ${DECLARATIONS} 3487 3488 float func (float f); 3489 float func (float f); 3490 3491 float func (float f) 3492 { 3493 return -f; 3494 } 3495 3496 void main() 3497 { 3498 ${POSITION_FRAG_COLOR} = vec4(func(1.0)); 3499 } 3500 "" 3501 end 3502 3503 end # invalid 3504