Hash :
d285d6a7
Author :
Date :
2021-11-23T23:12:00
Vulkan: Use VK_EXT_depth_clip_control Bug: angleproject:6679 Change-Id: Iea3b7a2d8db630dcea19836732de8f9e0a7a568f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3298356 Reviewed-by: mohan maiya <m.maiya@samsung.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
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
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// vk_cache_utils.cpp:
// Contains the classes for the Pipeline State Object cache as well as the RenderPass cache.
// Also contains the structures for the packed descriptions for the RenderPass and Pipeline.
//
#include "libANGLE/renderer/vulkan/vk_cache_utils.h"
#include "common/aligned_memory.h"
#include "common/vulkan/vk_google_filtering_precision.h"
#include "libANGLE/BlobCache.h"
#include "libANGLE/VertexAttribute.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/ProgramVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
#include <type_traits>
namespace rx
{
namespace vk
{
namespace
{
static_assert(static_cast<uint32_t>(RenderPassLoadOp::Load) == VK_ATTACHMENT_LOAD_OP_LOAD,
"ConvertRenderPassLoadOpToVkLoadOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassLoadOp::Clear) == VK_ATTACHMENT_LOAD_OP_CLEAR,
"ConvertRenderPassLoadOpToVkLoadOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassLoadOp::DontCare) == VK_ATTACHMENT_LOAD_OP_DONT_CARE,
"ConvertRenderPassLoadOpToVkLoadOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassLoadOp::None) == 3,
"ConvertRenderPassLoadOpToVkLoadOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassStoreOp::Store) == VK_ATTACHMENT_STORE_OP_STORE,
"ConvertRenderPassStoreOpToVkStoreOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassStoreOp::DontCare) ==
VK_ATTACHMENT_STORE_OP_DONT_CARE,
"ConvertRenderPassStoreOpToVkStoreOp must be updated");
static_assert(static_cast<uint32_t>(RenderPassStoreOp::None) == 2,
"ConvertRenderPassStoreOpToVkStoreOp must be updated");
VkAttachmentLoadOp ConvertRenderPassLoadOpToVkLoadOp(RenderPassLoadOp loadOp)
{
return loadOp == RenderPassLoadOp::None ? VK_ATTACHMENT_LOAD_OP_NONE_EXT
: static_cast<VkAttachmentLoadOp>(loadOp);
}
VkAttachmentStoreOp ConvertRenderPassStoreOpToVkStoreOp(RenderPassStoreOp storeOp)
{
return storeOp == RenderPassStoreOp::None ? VK_ATTACHMENT_STORE_OP_NONE_EXT
: static_cast<VkAttachmentStoreOp>(storeOp);
}
uint8_t PackGLBlendOp(GLenum blendOp)
{
switch (blendOp)
{
case GL_FUNC_ADD:
return static_cast<uint8_t>(VK_BLEND_OP_ADD);
case GL_FUNC_SUBTRACT:
return static_cast<uint8_t>(VK_BLEND_OP_SUBTRACT);
case GL_FUNC_REVERSE_SUBTRACT:
return static_cast<uint8_t>(VK_BLEND_OP_REVERSE_SUBTRACT);
case GL_MIN:
return static_cast<uint8_t>(VK_BLEND_OP_MIN);
case GL_MAX:
return static_cast<uint8_t>(VK_BLEND_OP_MAX);
default:
UNREACHABLE();
return 0;
}
}
uint8_t PackGLBlendFactor(GLenum blendFactor)
{
switch (blendFactor)
{
case GL_ZERO:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ZERO);
case GL_ONE:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE);
case GL_SRC_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_SRC_COLOR);
case GL_DST_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_DST_COLOR);
case GL_ONE_MINUS_SRC_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR);
case GL_SRC_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_SRC_ALPHA);
case GL_ONE_MINUS_SRC_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
case GL_DST_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_DST_ALPHA);
case GL_ONE_MINUS_DST_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA);
case GL_ONE_MINUS_DST_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR);
case GL_SRC_ALPHA_SATURATE:
return static_cast<uint8_t>(VK_BLEND_FACTOR_SRC_ALPHA_SATURATE);
case GL_CONSTANT_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_CONSTANT_COLOR);
case GL_CONSTANT_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_CONSTANT_ALPHA);
case GL_ONE_MINUS_CONSTANT_COLOR:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR);
case GL_ONE_MINUS_CONSTANT_ALPHA:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA);
case GL_SRC1_COLOR_EXT:
return static_cast<uint8_t>(VK_BLEND_FACTOR_SRC1_COLOR);
case GL_SRC1_ALPHA_EXT:
return static_cast<uint8_t>(VK_BLEND_FACTOR_SRC1_ALPHA);
case GL_ONE_MINUS_SRC1_COLOR_EXT:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR);
case GL_ONE_MINUS_SRC1_ALPHA_EXT:
return static_cast<uint8_t>(VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA);
default:
UNREACHABLE();
return 0;
}
}
VkStencilOp PackGLStencilOp(GLenum compareOp)
{
switch (compareOp)
{
case GL_KEEP:
return VK_STENCIL_OP_KEEP;
case GL_ZERO:
return VK_STENCIL_OP_ZERO;
case GL_REPLACE:
return VK_STENCIL_OP_REPLACE;
case GL_INCR:
return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
case GL_DECR:
return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
case GL_INCR_WRAP:
return VK_STENCIL_OP_INCREMENT_AND_WRAP;
case GL_DECR_WRAP:
return VK_STENCIL_OP_DECREMENT_AND_WRAP;
case GL_INVERT:
return VK_STENCIL_OP_INVERT;
default:
UNREACHABLE();
return VK_STENCIL_OP_KEEP;
}
}
VkCompareOp PackGLCompareFunc(GLenum compareFunc)
{
switch (compareFunc)
{
case GL_NEVER:
return VK_COMPARE_OP_NEVER;
case GL_ALWAYS:
return VK_COMPARE_OP_ALWAYS;
case GL_LESS:
return VK_COMPARE_OP_LESS;
case GL_LEQUAL:
return VK_COMPARE_OP_LESS_OR_EQUAL;
case GL_EQUAL:
return VK_COMPARE_OP_EQUAL;
case GL_GREATER:
return VK_COMPARE_OP_GREATER;
case GL_GEQUAL:
return VK_COMPARE_OP_GREATER_OR_EQUAL;
case GL_NOTEQUAL:
return VK_COMPARE_OP_NOT_EQUAL;
default:
UNREACHABLE();
return VK_COMPARE_OP_NEVER;
}
}
void UnpackAttachmentDesc(VkAttachmentDescription *desc,
angle::FormatID formatID,
uint8_t samples,
const PackedAttachmentOpsDesc &ops)
{
desc->flags = 0;
desc->format = GetVkFormatFromFormatID(formatID);
desc->samples = gl_vk::GetSamples(samples);
desc->loadOp = ConvertRenderPassLoadOpToVkLoadOp(static_cast<RenderPassLoadOp>(ops.loadOp));
desc->storeOp =
ConvertRenderPassStoreOpToVkStoreOp(static_cast<RenderPassStoreOp>(ops.storeOp));
desc->stencilLoadOp =
ConvertRenderPassLoadOpToVkLoadOp(static_cast<RenderPassLoadOp>(ops.stencilLoadOp));
desc->stencilStoreOp =
ConvertRenderPassStoreOpToVkStoreOp(static_cast<RenderPassStoreOp>(ops.stencilStoreOp));
desc->initialLayout =
ConvertImageLayoutToVkImageLayout(static_cast<ImageLayout>(ops.initialLayout));
desc->finalLayout =
ConvertImageLayoutToVkImageLayout(static_cast<ImageLayout>(ops.finalLayout));
}
void UnpackColorResolveAttachmentDesc(VkAttachmentDescription *desc,
angle::FormatID formatID,
bool usedAsInputAttachment,
bool isInvalidated)
{
desc->flags = 0;
desc->format = GetVkFormatFromFormatID(formatID);
// This function is for color resolve attachments.
const angle::Format &angleFormat = angle::Format::Get(formatID);
ASSERT(angleFormat.depthBits == 0 && angleFormat.stencilBits == 0);
// Resolve attachments always have a sample count of 1.
//
// If the corresponding color attachment needs to take its initial value from the resolve
// attachment (i.e. needs to be unresolved), loadOp needs to be set to LOAD, otherwise it should
// be DONT_CARE as it gets overwritten during resolve.
//
// storeOp should be STORE. If the attachment is invalidated, it is set to DONT_CARE.
desc->samples = VK_SAMPLE_COUNT_1_BIT;
desc->loadOp =
usedAsInputAttachment ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
desc->storeOp = isInvalidated ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
desc->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
desc->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
desc->initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
desc->finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
void UnpackDepthStencilResolveAttachmentDesc(VkAttachmentDescription *desc,
angle::FormatID formatID,
bool usedAsDepthInputAttachment,
bool usedAsStencilInputAttachment,
bool isDepthInvalidated,
bool isStencilInvalidated)
{
// There cannot be simultaneous usages of the depth/stencil resolve image, as depth/stencil
// resolve currently only comes from depth/stencil renderbuffers.
desc->flags = 0;
desc->format = GetVkFormatFromFormatID(formatID);
// This function is for depth/stencil resolve attachment.
const angle::Format &angleFormat = angle::Format::Get(formatID);
ASSERT(angleFormat.depthBits != 0 || angleFormat.stencilBits != 0);
// Missing aspects are folded in is*Invalidated parameters, so no need to double check.
ASSERT(angleFormat.depthBits > 0 || isDepthInvalidated);
ASSERT(angleFormat.stencilBits > 0 || isStencilInvalidated);
// Similarly to color resolve attachments, sample count is 1, loadOp is LOAD or DONT_CARE based
// on whether unresolve is required, and storeOp is STORE or DONT_CARE based on whether the
// attachment is invalidated or the aspect exists.
desc->samples = VK_SAMPLE_COUNT_1_BIT;
desc->loadOp =
usedAsDepthInputAttachment ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
desc->storeOp =
isDepthInvalidated ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
desc->stencilLoadOp =
usedAsStencilInputAttachment ? VK_ATTACHMENT_LOAD_OP_LOAD : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
desc->stencilStoreOp =
isStencilInvalidated ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
desc->initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
desc->finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
}
void UnpackStencilState(const PackedStencilOpState &packedState,
uint8_t stencilReference,
VkStencilOpState *stateOut)
{
stateOut->failOp = static_cast<VkStencilOp>(packedState.ops.fail);
stateOut->passOp = static_cast<VkStencilOp>(packedState.ops.pass);
stateOut->depthFailOp = static_cast<VkStencilOp>(packedState.ops.depthFail);
stateOut->compareOp = static_cast<VkCompareOp>(packedState.ops.compare);
stateOut->compareMask = packedState.compareMask;
stateOut->writeMask = packedState.writeMask;
stateOut->reference = stencilReference;
}
void UnpackBlendAttachmentState(const PackedColorBlendAttachmentState &packedState,
VkPipelineColorBlendAttachmentState *stateOut)
{
stateOut->srcColorBlendFactor = static_cast<VkBlendFactor>(packedState.srcColorBlendFactor);
stateOut->dstColorBlendFactor = static_cast<VkBlendFactor>(packedState.dstColorBlendFactor);
stateOut->colorBlendOp = static_cast<VkBlendOp>(packedState.colorBlendOp);
stateOut->srcAlphaBlendFactor = static_cast<VkBlendFactor>(packedState.srcAlphaBlendFactor);
stateOut->dstAlphaBlendFactor = static_cast<VkBlendFactor>(packedState.dstAlphaBlendFactor);
stateOut->alphaBlendOp = static_cast<VkBlendOp>(packedState.alphaBlendOp);
}
void SetPipelineShaderStageInfo(const VkStructureType type,
const VkShaderStageFlagBits stage,
const VkShaderModule module,
const VkSpecializationInfo &specializationInfo,
VkPipelineShaderStageCreateInfo *shaderStage)
{
shaderStage->sType = type;
shaderStage->flags = 0;
shaderStage->stage = stage;
shaderStage->module = module;
shaderStage->pName = "main";
shaderStage->pSpecializationInfo = &specializationInfo;
}
// Defines a subpass that uses the resolve attachments as input attachments to initialize color and
// depth/stencil attachments that need to be "unresolved" at the start of the render pass. The
// subpass will only contain the attachments that need to be unresolved to simplify the shader that
// performs the operations.
void InitializeUnresolveSubpass(
const RenderPassDesc &desc,
const gl::DrawBuffersVector<VkAttachmentReference> &drawSubpassColorAttachmentRefs,
const gl::DrawBuffersVector<VkAttachmentReference> &drawSubpassResolveAttachmentRefs,
const VkAttachmentReference &depthStencilAttachmentRef,
const VkAttachmentReference2KHR &depthStencilResolveAttachmentRef,
gl::DrawBuffersVector<VkAttachmentReference> *unresolveColorAttachmentRefs,
VkAttachmentReference *unresolveDepthStencilAttachmentRef,
FramebufferAttachmentsVector<VkAttachmentReference> *unresolveInputAttachmentRefs,
FramebufferAttachmentsVector<uint32_t> *unresolvePreserveAttachmentRefs,
VkSubpassDescription *subpassDesc)
{
for (uint32_t colorIndexGL = 0; colorIndexGL < desc.colorAttachmentRange(); ++colorIndexGL)
{
// Assume the GL Framebuffer has the following attachments enabled:
//
// GL Color 0
// GL Color 3
// GL Color 4
// GL Color 6
// GL Color 7
// GL Depth/Stencil
//
// Additionally, assume Color 0, 4 and 6 are multisampled-render-to-texture (or for any
// other reason) have corresponding resolve attachments. Furthermore, say Color 4 and 6
// require an initial unresolve operation.
//
// In the above example, the render pass is created with the following attachments:
//
// RP Attachment[0] <- corresponding to GL Color 0
// RP Attachment[1] <- corresponding to GL Color 3
// RP Attachment[2] <- corresponding to GL Color 4
// RP Attachment[3] <- corresponding to GL Color 6
// RP Attachment[4] <- corresponding to GL Color 7
// RP Attachment[5] <- corresponding to GL Depth/Stencil
// RP Attachment[6] <- corresponding to resolve attachment of GL Color 0
// RP Attachment[7] <- corresponding to resolve attachment of GL Color 4
// RP Attachment[8] <- corresponding to resolve attachment of GL Color 6
//
// If the depth/stencil attachment is to be resolved, the following attachment would also be
// present:
//
// RP Attachment[9] <- corresponding to resolve attachment of GL Depth/Stencil
//
// The subpass that takes the application draw calls has the following attachments, creating
// the mapping from the Vulkan attachment indices (i.e. RP attachment indices) to GL indices
// as indicated by the GL shaders:
//
// Subpass[1] Color[0] -> RP Attachment[0]
// Subpass[1] Color[1] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Color[2] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Color[3] -> RP Attachment[1]
// Subpass[1] Color[4] -> RP Attachment[2]
// Subpass[1] Color[5] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Color[6] -> RP Attachment[3]
// Subpass[1] Color[7] -> RP Attachment[4]
// Subpass[1] Depth/Stencil -> RP Attachment[5]
// Subpass[1] Resolve[0] -> RP Attachment[6]
// Subpass[1] Resolve[1] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Resolve[2] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Resolve[3] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Resolve[4] -> RP Attachment[7]
// Subpass[1] Resolve[5] -> VK_ATTACHMENT_UNUSED
// Subpass[1] Resolve[6] -> RP Attachment[8]
// Subpass[1] Resolve[7] -> VK_ATTACHMENT_UNUSED
//
// With depth/stencil resolve attachment:
//
// Subpass[1] Depth/Stencil Resolve -> RP Attachment[9]
//
// The initial subpass that's created here is (remember that in the above example Color 4
// and 6 need to be unresolved):
//
// Subpass[0] Input[0] -> RP Attachment[7] = Subpass[1] Resolve[4]
// Subpass[0] Input[1] -> RP Attachment[8] = Subpass[1] Resolve[6]
// Subpass[0] Color[0] -> RP Attachment[2] = Subpass[1] Color[4]
// Subpass[0] Color[1] -> RP Attachment[3] = Subpass[1] Color[6]
//
// The trick here therefore is to use the color attachment refs already created for the
// application draw subpass indexed with colorIndexGL.
//
// If depth/stencil needs to be unresolved:
//
// Subpass[0] Input[2] -> RP Attachment[9] = Subpass[1] Depth/Stencil Resolve
// Subpass[0] Color[2] -> RP Attachment[5] = Subpass[1] Depth/Stencil
//
// As an additional note, the attachments that are not used in the unresolve subpass must be
// preserved. That is color attachments and the depth/stencil attachment if any. Resolve
// attachments are rewritten by the next subpass, so they don't need to be preserved. Note
// that there's no need to preserve attachments whose loadOp is DONT_CARE. For simplicity,
// we preserve those as well. The driver would ideally avoid preserving attachments with
// loadOp=DONT_CARE.
//
// With the above example:
//
// Subpass[0] Preserve[0] -> RP Attachment[0] = Subpass[1] Color[0]
// Subpass[0] Preserve[1] -> RP Attachment[1] = Subpass[1] Color[3]
// Subpass[0] Preserve[2] -> RP Attachment[4] = Subpass[1] Color[7]
//
// If depth/stencil is not unresolved:
//
// Subpass[0] Preserve[3] -> RP Attachment[5] = Subpass[1] Depth/Stencil
//
// Again, the color attachment refs already created for the application draw subpass can be
// used indexed with colorIndexGL.
if (!desc.hasColorUnresolveAttachment(colorIndexGL))
{
if (desc.isColorAttachmentEnabled(colorIndexGL))
{
unresolvePreserveAttachmentRefs->push_back(
drawSubpassColorAttachmentRefs[colorIndexGL].attachment);
}
continue;
}
ASSERT(desc.isColorAttachmentEnabled(colorIndexGL));
ASSERT(desc.hasColorResolveAttachment(colorIndexGL));
ASSERT(drawSubpassColorAttachmentRefs[colorIndexGL].attachment != VK_ATTACHMENT_UNUSED);
ASSERT(drawSubpassResolveAttachmentRefs[colorIndexGL].attachment != VK_ATTACHMENT_UNUSED);
unresolveColorAttachmentRefs->push_back(drawSubpassColorAttachmentRefs[colorIndexGL]);
unresolveInputAttachmentRefs->push_back(drawSubpassResolveAttachmentRefs[colorIndexGL]);
// Note the input attachment layout should be shader read-only. The subpass dependency
// will take care of transitioning the layout of the resolve attachment to color attachment
// automatically.
unresolveInputAttachmentRefs->back().layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
if (desc.hasDepthStencilUnresolveAttachment())
{
ASSERT(desc.hasDepthStencilAttachment());
ASSERT(desc.hasDepthStencilResolveAttachment());
*unresolveDepthStencilAttachmentRef = depthStencilAttachmentRef;
VkAttachmentReference unresolveDepthStencilInputAttachmentRef = {};
unresolveDepthStencilInputAttachmentRef.attachment =
depthStencilResolveAttachmentRef.attachment;
unresolveDepthStencilInputAttachmentRef.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
unresolveInputAttachmentRefs->push_back(unresolveDepthStencilInputAttachmentRef);
}
else if (desc.hasDepthStencilAttachment())
{
// Preserve the depth/stencil attachment if not unresolved. Again, there's no need to
// preserve this attachment if loadOp=DONT_CARE, but we do for simplicity.
unresolvePreserveAttachmentRefs->push_back(depthStencilAttachmentRef.attachment);
}
ASSERT(!unresolveColorAttachmentRefs->empty() ||
unresolveDepthStencilAttachmentRef->attachment != VK_ATTACHMENT_UNUSED);
ASSERT(unresolveColorAttachmentRefs->size() +
(desc.hasDepthStencilUnresolveAttachment() ? 1 : 0) ==
unresolveInputAttachmentRefs->size());
subpassDesc->flags = 0;
subpassDesc->pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpassDesc->inputAttachmentCount = static_cast<uint32_t>(unresolveInputAttachmentRefs->size());
subpassDesc->pInputAttachments = unresolveInputAttachmentRefs->data();
subpassDesc->colorAttachmentCount = static_cast<uint32_t>(unresolveColorAttachmentRefs->size());
subpassDesc->pColorAttachments = unresolveColorAttachmentRefs->data();
subpassDesc->pResolveAttachments = nullptr;
subpassDesc->pDepthStencilAttachment = unresolveDepthStencilAttachmentRef;
subpassDesc->preserveAttachmentCount =
static_cast<uint32_t>(unresolvePreserveAttachmentRefs->size());
subpassDesc->pPreserveAttachments = unresolvePreserveAttachmentRefs->data();
}
// There is normally one subpass, and occasionally another for the unresolve operation.
constexpr size_t kSubpassFastVectorSize = 2;
template <typename T>
using SubpassVector = angle::FastVector<T, kSubpassFastVectorSize>;
void InitializeUnresolveSubpassDependencies(const SubpassVector<VkSubpassDescription> &subpassDesc,
bool unresolveColor,
bool unresolveDepthStencil,
std::vector<VkSubpassDependency> *subpassDependencies)
{
ASSERT(subpassDesc.size() >= 2);
ASSERT(unresolveColor || unresolveDepthStencil);
// The unresolve subpass is the first subpass. The application draw subpass is the next one.
constexpr uint32_t kUnresolveSubpassIndex = 0;
constexpr uint32_t kDrawSubpassIndex = 1;
// A subpass dependency is needed between the unresolve and draw subpasses. There are two
// hazards here:
//
// - Subpass 0 writes to color/depth/stencil attachments, subpass 1 writes to the same
// attachments. This is a WaW hazard (color/depth/stencil write -> color/depth/stencil write)
// similar to when two subsequent render passes write to the same images.
// - Subpass 0 reads from resolve attachments, subpass 1 writes to the same resolve attachments.
// This is a WaR hazard (fragment shader read -> color write) which only requires an execution
// barrier.
//
// Note: the DEPENDENCY_BY_REGION flag is necessary to create a "framebuffer-local" dependency,
// as opposed to "framebuffer-global". The latter is effectively a render pass break. The
// former creates a dependency per framebuffer region. If dependency scopes correspond to
// attachments with:
//
// - Same sample count: dependency is at sample granularity
// - Different sample count: dependency is at pixel granularity
//
// The latter is clarified by the spec as such:
//
// > Practically, the pixel vs sample granularity dependency means that if an input attachment
// > has a different number of samples than the pipeline's rasterizationSamples, then a fragment
// > can access any sample in the input attachment's pixel even if it only uses
// > framebuffer-local dependencies.
//
// The dependency for the first hazard above (attachment write -> attachment write) is on
// same-sample attachments, so it will not allow the use of input attachments as required by the
// unresolve subpass. As a result, even though the second hazard seems to be subsumed by the
// first (its src stage is earlier and its dst stage is the same), a separate dependency is
// created for it just to obtain a pixel granularity dependency.
//
// Note: depth/stencil resolve is considered to be done in the color write stage:
//
// > Moving to the next subpass automatically performs any multisample resolve operations in the
// > subpass being ended. End-of-subpass multisample resolves are treated as color attachment
// > writes for the purposes of synchronization. This applies to resolve operations for both
// > color and depth/stencil attachments. That is, they are considered to execute in the
// > VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT pipeline stage and their writes are
// > synchronized with VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT.
subpassDependencies->emplace_back();
VkSubpassDependency *dependency = &subpassDependencies->back();
constexpr VkPipelineStageFlags kColorWriteStage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
constexpr VkPipelineStageFlags kColorReadWriteStage =
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
constexpr VkAccessFlags kColorWriteFlags = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
constexpr VkAccessFlags kColorReadWriteFlags =
kColorWriteFlags | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
constexpr VkPipelineStageFlags kDepthStencilWriteStage =
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
constexpr VkPipelineStageFlags kDepthStencilReadWriteStage =
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
constexpr VkAccessFlags kDepthStencilWriteFlags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
constexpr VkAccessFlags kDepthStencilReadWriteFlags =
kDepthStencilWriteFlags | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
VkPipelineStageFlags attachmentWriteStages = 0;
VkPipelineStageFlags attachmentReadWriteStages = 0;
VkAccessFlags attachmentWriteFlags = 0;
VkAccessFlags attachmentReadWriteFlags = 0;
if (unresolveColor)
{
attachmentWriteStages |= kColorWriteStage;
attachmentReadWriteStages |= kColorReadWriteStage;
attachmentWriteFlags |= kColorWriteFlags;
attachmentReadWriteFlags |= kColorReadWriteFlags;
}
if (unresolveDepthStencil)
{
attachmentWriteStages |= kDepthStencilWriteStage;
attachmentReadWriteStages |= kDepthStencilReadWriteStage;
attachmentWriteFlags |= kDepthStencilWriteFlags;
attachmentReadWriteFlags |= kDepthStencilReadWriteFlags;
}
dependency->srcSubpass = kUnresolveSubpassIndex;
dependency->dstSubpass = kDrawSubpassIndex;
dependency->srcStageMask = attachmentWriteStages;
dependency->dstStageMask = attachmentReadWriteStages;
dependency->srcAccessMask = attachmentWriteFlags;
dependency->dstAccessMask = attachmentReadWriteFlags;
dependency->dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
subpassDependencies->emplace_back();
dependency = &subpassDependencies->back();
// Note again that depth/stencil resolve is considered to be done in the color output stage.
dependency->srcSubpass = kUnresolveSubpassIndex;
dependency->dstSubpass = kDrawSubpassIndex;
dependency->srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependency->dstStageMask = kColorWriteStage;
dependency->srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
dependency->dstAccessMask = kColorWriteFlags;
dependency->dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
}
void InitializeInputAttachmentSubpassDependencies(
std::vector<VkSubpassDependency> *subpassDependencies,
uint32_t subpassIndex)
{
subpassDependencies->emplace_back();
VkSubpassDependency *dependency = &subpassDependencies->back();
dependency->srcSubpass = subpassIndex;
dependency->dstSubpass = subpassIndex;
dependency->srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependency->dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependency->srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependency->dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
dependency->dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
}
void ToAttachmentDesciption2(const VkAttachmentDescription &desc,
VkAttachmentDescription2KHR *desc2Out)
{
*desc2Out = {};
desc2Out->sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION_2_KHR;
desc2Out->flags = desc.flags;
desc2Out->format = desc.format;
desc2Out->samples = desc.samples;
desc2Out->loadOp = desc.loadOp;
desc2Out->storeOp = desc.storeOp;
desc2Out->stencilLoadOp = desc.stencilLoadOp;
desc2Out->stencilStoreOp = desc.stencilStoreOp;
desc2Out->initialLayout = desc.initialLayout;
desc2Out->finalLayout = desc.finalLayout;
}
void ToAttachmentReference2(const VkAttachmentReference &ref,
VkImageAspectFlags aspectMask,
VkAttachmentReference2KHR *ref2Out)
{
*ref2Out = {};
ref2Out->sType = VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR;
ref2Out->attachment = ref.attachment;
ref2Out->layout = ref.layout;
ref2Out->aspectMask = aspectMask;
}
void ToSubpassDescription2(const VkSubpassDescription &desc,
const FramebufferAttachmentsVector<VkAttachmentReference2KHR> &inputRefs,
const gl::DrawBuffersVector<VkAttachmentReference2KHR> &colorRefs,
const gl::DrawBuffersVector<VkAttachmentReference2KHR> &resolveRefs,
const VkAttachmentReference2KHR &depthStencilRef,
uint32_t viewMask,
VkSubpassDescription2KHR *desc2Out)
{
*desc2Out = {};
desc2Out->sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_2_KHR;
desc2Out->flags = desc.flags;
desc2Out->pipelineBindPoint = desc.pipelineBindPoint;
desc2Out->viewMask = viewMask;
desc2Out->inputAttachmentCount = static_cast<uint32_t>(inputRefs.size());
desc2Out->pInputAttachments = !inputRefs.empty() ? inputRefs.data() : nullptr;
desc2Out->colorAttachmentCount = static_cast<uint32_t>(colorRefs.size());
desc2Out->pColorAttachments = !colorRefs.empty() ? colorRefs.data() : nullptr;
desc2Out->pResolveAttachments = !resolveRefs.empty() ? resolveRefs.data() : nullptr;
desc2Out->pDepthStencilAttachment = desc.pDepthStencilAttachment ? &depthStencilRef : nullptr;
desc2Out->preserveAttachmentCount = desc.preserveAttachmentCount;
desc2Out->pPreserveAttachments = desc.pPreserveAttachments;
}
void ToSubpassDependency2(const VkSubpassDependency &dep, VkSubpassDependency2KHR *dep2Out)
{
*dep2Out = {};
dep2Out->sType = VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2_KHR;
dep2Out->srcSubpass = dep.srcSubpass;
dep2Out->dstSubpass = dep.dstSubpass;
dep2Out->srcStageMask = dep.srcStageMask;
dep2Out->dstStageMask = dep.dstStageMask;
dep2Out->srcAccessMask = dep.srcAccessMask;
dep2Out->dstAccessMask = dep.dstAccessMask;
dep2Out->dependencyFlags = dep.dependencyFlags;
}
angle::Result CreateRenderPass2(Context *context,
const VkRenderPassCreateInfo &createInfo,
const VkSubpassDescriptionDepthStencilResolve &depthStencilResolve,
const VkRenderPassMultiviewCreateInfo &multiviewInfo,
bool unresolveDepth,
bool unresolveStencil,
bool isRenderToTexture,
uint8_t renderToTextureSamples,
RenderPass *renderPass)
{
// Convert the attachments to VkAttachmentDescription2.
FramebufferAttachmentArray<VkAttachmentDescription2KHR> attachmentDescs;
for (uint32_t index = 0; index < createInfo.attachmentCount; ++index)
{
ToAttachmentDesciption2(createInfo.pAttachments[index], &attachmentDescs[index]);
}
// Convert subpass attachments to VkAttachmentReference2 and the subpass description to
// VkSubpassDescription2.
SubpassVector<FramebufferAttachmentsVector<VkAttachmentReference2KHR>>
subpassInputAttachmentRefs(createInfo.subpassCount);
SubpassVector<gl::DrawBuffersVector<VkAttachmentReference2KHR>> subpassColorAttachmentRefs(
createInfo.subpassCount);
SubpassVector<gl::DrawBuffersVector<VkAttachmentReference2KHR>> subpassResolveAttachmentRefs(
createInfo.subpassCount);
SubpassVector<VkAttachmentReference2KHR> subpassDepthStencilAttachmentRefs(
createInfo.subpassCount);
SubpassVector<VkSubpassDescription2KHR> subpassDescriptions(createInfo.subpassCount);
for (uint32_t subpass = 0; subpass < createInfo.subpassCount; ++subpass)
{
const VkSubpassDescription &desc = createInfo.pSubpasses[subpass];
FramebufferAttachmentsVector<VkAttachmentReference2KHR> &inputRefs =
subpassInputAttachmentRefs[subpass];
gl::DrawBuffersVector<VkAttachmentReference2KHR> &colorRefs =
subpassColorAttachmentRefs[subpass];
gl::DrawBuffersVector<VkAttachmentReference2KHR> &resolveRefs =
subpassResolveAttachmentRefs[subpass];
VkAttachmentReference2KHR &depthStencilRef = subpassDepthStencilAttachmentRefs[subpass];
inputRefs.resize(desc.inputAttachmentCount);
colorRefs.resize(desc.colorAttachmentCount);
// Convert subpass attachment references.
for (uint32_t index = 0; index < desc.inputAttachmentCount; ++index)
{
VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
if (index >= desc.colorAttachmentCount)
{
// Set the aspect of the depth/stencil input attachment (of which there can be only
// one).
ASSERT(index + 1 == desc.inputAttachmentCount);
aspectMask = 0;
if (unresolveDepth)
{
aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
}
if (unresolveStencil)
{
aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
}
ASSERT(aspectMask != 0);
}
ToAttachmentReference2(desc.pInputAttachments[index], aspectMask, &inputRefs[index]);
}
for (uint32_t index = 0; index < desc.colorAttachmentCount; ++index)
{
ToAttachmentReference2(desc.pColorAttachments[index], VK_IMAGE_ASPECT_COLOR_BIT,
&colorRefs[index]);
}
if (desc.pResolveAttachments)
{
resolveRefs.resize(desc.colorAttachmentCount);
for (uint32_t index = 0; index < desc.colorAttachmentCount; ++index)
{
ToAttachmentReference2(desc.pResolveAttachments[index], VK_IMAGE_ASPECT_COLOR_BIT,
&resolveRefs[index]);
}
}
if (desc.pDepthStencilAttachment)
{
ToAttachmentReference2(*desc.pDepthStencilAttachment,
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT,
&depthStencilRef);
}
// Convert subpass itself.
ToSubpassDescription2(desc, inputRefs, colorRefs, resolveRefs, depthStencilRef,
multiviewInfo.pViewMasks[subpass], &subpassDescriptions[subpass]);
}
VkMultisampledRenderToSingleSampledInfoEXT renderToTextureInfo = {};
renderToTextureInfo.sType = VK_STRUCTURE_TYPE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_INFO_EXT;
renderToTextureInfo.multisampledRenderToSingleSampledEnable = true;
renderToTextureInfo.rasterizationSamples = gl_vk::GetSamples(renderToTextureSamples);
renderToTextureInfo.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
renderToTextureInfo.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
// Append the depth/stencil resolve attachment to the pNext chain of last subpass, if any.
if (depthStencilResolve.pDepthStencilResolveAttachment != nullptr)
{
ASSERT(!isRenderToTexture);
subpassDescriptions.back().pNext = &depthStencilResolve;
}
else
{
RendererVk *renderer = context->getRenderer();
ASSERT(isRenderToTexture);
ASSERT(renderer->getFeatures().supportsMultisampledRenderToSingleSampled.enabled);
ASSERT(subpassDescriptions.size() == 1);
subpassDescriptions.back().pNext = &renderToTextureInfo;
}
// Convert subpass dependencies to VkSubpassDependency2.
std::vector<VkSubpassDependency2KHR> subpassDependencies(createInfo.dependencyCount);
for (uint32_t index = 0; index < createInfo.dependencyCount; ++index)
{
ToSubpassDependency2(createInfo.pDependencies[index], &subpassDependencies[index]);
}
// Convert CreateInfo itself
VkRenderPassCreateInfo2KHR createInfo2 = {};
createInfo2.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO_2_KHR;
createInfo2.flags = createInfo.flags;
createInfo2.attachmentCount = createInfo.attachmentCount;
createInfo2.pAttachments = attachmentDescs.data();
createInfo2.subpassCount = createInfo.subpassCount;
createInfo2.pSubpasses = subpassDescriptions.data();
createInfo2.dependencyCount = static_cast<uint32_t>(subpassDependencies.size());
createInfo2.pDependencies = !subpassDependencies.empty() ? subpassDependencies.data() : nullptr;
createInfo2.correlatedViewMaskCount = multiviewInfo.correlationMaskCount;
createInfo2.pCorrelatedViewMasks = multiviewInfo.pCorrelationMasks;
// Initialize the render pass.
ANGLE_VK_TRY(context, renderPass->init2(context->getDevice(), createInfo2));
return angle::Result::Continue;
}
void UpdateRenderPassColorPerfCounters(const VkRenderPassCreateInfo &createInfo,
const VkSubpassDescription &subpass,
RenderPassPerfCounters *countersOut)
{
// Color resolve counters.
if (subpass.pResolveAttachments == nullptr)
{
return;
}
for (uint32_t colorSubpassIndex = 0; colorSubpassIndex < subpass.colorAttachmentCount;
++colorSubpassIndex)
{
uint32_t resolveRenderPassIndex = subpass.pResolveAttachments[colorSubpassIndex].attachment;
if (resolveRenderPassIndex == VK_ATTACHMENT_UNUSED)
{
continue;
}
++countersOut->colorAttachmentResolves;
}
}
void UpdateRenderPassDepthStencilPerfCounters(const VkRenderPassCreateInfo &createInfo,
size_t renderPassIndex,
RenderPassPerfCounters *countersOut)
{
ASSERT(renderPassIndex != VK_ATTACHMENT_UNUSED);
// Depth/stencil ops counters.
const VkAttachmentDescription &ds = createInfo.pAttachments[renderPassIndex];
countersOut->depthClears += ds.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? 1 : 0;
countersOut->depthLoads += ds.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD ? 1 : 0;
countersOut->depthStores +=
ds.storeOp == static_cast<uint16_t>(RenderPassStoreOp::Store) ? 1 : 0;
countersOut->stencilClears += ds.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? 1 : 0;
countersOut->stencilLoads += ds.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD ? 1 : 0;
countersOut->stencilStores +=
ds.stencilStoreOp == static_cast<uint16_t>(RenderPassStoreOp::Store) ? 1 : 0;
// Depth/stencil read-only mode.
countersOut->readOnlyDepthStencil +=
ds.finalLayout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL ? 1 : 0;
}
void UpdateRenderPassDepthStencilResolvePerfCounters(
const VkRenderPassCreateInfo &createInfo,
const VkSubpassDescriptionDepthStencilResolve &depthStencilResolve,
RenderPassPerfCounters *countersOut)
{
if (depthStencilResolve.pDepthStencilResolveAttachment == nullptr)
{
return;
}
uint32_t resolveRenderPassIndex =
depthStencilResolve.pDepthStencilResolveAttachment->attachment;
if (resolveRenderPassIndex == VK_ATTACHMENT_UNUSED)
{
return;
}
const VkAttachmentDescription &dsResolve = createInfo.pAttachments[resolveRenderPassIndex];
// Resolve depth/stencil ops counters.
countersOut->depthClears += dsResolve.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? 1 : 0;
countersOut->depthLoads += dsResolve.loadOp == VK_ATTACHMENT_LOAD_OP_LOAD ? 1 : 0;
countersOut->depthStores +=
dsResolve.storeOp == static_cast<uint16_t>(RenderPassStoreOp::Store) ? 1 : 0;
countersOut->stencilClears += dsResolve.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR ? 1 : 0;
countersOut->stencilLoads += dsResolve.stencilLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD ? 1 : 0;
countersOut->stencilStores +=
dsResolve.stencilStoreOp == static_cast<uint16_t>(RenderPassStoreOp::Store) ? 1 : 0;
// Depth/stencil resolve counters.
countersOut->depthAttachmentResolves +=
depthStencilResolve.depthResolveMode != VK_RESOLVE_MODE_NONE ? 1 : 0;
countersOut->stencilAttachmentResolves +=
depthStencilResolve.stencilResolveMode != VK_RESOLVE_MODE_NONE ? 1 : 0;
}
void UpdateRenderPassPerfCounters(
const RenderPassDesc &desc,
const VkRenderPassCreateInfo &createInfo,
const VkSubpassDescriptionDepthStencilResolve &depthStencilResolve,
RenderPassPerfCounters *countersOut)
{
// Accumulate depth/stencil attachment indices in all subpasses to avoid double-counting
// counters.
FramebufferAttachmentMask depthStencilAttachmentIndices;
for (uint32_t subpassIndex = 0; subpassIndex < createInfo.subpassCount; ++subpassIndex)
{
const VkSubpassDescription &subpass = createInfo.pSubpasses[subpassIndex];
// Color counters. Note: currently there are no counters for load/store ops of color
// attachments, so there's no risk of double counting.
UpdateRenderPassColorPerfCounters(createInfo, subpass, countersOut);
// Record index of depth/stencil attachment.
if (subpass.pDepthStencilAttachment != nullptr)
{
uint32_t attachmentRenderPassIndex = subpass.pDepthStencilAttachment->attachment;
if (attachmentRenderPassIndex != VK_ATTACHMENT_UNUSED)
{
depthStencilAttachmentIndices.set(attachmentRenderPassIndex);
}
}
}
// Depth/stencil counters. Currently, both subpasses use the same depth/stencil attachment (if
// any).
ASSERT(depthStencilAttachmentIndices.count() <= 1);
for (size_t attachmentRenderPassIndex : depthStencilAttachmentIndices)
{
UpdateRenderPassDepthStencilPerfCounters(createInfo, attachmentRenderPassIndex,
countersOut);
}
UpdateRenderPassDepthStencilResolvePerfCounters(createInfo, depthStencilResolve, countersOut);
// Determine unresolve counters from the render pass desc, to avoid making guesses from subpass
// count etc.
countersOut->colorAttachmentUnresolves += desc.getColorUnresolveAttachmentMask().count();
countersOut->depthAttachmentUnresolves += desc.hasDepthUnresolveAttachment() ? 1 : 0;
countersOut->stencilAttachmentUnresolves += desc.hasStencilUnresolveAttachment() ? 1 : 0;
}
angle::Result InitializeRenderPassFromDesc(ContextVk *contextVk,
const RenderPassDesc &desc,
const AttachmentOpsArray &ops,
RenderPassHelper *renderPassHelper)
{
constexpr VkAttachmentReference kUnusedAttachment = {VK_ATTACHMENT_UNUSED,
VK_IMAGE_LAYOUT_UNDEFINED};
constexpr VkAttachmentReference2 kUnusedAttachment2 = {
VK_STRUCTURE_TYPE_ATTACHMENT_REFERENCE_2_KHR, nullptr, VK_ATTACHMENT_UNUSED,
VK_IMAGE_LAYOUT_UNDEFINED, 0};
const bool needInputAttachments = desc.getFramebufferFetchMode();
const bool isRenderToTexture = desc.isRenderToTexture();
const uint8_t descSamples = desc.samples();
const uint8_t attachmentSamples = isRenderToTexture ? 1 : descSamples;
const uint8_t renderToTextureSamples = isRenderToTexture ? descSamples : 1;
// Unpack the packed and split representation into the format required by Vulkan.
gl::DrawBuffersVector<VkAttachmentReference> colorAttachmentRefs;
gl::DrawBuffersVector<VkAttachmentReference> colorResolveAttachmentRefs;
VkAttachmentReference depthStencilAttachmentRef = kUnusedAttachment;
VkAttachmentReference2KHR depthStencilResolveAttachmentRef = kUnusedAttachment2;
// The list of attachments includes all non-resolve and resolve attachments.
FramebufferAttachmentArray<VkAttachmentDescription> attachmentDescs;
// Track invalidated attachments so their resolve attachments can be invalidated as well.
// Resolve attachments can be removed in that case if the render pass has only one subpass
// (which is the case if there are no unresolve attachments).
gl::DrawBufferMask isColorInvalidated;
bool isDepthInvalidated = false;
bool isStencilInvalidated = false;
const bool hasUnresolveAttachments =
desc.getColorUnresolveAttachmentMask().any() || desc.hasDepthStencilUnresolveAttachment();
const bool canRemoveResolveAttachments = !hasUnresolveAttachments;
// Pack color attachments
PackedAttachmentIndex attachmentCount(0);
for (uint32_t colorIndexGL = 0; colorIndexGL < desc.colorAttachmentRange(); ++colorIndexGL)
{
// Vulkan says:
//
// > Each element of the pColorAttachments array corresponds to an output location in the
// > shader, i.e. if the shader declares an output variable decorated with a Location value
// > of X, then it uses the attachment provided in pColorAttachments[X].
//
// This means that colorAttachmentRefs is indexed by colorIndexGL. Where the color
// attachment is disabled, a reference with VK_ATTACHMENT_UNUSED is given.
if (!desc.isColorAttachmentEnabled(colorIndexGL))
{
colorAttachmentRefs.push_back(kUnusedAttachment);
continue;
}
angle::FormatID attachmentFormatID = desc[colorIndexGL];
ASSERT(attachmentFormatID != angle::FormatID::NONE);
VkAttachmentReference colorRef;
colorRef.attachment = attachmentCount.get();
colorRef.layout = needInputAttachments
? VK_IMAGE_LAYOUT_GENERAL
: ConvertImageLayoutToVkImageLayout(
static_cast<ImageLayout>(ops[attachmentCount].initialLayout));
colorAttachmentRefs.push_back(colorRef);
UnpackAttachmentDesc(&attachmentDescs[attachmentCount.get()], attachmentFormatID,
attachmentSamples, ops[attachmentCount]);
// If this renderpass uses EXT_srgb_write_control, we need to override the format to its
// linear counterpart. Formats that cannot be reinterpreted are exempt from this
// requirement.
angle::FormatID linearFormat = rx::ConvertToLinear(attachmentFormatID);
if (linearFormat != angle::FormatID::NONE)
{
if (desc.getSRGBWriteControlMode() == gl::SrgbWriteControlMode::Linear)
{
attachmentFormatID = linearFormat;
}
}
attachmentDescs[attachmentCount.get()].format = GetVkFormatFromFormatID(attachmentFormatID);
ASSERT(attachmentDescs[attachmentCount.get()].format != VK_FORMAT_UNDEFINED);
isColorInvalidated.set(colorIndexGL, ops[attachmentCount].isInvalidated);
++attachmentCount;
}
// Pack depth/stencil attachment, if any
if (desc.hasDepthStencilAttachment())
{
uint32_t depthStencilIndexGL = static_cast<uint32_t>(desc.depthStencilAttachmentIndex());
angle::FormatID attachmentFormatID = desc[depthStencilIndexGL];
ASSERT(attachmentFormatID != angle::FormatID::NONE);
depthStencilAttachmentRef.attachment = attachmentCount.get();
depthStencilAttachmentRef.layout = ConvertImageLayoutToVkImageLayout(
static_cast<ImageLayout>(ops[attachmentCount].initialLayout));
UnpackAttachmentDesc(&attachmentDescs[attachmentCount.get()], attachmentFormatID,
attachmentSamples, ops[attachmentCount]);
isDepthInvalidated = ops[attachmentCount].isInvalidated;
isStencilInvalidated = ops[attachmentCount].isStencilInvalidated;
++attachmentCount;
}
// Pack color resolve attachments
const uint32_t nonResolveAttachmentCount = attachmentCount.get();
for (uint32_t colorIndexGL = 0; colorIndexGL < desc.colorAttachmentRange(); ++colorIndexGL)
{
if (!desc.hasColorResolveAttachment(colorIndexGL))
{
colorResolveAttachmentRefs.push_back(kUnusedAttachment);
continue;
}
ASSERT(desc.isColorAttachmentEnabled(colorIndexGL));
angle::FormatID attachmentFormatID = desc[colorIndexGL];
VkAttachmentReference colorRef;
colorRef.attachment = attachmentCount.get();
colorRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
// If color attachment is invalidated, try to remove its resolve attachment altogether.
if (canRemoveResolveAttachments && isColorInvalidated.test(colorIndexGL))
{
colorResolveAttachmentRefs.push_back(kUnusedAttachment);
}
else
{
colorResolveAttachmentRefs.push_back(colorRef);
}
UnpackColorResolveAttachmentDesc(
&attachmentDescs[attachmentCount.get()], attachmentFormatID,
desc.hasColorUnresolveAttachment(colorIndexGL), isColorInvalidated.test(colorIndexGL));
++attachmentCount;
}
// Pack depth/stencil resolve attachment, if any
if (desc.hasDepthStencilResolveAttachment())
{
ASSERT(desc.hasDepthStencilAttachment());
uint32_t depthStencilIndexGL = static_cast<uint32_t>(desc.depthStencilAttachmentIndex());
angle::FormatID attachmentFormatID = desc[depthStencilIndexGL];
const angle::Format &angleFormat = angle::Format::Get(attachmentFormatID);
// Treat missing aspect as invalidated for the purpose of the resolve attachment.
if (angleFormat.depthBits == 0)
{
isDepthInvalidated = true;
}
if (angleFormat.stencilBits == 0)
{
isStencilInvalidated = true;
}
depthStencilResolveAttachmentRef.attachment = attachmentCount.get();
depthStencilResolveAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depthStencilResolveAttachmentRef.aspectMask = 0;
if (!isDepthInvalidated)
{
depthStencilResolveAttachmentRef.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
}
if (!isStencilInvalidated)
{
depthStencilResolveAttachmentRef.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
}
UnpackDepthStencilResolveAttachmentDesc(
&attachmentDescs[attachmentCount.get()], attachmentFormatID,
desc.hasDepthUnresolveAttachment(), desc.hasStencilUnresolveAttachment(),
isDepthInvalidated, isStencilInvalidated);
++attachmentCount;
}
SubpassVector<VkSubpassDescription> subpassDesc;
// If any attachment needs to be unresolved, create an initial subpass for this purpose. Note
// that the following arrays are used in initializing a VkSubpassDescription in subpassDesc,
// which is in turn used in VkRenderPassCreateInfo below. That is why they are declared in the
// same scope.
gl::DrawBuffersVector<VkAttachmentReference> unresolveColorAttachmentRefs;
VkAttachmentReference unresolveDepthStencilAttachmentRef = kUnusedAttachment;
FramebufferAttachmentsVector<VkAttachmentReference> unresolveInputAttachmentRefs;
FramebufferAttachmentsVector<uint32_t> unresolvePreserveAttachmentRefs;
if (hasUnresolveAttachments)
{
subpassDesc.push_back({});
InitializeUnresolveSubpass(
desc, colorAttachmentRefs, colorResolveAttachmentRefs, depthStencilAttachmentRef,
depthStencilResolveAttachmentRef, &unresolveColorAttachmentRefs,
&unresolveDepthStencilAttachmentRef, &unresolveInputAttachmentRefs,
&unresolvePreserveAttachmentRefs, &subpassDesc.back());
}
subpassDesc.push_back({});
VkSubpassDescription *applicationSubpass = &subpassDesc.back();
applicationSubpass->flags = 0;
applicationSubpass->pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
applicationSubpass->inputAttachmentCount =
needInputAttachments ? static_cast<uint32_t>(colorAttachmentRefs.size()) : 0;
applicationSubpass->pInputAttachments =
needInputAttachments ? colorAttachmentRefs.data() : nullptr;
applicationSubpass->colorAttachmentCount = static_cast<uint32_t>(colorAttachmentRefs.size());
applicationSubpass->pColorAttachments = colorAttachmentRefs.data();
applicationSubpass->pResolveAttachments = attachmentCount.get() > nonResolveAttachmentCount
? colorResolveAttachmentRefs.data()
: nullptr;
applicationSubpass->pDepthStencilAttachment =
(depthStencilAttachmentRef.attachment != VK_ATTACHMENT_UNUSED ? &depthStencilAttachmentRef
: nullptr);
applicationSubpass->preserveAttachmentCount = 0;
applicationSubpass->pPreserveAttachments = nullptr;
// If depth/stencil is to be resolved, add a VkSubpassDescriptionDepthStencilResolve to the
// pNext chain of the subpass description. Note that we need a VkSubpassDescription2KHR to have
// a pNext pointer. CreateRenderPass2 is called to convert the data structures here to those
// specified by VK_KHR_create_renderpass2 for this purpose.
VkSubpassDescriptionDepthStencilResolve depthStencilResolve = {};
if (desc.hasDepthStencilResolveAttachment())
{
depthStencilResolve.sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE;
depthStencilResolve.depthResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
depthStencilResolve.stencilResolveMode = VK_RESOLVE_MODE_SAMPLE_ZERO_BIT;
// If depth/stencil attachment is invalidated, try to remove its resolve attachment
// altogether.
const bool removeDepthStencilResolve =
canRemoveResolveAttachments && isDepthInvalidated && isStencilInvalidated;
if (!removeDepthStencilResolve)
{
depthStencilResolve.pDepthStencilResolveAttachment = &depthStencilResolveAttachmentRef;
}
}
std::vector<VkSubpassDependency> subpassDependencies;
if (hasUnresolveAttachments)
{
InitializeUnresolveSubpassDependencies(
subpassDesc, desc.getColorUnresolveAttachmentMask().any(),
desc.hasDepthStencilUnresolveAttachment(), &subpassDependencies);
}
if (needInputAttachments)
{
uint32_t drawSubpassIndex = static_cast<uint32_t>(subpassDesc.size()) - 1;
InitializeInputAttachmentSubpassDependencies(&subpassDependencies, drawSubpassIndex);
}
VkRenderPassCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
createInfo.flags = 0;
createInfo.attachmentCount = attachmentCount.get();
createInfo.pAttachments = attachmentDescs.data();
createInfo.subpassCount = static_cast<uint32_t>(subpassDesc.size());
createInfo.pSubpasses = subpassDesc.data();
createInfo.dependencyCount = 0;
createInfo.pDependencies = nullptr;
if (!subpassDependencies.empty())
{
createInfo.dependencyCount = static_cast<uint32_t>(subpassDependencies.size());
createInfo.pDependencies = subpassDependencies.data();
}
SubpassVector<uint32_t> viewMasks(subpassDesc.size(),
angle::BitMask<uint32_t>(desc.viewCount()));
VkRenderPassMultiviewCreateInfo multiviewInfo = {};
multiviewInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO;
multiviewInfo.subpassCount = createInfo.subpassCount;
multiviewInfo.pViewMasks = viewMasks.data();
if (desc.viewCount() > 0)
{
// For VR, the views are correlated, so this would be an optimization. However, an
// application can also use multiview for example to render to all 6 faces of a cubemap, in
// which case the views are actually not so correlated. In the absence of any hints from
// the application, we have to decide on one or the other. Since VR is more expensive, the
// views are marked as correlated to optimize that use case.
multiviewInfo.correlationMaskCount = 1;
multiviewInfo.pCorrelationMasks = viewMasks.data();
createInfo.pNext = &multiviewInfo;
}
// If depth/stencil resolve is used, we need to create the render pass with
// vkCreateRenderPass2KHR. Same when using the VK_EXT_multisampled_render_to_single_sampled
// extension.
if (depthStencilResolve.pDepthStencilResolveAttachment != nullptr || desc.isRenderToTexture())
{
ANGLE_TRY(CreateRenderPass2(contextVk, createInfo, depthStencilResolve, multiviewInfo,
desc.hasDepthUnresolveAttachment(),
desc.hasStencilUnresolveAttachment(), desc.isRenderToTexture(),
renderToTextureSamples, &renderPassHelper->getRenderPass()));
}
else
{
ANGLE_VK_TRY(contextVk,
renderPassHelper->getRenderPass().init(contextVk->getDevice(), createInfo));
}
// Calculate perf counters associated with this render pass, such as load/store ops, unresolve
// and resolve operations etc. This information is taken out of the render pass create info.
// Depth/stencil resolve attachment uses RenderPass2 structures, so it's passed in separately.
UpdateRenderPassPerfCounters(desc, createInfo, depthStencilResolve,
&renderPassHelper->getPerfCounters());
return angle::Result::Continue;
}
void GetRenderPassAndUpdateCounters(ContextVk *contextVk,
bool updatePerfCounters,
RenderPassHelper *renderPassHelper,
RenderPass **renderPassOut)
{
*renderPassOut = &renderPassHelper->getRenderPass();
if (updatePerfCounters)
{
PerfCounters &counters = contextVk->getPerfCounters();
const RenderPassPerfCounters &rpCounters = renderPassHelper->getPerfCounters();
counters.depthClears += rpCounters.depthClears;
counters.depthLoads += rpCounters.depthLoads;
counters.depthStores += rpCounters.depthStores;
counters.stencilClears += rpCounters.stencilClears;
counters.stencilLoads += rpCounters.stencilLoads;
counters.stencilStores += rpCounters.stencilStores;
counters.colorAttachmentUnresolves += rpCounters.colorAttachmentUnresolves;
counters.colorAttachmentResolves += rpCounters.colorAttachmentResolves;
counters.depthAttachmentUnresolves += rpCounters.depthAttachmentUnresolves;
counters.depthAttachmentResolves += rpCounters.depthAttachmentResolves;
counters.stencilAttachmentUnresolves += rpCounters.stencilAttachmentUnresolves;
counters.stencilAttachmentResolves += rpCounters.stencilAttachmentResolves;
counters.readOnlyDepthStencilRenderPasses += rpCounters.readOnlyDepthStencil;
}
}
void InitializeSpecializationInfo(
const SpecializationConstants &specConsts,
SpecializationConstantMap<VkSpecializationMapEntry> *specializationEntriesOut,
VkSpecializationInfo *specializationInfoOut)
{
// Collect specialization constants.
for (const sh::vk::SpecializationConstantId id :
angle::AllEnums<sh::vk::SpecializationConstantId>())
{
(*specializationEntriesOut)[id].constantID = static_cast<uint32_t>(id);
switch (id)
{
case sh::vk::SpecializationConstantId::LineRasterEmulation:
(*specializationEntriesOut)[id].offset =
offsetof(SpecializationConstants, lineRasterEmulation);
(*specializationEntriesOut)[id].size = sizeof(specConsts.lineRasterEmulation);
break;
case sh::vk::SpecializationConstantId::SurfaceRotation:
(*specializationEntriesOut)[id].offset =
offsetof(SpecializationConstants, surfaceRotation);
(*specializationEntriesOut)[id].size = sizeof(specConsts.surfaceRotation);
break;
case sh::vk::SpecializationConstantId::DrawableWidth:
(*specializationEntriesOut)[id].offset =
offsetof(vk::SpecializationConstants, drawableWidth);
(*specializationEntriesOut)[id].size = sizeof(specConsts.drawableWidth);
break;
case sh::vk::SpecializationConstantId::DrawableHeight:
(*specializationEntriesOut)[id].offset =
offsetof(vk::SpecializationConstants, drawableHeight);
(*specializationEntriesOut)[id].size = sizeof(specConsts.drawableHeight);
break;
case sh::vk::SpecializationConstantId::Dither:
(*specializationEntriesOut)[id].offset =
offsetof(vk::SpecializationConstants, dither);
(*specializationEntriesOut)[id].size = sizeof(specConsts.dither);
break;
default:
UNREACHABLE();
break;
}
}
specializationInfoOut->mapEntryCount = static_cast<uint32_t>(specializationEntriesOut->size());
specializationInfoOut->pMapEntries = specializationEntriesOut->data();
specializationInfoOut->dataSize = sizeof(specConsts);
specializationInfoOut->pData = &specConsts;
}
// Utility for setting a value on a packed 4-bit integer array.
template <typename SrcT>
void Int4Array_Set(uint8_t *arrayBytes, uint32_t arrayIndex, SrcT value)
{
uint32_t byteIndex = arrayIndex >> 1;
ASSERT(value < 16);
if ((arrayIndex & 1) == 0)
{
arrayBytes[byteIndex] &= 0xF0;
arrayBytes[byteIndex] |= static_cast<uint8_t>(value);
}
else
{
arrayBytes[byteIndex] &= 0x0F;
arrayBytes[byteIndex] |= static_cast<uint8_t>(value) << 4;
}
}
// Utility for getting a value from a packed 4-bit integer array.
template <typename DestT>
DestT Int4Array_Get(const uint8_t *arrayBytes, uint32_t arrayIndex)
{
uint32_t byteIndex = arrayIndex >> 1;
if ((arrayIndex & 1) == 0)
{
return static_cast<DestT>(arrayBytes[byteIndex] & 0xF);
}
else
{
return static_cast<DestT>(arrayBytes[byteIndex] >> 4);
}
}
// When converting a byte number to a transition bit index we can shift instead of divide.
constexpr size_t kTransitionByteShift = Log2(kGraphicsPipelineDirtyBitBytes);
// When converting a number of bits offset to a transition bit index we can also shift.
constexpr size_t kBitsPerByte = 8;
constexpr size_t kTransitionBitShift = kTransitionByteShift + Log2(kBitsPerByte);
// Helper macro to map from a PipelineDesc struct and field to a dirty bit index.
// Uses the 'offsetof' macro to compute the offset 'Member' within the PipelineDesc
// and the offset of 'Field' within 'Member'. We can optimize the dirty bit setting by computing
// the shifted dirty bit at compile time instead of calling "set".
#define ANGLE_GET_TRANSITION_BIT(Member, Field) \
((offsetof(GraphicsPipelineDesc, Member) + offsetof(decltype(Member), Field)) >> \
kTransitionByteShift)
// Indexed dirty bits cannot be entirely computed at compile time since the index is passed to
// the update function.
#define ANGLE_GET_INDEXED_TRANSITION_BIT(Member, Field, Index, BitWidth) \
(((BitWidth * Index) >> kTransitionBitShift) + ANGLE_GET_TRANSITION_BIT(Member, Field))
constexpr angle::PackedEnumMap<gl::ComponentType, VkFormat> kMismatchedComponentTypeMap = {{
{gl::ComponentType::Float, VK_FORMAT_R32G32B32A32_SFLOAT},
{gl::ComponentType::Int, VK_FORMAT_R32G32B32A32_SINT},
{gl::ComponentType::UnsignedInt, VK_FORMAT_R32G32B32A32_UINT},
}};
} // anonymous namespace
// RenderPassDesc implementation.
RenderPassDesc::RenderPassDesc()
{
memset(this, 0, sizeof(RenderPassDesc));
}
RenderPassDesc::~RenderPassDesc() = default;
RenderPassDesc::RenderPassDesc(const RenderPassDesc &other)
{
memcpy(this, &other, sizeof(RenderPassDesc));
}
void RenderPassDesc::packColorAttachment(size_t colorIndexGL, angle::FormatID formatID)
{
ASSERT(colorIndexGL < mAttachmentFormats.size());
static_assert(angle::kNumANGLEFormats < std::numeric_limits<uint8_t>::max(),
"Too many ANGLE formats to fit in uint8_t");
// Force the user to pack the depth/stencil attachment last.
ASSERT(!hasDepthStencilAttachment());
// This function should only be called for enabled GL color attachments.
ASSERT(formatID != angle::FormatID::NONE);
uint8_t &packedFormat = mAttachmentFormats[colorIndexGL];
SetBitField(packedFormat, formatID);
// Set color attachment range such that it covers the range from index 0 through last active
// index. This is the reasons why we need depth/stencil to be packed last.
SetBitField(mColorAttachmentRange, std::max<size_t>(mColorAttachmentRange, colorIndexGL + 1));
}
void RenderPassDesc::packColorAttachmentGap(size_t colorIndexGL)
{
ASSERT(colorIndexGL < mAttachmentFormats.size());
static_assert(angle::kNumANGLEFormats < std::numeric_limits<uint8_t>::max(),
"Too many ANGLE formats to fit in uint8_t");
// Force the user to pack the depth/stencil attachment last.
ASSERT(!hasDepthStencilAttachment());
// Use NONE as a flag for gaps in GL color attachments.
uint8_t &packedFormat = mAttachmentFormats[colorIndexGL];
SetBitField(packedFormat, angle::FormatID::NONE);
}
void RenderPassDesc::packDepthStencilAttachment(angle::FormatID formatID)
{
ASSERT(!hasDepthStencilAttachment());
size_t index = depthStencilAttachmentIndex();
ASSERT(index < mAttachmentFormats.size());
uint8_t &packedFormat = mAttachmentFormats[index];
SetBitField(packedFormat, formatID);
}
void RenderPassDesc::packColorResolveAttachment(size_t colorIndexGL)
{
ASSERT(isColorAttachmentEnabled(colorIndexGL));
ASSERT(!mColorResolveAttachmentMask.test(colorIndexGL));
ASSERT(mSamples > 1);
mColorResolveAttachmentMask.set(colorIndexGL);
}
void RenderPassDesc::removeColorResolveAttachment(size_t colorIndexGL)
{
ASSERT(mColorResolveAttachmentMask.test(colorIndexGL));
mColorResolveAttachmentMask.reset(colorIndexGL);
}
void RenderPassDesc::packColorUnresolveAttachment(size_t colorIndexGL)
{
mColorUnresolveAttachmentMask.set(colorIndexGL);
}
void RenderPassDesc::removeColorUnresolveAttachment(size_t colorIndexGL)
{
mColorUnresolveAttachmentMask.reset(colorIndexGL);
}
void RenderPassDesc::packDepthStencilResolveAttachment()
{
ASSERT(hasDepthStencilAttachment());
ASSERT(!hasDepthStencilResolveAttachment());
mResolveDepthStencil = true;
}
void RenderPassDesc::packDepthStencilUnresolveAttachment(bool unresolveDepth, bool unresolveStencil)
{
ASSERT(hasDepthStencilAttachment());
mUnresolveDepth = unresolveDepth;
mUnresolveStencil = unresolveStencil;
}
void RenderPassDesc::removeDepthStencilUnresolveAttachment()
{
mUnresolveDepth = false;
mUnresolveStencil = false;
}
RenderPassDesc &RenderPassDesc::operator=(const RenderPassDesc &other)
{
memcpy(this, &other, sizeof(RenderPassDesc));
return *this;
}
void RenderPassDesc::setWriteControlMode(gl::SrgbWriteControlMode mode)
{
SetBitField(mSrgbWriteControl, mode);
}
size_t RenderPassDesc::hash() const
{
return angle::ComputeGenericHash(*this);
}
bool RenderPassDesc::isColorAttachmentEnabled(size_t colorIndexGL) const
{
angle::FormatID formatID = operator[](colorIndexGL);
return formatID != angle::FormatID::NONE;
}
bool RenderPassDesc::hasDepthStencilAttachment() const
{
angle::FormatID formatID = operator[](depthStencilAttachmentIndex());
return formatID != angle::FormatID::NONE;
}
size_t RenderPassDesc::attachmentCount() const
{
size_t colorAttachmentCount = 0;
for (size_t i = 0; i < mColorAttachmentRange; ++i)
{
colorAttachmentCount += isColorAttachmentEnabled(i);
}
// Note that there are no gaps in depth/stencil attachments. In fact there is a maximum of 1 of
// it + 1 for its resolve attachment.
size_t depthStencilCount = hasDepthStencilAttachment() ? 1 : 0;
size_t depthStencilResolveCount = hasDepthStencilResolveAttachment() ? 1 : 0;
return colorAttachmentCount + mColorResolveAttachmentMask.count() + depthStencilCount +
depthStencilResolveCount;
}
bool operator==(const RenderPassDesc &lhs, const RenderPassDesc &rhs)
{
return (memcmp(&lhs, &rhs, sizeof(RenderPassDesc)) == 0);
}
// GraphicsPipelineDesc implementation.
// Use aligned allocation and free so we can use the alignas keyword.
void *GraphicsPipelineDesc::operator new(std::size_t size)
{
return angle::AlignedAlloc(size, 32);
}
void GraphicsPipelineDesc::operator delete(void *ptr)
{
return angle::AlignedFree(ptr);
}
GraphicsPipelineDesc::GraphicsPipelineDesc()
{
memset(this, 0, sizeof(GraphicsPipelineDesc));
}
GraphicsPipelineDesc::~GraphicsPipelineDesc() = default;
GraphicsPipelineDesc::GraphicsPipelineDesc(const GraphicsPipelineDesc &other)
{
memcpy(this, &other, sizeof(GraphicsPipelineDesc));
}
GraphicsPipelineDesc &GraphicsPipelineDesc::operator=(const GraphicsPipelineDesc &other)
{
memcpy(this, &other, sizeof(GraphicsPipelineDesc));
return *this;
}
size_t GraphicsPipelineDesc::hash() const
{
return angle::ComputeGenericHash(*this);
}
bool GraphicsPipelineDesc::operator==(const GraphicsPipelineDesc &other) const
{
return (memcmp(this, &other, sizeof(GraphicsPipelineDesc)) == 0);
}
// TODO(jmadill): We should prefer using Packed GLenums. http://anglebug.com/2169
// Initialize PSO states, it is consistent with initial value of gl::State
void GraphicsPipelineDesc::initDefaults(const ContextVk *contextVk)
{
// Set all vertex input attributes to default, the default format is Float
angle::FormatID defaultFormat = GetCurrentValueFormatID(gl::VertexAttribType::Float);
for (PackedAttribDesc &packedAttrib : mVertexInputAttribs.attribs)
{
SetBitField(packedAttrib.stride, 0);
SetBitField(packedAttrib.divisor, 0);
SetBitField(packedAttrib.format, defaultFormat);
SetBitField(packedAttrib.compressed, 0);
SetBitField(packedAttrib.offset, 0);
}
mRasterizationAndMultisampleStateInfo.bits.subpass = 0;
mRasterizationAndMultisampleStateInfo.bits.depthClampEnable =
contextVk->getFeatures().depthClamping.enabled ? VK_TRUE : VK_FALSE;
mRasterizationAndMultisampleStateInfo.bits.rasterizationDiscardEnable = 0;
SetBitField(mRasterizationAndMultisampleStateInfo.bits.polygonMode, VK_POLYGON_MODE_FILL);
SetBitField(mRasterizationAndMultisampleStateInfo.bits.cullMode, VK_CULL_MODE_BACK_BIT);
SetBitField(mRasterizationAndMultisampleStateInfo.bits.frontFace,
VK_FRONT_FACE_COUNTER_CLOCKWISE);
mRasterizationAndMultisampleStateInfo.bits.depthBiasEnable = 0;
mRasterizationAndMultisampleStateInfo.depthBiasConstantFactor = 0.0f;
mRasterizationAndMultisampleStateInfo.depthBiasClamp = 0.0f;
mRasterizationAndMultisampleStateInfo.depthBiasSlopeFactor = 0.0f;
mRasterizationAndMultisampleStateInfo.lineWidth = 1.0f;
mRasterizationAndMultisampleStateInfo.bits.rasterizationSamples = 1;
mRasterizationAndMultisampleStateInfo.bits.sampleShadingEnable = 0;
mRasterizationAndMultisampleStateInfo.minSampleShading = 1.0f;
for (uint32_t &sampleMask : mRasterizationAndMultisampleStateInfo.sampleMask)
{
sampleMask = 0xFFFFFFFF;
}
mRasterizationAndMultisampleStateInfo.bits.alphaToCoverageEnable = 0;
mRasterizationAndMultisampleStateInfo.bits.alphaToOneEnable = 0;
mDepthStencilStateInfo.enable.viewportNegativeOneToOne =
contextVk->getFeatures().supportsDepthClipControl.enabled;
mDepthStencilStateInfo.enable.depthTest = 0;
mDepthStencilStateInfo.enable.depthWrite = 0;
SetBitField(mDepthStencilStateInfo.depthCompareOpAndSurfaceRotation.depthCompareOp,
VK_COMPARE_OP_LESS);
mDepthStencilStateInfo.enable.depthBoundsTest = 0;
mDepthStencilStateInfo.enable.stencilTest = 0;
mDepthStencilStateInfo.minDepthBounds = 0.0f;
mDepthStencilStateInfo.maxDepthBounds = 0.0f;
SetBitField(mDepthStencilStateInfo.front.ops.fail, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.front.ops.pass, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.front.ops.depthFail, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.front.ops.compare, VK_COMPARE_OP_ALWAYS);
SetBitField(mDepthStencilStateInfo.front.compareMask, 0xFF);
SetBitField(mDepthStencilStateInfo.front.writeMask, 0xFF);
mDepthStencilStateInfo.frontStencilReference = 0;
SetBitField(mDepthStencilStateInfo.back.ops.fail, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.back.ops.pass, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.back.ops.depthFail, VK_STENCIL_OP_KEEP);
SetBitField(mDepthStencilStateInfo.back.ops.compare, VK_COMPARE_OP_ALWAYS);
SetBitField(mDepthStencilStateInfo.back.compareMask, 0xFF);
SetBitField(mDepthStencilStateInfo.back.writeMask, 0xFF);
mDepthStencilStateInfo.backStencilReference = 0;
mDepthStencilStateInfo.depthCompareOpAndSurfaceRotation.surfaceRotation =
static_cast<uint8_t>(SurfaceRotation::Identity);
PackedInputAssemblyAndColorBlendStateInfo &inputAndBlend = mInputAssemblyAndColorBlendStateInfo;
inputAndBlend.logic.opEnable = 0;
inputAndBlend.logic.op = static_cast<uint32_t>(VK_LOGIC_OP_CLEAR);
inputAndBlend.blendEnableMask = 0;
inputAndBlend.blendConstants[0] = 0.0f;
inputAndBlend.blendConstants[1] = 0.0f;
inputAndBlend.blendConstants[2] = 0.0f;
inputAndBlend.blendConstants[3] = 0.0f;
VkFlags allColorBits = (VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT);
for (uint32_t colorIndexGL = 0; colorIndexGL < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS;
++colorIndexGL)
{
Int4Array_Set(inputAndBlend.colorWriteMaskBits, colorIndexGL, allColorBits);
}
PackedColorBlendAttachmentState blendAttachmentState;
SetBitField(blendAttachmentState.srcColorBlendFactor, VK_BLEND_FACTOR_ONE);
SetBitField(blendAttachmentState.dstColorBlendFactor, VK_BLEND_FACTOR_ZERO);
SetBitField(blendAttachmentState.colorBlendOp, VK_BLEND_OP_ADD);
SetBitField(blendAttachmentState.srcAlphaBlendFactor, VK_BLEND_FACTOR_ONE);
SetBitField(blendAttachmentState.dstAlphaBlendFactor, VK_BLEND_FACTOR_ZERO);
SetBitField(blendAttachmentState.alphaBlendOp, VK_BLEND_OP_ADD);
std::fill(&inputAndBlend.attachments[0],
&inputAndBlend.attachments[gl::IMPLEMENTATION_MAX_DRAW_BUFFERS],
blendAttachmentState);
SetBitField(inputAndBlend.primitive.topology, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
SetBitField(inputAndBlend.primitive.patchVertices, 3);
inputAndBlend.primitive.restartEnable = 0;
mDrawableSize.width = 1;
mDrawableSize.height = 1;
mDither.emulatedDitherControl = 0;
mDither.unused = 0;
}
angle::Result GraphicsPipelineDesc::initializePipeline(
ContextVk *contextVk,
const PipelineCache &pipelineCacheVk,
const RenderPass &compatibleRenderPass,
const PipelineLayout &pipelineLayout,
const gl::AttributesMask &activeAttribLocationsMask,
const gl::ComponentTypeMask &programAttribsTypeMask,
const gl::DrawBufferMask &missingOutputsMask,
const ShaderAndSerialMap &shaders,
const SpecializationConstants &specConsts,
Pipeline *pipelineOut) const
{
angle::FixedVector<VkPipelineShaderStageCreateInfo, 5> shaderStages;
VkPipelineVertexInputStateCreateInfo vertexInputState = {};
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = {};
VkPipelineViewportStateCreateInfo viewportState = {};
VkPipelineRasterizationStateCreateInfo rasterState = {};
VkPipelineMultisampleStateCreateInfo multisampleState = {};
VkPipelineDepthStencilStateCreateInfo depthStencilState = {};
gl::DrawBuffersArray<VkPipelineColorBlendAttachmentState> blendAttachmentState;
VkPipelineTessellationStateCreateInfo tessellationState = {};
VkPipelineTessellationDomainOriginStateCreateInfo domainOriginState = {};
VkPipelineColorBlendStateCreateInfo blendState = {};
VkSpecializationInfo specializationInfo = {};
VkGraphicsPipelineCreateInfo createInfo = {};
SpecializationConstantMap<VkSpecializationMapEntry> specializationEntries;
InitializeSpecializationInfo(specConsts, &specializationEntries, &specializationInfo);
// Vertex shader is always expected to be present.
const ShaderModule &vertexModule = shaders[gl::ShaderType::Vertex].get().get();
ASSERT(vertexModule.valid());
VkPipelineShaderStageCreateInfo vertexStage = {};
SetPipelineShaderStageInfo(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
VK_SHADER_STAGE_VERTEX_BIT, vertexModule.getHandle(),
specializationInfo, &vertexStage);
shaderStages.push_back(vertexStage);
const ShaderAndSerialPointer &tessControlPointer = shaders[gl::ShaderType::TessControl];
if (tessControlPointer.valid())
{
const ShaderModule &tessControlModule = tessControlPointer.get().get();
VkPipelineShaderStageCreateInfo tessControlStage = {};
SetPipelineShaderStageInfo(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
tessControlModule.getHandle(), specializationInfo,
&tessControlStage);
shaderStages.push_back(tessControlStage);
}
const ShaderAndSerialPointer &tessEvaluationPointer = shaders[gl::ShaderType::TessEvaluation];
if (tessEvaluationPointer.valid())
{
const ShaderModule &tessEvaluationModule = tessEvaluationPointer.get().get();
VkPipelineShaderStageCreateInfo tessEvaluationStage = {};
SetPipelineShaderStageInfo(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
tessEvaluationModule.getHandle(), specializationInfo,
&tessEvaluationStage);
shaderStages.push_back(tessEvaluationStage);
}
const ShaderAndSerialPointer &geometryPointer = shaders[gl::ShaderType::Geometry];
if (geometryPointer.valid())
{
const ShaderModule &geometryModule = geometryPointer.get().get();
VkPipelineShaderStageCreateInfo geometryStage = {};
SetPipelineShaderStageInfo(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
VK_SHADER_STAGE_GEOMETRY_BIT, geometryModule.getHandle(),
specializationInfo, &geometryStage);
shaderStages.push_back(geometryStage);
}
// Fragment shader is optional.
// anglebug.com/3509 - Don't compile the fragment shader if rasterizationDiscardEnable = true
const ShaderAndSerialPointer &fragmentPointer = shaders[gl::ShaderType::Fragment];
if (fragmentPointer.valid() &&
!mRasterizationAndMultisampleStateInfo.bits.rasterizationDiscardEnable)
{
const ShaderModule &fragmentModule = fragmentPointer.get().get();
VkPipelineShaderStageCreateInfo fragmentStage = {};
SetPipelineShaderStageInfo(VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
VK_SHADER_STAGE_FRAGMENT_BIT, fragmentModule.getHandle(),
specializationInfo, &fragmentStage);
shaderStages.push_back(fragmentStage);
}
// TODO(jmadill): Possibly use different path for ES 3.1 split bindings/attribs.
gl::AttribArray<VkVertexInputBindingDescription> bindingDescs;
gl::AttribArray<VkVertexInputAttributeDescription> attributeDescs;
uint32_t vertexAttribCount = 0;
size_t unpackedSize = sizeof(shaderStages) + sizeof(vertexInputState) +
sizeof(inputAssemblyState) + sizeof(viewportState) + sizeof(rasterState) +
sizeof(multisampleState) + sizeof(depthStencilState) +
sizeof(tessellationState) + sizeof(blendAttachmentState) +
sizeof(blendState) + sizeof(bindingDescs) + sizeof(attributeDescs);
ANGLE_UNUSED_VARIABLE(unpackedSize);
gl::AttribArray<VkVertexInputBindingDivisorDescriptionEXT> divisorDesc;
VkPipelineVertexInputDivisorStateCreateInfoEXT divisorState = {};
divisorState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT;
divisorState.pVertexBindingDivisors = divisorDesc.data();
for (size_t attribIndexSizeT : activeAttribLocationsMask)
{
const uint32_t attribIndex = static_cast<uint32_t>(attribIndexSizeT);
VkVertexInputBindingDescription &bindingDesc = bindingDescs[vertexAttribCount];
VkVertexInputAttributeDescription &attribDesc = attributeDescs[vertexAttribCount];
const PackedAttribDesc &packedAttrib = mVertexInputAttribs.attribs[attribIndex];
bindingDesc.binding = attribIndex;
bindingDesc.stride = static_cast<uint32_t>(packedAttrib.stride);
if (packedAttrib.divisor != 0)
{
bindingDesc.inputRate = static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_INSTANCE);
divisorDesc[divisorState.vertexBindingDivisorCount].binding = bindingDesc.binding;
divisorDesc[divisorState.vertexBindingDivisorCount].divisor = packedAttrib.divisor;
++divisorState.vertexBindingDivisorCount;
}
else
{
bindingDesc.inputRate = static_cast<VkVertexInputRate>(VK_VERTEX_INPUT_RATE_VERTEX);
}
// Get the corresponding VkFormat for the attrib's format.
angle::FormatID formatID = static_cast<angle::FormatID>(packedAttrib.format);
const Format &format = contextVk->getRenderer()->getFormat(formatID);
const angle::Format &intendedFormat = format.getIntendedFormat();
VkFormat vkFormat = format.getActualBufferVkFormat(packedAttrib.compressed);
gl::ComponentType attribType = GetVertexAttributeComponentType(
intendedFormat.isPureInt(), intendedFormat.vertexAttribType);
gl::ComponentType programAttribType =
gl::GetComponentTypeMask(programAttribsTypeMask, attribIndex);
// This forces stride to 0 when glVertexAttribute specifies a different type from the
// program's attribute type except when the type mismatch is a mismatched integer sign.
if (attribType != programAttribType)
{
if (attribType == gl::ComponentType::Float ||
programAttribType == gl::ComponentType::Float)
{
// When dealing with float to int or unsigned int or vice versa, just override the
// format with a compatible one.
vkFormat = kMismatchedComponentTypeMap[programAttribType];
}
else
{
// When converting from an unsigned to a signed format or vice versa, attempt to
// match the bit width.
angle::FormatID convertedFormatID = gl::ConvertFormatSignedness(intendedFormat);
const Format &convertedFormat =
contextVk->getRenderer()->getFormat(convertedFormatID);
ASSERT(intendedFormat.channelCount ==
convertedFormat.getIntendedFormat().channelCount);
ASSERT(intendedFormat.redBits == convertedFormat.getIntendedFormat().redBits);
ASSERT(intendedFormat.greenBits == convertedFormat.getIntendedFormat().greenBits);
ASSERT(intendedFormat.blueBits == convertedFormat.getIntendedFormat().blueBits);
ASSERT(intendedFormat.alphaBits == convertedFormat.getIntendedFormat().alphaBits);
vkFormat = convertedFormat.getActualBufferVkFormat(packedAttrib.compressed);
}
ASSERT(contextVk->getNativeExtensions().relaxedVertexAttributeTypeANGLE);
if (programAttribType == gl::ComponentType::Float ||
attribType == gl::ComponentType::Float)
{
bindingDesc.stride = 0; // Prevent out-of-bounds accesses.
}
}
// The binding index could become more dynamic in ES 3.1.
attribDesc.binding = attribIndex;
attribDesc.format = vkFormat;
attribDesc.location = static_cast<uint32_t>(attribIndex);
attribDesc.offset = packedAttrib.offset;
vertexAttribCount++;
}
// The binding descriptions are filled in at draw time.
vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputState.flags = 0;
vertexInputState.vertexBindingDescriptionCount = vertexAttribCount;
vertexInputState.pVertexBindingDescriptions = bindingDescs.data();
vertexInputState.vertexAttributeDescriptionCount = vertexAttribCount;
vertexInputState.pVertexAttributeDescriptions = attributeDescs.data();
if (divisorState.vertexBindingDivisorCount)
vertexInputState.pNext = &divisorState;
// Primitive topology is filled in at draw time.
inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
inputAssemblyState.flags = 0;
inputAssemblyState.topology =
static_cast<VkPrimitiveTopology>(mInputAssemblyAndColorBlendStateInfo.primitive.topology);
// http://anglebug.com/3832
// We currently hit a VK Validation here where VUID
// VUID-VkPipelineInputAssemblyStateCreateInfo-topology-00428 is flagged because we allow
// primitiveRestartEnable to be true for topologies VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
// VK_PRIMITIVE_TOPOLOGY_LINE_LIST, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
// VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY,
// VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY and VK_PRIMITIVE_TOPOLOGY_PATCH_LIST
// However if we force primiteRestartEnable to FALSE we fail tests.
// Need to identify alternate fix.
inputAssemblyState.primitiveRestartEnable =
static_cast<VkBool32>(mInputAssemblyAndColorBlendStateInfo.primitive.restartEnable);
// Set initial viewport and scissor state.
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportState.flags = 0;
viewportState.viewportCount = 1;
viewportState.pViewports = nullptr;
viewportState.scissorCount = 1;
viewportState.pScissors = nullptr;
VkPipelineViewportDepthClipControlCreateInfoEXT depthClipControl = {};
if (contextVk->getFeatures().supportsDepthClipControl.enabled)
{
depthClipControl.sType =
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_DEPTH_CLIP_CONTROL_CREATE_INFO_EXT;
depthClipControl.negativeOneToOne =
static_cast<VkBool32>(mDepthStencilStateInfo.enable.viewportNegativeOneToOne);
viewportState.pNext = &depthClipControl;
}
const PackedRasterizationAndMultisampleStateInfo &rasterAndMS =
mRasterizationAndMultisampleStateInfo;
// Rasterizer state.
rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterState.flags = 0;
rasterState.depthClampEnable = static_cast<VkBool32>(rasterAndMS.bits.depthClampEnable);
rasterState.rasterizerDiscardEnable =
static_cast<VkBool32>(rasterAndMS.bits.rasterizationDiscardEnable);
rasterState.polygonMode = static_cast<VkPolygonMode>(rasterAndMS.bits.polygonMode);
rasterState.cullMode = static_cast<VkCullModeFlags>(rasterAndMS.bits.cullMode);
rasterState.frontFace = static_cast<VkFrontFace>(rasterAndMS.bits.frontFace);
rasterState.depthBiasEnable = static_cast<VkBool32>(rasterAndMS.bits.depthBiasEnable);
rasterState.depthBiasConstantFactor = rasterAndMS.depthBiasConstantFactor;
rasterState.depthBiasClamp = rasterAndMS.depthBiasClamp;
rasterState.depthBiasSlopeFactor = rasterAndMS.depthBiasSlopeFactor;
rasterState.lineWidth = rasterAndMS.lineWidth;
const void **pNextPtr = &rasterState.pNext;
VkPipelineRasterizationLineStateCreateInfoEXT rasterLineState = {};
rasterLineState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT;
// Enable Bresenham line rasterization if available and the following conditions are met:
// 1.) not multisampling
// 2.) VUID-VkGraphicsPipelineCreateInfo-lineRasterizationMode-02766:
// The Vulkan spec states: If the lineRasterizationMode member of a
// VkPipelineRasterizationLineStateCreateInfoEXT structure included in the pNext chain of
// pRasterizationState is VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT or
// VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT and if rasterization is enabled, then the
// alphaToCoverageEnable, alphaToOneEnable, and sampleShadingEnable members of pMultisampleState
// must all be VK_FALSE.
if (rasterAndMS.bits.rasterizationSamples <= 1 &&
!rasterAndMS.bits.rasterizationDiscardEnable && !rasterAndMS.bits.alphaToCoverageEnable &&
!rasterAndMS.bits.alphaToOneEnable && !rasterAndMS.bits.sampleShadingEnable &&
contextVk->getFeatures().bresenhamLineRasterization.enabled)
{
rasterLineState.lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT;
*pNextPtr = &rasterLineState;
pNextPtr = &rasterLineState.pNext;
}
VkPipelineRasterizationProvokingVertexStateCreateInfoEXT provokingVertexState = {};
provokingVertexState.sType =
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_PROVOKING_VERTEX_STATE_CREATE_INFO_EXT;
// Always set provoking vertex mode to last if available.
if (contextVk->getFeatures().provokingVertex.enabled)
{
provokingVertexState.provokingVertexMode = VK_PROVOKING_VERTEX_MODE_LAST_VERTEX_EXT;
*pNextPtr = &provokingVertexState;
pNextPtr = &provokingVertexState.pNext;
}
// When depth clamping is used, depth clipping is automatically disabled.
// When the 'depthClamping' feature is enabled, we'll be using depth clamping
// to work around a driver issue, not as an alternative to depth clipping. Therefore we need to
// explicitly re-enable depth clipping.
VkPipelineRasterizationDepthClipStateCreateInfoEXT depthClipState = {};
depthClipState.sType =
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT;
if (contextVk->getFeatures().depthClamping.enabled)
{
depthClipState.depthClipEnable = VK_TRUE;
*pNextPtr = &depthClipState;
pNextPtr = &depthClipState.pNext;
}
VkPipelineRasterizationStateStreamCreateInfoEXT rasterStreamState = {};
rasterStreamState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT;
if (contextVk->getFeatures().supportsGeometryStreamsCapability.enabled)
{
rasterStreamState.rasterizationStream = 0;
*pNextPtr = &rasterStreamState;
pNextPtr = &rasterStreamState.pNext;
}
// Multisample state.
multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
multisampleState.flags = 0;
multisampleState.rasterizationSamples =
gl_vk::GetSamples(rasterAndMS.bits.rasterizationSamples);
multisampleState.sampleShadingEnable =
static_cast<VkBool32>(rasterAndMS.bits.sampleShadingEnable);
multisampleState.minSampleShading = rasterAndMS.minSampleShading;
multisampleState.pSampleMask = rasterAndMS.sampleMask;
multisampleState.alphaToCoverageEnable =
static_cast<VkBool32>(rasterAndMS.bits.alphaToCoverageEnable);
multisampleState.alphaToOneEnable = static_cast<VkBool32>(rasterAndMS.bits.alphaToOneEnable);
// Depth/stencil state.
depthStencilState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
depthStencilState.flags = 0;
depthStencilState.depthTestEnable =
static_cast<VkBool32>(mDepthStencilStateInfo.enable.depthTest);
depthStencilState.depthWriteEnable =
static_cast<VkBool32>(mDepthStencilStateInfo.enable.depthWrite);
depthStencilState.depthCompareOp = static_cast<VkCompareOp>(
mDepthStencilStateInfo.depthCompareOpAndSurfaceRotation.depthCompareOp);
depthStencilState.depthBoundsTestEnable =
static_cast<VkBool32>(mDepthStencilStateInfo.enable.depthBoundsTest);
depthStencilState.stencilTestEnable =
static_cast<VkBool32>(mDepthStencilStateInfo.enable.stencilTest);
UnpackStencilState(mDepthStencilStateInfo.front, mDepthStencilStateInfo.frontStencilReference,
&depthStencilState.front);
UnpackStencilState(mDepthStencilStateInfo.back, mDepthStencilStateInfo.backStencilReference,
&depthStencilState.back);
depthStencilState.minDepthBounds = mDepthStencilStateInfo.minDepthBounds;
depthStencilState.maxDepthBounds = mDepthStencilStateInfo.maxDepthBounds;
const PackedInputAssemblyAndColorBlendStateInfo &inputAndBlend =
mInputAssemblyAndColorBlendStateInfo;
blendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
blendState.flags = 0;
blendState.logicOpEnable = static_cast<VkBool32>(inputAndBlend.logic.opEnable);
blendState.logicOp = static_cast<VkLogicOp>(inputAndBlend.logic.op);
blendState.attachmentCount = static_cast<uint32_t>(mRenderPassDesc.colorAttachmentRange());
blendState.pAttachments = blendAttachmentState.data();
// If this graphics pipeline is for the unresolve operation, correct the color attachment count
// for that subpass.
if ((mRenderPassDesc.getColorUnresolveAttachmentMask().any() ||
mRenderPassDesc.hasDepthStencilUnresolveAttachment()) &&
mRasterizationAndMultisampleStateInfo.bits.subpass == 0)
{
blendState.attachmentCount =
static_cast<uint32_t>(mRenderPassDesc.getColorUnresolveAttachmentMask().count());
}
for (int i = 0; i < 4; i++)
{
blendState.blendConstants[i] = inputAndBlend.blendConstants[i];
}
const gl::DrawBufferMask blendEnableMask(inputAndBlend.blendEnableMask);
// Zero-init all states.
blendAttachmentState = {};
for (uint32_t colorIndexGL = 0; colorIndexGL < blendState.attachmentCount; ++colorIndexGL)
{
VkPipelineColorBlendAttachmentState &state = blendAttachmentState[colorIndexGL];
if (blendEnableMask[colorIndexGL])
{
// To avoid triggering valid usage error, blending must be disabled for formats that do
// not have VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT feature bit set.
// From OpenGL ES clients, this means disabling blending for integer formats.
if (!angle::Format::Get(mRenderPassDesc[colorIndexGL]).isInt())
{
ASSERT(!contextVk->getRenderer()
->getFormat(mRenderPassDesc[colorIndexGL])
.getActualRenderableImageFormat()
.isInt());
state.blendEnable = VK_TRUE;
UnpackBlendAttachmentState(inputAndBlend.attachments[colorIndexGL], &state);
}
}
if (contextVk->getExtensions().robustFragmentShaderOutputANGLE &&
missingOutputsMask[colorIndexGL])
{
state.colorWriteMask = 0;
}
else
{
state.colorWriteMask = Int4Array_Get<VkColorComponentFlags>(
inputAndBlend.colorWriteMaskBits, colorIndexGL);
}
}
// Dynamic state
angle::FixedVector<VkDynamicState, 2> dynamicStateList;
dynamicStateList.push_back(VK_DYNAMIC_STATE_VIEWPORT);
dynamicStateList.push_back(VK_DYNAMIC_STATE_SCISSOR);
VkPipelineDynamicStateCreateInfo dynamicState = {};
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
dynamicState.dynamicStateCount = static_cast<uint32_t>(dynamicStateList.size());
dynamicState.pDynamicStates = dynamicStateList.data();
// tessellation State
if (tessControlPointer.valid() && tessEvaluationPointer.valid())
{
domainOriginState.sType =
VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO;
domainOriginState.pNext = NULL;
domainOriginState.domainOrigin = VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT;
tessellationState.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
tessellationState.flags = 0;
tessellationState.pNext = &domainOriginState;
tessellationState.patchControlPoints =
static_cast<uint32_t>(inputAndBlend.primitive.patchVertices);
}
createInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
createInfo.flags = 0;
createInfo.stageCount = static_cast<uint32_t>(shaderStages.size());
createInfo.pStages = shaderStages.data();
createInfo.pVertexInputState = &vertexInputState;
createInfo.pInputAssemblyState = &inputAssemblyState;
createInfo.pTessellationState = &tessellationState;
createInfo.pViewportState = &viewportState;
createInfo.pRasterizationState = &rasterState;
createInfo.pMultisampleState = &multisampleState;
createInfo.pDepthStencilState = &depthStencilState;
createInfo.pColorBlendState = &blendState;
createInfo.pDynamicState = dynamicStateList.empty() ? nullptr : &dynamicState;
createInfo.layout = pipelineLayout.getHandle();
createInfo.renderPass = compatibleRenderPass.getHandle();
createInfo.subpass = mRasterizationAndMultisampleStateInfo.bits.subpass;
createInfo.basePipelineHandle = VK_NULL_HANDLE;
createInfo.basePipelineIndex = 0;
ANGLE_VK_TRY(contextVk,
pipelineOut->initGraphics(contextVk->getDevice(), createInfo, pipelineCacheVk));
return angle::Result::Continue;
}
void GraphicsPipelineDesc::updateVertexInput(GraphicsPipelineTransitionBits *transition,
uint32_t attribIndex,
GLuint stride,
GLuint divisor,
angle::FormatID format,
bool compressed,
GLuint relativeOffset)
{
PackedAttribDesc &packedAttrib = mVertexInputAttribs.attribs[attribIndex];
SetBitField(packedAttrib.stride, stride);
SetBitField(packedAttrib.divisor, divisor);
if (format == angle::FormatID::NONE)
{
UNIMPLEMENTED();
}
SetBitField(packedAttrib.format, format);
SetBitField(packedAttrib.compressed, compressed);
SetBitField(packedAttrib.offset, relativeOffset);
constexpr size_t kAttribBits = kPackedAttribDescSize * kBitsPerByte;
const size_t kBit =
ANGLE_GET_INDEXED_TRANSITION_BIT(mVertexInputAttribs, attribs, attribIndex, kAttribBits);
// Cover the next dirty bit conservatively. Because each attribute is 6 bytes.
transition->set(kBit);
transition->set(kBit + 1);
}
void GraphicsPipelineDesc::setTopology(gl::PrimitiveMode drawMode)
{
VkPrimitiveTopology vkTopology = gl_vk::GetPrimitiveTopology(drawMode);
SetBitField(mInputAssemblyAndColorBlendStateInfo.primitive.topology, vkTopology);
}
void GraphicsPipelineDesc::updateTopology(GraphicsPipelineTransitionBits *transition,
gl::PrimitiveMode drawMode)
{
setTopology(drawMode);
transition->set(ANGLE_GET_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo, primitive));
}
void GraphicsPipelineDesc::updateDepthClipControl(GraphicsPipelineTransitionBits *transition,
bool negativeOneToOne)
{
SetBitField(mDepthStencilStateInfo.enable.viewportNegativeOneToOne, negativeOneToOne);
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, enable));
}
void GraphicsPipelineDesc::updatePrimitiveRestartEnabled(GraphicsPipelineTransitionBits *transition,
bool primitiveRestartEnabled)
{
mInputAssemblyAndColorBlendStateInfo.primitive.restartEnable =
static_cast<uint16_t>(primitiveRestartEnabled);
transition->set(ANGLE_GET_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo, primitive));
}
void GraphicsPipelineDesc::setCullMode(VkCullModeFlagBits cullMode)
{
SetBitField(mRasterizationAndMultisampleStateInfo.bits.cullMode, cullMode);
}
void GraphicsPipelineDesc::updateCullMode(GraphicsPipelineTransitionBits *transition,
const gl::RasterizerState &rasterState)
{
setCullMode(gl_vk::GetCullMode(rasterState));
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updateFrontFace(GraphicsPipelineTransitionBits *transition,
const gl::RasterizerState &rasterState,
bool invertFrontFace)
{
mRasterizationAndMultisampleStateInfo.bits.frontFace =
static_cast<uint16_t>(gl_vk::GetFrontFace(rasterState.frontFace, invertFrontFace));
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updateLineWidth(GraphicsPipelineTransitionBits *transition,
float lineWidth)
{
mRasterizationAndMultisampleStateInfo.lineWidth = lineWidth;
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, lineWidth));
}
void GraphicsPipelineDesc::updateRasterizerDiscardEnabled(
GraphicsPipelineTransitionBits *transition,
bool rasterizerDiscardEnabled)
{
mRasterizationAndMultisampleStateInfo.bits.rasterizationDiscardEnable =
static_cast<uint32_t>(rasterizerDiscardEnabled);
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
uint32_t GraphicsPipelineDesc::getRasterizationSamples() const
{
return mRasterizationAndMultisampleStateInfo.bits.rasterizationSamples;
}
void GraphicsPipelineDesc::setRasterizationSamples(uint32_t rasterizationSamples)
{
mRasterizationAndMultisampleStateInfo.bits.rasterizationSamples = rasterizationSamples;
}
void GraphicsPipelineDesc::updateRasterizationSamples(GraphicsPipelineTransitionBits *transition,
uint32_t rasterizationSamples)
{
setRasterizationSamples(rasterizationSamples);
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updateAlphaToCoverageEnable(GraphicsPipelineTransitionBits *transition,
bool enable)
{
mRasterizationAndMultisampleStateInfo.bits.alphaToCoverageEnable = enable;
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updateAlphaToOneEnable(GraphicsPipelineTransitionBits *transition,
bool enable)
{
mRasterizationAndMultisampleStateInfo.bits.alphaToOneEnable = enable;
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updateSampleMask(GraphicsPipelineTransitionBits *transition,
uint32_t maskNumber,
uint32_t mask)
{
ASSERT(maskNumber < gl::MAX_SAMPLE_MASK_WORDS);
mRasterizationAndMultisampleStateInfo.sampleMask[maskNumber] = mask;
constexpr size_t kMaskBits =
sizeof(mRasterizationAndMultisampleStateInfo.sampleMask[0]) * kBitsPerByte;
transition->set(ANGLE_GET_INDEXED_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo,
sampleMask, maskNumber, kMaskBits));
}
void GraphicsPipelineDesc::updateSampleShading(GraphicsPipelineTransitionBits *transition,
bool enable,
float value)
{
mRasterizationAndMultisampleStateInfo.bits.sampleShadingEnable = enable;
mRasterizationAndMultisampleStateInfo.minSampleShading = (enable ? value : 1.0f);
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
transition->set(
ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, minSampleShading));
}
void GraphicsPipelineDesc::updateBlendColor(GraphicsPipelineTransitionBits *transition,
const gl::ColorF &color)
{
mInputAssemblyAndColorBlendStateInfo.blendConstants[0] = color.red;
mInputAssemblyAndColorBlendStateInfo.blendConstants[1] = color.green;
mInputAssemblyAndColorBlendStateInfo.blendConstants[2] = color.blue;
mInputAssemblyAndColorBlendStateInfo.blendConstants[3] = color.alpha;
constexpr size_t kSizeBits = sizeof(mInputAssemblyAndColorBlendStateInfo.blendConstants[0]) * 8;
for (int index = 0; index < 4; ++index)
{
const size_t kBit = ANGLE_GET_INDEXED_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo,
blendConstants, index, kSizeBits);
transition->set(kBit);
}
}
void GraphicsPipelineDesc::setSingleBlend(uint32_t colorIndexGL,
bool enabled,
VkBlendOp op,
VkBlendFactor srcFactor,
VkBlendFactor dstFactor)
{
mInputAssemblyAndColorBlendStateInfo.blendEnableMask |= static_cast<uint8_t>(1 << colorIndexGL);
PackedColorBlendAttachmentState &blendAttachmentState =
mInputAssemblyAndColorBlendStateInfo.attachments[colorIndexGL];
blendAttachmentState.colorBlendOp = op;
blendAttachmentState.alphaBlendOp = op;
blendAttachmentState.srcColorBlendFactor = srcFactor;
blendAttachmentState.dstColorBlendFactor = dstFactor;
blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
}
void GraphicsPipelineDesc::updateBlendEnabled(GraphicsPipelineTransitionBits *transition,
gl::DrawBufferMask blendEnabledMask)
{
mInputAssemblyAndColorBlendStateInfo.blendEnableMask =
static_cast<uint8_t>(blendEnabledMask.bits());
transition->set(
ANGLE_GET_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo, blendEnableMask));
}
void GraphicsPipelineDesc::updateBlendEquations(GraphicsPipelineTransitionBits *transition,
const gl::BlendStateExt &blendStateExt,
gl::DrawBufferMask attachmentMask)
{
constexpr size_t kSizeBits = sizeof(PackedColorBlendAttachmentState) * 8;
for (size_t attachmentIndex : attachmentMask)
{
PackedColorBlendAttachmentState &blendAttachmentState =
mInputAssemblyAndColorBlendStateInfo.attachments[attachmentIndex];
blendAttachmentState.colorBlendOp =
PackGLBlendOp(blendStateExt.getEquationColorIndexed(attachmentIndex));
blendAttachmentState.alphaBlendOp =
PackGLBlendOp(blendStateExt.getEquationAlphaIndexed(attachmentIndex));
transition->set(ANGLE_GET_INDEXED_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo,
attachments, attachmentIndex, kSizeBits));
}
}
void GraphicsPipelineDesc::updateBlendFuncs(GraphicsPipelineTransitionBits *transition,
const gl::BlendStateExt &blendStateExt,
gl::DrawBufferMask attachmentMask)
{
constexpr size_t kSizeBits = sizeof(PackedColorBlendAttachmentState) * 8;
for (size_t attachmentIndex : attachmentMask)
{
PackedColorBlendAttachmentState &blendAttachmentState =
mInputAssemblyAndColorBlendStateInfo.attachments[attachmentIndex];
blendAttachmentState.srcColorBlendFactor =
PackGLBlendFactor(blendStateExt.getSrcColorIndexed(attachmentIndex));
blendAttachmentState.dstColorBlendFactor =
PackGLBlendFactor(blendStateExt.getDstColorIndexed(attachmentIndex));
blendAttachmentState.srcAlphaBlendFactor =
PackGLBlendFactor(blendStateExt.getSrcAlphaIndexed(attachmentIndex));
blendAttachmentState.dstAlphaBlendFactor =
PackGLBlendFactor(blendStateExt.getDstAlphaIndexed(attachmentIndex));
transition->set(ANGLE_GET_INDEXED_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo,
attachments, attachmentIndex, kSizeBits));
}
}
void GraphicsPipelineDesc::resetBlendFuncsAndEquations(GraphicsPipelineTransitionBits *transition,
const gl::BlendStateExt &blendStateExt,
gl::DrawBufferMask previousAttachmentsMask,
gl::DrawBufferMask newAttachmentsMask)
{
// A framebuffer with attachments in P was bound, and now one with attachments in N is bound.
// We need to clear blend funcs and equations for attachments in P that are not in N. That is
// attachments in P&~N.
const gl::DrawBufferMask attachmentsToClear = previousAttachmentsMask & ~newAttachmentsMask;
// We also need to restore blend funcs and equations for attachments in N that are not in P.
const gl::DrawBufferMask attachmentsToAdd = newAttachmentsMask & ~previousAttachmentsMask;
constexpr size_t kSizeBits = sizeof(PackedColorBlendAttachmentState) * 8;
for (size_t attachmentIndex : attachmentsToClear)
{
PackedColorBlendAttachmentState &blendAttachmentState =
mInputAssemblyAndColorBlendStateInfo.attachments[attachmentIndex];
blendAttachmentState.colorBlendOp = VK_BLEND_OP_ADD;
blendAttachmentState.alphaBlendOp = VK_BLEND_OP_ADD;
blendAttachmentState.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
blendAttachmentState.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
transition->set(ANGLE_GET_INDEXED_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo,
attachments, attachmentIndex, kSizeBits));
}
if (attachmentsToAdd.any())
{
updateBlendFuncs(transition, blendStateExt, attachmentsToAdd);
updateBlendEquations(transition, blendStateExt, attachmentsToAdd);
}
}
void GraphicsPipelineDesc::setColorWriteMasks(gl::BlendStateExt::ColorMaskStorage::Type colorMasks,
const gl::DrawBufferMask &alphaMask,
const gl::DrawBufferMask &enabledDrawBuffers)
{
PackedInputAssemblyAndColorBlendStateInfo &inputAndBlend = mInputAssemblyAndColorBlendStateInfo;
for (uint32_t colorIndexGL = 0; colorIndexGL < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS;
colorIndexGL++)
{
uint8_t colorMask =
gl::BlendStateExt::ColorMaskStorage::GetValueIndexed(colorIndexGL, colorMasks);
uint8_t mask = 0;
if (enabledDrawBuffers.test(colorIndexGL))
{
mask = alphaMask[colorIndexGL] ? (colorMask & ~VK_COLOR_COMPONENT_A_BIT) : colorMask;
}
Int4Array_Set(inputAndBlend.colorWriteMaskBits, colorIndexGL, mask);
}
}
void GraphicsPipelineDesc::setSingleColorWriteMask(uint32_t colorIndexGL,
VkColorComponentFlags colorComponentFlags)
{
PackedInputAssemblyAndColorBlendStateInfo &inputAndBlend = mInputAssemblyAndColorBlendStateInfo;
uint8_t colorMask = static_cast<uint8_t>(colorComponentFlags);
Int4Array_Set(inputAndBlend.colorWriteMaskBits, colorIndexGL, colorMask);
}
void GraphicsPipelineDesc::updateColorWriteMasks(
GraphicsPipelineTransitionBits *transition,
gl::BlendStateExt::ColorMaskStorage::Type colorMasks,
const gl::DrawBufferMask &alphaMask,
const gl::DrawBufferMask &enabledDrawBuffers)
{
setColorWriteMasks(colorMasks, alphaMask, enabledDrawBuffers);
for (size_t colorIndexGL = 0; colorIndexGL < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS;
colorIndexGL++)
{
transition->set(ANGLE_GET_INDEXED_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo,
colorWriteMaskBits, colorIndexGL, 4));
}
}
void GraphicsPipelineDesc::setDepthTestEnabled(bool enabled)
{
mDepthStencilStateInfo.enable.depthTest = enabled;
}
void GraphicsPipelineDesc::setDepthWriteEnabled(bool enabled)
{
mDepthStencilStateInfo.enable.depthWrite = enabled;
}
void GraphicsPipelineDesc::setDepthFunc(VkCompareOp op)
{
SetBitField(mDepthStencilStateInfo.depthCompareOpAndSurfaceRotation.depthCompareOp, op);
}
void GraphicsPipelineDesc::setDepthClampEnabled(bool enabled)
{
mRasterizationAndMultisampleStateInfo.bits.depthClampEnable = enabled;
}
void GraphicsPipelineDesc::setStencilTestEnabled(bool enabled)
{
mDepthStencilStateInfo.enable.stencilTest = enabled;
}
void GraphicsPipelineDesc::setStencilFrontFuncs(uint8_t reference,
VkCompareOp compareOp,
uint8_t compareMask)
{
mDepthStencilStateInfo.frontStencilReference = reference;
mDepthStencilStateInfo.front.compareMask = compareMask;
SetBitField(mDepthStencilStateInfo.front.ops.compare, compareOp);
}
void GraphicsPipelineDesc::setStencilBackFuncs(uint8_t reference,
VkCompareOp compareOp,
uint8_t compareMask)
{
mDepthStencilStateInfo.backStencilReference = reference;
mDepthStencilStateInfo.back.compareMask = compareMask;
SetBitField(mDepthStencilStateInfo.back.ops.compare, compareOp);
}
void GraphicsPipelineDesc::setStencilFrontOps(VkStencilOp failOp,
VkStencilOp passOp,
VkStencilOp depthFailOp)
{
SetBitField(mDepthStencilStateInfo.front.ops.fail, failOp);
SetBitField(mDepthStencilStateInfo.front.ops.pass, passOp);
SetBitField(mDepthStencilStateInfo.front.ops.depthFail, depthFailOp);
}
void GraphicsPipelineDesc::setStencilBackOps(VkStencilOp failOp,
VkStencilOp passOp,
VkStencilOp depthFailOp)
{
SetBitField(mDepthStencilStateInfo.back.ops.fail, failOp);
SetBitField(mDepthStencilStateInfo.back.ops.pass, passOp);
SetBitField(mDepthStencilStateInfo.back.ops.depthFail, depthFailOp);
}
void GraphicsPipelineDesc::setStencilFrontWriteMask(uint8_t mask)
{
mDepthStencilStateInfo.front.writeMask = mask;
}
void GraphicsPipelineDesc::setStencilBackWriteMask(uint8_t mask)
{
mDepthStencilStateInfo.back.writeMask = mask;
}
void GraphicsPipelineDesc::updateDepthTestEnabled(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState,
const gl::Framebuffer *drawFramebuffer)
{
// Only enable the depth test if the draw framebuffer has a depth buffer. It's possible that
// we're emulating a stencil-only buffer with a depth-stencil buffer
setDepthTestEnabled(depthStencilState.depthTest && drawFramebuffer->hasDepth());
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, enable));
}
void GraphicsPipelineDesc::updateDepthFunc(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState)
{
setDepthFunc(PackGLCompareFunc(depthStencilState.depthFunc));
transition->set(
ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, depthCompareOpAndSurfaceRotation));
}
void GraphicsPipelineDesc::updateSurfaceRotation(GraphicsPipelineTransitionBits *transition,
const SurfaceRotation surfaceRotation)
{
SetBitField(mDepthStencilStateInfo.depthCompareOpAndSurfaceRotation.surfaceRotation,
surfaceRotation);
transition->set(
ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, depthCompareOpAndSurfaceRotation));
}
void GraphicsPipelineDesc::updateDepthWriteEnabled(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState,
const gl::Framebuffer *drawFramebuffer)
{
// Don't write to depth buffers that should not exist
const bool depthWriteEnabled =
drawFramebuffer->hasDepth() && depthStencilState.depthTest && depthStencilState.depthMask;
if (static_cast<bool>(mDepthStencilStateInfo.enable.depthWrite) != depthWriteEnabled)
{
setDepthWriteEnabled(depthWriteEnabled);
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, enable));
}
}
void GraphicsPipelineDesc::updateStencilTestEnabled(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState,
const gl::Framebuffer *drawFramebuffer)
{
// Only enable the stencil test if the draw framebuffer has a stencil buffer. It's possible
// that we're emulating a depth-only buffer with a depth-stencil buffer
setStencilTestEnabled(depthStencilState.stencilTest && drawFramebuffer->hasStencil());
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, enable));
}
void GraphicsPipelineDesc::updateStencilFrontFuncs(GraphicsPipelineTransitionBits *transition,
GLint ref,
const gl::DepthStencilState &depthStencilState)
{
setStencilFrontFuncs(static_cast<uint8_t>(ref),
PackGLCompareFunc(depthStencilState.stencilFunc),
static_cast<uint8_t>(depthStencilState.stencilMask));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, front));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, frontStencilReference));
}
void GraphicsPipelineDesc::updateStencilBackFuncs(GraphicsPipelineTransitionBits *transition,
GLint ref,
const gl::DepthStencilState &depthStencilState)
{
setStencilBackFuncs(static_cast<uint8_t>(ref),
PackGLCompareFunc(depthStencilState.stencilBackFunc),
static_cast<uint8_t>(depthStencilState.stencilBackMask));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, back));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, backStencilReference));
}
void GraphicsPipelineDesc::updateStencilFrontOps(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState)
{
setStencilFrontOps(PackGLStencilOp(depthStencilState.stencilFail),
PackGLStencilOp(depthStencilState.stencilPassDepthPass),
PackGLStencilOp(depthStencilState.stencilPassDepthFail));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, front));
}
void GraphicsPipelineDesc::updateStencilBackOps(GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState)
{
setStencilBackOps(PackGLStencilOp(depthStencilState.stencilBackFail),
PackGLStencilOp(depthStencilState.stencilBackPassDepthPass),
PackGLStencilOp(depthStencilState.stencilBackPassDepthFail));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, back));
}
void GraphicsPipelineDesc::updateStencilFrontWriteMask(
GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState,
const gl::Framebuffer *drawFramebuffer)
{
// Don't write to stencil buffers that should not exist
setStencilFrontWriteMask(static_cast<uint8_t>(
drawFramebuffer->hasStencil() ? depthStencilState.stencilWritemask : 0));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, front));
}
void GraphicsPipelineDesc::updateStencilBackWriteMask(
GraphicsPipelineTransitionBits *transition,
const gl::DepthStencilState &depthStencilState,
const gl::Framebuffer *drawFramebuffer)
{
// Don't write to stencil buffers that should not exist
setStencilBackWriteMask(static_cast<uint8_t>(
drawFramebuffer->hasStencil() ? depthStencilState.stencilBackWritemask : 0));
transition->set(ANGLE_GET_TRANSITION_BIT(mDepthStencilStateInfo, back));
}
void GraphicsPipelineDesc::updatePolygonOffsetFillEnabled(
GraphicsPipelineTransitionBits *transition,
bool enabled)
{
mRasterizationAndMultisampleStateInfo.bits.depthBiasEnable = enabled;
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
void GraphicsPipelineDesc::updatePolygonOffset(GraphicsPipelineTransitionBits *transition,
const gl::RasterizerState &rasterState)
{
mRasterizationAndMultisampleStateInfo.depthBiasSlopeFactor = rasterState.polygonOffsetFactor;
mRasterizationAndMultisampleStateInfo.depthBiasConstantFactor = rasterState.polygonOffsetUnits;
transition->set(
ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, depthBiasSlopeFactor));
transition->set(
ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, depthBiasConstantFactor));
}
void GraphicsPipelineDesc::setRenderPassDesc(const RenderPassDesc &renderPassDesc)
{
mRenderPassDesc = renderPassDesc;
}
void GraphicsPipelineDesc::updateDrawableSize(GraphicsPipelineTransitionBits *transition,
uint32_t width,
uint32_t height)
{
SetBitField(mDrawableSize.width, width);
SetBitField(mDrawableSize.height, height);
transition->set(ANGLE_GET_TRANSITION_BIT(mDrawableSize, width));
transition->set(ANGLE_GET_TRANSITION_BIT(mDrawableSize, height));
}
void GraphicsPipelineDesc::updateSubpass(GraphicsPipelineTransitionBits *transition,
uint32_t subpass)
{
if (mRasterizationAndMultisampleStateInfo.bits.subpass != subpass)
{
SetBitField(mRasterizationAndMultisampleStateInfo.bits.subpass, subpass);
transition->set(ANGLE_GET_TRANSITION_BIT(mRasterizationAndMultisampleStateInfo, bits));
}
}
void GraphicsPipelineDesc::updatePatchVertices(GraphicsPipelineTransitionBits *transition,
GLuint value)
{
SetBitField(mInputAssemblyAndColorBlendStateInfo.primitive.patchVertices, value);
transition->set(ANGLE_GET_TRANSITION_BIT(mInputAssemblyAndColorBlendStateInfo, primitive));
}
void GraphicsPipelineDesc::resetSubpass(GraphicsPipelineTransitionBits *transition)
{
updateSubpass(transition, 0);
}
void GraphicsPipelineDesc::nextSubpass(GraphicsPipelineTransitionBits *transition)
{
updateSubpass(transition, mRasterizationAndMultisampleStateInfo.bits.subpass + 1);
}
void GraphicsPipelineDesc::setSubpass(uint32_t subpass)
{
SetBitField(mRasterizationAndMultisampleStateInfo.bits.subpass, subpass);
}
uint32_t GraphicsPipelineDesc::getSubpass() const
{
return mRasterizationAndMultisampleStateInfo.bits.subpass;
}
void GraphicsPipelineDesc::updateEmulatedDitherControl(GraphicsPipelineTransitionBits *transition,
uint16_t value)
{
// Make sure we don't waste time resetting this to zero in the common no-dither case.
ASSERT(value != 0 || mDither.emulatedDitherControl != 0);
mDither.emulatedDitherControl = value;
transition->set(ANGLE_GET_TRANSITION_BIT(mDither, emulatedDitherControl));
}
void GraphicsPipelineDesc::updateRenderPassDesc(GraphicsPipelineTransitionBits *transition,
const RenderPassDesc &renderPassDesc)
{
setRenderPassDesc(renderPassDesc);
// The RenderPass is a special case where it spans multiple bits but has no member.
constexpr size_t kFirstBit =
offsetof(GraphicsPipelineDesc, mRenderPassDesc) >> kTransitionByteShift;
constexpr size_t kBitCount = kRenderPassDescSize >> kTransitionByteShift;
for (size_t bit = 0; bit < kBitCount; ++bit)
{
transition->set(kFirstBit + bit);
}
}
// AttachmentOpsArray implementation.
AttachmentOpsArray::AttachmentOpsArray()
{
memset(&mOps, 0, sizeof(PackedAttachmentOpsDesc) * mOps.size());
}
AttachmentOpsArray::~AttachmentOpsArray() = default;
AttachmentOpsArray::AttachmentOpsArray(const AttachmentOpsArray &other)
{
memcpy(&mOps, &other.mOps, sizeof(PackedAttachmentOpsDesc) * mOps.size());
}
AttachmentOpsArray &AttachmentOpsArray::operator=(const AttachmentOpsArray &other)
{
memcpy(&mOps, &other.mOps, sizeof(PackedAttachmentOpsDesc) * mOps.size());
return *this;
}
const PackedAttachmentOpsDesc &AttachmentOpsArray::operator[](PackedAttachmentIndex index) const
{
return mOps[index.get()];
}
PackedAttachmentOpsDesc &AttachmentOpsArray::operator[](PackedAttachmentIndex index)
{
return mOps[index.get()];
}
void AttachmentOpsArray::initWithLoadStore(PackedAttachmentIndex index,
ImageLayout initialLayout,
ImageLayout finalLayout)
{
setLayouts(index, initialLayout, finalLayout);
setOps(index, RenderPassLoadOp::Load, RenderPassStoreOp::Store);
setStencilOps(index, RenderPassLoadOp::Load, RenderPassStoreOp::Store);
}
void AttachmentOpsArray::setLayouts(PackedAttachmentIndex index,
ImageLayout initialLayout,
ImageLayout finalLayout)
{
PackedAttachmentOpsDesc &ops = mOps[index.get()];
SetBitField(ops.initialLayout, initialLayout);
SetBitField(ops.finalLayout, finalLayout);
}
void AttachmentOpsArray::setOps(PackedAttachmentIndex index,
RenderPassLoadOp loadOp,
RenderPassStoreOp storeOp)
{
PackedAttachmentOpsDesc &ops = mOps[index.get()];
SetBitField(ops.loadOp, loadOp);
SetBitField(ops.storeOp, storeOp);
ops.isInvalidated = false;
}
void AttachmentOpsArray::setStencilOps(PackedAttachmentIndex index,
RenderPassLoadOp loadOp,
RenderPassStoreOp storeOp)
{
PackedAttachmentOpsDesc &ops = mOps[index.get()];
SetBitField(ops.stencilLoadOp, loadOp);
SetBitField(ops.stencilStoreOp, storeOp);
ops.isStencilInvalidated = false;
}
void AttachmentOpsArray::setClearOp(PackedAttachmentIndex index)
{
PackedAttachmentOpsDesc &ops = mOps[index.get()];
SetBitField(ops.loadOp, RenderPassLoadOp::Clear);
}
void AttachmentOpsArray::setClearStencilOp(PackedAttachmentIndex index)
{
PackedAttachmentOpsDesc &ops = mOps[index.get()];
SetBitField(ops.stencilLoadOp, RenderPassLoadOp::Clear);
}
size_t AttachmentOpsArray::hash() const
{
return angle::ComputeGenericHash(mOps);
}
bool operator==(const AttachmentOpsArray &lhs, const AttachmentOpsArray &rhs)
{
return (memcmp(&lhs, &rhs, sizeof(AttachmentOpsArray)) == 0);
}
// DescriptorSetLayoutDesc implementation.
DescriptorSetLayoutDesc::DescriptorSetLayoutDesc() : mPackedDescriptorSetLayout{} {}
DescriptorSetLayoutDesc::~DescriptorSetLayoutDesc() = default;
DescriptorSetLayoutDesc::DescriptorSetLayoutDesc(const DescriptorSetLayoutDesc &other) = default;
DescriptorSetLayoutDesc &DescriptorSetLayoutDesc::operator=(const DescriptorSetLayoutDesc &other) =
default;
size_t DescriptorSetLayoutDesc::hash() const
{
return angle::ComputeGenericHash(mPackedDescriptorSetLayout);
}
bool DescriptorSetLayoutDesc::operator==(const DescriptorSetLayoutDesc &other) const
{
return (memcmp(&mPackedDescriptorSetLayout, &other.mPackedDescriptorSetLayout,
sizeof(mPackedDescriptorSetLayout)) == 0);
}
void DescriptorSetLayoutDesc::update(uint32_t bindingIndex,
VkDescriptorType descriptorType,
uint32_t count,
VkShaderStageFlags stages,
const Sampler *immutableSampler)
{
ASSERT(static_cast<size_t>(descriptorType) < std::numeric_limits<uint16_t>::max());
ASSERT(count < std::numeric_limits<uint16_t>::max());
PackedDescriptorSetBinding &packedBinding = mPackedDescriptorSetLayout[bindingIndex];
SetBitField(packedBinding.type, descriptorType);
SetBitField(packedBinding.count, count);
SetBitField(packedBinding.stages, stages);
packedBinding.immutableSampler = VK_NULL_HANDLE;
packedBinding.pad = 0;
if (immutableSampler)
{
ASSERT(count == 1);
packedBinding.immutableSampler = immutableSampler->getHandle();
}
}
void DescriptorSetLayoutDesc::unpackBindings(DescriptorSetLayoutBindingVector *bindings,
std::vector<VkSampler> *immutableSamplers) const
{
for (uint32_t bindingIndex = 0; bindingIndex < kMaxDescriptorSetLayoutBindings; ++bindingIndex)
{
const PackedDescriptorSetBinding &packedBinding = mPackedDescriptorSetLayout[bindingIndex];
if (packedBinding.count == 0)
continue;
VkDescriptorSetLayoutBinding binding = {};
binding.binding = bindingIndex;
binding.descriptorCount = packedBinding.count;
binding.descriptorType = static_cast<VkDescriptorType>(packedBinding.type);
binding.stageFlags = static_cast<VkShaderStageFlags>(packedBinding.stages);
if (packedBinding.immutableSampler != VK_NULL_HANDLE)
{
ASSERT(packedBinding.count == 1);
immutableSamplers->push_back(packedBinding.immutableSampler);
binding.pImmutableSamplers = reinterpret_cast<const VkSampler *>(angle::DirtyPointer);
}
bindings->push_back(binding);
}
if (!immutableSamplers->empty())
{
// Patch up pImmutableSampler addresses now that the vector is stable
int immutableIndex = 0;
for (VkDescriptorSetLayoutBinding &binding : *bindings)
{
if (binding.pImmutableSamplers)
{
binding.pImmutableSamplers = &(*immutableSamplers)[immutableIndex];
immutableIndex++;
}
}
}
}
// PipelineLayoutDesc implementation.
PipelineLayoutDesc::PipelineLayoutDesc()
: mDescriptorSetLayouts{}, mPushConstantRange{}, mPadding(0)
{}
PipelineLayoutDesc::~PipelineLayoutDesc() = default;
PipelineLayoutDesc::PipelineLayoutDesc(const PipelineLayoutDesc &other) = default;
PipelineLayoutDesc &PipelineLayoutDesc::operator=(const PipelineLayoutDesc &rhs)
{
mDescriptorSetLayouts = rhs.mDescriptorSetLayouts;
mPushConstantRange = rhs.mPushConstantRange;
return *this;
}
size_t PipelineLayoutDesc::hash() const
{
return angle::ComputeGenericHash(*this);
}
bool PipelineLayoutDesc::operator==(const PipelineLayoutDesc &other) const
{
return memcmp(this, &other, sizeof(PipelineLayoutDesc)) == 0;
}
void PipelineLayoutDesc::updateDescriptorSetLayout(DescriptorSetIndex setIndex,
const DescriptorSetLayoutDesc &desc)
{
mDescriptorSetLayouts[setIndex] = desc;
}
void PipelineLayoutDesc::updatePushConstantRange(VkShaderStageFlags stageMask,
uint32_t offset,
uint32_t size)
{
SetBitField(mPushConstantRange.offset, offset);
SetBitField(mPushConstantRange.size, size);
SetBitField(mPushConstantRange.stageMask, stageMask);
}
// PipelineHelper implementation.
PipelineHelper::PipelineHelper() = default;
PipelineHelper::~PipelineHelper() = default;
void PipelineHelper::destroy(VkDevice device)
{
mPipeline.destroy(device);
}
void PipelineHelper::addTransition(GraphicsPipelineTransitionBits bits,
const GraphicsPipelineDesc *desc,
PipelineHelper *pipeline)
{
mTransitions.emplace_back(bits, desc, pipeline);
}
// DescriptorSetDesc implementation.
size_t DescriptorSetDesc::hash() const
{
return angle::ComputeGenericHash(mPayload.data(), sizeof(mPayload[0]) * mPayload.size());
}
// FramebufferDesc implementation.
FramebufferDesc::FramebufferDesc()
{
reset();
}
FramebufferDesc::~FramebufferDesc() = default;
FramebufferDesc::FramebufferDesc(const FramebufferDesc &other) = default;
FramebufferDesc &FramebufferDesc::operator=(const FramebufferDesc &other) = default;
void FramebufferDesc::update(uint32_t index, ImageOrBufferViewSubresourceSerial serial)
{
static_assert(kMaxFramebufferAttachments + 1 < std::numeric_limits<uint8_t>::max(),
"mMaxIndex size is too small");
ASSERT(index < kMaxFramebufferAttachments);
mSerials[index] = serial;
if (serial.viewSerial.valid())
{
SetBitField(mMaxIndex, std::max(mMaxIndex, static_cast<uint16_t>(index + 1)));
}
}
void FramebufferDesc::updateColor(uint32_t index, ImageOrBufferViewSubresourceSerial serial)
{
update(kFramebufferDescColorIndexOffset + index, serial);
}
void FramebufferDesc::updateColorResolve(uint32_t index, ImageOrBufferViewSubresourceSerial serial)
{
update(kFramebufferDescColorResolveIndexOffset + index, serial);
}
void FramebufferDesc::updateUnresolveMask(FramebufferNonResolveAttachmentMask unresolveMask)
{
SetBitField(mUnresolveAttachmentMask, unresolveMask.bits());
}
void FramebufferDesc::updateDepthStencil(ImageOrBufferViewSubresourceSerial serial)
{
update(kFramebufferDescDepthStencilIndex, serial);
}
void FramebufferDesc::updateDepthStencilResolve(ImageOrBufferViewSubresourceSerial serial)
{
update(kFramebufferDescDepthStencilResolveIndexOffset, serial);
}
size_t FramebufferDesc::hash() const
{
return angle::ComputeGenericHash(&mSerials, sizeof(mSerials[0]) * mMaxIndex) ^
mHasFramebufferFetch << 26 ^ mIsRenderToTexture << 25 ^ mLayerCount << 16 ^
mUnresolveAttachmentMask;
}
void FramebufferDesc::reset()
{
mMaxIndex = 0;
mHasFramebufferFetch = false;
mLayerCount = 0;
mSrgbWriteControlMode = 0;
mUnresolveAttachmentMask = 0;
mIsRenderToTexture = 0;
memset(&mSerials, 0, sizeof(mSerials));
}
bool FramebufferDesc::operator==(const FramebufferDesc &other) const
{
if (mMaxIndex != other.mMaxIndex || mLayerCount != other.mLayerCount ||
mUnresolveAttachmentMask != other.mUnresolveAttachmentMask ||
mHasFramebufferFetch != other.mHasFramebufferFetch ||
mSrgbWriteControlMode != other.mSrgbWriteControlMode ||
mIsRenderToTexture != other.mIsRenderToTexture)
{
return false;
}
size_t validRegionSize = sizeof(mSerials[0]) * mMaxIndex;
return memcmp(&mSerials, &other.mSerials, validRegionSize) == 0;
}
uint32_t FramebufferDesc::attachmentCount() const
{
uint32_t count = 0;
for (const ImageOrBufferViewSubresourceSerial &serial : mSerials)
{
if (serial.viewSerial.valid())
{
count++;
}
}
return count;
}
FramebufferNonResolveAttachmentMask FramebufferDesc::getUnresolveAttachmentMask() const
{
return FramebufferNonResolveAttachmentMask(mUnresolveAttachmentMask);
}
void FramebufferDesc::updateLayerCount(uint32_t layerCount)
{
SetBitField(mLayerCount, layerCount);
}
void FramebufferDesc::updateFramebufferFetchMode(bool hasFramebufferFetch)
{
SetBitField(mHasFramebufferFetch, hasFramebufferFetch);
}
void FramebufferDesc::updateRenderToTexture(bool isRenderToTexture)
{
SetBitField(mIsRenderToTexture, isRenderToTexture);
}
// YcbcrConversionDesc implementation
YcbcrConversionDesc::YcbcrConversionDesc()
{
reset();
}
YcbcrConversionDesc::~YcbcrConversionDesc() = default;
YcbcrConversionDesc::YcbcrConversionDesc(const YcbcrConversionDesc &other) = default;
YcbcrConversionDesc &YcbcrConversionDesc::operator=(const YcbcrConversionDesc &rhs) = default;
size_t YcbcrConversionDesc::hash() const
{
return angle::ComputeGenericHash(*this);
}
bool YcbcrConversionDesc::operator==(const YcbcrConversionDesc &other) const
{
return (memcmp(this, &other, sizeof(YcbcrConversionDesc)) == 0);
}
void YcbcrConversionDesc::reset()
{
mExternalOrVkFormat = 0;
mIsExternalFormat = 0;
mConversionModel = 0;
mColorRange = 0;
mXChromaOffset = 0;
mYChromaOffset = 0;
mChromaFilter = 0;
mRSwizzle = 0;
mGSwizzle = 0;
mBSwizzle = 0;
mASwizzle = 0;
mPadding = 0;
mReserved = 0;
}
void YcbcrConversionDesc::update(RendererVk *rendererVk,
uint64_t externalFormat,
VkSamplerYcbcrModelConversion conversionModel,
VkSamplerYcbcrRange colorRange,
VkChromaLocation xChromaOffset,
VkChromaLocation yChromaOffset,
VkFilter chromaFilter,
VkComponentMapping components,
angle::FormatID intendedFormatID)
{
const vk::Format &vkFormat = rendererVk->getFormat(intendedFormatID);
ASSERT(externalFormat != 0 || vkFormat.getIntendedFormat().isYUV);
SetBitField(mIsExternalFormat, (externalFormat) ? 1 : 0);
mExternalOrVkFormat = (externalFormat)
? externalFormat
: vkFormat.getActualImageVkFormat(vk::ImageAccess::SampleOnly);
SetBitField(mConversionModel, conversionModel);
SetBitField(mColorRange, colorRange);
SetBitField(mXChromaOffset, xChromaOffset);
SetBitField(mYChromaOffset, yChromaOffset);
SetBitField(mChromaFilter, chromaFilter);
SetBitField(mRSwizzle, components.r);
SetBitField(mGSwizzle, components.g);
SetBitField(mBSwizzle, components.b);
SetBitField(mASwizzle, components.a);
}
// SamplerDesc implementation.
SamplerDesc::SamplerDesc()
{
reset();
}
SamplerDesc::~SamplerDesc() = default;
SamplerDesc::SamplerDesc(const SamplerDesc &other) = default;
SamplerDesc &SamplerDesc::operator=(const SamplerDesc &rhs) = default;
SamplerDesc::SamplerDesc(ContextVk *contextVk,
const gl::SamplerState &samplerState,
bool stencilMode,
const YcbcrConversionDesc *ycbcrConversionDesc,
angle::FormatID intendedFormatID)
{
update(contextVk, samplerState, stencilMode, ycbcrConversionDesc, intendedFormatID);
}
void SamplerDesc::reset()
{
mMipLodBias = 0.0f;
mMaxAnisotropy = 0.0f;
mMinLod = 0.0f;
mMaxLod = 0.0f;
mYcbcrConversionDesc.reset();
mMagFilter = 0;
mMinFilter = 0;
mMipmapMode = 0;
mAddressModeU = 0;
mAddressModeV = 0;
mAddressModeW = 0;
mCompareEnabled = 0;
mCompareOp = 0;
mPadding = 0;
mBorderColorType = 0;
mBorderColor.red = 0.0f;
mBorderColor.green = 0.0f;
mBorderColor.blue = 0.0f;
mBorderColor.alpha = 0.0f;
mReserved = 0;
}
void SamplerDesc::update(ContextVk *contextVk,
const gl::SamplerState &samplerState,
bool stencilMode,
const YcbcrConversionDesc *ycbcrConversionDesc,
angle::FormatID intendedFormatID)
{
const angle::FeaturesVk &featuresVk = contextVk->getFeatures();
mMipLodBias = 0.0f;
for (size_t lodOffsetFeatureIdx = 0;
lodOffsetFeatureIdx < featuresVk.forceTextureLODOffset.size(); lodOffsetFeatureIdx++)
{
if (featuresVk.forceTextureLODOffset[lodOffsetFeatureIdx].enabled)
{
// Make sure only one forceTextureLODOffset feature is set.
ASSERT(mMipLodBias == 0.0f);
mMipLodBias = static_cast<float>(lodOffsetFeatureIdx + 1);
}
}
mMaxAnisotropy = samplerState.getMaxAnisotropy();
mMinLod = samplerState.getMinLod();
mMaxLod = samplerState.getMaxLod();
if (ycbcrConversionDesc && ycbcrConversionDesc->valid())
{
// Update the SamplerYcbcrConversionCache key
mYcbcrConversionDesc = *ycbcrConversionDesc;
}
bool compareEnable = samplerState.getCompareMode() == GL_COMPARE_REF_TO_TEXTURE;
VkCompareOp compareOp = gl_vk::GetCompareOp(samplerState.getCompareFunc());
// When sampling from stencil, deqp tests expect texture compare to have no effect
// dEQP - GLES31.functional.stencil_texturing.misc.compare_mode_effect
// states: NOTE: Texture compare mode has no effect when reading stencil values.
if (stencilMode)
{
compareEnable = VK_FALSE;
compareOp = VK_COMPARE_OP_ALWAYS;
}
GLenum magFilter = samplerState.getMagFilter();
GLenum minFilter = samplerState.getMinFilter();
if (featuresVk.forceNearestFiltering.enabled)
{
magFilter = gl::ConvertToNearestFilterMode(magFilter);
minFilter = gl::ConvertToNearestFilterMode(minFilter);
}
if (featuresVk.forceNearestMipFiltering.enabled)
{
minFilter = gl::ConvertToNearestMipFilterMode(minFilter);
}
SetBitField(mMagFilter, gl_vk::GetFilter(magFilter));
SetBitField(mMinFilter, gl_vk::GetFilter(minFilter));
SetBitField(mMipmapMode, gl_vk::GetSamplerMipmapMode(samplerState.getMinFilter()));
SetBitField(mAddressModeU, gl_vk::GetSamplerAddressMode(samplerState.getWrapS()));
SetBitField(mAddressModeV, gl_vk::GetSamplerAddressMode(samplerState.getWrapT()));
SetBitField(mAddressModeW, gl_vk::GetSamplerAddressMode(samplerState.getWrapR()));
SetBitField(mCompareEnabled, compareEnable);
SetBitField(mCompareOp, compareOp);
if (!gl::IsMipmapFiltered(minFilter))
{
// Per the Vulkan spec, GL_NEAREST and GL_LINEAR do not map directly to Vulkan, so
// they must be emulated (See "Mapping of OpenGL to Vulkan filter modes")
SetBitField(mMipmapMode, VK_SAMPLER_MIPMAP_MODE_NEAREST);
mMinLod = 0.0f;
mMaxLod = 0.25f;
}
mPadding = 0;
mBorderColorType =
(samplerState.getBorderColor().type == angle::ColorGeneric::Type::Float) ? 0 : 1;
const vk::Format &vkFormat = contextVk->getRenderer()->getFormat(intendedFormatID);
mBorderColor = samplerState.getBorderColor().colorF;
if (vkFormat.getIntendedFormatID() != angle::FormatID::NONE)
{
LoadTextureBorderFunctionInfo loadFunction = vkFormat.getTextureBorderLoadFunctions();
loadFunction.loadFunction(mBorderColor);
}
mReserved = 0;
}
angle::Result SamplerDesc::init(ContextVk *contextVk, Sampler *sampler) const
{
const gl::Extensions &extensions = contextVk->getExtensions();
bool anisotropyEnable = extensions.textureFilterAnisotropicEXT && mMaxAnisotropy > 1.0f;
VkSamplerCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
createInfo.flags = 0;
createInfo.magFilter = static_cast<VkFilter>(mMagFilter);
createInfo.minFilter = static_cast<VkFilter>(mMinFilter);
createInfo.mipmapMode = static_cast<VkSamplerMipmapMode>(mMipmapMode);
createInfo.addressModeU = static_cast<VkSamplerAddressMode>(mAddressModeU);
createInfo.addressModeV = static_cast<VkSamplerAddressMode>(mAddressModeV);
createInfo.addressModeW = static_cast<VkSamplerAddressMode>(mAddressModeW);
createInfo.mipLodBias = mMipLodBias;
createInfo.anisotropyEnable = anisotropyEnable;
createInfo.maxAnisotropy = mMaxAnisotropy;
createInfo.compareEnable = mCompareEnabled ? VK_TRUE : VK_FALSE;
createInfo.compareOp = static_cast<VkCompareOp>(mCompareOp);
createInfo.minLod = mMinLod;
createInfo.maxLod = mMaxLod;
createInfo.borderColor = VK_BORDER_COLOR_INT_TRANSPARENT_BLACK;
createInfo.unnormalizedCoordinates = VK_FALSE;
// Note: because we don't detect changes to this hint (no dirty bit), if a sampler is created
// with the hint enabled, and then the hint gets disabled, the next render will do so with the
// hint enabled.
VkSamplerFilteringPrecisionGOOGLE filteringInfo = {};
GLenum hint = contextVk->getState().getTextureFilteringHint();
if (hint == GL_NICEST)
{
ASSERT(extensions.textureFilteringHintCHROMIUM);
filteringInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_FILTERING_PRECISION_GOOGLE;
filteringInfo.samplerFilteringPrecisionMode =
VK_SAMPLER_FILTERING_PRECISION_MODE_HIGH_GOOGLE;
AddToPNextChain(&createInfo, &filteringInfo);
}
VkSamplerYcbcrConversionInfo samplerYcbcrConversionInfo = {};
if (mYcbcrConversionDesc.valid())
{
ASSERT((contextVk->getRenderer()->getFeatures().supportsYUVSamplerConversion.enabled));
samplerYcbcrConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
samplerYcbcrConversionInfo.pNext = nullptr;
ANGLE_TRY(contextVk->getRenderer()->getYuvConversionCache().getSamplerYcbcrConversion(
contextVk, mYcbcrConversionDesc, &samplerYcbcrConversionInfo.conversion));
AddToPNextChain(&createInfo, &samplerYcbcrConversionInfo);
// Vulkan spec requires these settings:
createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
createInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
createInfo.anisotropyEnable = VK_FALSE;
createInfo.unnormalizedCoordinates = VK_FALSE;
}
VkSamplerCustomBorderColorCreateInfoEXT customBorderColorInfo = {};
if (createInfo.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
createInfo.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER ||
createInfo.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)
{
ASSERT((contextVk->getRenderer()->getFeatures().supportsCustomBorderColor.enabled));
customBorderColorInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT;
customBorderColorInfo.customBorderColor.float32[0] = mBorderColor.red;
customBorderColorInfo.customBorderColor.float32[1] = mBorderColor.green;
customBorderColorInfo.customBorderColor.float32[2] = mBorderColor.blue;
customBorderColorInfo.customBorderColor.float32[3] = mBorderColor.alpha;
if (mBorderColorType == static_cast<uint32_t>(angle::ColorGeneric::Type::Float))
{
createInfo.borderColor = VK_BORDER_COLOR_FLOAT_CUSTOM_EXT;
}
else
{
createInfo.borderColor = VK_BORDER_COLOR_INT_CUSTOM_EXT;
}
vk::AddToPNextChain(&createInfo, &customBorderColorInfo);
}
ANGLE_VK_TRY(contextVk, sampler->init(contextVk->getDevice(), createInfo));
return angle::Result::Continue;
}
size_t SamplerDesc::hash() const
{
return angle::ComputeGenericHash(*this);
}
bool SamplerDesc::operator==(const SamplerDesc &other) const
{
return (memcmp(this, &other, sizeof(SamplerDesc)) == 0);
}
// SamplerHelper implementation.
SamplerHelper::SamplerHelper(ContextVk *contextVk)
: mSamplerSerial(contextVk->getRenderer()->getResourceSerialFactory().generateSamplerSerial())
{}
SamplerHelper::~SamplerHelper() {}
SamplerHelper::SamplerHelper(SamplerHelper &&samplerHelper)
{
*this = std::move(samplerHelper);
}
SamplerHelper &SamplerHelper::operator=(SamplerHelper &&rhs)
{
std::swap(mSampler, rhs.mSampler);
std::swap(mSamplerSerial, rhs.mSamplerSerial);
return *this;
}
// RenderPassHelper implementation.
RenderPassHelper::RenderPassHelper() : mPerfCounters{} {}
RenderPassHelper::~RenderPassHelper() = default;
RenderPassHelper::RenderPassHelper(RenderPassHelper &&other)
{
*this = std::move(other);
}
RenderPassHelper &RenderPassHelper::operator=(RenderPassHelper &&other)
{
mRenderPass = std::move(other.mRenderPass);
mPerfCounters = std::move(other.mPerfCounters);
return *this;
}
void RenderPassHelper::destroy(VkDevice device)
{
mRenderPass.destroy(device);
}
const RenderPass &RenderPassHelper::getRenderPass() const
{
return mRenderPass;
}
RenderPass &RenderPassHelper::getRenderPass()
{
return mRenderPass;
}
const RenderPassPerfCounters &RenderPassHelper::getPerfCounters() const
{
return mPerfCounters;
}
RenderPassPerfCounters &RenderPassHelper::getPerfCounters()
{
return mPerfCounters;
}
} // namespace vk
// RenderPassCache implementation.
RenderPassCache::RenderPassCache() = default;
RenderPassCache::~RenderPassCache()
{
ASSERT(mPayload.empty());
}
void RenderPassCache::destroy(RendererVk *rendererVk)
{
rendererVk->accumulateCacheStats(VulkanCacheType::CompatibleRenderPass,
mCompatibleRenderPassCacheStats);
rendererVk->accumulateCacheStats(VulkanCacheType::RenderPassWithOps,
mRenderPassWithOpsCacheStats);
VkDevice device = rendererVk->getDevice();
for (auto &outerIt : mPayload)
{
for (auto &innerIt : outerIt.second)
{
innerIt.second.destroy(device);
}
}
mPayload.clear();
}
angle::Result RenderPassCache::addRenderPass(ContextVk *contextVk,
const vk::RenderPassDesc &desc,
vk::RenderPass **renderPassOut)
{
// Insert some placeholder attachment ops. Note that render passes with different ops are still
// compatible. The load/store values are not important as they are aren't used for real RPs.
//
// It would be nice to pre-populate the cache in the Renderer so we rarely miss here.
vk::AttachmentOpsArray ops;
vk::PackedAttachmentIndex colorIndexVk(0);
for (uint32_t colorIndexGL = 0; colorIndexGL < desc.colorAttachmentRange(); ++colorIndexGL)
{
if (!desc.isColorAttachmentEnabled(colorIndexGL))
{
continue;
}
ops.initWithLoadStore(colorIndexVk, vk::ImageLayout::ColorAttachment,
vk::ImageLayout::ColorAttachment);
++colorIndexVk;
}
if (desc.hasDepthStencilAttachment())
{
// This API is only called by getCompatibleRenderPass(). What we need here is to create a
// compatible renderpass with the desc. Vulkan spec says image layout are not counted toward
// render pass compatibility: "Two render passes are compatible if their corresponding
// color, input, resolve, and depth/stencil attachment references are compatible and if they
// are otherwise identical except for: Initial and final image layout in attachment
// descriptions; Image layout in attachment references". We pick the most used layout here
// since it doesn't matter.
vk::ImageLayout imageLayout = vk::ImageLayout::DepthStencilAttachment;
ops.initWithLoadStore(colorIndexVk, imageLayout, imageLayout);
}
return getRenderPassWithOpsImpl(contextVk, desc, ops, false, renderPassOut);
}
angle::Result RenderPassCache::getRenderPassWithOps(ContextVk *contextVk,
const vk::RenderPassDesc &desc,
const vk::AttachmentOpsArray &attachmentOps,
vk::RenderPass **renderPassOut)
{
return getRenderPassWithOpsImpl(contextVk, desc, attachmentOps, true, renderPassOut);
}
angle::Result RenderPassCache::getRenderPassWithOpsImpl(ContextVk *contextVk,
const vk::RenderPassDesc &desc,
const vk::AttachmentOpsArray &attachmentOps,
bool updatePerfCounters,
vk::RenderPass **renderPassOut)
{
auto outerIt = mPayload.find(desc);
if (outerIt != mPayload.end())
{
InnerCache &innerCache = outerIt->second;
auto innerIt = innerCache.find(attachmentOps);
if (innerIt != innerCache.end())
{
// TODO(jmadill): Could possibly use an MRU cache here.
vk::GetRenderPassAndUpdateCounters(contextVk, updatePerfCounters, &innerIt->second,
renderPassOut);
mRenderPassWithOpsCacheStats.hit();
return angle::Result::Continue;
}
}
else
{
auto emplaceResult = mPayload.emplace(desc, InnerCache());
outerIt = emplaceResult.first;
}
mRenderPassWithOpsCacheStats.miss();
vk::RenderPassHelper newRenderPass;
ANGLE_TRY(vk::InitializeRenderPassFromDesc(contextVk, desc, attachmentOps, &newRenderPass));
InnerCache &innerCache = outerIt->second;
auto insertPos = innerCache.emplace(attachmentOps, std::move(newRenderPass));
vk::GetRenderPassAndUpdateCounters(contextVk, updatePerfCounters, &insertPos.first->second,
renderPassOut);
// TODO(jmadill): Trim cache, and pre-populate with the most common RPs on startup.
return angle::Result::Continue;
}
// GraphicsPipelineCache implementation.
GraphicsPipelineCache::GraphicsPipelineCache() = default;
GraphicsPipelineCache::~GraphicsPipelineCache()
{
ASSERT(mPayload.empty());
}
void GraphicsPipelineCache::destroy(RendererVk *rendererVk)
{
accumulateCacheStats(rendererVk);
VkDevice device = rendererVk->getDevice();
for (auto &item : mPayload)
{
vk::PipelineHelper &pipeline = item.second;
pipeline.destroy(device);
}
mPayload.clear();
}
void GraphicsPipelineCache::release(ContextVk *context)
{
for (auto &item : mPayload)
{
vk::PipelineHelper &pipeline = item.second;
context->addGarbage(&pipeline.getPipeline());
}
mPayload.clear();
}
angle::Result GraphicsPipelineCache::insertPipeline(
ContextVk *contextVk,
const vk::PipelineCache &pipelineCacheVk,
const vk::RenderPass &compatibleRenderPass,
const vk::PipelineLayout &pipelineLayout,
const gl::AttributesMask &activeAttribLocationsMask,
const gl::ComponentTypeMask &programAttribsTypeMask,
const gl::DrawBufferMask &missingOutputsMask,
const vk::ShaderAndSerialMap &shaders,
const vk::SpecializationConstants &specConsts,
const vk::GraphicsPipelineDesc &desc,
const vk::GraphicsPipelineDesc **descPtrOut,
vk::PipelineHelper **pipelineOut)
{
vk::Pipeline newPipeline;
// This "if" is left here for the benefit of VulkanPipelineCachePerfTest.
if (contextVk != nullptr)
{
contextVk->getRenderer()->onNewGraphicsPipeline();
ANGLE_TRY(desc.initializePipeline(contextVk, pipelineCacheVk, compatibleRenderPass,
pipelineLayout, activeAttribLocationsMask,
programAttribsTypeMask, missingOutputsMask, shaders,
specConsts, &newPipeline));
}
// The Serial will be updated outside of this query.
auto insertedItem = mPayload.emplace(desc, std::move(newPipeline));
*descPtrOut = &insertedItem.first->first;
*pipelineOut = &insertedItem.first->second;
return angle::Result::Continue;
}
void GraphicsPipelineCache::populate(const vk::GraphicsPipelineDesc &desc, vk::Pipeline &&pipeline)
{
auto item = mPayload.find(desc);
if (item != mPayload.end())
{
return;
}
mPayload.emplace(desc, std::move(pipeline));
}
// DescriptorSetLayoutCache implementation.
DescriptorSetLayoutCache::DescriptorSetLayoutCache() = default;
DescriptorSetLayoutCache::~DescriptorSetLayoutCache()
{
ASSERT(mPayload.empty());
}
void DescriptorSetLayoutCache::destroy(RendererVk *rendererVk)
{
rendererVk->accumulateCacheStats(VulkanCacheType::DescriptorSetLayout, mCacheStats);
VkDevice device = rendererVk->getDevice();
for (auto &item : mPayload)
{
vk::RefCountedDescriptorSetLayout &layout = item.second;
ASSERT(!layout.isReferenced());
layout.get().destroy(device);
}
mPayload.clear();
}
angle::Result DescriptorSetLayoutCache::getDescriptorSetLayout(
vk::Context *context,
const vk::DescriptorSetLayoutDesc &desc,
vk::BindingPointer<vk::DescriptorSetLayout> *descriptorSetLayoutOut)
{
auto iter = mPayload.find(desc);
if (iter != mPayload.end())
{
vk::RefCountedDescriptorSetLayout &layout = iter->second;
descriptorSetLayoutOut->set(&layout);
mCacheStats.hit();
return angle::Result::Continue;
}
mCacheStats.miss();
// We must unpack the descriptor set layout description.
vk::DescriptorSetLayoutBindingVector bindingVector;
std::vector<VkSampler> immutableSamplers;
desc.unpackBindings(&bindingVector, &immutableSamplers);
VkDescriptorSetLayoutCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
createInfo.flags = 0;
createInfo.bindingCount = static_cast<uint32_t>(bindingVector.size());
createInfo.pBindings = bindingVector.data();
vk::DescriptorSetLayout newLayout;
ANGLE_VK_TRY(context, newLayout.init(context->getDevice(), createInfo));
auto insertedItem =
mPayload.emplace(desc, vk::RefCountedDescriptorSetLayout(std::move(newLayout)));
vk::RefCountedDescriptorSetLayout &insertedLayout = insertedItem.first->second;
descriptorSetLayoutOut->set(&insertedLayout);
return angle::Result::Continue;
}
// PipelineLayoutCache implementation.
PipelineLayoutCache::PipelineLayoutCache() = default;
PipelineLayoutCache::~PipelineLayoutCache()
{
ASSERT(mPayload.empty());
}
void PipelineLayoutCache::destroy(RendererVk *rendererVk)
{
accumulateCacheStats(rendererVk);
VkDevice device = rendererVk->getDevice();
for (auto &item : mPayload)
{
vk::RefCountedPipelineLayout &layout = item.second;
layout.get().destroy(device);
}
mPayload.clear();
}
angle::Result PipelineLayoutCache::getPipelineLayout(
vk::Context *context,
const vk::PipelineLayoutDesc &desc,
const vk::DescriptorSetLayoutPointerArray &descriptorSetLayouts,
vk::BindingPointer<vk::PipelineLayout> *pipelineLayoutOut)
{
auto iter = mPayload.find(desc);
if (iter != mPayload.end())
{
vk::RefCountedPipelineLayout &layout = iter->second;
pipelineLayoutOut->set(&layout);
mCacheStats.hit();
return angle::Result::Continue;
}
mCacheStats.miss();
// Note this does not handle gaps in descriptor set layouts gracefully.
angle::FixedVector<VkDescriptorSetLayout, vk::kMaxDescriptorSetLayouts> setLayoutHandles;
for (const vk::BindingPointer<vk::DescriptorSetLayout> &layoutPtr : descriptorSetLayouts)
{
if (layoutPtr.valid())
{
VkDescriptorSetLayout setLayout = layoutPtr.get().getHandle();
if (setLayout != VK_NULL_HANDLE)
{
setLayoutHandles.push_back(setLayout);
}
}
}
const vk::PackedPushConstantRange &descPushConstantRange = desc.getPushConstantRange();
VkPushConstantRange pushConstantRange;
pushConstantRange.stageFlags = descPushConstantRange.stageMask;
pushConstantRange.offset = descPushConstantRange.offset;
pushConstantRange.size = descPushConstantRange.size;
// No pipeline layout found. We must create a new one.
VkPipelineLayoutCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
createInfo.flags = 0;
createInfo.setLayoutCount = static_cast<uint32_t>(setLayoutHandles.size());
createInfo.pSetLayouts = setLayoutHandles.data();
if (pushConstantRange.size > 0)
{
createInfo.pushConstantRangeCount = 1;
createInfo.pPushConstantRanges = &pushConstantRange;
}
vk::PipelineLayout newLayout;
ANGLE_VK_TRY(context, newLayout.init(context->getDevice(), createInfo));
auto insertedItem = mPayload.emplace(desc, vk::RefCountedPipelineLayout(std::move(newLayout)));
vk::RefCountedPipelineLayout &insertedLayout = insertedItem.first->second;
pipelineLayoutOut->set(&insertedLayout);
return angle::Result::Continue;
}
// YuvConversionCache implementation
SamplerYcbcrConversionCache::SamplerYcbcrConversionCache() = default;
SamplerYcbcrConversionCache::~SamplerYcbcrConversionCache()
{
ASSERT(mExternalFormatPayload.empty() && mVkFormatPayload.empty());
}
void SamplerYcbcrConversionCache::destroy(RendererVk *rendererVk)
{
rendererVk->accumulateCacheStats(VulkanCacheType::SamplerYcbcrConversion, mCacheStats);
VkDevice device = rendererVk->getDevice();
for (auto &iter : mExternalFormatPayload)
{
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter.second;
samplerYcbcrConversion.destroy(device);
rendererVk->onDeallocateHandle(vk::HandleType::SamplerYcbcrConversion);
}
for (auto &iter : mVkFormatPayload)
{
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter.second;
samplerYcbcrConversion.destroy(device);
rendererVk->onDeallocateHandle(vk::HandleType::SamplerYcbcrConversion);
}
mExternalFormatPayload.clear();
mVkFormatPayload.clear();
}
angle::Result SamplerYcbcrConversionCache::getSamplerYcbcrConversion(
vk::Context *context,
const vk::YcbcrConversionDesc &ycbcrConversionDesc,
VkSamplerYcbcrConversion *vkSamplerYcbcrConversionOut)
{
ASSERT(ycbcrConversionDesc.valid());
ASSERT(vkSamplerYcbcrConversionOut);
SamplerYcbcrConversionMap &payload =
(ycbcrConversionDesc.mIsExternalFormat) ? mExternalFormatPayload : mVkFormatPayload;
const auto iter = payload.find(ycbcrConversionDesc);
if (iter != payload.end())
{
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter->second;
mCacheStats.hit();
*vkSamplerYcbcrConversionOut = samplerYcbcrConversion.getHandle();
return angle::Result::Continue;
}
mCacheStats.miss();
// Create the VkSamplerYcbcrConversion
VkSamplerYcbcrConversionCreateInfo samplerYcbcrConversionInfo = {};
samplerYcbcrConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
samplerYcbcrConversionInfo.format = static_cast<VkFormat>(
(ycbcrConversionDesc.mIsExternalFormat) ? VK_FORMAT_UNDEFINED
: ycbcrConversionDesc.mExternalOrVkFormat);
samplerYcbcrConversionInfo.xChromaOffset =
static_cast<VkChromaLocation>(ycbcrConversionDesc.mXChromaOffset);
samplerYcbcrConversionInfo.yChromaOffset =
static_cast<VkChromaLocation>(ycbcrConversionDesc.mYChromaOffset);
samplerYcbcrConversionInfo.ycbcrModel =
static_cast<VkSamplerYcbcrModelConversion>(ycbcrConversionDesc.mConversionModel);
samplerYcbcrConversionInfo.ycbcrRange =
static_cast<VkSamplerYcbcrRange>(ycbcrConversionDesc.mColorRange);
samplerYcbcrConversionInfo.chromaFilter =
static_cast<VkFilter>(ycbcrConversionDesc.mChromaFilter);
samplerYcbcrConversionInfo.components = {
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mRSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mGSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mBSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mASwizzle)};
#ifdef VK_USE_PLATFORM_ANDROID_KHR
VkExternalFormatANDROID externalFormat = {};
if (ycbcrConversionDesc.mIsExternalFormat)
{
externalFormat.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID;
externalFormat.externalFormat = ycbcrConversionDesc.mExternalOrVkFormat;
samplerYcbcrConversionInfo.pNext = &externalFormat;
}
#else
// We do not support external format for any platform other than Android.
ASSERT(ycbcrConversionDesc.mIsExternalFormat == 0);
#endif // VK_USE_PLATFORM_ANDROID_KHR
vk::SamplerYcbcrConversion wrappedSamplerYcbcrConversion;
ANGLE_VK_TRY(context, wrappedSamplerYcbcrConversion.init(context->getDevice(),
samplerYcbcrConversionInfo));
auto insertedItem = payload.emplace(
ycbcrConversionDesc, vk::SamplerYcbcrConversion(std::move(wrappedSamplerYcbcrConversion)));
vk::SamplerYcbcrConversion &insertedSamplerYcbcrConversion = insertedItem.first->second;
*vkSamplerYcbcrConversionOut = insertedSamplerYcbcrConversion.getHandle();
context->getRenderer()->onAllocateHandle(vk::HandleType::SamplerYcbcrConversion);
return angle::Result::Continue;
}
// SamplerCache implementation.
SamplerCache::SamplerCache() = default;
SamplerCache::~SamplerCache()
{
ASSERT(mPayload.empty());
}
void SamplerCache::destroy(RendererVk *rendererVk)
{
rendererVk->accumulateCacheStats(VulkanCacheType::Sampler, mCacheStats);
VkDevice device = rendererVk->getDevice();
for (auto &iter : mPayload)
{
vk::RefCountedSampler &sampler = iter.second;
ASSERT(!sampler.isReferenced());
sampler.get().get().destroy(device);
rendererVk->onDeallocateHandle(vk::HandleType::Sampler);
}
mPayload.clear();
}
angle::Result SamplerCache::getSampler(ContextVk *contextVk,
const vk::SamplerDesc &desc,
vk::SamplerBinding *samplerOut)
{
auto iter = mPayload.find(desc);
if (iter != mPayload.end())
{
vk::RefCountedSampler &sampler = iter->second;
samplerOut->set(&sampler);
mCacheStats.hit();
return angle::Result::Continue;
}
mCacheStats.miss();
vk::SamplerHelper samplerHelper(contextVk);
ANGLE_TRY(desc.init(contextVk, &samplerHelper.get()));
vk::RefCountedSampler newSampler(std::move(samplerHelper));
auto insertedItem = mPayload.emplace(desc, std::move(newSampler));
vk::RefCountedSampler &insertedSampler = insertedItem.first->second;
samplerOut->set(&insertedSampler);
contextVk->getRenderer()->onAllocateHandle(vk::HandleType::Sampler);
return angle::Result::Continue;
}
// DriverUniformsDescriptorSetCache implementation.
void DriverUniformsDescriptorSetCache::destroy(RendererVk *rendererVk)
{
accumulateCacheStats(rendererVk);
mPayload.clear();
}
// DescriptorSetCache implementation.
void DescriptorSetCache::destroy(RendererVk *rendererVk, VulkanCacheType cacheType)
{
accumulateCacheStats(cacheType, rendererVk);
mPayload.clear();
}
} // namespace rx