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