1# encoding=utf-8 2# Copyright © 2019 Google 3 4# Permission is hereby granted, free of charge, to any person obtaining a copy 5# of this software and associated documentation files (the "Software"), to deal 6# in the Software without restriction, including without limitation the rights 7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8# copies of the Software, and to permit persons to whom the Software is 9# furnished to do so, subject to the following conditions: 10 11# The above copyright notice and this permission notice shall be included in 12# all copies or substantial portions of the Software. 13 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20# SOFTWARE. 21 22import sys 23import subprocess 24import tempfile 25import re 26from collections import namedtuple 27 28 29Test = namedtuple("Test", "name source match_re") 30 31# NOTE: This test is deprecated, please add any new tests to test_gl_lower_mediump.cpp. 32 33TESTS = [ 34 Test("f32 array-of-array with const index", 35 """ 36 #version 310 es 37 precision mediump float; 38 39 uniform float in_aoa[2][2]; 40 41 layout(location = 0) out float out_color; 42 43 void main() 44 { 45 out_color = in_aoa[0][0] / in_aoa[1][1]; 46 } 47 """, 48 r'\(expression +float16_t +/'), 49 Test("i32 array-of-array with const index", 50 """ 51 #version 310 es 52 precision mediump float; 53 precision mediump int; 54 55 uniform int in_aoa[2][2]; 56 57 layout(location = 0) out highp int out_color; 58 59 void main() 60 { 61 out_color = in_aoa[0][0] / in_aoa[1][1]; 62 } 63 """, 64 r'\(expression +int16_t +/'), 65 Test("u32 array-of-array with const index", 66 """ 67 #version 310 es 68 precision mediump float; 69 precision mediump int; 70 71 uniform uint in_aoa[2][2]; 72 73 layout(location = 0) out highp uint out_color; 74 75 void main() 76 { 77 out_color = in_aoa[0][0] / in_aoa[1][1]; 78 } 79 """, 80 r'\(expression +uint16_t +/'), 81 Test("f32 array-of-array with uniform index", 82 """ 83 #version 310 es 84 precision mediump float; 85 86 uniform float in_aoa[2][2]; 87 uniform int i0, i1; 88 89 layout(location = 0) out float out_color; 90 91 void main() 92 { 93 out_color = in_aoa[i0][i0] / in_aoa[i1][i1]; 94 } 95 """, 96 r'\(expression +float16_t +/'), 97 Test("i32 array-of-array with uniform index", 98 """ 99 #version 310 es 100 precision mediump float; 101 precision mediump int; 102 103 uniform int in_aoa[2][2]; 104 uniform int i0, i1; 105 106 layout(location = 0) out highp int out_color; 107 108 void main() 109 { 110 out_color = in_aoa[i0][i0] / in_aoa[i1][i1]; 111 } 112 """, 113 r'\(expression +int16_t +/'), 114 Test("u32 array-of-array with uniform index", 115 """ 116 #version 310 es 117 precision mediump float; 118 precision mediump int; 119 120 uniform uint in_aoa[2][2]; 121 uniform int i0, i1; 122 123 layout(location = 0) out highp uint out_color; 124 125 void main() 126 { 127 out_color = in_aoa[i0][i0] / in_aoa[i1][i1]; 128 } 129 """, 130 r'\(expression +uint16_t +/'), 131 Test("f32 function", 132 """ 133 precision mediump float; 134 135 uniform float a, b; 136 137 mediump float 138 get_a() 139 { 140 return a; 141 } 142 143 float 144 get_b() 145 { 146 return b; 147 } 148 149 void main() 150 { 151 gl_FragColor = vec4(get_a() / get_b()); 152 } 153 """, 154 r'\(expression +float16_t +/'), 155 Test("i32 function", 156 """ 157 #version 310 es 158 precision mediump float; 159 precision mediump int; 160 161 uniform int a, b; 162 163 mediump int 164 get_a() 165 { 166 return a; 167 } 168 169 int 170 get_b() 171 { 172 return b; 173 } 174 175 out highp int color; 176 177 void main() 178 { 179 color = get_a() / get_b(); 180 } 181 """, 182 r'\(expression +int16_t +/'), 183 Test("u32 function", 184 """ 185 #version 310 es 186 precision mediump float; 187 precision mediump int; 188 189 uniform uint a, b; 190 191 mediump uint 192 get_a() 193 { 194 return a; 195 } 196 197 uint 198 get_b() 199 { 200 return b; 201 } 202 203 out highp uint color; 204 205 void main() 206 { 207 color = get_a() / get_b(); 208 } 209 """, 210 r'\(expression +uint16_t +/'), 211 Test("f32 function mediump args", 212 """ 213 precision mediump float; 214 215 uniform float a, b; 216 217 mediump float 218 do_div(float x, float y) 219 { 220 return x / y; 221 } 222 223 void main() 224 { 225 gl_FragColor = vec4(do_div(a, b)); 226 } 227 """, 228 r'\(expression +float16_t +/'), 229 Test("i32 function mediump args", 230 """ 231 #version 310 es 232 precision mediump float; 233 precision mediump int; 234 235 uniform int a, b; 236 237 mediump int 238 do_div(int x, int y) 239 { 240 return x / y; 241 } 242 243 out highp int color; 244 245 void main() 246 { 247 color = do_div(a, b); 248 } 249 """, 250 r'\(expression +int16_t +/'), 251 Test("u32 function mediump args", 252 """ 253 #version 310 es 254 precision mediump float; 255 precision mediump int; 256 257 uniform uint a, b; 258 259 mediump uint 260 do_div(uint x, uint y) 261 { 262 return x / y; 263 } 264 265 out highp uint color; 266 267 void main() 268 { 269 color = do_div(a, b); 270 } 271 """, 272 r'\(expression +uint16_t +/'), 273 Test("f32 function highp args", 274 """ 275 precision mediump float; 276 277 uniform float a, b; 278 279 mediump float 280 do_div(highp float x, highp float y) 281 { 282 return x / y; 283 } 284 285 void main() 286 { 287 gl_FragColor = vec4(do_div(a, b)); 288 } 289 """, 290 r'\(expression +float +/'), 291 Test("i32 function highp args", 292 """ 293 #version 310 es 294 precision mediump float; 295 precision mediump int; 296 297 uniform int a, b; 298 299 mediump int 300 do_div(highp int x, highp int y) 301 { 302 return x / y; 303 } 304 305 out highp int color; 306 307 void main() 308 { 309 color = do_div(a, b); 310 } 311 """, 312 r'\(expression +int +/'), 313 Test("u32 function highp args", 314 """ 315 #version 310 es 316 precision mediump float; 317 precision mediump int; 318 319 uniform uint a, b; 320 321 mediump uint 322 do_div(highp uint x, highp uint y) 323 { 324 return x / y; 325 } 326 327 out highp uint color; 328 329 void main() 330 { 331 color = do_div(a, b); 332 } 333 """, 334 r'\(expression +uint +/'), 335 336 Test("f32 if", 337 """ 338 precision mediump float; 339 340 uniform float a, b; 341 342 void 343 main() 344 { 345 if (a / b < 0.31) 346 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); 347 else 348 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); 349 } 350 """, 351 r'\(expression +float16_t +/'), 352 Test("i32 if", 353 """ 354 #version 310 es 355 precision mediump float; 356 precision mediump int; 357 358 uniform int a, b; 359 360 out vec4 color; 361 362 void 363 main() 364 { 365 if (a / b < 10) 366 color = vec4(0.0, 1.0, 0.0, 1.0); 367 else 368 color = vec4(1.0, 0.0, 0.0, 1.0); 369 } 370 """, 371 r'\(expression +int16_t +/'), 372 Test("u32 if", 373 """ 374 #version 310 es 375 precision mediump float; 376 precision mediump int; 377 378 uniform uint a, b; 379 380 out vec4 color; 381 382 void 383 main() 384 { 385 if (a / b < 10u) 386 color = vec4(0.0, 1.0, 0.0, 1.0); 387 else 388 color = vec4(1.0, 0.0, 0.0, 1.0); 389 } 390 """, 391 r'\(expression +uint16_t +/'), 392 Test("matrix", 393 """ 394 precision mediump float; 395 396 uniform vec2 a; 397 uniform mat2 b; 398 399 void main() 400 { 401 gl_FragColor = vec4(b * a, 0.0, 0.0); 402 } 403 """, 404 r'\(expression f16vec2 \+ \(expression f16vec2 \* \(array_ref \(var_ref b\) \(constant int \(0\)\) \) \(swiz x \(var_ref a\) \)\) \(expression f16vec2 \* \(array_ref \(var_ref b\) \(constant int \(1\)\) \) \(swiz y \(var_ref a\) \)\) \) \)'), 405 Test("f32 simple struct deref", 406 """ 407 precision mediump float; 408 409 struct simple { 410 float a, b; 411 }; 412 413 uniform simple in_simple; 414 415 void main() 416 { 417 gl_FragColor = vec4(in_simple.a / in_simple.b); 418 } 419 """, 420 r'\(expression +float16_t +/'), 421 Test("i32 simple struct deref", 422 """ 423 #version 310 es 424 precision mediump float; 425 precision mediump int; 426 427 struct simple { 428 int a, b; 429 }; 430 431 uniform simple in_simple; 432 433 out highp int color; 434 435 void main() 436 { 437 color = in_simple.a / in_simple.b; 438 } 439 """, 440 r'\(expression +int16_t +/'), 441 Test("u32 simple struct deref", 442 """ 443 #version 310 es 444 precision mediump float; 445 precision mediump int; 446 447 struct simple { 448 uint a, b; 449 }; 450 451 uniform simple in_simple; 452 453 out highp uint color; 454 455 void main() 456 { 457 color = in_simple.a / in_simple.b; 458 } 459 """, 460 r'\(expression +uint16_t +/'), 461 Test("f32 embedded struct deref", 462 """ 463 precision mediump float; 464 465 struct simple { 466 float a, b; 467 }; 468 469 struct embedded { 470 simple a, b; 471 }; 472 473 uniform embedded in_embedded; 474 475 void main() 476 { 477 gl_FragColor = vec4(in_embedded.a.a / in_embedded.b.b); 478 } 479 """, 480 r'\(expression +float16_t +/'), 481 Test("i32 embedded struct deref", 482 """ 483 #version 310 es 484 precision mediump float; 485 precision mediump int; 486 487 struct simple { 488 int a, b; 489 }; 490 491 struct embedded { 492 simple a, b; 493 }; 494 495 uniform embedded in_embedded; 496 497 out highp int color; 498 499 void main() 500 { 501 color = in_embedded.a.a / in_embedded.b.b; 502 } 503 """, 504 r'\(expression +int16_t +/'), 505 Test("u32 embedded struct deref", 506 """ 507 #version 310 es 508 precision mediump float; 509 precision mediump int; 510 511 struct simple { 512 uint a, b; 513 }; 514 515 struct embedded { 516 simple a, b; 517 }; 518 519 uniform embedded in_embedded; 520 521 out highp uint color; 522 523 void main() 524 { 525 color = in_embedded.a.a / in_embedded.b.b; 526 } 527 """, 528 r'\(expression +uint16_t +/'), 529 Test("f32 arrayed struct deref", 530 """ 531 precision mediump float; 532 533 struct simple { 534 float a, b; 535 }; 536 537 struct arrayed { 538 simple a[2]; 539 }; 540 541 uniform arrayed in_arrayed; 542 543 void main() 544 { 545 gl_FragColor = vec4(in_arrayed.a[0].a / in_arrayed.a[1].b); 546 } 547 """, 548 r'\(expression +float16_t +/'), 549 Test("i32 arrayed struct deref", 550 """ 551 #version 310 es 552 precision mediump float; 553 precision mediump int; 554 555 struct simple { 556 int a, b; 557 }; 558 559 struct arrayed { 560 simple a[2]; 561 }; 562 563 uniform arrayed in_arrayed; 564 565 out highp int color; 566 567 void main() 568 { 569 color = in_arrayed.a[0].a / in_arrayed.a[1].b; 570 } 571 """, 572 r'\(expression +int16_t +/'), 573 Test("u32 arrayed struct deref", 574 """ 575 #version 310 es 576 precision mediump float; 577 precision mediump int; 578 579 struct simple { 580 uint a, b; 581 }; 582 583 struct arrayed { 584 simple a[2]; 585 }; 586 587 uniform arrayed in_arrayed; 588 589 out highp uint color; 590 591 void main() 592 { 593 color = in_arrayed.a[0].a / in_arrayed.a[1].b; 594 } 595 """, 596 r'\(expression +uint16_t +/'), 597 Test("f32 mixed precision not lowered", 598 """ 599 uniform mediump float a; 600 uniform highp float b; 601 602 void main() 603 { 604 gl_FragColor = vec4(a / b); 605 } 606 """, 607 r'\(expression +float +/'), 608 Test("i32 mixed precision not lowered", 609 """ 610 #version 310 es 611 uniform mediump int a; 612 uniform highp int b; 613 614 out mediump int color; 615 616 void main() 617 { 618 color = a / b; 619 } 620 """, 621 r'\(expression +int +/'), 622 Test("u32 mixed precision not lowered", 623 """ 624 #version 310 es 625 uniform mediump uint a; 626 uniform highp uint b; 627 628 out mediump uint color; 629 630 void main() 631 { 632 color = a / b; 633 } 634 """, 635 r'\(expression +uint +/'), 636 Test("f32 sampler array", 637 """ 638 #version 320 es 639 precision mediump float; 640 precision mediump int; 641 642 uniform sampler2D tex[2]; 643 // highp shouldn't affect the return value of texture2D 644 uniform highp vec2 coord; 645 uniform float divisor; 646 uniform int index; 647 648 out highp vec4 color; 649 650 void main() 651 { 652 color = texture2D(tex[index], coord) / divisor; 653 } 654 """, 655 r'\(expression +f16vec4 +/.*\(tex +f16vec4 +'), 656 Test("f32 texture sample", 657 """ 658 precision mediump float; 659 660 uniform sampler2D tex; 661 // highp shouldn't affect the return value of texture2D 662 uniform highp vec2 coord; 663 uniform float divisor; 664 665 void main() 666 { 667 gl_FragColor = texture2D(tex, coord) / divisor; 668 } 669 """, 670 r'\(expression +f16vec4 +/.*\(tex +f16vec4 +'), 671 Test("i32 texture sample", 672 """ 673 #version 310 es 674 precision mediump float; 675 precision mediump int; 676 677 uniform mediump isampler2D tex; 678 // highp shouldn't affect the return value of texture 679 uniform highp vec2 coord; 680 uniform int divisor; 681 682 out highp ivec4 color; 683 684 void main() 685 { 686 color = texture(tex, coord) / divisor; 687 } 688 """, 689 r'\(expression +i16vec4 +/.*\(tex +i16vec4 +'), 690 Test("u32 texture sample", 691 """ 692 #version 310 es 693 precision mediump float; 694 precision mediump int; 695 696 uniform mediump usampler2D tex; 697 // highp shouldn't affect the return value of texture 698 uniform highp vec2 coord; 699 uniform uint divisor; 700 701 out highp uvec4 color; 702 703 void main() 704 { 705 color = texture(tex, coord) / divisor; 706 } 707 """, 708 r'\(expression +u16vec4 +/.*\(tex +u16vec4 +'), 709 Test("f32 image array", 710 """ 711 #version 320 es 712 precision mediump float; 713 714 layout(rgba16f) readonly uniform mediump image2D img[2]; 715 // highp shouldn't affect the return value of imageLoad 716 uniform highp ivec2 coord; 717 uniform float divisor; 718 719 out highp vec4 color; 720 721 void main() 722 { 723 color = imageLoad(img[1], coord) / divisor; 724 } 725 """, 726 r'\(expression +f16vec4 +/'), 727 Test("f32 image load", 728 """ 729 #version 310 es 730 precision mediump float; 731 precision mediump int; 732 733 layout(rgba16f) readonly uniform mediump image2D img; 734 // highp shouldn't affect the return value of imageLoad 735 uniform highp ivec2 coord; 736 uniform float divisor; 737 738 out highp vec4 color; 739 740 void main() 741 { 742 color = imageLoad(img, coord) / divisor; 743 } 744 """, 745 r'\(expression +f16vec4 +/'), 746 Test("i32 image load", 747 """ 748 #version 310 es 749 precision mediump float; 750 precision mediump int; 751 752 layout(rgba16i) readonly uniform mediump iimage2D img; 753 // highp shouldn't affect the return value of imageLoad 754 uniform highp ivec2 coord; 755 uniform int divisor; 756 757 out highp ivec4 color; 758 759 void main() 760 { 761 color = imageLoad(img, coord) / divisor; 762 } 763 """, 764 r'\(expression +i16vec4 +/'), 765 Test("u32 image load", 766 """ 767 #version 310 es 768 precision mediump float; 769 precision mediump int; 770 771 layout(rgba16ui) readonly uniform mediump uimage2D img; 772 // highp shouldn't affect the return value of imageLoad 773 uniform highp ivec2 coord; 774 uniform uint divisor; 775 776 out highp uvec4 color; 777 778 void main() 779 { 780 color = imageLoad(img, coord) / divisor; 781 } 782 """, 783 r'\(expression +u16vec4 +/'), 784 Test("f32 expression in lvalue", 785 """ 786 uniform mediump float a, b; 787 788 void main() 789 { 790 gl_FragColor = vec4(1.0); 791 gl_FragColor[int(a / b)] = 0.5; 792 } 793 """, 794 r'\(expression +float16_t +/'), 795 Test("i32 expression in lvalue", 796 """ 797 #version 310 es 798 precision mediump float; 799 precision mediump int; 800 801 uniform mediump int a, b; 802 803 out vec4 color; 804 805 void main() 806 { 807 color = vec4(1.0); 808 color[a / b] = 0.5; 809 } 810 """, 811 r'\(expression +int16_t +/'), 812 Test("f32 builtin with const arg", 813 """ 814 uniform mediump float a; 815 816 void main() 817 { 818 gl_FragColor = vec4(min(a, 3.0)); 819 } 820 """, 821 r'\(expression +float16_t min'), 822 Test("i32 builtin with const arg", 823 """ 824 #version 310 es 825 uniform mediump int a; 826 827 out highp int color; 828 829 void main() 830 { 831 color = min(a, 3); 832 } 833 """, 834 r'\(expression +int16_t min'), 835 Test("u32 builtin with const arg", 836 """ 837 #version 310 es 838 uniform mediump uint a; 839 840 out highp uint color; 841 842 void main() 843 { 844 color = min(a, 3u); 845 } 846 """, 847 r'\(expression +uint16_t min'), 848 Test("dFdx", 849 """ 850 #version 300 es 851 precision mediump float; 852 853 in vec4 var; 854 out vec4 color; 855 856 void main() 857 { 858 color = dFdx(var); 859 } 860 """, 861 r'\(expression +f16vec4 +dFdx +\(expression +f16vec4'), 862 Test("dFdy", 863 """ 864 #version 300 es 865 precision mediump float; 866 867 in vec4 var; 868 out vec4 color; 869 870 void main() 871 { 872 color = dFdy(var); 873 } 874 """, 875 r'\(expression +f16vec4 +dFdy +\(expression +f16vec4'), 876 Test("textureSize", 877 """ 878 #version 310 es 879 precision mediump float; 880 precision mediump int; 881 882 uniform mediump sampler2D tex; 883 out ivec2 color; 884 885 void main() 886 { 887 color = textureSize(tex, 0) * ivec2(2); 888 } 889 """, 890 r'expression ivec2 \* \(txs ivec2 \(var_ref tex'), 891 Test("floatBitsToInt", 892 """ 893 #version 310 es 894 precision mediump float; 895 precision mediump int; 896 897 uniform float val; 898 out int color; 899 900 void main() 901 { 902 color = floatBitsToInt(val + 1.0) + 1; 903 } 904 """, 905 r'expression int bitcast_f2i \(expression float'), 906 Test("floatBitsToUint", 907 """ 908 #version 310 es 909 precision mediump float; 910 precision mediump int; 911 912 uniform float val; 913 out uint color; 914 915 void main() 916 { 917 color = floatBitsToUint(val + 1.0) + 1u; 918 } 919 """, 920 r'expression uint bitcast_f2u \(expression float'), 921 Test("intBitsToFloat", 922 """ 923 #version 310 es 924 precision mediump float; 925 precision mediump int; 926 927 uniform int val; 928 out float color; 929 930 void main() 931 { 932 color = intBitsToFloat(val + 1) + 1.0; 933 } 934 """, 935 r'expression float bitcast_i2f \(expression int'), 936 Test("uintBitsToFloat", 937 """ 938 #version 310 es 939 precision mediump float; 940 precision mediump int; 941 942 uniform uint val; 943 out float color; 944 945 void main() 946 { 947 color = uintBitsToFloat(val + 1u) + 1.0; 948 } 949 """, 950 r'expression float bitcast_u2f \(expression uint'), 951 Test("bitfieldReverse", 952 """ 953 #version 310 es 954 precision mediump float; 955 precision mediump int; 956 957 uniform int val; 958 out int color; 959 960 void main() 961 { 962 color = bitfieldReverse(val + 1) + 1; 963 } 964 """, 965 r'expression int bitfield_reverse \(expression int'), 966 Test("frexp", 967 """ 968 #version 310 es 969 precision mediump float; 970 precision mediump int; 971 972 uniform float val; 973 out float color; 974 out int color2; 975 976 void main() 977 { 978 int y; 979 float x = frexp(val + 1.0, y); 980 color = x + 1.0; 981 color2 = y + 1; 982 } 983 """, 984 r'expression int16_t i2imp \(expression int frexp_exp \(expression float f162f'), 985 Test("ldexp", 986 """ 987 #version 310 es 988 precision mediump float; 989 precision mediump int; 990 991 uniform float val; 992 uniform int exp; 993 out float color; 994 995 void main() 996 { 997 color = ldexp(val + 1.0, exp + 1) + 1.0; 998 } 999 """, 1000 r'expression float ldexp \(expression float'), 1001 Test("uaddCarry", 1002 """ 1003 #version 310 es 1004 precision mediump float; 1005 precision mediump int; 1006 1007 uniform uint x, y; 1008 out uint color; 1009 1010 void main() 1011 { 1012 lowp uint carry; 1013 color = uaddCarry(x * 2u, y * 2u, carry) * 2u; 1014 color *= carry; 1015 } 1016 """, 1017 r'expression uint \+ \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref x\) \) \(constant uint16_t \(2\)\) \) \) \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref y'), 1018 Test("usubBorrow", 1019 """ 1020 #version 310 es 1021 precision mediump float; 1022 precision mediump int; 1023 1024 uniform uint x, y; 1025 out uint color; 1026 1027 void main() 1028 { 1029 lowp uint borrow; 1030 color = usubBorrow(x * 2u, y * 2u, borrow) * 2u; 1031 color *= borrow; 1032 } 1033 """, 1034 r'expression uint \- \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref x\) \) \(constant uint16_t \(2\)\) \) \) \(expression uint u2u \(expression uint16_t \* \(expression uint16_t u2ump \(var_ref y'), 1035 Test("imulExtended", 1036 """ 1037 #version 310 es 1038 precision mediump float; 1039 precision mediump int; 1040 1041 uniform int x, y; 1042 out int color; 1043 1044 void main() 1045 { 1046 int msb, lsb; 1047 imulExtended(x + 2, y + 2, msb, lsb); 1048 color = msb + lsb; 1049 } 1050 """, 1051 r'expression int64_t \* \(expression int'), 1052 Test("umulExtended", 1053 """ 1054 #version 310 es 1055 precision mediump float; 1056 precision mediump int; 1057 1058 uniform uint x, y; 1059 out uint color; 1060 1061 void main() 1062 { 1063 uint msb, lsb; 1064 umulExtended(x + 2u, y + 2u, msb, lsb); 1065 color = msb + lsb; 1066 } 1067 """, 1068 r'expression uint64_t \* \(expression uint'), 1069 Test("unpackUnorm2x16", 1070 """ 1071 #version 310 es 1072 precision mediump float; 1073 precision mediump int; 1074 1075 uniform uint val; 1076 out vec2 color; 1077 1078 void main() 1079 { 1080 color = unpackUnorm2x16(val + 1u) + vec2(1.0); 1081 } 1082 """, 1083 r'expression vec2 unpackUnorm2x16 \(expression uint'), 1084 Test("unpackSnorm2x16", 1085 """ 1086 #version 310 es 1087 precision mediump float; 1088 precision mediump int; 1089 1090 uniform uint val; 1091 out vec2 color; 1092 1093 void main() 1094 { 1095 color = unpackSnorm2x16(val + 1u) + vec2(1.0); 1096 } 1097 """, 1098 r'expression vec2 unpackSnorm2x16 \(expression uint'), 1099 Test("packUnorm2x16", 1100 """ 1101 #version 310 es 1102 precision mediump float; 1103 precision mediump int; 1104 1105 uniform vec2 val; 1106 out uint color; 1107 1108 void main() 1109 { 1110 color = packUnorm2x16(val + vec2(1.0)) + 1u; 1111 } 1112 """, 1113 r'expression uint packUnorm2x16 \(expression vec2'), 1114 Test("packSnorm2x16", 1115 """ 1116 #version 310 es 1117 precision mediump float; 1118 precision mediump int; 1119 1120 uniform vec2 val; 1121 out uint color; 1122 1123 void main() 1124 { 1125 color = packSnorm2x16(val + vec2(1.0)) + 1u; 1126 } 1127 """, 1128 r'expression uint packSnorm2x16 \(expression vec2'), 1129 Test("packHalf2x16", 1130 """ 1131 #version 310 es 1132 precision mediump float; 1133 precision mediump int; 1134 1135 uniform vec2 val; 1136 out uint color; 1137 1138 void main() 1139 { 1140 color = packHalf2x16(val + vec2(1.0)) + 1u; 1141 } 1142 """, 1143 r'expression uint packHalf2x16 \(expression vec2'), 1144 Test("packUnorm4x8", 1145 """ 1146 #version 310 es 1147 precision mediump float; 1148 precision mediump int; 1149 1150 uniform vec4 val; 1151 out uint color; 1152 1153 void main() 1154 { 1155 color = packUnorm4x8(val + vec4(1.0)) + 1u; 1156 } 1157 """, 1158 r'expression uint packUnorm4x8 \(expression vec4'), 1159 Test("packSnorm4x8", 1160 """ 1161 #version 310 es 1162 precision mediump float; 1163 precision mediump int; 1164 1165 uniform vec4 val; 1166 out uint color; 1167 1168 void main() 1169 { 1170 color = packSnorm4x8(val + vec4(1.0)) + 1u; 1171 } 1172 """, 1173 r'expression uint packSnorm4x8 \(expression vec4'), 1174 Test("interpolateAtCentroid", 1175 """ 1176 #version 320 es 1177 precision mediump float; 1178 precision mediump int; 1179 1180 in float val; 1181 out float color; 1182 1183 void main() 1184 { 1185 color = interpolateAtCentroid(val) + 1.0; 1186 } 1187 """, 1188 r'expression float16_t interpolate_at_centroid \(expression float16_t'), 1189 Test("interpolateAtOffset", 1190 """ 1191 #version 320 es 1192 precision mediump float; 1193 precision mediump int; 1194 1195 uniform highp vec2 offset; 1196 in float val; 1197 out float color; 1198 1199 void main() 1200 { 1201 color = interpolateAtOffset(val, offset) + 1.0; 1202 } 1203 """, 1204 r'expression float16_t interpolate_at_offset \(expression float16_t'), 1205 Test("interpolateAtSample", 1206 """ 1207 #version 320 es 1208 precision mediump float; 1209 precision mediump int; 1210 1211 uniform highp int sample_index; 1212 in float val; 1213 out float color; 1214 1215 void main() 1216 { 1217 color = interpolateAtSample(val, sample_index) + 1.0; 1218 } 1219 """, 1220 r'expression float16_t interpolate_at_sample \(expression float16_t'), 1221 Test("bitfieldExtract", 1222 """ 1223 #version 310 es 1224 precision mediump float; 1225 precision mediump int; 1226 1227 uniform highp int offset, bits; 1228 uniform int val; 1229 out int color; 1230 1231 void main() 1232 { 1233 color = bitfieldExtract(val, offset, bits) + 1; 1234 } 1235 """, 1236 r'expression int16_t bitfield_extract \(expression int16_t'), 1237 Test("bitfieldInsert", 1238 """ 1239 #version 310 es 1240 precision mediump float; 1241 precision mediump int; 1242 1243 uniform highp int offset, bits; 1244 uniform int val, val2; 1245 out int color; 1246 1247 void main() 1248 { 1249 color = bitfieldInsert(val, val2, offset, bits) + 1; 1250 } 1251 """, 1252 r'expression int16_t bitfield_insert \(expression int16_t'), 1253 Test("bitCount", 1254 """ 1255 #version 310 es 1256 precision mediump float; 1257 precision mediump int; 1258 1259 uniform highp int val; 1260 out int color; 1261 1262 void main() 1263 { 1264 color = bitCount(val) + 1; 1265 } 1266 """, 1267 r'expression int16_t \+ \(expression int16_t i2imp \(expression int bit_count \(var_ref val'), 1268 Test("findLSB", 1269 """ 1270 #version 310 es 1271 precision mediump float; 1272 precision mediump int; 1273 1274 uniform highp int val; 1275 out int color; 1276 1277 void main() 1278 { 1279 color = findLSB(val) + 1; 1280 } 1281 """, 1282 r'expression int16_t \+ \(expression int16_t i2imp \(expression int find_lsb \(var_ref val'), 1283 Test("findMSB", 1284 """ 1285 #version 310 es 1286 precision mediump float; 1287 precision mediump int; 1288 1289 uniform highp int val; 1290 out int color; 1291 1292 void main() 1293 { 1294 color = findMSB(val) + 1; 1295 } 1296 """, 1297 r'expression int16_t \+ \(expression int16_t i2imp \(expression int find_msb \(var_ref val'), 1298 Test("unpackHalf2x16", 1299 """ 1300 #version 310 es 1301 precision mediump float; 1302 precision mediump int; 1303 1304 uniform highp uint val; 1305 out vec2 color; 1306 1307 void main() 1308 { 1309 color = unpackHalf2x16(val) + vec2(1.0); 1310 } 1311 """, 1312 r'expression f16vec2 \+ \(expression f16vec2 f2fmp \(expression vec2 unpackHalf2x16 \(var_ref val'), 1313 Test("unpackUnorm4x8", 1314 """ 1315 #version 310 es 1316 precision mediump float; 1317 precision mediump int; 1318 1319 uniform highp uint val; 1320 out vec4 color; 1321 1322 void main() 1323 { 1324 color = unpackUnorm4x8(val) + vec4(1.0); 1325 } 1326 """, 1327 r'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackUnorm4x8 \(var_ref val'), 1328 Test("unpackSnorm4x8", 1329 """ 1330 #version 310 es 1331 precision mediump float; 1332 precision mediump int; 1333 1334 uniform highp uint val; 1335 out vec4 color; 1336 1337 void main() 1338 { 1339 color = unpackSnorm4x8(val) + vec4(1.0); 1340 } 1341 """, 1342 r'expression f16vec4 \+ \(expression f16vec4 f2fmp \(expression vec4 unpackSnorm4x8 \(var_ref val'), 1343 Test("f32 csel", 1344 """ 1345 #version 300 es 1346 precision mediump float; 1347 1348 in vec4 var; 1349 out vec4 color; 1350 1351 void main() 1352 { 1353 color = (var.x > var.y) ? var : vec4(10.0); 1354 } 1355 """, 1356 r'\(expression f16vec4 f2fmp \(constant vec4 \(10'), 1357 Test("i32 csel", 1358 """ 1359 #version 310 es 1360 precision mediump int; 1361 1362 in flat ivec4 var; 1363 out ivec4 color; 1364 1365 void main() 1366 { 1367 color = (var.x > var.y) ? var : ivec4(10); 1368 } 1369 """, 1370 r'\(expression i16vec4 i2imp \(constant ivec4 \(10'), 1371 Test("u32 csel", 1372 """ 1373 #version 310 es 1374 precision mediump int; 1375 1376 in flat uvec4 var; 1377 out uvec4 color; 1378 1379 void main() 1380 { 1381 color = (var.x > var.y) ? var : uvec4(10); 1382 } 1383 """, 1384 r'\(expression u16vec4 u2ump \(constant uvec4 \(10'), 1385 Test("f32 loop counter", 1386 """ 1387 #version 300 es 1388 precision mediump float; 1389 1390 uniform float n, incr; 1391 out float color; 1392 1393 void main() 1394 { 1395 color = 0.0; 1396 for (float x = 0.0; x < n; x += incr) 1397 color += x; 1398 } 1399 """, 1400 r'\(assign \(x\) \(var_ref x\) \(expression float16_t \+ \(var_ref x\) \(var_ref incr'), 1401 Test("i32 loop counter", 1402 """ 1403 #version 310 es 1404 precision mediump float; 1405 precision mediump int; 1406 1407 uniform int n, incr; 1408 out int color; 1409 1410 void main() 1411 { 1412 color = 0; 1413 for (int x = 0; x < n; x += incr) 1414 color += x; 1415 } 1416 """, 1417 r'\(assign \(x\) \(var_ref x\) \(expression int16_t \+ \(var_ref x\) \(expression int16_t i2imp \(var_ref incr'), 1418 Test("u32 loop counter", 1419 """ 1420 #version 310 es 1421 precision mediump float; 1422 precision mediump int; 1423 1424 uniform uint n, incr; 1425 out uint color; 1426 1427 void main() 1428 { 1429 color = 0u; 1430 for (uint x = 0u; x < n; x += incr) 1431 color += x; 1432 } 1433 """, 1434 r'\(assign \(x\) \(var_ref x\) \(expression uint16_t \+ \(var_ref x\) \(expression uint16_t u2ump \(var_ref incr'), 1435 Test("f32 temp array", 1436 """ 1437 #version 300 es 1438 precision mediump float; 1439 1440 uniform float x,y; 1441 out float color; 1442 1443 void main() 1444 { 1445 float a[2] = float[2](x, y); 1446 if (x > 0.0) 1447 a[1] = 3.0; 1448 color = a[0] + a[1]; 1449 } 1450 """, 1451 r'\(expression float16_t f2fmp \(constant float \(3'), 1452 Test("i32 temp array", 1453 """ 1454 #version 310 es 1455 precision mediump int; 1456 1457 uniform int x,y; 1458 out int color; 1459 1460 void main() 1461 { 1462 int a[2] = int[2](x, y); 1463 if (x > 0) 1464 a[1] = 3; 1465 color = a[0] + a[1]; 1466 } 1467 """, 1468 r'\(expression int16_t i2imp \(constant int \(3'), 1469 Test("u32 temp array", 1470 """ 1471 #version 310 es 1472 precision mediump int; 1473 1474 uniform uint x,y; 1475 out uint color; 1476 1477 void main() 1478 { 1479 uint a[2] = uint[2](x, y); 1480 if (x > 0u) 1481 a[1] = 3u; 1482 color = a[0] + a[1]; 1483 } 1484 """, 1485 r'\(expression uint16_t u2ump \(constant uint \(3'), 1486 Test("f32 temp array of array", 1487 """ 1488 #version 310 es 1489 precision mediump float; 1490 1491 uniform float x,y; 1492 out float color; 1493 1494 void main() 1495 { 1496 float a[2][2] = float[2][2](float[2](x, y), float[2](x, y)); 1497 if (x > 0.0) 1498 a[1][1] = 3.0; 1499 color = a[0][0] + a[1][1]; 1500 } 1501 """, 1502 r'\(expression float16_t f2fmp \(constant float \(3'), 1503 Test("i32 temp array of array", 1504 """ 1505 #version 310 es 1506 precision mediump int; 1507 1508 uniform int x,y; 1509 out int color; 1510 1511 void main() 1512 { 1513 int a[2][2] = int[2][2](int[2](x, y), int[2](x, y)); 1514 if (x > 0) 1515 a[1][1] = 3; 1516 color = a[0][0] + a[1][1]; 1517 } 1518 """, 1519 r'\(expression int16_t i2imp \(constant int \(3'), 1520 Test("u32 temp array of array", 1521 """ 1522 #version 310 es 1523 precision mediump int; 1524 1525 uniform uint x,y; 1526 out uint color; 1527 1528 void main() 1529 { 1530 uint a[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y)); 1531 if (x > 0u) 1532 a[1][1] = 3u; 1533 color = a[0][0] + a[1][1]; 1534 } 1535 """, 1536 r'\(expression uint16_t u2ump \(constant uint \(3'), 1537 Test("f32 temp array of array assigned from highp", 1538 """ 1539 #version 310 es 1540 precision mediump float; 1541 1542 uniform float x,y; 1543 out float color; 1544 1545 void main() 1546 { 1547 highp float b[2][2] = float[2][2](float[2](x, y), float[2](x, y)); 1548 float a[2][2]; 1549 a = b; 1550 if (x > 0.0) 1551 a[1][1] = 3.0; 1552 color = a[0][0] + a[1][1]; 1553 } 1554 """, 1555 r'\(expression float16_t f2fmp \(constant float \(3'), 1556 Test("i32 temp array of array assigned from highp", 1557 """ 1558 #version 310 es 1559 precision mediump int; 1560 1561 uniform int x,y; 1562 out int color; 1563 1564 void main() 1565 { 1566 highp int b[2][2] = int[2][2](int[2](x, y), int[2](x, y)); 1567 int a[2][2]; 1568 a = b; 1569 if (x > 0) 1570 a[1][1] = 3; 1571 color = a[0][0] + a[1][1]; 1572 } 1573 """, 1574 r'\(expression int16_t i2imp \(constant int \(3'), 1575 Test("u32 temp array of array assigned from highp", 1576 """ 1577 #version 310 es 1578 precision mediump int; 1579 1580 uniform uint x,y; 1581 out uint color; 1582 1583 void main() 1584 { 1585 highp uint b[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y)); 1586 uint a[2][2]; 1587 a = b; 1588 if (x > 0u) 1589 a[1][1] = 3u; 1590 color = a[0][0] + a[1][1]; 1591 } 1592 """, 1593 r'\(expression uint16_t u2ump \(constant uint \(3'), 1594 Test("f32 temp array of array assigned to highp", 1595 """ 1596 #version 310 es 1597 precision mediump float; 1598 1599 uniform float x,y; 1600 out float color; 1601 1602 void main() 1603 { 1604 float a[2][2] = float[2][2](float[2](x, y), float[2](x, y)); 1605 highp float b[2][2]; 1606 b = a; 1607 a = b; 1608 if (x > 0.0) 1609 a[1][1] = 3.0; 1610 color = a[0][0] + a[1][1]; 1611 } 1612 """, 1613 r'\(expression float16_t f2fmp \(constant float \(3'), 1614 Test("i32 temp array of array assigned to highp", 1615 """ 1616 #version 310 es 1617 precision mediump int; 1618 1619 uniform int x,y; 1620 out int color; 1621 1622 void main() 1623 { 1624 int a[2][2] = int[2][2](int[2](x, y), int[2](x, y)); 1625 highp int b[2][2]; 1626 b = a; 1627 a = b; 1628 if (x > 0) 1629 a[1][1] = 3; 1630 color = a[0][0] + a[1][1]; 1631 } 1632 """, 1633 r'\(expression int16_t i2imp \(constant int \(3'), 1634 Test("u32 temp array of array assigned to highp", 1635 """ 1636 #version 310 es 1637 precision mediump int; 1638 1639 uniform uint x,y; 1640 out uint color; 1641 1642 void main() 1643 { 1644 uint a[2][2] = uint[2][2](uint[2](x, y), uint[2](x, y)); 1645 highp uint b[2][2]; 1646 b = a; 1647 a = b; 1648 if (x > 0u) 1649 a[1][1] = 3u; 1650 color = a[0][0] + a[1][1]; 1651 } 1652 """, 1653 r'\(expression uint16_t u2ump \(constant uint \(3'), 1654 Test("f32 temp array of array returned by function", 1655 """ 1656 #version 310 es 1657 precision mediump float; 1658 1659 uniform float x,y; 1660 out float color; 1661 1662 float[2][2] f(void) 1663 { 1664 return float[2][2](float[2](x, y), float[2](x, y)); 1665 } 1666 1667 void main() 1668 { 1669 float a[2][2] = f(); 1670 if (x > 0.0) 1671 a[1][1] = 3.0; 1672 color = a[0][0] + a[1][1]; 1673 } 1674 """, 1675 r'\(expression float16_t f2fmp \(constant float \(3'), 1676 Test("i32 temp array of array returned by function", 1677 """ 1678 #version 310 es 1679 precision mediump int; 1680 1681 uniform int x,y; 1682 out int color; 1683 1684 int[2][2] f(void) 1685 { 1686 return int[2][2](int[2](x, y), int[2](x, y)); 1687 } 1688 1689 void main() 1690 { 1691 int a[2][2] = f(); 1692 if (x > 0) 1693 a[1][1] = 3; 1694 color = a[0][0] + a[1][1]; 1695 } 1696 """, 1697 r'\(expression int16_t i2imp \(constant int \(3'), 1698 Test("u32 temp array of array returned by function", 1699 """ 1700 #version 310 es 1701 precision mediump int; 1702 1703 uniform uint x,y; 1704 out uint color; 1705 1706 uint[2][2] f(void) 1707 { 1708 return uint[2][2](uint[2](x, y), uint[2](x, y)); 1709 } 1710 1711 void main() 1712 { 1713 uint a[2][2] = f(); 1714 if (x > 0u) 1715 a[1][1] = 3u; 1716 color = a[0][0] + a[1][1]; 1717 } 1718 """, 1719 r'\(expression uint16_t u2ump \(constant uint \(3'), 1720 Test("f32 temp array of array as function out", 1721 """ 1722 #version 310 es 1723 precision mediump float; 1724 1725 uniform float x,y; 1726 out float color; 1727 1728 void f(out float[2][2] v) 1729 { 1730 v = float[2][2](float[2](x, y), float[2](x, y)); 1731 } 1732 1733 void main() 1734 { 1735 float a[2][2]; 1736 f(a); 1737 if (x > 0.0) 1738 a[1][1] = 3.0; 1739 color = a[0][0] + a[1][1]; 1740 } 1741 """, 1742 r'\(expression float16_t f2fmp \(constant float \(3'), 1743 Test("i32 temp array of array as function out", 1744 """ 1745 #version 310 es 1746 precision mediump int; 1747 1748 uniform int x,y; 1749 out int color; 1750 1751 void f(out int[2][2] v) 1752 { 1753 v = int[2][2](int[2](x, y), int[2](x, y)); 1754 } 1755 1756 void main() 1757 { 1758 int a[2][2]; 1759 f(a); 1760 if (x > 0) 1761 a[1][1] = 3; 1762 color = a[0][0] + a[1][1]; 1763 } 1764 """, 1765 r'\(expression int16_t i2imp \(constant int \(3'), 1766 Test("u32 temp array of array as function out", 1767 """ 1768 #version 310 es 1769 precision mediump int; 1770 1771 uniform uint x,y; 1772 out uint color; 1773 1774 void f(out uint[2][2] v) 1775 { 1776 v = uint[2][2](uint[2](x, y), uint[2](x, y)); 1777 } 1778 1779 void main() 1780 { 1781 uint a[2][2]; 1782 f(a); 1783 if (x > 0u) 1784 a[1][1] = 3u; 1785 color = a[0][0] + a[1][1]; 1786 } 1787 """, 1788 r'\(expression uint16_t u2ump \(constant uint \(3'), 1789 Test("f32 temp array of array as function in", 1790 """ 1791 #version 310 es 1792 precision mediump float; 1793 1794 uniform float x,y; 1795 out float color; 1796 1797 float[2][2] f(in float[2][2] v) 1798 { 1799 float t[2][2] = v; 1800 return t; 1801 } 1802 1803 void main() 1804 { 1805 float a[2][2]; 1806 a = f(a); 1807 if (x > 0.0) 1808 a[1][1] = 3.0; 1809 color = a[0][0] + a[1][1]; 1810 } 1811 """, 1812 r'\(expression float16_t f2fmp \(constant float \(3'), 1813 Test("i32 temp array of array as function in", 1814 """ 1815 #version 310 es 1816 precision mediump int; 1817 1818 uniform int x,y; 1819 out int color; 1820 1821 int[2][2] f(in int[2][2] v) 1822 { 1823 int t[2][2] = v; 1824 return t; 1825 } 1826 1827 void main() 1828 { 1829 int a[2][2]; 1830 a = f(a); 1831 if (x > 0) 1832 a[1][1] = 3; 1833 color = a[0][0] + a[1][1]; 1834 } 1835 """, 1836 r'\(expression int16_t i2imp \(constant int \(3'), 1837 Test("u32 temp array of array as function in", 1838 """ 1839 #version 310 es 1840 precision mediump int; 1841 1842 uniform uint x,y; 1843 out uint color; 1844 1845 uint[2][2] f(in uint[2][2] v) 1846 { 1847 uint t[2][2] = v; 1848 return t; 1849 } 1850 1851 void main() 1852 { 1853 uint a[2][2]; 1854 a = f(a); 1855 if (x > 0u) 1856 a[1][1] = 3u; 1857 color = a[0][0] + a[1][1]; 1858 } 1859 """, 1860 r'\(expression uint16_t u2ump \(constant uint \(3'), 1861 Test("f32 temp array of array as function inout", 1862 """ 1863 #version 310 es 1864 precision mediump float; 1865 1866 uniform float x,y; 1867 out float color; 1868 1869 void f(inout float[2][2] v) 1870 { 1871 float t[2][2] = v; 1872 v = t; 1873 } 1874 1875 void main() 1876 { 1877 float a[2][2]; 1878 f(a); 1879 if (x > 0.0) 1880 a[1][1] = 3.0; 1881 color = a[0][0] + a[1][1]; 1882 } 1883 """, 1884 r'\(expression float16_t f2fmp \(constant float \(3'), 1885 Test("i32 temp array of array as function inout", 1886 """ 1887 #version 310 es 1888 precision mediump int; 1889 1890 uniform int x,y; 1891 out int color; 1892 1893 void f(inout int[2][2] v) 1894 { 1895 int t[2][2] = v; 1896 v = t; 1897 } 1898 1899 void main() 1900 { 1901 int a[2][2]; 1902 f(a); 1903 if (x > 0) 1904 a[1][1] = 3; 1905 color = a[0][0] + a[1][1]; 1906 } 1907 """, 1908 r'\(expression int16_t i2imp \(constant int \(3'), 1909 Test("u32 temp array of array as function inout", 1910 """ 1911 #version 310 es 1912 precision mediump int; 1913 1914 uniform uint x,y; 1915 out uint color; 1916 1917 void f(inout uint[2][2] v) 1918 { 1919 uint t[2][2] = v; 1920 v = t; 1921 } 1922 1923 void main() 1924 { 1925 uint a[2][2]; 1926 f(a); 1927 if (x > 0u) 1928 a[1][1] = 3u; 1929 color = a[0][0] + a[1][1]; 1930 } 1931 """, 1932 r'\(expression uint16_t u2ump \(constant uint \(3'), 1933 Test("f32 temp struct (not lowered in the presence of control flow - TODO)", 1934 """ 1935 #version 300 es 1936 precision mediump float; 1937 1938 uniform float x,y; 1939 out float color; 1940 1941 void main() 1942 { 1943 struct { float x,y; } s; 1944 s.x = x; 1945 s.y = y; 1946 if (x > 0.0) 1947 s.y = 3.0; 1948 color = s.x + s.y; 1949 } 1950 """, 1951 r'\(constant float \(3'), # should be float16_t 1952 Test("i32 temp struct (not lowered in the presence of control flow - TODO)", 1953 """ 1954 #version 300 es 1955 precision mediump int; 1956 1957 uniform int x,y; 1958 out int color; 1959 1960 void main() 1961 { 1962 struct { int x,y; } s; 1963 s.x = x; 1964 s.y = y; 1965 if (x > 0) 1966 s.y = 3; 1967 color = s.x + s.y; 1968 } 1969 """, 1970 r'\(constant int \(3'), # should be int16_t 1971 Test("u32 temp struct (not lowered in the presence of control flow - TODO)", 1972 """ 1973 #version 300 es 1974 precision mediump int; 1975 1976 uniform uint x,y; 1977 out uint color; 1978 1979 void main() 1980 { 1981 struct { uint x,y; } s; 1982 s.x = x; 1983 s.y = y; 1984 if (x > 0u) 1985 s.y = 3u; 1986 color = s.x + s.y; 1987 } 1988 """, 1989 r'\(constant uint \(3'), # should be uint16_t 1990 1991 Test("vec4 constructor from float", 1992 """ 1993 uniform highp float a; 1994 uniform mediump float b; 1995 1996 void main() 1997 { 1998 gl_FragColor = vec4(a) * b; 1999 } 2000 """, 2001 r'\(expression vec4 \* \(swiz xxxx \(var_ref a\) \)\(expression float f162f \(var_ref b\) \) \)'), 2002 2003 Test("respect copies", 2004 """ 2005 uniform mediump float a, b; 2006 2007 void main() 2008 { 2009 highp float x = a; 2010 gl_FragColor.x = x * b; 2011 } 2012 """, 2013 r'expression float \* \(expression float f162f \(var_ref a\) \) \(expression float f162f \(var_ref b\) \) '), # should be uint16_t 2014 2015 Test("conversion constructor precision", 2016 """ 2017 #version 300 es 2018 uniform mediump uint a; 2019 out highp float result; 2020 2021 void main() 2022 { 2023 /* Constructors don't have a precision qualifier themselves, but 2024 * constructors are an operation, and so they do the usual "get 2025 * precision from my operands, or default to the precision of the 2026 * lvalue" rule. So, the u2f is done at mediump due to a's precision. 2027 */ 2028 result = float(a); 2029 } 2030 """, 2031 r'expression float16_t u2f \(expression uint16_t u2ump \(var_ref a\) \)'), # should be uint16_t 2032 2033] 2034 2035 2036def compile_shader(standalone_compiler, source): 2037 with tempfile.NamedTemporaryFile(mode='wt', suffix='.frag') as source_file: 2038 print(source, file=source_file) 2039 source_file.flush() 2040 return subprocess.check_output([standalone_compiler, 2041 '--version', '300', 2042 '--lower-precision', 2043 '--dump-lir', 2044 source_file.name], 2045 universal_newlines=True) 2046 2047 2048def run_test(standalone_compiler, test): 2049 ir = compile_shader(standalone_compiler, test.source) 2050 2051 if re.search(test.match_re, ir) is None: 2052 print(ir) 2053 return False 2054 2055 return True 2056 2057 2058def main(): 2059 standalone_compiler = sys.argv[1] 2060 passed = 0 2061 2062 for test in TESTS: 2063 print('Testing {} ... '.format(test.name), end='') 2064 2065 result = run_test(standalone_compiler, test) 2066 2067 if result: 2068 print('PASS') 2069 passed += 1 2070 else: 2071 print('FAIL') 2072 2073 print('{}/{} tests returned correct results'.format(passed, len(TESTS))) 2074 sys.exit(0 if passed == len(TESTS) else 1) 2075 2076 2077if __name__ == '__main__': 2078 main() 2079