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