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